Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Zend\Feed Added unittests for more code coverage #2349

Merged
merged 2 commits into from
Sep 13, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions library/Zend/Feed/Writer/Feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Feed extends AbstractFeed implements Iterator, Countable
protected $entriesKey = 0;

/**
* Creates a new Zend_Feed_Writer_Entry data container for use. This is NOT
* Creates a new Zend\Feed\Writer\Entry data container for use. This is NOT
* added to the current feed automatically, but is necessary to create a
* container with some initial values preset based on the current feed data.
*
Expand Down Expand Up @@ -66,7 +66,7 @@ public function addTombstone(Deleted $deleted)
}

/**
* Creates a new Zend_Feed_Writer_Deleted data container for use. This is NOT
* Creates a new Zend\Feed\Writer\Deleted data container for use. This is NOT
* added to the current feed automatically, but is necessary to create a
* container with some initial values preset based on the current feed data.
*
Expand Down Expand Up @@ -102,10 +102,10 @@ public function addEntry(Entry $entry)
*/
public function removeEntry($index)
{
if (isset($this->entries[$index])) {
unset($this->entries[$index]);
if (!isset($this->entries[$index])) {
throw new Exception\InvalidArgumentException('Undefined index: ' . $index . '. Entry does not exist.');
}
throw new Exception\InvalidArgumentException('Undefined index: ' . $index . '. Entry does not exist.');
unset($this->entries[$index]);
}

/**
Expand Down
3 changes: 0 additions & 3 deletions library/Zend/Feed/Writer/Renderer/Feed/Rss.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ public function __construct (Writer\Feed $container)
*/
public function render()
{
if (!$this->container->getEncoding()) {
$this->container->setEncoding('UTF-8');
}
$this->dom = new DOMDocument('1.0', $this->container->getEncoding());
$this->dom->formatOutput = true;
$this->dom->substituteEntities = false;
Expand Down
124 changes: 62 additions & 62 deletions tests/ZendTest/Feed/PubSubHubbub/PublisherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
class PublisherTest extends \PHPUnit_Framework_TestCase
{
/** @var Publisher */
protected $_publisher = null;
protected $publisher = null;

public function setUp()
{
$client = new HttpClient;
PubSubHubbub::setHttpClient($client);
$this->_publisher = new Publisher;
$this->publisher = new Publisher;
}

public function getClientSuccess()
Expand All @@ -58,206 +58,206 @@ public function getClientFail()

public function testAddsHubServerUrl()
{
$this->_publisher->addHubUrl('http://www.example.com/hub');
$this->assertEquals(array('http://www.example.com/hub'), $this->_publisher->getHubUrls());
$this->publisher->addHubUrl('http://www.example.com/hub');
$this->assertEquals(array('http://www.example.com/hub'), $this->publisher->getHubUrls());
}

public function testAddsHubServerUrlsFromArray()
{
$this->_publisher->addHubUrls(array(
$this->publisher->addHubUrls(array(
'http://www.example.com/hub', 'http://www.example.com/hub2'
));
$this->assertEquals(array(
'http://www.example.com/hub', 'http://www.example.com/hub2'
), $this->_publisher->getHubUrls());
), $this->publisher->getHubUrls());
}

public function testAddsHubServerUrlsFromArrayUsingSetConfig()
{
$this->_publisher->setOptions(array('hubUrls' => array(
$this->publisher->setOptions(array('hubUrls' => array(
'http://www.example.com/hub', 'http://www.example.com/hub2'
)));
$this->assertEquals(array(
'http://www.example.com/hub', 'http://www.example.com/hub2'
), $this->_publisher->getHubUrls());
), $this->publisher->getHubUrls());
}

public function testRemovesHubServerUrl()
{
$this->_publisher->addHubUrls(array(
$this->publisher->addHubUrls(array(
'http://www.example.com/hub', 'http://www.example.com/hub2'
));
$this->_publisher->removeHubUrl('http://www.example.com/hub');
$this->publisher->removeHubUrl('http://www.example.com/hub');
$this->assertEquals(array(
1 => 'http://www.example.com/hub2'
), $this->_publisher->getHubUrls());
), $this->publisher->getHubUrls());
}

public function testRetrievesUniqueHubServerUrlsOnly()
{
$this->_publisher->addHubUrls(array(
$this->publisher->addHubUrls(array(
'http://www.example.com/hub', 'http://www.example.com/hub2',
'http://www.example.com/hub'
));
$this->assertEquals(array(
'http://www.example.com/hub', 'http://www.example.com/hub2'
), $this->_publisher->getHubUrls());
), $this->publisher->getHubUrls());
}

public function testThrowsExceptionOnSettingEmptyHubServerUrl()
{
$this->setExpectedException('Zend\Feed\PubSubHubbub\Exception\ExceptionInterface');
$this->_publisher->addHubUrl('');
$this->publisher->addHubUrl('');
}


public function testThrowsExceptionOnSettingNonStringHubServerUrl()
{
$this->setExpectedException('Zend\Feed\PubSubHubbub\Exception\ExceptionInterface');
$this->_publisher->addHubUrl(123);
$this->publisher->addHubUrl(123);
}


public function testThrowsExceptionOnSettingInvalidHubServerUrl()
{
$this->setExpectedException('Zend\Feed\PubSubHubbub\Exception\ExceptionInterface');
$this->_publisher->addHubUrl('http://');
$this->publisher->addHubUrl('http://');
}

public function testAddsUpdatedTopicUrl()
{
$this->_publisher->addUpdatedTopicUrl('http://www.example.com/topic');
$this->assertEquals(array('http://www.example.com/topic'), $this->_publisher->getUpdatedTopicUrls());
$this->publisher->addUpdatedTopicUrl('http://www.example.com/topic');
$this->assertEquals(array('http://www.example.com/topic'), $this->publisher->getUpdatedTopicUrls());
}

public function testAddsUpdatedTopicUrlsFromArray()
{
$this->_publisher->addUpdatedTopicUrls(array(
$this->publisher->addUpdatedTopicUrls(array(
'http://www.example.com/topic', 'http://www.example.com/topic2'
));
$this->assertEquals(array(
'http://www.example.com/topic', 'http://www.example.com/topic2'
), $this->_publisher->getUpdatedTopicUrls());
), $this->publisher->getUpdatedTopicUrls());
}

public function testAddsUpdatedTopicUrlsFromArrayUsingSetConfig()
{
$this->_publisher->setOptions(array('updatedTopicUrls' => array(
$this->publisher->setOptions(array('updatedTopicUrls' => array(
'http://www.example.com/topic', 'http://www.example.com/topic2'
)));
$this->assertEquals(array(
'http://www.example.com/topic', 'http://www.example.com/topic2'
), $this->_publisher->getUpdatedTopicUrls());
), $this->publisher->getUpdatedTopicUrls());
}

public function testRemovesUpdatedTopicUrl()
{
$this->_publisher->addUpdatedTopicUrls(array(
$this->publisher->addUpdatedTopicUrls(array(
'http://www.example.com/topic', 'http://www.example.com/topic2'
));
$this->_publisher->removeUpdatedTopicUrl('http://www.example.com/topic');
$this->publisher->removeUpdatedTopicUrl('http://www.example.com/topic');
$this->assertEquals(array(
1 => 'http://www.example.com/topic2'
), $this->_publisher->getUpdatedTopicUrls());
), $this->publisher->getUpdatedTopicUrls());
}

public function testRetrievesUniqueUpdatedTopicUrlsOnly()
{
$this->_publisher->addUpdatedTopicUrls(array(
$this->publisher->addUpdatedTopicUrls(array(
'http://www.example.com/topic', 'http://www.example.com/topic2',
'http://www.example.com/topic'
));
$this->assertEquals(array(
'http://www.example.com/topic', 'http://www.example.com/topic2'
), $this->_publisher->getUpdatedTopicUrls());
), $this->publisher->getUpdatedTopicUrls());
}

public function testThrowsExceptionOnSettingEmptyUpdatedTopicUrl()
{
$this->setExpectedException('Zend\Feed\PubSubHubbub\Exception\ExceptionInterface');
$this->_publisher->addUpdatedTopicUrl('');
$this->publisher->addUpdatedTopicUrl('');
}


public function testThrowsExceptionOnSettingNonStringUpdatedTopicUrl()
{
$this->setExpectedException('Zend\Feed\PubSubHubbub\Exception\ExceptionInterface');
$this->_publisher->addUpdatedTopicUrl(123);
$this->publisher->addUpdatedTopicUrl(123);
}


public function testThrowsExceptionOnSettingInvalidUpdatedTopicUrl()
{
$this->setExpectedException('Zend\Feed\PubSubHubbub\Exception\ExceptionInterface');
$this->_publisher->addUpdatedTopicUrl('http://');
$this->publisher->addUpdatedTopicUrl('http://');
}

public function testAddsParameter()
{
$this->_publisher->setParameter('foo', 'bar');
$this->assertEquals(array('foo'=> 'bar'), $this->_publisher->getParameters());
$this->publisher->setParameter('foo', 'bar');
$this->assertEquals(array('foo'=> 'bar'), $this->publisher->getParameters());
}

public function testAddsParametersFromArray()
{
$this->_publisher->setParameters(array(
$this->publisher->setParameters(array(
'foo' => 'bar', 'boo' => 'baz'
));
$this->assertEquals(array(
'foo' => 'bar', 'boo' => 'baz'
), $this->_publisher->getParameters());
), $this->publisher->getParameters());
}

public function testAddsParametersFromArrayInSingleMethod()
{
$this->_publisher->setParameter(array(
$this->publisher->setParameter(array(
'foo' => 'bar', 'boo' => 'baz'
));
$this->assertEquals(array(
'foo' => 'bar', 'boo' => 'baz'
), $this->_publisher->getParameters());
), $this->publisher->getParameters());
}

public function testAddsParametersFromArrayUsingSetConfig()
{
$this->_publisher->setOptions(array('parameters' => array(
$this->publisher->setOptions(array('parameters' => array(
'foo' => 'bar', 'boo' => 'baz'
)));
$this->assertEquals(array(
'foo' => 'bar', 'boo' => 'baz'
), $this->_publisher->getParameters());
), $this->publisher->getParameters());
}

public function testRemovesParameter()
{
$this->_publisher->setParameters(array(
$this->publisher->setParameters(array(
'foo' => 'bar', 'boo' => 'baz'
));
$this->_publisher->removeParameter('boo');
$this->publisher->removeParameter('boo');
$this->assertEquals(array(
'foo' => 'bar'
), $this->_publisher->getParameters());
), $this->publisher->getParameters());
}

public function testRemovesParameterIfSetToNull()
{
$this->_publisher->setParameters(array(
$this->publisher->setParameters(array(
'foo' => 'bar', 'boo' => 'baz'
));
$this->_publisher->setParameter('boo', null);
$this->publisher->setParameter('boo', null);
$this->assertEquals(array(
'foo' => 'bar'
), $this->_publisher->getParameters());
), $this->publisher->getParameters());
}

public function testNotifiesHubWithCorrectParameters()
{
PubSubHubbub::setHttpClient($this->getClientSuccess());
$client = PubSubHubbub::getHttpClient();
$this->_publisher->addHubUrl('http://www.example.com/hub');
$this->_publisher->addUpdatedTopicUrl('http://www.example.com/topic');
$this->_publisher->setParameter('foo', 'bar');
$this->_publisher->notifyAll();
$this->publisher->addHubUrl('http://www.example.com/hub');
$this->publisher->addUpdatedTopicUrl('http://www.example.com/topic');
$this->publisher->setParameter('foo', 'bar');
$this->publisher->notifyAll();
$this->assertEquals('hub.mode=publish&hub.url=http%3A%2F%2Fwww.example.com%2Ftopic&foo=bar',
$client->getRequest()->getContent());
}
Expand All @@ -266,10 +266,10 @@ public function testNotifiesHubWithCorrectParametersAndMultipleTopics()
{
PubSubHubbub::setHttpClient($this->getClientSuccess());
$client = PubSubHubbub::getHttpClient();
$this->_publisher->addHubUrl('http://www.example.com/hub');
$this->_publisher->addUpdatedTopicUrl('http://www.example.com/topic');
$this->_publisher->addUpdatedTopicUrl('http://www.example.com/topic2');
$this->_publisher->notifyAll();
$this->publisher->addHubUrl('http://www.example.com/hub');
$this->publisher->addUpdatedTopicUrl('http://www.example.com/topic');
$this->publisher->addUpdatedTopicUrl('http://www.example.com/topic2');
$this->publisher->notifyAll();
$this->assertEquals('hub.mode=publish&hub.url=http%3A%2F%2Fwww.example.com%2Ftopic&hub.url=http%3A%2F%2Fwww.example.com%2Ftopic2',
$client->getRequest()->getContent());
}
Expand All @@ -278,22 +278,22 @@ public function testNotifiesHubAndReportsSuccess()
{
PubSubHubbub::setHttpClient($this->getClientSuccess());
$client = PubSubHubbub::getHttpClient();
$this->_publisher->addHubUrl('http://www.example.com/hub');
$this->_publisher->addUpdatedTopicUrl('http://www.example.com/topic');
$this->_publisher->setParameter('foo', 'bar');
$this->_publisher->notifyAll();
$this->assertTrue($this->_publisher->isSuccess());
$this->publisher->addHubUrl('http://www.example.com/hub');
$this->publisher->addUpdatedTopicUrl('http://www.example.com/topic');
$this->publisher->setParameter('foo', 'bar');
$this->publisher->notifyAll();
$this->assertTrue($this->publisher->isSuccess());
}

public function testNotifiesHubAndReportsFail()
{
PubSubHubbub::setHttpClient($this->getClientFail());
$client = PubSubHubbub::getHttpClient();
$this->_publisher->addHubUrl('http://www.example.com/hub');
$this->_publisher->addUpdatedTopicUrl('http://www.example.com/topic');
$this->_publisher->setParameter('foo', 'bar');
$this->_publisher->notifyAll();
$this->assertFalse($this->_publisher->isSuccess());
$this->publisher->addHubUrl('http://www.example.com/hub');
$this->publisher->addUpdatedTopicUrl('http://www.example.com/topic');
$this->publisher->setParameter('foo', 'bar');
$this->publisher->notifyAll();
$this->assertFalse($this->publisher->isSuccess());
}
}

Expand Down
Loading