Commit 0c45765e by Suralc

Added tests for uncovered lines.

parent 5c8927af
......@@ -55,7 +55,10 @@ class DateValidatorTest extends TestCase
DateTime::createFromFormat($val->format, '2013-09-13')->getTimestamp(),
$model->attr_timestamp
);
$val = new DateValidator();
$model = FakedValidationModel::createWithAttributes(array('attr_date' => array()));
$val->validateAttribute($model, 'attr_date');
$this->assertTrue($model->hasErrors('attr_date'));
}
}
\ No newline at end of file
......@@ -90,5 +90,11 @@ class ExistValidatorTest extends DatabaseTestCase
$m->a_field = 'some new value';
$val->validateAttribute($m, 'a_field');
$this->assertTrue($m->hasErrors('a_field'));
// check array
$val = new ExistValidator(array('attributeName' => 'ref'));
$m = ExistValidatorRefModel::find(array('id' => 2));
$m->test_val = array(1,2,3);
$val->validateAttribute($m, 'test_val');
$this->assertTrue($m->hasErrors('test_val'));
}
}
\ No newline at end of file
......@@ -137,6 +137,10 @@ class NumberValidatorTest extends TestCase
$model->attr_number = 3.43;
$val->validateAttribute($model, 'attr_number');
$this->assertTrue($model->hasErrors('attr_number'));
$val = new NumberValidator(array('min' => 1));
$model = FakedValidationModel::createWithAttributes(array('attr_num' => array(1,2,3)));
$val->validateAttribute($model, 'attr_num');
$this->assertTrue($model->hasErrors('attr_num'));
}
public function testEnsureCustomMessageIsSetOnValidateAttribute()
......
......@@ -86,6 +86,10 @@ class StringValidatorTest extends TestCase
$model->attr_string = 'abc';
$val->validateAttribute($model, 'attr_string');
$this->assertTrue($model->hasErrors('attr_string'));
$val = new StringValidator(array('max' => 1));
$model = FakedValidationModel::createWithAttributes(array('attr_str' => array('abc')));
$val->validateAttribute($model, 'attr_str');
$this->assertTrue($model->hasErrors('attr_str'));
}
public function testEnsureMessagesOnInit()
......
......@@ -30,6 +30,12 @@ class UrlValidatorTest extends TestCase
$this->assertTrue($val->validateValue('http://yiiframework.com'));
}
public function testValidateValueWithoutScheme()
{
$val = new UrlValidator(array('pattern' => '/(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)/i'));
$this->assertTrue($val->validateValue('yiiframework.com'));
}
public function testValidateWithCustomScheme()
{
$val = new UrlValidator(array(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment