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...
58 Copying config file...
63 Initializing setup...{$cfg}
68 Checking basic setup...
70 NOTICE: Not checking .htaccess/URL-Rewrite during CLI installation.
80 Inserting data into database...
91 Installation is finished
95 $this->assertEquals($finished, $txt);
98 private function assertStuckDB($txt)
101 Initializing setup...
103 Creating config file...
108 Checking basic setup...
110 NOTICE: Not checking .htaccess/URL-Rewrite during CLI installation.
118 MySQL Connection: Failed, please check your MySQL settings and credentials.
123 $this->assertEquals($finished, $txt);
129 public function testWithConfig()
142 ; ****************************************************************
143 ; The configuration below will be overruled by the admin panel.
144 ; Changes made below will only have an effect if the database does
145 ; not contain any configuration for the friendica system.
146 ; ****************************************************************
151 sitename = Friendica Social Network
153 register_policy = REGISTER_OPEN
157 default_timezone = UTC
165 vfsStream::newFile('prepared.ini.php')
167 ->setContent($config);
169 $txt = $this->execute(['autoinstall', '-f', 'prepared.ini.php']);
171 $this->assertFinished($txt, false, true);
173 $this->assertTrue($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.ini.php'));
179 public function testWithEnvironmentAndSave()
181 $this->assertTrue(putenv('FRIENDICA_ADMIN_MAIL=admin@friendica.local'));
182 $this->assertTrue(putenv('FRIENDICA_TZ=Europe/Berlin'));
183 $this->assertTrue(putenv('FRIENDICA_LANG=de'));
185 $txt = $this->execute(['autoinstall', '--savedb']);
187 $this->assertFinished($txt, true);
189 $this->assertTrue($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.ini.php'));
191 $this->assertConfig('database', 'hostname', $this->db_host . (!empty($this->db_port) ? ':' . $this->db_port : ''));
192 $this->assertConfig('database', 'username', $this->db_user);
193 $this->assertConfig('database', 'database', $this->db_data);
194 $this->assertConfig('config', 'admin_email', 'admin@friendica.local');
195 $this->assertConfig('system', 'default_timezone', 'Europe/Berlin');
196 $this->assertConfig('system', 'language', 'de');
203 public function testWithEnvironmentWithoutSave()
205 $this->assertTrue(putenv('FRIENDICA_ADMIN_MAIL=admin@friendica.local'));
206 $this->assertTrue(putenv('FRIENDICA_TZ=Europe/Berlin'));
207 $this->assertTrue(putenv('FRIENDICA_LANG=de'));
209 $txt = $this->execute(['autoinstall']);
211 $this->assertFinished($txt, true);
213 $this->assertTrue($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.ini.php'));
215 $this->assertConfig('database', 'hostname', '');
216 $this->assertConfig('database', 'username', '');
217 $this->assertConfig('database', 'database', '');
218 $this->assertConfig('config', 'admin_email', 'admin@friendica.local');
219 $this->assertConfig('system', 'default_timezone', 'Europe/Berlin');
220 $this->assertConfig('system', 'language', 'de');
226 public function testWithArguments()
228 $args = ['autoinstall'];
229 array_push($args, '--dbhost');
230 array_push($args, $this->db_host);
231 array_push($args, '--dbuser');
232 array_push($args, $this->db_user);
233 if (!empty($this->db_pass)) {
234 array_push($args, '--dbpass');
235 array_push($args, $this->db_pass);
237 if (!empty($this->db_port)) {
238 array_push($args, '--dbport');
239 array_push($args, $this->db_port);
241 array_push($args, '--dbdata');
242 array_push($args, $this->db_data);
244 array_push($args, '--admin');
245 array_push($args, 'admin@friendica.local');
246 array_push($args, '--tz');
247 array_push($args, 'Europe/Berlin');
248 array_push($args, '--lang');
249 array_push($args, 'de');
251 $txt = $this->execute($args);
253 $this->assertFinished($txt, true);
255 $this->assertTrue($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.ini.php'));
257 $this->assertConfig('database', 'hostname', $this->db_host . (!empty($this->db_port) ? ':' . $this->db_port : ''));
258 $this->assertConfig('database', 'username', $this->db_user);
259 $this->assertConfig('database', 'database', $this->db_data);
260 $this->assertConfig('config', 'admin_email', 'admin@friendica.local');
261 $this->assertConfig('system', 'default_timezone', 'Europe/Berlin');
262 $this->assertConfig('system', 'language', 'de');
265 public function testNoDatabaseConnection()
267 $this->assertTrue(putenv('MYSQL_USERNAME='));
268 $this->assertTrue(putenv('MYSQL_PASSWORD='));
269 $this->assertTrue(putenv('MYSQL_DATABASE='));
271 $txt = $this->execute(['autoinstall']);
273 $this->assertStuckDB($txt);
276 public function testGetHelp()
278 // Usable to purposely fail if new commands are added without taking tests into account
280 Installation - Install Friendica automatically
282 bin/console autoinstall [-h|--help|-?] [-v] [-a] [-f]
285 Installs Friendica with data based on the local.ini.php file or environment variables
288 Not checking .htaccess/URL-Rewrite during CLI installation.
291 -h|--help|-? Show help information
292 -v Show more debug information.
293 -a All setup checks are required (except .htaccess)
294 -f|--file <config> prepared config file (e.g. "config/local.ini.php" itself) which will override every other config option - except the environment variables)
295 -s|--savedb Save the DB credentials to the file (if environment variables is used)
296 -H|--dbhost <host> The host of the mysql/mariadb database (env MYSQL_HOST)
297 -p|--dbport <port> The port of the mysql/mariadb database (env MYSQL_PORT)
298 -d|--dbdata <database> The name of the mysql/mariadb database (env MYSQL_DATABASE)
299 -U|--dbuser <username> The username of the mysql/mariadb database login (env MYSQL_USER or MYSQL_USERNAME)
300 -P|--dbpass <password> The password of the mysql/mariadb database login (env MYSQL_PASSWORD)
301 -b|--phppath <path> The path of the PHP binary (env FRIENDICA_PHP_PATH)
302 -A|--admin <mail> The admin email address of Friendica (env FRIENDICA_ADMIN_MAIL)
303 -T|--tz <timezone> The timezone of Friendica (env FRIENDICA_TZ)
304 -L|--lang <language> The language of Friendica (env FRIENDICA_LANG)
306 Environment variables
307 MYSQL_HOST The host of the mysql/mariadb database (mandatory if mysql and environment is used)
308 MYSQL_PORT The port of the mysql/mariadb database
309 MYSQL_USERNAME|MYSQL_USER The username of the mysql/mariadb database login (MYSQL_USERNAME is for mysql, MYSQL_USER for mariadb)
310 MYSQL_PASSWORD The password of the mysql/mariadb database login
311 MYSQL_DATABASE The name of the mysql/mariadb database
312 FRIENDICA_PHP_PATH The path of the PHP binary
313 FRIENDICA_ADMIN_MAIL The admin email address of Friendica (this email will be used for admin access)
314 FRIENDICA_TZ The timezone of Friendica
315 FRIENDICA_LANG The langauge of Friendica
318 bin/console autoinstall -f 'input.ini.php
319 Installs Friendica with the prepared 'input.ini.php' file
321 bin/console autoinstall --savedb
322 Installs Friendica with environment variables and saves them to the 'config/local.ini.php' file
324 bin/console autoinstall -h localhost -p 3365 -U user -P passwort1234 -d friendica
325 Installs Friendica with a local mysql database with credentials
329 $txt = $this->execute(['autoinstall', '-h']);
331 $this->assertEquals($txt, $theHelp);