summaryrefslogtreecommitdiffstats
path: root/3rdparty/fguillot/picofeed/tests/Filter
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/fguillot/picofeed/tests/Filter')
-rw-r--r--3rdparty/fguillot/picofeed/tests/Filter/AttributeFilterTest.php140
-rw-r--r--3rdparty/fguillot/picofeed/tests/Filter/FilterTest.php88
-rw-r--r--3rdparty/fguillot/picofeed/tests/Filter/HtmlFilterTest.php168
-rw-r--r--3rdparty/fguillot/picofeed/tests/Filter/TagFilterTest.php33
4 files changed, 429 insertions, 0 deletions
diff --git a/3rdparty/fguillot/picofeed/tests/Filter/AttributeFilterTest.php b/3rdparty/fguillot/picofeed/tests/Filter/AttributeFilterTest.php
new file mode 100644
index 000000000..e4de74aaf
--- /dev/null
+++ b/3rdparty/fguillot/picofeed/tests/Filter/AttributeFilterTest.php
@@ -0,0 +1,140 @@
+<?php
+namespace PicoFeed\Filter;
+
+use PHPUnit_Framework_TestCase;
+
+use PicoFeed\Client\Url;
+
+
+class AttributeFilterTest extends PHPUnit_Framework_TestCase
+{
+ public function testFilterEmptyAttribute()
+ {
+ $filter = new Attribute(new Url('http://google.com'));
+
+ $this->assertTrue($filter->filterEmptyAttribute('abbr', 'title', 'test'));
+ $this->assertFalse($filter->filterEmptyAttribute('abbr', 'title', ''));
+ $this->assertEquals(array('title' => 'test'), $filter->filter('abbr', array('title' => 'test')));
+ $this->assertEquals(array(), $filter->filter('abbr', array('title' => '')));
+ }
+
+ public function testFilterAllowedAttribute()
+ {
+ $filter = new Attribute(new Url('http://google.com'));
+
+ $this->assertTrue($filter->filterAllowedAttribute('abbr', 'title', 'test'));
+ $this->assertFalse($filter->filterAllowedAttribute('script', 'type', 'text/javascript'));
+
+ $this->assertEquals(array(), $filter->filter('script', array('type' => 'text/javascript')));
+ $this->assertEquals(array(), $filter->filter('a', array('onclick' => 'javascript')));
+ $this->assertEquals(array('href' => 'http://google.com/'), $filter->filter('a', array('href' => 'http://google.com')));
+ }
+
+ public function testFilterIntegerAttribute()
+ {
+ $filter = new Attribute(new Url('http://google.com'));
+
+ $this->assertTrue($filter->filterIntegerAttribute('abbr', 'title', 'test'));
+ $this->assertTrue($filter->filterIntegerAttribute('iframe', 'width', '0'));
+ $this->assertTrue($filter->filterIntegerAttribute('iframe', 'width', '450'));
+ $this->assertFalse($filter->filterIntegerAttribute('iframe', 'width', 'test'));
+
+ $this->assertEquals(array('width' => '10', 'src' => 'http://www.youtube.com/test'), $filter->filter('iframe', array('width' => '10', 'src' => 'http://www.youtube.com/test')));
+ $this->assertEquals(array('src' => 'http://www.youtube.com/test'), $filter->filter('iframe', array('width' => 'test', 'src' => 'http://www.youtube.com/test')));
+ }
+
+ public function testFilterAbsoluteUrlAttribute()
+ {
+ $filter = new Attribute(new Url('http://www.la-grange.net'));
+ $url = '/2014/08/03/4668-noisettes';
+ $this->assertTrue($filter->filterAbsoluteUrlAttribute('a', 'href', $url));
+ $this->assertEquals('http://www.la-grange.net/2014/08/03/4668-noisettes', $url);
+
+ $filter = new Attribute(new Url('http://google.com'));
+
+ $url = 'test';
+ $this->assertTrue($filter->filterAbsoluteUrlAttribute('a', 'href', $url));
+ $this->assertEquals('http://google.com/test', $url);
+
+ $url = 'http://127.0.0.1:8000/test';
+ $this->assertTrue($filter->filterAbsoluteUrlAttribute('img', 'src', $url));
+ $this->assertEquals('http://127.0.0.1:8000/test', $url);
+
+ $url = '//example.com';
+ $this->assertTrue($filter->filterAbsoluteUrlAttribute('a', 'href', $url));
+ $this->assertEquals('http://example.com/', $url);
+
+ $filter = new Attribute(new Url('https://google.com'));
+ $url = '//example.com/?youpi';
+ $this->assertTrue($filter->filterAbsoluteUrlAttribute('a', 'href', $url));
+ $this->assertEquals('https://example.com/?youpi', $url);
+
+ $filter = new Attribute(new Url('https://127.0.0.1:8000/here/'));
+ $url = 'image.png?v=2';
+ $this->assertTrue($filter->filterAbsoluteUrlAttribute('a', 'href', $url));
+ $this->assertEquals('https://127.0.0.1:8000/here/image.png?v=2', $url);
+
+ $filter = new Attribute(new Url('https://truc/'));
+ $this->assertEquals(array('src' => 'https://www.youtube.com/test'), $filter->filter('iframe', array('width' => 'test', 'src' => '//www.youtube.com/test')));
+
+ $filter = new Attribute(new Url('http://truc/'));
+ $this->assertEquals(array('href' => 'http://google.fr/'), $filter->filter('a', array('href' => '//google.fr')));
+ }
+
+ public function testFilterIframeAttribute()
+ {
+ $filter = new Attribute(new Url('http://google.com'));
+
+ $this->assertTrue($filter->filterIframeAttribute('iframe', 'src', 'http://www.youtube.com/test'));
+ $this->assertTrue($filter->filterIframeAttribute('iframe', 'src', 'https://www.youtube.com/test'));
+ $this->assertFalse($filter->filterIframeAttribute('iframe', 'src', '//www.youtube.com/test'));
+ $this->assertFalse($filter->filterIframeAttribute('iframe', 'src', '//www.bidule.com/test'));
+
+ $this->assertEquals(array('src' => 'http://www.youtube.com/test'), $filter->filter('iframe', array('src' => '//www.youtube.com/test')));
+ }
+
+ public function testFilterBlacklistAttribute()
+ {
+ $filter = new Attribute(new Url('http://google.com'));
+
+ $this->assertTrue($filter->filterBlacklistResourceAttribute('a', 'href', 'http://google.fr/'));
+ $this->assertFalse($filter->filterBlacklistResourceAttribute('a', 'href', 'http://res3.feedsportal.com/truc'));
+
+ $this->assertEquals(array('href' => 'http://google.fr/'), $filter->filter('a', array('href' => 'http://google.fr/')));
+ $this->assertEquals(array(), $filter->filter('a', array('href' => 'http://res3.feedsportal.com/')));
+ }
+
+ public function testFilterProtocolAttribute()
+ {
+ $filter = new Attribute(new Url('http://google.com'));
+
+ $this->assertTrue($filter->filterProtocolUrlAttribute('a', 'href', 'http://google.fr/'));
+ $this->assertFalse($filter->filterProtocolUrlAttribute('a', 'href', 'bla://google.fr/'));
+ $this->assertFalse($filter->filterProtocolUrlAttribute('a', 'href', 'javascript:alert("test")'));
+
+ $this->assertEquals(array('href' => 'http://google.fr/'), $filter->filter('a', array('href' => 'http://google.fr/')));
+ $this->assertEquals(array(), $filter->filter('a', array('href' => 'bla://google.fr/')));
+ }
+
+ public function testRequiredAttribute()
+ {
+ $filter = new Attribute(new Url('http://google.com'));
+
+ $this->assertTrue($filter->hasRequiredAttributes('a', array('href' => 'bla')));
+ $this->assertTrue($filter->hasRequiredAttributes('img', array('src' => 'bla')));
+ $this->assertTrue($filter->hasRequiredAttributes('source', array('src' => 'bla')));
+ $this->assertTrue($filter->hasRequiredAttributes('audio', array('src' => 'bla')));
+ $this->assertTrue($filter->hasRequiredAttributes('iframe', array('src' => 'bla')));
+ $this->assertTrue($filter->hasRequiredAttributes('p', array('class' => 'bla')));
+ $this->assertFalse($filter->hasRequiredAttributes('a', array('title' => 'bla')));
+ }
+
+ public function testHtml()
+ {
+ $filter = new Attribute(new Url('http://google.com'));
+
+ $this->assertEquals('title="A &amp; B"', $filter->toHtml(array('title' => 'A & B')));
+ $this->assertEquals('title="&quot;a&quot;"', $filter->toHtml(array('title' => '"a"')));
+ $this->assertEquals('title="ç" alt="b"', $filter->toHtml(array('title' => 'ç', 'alt' => 'b')));
+ }
+}
diff --git a/3rdparty/fguillot/picofeed/tests/Filter/FilterTest.php b/3rdparty/fguillot/picofeed/tests/Filter/FilterTest.php
new file mode 100644
index 000000000..f3b736dfb
--- /dev/null
+++ b/3rdparty/fguillot/picofeed/tests/Filter/FilterTest.php
@@ -0,0 +1,88 @@
+<?php
+namespace PicoFeed\Filter;
+
+use PHPUnit_Framework_TestCase;
+
+use PicoFeed\Config\Config;
+
+
+class FilterTest extends PHPUnit_Framework_TestCase
+{
+ public function testStripHeadTag()
+ {
+ $input = '<html><head><title>test</title></head><body><h1>boo</h1></body>';
+ $expected = '<html><body><h1>boo</h1></body>';
+ $this->assertEquals($expected, Filter::stripHeadTags($input));
+
+ $input = file_get_contents('tests/fixtures/html_page.html');
+ $expected = file_get_contents('tests/fixtures/html_head_stripped_page.html');
+ $this->assertEquals($expected, Filter::stripHeadTags($input));
+ }
+
+ public function testStripXmlTag()
+ {
+ $data = file_get_contents('tests/fixtures/jeux-linux.fr.xml');
+ $this->assertEquals('<rss', substr(Filter::stripXmlTag($data), 0, 4));
+
+ $data = file_get_contents('tests/fixtures/ezrss.it');
+ $this->assertEquals('<!DOC', substr(Filter::stripXmlTag($data), 0, 5));
+
+ $data = file_get_contents('tests/fixtures/fulltextrss.xml');
+ $this->assertEquals('<rss', substr(Filter::stripXmlTag($data), 0, 4));
+
+ $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));
+
+ $data = file_get_contents('tests/fixtures/pcinpact.xml');
+ $this->assertEquals('<rss', substr(Filter::stripXmlTag($data), 0, 4));
+
+ $data = file_get_contents('tests/fixtures/resorts.xml');
+ $this->assertEquals('<rss', substr(Filter::stripXmlTag($data), 0, 4));
+
+ $data = file_get_contents('tests/fixtures/rue89.xml');
+ $this->assertEquals('<rss', substr(Filter::stripXmlTag($data), 0, 4));
+
+ $data = file_get_contents('tests/fixtures/cercle.psy.xml');
+ $this->assertEquals('<rss', substr(Filter::stripXmlTag($data), 0, 4));
+
+ $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');
+ $this->assertEquals('<feed', substr(trim(Filter::stripXmlTag($data)), 0, 5));
+
+ $data = file_get_contents('tests/fixtures/atomsample.xml');
+ $this->assertEquals('<feed', substr(trim(Filter::stripXmlTag($data)), 0, 5));
+
+ $data = file_get_contents('tests/fixtures/planete-jquery.xml');
+ $this->assertEquals('<rdf:RDF', trim(substr(trim(Filter::stripXmlTag($data)), 0, 8)));
+ }
+
+ public function testOverrideFilters()
+ {
+ $data = '<iframe src="http://www.kickstarter.com/projects/lefnire/habitrpg-mobile/widget/video.html" height="480" width="640" frameborder="0"></iframe>';
+
+ $f = Filter::html($data, 'http://blabla');
+ $f->attribute->setIframeWhitelist(array('http://www.kickstarter.com'));
+ $this->assertEquals($data, $f->execute());
+
+ $data = '<iframe src="http://www.youtube.com/bla" height="480" width="640" frameborder="0"></iframe>';
+
+ $f = Filter::html($data, 'http://blabla');
+ $f->attribute->setIframeWhitelist(array('http://www.kickstarter.com'));
+ $this->assertEmpty($f->execute());
+
+ $config = new Config;
+ $config->setFilterWhitelistedTags(array('p' => array('title')));
+
+ $f = Filter::html('<p>Test<strong>boo</strong></p>', 'http://blabla');
+ $f->setConfig($config);
+ $this->assertEquals('<p>Testboo</p>', $f->execute());
+ }
+} \ No newline at end of file
diff --git a/3rdparty/fguillot/picofeed/tests/Filter/HtmlFilterTest.php b/3rdparty/fguillot/picofeed/tests/Filter/HtmlFilterTest.php
new file mode 100644
index 000000000..271167481
--- /dev/null
+++ b/3rdparty/fguillot/picofeed/tests/Filter/HtmlFilterTest.php
@@ -0,0 +1,168 @@
+<?php
+namespace PicoFeed\Filter;
+
+use PHPUnit_Framework_TestCase;
+
+
+class HtmlFilterTest extends PHPUnit_Framework_TestCase
+{
+ public function testExecute()
+ {
+ $html = '<!DOCTYPE html><html><head>
+ <meta name="title" content="test">
+ </head><body><p>boo<br/><strong>foo</strong>.</p></body></html>';
+
+ $filter = new Html($html, 'http://www.google.ca/');
+
+ $this->assertEquals('<p>boo<br/><strong>foo</strong>.</p>', $filter->execute());
+ }
+
+ public function testIframe()
+ {
+ $data = '<iframe src="http://www.kickstarter.com/projects/lefnire/habitrpg-mobile/widget/video.html" height="480" width="640" frameborder="0"></iframe>';
+
+ $f = new Html($data, 'http://blabla');
+ $this->assertEmpty($f->execute());
+
+ $data = '<iframe src="http://www.youtube.com/bla" height="480" width="640" frameborder="0"></iframe>';
+
+ $f = new Html($data, 'http://blabla');
+ $this->assertEquals($data, $f->execute());
+ }
+
+ public function testEmptyTags()
+ {
+ $data = <<<EOD
+<div>
+<a href="file://path/to/a/file">
+ <img src="http://example.com/image.png" />
+</a>
+</div>
+EOD;
+ $f = new Html($data, 'http://blabla');
+ $output = $f->execute();
+
+ $this->assertEquals('<img src="http://example.com/image.png"/>', $output);
+ }
+
+ public function testBadAttributes()
+ {
+ $data = '<iframe src="http://www.youtube.com/bla" height="480px" width="100%" frameborder="0"></iframe>';
+
+ $f = new Html($data, 'http://blabla');
+ $this->assertEquals('<iframe src="http://www.youtube.com/bla" frameborder="0"></iframe>', $f->execute());
+ }
+
+ public function testRelativeScheme()
+ {
+ $f = new Html('<a href="//linuxfr.org">link</a>', 'http://blabla');
+ $this->assertEquals('<a href="http://linuxfr.org/" rel="noreferrer" target="_blank">link</a>', $f->execute());
+ }
+
+ public function testAttributes()
+ {
+ $f = new Html('<img src="foo" title="\'quote" alt="\'quote" data-src="bar" data-truc="boo"/>', 'http://blabla');
+ $this->assertEquals('<img src="http://blabla/foo" title="&#039;quote" alt="&#039;quote"/>', $f->execute());
+
+ $f = new Html('<img src="foo&bar=\'quote"/>', 'http://blabla');
+ $this->assertEquals('<img src="http://blabla/foo&amp;bar=&#039;quote"/>', $f->execute());
+
+ $f = new Html("<time datetime='quote\"here'>bla</time>", 'http://blabla');
+ $this->assertEquals('<time datetime="quote&quot;here">bla</time>', $f->execute());
+ }
+
+ public function testCode()
+ {
+ $data = '<pre><code>HEAD / HTTP/1.1
+Accept: text/html
+Accept-Encoding: gzip, deflate, compress
+Host: www.amazon.com
+User-Agent: HTTPie/0.6.0
+
+
+
+<strong>HTTP/1.1 405 MethodNotAllowed</strong>
+Content-Encoding: gzip
+Content-Type: text/html; charset=ISO-8859-1
+Date: Mon, 15 Jul 2013 02:05:59 GMT
+Server: Server
+Set-Cookie: skin=noskin; path=/; domain=.amazon.com; expires=Mon, 15-Jul-2013 02:05:59 GMT
+Vary: Accept-Encoding,User-Agent
+<strong>allow: POST, GET</strong>
+x-amz-id-1: 11WD3K15FC268R5GBJY5
+x-amz-id-2: DDjqfqz2ZJufzqRAcj1mh+9XvSogrPohKHwXlo8IlkzH67G6w4wnjn9HYgbs4uI0
+</code></pre>';
+
+ $f = new Html($data, 'http://blabla');
+ $this->assertEquals($data, $f->execute());
+ }
+
+ public function testRemoveNoBreakingSpace()
+ {
+ $f = new Html('<p>&nbsp;&nbsp;truc</p>', 'http://blabla');
+ $this->assertEquals('<p> truc</p>', $f->execute());
+ }
+
+ public function testRemoveEmptyTags()
+ {
+ $f = new Html('<p>toto</p><p></p><br/>', 'http://blabla');
+ $this->assertEquals('<p>toto</p><br/>', $f->execute());
+
+ $f = new Html('<p> </p>', 'http://blabla');
+ $this->assertEquals('', $f->execute());
+
+ $f = new Html('<p>&nbsp;</p>', 'http://blabla');
+ $this->assertEquals('', $f->execute());
+ }
+
+ public function testRemoveEmptyTable()
+ {
+ $f = new Html('<table><tr><td> </td></tr></table>', 'http://blabla');
+ $this->assertEquals('', $f->execute());
+
+ $f = new Html('<table><tr></tr></table>', 'http://blabla');
+ $this->assertEquals('', $f->execute());
+ }
+/*
+ public function testFilter()
+ {
+ $input = <<<EOD
+<div xmlns="http://www.w3.org/1999/xhtml"><article>
+<figure>
+ <img src="/2014/08/06/4694-pluie" alt="Flaque de pluie"/>
+ <figcaption>La Saussaye, France, 6 août 2014</figcaption>
+</figure>
+
+<div lang="en" class="extrait">
+ <blockquote cite="urn:isbn:978-0-8248-3742-6">
+ <p>Spring had truly arrived. Countless streams suddenly materialized all over the roads, fields, grasslands, and thickets; flowing as if the melting snow's waters were spilling over. </p>
+ </blockquote>
+ <p class="source"><span class="auteur">Takiji Kobayashi</span>, <cite class="titre">Yasuko</cite>.</p>
+</div>
+
+<p>La pluie abonde. La forêt humide resplendit. L'eau monte, l'eau déborde. Il reste pourtant notre humanité. Toute entière, resplendissante.</p>
+
+</article>
+</div>
+EOD;
+
+ $expected = <<<EOD
+<figure>
+ <img src="http://www.la-grange.net/2014/08/06/4694-pluie" alt="Flaque de pluie"/>
+ <figcaption>La Saussaye, France, 6 août 2014</figcaption>
+</figure>
+
+
+ <blockquote>
+ <p>Spring had truly arrived. Countless streams suddenly materialized all over the roads, fields, grasslands, and thickets; flowing as if the melting snow&#039;s waters were spilling over. </p>
+ </blockquote>
+ <p>Takiji Kobayashi, <cite>Yasuko</cite>.</p>
+
+
+<p>La pluie abonde. La forêt humide resplendit. L&#039;eau monte, l&#039;eau déborde. Il reste pourtant notre humanité. Toute entière, resplendissante.</p>
+EOD;
+
+ $f = new Html($input, 'http://www.la-grange.net/');
+ $this->assertEquals($expected, $f->execute());
+ }*/
+}
diff --git a/3rdparty/fguillot/picofeed/tests/Filter/TagFilterTest.php b/3rdparty/fguillot/picofeed/tests/Filter/TagFilterTest.php
new file mode 100644
index 000000000..86911bbb4
--- /dev/null
+++ b/3rdparty/fguillot/picofeed/tests/Filter/TagFilterTest.php
@@ -0,0 +1,33 @@
+<?php
+namespace PicoFeed\Filter;
+
+use PHPUnit_Framework_TestCase;
+
+
+class TagFilterTest extends PHPUnit_Framework_TestCase
+{
+ public function testAllowedTag()
+ {
+ $tag = new Tag;
+
+ $this->assertTrue($tag->isAllowed('p', array('class' => 'test')));
+ $this->assertTrue($tag->isAllowed('img', array('class' => 'test')));
+
+ $this->assertFalse($tag->isAllowed('script', array('class' => 'test')));
+ $this->assertFalse($tag->isAllowed('img', array('width' => '1', 'height' => '1')));
+ }
+
+ public function testHtml()
+ {
+ $tag = new Tag;
+
+ $this->assertEquals('<p>', $tag->openHtmlTag('p'));
+ $this->assertEquals('<img src="test" alt="truc"/>', $tag->openHtmlTag('img', 'src="test" alt="truc"'));
+ $this->assertEquals('<img/>', $tag->openHtmlTag('img'));
+ $this->assertEquals('<br/>', $tag->openHtmlTag('br'));
+
+ $this->assertEquals('</p>', $tag->closeHtmlTag('p'));
+ $this->assertEquals('', $tag->closeHtmlTag('img'));
+ $this->assertEquals('', $tag->closeHtmlTag('br'));
+ }
+}