diff options
Diffstat (limited to 'tests/core/command/config')
-rw-r--r-- | tests/core/command/config/app/deleteconfigtest.php | 123 | ||||
-rw-r--r-- | tests/core/command/config/app/getconfigtest.php | 163 | ||||
-rw-r--r-- | tests/core/command/config/app/setconfigtest.php | 118 | ||||
-rw-r--r-- | tests/core/command/config/importtest.php | 185 | ||||
-rw-r--r-- | tests/core/command/config/listconfigstest.php | 324 | ||||
-rw-r--r-- | tests/core/command/config/system/deleteconfigtest.php | 218 | ||||
-rw-r--r-- | tests/core/command/config/system/getconfigtest.php | 172 | ||||
-rw-r--r-- | tests/core/command/config/system/setconfigtest.php | 175 |
8 files changed, 0 insertions, 1478 deletions
diff --git a/tests/core/command/config/app/deleteconfigtest.php b/tests/core/command/config/app/deleteconfigtest.php deleted file mode 100644 index 7056e1b1ff9..00000000000 --- a/tests/core/command/config/app/deleteconfigtest.php +++ /dev/null @@ -1,123 +0,0 @@ -<?php -/** - * @author Joas Schilling <nickvergessen@owncloud.com> - * - * @copyright Copyright (c) 2015, ownCloud, Inc. - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program 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, version 3, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * - */ - -namespace Tests\Core\Command\Config\App; - - -use OC\Core\Command\Config\App\DeleteConfig; -use Test\TestCase; - -class DeleteConfigTest extends TestCase { - /** @var \PHPUnit_Framework_MockObject_MockObject */ - protected $config; - - /** @var \PHPUnit_Framework_MockObject_MockObject */ - protected $consoleInput; - /** @var \PHPUnit_Framework_MockObject_MockObject */ - protected $consoleOutput; - - /** @var \Symfony\Component\Console\Command\Command */ - protected $command; - - protected function setUp() { - parent::setUp(); - - $config = $this->config = $this->getMockBuilder('OCP\IConfig') - ->disableOriginalConstructor() - ->getMock(); - $this->consoleInput = $this->getMock('Symfony\Component\Console\Input\InputInterface'); - $this->consoleOutput = $this->getMock('Symfony\Component\Console\Output\OutputInterface'); - - /** @var \OCP\IConfig $config */ - $this->command = new DeleteConfig($config); - } - - - public function deleteData() { - return [ - [ - 'name', - true, - true, - 0, - 'info', - ], - [ - 'name', - true, - false, - 0, - 'info', - ], - [ - 'name', - false, - false, - 0, - 'info', - ], - [ - 'name', - false, - true, - 1, - 'error', - ], - ]; - } - - /** - * @dataProvider deleteData - * - * @param string $configName - * @param bool $configExists - * @param bool $checkIfExists - * @param int $expectedReturn - * @param string $expectedMessage - */ - public function testDelete($configName, $configExists, $checkIfExists, $expectedReturn, $expectedMessage) { - $this->config->expects(($checkIfExists) ? $this->once() : $this->never()) - ->method('getAppKeys') - ->with('app-name') - ->willReturn($configExists ? [$configName] : []); - - $this->config->expects(($expectedReturn === 0) ? $this->once() : $this->never()) - ->method('deleteAppValue') - ->with('app-name', $configName); - - $this->consoleInput->expects($this->exactly(2)) - ->method('getArgument') - ->willReturnMap([ - ['app', 'app-name'], - ['name', $configName], - ]); - $this->consoleInput->expects($this->any()) - ->method('hasParameterOption') - ->with('--error-if-not-exists') - ->willReturn($checkIfExists); - - $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/app/getconfigtest.php b/tests/core/command/config/app/getconfigtest.php deleted file mode 100644 index 1ceeb16ccf4..00000000000 --- a/tests/core/command/config/app/getconfigtest.php +++ /dev/null @@ -1,163 +0,0 @@ -<?php -/** - * @author Joas Schilling <nickvergessen@owncloud.com> - * - * @copyright Copyright (c) 2015, ownCloud, Inc. - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program 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, version 3, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * - */ - -namespace Tests\Core\Command\Config\App; - - -use OC\Core\Command\Config\App\GetConfig; -use Test\TestCase; - -class GetConfigTest extends TestCase { - /** @var \PHPUnit_Framework_MockObject_MockObject */ - protected $config; - - /** @var \PHPUnit_Framework_MockObject_MockObject */ - protected $consoleInput; - /** @var \PHPUnit_Framework_MockObject_MockObject */ - protected $consoleOutput; - - /** @var \Symfony\Component\Console\Command\Command */ - protected $command; - - protected function setUp() { - parent::setUp(); - - $config = $this->config = $this->getMockBuilder('OCP\IConfig') - ->disableOriginalConstructor() - ->getMock(); - $this->consoleInput = $this->getMock('Symfony\Component\Console\Input\InputInterface'); - $this->consoleOutput = $this->getMock('Symfony\Component\Console\Output\OutputInterface'); - - /** @var \OCP\IConfig $config */ - $this->command = new GetConfig($config); - } - - - public function getData() { - return [ - // String output as json - ['name', 'newvalue', true, null, false, 'json', 0, json_encode('newvalue')], - // String output as plain text - ['name', 'newvalue', true, null, false, 'plain', 0, 'newvalue'], - // String falling back to default output as json - ['name', null, false, 'newvalue', true, 'json', 0, json_encode('newvalue')], - // String falling back without default: error - ['name', null, false, null, false, 'json', 1, null], - - // Int "0" output as json/plain - ['name', 0, true, null, false, 'json', 0, json_encode(0)], - ['name', 0, true, null, false, 'plain', 0, '0'], - // Int "1" output as json/plain - ['name', 1, true, null, false, 'json', 0, json_encode(1)], - ['name', 1, true, null, false, 'plain', 0, '1'], - - // Bool "true" output as json/plain - ['name', true, true, null, false, 'json', 0, json_encode(true)], - ['name', true, true, null, false, 'plain', 0, 'true'], - // Bool "false" output as json/plain - ['name', false, true, null, false, 'json', 0, json_encode(false)], - ['name', false, true, null, false, 'plain', 0, 'false'], - - // Null output as json/plain - ['name', null, true, null, false, 'json', 0, json_encode(null)], - ['name', null, true, null, false, 'plain', 0, 'null'], - - // Array output as json/plain - ['name', ['a', 'b'], true, null, false, 'json', 0, json_encode(['a', 'b'])], - ['name', ['a', 'b'], true, null, false, 'plain', 0, "a\nb"], - // Key array output as json/plain - ['name', [0 => 'a', 1 => 'b'], true, null, false, 'json', 0, json_encode(['a', 'b'])], - ['name', [0 => 'a', 1 => 'b'], true, null, false, 'plain', 0, "a\nb"], - // Associative array output as json/plain - ['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"], - - ]; - } - - /** - * @dataProvider getData - * - * @param string $configName - * @param mixed $value - * @param bool $configExists - * @param mixed $defaultValue - * @param bool $hasDefault - * @param string $outputFormat - * @param int $expectedReturn - * @param string $expectedMessage - */ - public function testGet($configName, $value, $configExists, $defaultValue, $hasDefault, $outputFormat, $expectedReturn, $expectedMessage) { - $this->config->expects($this->atLeastOnce()) - ->method('getAppKeys') - ->with('app-name') - ->willReturn($configExists ? [$configName] : []); - - if (!$expectedReturn) { - if ($configExists) { - $this->config->expects($this->once()) - ->method('getAppValue') - ->with('app-name', $configName) - ->willReturn($value); - } - } - - $this->consoleInput->expects($this->exactly(2)) - ->method('getArgument') - ->willReturnMap([ - ['app', 'app-name'], - ['name', $configName], - ]); - $this->consoleInput->expects($this->any()) - ->method('getOption') - ->willReturnMap([ - ['default-value', $defaultValue], - ['output', $outputFormat], - ]); - $this->consoleInput->expects($this->any()) - ->method('hasParameterOption') - ->willReturnMap([ - ['--output', true], - ['--default-value', $hasDefault], - ]); - - if ($expectedMessage !== null) { - global $output; - - $output = ''; - $this->consoleOutput->expects($this->any()) - ->method('writeln') - ->willReturnCallback(function($value) { - global $output; - $output .= $value . "\n"; - return $output; - }); - } - - $this->assertSame($expectedReturn, $this->invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput])); - - if ($expectedMessage !== null) { - global $output; - // Remove the trailing newline - $this->assertSame($expectedMessage, substr($output, 0, -1)); - } - } -} diff --git a/tests/core/command/config/app/setconfigtest.php b/tests/core/command/config/app/setconfigtest.php deleted file mode 100644 index 14d7b0cb7b5..00000000000 --- a/tests/core/command/config/app/setconfigtest.php +++ /dev/null @@ -1,118 +0,0 @@ -<?php -/** - * @author Joas Schilling <nickvergessen@owncloud.com> - * - * @copyright Copyright (c) 2015, ownCloud, Inc. - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program 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, version 3, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * - */ - -namespace Tests\Core\Command\Config\App; - - -use OC\Core\Command\Config\App\SetConfig; -use Test\TestCase; - -class SetConfigTest extends TestCase { - /** @var \PHPUnit_Framework_MockObject_MockObject */ - protected $config; - - /** @var \PHPUnit_Framework_MockObject_MockObject */ - protected $consoleInput; - /** @var \PHPUnit_Framework_MockObject_MockObject */ - protected $consoleOutput; - - /** @var \Symfony\Component\Console\Command\Command */ - protected $command; - - protected function setUp() { - parent::setUp(); - - $config = $this->config = $this->getMockBuilder('OCP\IConfig') - ->disableOriginalConstructor() - ->getMock(); - $this->consoleInput = $this->getMock('Symfony\Component\Console\Input\InputInterface'); - $this->consoleOutput = $this->getMock('Symfony\Component\Console\Output\OutputInterface'); - - /** @var \OCP\IConfig $config */ - $this->command = new SetConfig($config); - } - - - public function setData() { - return [ - [ - 'name', - 'newvalue', - true, - true, - true, - 'info', - ], - [ - 'name', - 'newvalue', - false, - true, - false, - 'comment', - ], - ]; - } - - /** - * @dataProvider setData - * - * @param string $configName - * @param mixed $newValue - * @param bool $configExists - * @param bool $updateOnly - * @param bool $updated - * @param string $expectedMessage - */ - public function testSet($configName, $newValue, $configExists, $updateOnly, $updated, $expectedMessage) { - $this->config->expects($this->once()) - ->method('getAppKeys') - ->with('app-name') - ->willReturn($configExists ? [$configName] : []); - - if ($updated) { - $this->config->expects($this->once()) - ->method('setAppValue') - ->with('app-name', $configName, $newValue); - } - - $this->consoleInput->expects($this->exactly(2)) - ->method('getArgument') - ->willReturnMap([ - ['app', 'app-name'], - ['name', $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)); - - $this->invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]); - } -} diff --git a/tests/core/command/config/importtest.php b/tests/core/command/config/importtest.php deleted file mode 100644 index f14880f8bf4..00000000000 --- a/tests/core/command/config/importtest.php +++ /dev/null @@ -1,185 +0,0 @@ -<?php -/** - * @author Joas Schilling <nickvergessen@owncloud.com> - * - * @copyright Copyright (c) 2015, ownCloud, Inc. - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program 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, version 3, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * - */ - -namespace Tests\Core\Command\Config; - - -use OC\Core\Command\Config\Import; -use Test\TestCase; - -class ImportTest extends TestCase { - /** @var \PHPUnit_Framework_MockObject_MockObject */ - protected $config; - - /** @var \PHPUnit_Framework_MockObject_MockObject */ - protected $consoleInput; - /** @var \PHPUnit_Framework_MockObject_MockObject */ - protected $consoleOutput; - - /** @var \Symfony\Component\Console\Command\Command */ - protected $command; - - protected function setUp() { - parent::setUp(); - - $config = $this->config = $this->getMockBuilder('OCP\IConfig') - ->disableOriginalConstructor() - ->getMock(); - $this->consoleInput = $this->getMock('Symfony\Component\Console\Input\InputInterface'); - $this->consoleOutput = $this->getMock('Symfony\Component\Console\Output\OutputInterface'); - - /** @var \OCP\IConfig $config */ - $this->command = new Import($config); - } - - public function validateAppsArrayData() { - return [ - [0], - [1], - [null], - ['new \Exception()'], - [json_encode([])], - ]; - } - - /** - * @dataProvider validateAppsArrayData - * - * @param mixed $configValue - */ - public function testValidateAppsArray($configValue) { - $this->invokePrivate($this->command, 'validateAppsArray', [['app' => ['name' => $configValue]]]); - $this->assertTrue(true, 'Asserting that no exception is thrown'); - } - - public function validateAppsArrayThrowsData() { - return [ - [false], - [true], - [[]], - [new \Exception()], - ]; - } - - /** - * @dataProvider validateAppsArrayThrowsData - * - * @param mixed $configValue - */ - public function testValidateAppsArrayThrows($configValue) { - try { - $this->invokePrivate($this->command, 'validateAppsArray', [['app' => ['name' => $configValue]]]); - $this->fail('Did not throw expected UnexpectedValueException'); - } catch (\UnexpectedValueException $e) { - $this->assertStringStartsWith('Invalid app config value for "app":"name".', $e->getMessage()); - } - } - - public function checkTypeRecursivelyData() { - return [ - [0], - [1], - [null], - ['new \Exception()'], - [json_encode([])], - [false], - [true], - [[]], - [['string']], - [['test' => 'string']], - [['test' => ['sub' => 'string']]], - ]; - } - - /** - * @dataProvider checkTypeRecursivelyData - * - * @param mixed $configValue - */ - public function testCheckTypeRecursively($configValue) { - $this->invokePrivate($this->command, 'checkTypeRecursively', [$configValue, 'name']); - $this->assertTrue(true, 'Asserting that no exception is thrown'); - } - - public function checkTypeRecursivelyThrowsData() { - return [ - [new \Exception()], - [[new \Exception()]], - [['test' => new \Exception()]], - [['test' => ['sub' => new \Exception()]]], - ]; - } - - /** - * @dataProvider checkTypeRecursivelyThrowsData - * - * @param mixed $configValue - */ - public function testCheckTypeRecursivelyThrows($configValue) { - try { - $this->invokePrivate($this->command, 'checkTypeRecursively', [$configValue, 'name']); - $this->fail('Did not throw expected UnexpectedValueException'); - } catch (\UnexpectedValueException $e) { - $this->assertStringStartsWith('Invalid system config value for "name"', $e->getMessage()); - } - } - - public function validateArrayData() { - return [ - [['system' => []]], - [['apps' => []]], - [['system' => [], 'apps' => []]], - ]; - } - - /** - * @dataProvider validateArrayData - * - * @param array $configArray - */ - public function testValidateArray($configArray) { - $this->invokePrivate($this->command, 'validateArray', [$configArray]); - $this->assertTrue(true, 'Asserting that no exception is thrown'); - } - - public function validateArrayThrowsData() { - return [ - [[], 'At least one key of the following is expected:'], - [[0 => []], 'Found invalid entries in root'], - [['string' => []], 'Found invalid entries in root'], - ]; - } - - /** - * @dataProvider validateArrayThrowsData - * - * @param mixed $configArray - * @param string $expectedException - */ - public function testValidateArrayThrows($configArray, $expectedException) { - try { - $this->invokePrivate($this->command, 'validateArray', [$configArray]); - $this->fail('Did not throw expected UnexpectedValueException'); - } catch (\UnexpectedValueException $e) { - $this->assertStringStartsWith($expectedException, $e->getMessage()); - } - } -} diff --git a/tests/core/command/config/listconfigstest.php b/tests/core/command/config/listconfigstest.php deleted file mode 100644 index bde6a1b0db3..00000000000 --- a/tests/core/command/config/listconfigstest.php +++ /dev/null @@ -1,324 +0,0 @@ -<?php -/** - * @author Joas Schilling <nickvergessen@owncloud.com> - * - * @copyright Copyright (c) 2015, ownCloud, Inc. - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program 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, version 3, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * - */ - -namespace Tests\Core\Command\Config; - - -use OC\Core\Command\Config\ListConfigs; -use OCP\IConfig; -use Test\TestCase; - -class ListConfigsTest extends TestCase { - /** @var \PHPUnit_Framework_MockObject_MockObject */ - protected $appConfig; - /** @var \PHPUnit_Framework_MockObject_MockObject */ - protected $systemConfig; - - /** @var \PHPUnit_Framework_MockObject_MockObject */ - protected $consoleInput; - /** @var \PHPUnit_Framework_MockObject_MockObject */ - protected $consoleOutput; - - /** @var \Symfony\Component\Console\Command\Command */ - protected $command; - - protected function setUp() { - parent::setUp(); - - $systemConfig = $this->systemConfig = $this->getMockBuilder('OC\SystemConfig') - ->disableOriginalConstructor() - ->getMock(); - $appConfig = $this->appConfig = $this->getMockBuilder('OCP\IAppConfig') - ->disableOriginalConstructor() - ->getMock(); - $this->consoleInput = $this->getMock('Symfony\Component\Console\Input\InputInterface'); - $this->consoleOutput = $this->getMock('Symfony\Component\Console\Output\OutputInterface'); - - /** @var \OC\SystemConfig $systemConfig */ - /** @var \OCP\IAppConfig $appConfig */ - $this->command = new ListConfigs($systemConfig, $appConfig); - } - - public function listData() { - return [ - [ - 'all', - // config.php - [ - 'secret', - 'overwrite.cli.url', - ], - [ - ['secret', 'N;', IConfig::SENSITIVE_VALUE], - ['overwrite.cli.url', 'N;', 'http://localhost'], - ], - // app config - [ - ['files', false, [ - 'enabled' => 'yes', - ]], - ['core', false, [ - 'global_cache_gc_lastrun' => '1430388388', - ]], - ], - false, - json_encode([ - 'system' => [ - 'secret' => IConfig::SENSITIVE_VALUE, - 'overwrite.cli.url' => 'http://localhost', - ], - 'apps' => [ - 'core' => [ - 'global_cache_gc_lastrun' => '1430388388', - ], - 'files' => [ - 'enabled' => 'yes', - ], - ], - ]), - ], - [ - 'all', - // config.php - [ - 'secret', - 'overwrite.cli.url', - ], - [ - ['secret', 'N;', 'my secret'], - ['overwrite.cli.url', 'N;', 'http://localhost'], - ], - // app config - [ - ['files', false, [ - 'enabled' => 'yes', - ]], - ['core', false, [ - 'global_cache_gc_lastrun' => '1430388388', - ]], - ], - true, - json_encode([ - 'system' => [ - 'secret' => 'my secret', - 'overwrite.cli.url' => 'http://localhost', - ], - 'apps' => [ - 'core' => [ - 'global_cache_gc_lastrun' => '1430388388', - ], - 'files' => [ - 'enabled' => 'yes', - ], - ], - ]), - ], - [ - 'system', - // config.php - [ - 'secret', - 'objectstore', - 'overwrite.cli.url', - ], - [ - ['secret', 'N;', IConfig::SENSITIVE_VALUE], - ['objectstore', 'N;', [ - 'class' => 'OC\\Files\\ObjectStore\\Swift', - 'arguments' => [ - 'username' => 'facebook100000123456789', - 'password' => IConfig::SENSITIVE_VALUE, - ], - ]], - ['overwrite.cli.url', 'N;', 'http://localhost'], - ], - // app config - [ - ['files', false, [ - 'enabled' => 'yes', - ]], - ['core', false, [ - 'global_cache_gc_lastrun' => '1430388388', - ]], - ], - false, - json_encode([ - 'system' => [ - 'secret' => IConfig::SENSITIVE_VALUE, - 'objectstore' => [ - 'class' => 'OC\\Files\\ObjectStore\\Swift', - 'arguments' => [ - 'username' => 'facebook100000123456789', - 'password' => IConfig::SENSITIVE_VALUE, - ], - ], - 'overwrite.cli.url' => 'http://localhost', - ], - ]), - ], - [ - 'system', - // config.php - [ - 'secret', - 'overwrite.cli.url', - ], - [ - ['secret', 'N;', 'my secret'], - ['overwrite.cli.url', 'N;', 'http://localhost'], - ], - // app config - [ - ['files', false, [ - 'enabled' => 'yes', - ]], - ['core', false, [ - 'global_cache_gc_lastrun' => '1430388388', - ]], - ], - true, - json_encode([ - 'system' => [ - 'secret' => 'my secret', - 'overwrite.cli.url' => 'http://localhost', - ], - ]), - ], - [ - 'files', - // config.php - [ - 'secret', - 'overwrite.cli.url', - ], - [ - ['secret', 'N;', 'my secret'], - ['overwrite.cli.url', 'N;', 'http://localhost'], - ], - // app config - [ - ['files', false, [ - 'enabled' => 'yes', - ]], - ['core', false, [ - 'global_cache_gc_lastrun' => '1430388388', - ]], - ], - false, - json_encode([ - 'apps' => [ - 'files' => [ - 'enabled' => 'yes', - ], - ], - ]), - ], - [ - 'files', - // config.php - [ - 'secret', - 'overwrite.cli.url', - ], - [ - ['secret', 'N;', 'my secret'], - ['overwrite.cli.url', 'N;', 'http://localhost'], - ], - // app config - [ - ['files', false, [ - 'enabled' => 'yes', - ]], - ['core', false, [ - 'global_cache_gc_lastrun' => '1430388388', - ]], - ], - true, - json_encode([ - 'apps' => [ - 'files' => [ - 'enabled' => 'yes', - ], - ], - ]), - ], - ]; - } - - /** - * @dataProvider listData - * - * @param string $app - * @param array $systemConfigs - * @param array $systemConfigMap - * @param array $appConfig - * @param bool $private - * @param string $expected - */ - public function testList($app, $systemConfigs, $systemConfigMap, $appConfig, $private, $expected) { - $this->systemConfig->expects($this->any()) - ->method('getKeys') - ->willReturn($systemConfigs); - if ($private) { - $this->systemConfig->expects($this->any()) - ->method('getValue') - ->willReturnMap($systemConfigMap); - } else { - $this->systemConfig->expects($this->any()) - ->method('getFilteredValue') - ->willReturnMap($systemConfigMap); - } - - $this->appConfig->expects($this->any()) - ->method('getApps') - ->willReturn(['core', 'files']); - $this->appConfig->expects($this->any()) - ->method('getValues') - ->willReturnMap($appConfig); - - $this->consoleInput->expects($this->once()) - ->method('getArgument') - ->with('app') - ->willReturn($app); - - $this->consoleInput->expects($this->any()) - ->method('getOption') - ->willReturnMap([ - ['output', 'json'], - ['private', $private], - ]); - - global $output; - - $output = ''; - $this->consoleOutput->expects($this->any()) - ->method('writeln') - ->willReturnCallback(function($value) { - global $output; - $output .= $value . "\n"; - return $output; - }); - - $this->invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]); - - $this->assertEquals($expected, trim($output, "\n")); - } -} diff --git a/tests/core/command/config/system/deleteconfigtest.php b/tests/core/command/config/system/deleteconfigtest.php deleted file mode 100644 index 11bfb6ae7ad..00000000000 --- a/tests/core/command/config/system/deleteconfigtest.php +++ /dev/null @@ -1,218 +0,0 @@ -<?php -/** - * @author Joas Schilling <nickvergessen@owncloud.com> - * - * @copyright Copyright (c) 2015, ownCloud, Inc. - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program 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, version 3, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * - */ - -namespace Tests\Core\Command\Config\System; - - -use OC\Core\Command\Config\System\DeleteConfig; -use Test\TestCase; - -class DeleteConfigTest extends TestCase { - /** @var \PHPUnit_Framework_MockObject_MockObject */ - protected $systemConfig; - - /** @var \PHPUnit_Framework_MockObject_MockObject */ - protected $consoleInput; - /** @var \PHPUnit_Framework_MockObject_MockObject */ - protected $consoleOutput; - - /** @var \Symfony\Component\Console\Command\Command */ - protected $command; - - protected function setUp() { - parent::setUp(); - - $systemConfig = $this->systemConfig = $this->getMockBuilder('OC\SystemConfig') - ->disableOriginalConstructor() - ->getMock(); - $this->consoleInput = $this->getMock('Symfony\Component\Console\Input\InputInterface'); - $this->consoleOutput = $this->getMock('Symfony\Component\Console\Output\OutputInterface'); - - /** @var \OC\SystemConfig $systemConfig */ - $this->command = new DeleteConfig($systemConfig); - } - - public function deleteData() { - return [ - [ - 'name1', - true, - true, - 0, - 'info', - ], - [ - 'name2', - true, - false, - 0, - 'info', - ], - [ - 'name3', - false, - false, - 0, - 'info', - ], - [ - 'name4', - false, - true, - 1, - 'error', - ], - ]; - } - - /** - * @dataProvider deleteData - * - * @param string $configName - * @param bool $configExists - * @param bool $checkIfExists - * @param int $expectedReturn - * @param string $expectedMessage - */ - public function testDelete($configName, $configExists, $checkIfExists, $expectedReturn, $expectedMessage) { - $this->systemConfig->expects(($checkIfExists) ? $this->once() : $this->never()) - ->method('getKeys') - ->willReturn($configExists ? [$configName] : []); - - $this->systemConfig->expects(($expectedReturn === 0) ? $this->once() : $this->never()) - ->method('deleteValue') - ->with($configName); - - $this->consoleInput->expects($this->once()) - ->method('getArgument') - ->with('name') - ->willReturn([$configName]); - $this->consoleInput->expects($this->any()) - ->method('hasParameterOption') - ->with('--error-if-not-exists') - ->willReturn($checkIfExists); - - $this->consoleOutput->expects($this->any()) - ->method('writeln') - ->with($this->stringContains($expectedMessage)); - - $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 deleted file mode 100644 index ebbea634cde..00000000000 --- a/tests/core/command/config/system/getconfigtest.php +++ /dev/null @@ -1,172 +0,0 @@ -<?php -/** - * @author Joas Schilling <nickvergessen@owncloud.com> - * - * @copyright Copyright (c) 2015, ownCloud, Inc. - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program 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, version 3, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * - */ - -namespace Tests\Core\Command\Config\System; - - -use OC\Core\Command\Config\System\GetConfig; -use Test\TestCase; - -class GetConfigTest extends TestCase { - /** @var \PHPUnit_Framework_MockObject_MockObject */ - protected $systemConfig; - - /** @var \PHPUnit_Framework_MockObject_MockObject */ - protected $consoleInput; - /** @var \PHPUnit_Framework_MockObject_MockObject */ - protected $consoleOutput; - - /** @var \Symfony\Component\Console\Command\Command */ - protected $command; - - protected function setUp() { - parent::setUp(); - - $systemConfig = $this->systemConfig = $this->getMockBuilder('OC\SystemConfig') - ->disableOriginalConstructor() - ->getMock(); - $this->consoleInput = $this->getMock('Symfony\Component\Console\Input\InputInterface'); - $this->consoleOutput = $this->getMock('Symfony\Component\Console\Output\OutputInterface'); - - /** @var \OC\SystemConfig $systemConfig */ - $this->command = new GetConfig($systemConfig); - } - - - public function getData() { - return [ - // String output as json - ['name', 'newvalue', true, null, false, 'json', 0, json_encode('newvalue')], - // String output as plain text - ['name', 'newvalue', true, null, false, 'plain', 0, 'newvalue'], - // String falling back to default output as json - ['name', null, false, 'newvalue', true, 'json', 0, json_encode('newvalue')], - // String falling back without default: error - ['name', null, false, null, false, 'json', 1, null], - - // Int "0" output as json/plain - ['name', 0, true, null, false, 'json', 0, json_encode(0)], - ['name', 0, true, null, false, 'plain', 0, '0'], - // Int "1" output as json/plain - ['name', 1, true, null, false, 'json', 0, json_encode(1)], - ['name', 1, true, null, false, 'plain', 0, '1'], - - // Bool "true" output as json/plain - ['name', true, true, null, false, 'json', 0, json_encode(true)], - ['name', true, true, null, false, 'plain', 0, 'true'], - // Bool "false" output as json/plain - ['name', false, true, null, false, 'json', 0, json_encode(false)], - ['name', false, true, null, false, 'plain', 0, 'false'], - - // Null output as json/plain - ['name', null, true, null, false, 'json', 0, json_encode(null)], - ['name', null, true, null, false, 'plain', 0, 'null'], - - // Array output as json/plain - ['name', ['a', 'b'], true, null, false, 'json', 0, json_encode(['a', 'b'])], - ['name', ['a', 'b'], true, null, false, 'plain', 0, "a\nb"], - // Key array output as json/plain - ['name', [0 => 'a', 1 => 'b'], true, null, false, 'json', 0, json_encode(['a', 'b'])], - ['name', [0 => 'a', 1 => 'b'], true, null, false, 'plain', 0, "a\nb"], - // Associative array output as json/plain - ['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[] $configNames - * @param mixed $value - * @param bool $configExists - * @param mixed $defaultValue - * @param bool $hasDefault - * @param string $outputFormat - * @param int $expectedReturn - * @param string $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] : []); - - if (!$expectedReturn) { - if ($configExists) { - $this->systemConfig->expects($this->once()) - ->method('getValue') - ->with($configName) - ->willReturn($value); - } - } - - $this->consoleInput->expects($this->once()) - ->method('getArgument') - ->with('name') - ->willReturn($configNames); - $this->consoleInput->expects($this->any()) - ->method('getOption') - ->willReturnMap([ - ['default-value', $defaultValue], - ['output', $outputFormat], - ]); - $this->consoleInput->expects($this->any()) - ->method('hasParameterOption') - ->willReturnMap([ - ['--output', true], - ['--default-value', $hasDefault], - ]); - - if ($expectedMessage !== null) { - global $output; - - $output = ''; - $this->consoleOutput->expects($this->any()) - ->method('writeln') - ->willReturnCallback(function($value) { - global $output; - $output .= $value . "\n"; - return $output; - }); - } - - $this->assertSame($expectedReturn, $this->invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput])); - - if ($expectedMessage !== null) { - global $output; - // Remove the trailing newline - $this->assertSame($expectedMessage, substr($output, 0, -1)); - } - } -} diff --git a/tests/core/command/config/system/setconfigtest.php b/tests/core/command/config/system/setconfigtest.php deleted file mode 100644 index c0b664d7522..00000000000 --- a/tests/core/command/config/system/setconfigtest.php +++ /dev/null @@ -1,175 +0,0 @@ -<?php -/** - * @author Joas Schilling <nickvergessen@owncloud.com> - * - * @copyright Copyright (c) 2015, ownCloud, Inc. - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program 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, version 3, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * - */ - -namespace Tests\Core\Command\Config\System; - - -use OC\Core\Command\Config\System\SetConfig; -use Test\TestCase; - -class SetConfigTest extends TestCase { - /** @var \PHPUnit_Framework_MockObject_MockObject */ - protected $systemConfig; - - /** @var \PHPUnit_Framework_MockObject_MockObject */ - protected $consoleInput; - /** @var \PHPUnit_Framework_MockObject_MockObject */ - protected $consoleOutput; - - /** @var \Symfony\Component\Console\Command\Command */ - protected $command; - - protected function setUp() { - parent::setUp(); - - $systemConfig = $this->systemConfig = $this->getMockBuilder('OC\SystemConfig') - ->disableOriginalConstructor() - ->getMock(); - $this->consoleInput = $this->getMock('Symfony\Component\Console\Input\InputInterface'); - $this->consoleOutput = $this->getMock('Symfony\Component\Console\Output\OutputInterface'); - - /** @var \OC\SystemConfig $systemConfig */ - $this->command = new SetConfig($systemConfig); - } - - - public function setData() { - return [ - [['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 array $configNames - * @param string $newValue - * @param mixed $existingData - * @param mixed $expectedValue - */ - public function testSet($configNames, $newValue, $existingData, $expectedValue) { - $this->systemConfig->expects($this->once()) - ->method('setValue') - ->with($configNames[0], $expectedValue); - $this->systemConfig->method('getValue') - ->with($configNames[0]) - ->willReturn($existingData); - - $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($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]); - } - -} |