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