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