From 7ff29a57bda3bfff65cb57a9157ecf49c49ab206 Mon Sep 17 00:00:00 2001 From: Barry Pederson Date: Mon, 16 Nov 2015 15:40:39 -0600 Subject: [PATCH] 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. --- src/Suin/RSSWriter/Item.php | 4 +-- tests/Suin/RSSWriter/ItemTest.php | 47 ++++++++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/src/Suin/RSSWriter/Item.php b/src/Suin/RSSWriter/Item.php index 309877a..c392100 100644 --- a/src/Suin/RSSWriter/Item.php +++ b/src/Suin/RSSWriter/Item.php @@ -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'); } } diff --git a/tests/Suin/RSSWriter/ItemTest.php b/tests/Suin/RSSWriter/ItemTest.php index 7318256..c8ccd18 100644 --- a/tests/Suin/RSSWriter/ItemTest.php +++ b/tests/Suin/RSSWriter/ItemTest.php @@ -143,7 +143,52 @@ public function testAsXML() {$data['description']} {$data['categories'][0][0]} {$data['categories'][1][0]} - {$data['guid']} + {$data['guid']} + {$nowString} + + {$data['author']} + + "; + $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 = " + + {$data['title']} + {$data['url']} + {$data['description']} + {$data['categories'][0][0]} + {$data['categories'][1][0]} + {$data['guid']} {$nowString} {$data['author']}