From 997028a0ecf1df761363b061acf6ae220dd3479f Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 3 May 2014 01:17:51 +0200 Subject: [PATCH 01/10] [ticket/12483] Allow to setup extensions before database and functional tests PHPBB3-12483 --- .../phpbb_database_test_case.php | 54 +++++++++++++++ .../phpbb_functional_test_case.php | 66 +++++++++++++++++++ 2 files changed, 120 insertions(+) diff --git a/tests/test_framework/phpbb_database_test_case.php b/tests/test_framework/phpbb_database_test_case.php index 60ac68e7b8..157982ff3c 100644 --- a/tests/test_framework/phpbb_database_test_case.php +++ b/tests/test_framework/phpbb_database_test_case.php @@ -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,54 @@ 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() + { + $schema_md5 = md5(serialize(static::setup_extensions())); + + self::$schema_file = __DIR__ . '/schemas/' . $schema_md5 . '.json'; + self::$phpbb_schema_copy = __DIR__ . '/schemas/schema_phpbb_copy.json'; + self::$install_schema_file = __DIR__ . '/../../../../../install/schemas/schema.json'; + + if (!file_exists(self::$schema_file)) + { + global $phpbb_root_path, $phpEx, $table_prefix; + + $finder = new \phpbb\extension\finder(new phpbb_testcase_extension_manager(static::setup_extensions()), new \phpbb\filesystem(), $phpbb_root_path); + $classes = $finder->core_path('phpbb/') + ->core_directory('db/migration/data') + ->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(); + + $fp = fopen(self::$schema_file, 'wb'); + fwrite($fp, json_encode($schema_data)); + fclose($fp); + } + + copy(self::$install_schema_file, self::$phpbb_schema_copy); + copy(self::$schema_file, self::$install_schema_file); + + parent::setUpBeforeClass(); + } + + static public function tearDownAfterClass() + { + copy(self::$phpbb_schema_copy, self::$install_schema_file); + + parent::tearDownAfterClass(); + } + protected function tearDown() { parent::tearDown(); diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 182ffaaaf7..110c84927c 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -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,23 @@ 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); + } + } } /** @@ -358,6 +383,23 @@ 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('div.errorbox')->count()); + + $form = $crawler->selectButton('Enable')->form(); + $crawler = self::submit($form); + $this->assertGreaterThan(0, $crawler->filter('div.successbox')->count()); + + $this->logout(); + } + static private function recreate_database($config) { $db_conn_mgr = new phpbb_database_test_connection_manager($config); @@ -714,6 +756,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(); From 709296e54ab678bc64f1dd4fc533224fd873058a Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 3 May 2014 11:26:59 +0200 Subject: [PATCH 02/10] [ticket/12483] Add a .sh that moves an extension in place PHPBB3-12483 --- travis/prepare-extension.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100755 travis/prepare-extension.sh diff --git a/travis/prepare-extension.sh b/travis/prepare-extension.sh new file mode 100755 index 0000000000..f7567c5d96 --- /dev/null +++ b/travis/prepare-extension.sh @@ -0,0 +1,17 @@ +#!/bin/bash +# +# @copyright (c) 2014 phpBB Group +# @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +# +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 From 5bae2911a232648dcc355153180f9bb7ace64d83 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 3 May 2014 11:48:52 +0200 Subject: [PATCH 03/10] [ticket/12483] Move schema files into tmp/ and only copy them when needed PHPBB3-12483 --- .../phpbb_database_test_case.php | 54 +++++++++++-------- 1 file changed, 31 insertions(+), 23 deletions(-) diff --git a/tests/test_framework/phpbb_database_test_case.php b/tests/test_framework/phpbb_database_test_case.php index 157982ff3c..c704516968 100644 --- a/tests/test_framework/phpbb_database_test_case.php +++ b/tests/test_framework/phpbb_database_test_case.php @@ -54,40 +54,48 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test static public function setUpBeforeClass() { - $schema_md5 = md5(serialize(static::setup_extensions())); - - self::$schema_file = __DIR__ . '/schemas/' . $schema_md5 . '.json'; - self::$phpbb_schema_copy = __DIR__ . '/schemas/schema_phpbb_copy.json'; - self::$install_schema_file = __DIR__ . '/../../../../../install/schemas/schema.json'; - - if (!file_exists(self::$schema_file)) + $setup_extensions = static::setup_extensions(); + self::$schema_file = ''; + if (!empty($setup_extensions)) { - global $phpbb_root_path, $phpEx, $table_prefix; + $schema_md5 = md5(serialize($setup_extensions)); - $finder = new \phpbb\extension\finder(new phpbb_testcase_extension_manager(static::setup_extensions()), new \phpbb\filesystem(), $phpbb_root_path); - $classes = $finder->core_path('phpbb/') - ->core_directory('db/migration/data') - ->extension_directory('migrations') - ->get_classes(); + 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'; - $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(); + if (!file_exists(self::$schema_file)) + { + global $phpbb_root_path, $phpEx, $table_prefix; - $fp = fopen(self::$schema_file, 'wb'); - fwrite($fp, json_encode($schema_data)); - fclose($fp); + $finder = new \phpbb\extension\finder(new phpbb_testcase_extension_manager(static::setup_extensions()), new \phpbb\filesystem(), $phpbb_root_path); + $classes = $finder->core_path('phpbb/') + ->core_directory('db/migration/data') + ->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(); + + $fp = fopen(self::$schema_file, 'wb'); + fwrite($fp, json_encode($schema_data)); + fclose($fp); + } + + copy(self::$install_schema_file, self::$phpbb_schema_copy); + copy(self::$schema_file, self::$install_schema_file); } - copy(self::$install_schema_file, self::$phpbb_schema_copy); - copy(self::$schema_file, self::$install_schema_file); - parent::setUpBeforeClass(); } static public function tearDownAfterClass() { - copy(self::$phpbb_schema_copy, self::$install_schema_file); + if (self::$schema_file !== '') + { + copy(self::$phpbb_schema_copy, self::$install_schema_file); + } parent::tearDownAfterClass(); } From 13217fe3ff391ab958b0d0c6568366875c7d198e Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 3 May 2014 11:58:12 +0200 Subject: [PATCH 04/10] [ticket/12483] Require the extension manager class PHPBB3-12483 --- tests/test_framework/phpbb_database_test_case.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_framework/phpbb_database_test_case.php b/tests/test_framework/phpbb_database_test_case.php index c704516968..d8533a3d15 100644 --- a/tests/test_framework/phpbb_database_test_case.php +++ b/tests/test_framework/phpbb_database_test_case.php @@ -11,6 +11,8 @@ * */ +require_once dirname(__FILE__) . '/phpbb_testcase_extension_manager.php'; + abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_TestCase { static private $already_connected; From 7b0b6a99c031bdcbf2bfdf0d7ebbf1784ecbbd59 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 4 May 2014 23:15:56 +0200 Subject: [PATCH 05/10] [ticket/12483] Close database connection when tearDown() is called Similar to phpbb_database_test_case::tearDown() PHPBB3-12483 --- tests/test_framework/phpbb_functional_test_case.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 110c84927c..36d577aed7 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -108,6 +108,17 @@ class phpbb_functional_test_case extends phpbb_test_case } } + 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(); + } + } + /** * Perform a request to page * From 18d145f38f0f512039a15f64e132b2607283af89 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 6 May 2014 15:23:55 +0200 Subject: [PATCH 06/10] [ticket/12483] Use file_put_contents() PHPBB3-12483 --- tests/test_framework/phpbb_database_test_case.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/test_framework/phpbb_database_test_case.php b/tests/test_framework/phpbb_database_test_case.php index d8533a3d15..ff55b3fc63 100644 --- a/tests/test_framework/phpbb_database_test_case.php +++ b/tests/test_framework/phpbb_database_test_case.php @@ -80,9 +80,7 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test $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(); - $fp = fopen(self::$schema_file, 'wb'); - fwrite($fp, json_encode($schema_data)); - fclose($fp); + file_put_contents(self::$schema_file, json_encode($schema_data)); } copy(self::$install_schema_file, self::$phpbb_schema_copy); From 3d347d47f24a75e7d45d542c352e7054cc630eac Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 10 Jun 2014 19:26:37 +0200 Subject: [PATCH 07/10] [ticket/12483] Fix copyright in prepare_extension.sh PHPBB3-12483 --- travis/prepare-extension.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/travis/prepare-extension.sh b/travis/prepare-extension.sh index f7567c5d96..4518f935f8 100755 --- a/travis/prepare-extension.sh +++ b/travis/prepare-extension.sh @@ -1,7 +1,12 @@ #!/bin/bash # -# @copyright (c) 2014 phpBB Group -# @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +# This file is part of the phpBB Forum Software package. +# +# @copyright (c) phpBB Limited +# @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 From d0766a23218fb028aefaef231b6e42034f69bc8f Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 10 Jun 2014 19:38:24 +0200 Subject: [PATCH 08/10] [ticket/12483] Fix finder usage when generating the schema.json file PHPBB3-12483 --- tests/test_framework/phpbb_database_test_case.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/test_framework/phpbb_database_test_case.php b/tests/test_framework/phpbb_database_test_case.php index ff55b3fc63..049bd022d7 100644 --- a/tests/test_framework/phpbb_database_test_case.php +++ b/tests/test_framework/phpbb_database_test_case.php @@ -11,8 +11,6 @@ * */ -require_once dirname(__FILE__) . '/phpbb_testcase_extension_manager.php'; - abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_TestCase { static private $already_connected; @@ -70,9 +68,10 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test { global $phpbb_root_path, $phpEx, $table_prefix; - $finder = new \phpbb\extension\finder(new phpbb_testcase_extension_manager(static::setup_extensions()), new \phpbb\filesystem(), $phpbb_root_path); + $finder = new \phpbb\finder(new \phpbb\filesystem(), $phpbb_root_path, null, $phpEx); $classes = $finder->core_path('phpbb/') - ->core_directory('db/migration/data') + ->core_directory('/db/migration/data') + ->set_extensions($setup_extensions) ->extension_directory('migrations') ->get_classes(); From 38c2d42304047d9f7f1457c37bc5496825e14ae3 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 10 Jun 2014 19:44:06 +0200 Subject: [PATCH 09/10] [ticket/12483] Remove unused globals PHPBB3-12483 --- tests/test_framework/phpbb_database_test_case.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/test_framework/phpbb_database_test_case.php b/tests/test_framework/phpbb_database_test_case.php index 049bd022d7..05281b1d71 100644 --- a/tests/test_framework/phpbb_database_test_case.php +++ b/tests/test_framework/phpbb_database_test_case.php @@ -212,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'](); From 916db1a0b156a953b1917d74924f750864df4701 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 10 Jun 2014 20:04:03 +0200 Subject: [PATCH 10/10] [ticket/12483] Fix selectors for installing extensions in functional tests PHPBB3-12483 --- tests/test_framework/phpbb_functional_test_case.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 36d577aed7..e4504a5f8d 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -402,11 +402,12 @@ class phpbb_functional_test_case extends phpbb_test_case $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('div.errorbox')->count()); + $this->assertGreaterThan(0, $crawler->filter('.submit-buttons')->count()); $form = $crawler->selectButton('Enable')->form(); $crawler = self::submit($form); - $this->assertGreaterThan(0, $crawler->filter('div.successbox')->count()); + $this->add_lang('acp/extensions'); + $this->assertContainsLang('EXTENSION_ENABLE_SUCCESS', $crawler->filter('div.successbox')->text()); $this->logout(); }