From 90a957ad26f52e26c3979464c5ac15b1fd0fcc28 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 21 Jul 2012 17:43:43 +0200 Subject: [ticket/11015] Make DBAL classes autoloadable PHPBB3-11015 This allows us to just create the object without having to include the driver first. However, it also means that users must specify the full class name in config.php --- tests/test_framework/phpbb_database_test_case.php | 7 ++-- .../phpbb_database_test_connection_manager.php | 44 +++++++++++----------- .../test_framework/phpbb_functional_test_case.php | 8 +--- tests/test_framework/phpbb_test_case_helpers.php | 2 +- 4 files changed, 28 insertions(+), 33 deletions(-) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_database_test_case.php b/tests/test_framework/phpbb_database_test_case.php index bb86df0ef0..abc3c8d7a3 100644 --- a/tests/test_framework/phpbb_database_test_case.php +++ b/tests/test_framework/phpbb_database_test_case.php @@ -33,7 +33,7 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test $db_config = $this->get_database_config(); // Firebird requires table and column names to be uppercase - if ($db_config['dbms'] == 'firebird') + if ($db_config['dbms'] == 'phpbb_db_driver_firebird') { $xml_data = file_get_contents($path); $xml_data = preg_replace_callback('/(?:())/', 'phpbb_database_test_case::to_upper', $xml_data); @@ -100,9 +100,8 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test $config = $this->get_database_config(); - require_once dirname(__FILE__) . '/../../phpBB/includes/db/' . $config['dbms'] . '.php'; - $dbal = 'dbal_' . $config['dbms']; - $db = new $dbal(); + $dbms = $config['dbms']; + $db = new $dbms(); $db->sql_connect($config['dbhost'], $config['dbuser'], $config['dbpasswd'], $config['dbname'], $config['dbport']); return $db; diff --git a/tests/test_framework/phpbb_database_test_connection_manager.php b/tests/test_framework/phpbb_database_test_connection_manager.php index 25e0972f42..db772496a0 100644 --- a/tests/test_framework/phpbb_database_test_connection_manager.php +++ b/tests/test_framework/phpbb_database_test_connection_manager.php @@ -108,7 +108,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'] == 'mssql' || $this->config['dbms'] == 'firebird')) + if (!empty($this->config['custom_dsn']) && ($this->config['dbms'] == 'phpbb_db_driver_mssql' || $this->config['dbms'] == 'phpbb_db_driver_firebird')) { $dsn = 'odbc:' . $this->config['custom_dsn']; } @@ -117,12 +117,12 @@ class phpbb_database_test_connection_manager { switch ($this->config['dbms']) { - case 'mssql': - case 'mssql_odbc': + case 'phpbb_db_driver_mssql': + case 'phpbb_db_driver_mssql_odbc': $this->pdo = new phpbb_database_connection_odbc_pdo_wrapper('mssql', 0, $dsn, $this->config['dbuser'], $this->config['dbpasswd']); break; - case 'firebird': + 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']); @@ -165,14 +165,14 @@ class phpbb_database_test_connection_manager { switch ($this->config['dbms']) { - case 'sqlite': + case 'phpbb_db_driver_sqlite': if (file_exists($this->config['dbhost'])) { unlink($this->config['dbhost']); } break; - case 'firebird': + case 'phpbb_db_driver_firebird': $this->connect(); // Drop all of the tables foreach ($this->get_tables() as $table) @@ -182,7 +182,7 @@ class phpbb_database_test_connection_manager $this->purge_extras(); break; - case 'oracle': + case 'phpbb_db_driver_oracle': $this->connect(); // Drop all of the tables foreach ($this->get_tables() as $table) @@ -232,39 +232,39 @@ class phpbb_database_test_connection_manager switch ($this->config['dbms']) { - case 'mysql': - case 'mysql4': - case 'mysqli': + case 'phpbb_db_driver_mysql': + case 'phpbb_db_driver_mysql4': + case 'phpbb_db_driver_mysqli': $sql = 'SHOW TABLES'; break; - case 'sqlite': + case 'phpbb_db_driver_sqlite': $sql = 'SELECT name FROM sqlite_master WHERE type = "table"'; break; - case 'mssql': - case 'mssql_odbc': - case 'mssqlnative': + case 'phpbb_db_driver_mssql': + case 'phpbb_db_driver_mssql_odbc': + case 'phpbb_db_driver_mssqlnative': $sql = "SELECT name FROM sysobjects WHERE type='U'"; break; - case 'postgres': + case 'phpbb_db_driver_postgres': $sql = 'SELECT relname FROM pg_stat_user_tables'; break; - case 'firebird': + 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 'oracle': + case 'phpbb_db_driver_oracle': $sql = 'SELECT table_name FROM USER_TABLES'; break; @@ -299,8 +299,8 @@ class phpbb_database_test_connection_manager protected function load_schema_from_file($directory) { $schema = $this->dbms['SCHEMA']; - - if ($this->config['dbms'] == 'mysql') + + if ($this->config['dbms'] == 'phpbb_db_driver_mysql') { $sth = $this->pdo->query('SELECT VERSION() AS version'); $row = $sth->fetch(PDO::FETCH_ASSOC); @@ -319,7 +319,7 @@ class phpbb_database_test_connection_manager $queries = file_get_contents($filename); $sql = phpbb_remove_comments($queries); - + $sql = split_sql_file($sql, $this->dbms['DELIM']); foreach ($sql as $query) @@ -403,7 +403,7 @@ class phpbb_database_test_connection_manager switch ($this->config['dbms']) { - case 'firebird': + case 'phpbb_db_driver_firebird': $sql = 'SELECT RDB$GENERATOR_NAME FROM RDB$GENERATORS WHERE RDB$SYSTEM_FLAG = 0'; @@ -415,7 +415,7 @@ class phpbb_database_test_connection_manager } break; - case 'oracle': + case 'phpbb_db_driver_oracle': $sql = 'SELECT sequence_name FROM USER_SEQUENCES'; $result = $this->pdo->query($sql); diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index c042d75811..ce0042d538 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -87,12 +87,8 @@ class phpbb_functional_test_case extends phpbb_test_case // so we don't reopen an open connection if (!($this->db instanceof dbal)) { - if (!class_exists('dbal_' . self::$config['dbms'])) - { - include($phpbb_root_path . 'includes/db/' . self::$config['dbms'] . ".$phpEx"); - } - $sql_db = 'dbal_' . self::$config['dbms']; - $this->db = new $sql_db(); + $dbms = self::$config['dbms']; + $this->db = new $dbms(); $this->db->sql_connect(self::$config['dbhost'], self::$config['dbuser'], self::$config['dbpasswd'], self::$config['dbname'], self::$config['dbport']); } return $this->db; diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php index 46feef550a..5667aa6ca2 100644 --- a/tests/test_framework/phpbb_test_case_helpers.php +++ b/tests/test_framework/phpbb_test_case_helpers.php @@ -54,7 +54,7 @@ class phpbb_test_case_helpers if (extension_loaded('sqlite') && version_compare(PHPUnit_Runner_Version::id(), '3.4.15', '>=')) { $config = array_merge($config, array( - 'dbms' => 'sqlite', + 'dbms' => 'phpbb_db_driver_sqlite', 'dbhost' => dirname(__FILE__) . '/../phpbb_unit_tests.sqlite2', // filename 'dbport' => '', 'dbname' => '', -- cgit v1.2.1 From d6cca4e2c0719da35c75d3fff68f4a46255fe352 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 21 Jul 2012 19:35:39 +0200 Subject: [ticket/11015] Fix connection manager db driver selection PHPBB3-11015 --- .../phpbb_database_test_connection_manager.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_database_test_connection_manager.php b/tests/test_framework/phpbb_database_test_connection_manager.php index db772496a0..82da5fe4c3 100644 --- a/tests/test_framework/phpbb_database_test_connection_manager.php +++ b/tests/test_framework/phpbb_database_test_connection_manager.php @@ -334,47 +334,47 @@ class phpbb_database_test_connection_manager protected function get_dbms_data($dbms) { $available_dbms = array( - 'firebird' => array( + 'phpbb_db_driver_firebird' => array( 'SCHEMA' => 'firebird', 'DELIM' => ';;', 'PDO' => 'firebird', ), - 'mysqli' => array( + 'phpbb_db_driver_mysqli' => array( 'SCHEMA' => 'mysql_41', 'DELIM' => ';', 'PDO' => 'mysql', ), - 'mysql' => array( + 'phpbb_db_driver_mysql' => array( 'SCHEMA' => 'mysql', 'DELIM' => ';', 'PDO' => 'mysql', ), - 'mssql' => array( + 'phpbb_db_driver_mssql' => array( 'SCHEMA' => 'mssql', 'DELIM' => 'GO', 'PDO' => 'odbc', ), - 'mssql_odbc'=> array( + 'phpbb_db_driver_mssql_odbc'=> array( 'SCHEMA' => 'mssql', 'DELIM' => 'GO', 'PDO' => 'odbc', ), - 'mssqlnative' => array( + 'phpbb_db_driver_mssqlnative' => array( 'SCHEMA' => 'mssql', 'DELIM' => 'GO', 'PDO' => 'sqlsrv', ), - 'oracle' => array( + 'phpbb_db_driver_oracle' => array( 'SCHEMA' => 'oracle', 'DELIM' => '/', 'PDO' => 'oci', ), - 'postgres' => array( + 'phpbb_db_driver_postgres' => array( 'SCHEMA' => 'postgres', 'DELIM' => ';', 'PDO' => 'pgsql', ), - 'sqlite' => array( + 'phpbb_db_driver_sqlite' => array( 'SCHEMA' => 'sqlite', 'DELIM' => ';', 'PDO' => 'sqlite2', -- cgit v1.2.1 From a23eebdb7bb60c4b910357c1e948b97d48071d6a Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Fri, 16 Nov 2012 01:09:17 +0100 Subject: [tracker/11015] Prepend phpbb_db_driver_ for PHPBB_TEST_DBMS PHPBB3-11015 --- tests/test_framework/phpbb_test_case_helpers.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php index 0f4f7fbf34..5c1200657d 100644 --- a/tests/test_framework/phpbb_test_case_helpers.php +++ b/tests/test_framework/phpbb_test_case_helpers.php @@ -96,7 +96,7 @@ class phpbb_test_case_helpers if (isset($_SERVER['PHPBB_TEST_DBMS'])) { $config = array_merge($config, array( - 'dbms' => isset($_SERVER['PHPBB_TEST_DBMS']) ? $_SERVER['PHPBB_TEST_DBMS'] : '', + 'dbms' => isset($_SERVER['PHPBB_TEST_DBMS']) ? 'phpbb_db_driver_' . $_SERVER['PHPBB_TEST_DBMS'] : '', 'dbhost' => isset($_SERVER['PHPBB_TEST_DBHOST']) ? $_SERVER['PHPBB_TEST_DBHOST'] : '', 'dbport' => isset($_SERVER['PHPBB_TEST_DBPORT']) ? $_SERVER['PHPBB_TEST_DBPORT'] : '', 'dbname' => isset($_SERVER['PHPBB_TEST_DBNAME']) ? $_SERVER['PHPBB_TEST_DBNAME'] : '', -- cgit v1.2.1 From 8f8a7f76374679d2f893245c1f607a3b2db56a9a Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Fri, 16 Nov 2012 01:50:30 +0100 Subject: [ticket/11015] Allow full dbms class name in tests/test_config.php PHPBB3-11015 --- tests/test_framework/phpbb_test_case_helpers.php | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php index 5c1200657d..9bbdcff440 100644 --- a/tests/test_framework/phpbb_test_case_helpers.php +++ b/tests/test_framework/phpbb_test_case_helpers.php @@ -78,7 +78,7 @@ class phpbb_test_case_helpers include($test_config); $config = array_merge($config, array( - 'dbms' => 'phpbb_db_driver_' . $dbms, + 'dbms' => $this->convert_30_dbms($dbms), 'dbhost' => $dbhost, 'dbport' => $dbport, 'dbname' => $dbname, @@ -96,7 +96,7 @@ class phpbb_test_case_helpers if (isset($_SERVER['PHPBB_TEST_DBMS'])) { $config = array_merge($config, array( - 'dbms' => isset($_SERVER['PHPBB_TEST_DBMS']) ? 'phpbb_db_driver_' . $_SERVER['PHPBB_TEST_DBMS'] : '', + 'dbms' => isset($_SERVER['PHPBB_TEST_DBMS']) ? $this->convert_30_dbms($_SERVER['PHPBB_TEST_DBMS']) : '', 'dbhost' => isset($_SERVER['PHPBB_TEST_DBHOST']) ? $_SERVER['PHPBB_TEST_DBHOST'] : '', 'dbport' => isset($_SERVER['PHPBB_TEST_DBPORT']) ? $_SERVER['PHPBB_TEST_DBPORT'] : '', 'dbname' => isset($_SERVER['PHPBB_TEST_DBNAME']) ? $_SERVER['PHPBB_TEST_DBNAME'] : '', @@ -223,4 +223,20 @@ class phpbb_test_case_helpers } } } + + /** + * Convert 3.0 dbms to 3.1 db driver class name + * + * @param string $dbms dbms parameter + * @return db driver class + */ + protected function convert_30_dbms($dbms) + { + if (!preg_match('#^phpbb_db_driver_#', $dbms)) + { + return 'phpbb_db_driver_'.$dbms; + } + + return $dbms; + } } -- cgit v1.2.1 From 5bc0f4b3d49ed1bea45464beece42906646eb026 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 17 Nov 2012 00:24:32 +0100 Subject: [ticket/11015] Move db driver class name fixing to function PHPBB3-11015 --- tests/test_framework/phpbb_test_case_helpers.php | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php index 9bbdcff440..96a546e538 100644 --- a/tests/test_framework/phpbb_test_case_helpers.php +++ b/tests/test_framework/phpbb_test_case_helpers.php @@ -78,7 +78,7 @@ class phpbb_test_case_helpers include($test_config); $config = array_merge($config, array( - 'dbms' => $this->convert_30_dbms($dbms), + 'dbms' => phpbb_convert_30_dbms_to_31($dbms), 'dbhost' => $dbhost, 'dbport' => $dbport, 'dbname' => $dbname, @@ -96,7 +96,7 @@ class phpbb_test_case_helpers if (isset($_SERVER['PHPBB_TEST_DBMS'])) { $config = array_merge($config, array( - 'dbms' => isset($_SERVER['PHPBB_TEST_DBMS']) ? $this->convert_30_dbms($_SERVER['PHPBB_TEST_DBMS']) : '', + 'dbms' => isset($_SERVER['PHPBB_TEST_DBMS']) ? phpbb_convert_30_dbms_to_31($_SERVER['PHPBB_TEST_DBMS']) : '', 'dbhost' => isset($_SERVER['PHPBB_TEST_DBHOST']) ? $_SERVER['PHPBB_TEST_DBHOST'] : '', 'dbport' => isset($_SERVER['PHPBB_TEST_DBPORT']) ? $_SERVER['PHPBB_TEST_DBPORT'] : '', 'dbname' => isset($_SERVER['PHPBB_TEST_DBNAME']) ? $_SERVER['PHPBB_TEST_DBNAME'] : '', @@ -223,20 +223,4 @@ class phpbb_test_case_helpers } } } - - /** - * Convert 3.0 dbms to 3.1 db driver class name - * - * @param string $dbms dbms parameter - * @return db driver class - */ - protected function convert_30_dbms($dbms) - { - if (!preg_match('#^phpbb_db_driver_#', $dbms)) - { - return 'phpbb_db_driver_'.$dbms; - } - - return $dbms; - } } -- cgit v1.2.1 From 74093d0fd383619ec8b58914ebe2edd68145e070 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 4 Dec 2012 04:32:37 -0500 Subject: [ticket/11015] Fix functional test case. PHPBB3-11015 --- tests/test_framework/phpbb_functional_test_case.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index f9c1d64ff8..2a24e96a25 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -86,7 +86,7 @@ class phpbb_functional_test_case extends phpbb_test_case { global $phpbb_root_path, $phpEx; // so we don't reopen an open connection - if (!($this->db instanceof dbal)) + if (!($this->db instanceof phpbb_db_driver)) { $dbms = self::$config['dbms']; $this->db = new $dbms(); -- cgit v1.2.1 From bdc3ddf2bcec3caa9047d03e954c9de82f4916aa Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 4 Dec 2012 17:19:25 -0500 Subject: [ticket/10491] Set up functional tests sensibly. PHPBB_FUNCTIONAL_URL goes into setup before class. Drop PHPBB_FUNCTIONAL_URL check in board installation and silent return if it is not set. Take board installation out of constructor. Install board in setup method. PHPBB3-10491 --- .../test_framework/phpbb_functional_test_case.php | 35 ++++++++++++---------- 1 file changed, 19 insertions(+), 16 deletions(-) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 7c03f874e9..85019a5e31 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -33,11 +33,27 @@ class phpbb_functional_test_case extends phpbb_test_case static protected $config = array(); static protected $already_installed = false; - public function setUp() + static public function setUpBeforeClass() { + parent::setUpBeforeClass(); + + self::$config = phpbb_test_case_helpers::get_test_config(); + if (!isset(self::$config['phpbb_functional_url'])) { - $this->markTestSkipped('phpbb_functional_url was not set in test_config and wasn\'t set as PHPBB_FUNCTIONAL_URL environment variable either.'); + self::markTestSkipped('phpbb_functional_url was not set in test_config and wasn\'t set as PHPBB_FUNCTIONAL_URL environment variable either.'); + } + } + + public function setUp() + { + parent::setUp(); + + if (!static::$already_installed) + { + $this->install_board(); + $this->bootstrap(); + static::$already_installed = true; } $this->cookieJar = new CookieJar; @@ -91,26 +107,12 @@ class phpbb_functional_test_case extends phpbb_test_case $this->backupStaticAttributesBlacklist += array( 'phpbb_functional_test_case' => array('config', 'already_installed'), ); - - if (!static::$already_installed) - { - $this->install_board(); - $this->bootstrap(); - static::$already_installed = true; - } } protected function install_board() { global $phpbb_root_path, $phpEx; - self::$config = phpbb_test_case_helpers::get_test_config(); - - if (!isset(self::$config['phpbb_functional_url'])) - { - return; - } - self::$config['table_prefix'] = 'phpbb_'; $this->recreate_database(self::$config); @@ -158,6 +160,7 @@ class phpbb_functional_test_case extends phpbb_test_case // end data $content = $this->do_request('install'); + $this->assertNotSame(false, $content); $this->assertContains('Welcome to Installation', $content); $this->do_request('create_table', $data); -- cgit v1.2.1 From 38d2868ba8db0f6e24fdfb7bbdfef4925a97770c Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 4 Dec 2012 17:37:46 -0500 Subject: [ticket/10491] Move board installation into setup before class. Functional posting test already assumed that board is installed once per test case and not once per test. PHPBB3-10491 --- .../test_framework/phpbb_functional_test_case.php | 28 ++++++++++------------ 1 file changed, 12 insertions(+), 16 deletions(-) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 85019a5e31..66f4b6db65 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -31,7 +31,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() { @@ -43,18 +42,15 @@ class phpbb_functional_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.'); } + + self::install_board(); } public function setUp() { parent::setUp(); - if (!static::$already_installed) - { - $this->install_board(); - $this->bootstrap(); - static::$already_installed = true; - } + $this->bootstrap(); $this->cookieJar = new CookieJar; $this->client = new Goutte\Client(array(), null, $this->cookieJar); @@ -109,12 +105,12 @@ class phpbb_functional_test_case extends phpbb_test_case ); } - protected function install_board() + static protected function install_board() { global $phpbb_root_path, $phpEx; self::$config['table_prefix'] = 'phpbb_'; - $this->recreate_database(self::$config); + self::recreate_database(self::$config); if (file_exists($phpbb_root_path . "config.$phpEx")) { @@ -159,20 +155,20 @@ class phpbb_functional_test_case extends phpbb_test_case )); // end data - $content = $this->do_request('install'); - $this->assertNotSame(false, $content); - $this->assertContains('Welcome to Installation', $content); + $content = self::do_request('install'); + self::assertNotSame(false, $content); + self::assertContains('Welcome to Installation', $content); - $this->do_request('create_table', $data); + self::do_request('create_table', $data); - $this->do_request('config_file', $data); + self::do_request('config_file', $data); file_put_contents($phpbb_root_path . "config.$phpEx", phpbb_create_config_file_data($data, self::$config['dbms'], array(), true, true)); - $this->do_request('final', $data); + self::do_request('final', $data); copy($phpbb_root_path . "config.$phpEx", $phpbb_root_path . "config_test.$phpEx"); } - private function do_request($sub, $post_data = null) + static private function do_request($sub, $post_data = null) { $context = null; -- cgit v1.2.1 From 70050020699d9eab9b97bda342e0e928d1591de8 Mon Sep 17 00:00:00 2001 From: Fyorl Date: Sun, 8 Jul 2012 20:22:19 +0100 Subject: [ticket/10972] Added methods for creating and deleting basic users Modified the login method to allow logging in of an arbitrary user. Also added tests for the new functionality. PHPBB3-10972 --- .../test_framework/phpbb_functional_test_case.php | 45 +++++++++++++++++++++- 1 file changed, 43 insertions(+), 2 deletions(-) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 7c03f874e9..dfbfe2565e 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -194,7 +194,48 @@ class phpbb_functional_test_case extends phpbb_test_case $db_conn_mgr->recreate_db(); } - protected function login() + /** + * Creates a new user with limited permissions + * + * @param string $username Also doubles up as the user's password + */ + protected function create_user($username) + { + // Required by unique_id + global $config; + + if (!is_array($config)) + { + $config = array(); + } + + $config['rand_seed'] = ''; + $config['rand_seed_last_update'] = time() + 600; + + $db = $this->get_db(); + $query = " + INSERT INTO " . self::$config['table_prefix'] . "users + (user_type, group_id, username, username_clean, user_regdate, user_password, user_email, user_lang, user_style, user_rank, user_colour, user_posts, user_permissions, user_ip, user_birthday, user_lastpage, user_last_confirm_key, user_post_sortby_type, user_post_sortby_dir, user_topic_sortby_type, user_topic_sortby_dir, user_avatar, user_sig, user_sig_bbcode_uid, user_from, user_icq, user_aim, user_yim, user_msnm, user_jabber, user_website, user_occ, user_interests, user_actkey, user_newpasswd) + VALUES + (0, 2, 'user', 'user', 0, '" . phpbb_hash($username) . "', 'nobody@example.com', 'en', 1, 0, '', 1, '', '', '', '', '', 't', 'a', 't', 'd', '', '', '', '', '', '', '', '', '', '', '', '', '', '') + "; + + $db->sql_query($query); + } + + /** + * Deletes a user + * + * @param string $username The username of the user to delete + */ + protected function delete_user($username) + { + $db = $this->get_db(); + $query = "DELETE FROM " . self::$config['table_prefix'] . "users WHERE username = '" . $db->sql_escape($username) . "'"; + $db->sql_query($query); + } + + protected function login($username = 'admin') { $this->add_lang('ucp'); @@ -202,7 +243,7 @@ class phpbb_functional_test_case extends phpbb_test_case $this->assertContains($this->lang('LOGIN_EXPLAIN_UCP'), $crawler->filter('html')->text()); $form = $crawler->selectButton($this->lang('LOGIN'))->form(); - $login = $this->client->submit($form, array('username' => 'admin', 'password' => 'admin')); + $login = $this->client->submit($form, array('username' => $username, 'password' => $username)); $cookies = $this->cookieJar->all(); -- cgit v1.2.1 From cafc7feca12730fce59091bd7a18fb5c3f7ecdc0 Mon Sep 17 00:00:00 2001 From: Fyorl Date: Mon, 9 Jul 2012 00:24:28 +0100 Subject: [ticket/10972] Moved tests into appropriate places and added comments PHPBB3-10972 --- tests/test_framework/phpbb_functional_test_case.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index dfbfe2565e..a72c0940ab 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -197,6 +197,10 @@ class phpbb_functional_test_case extends phpbb_test_case /** * Creates a new user with limited permissions * + * Note that creating two users with the same name results in undefined + * login behaviour. Always call delete_user after running a test that + * requires create_user. + * * @param string $username Also doubles up as the user's password */ protected function create_user($username) -- cgit v1.2.1 From d33accb687ab4266559c12a356e121f3634d780b Mon Sep 17 00:00:00 2001 From: Fyorl Date: Fri, 10 Aug 2012 12:31:53 +0100 Subject: [ticket/10972] Added explicit checks for creating duplicate users. PHPBB3-10972 --- tests/test_framework/phpbb_functional_test_case.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index a72c0940ab..9bc2c96753 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -30,6 +30,11 @@ class phpbb_functional_test_case extends phpbb_test_case */ protected $lang = array(); + /** + * @var array + */ + protected $created_users = array(); + static protected $config = array(); static protected $already_installed = false; @@ -197,14 +202,18 @@ class phpbb_functional_test_case extends phpbb_test_case /** * Creates a new user with limited permissions * - * Note that creating two users with the same name results in undefined - * login behaviour. Always call delete_user after running a test that + * Always call delete_user after running a test that * requires create_user. * * @param string $username Also doubles up as the user's password */ protected function create_user($username) { + if (isset($this->created_users[$username])) + { + return; + } + // Required by unique_id global $config; @@ -225,6 +234,7 @@ class phpbb_functional_test_case extends phpbb_test_case "; $db->sql_query($query); + $this->created_users[$username] = 1; } /** @@ -234,6 +244,11 @@ class phpbb_functional_test_case extends phpbb_test_case */ protected function delete_user($username) { + if (isset($this->created_users[$username])) + { + unset($this->created_users[$username]); + } + $db = $this->get_db(); $query = "DELETE FROM " . self::$config['table_prefix'] . "users WHERE username = '" . $db->sql_escape($username) . "'"; $db->sql_query($query); -- cgit v1.2.1 From ebdd96592a100139c48204ef133e706c0ac465d1 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 6 Dec 2012 22:45:12 -0500 Subject: [ticket/10972] Backport get_db from develop. PHPBB3-10972 --- tests/test_framework/phpbb_functional_test_case.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 9bc2c96753..3b6232d091 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -16,7 +16,9 @@ class phpbb_functional_test_case extends phpbb_test_case { protected $client; protected $root_url; + protected $cache = null; + protected $db = null; /** * Session ID for current test's session (each test makes its own) @@ -70,6 +72,23 @@ class phpbb_functional_test_case extends phpbb_test_case { } + protected function get_db() + { + global $phpbb_root_path, $phpEx; + // so we don't reopen an open connection + if (!($this->db instanceof dbal)) + { + if (!class_exists('dbal_' . self::$config['dbms'])) + { + include($phpbb_root_path . 'includes/db/' . self::$config['dbms'] . ".$phpEx"); + } + $sql_db = 'dbal_' . self::$config['dbms']; + $this->db = new $sql_db(); + $this->db->sql_connect(self::$config['dbhost'], self::$config['dbuser'], self::$config['dbpasswd'], self::$config['dbname'], self::$config['dbport']); + } + return $this->db; + } + protected function get_cache_driver() { if (!$this->cache) -- cgit v1.2.1 From fb5c4440e598f2a775a52299a06e903d3cee5398 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 6 Dec 2012 23:43:22 -0500 Subject: [ticket/10972] Tweak user addition. Always add users, do not keep track of which users have been added. The tests should know whether users they want exist or not. Use more unique user names in tests for robustness. Added some more assertions here and there. PHPBB3-10972 --- .../test_framework/phpbb_functional_test_case.php | 57 ++++++++++++---------- 1 file changed, 32 insertions(+), 25 deletions(-) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 3b6232d091..b17b2dcd5f 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -32,11 +32,6 @@ class phpbb_functional_test_case extends phpbb_test_case */ protected $lang = array(); - /** - * @var array - */ - protected $created_users = array(); - static protected $config = array(); static protected $already_installed = false; @@ -225,14 +220,10 @@ class phpbb_functional_test_case extends phpbb_test_case * requires create_user. * * @param string $username Also doubles up as the user's password + * @return int ID of created user */ protected function create_user($username) { - if (isset($this->created_users[$username])) - { - return; - } - // Required by unique_id global $config; @@ -243,17 +234,36 @@ class phpbb_functional_test_case extends phpbb_test_case $config['rand_seed'] = ''; $config['rand_seed_last_update'] = time() + 600; - + + // Required by user_add + global $db, $cache; $db = $this->get_db(); - $query = " - INSERT INTO " . self::$config['table_prefix'] . "users - (user_type, group_id, username, username_clean, user_regdate, user_password, user_email, user_lang, user_style, user_rank, user_colour, user_posts, user_permissions, user_ip, user_birthday, user_lastpage, user_last_confirm_key, user_post_sortby_type, user_post_sortby_dir, user_topic_sortby_type, user_topic_sortby_dir, user_avatar, user_sig, user_sig_bbcode_uid, user_from, user_icq, user_aim, user_yim, user_msnm, user_jabber, user_website, user_occ, user_interests, user_actkey, user_newpasswd) - VALUES - (0, 2, 'user', 'user', 0, '" . phpbb_hash($username) . "', 'nobody@example.com', 'en', 1, 0, '', 1, '', '', '', '', '', 't', 'a', 't', 'd', '', '', '', '', '', '', '', '', '', '', '', '', '', '') - "; + if (!function_exists('phpbb_mock_null_cache')) + { + require_once(__DIR__ . '/../mock/null_cache.php'); + } + $cache = new phpbb_mock_null_cache; - $db->sql_query($query); - $this->created_users[$username] = 1; + if (!function_exists('utf_clean_string')) + { + require_once(__DIR__ . '/../../phpBB/includes/utf/utf_tools.php'); + } + if (!function_exists('user_add')) + { + require_once(__DIR__ . '/../../phpBB/includes/functions_user.php'); + } + + $user_row = array( + 'username' => $username, + 'group_id' => 2, + 'user_email' => 'nobody@example.com', + 'user_type' => 0, + 'user_lang' => 'en', + 'user_timezone' => 0, + 'user_dateformat' => '', + 'user_password' => phpbb_hash($username), + ); + return user_add($user_row); } /** @@ -263,11 +273,6 @@ class phpbb_functional_test_case extends phpbb_test_case */ protected function delete_user($username) { - if (isset($this->created_users[$username])) - { - unset($this->created_users[$username]); - } - $db = $this->get_db(); $query = "DELETE FROM " . self::$config['table_prefix'] . "users WHERE username = '" . $db->sql_escape($username) . "'"; $db->sql_query($query); @@ -281,7 +286,9 @@ class phpbb_functional_test_case extends phpbb_test_case $this->assertContains($this->lang('LOGIN_EXPLAIN_UCP'), $crawler->filter('html')->text()); $form = $crawler->selectButton($this->lang('LOGIN'))->form(); - $login = $this->client->submit($form, array('username' => $username, 'password' => $username)); + $crawler = $this->client->submit($form, array('username' => $username, 'password' => $username)); + $this->assert_response_success(); + $this->assertContains($this->lang('LOGIN_REDIRECT'), $crawler->filter('html')->text()); $cookies = $this->cookieJar->all(); -- cgit v1.2.1 From ff993ba9d30f5de49e5231647c5bb76d95c357f8 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 6 Dec 2012 23:47:19 -0500 Subject: [ticket/10972] Drop user deletion. Users should not be deleted in tests that test user creation. Tests should use unique user names to avoid collisions. User deletion should use user_remove anyway. PHPBB3-10972 --- tests/test_framework/phpbb_functional_test_case.php | 15 --------------- 1 file changed, 15 deletions(-) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index b17b2dcd5f..71e88fbcf6 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -216,9 +216,6 @@ class phpbb_functional_test_case extends phpbb_test_case /** * Creates a new user with limited permissions * - * Always call delete_user after running a test that - * requires create_user. - * * @param string $username Also doubles up as the user's password * @return int ID of created user */ @@ -266,18 +263,6 @@ class phpbb_functional_test_case extends phpbb_test_case return user_add($user_row); } - /** - * Deletes a user - * - * @param string $username The username of the user to delete - */ - protected function delete_user($username) - { - $db = $this->get_db(); - $query = "DELETE FROM " . self::$config['table_prefix'] . "users WHERE username = '" . $db->sql_escape($username) . "'"; - $db->sql_query($query); - } - protected function login($username = 'admin') { $this->add_lang('ucp'); -- cgit v1.2.1 From 2bc2cb1f6f78ef8cc2037941501d5389af009cd7 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Mon, 10 Dec 2012 06:42:43 -0500 Subject: [ticket/10491] Install board once per test run. This is how things used to be. Installing for each test class brings 3-4x performance penalty compared to installing once for the entire test run. However, with a single installation for all tests an individual test can see different data when it is invoked by itself vs when it is executed as part of the entire test suite. PHPBB3-10491 --- tests/test_framework/phpbb_functional_test_case.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 66f4b6db65..1e835fcc35 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -31,6 +31,7 @@ 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() { @@ -43,7 +44,11 @@ class phpbb_functional_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.'); } - self::install_board(); + if (!self::$already_installed) + { + self::install_board(); + self::$already_installed = true; + } } public function setUp() -- cgit v1.2.1 From 1441b70ae8e97782ae63c479b0635c1622078a48 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Wed, 12 Dec 2012 21:47:48 -0500 Subject: [ticket/10491] Make recreate_database static. PHPBB3-10491 --- tests/test_framework/phpbb_functional_test_case.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 1e835fcc35..71bb994f21 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -192,7 +192,7 @@ class phpbb_functional_test_case extends phpbb_test_case return file_get_contents(self::$config['phpbb_functional_url'] . 'install/index.php?mode=install&sub=' . $sub, false, $context); } - private function recreate_database($config) + static private function recreate_database($config) { $db_conn_mgr = new phpbb_database_test_connection_manager($config); $db_conn_mgr->recreate_db(); -- cgit v1.2.1 From 4de07338efcd4f0d390df0f2d7fa883712d8c942 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 13 Dec 2012 07:28:01 -0500 Subject: [ticket/10975] Avoid rewriting global config twice. PHPBB3-10975 --- tests/test_framework/phpbb_functional_test_case.php | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 9097854bd4..b6f8e5c44c 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -251,16 +251,12 @@ class phpbb_functional_test_case extends phpbb_test_case // Required by unique_id global $config; - if (!is_array($config)) - { - $config = array(); - } - + $config = new phpbb_config(array()); $config['rand_seed'] = ''; $config['rand_seed_last_update'] = time() + 600; // Required by user_add - global $db, $cache, $config, $phpbb_dispatcher; + global $db, $cache, $phpbb_dispatcher; $db = $this->get_db(); if (!function_exists('phpbb_mock_null_cache')) { @@ -276,7 +272,6 @@ class phpbb_functional_test_case extends phpbb_test_case { require_once(__DIR__ . '/../../phpBB/includes/functions_user.php'); } - $config = new phpbb_config(array()); set_config(null, null, null, $config); set_config_count(null, null, null, $config); $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); -- cgit v1.2.1 From 83345d986d172ee8b655ec4600c1f1575ba306d0 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 13 Dec 2012 08:11:10 -0500 Subject: [ticket/11015] Convert database drivers to new spelling in post setup sync. PHPBB3-11015 --- tests/test_framework/phpbb_database_test_connection_manager.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_database_test_connection_manager.php b/tests/test_framework/phpbb_database_test_connection_manager.php index 3fe3ab8d90..4ce5f03a8b 100644 --- a/tests/test_framework/phpbb_database_test_connection_manager.php +++ b/tests/test_framework/phpbb_database_test_connection_manager.php @@ -444,7 +444,7 @@ class phpbb_database_test_connection_manager switch ($this->config['dbms']) { - case 'oracle': + case 'phpbb_db_driver_oracle': // Get all of the information about the sequences $sql = "SELECT t.table_name, tc.column_name, d.referenced_name as sequence_name, s.increment_by, s.min_value FROM USER_TRIGGERS t @@ -486,7 +486,7 @@ class phpbb_database_test_connection_manager } break; - case 'postgres': + case 'phpbb_db_driver_postgres': // Get the sequences attached to the tables $sql = 'SELECT column_name, table_name FROM information_schema.columns WHERE table_name IN (' . implode(', ', $table_names) . ") -- cgit v1.2.1 From 789c04b90025cf230b3b965ece8022104128c92c Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 13 Dec 2012 15:42:00 -0500 Subject: [ticket/11265] Add assertions for board installation success. PHPBB3-11265 --- tests/test_framework/phpbb_functional_test_case.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 93a4ab2fbf..8ab6469e9a 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -183,12 +183,20 @@ class phpbb_functional_test_case extends phpbb_test_case self::assertNotSame(false, $content); self::assertContains('Welcome to Installation', $content); - self::do_request('create_table', $data); + $content = self::do_request('create_table', $data); + self::assertNotSame(false, $content); + self::assertContains('The database tables used by phpBB', $content); + // 3.0 or 3.1 + self::assertContains('have been created and populated with some initial data.', $content); - self::do_request('config_file', $data); + $content = self::do_request('config_file', $data); + self::assertNotSame(false, $content); + self::assertContains('Configuration file', $content); file_put_contents($phpbb_root_path . "config.$phpEx", phpbb_create_config_file_data($data, self::$config['dbms'], array(), true, true)); - self::do_request('final', $data); + $content = self::do_request('final', $data); + self::assertNotSame(false, $content); + self::assertContains('You have successfully installed', $content); copy($phpbb_root_path . "config.$phpEx", $phpbb_root_path . "config_test.$phpEx"); } -- cgit v1.2.1 From 586e8cbd97b4e2537f69ebe04b0c9d24fc090a4c Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 13 Dec 2012 15:27:38 -0500 Subject: [ticket/11015] Include functions.php because it is not always included. PHPBB3-11015 --- tests/test_framework/phpbb_test_case_helpers.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php index 18f575b980..47459832d5 100644 --- a/tests/test_framework/phpbb_test_case_helpers.php +++ b/tests/test_framework/phpbb_test_case_helpers.php @@ -104,6 +104,11 @@ class phpbb_test_case_helpers if (isset($_SERVER['PHPBB_TEST_DBMS'])) { + if (!function_exists('phpbb_convert_30_dbms_to_31')) + { + require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; + } + $config = array_merge($config, array( 'dbms' => isset($_SERVER['PHPBB_TEST_DBMS']) ? phpbb_convert_30_dbms_to_31($_SERVER['PHPBB_TEST_DBMS']) : '', 'dbhost' => isset($_SERVER['PHPBB_TEST_DBHOST']) ? $_SERVER['PHPBB_TEST_DBHOST'] : '', -- cgit v1.2.1 From 1774dd2af43e84f879813dedb0780f614810ad8a Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 13 Dec 2012 17:49:30 -0500 Subject: [ticket/11015] Installer still needs 3.0-style dbms name. PHPBB3-11015 --- tests/test_framework/phpbb_functional_test_case.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index db7fc4e6a3..67a5050892 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -202,6 +202,8 @@ class phpbb_functional_test_case extends phpbb_test_case self::assertNotSame(false, $content); self::assertContains('Welcome to Installation', $content); + // Installer uses 3.0-style dbms name + $data['dbms'] = str_replace('phpbb_db_driver_', '', $data['dbms']); $content = self::do_request('create_table', $data); self::assertNotSame(false, $content); self::assertContains('The database tables used by phpBB', $content); -- cgit v1.2.1 From d1eb3449af5e7675f6896406e78fa1f240d4a3e8 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Fri, 14 Dec 2012 14:05:46 -0500 Subject: [ticket/11268] Delete phpbb_db_driver_mysql4 as there is no such thing. PHPBB3-11268 --- tests/test_framework/phpbb_database_test_connection_manager.php | 1 - 1 file changed, 1 deletion(-) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_database_test_connection_manager.php b/tests/test_framework/phpbb_database_test_connection_manager.php index 4ce5f03a8b..03097a10a0 100644 --- a/tests/test_framework/phpbb_database_test_connection_manager.php +++ b/tests/test_framework/phpbb_database_test_connection_manager.php @@ -227,7 +227,6 @@ class phpbb_database_test_connection_manager switch ($this->config['dbms']) { case 'phpbb_db_driver_mysql': - case 'phpbb_db_driver_mysql4': case 'phpbb_db_driver_mysqli': $sql = 'SHOW TABLES'; break; -- cgit v1.2.1 From ff83580af1af7623012843c56fba605ec2ad7df1 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sat, 15 Dec 2012 13:45:33 -0500 Subject: [ticket/10758] Add a test for acp login. PHPBB3-10758 --- tests/test_framework/phpbb_functional_test_case.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 67a5050892..c599abcbcd 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -323,7 +323,7 @@ class phpbb_functional_test_case extends phpbb_test_case * Login to the ACP * You must run login() before calling this. */ - protected function admin_login() + protected function admin_login($username = 'admin') { $this->add_lang('acp/common'); @@ -343,7 +343,9 @@ class phpbb_functional_test_case extends phpbb_test_case { if (strpos($field, 'password_') === 0) { - $login = $this->client->submit($form, array('username' => 'admin', $field => 'admin')); + $crawler = $this->client->submit($form, array('username' => $username, $field => $username)); + $this->assert_response_success(); + $this->assertContains($this->lang('LOGIN_ADMIN_SUCCESS'), $crawler->filter('html')->text()); $cookies = $this->cookieJar->all(); -- cgit v1.2.1 From b6f40f7c33a4cdb4a31af6374b2b1fd7c13deb08 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 20 Dec 2012 20:27:59 -0500 Subject: [ticket/10758-upload] Convert error to a failure. PHPBB3-10758 --- tests/test_framework/phpbb_functional_test_case.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 67a5050892..a051410d7b 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -424,4 +424,20 @@ class phpbb_functional_test_case extends phpbb_test_case $content = $this->client->getResponse()->getContent(); $this->assertNotContains('Fatal error:', $content); } + + public function assert_filter($crawler, $expr, $msg = null) + { + $nodes = $crawler->filter($expr); + if ($msg) + { + $msg .= "\n"; + } + else + { + $msg = ''; + } + $msg .= "`$expr` not found in DOM."; + $this->assertGreaterThan(0, count($nodes), $msg); + return $nodes; + } } -- cgit v1.2.1 From 02a1777fcbc550b4d91aaa585cffa9c052e4c525 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Wed, 26 Dec 2012 00:30:20 -0500 Subject: [ticket/11295] Drop tables rather than database for postgres in test suite. Doing so allows: 1. User running the tests no longer needs create database privilege. 2. Test database may be located in a non-default tablespace and generally have site-specific options applied to it. PHPBB3-11295 --- .../phpbb_database_test_connection_manager.php | 27 ++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_database_test_connection_manager.php b/tests/test_framework/phpbb_database_test_connection_manager.php index d7c2804aa7..3b8c2e99ae 100644 --- a/tests/test_framework/phpbb_database_test_connection_manager.php +++ b/tests/test_framework/phpbb_database_test_connection_manager.php @@ -186,6 +186,16 @@ class phpbb_database_test_connection_manager $this->purge_extras(); break; + case 'postgres': + $this->connect(); + // Drop all of the tables + foreach ($this->get_tables() as $table) + { + $this->pdo->exec('DROP TABLE ' . $table . ' CASCADE'); + } + $this->purge_extras(); + break; + default: $this->connect(false); @@ -293,7 +303,7 @@ class phpbb_database_test_connection_manager protected function load_schema_from_file($directory) { $schema = $this->dbms['SCHEMA']; - + if ($this->config['dbms'] == 'mysql') { $sth = $this->pdo->query('SELECT VERSION() AS version'); @@ -313,7 +323,7 @@ class phpbb_database_test_connection_manager $queries = file_get_contents($filename); $sql = phpbb_remove_comments($queries); - + $sql = split_sql_file($sql, $this->dbms['DELIM']); foreach ($sql as $query) @@ -419,6 +429,19 @@ class phpbb_database_test_connection_manager $queries[] = 'DROP SEQUENCE ' . current($row); } break; + + case 'postgres': + $sql = 'SELECT sequence_name + FROM information_schema.sequences'; + $result = $this->pdo->query($sql); + + while ($row = $result->fetch(PDO::FETCH_NUM)) + { + $queries[] = 'DROP SEQUENCE ' . current($row); + } + + $queries[] = 'DROP TYPE IF EXISTS varchar_ci CASCADE'; + break; } foreach ($queries as $query) -- cgit v1.2.1 From 0483971f7786b10c3359dfbe4912501de0d6c7de Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Wed, 2 Jan 2013 21:44:22 +0100 Subject: [ticket/11305] Mock container for cache driver in functional create_user() create_user has calls to fetch the cache driver from the container. This PR mocks the container and returns a null cache driver in that case. PHPBB3-11305 --- tests/test_framework/phpbb_functional_test_case.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 59979e035d..e346223a4b 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -262,7 +262,7 @@ class phpbb_functional_test_case extends phpbb_test_case $config['rand_seed_last_update'] = time() + 600; // Required by user_add - global $db, $cache, $phpbb_dispatcher; + global $db, $cache, $phpbb_dispatcher, $phpbb_container; $db = $this->get_db(); if (!function_exists('phpbb_mock_null_cache')) { @@ -270,6 +270,14 @@ class phpbb_functional_test_case extends phpbb_test_case } $cache = new phpbb_mock_null_cache; + $cache_driver = new phpbb_cache_driver_null(); + $phpbb_container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); + $phpbb_container + ->expects($this->any()) + ->method('get') + ->with('cache.driver') + ->will($this->returnValue($cache_driver)); + if (!function_exists('utf_clean_string')) { require_once(__DIR__ . '/../../phpBB/includes/utf/utf_tools.php'); -- cgit v1.2.1 From 71e07ecc471f013aec698654cf5cfa928c8ad0e8 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 10 Jan 2013 19:21:12 -0600 Subject: [ticket/11320] Include functions file as we need phpbb_convert_30_dbms_to_31 PHPBB3-11320 --- tests/test_framework/phpbb_test_case_helpers.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php index 47459832d5..20ae384f21 100644 --- a/tests/test_framework/phpbb_test_case_helpers.php +++ b/tests/test_framework/phpbb_test_case_helpers.php @@ -77,6 +77,11 @@ class phpbb_test_case_helpers { include($test_config); + if (!function_exists('phpbb_convert_30_dbms_to_31')) + { + require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; + } + $config = array_merge($config, array( 'dbms' => phpbb_convert_30_dbms_to_31($dbms), 'dbhost' => $dbhost, -- cgit v1.2.1 From 7203f39f87b7910d8565eccca2523313cacf828f Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Fri, 25 Jan 2013 17:10:43 +0100 Subject: [ticket/11295] Correct cases: replace postgres with phpbb_db_driver_postgres. PHPBB3-11295 --- tests/test_framework/phpbb_database_test_connection_manager.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_database_test_connection_manager.php b/tests/test_framework/phpbb_database_test_connection_manager.php index c9bdd185d6..29058cc815 100644 --- a/tests/test_framework/phpbb_database_test_connection_manager.php +++ b/tests/test_framework/phpbb_database_test_connection_manager.php @@ -186,7 +186,7 @@ class phpbb_database_test_connection_manager $this->purge_extras(); break; - case 'postgres': + case 'phpbb_db_driver_postgres': $this->connect(); // Drop all of the tables foreach ($this->get_tables() as $table) @@ -429,7 +429,7 @@ class phpbb_database_test_connection_manager } break; - case 'postgres': + case 'phpbb_db_driver_postgres': $sql = 'SELECT sequence_name FROM information_schema.sequences'; $result = $this->pdo->query($sql); -- cgit v1.2.1 From 8d3a82a4fa8ced50fbc1d1019ef439d1d5c81e71 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 10 Jan 2013 19:32:39 -0600 Subject: [feature/migrations] Make the container available to extension installers This allows extensions to load and install migrations easily as per their needs. PHPBB3-11318 --- tests/test_framework/phpbb_functional_test_case.php | 1 + 1 file changed, 1 insertion(+) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index e346223a4b..cb0a475278 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -137,6 +137,7 @@ class phpbb_functional_test_case extends phpbb_test_case if (!$this->extension_manager) { $this->extension_manager = new phpbb_extension_manager( + new phpbb_mock_container_builder(), $this->get_db(), new phpbb_config(array()), self::$config['table_prefix'] . 'ext', -- cgit v1.2.1 From 193a3beb8f75e17b09a0e66d2815bc2bf8d4dce4 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Wed, 13 Feb 2013 21:12:50 -0600 Subject: [feature/migrations] Fix failing tests (again) PHPBB3-11318 --- .../test_framework/phpbb_functional_test_case.php | 28 +++++++++++----------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index cb0a475278..b570b464e6 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -134,20 +134,20 @@ class phpbb_functional_test_case extends phpbb_test_case { global $phpbb_root_path, $phpEx; - if (!$this->extension_manager) - { - $this->extension_manager = new phpbb_extension_manager( - new phpbb_mock_container_builder(), - $this->get_db(), - new phpbb_config(array()), - self::$config['table_prefix'] . 'ext', - $phpbb_root_path, - ".$phpEx", - $this->get_cache_driver() - ); - } - - return $this->extension_manager; + $config = new phpbb_config(array()); + $db = $this->get_db(); + $db_tools = new phpbb_db_tools($db); + + return new phpbb_extension_manager( + new phpbb_mock_container_builder(), + $db, + $config, + new phpbb_db_migrator($config, $db, $db_tools, self::$config['table_prefix'] . 'migrations', $phpbb_root_path, $php_ext, self::$config['table_prefix'], array()), + self::$config['table_prefix'] . 'ext', + dirname(__FILE__) . '/', + '.' . $php_ext, + $this->get_cache_driver() + ); } static protected function install_board() -- cgit v1.2.1 From 8415ae839cf699e043fe24ad91585dc419596ff8 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sat, 2 Mar 2013 11:37:58 -0600 Subject: [ticket/11386] Update tests with new constructors for ext.manager/migrator PHPBB3-11386 --- tests/test_framework/phpbb_functional_test_case.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index b570b464e6..ff358033b1 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -138,16 +138,29 @@ class phpbb_functional_test_case extends phpbb_test_case $db = $this->get_db(); $db_tools = new phpbb_db_tools($db); - return new phpbb_extension_manager( + $extension_manager = new phpbb_extension_manager( new phpbb_mock_container_builder(), $db, $config, - new phpbb_db_migrator($config, $db, $db_tools, self::$config['table_prefix'] . 'migrations', $phpbb_root_path, $php_ext, self::$config['table_prefix'], array()), self::$config['table_prefix'] . 'ext', dirname(__FILE__) . '/', '.' . $php_ext, $this->get_cache_driver() ); + $migrator = new phpbb_db_migrator( + $config, + $db, + $db_tools, + $manager, + self::$config['table_prefix'] . 'migrations', + $phpbb_root_path, + $php_ext, + self::$config['table_prefix'], + array() + ); + $extension_manager->set_migrator($migrator); + + return $extension_manager; } static protected function install_board() -- cgit v1.2.1 From 91be99822312d9a83ae4f6849eef864dfd47e4a1 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sat, 2 Mar 2013 15:17:51 -0600 Subject: [ticket/11386] Fix failing tests from constructor changes PHPBB3-11386 --- tests/test_framework/phpbb_functional_test_case.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index ff358033b1..3b9629b9f8 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -151,7 +151,6 @@ class phpbb_functional_test_case extends phpbb_test_case $config, $db, $db_tools, - $manager, self::$config['table_prefix'] . 'migrations', $phpbb_root_path, $php_ext, @@ -159,6 +158,7 @@ class phpbb_functional_test_case extends phpbb_test_case array() ); $extension_manager->set_migrator($migrator); + $migrator->set_extension_manager($extension_manager); return $extension_manager; } -- cgit v1.2.1 From e4f782819968ec44f1dd207dc9de7ec703826d29 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sun, 3 Mar 2013 19:54:22 -0600 Subject: [ticket/11386] Send list of migrations instead of using load_migrations Remove dependency of extension manager for migrator. Keeping load_migrations function for others to use if they desire but requiring the finder be sent to it in order to use it. PHPBB3-11386 --- tests/test_framework/phpbb_functional_test_case.php | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 3b9629b9f8..887dfea3b5 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -138,15 +138,6 @@ class phpbb_functional_test_case extends phpbb_test_case $db = $this->get_db(); $db_tools = new phpbb_db_tools($db); - $extension_manager = new phpbb_extension_manager( - new phpbb_mock_container_builder(), - $db, - $config, - self::$config['table_prefix'] . 'ext', - dirname(__FILE__) . '/', - '.' . $php_ext, - $this->get_cache_driver() - ); $migrator = new phpbb_db_migrator( $config, $db, @@ -157,8 +148,16 @@ class phpbb_functional_test_case extends phpbb_test_case self::$config['table_prefix'], array() ); - $extension_manager->set_migrator($migrator); - $migrator->set_extension_manager($extension_manager); + $extension_manager = new phpbb_extension_manager( + new phpbb_mock_container_builder(), + $db, + $config, + $migrator, + self::$config['table_prefix'] . 'ext', + dirname(__FILE__) . '/', + '.' . $php_ext, + $this->get_cache_driver() + ); return $extension_manager; } -- cgit v1.2.1 From 15aec0bbb24be10da850f78d85a3d10880c6f28a Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Thu, 21 Mar 2013 03:07:50 +0100 Subject: [ticket/11460] Add methods for checkbox handling to phpbb_functional_test_case. PHPBB3-11460 --- .../test_framework/phpbb_functional_test_case.php | 64 ++++++++++++++++++++++ 1 file changed, 64 insertions(+) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 887dfea3b5..a62f5341ca 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -463,4 +463,68 @@ class phpbb_functional_test_case extends phpbb_test_case $this->assertGreaterThan(0, count($nodes), $msg); return $nodes; } + + /** + * Asserts that exactly one checkbox with name $name exists within the scope + * of $crawler and that the checkbox is checked. + * + * @param Symfony\Component\DomCrawler\Crawler $crawler + * @param string $name + * @param string $message + * + * @return null + */ + public function assert_checkbox_is_checked($crawler, $name, $message = '') + { + $this->assertSame( + 'checked', + $this->assert_find_one_checkbox($crawler, $name)->attr('checked'), + $message ?: "Failed asserting that checkbox $name is checked." + ); + } + + /** + * Asserts that exactly one checkbox with name $name exists within the scope + * of $crawler and that the checkbox is unchecked. + * + * @param Symfony\Component\DomCrawler\Crawler $crawler + * @param string $name + * @param string $message + * + * @return null + */ + public function assert_checkbox_is_unchecked($crawler, $name, $message = '') + { + $this->assertSame( + '', + $this->assert_find_one_checkbox($crawler, $name)->attr('checked'), + $message ?: "Failed asserting that checkbox $name is unchecked." + ); + } + + /** + * Searches for an input element of type checkbox with the name $name using + * $crawler. Contains an assertion that only one such checkbox exists within + * the scope of $crawler. + * + * @param Symfony\Component\DomCrawler\Crawler $crawler + * @param string $name + * @param string $message + * + * @return Symfony\Component\DomCrawler\Crawler + */ + public function assert_find_one_checkbox($crawler, $name, $message = '') + { + $query = sprintf('//input[@type="checkbox" and @name="%s"]', $name); + $result = $crawler->filterXPath($query); + + $this->assertEquals( + 1, + sizeof($result), + $message ?: 'Failed asserting that exactly one checkbox with name' . + " $name exists in crawler scope." + ); + + return $result; + } } -- cgit v1.2.1 From 02817158fc4209b57893eaba107f732274835fa7 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Fri, 22 Mar 2013 22:42:05 +0100 Subject: [ticket/11460] Configure functional test board email using dummy SMTP data. PHPBB3-11460 --- tests/test_framework/phpbb_functional_test_case.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index a62f5341ca..a411d9c98a 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -196,12 +196,12 @@ class phpbb_functional_test_case extends phpbb_test_case $parseURL = parse_url(self::$config['phpbb_functional_url']); $data = array_merge($data, array( - 'email_enable' => false, - 'smtp_delivery' => false, - 'smtp_host' => '', - 'smtp_auth' => '', - 'smtp_user' => '', - 'smtp_pass' => '', + 'email_enable' => true, + 'smtp_delivery' => true, + 'smtp_host' => 'nxdomain.phpbb.com', + 'smtp_auth' => '', + 'smtp_user' => 'nxuser', + 'smtp_pass' => 'nxpass', 'cookie_secure' => false, 'force_server_vars' => false, 'server_protocol' => $parseURL['scheme'] . '://', -- cgit v1.2.1 From 60713c8a203b4d92db016f38cf8d78165d72b30a Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 11 Apr 2013 14:06:08 +0200 Subject: [ticket/11492] Add functional test for empty teampage PHPBB3-11492 --- .../test_framework/phpbb_functional_test_case.php | 40 ++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index a411d9c98a..283110a104 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -316,6 +316,46 @@ class phpbb_functional_test_case extends phpbb_test_case return user_add($user_row); } + protected function remove_user_group($group_name, $usernames) + { + global $db, $cache, $auth, $config, $phpbb_dispatcher, $phpbb_container; + + $config = new phpbb_config(array()); + $config['coppa_enable'] = 0; + + $db = $this->get_db(); + + $cache = new phpbb_mock_null_cache; + + $cache_driver = new phpbb_cache_driver_null(); + $phpbb_container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); + $phpbb_container + ->expects($this->any()) + ->method('get') + ->with('cache.driver') + ->will($this->returnValue($cache_driver)); + + if (!function_exists('utf_clean_string')) + { + require_once(__DIR__ . '/../../phpBB/includes/utf/utf_tools.php'); + } + if (!function_exists('group_user_del')) + { + require_once(__DIR__ . '/../../phpBB/includes/functions_user.php'); + } + $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); + $auth = $this->getMock('Observer', array('acl_clear_prefetch')); + + $sql = 'SELECT group_id + FROM ' . GROUPS_TABLE . " + WHERE group_name = '" . $db->sql_escape($group_name) . "'"; + $result = $db->sql_query($sql); + $group_id = (int) $db->sql_fetchfield('group_id'); + $db->sql_freeresult($result); + + return group_user_del($group_id, false, $usernames, $group_name); + } + protected function login($username = 'admin') { $this->add_lang('ucp'); -- cgit v1.2.1 From 59ad90b25c50f0a4062ae5e190b27811c4c0279b Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 11 Apr 2013 15:18:47 +0200 Subject: [ticket/11492] Add tests for removing/adding users PHPBB3-11492 --- .../test_framework/phpbb_functional_test_case.php | 52 +++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 283110a104..3eba57caa7 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -318,13 +318,18 @@ class phpbb_functional_test_case extends phpbb_test_case protected function remove_user_group($group_name, $usernames) { - global $db, $cache, $auth, $config, $phpbb_dispatcher, $phpbb_container; + global $db, $cache, $auth, $config, $phpbb_dispatcher, $phpbb_log, $phpbb_container; $config = new phpbb_config(array()); $config['coppa_enable'] = 0; $db = $this->get_db(); + $phpbb_log = $this->getMock('phpbb_log'); + $phpbb_log + ->expects($this->any()) + ->method('add') + ->will($this->returnValue(true)); $cache = new phpbb_mock_null_cache; $cache_driver = new phpbb_cache_driver_null(); @@ -356,6 +361,51 @@ class phpbb_functional_test_case extends phpbb_test_case return group_user_del($group_id, false, $usernames, $group_name); } + protected function add_user_group($group_name, $usernames) + { + global $db, $cache, $auth, $config, $phpbb_dispatcher, $phpbb_log, $phpbb_container; + + $config = new phpbb_config(array()); + $config['coppa_enable'] = 0; + + $db = $this->get_db(); + + $phpbb_log = $this->getMock('phpbb_log'); + $phpbb_log + ->expects($this->any()) + ->method('add') + ->will($this->returnValue(true)); + $cache = new phpbb_mock_null_cache; + + $cache_driver = new phpbb_cache_driver_null(); + $phpbb_container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); + $phpbb_container + ->expects($this->any()) + ->method('get') + ->with('cache.driver') + ->will($this->returnValue($cache_driver)); + + if (!function_exists('utf_clean_string')) + { + require_once(__DIR__ . '/../../phpBB/includes/utf/utf_tools.php'); + } + if (!function_exists('group_user_del')) + { + require_once(__DIR__ . '/../../phpBB/includes/functions_user.php'); + } + $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); + $auth = $this->getMock('Observer', array('acl_clear_prefetch')); + + $sql = 'SELECT group_id + FROM ' . GROUPS_TABLE . " + WHERE group_name = '" . $db->sql_escape($group_name) . "'"; + $result = $db->sql_query($sql); + $group_id = (int) $db->sql_fetchfield('group_id'); + $db->sql_freeresult($result); + + return group_user_add($group_id, false, $usernames, $group_name); + } + protected function login($username = 'admin') { $this->add_lang('ucp'); -- cgit v1.2.1 From 7f527e801221bf5638acf0d46a94c0e28ec03331 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 11 Apr 2013 15:59:31 +0200 Subject: [ticket/11492] Fix issues with log object PHPBB3-11492 --- .../test_framework/phpbb_functional_test_case.php | 26 +++++++++------------- 1 file changed, 10 insertions(+), 16 deletions(-) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 3eba57caa7..db6a6066e4 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -318,18 +318,17 @@ class phpbb_functional_test_case extends phpbb_test_case protected function remove_user_group($group_name, $usernames) { - global $db, $cache, $auth, $config, $phpbb_dispatcher, $phpbb_log, $phpbb_container; + global $db, $cache, $auth, $config, $phpbb_dispatcher, $phpbb_log, $phpbb_container, $phpbb_root_path, $phpEx; $config = new phpbb_config(array()); $config['coppa_enable'] = 0; $db = $this->get_db(); + $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); + $user = $this->getMock('phpbb_user'); + $auth = $this->getMock('phpbb_auth'); - $phpbb_log = $this->getMock('phpbb_log'); - $phpbb_log - ->expects($this->any()) - ->method('add') - ->will($this->returnValue(true)); + $phpbb_log = new phpbb_log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, LOG_TABLE); $cache = new phpbb_mock_null_cache; $cache_driver = new phpbb_cache_driver_null(); @@ -348,8 +347,6 @@ class phpbb_functional_test_case extends phpbb_test_case { require_once(__DIR__ . '/../../phpBB/includes/functions_user.php'); } - $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); - $auth = $this->getMock('Observer', array('acl_clear_prefetch')); $sql = 'SELECT group_id FROM ' . GROUPS_TABLE . " @@ -363,18 +360,17 @@ class phpbb_functional_test_case extends phpbb_test_case protected function add_user_group($group_name, $usernames) { - global $db, $cache, $auth, $config, $phpbb_dispatcher, $phpbb_log, $phpbb_container; + global $db, $cache, $auth, $config, $phpbb_dispatcher, $phpbb_log, $phpbb_container, $phpbb_root_path, $phpEx; $config = new phpbb_config(array()); $config['coppa_enable'] = 0; $db = $this->get_db(); + $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); + $user = $this->getMock('phpbb_user'); + $auth = $this->getMock('phpbb_auth'); - $phpbb_log = $this->getMock('phpbb_log'); - $phpbb_log - ->expects($this->any()) - ->method('add') - ->will($this->returnValue(true)); + $phpbb_log = new phpbb_log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, LOG_TABLE); $cache = new phpbb_mock_null_cache; $cache_driver = new phpbb_cache_driver_null(); @@ -393,8 +389,6 @@ class phpbb_functional_test_case extends phpbb_test_case { require_once(__DIR__ . '/../../phpBB/includes/functions_user.php'); } - $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); - $auth = $this->getMock('Observer', array('acl_clear_prefetch')); $sql = 'SELECT group_id FROM ' . GROUPS_TABLE . " -- cgit v1.2.1 From 82a630cd648b193079cd147144ad5b035450d824 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Mon, 15 Apr 2013 20:41:05 +0530 Subject: [ticket/11493] add check for phpBB Debug in functional tests PHPBB3-11493 --- tests/test_framework/phpbb_functional_test_case.php | 1 + 1 file changed, 1 insertion(+) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 8ab6469e9a..c600cba5f8 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -349,5 +349,6 @@ class phpbb_functional_test_case extends phpbb_test_case $this->assertEquals(200, $this->client->getResponse()->getStatus()); $content = $this->client->getResponse()->getContent(); $this->assertNotContains('Fatal error:', $content); + $this->assertNotContains('[phpBB Debug]', $content); } } -- cgit v1.2.1 From 14071e6085d55f459728ade117ff93b3957045d2 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Mon, 15 Apr 2013 22:02:21 +0530 Subject: [ticket/11493] add checks for Notice and Warning PHPBB3-11493 --- tests/test_framework/phpbb_functional_test_case.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index c600cba5f8..83c931f924 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -349,6 +349,8 @@ class phpbb_functional_test_case extends phpbb_test_case $this->assertEquals(200, $this->client->getResponse()->getStatus()); $content = $this->client->getResponse()->getContent(); $this->assertNotContains('Fatal error:', $content); + $this->assertNotContains('Notice:', $content); + $this->assertNotContains('Warning:', $content); $this->assertNotContains('[phpBB Debug]', $content); } } -- cgit v1.2.1 From 423b310e2acbbc72814a4278a4cccf2900114f85 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 17 Apr 2013 18:43:19 +0200 Subject: [ticket/11362] Extension manager depends on filesystem PHPBB3-11362 --- tests/test_framework/phpbb_functional_test_case.php | 1 + 1 file changed, 1 insertion(+) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 887dfea3b5..891fe237b3 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -153,6 +153,7 @@ class phpbb_functional_test_case extends phpbb_test_case $db, $config, $migrator, + new phpbb_filesystem(), self::$config['table_prefix'] . 'ext', dirname(__FILE__) . '/', '.' . $php_ext, -- cgit v1.2.1 From f49993766e2bcf4efe346e29972f3721b1b1438a Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Wed, 24 Apr 2013 17:41:27 -0500 Subject: [ticket/11335] (more) Make php_ext 'php' not '.php' PHPBB3-11335 --- tests/test_framework/phpbb_functional_test_case.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index b9647e4742..5534de89c9 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -156,7 +156,7 @@ class phpbb_functional_test_case extends phpbb_test_case new phpbb_filesystem(), self::$config['table_prefix'] . 'ext', dirname(__FILE__) . '/', - '.' . $php_ext, + $php_ext, $this->get_cache_driver() ); -- cgit v1.2.1 From 2fa5f9591e06e82ca76e7ac7e653d8ad4494eb67 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Thu, 25 Apr 2013 22:52:40 +0530 Subject: [ticket/10325] add logout function in functional_test_case PHPBB3-10325 --- tests/test_framework/phpbb_functional_test_case.php | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 5534de89c9..dae37f336d 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -425,6 +425,17 @@ class phpbb_functional_test_case extends phpbb_test_case } } + protected function logout() + { + $this->add_lang('ucp'); + + $crawler = $this->request('GET', 'ucp.php?sid=' . $this->sid . '&mode=logout'); + $this->assert_response_success(); + $this->assertContains($this->lang('LOGOUT_REDIRECT'), $crawler->filter('#message')->text()); + unset($this->sid); + + } + /** * Login to the ACP * You must run login() before calling this. -- cgit v1.2.1 From 60e32728393d4258f92f7893f8275889278a995f Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Wed, 1 May 2013 14:09:08 -0500 Subject: [ticket/11415] Remove migrator dependency from extension manager PHPBB3-11415 --- tests/test_framework/phpbb_functional_test_case.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 5534de89c9..a11c0f72ca 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -148,8 +148,11 @@ class phpbb_functional_test_case extends phpbb_test_case self::$config['table_prefix'], array() ); + $container = new phpbb_mock_container_builder(); + $container->set('migrator', $migrator); + $extension_manager = new phpbb_extension_manager( - new phpbb_mock_container_builder(), + $container, $db, $config, $migrator, -- cgit v1.2.1 From 1b34ddb330d1a666185947ec2325732466f9ce4e Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Fri, 3 May 2013 09:02:50 -0500 Subject: [ticket/11415] Fix ext.manager constructor in tests PHPBB3-11415 --- tests/test_framework/phpbb_functional_test_case.php | 1 - 1 file changed, 1 deletion(-) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index a11c0f72ca..0157706b12 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -155,7 +155,6 @@ class phpbb_functional_test_case extends phpbb_test_case $container, $db, $config, - $migrator, new phpbb_filesystem(), self::$config['table_prefix'] . 'ext', dirname(__FILE__) . '/', -- cgit v1.2.1 From ac8e8a156a771cabcd73859f1c2235c89257e76b Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 14 May 2013 22:51:10 +0200 Subject: [ticket/11544] Add admin_login() method to 3.0 functional test case This method is needed in order to be able to properly test acp functions. PHPBB3-11544 --- .../test_framework/phpbb_functional_test_case.php | 44 ++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 83c931f924..b1352b247e 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -299,6 +299,50 @@ class phpbb_functional_test_case extends phpbb_test_case } } + /** + * 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; + } + + $crawler = $this->request('GET', 'adm/index.php?sid=' . $this->sid); + $this->assertContains($this->lang('LOGIN_ADMIN_CONFIRM'), $crawler->filter('html')->text()); + + $form = $crawler->selectButton($this->lang('LOGIN'))->form(); + + foreach ($form->getValues() as $field => $value) + { + if (strpos($field, 'password_') === 0) + { + $crawler = $this->client->submit($form, array('username' => $username, $field => $username)); + $this->assert_response_success(); + $this->assertContains($this->lang('LOGIN_ADMIN_SUCCESS'), $crawler->filter('html')->text()); + + $cookies = $this->cookieJar->all(); + + // 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->getName(), -4) == '_sid') + { + $this->sid = $cookie->getValue(); + } + } + + break; + } + } + } + protected function add_lang($lang_file) { if (is_array($lang_file)) -- cgit v1.2.1 From 56ac97e819d0a31d24120bf4f92f2547fad000a2 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Thu, 16 May 2013 09:24:16 +0300 Subject: [ticket/10772] Functional tests for forum style PHPBB3-10772 --- .../test_framework/phpbb_functional_test_case.php | 103 +++++++++++++++++++++ 1 file changed, 103 insertions(+) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 83c931f924..c2904c93e1 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -225,6 +225,109 @@ class phpbb_functional_test_case extends phpbb_test_case $db_conn_mgr->recreate_db(); } + /** + * Creates a new style + * + * @param string $style_id Style ID + * @param string $style_path Style directory + * @param string $parent_style_id Parent style id. Default = 1 + * @param string $parent_style_path Parent style directory. Default = 'prosilver' + */ + protected function add_style($style_id, $style_path, $parent_style_id = 1, $parent_style_path = 'prosilver') + { + global $phpbb_root_path; + + $db = $this->get_db(); + if (version_compare(PHPBB_VERSION, '3.1.0-dev', '<')) + { + $sql = 'INSERT INTO ' . STYLES_TABLE . ' ' . $db->sql_build_array('INSERT', array( + 'style_id' => $style_id, + 'style_name' => $style_path, + 'style_copyright' => '', + 'style_active' => 1, + 'template_id' => $style_id, + 'theme_id' => $style_id, + 'imageset_id' => $style_id, + )); + $db->sql_query($sql); + + $sql = 'INSERT INTO ' . STYLES_IMAGESET_TABLE . ' ' . $db->sql_build_array('INSERT', array( + 'imageset_id' => $style_id, + 'imageset_name' => $style_path, + 'imageset_copyright' => '', + 'imageset_path' => $style_path, + )); + $db->sql_query($sql); + + $sql = 'INSERT INTO ' . STYLES_TEMPLATE_TABLE . ' ' . $db->sql_build_array('INSERT', array( + 'template_id' => $style_id, + 'template_name' => $style_path, + 'template_copyright' => '', + 'template_path' => $style_path, + 'bbcode_bitfield' => 'kNg=', + 'template_inherits_id' => $parent_style_id, + 'template_inherit_path' => $parent_style_path, + )); + $db->sql_query($sql); + + $sql = 'INSERT INTO ' . STYLES_THEME_TABLE . ' ' . $db->sql_build_array('INSERT', array( + 'theme_id' => $style_id, + 'theme_name' => $style_path, + 'theme_copyright' => '', + 'theme_path' => $style_path, + 'theme_storedb' => 0, + 'theme_mtime' => 0, + 'theme_data' => '', + )); + $db->sql_query($sql); + + if ($style_path != 'prosilver' && $style_path != 'subsilver2') + { + @mkdir($phpbb_root_path . 'styles/' . $style_path, 0777); + @mkdir($phpbb_root_path . 'styles/' . $style_path . '/template', 0777); + } + } + else + { + $db->sql_multi_insert(STYLES_TABLE, array( + 'style_id' => $style_id, + 'style_name' => $style_path, + 'style_copyright' => '', + 'style_active' => 1, + 'style_path' => $style_path, + 'bbcode_bitfield' => 'kNg=', + 'style_parent_id' => $parent_style_id, + 'style_parent_tree' => $parent_style_path, + )); + } + } + + /** + * Remove temporary style created by add_style() + * + * @param string $style_id Style ID + * @param string $style_path Style directory + */ + protected function delete_style($style_id, $style_path) + { + global $phpbb_root_path; + + $db = $this->get_db(); + $db->sql_query('DELETE FROM ' . STYLES_TABLE . ' WHERE style_id = ' . $style_id); + if (version_compare(PHPBB_VERSION, '3.1.0-dev', '<')) + { + $db->sql_query('DELETE FROM ' . STYLES_IMAGESET_TABLE . ' WHERE imageset_id = ' . $style_id); + $db->sql_query('DELETE FROM ' . STYLES_TEMPLATE_TABLE . ' WHERE template_id = ' . $style_id); + $db->sql_query('DELETE FROM ' . STYLES_THEME_TABLE . ' WHERE theme_id = ' . $style_id); + + if ($style_path != 'prosilver' && $style_path != 'subsilver2') + { + @rmdir($phpbb_root_path . 'styles/' . $style_path . '/template'); + @rmdir($phpbb_root_path . 'styles/' . $style_path); + } + } + } + /** * Creates a new user with limited permissions * -- cgit v1.2.1 From 225aba976e0603c24d4808ad71d6b00e86326400 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Fri, 17 May 2013 01:22:22 +0200 Subject: [ticket/11547] Set MySQL charset to UTF8 in database_test_connection_manager. PHPBB3-11547 --- tests/test_framework/phpbb_database_test_connection_manager.php | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_database_test_connection_manager.php b/tests/test_framework/phpbb_database_test_connection_manager.php index 3b8c2e99ae..af7e6b1144 100644 --- a/tests/test_framework/phpbb_database_test_connection_manager.php +++ b/tests/test_framework/phpbb_database_test_connection_manager.php @@ -142,6 +142,14 @@ class phpbb_database_test_connection_manager } $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + + switch ($this->config['dbms']) + { + case 'mysql': + case 'mysqli': + $this->pdo->exec('SET NAMES utf8'); + default: + } } /** -- cgit v1.2.1 From 0a1ca4d3eafda2e9c3baa30e55d825d934f5aed4 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Fri, 17 May 2013 02:31:25 +0200 Subject: [ticket/11547] Add phpbb_db_driver_ prefix to DBMS names. PHPBB3-11547 --- tests/test_framework/phpbb_database_test_connection_manager.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_database_test_connection_manager.php b/tests/test_framework/phpbb_database_test_connection_manager.php index 237fbd9af2..a192d2922f 100644 --- a/tests/test_framework/phpbb_database_test_connection_manager.php +++ b/tests/test_framework/phpbb_database_test_connection_manager.php @@ -145,8 +145,8 @@ class phpbb_database_test_connection_manager switch ($this->config['dbms']) { - case 'mysql': - case 'mysqli': + case 'phpbb_db_driver_mysql': + case 'phpbb_db_driver_mysqli': $this->pdo->exec('SET NAMES utf8'); default: } -- cgit v1.2.1 From 38022a6999c58b310bdad43021fa66195db7bf32 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Mon, 27 May 2013 15:25:48 +0200 Subject: [ticket/11576] MySQL unit tests: Enable STRICT_TRANS_TABLES and others. PHPBB3-11576 --- .../phpbb_database_test_connection_manager.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_database_test_connection_manager.php b/tests/test_framework/phpbb_database_test_connection_manager.php index af7e6b1144..bcd52b1794 100644 --- a/tests/test_framework/phpbb_database_test_connection_manager.php +++ b/tests/test_framework/phpbb_database_test_connection_manager.php @@ -148,6 +148,20 @@ class phpbb_database_test_connection_manager case 'mysql': case 'mysqli': $this->pdo->exec('SET NAMES utf8'); + + /* + * The phpBB MySQL drivers set the STRICT_ALL_TABLES and + * STRICT_TRANS_TABLES flags/modes, so as a minimum requirement + * we want to make sure those are set for the PDO side of the + * test suite. + * + * The TRADITIONAL flag implies STRICT_ALL_TABLES and + * STRICT_TRANS_TABLES as well as other useful strictness flags + * the phpBB MySQL driver does not set. + */ + $this->pdo->exec("SET SESSION sql_mode='TRADITIONAL'"); + break; + default: } } -- cgit v1.2.1 From 5dcf028cf0791956be0a8cb5f8ea82d3cd91080a Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 26 May 2013 21:12:32 +0200 Subject: [ticket/11568] Use Goutte Client to install the board for functional tests PHPBB3-11568 --- .../test_framework/phpbb_functional_test_case.php | 144 +++++++++++++++------ 1 file changed, 105 insertions(+), 39 deletions(-) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index b1352b247e..cd3133f3a0 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -17,6 +17,9 @@ class phpbb_functional_test_case extends phpbb_test_case protected $client; protected $root_url; + static protected $static_client; + static protected $static_root_url; + protected $cache = null; protected $db = null; @@ -77,6 +80,11 @@ class phpbb_functional_test_case extends phpbb_test_case return $this->client->request($method, $this->root_url . $path); } + static public function static_request($method, $path) + { + return self::$static_client->request($method, self::$static_root_url . $path); + } + // bootstrap, called after board is set up // once per test case class // test cases can override this @@ -148,28 +156,78 @@ class phpbb_functional_test_case extends phpbb_test_case } } - // begin data - $data = array(); + $cookieJar = new CookieJar; + self::$static_client = new Goutte\Client(array(), null, $cookieJar); - $data = array_merge($data, self::$config); + // Reset the curl handle because it is 0 at this point and not a valid + // resource + self::$static_client->getClient()->getCurlMulti()->reset(true); + self::$static_root_url = self::$config['phpbb_functional_url']; - $data = array_merge($data, array( + $parseURL = parse_url(self::$config['phpbb_functional_url']); + + $crawler = self::static_request('GET', 'install/index.php?mode=install'); + self::static_assert_response_success(); + self::assertContains('Welcome to Installation', $crawler->filter('#main')->text()); + $form = $crawler->selectButton('submit')->form(); + + $crawler = self::$static_client->submit($form); + self::static_assert_response_success(); + self::assertContains('Installation compatibility', $crawler->filter('#main')->text()); + $form = $crawler->selectButton('submit')->form(); + + $crawler = self::$static_client->submit($form); + self::static_assert_response_success(); + 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'], + )); + + $crawler = self::$static_client->submit($form); + self::static_assert_response_success(); + self::assertContains('Successful connection', $crawler->filter('#main')->text()); + $form = $crawler->selectButton('submit')->form(); + + $crawler = self::$static_client->submit($form); + self::static_assert_response_success(); + self::assertContains('Administrator configuration', $crawler->filter('#main')->text()); + $form = $crawler->selectButton('submit')->form(array( 'default_lang' => 'en', 'admin_name' => 'admin', - 'admin_pass1' => 'admin', - 'admin_pass2' => 'admin', - 'board_email' => 'nobody@example.com', + 'admin_pass1' => 'adminadmin', + 'admin_pass2' => 'adminadmin', + 'board_email1' => 'nobody@example.com', + 'board_email2' => 'nobody@example.com', )); - $parseURL = parse_url(self::$config['phpbb_functional_url']); - - $data = array_merge($data, array( - 'email_enable' => false, - 'smtp_delivery' => false, - 'smtp_host' => '', - 'smtp_auth' => '', - 'smtp_user' => '', - 'smtp_pass' => '', + $crawler = self::$static_client->submit($form); + self::static_assert_response_success(); + self::assertContains('Tests passed', $crawler->filter('#main')->text()); + $form = $crawler->selectButton('submit')->form(); + + $crawler = self::$static_client->submit($form); + self::static_assert_response_success(); + self::assertContains('The configuration file has been written.', $crawler->filter('#main')->text()); + file_put_contents($phpbb_root_path . "config.$phpEx", phpbb_create_config_file_data(self::$config, self::$config['dbms'], array(), true, true)); + $form = $crawler->selectButton('submit')->form(); + + $crawler = self::$static_client->submit($form); + self::static_assert_response_success(); + 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'] . '://', @@ -177,26 +235,16 @@ class phpbb_functional_test_case extends phpbb_test_case 'server_port' => isset($parseURL['port']) ? (int) $parseURL['port'] : 80, 'script_path' => $parseURL['path'], )); - // end data - - $content = self::do_request('install'); - self::assertNotSame(false, $content); - self::assertContains('Welcome to Installation', $content); - - $content = self::do_request('create_table', $data); - self::assertNotSame(false, $content); - self::assertContains('The database tables used by phpBB', $content); - // 3.0 or 3.1 - self::assertContains('have been created and populated with some initial data.', $content); - - $content = self::do_request('config_file', $data); - self::assertNotSame(false, $content); - self::assertContains('Configuration file', $content); - file_put_contents($phpbb_root_path . "config.$phpEx", phpbb_create_config_file_data($data, self::$config['dbms'], array(), true, true)); - - $content = self::do_request('final', $data); - self::assertNotSame(false, $content); - self::assertContains('You have successfully installed', $content); + + $crawler = self::$static_client->submit($form); + self::static_assert_response_success(); + 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(); + + $crawler = self::$static_client->submit($form); + self::static_assert_response_success(); + self::assertContains('You have successfully installed', $crawler->text()); copy($phpbb_root_path . "config.$phpEx", $phpbb_root_path . "config_test.$phpEx"); } @@ -270,7 +318,7 @@ class phpbb_functional_test_case extends phpbb_test_case 'user_lang' => 'en', 'user_timezone' => 0, 'user_dateformat' => '', - 'user_password' => phpbb_hash($username), + 'user_password' => phpbb_hash($username . $username), ); return user_add($user_row); } @@ -283,7 +331,7 @@ class phpbb_functional_test_case extends phpbb_test_case $this->assertContains($this->lang('LOGIN_EXPLAIN_UCP'), $crawler->filter('html')->text()); $form = $crawler->selectButton($this->lang('LOGIN'))->form(); - $crawler = $this->client->submit($form, array('username' => $username, 'password' => $username)); + $crawler = $this->client->submit($form, array('username' => $username, 'password' => $username . $username)); $this->assert_response_success(); $this->assertContains($this->lang('LOGIN_REDIRECT'), $crawler->filter('html')->text()); @@ -323,7 +371,7 @@ class phpbb_functional_test_case extends phpbb_test_case { if (strpos($field, 'password_') === 0) { - $crawler = $this->client->submit($form, array('username' => $username, $field => $username)); + $crawler = $this->client->submit($form, array('username' => $username, $field => $username . $username)); $this->assert_response_success(); $this->assertContains($this->lang('LOGIN_ADMIN_SUCCESS'), $crawler->filter('html')->text()); @@ -397,4 +445,22 @@ class phpbb_functional_test_case extends phpbb_test_case $this->assertNotContains('Warning:', $content); $this->assertNotContains('[phpBB Debug]', $content); } + + /** + * Heuristic function to check that the response is success. + * + * When php decides to die with a fatal error, it still sends 200 OK + * status code. This assertion tries to catch that. + * + * @return null + */ + static public function static_assert_response_success() + { + self::assertEquals(200, self::$static_client->getResponse()->getStatus()); + $content = self::$static_client->getResponse()->getContent(); + self::assertNotContains('Fatal error:', $content); + self::assertNotContains('Notice:', $content); + //@todo: self::assertNotContains('Warning:', $content); + self::assertNotContains('[phpBB Debug]', $content); + } } -- cgit v1.2.1 From a3e5efc63483f06c6d66296adbd0538d59a05a21 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 26 May 2013 21:16:49 +0200 Subject: [ticket/11568] Set client manually so we can increase the cURL timeout PHPBB3-11568 --- tests/test_framework/phpbb_functional_test_case.php | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index cd3133f3a0..b622c6e284 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -158,6 +158,13 @@ class phpbb_functional_test_case extends phpbb_test_case $cookieJar = new CookieJar; self::$static_client = new Goutte\Client(array(), null, $cookieJar); + // Set client manually so we can increase the cURL timeout + self::$static_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 -- cgit v1.2.1 From f25389f94a46bb63d8688be9eef699de9853b4fc Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 26 May 2013 23:57:50 +0200 Subject: [ticket/11568] Any output before the doc type means there was an error Change is needed to allow "Warning:" in the HTML body PHPBB3-11568 --- tests/test_framework/phpbb_functional_test_case.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index b622c6e284..8a386d1db7 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -447,10 +447,9 @@ class phpbb_functional_test_case extends phpbb_test_case { $this->assertEquals(200, $this->client->getResponse()->getStatus()); $content = $this->client->getResponse()->getContent(); - $this->assertNotContains('Fatal error:', $content); - $this->assertNotContains('Notice:', $content); - $this->assertNotContains('Warning:', $content); - $this->assertNotContains('[phpBB Debug]', $content); + + // Any output before the doc type means there was an error + $this->assertEquals(0, strpos($content, 'getResponse()->getStatus()); $content = self::$static_client->getResponse()->getContent(); - self::assertNotContains('Fatal error:', $content); - self::assertNotContains('Notice:', $content); - //@todo: self::assertNotContains('Warning:', $content); - self::assertNotContains('[phpBB Debug]', $content); + + // Any output before the doc type means there was an error + self::assertEquals(0, strpos($content, ' Date: Mon, 27 May 2013 22:09:44 +0200 Subject: [ticket/11568] Only use a static version of the client PHPBB3-11568 --- .../test_framework/phpbb_functional_test_case.php | 119 +++++++++++---------- 1 file changed, 60 insertions(+), 59 deletions(-) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 8a386d1db7..0d122604fd 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -14,11 +14,8 @@ require_once __DIR__ . '/../../phpBB/includes/cache.php'; class phpbb_functional_test_case extends phpbb_test_case { - protected $client; - protected $root_url; - - static protected $static_client; - static protected $static_root_url; + static protected $client; + static protected $root_url; protected $cache = null; protected $db = null; @@ -43,6 +40,7 @@ class phpbb_functional_test_case extends phpbb_test_case parent::setUpBeforeClass(); self::$config = phpbb_test_case_helpers::get_test_config(); + self::$root_url = self::$config['phpbb_functional_url']; if (!isset(self::$config['phpbb_functional_url'])) { @@ -63,11 +61,11 @@ class phpbb_functional_test_case extends phpbb_test_case $this->bootstrap(); $this->cookieJar = new CookieJar; - $this->client = new Goutte\Client(array(), null, $this->cookieJar); + self::$client = new Goutte\Client(array(), null, $this->cookieJar); // Reset the curl handle because it is 0 at this point and not a valid // resource - $this->client->getClient()->getCurlMulti()->reset(true); - $this->root_url = self::$config['phpbb_functional_url']; + self::$client->getClient()->getCurlMulti()->reset(true); + // Clear the language array so that things // that were added in other tests are gone $this->lang = array(); @@ -75,14 +73,45 @@ class phpbb_functional_test_case extends phpbb_test_case $this->purge_cache(); } - public function request($method, $path) + /** + * Perform a request to page + * + * @param string $method HTTP Method + * @param string $path Page path, relative from phpBB root path + * @param array $form_data An array of form field values + * @param bool $skip_assert_response_success Should we skip the basic response assertions? + * @return Symfony\Component\DomCrawler\Crawler + */ + static public function request($method, $path, $form_data = array(), $skip_assert_response_success = false) { - return $this->client->request($method, $this->root_url . $path); + $crawler = self::$client->request($method, self::$root_url . $path, $form_data); + + if (!$skip_assert_response_success) + { + self::assert_response_success(); + } + + return $crawler; } - static public function static_request($method, $path) + /** + * Submits a form + * + * @param Symfony\Component\DomCrawler\Form $form A Form instance + * @param array $values An array of form field values + * @param bool $skip_assert_response_success Should we skip the basic response assertions? + * @return Symfony\Component\DomCrawler\Crawler + */ + static public function submit(Symfony\Component\DomCrawler\Form $form, array $values = array(), $skip_assert_response_success = false) { - return self::$static_client->request($method, self::$static_root_url . $path); + $crawler = self::$client->submit($form, $values); + + if (!$skip_assert_response_success) + { + self::assert_response_success(); + } + + return $crawler; } // bootstrap, called after board is set up @@ -157,9 +186,9 @@ class phpbb_functional_test_case extends phpbb_test_case } $cookieJar = new CookieJar; - self::$static_client = new Goutte\Client(array(), null, $cookieJar); + self::$client = new Goutte\Client(array(), null, $cookieJar); // Set client manually so we can increase the cURL timeout - self::$static_client->setClient(new Guzzle\Http\Client('', array( + self::$client->setClient(new Guzzle\Http\Client('', array( Guzzle\Http\Client::DISABLE_REDIRECTS => true, 'curl.options' => array( CURLOPT_TIMEOUT => 120 @@ -168,23 +197,19 @@ class phpbb_functional_test_case extends phpbb_test_case // Reset the curl handle because it is 0 at this point and not a valid // resource - self::$static_client->getClient()->getCurlMulti()->reset(true); - self::$static_root_url = self::$config['phpbb_functional_url']; + self::$client->getClient()->getCurlMulti()->reset(true); $parseURL = parse_url(self::$config['phpbb_functional_url']); - $crawler = self::static_request('GET', 'install/index.php?mode=install'); - self::static_assert_response_success(); + $crawler = self::request('GET', 'install/index.php?mode=install'); self::assertContains('Welcome to Installation', $crawler->filter('#main')->text()); $form = $crawler->selectButton('submit')->form(); - $crawler = self::$static_client->submit($form); - self::static_assert_response_success(); + $crawler = self::submit($form); self::assertContains('Installation compatibility', $crawler->filter('#main')->text()); $form = $crawler->selectButton('submit')->form(); - $crawler = self::$static_client->submit($form); - self::static_assert_response_success(); + $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 @@ -197,13 +222,11 @@ class phpbb_functional_test_case extends phpbb_test_case 'table_prefix' => self::$config['table_prefix'], )); - $crawler = self::$static_client->submit($form); - self::static_assert_response_success(); + $crawler = self::submit($form); self::assertContains('Successful connection', $crawler->filter('#main')->text()); $form = $crawler->selectButton('submit')->form(); - $crawler = self::$static_client->submit($form); - self::static_assert_response_success(); + $crawler = self::submit($form); self::assertContains('Administrator configuration', $crawler->filter('#main')->text()); $form = $crawler->selectButton('submit')->form(array( 'default_lang' => 'en', @@ -214,19 +237,16 @@ class phpbb_functional_test_case extends phpbb_test_case 'board_email2' => 'nobody@example.com', )); - $crawler = self::$static_client->submit($form); - self::static_assert_response_success(); + $crawler = self::submit($form); self::assertContains('Tests passed', $crawler->filter('#main')->text()); $form = $crawler->selectButton('submit')->form(); - $crawler = self::$static_client->submit($form); - self::static_assert_response_success(); + $crawler = self::submit($form); self::assertContains('The configuration file has been written.', $crawler->filter('#main')->text()); file_put_contents($phpbb_root_path . "config.$phpEx", phpbb_create_config_file_data(self::$config, self::$config['dbms'], array(), true, true)); $form = $crawler->selectButton('submit')->form(); - $crawler = self::$static_client->submit($form); - self::static_assert_response_success(); + $crawler = self::submit($form); 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, @@ -243,14 +263,12 @@ class phpbb_functional_test_case extends phpbb_test_case 'script_path' => $parseURL['path'], )); - $crawler = self::$static_client->submit($form); - self::static_assert_response_success(); + $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(); - $crawler = self::$static_client->submit($form); - self::static_assert_response_success(); + $crawler = self::submit($form); self::assertContains('You have successfully installed', $crawler->text()); copy($phpbb_root_path . "config.$phpEx", $phpbb_root_path . "config_test.$phpEx"); } @@ -338,7 +356,7 @@ class phpbb_functional_test_case extends phpbb_test_case $this->assertContains($this->lang('LOGIN_EXPLAIN_UCP'), $crawler->filter('html')->text()); $form = $crawler->selectButton($this->lang('LOGIN'))->form(); - $crawler = $this->client->submit($form, array('username' => $username, 'password' => $username . $username)); + $crawler = $this->submit($form, array('username' => $username, 'password' => $username . $username)); $this->assert_response_success(); $this->assertContains($this->lang('LOGIN_REDIRECT'), $crawler->filter('html')->text()); @@ -378,7 +396,7 @@ class phpbb_functional_test_case extends phpbb_test_case { if (strpos($field, 'password_') === 0) { - $crawler = $this->client->submit($form, array('username' => $username, $field => $username . $username)); + $crawler = $this->submit($form, array('username' => $username, $field => $username . $username)); $this->assert_response_success(); $this->assertContains($this->lang('LOGIN_ADMIN_SUCCESS'), $crawler->filter('html')->text()); @@ -443,29 +461,12 @@ class phpbb_functional_test_case extends phpbb_test_case * * @return null */ - public function assert_response_success() - { - $this->assertEquals(200, $this->client->getResponse()->getStatus()); - $content = $this->client->getResponse()->getContent(); - - // Any output before the doc type means there was an error - $this->assertEquals(0, strpos($content, 'getResponse()->getStatus()); - $content = self::$static_client->getResponse()->getContent(); + self::assertEquals(200, self::$client->getResponse()->getStatus()); + $content = self::$client->getResponse()->getContent(); // Any output before the doc type means there was an error - self::assertEquals(0, strpos($content, ' Date: Mon, 27 May 2013 22:25:25 +0200 Subject: [ticket/11568] Make CookieJar static aswell PHPBB3-11568 --- tests/test_framework/phpbb_functional_test_case.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 0d122604fd..1725a45e38 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -15,6 +15,7 @@ require_once __DIR__ . '/../../phpBB/includes/cache.php'; class phpbb_functional_test_case extends phpbb_test_case { static protected $client; + static protected $cookieJar; static protected $root_url; protected $cache = null; @@ -60,8 +61,8 @@ class phpbb_functional_test_case extends phpbb_test_case $this->bootstrap(); - $this->cookieJar = new CookieJar; - self::$client = new Goutte\Client(array(), null, $this->cookieJar); + 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); @@ -185,8 +186,8 @@ class phpbb_functional_test_case extends phpbb_test_case } } - $cookieJar = new CookieJar; - self::$client = new Goutte\Client(array(), null, $cookieJar); + 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, @@ -360,7 +361,7 @@ class phpbb_functional_test_case extends phpbb_test_case $this->assert_response_success(); $this->assertContains($this->lang('LOGIN_REDIRECT'), $crawler->filter('html')->text()); - $cookies = $this->cookieJar->all(); + $cookies = self::$cookieJar->all(); // The session id is stored in a cookie that ends with _sid - we assume there is only one such cookie foreach ($cookies as $cookie); @@ -400,7 +401,7 @@ class phpbb_functional_test_case extends phpbb_test_case $this->assert_response_success(); $this->assertContains($this->lang('LOGIN_ADMIN_SUCCESS'), $crawler->filter('html')->text()); - $cookies = $this->cookieJar->all(); + $cookies = self::$cookieJar->all(); // The session id is stored in a cookie that ends with _sid - we assume there is only one such cookie foreach ($cookies as $cookie); -- cgit v1.2.1 From 3d6620f0db5dbbf9b1f59ec865854a1dcd2e3179 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 28 May 2013 14:10:27 +0200 Subject: [ticket/11568] Trim the output to allow Tabs before INCLUDE overall_header PHPBB3-11568 --- tests/test_framework/phpbb_functional_test_case.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 1725a45e38..4ebe1d2d17 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -468,6 +468,6 @@ class phpbb_functional_test_case extends phpbb_test_case $content = self::$client->getResponse()->getContent(); // Any output before the doc type means there was an error - self::assertStringStartsWith(' Date: Tue, 28 May 2013 14:38:28 +0200 Subject: [ticket/11568] Allow different status codes PHPBB3-11568 --- tests/test_framework/phpbb_functional_test_case.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 4ebe1d2d17..e87f53caed 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -462,9 +462,9 @@ class phpbb_functional_test_case extends phpbb_test_case * * @return null */ - static public function assert_response_success() + static public function assert_response_success($status_code = 200) { - self::assertEquals(200, self::$client->getResponse()->getStatus()); + self::assertEquals($status_code, self::$client->getResponse()->getStatus()); $content = self::$client->getResponse()->getContent(); // Any output before the doc type means there was an error -- cgit v1.2.1 From e84fb0c6cacdd4da2542bb94e5994d1962930ca4 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 28 May 2013 14:47:24 +0200 Subject: [ticket/11568] Add method to get page content PHPBB3-11568 --- tests/test_framework/phpbb_functional_test_case.php | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index e87f53caed..63cbeb515a 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -115,6 +115,16 @@ class phpbb_functional_test_case extends phpbb_test_case return $crawler; } + /** + * Get Client Content + * + * @return string HTML page + */ + static public function get_content() + { + return self::$client->getResponse()->getContent(); + } + // bootstrap, called after board is set up // once per test case class // test cases can override this -- cgit v1.2.1 From 4f6b12ae1d4b9ac681efff0651a0007fed6942b6 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 30 May 2013 10:49:13 +0200 Subject: [ticket/develop/11568] Remove php extension parameter We don't support that in 3.1 anymore PHPBB3-11568 --- tests/test_framework/phpbb_functional_test_case.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 42d38255f7..e5e08df5fc 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -288,7 +288,7 @@ class phpbb_functional_test_case extends phpbb_test_case $crawler = self::submit($form); self::assertContains('The configuration file has been written.', $crawler->filter('#main')->text()); - file_put_contents($phpbb_root_path . "config.$phpEx", phpbb_create_config_file_data(self::$config, self::$config['dbms'], array(), true, true)); + file_put_contents($phpbb_root_path . "config.$phpEx", phpbb_create_config_file_data(self::$config, self::$config['dbms'], true, true)); $form = $crawler->selectButton('submit')->form(); $crawler = self::submit($form); -- cgit v1.2.1 From 45c91be970f6afc1a5907442cd66e6a3a42a00fc Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 30 May 2013 14:12:08 +0200 Subject: [ticket/11568] Only assert string when doctype is there at all PHPBB3-11568 --- tests/test_framework/phpbb_functional_test_case.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 63cbeb515a..304220f243 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -478,6 +478,9 @@ class phpbb_functional_test_case extends phpbb_test_case $content = self::$client->getResponse()->getContent(); // Any output before the doc type means there was an error - self::assertStringStartsWith(' Date: Thu, 30 May 2013 14:16:31 +0200 Subject: [ticket/11568] Remove unused method PHPBB3-11568 --- tests/test_framework/phpbb_functional_test_case.php | 19 ------------------- 1 file changed, 19 deletions(-) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 304220f243..04a43182ae 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -284,25 +284,6 @@ class phpbb_functional_test_case extends phpbb_test_case copy($phpbb_root_path . "config.$phpEx", $phpbb_root_path . "config_test.$phpEx"); } - static private function do_request($sub, $post_data = null) - { - $context = null; - - if ($post_data) - { - $context = stream_context_create(array( - 'http' => array( - 'method' => 'POST', - 'header' => 'Content-Type: application/x-www-form-urlencoded', - 'content' => http_build_query($post_data), - 'ignore_errors' => true, - ), - )); - } - - return file_get_contents(self::$config['phpbb_functional_url'] . 'install/index.php?mode=install&sub=' . $sub, false, $context); - } - static private function recreate_database($config) { $db_conn_mgr = new phpbb_database_test_connection_manager($config); -- cgit v1.2.1 From b7b81f64316a900d6de308d4b65f89b7b4b58e2f Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 31 May 2013 16:16:41 +0200 Subject: [ticket/11568] Use static calls for static methods PHPBB3-11568 --- tests/test_framework/phpbb_functional_test_case.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 04a43182ae..a0dceb152b 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -344,11 +344,11 @@ class phpbb_functional_test_case extends phpbb_test_case { $this->add_lang('ucp'); - $crawler = $this->request('GET', 'ucp.php'); + $crawler = self::request('GET', 'ucp.php'); $this->assertContains($this->lang('LOGIN_EXPLAIN_UCP'), $crawler->filter('html')->text()); $form = $crawler->selectButton($this->lang('LOGIN'))->form(); - $crawler = $this->submit($form, array('username' => $username, 'password' => $username . $username)); + $crawler = self::submit($form, array('username' => $username, 'password' => $username . $username)); $this->assert_response_success(); $this->assertContains($this->lang('LOGIN_REDIRECT'), $crawler->filter('html')->text()); @@ -379,7 +379,7 @@ class phpbb_functional_test_case extends phpbb_test_case return; } - $crawler = $this->request('GET', 'adm/index.php?sid=' . $this->sid); + $crawler = self::request('GET', 'adm/index.php?sid=' . $this->sid); $this->assertContains($this->lang('LOGIN_ADMIN_CONFIRM'), $crawler->filter('html')->text()); $form = $crawler->selectButton($this->lang('LOGIN'))->form(); @@ -388,7 +388,7 @@ class phpbb_functional_test_case extends phpbb_test_case { if (strpos($field, 'password_') === 0) { - $crawler = $this->submit($form, array('username' => $username, $field => $username . $username)); + $crawler = self::submit($form, array('username' => $username, $field => $username . $username)); $this->assert_response_success(); $this->assertContains($this->lang('LOGIN_ADMIN_SUCCESS'), $crawler->filter('html')->text()); -- cgit v1.2.1 From b2be82cd57fd14e354d9e9c06b0324db74b754cf Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 31 May 2013 16:19:19 +0200 Subject: [ticket/11568] Invert logic for asserting the response PHPBB3-11568 --- tests/test_framework/phpbb_functional_test_case.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index a0dceb152b..f1d282311f 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -83,11 +83,11 @@ class phpbb_functional_test_case extends phpbb_test_case * @param bool $skip_assert_response_success Should we skip the basic response assertions? * @return Symfony\Component\DomCrawler\Crawler */ - static public function request($method, $path, $form_data = array(), $skip_assert_response_success = false) + static public function request($method, $path, $form_data = array(), $assert_response_success = true) { $crawler = self::$client->request($method, self::$root_url . $path, $form_data); - if (!$skip_assert_response_success) + if ($assert_response_success) { self::assert_response_success(); } @@ -103,11 +103,11 @@ class phpbb_functional_test_case extends phpbb_test_case * @param bool $skip_assert_response_success Should we skip the basic response assertions? * @return Symfony\Component\DomCrawler\Crawler */ - static public function submit(Symfony\Component\DomCrawler\Form $form, array $values = array(), $skip_assert_response_success = false) + static public function submit(Symfony\Component\DomCrawler\Form $form, array $values = array(), $assert_response_success = true) { $crawler = self::$client->submit($form, $values); - if (!$skip_assert_response_success) + if ($assert_response_success) { self::assert_response_success(); } -- cgit v1.2.1 From 09a3877ae4c5bda66f22d89408b589ea8b56f380 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 31 May 2013 16:20:20 +0200 Subject: [ticket/11568] Add comma at end of array key-value couple PHPBB3-11568 --- tests/test_framework/phpbb_functional_test_case.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index f1d282311f..5416125f42 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -202,7 +202,7 @@ class phpbb_functional_test_case extends phpbb_test_case self::$client->setClient(new Guzzle\Http\Client('', array( Guzzle\Http\Client::DISABLE_REDIRECTS => true, 'curl.options' => array( - CURLOPT_TIMEOUT => 120 + CURLOPT_TIMEOUT => 120, ), ))); -- cgit v1.2.1 From 6af5262fcccae3f3e651348a20dbbd8a78e191aa Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 31 May 2013 16:27:52 +0200 Subject: [ticket/11568] Split status code and html debug assertion into two methods PHPBB3-11568 --- .../test_framework/phpbb_functional_test_case.php | 48 ++++++++++++++-------- 1 file changed, 30 insertions(+), 18 deletions(-) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 5416125f42..651ab013c7 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -80,16 +80,16 @@ class phpbb_functional_test_case extends phpbb_test_case * @param string $method HTTP Method * @param string $path Page path, relative from phpBB root path * @param array $form_data An array of form field values - * @param bool $skip_assert_response_success Should we skip the basic response assertions? + * @param bool $assert_response_html Should we perform standard assertions for a normal html page * @return Symfony\Component\DomCrawler\Crawler */ - static public function request($method, $path, $form_data = array(), $assert_response_success = true) + static public function request($method, $path, $form_data = array(), $assert_response_html = true) { $crawler = self::$client->request($method, self::$root_url . $path, $form_data); - if ($assert_response_success) + if ($assert_response_html) { - self::assert_response_success(); + self::assert_response_html(); } return $crawler; @@ -100,16 +100,16 @@ class phpbb_functional_test_case extends phpbb_test_case * * @param Symfony\Component\DomCrawler\Form $form A Form instance * @param array $values An array of form field values - * @param bool $skip_assert_response_success Should we skip the basic response assertions? + * @param bool $assert_response_html Should we perform standard assertions for a normal html page * @return Symfony\Component\DomCrawler\Crawler */ - static public function submit(Symfony\Component\DomCrawler\Form $form, array $values = array(), $assert_response_success = true) + static public function submit(Symfony\Component\DomCrawler\Form $form, array $values = array(), $assert_response_html = true) { $crawler = self::$client->submit($form, $values); - if ($assert_response_success) + if ($assert_response_html) { - self::assert_response_success(); + self::assert_response_html(); } return $crawler; @@ -349,7 +349,6 @@ class phpbb_functional_test_case extends phpbb_test_case $form = $crawler->selectButton($this->lang('LOGIN'))->form(); $crawler = self::submit($form, array('username' => $username, 'password' => $username . $username)); - $this->assert_response_success(); $this->assertContains($this->lang('LOGIN_REDIRECT'), $crawler->filter('html')->text()); $cookies = self::$cookieJar->all(); @@ -389,7 +388,6 @@ class phpbb_functional_test_case extends phpbb_test_case if (strpos($field, 'password_') === 0) { $crawler = self::submit($form, array('username' => $username, $field => $username . $username)); - $this->assert_response_success(); $this->assertContains($this->lang('LOGIN_ADMIN_SUCCESS'), $crawler->filter('html')->text()); $cookies = self::$cookieJar->all(); @@ -445,23 +443,37 @@ class phpbb_functional_test_case extends phpbb_test_case return call_user_func_array('sprintf', $args); } + /** + * Perform some basic assertions for the page + * + * Checks for debug/error output before the actual page content and the status code + * + * @param mixed $status_code Expected status code, false to disable check + * @return null + */ + static public function assert_response_html($status_code = 200) + { + if ($status_code !== false) + { + self::assert_response_status_code($status_code); + } + + // Any output before the doc type means there was an error + $content = self::$client->getResponse()->getContent(); + self::assertStringStartsWith('getResponse()->getStatus()); - $content = self::$client->getResponse()->getContent(); - - // Any output before the doc type means there was an error - if (strpos($content, ' Date: Tue, 4 Jun 2013 17:16:22 +0200 Subject: [ticket/11538] Add admin as admins leader and moderator in memberlist_test Removing the admin user from the admin and moderator group in memberlist_test potentially breaks other tests, i.e. the ucp groups test. PHPBB3-11538 --- tests/test_framework/phpbb_functional_test_case.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 660234f3ed..923cb16d37 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -361,7 +361,7 @@ class phpbb_functional_test_case extends phpbb_test_case return group_user_del($group_id, false, $usernames, $group_name); } - protected function add_user_group($group_name, $usernames) + protected function add_user_group($group_name, $usernames, $default = false, $leader = false) { global $db, $cache, $auth, $config, $phpbb_dispatcher, $phpbb_log, $phpbb_container, $phpbb_root_path, $phpEx; @@ -400,7 +400,7 @@ class phpbb_functional_test_case extends phpbb_test_case $group_id = (int) $db->sql_fetchfield('group_id'); $db->sql_freeresult($result); - return group_user_add($group_id, false, $usernames, $group_name); + return group_user_add($group_id, false, $usernames, $group_name, $default, $leader); } protected function login($username = 'admin') -- cgit v1.2.1 From 228c1075b765e8d51a997935bf12f973ae02264e Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 7 Jun 2013 01:31:20 +0200 Subject: [ticket/11590] Close database connections when tearDown() is called PHPBB3-11590 --- tests/test_framework/phpbb_database_test_case.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_database_test_case.php b/tests/test_framework/phpbb_database_test_case.php index 429bb92bf1..beddece470 100644 --- a/tests/test_framework/phpbb_database_test_case.php +++ b/tests/test_framework/phpbb_database_test_case.php @@ -11,6 +11,8 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test { static private $already_connected; + private $db_connections; + protected $test_case_helpers; protected $fixture_xml_data; @@ -28,6 +30,22 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test 'phpbb_database_test_case' => array('already_connected'), ); + + $this->db_connections = array(); + } + + protected function tearDown() + { + parent::tearDown(); + + // Close all database connections from this test + if (!empty($this->db_connections)) + { + foreach ($this->db_connections as $db) + { + $db->sql_close(); + } + } } protected function setUp() @@ -123,6 +141,8 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test $db = new $dbal(); $db->sql_connect($config['dbhost'], $config['dbuser'], $config['dbpasswd'], $config['dbname'], $config['dbport']); + $this->db_connections[] = $db; + return $db; } -- cgit v1.2.1 From c8ee6cb0c200b7e64ebbae11806f4daddfd8d93d Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 8 Jun 2013 17:00:27 +0200 Subject: [ticket/11550] Move functionality for copying/restoring to test case helpers PHPBB3-11550 --- tests/test_framework/phpbb_test_case_helpers.php | 44 ++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php index 20ae384f21..0e0b5c2a8f 100644 --- a/tests/test_framework/phpbb_test_case_helpers.php +++ b/tests/test_framework/phpbb_test_case_helpers.php @@ -18,6 +18,50 @@ class phpbb_test_case_helpers $this->test_case = $test_case; } + private $copied_files = array(); + + public function copy_ext_fixtures($fixtures_dir, $fixtures) + { + global $phpbb_root_path; + + $this->copied_files = array(); + + if (file_exists($phpbb_root_path . 'ext/')) + { + // First, move any extensions setup on the board to a temp directory + $this->copied_files = $this->copy_dir($phpbb_root_path . 'ext/', $phpbb_root_path . 'store/temp_ext/'); + + // Then empty the ext/ directory on the board (for accurate test cases) + $this->empty_dir($phpbb_root_path . 'ext/'); + } + + // Copy our ext/ files from the test case to the board + foreach ($fixtures as $fixture) + { + $this->copied_files = array_merge($this->copied_files, $this->copy_dir($fixtures_dir . 'ext/' . $fixture, $phpbb_root_path . 'ext/' . $fixture)); + } + } + + public function restore_original_ext_dir() + { + global $phpbb_root_path; + + // Copy back the board installed extensions from the temp directory + if (file_exists($phpbb_root_path . 'store/temp_ext/')) + { + $this->copy_dir($phpbb_root_path . 'store/temp_ext/', $phpbb_root_path . 'ext/'); + } + + // Remove all of the files we copied around (from board ext -> temp_ext, from test ext -> board ext) + $this->remove_files($this->copied_files); + $this->copied_files = array(); + + if (file_exists($phpbb_root_path . 'store/temp_ext/')) + { + $this->empty_dir($phpbb_root_path . 'store/temp_ext/'); + } + } + public function setExpectedTriggerError($errno, $message = '') { $exceptionName = ''; -- cgit v1.2.1 From a61ab1e5e4bbe786d3f500438bb0dd6ca395989e Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 8 Jun 2013 17:02:31 +0200 Subject: [ticket/11550] Use new functionality from the test case helpers Instead of duplicating the extension copy code, it is now in the helpers. So we remove the code from existing tests. PHPBB3-11550 --- tests/test_framework/phpbb_test_case_helpers.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php index 0e0b5c2a8f..367bd3b142 100644 --- a/tests/test_framework/phpbb_test_case_helpers.php +++ b/tests/test_framework/phpbb_test_case_helpers.php @@ -38,7 +38,7 @@ class phpbb_test_case_helpers // Copy our ext/ files from the test case to the board foreach ($fixtures as $fixture) { - $this->copied_files = array_merge($this->copied_files, $this->copy_dir($fixtures_dir . 'ext/' . $fixture, $phpbb_root_path . 'ext/' . $fixture)); + $this->copied_files = array_merge($this->copied_files, $this->copy_dir($fixtures_dir . $fixture, $phpbb_root_path . 'ext/' . $fixture)); } } -- cgit v1.2.1 From 68d15f0f14dfdc827e1169a73c194a9e30795605 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 11 Jun 2013 11:14:24 +0200 Subject: [ticket/11550] Move comments to correct function PHPBB3-11550 --- tests/test_framework/phpbb_test_case_helpers.php | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php index 367bd3b142..1b08f2368f 100644 --- a/tests/test_framework/phpbb_test_case_helpers.php +++ b/tests/test_framework/phpbb_test_case_helpers.php @@ -20,6 +20,10 @@ class phpbb_test_case_helpers private $copied_files = array(); + /** + * This should only be called once before the tests are run. + * This is used to copy the fixtures to the phpBB install + */ public function copy_ext_fixtures($fixtures_dir, $fixtures) { global $phpbb_root_path; @@ -42,6 +46,10 @@ class phpbb_test_case_helpers } } + /** + * This should only be called once after the tests are run. + * This is used to remove the fixtures from the phpBB install + */ public function restore_original_ext_dir() { global $phpbb_root_path; -- cgit v1.2.1 From 5e8054f04598c449799a594fcb96cfeb8abf925a Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 11 Jun 2013 13:24:55 +0200 Subject: [ticket/11601] Split post_setup_synchronisation logic from xml parsing PHPBB3-11601 --- .../phpbb_database_test_connection_manager.php | 27 +++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_database_test_connection_manager.php b/tests/test_framework/phpbb_database_test_connection_manager.php index bcd52b1794..30f1fa6589 100644 --- a/tests/test_framework/phpbb_database_test_connection_manager.php +++ b/tests/test_framework/phpbb_database_test_connection_manager.php @@ -480,12 +480,33 @@ class phpbb_database_test_connection_manager * @return null */ public function post_setup_synchronisation($xml_data_set) + { + $table_names = $xml_data_set->getTableNames(); + + $tables = array(); + foreach ($table_names as $table) + { + $tables[$table] = $xml_data_set->getTableMetaData($table)->getColumns(); + } + + $this->database_synchronisation($tables); + } + + /** + * Performs synchronisations on the database after a fixture has been loaded + * + * @param array $table_column_map Array of tables/columns to synchronise + * array(table1 => array(column1, column2)) + * + * @return null + */ + public function database_synchronisation($table_column_map) { $this->ensure_connected(__METHOD__); $queries = array(); - // Get escaped versions of the table names used in the fixture - $table_names = array_map(array($this->pdo, 'PDO::quote'), $xml_data_set->getTableNames()); + // Get escaped versions of the table names to synchronise + $table_names = array_map(array($this->pdo, 'PDO::quote'), array_keys($table_column_map)); switch ($this->config['dbms']) { @@ -542,7 +563,7 @@ class phpbb_database_test_connection_manager while ($row = $result->fetch(PDO::FETCH_ASSOC)) { // Get the columns used in the fixture for this table - $column_names = $xml_data_set->getTableMetaData($row['table_name'])->getColumns(); + $column_names = $table_column_map[$row['table_name']]; // Skip sequences that weren't specified in the fixture if (!in_array($row['column_name'], $column_names)) -- cgit v1.2.1 From 33bce3fac6c29787e121e5d000251353637dd422 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 11 Jun 2013 13:26:17 +0200 Subject: [ticket/11601] Add protected method for database sync and call it PHPBB3-11601 --- tests/test_framework/phpbb_database_test_case.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_database_test_case.php b/tests/test_framework/phpbb_database_test_case.php index beddece470..28d3a716f0 100644 --- a/tests/test_framework/phpbb_database_test_case.php +++ b/tests/test_framework/phpbb_database_test_case.php @@ -62,6 +62,21 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test } } + /** + * Performs synchronisations for a given table/column set on the database + * + * @param array $table_column_map Information about the tables/columns to synchronise + * + * @return null + */ + protected function database_synchronisation($table_column_map) + { + $config = $this->get_database_config(); + $manager = $this->create_connection_manager($config); + $manager->connect(); + $manager->database_synchronisation($table_column_map); + } + public function createXMLDataSet($path) { $db_config = $this->get_database_config(); -- cgit v1.2.1 From d02f98c63530454700661fc80354d66207ed8b02 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 11 Jun 2013 16:03:34 +0200 Subject: [ticket/11605] Use empty_dir to better delete files and dirs of extensions PHPBB3-11605 --- tests/test_framework/phpbb_test_case_helpers.php | 29 +++++------------------- 1 file changed, 6 insertions(+), 23 deletions(-) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php index 1b08f2368f..8c91d357b8 100644 --- a/tests/test_framework/phpbb_test_case_helpers.php +++ b/tests/test_framework/phpbb_test_case_helpers.php @@ -54,14 +54,18 @@ class phpbb_test_case_helpers { global $phpbb_root_path; + // Remove all of the files we copied from test ext -> board ext + $this->empty_dir($phpbb_root_path . 'ext/'); + // Copy back the board installed extensions from the temp directory if (file_exists($phpbb_root_path . 'store/temp_ext/')) { $this->copy_dir($phpbb_root_path . 'store/temp_ext/', $phpbb_root_path . 'ext/'); + + // Remove all of the files we copied from board ext -> temp_ext + $this->empty_dir($phpbb_root_path . 'store/temp_ext/'); } - // Remove all of the files we copied around (from board ext -> temp_ext, from test ext -> board ext) - $this->remove_files($this->copied_files); $this->copied_files = array(); if (file_exists($phpbb_root_path . 'store/temp_ext/')) @@ -254,27 +258,6 @@ class phpbb_test_case_helpers return $copied_files; } - /** - * Remove files/directories that are listed in an array - * Designed for use with $this->copy_dir() - * - * @param array $file_list - */ - public function remove_files($file_list) - { - foreach ($file_list as $file) - { - if (is_dir($file)) - { - rmdir($file); - } - else - { - unlink($file); - } - } - } - /** * Empty directory (remove any subdirectories/files below) * -- cgit v1.2.1 From fa8d5c7d209b616e9552e072e38242ef4e74aaca Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 11 Jun 2013 16:04:23 +0200 Subject: [ticket/11605] Remove unused copied_files property PHPBB3-11605 --- tests/test_framework/phpbb_test_case_helpers.php | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php index 8c91d357b8..50b2bf03ec 100644 --- a/tests/test_framework/phpbb_test_case_helpers.php +++ b/tests/test_framework/phpbb_test_case_helpers.php @@ -18,8 +18,6 @@ class phpbb_test_case_helpers $this->test_case = $test_case; } - private $copied_files = array(); - /** * This should only be called once before the tests are run. * This is used to copy the fixtures to the phpBB install @@ -28,12 +26,10 @@ class phpbb_test_case_helpers { global $phpbb_root_path; - $this->copied_files = array(); - if (file_exists($phpbb_root_path . 'ext/')) { // First, move any extensions setup on the board to a temp directory - $this->copied_files = $this->copy_dir($phpbb_root_path . 'ext/', $phpbb_root_path . 'store/temp_ext/'); + $this->copy_dir($phpbb_root_path . 'ext/', $phpbb_root_path . 'store/temp_ext/'); // Then empty the ext/ directory on the board (for accurate test cases) $this->empty_dir($phpbb_root_path . 'ext/'); @@ -42,7 +38,7 @@ class phpbb_test_case_helpers // Copy our ext/ files from the test case to the board foreach ($fixtures as $fixture) { - $this->copied_files = array_merge($this->copied_files, $this->copy_dir($fixtures_dir . $fixture, $phpbb_root_path . 'ext/' . $fixture)); + $this->copy_dir($fixtures_dir . $fixture, $phpbb_root_path . 'ext/' . $fixture); } } @@ -66,8 +62,6 @@ class phpbb_test_case_helpers $this->empty_dir($phpbb_root_path . 'store/temp_ext/'); } - $this->copied_files = array(); - if (file_exists($phpbb_root_path . 'store/temp_ext/')) { $this->empty_dir($phpbb_root_path . 'store/temp_ext/'); -- cgit v1.2.1 From 516581c41edaa5f565ef90bac14cdbdc054e7914 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Tue, 18 Jun 2013 15:04:48 +0200 Subject: [ticket/11604] Use variables for config.php filesnames. PHPBB3-11604 --- tests/test_framework/phpbb_functional_test_case.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 651ab013c7..1b47cbe125 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -184,15 +184,19 @@ class phpbb_functional_test_case extends phpbb_test_case self::$config['table_prefix'] = 'phpbb_'; self::recreate_database(self::$config); - if (file_exists($phpbb_root_path . "config.$phpEx")) + $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($phpbb_root_path . "config_dev.$phpEx")) + if (!file_exists($config_file_dev)) { - rename($phpbb_root_path . "config.$phpEx", $phpbb_root_path . "config_dev.$phpEx"); + rename($config_file, $config_file_dev); } else { - unlink($phpbb_root_path . "config.$phpEx"); + unlink($config_file); } } @@ -254,7 +258,7 @@ class phpbb_functional_test_case extends phpbb_test_case $crawler = self::submit($form); self::assertContains('The configuration file has been written.', $crawler->filter('#main')->text()); - file_put_contents($phpbb_root_path . "config.$phpEx", phpbb_create_config_file_data(self::$config, self::$config['dbms'], array(), true, true)); + file_put_contents($config_file, phpbb_create_config_file_data(self::$config, self::$config['dbms'], array(), true, true)); $form = $crawler->selectButton('submit')->form(); $crawler = self::submit($form); @@ -281,7 +285,7 @@ class phpbb_functional_test_case extends phpbb_test_case $crawler = self::submit($form); self::assertContains('You have successfully installed', $crawler->text()); - copy($phpbb_root_path . "config.$phpEx", $phpbb_root_path . "config_test.$phpEx"); + copy($config_file, $config_file_test); } static private function recreate_database($config) -- cgit v1.2.1 From 21f839494ddb55d1c4aefeed113b5debe9b2e1b3 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Tue, 18 Jun 2013 15:21:28 +0200 Subject: [ticket/11604] Fix case where config.php is not generated by phpBB. PHPBB3-11604 --- .../test_framework/phpbb_functional_test_case.php | 24 +++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 1b47cbe125..16ed9f5a1e 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -257,8 +257,30 @@ class phpbb_functional_test_case extends phpbb_test_case $form = $crawler->selectButton('submit')->form(); $crawler = self::submit($form); + $config_writable = strpos($crawler->filter('#main')->text(), 'It was not possible to write the configuration file.') === false; + $config_php_data = phpbb_create_config_file_data(self::$config, self::$config['dbms'], array(), true, true); + + if (!$config_writable) + { + // phpBB could not write to the config.php file, so we have to "Download" it. + self::assertContains('Download config', $crawler->filter('#main')->text()); + + file_put_contents($config_file, $config_php_data); + + $form = $crawler->selectButton('dldone')->form(); + $crawler = self::submit($form); + } + self::assertContains('The configuration file has been written.', $crawler->filter('#main')->text()); - file_put_contents($config_file, phpbb_create_config_file_data(self::$config, self::$config['dbms'], array(), true, true)); + + // Overwrite the config.php file generated by phpBB in order to get the + // DEBUG constants defined if possible. It should be possible when unit + // tests run as the same user as phpBB. + if ($config_writable && is_writable($config_file)) + { + file_put_contents($config_file, $config_php_data); + } + $form = $crawler->selectButton('submit')->form(); $crawler = self::submit($form); -- cgit v1.2.1 From 1af6dc22e2ccb13b610a932a9b043d2d9d4ea17d Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 19 Jun 2013 17:03:41 +0200 Subject: [ticket/11604] Skip installer step where config.php is created. PHPBB3-11604 --- .../test_framework/phpbb_functional_test_case.php | 47 +++++++++++++--------- 1 file changed, 27 insertions(+), 20 deletions(-) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 16ed9f5a1e..6b423b56fd 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -220,10 +220,12 @@ class phpbb_functional_test_case extends phpbb_test_case 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( @@ -237,10 +239,12 @@ class phpbb_functional_test_case extends phpbb_test_case '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( @@ -252,38 +256,38 @@ class phpbb_functional_test_case extends phpbb_test_case 'board_email2' => '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(); - $crawler = self::submit($form); - $config_writable = strpos($crawler->filter('#main')->text(), 'It was not possible to write the configuration file.') === false; + // 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'], array(), true, true); - - if (!$config_writable) + $config_created = file_put_contents($config_file, $config_php_data) !== false; + if (!$config_created) { - // phpBB could not write to the config.php file, so we have to "Download" it. - self::assertContains('Download config', $crawler->filter('#main')->text()); - - file_put_contents($config_file, $config_php_data); - - $form = $crawler->selectButton('dldone')->form(); - $crawler = self::submit($form); + self::markTestSkipped("Could not write $config_file file."); } - self::assertContains('The configuration file has been written.', $crawler->filter('#main')->text()); - - // Overwrite the config.php file generated by phpBB in order to get the - // DEBUG constants defined if possible. It should be possible when unit - // tests run as the same user as phpBB. - if ($config_writable && is_writable($config_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) { - file_put_contents($config_file, $config_php_data); + self::markTestSkipped("Could not create $lock_created file."); } + @chmod($install_lock_file, 0666); - $form = $crawler->selectButton('submit')->form(); + // install/index.php?mode=install&sub=advanced + $form_data = $form->getValues(); + unset($form_data['submit']); - $crawler = self::submit($form); + $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, @@ -300,13 +304,16 @@ class phpbb_functional_test_case extends phpbb_test_case '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); } -- cgit v1.2.1 From 1f989c6be774d88ffff8a8d5ac1da58f442f6174 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Thu, 27 Jun 2013 00:57:34 +0530 Subject: [ticket/9341] Move create_topic and post into functional test case create_topic and create_post are moved into functional test case so that they can be used by other tests as well PHPBB3-9341 --- .../test_framework/phpbb_functional_test_case.php | 101 +++++++++++++++++++++ 1 file changed, 101 insertions(+) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 97fe147d8e..ece42c5fff 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -703,4 +703,105 @@ class phpbb_functional_test_case extends phpbb_test_case return $result; } + + /** + * Creates a topic + * + * Be sure to login before creating + * + * @param int $forum_id + * @param string $subject + * @param string $message + * @param array $additional_form_data Any additional form data to be sent in the request + * @return array post_id, topic_id + */ + public function create_topic($forum_id, $subject, $message, $additional_form_data = array()) + { + $posting_url = "posting.php?mode=post&f={$forum_id}&sid={$this->sid}"; + + $form_data = array_merge(array( + 'subject' => $subject, + 'message' => $message, + 'post' => true, + ), $additional_form_data); + + return self::submit_post($posting_url, 'POST_TOPIC', $form_data); + } + + /** + * Creates a post + * + * Be sure to login before creating + * + * @param int $forum_id + * @param string $subject + * @param string $message + * @param array $additional_form_data Any additional form data to be sent in the request + * @return array post_id, topic_id + */ + public function create_post($forum_id, $topic_id, $subject, $message, $additional_form_data = array()) + { + $posting_url = "posting.php?mode=reply&f={$forum_id}&t={$topic_id}&sid={$this->sid}"; + + $form_data = array_merge(array( + 'subject' => $subject, + 'message' => $message, + 'post' => true, + ), $additional_form_data); + + return self::submit_post($posting_url, 'POST_REPLY', $form_data); + } + + /** + * Helper for submitting posts + * + * @param string $posting_url + * @param string $posting_contains + * @param array $form_data + * @return array post_id, topic_id + */ + protected function submit_post($posting_url, $posting_contains, $form_data) + { + $this->add_lang('posting'); + + $crawler = self::request('GET', $posting_url); + $this->assertContains($this->lang($posting_contains), $crawler->filter('html')->text()); + + $hidden_fields = array( + $crawler->filter('[type="hidden"]')->each(function ($node, $i) { + return array('name' => $node->getAttribute('name'), 'value' => $node->getAttribute('value')); + }), + ); + + foreach ($hidden_fields as $fields) + { + foreach($fields as $field) + { + $form_data[$field['name']] = $field['value']; + } + } + + // Bypass time restriction that said that if the lastclick time (i.e. time when the form was opened) + // is not at least 2 seconds before submission, cancel the form + $form_data['lastclick'] = 0; + + // I use a request because the form submission method does not allow you to send data that is not + // contained in one of the actual form fields that the browser sees (i.e. it ignores "hidden" inputs) + // Instead, I send it as a request with the submit button "post" set to true. + $crawler = self::request('POST', $posting_url, $form_data); + $this->assertContains($this->lang('POST_STORED'), $crawler->filter('html')->text()); + + $url = $crawler->selectLink($this->lang('VIEW_MESSAGE', '', ''))->link()->getUri(); + + $matches = $topic_id = $post_id = false; + preg_match_all('#&t=([0-9]+)(&p=([0-9]+))?#', $url, $matches); + + $topic_id = (int) (isset($matches[1][0])) ? $matches[1][0] : 0; + $post_id = (int) (isset($matches[3][0])) ? $matches[3][0] : 0; + + return array( + 'topic_id' => $topic_id, + 'post_id' => $post_id, + ); + } } -- cgit v1.2.1 From 335d48775f66c49940429b3e4b2ab711febdf5f5 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Thu, 11 Jul 2013 12:12:47 -0400 Subject: [ticket/10772] Remove 3.1 code PHPBB3-10772 --- .../test_framework/phpbb_functional_test_case.php | 121 +++++++++------------ 1 file changed, 51 insertions(+), 70 deletions(-) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 4b08a1af72..684d7a84cb 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -336,67 +336,51 @@ class phpbb_functional_test_case extends phpbb_test_case global $phpbb_root_path; $db = $this->get_db(); - if (version_compare(PHPBB_VERSION, '3.1.0-dev', '<')) - { - $sql = 'INSERT INTO ' . STYLES_TABLE . ' ' . $db->sql_build_array('INSERT', array( - 'style_id' => $style_id, - 'style_name' => $style_path, - 'style_copyright' => '', - 'style_active' => 1, - 'template_id' => $style_id, - 'theme_id' => $style_id, - 'imageset_id' => $style_id, - )); - $db->sql_query($sql); - - $sql = 'INSERT INTO ' . STYLES_IMAGESET_TABLE . ' ' . $db->sql_build_array('INSERT', array( - 'imageset_id' => $style_id, - 'imageset_name' => $style_path, - 'imageset_copyright' => '', - 'imageset_path' => $style_path, - )); - $db->sql_query($sql); - - $sql = 'INSERT INTO ' . STYLES_TEMPLATE_TABLE . ' ' . $db->sql_build_array('INSERT', array( - 'template_id' => $style_id, - 'template_name' => $style_path, - 'template_copyright' => '', - 'template_path' => $style_path, - 'bbcode_bitfield' => 'kNg=', - 'template_inherits_id' => $parent_style_id, - 'template_inherit_path' => $parent_style_path, - )); - $db->sql_query($sql); - - $sql = 'INSERT INTO ' . STYLES_THEME_TABLE . ' ' . $db->sql_build_array('INSERT', array( - 'theme_id' => $style_id, - 'theme_name' => $style_path, - 'theme_copyright' => '', - 'theme_path' => $style_path, - 'theme_storedb' => 0, - 'theme_mtime' => 0, - 'theme_data' => '', - )); - $db->sql_query($sql); - - if ($style_path != 'prosilver' && $style_path != 'subsilver2') - { - @mkdir($phpbb_root_path . 'styles/' . $style_path, 0777); - @mkdir($phpbb_root_path . 'styles/' . $style_path . '/template', 0777); - } - } - else + $sql = 'INSERT INTO ' . STYLES_TABLE . ' ' . $db->sql_build_array('INSERT', array( + 'style_id' => $style_id, + 'style_name' => $style_path, + 'style_copyright' => '', + 'style_active' => 1, + 'template_id' => $style_id, + 'theme_id' => $style_id, + 'imageset_id' => $style_id, + )); + $db->sql_query($sql); + + $sql = 'INSERT INTO ' . STYLES_IMAGESET_TABLE . ' ' . $db->sql_build_array('INSERT', array( + 'imageset_id' => $style_id, + 'imageset_name' => $style_path, + 'imageset_copyright' => '', + 'imageset_path' => $style_path, + )); + $db->sql_query($sql); + + $sql = 'INSERT INTO ' . STYLES_TEMPLATE_TABLE . ' ' . $db->sql_build_array('INSERT', array( + 'template_id' => $style_id, + 'template_name' => $style_path, + 'template_copyright' => '', + 'template_path' => $style_path, + 'bbcode_bitfield' => 'kNg=', + 'template_inherits_id' => $parent_style_id, + 'template_inherit_path' => $parent_style_path, + )); + $db->sql_query($sql); + + $sql = 'INSERT INTO ' . STYLES_THEME_TABLE . ' ' . $db->sql_build_array('INSERT', array( + 'theme_id' => $style_id, + 'theme_name' => $style_path, + 'theme_copyright' => '', + 'theme_path' => $style_path, + 'theme_storedb' => 0, + 'theme_mtime' => 0, + 'theme_data' => '', + )); + $db->sql_query($sql); + + if ($style_path != 'prosilver' && $style_path != 'subsilver2') { - $db->sql_multi_insert(STYLES_TABLE, array( - 'style_id' => $style_id, - 'style_name' => $style_path, - 'style_copyright' => '', - 'style_active' => 1, - 'style_path' => $style_path, - 'bbcode_bitfield' => 'kNg=', - 'style_parent_id' => $parent_style_id, - 'style_parent_tree' => $parent_style_path, - )); + @mkdir($phpbb_root_path . 'styles/' . $style_path, 0777); + @mkdir($phpbb_root_path . 'styles/' . $style_path . '/template', 0777); } } @@ -412,17 +396,14 @@ class phpbb_functional_test_case extends phpbb_test_case $db = $this->get_db(); $db->sql_query('DELETE FROM ' . STYLES_TABLE . ' WHERE style_id = ' . $style_id); - if (version_compare(PHPBB_VERSION, '3.1.0-dev', '<')) - { - $db->sql_query('DELETE FROM ' . STYLES_IMAGESET_TABLE . ' WHERE imageset_id = ' . $style_id); - $db->sql_query('DELETE FROM ' . STYLES_TEMPLATE_TABLE . ' WHERE template_id = ' . $style_id); - $db->sql_query('DELETE FROM ' . STYLES_THEME_TABLE . ' WHERE theme_id = ' . $style_id); + $db->sql_query('DELETE FROM ' . STYLES_IMAGESET_TABLE . ' WHERE imageset_id = ' . $style_id); + $db->sql_query('DELETE FROM ' . STYLES_TEMPLATE_TABLE . ' WHERE template_id = ' . $style_id); + $db->sql_query('DELETE FROM ' . STYLES_THEME_TABLE . ' WHERE theme_id = ' . $style_id); - if ($style_path != 'prosilver' && $style_path != 'subsilver2') - { - @rmdir($phpbb_root_path . 'styles/' . $style_path . '/template'); - @rmdir($phpbb_root_path . 'styles/' . $style_path); - } + if ($style_path != 'prosilver' && $style_path != 'subsilver2') + { + @rmdir($phpbb_root_path . 'styles/' . $style_path . '/template'); + @rmdir($phpbb_root_path . 'styles/' . $style_path); } } -- cgit v1.2.1 From 224aec0f2dc3c14cddabc972f7893395a6fe5cb9 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Fri, 12 Jul 2013 13:57:24 -0500 Subject: [ticket/11669] Fix PHP bug #55124 (recursive mkdir on /./) PHPBB3-11669 --- tests/test_framework/phpbb_test_case_helpers.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php index 50b2bf03ec..3d9cd10f32 100644 --- a/tests/test_framework/phpbb_test_case_helpers.php +++ b/tests/test_framework/phpbb_test_case_helpers.php @@ -94,6 +94,9 @@ class phpbb_test_case_helpers public function makedirs($path) { + // PHP bug #55124 (fixed in 5.4.0) + $path = str_replace('/./', '/', $path); + mkdir($path, 0777, true); } -- cgit v1.2.1 From 0297b88aafd3ef12217965f2879af9f9fd12d91f Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 12 Jul 2013 15:41:52 -0400 Subject: [ticket/9657] Add unit tests for softdeleting and moving posts/topics PHPBB3-9657 --- .../test_framework/phpbb_functional_test_case.php | 48 ++++++++++++++++++---- 1 file changed, 39 insertions(+), 9 deletions(-) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 7e2e750e30..d2d16a4bda 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -767,6 +767,7 @@ class phpbb_functional_test_case extends phpbb_test_case * Be sure to login before creating * * @param int $forum_id + * @param int $topic_id * @param string $subject * @param string $message * @param array $additional_form_data Any additional form data to be sent in the request @@ -823,18 +824,47 @@ class phpbb_functional_test_case extends phpbb_test_case // Instead, I send it as a request with the submit button "post" set to true. $crawler = self::request('POST', $posting_url, $form_data); $this->assertContains($this->lang('POST_STORED'), $crawler->filter('html')->text()); - $url = $crawler->selectLink($this->lang('VIEW_MESSAGE', '', ''))->link()->getUri(); - $matches = $topic_id = $post_id = false; - preg_match_all('#&t=([0-9]+)(&p=([0-9]+))?#', $url, $matches); - - $topic_id = (int) (isset($matches[1][0])) ? $matches[1][0] : 0; - $post_id = (int) (isset($matches[3][0])) ? $matches[3][0] : 0; - return array( - 'topic_id' => $topic_id, - 'post_id' => $post_id, + 'topic_id' => $this->get_parameter_from_link($url, 't'), + 'post_id' => $this->get_parameter_from_link($url, 'p'), ); } + + /* + * Returns the requested parameter from a URL + * + * @param string $url + * @param string $parameter + * @return string Value of the parameter in the URL, null if not set + */ + public function get_parameter_from_link($url, $parameter) + { + if (strpos($url, '?') === false) + { + return null; + } + + $url_parts = explode('?', $url); + if (isset($url_parts[1])) + { + $url_parameters = $url_parts[1]; + if (strpos($url_parameters, '#') !== false) + { + $url_parameters = explode('#', $url_parameters); + $url_parameters = $url_parameters[0]; + } + + foreach (explode('&', $url_parameters) as $url_param) + { + list($param, $value) = explode('=', $url_param); + if ($param == $parameter) + { + return $value; + } + } + } + return null; + } } -- cgit v1.2.1 From 7d0c1d02ca428305f3cd4b57249c90d0d86bc3ae Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 13 Jul 2013 12:02:49 -0400 Subject: [ticket/11684] Remove useless confirmation page after login and admin login PHPBB3-11684 --- tests/test_framework/phpbb_functional_test_case.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index f27e339bb7..2f5de76c11 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -610,7 +610,7 @@ class phpbb_functional_test_case extends phpbb_test_case $form = $crawler->selectButton($this->lang('LOGIN'))->form(); $crawler = self::submit($form, array('username' => $username, 'password' => $username . $username)); - $this->assertContains($this->lang('LOGIN_REDIRECT'), $crawler->filter('html')->text()); + $this->assertNotContains($this->lang('LOGIN'), $crawler->filter('.navbar')->text()); $cookies = self::$cookieJar->all(); @@ -659,7 +659,7 @@ class phpbb_functional_test_case extends phpbb_test_case if (strpos($field, 'password_') === 0) { $crawler = self::submit($form, array('username' => $username, $field => $username . $username)); - $this->assertContains($this->lang('LOGIN_ADMIN_SUCCESS'), $crawler->filter('html')->text()); + $this->assertContains($this->lang('ADMIN_PANEL'), $crawler->filter('h1')->text()); $cookies = self::$cookieJar->all(); -- cgit v1.2.1 From 8f95ef55a65cbf58e74840957cf9acfaf9e16d31 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 13 Jul 2013 12:27:00 -0400 Subject: [ticket/11685] Remove logout confirmation page PHPBB3-11685 --- tests/test_framework/phpbb_functional_test_case.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index f27e339bb7..4e0a978839 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -629,7 +629,7 @@ class phpbb_functional_test_case extends phpbb_test_case $this->add_lang('ucp'); $crawler = self::request('GET', 'ucp.php?sid=' . $this->sid . '&mode=logout'); - $this->assertContains($this->lang('LOGOUT_REDIRECT'), $crawler->filter('#message')->text()); + $this->assertContains($this->lang('REGISTER'), $crawler->filter('.navbar')->text()); unset($this->sid); } -- cgit v1.2.1 From 6bfa2fc0551af7e4eb99c1452031a2f423611a6f Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sat, 13 Jul 2013 12:06:05 -0500 Subject: [ticket/11686] Not checking for phpBB Debug errors on functional tests PHPBB3-11686 --- tests/test_framework/phpbb_functional_test_case.php | 1 + 1 file changed, 1 insertion(+) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 684d7a84cb..66af0db2b1 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -577,6 +577,7 @@ class phpbb_functional_test_case extends phpbb_test_case // Any output before the doc type means there was an error $content = self::$client->getResponse()->getContent(); + self::assertNotContains('[phpBB Debug]', $content); self::assertStringStartsWith(' Date: Thu, 11 Jul 2013 14:58:41 -0700 Subject: [ticket/11620] Abstracted session setUp into a test_case class When defining a database test case with a setUp function, it is important to call the parent's setup function, because that is when the database is setup. PHPBB3-11620 --- tests/test_framework/phpbb_session_test_case.php | 27 ++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 tests/test_framework/phpbb_session_test_case.php (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_session_test_case.php b/tests/test_framework/phpbb_session_test_case.php new file mode 100644 index 0000000000..6ff7d8e2ef --- /dev/null +++ b/tests/test_framework/phpbb_session_test_case.php @@ -0,0 +1,27 @@ +session_factory = new phpbb_session_testable_factory; + $this->db = $this->new_dbal(); + $this->session_facade = + new phpbb_session_testable_facade($this->db, $this->session_factory); + } +} -- cgit v1.2.1 From 8dc8ee205a30e4f1813f2b85e0176cc47100f47b Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 23 Jul 2013 00:58:03 +0200 Subject: [ticket/11733] Add browse test for feed.php PHPBB3-11733 --- tests/test_framework/phpbb_functional_test_case.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index ed307c3ce2..de3611c4cc 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -747,6 +747,27 @@ class phpbb_functional_test_case extends phpbb_test_case self::assertStringStartsWith('getResponse()->getContent(); + self::assertNotContains('[phpBB Debug]', $content); + self::assertStringStartsWith(' Date: Mon, 22 Jul 2013 17:39:45 -0700 Subject: [ticket/11620] Whitespace and combine function into test_case PHPBB3-11620 --- tests/test_framework/phpbb_session_test_case.php | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_session_test_case.php b/tests/test_framework/phpbb_session_test_case.php index 6ff7d8e2ef..e6a2b03bba 100644 --- a/tests/test_framework/phpbb_session_test_case.php +++ b/tests/test_framework/phpbb_session_test_case.php @@ -24,4 +24,13 @@ abstract class phpbb_session_test_case extends phpbb_database_test_case $this->session_facade = new phpbb_session_testable_facade($this->db, $this->session_factory); } + + protected function check_sessions_equals($expected_sessions, $message) + { + $sql = 'SELECT session_id, session_user_id + FROM phpbb_sessions + ORDER BY session_user_id'; + + $this->assertSqlResultEquals($expected_sessions, $sql, $message); + } } -- cgit v1.2.1 From a6e69f377bb436fe59eed9fdedc0cd735d8d8ce9 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 8 Aug 2013 23:33:26 +0200 Subject: [ticket/11775] Backport moving of the posting functions to 3.0 PHPBB3-11775 --- .../test_framework/phpbb_functional_test_case.php | 131 +++++++++++++++++++++ 1 file changed, 131 insertions(+) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 684d7a84cb..15f7814800 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -593,4 +593,135 @@ class phpbb_functional_test_case extends phpbb_test_case { self::assertEquals($status_code, self::$client->getResponse()->getStatus()); } + + /** + * Creates a topic + * + * Be sure to login before creating + * + * @param int $forum_id + * @param string $subject + * @param string $message + * @param array $additional_form_data Any additional form data to be sent in the request + * @return array post_id, topic_id + */ + public function create_topic($forum_id, $subject, $message, $additional_form_data = array()) + { + $posting_url = "posting.php?mode=post&f={$forum_id}&sid={$this->sid}"; + + $form_data = array_merge(array( + 'subject' => $subject, + 'message' => $message, + 'post' => true, + ), $additional_form_data); + + return self::submit_post($posting_url, 'POST_TOPIC', $form_data); + } + + /** + * Creates a post + * + * Be sure to login before creating + * + * @param int $forum_id + * @param int $topic_id + * @param string $subject + * @param string $message + * @param array $additional_form_data Any additional form data to be sent in the request + * @return array post_id, topic_id + */ + public function create_post($forum_id, $topic_id, $subject, $message, $additional_form_data = array()) + { + $posting_url = "posting.php?mode=reply&f={$forum_id}&t={$topic_id}&sid={$this->sid}"; + + $form_data = array_merge(array( + 'subject' => $subject, + 'message' => $message, + 'post' => true, + ), $additional_form_data); + + return self::submit_post($posting_url, 'POST_REPLY', $form_data); + } + + /** + * Helper for submitting posts + * + * @param string $posting_url + * @param string $posting_contains + * @param array $form_data + * @return array post_id, topic_id + */ + protected function submit_post($posting_url, $posting_contains, $form_data) + { + $this->add_lang('posting'); + + $crawler = self::request('GET', $posting_url); + $this->assertContains($this->lang($posting_contains), $crawler->filter('html')->text()); + + $hidden_fields = array( + $crawler->filter('[type="hidden"]')->each(function ($node, $i) { + return array('name' => $node->getAttribute('name'), 'value' => $node->getAttribute('value')); + }), + ); + + foreach ($hidden_fields as $fields) + { + foreach($fields as $field) + { + $form_data[$field['name']] = $field['value']; + } + } + + // Bypass time restriction that said that if the lastclick time (i.e. time when the form was opened) + // is not at least 2 seconds before submission, cancel the form + $form_data['lastclick'] = 0; + + // I use a request because the form submission method does not allow you to send data that is not + // contained in one of the actual form fields that the browser sees (i.e. it ignores "hidden" inputs) + // Instead, I send it as a request with the submit button "post" set to true. + $crawler = self::request('POST', $posting_url, $form_data); + $this->assertContains($this->lang('POST_STORED'), $crawler->filter('html')->text()); + $url = $crawler->selectLink($this->lang('VIEW_MESSAGE', '', ''))->link()->getUri(); + + return array( + 'topic_id' => $this->get_parameter_from_link($url, 't'), + 'post_id' => $this->get_parameter_from_link($url, 'p'), + ); + } + + /* + * Returns the requested parameter from a URL + * + * @param string $url + * @param string $parameter + * @return string Value of the parameter in the URL, null if not set + */ + public function get_parameter_from_link($url, $parameter) + { + if (strpos($url, '?') === false) + { + return null; + } + + $url_parts = explode('?', $url); + if (isset($url_parts[1])) + { + $url_parameters = $url_parts[1]; + if (strpos($url_parameters, '#') !== false) + { + $url_parameters = explode('#', $url_parameters); + $url_parameters = $url_parameters[0]; + } + + foreach (explode('&', $url_parameters) as $url_param) + { + list($param, $value) = explode('=', $url_param); + if ($param == $parameter) + { + return $value; + } + } + } + return null; + } } -- cgit v1.2.1 From 4b0adfcff54f9ebd3261e4673f689eb2c4c066df Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 15 Aug 2013 01:35:02 +0200 Subject: [ticket/11775] Remove spaces at line ends PHPBB3-11775 --- tests/test_framework/phpbb_functional_test_case.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 15f7814800..72990d3a21 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -596,9 +596,9 @@ class phpbb_functional_test_case extends phpbb_test_case /** * Creates a topic - * + * * Be sure to login before creating - * + * * @param int $forum_id * @param string $subject * @param string $message @@ -620,9 +620,9 @@ class phpbb_functional_test_case extends phpbb_test_case /** * Creates a post - * + * * Be sure to login before creating - * + * * @param int $forum_id * @param int $topic_id * @param string $subject -- cgit v1.2.1 From c30d4025d2976db3f55a8d477e27ca5598f83f69 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 15 Aug 2013 01:36:38 +0200 Subject: [ticket/11775] Fix doc blocks syntax PHPBB3-11775 --- tests/test_framework/phpbb_functional_test_case.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/test_framework') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 72990d3a21..7d8b4a3144 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -689,7 +689,7 @@ class phpbb_functional_test_case extends phpbb_test_case ); } - /* + /** * Returns the requested parameter from a URL * * @param string $url -- cgit v1.2.1