diff options
author | Igor Wiedler <igor@wiedler.ch> | 2011-01-09 23:58:27 +0100 |
---|---|---|
committer | Igor Wiedler <igor@wiedler.ch> | 2011-01-09 23:58:27 +0100 |
commit | 95c683056b85399200e2caaa9aa65edc6843c16f (patch) | |
tree | ac11043ba149791a225d587e7a61e34db75a04f6 /tests | |
parent | 5373f8157d8a2619197702c3a00a6bb432ef3e25 (diff) | |
parent | 1aef7eb20ee195c7f21d6c5b78653b7c43e669ec (diff) | |
download | forums-95c683056b85399200e2caaa9aa65edc6843c16f.tar forums-95c683056b85399200e2caaa9aa65edc6843c16f.tar.gz forums-95c683056b85399200e2caaa9aa65edc6843c16f.tar.bz2 forums-95c683056b85399200e2caaa9aa65edc6843c16f.tar.xz forums-95c683056b85399200e2caaa9aa65edc6843c16f.zip |
Merge branch 'task/acm-refactor' into develop
Conflicts:
tests/bootstrap.php
Diffstat (limited to 'tests')
-rw-r--r-- | tests/bootstrap.php | 2 | ||||
-rw-r--r-- | tests/cache/cache_test.php | 41 | ||||
-rw-r--r-- | tests/cache/tmp/.gitkeep | 0 | ||||
-rw-r--r-- | tests/class_loader/cache_mock.php | 29 | ||||
-rw-r--r-- | tests/class_loader/class_loader_test.php | 14 | ||||
-rw-r--r-- | tests/mock/cache.php | 87 |
6 files changed, 136 insertions, 37 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/cache_test.php b/tests/cache/cache_test.php new file mode 100644 index 0000000000..463095f129 --- /dev/null +++ b/tests/cache/cache_test.php @@ -0,0 +1,41 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2010 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +require_once __DIR__ . '/../../phpBB/includes/functions.php'; + +class phpbb_cache_test extends phpbb_test_case +{ + protected function tearDown() + { + $iterator = new DirectoryIterator(__DIR__ . '/tmp'); + foreach ($iterator as $file) + { + if (is_file(__DIR__ . '/tmp/' . $file) && $file != '.gitkeep') + { + unlink(__DIR__ . '/tmp/' . $file); + } + } + } + + public function test_cache_driver_file() + { + global $phpEx; + $phpEx = 'txt'; // do not store files as .php + + $driver = new phpbb_cache_driver_file(__DIR__ . '/tmp/'); + $driver->put('test_key', 'test_value'); + $driver->save(); + + $this->assertEquals( + 'test_value', + $driver->get('test_key'), + 'File ACM put and get' + ); + } +} diff --git a/tests/cache/tmp/.gitkeep b/tests/cache/tmp/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/tests/cache/tmp/.gitkeep diff --git a/tests/class_loader/cache_mock.php b/tests/class_loader/cache_mock.php deleted file mode 100644 index b254978fcc..0000000000 --- a/tests/class_loader/cache_mock.php +++ /dev/null @@ -1,29 +0,0 @@ -<?php -/** -* -* @package testing -* @version $Id$ -* @copyright (c) 2008 phpBB Group -* @license http://opensource.org/licenses/gpl-license.php GNU Public License -* -*/ - -class phpbb_cache_mock -{ - private $variables = array(); - - function get($var_name) - { - if (isset($this->variables[$var_name])) - { - return $this->variables[$var_name]; - } - - return false; - } - - function put($var_name, $value) - { - $this->variables[$var_name] = $value; - } -} diff --git a/tests/class_loader/class_loader_test.php b/tests/class_loader/class_loader_test.php index 3eb3c915a1..cc6862dc70 100644 --- a/tests/class_loader/class_loader_test.php +++ b/tests/class_loader/class_loader_test.php @@ -2,15 +2,12 @@ /** * * @package testing -* @version $Id$ -* @copyright (c) 2008 phpBB Group +* @copyright (c) 2011 phpBB Group * @license http://opensource.org/licenses/gpl-license.php GNU Public License * */ -require_once __DIR__ . '/cache_mock.php'; - -require_once __DIR__ . '/../../phpBB/includes/class_loader.php'; +require_once __DIR__ . '/../mock/cache.php'; class phpbb_class_loader_test extends PHPUnit_Framework_TestCase { @@ -63,8 +60,8 @@ 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 = new phpbb_mock_cache($cacheMap); $prefix = __DIR__ . '/'; $class_loader = new phpbb_class_loader($prefix, '.php', $cache); @@ -82,5 +79,8 @@ class phpbb_class_loader_test extends PHPUnit_Framework_TestCase $class_loader->resolve_path('phpbb_a_cached_name'), 'Class in a directory' ); + + $cacheMap['class_loader']['phpbb_dir_class_name'] = 'dir/class_name'; + $cache->check($this, $cacheMap); } } diff --git a/tests/mock/cache.php b/tests/mock/cache.php new file mode 100644 index 0000000000..3bfb31f1be --- /dev/null +++ b/tests/mock/cache.php @@ -0,0 +1,87 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2011 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +class phpbb_mock_cache implements phpbb_cache_driver_interface +{ + protected $data; + + public function __construct($data = array()) + { + $this->data = $data; + } + + public function get($var_name) + { + if (isset($this->data[$var_name])) + { + return $this->data[$var_name]; + } + + return false; + } + + public function put($var_name, $var, $ttl = 0) + { + $this->data[$var_name] = $var; + } + + public function checkVar(PHPUnit_Framework_Assert $test, $var_name, $data) + { + $test->assertTrue(isset($this->data[$var_name])); + $test->assertEquals($data, $this->data[$var_name]); + } + + public function check(PHPUnit_Framework_Assert $test, $data) + { + $test->assertEquals($data, $this->data); + } + + 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) + { + } +} |