Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
ModelJoinBuilderUtilTest.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 
38  {
39  public static function setUpBeforeClass()
40  {
41  parent::setUpBeforeClass();
42  SecurityTestHelper::createSuperAdmin();
43  static::buildRelationModels();
44  }
45 
46  public static function getDependentTestModelClassNames()
47  {
48  return array('TestModelJoinHasManyAndHasOneBelongsToSide', 'TestModelJoinHasManySide',
49  'TestModelJoinHasOneSide', 'TestModelJoinManyManySide', 'TestModelJoinManyManySideTwo');
50  }
51 
52  protected function validJoinHelper($modelClassName, $attributeName, $relatedAttributeName)
53  {
54  $searchAttributeData = array();
55  $searchAttributeData['clauses'] = array(
56  1 => array(
57  'attributeName' => $attributeName,
58  'relatedAttributeName' => $relatedAttributeName,
59  'operatorType' => OperatorRules::TYPE_IS_NOT_NULL,
60  'value' => null
61  )
62  );
63  $searchAttributeData['structure'] = '1';
64 
65  $searchAttributeDataAndClassNames = array(
66  array($modelClassName => $searchAttributeData)
67  );
68 
69  $sql = RedBeanModelsDataProvider::makeUnionSql( $searchAttributeDataAndClassNames,
70  null,
71  true);
72 
73  $result = ZurmoRedBean::GetAll($sql);
74 
75  $this->assertTrue(is_array($result));
76  }
77 
78  public function testGettingValidJoinForHasManyBelongsTo()
79  {
80  $model = 'TestModelJoinHasManyAndHasOneBelongsToSide';
81  $attributeName = 'testModelJoinHasManySide';
82  $relatedAttributeName = 'hasManyField';
83 
84  $this->validJoinHelper($model, $attributeName, $relatedAttributeName);
85  }
86 
87  public function testGettingValidJoinForHasOneBelongsTo()
88  {
89  $model = 'TestModelJoinHasManyAndHasOneBelongsToSide';
90  $attributeName = 'testModelJoinHasOneSide';
91  $relatedAttributeName = 'hasOneField';
92 
93  $this->validJoinHelper($model, $attributeName, $relatedAttributeName);
94  }
95 
96  public function testGettingValidJoinForHasOne()
97  {
98  $model = 'TestModelJoinHasOneSide';
99  $attributeName = 'testModelJoinHasManyAndHasOneBelongsToSide';
100  $relatedAttributeName = 'hasManyAndHasOneField';
101 
102  $this->validJoinHelper($model, $attributeName, $relatedAttributeName);
103  }
104 
105  public function testGettingValidJoinForHasMany()
106  {
107  $model = 'TestModelJoinHasManySide';
108  $attributeName = 'testHasMany';
109  $relatedAttributeName = 'hasManyAndHasOneField';
110 
111  $this->validJoinHelper($model, $attributeName, $relatedAttributeName);
112  }
113 
114  public function testGettingValidJoinForManyMany()
115  {
116  $model = 'TestModelJoinManyManySide';
117  $attributeName = 'testModelJoinManyManySideTwos';
118  $relatedAttributeName = 'manyManyTwoField';
119 
120  $this->validJoinHelper($model, $attributeName, $relatedAttributeName);
121  }
122 
123  protected static function buildRelationModels()
124  {
125  $modelForListing1 = new TestModelJoinHasManyAndHasOneBelongsToSide();
126  $modelForListing1->name = "ModelForListing1";
127  $modelForListing1->hasManyAndHasOneField = "belongsTo1";
128  $modelForListing2 = new TestModelJoinHasManyAndHasOneBelongsToSide();
129  $modelForListing2->name = "ModelForListing2";
130  $modelForListing2->hasManyAndHasOneField = "belongsTo2";
131  $modelHasManyOfListItem = new TestModelJoinHasManySide();
132  $modelHasManyOfListItem->name = "Has List Items 1 and 2";
133  $modelHasManyOfListItem->hasManyField = "hasMany";
134  $modelHasOneOfListItem = new TestModelJoinHasOneSide();
135  $modelHasOneOfListItem->name = "Has List Item 1";
136  $modelHasOneOfListItem->hasOneField = "hasOne";
137  $modelManyManyItem1 = new TestModelJoinManyManySide();
138  $modelManyManyItem1->name = "Many Many 1-1";
139  $modelManyManyItem1->manyManyField = "hasMany1";
140  $modelManyManyItem2 = new TestModelJoinManyManySide();
141  $modelManyManyItem2->name = "Many Many 1-2";
142  $modelManyManyItem2->manyManyField = "hasMany1";
143  $modelManyManySideTwoItem1 = new TestModelJoinManyManySideTwo();
144  $modelManyManySideTwoItem1->name = "Many Many 2-1";
145  $modelManyManySideTwoItem1->manyManyTwoField = "hasMany2";
146  $modelManyManySideTwoItem2 = new TestModelJoinManyManySideTwo();
147  $modelManyManySideTwoItem2->name = "Many Many 2-2";
148  $modelManyManySideTwoItem2->manyManyTwoField = "hasMany2";
149 
150  $modelHasManyOfListItem->testHasMany->add($modelForListing1);
151  $modelHasManyOfListItem->testHasMany->add($modelForListing2);
152  $modelHasOneOfListItem->testModelJoinHasManyAndHasOneBelongsToSide = $modelForListing1;
153  $modelManyManyItem1->testModelJoinManyManySideTwos->add($modelManyManySideTwoItem1);
154  $modelManyManyItem1->testModelJoinManyManySideTwos->add($modelManyManySideTwoItem2);
155  $modelManyManySideTwoItem1->testModelJoinManyManySides->add($modelManyManyItem1);
156  $modelManyManySideTwoItem1->testModelJoinManyManySides->add($modelManyManyItem2);
157 
158  $saved = $modelHasManyOfListItem->save();
159  assert('$saved'); // Not Coding Standard
160 
161  $saved = $modelHasOneOfListItem->save();
162  assert('$saved'); // Not Coding Standard
163 
164  $saved = $modelManyManyItem1->save();
165  assert('$saved'); // Not Coding Standard
166 
167  $saved = $modelManyManySideTwoItem1->save();
168  assert('$saved'); // Not Coding Standard
169  }
170  }
171 ?>
static makeUnionSql(array $modelClassNamesAndSearchAttributeData, array $modelClassNamesAndSortAttributes=null, $sortDescending=false, $offset=null, $limit=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.