]> git.mxchange.org Git - friendica.git/blob - tests/src/Core/Console/ConfigConsoleTest.php
Automatic Install Tests & Doku (#5674)
[friendica.git] / tests / src / Core / Console / ConfigConsoleTest.php
1 <?php
2
3 namespace Friendica\Test\src\Core\Console;
4
5 use Friendica\Database\DBA;
6
7 /**
8  * @runTestsInSeparateProcesses
9  * @preserveGlobalState disabled
10  * @requires PHP 7.0
11  */
12 class ConfigConsoleTest extends ConsoleTest
13 {
14         public function tearDown()
15         {
16                 DBA::delete('config', ['k' => 'test']);
17
18                 parent::tearDown();
19         }
20
21         private function assertGet($family, $key, $value) {
22                 $config = $this->execute(['config', $family, $key]);
23                 $this->assertEquals($family . "." . $key . " => " . $value . "\n", $config);
24         }
25
26         private function assertSet($family, $key, $value) {
27                 $config = $this->execute(['config', $family, $key, $value]);
28                 $this->assertEquals($family . "." . $key . " <= " . $value . "\n", $config);
29         }
30
31         function testSetGetKeyValue() {
32                 $this->assertSet( 'config', 'test', 'now');
33                 $this->assertGet('config', 'test', 'now');
34                 $this->assertSet('config', 'test', '');
35                 $this->assertGet('config', 'test', '');
36                 DBA::delete('config', ['k' => 'test']);
37                 $this->assertGet('config', 'test', null);
38         }
39
40         function testSetArrayValue() {
41                 $testArray = [1, 2, 3];
42                 DBA::insert('config', ['cat' => 'config', 'k' => 'test', 'v' => serialize($testArray)]);
43
44                 $txt = $this->execute(['config', 'config', 'test', 'now']);
45
46                 $this->assertEquals("[Error] config.test is an array and can't be set using this command.\n", $txt);
47         }
48
49         function testTooManyArguments() {
50                 $txt = $this->execute(['config', 'config', 'test', 'it', 'now']);
51                 $assertion = '[Warning] Too many arguments';
52                 $firstline = substr($txt, 0, strlen($assertion));
53
54                 $this->assertEquals($assertion, $firstline);
55         }
56
57         function testVerbose() {
58                 $this->assertSet('test', 'it', 'now');
59                 $executable = $this->getExecutablePath();
60                 $assertion = <<<CONF
61 Executable: {$executable}
62 Arguments: array (
63   0 => 'config',
64   1 => 'test',
65 )
66 Options: array (
67   'v' => 1,
68 )
69 Command: config
70 Executable: {$executable}
71 Class: Friendica\Core\Console\Config
72 Arguments: array (
73   0 => 'test',
74 )
75 Options: array (
76   'v' => 1,
77 )
78 [test]
79 it => now
80
81 CONF;
82                 $txt = $this->execute(['config', 'test', '-v']);
83
84                 $this->assertEquals($assertion, $txt);
85         }
86 }