summaryrefslogtreecommitdiffstats
path: root/3rdparty/fguillot/picofeed/tests/Filter/AttributeFilterTest.php
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/fguillot/picofeed/tests/Filter/AttributeFilterTest.php')
-rw-r--r--3rdparty/fguillot/picofeed/tests/Filter/AttributeFilterTest.php140
1 files changed, 140 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')));
+ }
+}