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_1461_TestCase
24 *
25 * @package     Doctrine
26 * @author      Konsta Vesterinen <kvesteri@cc.hut.fi>
27 * @license     http://www.opensource.org/licenses/lgpl-license.php LGPL
28 * @category    Object Relational Mapping
29 * @link        www.doctrine-project.org
30 * @since       1.0
31 * @version     $Revision$
32 */
33class Doctrine_Ticket_1461_TestCase extends Doctrine_UnitTestCase
34{
35    public function testFetchArraySupportsTwoAggregates()
36    {
37        $q = new Doctrine_Query();
38
39        $q->select("u.*, p.*, CONCAT(u.name, '_1') concat1, CONCAT(u.name, '_2') concat2")
40        ->from('User u')
41        ->innerJoin('u.Phonenumber p')
42        ->where("u.name = 'zYne'");
43
44        $users = $q->execute(array(), Doctrine_Core::HYDRATE_ARRAY);
45
46        $this->assertEqual($users[0]['concat1'], 'zYne_1');
47
48        $this->assertEqual($users[0]['concat2'], 'zYne_2');
49    }
50
51    public function testFetchArraySupportsTwoAggregatesInRelation()
52    {
53        $q = new Doctrine_Query();
54
55        $q->select("u.*, p.*, CONCAT(p.phonenumber, '_1') concat1, CONCAT(p.phonenumber, '_2') concat2")
56        ->from('User u')
57        ->innerJoin('u.Phonenumber p')
58        ->where("u.name = 'zYne'");
59
60        $users = $q->execute(array(), Doctrine_Core::HYDRATE_ARRAY);
61
62        $this->assertEqual($users[0]['concat2'], '123 123_2');
63
64        $this->assertEqual($users[0]['concat1'], '123 123_1');
65    }
66
67    public function testFetchArraySupportsTwoAggregatesInRelationAndRoot()
68    {
69        $q = new Doctrine_Query();
70
71        $q->select("u.*, p.*, CONCAT(u.name, '_1') concat1, CONCAT(u.name, '_2') concat2, CONCAT(p.phonenumber, '_3') concat3, CONCAT(p.phonenumber, '_3') concat4")
72        ->from('User u')
73        ->innerJoin('u.Phonenumber p')
74        ->where("u.name = 'zYne'");
75
76        $users = $q->execute(array(), Doctrine_Core::HYDRATE_ARRAY);
77
78        $this->assertEqual($users[0]['concat1'], 'zYne_1');
79
80        $this->assertEqual($users[0]['concat2'], 'zYne_2');
81
82        $this->assertEqual($users[0]['concat3'], '123 123_3');
83
84        $this->assertTrue(isset($users[0]['concat4']));
85    }
86}