| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603 |
- <?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/Writer/Entry.php';
- /**
- * @category Zend
- * @package Zend_Exception
- * @subpackage UnitTests
- * @group Zend_Feed
- * @group Zend_Feed_Writer
- * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- */
- class Zend_Feed_Writer_EntryTest extends PHPUnit_Framework_TestCase
- {
- protected $_feedSamplePath = null;
- public function setup()
- {
- $this->_feedSamplePath = dirname(__FILE__) . '/_files';
- }
- public function testAddsAuthorName()
- {
- $entry = new Zend_Feed_Writer_Entry;
- $entry->addAuthor('Joe');
- $this->assertEquals(array(array('name'=>'Joe')), $entry->getAuthors());
- }
- public function testAddsAuthorEmail()
- {
- $entry = new Zend_Feed_Writer_Entry;
- $entry->addAuthor('Joe', 'joe@example.com');
- $this->assertEquals(array(array('name'=>'Joe', 'email' => 'joe@example.com')), $entry->getAuthors());
- }
- public function testAddsAuthorUri()
- {
- $entry = new Zend_Feed_Writer_Entry;
- $entry->addAuthor('Joe', null, 'http://www.example.com');
- $this->assertEquals(array(array('name'=>'Joe', 'uri' => 'http://www.example.com')), $entry->getAuthors());
- }
- public function testAddAuthorThrowsExceptionOnInvalidName()
- {
- $entry = new Zend_Feed_Writer_Entry;
- try {
- $entry->addAuthor('');
- $this->fail();
- } catch (Zend_Feed_Exception $e) {
- }
- }
- public function testAddAuthorThrowsExceptionOnInvalidEmail()
- {
- $entry = new Zend_Feed_Writer_Entry;
- try {
- $entry->addAuthor('Joe', '');
- $this->fail();
- } catch (Zend_Feed_Exception $e) {
- }
- }
- public function testAddAuthorThrowsExceptionOnInvalidUri()
- {
- $entry = new Zend_Feed_Writer_Entry;
- try {
- $entry->addAuthor('Joe', null, 'notauri');
- $this->fail();
- } catch (Zend_Feed_Exception $e) {
- }
- }
- public function testAddsAuthorNameFromArray()
- {
- $entry = new Zend_Feed_Writer_Entry;
- $entry->addAuthor(array('name'=>'Joe'));
- $this->assertEquals(array(array('name'=>'Joe')), $entry->getAuthors());
- }
- public function testAddsAuthorEmailFromArray()
- {
- $entry = new Zend_Feed_Writer_Entry;
- $entry->addAuthor(array('name'=>'Joe','email'=>'joe@example.com'));
- $this->assertEquals(array(array('name'=>'Joe', 'email' => 'joe@example.com')), $entry->getAuthors());
- }
- public function testAddsAuthorUriFromArray()
- {
- $entry = new Zend_Feed_Writer_Entry;
- $entry->addAuthor(array('name'=>'Joe','uri'=>'http://www.example.com'));
- $this->assertEquals(array(array('name'=>'Joe', 'uri' => 'http://www.example.com')), $entry->getAuthors());
- }
- public function testAddAuthorThrowsExceptionOnInvalidNameFromArray()
- {
- $entry = new Zend_Feed_Writer_Entry;
- try {
- $entry->addAuthor(array('name'=>''));
- $this->fail();
- } catch (Zend_Feed_Exception $e) {
- }
- }
- public function testAddAuthorThrowsExceptionOnInvalidEmailFromArray()
- {
- $entry = new Zend_Feed_Writer_Entry;
- try {
- $entry->addAuthor(array('name'=>'Joe','email'=>''));
- $this->fail();
- } catch (Zend_Feed_Exception $e) {
- }
- }
- public function testAddAuthorThrowsExceptionOnInvalidUriFromArray()
- {
- $entry = new Zend_Feed_Writer_Entry;
- try {
- $entry->addAuthor(array('name'=>'Joe','uri'=>'notauri'));
- $this->fail();
- } catch (Zend_Feed_Exception $e) {
- }
- }
- public function testAddAuthorThrowsExceptionIfNameOmittedFromArray()
- {
- $entry = new Zend_Feed_Writer_Entry;
- try {
- $entry->addAuthor(array('uri'=>'notauri'));
- $this->fail();
- } catch (Zend_Feed_Exception $e) {
- }
- }
- public function testAddsAuthorsFromArrayOfAuthors()
- {
- $entry = new Zend_Feed_Writer_Entry;
- $entry->addAuthors(array(
- array('name'=>'Joe','uri'=>'http://www.example.com'),
- array('name'=>'Jane','uri'=>'http://www.example.com')
- ));
- $expected = array(
- array('name'=>'Joe','uri'=>'http://www.example.com'),
- array('name'=>'Jane','uri'=>'http://www.example.com')
- );
- $this->assertEquals($expected, $entry->getAuthors());
- }
- public function testAddsEnclosure()
- {
- $entry = new Zend_Feed_Writer_Entry;
- $entry->setEnclosure(array(
- 'type' => 'audio/mpeg',
- 'uri' => 'http://example.com/audio.mp3',
- 'length' => '1337'
- ));
- $expected = array(
- 'type' => 'audio/mpeg',
- 'uri' => 'http://example.com/audio.mp3',
- 'length' => '1337'
- );
- $this->assertEquals($expected, $entry->getEnclosure());
- }
- /**
- * @expectedException Zend_Feed_Exception
- */
- public function testAddsEnclosureThrowsExceptionOnMissingUri()
- {
- $entry = new Zend_Feed_Writer_Entry;
- $entry->setEnclosure(array(
- 'type' => 'audio/mpeg',
- 'length' => '1337'
- ));
- }
- /**
- * @expectedException Zend_Feed_Exception
- */
- public function testAddsEnclosureThrowsExceptionWhenUriIsInvalid()
- {
- $entry = new Zend_Feed_Writer_Entry;
- $entry->setEnclosure(array(
- 'type' => 'audio/mpeg',
- 'uri' => 'http://',
- 'length' => '1337'
- ));
- }
- public function testSetsCopyright()
- {
- $entry = new Zend_Feed_Writer_Entry;
- $entry->setCopyright('Copyright (c) 2009 Paddy Brady');
- $this->assertEquals('Copyright (c) 2009 Paddy Brady', $entry->getCopyright());
- }
- public function testSetCopyrightThrowsExceptionOnInvalidParam()
- {
- $entry = new Zend_Feed_Writer_Entry;
- try {
- $entry->setCopyright('');
- $this->fail();
- } catch (Zend_Feed_Exception $e) {
- }
- }
- public function testSetsContent()
- {
- $entry = new Zend_Feed_Writer_Entry;
- $entry->setContent('I\'m content.');
- $this->assertEquals("I'm content.", $entry->getContent());
- }
- public function testSetContentThrowsExceptionOnInvalidParam()
- {
- $entry = new Zend_Feed_Writer_Entry;
- try {
- $entry->setContent('');
- $this->fail();
- } catch (Zend_Feed_Exception $e) {
- }
- }
- public function testSetDateCreatedDefaultsToCurrentTime()
- {
- $entry = new Zend_Feed_Writer_Entry;
- $entry->setDateCreated();
- $dateNow = new Zend_Date;
- $this->assertTrue($dateNow->isLater($entry->getDateCreated()) || $dateNow->equals($entry->getDateCreated()));
- }
- public function testSetDateCreatedUsesGivenUnixTimestamp()
- {
- $entry = new Zend_Feed_Writer_Entry;
- $entry->setDateCreated(1234567890);
- $myDate = new Zend_Date('1234567890', Zend_Date::TIMESTAMP);
- $this->assertTrue($myDate->equals($entry->getDateCreated()));
- }
- /**
- * @group ZF-12070
- */
- public function testSetDateCreatedUsesGivenUnixTimestampWhenItIsLessThanTenDigits()
- {
- $entry = new Zend_Feed_Writer_Entry;
- $entry->setDateCreated(123456789);
- $myDate = new Zend_Date('123456789', Zend_Date::TIMESTAMP);
- $this->assertTrue($myDate->equals($entry->getDateCreated()));
- }
- /**
- * @group ZF-11610
- */
- public function testSetDateCreatedUsesGivenUnixTimestampWhenItIsAVerySmallInteger()
- {
- $entry = new Zend_Feed_Writer_Entry;
- $entry->setDateCreated(123);
- $myDate = new Zend_Date('123', Zend_Date::TIMESTAMP);
- $this->assertTrue($myDate->equals($entry->getDateCreated()));
- }
- public function testSetDateCreatedUsesZendDateObject()
- {
- $entry = new Zend_Feed_Writer_Entry;
- $entry->setDateCreated(new Zend_Date('1234567890', Zend_Date::TIMESTAMP));
- $myDate = new Zend_Date('1234567890', Zend_Date::TIMESTAMP);
- $this->assertTrue($myDate->equals($entry->getDateCreated()));
- }
- public function testSetDateModifiedDefaultsToCurrentTime()
- {
- $entry = new Zend_Feed_Writer_Entry;
- $entry->setDateModified();
- $dateNow = new Zend_Date;
- $this->assertTrue($dateNow->isLater($entry->getDateModified()) || $dateNow->equals($entry->getDateModified()));
- }
- public function testSetDateModifiedUsesGivenUnixTimestamp()
- {
- $entry = new Zend_Feed_Writer_Entry;
- $entry->setDateModified(1234567890);
- $myDate = new Zend_Date('1234567890', Zend_Date::TIMESTAMP);
- $this->assertTrue($myDate->equals($entry->getDateModified()));
- }
- /**
- * @group ZF-12070
- */
- public function testSetDateModifiedUsesGivenUnixTimestampWhenItIsLessThanTenDigits()
- {
- $entry = new Zend_Feed_Writer_Entry;
- $entry->setDateModified(123456789);
- $myDate = new Zend_Date('123456789', Zend_Date::TIMESTAMP);
- $this->assertTrue($myDate->equals($entry->getDateModified()));
- }
- /**
- * @group ZF-11610
- */
- public function testSetDateModifiedUsesGivenUnixTimestampWhenItIsAVerySmallInteger()
- {
- $entry = new Zend_Feed_Writer_Entry;
- $entry->setDateModified(123);
- $myDate = new Zend_Date('123', Zend_Date::TIMESTAMP);
- $this->assertTrue($myDate->equals($entry->getDateModified()));
- }
- public function testSetDateModifiedUsesZendDateObject()
- {
- $entry = new Zend_Feed_Writer_Entry;
- $entry->setDateModified(new Zend_Date('1234567890', Zend_Date::TIMESTAMP));
- $myDate = new Zend_Date('1234567890', Zend_Date::TIMESTAMP);
- $this->assertTrue($myDate->equals($entry->getDateModified()));
- }
- public function testSetDateCreatedThrowsExceptionOnInvalidParameter()
- {
- $entry = new Zend_Feed_Writer_Entry;
- try {
- $entry->setDateCreated('abc');
- $this->fail();
- } catch (Zend_Feed_Exception $e) {
- }
- }
- public function testSetDateModifiedThrowsExceptionOnInvalidParameter()
- {
- $entry = new Zend_Feed_Writer_Entry;
- try {
- $entry->setDateModified('abc');
- $this->fail();
- } catch (Zend_Feed_Exception $e) {
- }
- }
- public function testGetDateCreatedReturnsNullIfDateNotSet()
- {
- $entry = new Zend_Feed_Writer_Entry;
- $this->assertTrue(is_null($entry->getDateCreated()));
- }
- public function testGetDateModifiedReturnsNullIfDateNotSet()
- {
- $entry = new Zend_Feed_Writer_Entry;
- $this->assertTrue(is_null($entry->getDateModified()));
- }
- public function testGetCopyrightReturnsNullIfDateNotSet()
- {
- $entry = new Zend_Feed_Writer_Entry;
- $this->assertTrue(is_null($entry->getCopyright()));
- }
- public function testGetContentReturnsNullIfDateNotSet()
- {
- $entry = new Zend_Feed_Writer_Entry;
- $this->assertTrue(is_null($entry->getContent()));
- }
- public function testSetsDescription()
- {
- $entry = new Zend_Feed_Writer_Entry;
- $entry->setDescription('abc');
- $this->assertEquals('abc', $entry->getDescription());
- }
- public function testSetDescriptionThrowsExceptionOnInvalidParameter()
- {
- $entry = new Zend_Feed_Writer_Entry;
- try {
- $entry->setDescription('');
- $this->fail();
- } catch (Zend_Feed_Exception $e) {
- }
- }
- public function testGetDescriptionReturnsNullIfDateNotSet()
- {
- $entry = new Zend_Feed_Writer_Entry;
- $this->assertTrue(is_null($entry->getDescription()));
- }
- public function testSetsId()
- {
- $entry = new Zend_Feed_Writer_Entry;
- $entry->setId('http://www.example.com/id');
- $this->assertEquals('http://www.example.com/id', $entry->getId());
- }
- public function testSetIdThrowsExceptionOnInvalidParameter()
- {
- $entry = new Zend_Feed_Writer_Entry;
- try {
- $entry->setId('');
- $this->fail();
- } catch (Zend_Feed_Exception $e) {
- }
- }
- public function testGetIdReturnsNullIfNotSet()
- {
- $entry = new Zend_Feed_Writer_Entry;
- $this->assertTrue(is_null($entry->getId()));
- }
- public function testSetsLink()
- {
- $entry = new Zend_Feed_Writer_Entry;
- $entry->setLink('http://www.example.com/id');
- $this->assertEquals('http://www.example.com/id', $entry->getLink());
- }
- public function testSetLinkThrowsExceptionOnEmptyString()
- {
- $entry = new Zend_Feed_Writer_Entry;
- try {
- $entry->setLink('');
- $this->fail();
- } catch (Zend_Feed_Exception $e) {
- }
- }
- public function testSetLinkThrowsExceptionOnInvalidUri()
- {
- $entry = new Zend_Feed_Writer_Entry;
- try {
- $entry->setLink('http://');
- $this->fail();
- } catch (Zend_Feed_Exception $e) {
- }
- }
- public function testGetLinkReturnsNullIfNotSet()
- {
- $entry = new Zend_Feed_Writer_Entry;
- $this->assertTrue(is_null($entry->getLink()));
- }
- public function testSetsCommentLink()
- {
- $entry = new Zend_Feed_Writer_Entry;
- $entry->setCommentLink('http://www.example.com/id/comments');
- $this->assertEquals('http://www.example.com/id/comments', $entry->getCommentLink());
- }
- public function testSetCommentLinkThrowsExceptionOnEmptyString()
- {
- $entry = new Zend_Feed_Writer_Entry;
- try {
- $entry->setCommentLink('');
- $this->fail();
- } catch (Zend_Feed_Exception $e) {
- }
- }
- public function testSetCommentLinkThrowsExceptionOnInvalidUri()
- {
- $entry = new Zend_Feed_Writer_Entry;
- try {
- $entry->setCommentLink('http://');
- $this->fail();
- } catch (Zend_Feed_Exception $e) {
- }
- }
- public function testGetCommentLinkReturnsNullIfDateNotSet()
- {
- $entry = new Zend_Feed_Writer_Entry;
- $this->assertTrue(is_null($entry->getCommentLink()));
- }
- public function testSetsCommentFeedLink()
- {
- $entry = new Zend_Feed_Writer_Entry;
- $entry->setCommentFeedLink(array('uri'=>'http://www.example.com/id/comments', 'type'=>'rdf'));
- $this->assertEquals(array(array('uri'=>'http://www.example.com/id/comments', 'type'=>'rdf')), $entry->getCommentFeedLinks());
- }
- public function testSetCommentFeedLinkThrowsExceptionOnEmptyString()
- {
- $entry = new Zend_Feed_Writer_Entry;
- try {
- $entry->setCommentFeedLink(array('uri'=>'', 'type'=>'rdf'));
- $this->fail();
- } catch (Zend_Feed_Exception $e) {
- }
- }
- public function testSetCommentFeedLinkThrowsExceptionOnInvalidUri()
- {
- $entry = new Zend_Feed_Writer_Entry;
- try {
- $entry->setCommentFeedLink(array('uri'=>'http://', 'type'=>'rdf'));
- $this->fail();
- } catch (Zend_Feed_Exception $e) {
- }
- }
- public function testSetCommentFeedLinkThrowsExceptionOnInvalidType()
- {
- $entry = new Zend_Feed_Writer_Entry;
- try {
- $entry->setCommentFeedLink(array('uri'=>'http://www.example.com/id/comments', 'type'=>'foo'));
- $this->fail();
- } catch (Zend_Feed_Exception $e) {
- }
- }
- public function testGetCommentFeedLinkReturnsNullIfNoneSet()
- {
- $entry = new Zend_Feed_Writer_Entry;
- $this->assertTrue(is_null($entry->getCommentFeedLinks()));
- }
- public function testSetsTitle()
- {
- $entry = new Zend_Feed_Writer_Entry;
- $entry->setTitle('abc');
- $this->assertEquals('abc', $entry->getTitle());
- }
- public function testSetTitleThrowsExceptionOnInvalidParameter()
- {
- $entry = new Zend_Feed_Writer_Entry;
- try {
- $entry->setTitle('');
- $this->fail();
- } catch (Zend_Feed_Exception $e) {
- }
- }
- public function testGetTitleReturnsNullIfDateNotSet()
- {
- $entry = new Zend_Feed_Writer_Entry;
- $this->assertTrue(is_null($entry->getTitle()));
- }
- public function testSetsCommentCount()
- {
- $entry = new Zend_Feed_Writer_Entry;
- $entry->setCommentCount('10');
- $this->assertEquals(10, $entry->getCommentCount());
- }
-
- /**
- * @group ZF-11150
- */
- public function testSetCommentCountAcceptsZero()
- {
- $entry = new Zend_Feed_Writer_Entry();
- $entry->setCommentCount(0);
- $this->assertEquals(0, $entry->getCommentCount());
- }
- public function testSetCommentCountThrowsExceptionOnInvalidEmptyParameter()
- {
- $entry = new Zend_Feed_Writer_Entry;
- try {
- $entry->setCommentCount('');
- $this->fail();
- } catch (Zend_Feed_Exception $e) {
- }
- }
- public function testSetCommentCountThrowsExceptionOnInvalidNonIntegerParameter()
- {
- $entry = new Zend_Feed_Writer_Entry;
- try {
- $entry->setCommentCount('a');
- $this->fail();
- } catch (Zend_Feed_Exception $e) {
- }
- }
- public function testGetCommentCountReturnsNullIfDateNotSet()
- {
- $entry = new Zend_Feed_Writer_Entry;
- $this->assertTrue(is_null($entry->getCommentCount()));
- }
- }
|