Permalink
Browse files

Adding documentation and tests for boolean string types.

  • Loading branch information...
1 parent b17e7b8 commit 947b37439198587f9e1a6238ff48b37bcd8e370d @davidpersson davidpersson committed Sep 5, 2011
Showing with 12 additions and 1 deletion.
  1. +7 −0 tests/cases/util/ValidatorTest.php
  2. +5 −1 util/Validator.php
View
7 tests/cases/util/ValidatorTest.php
@@ -243,16 +243,23 @@ public function testIsNumericRule() {
public function testBooleanValidation() {
$this->assertTrue(Validator::isBoolean(true));
$this->assertTrue(Validator::isBoolean(false));
+ $this->assertTrue(Validator::isBoolean('true'));
+ $this->assertTrue(Validator::isBoolean('false'));
$this->assertTrue(Validator::isBoolean(0));
$this->assertTrue(Validator::isBoolean(1));
$this->assertTrue(Validator::isBoolean('0'));
$this->assertTrue(Validator::isBoolean('1'));
+ $this->assertTrue(Validator::isBoolean('on'));
+ $this->assertTrue(Validator::isBoolean('off'));
+ $this->assertTrue(Validator::isBoolean('yes'));
+ $this->assertTrue(Validator::isBoolean('no'));
$this->assertFalse(Validator::isBoolean('11'));
$this->assertFalse(Validator::isBoolean('-1'));
$this->assertFalse(Validator::isBoolean(-1));
$this->assertFalse(Validator::isBoolean(11));
$this->assertFalse(Validator::isBoolean(null));
+ $this->assertFalse(Validator::isBoolean('test'));
}
/**
View
6 util/Validator.php
@@ -79,7 +79,11 @@
* - `time`: Checks that a value is a valid time. Validates time as 24hr (HH:MM) or am/pm
* ([ H]H:MM[a|p]m). Does not allow / validate seconds.
*
- * - `boolean`: Checks that a value is a boolean integer or `true` or `false`.
+ * - `boolean`: Checks that the value is or looks like a boolean value. The following types of
+ * values are interpreted as boolean and will pass the check.
+ * - boolean (`true`, `false`, `'true'`, `'false'`)
+ * - boolean number (`1`, `0`, `'1`', `'0`')
+ * - boolean text string (`'on'`, `'off'`, `'yes'`, `'no'`)
*
* - `decimal`: Checks that a value is a valid decimal. Takes one option, `'precision'`, which is
* an optional integer value defining the level of precision the decimal number must match.

0 comments on commit 947b374

Please sign in to comment.