summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorBernhard Posselt <nukeawhale@gmail.com>2013-08-29 13:30:38 +0200
committerBernhard Posselt <nukeawhale@gmail.com>2013-08-29 13:30:38 +0200
commit4d7f53380d31154709faa3f9d6cdc467ff141951 (patch)
treefdbe6e2e76b7b3c3483cc50216aaac8ffd34dc07 /tests
parenta73fe145a2856d6d075f8541f28c70b5cf01e1db (diff)
allow more than one article enhancer per url based on the url regex, also allow embedded youtube videos that start with //
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/utility/articleenhancer/ArticleEnhancerTest.php45
1 files changed, 38 insertions, 7 deletions
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 {
<body>
<div id="maincontent">
<div>nooo</div>
- <div><img src="hiho"></div>
+ <div><div><img src="hiho"></div></div>
</div>
</body>
</html>';
@@ -99,6 +101,35 @@ class ArticleEnhancerTest extends \OCA\AppFramework\Utility\TestUtility {
}
+ public function testDoesModifiyAllArticlesThatMatch() {
+ $file = new \stdClass;
+ $file->body = '<html>
+ <body>
+ <div id="maincontent">
+ <div>nooo</div>
+ <div><div>rawr</div></div>
+ </div>
+ </body>
+ </html>';
+ $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('<div>rawr</div>'))
+ ->will($this->returnValue('<div>rawr</div>'));
+
+ $result = $this->testEnhancer->enhance($item);
+ $this->assertEquals('<div>rawr</div>', $result->getBody());
+ }
+
+
public function testModificationHandlesEmptyResults() {
$file = new \stdClass;
$file->body = '<html>