diff options
Diffstat (limited to 'vendor/fguillot/picofeed/tests/Filter/FilterTest.php')
-rw-r--r-- | vendor/fguillot/picofeed/tests/Filter/FilterTest.php | 161 |
1 files changed, 30 insertions, 131 deletions
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 |