2018-08-17 19:41:46 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Friendica\Test\src\Core\Console;
|
|
|
|
|
|
|
|
use Friendica\Database\DBA;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @runTestsInSeparateProcesses
|
|
|
|
* @preserveGlobalState disabled
|
|
|
|
* @requires PHP 7.0
|
|
|
|
*/
|
|
|
|
class ConfigConsoleTest extends ConsoleTest
|
|
|
|
{
|
|
|
|
public function tearDown()
|
|
|
|
{
|
|
|
|
DBA::delete('config', ['k' => 'test']);
|
|
|
|
|
|
|
|
parent::tearDown();
|
|
|
|
}
|
|
|
|
|
|
|
|
private function assertGet($family, $key, $value) {
|
2018-08-27 04:15:55 +00:00
|
|
|
$config = $this->execute(['config', $family, $key]);
|
2018-08-17 19:41:46 +00:00
|
|
|
$this->assertEquals($family . "." . $key . " => " . $value . "\n", $config);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function assertSet($family, $key, $value) {
|
2018-08-27 04:15:55 +00:00
|
|
|
$config = $this->execute(['config', $family, $key, $value]);
|
2018-08-17 19:41:46 +00:00
|
|
|
$this->assertEquals($family . "." . $key . " <= " . $value . "\n", $config);
|
|
|
|
}
|
|
|
|
|
|
|
|
function testSetGetKeyValue() {
|
|
|
|
$this->assertSet( 'config', 'test', 'now');
|
|
|
|
$this->assertGet('config', 'test', 'now');
|
|
|
|
$this->assertSet('config', 'test', '');
|
|
|
|
$this->assertGet('config', 'test', '');
|
|
|
|
DBA::delete('config', ['k' => 'test']);
|
|
|
|
$this->assertGet('config', 'test', null);
|
|
|
|
}
|
|
|
|
|
|
|
|
function testSetArrayValue() {
|
|
|
|
$testArray = [1, 2, 3];
|
|
|
|
DBA::insert('config', ['cat' => 'config', 'k' => 'test', 'v' => serialize($testArray)]);
|
|
|
|
|
2018-08-27 04:15:55 +00:00
|
|
|
$txt = $this->execute(['config', 'config', 'test', 'now']);
|
2018-08-17 19:41:46 +00:00
|
|
|
|
|
|
|
$this->assertEquals("[Error] config.test is an array and can't be set using this command.\n", $txt);
|
|
|
|
}
|
|
|
|
|
|
|
|
function testTooManyArguments() {
|
2018-08-27 04:15:55 +00:00
|
|
|
$txt = $this->execute(['config', 'config', 'test', 'it', 'now']);
|
2018-08-17 19:41:46 +00:00
|
|
|
$assertion = '[Warning] Too many arguments';
|
|
|
|
$firstline = substr($txt, 0, strlen($assertion));
|
|
|
|
|
|
|
|
$this->assertEquals($assertion, $firstline);
|
|
|
|
}
|
|
|
|
|
|
|
|
function testVerbose() {
|
|
|
|
$this->assertSet('test', 'it', 'now');
|
2018-08-27 04:15:55 +00:00
|
|
|
$executable = $this->getExecutablePath();
|
2018-08-17 19:41:46 +00:00
|
|
|
$assertion = <<<CONF
|
2018-08-27 04:15:55 +00:00
|
|
|
Executable: {$executable}
|
2018-08-17 19:41:46 +00:00
|
|
|
Arguments: array (
|
|
|
|
0 => 'config',
|
|
|
|
1 => 'test',
|
|
|
|
)
|
|
|
|
Options: array (
|
|
|
|
'v' => 1,
|
|
|
|
)
|
|
|
|
Command: config
|
2018-08-27 04:15:55 +00:00
|
|
|
Executable: {$executable}
|
2018-08-17 19:41:46 +00:00
|
|
|
Class: Friendica\Core\Console\Config
|
|
|
|
Arguments: array (
|
|
|
|
0 => 'test',
|
|
|
|
)
|
|
|
|
Options: array (
|
|
|
|
'v' => 1,
|
|
|
|
)
|
|
|
|
[test]
|
|
|
|
it => now
|
|
|
|
|
|
|
|
CONF;
|
2018-08-27 04:15:55 +00:00
|
|
|
$txt = $this->execute(['config', 'test', '-v']);
|
2018-08-17 19:41:46 +00:00
|
|
|
|
|
|
|
$this->assertEquals($assertion, $txt);
|
|
|
|
}
|
|
|
|
}
|