summaryrefslogtreecommitdiffstats
path: root/tests
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
parentfa73d339df403506d58104ee60575972b88bfc09 (diff)
fix #454, allow global enhancers
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/articleenhancer/EnhancerTest.php35
-rw-r--r--tests/unit/articleenhancer/GlobalArticleEnhancerTest.php49
-rw-r--r--tests/unit/utility/ConfigTest.php45
3 files changed, 108 insertions, 21 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());
+ }
+
+}
diff --git a/tests/unit/utility/ConfigTest.php b/tests/unit/utility/ConfigTest.php
index 578949b4e..ad26035f5 100644
--- a/tests/unit/utility/ConfigTest.php
+++ b/tests/unit/utility/ConfigTest.php
@@ -59,11 +59,24 @@ class ConfigTest extends \PHPUnit_Framework_TestCase {
$this->config->read($this->configPath);
- $this->assertTrue(3 === $this->config->getAutoPurgeCount());
- $this->assertTrue(true === $this->config->getUseCronUpdates());
+ $this->assertSame(3, $this->config->getAutoPurgeCount());
+ $this->assertSame(true, $this->config->getUseCronUpdates());
}
+ public function testReadIgnoresVeryLowPurgeInterval () {
+ $this->fileSystem->expects($this->once())
+ ->method('file_get_contents')
+ ->with($this->equalTo($this->configPath))
+ ->will($this->returnValue("autoPurgeMinimumInterval = 59"));
+
+ $this->config->read($this->configPath);
+
+ $this->assertSame(60, $this->config->getAutoPurgeMinimumInterval());
+ }
+
+
+
public function testReadBool () {
$this->fileSystem->expects($this->once())
->method('file_get_contents')
@@ -72,8 +85,8 @@ class ConfigTest extends \PHPUnit_Framework_TestCase {
$this->config->read($this->configPath);
- $this->assertTrue(3 === $this->config->getAutoPurgeCount());
- $this->assertTrue(false === $this->config->getUseCronUpdates());
+ $this->assertSame(3, $this->config->getAutoPurgeCount());
+ $this->assertSame(false, $this->config->getUseCronUpdates());
}
@@ -84,8 +97,8 @@ class ConfigTest extends \PHPUnit_Framework_TestCase {
->will($this->returnValue('autoPurgeCounts = 3'));
$this->logger->expects($this->once())
->method('warning')
- ->with($this->equalTo('Configuration value "autoPurgeCounts" ' .
- 'does not exist. Ignored value.'),
+ ->with($this->equalTo('Configuration value "autoPurgeCounts" ' .
+ 'does not exist. Ignored value.'),
$this->equalTo($this->loggerParams));
$this->config->read($this->configPath);
@@ -99,7 +112,7 @@ class ConfigTest extends \PHPUnit_Framework_TestCase {
->will($this->returnValue(''));
$this->logger->expects($this->once())
->method('warning')
- ->with($this->equalTo('Configuration invalid. Ignoring values.'),
+ ->with($this->equalTo('Configuration invalid. Ignoring values.'),
$this->equalTo($this->loggerParams));
$this->config->read($this->configPath);
@@ -107,10 +120,10 @@ class ConfigTest extends \PHPUnit_Framework_TestCase {
public function testWrite () {
- $json = "autoPurgeMinimumInterval = 60\n" .
- "autoPurgeCount = 3\n" .
- "simplePieCacheDuration = 1800\n" .
- "feedFetcherTimeout = 60\n" .
+ $json = "autoPurgeMinimumInterval = 60\n" .
+ "autoPurgeCount = 3\n" .
+ "simplePieCacheDuration = 1800\n" .
+ "feedFetcherTimeout = 60\n" .
"useCronUpdates = true\n" .
"proxyHost = yo man\n" .
"proxyPort = 12\n" .
@@ -141,13 +154,13 @@ class ConfigTest extends \PHPUnit_Framework_TestCase {
->method('file_exists')
->with($this->equalTo($this->configPath))
->will($this->returnValue(false));
-
+
$this->config->setUseCronUpdates(false);
- $json = "autoPurgeMinimumInterval = 60\n" .
- "autoPurgeCount = 200\n" .
- "simplePieCacheDuration = 1800\n" .
- "feedFetcherTimeout = 60\n" .
+ $json = "autoPurgeMinimumInterval = 60\n" .
+ "autoPurgeCount = 200\n" .
+ "simplePieCacheDuration = 1800\n" .
+ "feedFetcherTimeout = 60\n" .
"useCronUpdates = false\n" .
"proxyHost = \n" .
"proxyPort = 8080\n" .