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_DC300_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_DC300_TestCase extends Doctrine_UnitTestCase 34{ 35 public function prepareData() 36 { 37 $g1 = new Ticket_DC300_Group(); 38 $g1['name'] = 'group1'; 39 $g1->save(); 40 41 $g2 = new Ticket_DC300_Group(); 42 $g2['name'] = 'group2'; 43 $g2->save(); 44 45 $g3 = new Ticket_DC300_Group(); 46 $g3['name'] = 'group3'; 47 $g3->save(); 48 49 $u1 = new Ticket_DC300_User(); 50 $u1['name'] = 'user1'; 51 $u1['Groups']->add($g1); 52 $u1['Groups']->add($g2); 53 $u1->save(); 54 } 55 56 public function prepareTables() 57 { 58 $this->tables[] = 'Ticket_DC300_Group'; 59 $this->tables[] = 'Ticket_DC300_User'; 60 $this->tables[] = 'Ticket_DC300_UserGroup'; 61 parent::prepareTables(); 62 } 63 64 public function testRefTableEntriesOnManyToManyRelationsWithSynchronizeWithArray() 65 { 66 $u1 = Doctrine_Core::getTable('Ticket_DC300_User')->find(1); 67 68 // update the groups user (id 1) is linked to 69 $u1->synchronizeWithArray(array( 70 'Groups' => array( 71 array('name' => 'group1 update'), 72 array('name' => 'group2 update') 73 ) 74 )); 75 $u1->save(); 76 77 // update the user-objects with real data from database 78 $u1->loadReference('Groups'); 79 80 // check wether the two database-entries in RefTable exists 81 $this->assertEqual(count($u1->Groups), 2); 82 } 83 84} 85 86class Ticket_DC300_Group extends Doctrine_Record 87{ 88 public function setTableDefinition() 89 { 90 $this->hasColumn('name', 'string', 255); 91 } 92 93 public function setUp() 94 { 95 $this->hasMany('Ticket_DC300_User as Users', array( 96 'local' => 'group_id', 97 'foreign' => 'user_id', 98 'refClass' => 'Ticket_DC300_UserGroup' 99 )); 100 } 101} 102 103class Ticket_DC300_User extends Doctrine_Record 104{ 105 public function setTableDefinition() 106 { 107 $this->hasColumn('name', 'string', 255); 108 } 109 110 public function setUp() 111 { 112 $this->hasMany('Ticket_DC300_Group as Groups', array( 113 'local' => 'user_id', 114 'foreign' => 'group_id', 115 'refClass' => 'Ticket_DC300_UserGroup' 116 )); 117 } 118} 119 120class Ticket_DC300_UserGroup extends Doctrine_Record 121{ 122 public function setTableDefinition() 123 { 124 $this->hasColumn('user_id', 'integer'); 125 $this->hasColumn('group_id', 'integer'); 126 } 127}