diff options
author | Tristan Darricau <github@nicofuma.fr> | 2014-08-10 00:28:01 +0200 |
---|---|---|
committer | Tristan Darricau <github@nicofuma.fr> | 2014-08-10 00:28:01 +0200 |
commit | 6a8413f064a0a8ade332634c2a891e8ca9038a8b (patch) | |
tree | e2612c5207ab4c39b7ed7537a921e9de5243f98d /tests | |
parent | 469790146ce6c47b92ecd2bcd8b4791ef3c6a069 (diff) | |
parent | dd8adb5d6eca9b1bc359ff3a0ff72b0531dfb9cd (diff) | |
download | forums-6a8413f064a0a8ade332634c2a891e8ca9038a8b.tar forums-6a8413f064a0a8ade332634c2a891e8ca9038a8b.tar.gz forums-6a8413f064a0a8ade332634c2a891e8ca9038a8b.tar.bz2 forums-6a8413f064a0a8ade332634c2a891e8ca9038a8b.tar.xz forums-6a8413f064a0a8ade332634c2a891e8ca9038a8b.zip |
Merge pull request #2691 from dhruvgoel92/ticket/11528
[ticket/11528] Revert all mink changes in functional tests
* dhruvgoel92/ticket/11528:
[ticket/11528] Revert Mink changes
Diffstat (limited to 'tests')
-rw-r--r-- | tests/bootstrap.php | 1 | ||||
-rw-r--r-- | tests/functional/fileupload_form_test.php | 2 | ||||
-rw-r--r-- | tests/functional/fileupload_remote_test.php | 2 | ||||
-rw-r--r-- | tests/functional/forgot_password_test.php | 2 | ||||
-rw-r--r-- | tests/functional/plupload_test.php | 2 | ||||
-rw-r--r-- | tests/test_framework/phpbb_functional_test_case.php | 182 | ||||
-rw-r--r-- | tests/test_framework/phpbb_mink_test_case.php | 183 |
7 files changed, 158 insertions, 216 deletions
diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 2856ba02bb..bb4a703cc3 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -31,5 +31,4 @@ require_once 'test_framework/phpbb_test_case_helpers.php'; 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'; -require_once 'test_framework/phpbb_mink_test_case.php'; require_once 'test_framework/phpbb_functional_test_case.php'; diff --git a/tests/functional/fileupload_form_test.php b/tests/functional/fileupload_form_test.php index 29036c821e..e87953367f 100644 --- a/tests/functional/fileupload_form_test.php +++ b/tests/functional/fileupload_form_test.php @@ -42,8 +42,6 @@ class phpbb_functional_fileupload_form_test extends phpbb_functional_test_case unlink($fileinfo->getPathname()); } - - parent::tearDown(); } private function upload_file($filename, $mimetype) diff --git a/tests/functional/fileupload_remote_test.php b/tests/functional/fileupload_remote_test.php index ef39e1d71b..6ece150b23 100644 --- a/tests/functional/fileupload_remote_test.php +++ b/tests/functional/fileupload_remote_test.php @@ -45,8 +45,6 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case global $config, $user; $user = null; $config = array(); - - parent::tearDown(); } public function test_invalid_extension() diff --git a/tests/functional/forgot_password_test.php b/tests/functional/forgot_password_test.php index c95efc5b2e..64fa19557f 100644 --- a/tests/functional/forgot_password_test.php +++ b/tests/functional/forgot_password_test.php @@ -57,7 +57,5 @@ class phpbb_functional_forgot_password_test extends phpbb_functional_test_case 'config[allow_password_reset]' => 1, )); $crawler = self::submit($form); - - parent::tearDown(); } } diff --git a/tests/functional/plupload_test.php b/tests/functional/plupload_test.php index d9faec035c..ee71597ffc 100644 --- a/tests/functional/plupload_test.php +++ b/tests/functional/plupload_test.php @@ -57,8 +57,6 @@ class phpbb_functional_plupload_test extends phpbb_functional_test_case unlink($fileinfo->getPathname()); } - - parent::tearDown(); } public function get_urls() diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 9bb4d69bf4..80e6293ff9 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -11,12 +11,14 @@ * */ use Symfony\Component\BrowserKit\CookieJar; -use Behat\Mink\Driver\Goutte\Client; -use Behat\Mink\Driver\GoutteDriver; -class phpbb_functional_test_case extends phpbb_mink_test_case +require_once __DIR__ . '/../../phpBB/includes/functions_install.php'; + +class phpbb_functional_test_case extends phpbb_test_case { + static protected $client; static protected $cookieJar; + static protected $root_url; protected $cache = null; protected $db = null; @@ -34,6 +36,7 @@ class phpbb_functional_test_case extends phpbb_mink_test_case */ protected $lang = array(); + static protected $config = array(); static protected $already_installed = false; static public function setUpBeforeClass() @@ -43,24 +46,6 @@ class phpbb_functional_test_case extends phpbb_mink_test_case self::$config = phpbb_test_case_helpers::get_test_config(); self::$root_url = self::$config['phpbb_functional_url']; - self::$cookieJar = new CookieJar; - self::$client = new Client(array(), null, self::$cookieJar); - - $client_options = array( - Guzzle\Http\Client::DISABLE_REDIRECTS => true, - 'curl.options' => array( - CURLOPT_TIMEOUT => 120, - ), - ); - - self::$client->setClient(new Guzzle\Http\Client('', $client_options)); - - // Reset the curl handle because it is 0 at this point and not a valid - // resource - self::$client->getClient()->getCurlMulti()->reset(true); - - self::$driver = new GoutteDriver(self::$client); - // 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 @@ -93,6 +78,12 @@ class phpbb_functional_test_case extends phpbb_mink_test_case $this->bootstrap(); + self::$cookieJar = new CookieJar; + self::$client = new Goutte\Client(array(), null, self::$cookieJar); + // Reset the curl handle because it is 0 at this point and not a valid + // resource + self::$client->getClient()->getCurlMulti()->reset(true); + // Clear the language array so that things // that were added in other tests are gone $this->lang = array(); @@ -119,14 +110,13 @@ class phpbb_functional_test_case extends phpbb_mink_test_case protected function tearDown() { + parent::tearDown(); + if ($this->db instanceof \phpbb\db\driver\driver_interface) { // Close the database connections again this test $this->db->sql_close(); } - - self::$cookieJar->clear(); - parent::tearDown(); } /** @@ -266,6 +256,144 @@ class phpbb_functional_test_case extends phpbb_mink_test_case return $extension_manager; } + static protected 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); + } + } + + self::$cookieJar = new CookieJar; + self::$client = new Goutte\Client(array(), null, self::$cookieJar); + // Set client manually so we can increase the cURL timeout + self::$client->setClient(new Guzzle\Http\Client('', array( + Guzzle\Http\Client::DISABLE_REDIRECTS => true, + 'curl.options' => array( + CURLOPT_TIMEOUT => 120, + ), + ))); + + // Reset the curl handle because it is 0 at this point and not a valid + // resource + self::$client->getClient()->getCurlMulti()->reset(true); + + $parseURL = parse_url(self::$config['phpbb_functional_url']); + + $crawler = self::request('GET', 'install/index.php?mode=install'); + self::assertContains('Welcome to Installation', $crawler->filter('#main')->text()); + $form = $crawler->selectButton('submit')->form(); + + // install/index.php?mode=install&sub=requirements + $crawler = self::submit($form); + self::assertContains('Installation compatibility', $crawler->filter('#main')->text()); + $form = $crawler->selectButton('submit')->form(); + + // install/index.php?mode=install&sub=database + $crawler = self::submit($form); + self::assertContains('Database configuration', $crawler->filter('#main')->text()); + $form = $crawler->selectButton('submit')->form(array( + // Installer uses 3.0-style dbms name + 'dbms' => str_replace('phpbb\db\driver\\', '', self::$config['dbms']), + 'dbhost' => self::$config['dbhost'], + 'dbport' => self::$config['dbport'], + 'dbname' => self::$config['dbname'], + 'dbuser' => self::$config['dbuser'], + 'dbpasswd' => self::$config['dbpasswd'], + 'table_prefix' => self::$config['table_prefix'], + )); + + // install/index.php?mode=install&sub=database + $crawler = self::submit($form); + self::assertContains('Successful connection', $crawler->filter('#main')->text()); + $form = $crawler->selectButton('submit')->form(); + + // install/index.php?mode=install&sub=administrator + $crawler = self::submit($form); + self::assertContains('Administrator configuration', $crawler->filter('#main')->text()); + $form = $crawler->selectButton('submit')->form(array( + 'default_lang' => 'en', + 'admin_name' => 'admin', + 'admin_pass1' => 'adminadmin', + 'admin_pass2' => 'adminadmin', + 'board_email' => 'nobody@example.com', + )); + + // install/index.php?mode=install&sub=administrator + $crawler = self::submit($form); + self::assertContains('Tests passed', $crawler->filter('#main')->text()); + $form = $crawler->selectButton('submit')->form(); + + // We have to skip install/index.php?mode=install&sub=config_file + // because that step will create a config.php file if phpBB has the + // permission to do so. We have to create the config file on 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."); + } + + // We also have to create a install lock that is normally created by + // the installer. The file will be removed by the final step of the + // installer. + $install_lock_file = $phpbb_root_path . 'cache/install_lock'; + $lock_created = file_put_contents($install_lock_file, '') !== false; + if (!$lock_created) + { + self::markTestSkipped("Could not create $lock_created file."); + } + @chmod($install_lock_file, 0666); + + // install/index.php?mode=install&sub=advanced + $form_data = $form->getValues(); + unset($form_data['submit']); + + $crawler = self::request('POST', 'install/index.php?mode=install&sub=advanced', $form_data); + self::assertContains('The settings on this page are only necessary to set if you know that you require something different from the default.', $crawler->filter('#main')->text()); + $form = $crawler->selectButton('submit')->form(array( + 'email_enable' => true, + 'smtp_delivery' => true, + 'smtp_host' => 'nxdomain.phpbb.com', + 'smtp_auth' => 'PLAIN', + 'smtp_user' => 'nxuser', + 'smtp_pass' => 'nxpass', + 'cookie_secure' => false, + 'force_server_vars' => false, + 'server_protocol' => $parseURL['scheme'] . '://', + 'server_name' => 'localhost', + 'server_port' => isset($parseURL['port']) ? (int) $parseURL['port'] : 80, + 'script_path' => $parseURL['path'], + )); + + // install/index.php?mode=install&sub=create_table + $crawler = self::submit($form); + self::assertContains('The database tables used by phpBB', $crawler->filter('#main')->text()); + self::assertContains('have been created and populated with some initial data.', $crawler->filter('#main')->text()); + $form = $crawler->selectButton('submit')->form(); + + // install/index.php?mode=install&sub=final + $crawler = self::submit($form); + self::assertContains('You have successfully installed', $crawler->text()); + + copy($config_file, $config_file_test); + } + public function install_ext($extension) { $this->login(); @@ -284,6 +412,12 @@ class phpbb_functional_test_case extends phpbb_mink_test_case $this->logout(); } + static private function recreate_database($config) + { + $db_conn_mgr = new phpbb_database_test_connection_manager($config); + $db_conn_mgr->recreate_db(); + } + /** * Creates a new style * diff --git a/tests/test_framework/phpbb_mink_test_case.php b/tests/test_framework/phpbb_mink_test_case.php deleted file mode 100644 index ba480e35fb..0000000000 --- a/tests/test_framework/phpbb_mink_test_case.php +++ /dev/null @@ -1,183 +0,0 @@ -<?php -/** -* -* This file is part of the phpBB Forum Software package. -* -* @copyright (c) phpBB Limited <https://www.phpbb.com> -* @license GNU General Public License, version 2 (GPL-2.0) -* -* For full copyright and license information, please see -* the docs/CREDITS.txt file. -* -*/ -use \Behat\Mink\Session; - -require_once __DIR__ . '/../../phpBB/includes/functions_install.php'; - -abstract class phpbb_mink_test_case extends phpbb_test_case -{ - static protected $driver; - static protected $client; - static protected $session; - static protected $config = array(); - static protected $root_url; - - public function __construct($name = null, array $data = array(), $dataName = '') - { - parent::__construct($name, $data, $dataName); - - $this->backupStaticAttributesBlacklist += array( - 'phpbb_mink_test_case' => array('config', 'already_installed'), - ); - } - - static public function setUpBeforeClass() - { - parent::setUpBeforeClass(); - } - - public function setUp() - { - parent::setUp(); - - if (!self::$driver) - { - self::markTestSkipped('Mink driver not initialized.'); - } - - if (!self::$session) - { - self::$session = new Session(self::$driver); - } - } - - static protected function recreate_database($config) - { - $db_conn_mgr = new phpbb_database_test_connection_manager($config); - $db_conn_mgr->recreate_db(); - } - - protected function tearDown() - { - self::$session->reset(); - parent::tearDown(); - } - - static protected function visit($path) - { - self::$session->visit(self::$root_url . $path); - return self::$session->getPage(); - } - - static protected function click_submit($submit_button_id = 'submit') - { - self::$session->getPage()->findById($submit_button_id)->click(); - return self::$session->getPage(); - } - - static protected function install_board() - { - global $phpbb_root_path, $phpEx; - - self::recreate_database(self::$config); - self::$session = new Session(self::$driver); - - $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']); - - $page = self::visit('install/index.php?mode=install'); - self::assertContains('Welcome to Installation', $page->findById('main')->getText()); - - // install/index.php?mode=install&sub=requirements - $page = self::click_submit(); - self::assertContains('Installation compatibility', $page->findById('main')->getText()); - - // install/index.php?mode=install&sub=database - $page = self::click_submit(); - self::assertContains('Database configuration', $page->findById('main')->getText()); - - $page->findById('dbms')->setValue(str_replace('phpbb\db\driver\\', '', self::$config['dbms'])); - $page->findById('dbhost')->setValue(self::$config['dbhost']); - $page->findById('dbport')->setValue(self::$config['dbport']); - $page->findById('dbname')->setValue(self::$config['dbname']); - $page->findById('dbuser')->setValue(self::$config['dbuser']); - $page->findById('dbpasswd')->setValue(self::$config['dbpasswd']); - $page->findById('table_prefix')->setValue(self::$config['table_prefix']); - - // install/index.php?mode=install&sub=database - $page = self::click_submit(); - self::assertContains('Successful connection', $page->findById('main')->getText()); - - // install/index.php?mode=install&sub=administrator - $page = self::click_submit(); - self::assertContains('Administrator configuration', $page->findById('main')->getText()); - - $page->findById('admin_name')->setValue('admin'); - $page->findById('admin_pass1')->setValue('adminadmin'); - $page->findById('admin_pass2')->setValue('adminadmin'); - $page->findById('board_email')->setValue('nobody@example.com'); - - // install/index.php?mode=install&sub=administrator - $page = self::click_submit(); - self::assertContains('Tests passed', $page->findById('main')->getText()); - - // install/index.php?mode=install&sub=config_file - $page = self::click_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($page->findById('main')->getText(), 'The configuration file has been written') === false) - { - $page = self::click_submit('dldone'); - } - self::assertContains('The configuration file has been written', $page->findById('main')->getText()); - - // install/index.php?mode=install&sub=advanced - $page = self::click_submit(); - self::assertContains('The settings on this page are only necessary to set if you know that you require something different from the default.', $page->findById('main')->getText()); - - $page->findById('smtp_delivery')->setValue('1'); - $page->findById('smtp_host')->setValue('nxdomain.phpbb.com'); - $page->findById('smtp_user')->setValue('nxuser'); - $page->findById('smtp_pass')->setValue('nxpass'); - $page->findById('server_protocol')->setValue($parseURL['scheme'] . '://'); - $page->findById('server_name')->setValue('localhost'); - $page->findById('server_port')->setValue(isset($parseURL['port']) ? $parseURL['port'] : 80); - $page->findById('script_path')->setValue($parseURL['path']); - - // install/index.php?mode=install&sub=create_table - $page = self::click_submit(); - self::assertContains('The database tables used by phpBB', $page->findById('main')->getText()); - self::assertContains('have been created and populated with some initial data.', $page->findById('main')->getText()); - - // install/index.php?mode=install&sub=final - $page = self::click_submit(); - self::assertContains('You have successfully installed', $page->getText()); - - copy($config_file, $config_file_test); - - self::$session->stop(); - } -} |