2007-07-14 19:05:49 +04:00
|
|
|
<?php
|
2007-07-14 18:31:34 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Doctrine_TicketNjero_TestCase
|
|
|
|
*
|
|
|
|
* @package Doctrine
|
2007-07-14 19:05:49 +04:00
|
|
|
* @author Jeff Rafter <lists@jeffrafter.com>
|
2007-07-14 18:31:34 +04:00
|
|
|
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
|
|
* @category Object Relational Mapping
|
|
|
|
* @link www.phpdoctrine.com
|
|
|
|
* @since 1.0
|
|
|
|
* @version $Revision$
|
|
|
|
*/
|
2007-07-14 19:05:49 +04:00
|
|
|
|
2007-07-14 19:13:06 +04:00
|
|
|
class CoverageCodeN extends Doctrine_Record {
|
2007-07-14 19:05:49 +04:00
|
|
|
|
|
|
|
public function setTableDefinition(){
|
|
|
|
$this->setTableName('coverage_codes');
|
|
|
|
$this->hasColumn('id', 'integer', 4, array('notnull' => true, 'primary' => true, 'autoincrement' => true));
|
|
|
|
$this->hasColumn('code', 'integer', 4, array ( 'notnull' => true, 'notblank' => true,));
|
|
|
|
$this->hasColumn('description', 'string', 4000, array ( 'notnull' => true, 'notblank' => true,));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setUp(){
|
2007-07-14 19:13:06 +04:00
|
|
|
# $this->index('code', array('fields' => 'code'));
|
2007-07-14 19:05:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-14 19:13:06 +04:00
|
|
|
class PolicyCodeN extends Doctrine_Record {
|
2007-07-14 19:05:49 +04:00
|
|
|
|
|
|
|
public function setTableDefinition(){
|
|
|
|
$this->setTableName('policy_codes');
|
|
|
|
$this->hasColumn('id', 'integer', 4, array('notnull' => true, 'primary' => true, 'autoincrement' => true));
|
|
|
|
$this->hasColumn('code', 'integer', 4, array ( 'notnull' => true, 'notblank' => true,));
|
|
|
|
$this->hasColumn('description', 'string', 4000, array ( 'notnull' => true, 'notblank' => true,));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setUp(){
|
2007-07-14 19:13:06 +04:00
|
|
|
# $this->index('code', array('fields' => 'code'));
|
2007-07-14 19:05:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-14 19:13:06 +04:00
|
|
|
class LiabilityCodeN extends Doctrine_Record {
|
2007-07-14 19:05:49 +04:00
|
|
|
|
|
|
|
public function setTableDefinition(){
|
|
|
|
$this->setTableName('liability_codes');
|
|
|
|
$this->hasColumn('id', 'integer', 4, array('notnull' => true, 'primary' => true, 'autoincrement' => true));
|
|
|
|
$this->hasColumn('code', 'integer', 4, array ( 'notnull' => true, 'notblank' => true,));
|
|
|
|
$this->hasColumn('description', 'string', 4000, array ( 'notnull' => true, 'notblank' => true,));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setUp(){
|
2007-07-14 19:13:06 +04:00
|
|
|
# $this->index('code', array('fields' => 'code'));
|
2007-07-14 19:05:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-14 19:13:06 +04:00
|
|
|
class PolicyN extends Doctrine_Record {
|
2007-07-14 19:05:49 +04:00
|
|
|
|
|
|
|
public function setTableDefinition(){
|
|
|
|
$this->setTableName('policies');
|
|
|
|
$this->hasColumn('id', 'integer', 4, array('notnull' => true, 'primary' => true, 'autoincrement' => true));
|
|
|
|
$this->hasColumn('rate_id', 'integer', 4, array ( ));
|
|
|
|
$this->hasColumn('policy_number', 'integer', 4, array ( 'unique' => true, ));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setUp(){
|
2007-07-14 19:13:06 +04:00
|
|
|
$this->hasOne('RateN', array('local' => 'rate_id', 'foreign' => 'id' ));
|
2007-07-14 19:05:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2007-07-14 19:13:06 +04:00
|
|
|
class RateN extends Doctrine_Record{
|
2007-07-14 19:05:49 +04:00
|
|
|
|
|
|
|
public function setTableDefinition(){
|
|
|
|
$this->setTableName('rates');
|
|
|
|
$this->hasColumn('id', 'integer', 4, array('notnull' => true, 'primary' => true, 'autoincrement' => true));
|
|
|
|
$this->hasColumn('policy_code', 'integer', 4, array ( 'notnull' => true, 'notblank' => true,));
|
|
|
|
$this->hasColumn('coverage_code', 'integer', 4, array ( 'notnull' => true, 'notblank' => true,));
|
|
|
|
$this->hasColumn('liability_code', 'integer', 4, array ( 'notnull' => true, 'notblank' => true,));
|
|
|
|
$this->hasColumn('total_rate', 'float', null, array ( 'notnull' => true, 'notblank' => true,));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setUp(){
|
2007-07-14 19:13:06 +04:00
|
|
|
# $this->index('policy_code_idx', array('fields' => 'policy_code'));
|
|
|
|
# $this->index('coverage_code_idx', array('fields' => 'coverage_code'));
|
|
|
|
# $this->index('liability_code_idx', array('fields' => 'liability_code'));
|
|
|
|
$this->hasOne('PolicyCodeN', array('local' => 'policy_code', 'foreign' => 'code' ));
|
|
|
|
$this->hasOne('CoverageCodeN', array('local' => 'coverage_code', 'foreign' => 'code' ));
|
|
|
|
$this->hasOne('LiabilityCodeN', array('local' => 'liability_code', 'foreign' => 'code' ));
|
2007-07-14 19:05:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
class Doctrine_TicketNjero_TestCase extends Doctrine_UnitTestCase
|
2007-07-14 18:31:34 +04:00
|
|
|
{
|
2007-07-14 19:05:49 +04:00
|
|
|
public function prepareData() { }
|
|
|
|
public function prepareTables()
|
|
|
|
{
|
2007-07-14 19:13:06 +04:00
|
|
|
$this->tables[] = 'CoverageCodeN';
|
|
|
|
$this->tables[] = 'PolicyCodeN';
|
|
|
|
$this->tables[] = 'LiabilityCodeN';
|
|
|
|
$this->tables[] = 'PolicyN';
|
|
|
|
$this->tables[] = 'RateN';
|
2007-07-14 19:05:49 +04:00
|
|
|
parent::prepareTables();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testHasOneMultiLevelRelations()
|
|
|
|
{
|
2007-07-14 19:13:06 +04:00
|
|
|
$policy_code = new PolicyCodeN();
|
2007-07-14 19:05:49 +04:00
|
|
|
$policy_code->code = 1;
|
|
|
|
$policy_code->description = "Special Policy";
|
|
|
|
$policy_code->save();
|
|
|
|
|
2007-07-14 19:13:06 +04:00
|
|
|
$coverage_code = new CoverageCodeN();
|
2007-07-14 19:05:49 +04:00
|
|
|
$coverage_code->code = 1;
|
|
|
|
$coverage_code->description = "Full Coverage";
|
|
|
|
$coverage_code->save();
|
|
|
|
|
2007-07-14 19:13:06 +04:00
|
|
|
$liability_code = new LiabilityCodeN();
|
2007-07-14 19:05:49 +04:00
|
|
|
$liability_code->code = 1;
|
|
|
|
$liability_code->description = "Limited Territory";
|
|
|
|
$liability_code->save();
|
|
|
|
|
2007-07-14 19:13:06 +04:00
|
|
|
$rate = new RateN();
|
2007-07-14 19:05:49 +04:00
|
|
|
$rate->policy_code = 1;
|
|
|
|
$rate->coverage_code = 1;
|
|
|
|
$rate->liability_code = 1;
|
|
|
|
$rate->total_rate = 123.45;
|
|
|
|
$rate->save();
|
|
|
|
|
2007-07-14 19:13:06 +04:00
|
|
|
$policy = new PolicyN();
|
2007-07-14 19:05:49 +04:00
|
|
|
$policy->rate_id = 1;
|
|
|
|
$policy->policy_number = "123456789";
|
|
|
|
$policy->save();
|
|
|
|
|
|
|
|
$q = new Doctrine_Query();
|
2007-07-14 19:13:06 +04:00
|
|
|
$p = $q->from("PolicyN p")
|
2007-07-14 19:05:49 +04:00
|
|
|
->where("p.id = 1")
|
|
|
|
->execute()
|
|
|
|
->getFirst();
|
|
|
|
|
|
|
|
$this->assertEqual($p->rate_id, 1);
|
2007-07-14 19:13:06 +04:00
|
|
|
$this->assertEqual($p->RateN->id, 1);
|
2007-07-14 19:05:49 +04:00
|
|
|
}
|
|
|
|
}
?>
|