Trac

Ticket #929: 929TestCase.php

File 929TestCase.php, 5.0 kB (added by David.Stendardi, 5 months ago)

Warning : this test case throw an uncatchable php error

Line 
1 <?php
2 /*
3  *  $Id$
4  *
5  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
6  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
7  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
8  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
9  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
10  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
11  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
12  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
13  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
14  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
15  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
16  *
17  * This software consists of voluntary contributions made by many individuals
18  * and is licensed under the LGPL. For more information, see
19  * <http://www.phpdoctrine.org>.
20  */
21
22 /**
23  * Doctrine_Ticket_929_TestCase
24  *
25  * @package     Doctrine
26  * @author      David Stendardi <david.stendardi@adenclassifieds.com>
27  * @category    Hydration
28  * @link        www.phpdoctrine.org
29  * @since       1.0
30  * @version     $Revision$
31  */
32 class Doctrine_Ticket_929_TestCase extends Doctrine_UnitTestCase
33 {
34     public function prepareData(){       
35           $oPerson = new T929_Person;
36           $oPerson->name = 'Jonathan';
37           $oPerson->Country->code = 'us';
38           $oPerson->Country->Translation['fr']->name = 'Etats Unis';
39           $oPerson->Country->Translation['en']->name = 'United states';         
40           $oPerson->save();
41
42         parent :: prepareData();
43     }
44  
45     public function prepareTables(){
46           $this->tables = array();
47           $this->tables[] = 'T929_Person';
48           $this->tables[] = 'T929_Country';
49           $this->tables[] = 'T929_JobPosition';
50           $this->tables[] = 'T929_JobCategory';
51           
52           parent :: prepareTables();
53     }
54  
55     public function testTicket(){
56           try {
57               $q = new Doctrine_Query();
58               $r = $q
59                 ->from('T929_Person P')
60                 ->leftJoin('P.Country Ct')
61                 ->leftJoin('Ct.Translation T1 WITH T1.lang = ?', 'fr')
62                 ->leftJoin('P.JobPositions J')
63                 ->leftJoin('J.Category C')
64                 ->leftJoin('C.Translation T2 WITH T2.lang = ?', 'fr')
65                 ->where('P.name = ?', 'Jonathan')
66                 ->fetchOne();
67           } catch(Exception $e){         
68             $this->fail($e->getMessage());       
69           }
70     }
71 }
72
73 class T929_Person extends Doctrine_Record
74 {
75       public function setTableDefinition() {
76           $this->setTableName('T929_person');
77           $this->hasColumn('country_id', 'integer');
78           $this->hasColumn('name', 'string', 200);
79       }
80
81       public function setUp() {
82             parent :: setUp();
83             $this->hasOne('T929_Country as Country', array(
84               'local' => 'country_id',
85               'foreign' => 'id',
86               'onDelete' => 'CASCADE'
87               ));
88             
89             $this->hasMany('T929_JobPosition as JobPositions', array(
90               'local' => 'id',
91               'foreign' => 'person_id',
92               'onDelete' => 'CASCADE'
93               ));
94       }
95 }
96
97 class T929_Country extends Doctrine_Record {
98  
99       public function setTableDefinition()
100       {
101           $this->setTableName('T929_country');
102           $this->hasColumn('name', 'string', 200);
103           $this->hasColumn('code', 'string', 200);
104       }
105     
106       public function setUp() {
107             parent :: setUp();
108             $this->hasMany('T929_Person as Persons', array(
109               'local' => 'id',
110               'foreign' => 'country_id',
111               'onDelete' => 'CASCADE'
112               ));
113               
114             $this->actAs('I18n', array('fields' => array('name')));
115       }
116 }
117
118
119
120 class T929_JobPosition extends Doctrine_Record
121 {
122       public function setTableDefinition(){
123           $this->setTableName('T929_address');
124           $this->hasColumn('name', 'string', 200);
125           $this->hasColumn('person_id', 'integer');
126           $this->hasColumn('job_category_id', 'integer');
127       }
128
129       public function setUp() {
130             parent :: setUp();
131             $this->hasOne('T929_Person as Person', array(
132               'local' => 'person_id',
133               'foreign' => 'id',
134               'onDelete' => 'CASCADE'
135               ));
136               
137             $this->hasOne('T929_JobCategory as Category', array(
138               'local' => 'job_category_id',
139               'foreign' => 'id',
140               'onDelete' => 'CASCADE'
141               ));
142       }
143 }
144
145 class T929_JobCategory extends Doctrine_Record
146 {
147       public function setTableDefinition() {
148           $this->setTableName('job_category');
149           $this->hasColumn('code', 'integer', 4);
150           $this->hasColumn('name', 'string', 200);
151       }
152     
153       public function setUp() {
154             parent :: setUp();
155             $this->hasMany('T929_JobPosition as Positions', array(
156               'local' => 'id',
157               'foreign' => 'job_category_id',
158               'onDelete' => 'CASCADE'
159               ));
160               
161             $this->actAs('I18n', array('fields' => array('name')));
162       }
163 }
164
165
166
167
168