mirror of
https://github.com/phpbb/phpbb.git
synced 2025-04-21 08:12:17 +02:00
Merge remote-tracking branch 'nickvergessen/ticket/12483' into develop-ascraeus
* nickvergessen/ticket/12483: [ticket/12483] Fix selectors for installing extensions in functional tests [ticket/12483] Remove unused globals [ticket/12483] Fix finder usage when generating the schema.json file [ticket/12483] Fix copyright in prepare_extension.sh [ticket/12483] Use file_put_contents() [ticket/12483] Close database connection when tearDown() is called [ticket/12483] Require the extension manager class [ticket/12483] Move schema files into tmp/ and only copy them when needed [ticket/12483] Add a .sh that moves an extension in place [ticket/12483] Allow to setup extensions before database and functional tests
This commit is contained in:
commit
e1f371d14a
@ -21,6 +21,12 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test
|
||||
|
||||
protected $fixture_xml_data;
|
||||
|
||||
static protected $schema_file;
|
||||
|
||||
static protected $phpbb_schema_copy;
|
||||
|
||||
static protected $install_schema_file;
|
||||
|
||||
public function __construct($name = NULL, array $data = array(), $dataName = '')
|
||||
{
|
||||
parent::__construct($name, $data, $dataName);
|
||||
@ -38,6 +44,61 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test
|
||||
$this->db_connections = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array List of extensions that should be set up
|
||||
*/
|
||||
static protected function setup_extensions()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
static public function setUpBeforeClass()
|
||||
{
|
||||
$setup_extensions = static::setup_extensions();
|
||||
self::$schema_file = '';
|
||||
if (!empty($setup_extensions))
|
||||
{
|
||||
$schema_md5 = md5(serialize($setup_extensions));
|
||||
|
||||
self::$schema_file = __DIR__ . '/../tmp/' . $schema_md5 . '.json';
|
||||
self::$phpbb_schema_copy = __DIR__ . '/../tmp/schema_phpbb_copy.json';
|
||||
self::$install_schema_file = __DIR__ . '/../../phpBB/install/schemas/schema.json';
|
||||
|
||||
if (!file_exists(self::$schema_file))
|
||||
{
|
||||
global $phpbb_root_path, $phpEx, $table_prefix;
|
||||
|
||||
$finder = new \phpbb\finder(new \phpbb\filesystem(), $phpbb_root_path, null, $phpEx);
|
||||
$classes = $finder->core_path('phpbb/')
|
||||
->core_directory('/db/migration/data')
|
||||
->set_extensions($setup_extensions)
|
||||
->extension_directory('migrations')
|
||||
->get_classes();
|
||||
|
||||
$db = new \phpbb\db\driver\sqlite();
|
||||
$schema_generator = new \phpbb\db\migration\schema_generator($classes, new \phpbb\config\config(array()), $db, new \phpbb\db\tools($db, true), $phpbb_root_path, $phpEx, $table_prefix);
|
||||
$schema_data = $schema_generator->get_schema();
|
||||
|
||||
file_put_contents(self::$schema_file, json_encode($schema_data));
|
||||
}
|
||||
|
||||
copy(self::$install_schema_file, self::$phpbb_schema_copy);
|
||||
copy(self::$schema_file, self::$install_schema_file);
|
||||
}
|
||||
|
||||
parent::setUpBeforeClass();
|
||||
}
|
||||
|
||||
static public function tearDownAfterClass()
|
||||
{
|
||||
if (self::$schema_file !== '')
|
||||
{
|
||||
copy(self::$phpbb_schema_copy, self::$install_schema_file);
|
||||
}
|
||||
|
||||
parent::tearDownAfterClass();
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
parent::tearDown();
|
||||
@ -151,8 +212,6 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test
|
||||
|
||||
public function new_dbal()
|
||||
{
|
||||
global $phpbb_root_path, $phpEx;
|
||||
|
||||
$config = $this->get_database_config();
|
||||
|
||||
$db = new $config['dbms']();
|
||||
|
@ -64,6 +64,14 @@ class phpbb_functional_test_case extends phpbb_test_case
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array List of extensions that should be set up
|
||||
*/
|
||||
static protected function setup_extensions()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
@ -81,6 +89,34 @@ class phpbb_functional_test_case extends phpbb_test_case
|
||||
$this->lang = array();
|
||||
$this->add_lang('common');
|
||||
$this->purge_cache();
|
||||
|
||||
$db = $this->get_db();
|
||||
|
||||
foreach (static::setup_extensions() as $extension)
|
||||
{
|
||||
$sql = 'SELECT ext_active
|
||||
FROM ' . EXT_TABLE . "
|
||||
WHERE ext_name = '" . $db->sql_escape($extension). "'";
|
||||
$result = $db->sql_query($sql);
|
||||
$status = (bool) $db->sql_fetchfield('ext_active');
|
||||
$db->sql_freeresult($result);
|
||||
|
||||
if (!$status)
|
||||
{
|
||||
$this->install_ext($extension);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
parent::tearDown();
|
||||
|
||||
if ($this->db instanceof \phpbb\db\driver\driver_interface)
|
||||
{
|
||||
// Close the database connections again this test
|
||||
$this->db->sql_close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -358,6 +394,24 @@ class phpbb_functional_test_case extends phpbb_test_case
|
||||
copy($config_file, $config_file_test);
|
||||
}
|
||||
|
||||
public function install_ext($extension)
|
||||
{
|
||||
$this->login();
|
||||
$this->admin_login();
|
||||
|
||||
$ext_path = str_replace('/', '%2F', $extension);
|
||||
|
||||
$crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=enable_pre&ext_name=' . $ext_path . '&sid=' . $this->sid);
|
||||
$this->assertGreaterThan(0, $crawler->filter('.submit-buttons')->count());
|
||||
|
||||
$form = $crawler->selectButton('Enable')->form();
|
||||
$crawler = self::submit($form);
|
||||
$this->add_lang('acp/extensions');
|
||||
$this->assertContainsLang('EXTENSION_ENABLE_SUCCESS', $crawler->filter('div.successbox')->text());
|
||||
|
||||
$this->logout();
|
||||
}
|
||||
|
||||
static private function recreate_database($config)
|
||||
{
|
||||
$db_conn_mgr = new phpbb_database_test_connection_manager($config);
|
||||
@ -714,6 +768,30 @@ class phpbb_functional_test_case extends phpbb_test_case
|
||||
$this->lang = array_merge($this->lang, $lang);
|
||||
}
|
||||
|
||||
protected function add_lang_ext($ext_name, $lang_file)
|
||||
{
|
||||
if (is_array($lang_file))
|
||||
{
|
||||
foreach ($lang_file as $file)
|
||||
{
|
||||
$this->add_lang_ext($ext_name, $file);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$lang_path = __DIR__ . "/../../phpBB/ext/{$ext_name}/language/en/$lang_file.php";
|
||||
|
||||
$lang = array();
|
||||
|
||||
if (file_exists($lang_path))
|
||||
{
|
||||
include($lang_path);
|
||||
}
|
||||
|
||||
$this->lang = array_merge($this->lang, $lang);
|
||||
}
|
||||
|
||||
protected function lang()
|
||||
{
|
||||
$args = func_get_args();
|
||||
|
22
travis/prepare-extension.sh
Executable file
22
travis/prepare-extension.sh
Executable file
@ -0,0 +1,22 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
set -e
|
||||
set -x
|
||||
|
||||
EXTNAME=$1
|
||||
BRANCH=$2
|
||||
|
||||
# Move the extension in place
|
||||
mkdir --parents phpBB/ext/$EXTNAME
|
||||
cp -R ../tmp/* phpBB/ext/$EXTNAME
|
||||
|
||||
# Move the extensions travis/phpunit-*-travis.xml files in place
|
||||
cp -R travis/* phpBB/ext/$EXTNAME/travis
|
Loading…
x
Reference in New Issue
Block a user