From 19910df42e93ef370048e8d0d2609af71bf46676 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Mon, 22 Sep 2014 12:14:23 +0200 Subject: fix #454, allow global enhancers --- tests/unit/articleenhancer/EnhancerTest.php | 35 +++++++++++++--- .../articleenhancer/GlobalArticleEnhancerTest.php | 49 ++++++++++++++++++++++ tests/unit/utility/ConfigTest.php | 45 +++++++++++++------- 3 files changed, 108 insertions(+), 21 deletions(-) create mode 100644 tests/unit/articleenhancer/GlobalArticleEnhancerTest.php (limited to 'tests') 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 @@ + + * @author Bernhard Posselt + * @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 = ''; + $expected = ''; + $item = new Item(); + $item->setBody($body); + + $result = $this->enhancer->enhance($item); + $this->assertEquals($expected, $result->getBody()); + } + + + public function testReplaceYoutubeAutoplay() { + $body = 'test '; + $expected = '

test

'; + $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" . -- cgit v1.2.3