From 597297b169e2ae14684ad1f40c8e083be22b241d Mon Sep 17 00:00:00 2001 From: Mate Bartus Date: Sun, 18 Oct 2015 22:47:04 +0200 Subject: [ticket/14044] Deduplicate the installers PHPBB3-14044 --- tests/test_framework/phpbb_ui_test_case.php | 159 +++++++++++++++------------- 1 file changed, 84 insertions(+), 75 deletions(-) (limited to 'tests/test_framework/phpbb_ui_test_case.php') diff --git a/tests/test_framework/phpbb_ui_test_case.php b/tests/test_framework/phpbb_ui_test_case.php index c8ac492e25..5da176e929 100644 --- a/tests/test_framework/phpbb_ui_test_case.php +++ b/tests/test_framework/phpbb_ui_test_case.php @@ -11,7 +11,7 @@ * */ -require_once __DIR__ . '/../../phpBB/includes/functions_install.php'; +require_once __DIR__ . '/mock/phpbb_mock_null_installer_task.php'; class phpbb_ui_test_case extends phpbb_test_case { @@ -118,87 +118,96 @@ class phpbb_ui_test_case extends phpbb_test_case } } + $container_builder = new \phpbb\di\container_builder($phpbb_root_path, $phpEx); + $container = $container_builder + ->with_environment('installer') + ->without_extensions() + ->without_cache() + ->with_custom_parameters([ + 'core.disable_super_globals' => false, + 'installer.create_config_file.options' => [ + 'debug' => true, + 'environment' => 'test', + ] + ]) + ->without_compiled_container() + ->get_container(); + + $container->register('installer.install_finish.notify_user')->setSynthetic(true); + $container->set('installer.install_finish.notify_user', new phpbb_mock_null_installer_task()); + $container->compile(); + + $language = $container->get('language'); + $language->add_lang(array('common', 'acp/common', 'acp/board', 'install', 'posting')); + + $iohandler_factory = $container->get('installer.helper.iohandler_factory'); + $iohandler_factory->set_environment('cli'); + $iohandler = $iohandler_factory->get(); + $parseURL = parse_url(self::$config['phpbb_functional_url']); - self::visit('install/index.php?mode=install&language=en'); - self::assertContains('Welcome to Installation', self::find_element('id', 'main')->getText()); - - // install/index.php?mode=install&sub=requirements - self::submit(); - self::assertContains('Installation compatibility', self::find_element('id', 'main')->getText()); - - // install/index.php?mode=install&sub=database - self::submit(); - self::assertContains('Database configuration', self::find_element('id', 'main')->getText()); - - self::find_element('id','dbms')->sendKeys(str_replace('phpbb\db\driver\\', '', self::$config['dbms'])); - self::find_element('id','dbhost')->sendKeys(self::$config['dbhost']); - self::find_element('id','dbport')->sendKeys(self::$config['dbport']); - self::find_element('id','dbname')->sendKeys(self::$config['dbname']); - self::find_element('id','dbuser')->sendKeys(self::$config['dbuser']); - self::find_element('id','dbpasswd')->sendKeys(self::$config['dbpasswd']); - - // Need to clear default phpbb_ prefix - self::find_element('id','table_prefix')->clear(); - self::find_element('id','table_prefix')->sendKeys(self::$config['table_prefix']); - - // install/index.php?mode=install&sub=database - self::submit(); - self::assertContains('Successful connection', self::find_element('id','main')->getText()); - - // install/index.php?mode=install&sub=administrator - self::submit(); - self::assertContains('Administrator configuration', self::find_element('id','main')->getText()); - - self::find_element('id','admin_name')->sendKeys('admin'); - self::find_element('id','admin_pass1')->sendKeys('adminadmin'); - self::find_element('id','admin_pass2')->sendKeys('adminadmin'); - self::find_element('id','board_email')->sendKeys('nobody@example.com'); - - // install/index.php?mode=install&sub=administrator - self::submit(); - self::assertContains('Tests passed', self::find_element('id','main')->getText()); - - // install/index.php?mode=install&sub=config_file - self::submit(); - - // Installer has created a config.php file, we will overwrite it with a - // config file of our own in order to get the DEBUG constants defined - $config_php_data = phpbb_create_config_file_data(self::$config, self::$config['dbms'], true, false, true); - $config_created = file_put_contents($config_file, $config_php_data) !== false; - if (!$config_created) + $output = new \Symfony\Component\Console\Output\NullOutput(); + $style = new \Symfony\Component\Console\Style\SymfonyStyle( + new \Symfony\Component\Console\Input\ArrayInput(array()), + $output + ); + $iohandler->set_style($style, $output); + + $installer = $container->get('installer.installer.install'); + $installer->set_iohandler($iohandler); + + // Set data + $iohandler->set_input('admin_name', 'admin'); + $iohandler->set_input('admin_pass1', 'adminadmin'); + $iohandler->set_input('admin_pass2', 'adminadmin'); + $iohandler->set_input('board_email', 'nobody@example.com'); + $iohandler->set_input('submit_admin', 'submit'); + + $iohandler->set_input('default_lang', 'en'); + $iohandler->set_input('board_name', 'yourdomain.com'); + $iohandler->set_input('board_description', 'A short text to describe your forum'); + $iohandler->set_input('submit_board', 'submit'); + + $iohandler->set_input('dbms', str_replace('phpbb\db\driver\\', '', self::$config['dbms'])); + $iohandler->set_input('dbhost', self::$config['dbhost']); + $iohandler->set_input('dbport', self::$config['dbport']); + $iohandler->set_input('dbuser', self::$config['dbuser']); + $iohandler->set_input('dbpasswd', self::$config['dbpasswd']); + $iohandler->set_input('dbname', self::$config['dbname']); + $iohandler->set_input('table_prefix', self::$config['table_prefix']); + $iohandler->set_input('submit_database', 'submit'); + + $iohandler->set_input('email_enable', true); + $iohandler->set_input('smtp_delivery', '1'); + $iohandler->set_input('smtp_host', 'nxdomain.phpbb.com'); + $iohandler->set_input('smtp_auth', 'PLAIN'); + $iohandler->set_input('smtp_user', 'nxuser'); + $iohandler->set_input('smtp_pass', 'nxpass'); + $iohandler->set_input('submit_email', 'submit'); + + $iohandler->set_input('cookie_secure', '0'); + $iohandler->set_input('server_protocol', '0'); + $iohandler->set_input('force_server_vars', $parseURL['scheme'] . '://'); + $iohandler->set_input('server_name', $parseURL['host']); + $iohandler->set_input('server_port', isset($parseURL['port']) ? (int) $parseURL['port'] : 80); + $iohandler->set_input('script_path', $parseURL['path']); + $iohandler->set_input('submit_server', 'submit'); + + do { - self::markTestSkipped("Could not write $config_file file."); + $installer->run(); } + while (file_exists($phpbb_root_path . 'store/install_config.php')); + + copy($config_file, $config_file_test); - if (strpos(self::find_element('id','main')->getText(), 'The configuration file has been written') === false) + if (file_exists($phpbb_root_path . 'cache/install_lock')) { - self::submit('id', 'dldone'); + unlink($phpbb_root_path . 'cache/install_lock'); } - self::assertContains('The configuration file has been written', self::find_element('id','main')->getText()); - - // install/index.php?mode=install&sub=advanced - self::submit(); - self::assertContains('The settings on this page are only necessary to set if you know that you require something different from the default.', self::find_element('id','main')->getText()); - - self::find_element('id','smtp_delivery')->sendKeys('1'); - self::find_element('id','smtp_host')->sendKeys('nxdomain.phpbb.com'); - self::find_element('id','smtp_user')->sendKeys('nxuser'); - self::find_element('id','smtp_pass')->sendKeys('nxpass'); - self::find_element('id','server_protocol')->sendKeys($parseURL['scheme'] . '://'); - self::find_element('id','server_name')->sendKeys('localhost'); - self::find_element('id','server_port')->sendKeys(isset($parseURL['port']) ? $parseURL['port'] : 80); - self::find_element('id','script_path')->sendKeys($parseURL['path']); - - // install/index.php?mode=install&sub=create_table - self::submit(); - self::assertContains('The database tables used by phpBB', self::find_element('id','main')->getText()); - self::assertContains('have been created and populated with some initial data.', self::find_element('id','main')->getText()); - - // install/index.php?mode=install&sub=final - self::submit(); - self::assertContains('You have successfully installed', self::find_element('id', 'main')->getText()); - copy($config_file, $config_file_test); + global $phpbb_container, $cache, $phpbb_dispatcher, $request, $user, $auth, $db, $config, $phpbb_log, $symfony_request, $phpbb_filesystem, $phpbb_path_helper, $phpbb_extension_manager, $template; + $phpbb_container->reset(); + unset($phpbb_container, $cache, $phpbb_dispatcher, $request, $user, $auth, $db, $config, $phpbb_log, $symfony_request, $phpbb_filesystem, $phpbb_path_helper, $phpbb_extension_manager, $template); } } -- cgit v1.2.1 From 8d178f15f06e0f6b5e64447dc07157a796645572 Mon Sep 17 00:00:00 2001 From: Mate Bartus Date: Wed, 4 Nov 2015 17:25:38 +0100 Subject: [ticket/14270] Purge cache when the installer is finished PHPBB3-14270 --- tests/test_framework/phpbb_ui_test_case.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'tests/test_framework/phpbb_ui_test_case.php') diff --git a/tests/test_framework/phpbb_ui_test_case.php b/tests/test_framework/phpbb_ui_test_case.php index 5da176e929..e118801972 100644 --- a/tests/test_framework/phpbb_ui_test_case.php +++ b/tests/test_framework/phpbb_ui_test_case.php @@ -128,7 +128,8 @@ class phpbb_ui_test_case extends phpbb_test_case 'installer.create_config_file.options' => [ 'debug' => true, 'environment' => 'test', - ] + ], + 'cache.driver.class' => 'phpbb\cache\driver\file' ]) ->without_compiled_container() ->get_container(); -- cgit v1.2.1 From d63b5a1315ecf819a412db382c1adcfa39fd9813 Mon Sep 17 00:00:00 2001 From: Mate Bartus Date: Fri, 12 Feb 2016 14:26:32 +0100 Subject: [ticket/14462] Fix installation in tests PHPBB3-14462 --- tests/test_framework/phpbb_ui_test_case.php | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'tests/test_framework/phpbb_ui_test_case.php') diff --git a/tests/test_framework/phpbb_ui_test_case.php b/tests/test_framework/phpbb_ui_test_case.php index e118801972..59f3bdf242 100644 --- a/tests/test_framework/phpbb_ui_test_case.php +++ b/tests/test_framework/phpbb_ui_test_case.php @@ -26,6 +26,7 @@ class phpbb_ui_test_case extends phpbb_test_case static protected $config; static protected $root_url; static protected $already_installed = false; + static protected $install_success = false; static public function setUpBeforeClass() { @@ -74,6 +75,14 @@ class phpbb_ui_test_case extends phpbb_test_case } } + public function setUp() + { + if (!self::$install_success) + { + $this->fail('Installing phpBB has failed.'); + } + } + static public function visit($path) { self::$webDriver->get(self::$root_url . $path); @@ -194,17 +203,17 @@ class phpbb_ui_test_case extends phpbb_test_case $iohandler->set_input('script_path', $parseURL['path']); $iohandler->set_input('submit_server', 'submit'); - do - { - $installer->run(); - } - while (file_exists($phpbb_root_path . 'store/install_config.php')); + $installer->run(); copy($config_file, $config_file_test); - if (file_exists($phpbb_root_path . 'cache/install_lock')) + self::$install_success = true; + + if (file_exists($phpbb_root_path . 'cache/install_lock') || file_exists($phpbb_root_path . 'store/install_config.php')) { + self::$install_success = false; unlink($phpbb_root_path . 'cache/install_lock'); + unlink($phpbb_root_path . 'store/install_config.php'); } global $phpbb_container, $cache, $phpbb_dispatcher, $request, $user, $auth, $db, $config, $phpbb_log, $symfony_request, $phpbb_filesystem, $phpbb_path_helper, $phpbb_extension_manager, $template; -- cgit v1.2.1 From 90710ffe9818fb45d177db4a8b07c70a43972776 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 12 Feb 2016 14:08:47 +0100 Subject: [ticket/14462] Set instance of db driver for database access using global PHPBB3-14462 --- tests/test_framework/phpbb_ui_test_case.php | 31 ++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'tests/test_framework/phpbb_ui_test_case.php') diff --git a/tests/test_framework/phpbb_ui_test_case.php b/tests/test_framework/phpbb_ui_test_case.php index 59f3bdf242..14e84b019d 100644 --- a/tests/test_framework/phpbb_ui_test_case.php +++ b/tests/test_framework/phpbb_ui_test_case.php @@ -27,6 +27,7 @@ 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; static public function setUpBeforeClass() { @@ -83,6 +84,17 @@ class phpbb_ui_test_case extends phpbb_test_case } } + protected function tearDown() + { + parent::tearDown(); + + if (self::$db instanceof \phpbb\db\driver\driver_interface) + { + // Close the database connections again this test + self::$db->sql_close(); + } + } + static public function visit($path) { self::$webDriver->get(self::$root_url . $path); @@ -107,10 +119,12 @@ class phpbb_ui_test_case extends phpbb_test_case static public function install_board() { - global $phpbb_root_path, $phpEx; + 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"; @@ -220,4 +234,19 @@ class phpbb_ui_test_case extends phpbb_test_case $phpbb_container->reset(); unset($phpbb_container, $cache, $phpbb_dispatcher, $request, $user, $auth, $db, $config, $phpbb_log, $symfony_request, $phpbb_filesystem, $phpbb_path_helper, $phpbb_extension_manager, $template); } + + static protected function get_db() + { + global $phpbb_root_path, $phpEx; + // so we don't reopen an open connection + if (!(self::$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; + } + return self::$db; + } } -- cgit v1.2.1 From 7c0fb563ec995d0d1fcb24d885a7d9d18838ed9c Mon Sep 17 00:00:00 2001 From: Mate Bartus Date: Fri, 12 Feb 2016 15:38:34 +0100 Subject: [ticket/14462] Fix CS and typo PHPBB3-14462 --- tests/test_framework/phpbb_ui_test_case.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/test_framework/phpbb_ui_test_case.php') diff --git a/tests/test_framework/phpbb_ui_test_case.php b/tests/test_framework/phpbb_ui_test_case.php index 14e84b019d..9cbac0ce47 100644 --- a/tests/test_framework/phpbb_ui_test_case.php +++ b/tests/test_framework/phpbb_ui_test_case.php @@ -94,7 +94,7 @@ class phpbb_ui_test_case extends phpbb_test_case self::$db->sql_close(); } } - + static public function visit($path) { self::$webDriver->get(self::$root_url . $path); -- cgit v1.2.1 From 97d128a7e4702b5a28b223b177a0e182e3b79080 Mon Sep 17 00:00:00 2001 From: Mate Bartus Date: Fri, 12 Feb 2016 15:53:36 +0100 Subject: [ticket/14462] Fix tests PHPBB3-14462 --- tests/test_framework/phpbb_ui_test_case.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'tests/test_framework/phpbb_ui_test_case.php') diff --git a/tests/test_framework/phpbb_ui_test_case.php b/tests/test_framework/phpbb_ui_test_case.php index 9cbac0ce47..3aec2a19f4 100644 --- a/tests/test_framework/phpbb_ui_test_case.php +++ b/tests/test_framework/phpbb_ui_test_case.php @@ -223,11 +223,15 @@ class phpbb_ui_test_case extends phpbb_test_case self::$install_success = true; - if (file_exists($phpbb_root_path . 'cache/install_lock') || file_exists($phpbb_root_path . 'store/install_config.php')) + if (file_exists($phpbb_root_path . 'store/install_config.php')) { self::$install_success = false; - unlink($phpbb_root_path . 'cache/install_lock'); - unlink($phpbb_root_path . 'store/install_config.php'); + @unlink($phpbb_root_path . 'store/install_config.php'); + } + + if (file_exists($phpbb_root_path . 'cache/install_lock')) + { + @unlink($phpbb_root_path . 'cache/install_lock'); } global $phpbb_container, $cache, $phpbb_dispatcher, $request, $user, $auth, $db, $config, $phpbb_log, $symfony_request, $phpbb_filesystem, $phpbb_path_helper, $phpbb_extension_manager, $template; -- cgit v1.2.1 From d330ef8c1b52bb93e02de3992edb9041f2c99fb5 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 14 Feb 2016 16:24:00 +0100 Subject: [ticket/14478] Move facebook/webdriver dependency to main composer file Also updated to latest version and now using proper version in composer.json. PHPBB3-14478 --- tests/test_framework/phpbb_ui_test_case.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'tests/test_framework/phpbb_ui_test_case.php') diff --git a/tests/test_framework/phpbb_ui_test_case.php b/tests/test_framework/phpbb_ui_test_case.php index e118801972..3c09ff96d1 100644 --- a/tests/test_framework/phpbb_ui_test_case.php +++ b/tests/test_framework/phpbb_ui_test_case.php @@ -11,6 +11,11 @@ * */ +use Facebook\WebDriver\WebDriverBy; +use Facebook\WebDriver\Exception\WebDriverCurlException; +use Facebook\WebDriver\Remote\RemoteWebDriver; +use Facebook\WebDriver\Remote\DesiredCapabilities; + require_once __DIR__ . '/mock/phpbb_mock_null_installer_task.php'; class phpbb_ui_test_case extends phpbb_test_case @@ -19,7 +24,7 @@ class phpbb_ui_test_case extends phpbb_test_case static protected $port = 8910; /** - * @var \RemoteWebDriver + * @var RemoteWebDriver */ static protected $webDriver; @@ -35,7 +40,7 @@ class phpbb_ui_test_case extends phpbb_test_case { self::markTestSkipped('UI test case requires at least PHP 5.3.19.'); } - else if (!class_exists('\RemoteWebDriver')) + else if (!class_exists('\Facebook\WebDriver\Remote\RemoteWebDriver')) { self::markTestSkipped( 'Could not find RemoteWebDriver class. ' . @@ -60,7 +65,7 @@ class phpbb_ui_test_case extends phpbb_test_case if (!self::$webDriver) { try { - $capabilities = array(\WebDriverCapabilityType::BROWSER_NAME => 'firefox'); + $capabilities = DesiredCapabilities::firefox(); self::$webDriver = RemoteWebDriver::create(self::$host . ':' . self::$port, $capabilities); } catch (WebDriverCurlException $e) { self::markTestSkipped('PhantomJS webserver is not running.'); -- cgit v1.2.1 From 845639ba371e0aacb60f760851c9c6b1cf6e9bd6 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 16 Feb 2016 22:45:31 +0100 Subject: [ticket/14315] Add more functionality to ui test cases PHPBB3-14315 --- tests/test_framework/phpbb_ui_test_case.php | 208 ++++++++++++++++++++++++++++ 1 file changed, 208 insertions(+) (limited to 'tests/test_framework/phpbb_ui_test_case.php') diff --git a/tests/test_framework/phpbb_ui_test_case.php b/tests/test_framework/phpbb_ui_test_case.php index 8b60096081..f9f4c516e6 100644 --- a/tests/test_framework/phpbb_ui_test_case.php +++ b/tests/test_framework/phpbb_ui_test_case.php @@ -34,6 +34,18 @@ class phpbb_ui_test_case extends phpbb_test_case static protected $install_success = false; static protected $db; + /** + * Session ID for current test's session (each test makes its own) + * @var string + */ + protected $sid; + + /** + * Language array used by phpBB + * @var array + */ + protected $lang = array(); + static public function setUpBeforeClass() { parent::setUpBeforeClass(); @@ -87,6 +99,11 @@ class phpbb_ui_test_case extends phpbb_test_case { $this->fail('Installing phpBB has failed.'); } + + // Clear the language array so that things + // that were added in other tests are gone + $this->lang = array(); + $this->add_lang('common'); } protected function tearDown() @@ -258,4 +275,195 @@ class phpbb_ui_test_case extends phpbb_test_case } return self::$db; } + + /** + * Login to the ACP + * You must run login() before calling this. + */ + protected function admin_login($username = 'admin') + { + $this->add_lang('acp/common'); + + // Requires login first! + if (empty($this->sid)) + { + $this->fail('$this->sid is empty. Make sure you call login() before admin_login()'); + return; + } + + $this->visit('adm/index.php?sid=' . $this->sid); + $this->assertContains($this->lang('LOGIN_ADMIN_CONFIRM'), self::$webDriver->getPageSource()); + + self::find_element('cssSelector', 'input[name=username]')->clear()->sendKeys($username); + self::find_element('cssSelector', 'input[type=password]')->sendKeys($username . $username); + self::find_element('cssSelector', 'input[name=login]')->click(); + $this->assertContains($this->lang('ADMIN_PANEL'), $this->find_element('cssSelector', 'h1')->getText()); + + $cookies = self::$webDriver->manage()->getCookies(); + + // The session id is stored in a cookie that ends with _sid - we assume there is only one such cookie + foreach ($cookies as $cookie) + { + if (substr($cookie['name'], -4) == '_sid') + { + $this->sid = $cookie['value']; + } + } + } + + protected function add_lang($lang_file) + { + if (is_array($lang_file)) + { + foreach ($lang_file as $file) + { + $this->add_lang($file); + } + } + + $lang_path = __DIR__ . "/../../phpBB/language/en/$lang_file.php"; + + $lang = array(); + + if (file_exists($lang_path)) + { + include($lang_path); + } + + $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(); + $key = $args[0]; + + if (empty($this->lang[$key])) + { + throw new RuntimeException('Language key "' . $key . '" could not be found.'); + } + + $args[0] = $this->lang[$key]; + + return call_user_func_array('sprintf', $args); + } + + /** + * assertContains for language strings + * + * @param string $needle Search string + * @param string $haystack Search this + * @param string $message Optional failure message + */ + public function assertContainsLang($needle, $haystack, $message = null) + { + $this->assertContains(html_entity_decode($this->lang($needle), ENT_QUOTES), $haystack, $message); + } + + /** + * assertNotContains for language strings + * + * @param string $needle Search string + * @param string $haystack Search this + * @param string $message Optional failure message + */ + public function assertNotContainsLang($needle, $haystack, $message = null) + { + $this->assertNotContains(html_entity_decode($this->lang($needle), ENT_QUOTES), $haystack, $message); + } + + protected function login($username = 'admin') + { + $this->add_lang('ucp'); + + $this->visit('ucp.php'); + $this->assertContains($this->lang('LOGIN_EXPLAIN_UCP'), self::$webDriver->getPageSource()); + + self::find_element('cssSelector', 'input[name=username]')->sendKeys($username); + self::find_element('cssSelector', 'input[name=password]')->sendKeys($username . $username); + self::find_element('cssSelector', 'input[name=login]')->click(); + $this->assertNotContains($this->lang('LOGIN'), $this->find_element('className', 'navbar')->getText()); + + $cookies = self::$webDriver->manage()->getCookies(); + + // The session id is stored in a cookie that ends with _sid - we assume there is only one such cookie + foreach ($cookies as $cookie) + { + if (substr($cookie['name'], -4) == '_sid') + { + $this->sid = $cookie['value']; + } + } + } + + /** + * Take screenshot. Can be used for debug purposes. + * + * @param \Facebook\WebDriver\Remote\RemoteWebElement $element + * @return string Element screenshot path + * @throws Exception When screenshot can't be created + */ + public function takeScreenshot($element = null) { + // Change the Path to your own settings + $screenshot = time() . ".png"; + + // Change the driver instance + self::$webDriver->takeScreenshot($screenshot); + if(!file_exists($screenshot)) { + throw new Exception('Could not save screenshot'); + } + + if( ! (bool) $element) { + return $screenshot; + } + + $element_screenshot = time() . ".png"; // Change the path here as well + + $element_width = $element->getSize()->getWidth(); + $element_height = $element->getSize()->getHeight(); + + $element_src_x = $element->getLocation()->getX(); + $element_src_y = $element->getLocation()->getY(); + + // Create image instances + $src = imagecreatefrompng($screenshot); + $dest = imagecreatetruecolor($element_width, $element_height); + + // Copy + imagecopy($dest, $src, 0, 0, $element_src_x, $element_src_y, $element_width, $element_height); + + imagepng($dest, $element_screenshot); + + // unlink($screenshot); // unlink function might be restricted in mac os x. + + if( ! file_exists($element_screenshot)) { + throw new Exception('Could not save element screenshot'); + } + + return $element_screenshot; + } } -- cgit v1.2.1 From a75885bd85d57401904055366c18733ac84b323a Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Wed, 17 Feb 2016 13:26:35 +0100 Subject: [ticket/14315] Add logout to ui tests and use in permissions role test PHPBB3-14315 --- tests/test_framework/phpbb_ui_test_case.php | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'tests/test_framework/phpbb_ui_test_case.php') diff --git a/tests/test_framework/phpbb_ui_test_case.php b/tests/test_framework/phpbb_ui_test_case.php index f9f4c516e6..7e87b63b97 100644 --- a/tests/test_framework/phpbb_ui_test_case.php +++ b/tests/test_framework/phpbb_ui_test_case.php @@ -276,6 +276,16 @@ class phpbb_ui_test_case extends phpbb_test_case return self::$db; } + protected function logout() + { + $this->add_lang('ucp'); + + $this->visit('ucp.php?sid=' . $this->sid . '&mode=logout'); + $this->assertContains($this->lang('REGISTER'), self::$webDriver->getPageSource()); + unset($this->sid); + + } + /** * Login to the ACP * You must run login() before calling this. -- cgit v1.2.1 From 7d41fe01362d7752ca64981791b56b5133d39848 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Wed, 17 Feb 2016 14:11:27 +0100 Subject: [ticket/14315] Properly get sid from cookies and simplify take_screenshot PHPBB3-14315 --- tests/test_framework/phpbb_ui_test_case.php | 51 +++++++++-------------------- 1 file changed, 15 insertions(+), 36 deletions(-) (limited to 'tests/test_framework/phpbb_ui_test_case.php') diff --git a/tests/test_framework/phpbb_ui_test_case.php b/tests/test_framework/phpbb_ui_test_case.php index 7e87b63b97..9bb89781a1 100644 --- a/tests/test_framework/phpbb_ui_test_case.php +++ b/tests/test_framework/phpbb_ui_test_case.php @@ -280,6 +280,11 @@ class phpbb_ui_test_case extends phpbb_test_case { $this->add_lang('ucp'); + if (empty($this->sid)) + { + return; + } + $this->visit('ucp.php?sid=' . $this->sid . '&mode=logout'); $this->assertContains($this->lang('REGISTER'), self::$webDriver->getPageSource()); unset($this->sid); @@ -301,6 +306,8 @@ class phpbb_ui_test_case extends phpbb_test_case return; } + self::$webDriver->manage()->deleteAllCookies(); + $this->visit('adm/index.php?sid=' . $this->sid); $this->assertContains($this->lang('LOGIN_ADMIN_CONFIRM'), self::$webDriver->getPageSource()); @@ -317,8 +324,12 @@ class phpbb_ui_test_case extends phpbb_test_case if (substr($cookie['name'], -4) == '_sid') { $this->sid = $cookie['value']; + + break; } } + + $this->assertNotEmpty($this->sid); } protected function add_lang($lang_file) @@ -428,52 +439,20 @@ class phpbb_ui_test_case extends phpbb_test_case $this->sid = $cookie['value']; } } + + $this->assertNotEmpty($this->sid); } /** * Take screenshot. Can be used for debug purposes. * - * @param \Facebook\WebDriver\Remote\RemoteWebElement $element - * @return string Element screenshot path * @throws Exception When screenshot can't be created */ - public function takeScreenshot($element = null) { + public function take_screenshot() + { // Change the Path to your own settings $screenshot = time() . ".png"; - // Change the driver instance self::$webDriver->takeScreenshot($screenshot); - if(!file_exists($screenshot)) { - throw new Exception('Could not save screenshot'); - } - - if( ! (bool) $element) { - return $screenshot; - } - - $element_screenshot = time() . ".png"; // Change the path here as well - - $element_width = $element->getSize()->getWidth(); - $element_height = $element->getSize()->getHeight(); - - $element_src_x = $element->getLocation()->getX(); - $element_src_y = $element->getLocation()->getY(); - - // Create image instances - $src = imagecreatefrompng($screenshot); - $dest = imagecreatetruecolor($element_width, $element_height); - - // Copy - imagecopy($dest, $src, 0, 0, $element_src_x, $element_src_y, $element_width, $element_height); - - imagepng($dest, $element_screenshot); - - // unlink($screenshot); // unlink function might be restricted in mac os x. - - if( ! file_exists($element_screenshot)) { - throw new Exception('Could not save element screenshot'); - } - - return $element_screenshot; } } -- cgit v1.2.1 From ae221602438b832968d307eba8baea4ce6358439 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 18 Feb 2016 23:53:40 +0100 Subject: [ticket/14488] Delete cookies to get correct session ID during login PHPBB3-14488 --- tests/test_framework/phpbb_ui_test_case.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests/test_framework/phpbb_ui_test_case.php') diff --git a/tests/test_framework/phpbb_ui_test_case.php b/tests/test_framework/phpbb_ui_test_case.php index 9bb89781a1..b5ac3a576b 100644 --- a/tests/test_framework/phpbb_ui_test_case.php +++ b/tests/test_framework/phpbb_ui_test_case.php @@ -424,6 +424,8 @@ class phpbb_ui_test_case extends phpbb_test_case $this->visit('ucp.php'); $this->assertContains($this->lang('LOGIN_EXPLAIN_UCP'), self::$webDriver->getPageSource()); + self::$webDriver->manage()->deleteAllCookies(); + self::find_element('cssSelector', 'input[name=username]')->sendKeys($username); self::find_element('cssSelector', 'input[name=password]')->sendKeys($username . $username); self::find_element('cssSelector', 'input[name=login]')->click(); -- cgit v1.2.1 From 6d2acb5ba3fbd22b345b312e704021eab1375941 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Thu, 24 Mar 2016 13:01:52 +0100 Subject: [ticket/13616] Fix UI tests PHPBB3-13616 --- tests/test_framework/phpbb_ui_test_case.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'tests/test_framework/phpbb_ui_test_case.php') diff --git a/tests/test_framework/phpbb_ui_test_case.php b/tests/test_framework/phpbb_ui_test_case.php index b5ac3a576b..e79c78db29 100644 --- a/tests/test_framework/phpbb_ui_test_case.php +++ b/tests/test_framework/phpbb_ui_test_case.php @@ -256,9 +256,17 @@ class phpbb_ui_test_case extends phpbb_test_case @unlink($phpbb_root_path . 'cache/install_lock'); } - global $phpbb_container, $cache, $phpbb_dispatcher, $request, $user, $auth, $db, $config, $phpbb_log, $symfony_request, $phpbb_filesystem, $phpbb_path_helper, $phpbb_extension_manager, $template; + global $phpbb_container; $phpbb_container->reset(); - unset($phpbb_container, $cache, $phpbb_dispatcher, $request, $user, $auth, $db, $config, $phpbb_log, $symfony_request, $phpbb_filesystem, $phpbb_path_helper, $phpbb_extension_manager, $template); + + $blacklist = ['phpbb_class_loader_mock', 'phpbb_class_loader_ext', 'phpbb_class_loader']; + + foreach (array_keys($GLOBALS) as $key) { + if (is_object($GLOBALS[$key]) && !in_array($key, $blacklist, true)) + { + unset($GLOBALS[$key]); + } + } } static protected function get_db() -- cgit v1.2.1 From 5754cbfec445919dd8b7f261de33d75cbdc78fdd Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Sun, 3 Apr 2016 16:14:50 +0200 Subject: [ticket/13616] Fix CS + constant in the core extension PHPBB3-13616 --- tests/test_framework/phpbb_ui_test_case.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'tests/test_framework/phpbb_ui_test_case.php') diff --git a/tests/test_framework/phpbb_ui_test_case.php b/tests/test_framework/phpbb_ui_test_case.php index e79c78db29..c8ca2a9003 100644 --- a/tests/test_framework/phpbb_ui_test_case.php +++ b/tests/test_framework/phpbb_ui_test_case.php @@ -261,7 +261,8 @@ class phpbb_ui_test_case extends phpbb_test_case $blacklist = ['phpbb_class_loader_mock', 'phpbb_class_loader_ext', 'phpbb_class_loader']; - foreach (array_keys($GLOBALS) as $key) { + foreach (array_keys($GLOBALS) as $key) + { if (is_object($GLOBALS[$key]) && !in_array($key, $blacklist, true)) { unset($GLOBALS[$key]); -- cgit v1.2.1 From 6242698a84dfc00bc5a09705eeed2db1a539996c Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 18 Sep 2016 21:52:11 +0200 Subject: [ticket/14484] Remove invalid code caused by merge conflict PHPBB3-14484 --- tests/test_framework/phpbb_ui_test_case.php | 4 ---- 1 file changed, 4 deletions(-) (limited to 'tests/test_framework/phpbb_ui_test_case.php') diff --git a/tests/test_framework/phpbb_ui_test_case.php b/tests/test_framework/phpbb_ui_test_case.php index bc761aff69..1d6dda0ba6 100644 --- a/tests/test_framework/phpbb_ui_test_case.php +++ b/tests/test_framework/phpbb_ui_test_case.php @@ -340,10 +340,6 @@ class phpbb_ui_test_case extends phpbb_test_case $this->assertContains($this->lang('ADMIN_PANEL'), $this->find_element('cssSelector', 'h1')->getText()); $cookies = self::$webDriver->manage()->getCookies(); - - copy($config_file, $config_file_test); - - self::$install_success = true; } public function install_ext($extension) -- cgit v1.2.1 From 2b22adbcacf469998b2490073c29a6188125f94d Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Wed, 21 Sep 2016 21:09:55 +0200 Subject: [ticket/14484] Remove duplicate methods and no longer needed calls PHPBB3-14484 --- tests/test_framework/phpbb_ui_test_case.php | 101 +++++++++++++++------------- 1 file changed, 56 insertions(+), 45 deletions(-) (limited to 'tests/test_framework/phpbb_ui_test_case.php') diff --git a/tests/test_framework/phpbb_ui_test_case.php b/tests/test_framework/phpbb_ui_test_case.php index 1d6dda0ba6..e3f636679c 100644 --- a/tests/test_framework/phpbb_ui_test_case.php +++ b/tests/test_framework/phpbb_ui_test_case.php @@ -174,8 +174,6 @@ class phpbb_ui_test_case extends phpbb_test_case 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"; @@ -299,49 +297,6 @@ class phpbb_ui_test_case extends phpbb_test_case } } - protected function logout() - { - $this->add_lang('ucp'); - - if (empty($this->sid)) - { - return; - } - - $this->visit('ucp.php?sid=' . $this->sid . '&mode=logout'); - $this->assertContains($this->lang('REGISTER'), self::$webDriver->getPageSource()); - unset($this->sid); - - } - - /** - * Login to the ACP - * You must run login() before calling this. - */ - protected function admin_login($username = 'admin') - { - $this->add_lang('acp/common'); - - // Requires login first! - if (empty($this->sid)) - { - $this->fail('$this->sid is empty. Make sure you call login() before admin_login()'); - return; - } - - self::$webDriver->manage()->deleteAllCookies(); - - $this->visit('adm/index.php?sid=' . $this->sid); - $this->assertContains($this->lang('LOGIN_ADMIN_CONFIRM'), self::$webDriver->getPageSource()); - - self::find_element('cssSelector', 'input[name=username]')->clear()->sendKeys($username); - self::find_element('cssSelector', 'input[type=password]')->sendKeys($username . $username); - self::find_element('cssSelector', 'input[name=login]')->click(); - $this->assertContains($this->lang('ADMIN_PANEL'), $this->find_element('cssSelector', 'h1')->getText()); - - $cookies = self::$webDriver->manage()->getCookies(); - } - public function install_ext($extension) { $this->login(); @@ -450,6 +405,62 @@ class phpbb_ui_test_case extends phpbb_test_case return $this->db; } + protected function logout() + { + $this->add_lang('ucp'); + + if (empty($this->sid)) + { + return; + } + + $this->visit('ucp.php?sid=' . $this->sid . '&mode=logout'); + $this->assertContains($this->lang('REGISTER'), self::$webDriver->getPageSource()); + unset($this->sid); + + } + + /** + * Login to the ACP + * You must run login() before calling this. + */ + protected function admin_login($username = 'admin') + { + $this->add_lang('acp/common'); + + // Requires login first! + if (empty($this->sid)) + { + $this->fail('$this->sid is empty. Make sure you call login() before admin_login()'); + return; + } + + self::$webDriver->manage()->deleteAllCookies(); + + $this->visit('adm/index.php?sid=' . $this->sid); + $this->assertContains($this->lang('LOGIN_ADMIN_CONFIRM'), self::$webDriver->getPageSource()); + + self::find_element('cssSelector', 'input[name=username]')->clear()->sendKeys($username); + self::find_element('cssSelector', 'input[type=password]')->sendKeys($username . $username); + self::find_element('cssSelector', 'input[name=login]')->click(); + $this->assertContains($this->lang('ADMIN_PANEL'), $this->find_element('cssSelector', 'h1')->getText()); + + $cookies = self::$webDriver->manage()->getCookies(); + + // The session id is stored in a cookie that ends with _sid - we assume there is only one such cookie + foreach ($cookies as $cookie) + { + if (substr($cookie['name'], -4) == '_sid') + { + $this->sid = $cookie['value']; + + break; + } + } + + $this->assertNotEmpty($this->sid); + } + protected function add_lang($lang_file) { if (is_array($lang_file)) -- cgit v1.2.1 From 429225027ecf53a359dafcfcc3b03ce40f40fa1b Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 2 Jan 2017 20:39:41 +0100 Subject: [ticket/14947] Create new webdriver instance for every test PHPUnit seems to have emptied the webdriver between every test, which causes curl errors. A new webdriver instance will now be created for every test file. This does not cause a lot of overhead for ui tests. PHPBB3-14947 --- tests/test_framework/phpbb_ui_test_case.php | 72 +++++++++++++++-------------- 1 file changed, 37 insertions(+), 35 deletions(-) (limited to 'tests/test_framework/phpbb_ui_test_case.php') diff --git a/tests/test_framework/phpbb_ui_test_case.php b/tests/test_framework/phpbb_ui_test_case.php index e3f636679c..b875d3212b 100644 --- a/tests/test_framework/phpbb_ui_test_case.php +++ b/tests/test_framework/phpbb_ui_test_case.php @@ -78,14 +78,11 @@ class phpbb_ui_test_case extends phpbb_test_case self::markTestSkipped('phpbb_functional_url was not set in test_config and wasn\'t set as PHPBB_FUNCTIONAL_URL environment variable either.'); } - if (!self::$webDriver) - { - try { - $capabilities = DesiredCapabilities::firefox(); - self::$webDriver = RemoteWebDriver::create(self::$host . ':' . self::$port, $capabilities); - } catch (WebDriverCurlException $e) { - self::markTestSkipped('PhantomJS webserver is not running.'); - } + try { + $capabilities = DesiredCapabilities::firefox(); + self::$webDriver = RemoteWebDriver::create(self::$host . ':' . self::$port, $capabilities); + } catch (WebDriverCurlException $e) { + self::markTestSkipped('PhantomJS webserver is not running.'); } if (!self::$already_installed) @@ -146,9 +143,14 @@ class phpbb_ui_test_case extends phpbb_test_case } } - static public function visit($path) + public function getDriver() + { + return self::$webDriver; + } + + public function visit($path) { - self::$webDriver->get(self::$root_url . $path); + $this->getDriver()->get(self::$root_url . $path); } static protected function recreate_database($config) @@ -157,14 +159,14 @@ class phpbb_ui_test_case extends phpbb_test_case $db_conn_mgr->recreate_db(); } - static public function find_element($type, $value) + public function find_element($type, $value) { - return self::$webDriver->findElement(WebDriverBy::$type($value)); + return $this->getDriver()->findElement(WebDriverBy::$type($value)); } - static public function submit($type = 'id', $value = 'submit') + public function submit($type = 'id', $value = 'submit') { - $element = self::find_element($type, $value); + $element = $this->find_element($type, $value); $element->click(); } @@ -305,21 +307,21 @@ class phpbb_ui_test_case extends phpbb_test_case $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'))); + $this->assertNotEmpty(count($this->find_element('cssSelector', '.submit-buttons'))); - self::find_element('cssSelector', "input[value='Enable']")->submit(); + $this->find_element('cssSelector', "input[value='Enable']")->submit(); $this->add_lang('acp/extensions'); try { - $meta_refresh = self::find_element('cssSelector', 'meta[http-equiv="refresh"]'); + $meta_refresh = $this->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"]'); + $this->getDriver()->execute(array('method' => 'post', 'url' => $match[1])); + $meta_refresh = $this->find_element('cssSelector', 'meta[http-equiv="refresh"]'); } } catch (\Facebook\WebDriver\Exception\NoSuchElementException $e) @@ -327,7 +329,7 @@ class phpbb_ui_test_case extends phpbb_test_case // Probably no refresh triggered } - $this->assertContainsLang('EXTENSION_ENABLE_SUCCESS', self::find_element('cssSelector', 'div.successbox')->getText()); + $this->assertContainsLang('EXTENSION_ENABLE_SUCCESS', $this->find_element('cssSelector', 'div.successbox')->getText()); $this->logout(); } @@ -415,7 +417,7 @@ class phpbb_ui_test_case extends phpbb_test_case } $this->visit('ucp.php?sid=' . $this->sid . '&mode=logout'); - $this->assertContains($this->lang('REGISTER'), self::$webDriver->getPageSource()); + $this->assertContains($this->lang('REGISTER'), $this->getDriver()->getPageSource()); unset($this->sid); } @@ -435,17 +437,17 @@ class phpbb_ui_test_case extends phpbb_test_case return; } - self::$webDriver->manage()->deleteAllCookies(); + $this->getDriver()->manage()->deleteAllCookies(); $this->visit('adm/index.php?sid=' . $this->sid); - $this->assertContains($this->lang('LOGIN_ADMIN_CONFIRM'), self::$webDriver->getPageSource()); + $this->assertContains($this->lang('LOGIN_ADMIN_CONFIRM'), $this->getDriver()->getPageSource()); - self::find_element('cssSelector', 'input[name=username]')->clear()->sendKeys($username); - self::find_element('cssSelector', 'input[type=password]')->sendKeys($username . $username); - self::find_element('cssSelector', 'input[name=login]')->click(); + $this->find_element('cssSelector', 'input[name=username]')->clear()->sendKeys($username); + $this->find_element('cssSelector', 'input[type=password]')->sendKeys($username . $username); + $this->find_element('cssSelector', 'input[name=login]')->click(); $this->assertContains($this->lang('ADMIN_PANEL'), $this->find_element('cssSelector', 'h1')->getText()); - $cookies = self::$webDriver->manage()->getCookies(); + $cookies = $this->getDriver()->manage()->getCookies(); // The session id is stored in a cookie that ends with _sid - we assume there is only one such cookie foreach ($cookies as $cookie) @@ -550,19 +552,19 @@ class phpbb_ui_test_case extends phpbb_test_case { $this->add_lang('ucp'); - self::$webDriver->manage()->deleteAllCookies(); + $this->getDriver()->manage()->deleteAllCookies(); $this->visit('ucp.php'); - $this->assertContains($this->lang('LOGIN_EXPLAIN_UCP'), self::$webDriver->getPageSource()); + $this->assertContains($this->lang('LOGIN_EXPLAIN_UCP'), $this->getDriver()->getPageSource()); - self::$webDriver->manage()->deleteAllCookies(); + $this->getDriver()->manage()->deleteAllCookies(); - self::find_element('cssSelector', 'input[name=username]')->sendKeys($username); - self::find_element('cssSelector', 'input[name=password]')->sendKeys($username . $username); - self::find_element('cssSelector', 'input[name=login]')->click(); + $this->find_element('cssSelector', 'input[name=username]')->sendKeys($username); + $this->find_element('cssSelector', 'input[name=password]')->sendKeys($username . $username); + $this->find_element('cssSelector', 'input[name=login]')->click(); $this->assertNotContains($this->lang('LOGIN'), $this->find_element('className', 'navbar')->getText()); - $cookies = self::$webDriver->manage()->getCookies(); + $cookies = $this->getDriver()->manage()->getCookies(); // The session id is stored in a cookie that ends with _sid - we assume there is only one such cookie foreach ($cookies as $cookie) @@ -586,6 +588,6 @@ class phpbb_ui_test_case extends phpbb_test_case // Change the Path to your own settings $screenshot = time() . ".png"; - self::$webDriver->takeScreenshot($screenshot); + $this->getDriver()->takeScreenshot($screenshot); } } -- cgit v1.2.1