Addition to the validator tests.
Ticket: 354
This commit is contained in:
parent
c02c83d4a7
commit
59df6edff9
@ -40,6 +40,9 @@ class Doctrine_Validator_TestCase extends Doctrine_UnitTestCase
|
|||||||
$this->tables[] = 'ValidatorTest';
|
$this->tables[] = 'ValidatorTest';
|
||||||
$this->tables[] = 'ValidatorTest_Person';
|
$this->tables[] = 'ValidatorTest_Person';
|
||||||
$this->tables[] = 'ValidatorTest_FootballPlayer';
|
$this->tables[] = 'ValidatorTest_FootballPlayer';
|
||||||
|
$this->tables[] = 'ValidatorTest_ClientModel';
|
||||||
|
$this->tables[] = 'ValidatorTest_ClientToAddressModel';
|
||||||
|
$this->tables[] = 'ValidatorTest_AddressModel';
|
||||||
parent::prepareTables();
|
parent::prepareTables();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -229,16 +232,14 @@ class Doctrine_Validator_TestCase extends Doctrine_UnitTestCase
|
|||||||
$this->pass();
|
$this->pass();
|
||||||
$a = $e->getInvalidRecords();
|
$a = $e->getInvalidRecords();
|
||||||
//var_dump($a[1]->getErrorStack());
|
//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_VLD, false);
|
||||||
$this->manager->setAttribute(Doctrine::ATTR_AUTO_LENGTH_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);
|
$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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
@ -791,6 +791,16 @@ class QueryTest_User extends Doctrine_Record
|
|||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
$this->hasOne('QueryTest_Rank as visibleRank', 'QueryTest_User.visibleRankId');
|
$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,
|
$this->hasColumn('icon as icon', 'string', 50,
|
||||||
array('notnull', 'default' => ' ', 'regexp' => '/^[a-zA-Z0-9_\-]+\.(jpg|gif|png)$/D'));
|
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'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user