2007-09-13 01:08:11 +04:00
|
|
|
<?php
|
2007-09-02 18:24:49 +04:00
|
|
|
/**
|
2007-09-02 20:32:26 +04:00
|
|
|
* Doctrine_Ticket_Njero_TestCase
|
2007-09-02 18:24:49 +04:00
|
|
|
*
|
|
|
|
* @package Doctrine
|
|
|
|
* @author Jeff Rafter <lists@jeffrafter.com>
|
|
|
|
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
|
|
* @category Object Relational Mapping
|
2008-02-22 21:11:35 +03:00
|
|
|
* @link www.phpdoctrine.org
|
2007-09-02 18:24:49 +04:00
|
|
|
* @since 1.0
|
|
|
|
* @version $Revision$
|
|
|
|
*/
|
2007-07-14 19:05:49 +04:00
|
|
|
|
2007-09-02 20:32:26 +04:00
|
|
|
class Doctrine_Ticket_Njero_TestCase extends Doctrine_UnitTestCase
|
2007-09-02 18:24:49 +04:00
|
|
|
{
|
|
|
|
public function prepareData() { }
|
|
|
|
public function prepareTables()
|
2007-07-14 19:05:49 +04:00
|
|
|
{
|
2008-02-04 00:29:57 +03:00
|
|
|
$this->tables = array();
|
2007-09-02 20:32:26 +04:00
|
|
|
$this->tables[] = 'CoverageCodeN';
|
|
|
|
$this->tables[] = 'PolicyCodeN';
|
|
|
|
$this->tables[] = 'LiabilityCodeN';
|
|
|
|
$this->tables[] = 'PolicyN';
|
|
|
|
$this->tables[] = 'RateN';
|
|
|
|
parent::prepareTables();
|
2007-09-02 18:24:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
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-09-02 18:24:49 +04:00
|
|
|
|
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-09-02 18:24:49 +04:00
|
|
|
|
2007-08-10 02:48:40 +04:00
|
|
|
$coverage_code = new CoverageCodeN();
|
|
|
|
$coverage_code->code = 3; # note we skip 2
|
|
|
|
$coverage_code->description = "Partial 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;
|
2007-08-10 02:48:40 +04:00
|
|
|
$rate->coverage_code = 3;
|
2007-07-14 19:05:49 +04:00
|
|
|
$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-08-10 09:08:31 +04:00
|
|
|
|
|
|
|
# If I use
|
|
|
|
# $p = $q->from('PolicyN p')
|
|
|
|
# this test passes, but there is another issue just not reflected in this test yet, see "in my app" note below
|
|
|
|
|
2007-09-13 01:08:11 +04:00
|
|
|
$q->from('PolicyN p, p.RateN r, r.PolicyCodeN y, r.CoverageCodeN c, r.LiabilityCodeN l')
|
|
|
|
->where('(p.id = ?)', array('1'));
|
|
|
|
|
|
|
|
$p = $q->execute()->getFirst();
|
2007-08-10 02:48:40 +04:00
|
|
|
|
2007-09-02 18:24:49 +04:00
|
|
|
$this->assertEqual($p->rate_id, 1);
|
|
|
|
$this->assertEqual($p->RateN->id, 1);
|
|
|
|
$this->assertEqual($p->RateN->policy_code, 1);
|
|
|
|
$this->assertEqual($p->RateN->coverage_code, 3); # fail
|
2007-08-10 02:48:40 +04:00
|
|
|
$this->assertEqual($p->RateN->liability_code, 1);
|
2007-08-10 09:08:31 +04:00
|
|
|
|
2007-09-02 18:24:49 +04:00
|
|
|
$c = $p->RateN->coverage_code;
|
|
|
|
$c2 = $p->RateN->CoverageCodeN->code;
|
|
|
|
$c3 = $p->RateN->coverage_code;
|
|
|
|
|
|
|
|
$this->assertEqual($c, $c2); # fail
|
2007-08-10 09:08:31 +04:00
|
|
|
$this->assertEqual($c, $c3); # in my app this fails as well, but I can't reproduce this
|
2007-09-02 18:24:49 +04:00
|
|
|
#echo "Values " . serialize(array($c, $c2, $c3));
|
2007-08-10 09:08:31 +04:00
|
|
|
|
2007-09-02 18:24:49 +04:00
|
|
|
}
|
2007-09-02 21:55:42 +04:00
|
|
|
}
|