DefaultValueValidatorTest.php 1.13 KB
Newer Older
Suralc committed
1
<?php
AlexGx committed
2

Suralc committed
3
namespace yiiunit\framework\validators;
AlexGx committed
4

Suralc committed
5 6 7 8
use yii\validators\DefaultValueValidator;
use yiiunit\TestCase;

/**
9
 * @group validators
Suralc committed
10 11 12
 */
class DefaultValueValidatorTest extends TestCase
{
13 14 15 16 17
    protected function setUp()
    {
        parent::setUp();
        $this->mockApplication();
    }
18

19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
    public function testValidateAttribute()
    {
        $val = new DefaultValueValidator;
        $val->value = 'test_value';
        $obj = new \stdclass;
        $obj->attrA = 'attrA';
        $obj->attrB = null;
        $obj->attrC = '';
        // original values to chek which attritubes where modified
        $objB = clone $obj;
        $val->validateAttribute($obj, 'attrB');
        $this->assertEquals($val->value, $obj->attrB);
        $this->assertEquals($objB->attrA, $obj->attrA);
        $val->value = 'new_test_value';
        $obj = clone $objB; // get clean object
        $val->validateAttribute($obj, 'attrC');
        $this->assertEquals('new_test_value', $obj->attrC);
        $this->assertEquals($objB->attrA, $obj->attrA);
        $val->validateAttribute($obj, 'attrA');
        $this->assertEquals($objB->attrA, $obj->attrA);
    }
Suralc committed
40
}