diff options
Diffstat (limited to 'tests/mock')
-rw-r--r-- | tests/mock/cache.php | 90 | ||||
-rw-r--r-- | tests/mock/extension_manager.php | 18 | ||||
-rw-r--r-- | tests/mock/filespec.php | 32 | ||||
-rw-r--r-- | tests/mock/fileupload.php | 52 | ||||
-rw-r--r-- | tests/mock/lang.php | 33 | ||||
-rw-r--r-- | tests/mock/request.php | 82 | ||||
-rw-r--r-- | tests/mock/session_testable.php | 3 |
7 files changed, 289 insertions, 21 deletions
diff --git a/tests/mock/cache.php b/tests/mock/cache.php index 650545c3d6..c6d08afef0 100644 --- a/tests/mock/cache.php +++ b/tests/mock/cache.php @@ -2,21 +2,18 @@ /** * * @package testing -* @copyright (c) 2008 phpBB Group +* @copyright (c) 2011 phpBB Group * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 * */ -class phpbb_mock_cache +class phpbb_mock_cache implements phpbb_cache_driver_interface { + protected $data; + public function __construct($data = array()) { $this->data = $data; - - if (!isset($this->data['_bots'])) - { - $this->data['_bots'] = array(); - } } public function get($var_name) @@ -35,14 +32,6 @@ class phpbb_mock_cache } /** - * Obtain active bots - */ - public function obtain_bots() - { - return $this->data['_bots']; - } - - /** * Obtain list of word censors. We don't need to parse them here, * that is tested elsewhere. */ @@ -64,17 +53,32 @@ class phpbb_mock_cache ); } - public function set_bots($bots) + public function checkVar(PHPUnit_Framework_Assert $test, $var_name, $data) { - $this->data['_bots'] = $bots; + $test->assertTrue(isset($this->data[$var_name])); + $test->assertEquals($data, $this->data[$var_name]); } - public function checkVar(PHPUnit_Framework_Assert $test, $var_name, $data) + public function checkAssociativeVar(PHPUnit_Framework_Assert $test, $var_name, $data, $sort = true) { $test->assertTrue(isset($this->data[$var_name])); + + if ($sort) + { + foreach ($this->data[$var_name] as &$content) + { + sort($content); + } + } + $test->assertEquals($data, $this->data[$var_name]); } + public function checkVarUnset(PHPUnit_Framework_Assert $test, $var_name) + { + $test->assertFalse(isset($this->data[$var_name])); + } + public function check(PHPUnit_Framework_Assert $test, $data, $ignore_db_info = true) { $cache_data = $this->data; @@ -91,5 +95,53 @@ class phpbb_mock_cache $test->assertEquals($data, $cache_data); } -} + function load() + { + } + function unload() + { + } + function save() + { + } + function tidy() + { + } + function purge() + { + } + function destroy($var_name, $table = '') + { + unset($this->data[$var_name]); + } + 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) + { + } + + public function obtain_bots() + { + return isset($this->data['_bots']) ? $this->data['_bots'] : array(); + } +} diff --git a/tests/mock/extension_manager.php b/tests/mock/extension_manager.php new file mode 100644 index 0000000000..77f799dd3b --- /dev/null +++ b/tests/mock/extension_manager.php @@ -0,0 +1,18 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2011 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +class phpbb_mock_extension_manager extends phpbb_extension_manager +{ + public function __construct($phpbb_root_path, $extensions = array()) + { + $this->phpbb_root_path = $phpbb_root_path; + $this->phpEx = '.php'; + $this->extensions = $extensions; + } +} diff --git a/tests/mock/filespec.php b/tests/mock/filespec.php new file mode 100644 index 0000000000..9d2a5c84de --- /dev/null +++ b/tests/mock/filespec.php @@ -0,0 +1,32 @@ +<?php +/** + * + * @package testing + * @copyright (c) 2012 phpBB Group + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 + * + */ + +/** + * Mock filespec class with some basic values to help with testing the + * fileupload class + */ +class phpbb_mock_filespec +{ + public $filesize; + public $realname; + public $extension; + public $width; + public $height; + public $error = array(); + + public function check_content($disallowed_content) + { + return true; + } + + public function get($property) + { + return $this->$property; + } +} diff --git a/tests/mock/fileupload.php b/tests/mock/fileupload.php new file mode 100644 index 0000000000..409036ba63 --- /dev/null +++ b/tests/mock/fileupload.php @@ -0,0 +1,52 @@ +<?php +/** + * + * @package testing + * @copyright (c) 2012 phpBB Group + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 + * + */ + +/** + * Mock fileupload class with some basic values to help with testing the + * filespec class + */ +class phpbb_mock_fileupload +{ + public $max_filesize = 100; + public $error_prefix = ''; + + public function valid_dimensions($filespec) + { + return true; + } + + /** + * Copied verbatim from phpBB/includes/functions_upload.php's fileupload + * class to ensure the correct behaviour of filespec::move_file. + * + * Maps file extensions to the constant in second index of the array + * returned by getimagesize() + */ + public function image_types() + { + return array( + IMAGETYPE_GIF => array('gif'), + IMAGETYPE_JPEG => array('jpg', 'jpeg'), + IMAGETYPE_PNG => array('png'), + IMAGETYPE_SWF => array('swf'), + IMAGETYPE_PSD => array('psd'), + IMAGETYPE_BMP => array('bmp'), + IMAGETYPE_TIFF_II => array('tif', 'tiff'), + IMAGETYPE_TIFF_MM => array('tif', 'tiff'), + IMAGETYPE_JPC => array('jpg', 'jpeg'), + IMAGETYPE_JP2 => array('jpg', 'jpeg'), + IMAGETYPE_JPX => array('jpg', 'jpeg'), + IMAGETYPE_JB2 => array('jpg', 'jpeg'), + IMAGETYPE_SWC => array('swc'), + IMAGETYPE_IFF => array('iff'), + IMAGETYPE_WBMP => array('wbmp'), + IMAGETYPE_XBM => array('xbm'), + ); + } +} diff --git a/tests/mock/lang.php b/tests/mock/lang.php new file mode 100644 index 0000000000..781b3d060e --- /dev/null +++ b/tests/mock/lang.php @@ -0,0 +1,33 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2010 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* phpbb_mock_lang +* mock a user with some language-keys specified +*/ +class phpbb_mock_lang implements ArrayAccess +{ + public function offsetExists($offset) + { + return true; + } + + public function offsetGet($offset) + { + return $offset; + } + + public function offsetSet($offset, $value) + { + } + + public function offsetUnset($offset) + { + } +} diff --git a/tests/mock/request.php b/tests/mock/request.php new file mode 100644 index 0000000000..946dfdada9 --- /dev/null +++ b/tests/mock/request.php @@ -0,0 +1,82 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2011 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +class phpbb_mock_request implements phpbb_request_interface +{ + protected $data; + + public function __construct($get = array(), $post = array(), $cookie = array(), $server = array(), $request = false) + { + $this->data[phpbb_request_interface::GET] = $get; + $this->data[phpbb_request_interface::POST] = $post; + $this->data[phpbb_request_interface::COOKIE] = $cookie; + $this->data[phpbb_request_interface::REQUEST] = ($request === false) ? $post + $get : $request; + $this->data[phpbb_request_interface::SERVER] = $server; + } + + public function overwrite($var_name, $value, $super_global = phpbb_request_interface::REQUEST) + { + $this->data[$super_global][$var_name] = $value; + } + + public function variable($var_name, $default, $multibyte = false, $super_global = phpbb_request_interface::REQUEST) + { + return isset($this->data[$super_global][$var_name]) ? $this->data[$super_global][$var_name] : $default; + } + + public function server($var_name, $default = '') + { + $super_global = phpbb_request_interface::SERVER; + return isset($this->data[$super_global][$var_name]) ? $this->data[$super_global][$var_name] : $default; + } + + public function header($header_name, $default = '') + { + $var_name = 'HTTP_' . str_replace('-', '_', strtoupper($header_name)); + return $this->server($var_name, $default); + } + + public function is_set_post($name) + { + return $this->is_set($name, phpbb_request_interface::POST); + } + + public function is_set($var, $super_global = phpbb_request_interface::REQUEST) + { + return isset($this->data[$super_global][$var]); + } + + public function is_ajax() + { + return false; + } + + public function is_secure() + { + return false; + } + + public function variable_names($super_global = phpbb_request_interface::REQUEST) + { + return array_keys($this->data[$super_global]); + } + + /* custom methods */ + + public function set_header($header_name, $value) + { + $var_name = 'HTTP_' . str_replace('-', '_', strtoupper($header_name)); + $this->data[phpbb_request_interface::SERVER][$var_name] = $value; + } + + public function merge($super_global = phpbb_request_interface::REQUEST, $values) + { + $this->data[$super_global] = array_merge($this->data[$super_global], $values); + } +} diff --git a/tests/mock/session_testable.php b/tests/mock/session_testable.php index 70a58fb6cc..56ff8c8b32 100644 --- a/tests/mock/session_testable.php +++ b/tests/mock/session_testable.php @@ -8,7 +8,6 @@ */ require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; -require_once dirname(__FILE__) . '/../../phpBB/includes/session.php'; /** * Extends the session class to overwrite the setting of cookies. @@ -17,7 +16,7 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/session.php'; * test it without warnings about sent headers. This class only stores cookie * data for later verification. */ -class phpbb_mock_session_testable extends session +class phpbb_mock_session_testable extends phpbb_session { private $_cookies = array(); |