aboutsummaryrefslogtreecommitdiffstats
path: root/tests/core
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2016-01-25 10:02:51 +0100
committerThomas Müller <thomas.mueller@tmit.eu>2016-01-25 10:02:51 +0100
commitce753231eb3ed36a2f5250a2b9cc118fad8dad37 (patch)
tree39b200aa2889ad621075ed519336f0aa3fd03e00 /tests/core
parent9d36972e0f3741c581b3307c5454d8829dfbfcd4 (diff)
parentf2cb03e1553e50a7aa93197ba2c9805681d3d768 (diff)
downloadnextcloud-server-ce753231eb3ed36a2f5250a2b9cc118fad8dad37.tar.gz
nextcloud-server-ce753231eb3ed36a2f5250a2b9cc118fad8dad37.zip
Merge pull request #18444 from owncloud/occ-config-types
occ config:system:set can now set other value types
Diffstat (limited to 'tests/core')
-rw-r--r--tests/core/command/config/system/deleteconfigtest.php110
-rw-r--r--tests/core/command/config/system/getconfigtest.php18
-rw-r--r--tests/core/command/config/system/setconfigtest.php146
3 files changed, 222 insertions, 52 deletions
diff --git a/tests/core/command/config/system/deleteconfigtest.php b/tests/core/command/config/system/deleteconfigtest.php
index aa1f93274c7..11bfb6ae7ad 100644
--- a/tests/core/command/config/system/deleteconfigtest.php
+++ b/tests/core/command/config/system/deleteconfigtest.php
@@ -50,32 +50,31 @@ class DeleteConfigTest extends TestCase {
$this->command = new DeleteConfig($systemConfig);
}
-
public function deleteData() {
return [
[
- 'name',
+ 'name1',
true,
true,
0,
'info',
],
[
- 'name',
+ 'name2',
true,
false,
0,
'info',
],
[
- 'name',
+ 'name3',
false,
false,
0,
'info',
],
[
- 'name',
+ 'name4',
false,
true,
1,
@@ -105,7 +104,7 @@ class DeleteConfigTest extends TestCase {
$this->consoleInput->expects($this->once())
->method('getArgument')
->with('name')
- ->willReturn($configName);
+ ->willReturn([$configName]);
$this->consoleInput->expects($this->any())
->method('hasParameterOption')
->with('--error-if-not-exists')
@@ -117,4 +116,103 @@ class DeleteConfigTest extends TestCase {
$this->assertSame($expectedReturn, $this->invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]));
}
+
+ public function deleteArrayData() {
+ return [
+ [
+ ['name', 'sub'],
+ true,
+ false,
+ true,
+ true,
+ 0,
+ 'info',
+ ],
+ [
+ ['name', 'sub', '2sub'],
+ true,
+ false,
+ ['sub' => ['2sub' => 1], 'sub2' => false],
+ ['sub' => [], 'sub2' => false],
+ 0,
+ 'info',
+ ],
+ [
+ ['name', 'sub3'],
+ true,
+ false,
+ ['sub' => ['2sub' => 1], 'sub2' => false],
+ ['sub' => ['2sub' => 1], 'sub2' => false],
+ 0,
+ 'info',
+ ],
+ [
+ ['name', 'sub'],
+ false,
+ true,
+ true,
+ true,
+ 1,
+ 'error',
+ ],
+ [
+ ['name', 'sub'],
+ true,
+ true,
+ true,
+ true,
+ 1,
+ 'error',
+ ],
+ [
+ ['name', 'sub3'],
+ true,
+ true,
+ ['sub' => ['2sub' => 1], 'sub2' => false],
+ ['sub' => ['2sub' => 1], 'sub2' => false],
+ 1,
+ 'error',
+ ],
+ ];
+ }
+
+ /**
+ * @dataProvider deleteArrayData
+ *
+ * @param string[] $configNames
+ * @param bool $configKeyExists
+ * @param bool $checkIfKeyExists
+ * @param mixed $configValue
+ * @param mixed $updateValue
+ * @param int $expectedReturn
+ * @param string $expectedMessage
+ */
+ public function testArrayDelete(array $configNames, $configKeyExists, $checkIfKeyExists, $configValue, $updateValue, $expectedReturn, $expectedMessage) {
+ $this->systemConfig->expects(($checkIfKeyExists) ? $this->once() : $this->never())
+ ->method('getKeys')
+ ->willReturn($configKeyExists ? [$configNames[0]] : []);
+
+ $this->systemConfig->expects(($configKeyExists) ? $this->once() : $this->never())
+ ->method('getValue')
+ ->willReturn($configValue);
+
+ $this->systemConfig->expects(($expectedReturn === 0) ? $this->once() : $this->never())
+ ->method('setValue')
+ ->with($configNames[0], $updateValue);
+
+ $this->consoleInput->expects($this->once())
+ ->method('getArgument')
+ ->with('name')
+ ->willReturn($configNames);
+ $this->consoleInput->expects($this->any())
+ ->method('hasParameterOption')
+ ->with('--error-if-not-exists')
+ ->willReturn($checkIfKeyExists);
+
+ $this->consoleOutput->expects($this->any())
+ ->method('writeln')
+ ->with($this->stringContains($expectedMessage));
+
+ $this->assertSame($expectedReturn, $this->invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]));
+ }
}
diff --git a/tests/core/command/config/system/getconfigtest.php b/tests/core/command/config/system/getconfigtest.php
index 54dcdd434ab..ebbea634cde 100644
--- a/tests/core/command/config/system/getconfigtest.php
+++ b/tests/core/command/config/system/getconfigtest.php
@@ -90,13 +90,19 @@ class GetConfigTest extends TestCase {
['name', ['a' => 1, 'b' => 2], true, null, false, 'json', 0, json_encode(['a' => 1, 'b' => 2])],
['name', ['a' => 1, 'b' => 2], true, null, false, 'plain', 0, "a: 1\nb: 2"],
+ // Nested depth
+ [['name', 'a'], ['a' => 1, 'b' => 2], true, null, false, 'json', 0, json_encode(1)],
+ [['name', 'a'], ['a' => 1, 'b' => 2], true, null, false, 'plain', 0, '1'],
+ [['name', 'c'], ['a' => 1, 'b' => 2], true, true, true, 'json', 0, json_encode(true)],
+ [['name', 'c'], ['a' => 1, 'b' => 2], true, true, false, 'json', 1, null],
+
];
}
/**
* @dataProvider getData
*
- * @param string $configName
+ * @param string[] $configNames
* @param mixed $value
* @param bool $configExists
* @param mixed $defaultValue
@@ -105,7 +111,13 @@ class GetConfigTest extends TestCase {
* @param int $expectedReturn
* @param string $expectedMessage
*/
- public function testGet($configName, $value, $configExists, $defaultValue, $hasDefault, $outputFormat, $expectedReturn, $expectedMessage) {
+ public function testGet($configNames, $value, $configExists, $defaultValue, $hasDefault, $outputFormat, $expectedReturn, $expectedMessage) {
+ if (is_array($configNames)) {
+ $configName = $configNames[0];
+ } else {
+ $configName = $configNames;
+ $configNames = [$configName];
+ }
$this->systemConfig->expects($this->atLeastOnce())
->method('getKeys')
->willReturn($configExists ? [$configName] : []);
@@ -122,7 +134,7 @@ class GetConfigTest extends TestCase {
$this->consoleInput->expects($this->once())
->method('getArgument')
->with('name')
- ->willReturn($configName);
+ ->willReturn($configNames);
$this->consoleInput->expects($this->any())
->method('getOption')
->willReturnMap([
diff --git a/tests/core/command/config/system/setconfigtest.php b/tests/core/command/config/system/setconfigtest.php
index bbabee9b18f..c0b664d7522 100644
--- a/tests/core/command/config/system/setconfigtest.php
+++ b/tests/core/command/config/system/setconfigtest.php
@@ -53,63 +53,123 @@ class SetConfigTest extends TestCase {
public function setData() {
return [
- [
- 'name',
- 'newvalue',
- true,
- true,
- true,
- 'info',
- ],
- [
- 'name',
- 'newvalue',
- false,
- true,
- false,
- 'comment',
- ],
+ [['name'], 'newvalue', null, 'newvalue'],
+ [['a', 'b', 'c'], 'foobar', null, ['b' => ['c' => 'foobar']]],
+ [['a', 'b', 'c'], 'foobar', ['b' => ['d' => 'barfoo']], ['b' => ['d' => 'barfoo', 'c' => 'foobar']]],
];
}
/**
* @dataProvider setData
*
- * @param string $configName
- * @param mixed $newValue
- * @param bool $configExists
- * @param bool $updateOnly
- * @param bool $updated
- * @param string $expectedMessage
+ * @param array $configNames
+ * @param string $newValue
+ * @param mixed $existingData
+ * @param mixed $expectedValue
*/
- public function testSet($configName, $newValue, $configExists, $updateOnly, $updated, $expectedMessage) {
+ public function testSet($configNames, $newValue, $existingData, $expectedValue) {
$this->systemConfig->expects($this->once())
- ->method('getKeys')
- ->willReturn($configExists ? [$configName] : []);
+ ->method('setValue')
+ ->with($configNames[0], $expectedValue);
+ $this->systemConfig->method('getValue')
+ ->with($configNames[0])
+ ->willReturn($existingData);
- if ($updated) {
- $this->systemConfig->expects($this->once())
- ->method('setValue')
- ->with($configName, $newValue);
- }
+ $this->consoleInput->expects($this->once())
+ ->method('getArgument')
+ ->with('name')
+ ->willReturn($configNames);
+ $this->consoleInput->method('getOption')
+ ->will($this->returnValueMap([
+ ['value', $newValue],
+ ['type', 'string'],
+ ]));
+
+ $this->invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]);
+ }
+
+ public function setUpdateOnlyProvider() {
+ return [
+ [['name'], null],
+ [['a', 'b', 'c'], null],
+ [['a', 'b', 'c'], ['b' => 'foobar']],
+ [['a', 'b', 'c'], ['b' => ['d' => 'foobar']]],
+ ];
+ }
+
+ /**
+ * @dataProvider setUpdateOnlyProvider
+ * @expectedException \UnexpectedValueException
+ */
+ public function testSetUpdateOnly($configNames, $existingData) {
+ $this->systemConfig->expects($this->never())
+ ->method('setValue');
+ $this->systemConfig->method('getValue')
+ ->with($configNames[0])
+ ->willReturn($existingData);
+ $this->systemConfig->method('getKeys')
+ ->willReturn($existingData ? $configNames[0] : []);
$this->consoleInput->expects($this->once())
->method('getArgument')
->with('name')
- ->willReturn($configName);
- $this->consoleInput->expects($this->any())
- ->method('getOption')
- ->with('value')
- ->willReturn($newValue);
- $this->consoleInput->expects($this->any())
- ->method('hasParameterOption')
- ->with('--update-only')
- ->willReturn($updateOnly);
-
- $this->consoleOutput->expects($this->any())
- ->method('writeln')
- ->with($this->stringContains($expectedMessage));
+ ->willReturn($configNames);
+ $this->consoleInput->method('getOption')
+ ->will($this->returnValueMap([
+ ['value', 'foobar'],
+ ['type', 'string'],
+ ['update-only', true],
+ ]));
$this->invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]);
}
+
+ public function castValueProvider() {
+ return [
+ [null, 'string', ['value' => '', 'readable-value' => 'empty string']],
+
+ ['abc', 'string', ['value' => 'abc', 'readable-value' => 'string abc']],
+
+ ['123', 'integer', ['value' => 123, 'readable-value' => 'integer 123']],
+ ['456', 'int', ['value' => 456, 'readable-value' => 'integer 456']],
+
+ ['2.25', 'double', ['value' => 2.25, 'readable-value' => 'double 2.25']],
+ ['0.5', 'float', ['value' => 0.5, 'readable-value' => 'double 0.5']],
+
+ ['', 'null', ['value' => null, 'readable-value' => 'null']],
+
+ ['true', 'boolean', ['value' => true, 'readable-value' => 'boolean true']],
+ ['false', 'bool', ['value' => false, 'readable-value' => 'boolean false']],
+ ];
+ }
+
+ /**
+ * @dataProvider castValueProvider
+ */
+ public function testCastValue($value, $type, $expectedValue) {
+ $this->assertSame($expectedValue,
+ $this->invokePrivate($this->command, 'castValue', [$value, $type])
+ );
+ }
+
+ public function castValueInvalidProvider() {
+ return [
+ ['123', 'foobar'],
+
+ [null, 'integer'],
+ ['abc', 'integer'],
+ ['76ggg', 'double'],
+ ['true', 'float'],
+ ['foobar', 'boolean'],
+ ];
+ }
+
+ /**
+ * @dataProvider castValueInvalidProvider
+ * @expectedException \InvalidArgumentException
+ */
+ public function testCastValueInvalid($value, $type) {
+ $this->invokePrivate($this->command, 'castValue', [$value, $type]);
+ }
+
}