Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
RedBeanModelPolyOneToManyTest.php
1 <?php
2  /*********************************************************************************
3  * Zurmo is a customer relationship management program developed by
4  * Zurmo, Inc. Copyright (C) 2017 Zurmo Inc.
5  *
6  * Zurmo is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License version 3 as published by the
8  * Free Software Foundation with the addition of the following permission added
9  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10  * IN WHICH THE COPYRIGHT IS OWNED BY ZURMO, ZURMO DISCLAIMS THE WARRANTY
11  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12  *
13  * Zurmo is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Affero General Public License along with
19  * this program; if not, see http://www.gnu.org/licenses or write to the Free
20  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  * 02110-1301 USA.
22  *
23  * You can contact Zurmo, Inc. with a mailing address at 27 North Wacker Drive
24  * Suite 370 Chicago, IL 60606. or at email address contact@zurmo.com.
25  *
26  * The interactive user interfaces in original and modified versions
27  * of this program must display Appropriate Legal Notices, as required under
28  * Section 5 of the GNU Affero General Public License version 3.
29  *
30  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31  * these Appropriate Legal Notices must retain the display of the Zurmo
32  * logo and Zurmo copyright notice. If the display of the logo is not reasonably
33  * feasible for technical reasons, the Appropriate Legal Notices must display the words
34  * "Copyright Zurmo Inc. 2017. All rights reserved".
35  ********************************************************************************/
36 
43  {
44  public static function getDependentTestModelClassNames()
45  {
46  return array('TestPolyOneToManyOneSide',
47  'TestPolyOneToManyOneSideTwo',
48  'TestPolyOneToManyPolySide',
49  'TestPolyOneToManyPolySideOwned'
50  );
51  }
52 
53  public function testPolyOneToManyNotOwned()
54  {
55  $polySide = new TestPolyOneToManyPolySide();
56  $polySide->name = 'polySideTest';
57 
58  $oneSide = new TestPolyOneToManyOneSide();
59  $oneSide->name = 'oneSideTest';
60  $oneSide->polys->add($polySide);
61  $this->assertTrue($oneSide->save());
62 
63  $polySideId = $polySide->id;
64  $this->assertTrue($polySideId > 0);
65 
66  $oneSideId = $oneSide->id;
67  $oneSide->forget();
68  unset($oneSide);
69 
70  $polySide2 = new TestPolyOneToManyPolySide();
71  $polySide2->name = 'polySideTest2';
72 
73  $oneSide2 = new TestPolyOneToManyOneSideTwo();
74  $oneSide2->name = 'oneSideTwoTest';
75  $oneSide2->polysTwo->add($polySide2);
76  $this->assertTrue($oneSide2->save());
77 
78  $polySide2Id = $polySide2->id;
79  $this->assertTrue($polySide2Id > 0);
80 
81  $oneSide2Id = $oneSide2->id;
82  $oneSide2->forget();
83  unset($oneSide2);
84 
85  //Get oneSide and make sure it has one polySide that matches the appropriate id
86  $oneSide = TestPolyOneToManyOneSide::getById($oneSideId);
87  $this->assertEquals(1, $oneSide->polys->count());
88  $this->assertEquals($polySideId, $oneSide->polys[0]->id);
89 
90  //Get oneSide2 and make sure it has one polySide2 that matches the appropriate id
91  $oneSide2 = TestPolyOneToManyOneSideTwo::getById($oneSide2Id);
92  $this->assertEquals(1, $oneSide2->polysTwo->count());
93  $this->assertEquals($polySide2Id, $oneSide2->polysTwo[0]->id);
94 
95  //do a direct sql to get the row for polySide
96  $row = ZurmoRedBean::getRow('select * from testpolyonetomanypolyside');
97  $this->assertTrue(!isset($row['testpolyonetomanyoneside_id']));
98  $this->assertTrue(!isset($row['testpolyonetomanyonesidetwo_id']));
99  //Confirm the poly type and poly id columns are there.
100  $this->assertTrue(isset($row['polytest_type']));
101  $this->assertTrue(isset($row['polytest_id']));
102 
103  //test adding an extra PolySide to oneSide
104  $polySide3 = new TestPolyOneToManyPolySide();
105  $polySide3->name = 'polySideTest3';
106  $oneSide->polys->add($polySide3);
107  $this->assertTrue($oneSide->save());
108  $polySide3Id = $polySide3->id;
109  $oneSide->forget();
110  unset($oneSide);
111 
112  //Now test there are 2 related polys
113  $oneSide = TestPolyOneToManyOneSide::getById($oneSideId);
114  $this->assertEquals(2, $oneSide->polys->count());
115  $this->assertEquals($polySideId, $oneSide->polys[0]->id);
116  $this->assertEquals($polySide3Id, $oneSide->polys[1]->id);
117 
118  //test disconnect a polySide, it should also remove the attached model from db. TestPolyOneToManyPolySide should be three
119  $polySide = $oneSide->polys[0];
120  $oneSide->polys->remove($polySide);
121  $this->assertTrue($oneSide->save());
122  $this->assertEquals(2, TestPolyOneToManyPolySide::getCount());
123 
124  //Now test there is 1 related polys
125  $oneSide = TestPolyOneToManyOneSide::getById($oneSideId);
126  $this->assertEquals(1, $oneSide->polys->count());
127  $this->assertEquals($polySide3Id, $oneSide->polys[0]->id);
128 
129  $this->assertEquals(2, TestPolyOneToManyPolySide::getCount());
130  $this->assertTrue($oneSide->delete());
131  $this->assertEquals(1, TestPolyOneToManyPolySide::getCount());
133  $this->assertEquals(0, TestPolyOneToManyPolySide::getCount());
134  }
135 
139  public function testPolyOneToManyOwned()
140  {
141  $this->assertEquals(0, TestPolyOneToManyPolySide::getCount());
142 
143  $polySide = new TestPolyOneToManyPolySideOwned();
144  $polySide->name = 'polySideTest';
145 
146  $oneSide = new TestPolyOneToManyOneSide();
147  $oneSide->name = 'oneSideTest';
148  $oneSide->ownedPolys->add($polySide);
149  $this->assertTrue($oneSide->save());
150 
151  $polySideId = $polySide->id;
152  $this->assertTrue($polySideId > 0);
153 
154  $oneSideId = $oneSide->id;
155  $oneSide->forget();
156  unset($oneSide);
157 
158  $polySide2 = new TestPolyOneToManyPolySideOwned();
159  $polySide2->name = 'polySideTest2';
160 
161  $oneSide2 = new TestPolyOneToManyOneSideTwo();
162  $oneSide2->name = 'oneSideTwoTest';
163  $oneSide2->ownedPolysTwo->add($polySide2);
164  $this->assertTrue($oneSide2->save());
165 
166  $polySide2Id = $polySide2->id;
167  $this->assertTrue($polySide2Id > 0);
168 
169  $oneSide2Id = $oneSide2->id;
170  $oneSide2->forget();
171  unset($oneSide2);
172 
173  $this->assertEquals(0, TestPolyOneToManyPolySide::getCount());
174  $this->assertEquals(2, TestPolyOneToManyPolySideOwned::getCount());
175 
176  //Get oneSide and make sure it has one polySide that matches the appropriate id
177  $oneSide = TestPolyOneToManyOneSide::getById($oneSideId);
178  $this->assertEquals(1, $oneSide->ownedPolys->count());
179  $this->assertEquals($polySideId, $oneSide->ownedPolys[0]->id);
180 
181  //Get oneSide2 and make sure it has one polySide2 that matches the appropriate id
182  $oneSide2 = TestPolyOneToManyOneSideTwo::getById($oneSide2Id);
183  $this->assertEquals(1, $oneSide2->ownedPolysTwo->count());
184  $this->assertEquals($polySide2Id, $oneSide2->ownedPolysTwo[0]->id);
185 
186  $this->assertTrue($oneSide->delete());
187  $this->assertEquals(1, TestPolyOneToManyPolySideOwned::getCount());
188  $this->assertTrue($oneSide2->delete());
189  $this->assertEquals(0, TestPolyOneToManyPolySideOwned::getCount());
190  }
191  }
192 ?>
static deleteAll()
static getCount(RedBeanModelJoinTablesQueryAdapter $joinTablesAdapter=null, $where=null, $modelClassName=null, $selectDistinct=false)
static getById($id, $modelClassName=null)
Generated on Sun Jul 12 2020 07:10:28
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.