From a0131b45f56847f7e5c44a6db66cd7359967585f Mon Sep 17 00:00:00 2001 From: David King Date: Wed, 8 Feb 2012 00:08:17 -0500 Subject: [PATCH 01/18] [ticket/10586] Extension front controller Handle extension front pages PHPBB3-10586 --- .../extension/controller_interface.php | 31 +++++++++++++++ phpBB/includes/extension/manager.php | 22 +++++++++++ phpBB/index.php | 39 +++++++++++++++++++ phpBB/language/en/common.php | 4 ++ 4 files changed, 96 insertions(+) create mode 100644 phpBB/includes/extension/controller_interface.php diff --git a/phpBB/includes/extension/controller_interface.php b/phpBB/includes/extension/controller_interface.php new file mode 100644 index 0000000000..bcc8972db4 --- /dev/null +++ b/phpBB/includes/extension/controller_interface.php @@ -0,0 +1,31 @@ +phpbb_root_path . "ext/$name/"); + } + + /** + * Check to see if a given extension is enabled + * + * @param string $name Extension name to check + * @return bool Depending on whether or not the extension is enabled + */ + public function enabled($name) + { + return isset($this->extensions[$name]) && $this->extensions[$name]['ext_active']; + } /** * Instantiates a phpbb_extension_finder. diff --git a/phpBB/index.php b/phpBB/index.php index f1243bb336..a206ed4d37 100644 --- a/phpBB/index.php +++ b/phpBB/index.php @@ -24,6 +24,45 @@ $user->session_begin(); $auth->acl($user->data); $user->setup('viewforum'); +// If given an extension, look for a front controller +if ($ext = $request->variable('ext', '')) +{ + // The class to load + $class = "phpbb_ext_{$ext}_controller"; + + // Make sure the specified extension is enabled + // and that it has a controller class + if (!$phpbb_extension_manager->available($ext)) + { + send_status_line(404, 'Not Found'); + trigger_error($user->lang('EXTENSION_DOES_NOT_EXIST', $ext)); + } + else if (!$phpbb_extension_manager->enabled($ext)) + { + send_status_line(404, 'Not Found'); + trigger_error($user->lang('EXTENSION_DISABLED', $ext)); + } + else if (!file_exists("{$phpbb_root_path}ext/$ext/controller.$phpEx") || !class_exists($class)) + { + send_status_line(404, 'Not Found'); + trigger_error($user->lang('EXTENSION_CONTROLLER_MISSING', $ext)); + } + + // Instantiate the extension controller + $controller = new $class; + + // But let's make sure it's actually a proper controller + if (!($controller instanceof phpbb_extension_controller_interface)) + { + send_status_line(500, 'Internal Server Error'); + trigger_error($user->lang('EXTENSION_CLASS_WRONG_TYPE', $class)); + } + + // Let's get it started... + $controller->handle(); + exit_handler(); +} + display_forums('', $config['load_moderators']); $order_legend = ($config['legend_sort_groupname']) ? 'group_name' : 'group_legend'; diff --git a/phpBB/language/en/common.php b/phpBB/language/en/common.php index 7741ff8d1f..94edddc6f5 100644 --- a/phpBB/language/en/common.php +++ b/phpBB/language/en/common.php @@ -185,7 +185,11 @@ $lang = array_merge($lang, array( 'ERR_WRONG_PATH_TO_PHPBB' => 'The phpBB path specified appears to be invalid.', 'EXPAND_VIEW' => 'Expand view', 'EXTENSION' => 'Extension', + 'EXTENSION_CONTROLLER_MISSING' => 'The extension %s is missing a controller class and cannot be accessed through the front-end.', + 'EXTENSION_CLASS_WRONG_TYPE' => 'The extension controller class %s is not an instance of the phpbb_extension_controller_interface.', + 'EXTENSION_DISABLED' => 'The extension %s is not enabled.', 'EXTENSION_DISABLED_AFTER_POSTING' => 'The extension %s has been deactivated and can no longer be displayed.', + 'EXTENSION_DOES_NOT_EXIST' => 'The extension %s does not exist.', 'FAQ' => 'FAQ', 'FAQ_EXPLAIN' => 'Frequently Asked Questions', From 969c6d42e390fe05960d9dd3b97b230d4e7830a0 Mon Sep 17 00:00:00 2001 From: David King Date: Fri, 17 Feb 2012 14:21:28 -0500 Subject: [PATCH 02/18] [ticket/10586] Removed file_exists() check because class_exists() covers that. PHPBB3-10586 --- phpBB/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/index.php b/phpBB/index.php index a206ed4d37..575134f6b1 100644 --- a/phpBB/index.php +++ b/phpBB/index.php @@ -42,7 +42,7 @@ if ($ext = $request->variable('ext', '')) send_status_line(404, 'Not Found'); trigger_error($user->lang('EXTENSION_DISABLED', $ext)); } - else if (!file_exists("{$phpbb_root_path}ext/$ext/controller.$phpEx") || !class_exists($class)) + else if (!class_exists($class)) { send_status_line(404, 'Not Found'); trigger_error($user->lang('EXTENSION_CONTROLLER_MISSING', $ext)); From e45452d1b3d39220ebd9b20390b9cc23ef64d3dd Mon Sep 17 00:00:00 2001 From: David King Date: Sat, 18 Feb 2012 11:24:27 -0500 Subject: [PATCH 03/18] [ticket/10586] Sanitize periods from class names, use manager to get path. PHPBB3-10586 --- phpBB/includes/extension/manager.php | 2 +- phpBB/index.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/extension/manager.php b/phpBB/includes/extension/manager.php index b94379141c..6f1c885ea9 100644 --- a/phpBB/includes/extension/manager.php +++ b/phpBB/includes/extension/manager.php @@ -437,7 +437,7 @@ class phpbb_extension_manager */ public function available($name) { - return file_exists($this->phpbb_root_path . "ext/$name/"); + return file_exists($this->get_extension_path($name, true)); } /** diff --git a/phpBB/index.php b/phpBB/index.php index 575134f6b1..e6a472ce31 100644 --- a/phpBB/index.php +++ b/phpBB/index.php @@ -28,7 +28,7 @@ $user->setup('viewforum'); if ($ext = $request->variable('ext', '')) { // The class to load - $class = "phpbb_ext_{$ext}_controller"; + $class = 'phpbb_ext_' . str_replace('/', '_', $name) . '_controller'; // Make sure the specified extension is enabled // and that it has a controller class From e5ce9646567e6b3441c21ab960f8a77f1281c72b Mon Sep 17 00:00:00 2001 From: David King Date: Sat, 18 Feb 2012 11:34:07 -0500 Subject: [PATCH 04/18] [ticket/10586] Copy/paste fail fixed PHPBB3-10586 --- phpBB/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/index.php b/phpBB/index.php index e6a472ce31..2500774f67 100644 --- a/phpBB/index.php +++ b/phpBB/index.php @@ -28,7 +28,7 @@ $user->setup('viewforum'); if ($ext = $request->variable('ext', '')) { // The class to load - $class = 'phpbb_ext_' . str_replace('/', '_', $name) . '_controller'; + $class = 'phpbb_ext_' . str_replace('/', '_', $ext) . '_controller'; // Make sure the specified extension is enabled // and that it has a controller class From 401de113f9a0cec57c9648a079303d30fdb23666 Mon Sep 17 00:00:00 2001 From: David King Date: Sun, 19 Feb 2012 15:26:20 -0500 Subject: [PATCH 05/18] [ticket/10586] test stuff. does not work yet, still need to put phpBB objects in bootstrap.php --- .../functional/extension_controller_test.php | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 tests/functional/extension_controller_test.php diff --git a/tests/functional/extension_controller_test.php b/tests/functional/extension_controller_test.php new file mode 100644 index 0000000000..7f0bccc485 --- /dev/null +++ b/tests/functional/extension_controller_test.php @@ -0,0 +1,96 @@ +enable('foobar'); + $phpbb_extension_manager->enable('foo_bar'); + $phpbb_extension_manager->enable('error_class'); + $phpbb_extension_manager->enable('error_classtype'); + } + + public function tearDown() + { + global $db, $cache; + $phpbb_extension_manager = new phpbb_extension_manager($db, 'phpbb_ext', '.php', $cache, '_cache'); + + $phpbb_extension_manager->purge('foobar'); + $phpbb_extension_manager->purge('foo_bar'); + $phpbb_extension_manager->purge('error_class'); + $phpbb_extension_manager->purge('error_classtype'); + } + + /** + * Check an extension at ./ext/foobar/ which should have the class + * phpbb_ext_foobar_controller + */ + public function test_foobar() + { + $crawler = $this->request('GET', 'index.php?ext=foobar'); + $this->assertGreaterThan(0, $crawler->filter('#welcome')->count()); + } + + /** + * Check an extension at ./ext/foo/bar/ which should have the class + * phpbb_ext_foo_bar_controller + */ + public function test_foo_bar() + { + $crawler = $this->request('GET', 'index.php?ext=foo/bar'); + $this->assertGreaterThan(0, $crawler->filter('#welcome')->count()); + } + + /** + * Check the error produced by extension at ./ext/error/class which has class + * phpbb_ext_foobar_controller + */ + public function test_error_class_name() + { + $crawler = $this->request('GET', 'index.php?ext=error/class'); + $this->assertGreaterThan(0, $crawler->filter('html:contains("The extension error_class is missing a controller class and cannot be accessed through the front-end.")')->count()); + } + + /** + * Check the error produced by extension at ./ext/error/classtype which has class + * phpbb_ext_error_classtype_controller but does not implement phpbb_extension_controller_interface + */ + public function test_error_class_type() + { + $crawler = $this->request('GET', 'index.php?ext=error/classtype'); + $this->assertGreaterThan(0, $crawler->filter('html:contains("The extension controller class phpbb_ext_error_classtype_controller is not an instance of the phpbb_extension_controller_interface.")')->count()); + } + + /** + * Check the error produced by extension at ./ext/error/disabled that is (obviously) + * a disabled extension + */ + public function test_error_ext_disabled() + { + $crawler = $this->request('GET', 'index.php?ext=error/disabled'); + $this->assertGreaterThan(0, $crawler->filter('html:contains("The extension error_classtype is not enabled.")')->count()); + } + + /** + * Check the error produced by extension at ./ext/error/404 that is (obviously) + * not existant + */ + public function test_error_ext_missing() + { + $crawler = $this->request('GET', 'index.php?ext=error/404'); + $this->assertGreaterThan(0, $crawler->filter('html:contains("The extension error_404 does not exist.")')->count()); + } +} From 9212466626a3d80a90cab1f23cf423a1c4e20655 Mon Sep 17 00:00:00 2001 From: David King Date: Tue, 21 Feb 2012 09:38:53 -0500 Subject: [PATCH 06/18] [ticket/10586] some bootstrap additions and test changes to try and make it work PHPBB3-10586 --- tests/bootstrap.php | 36 +++++++++++++++++++ .../functional/extension_controller_test.php | 6 ++-- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 302701e3b3..e98ec384e6 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -26,6 +26,42 @@ require_once 'test_framework/phpbb_test_case.php'; require_once 'test_framework/phpbb_database_test_case.php'; require_once 'test_framework/phpbb_database_test_connection_manager.php'; +// For functional tests, we need to make available the phpBB objects +require_once $phpbb_root_path . 'config.php'; +// Setup class loader first +$phpbb_class_loader_ext = new phpbb_class_loader('phpbb_ext_', $phpbb_root_path . 'ext/', ".$phpEx"); +$phpbb_class_loader_ext->register(); +$phpbb_class_loader = new phpbb_class_loader('phpbb_', $phpbb_root_path . 'includes/', ".$phpEx"); +$phpbb_class_loader->register(); + +// set up caching +$cache_factory = new phpbb_cache_factory($acm_type); +$cache = $cache_factory->get_service(); +$phpbb_class_loader_ext->set_cache($cache->get_driver()); +$phpbb_class_loader->set_cache($cache->get_driver()); + +// We have to include this because the class loader doesn't +// recognize classes without the phpbb_ prefix +// So user and auth and the DBAL aren't found unless we require these files +require($phpbb_root_path . 'includes/session.' . $phpEx); +require($phpbb_root_path . 'includes/auth.' . $phpEx); +require($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx); +// Instantiate some basic classes +$user = new user(); +$auth = new auth(); +$db = new $sql_db(); + +$db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, defined('PHPBB_DB_NEW_LINK') ? PHPBB_DB_NEW_LINK : false); + +// We do not need this any longer, unset for safety purposes +unset($dbpasswd); + +// Grab global variables, re-cache if necessary +$config = new phpbb_config_db($db, $cache->get_driver(), CONFIG_TABLE); + +// load extensions +$phpbb_extension_manager = new phpbb_extension_manager($db, EXT_TABLE, $phpbb_root_path, ".$phpEx", $cache->get_driver()); + if (version_compare(PHP_VERSION, '5.3.0-dev', '>=')) { require_once 'test_framework/phpbb_functional_test_case.php'; diff --git a/tests/functional/extension_controller_test.php b/tests/functional/extension_controller_test.php index 7f0bccc485..430d93f9bf 100644 --- a/tests/functional/extension_controller_test.php +++ b/tests/functional/extension_controller_test.php @@ -14,8 +14,7 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c { public function setUp() { - global $db, $cache; - $phpbb_extension_manager = new phpbb_extension_manager($db, 'phpbb_ext', '.php', $cache, '_cache'); + global $phpbb_extension_manager; $phpbb_extension_manager->enable('foobar'); $phpbb_extension_manager->enable('foo_bar'); @@ -25,8 +24,7 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c public function tearDown() { - global $db, $cache; - $phpbb_extension_manager = new phpbb_extension_manager($db, 'phpbb_ext', '.php', $cache, '_cache'); + global $phpbb_extension_manager; $phpbb_extension_manager->purge('foobar'); $phpbb_extension_manager->purge('foo_bar'); From a37a28b48546afc880446db7e4b2fd87c70a6cda Mon Sep 17 00:00:00 2001 From: David King Date: Tue, 21 Feb 2012 10:53:22 -0500 Subject: [PATCH 07/18] [ticket/10586] Now tests run, but fail. But here is what I have. PHPBB3-10586 --- tests/bootstrap.php | 36 ------------------- .../functional/extension_controller_test.php | 6 ++-- .../phpbb_functional_test_case.php | 20 +++++++++++ 3 files changed, 24 insertions(+), 38 deletions(-) diff --git a/tests/bootstrap.php b/tests/bootstrap.php index e98ec384e6..302701e3b3 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -26,42 +26,6 @@ require_once 'test_framework/phpbb_test_case.php'; require_once 'test_framework/phpbb_database_test_case.php'; require_once 'test_framework/phpbb_database_test_connection_manager.php'; -// For functional tests, we need to make available the phpBB objects -require_once $phpbb_root_path . 'config.php'; -// Setup class loader first -$phpbb_class_loader_ext = new phpbb_class_loader('phpbb_ext_', $phpbb_root_path . 'ext/', ".$phpEx"); -$phpbb_class_loader_ext->register(); -$phpbb_class_loader = new phpbb_class_loader('phpbb_', $phpbb_root_path . 'includes/', ".$phpEx"); -$phpbb_class_loader->register(); - -// set up caching -$cache_factory = new phpbb_cache_factory($acm_type); -$cache = $cache_factory->get_service(); -$phpbb_class_loader_ext->set_cache($cache->get_driver()); -$phpbb_class_loader->set_cache($cache->get_driver()); - -// We have to include this because the class loader doesn't -// recognize classes without the phpbb_ prefix -// So user and auth and the DBAL aren't found unless we require these files -require($phpbb_root_path . 'includes/session.' . $phpEx); -require($phpbb_root_path . 'includes/auth.' . $phpEx); -require($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx); -// Instantiate some basic classes -$user = new user(); -$auth = new auth(); -$db = new $sql_db(); - -$db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, defined('PHPBB_DB_NEW_LINK') ? PHPBB_DB_NEW_LINK : false); - -// We do not need this any longer, unset for safety purposes -unset($dbpasswd); - -// Grab global variables, re-cache if necessary -$config = new phpbb_config_db($db, $cache->get_driver(), CONFIG_TABLE); - -// load extensions -$phpbb_extension_manager = new phpbb_extension_manager($db, EXT_TABLE, $phpbb_root_path, ".$phpEx", $cache->get_driver()); - if (version_compare(PHP_VERSION, '5.3.0-dev', '>=')) { require_once 'test_framework/phpbb_functional_test_case.php'; diff --git a/tests/functional/extension_controller_test.php b/tests/functional/extension_controller_test.php index 430d93f9bf..7e50eb7d91 100644 --- a/tests/functional/extension_controller_test.php +++ b/tests/functional/extension_controller_test.php @@ -14,7 +14,8 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c { public function setUp() { - global $phpbb_extension_manager; + parent::setUp(); + $phpbb_extension_manager = $this->get_ext_manager(); $phpbb_extension_manager->enable('foobar'); $phpbb_extension_manager->enable('foo_bar'); @@ -24,7 +25,8 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c public function tearDown() { - global $phpbb_extension_manager; + parent::tearDown(); + $phpbb_extension_manager = $this->get_ext_manager(); $phpbb_extension_manager->purge('foobar'); $phpbb_extension_manager->purge('foo_bar'); diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index b5e6f7e377..b2ae215d91 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -66,6 +66,26 @@ class phpbb_functional_test_case extends phpbb_test_case } } + protected function get_db() + { + global $phpbb_root_path, $phpEx; + if (!class_exists('dbal_' . self::$config['dbms'])) + { + include($phpbb_root_path . 'includes/db/' . self::$config['dbms'] . ".$phpEx"); + } + $sql_db = 'dbal_' . self::$config['dbms']; + $db = new $sql_db(); + $db->sql_connect(self::$config['dbhost'], self::$config['dbuser'], self::$config['dbpasswd'], self::$config['dbname'], self::$config['dbport']); + return $db; + } + + protected function get_ext_manager() + { + global $phpbb_root_path, $phpEx; + + return new phpbb_extension_manager($this->get_db(), self::$config['table_prefix'] . 'ext', $phpbb_root_path, ".$phpEx", new phpbb_cache_driver_null); + } + protected function install_board() { global $phpbb_root_path, $phpEx; From d235262bc21657f0693501ac1154e1443578d507 Mon Sep 17 00:00:00 2001 From: David King Date: Tue, 21 Feb 2012 11:17:21 -0500 Subject: [PATCH 08/18] [ticket/10586] Adding the extensions used by the tests PHPBB3-10586 --- .../fixtures/ext/error/class/controller.php | 17 +++++++++++++++++ .../fixtures/ext/error/class/ext.php | 6 ++++++ .../ext/error/classtype/controller.php | 17 +++++++++++++++++ .../fixtures/ext/error/classtype/ext.php | 6 ++++++ .../fixtures/ext/error/disabled/controller.php | 17 +++++++++++++++++ .../fixtures/ext/error/disabled/ext.php | 6 ++++++ .../fixtures/ext/foo/bar/controller.php | 17 +++++++++++++++++ tests/functional/fixtures/ext/foo/bar/ext.php | 6 ++++++ .../styles/prosilver/template/index_body.html | 5 +++++ .../fixtures/ext/foobar/controller.php | 17 +++++++++++++++++ tests/functional/fixtures/ext/foobar/ext.php | 6 ++++++ .../styles/prosilver/template/index_body.html | 5 +++++ .../phpbb_functional_test_case.php | 18 ++++++++++++------ 13 files changed, 137 insertions(+), 6 deletions(-) create mode 100644 tests/functional/fixtures/ext/error/class/controller.php create mode 100644 tests/functional/fixtures/ext/error/class/ext.php create mode 100644 tests/functional/fixtures/ext/error/classtype/controller.php create mode 100644 tests/functional/fixtures/ext/error/classtype/ext.php create mode 100644 tests/functional/fixtures/ext/error/disabled/controller.php create mode 100644 tests/functional/fixtures/ext/error/disabled/ext.php create mode 100644 tests/functional/fixtures/ext/foo/bar/controller.php create mode 100644 tests/functional/fixtures/ext/foo/bar/ext.php create mode 100644 tests/functional/fixtures/ext/foo/bar/styles/prosilver/template/index_body.html create mode 100644 tests/functional/fixtures/ext/foobar/controller.php create mode 100644 tests/functional/fixtures/ext/foobar/ext.php create mode 100644 tests/functional/fixtures/ext/foobar/styles/prosilver/template/index_body.html diff --git a/tests/functional/fixtures/ext/error/class/controller.php b/tests/functional/fixtures/ext/error/class/controller.php new file mode 100644 index 0000000000..eb2ae362a6 --- /dev/null +++ b/tests/functional/fixtures/ext/error/class/controller.php @@ -0,0 +1,17 @@ +set_ext_dir_prefix($phpbb_root_path . 'ext/error/class/'); + + $template->set_filenames(array( + 'body' => 'index_body.html' + )); + + page_header('Test extension'); + page_footer(); + } +} diff --git a/tests/functional/fixtures/ext/error/class/ext.php b/tests/functional/fixtures/ext/error/class/ext.php new file mode 100644 index 0000000000..f97ad2b838 --- /dev/null +++ b/tests/functional/fixtures/ext/error/class/ext.php @@ -0,0 +1,6 @@ +set_ext_dir_prefix($phpbb_root_path . 'ext/error/classtype/'); + + $template->set_filenames(array( + 'body' => 'index_body.html' + )); + + page_header('Test extension'); + page_footer(); + } +} diff --git a/tests/functional/fixtures/ext/error/classtype/ext.php b/tests/functional/fixtures/ext/error/classtype/ext.php new file mode 100644 index 0000000000..35b1cd15a2 --- /dev/null +++ b/tests/functional/fixtures/ext/error/classtype/ext.php @@ -0,0 +1,6 @@ +set_ext_dir_prefix($phpbb_root_path . 'ext/error/disabled/'); + + $template->set_filenames(array( + 'body' => 'index_body.html' + )); + + page_header('Test extension'); + page_footer(); + } +} diff --git a/tests/functional/fixtures/ext/error/disabled/ext.php b/tests/functional/fixtures/ext/error/disabled/ext.php new file mode 100644 index 0000000000..aec8051848 --- /dev/null +++ b/tests/functional/fixtures/ext/error/disabled/ext.php @@ -0,0 +1,6 @@ +set_ext_dir_prefix($phpbb_root_path . 'ext/foo/bar/'); + + $template->set_filenames(array( + 'body' => 'index_body.html' + )); + + page_header('Test extension'); + page_footer(); + } +} diff --git a/tests/functional/fixtures/ext/foo/bar/ext.php b/tests/functional/fixtures/ext/foo/bar/ext.php new file mode 100644 index 0000000000..3a2068631e --- /dev/null +++ b/tests/functional/fixtures/ext/foo/bar/ext.php @@ -0,0 +1,6 @@ + + +
This is for testing purposes.
+ + diff --git a/tests/functional/fixtures/ext/foobar/controller.php b/tests/functional/fixtures/ext/foobar/controller.php new file mode 100644 index 0000000000..c3ef29ffef --- /dev/null +++ b/tests/functional/fixtures/ext/foobar/controller.php @@ -0,0 +1,17 @@ +set_ext_dir_prefix($phpbb_root_path . 'ext/foobar/'); + + $template->set_filenames(array( + 'body' => 'index_body.html' + )); + + page_header('Test extension'); + page_footer(); + } +} diff --git a/tests/functional/fixtures/ext/foobar/ext.php b/tests/functional/fixtures/ext/foobar/ext.php new file mode 100644 index 0000000000..7b3f37cbfb --- /dev/null +++ b/tests/functional/fixtures/ext/foobar/ext.php @@ -0,0 +1,6 @@ + + +
This is for testing purposes.
+ + diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index b2ae215d91..9797ecfef8 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -14,6 +14,8 @@ class phpbb_functional_test_case extends phpbb_test_case protected $client; protected $root_url; + protected $db = null; + static protected $config = array(); static protected $already_installed = false; @@ -69,14 +71,18 @@ class phpbb_functional_test_case extends phpbb_test_case protected function get_db() { global $phpbb_root_path, $phpEx; - if (!class_exists('dbal_' . self::$config['dbms'])) + // so we don't reopen an open connection + if (!($this->db instanceof dbal)) { - include($phpbb_root_path . 'includes/db/' . self::$config['dbms'] . ".$phpEx"); + if (!class_exists('dbal_' . self::$config['dbms'])) + { + include($phpbb_root_path . 'includes/db/' . self::$config['dbms'] . ".$phpEx"); + } + $sql_db = 'dbal_' . self::$config['dbms']; + $this->db = new $sql_db(); + $this->db->sql_connect(self::$config['dbhost'], self::$config['dbuser'], self::$config['dbpasswd'], self::$config['dbname'], self::$config['dbport']); } - $sql_db = 'dbal_' . self::$config['dbms']; - $db = new $sql_db(); - $db->sql_connect(self::$config['dbhost'], self::$config['dbuser'], self::$config['dbpasswd'], self::$config['dbname'], self::$config['dbport']); - return $db; + return $this->db; } protected function get_ext_manager() From 7b44d6f21a5a8be289bf6810f2c38d580647581e Mon Sep 17 00:00:00 2001 From: David King Date: Fri, 16 Mar 2012 15:35:01 -0400 Subject: [PATCH 09/18] [ticket/10586] initial work on copying fixtures. Note that this depends on 10706 PHPBB3-10586 --- .../functional/extension_controller_test.php | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/functional/extension_controller_test.php b/tests/functional/extension_controller_test.php index 7e50eb7d91..b52174bbd5 100644 --- a/tests/functional/extension_controller_test.php +++ b/tests/functional/extension_controller_test.php @@ -12,6 +12,39 @@ */ class phpbb_functional_extension_controller_test extends phpbb_functional_test_case { + /** + * This should only be called once before the tests are run. + * This is used to copy the fixtures to the phpBB install + */ + static public function setUpBeforeClass() + { + parent::setUpBeforeClass(); + // When you add new tests that require new fixtures, add them to the array. + $fixtures = array( + 'error/class/controller.php', + 'error/class/ext.php', + 'error/classtype/controller.php', + 'error/classtype/ext.php', + 'error/disabled/controller.php', + 'error/disabled/ext.php', + 'foo/bar/controller.php', + 'foo/bar/ext.php', + 'foo/bar/styles/prosilver/template/index_body.html', + 'foobar/controller.php', + 'foobar/ext.php', + 'foobar/styles/prosilver/template/index_body.html', + ); + + foreach ($fixtures as $fixture) + { + // we have to use self::$config['phpbb_functional_url'] because $this->root_url is not available in static classes + if(!copy("tests/functional/fixtures/ext/$fixture", self::$config['phpbb_functional_url'] . "/ext/$fixture")) + { + echo 'Could not copy file ' . $fixture; + } + } + } + public function setUp() { parent::setUp(); From 66b45318efea886ac6afc1f332cc94ee2af1c494 Mon Sep 17 00:00:00 2001 From: David King Date: Fri, 16 Mar 2012 16:42:29 -0400 Subject: [PATCH 10/18] [ticket/10586] browse tests now work, but mine dont. at least we are making progress PHPBB3-10586 --- tests/functional/browse_test.php | 11 ++++++++++ .../functional/extension_controller_test.php | 22 ++++++++++++++++++- .../phpbb_test_case_helpers.php | 12 ++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/tests/functional/browse_test.php b/tests/functional/browse_test.php index 723cf93232..d119787d13 100644 --- a/tests/functional/browse_test.php +++ b/tests/functional/browse_test.php @@ -12,6 +12,17 @@ */ class phpbb_functional_browse_test extends phpbb_functional_test_case { + public static function setUpBeforeClass() + { + parent::setUpBeforeClass(); + $f_path = self::$config['phpbb_functional_path']; + // we cannot run these tests correctly if the install directory is present + if (is_dir($f_path . 'install/')) + { + rename($f_path . 'install/', $f_path . 'install_/'); + } + // NOTE: this will need to be renamed back again later if you wish to test again + } public function test_index() { $crawler = $this->request('GET', 'index.php'); diff --git a/tests/functional/extension_controller_test.php b/tests/functional/extension_controller_test.php index b52174bbd5..50710d0347 100644 --- a/tests/functional/extension_controller_test.php +++ b/tests/functional/extension_controller_test.php @@ -19,7 +19,27 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c static public function setUpBeforeClass() { parent::setUpBeforeClass(); + $f_path = self::$config['phpbb_functional_path']; + + // these directories need to be created before the files can be copied + $directories = array( + $f_path . 'ext/error/class/', + $f_path . 'ext/error/classtype/', + $f_path . 'ext/error/disabled/', + $f_path . 'ext/foo/bar/', + $f_path . 'ext/foo/bar/styles/prosilver/template/', + $f_path . 'ext/foobar/', + $f_path . 'ext/foobar/styles/prosilver/template/', + ); // When you add new tests that require new fixtures, add them to the array. + foreach ($directories as $dir) + { + if (!is_dir($dir)) + { + mkdir($dir, 0777, true); + } + } + $fixtures = array( 'error/class/controller.php', 'error/class/ext.php', @@ -38,7 +58,7 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c foreach ($fixtures as $fixture) { // we have to use self::$config['phpbb_functional_url'] because $this->root_url is not available in static classes - if(!copy("tests/functional/fixtures/ext/$fixture", self::$config['phpbb_functional_url'] . "/ext/$fixture")) + if(!copy("tests/functional/fixtures/ext/$fixture", "{$f_path}ext/$fixture")) { echo 'Could not copy file ' . $fixture; } diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php index 9c91778cb0..51b04db263 100644 --- a/tests/test_framework/phpbb_test_case_helpers.php +++ b/tests/test_framework/phpbb_test_case_helpers.php @@ -80,6 +80,11 @@ class phpbb_test_case_helpers { $config['phpbb_functional_url'] = $phpbb_functional_url; } + + if (isset($phpbb_functional_path)) + { + $config['phpbb_functional_path'] = $phpbb_functional_path; + } } if (isset($_SERVER['PHPBB_TEST_DBMS'])) @@ -101,6 +106,13 @@ class phpbb_test_case_helpers )); } + if (isset($_SERVER['PHPBB_FUNCTIONAL_PATH'])) + { + $config = array_merge($config, array( + 'phpbb_functional_path' => isset($_SERVER['PHPBB_FUNCTIONAL_PATH']) ? $_SERVER['PHPBB_FUNCTIONAL_PATH'] : '', + )); + } + return $config; } } From e78585c973d260651dd8487d586facd2ab9e1e51 Mon Sep 17 00:00:00 2001 From: David King Date: Fri, 16 Mar 2012 17:18:08 -0400 Subject: [PATCH 11/18] [ticket/10586] Rename install directory back to install/ after tests PHPBB3-10586 --- tests/functional/extension_controller_test.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/functional/extension_controller_test.php b/tests/functional/extension_controller_test.php index 50710d0347..f137a49bf4 100644 --- a/tests/functional/extension_controller_test.php +++ b/tests/functional/extension_controller_test.php @@ -65,6 +65,17 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c } } + public static function tearDownAfterClass() + { + $f_path = self::$config['phpbb_functional_path']; + // first we rename the install_ directory back to install + rename($f_path . 'install_/', $f_path . 'install/'); + + // @todo delete the fixtures from the $f_path board + // Note that it might be best to find a public domain function + // and port it into here instead of writing it from scratch + } + public function setUp() { parent::setUp(); From 4100b312bb0eb7246e9057461b6f8f3c66fdad60 Mon Sep 17 00:00:00 2001 From: David King Date: Sat, 17 Mar 2012 22:12:50 -0400 Subject: [PATCH 12/18] [ticket/10586] Tests are coming along, just a little more to go PHPBB3-10586 --- .../functional/extension_controller_test.php | 56 +++++++++---------- .../fixtures/ext/foo/bar/controller.php | 2 +- .../{index_body.html => foobar_body.html} | 0 .../fixtures/ext/foobar/controller.php | 2 +- .../{index_body.html => foobar_body.html} | 0 5 files changed, 28 insertions(+), 32 deletions(-) rename tests/functional/fixtures/ext/foo/bar/styles/prosilver/template/{index_body.html => foobar_body.html} (100%) rename tests/functional/fixtures/ext/foobar/styles/prosilver/template/{index_body.html => foobar_body.html} (100%) diff --git a/tests/functional/extension_controller_test.php b/tests/functional/extension_controller_test.php index f137a49bf4..cb27511be1 100644 --- a/tests/functional/extension_controller_test.php +++ b/tests/functional/extension_controller_test.php @@ -49,10 +49,10 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c 'error/disabled/ext.php', 'foo/bar/controller.php', 'foo/bar/ext.php', - 'foo/bar/styles/prosilver/template/index_body.html', + 'foo/bar/styles/prosilver/template/foobar_body.html', 'foobar/controller.php', 'foobar/ext.php', - 'foobar/styles/prosilver/template/index_body.html', + 'foobar/styles/prosilver/template/foobar_body.html', ); foreach ($fixtures as $fixture) @@ -76,36 +76,20 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c // and port it into here instead of writing it from scratch } - public function setUp() - { - parent::setUp(); - $phpbb_extension_manager = $this->get_ext_manager(); - - $phpbb_extension_manager->enable('foobar'); - $phpbb_extension_manager->enable('foo_bar'); - $phpbb_extension_manager->enable('error_class'); - $phpbb_extension_manager->enable('error_classtype'); - } - - public function tearDown() - { - parent::tearDown(); - $phpbb_extension_manager = $this->get_ext_manager(); - - $phpbb_extension_manager->purge('foobar'); - $phpbb_extension_manager->purge('foo_bar'); - $phpbb_extension_manager->purge('error_class'); - $phpbb_extension_manager->purge('error_classtype'); - } - /** * Check an extension at ./ext/foobar/ which should have the class * phpbb_ext_foobar_controller */ public function test_foobar() { + $phpbb_extension_manager = $this->get_ext_manager(); + $phpbb_extension_manager->enable('foobar'); $crawler = $this->request('GET', 'index.php?ext=foobar'); - $this->assertGreaterThan(0, $crawler->filter('#welcome')->count()); + if($this->assertGreaterThan(0, $crawler->filter('#welcome')->count())) + { + $this->assertContains("This is for testing purposes.", $crawler->filter('#welcome')->text()); + } + $phpbb_extension_manager->purge('foobar'); } /** @@ -114,8 +98,14 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c */ public function test_foo_bar() { + $phpbb_extension_manager = $this->get_ext_manager(); + $phpbb_extension_manager->enable('foo/bar'); $crawler = $this->request('GET', 'index.php?ext=foo/bar'); - $this->assertGreaterThan(0, $crawler->filter('#welcome')->count()); + if($this->assertGreaterThan(0, $crawler->filter('#welcome')->count())) + { + $this->assertContains("This is for testing purposes.", $crawler->filter('#welcome')->text()); + } + $phpbb_extension_manager->purge('foo_bar'); } /** @@ -124,8 +114,11 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c */ public function test_error_class_name() { + $phpbb_extension_manager = $this->get_ext_manager(); + $phpbb_extension_manager->enable('error/class'); $crawler = $this->request('GET', 'index.php?ext=error/class'); - $this->assertGreaterThan(0, $crawler->filter('html:contains("The extension error_class is missing a controller class and cannot be accessed through the front-end.")')->count()); + $this->assertContains("The extension error/class is missing a controller class and cannot be accessed through the front-end.", $crawler->filter('#message')->text()); + $phpbb_extension_manager->purge('error_class'); } /** @@ -134,8 +127,11 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c */ public function test_error_class_type() { + $phpbb_extension_manager = $this->get_ext_manager(); + $phpbb_extension_manager->enable('error/classtype'); $crawler = $this->request('GET', 'index.php?ext=error/classtype'); - $this->assertGreaterThan(0, $crawler->filter('html:contains("The extension controller class phpbb_ext_error_classtype_controller is not an instance of the phpbb_extension_controller_interface.")')->count()); + $this->assertContains("The extension controller class phpbb_ext_error_classtype_controller is not an instance of the phpbb_extension_controller_interface.", $crawler->filter('#message')->text()); + $phpbb_extension_manager->purge('error_classtype'); } /** @@ -145,7 +141,7 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c public function test_error_ext_disabled() { $crawler = $this->request('GET', 'index.php?ext=error/disabled'); - $this->assertGreaterThan(0, $crawler->filter('html:contains("The extension error_classtype is not enabled.")')->count()); + $this->assertContains("The extension error/disabled is not enabled", $crawler->filter('#message')->text()); } /** @@ -155,6 +151,6 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c public function test_error_ext_missing() { $crawler = $this->request('GET', 'index.php?ext=error/404'); - $this->assertGreaterThan(0, $crawler->filter('html:contains("The extension error_404 does not exist.")')->count()); + $this->assertContains("The extension error/404 does not exist.", $crawler->filter('#message')->text()); } } diff --git a/tests/functional/fixtures/ext/foo/bar/controller.php b/tests/functional/fixtures/ext/foo/bar/controller.php index 93d1f099c9..24d218c412 100644 --- a/tests/functional/fixtures/ext/foo/bar/controller.php +++ b/tests/functional/fixtures/ext/foo/bar/controller.php @@ -8,7 +8,7 @@ class phpbb_ext_foo_bar_controller implements phpbb_extension_controller_interfa $template->set_ext_dir_prefix($phpbb_root_path . 'ext/foo/bar/'); $template->set_filenames(array( - 'body' => 'index_body.html' + 'body' => 'foobar_body.html' )); page_header('Test extension'); diff --git a/tests/functional/fixtures/ext/foo/bar/styles/prosilver/template/index_body.html b/tests/functional/fixtures/ext/foo/bar/styles/prosilver/template/foobar_body.html similarity index 100% rename from tests/functional/fixtures/ext/foo/bar/styles/prosilver/template/index_body.html rename to tests/functional/fixtures/ext/foo/bar/styles/prosilver/template/foobar_body.html diff --git a/tests/functional/fixtures/ext/foobar/controller.php b/tests/functional/fixtures/ext/foobar/controller.php index c3ef29ffef..bf8d8139ae 100644 --- a/tests/functional/fixtures/ext/foobar/controller.php +++ b/tests/functional/fixtures/ext/foobar/controller.php @@ -8,7 +8,7 @@ class phpbb_ext_foobar_controller implements phpbb_extension_controller_interfac $template->set_ext_dir_prefix($phpbb_root_path . 'ext/foobar/'); $template->set_filenames(array( - 'body' => 'index_body.html' + 'body' => 'foobar_body.html' )); page_header('Test extension'); diff --git a/tests/functional/fixtures/ext/foobar/styles/prosilver/template/index_body.html b/tests/functional/fixtures/ext/foobar/styles/prosilver/template/foobar_body.html similarity index 100% rename from tests/functional/fixtures/ext/foobar/styles/prosilver/template/index_body.html rename to tests/functional/fixtures/ext/foobar/styles/prosilver/template/foobar_body.html From 7d1e4bca334dc9fcef3eb6e62cb412226ebc7ca4 Mon Sep 17 00:00:00 2001 From: David King Date: Sun, 18 Mar 2012 14:44:37 -0400 Subject: [PATCH 13/18] [ticket/10586] more work on getting tests to pass PHPBB3-10586 --- tests/functional/extension_controller_test.php | 16 +++++----------- .../phpbb_functional_test_case.php | 2 +- tests/test_framework/phpbb_test_case_helpers.php | 8 +++----- 3 files changed, 9 insertions(+), 17 deletions(-) diff --git a/tests/functional/extension_controller_test.php b/tests/functional/extension_controller_test.php index cb27511be1..46f3dc6f96 100644 --- a/tests/functional/extension_controller_test.php +++ b/tests/functional/extension_controller_test.php @@ -85,10 +85,7 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c $phpbb_extension_manager = $this->get_ext_manager(); $phpbb_extension_manager->enable('foobar'); $crawler = $this->request('GET', 'index.php?ext=foobar'); - if($this->assertGreaterThan(0, $crawler->filter('#welcome')->count())) - { - $this->assertContains("This is for testing purposes.", $crawler->filter('#welcome')->text()); - } + $this->assertContains("This is for testing purposes.", $crawler->filter('#page-body')->text()); $phpbb_extension_manager->purge('foobar'); } @@ -101,11 +98,8 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c $phpbb_extension_manager = $this->get_ext_manager(); $phpbb_extension_manager->enable('foo/bar'); $crawler = $this->request('GET', 'index.php?ext=foo/bar'); - if($this->assertGreaterThan(0, $crawler->filter('#welcome')->count())) - { - $this->assertContains("This is for testing purposes.", $crawler->filter('#welcome')->text()); - } - $phpbb_extension_manager->purge('foo_bar'); + $this->assertContains("This is for testing purposes.", $crawler->filter('#page-body')->text()); + $phpbb_extension_manager->purge('foo/bar'); } /** @@ -118,7 +112,7 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c $phpbb_extension_manager->enable('error/class'); $crawler = $this->request('GET', 'index.php?ext=error/class'); $this->assertContains("The extension error/class is missing a controller class and cannot be accessed through the front-end.", $crawler->filter('#message')->text()); - $phpbb_extension_manager->purge('error_class'); + $phpbb_extension_manager->purge('error/class'); } /** @@ -131,7 +125,7 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c $phpbb_extension_manager->enable('error/classtype'); $crawler = $this->request('GET', 'index.php?ext=error/classtype'); $this->assertContains("The extension controller class phpbb_ext_error_classtype_controller is not an instance of the phpbb_extension_controller_interface.", $crawler->filter('#message')->text()); - $phpbb_extension_manager->purge('error_classtype'); + $phpbb_extension_manager->purge('error/classtype'); } /** diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 9797ecfef8..b3376891bc 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -89,7 +89,7 @@ class phpbb_functional_test_case extends phpbb_test_case { global $phpbb_root_path, $phpEx; - return new phpbb_extension_manager($this->get_db(), self::$config['table_prefix'] . 'ext', $phpbb_root_path, ".$phpEx", new phpbb_cache_driver_null); + return new phpbb_extension_manager($this->get_db(), self::$config['table_prefix'] . 'ext', $phpbb_root_path, ".$phpEx", new phpbb_cache_driver_file); } protected function install_board() diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php index 51b04db263..4aec07a8fb 100644 --- a/tests/test_framework/phpbb_test_case_helpers.php +++ b/tests/test_framework/phpbb_test_case_helpers.php @@ -81,7 +81,7 @@ class phpbb_test_case_helpers $config['phpbb_functional_url'] = $phpbb_functional_url; } - if (isset($phpbb_functional_path)) + if (!empty($phpbb_functional_path)) { $config['phpbb_functional_path'] = $phpbb_functional_path; } @@ -106,11 +106,9 @@ class phpbb_test_case_helpers )); } - if (isset($_SERVER['PHPBB_FUNCTIONAL_PATH'])) + if (!empty($_SERVER['PHPBB_FUNCTIONAL_PATH'])) { - $config = array_merge($config, array( - 'phpbb_functional_path' => isset($_SERVER['PHPBB_FUNCTIONAL_PATH']) ? $_SERVER['PHPBB_FUNCTIONAL_PATH'] : '', - )); + $config['phpbb_functional_path'] = $_SERVER['PHPBB_FUNCTIONAL_PATH']; } return $config; From 76e61951942048e3e98dbe60a3683d5269a4fa0e Mon Sep 17 00:00:00 2001 From: David King Date: Sun, 18 Mar 2012 16:50:41 -0400 Subject: [PATCH 14/18] [ticket/10586] trying to get tests to work PHPBB3-10586 --- .../functional/extension_controller_test.php | 28 +++++++++++-------- .../phpbb_functional_test_case.php | 5 ++-- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/tests/functional/extension_controller_test.php b/tests/functional/extension_controller_test.php index 46f3dc6f96..4123853151 100644 --- a/tests/functional/extension_controller_test.php +++ b/tests/functional/extension_controller_test.php @@ -12,6 +12,7 @@ */ class phpbb_functional_extension_controller_test extends phpbb_functional_test_case { + protected $phpbb_extension_manager; /** * This should only be called once before the tests are run. * This is used to copy the fixtures to the phpBB install @@ -76,17 +77,23 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c // and port it into here instead of writing it from scratch } + public function setUp() + { + parent::setUp(); + $this->phpbb_extension_manager = !($this->phpbb_extension_manager instanceof phpbb_extension_manager) ? $this->get_ext_manager() : $this->phpbb_extension_manager; + $this->cache->purge('_ext'); + } + /** * Check an extension at ./ext/foobar/ which should have the class * phpbb_ext_foobar_controller */ public function test_foobar() { - $phpbb_extension_manager = $this->get_ext_manager(); - $phpbb_extension_manager->enable('foobar'); + $this->phpbb_extension_manager->enable('foobar'); $crawler = $this->request('GET', 'index.php?ext=foobar'); $this->assertContains("This is for testing purposes.", $crawler->filter('#page-body')->text()); - $phpbb_extension_manager->purge('foobar'); + $this->phpbb_extension_manager->purge('foobar'); } /** @@ -95,11 +102,10 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c */ public function test_foo_bar() { - $phpbb_extension_manager = $this->get_ext_manager(); - $phpbb_extension_manager->enable('foo/bar'); + $this->phpbb_extension_manager->enable('foo/bar'); $crawler = $this->request('GET', 'index.php?ext=foo/bar'); $this->assertContains("This is for testing purposes.", $crawler->filter('#page-body')->text()); - $phpbb_extension_manager->purge('foo/bar'); + $this->phpbb_extension_manager->purge('foo/bar'); } /** @@ -108,11 +114,10 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c */ public function test_error_class_name() { - $phpbb_extension_manager = $this->get_ext_manager(); - $phpbb_extension_manager->enable('error/class'); + $this->phpbb_extension_manager->enable('error/class'); $crawler = $this->request('GET', 'index.php?ext=error/class'); $this->assertContains("The extension error/class is missing a controller class and cannot be accessed through the front-end.", $crawler->filter('#message')->text()); - $phpbb_extension_manager->purge('error/class'); + $this->phpbb_extension_manager->purge('error/class'); } /** @@ -121,11 +126,10 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c */ public function test_error_class_type() { - $phpbb_extension_manager = $this->get_ext_manager(); - $phpbb_extension_manager->enable('error/classtype'); + $this->phpbb_extension_manager->enable('error/classtype'); $crawler = $this->request('GET', 'index.php?ext=error/classtype'); $this->assertContains("The extension controller class phpbb_ext_error_classtype_controller is not an instance of the phpbb_extension_controller_interface.", $crawler->filter('#message')->text()); - $phpbb_extension_manager->purge('error/classtype'); + $this->phpbb_extension_manager->purge('error/classtype'); } /** diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index b3376891bc..d569556d02 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -14,6 +14,7 @@ class phpbb_functional_test_case extends phpbb_test_case protected $client; protected $root_url; + protected $cache = null; protected $db = null; static protected $config = array(); @@ -88,8 +89,8 @@ class phpbb_functional_test_case extends phpbb_test_case protected function get_ext_manager() { global $phpbb_root_path, $phpEx; - - return new phpbb_extension_manager($this->get_db(), self::$config['table_prefix'] . 'ext', $phpbb_root_path, ".$phpEx", new phpbb_cache_driver_file); + $this->cache = ($this->cache instanceof phpbb_cache_driver_null) ? $this->cache : new phpbb_cache_driver_null; + return new phpbb_extension_manager($this->get_db(), self::$config['table_prefix'] . 'ext', $phpbb_root_path, ".$phpEx", $this->cache); } protected function install_board() From 1bbb32a5cffeff4875c4ed0566999cbee8919c86 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Sun, 18 Mar 2012 22:57:37 +0100 Subject: [PATCH 15/18] [ticket/10586] Correctly purge board cache and don't rename install directory PHPBB3-10586 --- tests/functional/browse_test.php | 11 ------ .../functional/extension_controller_test.php | 8 ++-- tests/functional/fixtures/ext/foobar/ext.php | 4 +- .../phpbb_functional_test_case.php | 37 +++++++++++++++++-- 4 files changed, 40 insertions(+), 20 deletions(-) diff --git a/tests/functional/browse_test.php b/tests/functional/browse_test.php index d119787d13..723cf93232 100644 --- a/tests/functional/browse_test.php +++ b/tests/functional/browse_test.php @@ -12,17 +12,6 @@ */ class phpbb_functional_browse_test extends phpbb_functional_test_case { - public static function setUpBeforeClass() - { - parent::setUpBeforeClass(); - $f_path = self::$config['phpbb_functional_path']; - // we cannot run these tests correctly if the install directory is present - if (is_dir($f_path . 'install/')) - { - rename($f_path . 'install/', $f_path . 'install_/'); - } - // NOTE: this will need to be renamed back again later if you wish to test again - } public function test_index() { $crawler = $this->request('GET', 'index.php'); diff --git a/tests/functional/extension_controller_test.php b/tests/functional/extension_controller_test.php index 4123853151..dd8aa1181b 100644 --- a/tests/functional/extension_controller_test.php +++ b/tests/functional/extension_controller_test.php @@ -69,8 +69,6 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c public static function tearDownAfterClass() { $f_path = self::$config['phpbb_functional_path']; - // first we rename the install_ directory back to install - rename($f_path . 'install_/', $f_path . 'install/'); // @todo delete the fixtures from the $f_path board // Note that it might be best to find a public domain function @@ -80,8 +78,10 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c public function setUp() { parent::setUp(); - $this->phpbb_extension_manager = !($this->phpbb_extension_manager instanceof phpbb_extension_manager) ? $this->get_ext_manager() : $this->phpbb_extension_manager; - $this->cache->purge('_ext'); + + $this->phpbb_extension_manager = $this->get_extension_manager(); + + $this->purge_cache(); } /** diff --git a/tests/functional/fixtures/ext/foobar/ext.php b/tests/functional/fixtures/ext/foobar/ext.php index 7b3f37cbfb..7cf443d369 100644 --- a/tests/functional/fixtures/ext/foobar/ext.php +++ b/tests/functional/fixtures/ext/foobar/ext.php @@ -1,6 +1,6 @@ db; } - protected function get_ext_manager() + protected function get_cache_driver() + { + if (!$this->cache) + { + $this->cache = new phpbb_cache_driver_file; + } + + return $this->cache; + } + + protected function purge_cache() + { + $cache = $this->get_cache_driver(); + + $cache->purge(); + $cache->unload(); + $cache->load(); + } + + protected function get_extension_manager() { global $phpbb_root_path, $phpEx; - $this->cache = ($this->cache instanceof phpbb_cache_driver_null) ? $this->cache : new phpbb_cache_driver_null; - return new phpbb_extension_manager($this->get_db(), self::$config['table_prefix'] . 'ext', $phpbb_root_path, ".$phpEx", $this->cache); + + if (!$this->extension_manager) + { + $this->extension_manager = new phpbb_extension_manager( + $this->get_db(), + self::$config['table_prefix'] . 'ext', + $phpbb_root_path, + ".$phpEx", + $this->get_cache_driver() + ); + } + + return $this->extension_manager; } protected function install_board() From 6a0bad8c0b7bdb261c0ee72b850bc727de6d019b Mon Sep 17 00:00:00 2001 From: David King Date: Mon, 19 Mar 2012 09:56:48 -0400 Subject: [PATCH 16/18] [ticket/10586] Tests finally work (thanks naderman) PHPBB3-10586 --- .../functional/extension_controller_test.php | 25 +++++++++---------- .../phpbb_test_case_helpers.php | 10 -------- 2 files changed, 12 insertions(+), 23 deletions(-) diff --git a/tests/functional/extension_controller_test.php b/tests/functional/extension_controller_test.php index dd8aa1181b..263d48c034 100644 --- a/tests/functional/extension_controller_test.php +++ b/tests/functional/extension_controller_test.php @@ -19,20 +19,20 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c */ static public function setUpBeforeClass() { + global $phpbb_root_path; parent::setUpBeforeClass(); - $f_path = self::$config['phpbb_functional_path']; // these directories need to be created before the files can be copied $directories = array( - $f_path . 'ext/error/class/', - $f_path . 'ext/error/classtype/', - $f_path . 'ext/error/disabled/', - $f_path . 'ext/foo/bar/', - $f_path . 'ext/foo/bar/styles/prosilver/template/', - $f_path . 'ext/foobar/', - $f_path . 'ext/foobar/styles/prosilver/template/', + $phpbb_root_path . 'ext/error/class/', + $phpbb_root_path . 'ext/error/classtype/', + $phpbb_root_path . 'ext/error/disabled/', + $phpbb_root_path . 'ext/foo/bar/', + $phpbb_root_path . 'ext/foo/bar/styles/prosilver/template/', + $phpbb_root_path . 'ext/foobar/', + $phpbb_root_path . 'ext/foobar/styles/prosilver/template/', ); - // When you add new tests that require new fixtures, add them to the array. + foreach ($directories as $dir) { if (!is_dir($dir)) @@ -58,8 +58,7 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c foreach ($fixtures as $fixture) { - // we have to use self::$config['phpbb_functional_url'] because $this->root_url is not available in static classes - if(!copy("tests/functional/fixtures/ext/$fixture", "{$f_path}ext/$fixture")) + if(!copy("tests/functional/fixtures/ext/$fixture", "{$phpbb_root_path}ext/$fixture")) { echo 'Could not copy file ' . $fixture; } @@ -68,9 +67,9 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c public static function tearDownAfterClass() { - $f_path = self::$config['phpbb_functional_path']; + $phpbb_root_path = self::$config['phpbb_functional_path']; - // @todo delete the fixtures from the $f_path board + // @todo delete the fixtures from the $phpbb_root_path board // Note that it might be best to find a public domain function // and port it into here instead of writing it from scratch } diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php index 4aec07a8fb..9c91778cb0 100644 --- a/tests/test_framework/phpbb_test_case_helpers.php +++ b/tests/test_framework/phpbb_test_case_helpers.php @@ -80,11 +80,6 @@ class phpbb_test_case_helpers { $config['phpbb_functional_url'] = $phpbb_functional_url; } - - if (!empty($phpbb_functional_path)) - { - $config['phpbb_functional_path'] = $phpbb_functional_path; - } } if (isset($_SERVER['PHPBB_TEST_DBMS'])) @@ -106,11 +101,6 @@ class phpbb_test_case_helpers )); } - if (!empty($_SERVER['PHPBB_FUNCTIONAL_PATH'])) - { - $config['phpbb_functional_path'] = $_SERVER['PHPBB_FUNCTIONAL_PATH']; - } - return $config; } } From 56f75dbf93b0476f88c866abcae129fa3b61fc2c Mon Sep 17 00:00:00 2001 From: David King Date: Tue, 27 Mar 2012 19:57:32 -0400 Subject: [PATCH 17/18] [ticket/10586] Tidy up comments PHPBB3-10586 --- phpBB/includes/extension/manager.php | 2 +- phpBB/index.php | 8 +------- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/phpBB/includes/extension/manager.php b/phpBB/includes/extension/manager.php index 6f1c885ea9..f103983fcd 100644 --- a/phpBB/includes/extension/manager.php +++ b/phpBB/includes/extension/manager.php @@ -432,7 +432,7 @@ class phpbb_extension_manager /** * Check to see if a given extension is available on the filesystem * - * @param string $name Extension name to check + * @param string $name Extension name to check NOTE: Can be user input * @return bool Depending on whether or not the extension is available */ public function available($name) diff --git a/phpBB/index.php b/phpBB/index.php index 2500774f67..d71878a885 100644 --- a/phpBB/index.php +++ b/phpBB/index.php @@ -24,14 +24,11 @@ $user->session_begin(); $auth->acl($user->data); $user->setup('viewforum'); -// If given an extension, look for a front controller +// Handle the display of extension front pages if ($ext = $request->variable('ext', '')) { - // The class to load $class = 'phpbb_ext_' . str_replace('/', '_', $ext) . '_controller'; - // Make sure the specified extension is enabled - // and that it has a controller class if (!$phpbb_extension_manager->available($ext)) { send_status_line(404, 'Not Found'); @@ -48,17 +45,14 @@ if ($ext = $request->variable('ext', '')) trigger_error($user->lang('EXTENSION_CONTROLLER_MISSING', $ext)); } - // Instantiate the extension controller $controller = new $class; - // But let's make sure it's actually a proper controller if (!($controller instanceof phpbb_extension_controller_interface)) { send_status_line(500, 'Internal Server Error'); trigger_error($user->lang('EXTENSION_CLASS_WRONG_TYPE', $class)); } - // Let's get it started... $controller->handle(); exit_handler(); } From 7c3ebcc3ff16950f76f857381222070c36a76fc3 Mon Sep 17 00:00:00 2001 From: David King Date: Wed, 28 Mar 2012 15:34:24 -0400 Subject: [PATCH 18/18] [ticket/10586] Added space in if statement PHPBB3-10586 --- tests/functional/extension_controller_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/functional/extension_controller_test.php b/tests/functional/extension_controller_test.php index 263d48c034..4ee0e68718 100644 --- a/tests/functional/extension_controller_test.php +++ b/tests/functional/extension_controller_test.php @@ -58,7 +58,7 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c foreach ($fixtures as $fixture) { - if(!copy("tests/functional/fixtures/ext/$fixture", "{$phpbb_root_path}ext/$fixture")) + if (!copy("tests/functional/fixtures/ext/$fixture", "{$phpbb_root_path}ext/$fixture")) { echo 'Could not copy file ' . $fixture; }