Added Checked validation

This commit is contained in:
Igor Scheller 2020-03-01 02:39:06 +01:00 committed by msquare
parent 951755598a
commit e42284deca
2 changed files with 45 additions and 0 deletions

View File

@ -0,0 +1,13 @@
<?php
namespace Engelsystem\Http\Validation\Rules;
use Respect\Validation\Rules\AbstractRule;
class Checked extends AbstractRule
{
public function validate($input)
{
return in_array($input, ['yes', 'on', 1, '1', 'true', true], true);
}
}

View File

@ -0,0 +1,32 @@
<?php
namespace Engelsystem\Test\Unit\Http\Validation\Rules;
use Engelsystem\Http\Validation\Rules\Checked;
use Engelsystem\Test\Unit\TestCase;
class CheckedTest extends TestCase
{
/**
* @covers \Engelsystem\Http\Validation\Rules\Checked::validate
*/
public function testValidate()
{
$rule = new Checked();
$this->assertTrue($rule->validate('yes'));
$this->assertTrue($rule->validate('on'));
$this->assertTrue($rule->validate(1));
$this->assertTrue($rule->validate('1'));
$this->assertTrue($rule->validate('true'));
$this->assertTrue($rule->validate(true));
$this->assertFalse($rule->validate('no'));
$this->assertFalse($rule->validate('off'));
$this->assertFalse($rule->validate(0));
$this->assertFalse($rule->validate('0'));
$this->assertFalse($rule->validate('false'));
$this->assertFalse($rule->validate(false));
$this->assertFalse($rule->validate(null));
}
}