2015-04-30 18:33:24 +03:00
|
|
|
<?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;
|
2016-09-01 10:20:54 +03:00
|
|
|
use OC\SystemConfig;
|
|
|
|
use OCP\IAppConfig;
|
2015-09-25 12:08:33 +03:00
|
|
|
use OCP\IConfig;
|
2016-09-01 10:20:54 +03:00
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
2015-04-30 18:33:24 +03:00
|
|
|
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;
|
|
|
|
|
2019-11-21 18:40:38 +03:00
|
|
|
protected function setUp(): void {
|
2015-04-30 18:33:24 +03:00
|
|
|
parent::setUp();
|
|
|
|
|
2016-09-01 10:20:54 +03:00
|
|
|
$systemConfig = $this->systemConfig = $this->getMockBuilder(SystemConfig::class)
|
2015-04-30 18:33:24 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2016-09-01 10:20:54 +03:00
|
|
|
$appConfig = $this->appConfig = $this->getMockBuilder(IAppConfig::class)
|
2015-04-30 18:33:24 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2016-09-01 10:20:54 +03:00
|
|
|
$this->consoleInput = $this->getMockBuilder(InputInterface::class)->getMock();
|
|
|
|
$this->consoleOutput = $this->getMockBuilder(OutputInterface::class)->getMock();
|
2015-04-30 18:33:24 +03:00
|
|
|
|
|
|
|
/** @var \OC\SystemConfig $systemConfig */
|
|
|
|
/** @var \OCP\IAppConfig $appConfig */
|
|
|
|
$this->command = new ListConfigs($systemConfig, $appConfig);
|
|
|
|
}
|
|
|
|
|
2015-05-08 10:58:47 +03:00
|
|
|
public function listData() {
|
2015-04-30 18:33:24 +03:00
|
|
|
return [
|
|
|
|
[
|
|
|
|
'all',
|
|
|
|
// config.php
|
|
|
|
[
|
|
|
|
'secret',
|
|
|
|
'overwrite.cli.url',
|
|
|
|
],
|
|
|
|
[
|
2015-09-25 12:08:33 +03:00
|
|
|
['secret', 'N;', IConfig::SENSITIVE_VALUE],
|
2015-04-30 18:33:24 +03:00
|
|
|
['overwrite.cli.url', 'N;', 'http://localhost'],
|
|
|
|
],
|
|
|
|
// app config
|
|
|
|
[
|
|
|
|
['files', false, [
|
|
|
|
'enabled' => 'yes',
|
|
|
|
]],
|
|
|
|
['core', false, [
|
|
|
|
'global_cache_gc_lastrun' => '1430388388',
|
|
|
|
]],
|
|
|
|
],
|
2015-07-07 12:30:21 +03:00
|
|
|
false,
|
2015-04-30 18:33:24 +03:00
|
|
|
json_encode([
|
|
|
|
'system' => [
|
2015-09-25 12:08:33 +03:00
|
|
|
'secret' => IConfig::SENSITIVE_VALUE,
|
2015-04-30 18:33:24 +03:00
|
|
|
'overwrite.cli.url' => 'http://localhost',
|
|
|
|
],
|
2015-05-08 10:58:47 +03:00
|
|
|
'apps' => [
|
|
|
|
'core' => [
|
|
|
|
'global_cache_gc_lastrun' => '1430388388',
|
|
|
|
],
|
|
|
|
'files' => [
|
|
|
|
'enabled' => 'yes',
|
|
|
|
],
|
|
|
|
],
|
2015-04-30 18:33:24 +03:00
|
|
|
]),
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'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',
|
|
|
|
]],
|
|
|
|
],
|
2015-07-07 12:30:21 +03:00
|
|
|
true,
|
2015-04-30 18:33:24 +03:00
|
|
|
json_encode([
|
|
|
|
'system' => [
|
|
|
|
'secret' => 'my secret',
|
|
|
|
'overwrite.cli.url' => 'http://localhost',
|
|
|
|
],
|
2015-05-08 10:58:47 +03:00
|
|
|
'apps' => [
|
|
|
|
'core' => [
|
|
|
|
'global_cache_gc_lastrun' => '1430388388',
|
|
|
|
],
|
|
|
|
'files' => [
|
|
|
|
'enabled' => 'yes',
|
|
|
|
],
|
|
|
|
],
|
2015-04-30 18:33:24 +03:00
|
|
|
]),
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'system',
|
|
|
|
// config.php
|
|
|
|
[
|
|
|
|
'secret',
|
2015-08-19 15:06:05 +03:00
|
|
|
'objectstore',
|
2015-04-30 18:33:24 +03:00
|
|
|
'overwrite.cli.url',
|
|
|
|
],
|
|
|
|
[
|
2015-09-25 12:08:33 +03:00
|
|
|
['secret', 'N;', IConfig::SENSITIVE_VALUE],
|
2015-08-19 15:06:05 +03:00
|
|
|
['objectstore', 'N;', [
|
|
|
|
'class' => 'OC\\Files\\ObjectStore\\Swift',
|
|
|
|
'arguments' => [
|
|
|
|
'username' => 'facebook100000123456789',
|
2015-09-25 12:08:33 +03:00
|
|
|
'password' => IConfig::SENSITIVE_VALUE,
|
2015-08-19 15:06:05 +03:00
|
|
|
],
|
|
|
|
]],
|
2015-04-30 18:33:24 +03:00
|
|
|
['overwrite.cli.url', 'N;', 'http://localhost'],
|
|
|
|
],
|
|
|
|
// app config
|
|
|
|
[
|
|
|
|
['files', false, [
|
|
|
|
'enabled' => 'yes',
|
|
|
|
]],
|
|
|
|
['core', false, [
|
|
|
|
'global_cache_gc_lastrun' => '1430388388',
|
|
|
|
]],
|
|
|
|
],
|
2015-07-07 12:30:21 +03:00
|
|
|
false,
|
2015-04-30 18:33:24 +03:00
|
|
|
json_encode([
|
2015-07-07 12:25:29 +03:00
|
|
|
'system' => [
|
2015-09-25 12:08:33 +03:00
|
|
|
'secret' => IConfig::SENSITIVE_VALUE,
|
2015-08-19 15:06:05 +03:00
|
|
|
'objectstore' => [
|
|
|
|
'class' => 'OC\\Files\\ObjectStore\\Swift',
|
|
|
|
'arguments' => [
|
|
|
|
'username' => 'facebook100000123456789',
|
2015-09-25 12:08:33 +03:00
|
|
|
'password' => IConfig::SENSITIVE_VALUE,
|
2015-08-19 15:06:05 +03:00
|
|
|
],
|
|
|
|
],
|
2015-07-07 12:25:29 +03:00
|
|
|
'overwrite.cli.url' => 'http://localhost',
|
|
|
|
],
|
2015-04-30 18:33:24 +03:00
|
|
|
]),
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'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',
|
|
|
|
]],
|
|
|
|
],
|
2015-07-07 12:30:21 +03:00
|
|
|
true,
|
2015-04-30 18:33:24 +03:00
|
|
|
json_encode([
|
2015-07-07 12:25:29 +03:00
|
|
|
'system' => [
|
|
|
|
'secret' => 'my secret',
|
|
|
|
'overwrite.cli.url' => 'http://localhost',
|
|
|
|
],
|
2015-04-30 18:33:24 +03:00
|
|
|
]),
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'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',
|
|
|
|
]],
|
|
|
|
],
|
2015-07-07 12:30:21 +03:00
|
|
|
false,
|
2015-04-30 18:33:24 +03:00
|
|
|
json_encode([
|
2015-07-07 12:25:29 +03:00
|
|
|
'apps' => [
|
|
|
|
'files' => [
|
|
|
|
'enabled' => 'yes',
|
|
|
|
],
|
|
|
|
],
|
2015-04-30 18:33:24 +03:00
|
|
|
]),
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'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',
|
|
|
|
]],
|
|
|
|
],
|
2015-07-07 12:30:21 +03:00
|
|
|
true,
|
2015-04-30 18:33:24 +03:00
|
|
|
json_encode([
|
2015-07-07 12:25:29 +03:00
|
|
|
'apps' => [
|
|
|
|
'files' => [
|
|
|
|
'enabled' => 'yes',
|
|
|
|
],
|
|
|
|
],
|
2015-04-30 18:33:24 +03:00
|
|
|
]),
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-05-08 10:58:47 +03:00
|
|
|
* @dataProvider listData
|
2015-04-30 18:33:24 +03:00
|
|
|
*
|
|
|
|
* @param string $app
|
|
|
|
* @param array $systemConfigs
|
|
|
|
* @param array $systemConfigMap
|
|
|
|
* @param array $appConfig
|
2015-07-07 12:30:21 +03:00
|
|
|
* @param bool $private
|
2015-04-30 18:33:24 +03:00
|
|
|
* @param string $expected
|
|
|
|
*/
|
2015-07-07 12:30:21 +03:00
|
|
|
public function testList($app, $systemConfigs, $systemConfigMap, $appConfig, $private, $expected) {
|
2015-04-30 18:33:24 +03:00
|
|
|
$this->systemConfig->expects($this->any())
|
|
|
|
->method('getKeys')
|
|
|
|
->willReturn($systemConfigs);
|
2015-09-25 12:08:33 +03:00
|
|
|
if ($private) {
|
|
|
|
$this->systemConfig->expects($this->any())
|
|
|
|
->method('getValue')
|
|
|
|
->willReturnMap($systemConfigMap);
|
2017-01-12 12:49:22 +03:00
|
|
|
$this->appConfig->expects($this->any())
|
|
|
|
->method('getValues')
|
|
|
|
->willReturnMap($appConfig);
|
2015-09-25 12:08:33 +03:00
|
|
|
} else {
|
|
|
|
$this->systemConfig->expects($this->any())
|
|
|
|
->method('getFilteredValue')
|
|
|
|
->willReturnMap($systemConfigMap);
|
2017-01-12 12:49:22 +03:00
|
|
|
$this->appConfig->expects($this->any())
|
|
|
|
->method('getFilteredValues')
|
|
|
|
->willReturnMap($appConfig);
|
2015-09-25 12:08:33 +03:00
|
|
|
}
|
2015-04-30 18:33:24 +03:00
|
|
|
|
|
|
|
$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'],
|
2015-07-07 12:30:21 +03:00
|
|
|
['private', $private],
|
2015-04-30 18:33:24 +03:00
|
|
|
]);
|
|
|
|
|
|
|
|
global $output;
|
|
|
|
|
|
|
|
$output = '';
|
|
|
|
$this->consoleOutput->expects($this->any())
|
|
|
|
->method('writeln')
|
|
|
|
->willReturnCallback(function($value) {
|
|
|
|
global $output;
|
|
|
|
$output .= $value . "\n";
|
|
|
|
return $output;
|
|
|
|
});
|
|
|
|
|
2015-06-10 18:09:14 +03:00
|
|
|
$this->invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]);
|
2015-04-30 18:33:24 +03:00
|
|
|
|
|
|
|
$this->assertEquals($expected, trim($output, "\n"));
|
|
|
|
}
|
|
|
|
}
|