aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_framework/phpbb_ui_test_case.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_framework/phpbb_ui_test_case.php')
-rw-r--r--tests/test_framework/phpbb_ui_test_case.php324
1 files changed, 211 insertions, 113 deletions
diff --git a/tests/test_framework/phpbb_ui_test_case.php b/tests/test_framework/phpbb_ui_test_case.php
index e8b230ecbe..48e510abe3 100644
--- a/tests/test_framework/phpbb_ui_test_case.php
+++ b/tests/test_framework/phpbb_ui_test_case.php
@@ -11,12 +11,13 @@
*
*/
+use Facebook\WebDriver\Chrome\ChromeOptions;
use Facebook\WebDriver\WebDriverBy;
use Facebook\WebDriver\Exception\WebDriverCurlException;
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Facebook\WebDriver\Remote\DesiredCapabilities;
-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
{
@@ -32,7 +33,6 @@ class phpbb_ui_test_case extends phpbb_test_case
static protected $root_url;
static protected $already_installed = false;
static protected $install_success = false;
-
protected $cache = null;
protected $db = null;
protected $extension_manager = null;
@@ -79,14 +79,18 @@ 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::chrome();
+ $chromeOptions = (new ChromeOptions)->addArguments(['headless', 'disable-gpu']);
+ $capabilities->setCapability(ChromeOptions::CAPABILITY, $chromeOptions);
+ self::$webDriver = RemoteWebDriver::create(
+ self::$host . ':' . self::$port,
+ $capabilities,
+ 30 * 1000, // 30 seconds connection timeout
+ 30 * 1000 // 30 seconds request timeout
+ );
+ } catch (WebDriverCurlException $e) {
+ self::markTestSkipped('PhantomJS webserver is not running.');
}
if (!self::$already_installed)
@@ -147,9 +151,33 @@ class phpbb_ui_test_case extends phpbb_test_case
}
}
- static public function visit($path)
+ public function getDriver()
{
- self::$webDriver->get(self::$root_url . $path);
+ return self::$webDriver;
+ }
+
+ public function visit($path)
+ {
+ // Retry three times on curl issues, e.g. timeout
+ $attempts = 0;
+ $retries = 3;
+
+ while (true)
+ {
+ $attempts++;
+ try
+ {
+ $this->getDriver()->get(self::$root_url . $path);
+ break;
+ }
+ catch (Facebook\WebDriver\Exception\WebDriverCurlException $exception)
+ {
+ if ($attempts >= $retries)
+ {
+ throw $exception;
+ }
+ }
+ }
}
static protected function recreate_database($config)
@@ -158,14 +186,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();
}
@@ -191,90 +219,121 @@ class phpbb_ui_test_case extends phpbb_test_case
}
}
+ $install_config_file = $phpbb_root_path . 'store/install_config.php';
+
+ if (file_exists($install_config_file))
+ {
+ unlink($install_config_file);
+ }
+
+ $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',
+ ],
+ 'cache.driver.class' => 'phpbb\cache\driver\file'
+ ])
+ ->with_config(new \phpbb\config_php_file($phpbb_root_path, $phpEx))
+ ->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->register('installer.install_finish.install_extensions')->setSynthetic(true);
+ $container->set('installer.install_finish.install_extensions', 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');
+
+ $installer->run();
+
+ copy($config_file, $config_file_test);
+
+ self::$install_success = true;
+
+ if (file_exists($phpbb_root_path . 'store/install_config.php'))
{
- self::markTestSkipped("Could not write $config_file file.");
+ self::$install_success = false;
+ @unlink($phpbb_root_path . 'store/install_config.php');
}
- 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;
+ $phpbb_container->reset();
- self::$install_success = true;
+ $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]);
+ }
+ }
}
public function install_ext($extension)
@@ -285,21 +344,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))
+ while (count($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)
@@ -307,7 +366,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();
}
@@ -316,6 +375,12 @@ class phpbb_ui_test_case extends phpbb_test_case
{
if (!$this->cache)
{
+ global $phpbb_container, $phpbb_root_path;
+
+ $phpbb_container = new phpbb_mock_container_builder();
+ $phpbb_container->setParameter('core.environment', PHPBB_ENVIRONMENT);
+ $phpbb_container->setParameter('core.cache_dir', $phpbb_root_path . 'cache/' . PHPBB_ENVIRONMENT . '/');
+
$this->cache = new \phpbb\cache\driver\file;
}
@@ -395,7 +460,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);
}
@@ -415,17 +480,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)
@@ -530,19 +595,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)
@@ -566,6 +631,39 @@ 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);
+ }
+
+ /**
+ * Wait for AJAX. Should be called after an AJAX action is made.
+ *
+ * @param string $framework javascript frameworks jquery|prototype|dojo
+ * @throws \Facebook\WebDriver\Exception\NoSuchElementException
+ * @throws \Facebook\WebDriver\Exception\TimeOutException
+ */
+ public function waitForAjax($framework = 'jquery')
+ {
+ switch ($framework)
+ {
+ case 'jquery':
+ $code = 'return jQuery.active;';
+ break;
+ case 'prototype':
+ $code = 'return Ajax.activeRequestCount;';
+ break;
+ case 'dojo':
+ $code = 'return dojo.io.XMLHTTPTransport.inFlight.length;';
+ break;
+ default:
+ throw new \RuntimeException('Unsupported framework');
+ break;
+ }
+ // wait for at most 30s, retry every 2000ms (2s)
+ $driver = $this->getDriver();
+ $driver->wait(30, 2000)->until(
+ function () use ($driver, $code) {
+ return !$driver->executeScript($code);
+ }
+ );
}
}