3 namespace Friendica\Test\src\Core\Console;
5 use Friendica\Core\Console\AutomaticInstallation;
6 use Friendica\Test\Util\DBAMockTrait;
7 use Friendica\Test\Util\DBStructureMockTrait;
8 use org\bovigo\vfs\vfsStream;
11 * @runTestsInSeparateProcesses
12 * @preserveGlobalState disabled
15 class AutomaticInstallationConsoleTest extends ConsoleTest
18 use DBStructureMockTrait;
27 private $assertFileDb;
29 public function setUp()
33 if ($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.ini.php')) {
34 $this->root->getChild('config')
35 ->removeChild('local.ini.php');
38 $this->db_host = getenv('MYSQL_HOST');
39 $this->db_port = (!empty(getenv('MYSQL_PORT'))) ? getenv('MYSQL_PORT') : null;
40 $this->db_data = getenv('MYSQL_DATABASE');
41 $this->db_user = getenv('MYSQL_USERNAME') . getenv('MYSQL_USER');
42 $this->db_pass = getenv('MYSQL_PASSWORD');
44 $this->mockConfigGet('config', 'php_path', false);
46 $this->assertFile = dirname(__DIR__) . DIRECTORY_SEPARATOR .
47 '..' . DIRECTORY_SEPARATOR .
48 '..' . DIRECTORY_SEPARATOR .
49 'datasets' . DIRECTORY_SEPARATOR .
50 'ini' . DIRECTORY_SEPARATOR .
52 $this->assertFileDb = dirname(__DIR__) . DIRECTORY_SEPARATOR .
53 '..' . DIRECTORY_SEPARATOR .
54 '..' . DIRECTORY_SEPARATOR .
55 'datasets' . DIRECTORY_SEPARATOR .
56 'ini' . DIRECTORY_SEPARATOR .
60 private function assertFinished($txt, $withconfig = false, $copyfile = false)
68 Creating config file...
78 Copying config file...
90 Checking environment...
92 NOTICE: Not checking .htaccess/URL-Rewrite during CLI installation.
103 Inserting data into database...
114 Installation is finished
118 $this->assertEquals($finished, $txt);
121 private function assertStuckDB($txt)
124 Initializing setup...
129 Checking environment...
131 NOTICE: Not checking .htaccess/URL-Rewrite during CLI installation.
136 Creating config file...
149 $this->assertEquals($finished, $txt);
155 public function testWithConfig()
157 $this->mockConnect(true, 1);
158 $this->mockConnected(true, 1);
159 $this->mockExistsTable('user', false, 1);
160 $this->mockUpdate([false, true, true], null, 1);
173 ; ****************************************************************
174 ; The configuration below will be overruled by the admin panel.
175 ; Changes made below will only have an effect if the database does
176 ; not contain any configuration for the friendica system.
177 ; ****************************************************************
182 sitename = Friendica Social Network
184 register_policy = REGISTER_OPEN
188 default_timezone = UTC
196 vfsStream::newFile('prepared.ini.php')
198 ->setContent($config);
200 $console = new AutomaticInstallation();
201 $console->setOption('f', 'prepared.ini.php');
203 $txt = $this->dumpExecute($console);
205 $this->assertFinished($txt, false, true);
207 $this->assertTrue($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.ini.php'));
213 public function testWithEnvironmentAndSave()
215 $this->mockConnect(true, 1);
216 $this->mockConnected(true, 1);
217 $this->mockExistsTable('user', false, 1);
218 $this->mockUpdate([false, true, true], null, 1);
220 $this->assertTrue(putenv('FRIENDICA_ADMIN_MAIL=admin@friendica.local'));
221 $this->assertTrue(putenv('FRIENDICA_TZ=Europe/Berlin'));
222 $this->assertTrue(putenv('FRIENDICA_LANG=de'));
223 $this->assertTrue(putenv('FRIENDICA_URL_PATH=/friendica'));
225 $console = new AutomaticInstallation();
226 $console->setOption('savedb', true);
228 $txt = $this->dumpExecute($console);
230 $this->assertFinished($txt, true);
232 $this->assertTrue($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.ini.php'));
234 $this->assertFileEquals(
236 $this->root->getChild('config' . DIRECTORY_SEPARATOR . 'local.ini.php')->url());
242 public function testWithEnvironmentWithoutSave()
244 $this->mockConnect(true, 1);
245 $this->mockConnected(true, 1);
246 $this->mockExistsTable('user', false, 1);
247 $this->mockUpdate([false, true, true], null, 1);
249 $this->assertTrue(putenv('FRIENDICA_ADMIN_MAIL=admin@friendica.local'));
250 $this->assertTrue(putenv('FRIENDICA_TZ=Europe/Berlin'));
251 $this->assertTrue(putenv('FRIENDICA_LANG=de'));
252 $this->assertTrue(putenv('FRIENDICA_URL_PATH=/friendica'));
254 $console = new AutomaticInstallation();
256 $txt = $this->dumpExecute($console);
258 $this->assertFinished($txt, true);
260 $this->assertTrue($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.ini.php'));
262 $this->assertFileEquals(
264 $this->root->getChild('config' . DIRECTORY_SEPARATOR . 'local.ini.php')->url());
270 public function testWithArguments()
272 $this->mockConnect(true, 1);
273 $this->mockConnected(true, 1);
274 $this->mockExistsTable('user', false, 1);
275 $this->mockUpdate([false, true, true], null, 1);
277 $console = new AutomaticInstallation();
279 $console->setOption('dbhost', $this->db_host);
280 $console->setOption('dbuser', $this->db_user);
281 if (!empty($this->db_pass)) {
282 $console->setOption('dbpass', $this->db_pass);
284 if (!empty($this->db_port)) {
285 $console->setOption('dbport', $this->db_port);
287 $console->setOption('dbdata', $this->db_data);
289 $console->setOption('admin', 'admin@friendica.local');
290 $console->setOption('tz', 'Europe/Berlin');
291 $console->setOption('lang', 'de');
293 $console->setOption('urlpath', '/friendica');
295 $txt = $this->dumpExecute($console);
297 $this->assertFinished($txt, true);
299 $this->assertTrue($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.ini.php'));
301 $this->assertFileEquals(
303 $this->root->getChild('config' . DIRECTORY_SEPARATOR . 'local.ini.php')->url());
307 * @runTestsInSeparateProcesses
308 * @preserveGlobalState disabled
310 public function testNoDatabaseConnection()
312 $this->mockConnect(false, 1);
314 $console = new AutomaticInstallation();
316 $txt = $this->dumpExecute($console);
318 $this->assertStuckDB($txt);
321 public function testGetHelp()
323 // Usable to purposely fail if new commands are added without taking tests into account
325 Installation - Install Friendica automatically
327 bin/console autoinstall [-h|--help|-?] [-v] [-a] [-f]
330 Installs Friendica with data based on the local.ini.php file or environment variables
333 Not checking .htaccess/URL-Rewrite during CLI installation.
336 -h|--help|-? Show help information
337 -v Show more debug information.
338 -a All setup checks are required (except .htaccess)
339 -f|--file <config> prepared config file (e.g. "config/local.ini.php" itself) which will override every other config option - except the environment variables)
340 -s|--savedb Save the DB credentials to the file (if environment variables is used)
341 -H|--dbhost <host> The host of the mysql/mariadb database (env MYSQL_HOST)
342 -p|--dbport <port> The port of the mysql/mariadb database (env MYSQL_PORT)
343 -d|--dbdata <database> The name of the mysql/mariadb database (env MYSQL_DATABASE)
344 -U|--dbuser <username> The username of the mysql/mariadb database login (env MYSQL_USER or MYSQL_USERNAME)
345 -P|--dbpass <password> The password of the mysql/mariadb database login (env MYSQL_PASSWORD)
346 -u|--urlpath <url_path> The URL path of Friendica - f.e. '/friendica' (env FRIENDICA_URL_PATH)
347 -b|--phppath <php_path> The path of the PHP binary (env FRIENDICA_PHP_PATH)
348 -A|--admin <mail> The admin email address of Friendica (env FRIENDICA_ADMIN_MAIL)
349 -T|--tz <timezone> The timezone of Friendica (env FRIENDICA_TZ)
350 -L|--lang <language> The language of Friendica (env FRIENDICA_LANG)
352 Environment variables
353 MYSQL_HOST The host of the mysql/mariadb database (mandatory if mysql and environment is used)
354 MYSQL_PORT The port of the mysql/mariadb database
355 MYSQL_USERNAME|MYSQL_USER The username of the mysql/mariadb database login (MYSQL_USERNAME is for mysql, MYSQL_USER for mariadb)
356 MYSQL_PASSWORD The password of the mysql/mariadb database login
357 MYSQL_DATABASE The name of the mysql/mariadb database
358 FRIENDICA_URL_PATH The URL path of Friendica (f.e. '/friendica')
359 FRIENDICA_PHP_PATH The path of the PHP binary
360 FRIENDICA_ADMIN_MAIL The admin email address of Friendica (this email will be used for admin access)
361 FRIENDICA_TZ The timezone of Friendica
362 FRIENDICA_LANG The langauge of Friendica
365 bin/console autoinstall -f 'input.ini.php
366 Installs Friendica with the prepared 'input.ini.php' file
368 bin/console autoinstall --savedb
369 Installs Friendica with environment variables and saves them to the 'config/local.ini.php' file
371 bin/console autoinstall -h localhost -p 3365 -U user -P passwort1234 -d friendica
372 Installs Friendica with a local mysql database with credentials
376 $console = new AutomaticInstallation();
377 $console->setOption('help', true);
379 $txt = $this->dumpExecute($console);
381 $this->assertEquals($txt, $theHelp);