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

Commit

Permalink
Merge branch 'hotfix/uri-validation' of https://github.com/Maks3w/zf2
Browse files Browse the repository at this point in the history
…into hotfix/validator-uri
  • Loading branch information
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 88 deletions.
2 changes: 1 addition & 1 deletion src/Reader/Extension/Atom/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ public function getSource()
*/
protected function _absolutiseUri($link)
{
if (!Uri\UriFactory::factory($link)->isValid()) {
if (!Uri\UriFactory::factory($link)->isAbsolute()) {
if ($this->getBaseUrl() !== null) {
$link = $this->getBaseUrl() . $link;
if (!Uri\UriFactory::factory($link)->isValid()) {
Expand Down
2 changes: 1 addition & 1 deletion src/Reader/Extension/Atom/Feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ protected function _getAuthor(DOMElement $element)
*/
protected function _absolutiseUri($link)
{
if (!Uri\UriFactory::factory($link)->isValid()) {
if (!Uri\UriFactory::factory($link)->isAbsolute()) {
if ($this->getBaseUrl() !== null) {
$link = $this->getBaseUrl() . $link;
if (!Uri\UriFactory::factory($link)->isValid()) {
Expand Down
2 changes: 0 additions & 2 deletions test/Reader/Entry/AtomTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,6 @@ public function testGetsLinkFromAtom10_WithNoRelAttribute()

public function testGetsLinkFromAtom10_WithRelativeUrl()
{
$this->markTestIncomplete('Pending fix to \Zend\URI\URL::validate()');
$feed = Reader\Reader::importString(
file_get_contents($this->_feedSamplePath . '/link/plain/atom10-relative.xml')
);
Expand Down Expand Up @@ -430,7 +429,6 @@ public function testGetsCommentLinkFromAtom10()

public function testGetsCommentLinkFromAtom10_RelativeLinks()
{
$this->markTestIncomplete('Pending fix to \Zend\URI\URL::validate()');
$feed = Reader\Reader::importString(
file_get_contents($this->_feedSamplePath . '/commentlink/plain/atom10-relative.xml')
);
Expand Down
2 changes: 0 additions & 2 deletions test/Reader/Feed/AtomTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,6 @@ public function testGetsLinkFromAtom10WithNoRelAttribute()

public function testGetsLinkFromAtom10WithRelativeUrl()
{
$this->markTestIncomplete('Pending fix for \Zend\URI\URL::validate()');
$feed = Reader\Reader::importString(
file_get_contents($this->_feedSamplePath.'/link/plain/atom10-relative.xml')
);
Expand Down Expand Up @@ -375,7 +374,6 @@ public function testGetsFeedLinkFromAtom10()

public function testGetsFeedLinkFromAtom10IfRelativeUri()
{
$this->markTestIncomplete('Pending fix for \Zend\URI\URL::validate()');
$feed = Reader\Reader::importString(
file_get_contents($this->_feedSamplePath.'/feedlink/plain/atom10-relative.xml')
);
Expand Down
118 changes: 36 additions & 82 deletions test/Reader/ReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
*/

namespace ZendTest\Feed\Reader;

use Zend\Http\Client as HttpClient;
use Zend\Http\Client\Adapter\Test as TestAdapter;
use Zend\Http\Response as HttpResponse;
use Zend\Feed\Reader;

/**
Expand Down Expand Up @@ -140,71 +144,49 @@ public function testGetEncoding()

public function testImportsFile()
{
try {
$feed = Reader\Reader::importFile(
dirname(__FILE__) . '/Entry/_files/Atom/title/plain/atom10.xml'
);
} catch(\Exception $e) {
$this->fail($e->getMessage());
}
$feed = Reader\Reader::importFile(
dirname(__FILE__) . '/Entry/_files/Atom/title/plain/atom10.xml'
);
$this->assertInstanceOf('Zend\Feed\Reader\Feed\FeedInterface', $feed);
}

public function testImportsUri()
{
if (!defined('TESTS_ZEND_FEED_READER_ONLINE_ENABLED')
|| !constant('TESTS_ZEND_FEED_READER_ONLINE_ENABLED')
) {
if (!constant('TESTS_ZEND_FEED_READER_ONLINE_ENABLED')) {
$this->markTestSkipped('testImportsUri() requires a network connection');
return;
}

try {
$feed = Reader\Reader::import('http://www.planet-php.net/rdf/');
} catch(\Exception $e) {
$this->fail($e->getMessage());
}
Reader\Reader::import('http://www.planet-php.net/rdf/');
}

/**
* @group ZF-8328
* @expectedException Zend_Feed_Exception
* @expectedException Zend\Feed\Reader\Exception\RuntimeException
*/
public function testImportsUriAndThrowsExceptionIfNotAFeed()
{
if (!defined('TESTS_ZEND_FEED_READER_ONLINE_ENABLED')
|| !constant('TESTS_ZEND_FEED_READER_ONLINE_ENABLED')
) {
if (!constant('TESTS_ZEND_FEED_READER_ONLINE_ENABLED')) {
$this->markTestSkipped('testImportsUri() requires a network connection');
return;
}

$feed = Reader\Reader::import('http://twitter.com/alganet');
Reader\Reader::import('http://twitter.com/alganet');
}

public function testGetsFeedLinksAsValueObject()
{
if (!defined('TESTS_Reader\Reader_ONLINE_ENABLED')
|| !constant('TESTS_Reader\Reader_ONLINE_ENABLED')
) {
if (!constant('TESTS_ZEND_FEED_READER_ONLINE_ENABLED')) {
$this->markTestSkipped('testGetsFeedLinksAsValueObject() requires a network connection');
return;
}

try {
$links = Reader\Reader::findFeedLinks('http://www.planet-php.net');
} catch(\Exception $e) {
$this->fail($e->getMessage());
}
$links = Reader\Reader::findFeedLinks('http://www.planet-php.net');

$this->assertEquals('http://www.planet-php.org/rss/', $links->rss);
}

public function testCompilesLinksAsArrayObject()
{
if (!defined('TESTS_Reader\Reader_ONLINE_ENABLED')
|| !constant('TESTS_Reader\Reader_ONLINE_ENABLED')
) {
if (!constant('TESTS_ZEND_FEED_READER_ONLINE_ENABLED')) {
$this->markTestSkipped('testGetsFeedLinksAsValueObject() requires a network connection');
return;
}
$links = Reader\Reader::findFeedLinks('http://www.planet-php.net');
$this->assertTrue($links instanceof Reader\FeedSet);
Expand All @@ -215,11 +197,8 @@ public function testCompilesLinksAsArrayObject()

public function testFeedSetLoadsFeedObjectWhenFeedArrayKeyAccessed()
{
if (!defined('TESTS_ZEND_FEED_READER_ONLINE_ENABLED')
|| !constant('TESTS_ZEND_FEED_READER_ONLINE_ENABLED')
) {
if (!constant('TESTS_ZEND_FEED_READER_ONLINE_ENABLED')) {
$this->markTestSkipped('testGetsFeedLinksAsValueObject() requires a network connection');
return;
}
$links = Reader\Reader::findFeedLinks('http://www.planet-php.net');
$link = $links->getIterator()->current();
Expand All @@ -228,11 +207,8 @@ public function testFeedSetLoadsFeedObjectWhenFeedArrayKeyAccessed()

public function testZeroCountFeedSetReturnedFromEmptyList()
{
if (!defined('TESTS_ZEND_FEED_READER_ONLINE_ENABLED')
|| !constant('TESTS_ZEND_FEED_READER_ONLINE_ENABLED')
) {
if (!constant('TESTS_ZEND_FEED_READER_ONLINE_ENABLED')) {
$this->markTestSkipped('testGetsFeedLinksAsValueObject() requires a network connection');
return;
}
$links = Reader\Reader::findFeedLinks('http://www.example.com');
$this->assertEquals(0, count($links));
Expand All @@ -243,18 +219,11 @@ public function testZeroCountFeedSetReturnedFromEmptyList()
*/
public function testGetsFeedLinksAndTrimsNewlines()
{
if (!defined('TESTS_ZEND_FEED_READER_ONLINE_ENABLED')
|| !constant('TESTS_ZEND_FEED_READER_ONLINE_ENABLED')
) {
if (!constant('TESTS_ZEND_FEED_READER_ONLINE_ENABLED')) {
$this->markTestSkipped('testGetsFeedLinksAsValueObject() requires a network connection');
return;
}

try {
$links = Reader\Reader::findFeedLinks('http://www.infopod.com.br');
} catch(\Exception $e) {
$this->fail($e->getMessage());
}
$links = Reader\Reader::findFeedLinks('http://www.infopod.com.br');
$this->assertEquals('http://feeds.feedburner.com/jonnyken/infoblog', $links->rss);
}

Expand All @@ -263,18 +232,11 @@ public function testGetsFeedLinksAndTrimsNewlines()
*/
public function testGetsFeedLinksAndNormalisesRelativeUrls()
{
if (!defined('TESTS_ZEND_FEED_READER_ONLINE_ENABLED')
|| !constant('TESTS_ZEND_FEED_READER_ONLINE_ENABLED')
) {
if (!constant('TESTS_ZEND_FEED_READER_ONLINE_ENABLED')) {
$this->markTestSkipped('testGetsFeedLinksAsValueObject() requires a network connection');
return;
}

try {
$links = Reader\Reader::findFeedLinks('http://meiobit.com');
} catch(\Exception $e) {
$this->fail($e->getMessage());
}
$links = Reader\Reader::findFeedLinks('http://meiobit.com');
$this->assertEquals('http://meiobit.com/rss.xml', $links->rss);
}

Expand All @@ -283,20 +245,18 @@ public function testGetsFeedLinksAndNormalisesRelativeUrls()
*/
public function testGetsFeedLinksAndNormalisesRelativeUrlsOnUriWithPath()
{
$this->markTestIncomplete('Pending fix to \Zend\URI\URL::validate()');
try {
$currClient = Reader\Reader::getHttpClient();
$currClient = Reader\Reader::getHttpClient();

$testAdapter = new \Zend\HTTP\Client\Adapter\Test();
$testAdapter->setResponse(new \Zend\HTTP\Response\Response(200, array(), '<!DOCTYPE html><html><head><link rel="alternate" type="application/rss+xml" href="../test.rss"><link rel="alternate" type="application/atom+xml" href="/test.atom"></head><body></body></html>'));
Reader\Reader::setHttpClient(new \Zend\HTTP\Client(null, array('adapter' => $testAdapter)));
$testAdapter = new TestAdapter();
$response = new HttpResponse();
$response->setStatusCode(200);
$response->setContent('<!DOCTYPE html><html><head><link rel="alternate" type="application/rss+xml" href="../test.rss"><link rel="alternate" type="application/atom+xml" href="/test.atom"></head><body></body></html>');
$testAdapter->setResponse($response);
Reader\Reader::setHttpClient(new HttpClient(null, array('adapter' => $testAdapter)));

$links = Reader\Reader::findFeedLinks('http://foo/bar');
$links = Reader\Reader::findFeedLinks('http://foo/bar');

Reader\Reader::setHttpClient($currClient);
} catch(\Exception $e) {
$this->fail($e->getMessage());
}
Reader\Reader::setHttpClient($currClient);

$this->assertEquals('http://foo/test.rss', $links->rss);
$this->assertEquals('http://foo/test.atom', $links->atom);
Expand All @@ -312,12 +272,9 @@ public function testAddsPrefixPath()

public function testRegistersUserExtension()
{
try {
Reader\Reader::addPrefixPath('My\\Extension', dirname(__FILE__) . '/_files/My/Extension');
Reader\Reader::registerExtension('JungleBooks');
} catch(\Exception $e) {
$this->fail($e->getMessage());
}
Reader\Reader::addPrefixPath('My\\Extension', dirname(__FILE__) . '/_files/My/Extension');
Reader\Reader::registerExtension('JungleBooks');

$this->assertTrue(Reader\Reader::isRegistered('JungleBooks'));
}

Expand Down Expand Up @@ -362,10 +319,7 @@ protected function _getTempDirectory()

protected function _isGoodTmpDir($dir)
{
if (is_readable($dir) && is_writable($dir)) {
return true;
}
return false;
return (is_readable($dir) && is_writable($dir));
}

}

0 comments on commit d16deed

Please sign in to comment.