DefaultValueValidatorTest.php 1 KB
Newer Older
Suralc committed
1 2 3 4 5 6 7 8 9 10
<?php
namespace yiiunit\framework\validators;
use yii\validators\DefaultValueValidator;
use yiiunit\TestCase;

/**
 * DefaultValueValidatorTest
 */
class DefaultValueValidatorTest extends TestCase
{
11 12 13 14 15 16
	protected function setUp()
	{
		parent::setUp();
		$this->mockApplication();
	}

Suralc committed
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
	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);
	}
}