From 24eb4c780f531363e90fe2d8248d50189dcb6b38 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Wed, 10 Nov 2010 22:48:16 +0100 Subject: [PATCH] add unit tests for url_is_html and fix a bug with UPPERCASE in it --- functions.php | 4 +- tests/FunctionsTest.php | 121 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 123 insertions(+), 2 deletions(-) diff --git a/functions.php b/functions.php index e73c0d16e..96fa19224 100644 --- a/functions.php +++ b/functions.php @@ -6961,8 +6961,8 @@ */ function url_is_html($url) { $content = substr(fetch_file_contents($url, false), 0, 1000); - if (strpos($content, '') === false - && strpos($content, '') === false + && stripos($content, 'tmpFile = sys_get_temp_dir() . '/tt-rss-unittest.dat'; + } + + public function tearDown() + { + if (file_exists($this->tmpFile)) { + unlink($this->tmpFile); + } + } + /** * Test fix_url with feed:// urls */ @@ -56,6 +69,114 @@ class FunctionsTest extends PHPUnit_Framework_TestCase fix_url('tt-rss.org/foo/bar/baz/') ); } + + + /** + * Test url_is_html() on html with a doctype + */ + public function testUrlIsHtmlNormalHtmlWithDoctype() + { + file_put_contents( + $this->tmpFile, << + + +HTM + ); + $this->assertTrue(url_is_html($this->tmpFile)); + + file_put_contents( + $this->tmpFile, << + + +HTM + ); + $this->assertTrue(url_is_html($this->tmpFile)); + } + + /** + * Test url_is_html() on html with a doctype and xml header + */ + public function testUrlIsHtmlNormalHtmlWithDoctypeAndXml() + { + file_put_contents( + $this->tmpFile, << + + + +HTM + ); + $this->assertTrue(url_is_html($this->tmpFile)); + } + + /** + * Test url_is_html() on html without a doctype + */ + public function testUrlIsHtmlNormalHtmlWithoutDoctype() + { + file_put_contents( + $this->tmpFile, << + +HTM + ); + $this->assertTrue(url_is_html($this->tmpFile)); + } + + /** + * Test url_is_html() on UPPERCASE HTML + */ + public function testUrlIsHtmlNormalHtmlUppercase() + { + file_put_contents( + $this->tmpFile, << + +HTM + ); + $this->assertTrue(url_is_html($this->tmpFile)); + + file_put_contents( + $this->tmpFile, << + +HTM + ); + $this->assertTrue(url_is_html($this->tmpFile)); + } + + /** + * Test url_is_html() on atom + */ + public function testUrlIsHtmlAtom() + { + file_put_contents( + $this->tmpFile, << + + Christians Tagebuch +HTM + ); + $this->assertFalse(url_is_html($this->tmpFile)); + } + + /** + * Test url_is_html() on RSS + */ + public function testUrlIsHtmlRss() + { + file_put_contents( + $this->tmpFile, << + + + <![CDATA[Planet-PEAR]]> +HTM + ); + $this->assertFalse(url_is_html($this->tmpFile)); + } } ?> \ No newline at end of file