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_1341_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_1341_TestCase extends Doctrine_UnitTestCase 34{ 35 public function prepareTables() 36 { 37 $this->tables[] = 'Ticket_1341_User'; 38 $this->tables[] = 'Ticket_1341_Profile'; 39 parent::prepareTables(); 40 } 41 42 public function testTest() 43 { 44 try { 45 $user = new Ticket_1341_User(); 46 $user->username = 'jwage'; 47 $user->password = 'changeme'; 48 $user->Profile->name = 'Jonathan H. Wage'; 49 $user->save(); 50 $this->pass(); 51 $this->assertEqual($user->toArray(true), array( 52 'id' => '1', 53 'username' => 'jwage', 54 'password' => 'changeme', 55 'Profile' => 56 array( 57 'id' => '1', 58 'name' => 'Jonathan H. Wage', 59 'user_id' => '1', 60 ), 61 )); 62 $q = Doctrine_Query::create() 63 ->from('Ticket_1341_User u') 64 ->leftJoin('u.Profile p'); 65 $this->assertEqual($q->getSqlQuery(), 'SELECT t.id AS t__id, t.username AS t__username, t.password AS t__password, t2.id AS t2__id, t2.name AS t2__name, t2.userid AS t2__userid FROM ticket_1341__user t LEFT JOIN ticket_1341__profile t2 ON t.id = t2.userid'); 66 } catch (Exception $e) { 67 $this->fail($e->getMessage()); 68 } 69 } 70} 71 72class Ticket_1341_User extends Doctrine_Record 73{ 74 public function setTableDefinition() 75 { 76 $this->hasColumn('username', 'string', 255); 77 $this->hasColumn('password', 'string', 255); 78 } 79 80 public function setUp() 81 { 82 $this->hasOne('Ticket_1341_Profile as Profile', array('local' => 'id', 'foreign' => 'user_id')); 83 } 84} 85 86class Ticket_1341_Profile extends Doctrine_Record 87{ 88 public function setTableDefinition() 89 { 90 $this->hasColumn('name', 'string', 255); 91 $this->hasColumn('userId as user_id', 'integer'); 92 } 93 94 public function setUp() 95 { 96 $this->hasOne('Ticket_1341_User as User', array('local' => 'user_id', 'foreign' => 'id')); 97 } 98}