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_1992_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_1992_TestCase extends Doctrine_UnitTestCase 34{ 35 public function prepareTables() 36 { 37 $this->tables[] = 'Ticket_1992_Person'; 38 $this->tables[] = 'Ticket_1992_Profile'; 39 $this->tables[] = 'Ticket_1992_PersonProfile'; 40 parent::prepareTables(); 41 } 42 43 public function prepareData() 44 { 45 $this->person = new Ticket_1992_Person(); 46 $this->person->nummer = '1'; 47 $this->profile1 = new Ticket_1992_Profile(); 48 $this->profile1->name = 'test 2'; 49 $this->person->Profile[] = $this->profile1; 50 $this->profile2 = new Ticket_1992_Profile(); 51 $this->profile2->name = 'test 2'; 52 $this->person->Profile[] = $this->profile2; 53 $this->person->save(); 54 } 55 56 public function testTest() 57 { 58 Doctrine_Manager::getInstance()->setAttribute(Doctrine_Core::ATTR_USE_DQL_CALLBACKS, true); 59 60 $person = Doctrine_Query::create() 61 ->from('Ticket_1992_Person p') 62 ->innerJoin('p.Profile pr') 63 ->fetchOne(); 64 $this->assertEqual($person['nummer'], 1); 65 $this->assertEqual(count($person['Profile']), 2); 66 67 $this->profile1->delete(); 68 69 $person = Doctrine_Query::create() 70 ->from('Ticket_1992_Person p') 71 ->innerJoin('p.Profile pr') 72 ->fetchOne(); 73 $this->assertEqual($person['nummer'], 1); 74 $this->assertEqual(count($person['Profile']), 1); 75 76 $this->profile2->delete(); 77 78 $person = Doctrine_Query::create() 79 ->from('Ticket_1992_Person p') 80 ->innerJoin('p.Profile pr') 81 ->fetchOne(); 82 $this->assertEqual($person, false); 83 84 $person = Doctrine_Query::create() 85 ->from('Ticket_1992_Person p') 86 ->leftJoin('p.Profile pr') 87 ->fetchOne(); 88 $this->assertEqual($person['nummer'], 1); 89 $this->assertEqual(count($person['Profile']), 0); 90 91 $this->person->delete(); 92 93 $person = Doctrine_Query::create() 94 ->from('Ticket_1992_Person p') 95 ->fetchOne(); 96 $this->assertEqual($person, false); 97 98 Doctrine_Manager::getInstance()->setAttribute(Doctrine_Core::ATTR_USE_DQL_CALLBACKS, false); 99 } 100} 101 102class Ticket_1992_Person extends Doctrine_Record 103{ 104 public function setTableDefinition() 105 { 106 $this->hasColumn('nummer', 'string', 16, array('type' => 'string', 'length' => 16, 'primary' => true)); 107 } 108 109 public function setUp() 110 { 111 $this->hasMany('Ticket_1992_Profile as Profile', array('local' => 'person_nummer', 'foreign' => 'profile_id', 'refClass' => 'Ticket_1992_PersonProfile')); 112 $this->actAs('SoftDelete'); 113 } 114} 115 116class Ticket_1992_Profile extends Doctrine_Record 117{ 118 public function setTableDefinition() 119 { 120 $this->hasColumn('id', 'integer', 4, array('type' => 'integer', 'length' => 4, 'unsigned' => 1, 'primary' => true, 'autoincrement' => true)); 121 $this->hasColumn('name', 'string'); 122 } 123 124 public function setUp() 125 { 126 $this->hasMany('Ticket_1992_Person as Person', array('local' => 'profile_id', 'foreign' => 'person_nummer', 'refClass' => 'Ticket_1992_PersonProfile')); 127 $this->actAs('SoftDelete'); 128 } 129} 130 131class Ticket_1992_PersonProfile extends Doctrine_Record 132{ 133 public function setTableDefinition() 134 { 135 $this->hasColumn('person_nummer', 'string', 16, array('type' => 'string', 'length' => 16, 'notnull' => true)); 136 $this->hasColumn('profile_id', 'integer', 4, array('type' => 'integer', 'length' => 4, 'unsigned' => 1, 'notnull' => true)); 137 } 138 139 public function setUp() 140 { 141 $this->actAs('SoftDelete'); 142 } 143}