3 namespace Friendica\Test\src\Core\Console;
5 use org\bovigo\vfs\vfsStream;
8 * @runTestsInSeparateProcesses
9 * @preserveGlobalState disabled
12 class AutomaticInstallationConsoleTest extends ConsoleTest
20 public function setUp()
24 if ($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.ini.php')) {
25 $this->root->getChild('config')
26 ->removeChild('local.ini.php');
29 $this->db_host = getenv('MYSQL_HOST');
30 $this->db_port = (!empty(getenv('MYSQL_PORT'))) ? getenv('MYSQL_PORT') : null;
31 $this->db_data = getenv('MYSQL_DATABASE');
32 $this->db_user = getenv('MYSQL_USERNAME') . getenv('MYSQL_USER');
33 $this->db_pass = getenv('MYSQL_PASSWORD');
35 // Mocking 'DBStructure::existsTable()' because with CI, we cannot create an empty database
36 // therefore we temporary override the existing database
37 /// @todo Mocking the DB-Calls of ConsoleTest so we don't need this specific mock anymore
38 $existsMock = \Mockery::mock('alias:Friendica\Database\DBStructure');
39 $existsMock->shouldReceive('existsTable')
44 private function assertConfig($family, $key, $value)
46 $config = $this->execute(['config', $family, $key]);
47 $this->assertEquals($family . "." . $key . " => " . $value . "\n", $config);
50 private function assertFinished($txt, $withconfig = false, $copyfile = false)
58 Creating config file...
68 Copying config file...
80 Checking environment...
82 NOTICE: Not checking .htaccess/URL-Rewrite during CLI installation.
93 Inserting data into database...
104 Installation is finished
108 $this->assertEquals($finished, $txt);
111 private function assertStuckDB($txt)
114 Initializing setup...
116 Creating config file...
121 Checking basic setup...
123 NOTICE: Not checking .htaccess/URL-Rewrite during CLI installation.
131 MySQL Connection: Failed, please check your MySQL settings and credentials.
136 $this->assertEquals($finished, $txt);
142 public function testWithConfig()
155 ; ****************************************************************
156 ; The configuration below will be overruled by the admin panel.
157 ; Changes made below will only have an effect if the database does
158 ; not contain any configuration for the friendica system.
159 ; ****************************************************************
164 sitename = Friendica Social Network
166 register_policy = REGISTER_OPEN
170 default_timezone = UTC
178 vfsStream::newFile('prepared.ini.php')
180 ->setContent($config);
182 $txt = $this->execute(['autoinstall', '-f', 'prepared.ini.php']);
184 $this->assertFinished($txt, false, true);
186 $this->assertTrue($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.ini.php'));
192 public function testWithEnvironmentAndSave()
194 $this->assertTrue(putenv('FRIENDICA_ADMIN_MAIL=admin@friendica.local'));
195 $this->assertTrue(putenv('FRIENDICA_TZ=Europe/Berlin'));
196 $this->assertTrue(putenv('FRIENDICA_LANG=de'));
198 $txt = $this->execute(['autoinstall', '--savedb']);
200 $this->assertFinished($txt, true);
202 $this->assertTrue($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.ini.php'));
204 $this->assertConfig('database', 'hostname', $this->db_host . (!empty($this->db_port) ? ':' . $this->db_port : ''));
205 $this->assertConfig('database', 'username', $this->db_user);
206 $this->assertConfig('database', 'database', $this->db_data);
207 $this->assertConfig('config', 'admin_email', 'admin@friendica.local');
208 $this->assertConfig('system', 'default_timezone', 'Europe/Berlin');
209 // TODO language changes back to en
210 //$this->assertConfig('system', 'language', 'de');
216 public function testWithEnvironmentWithoutSave()
218 $this->assertTrue(putenv('FRIENDICA_ADMIN_MAIL=admin@friendica.local'));
219 $this->assertTrue(putenv('FRIENDICA_TZ=Europe/Berlin'));
220 $this->assertTrue(putenv('FRIENDICA_LANG=de'));
221 $this->assertTrue(putenv('FRIENDICA_URL_PATH=/friendica'));
223 $txt = $this->execute(['autoinstall']);
225 $this->assertFinished($txt, true);
227 $this->assertTrue($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.ini.php'));
229 $this->assertConfig('database', 'hostname', '');
230 $this->assertConfig('database', 'username', '');
231 $this->assertConfig('database', 'database', '');
232 $this->assertConfig('config', 'admin_email', 'admin@friendica.local');
233 $this->assertConfig('system', 'default_timezone', 'Europe/Berlin');
234 $this->assertConfig('system', 'urlpath', '/friendica');
235 // TODO language changes back to en
236 //$this->assertConfig('system', 'language', 'de');
242 public function testWithArguments()
244 $args = ['autoinstall'];
245 array_push($args, '--dbhost');
246 array_push($args, $this->db_host);
247 array_push($args, '--dbuser');
248 array_push($args, $this->db_user);
249 if (!empty($this->db_pass)) {
250 array_push($args, '--dbpass');
251 array_push($args, $this->db_pass);
253 if (!empty($this->db_port)) {
254 array_push($args, '--dbport');
255 array_push($args, $this->db_port);
257 array_push($args, '--dbdata');
258 array_push($args, $this->db_data);
260 array_push($args, '--admin');
261 array_push($args, 'admin@friendica.local');
262 array_push($args, '--tz');
263 array_push($args, 'Europe/Berlin');
264 array_push($args, '--lang');
265 array_push($args, 'de');
267 array_push($args, '--urlpath');
268 array_push($args, '/friendica');
270 $txt = $this->execute($args);
272 $this->assertFinished($txt, true);
274 $this->assertTrue($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.ini.php'));
276 $this->assertConfig('database', 'hostname', $this->db_host . (!empty($this->db_port) ? ':' . $this->db_port : ''));
277 $this->assertConfig('database', 'username', $this->db_user);
278 $this->assertConfig('database', 'database', $this->db_data);
279 $this->assertConfig('config', 'admin_email', 'admin@friendica.local');
280 $this->assertConfig('system', 'default_timezone', 'Europe/Berlin');
281 $this->assertConfig('system', 'urlpath', '/friendica');
282 // TODO language changes back to en
283 //$this->assertConfig('system', 'language', 'de');
287 * @runTestsInSeparateProcesses
288 * @preserveGlobalState disabled
290 public function testNoDatabaseConnection()
292 // TODO DBA mocking for whole console tests make this test work again
293 $this->markTestSkipped('DBA is already loaded, we have to mock the whole App to make it work');
295 $dbaMock = \Mockery::mock('alias:Friendica\Database\DBA');
297 ->shouldReceive('connected')
300 $txt = $this->execute(['autoinstall']);
302 $this->assertStuckDB($txt);
305 public function testGetHelp()
307 // Usable to purposely fail if new commands are added without taking tests into account
309 Installation - Install Friendica automatically
311 bin/console autoinstall [-h|--help|-?] [-v] [-a] [-f]
314 Installs Friendica with data based on the local.ini.php file or environment variables
317 Not checking .htaccess/URL-Rewrite during CLI installation.
320 -h|--help|-? Show help information
321 -v Show more debug information.
322 -a All setup checks are required (except .htaccess)
323 -f|--file <config> prepared config file (e.g. "config/local.ini.php" itself) which will override every other config option - except the environment variables)
324 -s|--savedb Save the DB credentials to the file (if environment variables is used)
325 -H|--dbhost <host> The host of the mysql/mariadb database (env MYSQL_HOST)
326 -p|--dbport <port> The port of the mysql/mariadb database (env MYSQL_PORT)
327 -d|--dbdata <database> The name of the mysql/mariadb database (env MYSQL_DATABASE)
328 -U|--dbuser <username> The username of the mysql/mariadb database login (env MYSQL_USER or MYSQL_USERNAME)
329 -P|--dbpass <password> The password of the mysql/mariadb database login (env MYSQL_PASSWORD)
330 -u|--urlpath <url_path> The URL path of Friendica - f.e. '/friendica' (env FRIENDICA_URL_PATH)
331 -b|--phppath <php_path> The path of the PHP binary (env FRIENDICA_PHP_PATH)
332 -A|--admin <mail> The admin email address of Friendica (env FRIENDICA_ADMIN_MAIL)
333 -T|--tz <timezone> The timezone of Friendica (env FRIENDICA_TZ)
334 -L|--lang <language> The language of Friendica (env FRIENDICA_LANG)
336 Environment variables
337 MYSQL_HOST The host of the mysql/mariadb database (mandatory if mysql and environment is used)
338 MYSQL_PORT The port of the mysql/mariadb database
339 MYSQL_USERNAME|MYSQL_USER The username of the mysql/mariadb database login (MYSQL_USERNAME is for mysql, MYSQL_USER for mariadb)
340 MYSQL_PASSWORD The password of the mysql/mariadb database login
341 MYSQL_DATABASE The name of the mysql/mariadb database
342 FRIENDICA_URL_PATH The URL path of Friendica (f.e. '/friendica')
343 FRIENDICA_PHP_PATH The path of the PHP binary
344 FRIENDICA_ADMIN_MAIL The admin email address of Friendica (this email will be used for admin access)
345 FRIENDICA_TZ The timezone of Friendica
346 FRIENDICA_LANG The langauge of Friendica
349 bin/console autoinstall -f 'input.ini.php
350 Installs Friendica with the prepared 'input.ini.php' file
352 bin/console autoinstall --savedb
353 Installs Friendica with environment variables and saves them to the 'config/local.ini.php' file
355 bin/console autoinstall -h localhost -p 3365 -U user -P passwort1234 -d friendica
356 Installs Friendica with a local mysql database with credentials
360 $txt = $this->execute(['autoinstall', '-h']);
362 $this->assertEquals($txt, $theHelp);