summaryrefslogtreecommitdiffstats
path: root/tests/mocks
diff options
context:
space:
mode:
authorPhil Sturgeon <email@philsturgeon.co.uk>2012-05-16 14:08:24 +0200
committerPhil Sturgeon <email@philsturgeon.co.uk>2012-05-16 14:08:24 +0200
commit8279420f989a8cda4427c3983ee919c6a1073dd7 (patch)
tree77921a510be4a02d3408c259a20af14a67c41d04 /tests/mocks
parentf4f9f787082e45c04a8d007450d9151f5a068732 (diff)
parent14455e57770112bf8cd938980925ded12f3cba9e (diff)
Merge pull request #1360 from toopay/core-tests
Unit tests for Benchmark, Input and Security classes.
Diffstat (limited to 'tests/mocks')
-rw-r--r--tests/mocks/autoloader.php1
-rw-r--r--tests/mocks/core/benchmark.php3
-rw-r--r--tests/mocks/core/input.php31
-rw-r--r--tests/mocks/core/security.php30
-rw-r--r--tests/mocks/core/utf8.php27
-rw-r--r--tests/mocks/libraries/table.php2
6 files changed, 92 insertions, 2 deletions
diff --git a/tests/mocks/autoloader.php b/tests/mocks/autoloader.php
index f1bdb5d6f..92c9bea59 100644
--- a/tests/mocks/autoloader.php
+++ b/tests/mocks/autoloader.php
@@ -6,7 +6,6 @@
//
// Prototype :
//
-// include_once('Mock_Core_Loader') // Will load ./mocks/core/loader.php
// $mock_table = new Mock_Libraries_Table(); // Will load ./mocks/libraries/table.php
// $mock_database_driver = new Mock_Database_Driver(); // Will load ./mocks/database/driver.php
// and so on...
diff --git a/tests/mocks/core/benchmark.php b/tests/mocks/core/benchmark.php
new file mode 100644
index 000000000..d92be21db
--- /dev/null
+++ b/tests/mocks/core/benchmark.php
@@ -0,0 +1,3 @@
+<?php
+
+class Mock_Core_Benchmark extends CI_Benchmark {} \ No newline at end of file
diff --git a/tests/mocks/core/input.php b/tests/mocks/core/input.php
new file mode 100644
index 000000000..8a337d2ef
--- /dev/null
+++ b/tests/mocks/core/input.php
@@ -0,0 +1,31 @@
+<?php
+
+class Mock_Core_Input extends CI_Input {
+
+ /**
+ * Since we use GLOBAL to fetch Security and Utf8 classes,
+ * we need to use inversion of control to mock up
+ * the same process within CI_Input class constructor.
+ *
+ * @covers CI_Input::__construct()
+ */
+ public function __construct($security, $utf8)
+ {
+ $this->_allow_get_array = (config_item('allow_get_array') === TRUE);
+ $this->_enable_xss = (config_item('global_xss_filtering') === TRUE);
+ $this->_enable_csrf = (config_item('csrf_protection') === TRUE);
+
+ // Assign Security and Utf8 classes
+ $this->security = $security;
+ $this->uni = $utf8;
+
+ // Sanitize global arrays
+ $this->_sanitize_globals();
+ }
+
+ public function fetch_from_array($array, $index = '', $xss_clean = FALSE)
+ {
+ return parent::_fetch_from_array($array, $index, $xss_clean);
+ }
+
+} \ No newline at end of file
diff --git a/tests/mocks/core/security.php b/tests/mocks/core/security.php
new file mode 100644
index 000000000..d7ea0e6bd
--- /dev/null
+++ b/tests/mocks/core/security.php
@@ -0,0 +1,30 @@
+<?php
+
+class Mock_Core_Security extends CI_Security {
+
+ public function csrf_set_cookie()
+ {
+ // We cannot set cookie in CLI mode, so for csrf test, who rely on $_COOKIE,
+ // we superseded set_cookie with directly set the cookie variable,
+ // @see : ./tests/codeigniter/core/Security_test.php, line 8
+ return $this;
+ }
+
+ // Overide inaccesible protected properties
+ public function __get($property)
+ {
+ return isset($this->{'_'.$property}) ? $this->{'_'.$property} : NULL;
+ }
+
+ // Overide inaccesible protected method
+ public function __call($method, $params)
+ {
+ if (is_callable(array($this, '_'.$method)))
+ {
+ return call_user_func_array(array($this, '_'.$method), $params);
+ }
+
+ throw new BadMethodCallException('Method '.$method.' was not found');
+ }
+
+} \ No newline at end of file
diff --git a/tests/mocks/core/utf8.php b/tests/mocks/core/utf8.php
new file mode 100644
index 000000000..b77d717e7
--- /dev/null
+++ b/tests/mocks/core/utf8.php
@@ -0,0 +1,27 @@
+<?php
+
+class Mock_Core_Utf8 extends CI_Utf8 {
+
+ /**
+ * We need to define several constants as
+ * the same process within CI_Utf8 class constructor.
+ *
+ * @covers CI_Utf8::__construct()
+ */
+ public function __construct()
+ {
+ defined('UTF8_ENABLED') or define('UTF8_ENABLED', TRUE);
+
+ if (extension_loaded('mbstring'))
+ {
+ defined('MB_ENABLED') or define('MB_ENABLED', TRUE);
+ mb_internal_encoding('UTF-8');
+ }
+ else
+ {
+ defined('MB_ENABLED') or define('MB_ENABLED', FALSE);
+ }
+
+ }
+
+} \ No newline at end of file
diff --git a/tests/mocks/libraries/table.php b/tests/mocks/libraries/table.php
index 1a6ff8d35..97fbb30bd 100644
--- a/tests/mocks/libraries/table.php
+++ b/tests/mocks/libraries/table.php
@@ -2,7 +2,7 @@
class Mock_Libraries_Table extends CI_Table {
- // Overide inaccesible private or protected method
+ // Overide inaccesible protected method
public function __call($method, $params)
{
if (is_callable(array($this, '_'.$method)))