diff options
Diffstat (limited to 'vendor/fguillot/picofeed/tests')
54 files changed, 2527 insertions, 34773 deletions
diff --git a/vendor/fguillot/picofeed/tests/Filter/AttributeFilterTest.php b/vendor/fguillot/picofeed/tests/Filter/AttributeFilterTest.php index 5dcfda141..6c68ef433 100644 --- a/vendor/fguillot/picofeed/tests/Filter/AttributeFilterTest.php +++ b/vendor/fguillot/picofeed/tests/Filter/AttributeFilterTest.php @@ -4,6 +4,7 @@ namespace PicoFeed\Filter; use PHPUnit_Framework_TestCase; use PicoFeed\Client\Url; +use PicoFeed\Config\Config; class AttributeFilterTest extends PHPUnit_Framework_TestCase @@ -190,4 +191,134 @@ class AttributeFilterTest extends PHPUnit_Framework_TestCase $this->assertEquals('title=""a""', $filter->toHtml(array('title' => '"a"'))); $this->assertEquals('title="ç" alt="b"', $filter->toHtml(array('title' => 'ç', 'alt' => 'b'))); } + + public function testNoImageProxySet() + { + $f = Filter::html('<p>Image <img src="/image.png" alt="My Image"/></p>', 'http://foo'); + + $this->assertEquals( + '<p>Image <img src="http://foo/image.png" alt="My Image"/></p>', + $f->execute() + ); + } + + public function testImageProxyWithHTTPLink() + { + $config = new Config; + $config->setFilterImageProxyUrl('http://myproxy/?url=%s'); + + $f = Filter::html('<p>Image <img src="http://localhost/image.png" alt="My Image"/></p>', 'http://foo'); + $f->setConfig($config); + + $this->assertEquals( + '<p>Image <img src="http://myproxy/?url='.rawurlencode('http://localhost/image.png').'" alt="My Image"/></p>', + $f->execute() + ); + } + + public function testImageProxyWithHTTPSLink() + { + $config = new Config; + $config->setFilterImageProxyUrl('http://myproxy/?url=%s'); + + $f = Filter::html('<p>Image <img src="https://localhost/image.png" alt="My Image"/></p>', 'http://foo'); + $f->setConfig($config); + + $this->assertEquals( + '<p>Image <img src="http://myproxy/?url='.rawurlencode('https://localhost/image.png').'" alt="My Image"/></p>', + $f->execute() + ); + } + + public function testImageProxyLimitedToUnknownProtocol() + { + $config = new Config; + $config->setFilterImageProxyUrl('http://myproxy/?url=%s'); + $config->setFilterImageProxyProtocol('tripleX'); + + $f = Filter::html('<p>Image <img src="http://localhost/image.png" alt="My Image"/></p>', 'http://foo'); + $f->setConfig($config); + + $this->assertEquals( + '<p>Image <img src="http://localhost/image.png" alt="My Image"/></p>', + $f->execute() + ); + } + + public function testImageProxyLimitedToHTTPwithHTTPLink() + { + $config = new Config; + $config->setFilterImageProxyUrl('http://myproxy/?url=%s'); + $config->setFilterImageProxyProtocol('http'); + + $f = Filter::html('<p>Image <img src="http://localhost/image.png" alt="My Image"/></p>', 'http://foo'); + $f->setConfig($config); + + $this->assertEquals( + '<p>Image <img src="http://myproxy/?url='.rawurlencode('http://localhost/image.png').'" alt="My Image"/></p>', + $f->execute() + ); + } + + public function testImageProxyLimitedToHTTPwithHTTPSLink() + { + $config = new Config; + $config->setFilterImageProxyUrl('http://myproxy/?url=%s'); + $config->setFilterImageProxyProtocol('http'); + + $f = Filter::html('<p>Image <img src="https://localhost/image.png" alt="My Image"/></p>', 'http://foo'); + $f->setConfig($config); + + $this->assertEquals( + '<p>Image <img src="https://localhost/image.png" alt="My Image"/></p>', + $f->execute() + ); + } + + public function testImageProxyLimitedToHTTPSwithHTTPLink() + { + $config = new Config; + $config->setFilterImageProxyUrl('http://myproxy/?url=%s'); + $config->setFilterImageProxyProtocol('https'); + + $f = Filter::html('<p>Image <img src="http://localhost/image.png" alt="My Image"/></p>', 'http://foo'); + $f->setConfig($config); + + $this->assertEquals( + '<p>Image <img src="http://localhost/image.png" alt="My Image"/></p>', + $f->execute() + ); + } + + public function testImageProxyLimitedToHTTPSwithHTTPSLink() + { + $config = new Config; + $config->setFilterImageProxyUrl('http://myproxy/?url=%s'); + $config->setFilterImageProxyProtocol('https'); + + $f = Filter::html('<p>Image <img src="https://localhost/image.png" alt="My Image"/></p>', 'http://foo'); + $f->setConfig($config); + + $this->assertEquals( + '<p>Image <img src="http://myproxy/?url='.rawurlencode('https://localhost/image.png').'" alt="My Image"/></p>', + $f->execute() + ); + } + + public function testsetFilterImageProxyCallback() + { + $config = new Config; + $config->setFilterImageProxyCallback(function ($image_url) { + $key = hash_hmac('sha1', $image_url, 'secret'); + return 'https://mypublicproxy/'.$key.'/'.rawurlencode($image_url); + }); + + $f = Filter::html('<p>Image <img src="/image.png" alt="My Image"/></p>', 'http://foo'); + $f->setConfig($config); + + $this->assertEquals( + '<p>Image <img src="https://mypublicproxy/4924964043f3119b3cf2b07b1922d491bcc20092/'.rawurlencode('http://foo/image.png').'" alt="My Image"/></p>', + $f->execute() + ); + } } diff --git a/vendor/fguillot/picofeed/tests/Filter/FilterTest.php b/vendor/fguillot/picofeed/tests/Filter/FilterTest.php index f5f98a96b..29cff4668 100644 --- a/vendor/fguillot/picofeed/tests/Filter/FilterTest.php +++ b/vendor/fguillot/picofeed/tests/Filter/FilterTest.php @@ -37,9 +37,6 @@ class FilterTest extends PHPUnit_Framework_TestCase $data = file_get_contents('tests/fixtures/sametmax.xml'); $this->assertEquals('<rss', substr(Filter::stripXmlTag($data), 0, 4)); - $data = file_get_contents('tests/fixtures/grotte_barbu.xml'); - $this->assertEquals('<rss', substr(Filter::stripXmlTag($data), 0, 4)); - $data = file_get_contents('tests/fixtures/ibash.ru.xml'); $this->assertEquals('<rss', substr(Filter::stripXmlTag($data), 0, 4)); @@ -58,7 +55,7 @@ class FilterTest extends PHPUnit_Framework_TestCase $data = file_get_contents('tests/fixtures/lagrange.xml'); $this->assertEquals('<feed', substr(Filter::stripXmlTag($data), 0, 5)); - $data = file_get_contents('tests/fixtures/atom.xml'); + $data = file_get_contents('tests/fixtures/googleblog.xml'); $this->assertEquals('<feed', substr(trim(Filter::stripXmlTag($data)), 0, 5)); $data = file_get_contents('tests/fixtures/atomsample.xml'); @@ -91,133 +88,35 @@ class FilterTest extends PHPUnit_Framework_TestCase $this->assertEquals('<p>Testboo</p>', $f->execute()); } - public function testNoImageProxySet() - { - $f = Filter::html('<p>Image <img src="/image.png" alt="My Image"/></p>', 'http://foo'); - - $this->assertEquals( - '<p>Image <img src="http://foo/image.png" alt="My Image"/></p>', - $f->execute() - ); - } - - public function testImageProxyWithHTTPLink() - { - $config = new Config; - $config->setFilterImageProxyUrl('http://myproxy/?url=%s'); - - $f = Filter::html('<p>Image <img src="http://localhost/image.png" alt="My Image"/></p>', 'http://foo'); - $f->setConfig($config); - - $this->assertEquals( - '<p>Image <img src="http://myproxy/?url='.rawurlencode('http://localhost/image.png').'" alt="My Image"/></p>', - $f->execute() - ); - } - - public function testImageProxyWithHTTPSLink() - { - $config = new Config; - $config->setFilterImageProxyUrl('http://myproxy/?url=%s'); - - $f = Filter::html('<p>Image <img src="https://localhost/image.png" alt="My Image"/></p>', 'http://foo'); - $f->setConfig($config); - - $this->assertEquals( - '<p>Image <img src="http://myproxy/?url='.rawurlencode('https://localhost/image.png').'" alt="My Image"/></p>', - $f->execute() - ); - } - - public function testImageProxyLimitedToUnknownProtocol() + public function testNormalizeData() { - $config = new Config; - $config->setFilterImageProxyUrl('http://myproxy/?url=%s'); - $config->setFilterImageProxyProtocol('tripleX'); - - $f = Filter::html('<p>Image <img src="http://localhost/image.png" alt="My Image"/></p>', 'http://foo'); - $f->setConfig($config); - - $this->assertEquals( - '<p>Image <img src="http://localhost/image.png" alt="My Image"/></p>', - $f->execute() - ); - } - - public function testImageProxyLimitedToHTTPwithHTTPLink() - { - $config = new Config; - $config->setFilterImageProxyUrl('http://myproxy/?url=%s'); - $config->setFilterImageProxyProtocol('http'); - - $f = Filter::html('<p>Image <img src="http://localhost/image.png" alt="My Image"/></p>', 'http://foo'); - $f->setConfig($config); - - $this->assertEquals( - '<p>Image <img src="http://myproxy/?url='.rawurlencode('http://localhost/image.png').'" alt="My Image"/></p>', - $f->execute() - ); - } - - public function testImageProxyLimitedToHTTPwithHTTPSLink() - { - $config = new Config; - $config->setFilterImageProxyUrl('http://myproxy/?url=%s'); - $config->setFilterImageProxyProtocol('http'); - - $f = Filter::html('<p>Image <img src="https://localhost/image.png" alt="My Image"/></p>', 'http://foo'); - $f->setConfig($config); - - $this->assertEquals( - '<p>Image <img src="https://localhost/image.png" alt="My Image"/></p>', - $f->execute() - ); - } - - public function testImageProxyLimitedToHTTPSwithHTTPLink() - { - $config = new Config; - $config->setFilterImageProxyUrl('http://myproxy/?url=%s'); - $config->setFilterImageProxyProtocol('https'); - - $f = Filter::html('<p>Image <img src="http://localhost/image.png" alt="My Image"/></p>', 'http://foo'); - $f->setConfig($config); - - $this->assertEquals( - '<p>Image <img src="http://localhost/image.png" alt="My Image"/></p>', - $f->execute() - ); - } - - public function testImageProxyLimitedToHTTPSwithHTTPSLink() - { - $config = new Config; - $config->setFilterImageProxyUrl('http://myproxy/?url=%s'); - $config->setFilterImageProxyProtocol('https'); - - $f = Filter::html('<p>Image <img src="https://localhost/image.png" alt="My Image"/></p>', 'http://foo'); - $f->setConfig($config); - - $this->assertEquals( - '<p>Image <img src="http://myproxy/?url='.rawurlencode('https://localhost/image.png').'" alt="My Image"/></p>', - $f->execute() - ); - } - - public function testsetFilterImageProxyCallback() - { - $config = new Config; - $config->setFilterImageProxyCallback(function ($image_url) { - $key = hash_hmac('sha1', $image_url, 'secret'); - return 'https://mypublicproxy/'.$key.'/'.rawurlencode($image_url); - }); - - $f = Filter::html('<p>Image <img src="/image.png" alt="My Image"/></p>', 'http://foo'); - $f->setConfig($config); - - $this->assertEquals( - '<p>Image <img src="https://mypublicproxy/4924964043f3119b3cf2b07b1922d491bcc20092/'.rawurlencode('http://foo/image.png').'" alt="My Image"/></p>', - $f->execute() - ); + // invalid data link escape control character + $this->assertEquals('<xml>random text</xml>', Filter::normalizeData("<xml>random\x10 text</xml>")); + $this->assertEquals('<xml>random text</xml>', Filter::normalizeData("<xml>random text</xml>")); + $this->assertEquals('<xml>random text</xml>', Filter::normalizeData("<xml>random text</xml>")); + + // invalid unit seperator control character (lower and upper case) + $this->assertEquals('<xml>random text</xml>', Filter::normalizeData("<xml>random\x1f text</xml>")); + $this->assertEquals('<xml>random text</xml>', Filter::normalizeData("<xml>random\x1F text</xml>")); + $this->assertEquals('<xml>random text</xml>', Filter::normalizeData("<xml>random text</xml>")); + $this->assertEquals('<xml>random text</xml>', Filter::normalizeData("<xml>random text</xml>")); + $this->assertEquals('<xml>random text</xml>', Filter::normalizeData("<xml>random text</xml>")); + + /* + * Do not test invalid multibyte characters. The output depends on php + * version and character. + * + * php 5.3: always null + * php >5.3: sometime null, sometimes the stripped string + */ + + // invalid backspace control character + valid multibyte character + $this->assertEquals('<xml>“random“ text</xml>', Filter::normalizeData("<xml>\xe2\x80\x9crandom\xe2\x80\x9c\x08 text</xml>")); + $this->assertEquals('<xml>“random“ text</xml>', Filter::normalizeData("<xml>“random“ text</xml>")); + $this->assertEquals('<xml>“random“ text</xml>', Filter::normalizeData("<xml>“random“ text</xml>")); + + // do not convert valid entities to utf-8 character + $this->assertEquals('<xml attribute=""value"">random text</xml>', Filter::normalizeData('<xml attribute=""value"">random text</xml>')); + $this->assertEquals('<xml attribute=""value"">random text</xml>', Filter::normalizeData('<xml attribute=""value"">random text</xml>')); } }
\ No newline at end of file diff --git a/vendor/fguillot/picofeed/tests/Parser/AtomParserTest.php b/vendor/fguillot/picofeed/tests/Parser/AtomParserTest.php index 9c2526c04..5cbd0eeb8 100644 --- a/vendor/fguillot/picofeed/tests/Parser/AtomParserTest.php +++ b/vendor/fguillot/picofeed/tests/Parser/AtomParserTest.php @@ -14,249 +14,450 @@ class AtomParserTest extends PHPUnit_Framework_TestCase $parser->execute(); } - public function testFeedTitle() + public function testGetItemsTree() { $parser = new Atom(file_get_contents('tests/fixtures/atom.xml')); $feed = $parser->execute(); - $this->assertEquals('The Official Google Blog', $feed->getTitle()); + $this->assertCount(4, $feed->items); - $parser = new Atom(file_get_contents('tests/fixtures/atomsample.xml')); + $parser = new Atom(file_get_contents('tests/fixtures/atom_no_default_namespace.xml')); $feed = $parser->execute(); - $this->assertEquals('Example Feed', $feed->getTitle()); + $this->assertCount(4, $feed->items); + + $parser = new Atom(file_get_contents('tests/fixtures/atom_prefixed.xml')); + $feed = $parser->execute(); + $this->assertCount(4, $feed->items); + + $parser = new Atom(file_get_contents('tests/fixtures/atom_empty_feed.xml')); + $feed = $parser->execute(); + $this->assertEquals(array(), $feed->items); + } + + public function testFindFeedTitle() + { + $parser = new Atom(file_get_contents('tests/fixtures/atom.xml')); + $feed = $parser->execute(); + $this->assertEquals('литература на русском языке, либо написанная русскими авторами', $feed->getTitle()); + + $parser = new Atom(file_get_contents('tests/fixtures/atom_no_default_namespace.xml')); + $feed = $parser->execute(); + $this->assertEquals('литература на русском языке, либо написанная русскими авторами', $feed->getTitle()); + + $parser = new Atom(file_get_contents('tests/fixtures/atom_prefixed.xml')); + $feed = $parser->execute(); + $this->assertEquals('литература на русском языке, либо написанная русскими авторами', $feed->getTitle()); + + $parser = new Atom(file_get_contents('tests/fixtures/atom_fallback_on_invalid_feed_values.xml')); + $feed = $parser->execute(); + $this->assertEquals('https://en.wikipedia.org/wiki/Category:Russian-language_literature', $feed->getTitle()); + + $parser = new Atom(file_get_contents('tests/fixtures/atom_empty_feed.xml')); + $feed = $parser->execute(); + $this->assertEquals('', $feed->getTitle()); } - public function testFeedDescription() + public function testFindFeedDescription() { $parser = new Atom(file_get_contents('tests/fixtures/atom.xml')); $feed = $parser->execute(); - $this->assertEquals('Insights from Googlers into our products, technology, and the Google culture.', $feed->getDescription()); + $this->assertEquals("Зародилась во второй половине X века, однако до XIX века,\nкогда начался её «золотой век», была практически неизвестна\nв мире.", $feed->getDescription()); - $parser = new Atom(file_get_contents('tests/fixtures/atomsample.xml')); + $parser = new Atom(file_get_contents('tests/fixtures/atom_no_default_namespace.xml')); + $feed = $parser->execute(); + $this->assertEquals("Зародилась во второй половине X века, однако до XIX века,\nкогда начался её «золотой век», была практически неизвестна\nв мире.", $feed->getDescription()); + + $parser = new Atom(file_get_contents('tests/fixtures/atom_prefixed.xml')); + $feed = $parser->execute(); + $this->assertEquals("Зародилась во второй половине X века, однако до XIX века,\nкогда начался её «золотой век», была практически неизвестна\nв мире.", $feed->getDescription()); + + $parser = new Atom(file_get_contents('tests/fixtures/atom_empty_feed.xml')); $feed = $parser->execute(); $this->assertEquals('', $feed->getDescription()); |