From 24e2f885037bca1de58cdf0b6e67e72966c6cbf3 Mon Sep 17 00:00:00 2001 From: Suralc Date: Fri, 23 Aug 2013 22:47:45 +0200 Subject: [PATCH] Renamed validator test models to be less specific. --- tests/unit/data/mysql.sql | 30 +++++++++++----------- tests/unit/data/postgres.sql | 30 +++++++++++----------- tests/unit/data/sqlite.sql | 30 +++++++++++----------- .../validators/models/ExistValidatorMainModel.php | 20 --------------- .../validators/models/ExistValidatorRefModel.php | 22 ---------------- .../validators/models/ValidatorTestMainModel.php | 21 +++++++++++++++ .../validators/models/ValidatorTestRefModel.php | 23 +++++++++++++++++ .../framework/validators/CompareValidatorTest.php | 5 ++++ .../framework/validators/ExistValidatorTest.php | 26 +++++++++---------- 9 files changed, 107 insertions(+), 100 deletions(-) delete mode 100644 tests/unit/data/validators/models/ExistValidatorMainModel.php delete mode 100644 tests/unit/data/validators/models/ExistValidatorRefModel.php create mode 100644 tests/unit/data/validators/models/ValidatorTestMainModel.php create mode 100644 tests/unit/data/validators/models/ValidatorTestRefModel.php diff --git a/tests/unit/data/mysql.sql b/tests/unit/data/mysql.sql index 9a31083..9ed0d90 100644 --- a/tests/unit/data/mysql.sql +++ b/tests/unit/data/mysql.sql @@ -103,32 +103,32 @@ INSERT INTO tbl_order_item (order_id, item_id, quantity, subtotal) VALUES (3, 2, /** - * (MySQL-)Database Schema for ExistValidatorTest + * (MySQL-)Database Schema for validator tests */ -DROP TABLE IF EXISTS tbl_validator_exist_main CASCADE; -DROP TABLE IF EXISTS tbl_validator_exist_ref CASCADE; +DROP TABLE IF EXISTS tbl_validator_main CASCADE; +DROP TABLE IF EXISTS tbl_validator_ref CASCADE; -CREATE TABLE `tbl_validator_exist_main` ( +CREATE TABLE tbl_validator_main ( `id` INT(11) NOT NULL AUTO_INCREMENT, `field1` VARCHAR(255), PRIMARY KEY (`id`) ) ENGINE =InnoDB DEFAULT CHARSET =utf8; -CREATE TABLE `tbl_validator_exist_ref` ( +CREATE TABLE tbl_validator_ref ( `id` INT(11) NOT NULL AUTO_INCREMENT, `a_field` VARCHAR(255), `ref` INT(11), PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -INSERT INTO tbl_validator_exist_main (id, field1) VALUES (1, 'just a string1'); -INSERT INTO tbl_validator_exist_main (id, field1) VALUES (2, 'just a string2'); -INSERT INTO tbl_validator_exist_main (id, field1) VALUES (3, 'just a string3'); -INSERT INTO tbl_validator_exist_main (id, field1) VALUES (4, 'just a string4'); -INSERT INTO tbl_validator_exist_ref (a_field, ref) VALUES ('ref_to_2', 2); -INSERT INTO tbl_validator_exist_ref (a_field, ref) VALUES ('ref_to_2', 2); -INSERT INTO tbl_validator_exist_ref (a_field, ref) VALUES ('ref_to_3', 3); -INSERT INTO tbl_validator_exist_ref (a_field, ref) VALUES ('ref_to_4', 4); -INSERT INTO tbl_validator_exist_ref (a_field, ref) VALUES ('ref_to_4', 4); -INSERT INTO tbl_validator_exist_ref (a_field, ref) VALUES ('ref_to_5', 5); +INSERT INTO tbl_validator_main (id, field1) VALUES (1, 'just a string1'); +INSERT INTO tbl_validator_main (id, field1) VALUES (2, 'just a string2'); +INSERT INTO tbl_validator_main (id, field1) VALUES (3, 'just a string3'); +INSERT INTO tbl_validator_main (id, field1) VALUES (4, 'just a string4'); +INSERT INTO tbl_validator_ref (a_field, ref) VALUES ('ref_to_2', 2); +INSERT INTO tbl_validator_ref (a_field, ref) VALUES ('ref_to_2', 2); +INSERT INTO tbl_validator_ref (a_field, ref) VALUES ('ref_to_3', 3); +INSERT INTO tbl_validator_ref (a_field, ref) VALUES ('ref_to_4', 4); +INSERT INTO tbl_validator_ref (a_field, ref) VALUES ('ref_to_4', 4); +INSERT INTO tbl_validator_ref (a_field, ref) VALUES ('ref_to_5', 5); diff --git a/tests/unit/data/postgres.sql b/tests/unit/data/postgres.sql index fc306da..c2702c9 100644 --- a/tests/unit/data/postgres.sql +++ b/tests/unit/data/postgres.sql @@ -94,30 +94,30 @@ INSERT INTO tbl_order_item (order_id, item_id, quantity, subtotal) VALUES (2, 3, INSERT INTO tbl_order_item (order_id, item_id, quantity, subtotal) VALUES (3, 2, 1, 40.0); /** - * (Postgres-)Database Schema for ExistValidatorTest + * (Postgres-)Database Schema for validator tests */ -DROP TABLE IF EXISTS tbl_validator_exist_main CASCADE; -DROP TABLE IF EXISTS tbl_validator_exist_ref CASCADE; +DROP TABLE IF EXISTS tbl_validator_main CASCADE; +DROP TABLE IF EXISTS tbl_validator_ref CASCADE; -CREATE TABLE tbl_validator_exist_main ( +CREATE TABLE tbl_validator_main ( id integer not null primary key, field1 VARCHAR(255) ); -CREATE TABLE tbl_validator_exist_ref ( +CREATE TABLE tbl_validator_ref ( id integer not null primary key, a_field VARCHAR(255), ref integer ); -INSERT INTO tbl_validator_exist_main (id, field1) VALUES (1, 'just a string1'); -INSERT INTO tbl_validator_exist_main (id, field1) VALUES (2, 'just a string2'); -INSERT INTO tbl_validator_exist_main (id, field1) VALUES (3, 'just a string3'); -INSERT INTO tbl_validator_exist_main (id, field1) VALUES (4, 'just a string4'); -INSERT INTO tbl_validator_exist_ref (id, a_field, ref) VALUES (1, 'ref_to_2', 2); -INSERT INTO tbl_validator_exist_ref (id, a_field, ref) VALUES (2, 'ref_to_2', 2); -INSERT INTO tbl_validator_exist_ref (id, a_field, ref) VALUES (3, 'ref_to_3', 3); -INSERT INTO tbl_validator_exist_ref (id, a_field, ref) VALUES (4, 'ref_to_4', 4); -INSERT INTO tbl_validator_exist_ref (id, a_field, ref) VALUES (5, 'ref_to_4', 4); -INSERT INTO tbl_validator_exist_ref (id, a_field, ref) VALUES (6, 'ref_to_5', 5); \ No newline at end of file +INSERT INTO tbl_validator_main (id, field1) VALUES (1, 'just a string1'); +INSERT INTO tbl_validator_main (id, field1) VALUES (2, 'just a string2'); +INSERT INTO tbl_validator_main (id, field1) VALUES (3, 'just a string3'); +INSERT INTO tbl_validator_main (id, field1) VALUES (4, 'just a string4'); +INSERT INTO tbl_validator_ref (id, a_field, ref) VALUES (1, 'ref_to_2', 2); +INSERT INTO tbl_validator_ref (id, a_field, ref) VALUES (2, 'ref_to_2', 2); +INSERT INTO tbl_validator_ref (id, a_field, ref) VALUES (3, 'ref_to_3', 3); +INSERT INTO tbl_validator_ref (id, a_field, ref) VALUES (4, 'ref_to_4', 4); +INSERT INTO tbl_validator_ref (id, a_field, ref) VALUES (5, 'ref_to_4', 4); +INSERT INTO tbl_validator_ref (id, a_field, ref) VALUES (6, 'ref_to_5', 5); \ No newline at end of file diff --git a/tests/unit/data/sqlite.sql b/tests/unit/data/sqlite.sql index c1111da..8976519 100644 --- a/tests/unit/data/sqlite.sql +++ b/tests/unit/data/sqlite.sql @@ -88,32 +88,32 @@ INSERT INTO tbl_order_item (order_id, item_id, quantity, subtotal) VALUES (2, 3, INSERT INTO tbl_order_item (order_id, item_id, quantity, subtotal) VALUES (3, 2, 1, 40.0); /** - * (SqLite-)Database Schema for ExistValidatorTest + * (SqLite-)Database Schema for validator tests */ -DROP TABLE IF EXISTS tbl_validator_exist_main; -DROP TABLE IF EXISTS tbl_validator_exist_ref; +DROP TABLE IF EXISTS tbl_validator_main; +DROP TABLE IF EXISTS tbl_validator_ref; -CREATE TABLE tbl_validator_exist_main ( +CREATE TABLE tbl_validator_main ( id INT(11) NOT NULL, field1 VARCHAR(255), PRIMARY KEY (id) ); -CREATE TABLE tbl_validator_exist_ref ( +CREATE TABLE tbl_validator_ref ( id INT(11) NOT NULL, a_field VARCHAR(255), ref INT(11), PRIMARY KEY (id) ); -INSERT INTO tbl_validator_exist_main (id, field1) VALUES (1, 'just a string1'); -INSERT INTO tbl_validator_exist_main (id, field1) VALUES (2, 'just a string2'); -INSERT INTO tbl_validator_exist_main (id, field1) VALUES (3, 'just a string3'); -INSERT INTO tbl_validator_exist_main (id, field1) VALUES (4, 'just a string4'); -INSERT INTO tbl_validator_exist_ref (id, a_field, ref) VALUES (1, 'ref_to_2', 2); -INSERT INTO tbl_validator_exist_ref (id, a_field, ref) VALUES (2, 'ref_to_2', 2); -INSERT INTO tbl_validator_exist_ref (id, a_field, ref) VALUES (3, 'ref_to_3', 3); -INSERT INTO tbl_validator_exist_ref (id, a_field, ref) VALUES (4, 'ref_to_4', 4); -INSERT INTO tbl_validator_exist_ref (id, a_field, ref) VALUES (5, 'ref_to_4', 4); -INSERT INTO tbl_validator_exist_ref (id, a_field, ref) VALUES (6, 'ref_to_5', 5); \ No newline at end of file +INSERT INTO tbl_validator_main (id, field1) VALUES (1, 'just a string1'); +INSERT INTO tbl_validator_main (id, field1) VALUES (2, 'just a string2'); +INSERT INTO tbl_validator_main (id, field1) VALUES (3, 'just a string3'); +INSERT INTO tbl_validator_main (id, field1) VALUES (4, 'just a string4'); +INSERT INTO tbl_validator_ref (id, a_field, ref) VALUES (1, 'ref_to_2', 2); +INSERT INTO tbl_validator_ref (id, a_field, ref) VALUES (2, 'ref_to_2', 2); +INSERT INTO tbl_validator_ref (id, a_field, ref) VALUES (3, 'ref_to_3', 3); +INSERT INTO tbl_validator_ref (id, a_field, ref) VALUES (4, 'ref_to_4', 4); +INSERT INTO tbl_validator_ref (id, a_field, ref) VALUES (5, 'ref_to_4', 4); +INSERT INTO tbl_validator_ref (id, a_field, ref) VALUES (6, 'ref_to_5', 5); \ No newline at end of file diff --git a/tests/unit/data/validators/models/ExistValidatorMainModel.php b/tests/unit/data/validators/models/ExistValidatorMainModel.php deleted file mode 100644 index 5f3ff00..0000000 --- a/tests/unit/data/validators/models/ExistValidatorMainModel.php +++ /dev/null @@ -1,20 +0,0 @@ -hasMany(ExistValidatorRefModel::className(), array('ref' => 'id')); - } -} \ No newline at end of file diff --git a/tests/unit/data/validators/models/ExistValidatorRefModel.php b/tests/unit/data/validators/models/ExistValidatorRefModel.php deleted file mode 100644 index 6cafa39..0000000 --- a/tests/unit/data/validators/models/ExistValidatorRefModel.php +++ /dev/null @@ -1,22 +0,0 @@ -hasOne(ExistValidatorMainModel::className(), array('id' => 'ref')); - } -} \ No newline at end of file diff --git a/tests/unit/data/validators/models/ValidatorTestMainModel.php b/tests/unit/data/validators/models/ValidatorTestMainModel.php new file mode 100644 index 0000000..6f2808b --- /dev/null +++ b/tests/unit/data/validators/models/ValidatorTestMainModel.php @@ -0,0 +1,21 @@ +hasMany(ValidatorTestRefModel::className(), array('ref' => 'id')); + } +} \ No newline at end of file diff --git a/tests/unit/data/validators/models/ValidatorTestRefModel.php b/tests/unit/data/validators/models/ValidatorTestRefModel.php new file mode 100644 index 0000000..aa3d199 --- /dev/null +++ b/tests/unit/data/validators/models/ValidatorTestRefModel.php @@ -0,0 +1,23 @@ +hasOne(ValidatorTestMainModel::className(), array('id' => 'ref')); + } +} \ No newline at end of file diff --git a/tests/unit/framework/validators/CompareValidatorTest.php b/tests/unit/framework/validators/CompareValidatorTest.php index 7ae0263..46ab383 100644 --- a/tests/unit/framework/validators/CompareValidatorTest.php +++ b/tests/unit/framework/validators/CompareValidatorTest.php @@ -77,6 +77,11 @@ class CompareValidatorTest extends TestCase array($value + 1, false), array($value - 1, true), ), + //'non-op' => array( + // array($value, false), + // array($value + 1, false), + // array($value - 1, false), + //), ); } diff --git a/tests/unit/framework/validators/ExistValidatorTest.php b/tests/unit/framework/validators/ExistValidatorTest.php index 930712c..40d0935 100644 --- a/tests/unit/framework/validators/ExistValidatorTest.php +++ b/tests/unit/framework/validators/ExistValidatorTest.php @@ -7,8 +7,8 @@ use Yii; use yii\base\Exception; use yii\validators\ExistValidator; use yiiunit\data\ar\ActiveRecord; -use yiiunit\data\validators\models\ExistValidatorMainModel; -use yiiunit\data\validators\models\ExistValidatorRefModel; +use yiiunit\data\validators\models\ValidatorTestMainModel; +use yiiunit\data\validators\models\ValidatorTestRefModel; use yiiunit\framework\db\DatabaseTestCase; class ExistValidatorTest extends DatabaseTestCase @@ -39,7 +39,7 @@ class ExistValidatorTest extends DatabaseTestCase } // combine to save the time creating a new db-fixture set (likely ~5 sec) try { - $val = new ExistValidator(array('className' => ExistValidatorMainModel::className())); + $val = new ExistValidator(array('className' => ValidatorTestMainModel::className())); $val->validateValue('ref'); $this->fail('Exception should have been thrown at this time'); } catch (Exception $e) { @@ -50,7 +50,7 @@ class ExistValidatorTest extends DatabaseTestCase public function testValidateValue() { - $val = new ExistValidator(array('className' => ExistValidatorRefModel::className(), 'attributeName' => 'id')); + $val = new ExistValidator(array('className' => ValidatorTestRefModel::className(), 'attributeName' => 'id')); $this->assertTrue($val->validateValue(2)); $this->assertTrue($val->validateValue(5)); $this->assertFalse($val->validateValue(99)); @@ -60,39 +60,39 @@ class ExistValidatorTest extends DatabaseTestCase public function testValidateAttribute() { // existing value on different table - $val = new ExistValidator(array('className' => ExistValidatorMainModel::className(), 'attributeName' => 'id')); - $m = ExistValidatorRefModel::find(array('id' => 1)); + $val = new ExistValidator(array('className' => ValidatorTestMainModel::className(), 'attributeName' => 'id')); + $m = ValidatorTestRefModel::find(array('id' => 1)); $val->validateAttribute($m, 'ref'); $this->assertFalse($m->hasErrors()); // non-existing value on different table - $val = new ExistValidator(array('className' => ExistValidatorMainModel::className(), 'attributeName' => 'id')); - $m = ExistValidatorRefModel::find(array('id' => 6)); + $val = new ExistValidator(array('className' => ValidatorTestMainModel::className(), 'attributeName' => 'id')); + $m = ValidatorTestRefModel::find(array('id' => 6)); $val->validateAttribute($m, 'ref'); $this->assertTrue($m->hasErrors('ref')); // existing value on same table $val = new ExistValidator(array('attributeName' => 'ref')); - $m = ExistValidatorRefModel::find(array('id' => 2)); + $m = ValidatorTestRefModel::find(array('id' => 2)); $val->validateAttribute($m, 'test_val'); $this->assertFalse($m->hasErrors()); // non-existing value on same table $val = new ExistValidator(array('attributeName' => 'ref')); - $m = ExistValidatorRefModel::find(array('id' => 5)); + $m = ValidatorTestRefModel::find(array('id' => 5)); $val->validateAttribute($m, 'test_val_fail'); $this->assertTrue($m->hasErrors('test_val_fail')); // check for given value (true) $val = new ExistValidator(); - $m = ExistValidatorRefModel::find(array('id' => 3)); + $m = ValidatorTestRefModel::find(array('id' => 3)); $val->validateAttribute($m, 'ref'); $this->assertFalse($m->hasErrors()); // check for given defaults (false) $val = new ExistValidator(); - $m = ExistValidatorRefModel::find(array('id' => 4)); + $m = ValidatorTestRefModel::find(array('id' => 4)); $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 = ValidatorTestRefModel::find(array('id' => 2)); $m->test_val = array(1,2,3); $val->validateAttribute($m, 'test_val'); $this->assertTrue($m->hasErrors('test_val'));