aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/bootstrap.php2
-rw-r--r--tests/cache/all_tests.php40
-rw-r--r--tests/cache/cache_test.php39
-rw-r--r--tests/class_loader/cache_mock.php49
-rw-r--r--tests/class_loader/class_loader_test.php14
5 files changed, 137 insertions, 7 deletions
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
index 161bd83a3d..8d4e9c4527 100644
--- a/tests/bootstrap.php
+++ b/tests/bootstrap.php
@@ -28,7 +28,7 @@ else
require_once $phpbb_root_path . 'includes/constants.php';
require_once $phpbb_root_path . 'includes/class_loader.' . $phpEx;
-$class_loader = new phpbb_class_loader($phpbb_root_path, '.' . $phpEx);
+$class_loader = new phpbb_class_loader($phpbb_root_path, '.php');
$class_loader->register();
require_once 'test_framework/phpbb_test_case_helpers.php';
diff --git a/tests/cache/all_tests.php b/tests/cache/all_tests.php
new file mode 100644
index 0000000000..829d496e5d
--- /dev/null
+++ b/tests/cache/all_tests.php
@@ -0,0 +1,40 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2010 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+*/
+
+if (!defined('PHPUnit_MAIN_METHOD'))
+{
+ define('PHPUnit_MAIN_METHOD', 'phpbb_request_all_tests::main');
+}
+
+require_once 'test_framework/framework.php';
+require_once 'PHPUnit/TextUI/TestRunner.php';
+
+require_once 'cache/cache_test.php';
+
+class phpbb_cache_all_tests
+{
+ public static function main()
+ {
+ PHPUnit_TextUI_TestRunner::run(self::suite());
+ }
+
+ public static function suite()
+ {
+ $suite = new PHPUnit_Framework_TestSuite('phpBB Cache System');
+
+ $suite->addTestSuite('phpbb_cache_test');
+
+ return $suite;
+ }
+}
+
+if (PHPUnit_MAIN_METHOD == 'phpbb_cache_all_tests::main')
+{
+ phpbb_cache_all_tests::main();
+}
diff --git a/tests/cache/cache_test.php b/tests/cache/cache_test.php
new file mode 100644
index 0000000000..220fddfd25
--- /dev/null
+++ b/tests/cache/cache_test.php
@@ -0,0 +1,39 @@
+<?php
+/**
+*
+* @package testing
+* @version $Id$
+* @copyright (c) 2010 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+*/
+
+require_once 'test_framework/framework.php';
+
+class phpbb_cache_test extends phpbb_test_case
+{
+ protected function tearDown()
+ {
+ $iterator = new DirectoryIterator('cache/tmp');
+ foreach ($iterator as $file)
+ {
+ if (is_file('cache/tmp/' . $file))
+ {
+ unlink('cache/tmp/' . $file);
+ }
+ }
+ }
+
+ public function test_acm_file()
+ {
+ $acm = new phpbb_cache_driver_file('cache/tmp/');
+ $acm->put('test_key', 'test_value');
+ $acm->save();
+
+ $this->assertEquals(
+ 'test_value',
+ $acm->get('test_key'),
+ 'File ACM put and get'
+ );
+ }
+}
diff --git a/tests/class_loader/cache_mock.php b/tests/class_loader/cache_mock.php
index b254978fcc..73d1e64cf5 100644
--- a/tests/class_loader/cache_mock.php
+++ b/tests/class_loader/cache_mock.php
@@ -8,7 +8,9 @@
*
*/
-class phpbb_cache_mock
+require '../phpBB/includes/cache/driver/interface.php';
+
+class phpbb_cache_mock implements phpbb_cache_driver_interface
{
private $variables = array();
@@ -22,8 +24,51 @@ class phpbb_cache_mock
return false;
}
- function put($var_name, $value)
+ function put($var_name, $value, $ttl = 0)
{
$this->variables[$var_name] = $value;
}
+
+ function load()
+ {
+ }
+ function unload()
+ {
+ }
+ function save()
+ {
+ }
+ function tidy()
+ {
+ }
+ function purge()
+ {
+ }
+ function destroy($var_name, $table = '')
+ {
+ }
+ public function _exists($var_name)
+ {
+ }
+ public function sql_load($query)
+ {
+ }
+ public function sql_save($query, &$query_result, $ttl)
+ {
+ }
+ public function sql_exists($query_id)
+ {
+ }
+ public function sql_fetchrow($query_id)
+ {
+ }
+ public function sql_fetchfield($query_id, $field)
+ {
+ }
+ public function sql_rowseek($rownum, $query_id)
+ {
+ }
+ public function sql_freeresult($query_id)
+ {
+ }
}
diff --git a/tests/class_loader/class_loader_test.php b/tests/class_loader/class_loader_test.php
index 3eb3c915a1..c01278f914 100644
--- a/tests/class_loader/class_loader_test.php
+++ b/tests/class_loader/class_loader_test.php
@@ -10,8 +10,6 @@
require_once __DIR__ . '/cache_mock.php';
-require_once __DIR__ . '/../../phpBB/includes/class_loader.php';
-
class phpbb_class_loader_test extends PHPUnit_Framework_TestCase
{
public function setUp()
@@ -63,8 +61,16 @@ class phpbb_class_loader_test extends PHPUnit_Framework_TestCase
public function test_resolve_cached()
{
- $cache = new phpbb_cache_mock;
- $cache->put('class_loader', array('phpbb_a_cached_name' => 'a/cached_name'));
+ $cacheMap = array('class_loader' => array('phpbb_a_cached_name' => 'a/cached_name'));
+
+ $cache = $this->getMock('phpbb_cache_driver_interface',
+ array('get', 'put', 'load', 'unload', 'save', 'tidy', 'purge', 'destroy', '_exists',
+ 'sql_load', 'sql_save', 'sql_exists', 'sql_fetchrow', 'sql_fetchfield', 'sql_rowseek', 'sql_freeresult'));
+ $cache->expects($this->any())
+ ->method('get')
+ ->will($this->returnCallback(function($var_name) use ($cacheMap) {
+ return $cacheMap[$var_name];
+ }));
$prefix = __DIR__ . '/';
$class_loader = new phpbb_class_loader($prefix, '.php', $cache);