Browse Source

Added tests for uncovered lines.

tags/2.0.0-beta
Suralc 12 years ago
parent
commit
0c45765e7d
  1. 5
      tests/unit/framework/validators/DateValidatorTest.php
  2. 6
      tests/unit/framework/validators/ExistValidatorTest.php
  3. 4
      tests/unit/framework/validators/NumberValidatorTest.php
  4. 4
      tests/unit/framework/validators/StringValidatorTest.php
  5. 6
      tests/unit/framework/validators/UrlValidatorTest.php

5
tests/unit/framework/validators/DateValidatorTest.php

@ -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'));
}
}

6
tests/unit/framework/validators/ExistValidatorTest.php

@ -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'));
}
}

4
tests/unit/framework/validators/NumberValidatorTest.php

@ -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()

4
tests/unit/framework/validators/StringValidatorTest.php

@ -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()

6
tests/unit/framework/validators/UrlValidatorTest.php

@ -29,6 +29,12 @@ class UrlValidatorTest extends TestCase
$this->assertTrue($val->validateValue('yiiframework.com'));
$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()
{

Loading…
Cancel
Save