diff --git a/tests/test_framework/phpbb_ui_test_case.php b/tests/test_framework/phpbb_ui_test_case.php index c8ca2a9003..e3f636679c 100644 --- a/tests/test_framework/phpbb_ui_test_case.php +++ b/tests/test_framework/phpbb_ui_test_case.php @@ -32,7 +32,9 @@ class phpbb_ui_test_case extends phpbb_test_case static protected $root_url; static protected $already_installed = false; static protected $install_success = false; - static protected $db; + protected $cache = null; + protected $db = null; + protected $extension_manager = null; /** * Session ID for current test's session (each test makes its own) @@ -93,6 +95,14 @@ class phpbb_ui_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() { if (!self::$install_success) @@ -104,16 +114,35 @@ class phpbb_ui_test_case extends phpbb_test_case // that were added in other tests are gone $this->lang = array(); $this->add_lang('common'); + + $db = $this->get_db(); + + foreach (static::setup_extensions() as $extension) + { + $this->purge_cache(); + + $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 (self::$db instanceof \phpbb\db\driver\driver_interface) + if ($this->db instanceof \phpbb\db\driver\driver_interface) { // Close the database connections again this test - self::$db->sql_close(); + $this->db->sql_close(); } } @@ -139,14 +168,12 @@ class phpbb_ui_test_case extends phpbb_test_case $element->click(); } - static public function install_board() + static protected function install_board() { global $phpbb_root_path, $phpEx, $db; self::recreate_database(self::$config); - $db = self::get_db(); - $config_file = $phpbb_root_path . "config.$phpEx"; $config_file_dev = $phpbb_root_path . "config_dev.$phpEx"; $config_file_test = $phpbb_root_path . "config_test.$phpEx"; @@ -270,19 +297,112 @@ class phpbb_ui_test_case extends phpbb_test_case } } - static protected function get_db() + public function install_ext($extension) + { + $this->login(); + $this->admin_login(); + + $ext_path = str_replace('/', '%2F', $extension); + + $this->visit('adm/index.php?i=acp_extensions&mode=main&action=enable_pre&ext_name=' . $ext_path . '&sid=' . $this->sid); + $this->assertNotEmpty(count(self::find_element('cssSelector', '.submit-buttons'))); + + self::find_element('cssSelector', "input[value='Enable']")->submit(); + $this->add_lang('acp/extensions'); + + try + { + $meta_refresh = self::find_element('cssSelector', 'meta[http-equiv="refresh"]'); + + // Wait for extension to be fully enabled + while (sizeof($meta_refresh)) + { + preg_match('#url=.+/(adm+.+)#', $meta_refresh->getAttribute('content'), $match); + self::$webDriver->execute(array('method' => 'post', 'url' => $match[1])); + $meta_refresh = self::find_element('cssSelector', 'meta[http-equiv="refresh"]'); + } + } + catch (\Facebook\WebDriver\Exception\NoSuchElementException $e) + { + // Probably no refresh triggered + } + + $this->assertContainsLang('EXTENSION_ENABLE_SUCCESS', self::find_element('cssSelector', 'div.successbox')->getText()); + + $this->logout(); + } + + 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; + + $config = new \phpbb\config\config(array()); + $db = $this->get_db(); + $db_tools = new \phpbb\db\tools($db); + + $container = new phpbb_mock_container_builder(); + $migrator = new \phpbb\db\migrator( + $container, + $config, + $db, + $db_tools, + self::$config['table_prefix'] . 'migrations', + $phpbb_root_path, + $phpEx, + self::$config['table_prefix'], + array(), + new \phpbb\db\migration\helper() + ); + $container->set('migrator', $migrator); + $container->set('dispatcher', new phpbb_mock_event_dispatcher()); + $user = new \phpbb\user('\phpbb\datetime'); + + $extension_manager = new \phpbb\extension\manager( + $container, + $db, + $config, + new phpbb\filesystem(), + $user, + self::$config['table_prefix'] . 'ext', + dirname(__FILE__) . '/', + $phpEx, + $this->get_cache_driver() + ); + + return $extension_manager; + } + + protected function get_db() + { // so we don't reopen an open connection - if (!(self::$db instanceof \phpbb\db\driver\driver_interface)) + if (!($this->db instanceof \phpbb\db\driver\driver_interface)) { $dbms = self::$config['dbms']; /** @var \phpbb\db\driver\driver_interface $db */ $db = new $dbms(); $db->sql_connect(self::$config['dbhost'], self::$config['dbuser'], self::$config['dbpasswd'], self::$config['dbname'], self::$config['dbport']); - self::$db = $db; + $this->db = $db; } - return self::$db; + return $this->db; } protected function logout() @@ -430,6 +550,8 @@ class phpbb_ui_test_case extends phpbb_test_case { $this->add_lang('ucp'); + self::$webDriver->manage()->deleteAllCookies(); + $this->visit('ucp.php'); $this->assertContains($this->lang('LOGIN_EXPLAIN_UCP'), self::$webDriver->getPageSource());