Skip to content

Commit

Permalink
Merge pull request #13 from barryp/issue_11
Browse files Browse the repository at this point in the history
Render guid with isPermaLink=false
  • Loading branch information
suin committed Mar 1, 2016
2 parents 96ff595 + 7ff29a5 commit 51840d2
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/Suin/RSSWriter/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ public function asXML()
if ($this->guid) {
$guid = $xml->addChild('guid', $this->guid);

if ($this->isPermalink) {
$guid->addAttribute('isPermaLink', 'true');
if ($this->isPermalink === false) {
$guid->addAttribute('isPermaLink', 'false');
}
}

Expand Down
47 changes: 46 additions & 1 deletion tests/Suin/RSSWriter/ItemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,52 @@ public function testAsXML()
<description>{$data['description']}</description>
<category>{$data['categories'][0][0]}</category>
<category domain=\"{$data['categories'][1][1]}\">{$data['categories'][1][0]}</category>
<guid isPermaLink=\"true\">{$data['guid']}</guid>
<guid>{$data['guid']}</guid>
<pubDate>{$nowString}</pubDate>
<enclosure url=\"{$data['enclosure']['url']}\" type=\"{$data['enclosure']['type']}\" length=\"{$data['enclosure']['length']}\"/>
<author>{$data['author']}</author>
</item>
";
$this->assertXmlStringEqualsXmlString($expect, $item->asXML()->asXML());
}

public function testAsXML_false_permalink()
{
$now = time();
$nowString = date(DATE_RSS, $now);

$data = array(
'title' => "Venice Film Festival Tries to Quit Sinking",
'url' => 'http://nytimes.com/2004/12/07FEST.html',
'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.",
'categories' => array(
array("Grateful Dead", null),
array("MSFT", 'http://www.fool.com/cusips'),
),
'guid' => "http://inessential.com/2002/09/01.php#a2",
'isPermalink' => false,
'pubDate' => $now,
'enclosure' => array(
'url' => 'http://link-to-audio-file.com/test.mp3',
'length' => 4992,
'type' => 'audio/mpeg'),
'author' => 'Hidehito Nozawa aka Suin'
);

$item = new Item();

foreach ($data as $key => $value) {
$this->reveal($item)->attr($key, $value);
}

$expect = "
<item>
<title>{$data['title']}</title>
<link>{$data['url']}</link>
<description>{$data['description']}</description>
<category>{$data['categories'][0][0]}</category>
<category domain=\"{$data['categories'][1][1]}\">{$data['categories'][1][0]}</category>
<guid isPermaLink=\"false\">{$data['guid']}</guid>
<pubDate>{$nowString}</pubDate>
<enclosure url=\"{$data['enclosure']['url']}\" type=\"{$data['enclosure']['type']}\" length=\"{$data['enclosure']['length']}\"/>
<author>{$data['author']}</author>
Expand Down

0 comments on commit 51840d2

Please sign in to comment.