diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/RUNNING_TESTS.md | 13 | ||||
-rw-r--r-- | tests/bootstrap.php | 1 | ||||
-rw-r--r-- | tests/event/php_exporter_test.php | 2 | ||||
-rw-r--r-- | tests/filesystem/clean_path_test.php | 2 | ||||
-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/functional/ucp_profile_test.php | 2 | ||||
-rw-r--r-- | tests/functions/convert_30_dbms_to_31_test.php | 1 | ||||
-rw-r--r-- | tests/notification/user_list_trim_test.php | 10 | ||||
-rw-r--r-- | tests/path_helper/path_helper_test.php | 39 | ||||
-rw-r--r-- | tests/profilefields/type_googleplus_test.php | 62 | ||||
-rw-r--r-- | tests/test_framework/phpbb_database_connection_odbc_pdo_wrapper.php | 2 | ||||
-rw-r--r-- | tests/test_framework/phpbb_database_test_case.php | 31 | ||||
-rw-r--r-- | tests/test_framework/phpbb_database_test_connection_manager.php | 50 | ||||
-rw-r--r-- | tests/test_framework/phpbb_functional_test_case.php | 182 | ||||
-rw-r--r-- | tests/test_framework/phpbb_mink_test_case.php | 183 |
18 files changed, 326 insertions, 262 deletions
diff --git a/tests/RUNNING_TESTS.md b/tests/RUNNING_TESTS.md index d638c86859..afd7caa709 100644 --- a/tests/RUNNING_TESTS.md +++ b/tests/RUNNING_TESTS.md @@ -32,7 +32,6 @@ will be skipped: - apc (APC cache driver) - bz2 (compress tests) -- interbase, pdo_firebird (Firebird database driver) - mysql, pdo_mysql (MySQL database driver) - mysqli, pdo_mysql (MySQLi database driver) - pcntl (flock class) @@ -82,16 +81,10 @@ Special Database Cases ---------------------- In order to run tests on some of the databases that we support, it will be necessary to provide a custom DSN string in test_config.php. This is only -needed for MSSQL 2000+ (PHP module), MSSQL via ODBC, and Firebird when -PDO_Firebird does not work on your system -(https://bugs.php.net/bug.php?id=61183). The variable must be named `$custom_dsn`. +needed for MSSQL 2000+ (PHP module) and MSSQL via ODBC. The variable must be +named `$custom_dsn`. -Examples: -Firebird using http://www.firebirdsql.org/en/odbc-driver/ - - $custom_dsn = "Driver={Firebird/InterBase(r) driver};dbname=$dbhost:$dbname"; - -MSSQL +Example MSSQL: $custom_dsn = "Driver={SQL Server Native Client 10.0};Server=$dbhost;Database=$dbname"; diff --git a/tests/bootstrap.php b/tests/bootstrap.php index bb4a703cc3..2856ba02bb 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -31,4 +31,5 @@ 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/event/php_exporter_test.php b/tests/event/php_exporter_test.php index 823d90b63f..b52d68e305 100644 --- a/tests/event/php_exporter_test.php +++ b/tests/event/php_exporter_test.php @@ -118,6 +118,7 @@ class phpbb_event_php_exporter_test extends phpbb_test_case array('* @since 3.1.0-a1', '3.1.0-a1'), array('* @since 3.1.0-b3', '3.1.0-b3'), array(' * @since 3.1.0-b3', '3.1.0-b3'), + array('* @since 3.1.0-RC2', '3.1.0-RC2'), ); } @@ -137,6 +138,7 @@ class phpbb_event_php_exporter_test extends phpbb_test_case array('* @since 3.1.0-a1 bertie is cool'), array('bertie* @since 3.1.0-a1'), array('* @since 3.1-A2'), + array('* @since 3.1.0-rc1'), ); } diff --git a/tests/filesystem/clean_path_test.php b/tests/filesystem/clean_path_test.php index 1aef0d8a0c..c585b17155 100644 --- a/tests/filesystem/clean_path_test.php +++ b/tests/filesystem/clean_path_test.php @@ -32,6 +32,8 @@ class phpbb_filesystem_clean_path_test extends phpbb_test_case array('foo/bar/.', 'foo/bar'), array('./foo/bar', './foo/bar'), array('../foo/bar', '../foo/bar'), + array('./../foo/bar', './../foo/bar'), + array('././../foo/bar', './../foo/bar'), array('one/two/three', 'one/two/three'), array('one/two/../three', 'one/three'), array('one/../two/three', 'two/three'), diff --git a/tests/functional/fileupload_form_test.php b/tests/functional/fileupload_form_test.php index cf36a0523f..b9d55fbd3c 100644 --- a/tests/functional/fileupload_form_test.php +++ b/tests/functional/fileupload_form_test.php @@ -42,6 +42,8 @@ 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 f904258a5c..b170fc051f 100644 --- a/tests/functional/fileupload_remote_test.php +++ b/tests/functional/fileupload_remote_test.php @@ -43,6 +43,8 @@ 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 64fa19557f..c95efc5b2e 100644 --- a/tests/functional/forgot_password_test.php +++ b/tests/functional/forgot_password_test.php @@ -57,5 +57,7 @@ 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 ee71597ffc..d9faec035c 100644 --- a/tests/functional/plupload_test.php +++ b/tests/functional/plupload_test.php @@ -57,6 +57,8 @@ class phpbb_functional_plupload_test extends phpbb_functional_test_case unlink($fileinfo->getPathname()); } + + parent::tearDown(); } public function get_urls() diff --git a/tests/functional/ucp_profile_test.php b/tests/functional/ucp_profile_test.php index 2d68704162..e7abba9255 100644 --- a/tests/functional/ucp_profile_test.php +++ b/tests/functional/ucp_profile_test.php @@ -26,6 +26,7 @@ class phpbb_functional_ucp_profile_test extends phpbb_functional_test_case $form = $crawler->selectButton('Submit')->form(array( 'pf_phpbb_facebook' => 'phpbb', + 'pf_phpbb_googleplus' => 'phpbb', 'pf_phpbb_location' => 'Bertie´s Empire', 'pf_phpbb_skype' => 'phpbb.skype.account', 'pf_phpbb_twitter' => 'phpbb_twitter', @@ -39,6 +40,7 @@ class phpbb_functional_ucp_profile_test extends phpbb_functional_test_case $form = $crawler->selectButton('Submit')->form(); $this->assertEquals('phpbb', $form->get('pf_phpbb_facebook')->getValue()); + $this->assertEquals('phpbb', $form->get('pf_phpbb_googleplus')->getValue()); $this->assertEquals('Bertie´s Empire', $form->get('pf_phpbb_location')->getValue()); $this->assertEquals('phpbb.skype.account', $form->get('pf_phpbb_skype')->getValue()); $this->assertEquals('phpbb_twitter', $form->get('pf_phpbb_twitter')->getValue()); diff --git a/tests/functions/convert_30_dbms_to_31_test.php b/tests/functions/convert_30_dbms_to_31_test.php index 9647eb341c..a3992aef5c 100644 --- a/tests/functions/convert_30_dbms_to_31_test.php +++ b/tests/functions/convert_30_dbms_to_31_test.php @@ -18,7 +18,6 @@ class phpbb_convert_30_dbms_to_31_test extends phpbb_test_case public function convert_30_dbms_to_31_data() { return array( - array('firebird'), array('mssql'), array('mssql_odbc'), array('mssqlnative'), diff --git a/tests/notification/user_list_trim_test.php b/tests/notification/user_list_trim_test.php index 7e0add2bb5..85d8961e82 100644 --- a/tests/notification/user_list_trim_test.php +++ b/tests/notification/user_list_trim_test.php @@ -75,7 +75,7 @@ class phpbb_notification_user_list_trim_test extends phpbb_database_test_case 'post_username' => 'A', 'responders' => null, ), - 'A replied to the topic “Test”.', + '<strong>Reply</strong> from A in topic:', ), array( array( @@ -86,7 +86,7 @@ class phpbb_notification_user_list_trim_test extends phpbb_database_test_case array('username' => '', 'poster_id' => 3), ), ), - 'A and B replied to the topic “Test”.', + '<strong>Reply</strong> from A and B in topic:', ), array( array( @@ -98,7 +98,7 @@ class phpbb_notification_user_list_trim_test extends phpbb_database_test_case array('username' => '', 'poster_id' => 4), ), ), - 'A, B, and C replied to the topic “Test”.', + '<strong>Reply</strong> from A, B, and C in topic:', ), array( array( @@ -111,7 +111,7 @@ class phpbb_notification_user_list_trim_test extends phpbb_database_test_case array('username' => '', 'poster_id' => 5), ), ), - 'A, B, C, and D replied to the topic “Test”.', + '<strong>Reply</strong> from A, B, C, and D in topic:', ), array( array( @@ -125,7 +125,7 @@ class phpbb_notification_user_list_trim_test extends phpbb_database_test_case array('username' => '', 'poster_id' => 6), ), ), - 'A, B, C, and 2 others replied to the topic “Test”.', + '<strong>Reply</strong> from A, B, C, and 2 others in topic:', ), ); } diff --git a/tests/path_helper/path_helper_test.php b/tests/path_helper/path_helper_test.php index a3ad901379..9866cb6efe 100644 --- a/tests/path_helper/path_helper_test.php +++ b/tests/path_helper/path_helper_test.php @@ -13,6 +13,7 @@ class phpbb_path_helper_test extends phpbb_test_case { + /** @var \phpbb\path_helper */ protected $path_helper; protected $phpbb_root_path = ''; @@ -20,7 +21,8 @@ class phpbb_path_helper_test extends phpbb_test_case { parent::setUp(); - $this->set_phpbb_root_path(); + $filesystem = new \phpbb\filesystem(); + $this->set_phpbb_root_path($filesystem); $this->path_helper = new \phpbb\path_helper( new \phpbb\symfony_request( @@ -40,9 +42,9 @@ class phpbb_path_helper_test extends phpbb_test_case * any time we wish to use it in one of these functions (and * also in general for everything else) */ - public function set_phpbb_root_path() + public function set_phpbb_root_path($filesystem) { - $this->phpbb_root_path = dirname(__FILE__) . './../../phpBB/'; + $this->phpbb_root_path = $filesystem->clean_path(dirname(__FILE__) . '/../../phpBB/'); } public function test_get_web_root_path() @@ -53,7 +55,8 @@ class phpbb_path_helper_test extends phpbb_test_case public function basic_update_web_root_path_data() { - $this->set_phpbb_root_path(); + $filesystem = new \phpbb\filesystem(); + $this->set_phpbb_root_path($filesystem); return array( array( @@ -71,7 +74,7 @@ class phpbb_path_helper_test extends phpbb_test_case ), array( $this->phpbb_root_path . $this->phpbb_root_path . 'test.php', - $this->phpbb_root_path . $this->phpbb_root_path . 'test.php', + $filesystem->clean_path($this->phpbb_root_path . $this->phpbb_root_path . 'test.php'), ), ); } @@ -81,51 +84,55 @@ class phpbb_path_helper_test extends phpbb_test_case */ public function test_basic_update_web_root_path($input, $expected) { - $this->assertEquals($expected, $this->path_helper->update_web_root_path($input, $symfony_request)); + $this->assertEquals($expected, $this->path_helper->update_web_root_path($input)); } public function update_web_root_path_data() { - $this->set_phpbb_root_path(); + $this->set_phpbb_root_path(new \phpbb\filesystem()); return array( array( $this->phpbb_root_path . 'test.php', - $this->phpbb_root_path . 'test.php', '/', + null, + null, + '', ), array( $this->phpbb_root_path . 'test.php', - $this->phpbb_root_path . '../test.php', '//', + null, + null, + './../', ), array( $this->phpbb_root_path . 'test.php', - $this->phpbb_root_path . '../test.php', '//', 'foo/bar.php', 'bar.php', + './../', ), array( $this->phpbb_root_path . 'test.php', - $this->phpbb_root_path . '../../test.php', '/foo/template', '/phpbb3-fork/phpBB/app.php/foo/template', '/phpbb3-fork/phpBB/app.php', + './../../', ), array( $this->phpbb_root_path . 'test.php', - $this->phpbb_root_path . '../test.php', '/foo/template', '/phpbb3-fork/phpBB/foo/template', '/phpbb3-fork/phpBB/app.php', + './../', ), array( $this->phpbb_root_path . 'test.php', - $this->phpbb_root_path . '../test.php', '/', '/phpbb3-fork/phpBB/app.php/', '/phpbb3-fork/phpBB/app.php', + './../', ), ); } @@ -133,9 +140,9 @@ class phpbb_path_helper_test extends phpbb_test_case /** * @dataProvider update_web_root_path_data */ - public function test_update_web_root_path($input, $expected, $getPathInfo, $getRequestUri = null, $getScriptName = null) + public function test_update_web_root_path($input, $getPathInfo, $getRequestUri, $getScriptName, $correction) { - $symfony_request = $this->getMock("\phpbb\symfony_request", array(), array( + $symfony_request = $this->getMock('\phpbb\symfony_request', array(), array( new phpbb_mock_request(), )); $symfony_request->expects($this->any()) @@ -155,7 +162,7 @@ class phpbb_path_helper_test extends phpbb_test_case 'php' ); - $this->assertEquals($expected, $path_helper->update_web_root_path($input, $symfony_request)); + $this->assertEquals($correction . $input, $path_helper->update_web_root_path($input, $symfony_request)); } public function clean_url_data() diff --git a/tests/profilefields/type_googleplus_test.php b/tests/profilefields/type_googleplus_test.php new file mode 100644 index 0000000000..fdbdd86553 --- /dev/null +++ b/tests/profilefields/type_googleplus_test.php @@ -0,0 +1,62 @@ +<?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. +* +*/ + +class phpbb_profilefield_type_googleplus_test extends phpbb_test_case +{ + public function get_profile_contact_value_data() + { + return array( + array( + '112010191010100', + array(), + '112010191010100', + 'Field should return a numerical Google+ ID as is', + ), + array( + 'TestUsername', + array(), + '+TestUsername', + 'Field should return a string Google+ ID with a + prefixed', + ), + ); + } + + /** + * @dataProvider get_profile_contact_value_data + */ + public function test_get_profile_contact_value($value, $field_options, $expected, $description) + { + $user = $this->getMock('\phpbb\user'); + $request = $this->getMock('\phpbb\request\request'); + $template = $this->getMock('\phpbb\template\template'); + + $field = new \phpbb\profilefields\type\type_googleplus( + $request, + $template, + $user + ); + + $default_field_options = array( + 'field_type' => '\phpbb\profilefields\type\type_googleplus', + 'field_name' => 'field', + 'field_id' => 1, + 'lang_id' => 1, + 'lang_name' => 'field', + 'field_required' => false, + 'field_validation' => '[\w]+', + ); + $field_options = array_merge($default_field_options, $field_options); + + $this->assertSame($expected, $field->get_profile_contact_value($value, $field_options), $description); + } +} diff --git a/tests/test_framework/phpbb_database_connection_odbc_pdo_wrapper.php b/tests/test_framework/phpbb_database_connection_odbc_pdo_wrapper.php index 22d55b4ed5..db31edc984 100644 --- a/tests/test_framework/phpbb_database_connection_odbc_pdo_wrapper.php +++ b/tests/test_framework/phpbb_database_connection_odbc_pdo_wrapper.php @@ -25,7 +25,7 @@ if (!class_exists('PDO')) */ class phpbb_database_connection_odbc_pdo_wrapper extends PDO { - // Name of the driver being used (i.e. mssql, firebird) + // Name of the driver being used (i.e. mssql) public $driver = ''; // Version number of driver since PDO::getAttribute(PDO::ATTR_CLIENT_VERSION) is pretty useless for this diff --git a/tests/test_framework/phpbb_database_test_case.php b/tests/test_framework/phpbb_database_test_case.php index 1f3a564205..46276bcfcb 100644 --- a/tests/test_framework/phpbb_database_test_case.php +++ b/tests/test_framework/phpbb_database_test_case.php @@ -145,25 +145,7 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test public function createXMLDataSet($path) { - $db_config = $this->get_database_config(); - - // Firebird requires table and column names to be uppercase - if ($db_config['dbms'] == 'phpbb\db\driver\firebird') - { - $xml_data = file_get_contents($path); - $xml_data = preg_replace_callback('/(?:(<table name="))([a-z_]+)(?:(">))/', 'phpbb_database_test_case::to_upper', $xml_data); - $xml_data = preg_replace_callback('/(?:(<column>))([a-z_]+)(?:(<\/column>))/', 'phpbb_database_test_case::to_upper', $xml_data); - - $new_fixture = tmpfile(); - fwrite($new_fixture, $xml_data); - fseek($new_fixture, 0); - - $meta_data = stream_get_meta_data($new_fixture); - $path = $meta_data['uri']; - } - $this->fixture_xml_data = parent::createXMLDataSet($path); - return $this->fixture_xml_data; } @@ -244,19 +226,6 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test return new phpbb_database_test_connection_manager($config); } - /** - * Converts a match in the middle of a string to uppercase. - * This is necessary for transforming the fixture information for Firebird tests - * - * @param $matches The array of matches from a regular expression - * - * @return string The string with the specified match converted to uppercase - */ - static public function to_upper($matches) - { - return $matches[1] . strtoupper($matches[2]) . $matches[3]; - } - public function assert_array_content_equals($one, $two) { // http://stackoverflow.com/questions/3838288/phpunit-assert-two-arrays-are-equal-but-order-of-elements-not-important diff --git a/tests/test_framework/phpbb_database_test_connection_manager.php b/tests/test_framework/phpbb_database_test_connection_manager.php index b73b05025e..92e2080dba 100644 --- a/tests/test_framework/phpbb_database_test_connection_manager.php +++ b/tests/test_framework/phpbb_database_test_connection_manager.php @@ -116,7 +116,7 @@ class phpbb_database_test_connection_manager // These require different connection strings on the phpBB side than they do in PDO // so you must provide a DSN string for ODBC separately - if (!empty($this->config['custom_dsn']) && ($this->config['dbms'] == 'phpbb\db\driver\mssql' || $this->config['dbms'] == 'phpbb\db\driver\firebird')) + if (!empty($this->config['custom_dsn']) && $this->config['dbms'] == 'phpbb\db\driver\mssql') { $dsn = 'odbc:' . $this->config['custom_dsn']; } @@ -130,14 +130,6 @@ class phpbb_database_test_connection_manager $this->pdo = new phpbb_database_connection_odbc_pdo_wrapper('mssql', 0, $dsn, $this->config['dbuser'], $this->config['dbpasswd']); break; - case 'phpbb\db\driver\firebird': - if (!empty($this->config['custom_dsn'])) - { - $this->pdo = new phpbb_database_connection_odbc_pdo_wrapper('firebird', 0, $dsn, $this->config['dbuser'], $this->config['dbpasswd']); - break; - } - // Fall through if they're using the firebird PDO driver and not the generic ODBC driver - default: $this->pdo = new PDO($dsn, $this->config['dbuser'], $this->config['dbpasswd']); break; @@ -197,7 +189,6 @@ class phpbb_database_test_connection_manager { case 'phpbb\db\driver\sqlite': case 'phpbb\db\driver\sqlite3': - case 'phpbb\db\driver\firebird': $this->connect(); // Drop all of the tables foreach ($this->get_tables() as $table) @@ -298,13 +289,6 @@ class phpbb_database_test_connection_manager FROM pg_stat_user_tables'; break; - case 'phpbb\db\driver\firebird': - $sql = 'SELECT rdb$relation_name - FROM rdb$relations - WHERE rdb$view_source is null - AND rdb$system_flag = 0'; - break; - case 'phpbb\db\driver\oracle': $sql = 'SELECT table_name FROM USER_TABLES'; @@ -358,14 +342,17 @@ class phpbb_database_test_connection_manager $filename = $directory . $schema . '_schema.sql'; - $queries = file_get_contents($filename); - $sql = phpbb_remove_comments($queries); + if (file_exists($filename)) + { + $queries = file_get_contents($filename); + $sql = phpbb_remove_comments($queries); - $sql = split_sql_file($sql, $this->dbms['DELIM']); + $sql = split_sql_file($sql, $this->dbms['DELIM']); - foreach ($sql as $query) - { - $this->pdo->exec($query); + foreach ($sql as $query) + { + $this->pdo->exec($query); + } } // Ok we have the db info go ahead and work on building the table @@ -404,11 +391,6 @@ class phpbb_database_test_connection_manager protected function get_dbms_data($dbms) { $available_dbms = array( - 'phpbb\db\driver\firebird' => array( - 'SCHEMA' => 'firebird', - 'DELIM' => ';;', - 'PDO' => 'firebird', - ), 'phpbb\db\driver\mysqli' => array( 'SCHEMA' => 'mysql_41', 'DELIM' => ';', @@ -478,18 +460,6 @@ class phpbb_database_test_connection_manager switch ($this->config['dbms']) { - case 'phpbb\db\driver\firebird': - $sql = 'SELECT RDB$GENERATOR_NAME - FROM RDB$GENERATORS - WHERE RDB$SYSTEM_FLAG = 0'; - $result = $this->pdo->query($sql); - - while ($row = $result->fetch(PDO::FETCH_NUM)) - { - $queries[] = 'DROP GENERATOR ' . current($row); - } - break; - case 'phpbb\db\driver\oracle': $sql = 'SELECT sequence_name FROM USER_SEQUENCES'; diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index fde6a6a4ff..eef30fbcc7 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -11,14 +11,12 @@ * */ use Symfony\Component\BrowserKit\CookieJar; +use Behat\Mink\Driver\Goutte\Client; +use Behat\Mink\Driver\GoutteDriver; -require_once __DIR__ . '/../../phpBB/includes/functions_install.php'; - -class phpbb_functional_test_case extends phpbb_test_case +class phpbb_functional_test_case extends phpbb_mink_test_case { - static protected $client; static protected $cookieJar; - static protected $root_url; protected $cache = null; protected $db = null; @@ -36,7 +34,6 @@ class phpbb_functional_test_case extends phpbb_test_case */ protected $lang = array(); - static protected $config = array(); static protected $already_installed = false; static public function setUpBeforeClass() @@ -46,6 +43,24 @@ class phpbb_functional_test_case extends phpbb_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 @@ -78,12 +93,6 @@ class phpbb_functional_test_case extends phpbb_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(); @@ -110,13 +119,14 @@ class phpbb_functional_test_case extends phpbb_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(); } /** @@ -256,144 +266,6 @@ class phpbb_functional_test_case extends phpbb_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(); @@ -412,12 +284,6 @@ class phpbb_functional_test_case extends phpbb_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 new file mode 100644 index 0000000000..ba480e35fb --- /dev/null +++ b/tests/test_framework/phpbb_mink_test_case.php @@ -0,0 +1,183 @@ +<?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(); + } +} |