summaryrefslogtreecommitdiffstats
path: root/tests/unit/articleenhancer
diff options
context:
space:
mode:
authorBernhard Posselt <dev@bernhard-posselt.com>2014-09-22 12:14:23 +0200
committerBernhard Posselt <dev@bernhard-posselt.com>2014-09-22 12:14:23 +0200
commit19910df42e93ef370048e8d0d2609af71bf46676 (patch)
tree2a9557b219a6f3d8efb830333900473a93241b19 /tests/unit/articleenhancer
parentfa73d339df403506d58104ee60575972b88bfc09 (diff)
fix #454, allow global enhancers
Diffstat (limited to 'tests/unit/articleenhancer')
-rw-r--r--tests/unit/articleenhancer/EnhancerTest.php35
-rw-r--r--tests/unit/articleenhancer/GlobalArticleEnhancerTest.php49
2 files changed, 79 insertions, 5 deletions
diff --git a/tests/unit/articleenhancer/EnhancerTest.php b/tests/unit/articleenhancer/EnhancerTest.php
index 129b88fd7..2223b1d06 100644
--- a/tests/unit/articleenhancer/EnhancerTest.php
+++ b/tests/unit/articleenhancer/EnhancerTest.php
@@ -16,6 +16,15 @@ namespace OCA\News\ArticleEnhancer;
use \OCA\News\Db\Item;
+class AddEnhancer implements ArticleEnhancer {
+ public function enhance(Item $item) {
+ $body = $item->getBody();
+ $item->setBody($body += 1);
+ return $item;
+ }
+}
+
+
class EnhancerTest extends \PHPUnit_Framework_TestCase {
private $enhancer;
@@ -43,19 +52,19 @@ class EnhancerTest extends \PHPUnit_Framework_TestCase {
'http://test.com/',
'http://www.test.com'
];
- for ($i=0; $i < count($urls); $i++) {
+ for ($i=0; $i < count($urls); $i++) {
$this->articleEnhancer->expects($this->at($i))
->method('enhance')
->with($this->equalTo($item))
->will($this->returnValue($item));
}
- for ($i=0; $i < count($urls); $i++) {
+ for ($i=0; $i < count($urls); $i++) {
$url = $urls[$i];
$result = $this->enhancer->enhance($item, $url);
$this->assertEquals($item, $result);
}
-
+
}
@@ -67,10 +76,26 @@ class EnhancerTest extends \PHPUnit_Framework_TestCase {
$this->articleEnhancer->expects($this->never())
->method('enhance');
- $result = $this->enhancer->enhance($item, $url);
+ $result = $this->enhancer->enhance($item, $url);
$this->assertEquals($item, $result);
-
}
+ public function testGlobalEnhancer() {
+ $this->enhancer->registerGlobalEnhancer(
+ new AddEnhancer()
+ );
+
+ $this->enhancer->registerGlobalEnhancer(
+ new AddEnhancer()
+ );
+
+ $item = new Item();
+ $item->setBody(1);
+
+ $result = $this->enhancer->enhance($item, 'test');
+
+ $this->assertEquals(3, $item->getBody());
+ }
+
} \ No newline at end of file
diff --git a/tests/unit/articleenhancer/GlobalArticleEnhancerTest.php b/tests/unit/articleenhancer/GlobalArticleEnhancerTest.php
new file mode 100644
index 000000000..4b0db31a1
--- /dev/null
+++ b/tests/unit/articleenhancer/GlobalArticleEnhancerTest.php
@@ -0,0 +1,49 @@
+<?php
+/**
+ * ownCloud - News
+ *
+ * This file is licensed under the Affero General Public License version 3 or
+ * later. See the COPYING file.
+ *
+ * @author Alessandro Cosentino <cosenal@gmail.com>
+ * @author Bernhard Posselt <dev@bernhard-posselt.com>
+ * @copyright Alessandro Cosentino 2012
+ * @copyright Bernhard Posselt 2012, 2014
+ */
+
+namespace OCA\News\ArticleEnhancer;
+
+use \OCA\News\Db\Item;
+
+
+class GlobalArticleEnhancerTest extends \PHPUnit_Framework_TestCase {
+
+ private $enhancer;
+
+ protected function setUp() {
+ $this->enhancer = new GlobalArticleEnhancer();
+ }
+
+
+ public function testNoReplaceYoutubeAutoplay() {
+ $body = '<iframe width="728" height="410" src="//www.youtube.com/embed/AWE6UpXQoGU?autoplay=0" frameborder="0" allowfullscreen=""></iframe>';
+ $expected = '<iframe width="728" height="410" src="//www.youtube.com/embed/AWE6UpXQoGU?autoplay=0" frameborder="0" allowfullscreen=""></iframe>';
+ $item = new Item();
+ $item->setBody($body);
+
+ $result = $this->enhancer->enhance($item);
+ $this->assertEquals($expected, $result->getBody());
+ }
+
+
+ public function testReplaceYoutubeAutoplay() {
+ $body = 'test <iframe width="728" height="410" src="//www.youtube.com/embed/AWE6UpXQoGU?tst=1&autoplay=1&abc=1" frameborder="0" allowfullscreen=""></iframe>';
+ $expected = '<p>test <iframe width="728" height="410" src="//www.youtube.com/embed/AWE6UpXQoGU?tst=1&amp;autoplay=0&amp;abc=1" frameborder="0" allowfullscreen=""></iframe></p>';
+ $item = new Item();
+ $item->setBody($body);
+
+ $result = $this->enhancer->enhance($item);
+ $this->assertEquals($expected, $result->getBody());
+ }
+
+}