From 77f8bb48fedf0e1afad3a98655aed94c21ae863c Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sun, 10 Aug 2014 00:04:15 +0200 Subject: [ticket/12962] Add initial class for ui_testing PHPBB3-12962 --- tests/test_framework/phpbb_ui_test_case.php | 190 ++++++++++++++++++++++++++++ 1 file changed, 190 insertions(+) create mode 100644 tests/test_framework/phpbb_ui_test_case.php (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_ui_test_case.php b/tests/test_framework/phpbb_ui_test_case.php new file mode 100644 index 0000000000..d8ef98ba7c --- /dev/null +++ b/tests/test_framework/phpbb_ui_test_case.php @@ -0,0 +1,190 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ +require_once __DIR__ . '/../../phpBB/vendor/facebook/webdriver/lib/__init__.php'; +require_once __DIR__ . '/phpbb_test_case_helpers.php'; + +require_once __DIR__ . '/../../phpBB/includes/functions_install.php'; + +class phpbb_ui_test_case extends phpbb_test_case +{ + static protected $host = '127.0.0.1'; + static protected $port = 8910; + + /** + * @var \RemoteWebDriver + */ + static protected $webDriver; + + static protected $config; + static protected $root_url; + static protected $already_installed = false; + + static public function setUpBeforeClass() + { + parent::setUpBeforeClass(); + + self::$config = phpbb_test_case_helpers::get_test_config(); + self::$root_url = self::$config['phpbb_functional_url']; + + // Important: this is used both for installation and by + // test cases for querying the tables. + // Therefore table prefix must be set before a board is + // installed, and also before each test case is run. + self::$config['table_prefix'] = 'phpbb_'; + + if (!isset(self::$config['phpbb_functional_url'])) + { + 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) + { + $capabilities = array(\WebDriverCapabilityType::BROWSER_NAME => 'firefox'); + self::$webDriver = RemoteWebDriver::create(self::$host . ':' . self::$port, $capabilities); + } + + if (!self::$already_installed) + { + self::install_board(); + self::$already_installed = true; + } + } + + static public function visit($path) + { + self::$webDriver->get(self::$root_url . $path); + } + + static protected function recreate_database($config) + { + $db_conn_mgr = new phpbb_database_test_connection_manager($config); + $db_conn_mgr->recreate_db(); + } + + static public function find_element($type, $value) + { + return self::$webDriver->findElement(WebDriverBy::$type($value)); + } + + static public function submit($type = 'id', $value = 'submit') + { + $element = self::find_element($type, $value); + $element->click(); + } + + static public function install_board() + { + global $phpbb_root_path, $phpEx; + + self::recreate_database(self::$config); + + $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"; + + if (file_exists($config_file)) + { + if (!file_exists($config_file_dev)) + { + rename($config_file, $config_file_dev); + } + else + { + unlink($config_file); + } + } + + $parseURL = parse_url(self::$config['phpbb_functional_url']); + + self::visit('install/index.php?mode=install'); + 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) + { + self::markTestSkipped("Could not write $config_file file."); + } + + if (strpos(self::find_element('id','main')->getText(), 'The configuration file has been written') === false) + { + self::submit('id', 'dldone'); + } + 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); + } +} -- cgit v1.2.1 From f21ef60175ce5a5744231410c18f1c4a701a17ab Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sun, 10 Aug 2014 00:44:00 +0200 Subject: [ticket/12962] Add quick-links JS test PHPBB3-12962 --- tests/test_framework/phpbb_ui_test_case.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_ui_test_case.php b/tests/test_framework/phpbb_ui_test_case.php index d8ef98ba7c..271a102299 100644 --- a/tests/test_framework/phpbb_ui_test_case.php +++ b/tests/test_framework/phpbb_ui_test_case.php @@ -10,9 +10,7 @@ * the docs/CREDITS.txt file. * */ -require_once __DIR__ . '/../../phpBB/vendor/facebook/webdriver/lib/__init__.php'; -require_once __DIR__ . '/phpbb_test_case_helpers.php'; - +require_once __DIR__ . '/../../phpBB/vendor/facebook/webdriver/lib/__init__.php'; require_once __DIR__ . '/../../phpBB/includes/functions_install.php'; class phpbb_ui_test_case extends phpbb_test_case -- cgit v1.2.1 From c371e86fa1a640661a47b1d4871f4ea7730f727f Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sun, 10 Aug 2014 12:55:21 +0200 Subject: [ticket/12962] Mark test skipped when phantom server not running PHPBB3-12962 --- tests/test_framework/phpbb_ui_test_case.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_ui_test_case.php b/tests/test_framework/phpbb_ui_test_case.php index 271a102299..9671cc5da4 100644 --- a/tests/test_framework/phpbb_ui_test_case.php +++ b/tests/test_framework/phpbb_ui_test_case.php @@ -47,8 +47,12 @@ class phpbb_ui_test_case extends phpbb_test_case if (!self::$webDriver) { - $capabilities = array(\WebDriverCapabilityType::BROWSER_NAME => 'firefox'); - self::$webDriver = RemoteWebDriver::create(self::$host . ':' . self::$port, $capabilities); + try { + $capabilities = array(\WebDriverCapabilityType::BROWSER_NAME => 'firefox'); + self::$webDriver = RemoteWebDriver::create(self::$host . ':' . self::$port, $capabilities); + } catch (WebDriverCurlException $e) { + self::markTestSkipped('PhantomJS webserver is not running.'); + } } if (!self::$already_installed) -- cgit v1.2.1 From 20dfb23dd437c15999f8886bf17096606525bb27 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sun, 10 Aug 2014 13:58:57 +0200 Subject: [ticket/12962] Force language=en for UI tests installation PHPBB3-12962 --- tests/test_framework/phpbb_ui_test_case.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_ui_test_case.php b/tests/test_framework/phpbb_ui_test_case.php index 9671cc5da4..7787f4ee68 100644 --- a/tests/test_framework/phpbb_ui_test_case.php +++ b/tests/test_framework/phpbb_ui_test_case.php @@ -108,7 +108,7 @@ class phpbb_ui_test_case extends phpbb_test_case $parseURL = parse_url(self::$config['phpbb_functional_url']); - self::visit('install/index.php?mode=install'); + 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 -- cgit v1.2.1 From a1dff65cd1872fd239c0e78949a5924ee6784a34 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sun, 10 Aug 2014 14:55:44 +0200 Subject: [ticket/12962] Fix whitespace characters PHPBB3-12962 --- tests/test_framework/phpbb_ui_test_case.php | 32 ++++++++++++++--------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_ui_test_case.php b/tests/test_framework/phpbb_ui_test_case.php index 7787f4ee68..451aad7e60 100644 --- a/tests/test_framework/phpbb_ui_test_case.php +++ b/tests/test_framework/phpbb_ui_test_case.php @@ -18,17 +18,17 @@ class phpbb_ui_test_case extends phpbb_test_case static protected $host = '127.0.0.1'; static protected $port = 8910; - /** - * @var \RemoteWebDriver - */ - static protected $webDriver; + /** + * @var \RemoteWebDriver + */ + static protected $webDriver; - static protected $config; - static protected $root_url; - static protected $already_installed = false; + static protected $config; + static protected $root_url; + static protected $already_installed = false; static public function setUpBeforeClass() - { + { parent::setUpBeforeClass(); self::$config = phpbb_test_case_helpers::get_test_config(); @@ -60,14 +60,14 @@ class phpbb_ui_test_case extends phpbb_test_case self::install_board(); self::$already_installed = true; } - } + } - static public function visit($path) - { + static public function visit($path) + { self::$webDriver->get(self::$root_url . $path); - } + } - static protected function recreate_database($config) + static protected function recreate_database($config) { $db_conn_mgr = new phpbb_database_test_connection_manager($config); $db_conn_mgr->recreate_db(); @@ -84,8 +84,8 @@ class phpbb_ui_test_case extends phpbb_test_case $element->click(); } - static public function install_board() - { + static public function install_board() + { global $phpbb_root_path, $phpEx; self::recreate_database(self::$config); @@ -188,5 +188,5 @@ class phpbb_ui_test_case extends phpbb_test_case self::assertContains('You have successfully installed', self::find_element('id', 'main')->getText()); copy($config_file, $config_file_test); - } + } } -- cgit v1.2.1 From 77d52982c8b8e0a6366b361ee0d2fe8cf588b5d7 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sun, 21 Sep 2014 12:52:53 +0530 Subject: [ticket/12962] Add facebook/webdriver dependency Create a new composer.json for tests dir and add facebook/webdriver dependency PHPBB3-12962 --- tests/test_framework/phpbb_ui_test_case.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_ui_test_case.php b/tests/test_framework/phpbb_ui_test_case.php index 451aad7e60..702b15d50a 100644 --- a/tests/test_framework/phpbb_ui_test_case.php +++ b/tests/test_framework/phpbb_ui_test_case.php @@ -10,7 +10,7 @@ * the docs/CREDITS.txt file. * */ -require_once __DIR__ . '/../../phpBB/vendor/facebook/webdriver/lib/__init__.php'; +require_once __DIR__ . '/../vendor/facebook/webdriver/lib/__init__.php'; require_once __DIR__ . '/../../phpBB/includes/functions_install.php'; class phpbb_ui_test_case extends phpbb_test_case -- cgit v1.2.1