aboutsummaryrefslogtreecommitdiffstats
path: root/tests/mock
diff options
context:
space:
mode:
Diffstat (limited to 'tests/mock')
-rw-r--r--tests/mock/auth_provider.php53
-rw-r--r--tests/mock/cache.php105
-rw-r--r--tests/mock/container_builder.php179
-rw-r--r--tests/mock/event_dispatcher.php16
-rw-r--r--tests/mock/extension_manager.php19
-rw-r--r--tests/mock/filespec.php32
-rw-r--r--tests/mock/filesystem_extension_manager.php32
-rw-r--r--tests/mock/fileupload.php23
-rw-r--r--tests/mock/lang.php38
-rw-r--r--tests/mock/metadata_manager.php21
-rw-r--r--tests/mock/notification_manager.php94
-rw-r--r--tests/mock/notifications_auth.php40
-rw-r--r--tests/mock/null_cache.php5
-rw-r--r--tests/mock/request.php89
-rw-r--r--tests/mock/search.php23
-rw-r--r--tests/mock/session_testable.php7
-rw-r--r--tests/mock/sql_insert_buffer.php21
17 files changed, 766 insertions, 31 deletions
diff --git a/tests/mock/auth_provider.php b/tests/mock/auth_provider.php
new file mode 100644
index 0000000000..9d002334d6
--- /dev/null
+++ b/tests/mock/auth_provider.php
@@ -0,0 +1,53 @@
+<?php
+/**
+ *
+ * @package testing
+ * @copyright (c) 2013 phpBB Group
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+ *
+ */
+
+/**
+ * Mock auth provider class with basic functions to help test sessions.
+ */
+class phpbb_mock_auth_provider implements phpbb_auth_provider_interface
+{
+ function init()
+ {
+ return null;
+ }
+
+ function login($username, $password)
+ {
+ return array(
+ 'status' => "",
+ 'error_msg' => "",
+ 'user_row' => "",
+ );
+ }
+
+ function autologin()
+ {
+ return array();
+ }
+
+ function acp()
+ {
+ return array();
+ }
+
+ function logout($data, $new_session)
+ {
+ return null;
+ }
+
+ function validate_session($user)
+ {
+ return null;
+ }
+
+ public function get_acp_template($new_config)
+ {
+ return null;
+ }
+}
diff --git a/tests/mock/cache.php b/tests/mock/cache.php
index acf4288319..440592665a 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)
@@ -34,24 +31,6 @@ class phpbb_mock_cache
$this->data[$var_name] = $var;
}
- public function destroy($var_name, $table = '')
- {
- if ($table)
- {
- throw new Exception('Destroying tables is not implemented yet');
- }
-
- unset($this->data[$var_name]);
- }
-
- /**
- * 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.
@@ -89,17 +68,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;
@@ -116,5 +110,58 @@ 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)
+ {
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function sql_save(phpbb_db_driver $db, $query, $query_result, $ttl)
+ {
+ return $query_result;
+ }
+ 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/container_builder.php b/tests/mock/container_builder.php
new file mode 100644
index 0000000000..734d3e1741
--- /dev/null
+++ b/tests/mock/container_builder.php
@@ -0,0 +1,179 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2012 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+use Symfony\Component\DependencyInjection\ContainerInterface;
+use Symfony\Component\DependencyInjection\ScopeInterface;
+
+class phpbb_mock_container_builder implements ContainerInterface
+{
+ protected $services = array();
+ protected $parameters = array();
+
+ /**
+ * Sets a service.
+ *
+ * @param string $id The service identifier
+ * @param object $service The service instance
+ * @param string $scope The scope of the service
+ *
+ * @api
+ */
+ public function set($id, $service, $scope = self::SCOPE_CONTAINER)
+ {
+ $this->services[$id] = $service;
+ }
+
+ /**
+ * Gets a service.
+ *
+ * @param string $id The service identifier
+ * @param int $invalidBehavior The behavior when the service does not exist
+ *
+ * @return object The associated service
+ *
+ * @throws InvalidArgumentException if the service is not defined
+ * @throws ServiceCircularReferenceException When a circular reference is detected
+ * @throws ServiceNotFoundException When the service is not defined
+ *
+ * @see Reference
+ *
+ * @api
+ */
+ public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE)
+ {
+ if ($this->has($id))
+ {
+ return $this->services[$id];
+ }
+
+ throw new Exception('Could not find service: ' . $id);
+ }
+
+ /**
+ * Returns true if the given service is defined.
+ *
+ * @param string $id The service identifier
+ *
+ * @return Boolean true if the service is defined, false otherwise
+ *
+ * @api
+ */
+ public function has($id)
+ {
+ return isset($this->services[$id]);
+ }
+
+ /**
+ * Gets a parameter.
+ *
+ * @param string $name The parameter name
+ *
+ * @return mixed The parameter value
+ *
+ * @throws InvalidArgumentException if the parameter is not defined
+ *
+ * @api
+ */
+ public function getParameter($name)
+ {
+ if ($this->hasParameter($name))
+ {
+ return $this->parameters[$name];
+ }
+
+ throw new Exception('Could not find parameter: ' . $name);
+ }
+
+ /**
+ * Checks if a parameter exists.
+ *
+ * @param string $name The parameter name
+ *
+ * @return Boolean The presence of parameter in container
+ *
+ * @api
+ */
+ public function hasParameter($name)
+ {
+ return isset($this->parameters[$name]);
+ }
+
+ /**
+ * Sets a parameter.
+ *
+ * @param string $name The parameter name
+ * @param mixed $value The parameter value
+ *
+ * @api
+ */
+ public function setParameter($name, $value)
+ {
+ $this->parameters[$name] = $value;
+ }
+
+ /**
+ * Enters the given scope
+ *
+ * @param string $name
+ *
+ * @api
+ */
+ public function enterScope($name)
+ {
+ }
+
+ /**
+ * Leaves the current scope, and re-enters the parent scope
+ *
+ * @param string $name
+ *
+ * @api
+ */
+ public function leaveScope($name)
+ {
+ }
+
+ /**
+ * Adds a scope to the container
+ *
+ * @param ScopeInterface $scope
+ *
+ * @api
+ */
+ public function addScope(ScopeInterface $scope)
+ {
+ }
+
+ /**
+ * Whether this container has the given scope
+ *
+ * @param string $name
+ *
+ * @return Boolean
+ *
+ * @api
+ */
+ public function hasScope($name)
+ {
+ }
+
+ /**
+ * Determines whether the given scope is currently active.
+ *
+ * It does however not check if the scope actually exists.
+ *
+ * @param string $name
+ *
+ * @return Boolean
+ *
+ * @api
+ */
+ public function isScopeActive($name)
+ {
+ }
+}
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/mock/extension_manager.php b/tests/mock/extension_manager.php
new file mode 100644
index 0000000000..10b3595206
--- /dev/null
+++ b/tests/mock/extension_manager.php
@@ -0,0 +1,19 @@
+<?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->php_ext = 'php';
+ $this->extensions = $extensions;
+ $this->filesystem = new phpbb_filesystem();
+ }
+}
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/filesystem_extension_manager.php b/tests/mock/filesystem_extension_manager.php
new file mode 100644
index 0000000000..c5a51bbb3f
--- /dev/null
+++ b/tests/mock/filesystem_extension_manager.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
+*
+*/
+
+class phpbb_mock_filesystem_extension_manager extends phpbb_mock_extension_manager
+{
+ public function __construct($phpbb_root_path)
+ {
+ $extensions = array();
+ $iterator = new DirectoryIterator($phpbb_root_path . 'ext/');
+ foreach ($iterator as $fileinfo)
+ {
+ if ($fileinfo->isDir() && substr($fileinfo->getFilename(), 0, 1) != '.')
+ {
+ $name = $fileinfo->getFilename();
+ $extension = array(
+ 'ext_name' => $name,
+ 'ext_active' => true,
+ 'ext_path' => 'ext/' . $name . '/',
+ );
+ $extensions[$name] = $extension;
+ }
+ }
+ ksort($extensions);
+ parent::__construct($phpbb_root_path, $extensions);
+ }
+}
diff --git a/tests/mock/fileupload.php b/tests/mock/fileupload.php
new file mode 100644
index 0000000000..cbcbf4a6ab
--- /dev/null
+++ b/tests/mock/fileupload.php
@@ -0,0 +1,23 @@
+<?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;
+ }
+}
diff --git a/tests/mock/lang.php b/tests/mock/lang.php
new file mode 100644
index 0000000000..ac814b45db
--- /dev/null
+++ b/tests/mock/lang.php
@@ -0,0 +1,38 @@
+<?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)
+ {
+ }
+
+ public function lang()
+ {
+ return implode(' ', func_get_args());
+ }
+}
diff --git a/tests/mock/metadata_manager.php b/tests/mock/metadata_manager.php
new file mode 100644
index 0000000000..a7fbf0681c
--- /dev/null
+++ b/tests/mock/metadata_manager.php
@@ -0,0 +1,21 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2013 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+class phpbb_mock_metadata_manager extends phpbb_extension_metadata_manager
+{
+ public function set_metadata($metadata)
+ {
+ $this->metadata = $metadata;
+ }
+
+ public function merge_metadata($metadata)
+ {
+ $this->metadata = array_merge($this->metadata, $metadata);
+ }
+}
diff --git a/tests/mock/notification_manager.php b/tests/mock/notification_manager.php
new file mode 100644
index 0000000000..47fe30730f
--- /dev/null
+++ b/tests/mock/notification_manager.php
@@ -0,0 +1,94 @@
+<?php
+/**
+*
+* @package notifications
+* @copyright (c) 2012 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+/**
+* @ignore
+*/
+if (!defined('IN_PHPBB'))
+{
+ exit;
+}
+
+/**
+* Notifications service class
+* @package notifications
+*/
+class phpbb_mock_notification_manager
+{
+ public function load_notifications()
+ {
+ return array(
+ 'notifications' => array(),
+ 'unread_count' => 0,
+ );
+ }
+
+ public function mark_notifications_read()
+ {
+ }
+
+ public function mark_notifications_read_by_parent()
+ {
+ }
+
+ public function mark_notifications_read_by_id()
+ {
+ }
+
+
+ public function add_notifications()
+ {
+ return array();
+ }
+
+ public function add_notifications_for_users()
+ {
+ }
+
+ public function update_notifications()
+ {
+ }
+
+ public function delete_notifications()
+ {
+ }
+
+ public function get_subscription_types()
+ {
+ return array();
+ }
+
+ public function get_subscription_methods()
+ {
+ return array();
+ }
+
+
+ public function get_global_subscriptions()
+ {
+ return array();
+ }
+
+ public function add_subscription()
+ {
+ }
+
+ public function delete_subscription()
+ {
+ }
+
+ public function load_users()
+ {
+ }
+
+ public function get_user()
+ {
+ return null;
+ }
+}
diff --git a/tests/mock/notifications_auth.php b/tests/mock/notifications_auth.php
new file mode 100644
index 0000000000..d960acb81a
--- /dev/null
+++ b/tests/mock/notifications_auth.php
@@ -0,0 +1,40 @@
+<?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_notifications_auth extends phpbb_auth
+{
+ function acl_get_list($user_id = false, $opts = false, $forum_id = false)
+ {
+ $user_id = (!is_array($user_id)) ? array($user_id) : $user_id;
+ $opts = (!is_array($opts)) ? array($opts) : $opts;
+ $forum_id = (!is_array($forum_id)) ? array($forum_id) : $forum_id;
+
+ $auth_list = array();
+
+ foreach ($forum_id as $fid)
+ {
+ foreach ($opts as $opt)
+ {
+ $auth_list[$fid][$opt] = array();
+
+ foreach ($user_id as $uid)
+ {
+ $auth_list[$fid][$opt][] = $uid;
+ }
+ }
+ }
+
+ return $auth_list;
+ }
+
+ function acl_get($opt, $f = 0)
+ {
+ return true;
+ }
+}
diff --git a/tests/mock/null_cache.php b/tests/mock/null_cache.php
index aca20ca77b..7bd33b441b 100644
--- a/tests/mock/null_cache.php
+++ b/tests/mock/null_cache.php
@@ -39,4 +39,9 @@ class phpbb_mock_null_cache
public function set_bots($bots)
{
}
+
+ public function sql_exists($query_id)
+ {
+ return false;
+ }
}
diff --git a/tests/mock/request.php b/tests/mock/request.php
new file mode 100644
index 0000000000..2a272fc03b
--- /dev/null
+++ b/tests/mock/request.php
@@ -0,0 +1,89 @@
+<?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, $files = array())
+ {
+ $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;
+ $this->data[phpbb_request_interface::FILES] = $files;
+ }
+
+ 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 file($form_name)
+ {
+ $super_global = phpbb_request_interface::FILES;
+ return isset($this->data[$super_global][$form_name]) ? $this->data[$super_global][$form_name] : array();
+ }
+
+ 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/search.php b/tests/mock/search.php
new file mode 100644
index 0000000000..6739719216
--- /dev/null
+++ b/tests/mock/search.php
@@ -0,0 +1,23 @@
+<?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_search
+{
+
+ public function __construct($error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user)
+ {
+ }
+
+ public function index_remove($post_ids, $poster_ids, $forum_ids)
+ {
+ }
+}
+
diff --git a/tests/mock/session_testable.php b/tests/mock/session_testable.php
index 70a58fb6cc..283f9af192 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();
@@ -59,5 +58,9 @@ class phpbb_mock_session_testable extends session
}
}
}
+
+ public function setup()
+ {
+ }
}
diff --git a/tests/mock/sql_insert_buffer.php b/tests/mock/sql_insert_buffer.php
new file mode 100644
index 0000000000..ba09aa8d7f
--- /dev/null
+++ b/tests/mock/sql_insert_buffer.php
@@ -0,0 +1,21 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2013 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+class phpbb_mock_sql_insert_buffer extends phpbb_db_sql_insert_buffer
+{
+ public function flush()
+ {
+ return (sizeof($this->buffer)) ? true : false;
+ }
+
+ public function get_buffer()
+ {
+ return $this->buffer;
+ }
+}