Skip to content

Commit 7ff29a5

Browse files
committed
Render guid with isPermaLink=false
Swaps behaviour to match the specs at http://cyber.law.harvard.edu/rss/rss.html#ltguidgtSubelementOfLtitemgt "isPermaLink is optional, its default value is true". Fix existing unittest to look for no "isPermalink" attribute when the value is true, add a new test to look for it when it's false.
1 parent 96ff595 commit 7ff29a5

File tree

2 files changed

+48
-3
lines changed

2 files changed

+48
-3
lines changed

src/Suin/RSSWriter/Item.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ public function asXML()
108108
if ($this->guid) {
109109
$guid = $xml->addChild('guid', $this->guid);
110110

111-
if ($this->isPermalink) {
112-
$guid->addAttribute('isPermaLink', 'true');
111+
if ($this->isPermalink === false) {
112+
$guid->addAttribute('isPermaLink', 'false');
113113
}
114114
}
115115

tests/Suin/RSSWriter/ItemTest.php

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,52 @@ public function testAsXML()
143143
<description>{$data['description']}</description>
144144
<category>{$data['categories'][0][0]}</category>
145145
<category domain=\"{$data['categories'][1][1]}\">{$data['categories'][1][0]}</category>
146-
<guid isPermaLink=\"true\">{$data['guid']}</guid>
146+
<guid>{$data['guid']}</guid>
147+
<pubDate>{$nowString}</pubDate>
148+
<enclosure url=\"{$data['enclosure']['url']}\" type=\"{$data['enclosure']['type']}\" length=\"{$data['enclosure']['length']}\"/>
149+
<author>{$data['author']}</author>
150+
</item>
151+
";
152+
$this->assertXmlStringEqualsXmlString($expect, $item->asXML()->asXML());
153+
}
154+
155+
public function testAsXML_false_permalink()
156+
{
157+
$now = time();
158+
$nowString = date(DATE_RSS, $now);
159+
160+
$data = array(
161+
'title' => "Venice Film Festival Tries to Quit Sinking",
162+
'url' => 'http://nytimes.com/2004/12/07FEST.html',
163+
'description' => "Some of the most heated chatter at the Venice Film Festival this week was about the way that the arrival of the stars at the Palazzo del Cinema was being staged.",
164+
'categories' => array(
165+
array("Grateful Dead", null),
166+
array("MSFT", 'http://www.fool.com/cusips'),
167+
),
168+
'guid' => "http://inessential.com/2002/09/01.php#a2",
169+
'isPermalink' => false,
170+
'pubDate' => $now,
171+
'enclosure' => array(
172+
'url' => 'http://link-to-audio-file.com/test.mp3',
173+
'length' => 4992,
174+
'type' => 'audio/mpeg'),
175+
'author' => 'Hidehito Nozawa aka Suin'
176+
);
177+
178+
$item = new Item();
179+
180+
foreach ($data as $key => $value) {
181+
$this->reveal($item)->attr($key, $value);
182+
}
183+
184+
$expect = "
185+
<item>
186+
<title>{$data['title']}</title>
187+
<link>{$data['url']}</link>
188+
<description>{$data['description']}</description>
189+
<category>{$data['categories'][0][0]}</category>
190+
<category domain=\"{$data['categories'][1][1]}\">{$data['categories'][1][0]}</category>
191+
<guid isPermaLink=\"false\">{$data['guid']}</guid>
147192
<pubDate>{$nowString}</pubDate>
148193
<enclosure url=\"{$data['enclosure']['url']}\" type=\"{$data['enclosure']['type']}\" length=\"{$data['enclosure']['length']}\"/>
149194
<author>{$data['author']}</author>

0 commit comments

Comments
 (0)