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');
36 private function assertConfig($family, $key, $value)
38 $config = $this->execute(['config', $family, $key]);
39 $this->assertEquals($family . "." . $key . " => " . $value . "\n", $config);
42 private function assertFinished($txt, $withconfig = false, $copyfile = false)
50 Creating config file...
60 Copying config file...
72 Checking environment...
74 NOTICE: Not checking .htaccess/URL-Rewrite during CLI installation.
85 Inserting data into database...
96 Installation is finished
100 $this->assertEquals($finished, $txt);
103 private function assertStuckDB($txt)
106 Initializing setup...
108 Creating config file...
113 Checking basic setup...
115 NOTICE: Not checking .htaccess/URL-Rewrite during CLI installation.
123 MySQL Connection: Failed, please check your MySQL settings and credentials.
128 $this->assertEquals($finished, $txt);
134 public function testWithConfig()
147 ; ****************************************************************
148 ; The configuration below will be overruled by the admin panel.
149 ; Changes made below will only have an effect if the database does
150 ; not contain any configuration for the friendica system.
151 ; ****************************************************************
156 sitename = Friendica Social Network
158 register_policy = REGISTER_OPEN
162 default_timezone = UTC
170 vfsStream::newFile('prepared.ini.php')
172 ->setContent($config);
174 $txt = $this->execute(['autoinstall', '-f', 'prepared.ini.php']);
176 $this->assertFinished($txt, false, true);
178 $this->assertTrue($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.ini.php'));
184 public function testWithEnvironmentAndSave()
186 $this->assertTrue(putenv('FRIENDICA_ADMIN_MAIL=admin@friendica.local'));
187 $this->assertTrue(putenv('FRIENDICA_TZ=Europe/Berlin'));
188 $this->assertTrue(putenv('FRIENDICA_LANG=de'));
190 $txt = $this->execute(['autoinstall', '--savedb']);
192 $this->assertFinished($txt, true);
194 $this->assertTrue($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.ini.php'));
196 $this->assertConfig('database', 'hostname', $this->db_host . (!empty($this->db_port) ? ':' . $this->db_port : ''));
197 $this->assertConfig('database', 'username', $this->db_user);
198 $this->assertConfig('database', 'database', $this->db_data);
199 $this->assertConfig('config', 'admin_email', 'admin@friendica.local');
200 $this->assertConfig('system', 'default_timezone', 'Europe/Berlin');
201 // TODO language changes back to en
202 //$this->assertConfig('system', 'language', 'de');
208 public function testWithEnvironmentWithoutSave()
210 $this->assertTrue(putenv('FRIENDICA_ADMIN_MAIL=admin@friendica.local'));
211 $this->assertTrue(putenv('FRIENDICA_TZ=Europe/Berlin'));
212 $this->assertTrue(putenv('FRIENDICA_LANG=de'));
213 $this->assertTrue(putenv('FRIENDICA_URL_PATH=/friendica'));
215 $txt = $this->execute(['autoinstall']);
217 $this->assertFinished($txt, true);
219 $this->assertTrue($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.ini.php'));
221 $this->assertConfig('database', 'hostname', '');
222 $this->assertConfig('database', 'username', '');
223 $this->assertConfig('database', 'database', '');
224 $this->assertConfig('config', 'admin_email', 'admin@friendica.local');
225 $this->assertConfig('system', 'default_timezone', 'Europe/Berlin');
226 $this->assertConfig('system', 'urlpath', '/friendica');
227 // TODO language changes back to en
228 //$this->assertConfig('system', 'language', 'de');
234 public function testWithArguments()
236 $args = ['autoinstall'];
237 array_push($args, '--dbhost');
238 array_push($args, $this->db_host);
239 array_push($args, '--dbuser');
240 array_push($args, $this->db_user);
241 if (!empty($this->db_pass)) {
242 array_push($args, '--dbpass');
243 array_push($args, $this->db_pass);
245 if (!empty($this->db_port)) {
246 array_push($args, '--dbport');
247 array_push($args, $this->db_port);
249 array_push($args, '--dbdata');
250 array_push($args, $this->db_data);
252 array_push($args, '--admin');
253 array_push($args, 'admin@friendica.local');
254 array_push($args, '--tz');
255 array_push($args, 'Europe/Berlin');
256 array_push($args, '--lang');
257 array_push($args, 'de');
259 array_push($args, '--urlpath');
260 array_push($args, '/friendica');
262 $txt = $this->execute($args);
264 $this->assertFinished($txt, true);
266 $this->assertTrue($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.ini.php'));
268 $this->assertConfig('database', 'hostname', $this->db_host . (!empty($this->db_port) ? ':' . $this->db_port : ''));
269 $this->assertConfig('database', 'username', $this->db_user);
270 $this->assertConfig('database', 'database', $this->db_data);
271 $this->assertConfig('config', 'admin_email', 'admin@friendica.local');
272 $this->assertConfig('system', 'default_timezone', 'Europe/Berlin');
273 $this->assertConfig('system', 'urlpath', '/friendica');
274 // TODO language changes back to en
275 //$this->assertConfig('system', 'language', 'de');
279 * @runTestsInSeparateProcesses
280 * @preserveGlobalState disabled
282 public function testNoDatabaseConnection()
284 // TODO DBA mocking for whole console tests make this test work again
285 $this->markTestSkipped('DBA is already loaded, we have to mock the whole App to make it work');
287 $dbaMock = \Mockery::mock('alias:Friendica\Database\DBA');
289 ->shouldReceive('connected')
292 $txt = $this->execute(['autoinstall']);
294 $this->assertStuckDB($txt);
297 public function testGetHelp()
299 // Usable to purposely fail if new commands are added without taking tests into account
301 Installation - Install Friendica automatically
303 bin/console autoinstall [-h|--help|-?] [-v] [-a] [-f]
306 Installs Friendica with data based on the local.ini.php file or environment variables
309 Not checking .htaccess/URL-Rewrite during CLI installation.
312 -h|--help|-? Show help information
313 -v Show more debug information.
314 -a All setup checks are required (except .htaccess)
315 -f|--file <config> prepared config file (e.g. "config/local.ini.php" itself) which will override every other config option - except the environment variables)
316 -s|--savedb Save the DB credentials to the file (if environment variables is used)
317 -H|--dbhost <host> The host of the mysql/mariadb database (env MYSQL_HOST)
318 -p|--dbport <port> The port of the mysql/mariadb database (env MYSQL_PORT)
319 -d|--dbdata <database> The name of the mysql/mariadb database (env MYSQL_DATABASE)
320 -U|--dbuser <username> The username of the mysql/mariadb database login (env MYSQL_USER or MYSQL_USERNAME)
321 -P|--dbpass <password> The password of the mysql/mariadb database login (env MYSQL_PASSWORD)
322 -u|--urlpath <url_path> The URL path of Friendica - f.e. '/friendica' (env FRIENDICA_URL_PATH)
323 -b|--phppath <php_path> The path of the PHP binary (env FRIENDICA_PHP_PATH)
324 -A|--admin <mail> The admin email address of Friendica (env FRIENDICA_ADMIN_MAIL)
325 -T|--tz <timezone> The timezone of Friendica (env FRIENDICA_TZ)
326 -L|--lang <language> The language of Friendica (env FRIENDICA_LANG)
328 Environment variables
329 MYSQL_HOST The host of the mysql/mariadb database (mandatory if mysql and environment is used)
330 MYSQL_PORT The port of the mysql/mariadb database
331 MYSQL_USERNAME|MYSQL_USER The username of the mysql/mariadb database login (MYSQL_USERNAME is for mysql, MYSQL_USER for mariadb)
332 MYSQL_PASSWORD The password of the mysql/mariadb database login
333 MYSQL_DATABASE The name of the mysql/mariadb database
334 FRIENDICA_URL_PATH The URL path of Friendica (f.e. '/friendica')
335 FRIENDICA_PHP_PATH The path of the PHP binary
336 FRIENDICA_ADMIN_MAIL The admin email address of Friendica (this email will be used for admin access)
337 FRIENDICA_TZ The timezone of Friendica
338 FRIENDICA_LANG The langauge of Friendica
341 bin/console autoinstall -f 'input.ini.php
342 Installs Friendica with the prepared 'input.ini.php' file
344 bin/console autoinstall --savedb
345 Installs Friendica with environment variables and saves them to the 'config/local.ini.php' file
347 bin/console autoinstall -h localhost -p 3365 -U user -P passwort1234 -d friendica
348 Installs Friendica with a local mysql database with credentials
352 $txt = $this->execute(['autoinstall', '-h']);
354 $this->assertEquals($txt, $theHelp);