1<?php 2 3/* 4 * $Id$ 5 * 6 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 7 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 8 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 9 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 10 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 11 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 12 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 13 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 14 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 15 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 16 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 17 * 18 * This software consists of voluntary contributions made by many individuals 19 * and is licensed under the LGPL. For more information, see 20 * <http://www.doctrine-project.org>. 21 */ 22 23/** 24 * Doctrine_Ticket_1365_TestCase 25 * 26 * @package Doctrine 27 * @author David Stendardi <david.stendardi@adenclassifieds.com> 28 * @category Query 29 * @link www.doctrine-project.org 30 * @since 0.10.4 31 * @version $Revision$ 32 */ 33class Doctrine_Ticket_1365_TestCase extends Doctrine_UnitTestCase 34{ 35 public function testInit() 36 { 37 $this->dbh = new Doctrine_Adapter_Mock('mysql'); 38 $this->conn = Doctrine_Manager::getInstance()->openConnection($this->dbh); 39 40 $this->conn->setCharset('utf8'); 41 $this->conn->setAttribute(Doctrine_Core::ATTR_USE_NATIVE_ENUM, true); 42 } 43 44 public function prepareData() 45 { 46 } 47 48 public function prepareTables() 49 { 50 $this->tables = array(); 51 $this->tables[] = 'T1365_Person'; 52 $this->tables[] = 'T1365_Skill'; 53 $this->tables[] = 'T1365_PersonHasSkill'; 54 55 parent :: prepareTables(); 56 } 57 58 public function testTicket() 59 { 60 $q = Doctrine_Query::create() 61 ->select('s.*, phs.*') 62 ->from('T1365_Skill s') 63 ->leftJoin('s.T1365_PersonHasSkill phs') 64 ->where('phs.value0 > phs.value1'); 65 66 $this->assertEqual( 67 $q->getSqlQuery(), 68 'SELECT l.id AS l__id, l.name AS l__name, ' . 69 'l2.id AS l2__id, l2.fk_person_id AS l2__fk_person_id, l2.fk_skill_id AS l2__fk_skill_id, l2.value0 AS l2__value0, l2.value1 AS l2__value1 ' . 70 'FROM la__skill l LEFT JOIN la__person_has_skill l2 ON l.id = l2.fk_skill_id ' . 71 'WHERE (l2.value0 > l2.value1)' 72 ); 73 } 74} 75 76 77class T1365_Person extends Doctrine_Record 78{ 79 public function setTableDefinition() 80 { 81 $this->setTableName('la__person'); 82 83 $this->hasColumn('name', 'string', 255); 84 } 85 86 public function setUp() 87 { 88 $this->hasMany('T1365_PersonHasSkill', array('local' => 'id', 'foreign' => 'fk_person_id')); 89 } 90} 91 92 93class T1365_Skill extends Doctrine_Record 94{ 95 public function setTableDefinition() 96 { 97 $this->setTableName('la__skill'); 98 99 $this->hasColumn('name', 'string', 255); 100 } 101 102 public function setUp() 103 { 104 $this->hasMany('T1365_PersonHasSkill', array('local' => 'id', 'foreign' => 'fk_skill_id')); 105 } 106} 107 108 109class T1365_PersonHasSkill extends Doctrine_Record 110{ 111 public function setTableDefinition() 112 { 113 $this->setTableName('la__person_has_skill'); 114 115 $this->hasColumn('fk_person_id', 'integer', 8, array( 116 'type' => 'integer', 'length' => '8' 117 )); 118 119 $this->hasColumn('fk_skill_id', 'integer', 8, array( 120 'type' => 'integer', 'length' => '8' 121 )); 122 123 $this->hasColumn('value0', 'enum', 3, array( 124 'type' => 'enum', 'values' => array( 125 0 => '0', 1 => '1', 2 => '2', 3 => '3' 126 ), 'default' => 0, 'notnull' => true, 'length' => '3' 127 )); 128 129 $this->hasColumn('value1', 'enum', 3, array( 130 'type' => 'enum', 'values' => array( 131 0 => '0', 1 => '1', 2 => '2', 3 => '3' 132 ), 'default' => 0, 'notnull' => true, 'length' => '3' 133 )); 134 } 135 136 public function setUp() 137 { 138 $this->hasOne('T1365_Person', array('local' => 'fk_person_id', 'foreign' => 'id')); 139 $this->hasOne('T1365_Skill', array('local' => 'fk_skill_id', 'foreign' => 'id')); 140 } 141}