2013-03-03 15:06:00 +04:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Copyright (c) 2013 Bart Visscher <bartv@thisnet.nl>
|
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
* later.
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
class Test_Config extends PHPUnit_Framework_TestCase {
|
|
|
|
const CONFIG_FILE = 'static://config.php';
|
|
|
|
const CONFIG_DIR = 'static://';
|
|
|
|
const TESTCONTENT = '<?php $CONFIG=array("foo"=>"bar");';
|
|
|
|
|
2013-07-02 02:15:42 +04:00
|
|
|
/**
|
|
|
|
* @var \OC\Config
|
|
|
|
*/
|
|
|
|
private $config;
|
|
|
|
|
2013-06-28 00:50:28 +04:00
|
|
|
function setUp() {
|
|
|
|
file_put_contents(self::CONFIG_FILE, self::TESTCONTENT);
|
|
|
|
$this->config = new OC\Config(self::CONFIG_DIR);
|
|
|
|
}
|
|
|
|
|
2013-07-05 17:25:53 +04:00
|
|
|
public function testReadData() {
|
2013-06-28 00:50:28 +04:00
|
|
|
$config = new OC\Config('/non-existing');
|
2013-03-03 15:06:00 +04:00
|
|
|
$this->assertAttributeEquals(array(), 'cache', $config);
|
|
|
|
|
2013-07-05 17:25:53 +04:00
|
|
|
$this->assertAttributeEquals(array('foo' => 'bar'), 'cache', $this->config);
|
2013-03-03 15:06:00 +04:00
|
|
|
}
|
|
|
|
|
2013-07-05 17:25:53 +04:00
|
|
|
public function testGetKeys() {
|
2013-06-28 00:50:28 +04:00
|
|
|
$this->assertEquals(array('foo'), $this->config->getKeys());
|
2013-03-03 15:06:00 +04:00
|
|
|
}
|
|
|
|
|
2013-07-05 17:25:53 +04:00
|
|
|
public function testGetValue() {
|
2013-06-28 00:50:28 +04:00
|
|
|
$this->assertEquals('bar', $this->config->getValue('foo'));
|
|
|
|
$this->assertEquals(null, $this->config->getValue('bar'));
|
|
|
|
$this->assertEquals('moo', $this->config->getValue('bar', 'moo'));
|
2013-03-03 15:06:00 +04:00
|
|
|
}
|
|
|
|
|
2013-07-05 17:25:53 +04:00
|
|
|
public function testSetValue() {
|
2013-07-05 17:26:39 +04:00
|
|
|
$this->config->setDebugMode(false);
|
2013-06-28 00:50:28 +04:00
|
|
|
$this->config->setValue('foo', 'moo');
|
2013-07-05 17:25:53 +04:00
|
|
|
$this->assertAttributeEquals(array('foo' => 'moo'), 'cache', $this->config);
|
2013-03-03 15:06:00 +04:00
|
|
|
$content = file_get_contents(self::CONFIG_FILE);
|
|
|
|
|
2013-07-15 12:28:14 +04:00
|
|
|
$expected = "<?php\n\$CONFIG = array (\n 'foo' => 'moo',\n);\n";
|
|
|
|
$this->assertEquals($expected, $content);
|
2013-06-28 00:50:28 +04:00
|
|
|
$this->config->setValue('bar', 'red');
|
2013-07-05 17:25:53 +04:00
|
|
|
$this->assertAttributeEquals(array('foo' => 'moo', 'bar' => 'red'), 'cache', $this->config);
|
2013-03-03 15:06:00 +04:00
|
|
|
$content = file_get_contents(self::CONFIG_FILE);
|
|
|
|
|
2013-07-15 12:28:14 +04:00
|
|
|
$expected = "<?php\n\$CONFIG = array (\n 'foo' => 'moo',\n 'bar' => 'red',\n);\n";
|
|
|
|
$this->assertEquals($expected, $content);
|
2013-03-03 15:06:00 +04:00
|
|
|
}
|
|
|
|
|
2013-07-05 17:25:53 +04:00
|
|
|
public function testDeleteKey() {
|
2013-07-05 17:26:39 +04:00
|
|
|
$this->config->setDebugMode(false);
|
2013-06-28 00:50:28 +04:00
|
|
|
$this->config->deleteKey('foo');
|
|
|
|
$this->assertAttributeEquals(array(), 'cache', $this->config);
|
2013-03-03 15:06:00 +04:00
|
|
|
$content = file_get_contents(self::CONFIG_FILE);
|
|
|
|
|
2013-07-15 12:28:14 +04:00
|
|
|
$expected = "<?php\n\$CONFIG = array (\n);\n";
|
|
|
|
$this->assertEquals($expected, $content);
|
2013-03-03 15:06:00 +04:00
|
|
|
}
|
|
|
|
|
2013-07-05 17:25:53 +04:00
|
|
|
public function testSavingDebugMode() {
|
2013-06-28 00:50:28 +04:00
|
|
|
$this->config->setDebugMode(true);
|
|
|
|
$this->config->deleteKey('foo'); // change something so we save to the config file
|
|
|
|
$this->assertAttributeEquals(array(), 'cache', $this->config);
|
|
|
|
$this->assertAttributeEquals(true, 'debugMode', $this->config);
|
2013-03-03 15:06:00 +04:00
|
|
|
$content = file_get_contents(self::CONFIG_FILE);
|
|
|
|
|
2013-07-15 12:28:14 +04:00
|
|
|
$expected = "<?php\ndefine('DEBUG',true);\n\$CONFIG = array (\n);\n";
|
|
|
|
$this->assertEquals($expected, $content);
|
2013-03-03 15:06:00 +04:00
|
|
|
}
|
|
|
|
|
2013-07-02 02:15:42 +04:00
|
|
|
/**
|
|
|
|
* @expectedException \OC\HintException
|
|
|
|
*/
|
2013-07-05 17:25:53 +04:00
|
|
|
public function testWriteData() {
|
2013-06-28 00:50:28 +04:00
|
|
|
$config = new OC\Config('/non-writable');
|
2013-07-02 02:15:42 +04:00
|
|
|
$config->setValue('foo', 'bar');
|
2013-03-03 15:06:00 +04:00
|
|
|
}
|
|
|
|
}
|