diff options
author | Joas Schilling <nickvergessen@owncloud.com> | 2015-12-09 14:26:17 +0100 |
---|---|---|
committer | Joas Schilling <nickvergessen@owncloud.com> | 2016-01-14 15:02:54 +0100 |
commit | a06f0256a9ce0f928b6b658b1df92bafbf6b6086 (patch) | |
tree | 1283a9d2fcf58fdecf17e9b8b5539795b5237371 /tests/core | |
parent | 00ab50defc7a683907df59fd503b24a35decf962 (diff) | |
download | nextcloud-server-a06f0256a9ce0f928b6b658b1df92bafbf6b6086.tar.gz nextcloud-server-a06f0256a9ce0f928b6b658b1df92bafbf6b6086.zip |
Allow deleting a nested system config value
Diffstat (limited to 'tests/core')
-rw-r--r-- | tests/core/command/config/system/deleteconfigtest.php | 110 |
1 files changed, 104 insertions, 6 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])); + } } |