From ea8e552ccb6e7d3818b41df1914dccc62cb4b324 Mon Sep 17 00:00:00 2001 From: bastei Date: Sat, 21 Sep 2013 04:27:13 +0200 Subject: ArticleEnhancer: Transform relative to absolute URLs --- .../articleenhancer/ArticleEnhancerTest.php | 92 ++++++++++++++++++++-- 1 file changed, 87 insertions(+), 5 deletions(-) (limited to 'tests/unit') diff --git a/tests/unit/utility/articleenhancer/ArticleEnhancerTest.php b/tests/unit/utility/articleenhancer/ArticleEnhancerTest.php index a7585d771..ce105db49 100644 --- a/tests/unit/utility/articleenhancer/ArticleEnhancerTest.php +++ b/tests/unit/utility/articleenhancer/ArticleEnhancerTest.php @@ -57,8 +57,9 @@ class ArticleEnhancerTest extends \OCA\AppFramework\Utility\TestUtility { $this->purifier, $this->fileFactory, array( - '/explosm.net\/comics/' => '//*[@id=\'maincontent\']/div[2]/div/img', + '/explosm.net\/comics/' => '//*[@id=\'maincontent\']/div[2]/div/span', '/explosm.net\/shorts/' => '//*[@id=\'maincontent\']/div/div', + '/explosm.net\/all/' => '//body/*', '/themerepublic.net/' => '//*[@class=\'post hentry\']' ), $this->timeout @@ -80,7 +81,7 @@ class ArticleEnhancerTest extends \OCA\AppFramework\Utility\TestUtility {
nooo
-
+
hiho
'; @@ -95,11 +96,11 @@ class ArticleEnhancerTest extends \OCA\AppFramework\Utility\TestUtility { ->will($this->returnValue($file)); $this->purifier->expects($this->once()) ->method('purify') - ->with($this->equalTo('')) - ->will($this->returnValue('')); + ->with($this->equalTo('hiho')) + ->will($this->returnValue('hiho')); $result = $this->testEnhancer->enhance($item); - $this->assertEquals('', $result->getBody()); + $this->assertEquals('hiho', $result->getBody()); } @@ -212,4 +213,85 @@ class ArticleEnhancerTest extends \OCA\AppFramework\Utility\TestUtility { } + public function testTransformRelativeUrls() { + $file = new \stdClass; + $file->headers = array("content-type"=>"text/html; charset=utf-8"); + $file->body = ' + + link + link2 + + + '; + $item = new Item(); + $item->setUrl('https://www.explosm.net/all/312'); + $item->setBody('Hello thar'); + + $this->fileFactory->expects($this->once()) + ->method('getFile') + ->with($this->equalTo($item->getUrl()), + $this->equalTo($this->timeout)) + ->will($this->returnValue($file)); + $this->purifier->expects($this->once()) + ->method('purify') + ->with($this->equalTo('linklink2')) + ->will($this->returnValue('linklink2')); + + $result = $this->testEnhancer->enhance($item); + $this->assertEquals('linklink2', $result->getBody()); + } + + public function testTransformRelativeUrlSpecials() { + $file = new \stdClass; + $file->headers = array("content-type"=>"text/html; charset=utf-8"); + $file->body = ' + + + + '; + $item = new Item(); + $item->setUrl('https://username:secret@www.explosm.net/all/312'); + $item->setBody('Hello thar'); + + $this->fileFactory->expects($this->once()) + ->method('getFile') + ->with($this->equalTo($item->getUrl()), + $this->equalTo($this->timeout)) + ->will($this->returnValue($file)); + $this->purifier->expects($this->once()) + ->method('purify') + ->with($this->equalTo('')) + ->will($this->returnValue('')); + + $result = $this->testEnhancer->enhance($item); + $this->assertEquals('', $result->getBody()); + } + + public function testDontTransformAbsoluteUrlsAndMails() { + $file = new \stdClass; + $file->headers = array("content-type"=>"text/html; charset=utf-8"); + $file->body = ' + + + mail + + '; + $item = new Item(); + $item->setUrl('https://www.explosm.net/all/312'); + $item->setBody('Hello thar'); + + $this->fileFactory->expects($this->once()) + ->method('getFile') + ->with($this->equalTo($item->getUrl()), + $this->equalTo($this->timeout)) + ->will($this->returnValue($file)); + $this->purifier->expects($this->once()) + ->method('purify') + ->with($this->equalTo('mail')) + ->will($this->returnValue('mail')); + + $result = $this->testEnhancer->enhance($item); + $this->assertEquals('mail', $result->getBody()); + } + } \ No newline at end of file -- cgit v1.2.3