1
0
mirror of synced 2025-01-18 06:21:40 +03:00

Added a validator test.

This commit is contained in:
romanb 2007-03-28 13:31:54 +00:00
parent 0ff46eb77c
commit 4652ae5c50
2 changed files with 73 additions and 1 deletions

View File

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

View File

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