root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.ini.php')) { $this->root->getChild('config') ->removeChild('local.ini.php'); } $this->db_host = getenv('MYSQL_HOST'); $this->db_port = (!empty(getenv('MYSQL_PORT'))) ? getenv('MYSQL_PORT') : null; $this->db_data = getenv('MYSQL_DATABASE'); $this->db_user = getenv('MYSQL_USERNAME') . getenv('MYSQL_USER'); $this->db_pass = getenv('MYSQL_PASSWORD'); } private function assertConfig($family, $key, $value) { $config = $this->execute(['config', $family, $key]); $this->assertEquals($family . "." . $key . " => " . $value . "\n", $config); } private function assertFinished($txt, $withconfig = false, $copyfile = false) { $cfg = ''; if ($withconfig) { $cfg = <<assertEquals($finished, $txt); } private function assertStuckDB($txt) { $finished = <<assertEquals($finished, $txt); } /** * @medium */ public function testWithConfig() { $config = <<at($this->root) ->setContent($config); $txt = $this->execute(['autoinstall', '-f', 'prepared.ini.php']); $this->assertFinished($txt, false, true); $this->assertTrue($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.ini.php')); } /** * @medium */ public function testWithEnvironmentAndSave() { $this->assertTrue(putenv('FRIENDICA_ADMIN_MAIL=admin@friendica.local')); $this->assertTrue(putenv('FRIENDICA_TZ=Europe/Berlin')); $this->assertTrue(putenv('FRIENDICA_LANG=de')); $txt = $this->execute(['autoinstall', '--savedb']); $this->assertFinished($txt, true); $this->assertTrue($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.ini.php')); $this->assertConfig('database', 'hostname', $this->db_host . (!empty($this->db_port) ? ':' . $this->db_port : '')); $this->assertConfig('database', 'username', $this->db_user); $this->assertConfig('database', 'database', $this->db_data); $this->assertConfig('config', 'admin_email', 'admin@friendica.local'); $this->assertConfig('system', 'default_timezone', 'Europe/Berlin'); $this->assertConfig('system', 'language', 'de'); } /** * @medium */ public function testWithEnvironmentWithoutSave() { $this->assertTrue(putenv('FRIENDICA_ADMIN_MAIL=admin@friendica.local')); $this->assertTrue(putenv('FRIENDICA_TZ=Europe/Berlin')); $this->assertTrue(putenv('FRIENDICA_LANG=de')); $this->assertTrue(putenv('FRIENDICA_URL_PATH=/friendica')); $txt = $this->execute(['autoinstall']); $this->assertFinished($txt, true); $this->assertTrue($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.ini.php')); $this->assertConfig('database', 'hostname', ''); $this->assertConfig('database', 'username', ''); $this->assertConfig('database', 'database', ''); $this->assertConfig('config', 'admin_email', 'admin@friendica.local'); $this->assertConfig('system', 'default_timezone', 'Europe/Berlin'); $this->assertConfig('system', 'language', 'de'); $this->assertConfig('system', 'url_path', '/friendica'); } /** * @medium */ public function testWithArguments() { $args = ['autoinstall']; array_push($args, '--dbhost'); array_push($args, $this->db_host); array_push($args, '--dbuser'); array_push($args, $this->db_user); if (!empty($this->db_pass)) { array_push($args, '--dbpass'); array_push($args, $this->db_pass); } if (!empty($this->db_port)) { array_push($args, '--dbport'); array_push($args, $this->db_port); } array_push($args, '--dbdata'); array_push($args, $this->db_data); array_push($args, '--admin'); array_push($args, 'admin@friendica.local'); array_push($args, '--tz'); array_push($args, 'Europe/Berlin'); array_push($args, '--lang'); array_push($args, 'de'); array_push($args, '--urlpath'); array_push($args, '/friendica'); $txt = $this->execute($args); $this->assertFinished($txt, true); $this->assertTrue($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.ini.php')); $this->assertConfig('database', 'hostname', $this->db_host . (!empty($this->db_port) ? ':' . $this->db_port : '')); $this->assertConfig('database', 'username', $this->db_user); $this->assertConfig('database', 'database', $this->db_data); $this->assertConfig('config', 'admin_email', 'admin@friendica.local'); $this->assertConfig('system', 'default_timezone', 'Europe/Berlin'); $this->assertConfig('system', 'language', 'de'); $this->assertConfig('system', 'url_path', '/friendica'); } public function testNoDatabaseConnection() { $this->assertTrue(putenv('MYSQL_USERNAME=')); $this->assertTrue(putenv('MYSQL_PASSWORD=')); $this->assertTrue(putenv('MYSQL_DATABASE=')); $txt = $this->execute(['autoinstall']); $this->assertStuckDB($txt); } public function testGetHelp() { // Usable to purposely fail if new commands are added without taking tests into account $theHelp = << prepared config file (e.g. "config/local.ini.php" itself) which will override every other config option - except the environment variables) -s|--savedb Save the DB credentials to the file (if environment variables is used) -H|--dbhost The host of the mysql/mariadb database (env MYSQL_HOST) -p|--dbport The port of the mysql/mariadb database (env MYSQL_PORT) -d|--dbdata The name of the mysql/mariadb database (env MYSQL_DATABASE) -U|--dbuser The username of the mysql/mariadb database login (env MYSQL_USER or MYSQL_USERNAME) -P|--dbpass The password of the mysql/mariadb database login (env MYSQL_PASSWORD) -b|--urlpath The URL path of Friendica - f.e. '/friendica' (env FRIENDICA_URL_PATH) -b|--phppath The path of the PHP binary (env FRIENDICA_PHP_PATH) -A|--admin The admin email address of Friendica (env FRIENDICA_ADMIN_MAIL) -T|--tz The timezone of Friendica (env FRIENDICA_TZ) -L|--lang The language of Friendica (env FRIENDICA_LANG) Environment variables MYSQL_HOST The host of the mysql/mariadb database (mandatory if mysql and environment is used) MYSQL_PORT The port of the mysql/mariadb database MYSQL_USERNAME|MYSQL_USER The username of the mysql/mariadb database login (MYSQL_USERNAME is for mysql, MYSQL_USER for mariadb) MYSQL_PASSWORD The password of the mysql/mariadb database login MYSQL_DATABASE The name of the mysql/mariadb database FRIENDICA_URL_PATH The URL path of Friendica (f.e. '/friendica') FRIENDICA_PHP_PATH The path of the PHP binary FRIENDICA_ADMIN_MAIL The admin email address of Friendica (this email will be used for admin access) FRIENDICA_TZ The timezone of Friendica FRIENDICA_LANG The langauge of Friendica Examples bin/console autoinstall -f 'input.ini.php Installs Friendica with the prepared 'input.ini.php' file bin/console autoinstall --savedb Installs Friendica with environment variables and saves them to the 'config/local.ini.php' file bin/console autoinstall -h localhost -p 3365 -U user -P passwort1234 -d friendica Installs Friendica with a local mysql database with credentials HELP; $txt = $this->execute(['autoinstall', '-h']); $this->assertEquals($txt, $theHelp); } }