mirror of
https://github.com/phpbb/phpbb.git
synced 2025-08-06 16:56:44 +02:00
Merge pull request #3514 from CHItA/ticket/13740
[ticket/13740] Refactoring installer * CHItA/ticket/13740: (75 commits) [ticket/13740] Reduce number of references in nav provider [ticket/13740] Move handle_language_select calls to the controllers [ticket/13740] Fix infinite config.php check loop [ticket/13740] Move default data settings out of constructors [ticket/13740] Deduplicate container builder's checks [ticket/13740] Use JSON for installer config [ticket/13740] Fix comment [ticket/13740] Use language service in console application [ticket/13740] Fix CS in compatibilty_globals.php [ticket/13740] Fix message element creation in JS [ticket/13740] Replace more spaces with tabs [ticket/13740] Fix CS [ticket/13740] Filter basic directory change attempts in lang change [ticket/13740] Use tabs instead of spaces in JS file [ticket/13740] Add success message when install finished [ticket/13740] Fix $script_path in obtain_data [ticket/13740] Fix is_phpbb_installed() method [ticket/13740] Login admin when install finished [ticket/13740] Enhance server output buffer bypass [ticket/13740] Secure installer config against corrupted config data ...
This commit is contained in:
141
tests/installer/database_helper_test.php
Normal file
141
tests/installer/database_helper_test.php
Normal file
@@ -0,0 +1,141 @@
|
||||
<?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_installer_database_helper_test extends phpbb_test_case
|
||||
{
|
||||
/**
|
||||
* @var phpbb\install\helper\database
|
||||
*/
|
||||
private $database_helper;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$filesystem = new \phpbb\filesystem\filesystem();
|
||||
$phpbb_root_path = '';
|
||||
$this->database_helper = new \phpbb\install\helper\database($filesystem, $phpbb_root_path);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $input
|
||||
* @param string $expected
|
||||
*
|
||||
* @dataProvider comment_string_provider
|
||||
*/
|
||||
public function test_remove_comments($input, $expected)
|
||||
{
|
||||
$this->assertEquals($expected, $this->database_helper->remove_comments($input));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $expected
|
||||
* @param string $sql
|
||||
* @param string $delimiter
|
||||
*
|
||||
* @dataProvider sql_file_string_provider
|
||||
*/
|
||||
public function test_split_sql($expected, $sql, $delimiter)
|
||||
{
|
||||
$this->assertEquals($expected, $this->database_helper->split_sql_file($sql, $delimiter));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool|array $expected
|
||||
* @param string $test_string
|
||||
*
|
||||
* @dataProvider prefix_test_case_provider
|
||||
*/
|
||||
public function test_validate_table_prefix($expected, $test_string)
|
||||
{
|
||||
$this->assertEquals($expected, $this->database_helper->validate_table_prefix('sqlite3', $test_string));
|
||||
}
|
||||
|
||||
// Data provider for the remove comments function
|
||||
public function comment_string_provider()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'abc',
|
||||
'abc',
|
||||
),
|
||||
array(
|
||||
'abc /* asdf */',
|
||||
"abc \n",
|
||||
),
|
||||
array(
|
||||
'abc /* asdf */ f',
|
||||
"abc \n f",
|
||||
),
|
||||
array(
|
||||
'# abc',
|
||||
"\n",
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Data provider for the sql file splitter function
|
||||
public function sql_file_string_provider()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
array(
|
||||
'abcd "efgh"' . "\n" . 'qwerty',
|
||||
'SELECT * FROM table',
|
||||
),
|
||||
'abcd "efgh"' . "\n" .
|
||||
'qwerty;' . "\n" .
|
||||
'SELECT * FROM table',
|
||||
';',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Test data for prefix test
|
||||
public function prefix_test_case_provider()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
true,
|
||||
'phpbb_',
|
||||
),
|
||||
array(
|
||||
true,
|
||||
'phpbb',
|
||||
),
|
||||
array(
|
||||
array(
|
||||
array('title' => 'INST_ERR_DB_INVALID_PREFIX'),
|
||||
),
|
||||
'1hpbb_',
|
||||
),
|
||||
array(
|
||||
array(
|
||||
array('title' => 'INST_ERR_DB_INVALID_PREFIX'),
|
||||
),
|
||||
'?hpbb_',
|
||||
),
|
||||
array(
|
||||
array(
|
||||
array('title' => array('INST_ERR_PREFIX_TOO_LONG', 200)),
|
||||
),
|
||||
'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
|
||||
),
|
||||
array(
|
||||
array(
|
||||
array('title' => 'INST_ERR_DB_INVALID_PREFIX'),
|
||||
array('title' => array('INST_ERR_PREFIX_TOO_LONG', 200)),
|
||||
),
|
||||
'_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
85
tests/installer/installer_config_test.php
Normal file
85
tests/installer/installer_config_test.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?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.
|
||||
*
|
||||
*/
|
||||
|
||||
use phpbb\install\helper\config;
|
||||
|
||||
class phpbb_installer_config_test extends phpbb_test_case
|
||||
{
|
||||
/**
|
||||
* @var \phpbb\install\helper\config
|
||||
*/
|
||||
private $config;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$phpbb_root_path = __DIR__ . './../../phpBB/';
|
||||
$filesystem = $this->getMock('\phpbb\filesystem\filesystem');
|
||||
$php_ini = $this->getMockBuilder('\phpbb\php\ini')
|
||||
->getMock();
|
||||
$php_ini->method('get_int')
|
||||
->willReturn(-1);
|
||||
$php_ini->method('get_bytes')
|
||||
->willReturn(-1);
|
||||
|
||||
$this->config = new config($filesystem, $php_ini, $phpbb_root_path);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers config::set
|
||||
* @covers config::get
|
||||
*/
|
||||
public function test_set_get_var()
|
||||
{
|
||||
$this->config->set('foo', 'bar');
|
||||
$this->assertEquals('bar', $this->config->get('foo'));
|
||||
}
|
||||
|
||||
public function test_get_time_remaining()
|
||||
{
|
||||
$this->assertGreaterThan(0, $this->config->get_time_remaining());
|
||||
}
|
||||
|
||||
public function test_get_memory_remaining()
|
||||
{
|
||||
$this->assertGreaterThan(0, $this->config->get_memory_remaining());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers config::set_finished_task
|
||||
* @covers config::set_active_module
|
||||
* @covers config::set_task_progress_count
|
||||
* @covers config::increment_current_task_progress
|
||||
* @covers config::get_progress_data
|
||||
*/
|
||||
public function test_progress_tracking()
|
||||
{
|
||||
$this->config->set_finished_task('foo');
|
||||
$this->config->set_active_module('bar');
|
||||
$this->config->set_task_progress_count(10);
|
||||
$this->config->increment_current_task_progress();
|
||||
|
||||
$progress_data = $this->config->get_progress_data();
|
||||
$this->assertEquals(1, $progress_data['current_task_progress']);
|
||||
|
||||
$this->config->increment_current_task_progress(2);
|
||||
|
||||
$this->assertEquals(array(
|
||||
'last_task_module_name' => 'bar',
|
||||
'last_task_name' => 'foo',
|
||||
'max_task_progress' => 10,
|
||||
'current_task_progress' => 3,
|
||||
),
|
||||
$this->config->get_progress_data()
|
||||
);
|
||||
}
|
||||
}
|
20
tests/installer/mocks/test_installer_module.php
Normal file
20
tests/installer/mocks/test_installer_module.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?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 test_installer_module extends \phpbb\install\module_base
|
||||
{
|
||||
public function get_navigation_stage_path()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
}
|
44
tests/installer/mocks/test_installer_task_mock.php
Normal file
44
tests/installer/mocks/test_installer_task_mock.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?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 test_installer_task_mock extends \phpbb\install\task_base
|
||||
{
|
||||
private $task_was_runned;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->task_was_runned = false;
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function run()
|
||||
{
|
||||
$this->task_was_runned = true;
|
||||
}
|
||||
|
||||
public function was_task_runned()
|
||||
{
|
||||
return $this->task_was_runned;
|
||||
}
|
||||
|
||||
public function get_task_lang_name()
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public static function get_step_count()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
}
|
65
tests/installer/module_base_test.php
Normal file
65
tests/installer/module_base_test.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?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 __DIR__ . '/mocks/test_installer_task_mock.php';
|
||||
require_once __DIR__ . '/mocks/test_installer_module.php';
|
||||
|
||||
class module_base_test extends phpbb_test_case
|
||||
{
|
||||
/**
|
||||
* @var \phpbb\install\module_interface
|
||||
*/
|
||||
protected $module;
|
||||
|
||||
/**
|
||||
* @var phpbb_mock_container_builder
|
||||
*/
|
||||
protected $container;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
// DI container mock
|
||||
$this->container = new phpbb_mock_container_builder();
|
||||
$this->container->set('task_one', new test_installer_task_mock());
|
||||
$this->container->set('task_two', new test_installer_task_mock());
|
||||
|
||||
// the collection
|
||||
$module_collection = new \phpbb\di\ordered_service_collection($this->container);
|
||||
$module_collection->add('task_one');
|
||||
$module_collection->add('task_two');
|
||||
$module_collection->add_service_class('task_one', 'test_installer_task_mock');
|
||||
$module_collection->add_service_class('task_two', 'test_installer_task_mock');
|
||||
|
||||
$this->module = new test_installer_module($module_collection, true, false);
|
||||
|
||||
$iohandler = $this->getMock('\phpbb\install\helper\iohandler\iohandler_interface');
|
||||
$config = new \phpbb\install\helper\config(new \phpbb\filesystem\filesystem(), new \phpbb\php\ini(), '', 'php');
|
||||
$this->module->setup($config, $iohandler);
|
||||
}
|
||||
|
||||
public function test_run()
|
||||
{
|
||||
$this->module->run();
|
||||
|
||||
$task = $this->container->get('task_one');
|
||||
$this->assertTrue($task->was_task_runned());
|
||||
|
||||
$task = $this->container->get('task_two');
|
||||
$this->assertTrue($task->was_task_runned());
|
||||
}
|
||||
|
||||
public function test_step_count()
|
||||
{
|
||||
$this->assertEquals(4, $this->module->get_step_count());
|
||||
}
|
||||
}
|
34
tests/installer/navigation_provider_test.php
Normal file
34
tests/installer/navigation_provider_test.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?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_installer_navigation_provider_test extends phpbb_test_case
|
||||
{
|
||||
public function test_navigation()
|
||||
{
|
||||
// Mock nav interface
|
||||
$nav_stub = $this->getMockBuilder('\phpbb\install\helper\navigation\navigation_interface')
|
||||
->getMock();
|
||||
$nav_stub->method('get')
|
||||
->willReturn(array('foo' => 'bar'));
|
||||
|
||||
// Set up dependencies
|
||||
$container = new phpbb_mock_container_builder();
|
||||
$container->set('foo', $nav_stub);
|
||||
$nav_collection = new \phpbb\di\service_collection($container);
|
||||
$nav_collection->add('foo');
|
||||
|
||||
// Let's test
|
||||
$nav_provider = new \phpbb\install\helper\navigation\navigation_provider($nav_collection);
|
||||
$this->assertEquals(array('foo' => 'bar'), $nav_provider->get());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user