Adding enclosures now treats type and length parameters as optional for Atom, but...
[zend.git] / tests / Zend / Feed / Writer / Renderer / Entry / RssTest.php
blobc4de5fbf8c07e9bd73d02de3a41f50e510b4e47d
1 <?php
2 /**
3 * Zend Framework
5 * LICENSE
7 * This source file is subject to the new BSD license that is bundled
8 * with this package in the file LICENSE.txt.
9 * It is also available through the world-wide-web at this URL:
10 * http://framework.zend.com/license/new-bsd
11 * If you did not receive a copy of the license and are unable to
12 * obtain it through the world-wide-web, please send an email
13 * to license@zend.com so we can send you a copy immediately.
15 * @category Zend
16 * @package Zend_Feed
17 * @subpackage UnitTests
18 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19 * @license http://framework.zend.com/license/new-bsd New BSD License
20 * @version $Id$
23 require_once dirname(dirname(dirname(dirname(dirname(dirname(__FILE__)))))) . DIRECTORY_SEPARATOR . 'TestHelper.php';
25 require_once 'Zend/Feed/Writer/Renderer/Feed/Rss.php';
26 require_once 'Zend/Feed/Reader.php';
27 require_once 'Zend/Version.php';
29 /**
30 * @category Zend
31 * @package Zend_Feed
32 * @subpackage UnitTests
33 * @group Zend_Feed
34 * @group Zend_Feed_Writer
35 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
36 * @license http://framework.zend.com/license/new-bsd New BSD License
38 class Zend_Feed_Writer_Renderer_Entry_RssTest extends PHPUnit_Framework_TestCase
41 protected $_validWriter = null;
42 protected $_validEntry = null;
44 public function setUp()
46 $this->_validWriter = new Zend_Feed_Writer_Feed;
48 $this->_validWriter->setType('rss');
50 $this->_validWriter->setTitle('This is a test feed.');
51 $this->_validWriter->setDescription('This is a test description.');
52 $this->_validWriter->setLink('http://www.example.com');
53 $this->_validEntry = $this->_validWriter->createEntry();
54 $this->_validEntry->setTitle('This is a test entry.');
55 $this->_validEntry->setDescription('This is a test entry description.');
56 $this->_validEntry->setLink('http://www.example.com/1');;
57 $this->_validWriter->addEntry($this->_validEntry);
60 public function tearDown()
62 $this->_validWriter = null;
63 $this->_validEntry = null;
66 public function testRenderMethodRunsMinimalWriterContainerProperlyBeforeICheckAtomCompliance()
68 $renderer = new Zend_Feed_Writer_Renderer_Feed_Rss($this->_validWriter);
69 try {
70 $renderer->render();
71 } catch (Zend_Feed_Exception $e) {
72 $this->fail('Valid Writer object caused an exception when building which should never happen');
76 public function testEntryEncodingHasBeenSet()
78 $this->_validWriter->setEncoding('iso-8859-1');
79 $renderer = new Zend_Feed_Writer_Renderer_Feed_Rss($this->_validWriter);
80 $feed = Zend_Feed_Reader::importString($renderer->render()->saveXml());
81 $entry = $feed->current();
82 $this->assertEquals('iso-8859-1', $entry->getEncoding());
85 public function testEntryEncodingDefaultIsUsedIfEncodingNotSetByHand()
87 $renderer = new Zend_Feed_Writer_Renderer_Feed_Rss($this->_validWriter);
88 $feed = Zend_Feed_Reader::importString($renderer->render()->saveXml());
89 $entry = $feed->current();
90 $this->assertEquals('UTF-8', $entry->getEncoding());
93 public function testEntryTitleHasBeenSet()
95 $renderer = new Zend_Feed_Writer_Renderer_Feed_Rss($this->_validWriter);
96 $feed = Zend_Feed_Reader::importString($renderer->render()->saveXml());
97 $entry = $feed->current();
98 $this->assertEquals('This is a test entry.', $entry->getTitle());
102 * @expectedException Zend_Feed_Exception
104 public function testEntryTitleIfMissingThrowsExceptionIfDescriptionAlsoMissing()
106 $atomFeed = new Zend_Feed_Writer_Renderer_Feed_Rss($this->_validWriter);
107 $this->_validEntry->remove('title');
108 $this->_validEntry->remove('description');
109 $atomFeed->render();
112 public function testEntryTitleCharDataEncoding()
114 $renderer = new Zend_Feed_Writer_Renderer_Feed_Rss($this->_validWriter);
115 $this->_validEntry->setTitle('<>&\'"áéíóú');
116 $feed = Zend_Feed_Reader::importString($renderer->render()->saveXml());
117 $entry = $feed->current();
118 $this->assertEquals('<>&\'"áéíóú', $entry->getTitle());
121 public function testEntrySummaryDescriptionHasBeenSet()
123 $renderer = new Zend_Feed_Writer_Renderer_Feed_Rss($this->_validWriter);
124 $feed = Zend_Feed_Reader::importString($renderer->render()->saveXml());
125 $entry = $feed->current();
126 $this->assertEquals('This is a test entry description.', $entry->getDescription());
130 * @expectedException Zend_Feed_Exception
132 public function testEntryDescriptionIfMissingThrowsExceptionIfAlsoNoTitle()
134 $atomFeed = new Zend_Feed_Writer_Renderer_Feed_Rss($this->_validWriter);
135 $this->_validEntry->remove('description');
136 $this->_validEntry->remove('title');
137 $atomFeed->render();
140 public function testEntryDescriptionCharDataEncoding()
142 $renderer = new Zend_Feed_Writer_Renderer_Feed_Rss($this->_validWriter);
143 $this->_validEntry->setDescription('<>&\'"áéíóú');
144 $feed = Zend_Feed_Reader::importString($renderer->render()->saveXml());
145 $entry = $feed->current();
146 $this->assertEquals('<>&\'"áéíóú', $entry->getDescription());
149 public function testEntryContentHasBeenSet()
151 $this->_validEntry->setContent('This is test entry content.');
152 $renderer = new Zend_Feed_Writer_Renderer_Feed_Rss($this->_validWriter);
153 $feed = Zend_Feed_Reader::importString($renderer->render()->saveXml());
154 $entry = $feed->current();
155 $this->assertEquals('This is test entry content.', $entry->getContent());
158 public function testEntryContentCharDataEncoding()
160 $renderer = new Zend_Feed_Writer_Renderer_Feed_Rss($this->_validWriter);
161 $this->_validEntry->setContent('<>&\'"áéíóú');
162 $feed = Zend_Feed_Reader::importString($renderer->render()->saveXml());
163 $entry = $feed->current();
164 $this->assertEquals('<>&\'"áéíóú', $entry->getContent());
167 public function testEntryUpdatedDateHasBeenSet()
169 $this->_validEntry->setDateModified(1234567890);
170 $renderer = new Zend_Feed_Writer_Renderer_Feed_Rss($this->_validWriter);
171 $feed = Zend_Feed_Reader::importString($renderer->render()->saveXml());
172 $entry = $feed->current();
173 $this->assertEquals(1234567890, $entry->getDateModified()->get(Zend_Date::TIMESTAMP));
176 public function testEntryPublishedDateHasBeenSet()
178 $this->_validEntry->setDateCreated(1234567000);
179 $renderer = new Zend_Feed_Writer_Renderer_Feed_Rss($this->_validWriter);
180 $feed = Zend_Feed_Reader::importString($renderer->render()->saveXml());
181 $entry = $feed->current();
182 $this->assertEquals(1234567000, $entry->getDateCreated()->get(Zend_Date::TIMESTAMP));
185 public function testEntryIncludesLinkToHtmlVersionOfFeed()
187 $renderer= new Zend_Feed_Writer_Renderer_Feed_Rss($this->_validWriter);
188 $feed = Zend_Feed_Reader::importString($renderer->render()->saveXml());
189 $entry = $feed->current();
190 $this->assertEquals('http://www.example.com/1', $entry->getLink());
193 public function testEntryHoldsAnyAuthorAdded()
195 $this->_validEntry->addAuthor('Jane', 'jane@example.com', 'http://www.example.com/jane');
196 $renderer = new Zend_Feed_Writer_Renderer_Feed_Rss($this->_validWriter);
197 $feed = Zend_Feed_Reader::importString($renderer->render()->saveXml());
198 $entry = $feed->current();
199 $author = $entry->getAuthor();
200 $this->assertEquals(array('name'=>'Jane'), $entry->getAuthor());
203 public function testEntryAuthorCharDataEncoding()
205 $this->_validEntry->addAuthor('<>&\'"áéíóú', 'jane@example.com', 'http://www.example.com/jane');
206 $renderer = new Zend_Feed_Writer_Renderer_Feed_Rss($this->_validWriter);
207 $feed = Zend_Feed_Reader::importString($renderer->render()->saveXml());
208 $entry = $feed->current();
209 $author = $entry->getAuthor();
210 $this->assertEquals(array('name'=>'<>&\'"áéíóú'), $entry->getAuthor());
213 public function testEntryHoldsAnyEnclosureAdded()
215 $renderer = new Zend_Feed_Writer_Renderer_Feed_Rss($this->_validWriter);
216 $this->_validEntry->setEnclosure(array(
217 'type' => 'audio/mpeg',
218 'length' => '1337',
219 'uri' => 'http://example.com/audio.mp3'
221 $feed = Zend_Feed_Reader::importString($renderer->render()->saveXml());
222 $entry = $feed->current();
223 $enc = $entry->getEnclosure();
224 $this->assertEquals('audio/mpeg', $enc->type);
225 $this->assertEquals('1337', $enc->length);
226 $this->assertEquals('http://example.com/audio.mp3', $enc->url);
230 * @expectedException Zend_Feed_Exception
232 public function testAddsEnclosureThrowsExceptionOnMissingType()
234 $renderer = new Zend_Feed_Writer_Renderer_Feed_Rss($this->_validWriter);
235 $this->_validEntry->setEnclosure(array(
236 'uri' => 'http://example.com/audio.mp3',
237 'length' => '1337'
239 $renderer->render();
243 * @expectedException Zend_Feed_Exception
245 public function testAddsEnclosureThrowsExceptionOnMissingLength()
247 $renderer = new Zend_Feed_Writer_Renderer_Feed_Rss($this->_validWriter);
248 $this->_validEntry->setEnclosure(array(
249 'type' => 'audio/mpeg',
250 'uri' => 'http://example.com/audio.mp3'
252 $renderer->render();
256 * @expectedException Zend_Feed_Exception
258 public function testAddsEnclosureThrowsExceptionOnNonNumericLength()
260 $renderer = new Zend_Feed_Writer_Renderer_Feed_Rss($this->_validWriter);
261 $this->_validEntry->setEnclosure(array(
262 'type' => 'audio/mpeg',
263 'uri' => 'http://example.com/audio.mp3',
264 'length' => 'abc'
266 $renderer->render();
270 * @expectedException Zend_Feed_Exception
272 public function testAddsEnclosureThrowsExceptionOnNegativeLength()
274 $renderer = new Zend_Feed_Writer_Renderer_Feed_Rss($this->_validWriter);
275 $this->_validEntry->setEnclosure(array(
276 'type' => 'audio/mpeg',
277 'uri' => 'http://example.com/audio.mp3',
278 'length' => -23
280 $renderer->render();
283 public function testEntryIdHasBeenSet()
285 $this->_validEntry->setId('urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6');
286 $renderer = new Zend_Feed_Writer_Renderer_Feed_Rss($this->_validWriter);
287 $feed = Zend_Feed_Reader::importString($renderer->render()->saveXml());
288 $entry = $feed->current();
289 $this->assertEquals('urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6', $entry->getId());
292 public function testEntryIdHasBeenSetWithPermaLinkAsFalseWhenNotUri()
294 $this->markTestIncomplete('Untest due to ZFR potential bug');
297 public function testEntryIdDefaultIsUsedIfNotSetByHand()
299 $renderer = new Zend_Feed_Writer_Renderer_Feed_Rss($this->_validWriter);
300 $feed = Zend_Feed_Reader::importString($renderer->render()->saveXml());
301 $entry = $feed->current();
302 $this->assertEquals($entry->getLink(), $entry->getId());
305 public function testCommentLinkRendered()
307 $renderer = new Zend_Feed_Writer_Renderer_Feed_Rss($this->_validWriter);
308 $this->_validEntry->setCommentLink('http://www.example.com/id/1');
309 $feed = Zend_Feed_Reader::importString($renderer->render()->saveXml());
310 $entry = $feed->current();
311 $this->assertEquals('http://www.example.com/id/1', $entry->getCommentLink());
314 public function testCommentCountRendered()
316 $renderer = new Zend_Feed_Writer_Renderer_Feed_Rss($this->_validWriter);
317 $this->_validEntry->setCommentCount(22);
318 $feed = Zend_Feed_Reader::importString($renderer->render()->saveXml());
319 $entry = $feed->current();
320 $this->assertEquals(22, $entry->getCommentCount());
323 public function testCommentFeedLinksRendered()
325 $renderer = new Zend_Feed_Writer_Renderer_Feed_Rss($this->_validWriter);
326 $this->_validEntry->setCommentFeedLinks(array(
327 array('uri'=>'http://www.example.com/atom/id/1','type'=>'atom'),
328 array('uri'=>'http://www.example.com/rss/id/1','type'=>'rss'),
330 $feed = Zend_Feed_Reader::importString($renderer->render()->saveXml());
331 $entry = $feed->current();
332 // Skipped assertion is because RSS has no facility to show Atom feeds without an extension
333 $this->assertEquals('http://www.example.com/rss/id/1', $entry->getCommentFeedLink('rss'));
334 //$this->assertEquals('http://www.example.com/atom/id/1', $entry->getCommentFeedLink('atom'));
337 public function testCategoriesCanBeSet()
339 $this->_validEntry->addCategories(array(
340 array('term'=>'cat_dog', 'label' => 'Cats & Dogs', 'scheme' => 'http://example.com/schema1'),
341 array('term'=>'cat_dog2')
343 $renderer = new Zend_Feed_Writer_Renderer_Feed_Rss($this->_validWriter);
344 $feed = Zend_Feed_Reader::importString($renderer->render()->saveXml());
345 $entry = $feed->current();
346 $expected = array(
347 array('term'=>'cat_dog', 'label' => 'cat_dog', 'scheme' => 'http://example.com/schema1'),
348 array('term'=>'cat_dog2', 'label' => 'cat_dog2', 'scheme' => null)
350 $this->assertEquals($expected, (array) $entry->getCategories());
354 * @group ZFWCHARDATA01
356 public function testCategoriesCharDataEncoding()
358 $this->_validEntry->addCategories(array(
359 array('term'=>'<>&\'"áéíóú', 'label' => 'Cats & Dogs', 'scheme' => 'http://example.com/schema1'),
360 array('term'=>'cat_dog2')
362 $renderer = new Zend_Feed_Writer_Renderer_Feed_Rss($this->_validWriter);
363 $feed = Zend_Feed_Reader::importString($renderer->render()->saveXml());
364 $entry = $feed->current();
365 $expected = array(
366 array('term'=>'<>&\'"áéíóú', 'label' => '<>&\'"áéíóú', 'scheme' => 'http://example.com/schema1'),
367 array('term'=>'cat_dog2', 'label' => 'cat_dog2', 'scheme' => null)
369 $this->assertEquals($expected, (array) $entry->getCategories());