aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/cache/cache_test.php41
-rw-r--r--tests/cache/fixtures/config.xml18
-rw-r--r--tests/functions_acp/build_cfg_template_test.php15
-rw-r--r--tests/mock/cache.php2
-rw-r--r--tests/mock/event_dispatcher.php16
-rw-r--r--tests/test_framework/phpbb_functional_test_case.php6
6 files changed, 87 insertions, 11 deletions
diff --git a/tests/cache/cache_test.php b/tests/cache/cache_test.php
index 564bd35863..c5f5fac88c 100644
--- a/tests/cache/cache_test.php
+++ b/tests/cache/cache_test.php
@@ -9,7 +9,7 @@
require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
-class phpbb_cache_test extends phpbb_test_case
+class phpbb_cache_test extends phpbb_database_test_case
{
private $cache_dir;
@@ -18,8 +18,15 @@ class phpbb_cache_test extends phpbb_test_case
$this->cache_dir = dirname(__FILE__) . '/../tmp/cache/';
}
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/config.xml');
+ }
+
protected function setUp()
{
+ parent::setUp();
+
if (file_exists($this->cache_dir))
{
// cache directory possibly left after aborted
@@ -35,6 +42,8 @@ class phpbb_cache_test extends phpbb_test_case
{
$this->remove_cache_dir();
}
+
+ parent::tearDown();
}
private function create_cache_dir()
@@ -67,4 +76,34 @@ class phpbb_cache_test extends phpbb_test_case
'File ACM put and get'
);
}
+
+ public function test_cache_sql()
+ {
+ $driver = new phpbb_cache_driver_file($this->cache_dir);
+
+ global $db, $cache;
+ $db = $this->new_dbal();
+ $cache = new phpbb_cache_service($driver);
+
+ $sql = "SELECT * FROM phpbb_config
+ WHERE config_name = 'foo'";
+ $result = $db->sql_query($sql, 300);
+ $first_result = $db->sql_fetchrow($result);
+
+ $this->assertFileExists($this->cache_dir . 'sql_' . md5(preg_replace('/[\n\r\s\t]+/', ' ', $sql)) . '.php');
+
+ $sql = "SELECT * FROM phpbb_config
+ WHERE config_name = 'foo'";
+ $result = $db->sql_query($sql, 300);
+
+ $this->assertEquals($first_result, $db->sql_fetchrow($result));
+
+ $sql = "SELECT * FROM phpbb_config
+ WHERE config_name = 'bar'";
+ $result = $db->sql_query($sql, 300);
+
+ $this->assertNotEquals($first_result, $db->sql_fetchrow($result));
+
+ $db->sql_close();
+ }
}
diff --git a/tests/cache/fixtures/config.xml b/tests/cache/fixtures/config.xml
new file mode 100644
index 0000000000..9d395b685c
--- /dev/null
+++ b/tests/cache/fixtures/config.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_config">
+ <column>config_name</column>
+ <column>config_value</column>
+ <column>is_dynamic</column>
+ <row>
+ <value>foo</value>
+ <value>23</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>bar</value>
+ <value>42</value>
+ <value>1</value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/functions_acp/build_cfg_template_test.php b/tests/functions_acp/build_cfg_template_test.php
index 12121f6678..bf5330fd88 100644
--- a/tests/functions_acp/build_cfg_template_test.php
+++ b/tests/functions_acp/build_cfg_template_test.php
@@ -46,8 +46,9 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case
*/
public function test_build_cfg_template_text($tpl_type, $key, $new, $config_key, $vars, $expected)
{
- global $user;
+ global $user, $phpbb_dispatcher;
+ $phpbb_dispatcher = new phpbb_mock_event_dispatcher();
$user->lang = new phpbb_mock_lang();
$this->assertEquals($expected, build_cfg_template($tpl_type, $key, $new, $config_key, $vars));
@@ -80,8 +81,9 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case
*/
public function test_build_cfg_template_dimension($tpl_type, $key, $new, $config_key, $vars, $expected)
{
- global $user;
+ global $user, $phpbb_dispatcher;
+ $phpbb_dispatcher = new phpbb_mock_event_dispatcher();
$user->lang = new phpbb_mock_lang();
$this->assertEquals($expected, build_cfg_template($tpl_type, $key, $new, $config_key, $vars));
@@ -106,8 +108,9 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case
*/
public function test_build_cfg_template_textarea($tpl_type, $key, $new, $config_key, $vars, $expected)
{
- global $user;
+ global $user, $phpbb_dispatcher;
+ $phpbb_dispatcher = new phpbb_mock_event_dispatcher();
$user->lang = new phpbb_mock_lang();
$this->assertEquals($expected, build_cfg_template($tpl_type, $key, $new, $config_key, $vars));
@@ -156,8 +159,9 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case
*/
public function test_build_cfg_template_radio($tpl_type, $key, $new, $config_key, $vars, $expected)
{
- global $user;
+ global $user, $phpbb_dispatcher;
+ $phpbb_dispatcher = new phpbb_mock_event_dispatcher();
$user->lang = new phpbb_mock_lang();
$this->assertEquals($expected, build_cfg_template($tpl_type, $key, $new, $config_key, $vars));
@@ -182,8 +186,9 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case
*/
public function test_build_cfg_template_append($tpl_type, $key, $new, $config_key, $vars, $expected)
{
- global $user;
+ global $user, $phpbb_dispatcher;
+ $phpbb_dispatcher = new phpbb_mock_event_dispatcher();
$user->lang = new phpbb_mock_lang();
$this->assertEquals($expected, build_cfg_template($tpl_type, $key, $new, $config_key, $vars));
diff --git a/tests/mock/cache.php b/tests/mock/cache.php
index c6d08afef0..b64c92ea89 100644
--- a/tests/mock/cache.php
+++ b/tests/mock/cache.php
@@ -121,7 +121,7 @@ class phpbb_mock_cache implements phpbb_cache_driver_interface
public function sql_load($query)
{
}
- public function sql_save($query, &$query_result, $ttl)
+ public function sql_save($query, $query_result, $ttl)
{
}
public function sql_exists($query_id)
diff --git a/tests/mock/event_dispatcher.php b/tests/mock/event_dispatcher.php
new file mode 100644
index 0000000000..8887b16163
--- /dev/null
+++ b/tests/mock/event_dispatcher.php
@@ -0,0 +1,16 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2012 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+class phpbb_mock_event_dispatcher
+{
+ public function trigger_event($eventName, $data)
+ {
+ return array();
+ }
+}
diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php
index c042d75811..b953017d0a 100644
--- a/tests/test_framework/phpbb_functional_test_case.php
+++ b/tests/test_framework/phpbb_functional_test_case.php
@@ -197,13 +197,11 @@ class phpbb_functional_test_case extends phpbb_test_case
$this->do_request('create_table', $data);
- file_put_contents($phpbb_root_path . "config.$phpEx", phpbb_create_config_file_data($data, self::$config['dbms'], array(), true));
-
$this->do_request('config_file', $data);
-
- copy($phpbb_root_path . "config.$phpEx", $phpbb_root_path . "config_test.$phpEx");
+ file_put_contents($phpbb_root_path . "config.$phpEx", phpbb_create_config_file_data($data, self::$config['dbms'], array(), true));
$this->do_request('final', $data);
+ copy($phpbb_root_path . "config.$phpEx", $phpbb_root_path . "config_test.$phpEx");
}
private function do_request($sub, $post_data = null)