]> git.mxchange.org Git - friendica.git/blob - tests/src/Core/Console/AutomaticInstallationConsoleTest.php
df679ed38c1f4873c34d9e2350b40ab5678c26aa
[friendica.git] / tests / src / Core / Console / AutomaticInstallationConsoleTest.php
1 <?php
2
3 namespace Friendica\Test\src\Core\Console;
4
5 use Friendica\Core\Config\Cache\ConfigCache;
6 use Friendica\Core\Console\AutomaticInstallation;
7 use Friendica\Core\Installer;
8 use Friendica\Core\Logger;
9 use Friendica\Test\Util\DBAMockTrait;
10 use Friendica\Test\Util\DBStructureMockTrait;
11 use Friendica\Test\Util\L10nMockTrait;
12 use Friendica\Test\Util\RendererMockTrait;
13 use Friendica\Util\Logger\VoidLogger;
14 use org\bovigo\vfs\vfsStream;
15 use org\bovigo\vfs\vfsStreamFile;
16
17 /**
18  * @runTestsInSeparateProcesses
19  * @preserveGlobalState disabled
20  * @requires PHP 7.0
21  */
22 class AutomaticInstallationConsoleTest extends ConsoleTest
23 {
24         use L10nMockTrait;
25         use DBAMockTrait;
26         use DBStructureMockTrait;
27         use RendererMockTrait;
28
29         private $db_host;
30         private $db_port;
31         private $db_data;
32         private $db_user;
33         private $db_pass;
34
35         /**
36          * @var vfsStreamFile Assert file without DB credentials
37          */
38         private $assertFile;
39         /**
40          * @var vfsStreamFile Assert file with DB credentials
41          */
42         private $assertFileDb;
43
44         public function setUp()
45         {
46                 parent::setUp();
47
48                 if ($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.config.php')) {
49                         $this->root->getChild('config')
50                                 ->removeChild('local.config.php');
51                 }
52
53                 $this->db_host = getenv('MYSQL_HOST');
54                 $this->db_port = !empty(getenv('MYSQL_PORT')) ? getenv('MYSQL_PORT') : null;
55                 $this->db_data = getenv('MYSQL_DATABASE');
56                 $this->db_user = getenv('MYSQL_USERNAME') . getenv('MYSQL_USER');
57                 $this->db_pass = getenv('MYSQL_PASSWORD');
58
59                 $this->mockL10nT();
60         }
61
62         /**
63          * Returns the dataset for each automatic installation test
64          *
65          * @return array the dataset
66          */
67         public function dataInstaller()
68         {
69                 return [
70                         'empty' => [
71                                 'data' => [
72                                         'database' => [
73                                                 'hostname'    => '',
74                                                 'username'    => '',
75                                                 'password'    => '',
76                                                 'database'    => '',
77                                                 'port'        => '',
78                                         ],
79                                         'config' => [
80                                                 'php_path'    => '',
81                                                 'hostname'    => '',
82                                                 'admin_email' => '',
83                                         ],
84                                         'system' => [
85                                                 'urlpath'     => '',
86                                                 'url'         => '',
87                                                 'basepath'    => '',
88                                                 'ssl_policy'  => '',
89                                                 'default_timezone' => '',
90                                                 'language'    => '',
91                                         ],
92                                 ],
93                         ],
94                         'normal' => [
95                                 'data' => [
96                                         'database' => [
97                                                 'hostname'    => getenv('MYSQL_HOST'),
98                                                 'port'        =>!empty(getenv('MYSQL_PORT')) ? getenv('MYSQL_PORT') : null,
99                                                 'username'    => getenv('MYSQL_USERNAME'),
100                                                 'password'    => getenv('MYSQL_PASSWORD'),
101                                                 'database'    => getenv('MYSQL_DATABASE'),
102                                         ],
103                                         'config' => [
104                                                 'php_path'    => '',
105                                                 'hostname'    => 'friendica.local',
106                                                 'admin_email' => 'admin@philipp.info',
107                                         ],
108                                         'system' => [
109                                                 'urlpath'     => 'test/it',
110                                                 'url'         => 'friendica.local/test/it',
111                                                 'basepath'    => '',
112                                                 'ssl_policy'  => '2',
113                                                 'default_timezone' => 'en',
114                                                 'language'    => 'Europe/Berlin',
115                                         ],
116                                 ],
117                         ],
118                 ];
119         }
120
121         private function assertFinished($txt, $withconfig = false, $copyfile = false)
122         {
123                 $cfg = '';
124
125                 if ($withconfig) {
126                         $cfg = <<<CFG
127
128
129 Creating config file...
130
131  Complete!
132 CFG;
133                 }
134
135                 if ($copyfile) {
136                         $cfg = <<<CFG
137
138
139 Copying config file...
140
141  Complete!
142 CFG;
143                 }
144
145                 $finished = <<<FIN
146 Initializing setup...
147
148  Complete!
149
150
151 Checking environment...
152
153  NOTICE: Not checking .htaccess/URL-Rewrite during CLI installation.
154
155  Complete!
156 {$cfg}
157
158
159 Checking database...
160
161  Complete!
162
163
164 Inserting data into database...
165
166  Complete!
167
168
169 Installing theme
170
171  Complete
172
173
174
175 Installation is finished
176
177
178 FIN;
179                 $this->assertEquals($finished, $txt);
180         }
181
182         private function assertStuckDB($txt)
183         {
184                 $finished = <<<FIN
185 Initializing setup...
186
187  Complete!
188
189
190 Checking environment...
191
192  NOTICE: Not checking .htaccess/URL-Rewrite during CLI installation.
193
194  Complete!
195
196
197 Creating config file...
198
199  Complete!
200
201
202 Checking database...
203
204 [Error] --------
205 Could not connect to database.: 
206
207
208 FIN;
209
210                 $this->assertEquals($finished, $txt);
211         }
212
213         /**
214          * Test the automatic installation without any parameter/setting
215          */
216         public function testEmpty()
217         {
218                 $configCache = new ConfigCache();
219                 $configCache->set('system', 'basepath', $this->root->url());
220                 $configCache->set('config', 'php_path', trim(shell_exec('which php')));
221
222                 $this->mockApp($this->root, null, true);
223
224                 $this->configMock->shouldReceive('set')->andReturnUsing(function ($cat, $key, $value) use ($configCache) {
225                         if ($key !== 'basepath') {
226                                 return $configCache->set($cat, $key, $value);
227                         } else {
228                                 return true;
229                         }
230                 });;
231                 $this->configMock->shouldReceive('has')->andReturn(true);
232                 $this->configMock->shouldReceive('get')->andReturnUsing(function ($cat, $key) use ($configCache) {
233                         return $configCache->get($cat, $key);
234                 });
235
236                 $this->mockConnect(true, 1);
237                 $this->mockConnected(true, 1);
238                 $this->mockExistsTable('user', false, 1);
239                 $this->mockUpdate([$this->root->url(), false, true, true], null, 1);
240
241                 $this->mockGetMarkupTemplate('local.config.tpl', 'testTemplate', 1);
242                 $this->mockReplaceMacros('testTemplate', \Mockery::any(), '', 1);
243
244                 $console = new AutomaticInstallation($this->consoleArgv);
245
246                 $txt = $this->dumpExecute($console);
247
248                 $this->assertFinished($txt, true, false);
249                 $this->assertTrue($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.config.php'));
250
251                 // Assert the default values without any config
252                 $this->assertEquals(Installer::DEFAULT_HOST, $configCache->get('database', 'hostname'));
253                 $this->assertEmpty($configCache->get('database', 'username'));
254                 $this->assertEmpty($configCache->get('database', 'password'));
255                 $this->assertEmpty($configCache->get('database', 'database'));
256
257                 $this->assertEmpty($configCache->get('config', 'hostname'), $configCache->get('config', 'hostname'));
258                 $this->assertEmpty($configCache->get('config', 'admin_email'), $configCache->get('config', 'admin_email'));
259                 $this->assertEquals(trim(shell_exec('which php')), $configCache->get('config', 'php_path'));
260
261                 $this->assertEquals(Installer::DEFAULT_TZ, $configCache->get('system', 'default_timezone'));
262                 $this->assertEquals(Installer::DEFAULT_LANG, $configCache->get('system', 'language'));
263                 $this->assertEquals(SSL_POLICY_NONE, $configCache->get('system', 'ssl_policy'));
264                 $this->assertEmpty($configCache->get('system', 'urlpath'), $configCache->get('system', 'urlpath'));
265                 $this->assertEquals($this->root->url(), $configCache->get('system', 'basepath'));
266         }
267
268         /**
269          * Test the automatic installation with a prepared config file
270          * @dataProvider dataInstaller
271          */
272         public function testWithConfig(array $data)
273         {
274                 $configCache = new ConfigCache();
275                 $configCache->load($data);
276                 $configCache->set('system', 'basepath', $this->root->url());
277                 $configCache->set('config', 'php_path', trim(shell_exec('which php')));
278
279                 $this->mockApp($this->root, $configCache, true);
280                 $this->mode->shouldReceive('isInstall')->andReturn(false);
281                 Logger::init(new VoidLogger());
282
283                 $this->mockConnect(true, 1);
284                 $this->mockConnected(true, 1);
285                 $this->mockExistsTable('user', false, 1);
286                 $this->mockUpdate([$this->root->url(), false, true, true], null, 1);
287
288                 $conf = function ($cat, $key) use ($configCache) {
289                         return $configCache->get($cat, $key);
290                 };
291
292                 $config = <<<CONF
293 <?php
294
295 // Local configuration
296
297 // If you're unsure about what any of the config keys below do, please check the config/defaults.config.php for detailed
298 // documentation of their data type and behavior.
299
300 return [
301         'database' => [
302                 'hostname' => '{$conf('database','hostname')}',
303                 'username' => '{$conf('database', 'username')}',
304                 'password' => '{$conf('database', 'password')}',
305                 'database' => '{$conf('database', 'database')}',
306                 'charset' => 'utf8mb4',
307         ],
308
309         // ****************************************************************
310         // The configuration below will be overruled by the admin panel.
311         // Changes made below will only have an effect if the database does
312         // not contain any configuration for the friendica system.
313         // ****************************************************************
314
315         'config' => [
316                 'admin_email' => '{$conf('config', 'admin_email')}',
317                 'hostname' => '{$conf('config', 'hostname')}',
318                 'sitename' => 'Friendica Social Network',
319                 'register_policy' => \Friendica\Module\Register::OPEN,
320                 'register_text' => '',
321         ],
322         'system' => [
323                 'basepath => '{$conf('system', 'basepath')}',
324                 'urlpath => '{$conf('system', 'urlpath')}',
325                 'url' => '{$conf('system', 'url')}',
326                 'default_timezone' => '{$conf('system', 'default_timezone')}',
327                 'language' => '{$conf('system', 'language')}',
328         ],
329 ];
330 CONF;
331
332                 vfsStream::newFile('prepared.config.php')
333                         ->at($this->root)
334                         ->setContent($config);
335
336                 $console = new AutomaticInstallation($this->consoleArgv);
337                 $console->setOption('f', 'prepared.config.php');
338
339                 $txt = $this->dumpExecute($console);
340
341                 $this->assertFinished($txt, false, true);
342
343                 $this->assertTrue($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.config.php'));
344                 $this->assertEquals($config, file_get_contents($this->root->getChild('config' . DIRECTORY_SEPARATOR . 'local.config.php')->url()));
345         }
346
347         /**
348          * Test the automatic installation with environment variables
349          * Includes saving the DB credentials to the file
350          * @dataProvider dataInstaller
351          */
352         public function testWithEnvironmentAndSave(array $data)
353         {
354                 $configCache = new ConfigCache();
355                 $configCache->set('system', 'basepath', $this->root->url());
356                 $configCache->set('config', 'php_path', trim(shell_exec('which php')));
357
358                 $this->mockApp($this->root, null, true);
359
360                 $this->configMock->shouldReceive('set')->andReturnUsing(function ($cat, $key, $value) use ($configCache) {
361                         if ($key !== 'basepath') {
362                                 return $configCache->set($cat, $key, $value);
363                         } else {
364                                 return true;
365                         }
366                 });;
367                 $this->configMock->shouldReceive('has')->andReturn(true);
368                 $this->configMock->shouldReceive('get')->andReturnUsing(function ($cat, $key) use ($configCache) {
369                         return $configCache->get($cat, $key);
370                 });
371
372                 $this->mockConnect(true, 1);
373                 $this->mockConnected(true, 1);
374                 $this->mockExistsTable('user', false, 1);
375                 $this->mockUpdate([$this->root->url(), false, true, true], null, 1);
376
377                 $this->mockGetMarkupTemplate('local.config.tpl', 'testTemplate', 1);
378                 $this->mockReplaceMacros('testTemplate', \Mockery::any(), '', 1);
379
380                 $this->assertTrue(putenv('MYSQL_HOST='     . $data['database']['hostname']));
381                 $this->assertTrue(putenv('MYSQL_PORT='     . $data['database']['port']));
382                 $this->assertTrue(putenv('MYSQL_DATABASE=' . $data['database']['database']));
383                 $this->assertTrue(putenv('MYSQL_USERNAME=' . $data['database']['username']));
384                 $this->assertTrue(putenv('MYSQL_PASSWORD=' . $data['database']['password']));
385
386                 $this->assertTrue(putenv('FRIENDICA_URL_PATH='   . $data['system']['urlpath']));
387                 $this->assertTrue(putenv('FRIENDICA_BASE_PATH='  . $data['system']['basepath']));
388                 $this->assertTrue(putenv('FRIENDICA_PHP_PATH='   . $data['config']['php_path']));
389                 $this->assertTrue(putenv('FRIENDICA_SSL_POLICY=' . $data['system']['ssl_policy']));
390                 $this->assertTrue(putenv('FRIENDICA_HOSTNAME='   . $data['config']['hostname']));
391                 $this->assertTrue(putenv('FRIENDICA_ADMIN_MAIL=' . $data['config']['admin_email']));
392                 $this->assertTrue(putenv('FRIENDICA_TZ='         . $data['system']['default_timezone']));
393                 $this->assertTrue(putenv('FRIENDICA_LANG='       . $data['system']['language']));
394
395                 $console = new AutomaticInstallation($this->consoleArgv);
396                 $console->setOption('savedb', true);
397
398                 $txt = $this->dumpExecute($console);
399
400                 // Assert the default values without any config
401                 $dbhost = $data['database']['hostname'] . (!empty($data['database']['port']) ? ':' . $data['database']['port'] : '');
402                 $this->assertEquals($dbhost, $configCache->get('database', 'hostname'));
403                 $this->assertEquals($data['database']['username'], $configCache->get('database', 'username'));
404                 $this->assertEquals($data['database']['database'], $configCache->get('database', 'database'));
405                 $this->assertEquals($data['database']['password'], $configCache->get('database', 'password'));
406
407                 $this->assertEquals($data['config']['hostname'], $configCache->get('config', 'hostname'));
408                 $this->assertEquals($data['config']['admin_email'], $configCache->get('config', 'admin_email'));
409                 $this->assertEquals(trim(shell_exec('which php')), $configCache->get('config', 'php_path'));
410
411                 $this->assertEquals((!empty($data['system']['default_timezone']) ? $data['system']['default_timezone'] : Installer::DEFAULT_TZ),
412                         $configCache->get('system', 'default_timezone'));
413                 $this->assertEquals((!empty($data['system']['language']) ? $data['system']['language'] : Installer::DEFAULT_LANG),
414                         $configCache->get('system', 'language'));
415                 $this->assertEquals((!empty($data['system']['ssl_policy']) ? $data['system']['ssl_policy'] : SSL_POLICY_NONE),
416                         $configCache->get('system', 'ssl_policy'));
417                 $this->assertEquals((!empty($data['system']['urlpath']) ? $data['system']['urlpath'] : null),
418                         $configCache->get('system', 'urlpath'));
419
420                 $this->assertFinished($txt, true);
421         }
422
423         /**
424          * Test the automatic installation with environment variables
425          * Don't save the db credentials to the file
426          * @dataProvider dataInstaller
427          */
428         public function testWithEnvironmentWithoutSave(array $data)
429         {
430                 $configCache = new ConfigCache();
431                 $configCache->set('system', 'basepath', $this->root->url());
432                 $configCache->set('config', 'php_path', trim(shell_exec('which php')));
433
434                 $this->mockApp($this->root, null, true);
435
436                 $this->configMock->shouldReceive('set')->andReturnUsing(function ($cat, $key, $value) use ($configCache) {
437                         if ($key !== 'basepath') {
438                                 return $configCache->set($cat, $key, $value);
439                         } else {
440                                 return true;
441                         }
442                 });;
443                 $this->configMock->shouldReceive('has')->andReturn(true);
444                 $this->configMock->shouldReceive('get')->andReturnUsing(function ($cat, $key) use ($configCache) {
445                         return $configCache->get($cat, $key);
446                 });
447
448                 $this->mockConnect(true, 1);
449                 $this->mockConnected(true, 1);
450                 $this->mockExistsTable('user', false, 1);
451                 $this->mockUpdate([$this->root->url(), false, true, true], null, 1);
452
453                 $this->mockGetMarkupTemplate('local.config.tpl', 'testTemplate', 1);
454                 $this->mockReplaceMacros('testTemplate', \Mockery::any(), '', 1);
455
456                 $this->assertTrue(putenv('MYSQL_HOST=' . $data['database']['hostname']));
457                 $this->assertTrue(putenv('MYSQL_PORT=' . $data['database']['port']));
458                 $this->assertTrue(putenv('MYSQL_DATABASE=' . $data['database']['database']));
459                 $this->assertTrue(putenv('MYSQL_USERNAME=' . $data['database']['username']));
460                 $this->assertTrue(putenv('MYSQL_PASSWORD=' . $data['database']['password']));
461
462                 $this->assertTrue(putenv('FRIENDICA_URL_PATH=' . $data['system']['urlpath']));
463                 $this->assertTrue(putenv('FRIENDICA_BASE_PATH=' . $data['system']['basepath']));
464                 $this->assertTrue(putenv('FRIENDICA_PHP_PATH=' . $data['config']['php_path']));
465                 $this->assertTrue(putenv('FRIENDICA_SSL_POLICY=' . $data['system']['ssl_policy']));
466                 $this->assertTrue(putenv('FRIENDICA_HOSTNAME=' . $data['config']['hostname']));
467                 $this->assertTrue(putenv('FRIENDICA_ADMIN_MAIL=' . $data['config']['admin_email']));
468                 $this->assertTrue(putenv('FRIENDICA_TZ=' . $data['system']['default_timezone']));
469                 $this->assertTrue(putenv('FRIENDICA_LANG=' . $data['system']['language']));
470
471                 $console = new AutomaticInstallation($this->consoleArgv);
472
473                 $txt = $this->dumpExecute($console);
474
475                 $this->assertEquals(Installer::DEFAULT_HOST, $configCache->get('database', 'hostname'));
476                 $this->assertEmpty($configCache->get('database', 'username'), $configCache->get('database', 'username'));
477                 $this->assertEmpty($configCache->get('database', 'password'), $configCache->get('database', 'password'));
478                 $this->assertEmpty($configCache->get('database', 'database'), $configCache->get('database', 'database'));
479
480                 $this->assertEquals($data['config']['hostname'], $configCache->get('config', 'hostname'));
481                 $this->assertEquals($data['config']['admin_email'], $configCache->get('config', 'admin_email'));
482                 $this->assertEquals(trim(shell_exec('which php')), $configCache->get('config', 'php_path'));
483
484                 $this->assertEquals((!empty($data['system']['default_timezone']) ? $data['system']['default_timezone'] : Installer::DEFAULT_TZ),
485                         $configCache->get('system', 'default_timezone'));
486                 $this->assertEquals((!empty($data['system']['language']) ? $data['system']['language'] : Installer::DEFAULT_LANG),
487                         $configCache->get('system', 'language'));
488                 $this->assertEquals((!empty($data['system']['ssl_policy']) ? $data['system']['ssl_policy'] : SSL_POLICY_NONE),
489                         $configCache->get('system', 'ssl_policy'));
490                 $this->assertEquals((!empty($data['system']['urlpath']) ? $data['system']['urlpath'] : null),
491                         $configCache->get('system', 'urlpath'));
492
493                 $this->assertFinished($txt, true);
494         }
495
496         /**
497          * Test the automatic installation with arguments
498          * @dataProvider dataInstaller
499          */
500         public function testWithArguments(array $data)
501         {
502                 $configCache = new ConfigCache();
503                 $configCache->set('system', 'basepath', $this->root->url());
504                 $configCache->set('config', 'php_path', trim(shell_exec('which php')));
505
506                 $this->mockApp($this->root, null, true);
507
508                 $this->configMock->shouldReceive('set')->andReturnUsing(function ($cat, $key, $value) use ($configCache) {
509                         if ($key !== 'basepath') {
510                                 return $configCache->set($cat, $key, $value);
511                         } else {
512                                 return true;
513                         }
514                 });;
515                 $this->configMock->shouldReceive('has')->andReturn(true);
516                 $this->configMock->shouldReceive('get')->andReturnUsing(function ($cat, $key) use ($configCache) {
517                         return $configCache->get($cat, $key);
518                 });
519
520                 $this->mockConnect(true, 1);
521                 $this->mockConnected(true, 1);
522                 $this->mockExistsTable('user', false, 1);
523                 $this->mockUpdate([$this->root->url(), false, true, true], null, 1);
524
525                 $this->mockGetMarkupTemplate('local.config.tpl', 'testTemplate', 1);
526                 $this->mockReplaceMacros('testTemplate', \Mockery::any(), '', 1);
527
528                 $console = new AutomaticInstallation($this->consoleArgv);
529
530                 if (!empty($data['database']['hostname'])) {
531                         $console->setOption('dbhost', $data['database']['hostname']);
532                 }
533                 if (!empty($data['database']['port'])) {
534                         $console->setOption('dbport', $data['database']['port']);
535                 }
536                 if (!empty($data['database']['username'])) {
537                         $console->setOption('dbuser', $data['database']['username']);
538                 }
539                 if (!empty($data['database']['password'])) {
540                         $console->setOption('dbpass', $data['database']['password']);
541                 }
542                 if (!empty($data['database']['database'])) {
543                         $console->setOption('dbdata', $data['database']['database']);
544                 }
545                 if (!empty($data['system']['urlpath'])) {
546                         $console->setOption('urlpath', $data['system']['urlpath']);
547                 }
548                 if (!empty($data['system']['basepath'])) {
549                         $console->setOption('basepath', $data['system']['basepath']);
550                 }
551                 if (!empty($data['config']['php_path'])) {
552                         $console->setOption('phppath', $data['config']['php_path']);
553                 }
554                 if (!empty($data['system']['ssl_policy'])) {
555                         $console->setOption('sslpolicy', $data['system']['ssl_policy']);
556                 }
557                 if (!empty($data['config']['hostname'])) {
558                         $console->setOption('hostname', $data['config']['hostname']);
559                 }
560                 if (!empty($data['config']['admin_email'])) {
561                         $console->setOption('admin', $data['config']['admin_email']);
562                 }
563                 if (!empty($data['system']['default_timezone'])) {
564                         $console->setOption('tz', $data['system']['default_timezone']);
565                 }
566                 if (!empty($data['system']['language'])) {
567                         $console->setOption('lang', $data['system']['language']);
568                 }
569
570                 $txt = $this->dumpExecute($console);
571
572                 $dbhost = (!empty($data['database']['hostname'])) ? $data['database']['hostname'] : Installer::DEFAULT_HOST;
573                 $dbhost .= (!empty($data['database']['port']) ? ':' . $data['database']['port'] : '');
574                 $this->assertEquals($dbhost, $configCache->get('database', 'hostname'));
575                 $this->assertEquals($data['database']['username'], $configCache->get('database', 'username'));
576                 $this->assertEquals($data['database']['database'], $configCache->get('database', 'database'));
577                 $this->assertEquals($data['database']['password'], $configCache->get('database', 'password'));
578
579                 $this->assertEquals($data['config']['hostname'], $configCache->get('config', 'hostname'));
580                 $this->assertEquals($data['config']['admin_email'], $configCache->get('config', 'admin_email'));
581                 $this->assertEquals(trim(shell_exec('which php')), $configCache->get('config', 'php_path'));
582
583                 $this->assertEquals((!empty($data['system']['default_timezone']) ? $data['system']['default_timezone'] : Installer::DEFAULT_TZ),
584                         $configCache->get('system', 'default_timezone'));
585                 $this->assertEquals((!empty($data['system']['language']) ? $data['system']['language'] : Installer::DEFAULT_LANG),
586                         $configCache->get('system', 'language'));
587                 $this->assertEquals((!empty($data['system']['ssl_policy']) ? $data['system']['ssl_policy'] : SSL_POLICY_NONE),
588                         $configCache->get('system', 'ssl_policy'));
589                 $this->assertEquals((!empty($data['system']['urlpath']) ? $data['system']['urlpath'] : null),
590                         $configCache->get('system', 'urlpath'));
591
592                 $this->assertFinished($txt, true);
593         }
594
595         /**
596          * Test the automatic installation with a wrong database connection
597          */
598         public function testNoDatabaseConnection()
599         {
600                 $configCache = new ConfigCache();
601                 $configCache->set('system', 'basepath', $this->root->url());
602                 $configCache->set('config', 'php_path', trim(shell_exec('which php')));
603
604                 $this->mockApp($this->root, null, true);
605
606                 $this->configMock->shouldReceive('set')->andReturnUsing(function ($cat, $key, $value) use ($configCache) {
607                         if ($key !== 'basepath') {
608                                 return $configCache->set($cat, $key, $value);
609                         } else {
610                                 return true;
611                         }
612                 });;
613                 $this->configMock->shouldReceive('has')->andReturn(true);
614                 $this->configMock->shouldReceive('get')->andReturnUsing(function ($cat, $key) use ($configCache) {
615                         return $configCache->get($cat, $key);
616                 });
617
618                 $this->mockConnect(false, 1);
619
620                 $this->mockGetMarkupTemplate('local.config.tpl', 'testTemplate', 1);
621                 $this->mockReplaceMacros('testTemplate', \Mockery::any(), '', 1);
622
623                 $console = new AutomaticInstallation($this->consoleArgv);
624
625                 $txt = $this->dumpExecute($console);
626
627                 $this->assertStuckDB($txt);
628                 $this->assertTrue($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.config.php'));
629
630                 // Assert the default values without any config
631                 $this->assertEquals(Installer::DEFAULT_HOST, $configCache->get('database', 'hostname'));
632                 $this->assertEmpty($configCache->get('database', 'username'));
633                 $this->assertEmpty($configCache->get('database', 'password'));
634                 $this->assertEmpty($configCache->get('database', 'database'));
635
636                 $this->assertEmpty($configCache->get('config', 'hostname'), $configCache->get('config', 'hostname'));
637                 $this->assertEmpty($configCache->get('config', 'admin_email'), $configCache->get('config', 'admin_email'));
638                 $this->assertEquals(trim(shell_exec('which php')), $configCache->get('config', 'php_path'));
639
640                 $this->assertEquals(Installer::DEFAULT_TZ, $configCache->get('system', 'default_timezone'));
641                 $this->assertEquals(Installer::DEFAULT_LANG, $configCache->get('system', 'language'));
642                 $this->assertEquals(SSL_POLICY_NONE, $configCache->get('system', 'ssl_policy'));
643                 $this->assertEmpty($configCache->get('system', 'urlpath'), $configCache->get('system', 'urlpath'));
644                 $this->assertEquals($this->root->url(), $configCache->get('system', 'basepath'));
645         }
646
647         public function testGetHelp()
648         {
649                 // Usable to purposely fail if new commands are added without taking tests into account
650                 $theHelp = <<<HELP
651 Installation - Install Friendica automatically
652 Synopsis
653         bin/console autoinstall [-h|--help|-?] [-v] [-a] [-f]
654
655 Description
656     Installs Friendica with data based on the local.config.php file or environment variables
657
658 Notes
659     Not checking .htaccess/URL-Rewrite during CLI installation.
660
661 Options
662     -h|--help|-?            Show help information
663     -v                      Show more debug information.
664     -a                      All setup checks are required (except .htaccess)
665     -f|--file <config>      prepared config file (e.g. "config/local.config.php" itself) which will override every other config option - except the environment variables)
666     -s|--savedb                 Save the DB credentials to the file (if environment variables is used)
667     -H|--dbhost <host>          The host of the mysql/mariadb database (env MYSQL_HOST)
668     -p|--dbport <port>          The port of the mysql/mariadb database (env MYSQL_PORT)
669     -d|--dbdata <database>      The name of the mysql/mariadb database (env MYSQL_DATABASE)
670     -U|--dbuser <username>      The username of the mysql/mariadb database login (env MYSQL_USER or MYSQL_USERNAME)
671     -P|--dbpass <password>      The password of the mysql/mariadb database login (env MYSQL_PASSWORD)
672     -U|--urlpath <url_path>     The URL path of Friendica - f.e. '/friendica' (env FRIENDICA_URL_PATH) 
673     -B|--phppath <php_path>     The path of the PHP binary (env FRIENDICA_PHP_PATH)
674     -b|--basepath <base_path>   The basepath of Friendica(env FRIENDICA_BASE_PATH)
675     -S|--sslpolicy <ssl_policy> The SSL policy of Friendica (env FRIENDICA_SSL_POLICY) 
676     -n|--hostname <hostname>    The hostname of Friendica (env FRIENDICA_PHP_HOSTNAME)  
677     -t|--tz <timezone>          The timezone of Friendica (env FRIENDICA_TZ)
678     -L|--lang <language>        The language of Friendica (env FRIENDICA_LANG)
679  
680 Environment variables
681    MYSQL_HOST                  The host of the mysql/mariadb database (mandatory if mysql and environment is used)
682    MYSQL_PORT                  The port of the mysql/mariadb database
683    MYSQL_USERNAME|MYSQL_USER   The username of the mysql/mariadb database login (MYSQL_USERNAME is for mysql, MYSQL_USER for mariadb)
684    MYSQL_PASSWORD              The password of the mysql/mariadb database login
685    MYSQL_DATABASE              The name of the mysql/mariadb database
686    FRIENDICA_URL_PATH          The URL path of Friendica (f.e. '/friendica') - leave empty for auto detection
687    FRIENDICA_PHP_PATH          The path of the PHP binary - leave empty for auto detection
688    FRIENDICA_BASE_PATH         The basepath of Friendica - leave empty for auto detection
689    FRIENDICA_ADMIN_MAIL        The admin email address of Friendica (this email will be used for admin access)
690    FRIENDICA_SSL_POLICY        The SSL policy of Friendica (default is NO SSL)
691    FRIENDICA_HOSTNAME          The hostname of Friendica - leave empty for auto detection
692    FRIENDICA_TZ                The timezone of Friendica
693    FRIENDICA_LANG              The langauge of Friendica
694    
695 Examples
696         bin/console autoinstall -f 'input.config.php
697                 Installs Friendica with the prepared 'input.config.php' file
698
699         bin/console autoinstall --savedb
700                 Installs Friendica with environment variables and saves them to the 'config/local.config.php' file
701
702         bin/console autoinstall -h localhost -p 3365 -U user -P passwort1234 -d friendica
703                 Installs Friendica with a local mysql database with credentials
704
705 HELP;
706
707                 $console = new AutomaticInstallation($this->consoleArgv);
708                 $console->setOption('help', true);
709
710                 $txt = $this->dumpExecute($console);
711
712                 $this->assertEquals($txt, $theHelp);
713         }
714 }