From 4652ae5c505f1516a69f351d0b39c7e5f87af13f Mon Sep 17 00:00:00 2001 From: romanb Date: Wed, 28 Mar 2007 13:31:54 +0000 Subject: [PATCH] Added a validator test. --- tests/ValidatorTestCase.php | 54 ++++++++++++++++++++++++++++++++++++- tests/classes.php | 20 ++++++++++++++ 2 files changed, 73 insertions(+), 1 deletion(-) diff --git a/tests/ValidatorTestCase.php b/tests/ValidatorTestCase.php index e954aea12..813cffe0f 100644 --- a/tests/ValidatorTestCase.php +++ b/tests/ValidatorTestCase.php @@ -35,7 +35,9 @@ */ class Doctrine_Validator_TestCase extends Doctrine_UnitTestCase { public function prepareTables() { - $this->tables[] = "ValidatorTest"; + $this->tables[] = 'ValidatorTest'; + $this->tables[] = 'ValidatorTest_Person'; + $this->tables[] = 'ValidatorTest_FootballPlayer'; parent::prepareTables(); } @@ -300,5 +302,55 @@ class Doctrine_Validator_TestCase extends Doctrine_UnitTestCase { $this->manager->setAttribute(Doctrine::ATTR_VLD, false); } + + /* + public function testIssue() + { + $this->manager->setAttribute(Doctrine::ATTR_VLD, true); + + try { + $person = new ValidatorTest_Person(); + $person->name = ''; // will raise a validation exception since name must be 'notblank' + $person->is_football_player = true; + + $person->ValidatorTest_FootballPlayer->team_name = 'liverpool'; + $person->ValidatorTest_FootballPlayer->goals_count = 2; + + $person->save(); + } + catch(Doctrine_Validator_Exception $e) { + $this->fail("test"); + //var_dump($person->getErrorStack()); + //var_dump($person->ValidatorTest_FootballPlayer->getErrorStack()); + } + + $this->manager->setAttribute(Doctrine::ATTR_VLD, false); + } + */ + + /** + * Enter description here... + * + * @todo move to a separate test file (tests/Validator/UniqueTestCase) . + */ + public function testSetSameUniqueValueThrowsNoException() + { + $this->manager->setAttribute(Doctrine::ATTR_VLD, true); + + $r = new ValidatorTest_Person(); + $r->name = 'value'; + $r->save(); + + $r = $this->connection->getTable('ValidatorTest_Person')->findAll()->getFirst(); + $r->name = 'value'; + try { + $r->save(); + } + catch(Doctrine_Validator_Exception $e) { + $this->fail("Validator exception raised without reason!"); + } + + $this->manager->setAttribute(Doctrine::ATTR_VLD, false); + } } ?> diff --git a/tests/classes.php b/tests/classes.php index cbea453fe..59786c4af 100644 --- a/tests/classes.php +++ b/tests/classes.php @@ -602,4 +602,24 @@ class NestReference extends Doctrine_Record $this->hasColumn('child_id', 'integer', 4, 'primary'); } } + +class ValidatorTest_Person extends Doctrine_Record { + public function setTableDefinition() { + $this->hasColumn('name', 'string', 255, array('notblank', 'unique')); + $this->hasColumn('is_football_player', 'boolean'); + } + + public function setUp() { + $this->ownsOne('ValidatorTest_FootballPlayer', 'ValidatorTest_FootballPlayer.person_id'); + } +} + +class ValidatorTest_FootballPlayer extends Doctrine_Record { + public function setTableDefinition() { + $this->hasColumn('person_id', 'string', 255, 'primary'); + $this->hasColumn('team_name', 'string', 255); + $this->hasColumn('goals_count', 'integer', 4); + } +} + ?>