summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAndrey Andreev <narf@devilix.net>2016-12-14 17:14:35 +0100
committerAndrey Andreev <narf@devilix.net>2016-12-14 17:14:35 +0100
commitdcd6f5153b7e7e6d798d5a77af65b7460f152e5c (patch)
tree3f52a8b24fe55aeaf29f6cdb6dfa5b6e9f2ac095 /tests
parent24c866628d0ce5463d7e8b4eba512fa9e7752dfd (diff)
Isolate CI_Security instantiation from CI_Input; improve tests
Diffstat (limited to 'tests')
-rw-r--r--tests/codeigniter/core/Input_test.php4
-rw-r--r--tests/codeigniter/core/URI_test.php9
-rw-r--r--tests/codeigniter/core/Utf8_test.php53
-rw-r--r--tests/codeigniter/helpers/cookie_helper_test.php5
-rw-r--r--tests/codeigniter/helpers/text_helper_test.php23
-rw-r--r--tests/codeigniter/helpers/url_helper_test.php12
-rw-r--r--tests/codeigniter/libraries/Form_validation_test.php4
-rw-r--r--tests/mocks/ci_testcase.php4
-rw-r--r--tests/mocks/core/input.php8
-rw-r--r--tests/mocks/core/utf8.php19
10 files changed, 69 insertions, 72 deletions
diff --git a/tests/codeigniter/core/Input_test.php b/tests/codeigniter/core/Input_test.php
index e1f4011b5..78b659691 100644
--- a/tests/codeigniter/core/Input_test.php
+++ b/tests/codeigniter/core/Input_test.php
@@ -15,9 +15,7 @@ class Input_test extends CI_TestCase {
$security = new Mock_Core_Security();
$this->ci_set_config('charset', 'UTF-8');
- $utf8 = new Mock_Core_Utf8();
-
- $this->input = new Mock_Core_Input($security, $utf8);
+ $this->input = new Mock_Core_Input($security);
}
// --------------------------------------------------------------------
diff --git a/tests/codeigniter/core/URI_test.php b/tests/codeigniter/core/URI_test.php
index 42dff3639..f862c666e 100644
--- a/tests/codeigniter/core/URI_test.php
+++ b/tests/codeigniter/core/URI_test.php
@@ -119,8 +119,13 @@ class URI_test extends CI_TestCase {
*/
// --------------------------------------------------------------------
+ /**
+ * @runInSeparateProcess
+ */
public function test_filter_uri_passing()
{
+ define('UTF8_ENABLED', FALSE);
+
$this->uri->_set_permitted_uri_chars('a-z 0-9~%.:_\-');
$str = 'abc01239~%.:_-';
@@ -129,8 +134,12 @@ class URI_test extends CI_TestCase {
// --------------------------------------------------------------------
+ /**
+ * @runInSeparateProcess
+ */
public function test_filter_uri_throws_error()
{
+ define('UTF8_ENABLED', FALSE);
$this->setExpectedException('RuntimeException');
$this->uri->config->set_item('enable_query_strings', FALSE);
diff --git a/tests/codeigniter/core/Utf8_test.php b/tests/codeigniter/core/Utf8_test.php
index 7e6ffd930..f40bb9848 100644
--- a/tests/codeigniter/core/Utf8_test.php
+++ b/tests/codeigniter/core/Utf8_test.php
@@ -1,31 +1,27 @@
<?php
+/**
+ * @runTestsInSeparateProcesses
+ */
class Utf8_test extends CI_TestCase {
- public function set_up()
+ public function test___constructUTF8_ENABLED()
{
- $this->ci_set_config('charset', 'UTF-8');
- $this->utf8 = new Mock_Core_Utf8();
- $this->ci_instance_var('utf8', $this->utf8);
+ if ( ! defined('PREG_BAD_UTF8_ERROR') OR (ICONV_ENABLED === FALSE && MB_ENABLED === FALSE))
+ {
+ return $this->markTestSkipped('PCRE_UTF8 and/or both ext/mbstring & ext/iconv are unavailable');
+ }
+
+ new CI_Utf8('UTF-8');
+ $this->assertTrue(UTF8_ENABLED);
}
// --------------------------------------------------------------------
- /**
- * __construct() test
- *
- * @covers CI_Utf8::__construct
- */
- public function test___construct()
+ public function test__constructUTF8_DISABLED()
{
- if (defined('PREG_BAD_UTF8_ERROR') && (ICONV_ENABLED === TRUE OR MB_ENABLED === TRUE) && strtoupper(config_item('charset')) === 'UTF-8')
- {
- $this->assertTrue(UTF8_ENABLED);
- }
- else
- {
- $this->assertFalse(UTF8_ENABLED);
- }
+ new CI_Utf8('WINDOWS-1251');
+ $this->assertFalse(UTF8_ENABLED);
}
// --------------------------------------------------------------------
@@ -37,8 +33,9 @@ class Utf8_test extends CI_TestCase {
*/
public function test_is_ascii()
{
- $this->assertTrue($this->utf8->is_ascii('foo bar'));
- $this->assertFalse($this->utf8->is_ascii('тест'));
+ $utf8 = new CI_Utf8('UTF-8');
+ $this->assertTrue($utf8->is_ascii('foo bar'));
+ $this->assertFalse($utf8->is_ascii('тест'));
}
// --------------------------------------------------------------------
@@ -51,21 +48,22 @@ class Utf8_test extends CI_TestCase {
*/
public function test_clean_string()
{
- $this->assertEquals('foo bar', $this->utf8->clean_string('foo bar'));
+ $utf8 = new CI_Utf8('UTF-8');
+ $this->assertEquals('foo bar', $utf8->clean_string('foo bar'));
$illegal_utf8 = "\xc0тест";
if (MB_ENABLED)
{
- $this->assertEquals('тест', $this->utf8->clean_string($illegal_utf8));
+ $this->assertEquals('тест', $utf8->clean_string($illegal_utf8));
}
elseif (ICONV_ENABLED)
{
// This is a known issue, iconv doesn't always work with //IGNORE
- $this->assertTrue(in_array($this->utf8->clean_string($illegal_utf8), array('тест', ''), TRUE));
+ $this->assertTrue(in_array($utf8->clean_string($illegal_utf8), array('тест', ''), TRUE));
}
else
{
- $this->assertEquals($illegal_utf8, $this->utf8->clean_string($illegal_utf8));
+ $this->assertEquals($illegal_utf8, $utf8->clean_string($illegal_utf8));
}
}
@@ -78,14 +76,15 @@ class Utf8_test extends CI_TestCase {
*/
public function test_convert_to_utf8()
{
+ $utf8 = new CI_Utf8('UTF-8');
if (MB_ENABLED OR ICONV_ENABLED)
{
- $this->assertEquals('тест', $this->utf8->convert_to_utf8('', 'WINDOWS-1251'));
+ $this->assertEquals('тест', $utf8->convert_to_utf8('', 'WINDOWS-1251'));
}
else
{
- $this->assertFalse($this->utf8->convert_to_utf8('', 'WINDOWS-1251'));
+ $this->assertFalse($utf8->convert_to_utf8('', 'WINDOWS-1251'));
}
}
-} \ No newline at end of file
+}
diff --git a/tests/codeigniter/helpers/cookie_helper_test.php b/tests/codeigniter/helpers/cookie_helper_test.php
index fba68f20f..1fbb57f67 100644
--- a/tests/codeigniter/helpers/cookie_helper_test.php
+++ b/tests/codeigniter/helpers/cookie_helper_test.php
@@ -29,9 +29,8 @@ class Cookie_helper_test extends CI_TestCase {
$_COOKIE['foo'] = 'bar';
$security = new Mock_Core_Security();
- $utf8 = new Mock_Core_Utf8();
$input_cls = $this->ci_core_class('input');
- $this->ci_instance_var('input', new Mock_Core_Input($security, $utf8));
+ $this->ci_instance_var('input', new Mock_Core_Input($security));
$this->assertEquals('bar', get_cookie('foo', FALSE));
$this->assertEquals('bar', get_cookie('foo', TRUE));
@@ -56,4 +55,4 @@ class Cookie_helper_test extends CI_TestCase {
$this->markTestSkipped('Need to find a way to overcome a headers already set exception');
}
-} \ No newline at end of file
+}
diff --git a/tests/codeigniter/helpers/text_helper_test.php b/tests/codeigniter/helpers/text_helper_test.php
index 7a7dc0a12..36465f203 100644
--- a/tests/codeigniter/helpers/text_helper_test.php
+++ b/tests/codeigniter/helpers/text_helper_test.php
@@ -2,21 +2,19 @@
class Text_helper_test extends CI_TestCase {
- private $_long_string;
-
public function set_up()
{
$this->helper('text');
-
- $this->_long_string = 'Once upon a time, a framework had no tests. It sad. So some nice people began to write tests. The more time that went on, the happier it became. Everyone was happy.';
}
// ------------------------------------------------------------------------
public function test_word_limiter()
{
- $this->assertEquals('Once upon a time,&#8230;', word_limiter($this->_long_string, 4));
- $this->assertEquals('Once upon a time,&hellip;', word_limiter($this->_long_string, 4, '&hellip;'));
+ $long_string = 'Once upon a time, a framework had no tests. It sad. So some nice people began to write tests. The more time that went on, the happier it became. Everyone was happy.';
+
+ $this->assertEquals('Once upon a time,&#8230;', word_limiter($long_string, 4));
+ $this->assertEquals('Once upon a time,&hellip;', word_limiter($long_string, 4, '&hellip;'));
$this->assertEquals('', word_limiter('', 4));
}
@@ -24,8 +22,10 @@ class Text_helper_test extends CI_TestCase {
public function test_character_limiter()
{
- $this->assertEquals('Once upon a time, a&#8230;', character_limiter($this->_long_string, 20));
- $this->assertEquals('Once upon a time, a&hellip;', character_limiter($this->_long_string, 20, '&hellip;'));
+ $long_string = 'Once upon a time, a framework had no tests. It sad. So some nice people began to write tests. The more time that went on, the happier it became. Everyone was happy.';
+
+ $this->assertEquals('Once upon a time, a&#8230;', character_limiter($long_string, 20));
+ $this->assertEquals('Once upon a time, a&hellip;', character_limiter($long_string, 20, '&hellip;'));
$this->assertEquals('Short', character_limiter('Short', 20));
$this->assertEquals('Short', character_limiter('Short', 5));
}
@@ -103,8 +103,13 @@ class Text_helper_test extends CI_TestCase {
// ------------------------------------------------------------------------
+ /**
+ * @runInSeparateProcess
+ */
public function test_highlight_phrase()
{
+ define('UTF8_ENABLED', FALSE);
+
$strs = array(
'this is a phrase' => '<mark>this is</mark> a phrase',
'this is another' => '<mark>this is</mark> another',
@@ -171,4 +176,4 @@ class Text_helper_test extends CI_TestCase {
$this->assertEquals(strpos(word_wrap($string), "\n"), 73);
}
-} \ No newline at end of file
+}
diff --git a/tests/codeigniter/helpers/url_helper_test.php b/tests/codeigniter/helpers/url_helper_test.php
index 24823a634..c5b0f80b7 100644
--- a/tests/codeigniter/helpers/url_helper_test.php
+++ b/tests/codeigniter/helpers/url_helper_test.php
@@ -7,8 +7,13 @@ class Url_helper_test extends CI_TestCase {
$this->helper('url');
}
+ /**
+ * @runInSeparateProcess
+ */
public function test_url_title()
{
+ define('UTF8_ENABLED', FALSE);
+
$words = array(
'foo bar /' => 'foo-bar',
'\ testing 12' => 'testing-12'
@@ -22,8 +27,13 @@ class Url_helper_test extends CI_TestCase {
// --------------------------------------------------------------------
+ /**
+ * @runInSeparateProcess
+ */
public function test_url_title_extra_dashes()
{
+ define('UTF8_ENABLED', FALSE);
+
$words = array(
'_foo bar_' => 'foo_bar',
'_What\'s wrong with CSS?_' => 'Whats_wrong_with_CSS'
@@ -76,4 +86,4 @@ class Url_helper_test extends CI_TestCase {
}
}
-} \ No newline at end of file
+}
diff --git a/tests/codeigniter/libraries/Form_validation_test.php b/tests/codeigniter/libraries/Form_validation_test.php
index 4be080f90..5b7830dd8 100644
--- a/tests/codeigniter/libraries/Form_validation_test.php
+++ b/tests/codeigniter/libraries/Form_validation_test.php
@@ -13,10 +13,8 @@ class Form_validation_test extends CI_TestCase {
// Same applies for lang
$lang = $this->getMockBuilder('CI_Lang')->setMethods(array('load'))->getMock();
- $this->ci_set_config('charset', 'UTF-8');
- $utf8 = new Mock_Core_Utf8();
$security = new Mock_Core_Security();
- $input = new Mock_Core_Input($security, $utf8);
+ $input = new Mock_Core_Input($security);
$this->ci_instance_var('lang', $lang);
$this->ci_instance_var('load', $loader);
diff --git a/tests/mocks/ci_testcase.php b/tests/mocks/ci_testcase.php
index a2c37b92e..b320aab74 100644
--- a/tests/mocks/ci_testcase.php
+++ b/tests/mocks/ci_testcase.php
@@ -24,9 +24,9 @@ class CI_TestCase extends PHPUnit_Framework_TestCase {
// --------------------------------------------------------------------
- public function __construct()
+ public function __construct($name = null, array $data = [], $dataName = '')
{
- parent::__construct();
+ parent::__construct($name, $data, $dataName);
$this->ci_instance = new stdClass();
}
diff --git a/tests/mocks/core/input.php b/tests/mocks/core/input.php
index 4d217a252..6f6a91365 100644
--- a/tests/mocks/core/input.php
+++ b/tests/mocks/core/input.php
@@ -9,12 +9,10 @@ class Mock_Core_Input extends CI_Input {
*
* @covers CI_Input::__construct()
*/
- public function __construct($security, $utf8)
+ public function __construct($security)
{
- $this->_enable_csrf = (config_item('csrf_protection') === TRUE);
-
- // Assign Security and Utf8 classes
- $this->security = $security;
+ $this->_enable_csrf = (config_item('csrf_protection') === TRUE);
+ $this->security = $security;
}
public function fetch_from_array($array, $index = '', $xss_clean = FALSE)
diff --git a/tests/mocks/core/utf8.php b/tests/mocks/core/utf8.php
deleted file mode 100644
index 3a6282e1d..000000000
--- a/tests/mocks/core/utf8.php
+++ /dev/null
@@ -1,19 +0,0 @@
-<?php
-
-class Mock_Core_Utf8 extends CI_Utf8 {
-
- /**
- * We need to define UTF8_ENABLED the same way that
- * CI_Utf8 constructor does.
- */
- public function __construct()
- {
- if (defined('UTF8_ENABLED'))
- {
- return;
- }
-
- parent::__construct();
- }
-
-} \ No newline at end of file