From 43d3a2c2cab6405dde6e68662659574bea0e6432 Mon Sep 17 00:00:00 2001 From: Zach Ploskey Date: Wed, 11 Oct 2017 08:24:06 -0700 Subject: Clean up form validation tests Remove a number unnecessary calls to reset_validation(). A new form_validation object is already initialized for every test in set_up(), so these lines do nothing unless multiple validations are done in the same test. Explicitly empty the $_POST array after each test that modifies it. Signed-off-by: Zach Ploskey --- .../codeigniter/libraries/Form_validation_test.php | 42 +++++++++++----------- 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'tests/codeigniter/libraries') diff --git a/tests/codeigniter/libraries/Form_validation_test.php b/tests/codeigniter/libraries/Form_validation_test.php index b70f950a2..90dd721a3 100644 --- a/tests/codeigniter/libraries/Form_validation_test.php +++ b/tests/codeigniter/libraries/Form_validation_test.php @@ -321,9 +321,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'); @@ -342,9 +339,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( @@ -372,7 +366,6 @@ class Form_validation_test extends CI_TestCase { public function test_set_error_delimiters() { - $this->form_validation->reset_validation(); $prefix = '
'; $suffix = '
'; $this->form_validation->set_error_delimiters($prefix, $suffix); @@ -383,11 +376,12 @@ class Form_validation_test extends CI_TestCase { $this->assertTrue(strrpos($error_msg, $prefix) === 0); $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'); @@ -395,11 +389,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 = ''; $suffix_default = ''; @@ -421,6 +416,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() @@ -449,6 +446,8 @@ 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_set_rules_exception() @@ -459,7 +458,6 @@ class Form_validation_test extends CI_TestCase { 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')); @@ -468,7 +466,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'); @@ -480,12 +477,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_issue_5202() { $data = array('person' => array('firstname' => 'Dick', 'lastname' => 'Tracy ')); - $this->form_validation->reset_validation(); $this->form_validation->set_rules('person[firstname]', 'First Name', 'required|trim'); $this->form_validation->set_rules('person[lastname]', 'Last Name', 'required|trim'); $this->form_validation->set_data($data); @@ -499,8 +497,6 @@ class Form_validation_test extends CI_TestCase { 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')); @@ -529,13 +525,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')); @@ -565,13 +561,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')); @@ -600,6 +596,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() @@ -638,7 +636,6 @@ class Form_validation_test extends CI_TestCase { $this->assertEquals($post_original, $_POST); $this->assertEquals(array('foo' => 'bar', 'bar' => 'baz'), $data_processed); - $this->form_validation->reset_validation(); $_POST = array(); } @@ -652,13 +649,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; } } -- cgit v1.2.3-24-g4f1b