diff options
author | Bernhard Posselt <dev@bernhard-posselt.com> | 2014-12-17 09:01:54 +0100 |
---|---|---|
committer | Bernhard Posselt <dev@bernhard-posselt.com> | 2014-12-17 09:02:13 +0100 |
commit | 867cb7dbf960dc0cfbf7e59d656d1337bb59c526 (patch) | |
tree | 5bbdf1eef51cd3747f55ef2c524364f9cd3bf029 /vendor/fguillot/picofeed/tests/Filter | |
parent | a813b535eeb517e0ccd69a90d0058756014a1e01 (diff) |
update picofeed, fix #695
Diffstat (limited to 'vendor/fguillot/picofeed/tests/Filter')
-rw-r--r-- | vendor/fguillot/picofeed/tests/Filter/AttributeFilterTest.php | 49 | ||||
-rw-r--r-- | vendor/fguillot/picofeed/tests/Filter/FilterTest.php | 35 |
2 files changed, 77 insertions, 7 deletions
diff --git a/vendor/fguillot/picofeed/tests/Filter/AttributeFilterTest.php b/vendor/fguillot/picofeed/tests/Filter/AttributeFilterTest.php index e4de74aaf..b0de530e7 100644 --- a/vendor/fguillot/picofeed/tests/Filter/AttributeFilterTest.php +++ b/vendor/fguillot/picofeed/tests/Filter/AttributeFilterTest.php @@ -43,35 +43,70 @@ class AttributeFilterTest extends PHPUnit_Framework_TestCase $this->assertEquals(array('src' => 'http://www.youtube.com/test'), $filter->filter('iframe', array('width' => 'test', 'src' => 'http://www.youtube.com/test'))); } - public function testFilterAbsoluteUrlAttribute() + public function testRewriteProxyImageUrl() { $filter = new Attribute(new Url('http://www.la-grange.net')); $url = '/2014/08/03/4668-noisettes'; - $this->assertTrue($filter->filterAbsoluteUrlAttribute('a', 'href', $url)); + $this->assertTrue($filter->rewriteImageProxyUrl('a', 'href', $url)); + $this->assertEquals('/2014/08/03/4668-noisettes', $url); + + $filter = new Attribute(new Url('http://www.la-grange.net')); + $url = '/2014/08/03/4668-noisettes'; + $this->assertTrue($filter->rewriteImageProxyUrl('img', 'alt', $url)); + $this->assertEquals('/2014/08/03/4668-noisettes', $url); + + $filter = new Attribute(new Url('http://www.la-grange.net')); + $url = '/2014/08/03/4668-noisettes'; + $this->assertTrue($filter->rewriteImageProxyUrl('img', 'src', $url)); + $this->assertEquals('/2014/08/03/4668-noisettes', $url); + + $filter = new Attribute(new Url('http://www.la-grange.net')); + $filter->setImageProxyUrl('https://myproxy/?u=%s'); + $url = 'http://example.net/image.png'; + $this->assertTrue($filter->rewriteImageProxyUrl('img', 'src', $url)); + $this->assertEquals('https://myproxy/?u='.urlencode('http://example.net/image.png'), $url); + + $filter = new Attribute(new Url('http://www.la-grange.net')); + + $filter->setImageProxyCallback(function ($image_url) { + $key = hash_hmac('sha1', $image_url, 'secret'); + return 'https://mypublicproxy/'.$key.'/'.urlencode($image_url); + }); + + $url = 'http://example.net/image.png'; + $this->assertTrue($filter->rewriteImageProxyUrl('img', 'src', $url)); + $this->assertEquals('https://mypublicproxy/d9701029b054f6e178ef88fcd3c789365e52a26d/'.urlencode('http://example.net/image.png'), $url); + } + + public function testRewriteAbsoluteUrl() + { + $filter = new Attribute(new Url('http://www.la-grange.net')); + $url = '/2014/08/03/4668-noisettes'; + $this->assertTrue($filter->rewriteAbsoluteUrl('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->assertTrue($filter->rewriteAbsoluteUrl('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->assertTrue($filter->rewriteAbsoluteUrl('img', 'src', $url)); $this->assertEquals('http://127.0.0.1:8000/test', $url); $url = '//example.com'; - $this->assertTrue($filter->filterAbsoluteUrlAttribute('a', 'href', $url)); + $this->assertTrue($filter->rewriteAbsoluteUrl('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->assertTrue($filter->rewriteAbsoluteUrl('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->assertTrue($filter->rewriteAbsoluteUrl('a', 'href', $url)); $this->assertEquals('https://127.0.0.1:8000/here/image.png?v=2', $url); $filter = new Attribute(new Url('https://truc/')); diff --git a/vendor/fguillot/picofeed/tests/Filter/FilterTest.php b/vendor/fguillot/picofeed/tests/Filter/FilterTest.php index f3b736dfb..8bbb2b97c 100644 --- a/vendor/fguillot/picofeed/tests/Filter/FilterTest.php +++ b/vendor/fguillot/picofeed/tests/Filter/FilterTest.php @@ -85,4 +85,39 @@ class FilterTest extends PHPUnit_Framework_TestCase $f->setConfig($config); $this->assertEquals('<p>Testboo</p>', $f->execute()); } + + public function testImageProxy() + { + $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() + ); + + $config = new Config; + $config->setFilterImageProxyUrl('http://myproxy/?url=%s'); + + $f = Filter::html('<p>Image <img src="/image.png" alt="My Image"/></p>', 'http://foo'); + $f->setConfig($config); + + $this->assertEquals( + '<p>Image <img src="http://myproxy/?url='.urlencode('http://foo/image.png').'" alt="My Image"/></p>', + $f->execute() + ); + + $config = new Config; + $config->setFilterImageProxyCallback(function ($image_url) { + $key = hash_hmac('sha1', $image_url, 'secret'); + return 'https://mypublicproxy/'.$key.'/'.urlencode($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/'.urlencode('http://foo/image.png').'" alt="My Image"/></p>', + $f->execute() + ); + } }
\ No newline at end of file |