Skip to content

Commit

Permalink
Merge branch 'hotfix/zend_feed_tests' of https://github.com/robertbas…
Browse files Browse the repository at this point in the history
…ic/zf2 into hotfix/feed-tests
  • Loading branch information
weierophinney committed Mar 5, 2012
2 parents 00bf9e2 + 3a00fd3 commit 2c6b7bc
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 70 deletions.
6 changes: 4 additions & 2 deletions library/Zend/Feed/PubSubHubbub/Model/AbstractModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
*/
namespace Zend\Feed\PubSubHubbub\Model;

use \Zend\Db\TableGateway;

/**
* @uses \Zend\Db\Table\Table
* @uses \Zend\Registry
Expand All @@ -47,12 +49,12 @@ class AbstractModel
* @param \Zend\Db\Table\AbstractTable $tableGateway
* @return void
*/
public function __construct(\Zend\Db\Table\AbstractTable $tableGateway = null)
public function __construct(TableGateway\TableGatewayInterface $tableGateway = null)
{
if ($tableGateway === null) {
$parts = explode('\\', get_class($this));
$table = strtolower(array_pop($parts));
$this->_db = new \Zend\Db\Table\Table($table);
$this->_db = new TableGateway\TableGateway($table);
} else {
$this->_db = $tableGateway;
}
Expand Down
14 changes: 7 additions & 7 deletions library/Zend/Feed/PubSubHubbub/Model/Subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function setSubscription(array $data)
'ID must be set before attempting a save'
);
}
$result = $this->_db->find($data['id']);
$result = $this->_db->select(array('id' => $data['id']));
if ($result && (0 < count($result))) {
$data['created_time'] = $result->current()->created_time;
$now = new Date\Date;
Expand All @@ -65,7 +65,7 @@ public function setSubscription(array $data)
}
$this->_db->update(
$data,
$this->_db->getAdapter()->quoteInto('id = ?', $data['id'])
array('id' => $data['id'])
);
return false;
}
Expand All @@ -86,9 +86,9 @@ public function getSubscription($key)
throw new PubSubHubbub\Exception('Invalid parameter "key"'
.' of "' . $key . '" must be a non-empty string');
}
$result = $this->_db->find($key);
$result = $this->_db->select(array('id' => $key));
if (count($result)) {
return $result->current()->toArray();
return $result->current()->getArrayCopy();
}
return false;
}
Expand All @@ -105,7 +105,7 @@ public function hasSubscription($key)
throw new PubSubHubbub\Exception('Invalid parameter "key"'
.' of "' . $key . '" must be a non-empty string');
}
$result = $this->_db->find($key);
$result = $this->_db->select(array('id' => $key));
if (count($result)) {
return true;
}
Expand All @@ -120,10 +120,10 @@ public function hasSubscription($key)
*/
public function deleteSubscription($key)
{
$result = $this->_db->find($key);
$result = $this->_db->select(array('id' => $key));
if (count($result)) {
$this->_db->delete(
$this->_db->getAdapter()->quoteInto('id = ?', $key)
array('id' => $key)
);
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions library/Zend/Feed/PubSubHubbub/Publisher.php
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ public function getErrors()
protected function _getHttpClient()
{
$client = PubSubHubbub::getHttpClient();
$client->setMethod(\Zend\Http\Client::POST);
$client->setMethod(\Zend\Http\Request::METHOD_POST);
$client->setConfig(array(
'useragent' => 'Zend_Feed_Pubsubhubbub_Publisher/' . \Zend\Version::VERSION,
));
Expand All @@ -403,7 +403,7 @@ protected function _getHttpClient()
$params[] = urlencode($name) . '=' . urlencode($value);
}
$paramString = implode('&', $params);
$client->setRawData($paramString);
$client->setRawBody($paramString);
return $client;
}
}
17 changes: 9 additions & 8 deletions library/Zend/Feed/Reader/FeedSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,34 +65,35 @@ public function addLinks(\DOMNodeList $links, $uri)
continue;
}
if (!isset($this->rss) && $link->getAttribute('type') == 'application/rss+xml') {
$this->rss = $this->_absolutiseUri(trim($link->getAttribute('href')), $uri);
$this->rss = $this->absolutiseUri(trim($link->getAttribute('href')), $uri);
} elseif(!isset($this->atom) && $link->getAttribute('type') == 'application/atom+xml') {
$this->atom = $this->_absolutiseUri(trim($link->getAttribute('href')), $uri);
$this->atom = $this->absolutiseUri(trim($link->getAttribute('href')), $uri);
} elseif(!isset($this->rdf) && $link->getAttribute('type') == 'application/rdf+xml') {
$this->rdf = $this->_absolutiseUri(trim($link->getAttribute('href')), $uri);
$this->rdf = $this->absolutiseUri(trim($link->getAttribute('href')), $uri);
}
$this[] = new self(array(
'rel' => 'alternate',
'type' => $link->getAttribute('type'),
'href' => $this->_absolutiseUri(trim($link->getAttribute('href')), $uri),
'href' => $this->absolutiseUri(trim($link->getAttribute('href')), $uri),
));
}
}

/**
* Attempt to turn a relative URI into an absolute URI
*/
protected function _absolutiseUri($link, $uri = null)
protected function absolutiseUri($link, $uri = null)
{
if (!Uri\UriFactory::factory($link)->isValid()) {
$linkUri = Uri\UriFactory::factory($link);
if (!$linkUri->isAbsolute() or !$linkUri->isValid()) {
if ($uri !== null) {
$uri = Uri\UriFactory::factory($uri);

if ($link[0] !== '/') {
$link = $uri->getPath() . '/' . $link;
}

$link = $uri->getScheme() . '://' . $uri->getHost() . '/' . $this->_canonicalizePath($link);
$link = $uri->getScheme() . '://' . $uri->getHost() . '/' . $this->canonicalizePath($link);
if (!Uri\UriFactory::factory($link)->isValid()) {
$link = null;
}
Expand All @@ -104,7 +105,7 @@ protected function _absolutiseUri($link, $uri = null)
/**
* Canonicalize relative path
*/
protected function _canonicalizePath($path)
protected function canonicalizePath($path)
{
$parts = array_filter(explode('/', $path));
$absolutes = array();
Expand Down
20 changes: 13 additions & 7 deletions tests/Zend/Feed/PubSubHubbub/Model/SubscriptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
namespace ZendTest\Feed\PubSubHubbub\Model;

use Zend\Feed\PubSubHubbub\Model\Subscription;
use \Zend\Db\Adapter\Adapter as DbAdapter;
use \Zend\Db\TableGateway\TableGateway;

/**
* @category Zend
Expand All @@ -38,8 +40,11 @@ class SubscriptionTest extends \PHPUnit_Framework_TestCase
*/
public function testAllOperations()
{
$this->_initDb();
$subscription = new Subscription();
$adapter = $this->_initDb();
$table = new TableGateway('subscription', $adapter);

$subscription = new Subscription($table);

$id = uniqid();
$this->assertFalse($subscription->hasSubscription($id));
$this->assertFalse($subscription->getSubscription($id));
Expand Down Expand Up @@ -73,12 +78,13 @@ protected function _initDb()
) {
$this->markTestSkipped('Test only with pdo_sqlite');
}
$db = \Zend\Db\Db::factory('Pdo\Sqlite', array('dbname' => ':memory:'));
\Zend\Db\Table\AbstractTable::setDefaultAdapter($db);
$this->_createTable();
$db = new DbAdapter(array('driver' => 'pdo_sqlite', 'dsn' => 'sqlite::memory:'));
$this->_createTable($db);

return $db;
}

protected function _createTable()
protected function _createTable($db)
{
$sql = "CREATE TABLE subscription ("
. "id varchar(32) PRIMARY KEY NOT NULL DEFAULT '', "
Expand All @@ -92,6 +98,6 @@ protected function _createTable()
. "subscription_state varchar(12) DEFAULT NULL"
. ");";

\Zend\Db\Table\AbstractTable::getDefaultAdapter()->getConnection()->query($sql);
$db->query($sql)->execute();
}
}
4 changes: 2 additions & 2 deletions tests/Zend/Feed/PubSubHubbub/PublisherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,15 +309,15 @@ public function request($method = null) {
$response = new ResponseSuccess;
return $response;
}
public function getBody(){return $this->_prepareBody();}
public function getBody(){return $this->prepareBody();}
}
class ClientFail extends Http\Client
{
public function request($method = null) {
$response = new ResponseFail;
return $response;
}
public function getBody(){return $this->_prepareBody();}
public function getBody(){return $this->prepareBody();}
}
class ResponseSuccess
{
Expand Down
Loading

0 comments on commit 2c6b7bc

Please sign in to comment.