summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorBernhard Posselt <nukeawhale@gmail.com>2013-09-02 02:43:25 +0200
committerBernhard Posselt <nukeawhale@gmail.com>2013-09-02 02:43:32 +0200
commit38297af11f458b30af3cbdc42cf3407d6aff44ab (patch)
tree6c61f09234182c78fe291bcd439284c8e77e7ffe /tests
parent1b144268cbb49854aaba1c04c773dcf2f9cf0b7a (diff)
move configuration values into a config file, fix #167
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/utility/ConfigTest.php143
1 files changed, 143 insertions, 0 deletions
diff --git a/tests/unit/utility/ConfigTest.php b/tests/unit/utility/ConfigTest.php
new file mode 100644
index 000000000..849fe37fd
--- /dev/null
+++ b/tests/unit/utility/ConfigTest.php
@@ -0,0 +1,143 @@
+<?php
+
+/**
+* ownCloud - News
+*
+* @author Alessandro Cosentino
+* @author Bernhard Posselt
+* @copyright 2012 Alessandro Cosentino cosenal@gmail.com
+* @copyright 2012 Bernhard Posselt dev@bernhard-posselt.com
+*
+* This library is free software; you can redistribute it and/or
+* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+* License as published by the Free Software Foundation; either
+* version 3 of the License, or any later version.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+*
+* You should have received a copy of the GNU Affero General Public
+* License along with this library. If not, see <http://www.gnu.org/licenses/>.
+*
+*/
+
+namespace OCA\News\Utility;
+
+require_once(__DIR__ . "/../../classloader.php");
+
+
+class ConfigFetcherTest extends \OCA\AppFramework\Utility\TestUtility {
+
+ private $fileSystem;
+ private $config;
+ private $configPath;
+
+ public function setUp() {
+ $this->api = $this->getMockBuilder(
+ '\OCA\AppFramework\Core\API')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->fileSystem = $this->getMock('FileSystem', array(
+ 'file_get_contents',
+ 'file_put_contents',
+ 'file_exists'
+ ));
+ $this->config = new Config($this->fileSystem, $this->api);
+ $this->configPath = 'config.json';
+ }
+
+
+ public function testDefaults() {
+ $this->assertEquals(60, $this->config->getAutoPurgeMinimumInterval());
+ $this->assertEquals(200, $this->config->getAutoPurgeCount());
+ $this->assertEquals(30*60, $this->config->getSimplePieCacheDuration());
+ $this->assertEquals(60, $this->config->getFeedFetcherTimeout());
+ $this->assertEquals(true, $this->config->getUseCronUpdates());
+ }
+
+
+ public function testRead () {
+ $this->fileSystem->expects($this->once())
+ ->method('file_get_contents')
+ ->with($this->equalTo($this->configPath))
+ ->will($this->returnValue('{"autoPurgeCount": 3}'));
+
+ $this->config->read($this->configPath);
+
+ $this->assertEquals(3, $this->config->getAutoPurgeCount());
+ }
+
+
+ public function testReadLogsInvalidValue() {
+ $this->fileSystem->expects($this->once())
+ ->method('file_get_contents')
+ ->with($this->equalTo($this->configPath))
+ ->will($this->returnValue('{"autoPurgeCounts": 3}'));
+ $this->api->expects($this->once())
+ ->method('log')
+ ->with($this->equalTo('Configuration value "autoPurgeCounts" ' .
+ 'does not exist. Ignored value.'),
+ $this->equalTo('warn'));
+
+ $this->config->read($this->configPath);
+ }
+
+
+ public function testReadLogsInvalidJSON() {
+ $this->fileSystem->expects($this->once())
+ ->method('file_get_contents')
+ ->with($this->equalTo($this->configPath))
+ ->will($this->returnValue(null));
+ $this->api->expects($this->once())
+ ->method('log')
+ ->with($this->equalTo('Configuration contains invalid JSON'),
+ $this->equalTo('warn'));
+
+ $this->config->read($this->configPath);
+ }
+
+
+ public function testWrite () {
+ $json = "{\n" .
+ " \"autoPurgeMinimumInterval\": 60,\n" .
+ " \"autoPurgeCount\": 3,\n" .
+ " \"simplePieCacheDuration\": 1800,\n" .
+ " \"feedFetcherTimeout\": 60,\n" .
+ " \"useCronUpdates\": true\n" .
+ "}";
+ $this->config->setAutoPurgeCount(3);
+
+ $this->fileSystem->expects($this->once())
+ ->method('file_put_contents')
+ ->with($this->equalTo($this->configPath),
+ $this->equalTo($json));
+
+ $this->config->write($this->configPath);
+ }
+
+
+ public function testReadingNonExistentConfigWillWriteDefaults() {
+ $this->fileSystem->expects($this->once())
+ ->method('file_exists')
+ ->with($this->equalTo($this->configPath))
+ ->will($this->returnValue(false));
+
+ $json = "{\n" .
+ " \"autoPurgeMinimumInterval\": 60,\n" .
+ " \"autoPurgeCount\": 200,\n" .
+ " \"simplePieCacheDuration\": 1800,\n" .
+ " \"feedFetcherTimeout\": 60,\n" .
+ " \"useCronUpdates\": true\n" .
+ "}";
+
+ $this->fileSystem->expects($this->once())
+ ->method('file_put_contents')
+ ->with($this->equalTo($this->configPath),
+ $this->equalTo($json));
+
+ $this->config->read($this->configPath, true);
+ }
+
+} \ No newline at end of file