From 516581c41edaa5f565ef90bac14cdbdc054e7914 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Tue, 18 Jun 2013 15:04:48 +0200 Subject: [PATCH 1/3] [ticket/11604] Use variables for config.php filesnames. PHPBB3-11604 --- .../phpbb_functional_test_case.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 651ab013c7..1b47cbe125 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -184,15 +184,19 @@ class phpbb_functional_test_case extends phpbb_test_case self::$config['table_prefix'] = 'phpbb_'; self::recreate_database(self::$config); - if (file_exists($phpbb_root_path . "config.$phpEx")) + $config_file = $phpbb_root_path . "config.$phpEx"; + $config_file_dev = $phpbb_root_path . "config_dev.$phpEx"; + $config_file_test = $phpbb_root_path . "config_test.$phpEx"; + + if (file_exists($config_file)) { - if (!file_exists($phpbb_root_path . "config_dev.$phpEx")) + if (!file_exists($config_file_dev)) { - rename($phpbb_root_path . "config.$phpEx", $phpbb_root_path . "config_dev.$phpEx"); + rename($config_file, $config_file_dev); } else { - unlink($phpbb_root_path . "config.$phpEx"); + unlink($config_file); } } @@ -254,7 +258,7 @@ class phpbb_functional_test_case extends phpbb_test_case $crawler = self::submit($form); self::assertContains('The configuration file has been written.', $crawler->filter('#main')->text()); - file_put_contents($phpbb_root_path . "config.$phpEx", phpbb_create_config_file_data(self::$config, self::$config['dbms'], array(), true, true)); + file_put_contents($config_file, phpbb_create_config_file_data(self::$config, self::$config['dbms'], array(), true, true)); $form = $crawler->selectButton('submit')->form(); $crawler = self::submit($form); @@ -281,7 +285,7 @@ class phpbb_functional_test_case extends phpbb_test_case $crawler = self::submit($form); self::assertContains('You have successfully installed', $crawler->text()); - copy($phpbb_root_path . "config.$phpEx", $phpbb_root_path . "config_test.$phpEx"); + copy($config_file, $config_file_test); } static private function recreate_database($config) From 21f839494ddb55d1c4aefeed113b5debe9b2e1b3 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Tue, 18 Jun 2013 15:21:28 +0200 Subject: [PATCH 2/3] [ticket/11604] Fix case where config.php is not generated by phpBB. PHPBB3-11604 --- .../phpbb_functional_test_case.php | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 1b47cbe125..16ed9f5a1e 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -257,8 +257,30 @@ class phpbb_functional_test_case extends phpbb_test_case $form = $crawler->selectButton('submit')->form(); $crawler = self::submit($form); + $config_writable = strpos($crawler->filter('#main')->text(), 'It was not possible to write the configuration file.') === false; + $config_php_data = phpbb_create_config_file_data(self::$config, self::$config['dbms'], array(), true, true); + + if (!$config_writable) + { + // phpBB could not write to the config.php file, so we have to "Download" it. + self::assertContains('Download config', $crawler->filter('#main')->text()); + + file_put_contents($config_file, $config_php_data); + + $form = $crawler->selectButton('dldone')->form(); + $crawler = self::submit($form); + } + self::assertContains('The configuration file has been written.', $crawler->filter('#main')->text()); - file_put_contents($config_file, phpbb_create_config_file_data(self::$config, self::$config['dbms'], array(), true, true)); + + // Overwrite the config.php file generated by phpBB in order to get the + // DEBUG constants defined if possible. It should be possible when unit + // tests run as the same user as phpBB. + if ($config_writable && is_writable($config_file)) + { + file_put_contents($config_file, $config_php_data); + } + $form = $crawler->selectButton('submit')->form(); $crawler = self::submit($form); From 1af6dc22e2ccb13b610a932a9b043d2d9d4ea17d Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 19 Jun 2013 17:03:41 +0200 Subject: [PATCH 3/3] [ticket/11604] Skip installer step where config.php is created. PHPBB3-11604 --- .../phpbb_functional_test_case.php | 47 +++++++++++-------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 16ed9f5a1e..6b423b56fd 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -220,10 +220,12 @@ class phpbb_functional_test_case extends phpbb_test_case self::assertContains('Welcome to Installation', $crawler->filter('#main')->text()); $form = $crawler->selectButton('submit')->form(); + // install/index.php?mode=install&sub=requirements $crawler = self::submit($form); self::assertContains('Installation compatibility', $crawler->filter('#main')->text()); $form = $crawler->selectButton('submit')->form(); + // install/index.php?mode=install&sub=database $crawler = self::submit($form); self::assertContains('Database configuration', $crawler->filter('#main')->text()); $form = $crawler->selectButton('submit')->form(array( @@ -237,10 +239,12 @@ class phpbb_functional_test_case extends phpbb_test_case 'table_prefix' => self::$config['table_prefix'], )); + // install/index.php?mode=install&sub=database $crawler = self::submit($form); self::assertContains('Successful connection', $crawler->filter('#main')->text()); $form = $crawler->selectButton('submit')->form(); + // install/index.php?mode=install&sub=administrator $crawler = self::submit($form); self::assertContains('Administrator configuration', $crawler->filter('#main')->text()); $form = $crawler->selectButton('submit')->form(array( @@ -252,38 +256,38 @@ class phpbb_functional_test_case extends phpbb_test_case 'board_email2' => 'nobody@example.com', )); + // install/index.php?mode=install&sub=administrator $crawler = self::submit($form); self::assertContains('Tests passed', $crawler->filter('#main')->text()); $form = $crawler->selectButton('submit')->form(); - $crawler = self::submit($form); - $config_writable = strpos($crawler->filter('#main')->text(), 'It was not possible to write the configuration file.') === false; + // We have to skip install/index.php?mode=install&sub=config_file + // because that step will create a config.php file if phpBB has the + // permission to do so. We have to create the config file on our own + // in order to get the DEBUG constants defined. $config_php_data = phpbb_create_config_file_data(self::$config, self::$config['dbms'], array(), true, true); - - if (!$config_writable) + $config_created = file_put_contents($config_file, $config_php_data) !== false; + if (!$config_created) { - // phpBB could not write to the config.php file, so we have to "Download" it. - self::assertContains('Download config', $crawler->filter('#main')->text()); - - file_put_contents($config_file, $config_php_data); - - $form = $crawler->selectButton('dldone')->form(); - $crawler = self::submit($form); + self::markTestSkipped("Could not write $config_file file."); } - self::assertContains('The configuration file has been written.', $crawler->filter('#main')->text()); - - // Overwrite the config.php file generated by phpBB in order to get the - // DEBUG constants defined if possible. It should be possible when unit - // tests run as the same user as phpBB. - if ($config_writable && is_writable($config_file)) + // We also have to create a install lock that is normally created by + // the installer. The file will be removed by the final step of the + // installer. + $install_lock_file = $phpbb_root_path . 'cache/install_lock'; + $lock_created = file_put_contents($install_lock_file, '') !== false; + if (!$lock_created) { - file_put_contents($config_file, $config_php_data); + self::markTestSkipped("Could not create $lock_created file."); } + @chmod($install_lock_file, 0666); - $form = $crawler->selectButton('submit')->form(); + // install/index.php?mode=install&sub=advanced + $form_data = $form->getValues(); + unset($form_data['submit']); - $crawler = self::submit($form); + $crawler = self::request('POST', 'install/index.php?mode=install&sub=advanced', $form_data); self::assertContains('The settings on this page are only necessary to set if you know that you require something different from the default.', $crawler->filter('#main')->text()); $form = $crawler->selectButton('submit')->form(array( 'email_enable' => true, @@ -300,13 +304,16 @@ class phpbb_functional_test_case extends phpbb_test_case 'script_path' => $parseURL['path'], )); + // install/index.php?mode=install&sub=create_table $crawler = self::submit($form); self::assertContains('The database tables used by phpBB', $crawler->filter('#main')->text()); self::assertContains('have been created and populated with some initial data.', $crawler->filter('#main')->text()); $form = $crawler->selectButton('submit')->form(); + // install/index.php?mode=install&sub=final $crawler = self::submit($form); self::assertContains('You have successfully installed', $crawler->text()); + copy($config_file, $config_file_test); }