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_1121_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_1121_TestCase extends Doctrine_UnitTestCase
34{
35    public function prepareTables()
36    {
37        $this->tables[] = 'Ticket_1121_User';
38        $this->tables[] = 'Ticket_1121_Profile';
39        parent::prepareTables();
40    }
41
42    public function testTest()
43    {
44        Doctrine_Manager::getInstance()->setAttribute(Doctrine_Core::ATTR_USE_DQL_CALLBACKS, true);
45        $q = Doctrine_Query::create()
46                ->from('Ticket_1121_User u')
47                // UserProfile has SoftDelete behavior but because it is aliased as Profile, it tries to
48                // call the dql callbacks for the query on a class named Profile instead of UserProfile
49                // Code responsible for this is in Doctrine_Query_Abstract::_preQuery()
50                ->leftJoin('u.Profile p');
51
52        // The condition and params for UserProfile SoftDelete and are not added properly
53        $this->assertEqual($q->getSqlQuery(), 'SELECT t.id AS t__id, t.username AS t__username, t.password AS t__password, t.profile_id AS t__profile_id, t.deleted_at AS t__deleted_at, t2.id AS t2__id, t2.name AS t2__name, t2.about AS t2__about, t2.deleted_at AS t2__deleted_at FROM ticket_1121__user t LEFT JOIN ticket_1121__profile t2 ON t.profile_id = t2.id AND (t2.deleted_at IS NULL) WHERE (t.deleted_at IS NULL)');
54        $this->assertEqual(count($q->getFlattenedParams()), 0);
55        Doctrine_Manager::getInstance()->setAttribute(Doctrine_Core::ATTR_USE_DQL_CALLBACKS, false);
56    }
57}
58
59class Ticket_1121_User extends Doctrine_Record
60{
61    public function setTableDefinition()
62    {
63        $this->hasColumn('username', 'string', 255);
64        $this->hasColumn('password', 'string', 255);
65        $this->hasColumn('profile_id', 'integer');
66    }
67
68    public function setUp()
69    {
70        $this->actAs('SoftDelete');
71        $this->hasOne('Ticket_1121_Profile as Profile', array('local'   => 'profile_id',
72                                                              'foreign' => 'id'));
73    }
74}
75
76class Ticket_1121_Profile extends Doctrine_Record
77{
78    public function setTableDefinition()
79    {
80        $this->hasColumn('name', 'string', 255);
81        $this->hasColumn('about', 'string', 2000);
82    }
83
84    public function setUp()
85    {
86        $this->actAs('SoftDelete');
87        $this->hasOne('Ticket_1121_User as User', array('local'   => 'id',
88                                                        'foreign' => 'profile_id'));
89    }
90}