From 4d7f53380d31154709faa3f9d6cdc467ff141951 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Thu, 29 Aug 2013 13:30:38 +0200 Subject: allow more than one article enhancer per url based on the url regex, also allow embedded youtube videos that start with // --- .../articleenhancer/ArticleEnhancerTest.php | 45 ++++++++++++++++++---- 1 file changed, 38 insertions(+), 7 deletions(-) (limited to 'tests') diff --git a/tests/unit/utility/articleenhancer/ArticleEnhancerTest.php b/tests/unit/utility/articleenhancer/ArticleEnhancerTest.php index c808a0e49..5f82a4752 100644 --- a/tests/unit/utility/articleenhancer/ArticleEnhancerTest.php +++ b/tests/unit/utility/articleenhancer/ArticleEnhancerTest.php @@ -31,10 +31,10 @@ require_once(__DIR__ . "/../../../classloader.php"); class TestEnhancer extends ArticleEnhancer { - public function __construct($purifier, $fileFactory, $articleRegex, - $articleXPATH, $timeout){ - parent::__construct($purifier, $fileFactory, $articleRegex, - $articleXPATH, $timeout); + public function __construct($purifier, $fileFactory, $regexXPathPair, + $timeout){ + parent::__construct($purifier, $fileFactory, $regexXPathPair, + $timeout); } } @@ -56,8 +56,10 @@ class ArticleEnhancerTest extends \OCA\AppFramework\Utility\TestUtility { $this->testEnhancer = new TestEnhancer( $this->purifier, $this->fileFactory, - '/explosm.net\/comics/', - '//*[@id=\'maincontent\']/div[2]/img', + array( + '/explosm.net\/comics/' => '//*[@id=\'maincontent\']/div[2]/div/img', + '/explosm.net\/shorts/' => '//*[@id=\'maincontent\']/div[2]/div' + ), $this->timeout ); } @@ -76,7 +78,7 @@ class ArticleEnhancerTest extends \OCA\AppFramework\Utility\TestUtility {
nooo
-
+
'; @@ -99,6 +101,35 @@ class ArticleEnhancerTest extends \OCA\AppFramework\Utility\TestUtility { } + public function testDoesModifiyAllArticlesThatMatch() { + $file = new \stdClass; + $file->body = ' + +
+
nooo
+
rawr
+
+ + '; + $item = new Item(); + $item->setUrl('https://www.explosm.net/shorts/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('
rawr
')) + ->will($this->returnValue('
rawr
')); + + $result = $this->testEnhancer->enhance($item); + $this->assertEquals('
rawr
', $result->getBody()); + } + + public function testModificationHandlesEmptyResults() { $file = new \stdClass; $file->body = ' -- cgit v1.2.3