aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_framework/phpbb_test_case_helpers.php
diff options
context:
space:
mode:
authorNils Adermann <naderman@naderman.de>2010-04-01 19:16:45 +0200
committerNils Adermann <naderman@naderman.de>2010-04-01 19:16:45 +0200
commit6d9d2b6be681b6676067bf7e2ec9f58c2aa617ae (patch)
tree8b9157d1b4bb4efc24ec502f9d7d2cb5dc5c21a0 /tests/test_framework/phpbb_test_case_helpers.php
parentf97d0e0195de5f7d0d6ad4a4c5663b95971f96f3 (diff)
parent2bbfa9c29f4ce33d25e58c550540e236a4ee3c1a (diff)
downloadforums-6d9d2b6be681b6676067bf7e2ec9f58c2aa617ae.tar
forums-6d9d2b6be681b6676067bf7e2ec9f58c2aa617ae.tar.gz
forums-6d9d2b6be681b6676067bf7e2ec9f58c2aa617ae.tar.bz2
forums-6d9d2b6be681b6676067bf7e2ec9f58c2aa617ae.tar.xz
forums-6d9d2b6be681b6676067bf7e2ec9f58c2aa617ae.zip
Merge branch 'feature/dbal-tests' into develop-olympus
* feature/dbal-tests: [feature/dbal-tests] Only output the missing config error message once. [feature/dbal-tests] Make the PDO prefix depend on the dbms. [feature/dbal-tests] Fix whitespace and line endings. [feature/dbal-tests] Make some tests for build_array_data on SELECT [feature/dbal-tests] Make some tests for return_on_error on SELECT-queries [feature/dbal-tests] Tests for $db->sql_query_limit() [feature/dbal-tests] Load phpbb-schema after creating the connection to the database [feature/dbal-tests] Added tests for dbal fetchrow and fetchfield. [feature/dbal-tests] Added database test & refactored test framework
Diffstat (limited to 'tests/test_framework/phpbb_test_case_helpers.php')
-rw-r--r--tests/test_framework/phpbb_test_case_helpers.php97
1 files changed, 97 insertions, 0 deletions
diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php
new file mode 100644
index 0000000000..0c5932e1ad
--- /dev/null
+++ b/tests/test_framework/phpbb_test_case_helpers.php
@@ -0,0 +1,97 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2008 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+*/
+
+class phpbb_test_case_helpers
+{
+ protected $expectedTriggerError = false;
+
+ protected $test_case;
+
+ public function __construct($test_case)
+ {
+ $this->test_case = $test_case;
+ }
+
+ public function get_database_config()
+ {
+ static $show_error = true;
+
+ if (!file_exists('test_config.php'))
+ {
+ if ($show_error)
+ {
+ $show_error = false;
+ }
+ else
+ {
+ $this->test_case->markTestSkipped('Missing test_config.php: See first error.');
+ return;
+ }
+
+ trigger_error("You have to create a test_config.php like this:
+\"<?php
+\$dbms = 'mysqli';
+\$dbhost = 'localhost';
+\$dbport = '';
+\$dbname = 'database';
+\$dbuser = 'user';
+\$dbpasswd = 'password';
+\"
+
+NOTE: The database is dropped and recreated with the phpbb-db-schema! Do NOT specify a database with important data.", E_USER_ERROR);
+ }
+ include('test_config.php');
+
+ return array(
+ 'dbms' => $dbms,
+ 'dbhost' => $dbhost,
+ 'dbport' => $dbport,
+ 'dbname' => $dbname,
+ 'dbuser' => $dbuser,
+ 'dbpasswd' => $dbpasswd,
+ );
+ }
+
+ public function new_dbal()
+ {
+ global $phpbb_root_path, $phpEx;
+ $config = $this->get_database_config();
+
+ require_once '../phpBB/includes/db/' . $config['dbms'] . '.php';
+ $dbal = 'dbal_' . $config['dbms'];
+ $db = new $dbal();
+ $db->sql_connect($config['dbhost'], $config['dbuser'], $config['dbpasswd'], $config['dbname'], $config['dbport']);
+
+ return $db;
+ }
+
+ public function setExpectedTriggerError($errno, $message = '')
+ {
+ $exceptionName = '';
+ switch ($errno)
+ {
+ case E_NOTICE:
+ case E_STRICT:
+ PHPUnit_Framework_Error_Notice::$enabled = true;
+ $exceptionName = 'PHPUnit_Framework_Error_Notice';
+ break;
+
+ case E_WARNING:
+ PHPUnit_Framework_Error_Warning::$enabled = true;
+ $exceptionName = 'PHPUnit_Framework_Error_Warning';
+ break;
+
+ default:
+ $exceptionName = 'PHPUnit_Framework_Error';
+ break;
+ }
+ $this->expectedTriggerError = true;
+ $this->test_case->setExpectedException($exceptionName, (string) $message, $errno);
+ }
+}