1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-08-10 02:36:38 +02:00

Merge pull request #3995 from CHItA/ticket/14044

[ticket/14044] Deduplicate the installers

* CHItA/ticket/14044:
  [ticket/14044] Add config as global in notify user
  [ticket/14044] Fix language selection data loss
  [ticket/14044] Patch language::set_fallback_array()
  [ticket/14044] Fix tests
  [ticket/14044] Fix wrong descriptions in install
  [ticket/14044] Solve missing email template error
  [ticket/14044] global $table_prefix in constants.php
  [ticket/14044] Try to fix missing table prefix
  [ticket/14044] Use the correct language file version
  [ticket/14044] Automatically trigger rollback on insert in transaction
  [ticket/14044] Use empty instead of !count
  [ticket/14044] Fix Sqlite error in tests
  [ticket/14044] Deduplicate the installers
This commit is contained in:
Tristan Darricau
2015-11-03 20:35:24 +01:00
43 changed files with 596 additions and 10308 deletions

View File

@@ -16,6 +16,8 @@ define('PHPBB_ENVIRONMENT', 'test');
$phpbb_root_path = 'phpBB/';
$phpEx = 'php';
global $table_prefix;
require_once $phpbb_root_path . 'includes/startup.php';
$table_prefix = 'phpbb_';

View File

@@ -36,6 +36,8 @@ abstract class phpbb_functional_search_base extends phpbb_functional_test_case
$this->login();
$this->admin_login();
$this->create_search_index('\phpbb\search\fulltext_native');
$post = $this->create_topic(2, 'Test Topic 1 foosubject', 'This is a test topic posted by the barsearch testing framework.');
$crawler = self::request('GET', 'adm/index.php?i=acp_search&mode=settings&sid=' . $this->sid);
@@ -58,6 +60,7 @@ abstract class phpbb_functional_search_base extends phpbb_functional_test_case
$this->delete_topic($post['topic_id']);
$this->markTestSkipped("Search backend is not supported/running");
}
$this->create_search_index();
}
@@ -72,14 +75,14 @@ abstract class phpbb_functional_search_base extends phpbb_functional_test_case
$this->delete_topic($post['topic_id']);
}
protected function create_search_index()
protected function create_search_index($backend = null)
{
$this->add_lang('acp/search');
$crawler = self::request(
'POST',
'adm/index.php?i=acp_search&mode=index&sid=' . $this->sid,
array(
'search_type' => $this->search_backend,
'search_type' => ( ($backend === null) ? $this->search_backend : $backend ),
'action' => 'create',
'submit' => true,
)

View File

@@ -1,45 +0,0 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
require_once dirname(__FILE__) . '/../../phpBB/includes/functions_install.php';
class phpbb_functions_install_ignore_new_file_on_update_test extends phpbb_test_case
{
static public function ignore_new_file_on_update_data()
{
return array(
array('willneverexist.php', false),
array('includes/dirwillneverexist/newfile.php', false),
array('language/en/email/short/bookmark.txt', false),
array('language/languagewillneverexist/email/short/bookmark.txt', true),
array('styles/prosilver/template/bbcode.html', false),
array('styles/stylewillneverexist/template/bbcode.html', true),
array('styles/prosilver/theme/en/icon_user_online.gif', false),
array('styles/prosilver/theme/languagewillneverexist/icon_user_online.gif', true),
array('styles/prosilver/theme/imageset.css', false),
);
}
/**
* @dataProvider ignore_new_file_on_update_data
*/
public function test_ignore_new_file_on_update($file, $expected)
{
global $phpbb_root_path;
$this->assertEquals($expected, phpbb_ignore_new_file_on_update($phpbb_root_path, $file));
}
}

View File

@@ -0,0 +1,30 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
class phpbb_mock_null_installer_task extends \phpbb\install\task_base
{
public function run()
{
}
static public function get_step_count()
{
return 0;
}
public function get_task_lang_name()
{
return '';
}
}

View File

@@ -11,7 +11,6 @@
*
*/
require_once dirname(__FILE__) . '/../../phpBB/includes/functions_install.php';
require_once dirname(__FILE__) . '/phpbb_database_connection_odbc_pdo_wrapper.php';
class phpbb_database_test_connection_manager
@@ -344,10 +343,13 @@ class phpbb_database_test_connection_manager
if (file_exists($filename))
{
$queries = file_get_contents($filename);
$sql = phpbb_remove_comments($queries);
global $phpbb_root_path;
$sql = split_sql_file($sql, $this->dbms['DELIM']);
$queries = file_get_contents($filename);
$db_helper = new \phpbb\install\helper\database(new \phpbb\filesystem\filesystem(), $phpbb_root_path);
$sql = $db_helper->remove_comments($queries);
$sql = $db_helper->split_sql_file($sql, $this->dbms['DELIM']);
foreach ($sql as $query)
{

View File

@@ -12,7 +12,7 @@
*/
use Symfony\Component\BrowserKit\CookieJar;
require_once __DIR__ . '/../../phpBB/includes/functions_install.php';
require_once __DIR__ . '/mock/phpbb_mock_null_installer_task.php';
class phpbb_functional_test_case extends phpbb_test_case
{
@@ -285,120 +285,97 @@ class phpbb_functional_test_case extends phpbb_test_case
}
}
self::$cookieJar = new CookieJar;
self::$client = new Goutte\Client(array(), null, self::$cookieJar);
// Set client manually so we can increase the cURL timeout
self::$client->setClient(new Guzzle\Http\Client('', array(
Guzzle\Http\Client::DISABLE_REDIRECTS => true,
'curl.options' => array(
CURLOPT_TIMEOUT => 120,
),
)));
$container_builder = new \phpbb\di\container_builder($phpbb_root_path, $phpEx);
$container = $container_builder
->with_environment('installer')
->without_extensions()
->without_cache()
->with_custom_parameters([
'core.disable_super_globals' => false,
'installer.create_config_file.options' => [
'debug' => true,
'environment' => 'test',
]
])
->without_compiled_container()
->get_container();
// Reset the curl handle because it is 0 at this point and not a valid
// resource
self::$client->getClient()->getCurlMulti()->reset(true);
$container->register('installer.install_finish.notify_user')->setSynthetic(true);
$container->set('installer.install_finish.notify_user', new phpbb_mock_null_installer_task());
$container->compile();
$language = $container->get('language');
$language->add_lang(array('common', 'acp/common', 'acp/board', 'install', 'posting'));
$iohandler_factory = $container->get('installer.helper.iohandler_factory');
$iohandler_factory->set_environment('cli');
$iohandler = $iohandler_factory->get();
$parseURL = parse_url(self::$config['phpbb_functional_url']);
$crawler = self::request('GET', 'install/index.php?mode=install&language=en');
self::assertContains('Welcome to Installation', $crawler->filter('#main')->text());
$form = $crawler->selectButton('submit')->form();
$output = new \Symfony\Component\Console\Output\NullOutput();
$style = new \Symfony\Component\Console\Style\SymfonyStyle(
new \Symfony\Component\Console\Input\ArrayInput(array()),
$output
);
$iohandler->set_style($style, $output);
// install/index.php?mode=install&sub=requirements
$crawler = self::submit($form);
self::assertContains('Installation compatibility', $crawler->filter('#main')->text());
$form = $crawler->selectButton('submit')->form();
$installer = $container->get('installer.installer.install');
$installer->set_iohandler($iohandler);
// 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(
// Installer uses 3.0-style dbms name
'dbms' => str_replace('phpbb\db\driver\\', '', self::$config['dbms']),
'dbhost' => self::$config['dbhost'],
'dbport' => self::$config['dbport'],
'dbname' => self::$config['dbname'],
'dbuser' => self::$config['dbuser'],
'dbpasswd' => self::$config['dbpasswd'],
'table_prefix' => self::$config['table_prefix'],
));
// Set data
$iohandler->set_input('admin_name', 'admin');
$iohandler->set_input('admin_pass1', 'adminadmin');
$iohandler->set_input('admin_pass2', 'adminadmin');
$iohandler->set_input('board_email', 'nobody@example.com');
$iohandler->set_input('submit_admin', 'submit');
// install/index.php?mode=install&sub=database
$crawler = self::submit($form);
self::assertContains('Successful connection', $crawler->filter('#main')->text());
$form = $crawler->selectButton('submit')->form();
$iohandler->set_input('default_lang', 'en');
$iohandler->set_input('board_name', 'yourdomain.com');
$iohandler->set_input('board_description', 'A short text to describe your forum');
$iohandler->set_input('submit_board', 'submit');
// 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(
'default_lang' => 'en',
'admin_name' => 'admin',
'admin_pass1' => 'adminadmin',
'admin_pass2' => 'adminadmin',
'board_email' => 'nobody@example.com',
));
$iohandler->set_input('dbms', str_replace('phpbb\db\driver\\', '', self::$config['dbms']));
$iohandler->set_input('dbhost', self::$config['dbhost']);
$iohandler->set_input('dbport', self::$config['dbport']);
$iohandler->set_input('dbuser', self::$config['dbuser']);
$iohandler->set_input('dbpasswd', self::$config['dbpasswd']);
$iohandler->set_input('dbname', self::$config['dbname']);
$iohandler->set_input('table_prefix', self::$config['table_prefix']);
$iohandler->set_input('submit_database', 'submit');
// install/index.php?mode=install&sub=administrator
$crawler = self::submit($form);
self::assertContains('Tests passed', $crawler->filter('#main')->text());
$form = $crawler->selectButton('submit')->form();
$iohandler->set_input('email_enable', true);
$iohandler->set_input('smtp_delivery', '1');
$iohandler->set_input('smtp_host', 'nxdomain.phpbb.com');
$iohandler->set_input('smtp_auth', 'PLAIN');
$iohandler->set_input('smtp_user', 'nxuser');
$iohandler->set_input('smtp_pass', 'nxpass');
$iohandler->set_input('submit_email', 'submit');
// 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'], true, false, true);
$config_created = file_put_contents($config_file, $config_php_data) !== false;
if (!$config_created)
$iohandler->set_input('cookie_secure', '0');
$iohandler->set_input('server_protocol', '0');
$iohandler->set_input('force_server_vars', $parseURL['scheme'] . '://');
$iohandler->set_input('server_name', $parseURL['host']);
$iohandler->set_input('server_port', isset($parseURL['port']) ? (int) $parseURL['port'] : 80);
$iohandler->set_input('script_path', $parseURL['path']);
$iohandler->set_input('submit_server', 'submit');
do
{
self::markTestSkipped("Could not write $config_file file.");
$installer->run();
}
// 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)
{
self::markTestSkipped("Could not create $lock_created file.");
}
@chmod($install_lock_file, 0666);
// install/index.php?mode=install&sub=advanced
$form_data = $form->getValues();
unset($form_data['submit']);
$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,
'smtp_delivery' => true,
'smtp_host' => 'nxdomain.phpbb.com',
'smtp_auth' => 'PLAIN',
'smtp_user' => 'nxuser',
'smtp_pass' => 'nxpass',
'cookie_secure' => false,
'force_server_vars' => false,
'server_protocol' => $parseURL['scheme'] . '://',
'server_name' => 'localhost',
'server_port' => isset($parseURL['port']) ? (int) $parseURL['port'] : 80,
'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());
while (file_exists($phpbb_root_path . 'store/install_config.php'));
copy($config_file, $config_file_test);
if (file_exists($phpbb_root_path . 'cache/install_lock'))
{
unlink($phpbb_root_path . 'cache/install_lock');
}
global $phpbb_container, $cache, $phpbb_dispatcher, $request, $user, $auth, $db, $config, $phpbb_log, $symfony_request, $phpbb_filesystem, $phpbb_path_helper, $phpbb_extension_manager, $template;
$phpbb_container->reset();
unset($phpbb_container, $cache, $phpbb_dispatcher, $request, $user, $auth, $db, $config, $phpbb_log, $symfony_request, $phpbb_filesystem, $phpbb_path_helper, $phpbb_extension_manager, $template);
}
public function install_ext($extension)

View File

@@ -11,7 +11,7 @@
*
*/
require_once __DIR__ . '/../../phpBB/includes/functions_install.php';
require_once __DIR__ . '/mock/phpbb_mock_null_installer_task.php';
class phpbb_ui_test_case extends phpbb_test_case
{
@@ -118,87 +118,96 @@ class phpbb_ui_test_case extends phpbb_test_case
}
}
$container_builder = new \phpbb\di\container_builder($phpbb_root_path, $phpEx);
$container = $container_builder
->with_environment('installer')
->without_extensions()
->without_cache()
->with_custom_parameters([
'core.disable_super_globals' => false,
'installer.create_config_file.options' => [
'debug' => true,
'environment' => 'test',
]
])
->without_compiled_container()
->get_container();
$container->register('installer.install_finish.notify_user')->setSynthetic(true);
$container->set('installer.install_finish.notify_user', new phpbb_mock_null_installer_task());
$container->compile();
$language = $container->get('language');
$language->add_lang(array('common', 'acp/common', 'acp/board', 'install', 'posting'));
$iohandler_factory = $container->get('installer.helper.iohandler_factory');
$iohandler_factory->set_environment('cli');
$iohandler = $iohandler_factory->get();
$parseURL = parse_url(self::$config['phpbb_functional_url']);
self::visit('install/index.php?mode=install&language=en');
self::assertContains('Welcome to Installation', self::find_element('id', 'main')->getText());
$output = new \Symfony\Component\Console\Output\NullOutput();
$style = new \Symfony\Component\Console\Style\SymfonyStyle(
new \Symfony\Component\Console\Input\ArrayInput(array()),
$output
);
$iohandler->set_style($style, $output);
// install/index.php?mode=install&sub=requirements
self::submit();
self::assertContains('Installation compatibility', self::find_element('id', 'main')->getText());
$installer = $container->get('installer.installer.install');
$installer->set_iohandler($iohandler);
// install/index.php?mode=install&sub=database
self::submit();
self::assertContains('Database configuration', self::find_element('id', 'main')->getText());
// Set data
$iohandler->set_input('admin_name', 'admin');
$iohandler->set_input('admin_pass1', 'adminadmin');
$iohandler->set_input('admin_pass2', 'adminadmin');
$iohandler->set_input('board_email', 'nobody@example.com');
$iohandler->set_input('submit_admin', 'submit');
self::find_element('id','dbms')->sendKeys(str_replace('phpbb\db\driver\\', '', self::$config['dbms']));
self::find_element('id','dbhost')->sendKeys(self::$config['dbhost']);
self::find_element('id','dbport')->sendKeys(self::$config['dbport']);
self::find_element('id','dbname')->sendKeys(self::$config['dbname']);
self::find_element('id','dbuser')->sendKeys(self::$config['dbuser']);
self::find_element('id','dbpasswd')->sendKeys(self::$config['dbpasswd']);
$iohandler->set_input('default_lang', 'en');
$iohandler->set_input('board_name', 'yourdomain.com');
$iohandler->set_input('board_description', 'A short text to describe your forum');
$iohandler->set_input('submit_board', 'submit');
// Need to clear default phpbb_ prefix
self::find_element('id','table_prefix')->clear();
self::find_element('id','table_prefix')->sendKeys(self::$config['table_prefix']);
$iohandler->set_input('dbms', str_replace('phpbb\db\driver\\', '', self::$config['dbms']));
$iohandler->set_input('dbhost', self::$config['dbhost']);
$iohandler->set_input('dbport', self::$config['dbport']);
$iohandler->set_input('dbuser', self::$config['dbuser']);
$iohandler->set_input('dbpasswd', self::$config['dbpasswd']);
$iohandler->set_input('dbname', self::$config['dbname']);
$iohandler->set_input('table_prefix', self::$config['table_prefix']);
$iohandler->set_input('submit_database', 'submit');
// install/index.php?mode=install&sub=database
self::submit();
self::assertContains('Successful connection', self::find_element('id','main')->getText());
$iohandler->set_input('email_enable', true);
$iohandler->set_input('smtp_delivery', '1');
$iohandler->set_input('smtp_host', 'nxdomain.phpbb.com');
$iohandler->set_input('smtp_auth', 'PLAIN');
$iohandler->set_input('smtp_user', 'nxuser');
$iohandler->set_input('smtp_pass', 'nxpass');
$iohandler->set_input('submit_email', 'submit');
// install/index.php?mode=install&sub=administrator
self::submit();
self::assertContains('Administrator configuration', self::find_element('id','main')->getText());
$iohandler->set_input('cookie_secure', '0');
$iohandler->set_input('server_protocol', '0');
$iohandler->set_input('force_server_vars', $parseURL['scheme'] . '://');
$iohandler->set_input('server_name', $parseURL['host']);
$iohandler->set_input('server_port', isset($parseURL['port']) ? (int) $parseURL['port'] : 80);
$iohandler->set_input('script_path', $parseURL['path']);
$iohandler->set_input('submit_server', 'submit');
self::find_element('id','admin_name')->sendKeys('admin');
self::find_element('id','admin_pass1')->sendKeys('adminadmin');
self::find_element('id','admin_pass2')->sendKeys('adminadmin');
self::find_element('id','board_email')->sendKeys('nobody@example.com');
// install/index.php?mode=install&sub=administrator
self::submit();
self::assertContains('Tests passed', self::find_element('id','main')->getText());
// install/index.php?mode=install&sub=config_file
self::submit();
// Installer has created a config.php file, we will overwrite it with a
// config file of our own in order to get the DEBUG constants defined
$config_php_data = phpbb_create_config_file_data(self::$config, self::$config['dbms'], true, false, true);
$config_created = file_put_contents($config_file, $config_php_data) !== false;
if (!$config_created)
do
{
self::markTestSkipped("Could not write $config_file file.");
$installer->run();
}
if (strpos(self::find_element('id','main')->getText(), 'The configuration file has been written') === false)
{
self::submit('id', 'dldone');
}
self::assertContains('The configuration file has been written', self::find_element('id','main')->getText());
// install/index.php?mode=install&sub=advanced
self::submit();
self::assertContains('The settings on this page are only necessary to set if you know that you require something different from the default.', self::find_element('id','main')->getText());
self::find_element('id','smtp_delivery')->sendKeys('1');
self::find_element('id','smtp_host')->sendKeys('nxdomain.phpbb.com');
self::find_element('id','smtp_user')->sendKeys('nxuser');
self::find_element('id','smtp_pass')->sendKeys('nxpass');
self::find_element('id','server_protocol')->sendKeys($parseURL['scheme'] . '://');
self::find_element('id','server_name')->sendKeys('localhost');
self::find_element('id','server_port')->sendKeys(isset($parseURL['port']) ? $parseURL['port'] : 80);
self::find_element('id','script_path')->sendKeys($parseURL['path']);
// install/index.php?mode=install&sub=create_table
self::submit();
self::assertContains('The database tables used by phpBB', self::find_element('id','main')->getText());
self::assertContains('have been created and populated with some initial data.', self::find_element('id','main')->getText());
// install/index.php?mode=install&sub=final
self::submit();
self::assertContains('You have successfully installed', self::find_element('id', 'main')->getText());
while (file_exists($phpbb_root_path . 'store/install_config.php'));
copy($config_file, $config_file_test);
if (file_exists($phpbb_root_path . 'cache/install_lock'))
{
unlink($phpbb_root_path . 'cache/install_lock');
}
global $phpbb_container, $cache, $phpbb_dispatcher, $request, $user, $auth, $db, $config, $phpbb_log, $symfony_request, $phpbb_filesystem, $phpbb_path_helper, $phpbb_extension_manager, $template;
$phpbb_container->reset();
unset($phpbb_container, $cache, $phpbb_dispatcher, $request, $user, $auth, $db, $config, $phpbb_log, $symfony_request, $phpbb_filesystem, $phpbb_path_helper, $phpbb_extension_manager, $template);
}
}