Commit 06682d0b by Suralc

coverage improvements

parent c189e5ad
......@@ -95,16 +95,14 @@ DROP TABLE IF EXISTS tbl_validator_main;
DROP TABLE IF EXISTS tbl_validator_ref;
CREATE TABLE tbl_validator_main (
id INT(11) NOT NULL,
field1 VARCHAR(255),
PRIMARY KEY (id)
id INTEGER PRIMARY KEY ,
field1 VARCHAR(255)
);
CREATE TABLE tbl_validator_ref (
id INT(11) NOT NULL,
id INTEGER PRIMARY KEY ,
a_field VARCHAR(255),
ref INT(11),
PRIMARY KEY (id)
ref INT(11)
);
INSERT INTO tbl_validator_main (id, field1) VALUES (1, 'just a string1');
......
......@@ -128,6 +128,12 @@ class CompareValidatorTest extends TestCase
$val->validateAttribute($model, 'attr_test');
$this->assertTrue($model->hasErrors('attr_test'));
$this->assertFalse($model->hasErrors('attr_test_repeat'));
// not existing op
$val = new CompareValidator();
$val->operator = '<>';
$model = FakedValidationModel::createWithAttributes(array('attr_o' => 5, 'attr_o_repeat' => 5 ));
$val->validateAttribute($model, 'attr_o');
$this->assertTrue($model->hasErrors('attr_o'));
}
public function testValidateAttributeOperators()
......
......@@ -205,6 +205,23 @@ class FileValidatorTest extends TestCase
$this->assertSame(FileValidator::className() . '::validateFile', $log['messages'][0][2]);
}
public function testValidateAttributeType()
{
$val = new FileValidator(array('types' => 'jpeg, jpg'));
$m = FakedValidationModel::createWithAttributes(
array(
'attr_jpg' => $this->createTestFiles(array(array('name' => 'one.jpeg'))),
'attr_exe' => $this->createTestFiles(array(array('name' => 'bad.exe'))),
)
);
$val->validateAttribute($m, 'attr_jpg');
$this->assertFalse($m->hasErrors('attr_jpg'));
$val->validateAttribute($m, 'attr_exe');
$this->assertTrue($m->hasErrors('attr_exe'));
$this->assertTrue(stripos(current($m->getErrors('attr_exe')), 'Only files with these extensions ') !== false);
}
protected function createModelForAttributeTest()
{
return FakedValidationModel::createWithAttributes(
......
......@@ -3,6 +3,7 @@ namespace yiiunit\framework\validators;
use yii\validators\RequiredValidator;
use yiiunit\data\validators\models\FakedValidationModel;
use yiiunit\TestCase;
class RequiredValidatorTest extends TestCase
......@@ -31,4 +32,23 @@ class RequiredValidatorTest extends TestCase
$this->assertFalse($val->validateValue("should fail"));
$this->assertFalse($val->validateValue(true));
}
public function testValidateAttribute()
{
// empty req-value
$val = new RequiredValidator();
$m = FakedValidationModel::createWithAttributes(array('attr_val' => null));
$val->validateAttribute($m, 'attr_val');
$this->assertTrue($m->hasErrors('attr_val'));
$this->assertTrue(stripos(current($m->getErrors('attr_val')), 'blank') !== false);
$val = new RequiredValidator(array('requiredValue' => 55));
$m = FakedValidationModel::createWithAttributes(array('attr_val' => 56));
$val->validateAttribute($m, 'attr_val');
$this->assertTrue($m->hasErrors('attr_val'));
$this->assertTrue(stripos(current($m->getErrors('attr_val')), 'must be') !== false);
$val = new RequiredValidator(array('requiredValue' => 55));
$m = FakedValidationModel::createWithAttributes(array('attr_val' => 55));
$val->validateAttribute($m, 'attr_val');
$this->assertFalse($m->hasErrors('attr_val'));
}
}
\ No newline at end of file
......@@ -44,6 +44,7 @@ class UniqueValidatorTest extends DatabaseTestCase
$val->validateAttribute($m, 'ref');
$this->assertTrue($m->hasErrors('ref'));
$m = new ValidatorTestRefModel();
$m->id = 7;
$m->ref = 12121;
$val->validateAttribute($m, 'ref');
$this->assertFalse($m->hasErrors('ref'));
......
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