public function testIsBool() { $this->assertTrue(SpoonFilter::isBool('true')); $this->assertTrue(SpoonFilter::isBool(1)); $this->assertTrue(SpoonFilter::isBool('on')); $this->assertTrue(SpoonFilter::isBool('yes')); $this->assertTrue(SpoonFilter::isBool('false')); $this->assertTrue(SpoonFilter::isBool(0)); $this->assertFalse(SpoonFilter::isBool(100)); $this->assertFalse(SpoonFilter::isBool(900)); $this->assertTrue(SpoonFilter::isBool(00)); $this->assertFalse(SpoonFilter::isBool(array())); }
/** * Checks this field for a boolean (true/false | 0/1). * * @return bool * @param string[optional] $error The error message to set. */ public function isBool($error = null) { // filled if ($this->isFilled()) { // post/get data $data = $this->getMethod(true); // validate if (!isset($data[$this->attributes['name']]) || !SpoonFilter::isBool($data[$this->attributes['name']])) { if ($error !== null) { $this->setError($error); } return false; } return true; } // not submitted if ($error !== null) { $this->setError($error); } return false; }