You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

34 lines
1.1 KiB

<?php
namespace yiiunit\framework\validators;
use yii\validators\RequiredValidator;
use yiiunit\TestCase;
class RequiredValidatorTest extends TestCase
{
public function testValidateValueWithDefaults()
{
$val = new RequiredValidator();
$this->assertFalse($val->validateValue(null));
$this->assertFalse($val->validateValue(array()));
$this->assertTrue($val->validateValue('not empty'));
$this->assertTrue($val->validateValue(array('with', 'elements')));
}
public function testValidateValueWithValue()
{
$val = new RequiredValidator(array('requiredValue' => 55));
$this->assertTrue($val->validateValue(55));
$this->assertTrue($val->validateValue("55"));
$this->assertTrue($val->validateValue("0x37"));
$this->assertFalse($val->validateValue("should fail"));
$this->assertTrue($val->validateValue(true));
$val->strict = true;
$this->assertTrue($val->validateValue(55));
$this->assertFalse($val->validateValue("55"));
$this->assertFalse($val->validateValue("0x37"));
$this->assertFalse($val->validateValue("should fail"));
$this->assertFalse($val->validateValue(true));
}
}