Browse Source

Added RequiredValidatorTest

tags/2.0.0-beta
Suralc 11 years ago
parent
commit
d9f87f4045
  1. 34
      tests/unit/framework/validators/RequiredValidatorTest.php

34
tests/unit/framework/validators/RequiredValidatorTest.php

@ -0,0 +1,34 @@
<?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));
}
}
Loading…
Cancel
Save