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.doctrine-project.org>.
20 */
21
22/**
23 * Doctrine_Ticket_1015_TestCase
24 *
25 * @package     Doctrine
26 * @license     http://www.opensource.org/licenses/lgpl-license.php LGPL
27 * @category    Object Relational Mapping
28 * @link        www.doctrine-project.org
29 * @since       1.0
30 * @version     $Revision$
31 */
32class Doctrine_Ticket_1015_TestCase extends Doctrine_UnitTestCase {
33
34    public function prepareTables() {
35        $this->tables = array();
36        $this->tables[] = 'T1015_Person';
37        $this->tables[] = 'T1015_Points';
38
39        parent::prepareTables();
40    }
41
42    public function prepareData()
43    {
44        $person = new T1015_Person();
45        $person['name'] = "James";
46        $person['T1015_Points']['total'] = 15;
47        $person->save();
48    }
49
50
51    public function testDoctrineQueryJoinSelect()
52    {
53
54        $q = new Doctrine_Query();
55        $q->select('person.id, points.total')
56        ->from('T1015_Person person')
57        ->innerJoin('person.T1015_Points points WITH person.id = 1');
58
59        $results = $q->execute(array(), Doctrine_Core::HYDRATE_ARRAY);
60        //var_dump($results);
61        $person = $results[0];
62
63        // number of points for person id of 1 should be 15
64        $this->assertEqual(15, $person['T1015_Points']['total']); //THIS WILL FAIL
65
66    }
67
68    public function testDoctrineRawSQLJoinSelect()
69    {
70        $q = new Doctrine_RawSql();
71        $q->select('{person.id}, {points.total}')
72        ->from('person person INNER JOIN points points ON person.id = points.person_id AND person.id=1')
73        ->addComponent('person', 'T1015_Person person')
74        ->addComponent('points', 'person.T1015_Points points');
75
76        $results = $q->execute(array(), Doctrine_Core::HYDRATE_ARRAY);
77        //var_dump($results);
78        $person = $results[0];
79
80        // number of points for person id of 1 should be 15
81        $this->assertEqual(15, $person['T1015_Points']['total']);
82    }
83}
84
85class T1015_Person extends Doctrine_Record
86{
87    public function setTableDefinition()
88    {
89        $this->setTableName('person');
90        $this->hasColumn('id', 'integer', 15, array('autoincrement' => true, 'unsigned' => true, 'primary' => true, 'notnull' => true));
91        $this->hasColumn('name', 'string', 50);
92    }
93
94    public function setUp()
95    {
96        parent :: setUp();
97        $this->hasOne('T1015_Points', array('local' => 'id', 'foreign' => 'person_id'));
98    }
99}
100
101class T1015_Points extends Doctrine_Record
102{
103    public function setTableDefinition()
104    {
105        $this->setTableName('points');
106        $this->hasColumn('person_id', 'integer', 15, array('primary' => true, 'notnull' => true));
107        $this->hasColumn('total', 'integer', 3);
108    }
109
110    public function setUp()
111    {
112        parent :: setUp();
113        $this->hasOne('T1015_Person', array('local' => 'person_id', 'foreign' => 'id'));
114    }
115}
116