public function testCanDetectHubs() { $feed = \Zend\Feed\Reader\Reader::importFile(__DIR__ . '/_files/rss20.xml'); $this->assertEquals(array( 'http://www.example.com/hub', 'http://www.example.com/hub2' ), PubSubHubbub\PubSubHubbub::detectHubs($feed)); }
public function setUp() { if (defined('TESTS_Zend_Feed_PubSubHubbub_BASEURI') && \Zend\Uri\Url::check(TESTS_Zend_Feed_PubSubHubbub_BASEURI)) { $this->_baseuri = TESTS_Zend_Feed_PubSubHubbub_BASEURI; if (substr($this->_baseuri, -1) != '/') $this->_baseuri .= '/'; $name = $this->getName(); if (($pos = strpos($name, ' ')) !== false) { $name = substr($name, 0, $pos); } $uri = $this->_baseuri . $name . '.php'; $this->_adapter = new $this->_config['adapter']; $this->_client = new \Zend\Http\Client($uri, $this->_config); $this->_client->setAdapter($this->_adapter); \Zend\Feed\PubSubHubbub\PubSubHubbub::setHttpClient($this->_client); $this->_subscriber = new \Zend\Feed\PubSubHubbub\Subscriber\Subscriber; $this->_storage = $this->_getCleanMock('Zend_Feed_PubSubHubbub_Entity_TopicSubscription'); $this->_subscriber->setStorage($this->_storage); } else { // Skip tests $this->markTestSkipped("Zend_Feed_PubSubHubbub_Subscriber dynamic tests' . ' are not enabled in TestConfiguration.php"); } }
public function setUp() { $client = new HttpClient(); PubSubHubbub::setHttpClient($client); $this->subscriber = new Subscriber(); $this->adapter = $this->_getCleanMock('\\Zend\\Db\\Adapter\\Adapter'); $this->tableGateway = $this->_getCleanMock('\\Zend\\Db\\TableGateway\\TableGateway'); $this->tableGateway->expects($this->any())->method('getAdapter')->will($this->returnValue($this->adapter)); }
public function setUp() { $client = new \Zend\Http\Client(); PubSubHubbub\PubSubHubbub::setHttpClient($client); $this->_subscriber = new \Zend\Feed\PubSubHubbub\Subscriber(); $this->_adapter = $this->_getCleanMock('\\Zend\\Db\\Adapter\\AbstractAdapter'); $this->_tableGateway = $this->_getCleanMock('\\Zend\\Db\\Table\\AbstractTable'); $this->_tableGateway->expects($this->any())->method('getAdapter')->will($this->returnValue($this->_adapter)); }
public function setUp() { $this->baseuri = constant('TESTS_ZEND_FEED_PUBSUBHUBBUB_BASEURI'); if ($this->baseuri) { if (substr($this->baseuri, -1) != '/') { $this->baseuri .= '/'; } $name = $this->getName(); if (($pos = strpos($name, ' ')) !== false) { $name = substr($name, 0, $pos); } $uri = $this->baseuri . $name . '.php'; $this->client = new HttpClient($uri); $this->client->setAdapter('\\Zend\\Http\\Client\\Adapter\\Socket'); PubSubHubbub::setHttpClient($this->client); $this->subscriber = new Subscriber(); $this->storage = $this->_getCleanMock('\\Zend\\Feed\\PubSubHubbub\\Model\\Subscription'); $this->subscriber->setStorage($this->storage); } else { // Skip tests $this->markTestSkipped('Zend\\Feed\\PubSubHubbub\\Subscriber dynamic tests are not enabled in TestConfiguration.php'); } }
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()); }
/** * URL Encode an array of parameters * * @param array $params * @return array */ protected function _urlEncode(array $params) { $encoded = array(); foreach ($params as $key => $value) { if (is_array($value)) { $ekey = PubSubHubbub::urlencode($key); $encoded[$ekey] = array(); foreach ($value as $duplicateKey) { $encoded[$ekey][] = PubSubHubbub::urlencode($duplicateKey); } } else { $encoded[PubSubHubbub::urlencode($key)] = PubSubHubbub::urlencode($value); } } return $encoded; }
/** * Get a basic prepared HTTP client for use * * @return \Zend\HTTP\Client */ protected function _getHttpClient() { $client = PubSubHubbub::getHttpClient(); $client->setMethod(\Zend\HTTP\Client::POST); $client->setConfig(array('useragent' => 'Zend_Feed_Pubsubhubbub_Publisher/' . \Zend\Version::VERSION)); $params = array(); $params[] = 'hub.mode=publish'; $topics = $this->getUpdatedTopicUrls(); if (empty($topics)) { throw new Exception('No updated topic URLs' . ' have been set'); } foreach ($topics as $topicUrl) { $params[] = 'hub.url=' . urlencode($topicUrl); } $optParams = $this->getParameters(); foreach ($optParams as $name => $value) { $params[] = urlencode($name) . '=' . urlencode($value); } $paramString = implode('&', $params); $client->setRawData($paramString); return $client; }
/** * Get a basic prepared HTTP client for use * * @return \Zend\Http\Client * @throws Exception\RuntimeException */ protected function _getHttpClient() { $client = PubSubHubbub::getHttpClient(); $client->setMethod(HttpRequest::METHOD_POST); $client->setOptions(['useragent' => 'Zend_Feed_Pubsubhubbub_Publisher/' . Version::VERSION]); $params = []; $params[] = 'hub.mode=publish'; $topics = $this->getUpdatedTopicUrls(); if (empty($topics)) { throw new Exception\RuntimeException('No updated topic URLs' . ' have been set'); } foreach ($topics as $topicUrl) { $params[] = 'hub.url=' . urlencode($topicUrl); } $optParams = $this->getParameters(); foreach ($optParams as $name => $value) { $params[] = urlencode($name) . '=' . urlencode($value); } $paramString = implode('&', $params); $client->setRawBody($paramString); return $client; }