| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527 |
- <?php
- /**
- * Zend Framework
- *
- * LICENSE
- *
- * This source file is subject to the new BSD license that is bundled
- * with this package in the file LICENSE.txt.
- * It is also available through the world-wide-web at this URL:
- * http://framework.zend.com/license/new-bsd
- * If you did not receive a copy of the license and are unable to
- * obtain it through the world-wide-web, please send an email
- * to license@zend.com so we can send you a copy immediately.
- *
- * @category Zend
- * @package Zend_Feed
- * @subpackage UnitTests
- * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- * @version $Id$
- */
- require_once 'Zend/Feed/Reader.php';
- /**
- * @category Zend
- * @package Zend_Feed
- * @subpackage UnitTests
- * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- * @group Zend_Feed
- * @group Zend_Feed_Reader
- */
- class Zend_Feed_Reader_Entry_AtomTest extends PHPUnit_Framework_TestCase
- {
- protected $_feedSamplePath = null;
-
- protected $_expectedCats = array();
-
- protected $_expectedCatsDc = array();
- public function setup()
- {
- Zend_Feed_Reader::reset();
- if (Zend_Registry::isRegistered('Zend_Locale')) {
- $registry = Zend_Registry::getInstance();
- unset($registry['Zend_Locale']);
- }
- $this->_feedSamplePath = dirname(__FILE__) . '/_files/Atom';
- $this->_options = Zend_Date::setOptions();
- foreach($this->_options as $k=>$v) {
- if (is_null($v)) {
- unset($this->_options[$k]);
- }
- }
- Zend_Date::setOptions(array('format_type'=>'iso'));
- $this->_expectedCats = array(
- array(
- 'term' => 'topic1',
- 'scheme' => 'http://example.com/schema1',
- 'label' => 'topic1'
- ),
- array(
- 'term' => 'topic1',
- 'scheme' => 'http://example.com/schema2',
- 'label' => 'topic1'
- ),
- array(
- 'term' => 'cat_dog',
- 'scheme' => 'http://example.com/schema1',
- 'label' => 'Cat & Dog'
- )
- );
- $this->_expectedCatsDc = array(
- array(
- 'term' => 'topic1',
- 'scheme' => null,
- 'label' => 'topic1'
- ),
- array(
- 'term' => 'topic2',
- 'scheme' => null,
- 'label' => 'topic2'
- )
- );
- }
-
- public function teardown()
- {
- Zend_Date::setOptions($this->_options);
- }
- /**
- * Get Id (Unencoded Text)
- * @group ZFR003
- */
- public function testGetsIdFromAtom03()
- {
- $feed = Zend_Feed_Reader::importString(
- file_get_contents($this->_feedSamplePath . '/id/plain/atom03.xml')
- );
- $entry = $feed->current();
- $this->assertEquals('1', $entry->getId());
- }
- public function testGetsIdFromAtom10()
- {
- $feed = Zend_Feed_Reader::importString(
- file_get_contents($this->_feedSamplePath . '/id/plain/atom10.xml')
- );
- $entry = $feed->current();
- $this->assertEquals('1', $entry->getId());
- }
- /**
- * Get creation date (Unencoded Text)
- */
- public function testGetsDateCreatedFromAtom03()
- {
- $feed = Zend_Feed_Reader::importString(
- file_get_contents($this->_feedSamplePath . '/datecreated/plain/atom03.xml')
- );
- $entry = $feed->current();
- $edate = new Zend_Date;
- $edate->set('2009-03-07T08:03:50Z', Zend_Date::ISO_8601);
- $this->assertTrue($edate->equals($entry->getDateCreated()));
- }
- public function testGetsDateCreatedFromAtom10()
- {
- $feed = Zend_Feed_Reader::importString(
- file_get_contents($this->_feedSamplePath . '/datecreated/plain/atom10.xml')
- );
- $entry = $feed->current();
- $edate = new Zend_Date;
- $edate->set('2009-03-07T08:03:50Z', Zend_Date::ISO_8601);
- $this->assertTrue($edate->equals($entry->getDateCreated()));
- }
- /**
- * Get modification date (Unencoded Text)
- */
- public function testGetsDateModifiedFromAtom03()
- {
- $feed = Zend_Feed_Reader::importString(
- file_get_contents($this->_feedSamplePath . '/datemodified/plain/atom03.xml')
- );
- $entry = $feed->current();
- $edate = new Zend_Date;
- $edate->set('2009-03-07T08:03:50Z', Zend_Date::ISO_8601);
- $this->assertTrue($edate->equals($entry->getDateModified()));
- }
- public function testGetsDateModifiedFromAtom10()
- {
- $feed = Zend_Feed_Reader::importString(
- file_get_contents($this->_feedSamplePath . '/datemodified/plain/atom10.xml')
- );
- $entry = $feed->current();
- $edate = new Zend_Date;
- $edate->set('2009-03-07T08:03:50Z', Zend_Date::ISO_8601);
- $this->assertTrue($edate->equals($entry->getDateModified()));
- }
- /**
- * Get Title (Unencoded Text)
- */
- public function testGetsTitleFromAtom03()
- {
- $feed = Zend_Feed_Reader::importString(
- file_get_contents($this->_feedSamplePath . '/title/plain/atom03.xml')
- );
- $entry = $feed->current();
- $this->assertEquals('Entry Title', $entry->getTitle());
- }
- public function testGetsTitleFromAtom10()
- {
- $feed = Zend_Feed_Reader::importString(
- file_get_contents($this->_feedSamplePath . '/title/plain/atom10.xml')
- );
- $entry = $feed->current();
- $this->assertEquals('Entry Title', $entry->getTitle());
- }
- /**
- * Get Authors (Unencoded Text)
- */
- public function testGetsAuthorsFromAtom03()
- {
- $feed = Zend_Feed_Reader::importString(
- file_get_contents($this->_feedSamplePath . '/author/plain/atom03.xml')
- );
- $authors = array(
- array('email'=>'joe@example.com','name'=>'Joe Bloggs','uri'=>'http://www.example.com'),
- array('name'=>'Joe Bloggs','uri'=>'http://www.example.com'),
- array('name'=>'Joe Bloggs'),
- array('email'=>'joe@example.com','uri'=>'http://www.example.com'),
- array('uri'=>'http://www.example.com'),
- array('email'=>'joe@example.com')
- );
- $entry = $feed->current();
- $this->assertEquals($authors, (array) $entry->getAuthors());
- }
- public function testGetsAuthorsFromAtom10()
- {
- $feed = Zend_Feed_Reader::importString(
- file_get_contents($this->_feedSamplePath . '/author/plain/atom10.xml')
- );
- $authors = array(
- array('email'=>'joe@example.com','name'=>'Joe Bloggs','uri'=>'http://www.example.com'),
- array('name'=>'Joe Bloggs','uri'=>'http://www.example.com'),
- array('name'=>'Joe Bloggs'),
- array('email'=>'joe@example.com','uri'=>'http://www.example.com'),
- array('uri'=>'http://www.example.com'),
- array('email'=>'joe@example.com')
- );
- $entry = $feed->current();
- $this->assertEquals($authors, (array) $entry->getAuthors());
- }
- /**
- * Get Author (Unencoded Text)
- */
- public function testGetsAuthorFromAtom03()
- {
- $feed = Zend_Feed_Reader::importString(
- file_get_contents($this->_feedSamplePath . '/author/plain/atom03.xml')
- );
- $entry = $feed->current();
- $this->assertEquals(array('name'=>'Joe Bloggs','email'=>'joe@example.com','uri'=>'http://www.example.com'), $entry->getAuthor());
- }
- public function testGetsAuthorFromAtom10()
- {
- $feed = Zend_Feed_Reader::importString(
- file_get_contents($this->_feedSamplePath . '/author/plain/atom10.xml')
- );
- $entry = $feed->current();
- $this->assertEquals(array('name'=>'Joe Bloggs','email'=>'joe@example.com','uri'=>'http://www.example.com'), $entry->getAuthor());
- }
- /**
- * Get Description (Unencoded Text)
- */
- public function testGetsDescriptionFromAtom03()
- {
- $feed = Zend_Feed_Reader::importString(
- file_get_contents($this->_feedSamplePath . '/description/plain/atom03.xml')
- );
- $entry = $feed->current();
- $this->assertEquals('Entry Description', $entry->getDescription());
- }
- public function testGetsDescriptionFromAtom10()
- {
- $feed = Zend_Feed_Reader::importString(
- file_get_contents($this->_feedSamplePath . '/description/plain/atom10.xml')
- );
- $entry = $feed->current();
- $this->assertEquals('Entry Description', $entry->getDescription());
- }
- /**
- * Get enclosure
- */
- public function testGetsEnclosureFromAtom03()
- {
- $feed = Zend_Feed_Reader::importString(
- file_get_contents($this->_feedSamplePath.'/enclosure/plain/atom03.xml')
- );
- $entry = $feed->current();
- $expected = new stdClass();
- $expected->url = 'http://www.example.org/myaudiofile.mp3';
- $expected->length = '1234';
- $expected->type = 'audio/mpeg';
- $this->assertEquals($expected, $entry->getEnclosure());
- }
- public function testGetsEnclosureFromAtom10()
- {
- $feed = Zend_Feed_Reader::importString(
- file_get_contents($this->_feedSamplePath.'/enclosure/plain/atom10.xml')
- );
- $entry = $feed->current();
- $expected = new stdClass();
- $expected->url = 'http://www.example.org/myaudiofile.mp3';
- $expected->length = '1234';
- $expected->type = 'audio/mpeg';
- $this->assertEquals($expected, $entry->getEnclosure());
- }
- /**
- * Get Content (Unencoded Text)
- */
- public function testGetsContentFromAtom03()
- {
- $feed = Zend_Feed_Reader::importString(
- file_get_contents($this->_feedSamplePath . '/content/plain/atom03.xml')
- );
- $entry = $feed->current();
- $this->assertEquals('Entry Content', $entry->getContent());
- }
- /**
- * TEXT
- * @group ZFRATOMCONTENT
- */
- public function testGetsContentFromAtom10()
- {
- $feed = Zend_Feed_Reader::importString(
- file_get_contents($this->_feedSamplePath . '/content/plain/atom10.xml')
- );
- $entry = $feed->current();
- $this->assertEquals('Entry Content &', $entry->getContent());
- }
-
- /**
- * HTML Escaped
- * @group ZFRATOMCONTENT
- */
- public function testGetsContentFromAtom10Html()
- {
- $feed = Zend_Feed_Reader::importString(
- file_get_contents($this->_feedSamplePath . '/content/plain/atom10_Html.xml')
- );
- $entry = $feed->current();
- $this->assertEquals('<p>Entry Content &</p>', $entry->getContent());
- }
-
- /**
- * HTML CDATA Escaped
- * @group ZFRATOMCONTENT
- */
- public function testGetsContentFromAtom10HtmlCdata()
- {
- $feed = Zend_Feed_Reader::importString(
- file_get_contents($this->_feedSamplePath . '/content/plain/atom10_HtmlCdata.xml')
- );
- $entry = $feed->current();
- $this->assertEquals('<p>Entry Content &</p>', $entry->getContent());
- }
-
- /**
- * XHTML
- * @group ZFRATOMCONTENT
- */
- public function testGetsContentFromAtom10XhtmlNamespaced()
- {
- $feed = Zend_Feed_Reader::importString(
- file_get_contents($this->_feedSamplePath . '/content/plain/atom10_Xhtml.xml')
- );
- $entry = $feed->current();
- $this->assertEquals('<p class="x:"><em>Entry Content &x:</em></p>', $entry->getContent());
- }
- /**
- * Get Link (Unencoded Text)
- */
- public function testGetsLinkFromAtom03()
- {
- $feed = Zend_Feed_Reader::importString(
- file_get_contents($this->_feedSamplePath . '/link/plain/atom03.xml')
- );
- $entry = $feed->current();
- $this->assertEquals('http://www.example.com/entry', $entry->getLink());
- }
- public function testGetsLinkFromAtom10()
- {
- $feed = Zend_Feed_Reader::importString(
- file_get_contents($this->_feedSamplePath . '/link/plain/atom10.xml')
- );
- $entry = $feed->current();
- $this->assertEquals('http://www.example.com/entry', $entry->getLink());
- }
- public function testGetsLinkFromAtom10_WithNoRelAttribute()
- {
- $feed = Zend_Feed_Reader::importString(
- file_get_contents($this->_feedSamplePath . '/link/plain/atom10-norel.xml')
- );
- $entry = $feed->current();
- $this->assertEquals('http://www.example.com/entry', $entry->getLink());
- }
- public function testGetsLinkFromAtom10_WithRelativeUrl()
- {
- $feed = Zend_Feed_Reader::importString(
- file_get_contents($this->_feedSamplePath . '/link/plain/atom10-relative.xml')
- );
- $entry = $feed->current();
- $this->assertEquals('http://www.example.com/entry', $entry->getLink());
- }
- /**
- * Get Base Uri
- */
- public function testGetsBaseUriFromAtom10_FromFeedElement()
- {
- $feed = Zend_Feed_Reader::importString(
- file_get_contents($this->_feedSamplePath . '/baseurl/plain/atom10-feedlevel.xml')
- );
- $entry = $feed->current();
- $this->assertEquals('http://www.example.com', $entry->getBaseUrl());
- }
- public function testGetsBaseUriFromAtom10_FromEntryElement()
- {
- $feed = Zend_Feed_Reader::importString(
- file_get_contents($this->_feedSamplePath . '/baseurl/plain/atom10-entrylevel.xml')
- );
- $entry = $feed->current();
- $this->assertEquals('http://www.example.com/', $entry->getBaseUrl());
- }
- /**
- * Get Comment HTML Link
- */
- public function testGetsCommentLinkFromAtom03()
- {
- $feed = Zend_Feed_Reader::importString(
- file_get_contents($this->_feedSamplePath . '/commentlink/plain/atom03.xml')
- );
- $entry = $feed->current();
- $this->assertEquals('http://www.example.com/entry/comments', $entry->getCommentLink());
- }
- public function testGetsCommentLinkFromAtom10()
- {
- $feed = Zend_Feed_Reader::importString(
- file_get_contents($this->_feedSamplePath . '/commentlink/plain/atom10.xml')
- );
- $entry = $feed->current();
- $this->assertEquals('http://www.example.com/entry/comments', $entry->getCommentLink());
- }
- public function testGetsCommentLinkFromAtom10_RelativeLinks()
- {
- $feed = Zend_Feed_Reader::importString(
- file_get_contents($this->_feedSamplePath . '/commentlink/plain/atom10-relative.xml')
- );
- $entry = $feed->current();
- $this->assertEquals('http://www.example.com/entry/comments', $entry->getCommentLink());
- }
-
- /**
- * Get category data
- */
-
- // Atom 1.0 (Atom 0.3 never supported categories except via Atom 1.0/Dublin Core extensions)
-
- public function testGetsCategoriesFromAtom10()
- {
- $feed = Zend_Feed_Reader::importString(
- file_get_contents($this->_feedSamplePath.'/category/plain/atom10.xml')
- );
- $entry = $feed->current();
- $this->assertEquals($this->_expectedCats, (array) $entry->getCategories());
- $this->assertEquals(array('topic1','Cat & Dog'), array_values($entry->getCategories()->getValues()));
- }
-
- public function testGetsCategoriesFromAtom03_Atom10Extension()
- {
- $feed = Zend_Feed_Reader::importString(
- file_get_contents($this->_feedSamplePath.'/category/plain/atom03.xml')
- );
- $entry = $feed->current();
- $this->assertEquals($this->_expectedCats, (array) $entry->getCategories());
- $this->assertEquals(array('topic1','Cat & Dog'), array_values($entry->getCategories()->getValues()));
- }
-
- // DC 1.0/1.1 for Atom 0.3
-
- public function testGetsCategoriesFromAtom03_Dc10()
- {
- $feed = Zend_Feed_Reader::importString(
- file_get_contents($this->_feedSamplePath.'/category/plain/dc10/atom03.xml')
- );
- $entry = $feed->current();
- $this->assertEquals($this->_expectedCatsDc, (array) $entry->getCategories());
- $this->assertEquals(array('topic1','topic2'), array_values($entry->getCategories()->getValues()));
- }
-
- public function testGetsCategoriesFromAtom03_Dc11()
- {
- $feed = Zend_Feed_Reader::importString(
- file_get_contents($this->_feedSamplePath.'/category/plain/dc11/atom03.xml')
- );
- $entry = $feed->current();
- $this->assertEquals($this->_expectedCatsDc, (array) $entry->getCategories());
- $this->assertEquals(array('topic1','topic2'), array_values($entry->getCategories()->getValues()));
- }
-
- // No Categories In Entry
-
- public function testGetsCategoriesFromAtom10_None()
- {
- $feed = Zend_Feed_Reader::importString(
- file_get_contents($this->_feedSamplePath.'/category/plain/none/atom10.xml')
- );
- $entry = $feed->current();
- $this->assertEquals(array(), (array) $entry->getCategories());
- $this->assertEquals(array(), array_values($entry->getCategories()->getValues()));
- }
-
- public function testGetsCategoriesFromAtom03_None()
- {
- $feed = Zend_Feed_Reader::importString(
- file_get_contents($this->_feedSamplePath.'/category/plain/none/atom03.xml')
- );
- $entry = $feed->current();
- $this->assertEquals(array(), (array) $entry->getCategories());
- $this->assertEquals(array(), array_values($entry->getCategories()->getValues()));
- }
-
- }
|