summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrey Andreev <narf@devilix.net>2016-10-20 12:40:57 +0200
committerAndrey Andreev <narf@devilix.net>2016-10-20 12:40:57 +0200
commit5d05372f4f59d27fdd93249d813970fcf181a4af (patch)
tree2b82203f66babc12017eb6b9f350502e2aa5d085
parent34fe402ea28e928865ec15242e8f20f760b7a334 (diff)
FV: throw BadMethodCallException when set_rules() called without
-rw-r--r--system/libraries/Form_validation.php6
-rw-r--r--tests/codeigniter/libraries/Form_validation_test.php6
-rw-r--r--user_guide_src/source/changelog.rst4
-rw-r--r--user_guide_src/source/libraries/form_validation.rst3
4 files changed, 17 insertions, 2 deletions
diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php
index 86a569ced..4380dd276 100644
--- a/system/libraries/Form_validation.php
+++ b/system/libraries/Form_validation.php
@@ -164,7 +164,7 @@ class CI_Form_validation {
* @param array $errors
* @return CI_Form_validation
*/
- public function set_rules($field, $label = '', $rules = array(), $errors = array())
+ public function set_rules($field, $label = null, $rules = null, $errors = array())
{
// No reason to set rules if we have no POST data
// or a validation array has not been specified
@@ -197,6 +197,10 @@ class CI_Form_validation {
return $this;
}
+ elseif ( ! isset($rules))
+ {
+ throw new BadMethodCallException('Form_validation: set_rules() called without a $rules parameter');
+ }
// No fields or no rules? Nothing to do...
if ( ! is_string($field) OR $field === '' OR empty($rules))
diff --git a/tests/codeigniter/libraries/Form_validation_test.php b/tests/codeigniter/libraries/Form_validation_test.php
index 0815300e6..5f4bb9316 100644
--- a/tests/codeigniter/libraries/Form_validation_test.php
+++ b/tests/codeigniter/libraries/Form_validation_test.php
@@ -435,6 +435,12 @@ class Form_validation_test extends CI_TestCase {
$this->assertFalse($form_validation->run('fail'));
}
+ public function test_set_rules_exception()
+ {
+ $this->setExpectedException('BadMethodCallException');
+ $this->form_validation->set_rules('foo', 'bar');
+ }
+
public function test_has_rule()
{
$this->form_validation->reset_validation();
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index 3e7749f5b..4bff51a93 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -23,6 +23,10 @@ Release Date: Not Released
- Removed the *socket_type* configuration setting from the 'redis' driver.
- Changed data serialization logic in 'redis' driver for better performance.
+ - :doc:`Form Validation Library <libraries/form_validation>` changes include:
+
+ - Changed method ``set_rules()`` to throw a ``BadMethodCallException`` when its first parameter is not an array and the ``$rules`` one is unused.
+
- Database
- Changed method ``initialize()`` to return void and instead throw a ``RuntimeException`` in case of failure.
diff --git a/user_guide_src/source/libraries/form_validation.rst b/user_guide_src/source/libraries/form_validation.rst
index 7792369b2..b503b9be0 100644
--- a/user_guide_src/source/libraries/form_validation.rst
+++ b/user_guide_src/source/libraries/form_validation.rst
@@ -1027,13 +1027,14 @@ Class Reference
.. php:class:: CI_Form_validation
- .. php:method:: set_rules($field[, $label = ''[, $rules = ''[, $errors = array()]]])
+ .. php:method:: set_rules($field[, $label = null[, $rules = null[, $errors = array()]]])
:param string $field: Field name
:param string $label: Field label
:param mixed $rules: Validation rules, as a string list separated by a pipe "|", or as an array or rules
:param array $errors: A list of custom error messages
:returns: CI_Form_validation instance (method chaining)
+ :throws: BadMethodCallException If $field is not an array and $rules was not used
:rtype: CI_Form_validation
Permits you to set validation rules, as described in the tutorial