From 59df6edff98c5a25c9393eb77657cfd58ea275e0 Mon Sep 17 00:00:00 2001 From: romanb Date: Thu, 28 Jun 2007 16:14:06 +0000 Subject: [PATCH] Addition to the validator tests. Ticket: 354 --- tests/ValidatorTestCase.php | 42 +++++++++++++++++++----- tests/classes.php | 64 ++++++++++++++++++++++++++++++++++++- 2 files changed, 97 insertions(+), 9 deletions(-) diff --git a/tests/ValidatorTestCase.php b/tests/ValidatorTestCase.php index 22a6b8f8f..7086a962c 100644 --- a/tests/ValidatorTestCase.php +++ b/tests/ValidatorTestCase.php @@ -40,6 +40,9 @@ class Doctrine_Validator_TestCase extends Doctrine_UnitTestCase $this->tables[] = 'ValidatorTest'; $this->tables[] = 'ValidatorTest_Person'; $this->tables[] = 'ValidatorTest_FootballPlayer'; + $this->tables[] = 'ValidatorTest_ClientModel'; + $this->tables[] = 'ValidatorTest_ClientToAddressModel'; + $this->tables[] = 'ValidatorTest_AddressModel'; parent::prepareTables(); } @@ -229,16 +232,14 @@ class Doctrine_Validator_TestCase extends Doctrine_UnitTestCase $this->pass(); $a = $e->getInvalidRecords(); //var_dump($a[1]->getErrorStack()); + $this->assertTrue(is_array($a)); + //var_dump(array_search($user, $a)); + $emailStack = $user->Email->errorStack(); + $userStack = $user->errorStack(); + $this->assertTrue(in_array('email', $emailStack['address'])); + $this->assertTrue(in_array('length', $userStack['name'])); } - $this->assertTrue(is_array($a)); - //var_dump(array_search($user, $a)); - $emailStack = $user->Email->errorStack(); - $userStack = $user->errorStack(); - //var_dump($userStack); - - $this->assertTrue(in_array('email', $emailStack['address'])); - $this->assertTrue(in_array('length', $userStack['name'])); $this->manager->setAttribute(Doctrine::ATTR_VLD, false); $this->manager->setAttribute(Doctrine::ATTR_AUTO_LENGTH_VLD, false); } @@ -384,5 +385,30 @@ class Doctrine_Validator_TestCase extends Doctrine_UnitTestCase $this->manager->setAttribute(Doctrine::ATTR_VLD, false); } + + public function testValidationOnManyToManyRelations() + { + $this->manager->setAttribute(Doctrine::ATTR_VLD, true); + try { + $client = new ValidatorTest_ClientModel(); + $client->short_name = 'test'; + $client->ValidatorTest_AddressModel[0]->state = 'az'; + $client->save(); + $this->fail(); + } catch (Doctrine_Validator_Exception $dve) { + $this->assertEqual(1, count($dve->getInvalidRecords())); + $stack = $client->ValidatorTest_AddressModel[0]->getErrorStack(); + $this->assertTrue(in_array('notnull', $stack['address1'])); + $this->assertTrue(in_array('notblank', $stack['address1'])); + $this->assertTrue(in_array('notnull', $stack['address2'])); + $this->assertTrue(in_array('notnull', $stack['city'])); + $this->assertTrue(in_array('notblank', $stack['city'])); + $this->assertTrue(in_array('usstate', $stack['state'])); + $this->assertTrue(in_array('notnull', $stack['zip'])); + $this->assertTrue(in_array('notblank', $stack['zip'])); + } + + $this->manager->setAttribute(Doctrine::ATTR_VLD, false); + } } ?> diff --git a/tests/classes.php b/tests/classes.php index fbe90fe0b..061d5dac3 100644 --- a/tests/classes.php +++ b/tests/classes.php @@ -791,6 +791,16 @@ class QueryTest_User extends Doctrine_Record public function setUp() { $this->hasOne('QueryTest_Rank as visibleRank', 'QueryTest_User.visibleRankId'); + $this->hasMany('QueryTest_Rank as ranks', 'QueryTest_UserRank.rankId'); + } +} + +class QueryTest_UserRank extends Doctrine_Record +{ + public function setTableDefinition() + { + $this->hasColumn('rankId', 'integer', 4, array('primary')); + $this->hasColumn('userId', 'integer', 4, array('primary')); } } @@ -808,6 +818,58 @@ class QueryTest_Rank extends Doctrine_Record $this->hasColumn('icon as icon', 'string', 50, array('notnull', 'default' => ' ', 'regexp' => '/^[a-zA-Z0-9_\-]+\.(jpg|gif|png)$/D')); } + public function setUp() + { + $this->hasMany('QueryTest_User as users', 'QueryTest_UserRank.userId'); + } } - + +class ValidatorTest_ClientModel extends Doctrine_Record { + public function setTableDefinition() { + + $this->hasColumn('id', 'integer', 4, array('notnull' => true, + 'primary' => true, + 'autoincrement' => true, + 'unsigned' => true)); + $this->hasColumn('short_name', 'string', 32, array('notnull' => true, 'notblank', 'unique' => true)); + } + + public function setUp() { + $this->hasMany("ValidatorTest_AddressModel", array('local' => 'client_id', 'foreign' => 'address_id', 'refClass' => 'ValidatorTest_ClientToAddressModel')); + } +} + +class ValidatorTest_ClientToAddressModel extends Doctrine_Record { + + public function setTableDefinition() { + + $this->hasColumn("client_id", "integer", 11, array('primary' => true)); + $this->hasColumn("address_id", "integer", 11, array('primary' => true)); + } + + public function construct(){ + } + + public function setUp() { + } +} + +class ValidatorTest_AddressModel extends Doctrine_Record { + public function setTableDefinition() { + + $this->hasColumn("id", "integer", 11, array('autoincrement' => true, + 'primary' => true + )); + $this->hasColumn('address1', 'string', 255, array('notnull' => true, 'notblank')); + $this->hasColumn('address2', 'string', 255, array('notnull' => true)); + $this->hasColumn('city', 'string', 255, array('notnull' => true, 'notblank')); + $this->hasColumn('state', 'string', 10, array('notnull' => true, 'notblank', 'usstate')); + $this->hasColumn('zip', 'string', 15, array('notnull' => true, 'notblank', 'regexp' => '/^[0-9-]*$/')); + } + + public function setUp() { + $this->hasMany('ValidatorTest_ClientModel', array('local' => 'address_id', 'foreign' => 'client_id', 'refClass' => 'ValidatorTest_ClientToAddressModel')); + } +} + ?>