mirror of
https://github.com/friendica/friendica
synced 2025-04-24 02:30:13 +00:00
Config Console Tests (#5621)
* Config Console Tests - `MultiUseConsole` is now a testable console - `ConsoleTest` is a abstract TestClass for console tests - `ConfigConsoleTest` tests the config console commands * disable preserve global state because of smarty * fixed requires & basepath für Console Test
This commit is contained in:
parent
1711f4dc56
commit
4eaeea7889
4 changed files with 201 additions and 0 deletions
85
tests/src/Core/Console/ConfigConsoleTest.php
Normal file
85
tests/src/Core/Console/ConfigConsoleTest.php
Normal file
|
@ -0,0 +1,85 @@
|
|||
<?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) {
|
||||
$config = $this->execute([__FILE__, 'config', $family, $key]);
|
||||
$this->assertEquals($family . "." . $key . " => " . $value . "\n", $config);
|
||||
}
|
||||
|
||||
private function assertSet($family, $key, $value) {
|
||||
$config = $this->execute([__FILE__, 'config', $family, $key, $value]);
|
||||
$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)]);
|
||||
|
||||
$txt = $this->execute([__FILE__, 'config', 'config', 'test', 'now']);
|
||||
|
||||
$this->assertEquals("[Error] config.test is an array and can't be set using this command.\n", $txt);
|
||||
}
|
||||
|
||||
function testTooManyArguments() {
|
||||
$txt = $this->execute([__FILE__, 'config', 'config', 'test', 'it', 'now']);
|
||||
$assertion = '[Warning] Too many arguments';
|
||||
$firstline = substr($txt, 0, strlen($assertion));
|
||||
|
||||
$this->assertEquals($assertion, $firstline);
|
||||
}
|
||||
|
||||
function testVerbose() {
|
||||
$this->assertSet('test', 'it', 'now');
|
||||
$assertion = <<<CONF
|
||||
Executable: {$this->app->basepath}/tests/src/Core/Console/ConfigConsoleTest.php
|
||||
Arguments: array (
|
||||
0 => 'config',
|
||||
1 => 'test',
|
||||
)
|
||||
Options: array (
|
||||
'v' => 1,
|
||||
)
|
||||
Command: config
|
||||
Executable: {$this->app->basepath}/tests/src/Core/Console/ConfigConsoleTest.php
|
||||
Class: Friendica\Core\Console\Config
|
||||
Arguments: array (
|
||||
0 => 'test',
|
||||
)
|
||||
Options: array (
|
||||
'v' => 1,
|
||||
)
|
||||
[test]
|
||||
it => now
|
||||
|
||||
CONF;
|
||||
$txt = $this->execute([__FILE__, 'config', 'test', '-v']);
|
||||
|
||||
$this->assertEquals($assertion, $txt);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue