diff options
author | Andrey Andreev <narf@devilix.net> | 2018-06-12 15:46:16 +0200 |
---|---|---|
committer | Andrey Andreev <narf@devilix.net> | 2018-06-12 15:46:16 +0200 |
commit | bb451aa0e4853f9afd4263769eeea1d9aad3a600 (patch) | |
tree | aa3770006128ab46d570e6b6aad756e4e92299d9 /tests | |
parent | e76217041ddcae80f11b50b44a7d409b6722ad40 (diff) | |
parent | a9da3dd2f16a8f97d7bc4ff5572b28e4bb84c813 (diff) |
Merge branch '3.1-stable'
Diffstat (limited to 'tests')
25 files changed, 135 insertions, 103 deletions
diff --git a/tests/codeigniter/core/Benchmark_test.php b/tests/codeigniter/core/Benchmark_test.php index 63b0e3d5a..33bd742b2 100644 --- a/tests/codeigniter/core/Benchmark_test.php +++ b/tests/codeigniter/core/Benchmark_test.php @@ -15,7 +15,7 @@ class Benchmark_test extends CI_TestCase { $this->benchmark->mark('code_start'); - $this->assertEquals(1, count($this->benchmark->marker)); + $this->assertCount(1, $this->benchmark->marker); $this->assertArrayHasKey('code_start', $this->benchmark->marker); } @@ -64,4 +64,4 @@ class Benchmark_test extends CI_TestCase { $this->assertEquals('{memory_usage}', $this->benchmark->memory_usage()); } -}
\ No newline at end of file +} diff --git a/tests/codeigniter/core/Common_test.php b/tests/codeigniter/core/Common_test.php index ca19e5de0..effae50c5 100644 --- a/tests/codeigniter/core/Common_test.php +++ b/tests/codeigniter/core/Common_test.php @@ -4,8 +4,8 @@ class Common_test extends CI_TestCase { public function test_is_php() { - $this->assertEquals(TRUE, is_php('1.2.0')); - $this->assertEquals(FALSE, is_php('9999.9.9')); + $this->assertTrue(is_php('1.2.0')); + $this->assertFalse(is_php('9999.9.9')); } // ------------------------------------------------------------------------ @@ -66,4 +66,4 @@ class Common_test extends CI_TestCase { $removed_string = 'Here is a string containing url_encoded invisible text.'; $this->assertEquals($removed_string, remove_invisible_characters($raw_string)); } -}
\ No newline at end of file +} diff --git a/tests/codeigniter/core/Input_test.php b/tests/codeigniter/core/Input_test.php index e1f4011b5..976941d41 100644 --- a/tests/codeigniter/core/Input_test.php +++ b/tests/codeigniter/core/Input_test.php @@ -24,8 +24,8 @@ class Input_test extends CI_TestCase { public function test_get_not_exists() { - $this->assertTrue($this->input->get() === array()); - $this->assertTrue($this->input->get('foo') === NULL); + $this->assertSame(array(), $this->input->get()); + $this->assertNull($this->input->get('foo')); } // -------------------------------------------------------------------- @@ -55,8 +55,8 @@ class Input_test extends CI_TestCase { public function test_post_not_exists() { - $this->assertTrue($this->input->post() === array()); - $this->assertTrue($this->input->post('foo') === NULL); + $this->assertSame(array(), $this->input->post()); + $this->assertNull($this->input->post('foo')); } // -------------------------------------------------------------------- diff --git a/tests/codeigniter/core/Log_test.php b/tests/codeigniter/core/Log_test.php index d5a6fcb6b..103af342b 100644 --- a/tests/codeigniter/core/Log_test.php +++ b/tests/codeigniter/core/Log_test.php @@ -28,7 +28,7 @@ class Log_test extends CI_TestCase { $this->assertEquals($date_fmt->getValue($instance), 'd.m.Y'); $this->assertEquals($file_ext->getValue($instance), 'php'); $this->assertEquals($file_perms->getValue($instance), 0644); - $this->assertEquals($enabled->getValue($instance), FALSE); + $this->assertFalse($enabled->getValue($instance)); $this->ci_set_config('log_path', ''); $this->ci_set_config('log_threshold', '0'); @@ -60,4 +60,4 @@ class Log_test extends CI_TestCase { "LEVEL - Timestamp --> Message\n" ); } -}
\ No newline at end of file +} diff --git a/tests/codeigniter/core/Security_test.php b/tests/codeigniter/core/Security_test.php index 4c54ec9fa..c3113adba 100644 --- a/tests/codeigniter/core/Security_test.php +++ b/tests/codeigniter/core/Security_test.php @@ -252,7 +252,7 @@ class Security_test extends CI_TestCase { // Perform hash $this->security->xss_hash(); - $this->assertTrue(preg_match('#^[0-9a-f]{32}$#iS', $this->security->xss_hash) === 1); + $this->assertRegExp('#^[0-9a-f]{32}$#iS', $this->security->xss_hash); } // -------------------------------------------------------------------- diff --git a/tests/codeigniter/core/Utf8_test.php b/tests/codeigniter/core/Utf8_test.php index 7e6ffd930..a0327dbd7 100644 --- a/tests/codeigniter/core/Utf8_test.php +++ b/tests/codeigniter/core/Utf8_test.php @@ -61,7 +61,7 @@ class Utf8_test extends CI_TestCase { 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->assertContains($utf8->clean_string($illegal_utf8), array('тест', '')); } else { @@ -88,4 +88,4 @@ class Utf8_test extends CI_TestCase { } } -}
\ No newline at end of file +} diff --git a/tests/codeigniter/core/compat/password_test.php b/tests/codeigniter/core/compat/password_test.php index 77f5eba4e..b6dbcfab1 100644 --- a/tests/codeigniter/core/compat/password_test.php +++ b/tests/codeigniter/core/compat/password_test.php @@ -156,4 +156,4 @@ class password_test extends CI_TestCase { $this->assertTrue(password_verify('rasmuslerdorf', '$2a$07$usesomesillystringfore2uDLvp1Ii2e./U9C8sBjqp8I90dH6hi')); } -}
\ No newline at end of file +} diff --git a/tests/codeigniter/database/DB_test.php b/tests/codeigniter/database/DB_test.php index dc4fae986..9d53fd6f2 100644 --- a/tests/codeigniter/database/DB_test.php +++ b/tests/codeigniter/database/DB_test.php @@ -36,8 +36,8 @@ class DB_test extends CI_TestCase { $db = Mock_Database_DB::DB($connection->set_dsn(DB_DRIVER), TRUE); - $this->assertTrue($db instanceof CI_DB); - $this->assertTrue($db instanceof CI_DB_Driver); + $this->assertInstanceOf('CI_DB', $db); + $this->assertInstanceOf('CI_DB_Driver', $db); } // ------------------------------------------------------------------------ @@ -53,9 +53,9 @@ class DB_test extends CI_TestCase { $connection = new Mock_Database_DB($config); $db = Mock_Database_DB::DB($connection->set_dsn(DB_DRIVER.'_failover'), TRUE); - $this->assertTrue($db instanceof CI_DB); - $this->assertTrue($db instanceof CI_DB_Driver); + $this->assertInstanceOf('CI_DB', $db); + $this->assertInstanceOf('CI_DB_Driver', $db); } */ -}
\ No newline at end of file +} diff --git a/tests/codeigniter/database/query_builder/distinct_test.php b/tests/codeigniter/database/query_builder/distinct_test.php index cc98009ce..81fabe448 100644 --- a/tests/codeigniter/database/query_builder/distinct_test.php +++ b/tests/codeigniter/database/query_builder/distinct_test.php @@ -27,7 +27,7 @@ class Distinct_test extends CI_TestCase { ->get('user') ->result_array(); - $this->assertEquals(3, count($users)); + $this->assertCount(3, $users); } -}
\ No newline at end of file +} diff --git a/tests/codeigniter/database/query_builder/empty_test.php b/tests/codeigniter/database/query_builder/empty_test.php index d1f56285f..3f63a60f5 100644 --- a/tests/codeigniter/database/query_builder/empty_test.php +++ b/tests/codeigniter/database/query_builder/empty_test.php @@ -25,7 +25,7 @@ class Empty_test extends CI_TestCase { // Check initial record $jobs = $this->db->get('job')->result_array(); - $this->assertEquals(4, count($jobs)); + $this->assertCount(4, $jobs); // Do the empty $this->db->empty_table('job'); @@ -36,4 +36,4 @@ class Empty_test extends CI_TestCase { $this->assertEmpty($jobs->result_array()); } -}
\ No newline at end of file +} diff --git a/tests/codeigniter/database/query_builder/escape_test.php b/tests/codeigniter/database/query_builder/escape_test.php index 27e678f22..de6cd0a9d 100644 --- a/tests/codeigniter/database/query_builder/escape_test.php +++ b/tests/codeigniter/database/query_builder/escape_test.php @@ -37,7 +37,7 @@ class Escape_test extends CI_TestCase { $res = $this->db->query($sql)->result_array(); // Check the result - $this->assertEquals(1, count($res)); + $this->assertCount(1, $res); } // ------------------------------------------------------------------------ @@ -62,7 +62,7 @@ class Escape_test extends CI_TestCase { $res = $this->db->query($sql)->result_array(); // Check the result - $this->assertEquals(2, count($res)); + $this->assertCount(2, $res); } -}
\ No newline at end of file +} diff --git a/tests/codeigniter/database/query_builder/from_test.php b/tests/codeigniter/database/query_builder/from_test.php index 7aaae348d..5a4ac690d 100644 --- a/tests/codeigniter/database/query_builder/from_test.php +++ b/tests/codeigniter/database/query_builder/from_test.php @@ -26,7 +26,7 @@ class From_test extends CI_TestCase { ->get() ->result_array(); - $this->assertEquals(4, count($jobs)); + $this->assertCount(4, $jobs); } // ------------------------------------------------------------------------ @@ -46,4 +46,4 @@ class From_test extends CI_TestCase { $this->assertEquals('Awesome job, but sometimes makes you bored', $job1->description); } -}
\ No newline at end of file +} diff --git a/tests/codeigniter/database/query_builder/group_test.php b/tests/codeigniter/database/query_builder/group_test.php index 5249f7c87..b40e5e507 100644 --- a/tests/codeigniter/database/query_builder/group_test.php +++ b/tests/codeigniter/database/query_builder/group_test.php @@ -28,7 +28,7 @@ class Group_test extends CI_TestCase { ->get() ->result_array(); - $this->assertEquals(4, count($jobs)); + $this->assertCount(4, $jobs); } // ------------------------------------------------------------------------ @@ -45,7 +45,6 @@ class Group_test extends CI_TestCase { ->get() ->result_array(); - $this->assertEquals(2, count($jobs)); + $this->assertCount(2, $jobs); } - -}
\ No newline at end of file +} diff --git a/tests/codeigniter/database/query_builder/like_test.php b/tests/codeigniter/database/query_builder/like_test.php index 2736fbe0b..4d8673d99 100644 --- a/tests/codeigniter/database/query_builder/like_test.php +++ b/tests/codeigniter/database/query_builder/like_test.php @@ -44,7 +44,7 @@ class Like_test extends CI_TestCase { ->result_array(); // Check the result - $this->assertEquals(3, count($jobs)); + $this->assertCount(3, $jobs); $this->assertEquals('Developer', $jobs[0]['name']); $this->assertEquals('Politician', $jobs[1]['name']); $this->assertEquals('Musician', $jobs[2]['name']); @@ -62,7 +62,7 @@ class Like_test extends CI_TestCase { ->result_array(); // Check the result - $this->assertEquals(3, count($jobs)); + $this->assertCount(3, $jobs); $this->assertEquals('Politician', $jobs[0]['name']); $this->assertEquals('Accountant', $jobs[1]['name']); $this->assertEquals('Musician', $jobs[2]['name']); @@ -81,7 +81,7 @@ class Like_test extends CI_TestCase { ->result_array(); // Check the result - $this->assertEquals(3, count($jobs)); + $this->assertCount(3, $jobs); $this->assertEquals('Politician', $jobs[0]['name']); $this->assertEquals('Accountant', $jobs[1]['name']); $this->assertEquals('Musician', $jobs[2]['name']); @@ -99,8 +99,31 @@ class Like_test extends CI_TestCase { $spaces = $this->db->like('value', ' ')->get('misc')->result_array(); $tabs = $this->db->like('value', "\t")->get('misc')->result_array(); - $this->assertEquals(1, count($spaces)); - $this->assertEquals(1, count($tabs)); + $this->assertCount(1, $spaces); + $this->assertCount(1, $tabs); } -}
\ No newline at end of file + /** + * GitHub issue #5462 + * + * @see ./mocks/schema/skeleton.php + * + * @dataProvider like_set_side_provider + */ + public function test_like_set_side($str, $side, $expected_name) + { + $actual = $this->db->like('name', $str, $side)->get('job')->result_array(); + $this->assertCount(1, $actual); + $this->assertEquals($expected_name, $actual[0]['name']); + } + + public function like_set_side_provider() + { + return array( + array('Developer', 'none', 'Developer'), + array('tician', 'before', 'Politician'), + array('Accou', 'after', 'Accountant'), + array('usicia', 'both', 'Musician'), + ); + } +} diff --git a/tests/codeigniter/database/query_builder/limit_test.php b/tests/codeigniter/database/query_builder/limit_test.php index a0954c7ab..a1976d457 100644 --- a/tests/codeigniter/database/query_builder/limit_test.php +++ b/tests/codeigniter/database/query_builder/limit_test.php @@ -26,7 +26,7 @@ class Limit_test extends CI_TestCase { ->get('job') ->result_array(); - $this->assertEquals(2, count($jobs)); + $this->assertCount(2, $jobs); } // ------------------------------------------------------------------------ @@ -40,9 +40,9 @@ class Limit_test extends CI_TestCase { ->get('job') ->result_array(); - $this->assertEquals(2, count($jobs)); + $this->assertCount(2, $jobs); $this->assertEquals('Accountant', $jobs[0]['name']); $this->assertEquals('Musician', $jobs[1]['name']); } -}
\ No newline at end of file +} diff --git a/tests/codeigniter/database/query_builder/order_test.php b/tests/codeigniter/database/query_builder/order_test.php index 46f452bae..ff5bc543d 100644 --- a/tests/codeigniter/database/query_builder/order_test.php +++ b/tests/codeigniter/database/query_builder/order_test.php @@ -27,7 +27,7 @@ class Order_test extends CI_TestCase { ->result_array(); // Check the result - $this->assertEquals(4, count($jobs)); + $this->assertCount(4, $jobs); $this->assertEquals('Accountant', $jobs[0]['name']); $this->assertEquals('Developer', $jobs[1]['name']); $this->assertEquals('Musician', $jobs[2]['name']); @@ -45,11 +45,11 @@ class Order_test extends CI_TestCase { ->get('job') ->result_array(); - $this->assertEquals(4, count($jobs)); + $this->assertCount(4, $jobs); $this->assertEquals('Politician', $jobs[0]['name']); $this->assertEquals('Musician', $jobs[1]['name']); $this->assertEquals('Developer', $jobs[2]['name']); $this->assertEquals('Accountant', $jobs[3]['name']); } -}
\ No newline at end of file +} diff --git a/tests/codeigniter/database/query_builder/select_test.php b/tests/codeigniter/database/query_builder/select_test.php index 877b5d8c0..93b5c3d46 100644 --- a/tests/codeigniter/database/query_builder/select_test.php +++ b/tests/codeigniter/database/query_builder/select_test.php @@ -28,8 +28,8 @@ class Select_test extends CI_TestCase { // Check rows item $this->assertArrayHasKey('name',$jobs_name[0]); - $this->assertFalse(array_key_exists('id', $jobs_name[0])); - $this->assertFalse(array_key_exists('description', $jobs_name[0])); + $this->assertArrayNotHasKey('id', $jobs_name[0]); + $this->assertArrayNotHasKey('description', $jobs_name[0]); } // ------------------------------------------------------------------------ @@ -92,4 +92,4 @@ class Select_test extends CI_TestCase { $this->assertEquals('10', $job_sum->id); } -}
\ No newline at end of file +} diff --git a/tests/codeigniter/database/query_builder/truncate_test.php b/tests/codeigniter/database/query_builder/truncate_test.php index 09923c7f1..64abe2872 100644 --- a/tests/codeigniter/database/query_builder/truncate_test.php +++ b/tests/codeigniter/database/query_builder/truncate_test.php @@ -24,7 +24,7 @@ class Truncate_test extends CI_TestCase { { // Check initial record $jobs = $this->db->get('job')->result_array(); - $this->assertEquals(4, count($jobs)); + $this->assertCount(4, $jobs); // Do the empty $this->db->truncate('job'); @@ -43,7 +43,7 @@ class Truncate_test extends CI_TestCase { { // Check initial record $users = $this->db->get('user')->result_array(); - $this->assertEquals(4, count($users)); + $this->assertCount(4, $users); // Do the empty $this->db->from('user')->truncate(); @@ -53,4 +53,4 @@ class Truncate_test extends CI_TestCase { $this->assertEmpty($users->result_array()); } -}
\ No newline at end of file +} diff --git a/tests/codeigniter/database/query_builder/where_test.php b/tests/codeigniter/database/query_builder/where_test.php index 46a7fa2eb..8a7a09ddb 100644 --- a/tests/codeigniter/database/query_builder/where_test.php +++ b/tests/codeigniter/database/query_builder/where_test.php @@ -36,7 +36,7 @@ class Where_test extends CI_TestCase { public function test_where_custom_key_value() { $jobs = $this->db->where('id !=', 1)->get('job')->result_array(); - $this->assertEquals(3, count($jobs)); + $this->assertCount(3, $jobs); } // ------------------------------------------------------------------------ @@ -49,7 +49,7 @@ class Where_test extends CI_TestCase { $where = array('id >' => 2, 'name !=' => 'Accountant'); $jobs = $this->db->where($where)->get('job')->result_array(); - $this->assertEquals(1, count($jobs)); + $this->assertCount(1, $jobs); // Should be Musician $job = current($jobs); @@ -66,7 +66,7 @@ class Where_test extends CI_TestCase { $where = "id > 2 AND name != 'Accountant'"; $jobs = $this->db->where($where)->get('job')->result_array(); - $this->assertEquals(1, count($jobs)); + $this->assertCount(1, $jobs); // Should be Musician $job = current($jobs); @@ -85,7 +85,7 @@ class Where_test extends CI_TestCase { ->get('job') ->result_array(); - $this->assertEquals(3, count($jobs)); + $this->assertCount(3, $jobs); $this->assertEquals('Developer', $jobs[0]['name']); $this->assertEquals('Politician', $jobs[1]['name']); $this->assertEquals('Musician', $jobs[2]['name']); @@ -102,7 +102,7 @@ class Where_test extends CI_TestCase { ->get('job') ->result_array(); - $this->assertEquals(2, count($jobs)); + $this->assertCount(2, $jobs); $this->assertEquals('Politician', $jobs[0]['name']); $this->assertEquals('Accountant', $jobs[1]['name']); } @@ -118,7 +118,7 @@ class Where_test extends CI_TestCase { ->get('job') ->result_array(); - $this->assertEquals(2, count($jobs)); + $this->assertCount(2, $jobs); $this->assertEquals('Developer', $jobs[0]['name']); $this->assertEquals('Musician', $jobs[1]['name']); } @@ -131,4 +131,4 @@ class Where_test extends CI_TestCase { $sql = $this->db->where('foo', $input)->get_compiled_select('dummy'); $this->assertEquals("'".$input."'", substr($sql, -20)); } -}
\ No newline at end of file +} diff --git a/tests/codeigniter/helpers/array_helper_test.php b/tests/codeigniter/helpers/array_helper_test.php index 5a9958971..b2409c330 100644 --- a/tests/codeigniter/helpers/array_helper_test.php +++ b/tests/codeigniter/helpers/array_helper_test.php @@ -31,15 +31,15 @@ class Array_helper_test extends CI_TestCase { $this->assertEquals('my string', random_element('my string')); // Test sending an array - $this->assertEquals(TRUE, in_array(random_element($this->my_array), $this->my_array)); + $this->assertContains(random_element($this->my_array), $this->my_array); } // ------------------------------------------------------------------------ public function test_elements() { - $this->assertEquals(TRUE, is_array(elements('test', $this->my_array))); - $this->assertEquals(TRUE, is_array(elements('foo', $this->my_array))); + $this->assertInternalType('array', elements('test', $this->my_array)); + $this->assertInternalType('array', elements('foo', $this->my_array)); } -}
\ 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..83a8c0ec2 100644 --- a/tests/codeigniter/helpers/url_helper_test.php +++ b/tests/codeigniter/helpers/url_helper_test.php @@ -53,7 +53,8 @@ class Url_helper_test extends CI_TestCase { '<br />www.google.com' => '<br /><a href="http://www.google.com">www.google.com</a>', 'Download CodeIgniter at www.codeigniter.com. Period test.' => 'Download CodeIgniter at <a href="http://www.codeigniter.com">www.codeigniter.com</a>. Period test.', 'Download CodeIgniter at www.codeigniter.com, comma test' => 'Download CodeIgniter at <a href="http://www.codeigniter.com">www.codeigniter.com</a>, comma test', - 'This one: ://codeigniter.com must not break this one: http://codeigniter.com' => 'This one: <a href="://codeigniter.com">://codeigniter.com</a> must not break this one: <a href="http://codeigniter.com">http://codeigniter.com</a>' + 'This one: ://codeigniter.com must not break this one: http://codeigniter.com' => 'This one: <a href="://codeigniter.com">://codeigniter.com</a> must not break this one: <a href="http://codeigniter.com">http://codeigniter.com</a>', + 'Trailing slash: https://codeigniter.com/ fubar' => 'Trailing slash: <a href="https://codeigniter.com/">https://codeigniter.com/</a> fubar' ); foreach ($strings as $in => $out) @@ -76,4 +77,13 @@ class Url_helper_test extends CI_TestCase { } } -}
\ No newline at end of file + // -------------------------------------------------------------------- + + public function test_issue_5331() + { + $this->assertEquals( + 'this is some text that includes '.safe_mailto('www.email@domain.com').' which is causing an issue', + auto_link('this is some text that includes www.email@domain.com which is causing an issue') + ); + } +} diff --git a/tests/codeigniter/libraries/Encryption_test.php b/tests/codeigniter/libraries/Encryption_test.php index 99c5d4b9d..8e411d9fa 100644 --- a/tests/codeigniter/libraries/Encryption_test.php +++ b/tests/codeigniter/libraries/Encryption_test.php @@ -151,7 +151,7 @@ class Encryption_test extends CI_TestCase { 'hmac_key' => str_repeat("\x0", 16) ); - $this->assertTrue(is_array($this->encryption->__get_params($params))); + $this->assertInternalType('array', $this->encryption->__get_params($params)); $params['base64'] = TRUE; $params['hmac_digest'] = 'sha512'; @@ -257,7 +257,7 @@ class Encryption_test extends CI_TestCase { return $this->markTestSkipped('ext/mcrypt is deprecated since PHP 7.1 and will generate notices here.'); } - $this->assertTrue(is_resource($this->encryption->__driver_get_handle('mcrypt', 'rijndael-128', 'cbc'))); + $this->assertInternalType('resource', $this->encryption->__driver_get_handle('mcrypt', 'rijndael-128', 'cbc')); } // -------------------------------------------------------------------- diff --git a/tests/codeigniter/libraries/Form_validation_test.php b/tests/codeigniter/libraries/Form_validation_test.php index c9c404b43..3280f5bd8 100644 --- a/tests/codeigniter/libraries/Form_validation_test.php +++ b/tests/codeigniter/libraries/Form_validation_test.php @@ -305,9 +305,6 @@ class Form_validation_test extends CI_TestCase { public function test_set_data() { - // Reset test environment - $_POST = array(); - $this->form_validation->reset_validation(); $data = array('field' => 'some_data'); $this->form_validation->set_data($data); $this->form_validation->set_rules('field', 'label', 'required'); @@ -326,9 +323,6 @@ class Form_validation_test extends CI_TestCase { public function test_set_message() { - // Reset test environment - $_POST = array(); - $this->form_validation->reset_validation(); $err_message = 'What a terrible error!'; $rules = array( array( @@ -356,7 +350,6 @@ class Form_validation_test extends CI_TestCase { public function test_set_error_delimiters() { - $this->form_validation->reset_validation(); $prefix = '<div class="error">'; $suffix = '</div>'; $this->form_validation->set_error_delimiters($prefix, $suffix); @@ -365,13 +358,14 @@ class Form_validation_test extends CI_TestCase { $this->form_validation->run(); $error_msg = $this->form_validation->error('foo'); - $this->assertTrue(strrpos($error_msg, $prefix) === 0); + $this->assertStringStartsWith($prefix, $error_msg); $this->assertTrue(strrpos($error_msg, $suffix, -strlen($suffix)) === (strlen($error_msg) - strlen($suffix))); + + $_POST = array(); } public function test_error_array() { - $this->form_validation->reset_validation(); $error_message = 'What a terrible error!'; $this->form_validation->set_message('required', $error_message); $this->form_validation->set_rules('foo', 'label', 'required'); @@ -379,11 +373,12 @@ class Form_validation_test extends CI_TestCase { $this->form_validation->run(); $error_array = $this->form_validation->error_array(); $this->assertEquals($error_message, $error_array['foo']); + + $_POST = array(); } public function test_error_string() { - $this->form_validation->reset_validation(); $error_message = 'What a terrible error!'; $prefix_default = '<foo>'; $suffix_default = '</foo>'; @@ -405,6 +400,8 @@ class Form_validation_test extends CI_TestCase { $_POST = array('foo' => 'bar'); $this->form_validation->run(); $this->assertEquals('', $this->form_validation->error_string()); + + $_POST = array(); } public function test_run() @@ -433,11 +430,12 @@ class Form_validation_test extends CI_TestCase { $form_validation = new CI_Form_validation($config); $this->assertFalse($form_validation->run('fail')); + + $_POST = array(); } public function test_has_rule() { - $this->form_validation->reset_validation(); $this->form_validation->set_rules('foo', 'label', 'required'); $this->assertTrue($this->form_validation->has_rule('foo')); @@ -446,7 +444,6 @@ class Form_validation_test extends CI_TestCase { public function test_set_value() { - $this->form_validation->reset_validation(); $default = 'default'; $this->form_validation->set_rules('foo', 'label', 'required'); $this->form_validation->set_rules('bar[]', 'label', 'required'); @@ -458,13 +455,13 @@ class Form_validation_test extends CI_TestCase { $this->assertEquals('foo', $this->form_validation->set_value('foo', $default)); $this->assertEquals('bar1', $this->form_validation->set_value('bar[]', $default)); $this->assertEquals('bar2', $this->form_validation->set_value('bar[]', $default)); + + $_POST = array(); } public function test_set_select() { // Test 1: No options selected - $this->form_validation->reset_validation(); - $_POST = array(); $this->form_validation->run(); $this->assertEquals('', $this->form_validation->set_select('select', 'foo')); @@ -493,13 +490,13 @@ class Form_validation_test extends CI_TestCase { $this->assertEquals(' selected="selected"', $this->form_validation->set_select('select[]', 'bar', TRUE)); $this->assertEquals('', $this->form_validation->set_select('select[]', 'foobar')); $this->assertEquals('', $this->form_validation->set_select('select[]', 'foobar', TRUE)); + + $_POST = array(); } public function test_set_radio() { // Test 1: No options selected - $this->form_validation->reset_validation(); - $_POST = array(); $this->form_validation->run(); $this->assertEquals('', $this->form_validation->set_radio('select', 'foo')); @@ -529,13 +526,13 @@ class Form_validation_test extends CI_TestCase { $this->assertEquals(' checked="checked"', $this->form_validation->set_radio('select[]', 'bar', TRUE)); $this->assertEquals('', $this->form_validation->set_radio('select[]', 'foobar')); $this->assertEquals('', $this->form_validation->set_radio('select[]', 'foobar', TRUE)); + + $_POST = array(); } public function test_set_checkbox() { // Test 1: No options selected - $this->form_validation->reset_validation(); - $_POST = array(); $this->form_validation->run(); $this->assertEquals('', $this->form_validation->set_checkbox('select', 'foo')); @@ -564,6 +561,8 @@ class Form_validation_test extends CI_TestCase { $this->assertEquals(' checked="checked"', $this->form_validation->set_checkbox('select[]', 'bar', TRUE)); $this->assertEquals('', $this->form_validation->set_checkbox('select[]', 'foobar')); $this->assertEquals('', $this->form_validation->set_checkbox('select[]', 'foobar', TRUE)); + + $_POST = array(); } public function test_regex_match() @@ -612,13 +611,16 @@ class Form_validation_test extends CI_TestCase { { $this->form_validation->reset_validation(); $_POST = array(); - $this->form_validation->set_rules($rules); + foreach ($values as $field => $value) { $_POST[$field] = $value; } - return $this->form_validation->run(); + $valid = $this->form_validation->run(); + $_POST = array(); + + return $valid; } } diff --git a/tests/codeigniter/libraries/Table_test.php b/tests/codeigniter/libraries/Table_test.php index 8e7452474..f505a43fc 100644 --- a/tests/codeigniter/libraries/Table_test.php +++ b/tests/codeigniter/libraries/Table_test.php @@ -67,7 +67,7 @@ class Table_test extends CI_TestCase { $this->table->add_row('your', 'pony', 'stinks'); $this->table->add_row('my pony', '>', 'your pony'); - $this->assertEquals(count($this->table->rows), 3); + $this->assertCount(3, $this->table->rows); $this->assertEquals( array( @@ -188,8 +188,8 @@ class Table_test extends CI_TestCase { } $this->assertFalse($this->table->auto_heading); - $this->assertEquals(count($this->table->heading), 3); - $this->assertEquals(count($this->table->rows), 2); + $this->assertCount(3, $this->table->heading); + $this->assertCount(2, $this->table->rows); $this->table->clear(); @@ -213,7 +213,7 @@ class Table_test extends CI_TestCase { $this->table->clear(); $this->table->set_from_array($data); - $this->assertEquals(count($this->table->rows), 2); + $this->assertCount(2, $this->table->rows); $expected = array( array('data' => 'name'), @@ -270,14 +270,14 @@ class Table_test extends CI_TestCase { $table = $this->table->generate($data); // Test the table header - $this->assertTrue(strpos($table, '<th>Name</th>') !== FALSE); - $this->assertTrue(strpos($table, '<th>Color</th>') !== FALSE); - $this->assertTrue(strpos($table, '<th>Size</th>') !== FALSE); + $this->assertContains('<th>Name</th>', $table); + $this->assertContains('<th>Color</th>', $table); + $this->assertContains('<th>Size</th>', $table); // Test the first entry - $this->assertTrue(strpos($table, '<td>Fred</td>') !== FALSE); - $this->assertTrue(strpos($table, '<td>Blue</td>') !== FALSE); - $this->assertTrue(strpos($table, '<td>Small</td>') !== FALSE); + $this->assertContains('<td>Fred</td>', $table); + $this->assertContains('<td>Blue</td>', $table); + $this->assertContains('<td>Small</td>', $table); } } @@ -297,4 +297,4 @@ class DB_result_dummy extends CI_DB_result array('name' => 'Foo Bar', 'email' => 'foo@bar.com') ); } -}
\ No newline at end of file +} diff --git a/tests/mocks/ci_testcase.php b/tests/mocks/ci_testcase.php index a2c37b92e..4f478fb4e 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 = array(), $dataName = '') { - parent::__construct(); + parent::__construct($name, $data, $dataName); $this->ci_instance = new stdClass(); } @@ -377,10 +377,8 @@ class CI_TestCase extends PHPUnit_Framework_TestCase { { return call_user_func_array($this->{$method},$args); } - else - { - return parent::__call($method, $args); - } + + return parent::__call($method, $args); } } |