Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
RedBeanModelsDataProviderTest.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 setUpBeforeClass()
45  {
46  parent::setUpBeforeClass();
47  SecurityTestHelper::createSuperAdmin();
48  $i = new I();
49  $i->iMember = 'iString1';
50  $i->name = 'd';
51  $saved = $i->save();
52  assert('$saved'); // Not Coding Standard
53  $i = new I();
54  $i->iMember = 'xString1';
55  $i->name = 'e';
56  $saved = $i->save();
57  assert('$saved'); // Not Coding Standard
58  $i = new I();
59  $i->iMember = 'yString1';
60  $i->name = 'f';
61  $saved = $i->save();
62  assert('$saved'); // Not Coding Standard
63 
64  $j = new J();
65  $j->jMember = 'jString1';
66  $j->name = 'a';
67  $saved = $j->save();
68  assert('$saved'); // Not Coding Standard
69  $j = new J();
70  $j->jMember = 'xString1';
71  $j->name = 'b';
72  $saved = $j->save();
73  assert('$saved'); // Not Coding Standard
74  $j = new J();
75  $j->jMember = 'yString1';
76  $j->name = 'c';
77  $saved = $j->save();
78  assert('$saved'); // Not Coding Standard
79 
80  $k = new K();
81  $k->kMember = 'kString1';
82  $k->name = 'g';
83  $saved = $k->save();
84  assert('$saved'); // Not Coding Standard
85  $k = new K();
86  $k->kMember = 'xString1';
87  $k->name = 'i';
88  $saved = $k->save();
89  assert('$saved'); // Not Coding Standard
90  $k = new K();
91  $k->kMember = 'yString1';
92  $k->name = 'h';
93  $saved = $k->save();
94  assert('$saved'); // Not Coding Standard
95  }
96 
97  public static function getDependentTestModelClassNames()
98  {
99  return array('H', 'I', 'J', 'K');
100  }
101 
102  public function testUnionSqlAcrossMultipleModels()
103  {
105  //Test search attribute data across multiple models.
106  $iFakePost = array('iMember' => 'iString');
107  $iMetadataAdapter = new SearchDataProviderMetadataAdapter(new I(false), 1, $iFakePost);
108  $jFakePost = array('jMember' => 'jString');
109  $jMetadataAdapter = new SearchDataProviderMetadataAdapter(new J(false), 1, $jFakePost);
110  $kFakePost = array('kMember' => 'kString');
111  $kMetadataAdapter = new SearchDataProviderMetadataAdapter(new K(false), 1, $kFakePost);
112  $modelClassNamesAndSearchAttributeData = array(
113  array('I' => $iMetadataAdapter->getAdaptedMetadata()),
114  array('J' => $jMetadataAdapter->getAdaptedMetadata()),
115  array('K' => $kMetadataAdapter->getAdaptedMetadata()),
116  );
117  $unionSql = RedBeanModelsDataProvider::makeUnionSql($modelClassNamesAndSearchAttributeData,
118  null, false, 2, 7);
119  $compareSubsetSql = "(";
120  $compareSubsetSql .= "select {$quote}i{$quote}.{$quote}id{$quote} id, 'I' modelClassName from {$quote}i{$quote} ";
121  $compareSubsetSql .= "where ({$quote}i{$quote}.{$quote}imember{$quote} like 'iString%')";
122  $compareSubsetSql .= ") ";
123  $compareSubsetSql .= "UNION (";
124  $compareSubsetSql .= "select {$quote}j{$quote}.{$quote}id{$quote} id, 'J' modelClassName from {$quote}j{$quote} ";
125  $compareSubsetSql .= "where ({$quote}j{$quote}.{$quote}jmember{$quote} like 'jString%')";
126  $compareSubsetSql .= ") ";
127  $compareSubsetSql .= "UNION (";
128  $compareSubsetSql .= "select {$quote}k{$quote}.{$quote}id{$quote} id, 'K' modelClassName from {$quote}k{$quote} ";
129  $compareSubsetSql .= "where ({$quote}k{$quote}.{$quote}kmember{$quote} like 'kString%')";
130  $compareSubsetSql .= ") ";
131  $compareSubsetSql .= 'limit 7 offset 2';
132  $this->assertEquals($compareSubsetSql, $unionSql);
133 
134  //Make sure the sql runs properly.
135  $dataProvider = new RedBeanModelsDataProvider('anId', null, false, $modelClassNamesAndSearchAttributeData);
136  $data = $dataProvider->getData();
137  //Test results are correct
138  $this->assertEquals(3, count($data));
139  $this->assertEquals('I', get_class($data[0]));
140  $this->assertEquals('J', get_class($data[1]));
141  $this->assertEquals('K', get_class($data[2]));
142  }
143 
148  {
150  $iFakePost = array();
151  $iMetadataAdapter = new SearchDataProviderMetadataAdapter(new I(false), 1, $iFakePost);
152  $jFakePost = array();
153  $jMetadataAdapter = new SearchDataProviderMetadataAdapter(new J(false), 1, $jFakePost);
154  $kFakePost = array();
155  $kMetadataAdapter = new SearchDataProviderMetadataAdapter(new K(false), 1, $kFakePost);
156  $modelClassNamesAndSearchAttributeData = array(
157  array('I' => $iMetadataAdapter->getAdaptedMetadata()),
158  array('J' => $jMetadataAdapter->getAdaptedMetadata()),
159  array('K' => $kMetadataAdapter->getAdaptedMetadata()),
160  );
161  $modelClassNamesAndSortAttributes = array(
162  'I' => 'name',
163  'J' => 'name',
164  'K' => 'name',
165  );
166  $unionSql = RedBeanModelsDataProvider::makeUnionSql($modelClassNamesAndSearchAttributeData,
167  $modelClassNamesAndSortAttributes, true, 2, 7);
168  $compareSubsetSql = "(";
169  $compareSubsetSql .= "select {$quote}i{$quote}.{$quote}id{$quote} id";
170  $compareSubsetSql .= ", 'I' modelClassName, {$quote}h{$quote}.{$quote}name{$quote} orderByColumn ";
171  $compareSubsetSql .= "from ({$quote}i{$quote}, {$quote}h{$quote}) ";
172  $compareSubsetSql .= " where {$quote}h{$quote}.{$quote}id{$quote} = {$quote}i{$quote}.{$quote}h_id{$quote}";
173  $compareSubsetSql .= ") ";
174  $compareSubsetSql .= "UNION (";
175  $compareSubsetSql .= "select {$quote}j{$quote}.{$quote}id{$quote} id";
176  $compareSubsetSql .= ", 'J' modelClassName, {$quote}h{$quote}.{$quote}name{$quote} orderByColumn ";
177  $compareSubsetSql .= "from ({$quote}j{$quote}, {$quote}h{$quote}) ";
178  $compareSubsetSql .= " where {$quote}h{$quote}.{$quote}id{$quote} = {$quote}j{$quote}.{$quote}h_id{$quote}";
179  $compareSubsetSql .= ") ";
180  $compareSubsetSql .= "UNION (";
181  $compareSubsetSql .= "select {$quote}k{$quote}.{$quote}id{$quote} id";
182  $compareSubsetSql .= ", 'K' modelClassName, {$quote}h{$quote}.{$quote}name{$quote} orderByColumn ";
183  $compareSubsetSql .= "from ({$quote}k{$quote}, {$quote}h{$quote}) ";
184  $compareSubsetSql .= " where {$quote}h{$quote}.{$quote}id{$quote} = {$quote}k{$quote}.{$quote}h_id{$quote}";
185  $compareSubsetSql .= ") ";
186  $compareSubsetSql .= "order by orderByColumn desc ";
187  $compareSubsetSql .= 'limit 7 offset 2';
188  $this->assertEquals($compareSubsetSql, $unionSql);
189 
190  //Make sure the sql runs properly.
191  $dataProvider = new RedBeanModelsDataProvider('anId', $modelClassNamesAndSortAttributes, true,
192  $modelClassNamesAndSearchAttributeData);
193  $data = $dataProvider->getData();
194  //Test results are correct
195  $this->assertEquals(9, count($data));
196  $this->assertEquals('xString1', $data[0]->kMember);
197  $this->assertEquals('yString1', $data[1]->kMember);
198  $this->assertEquals('kString1', $data[2]->kMember);
199  $this->assertEquals('yString1', $data[3]->iMember);
200  $this->assertEquals('xString1', $data[4]->iMember);
201  $this->assertEquals('iString1', $data[5]->iMember);
202  $this->assertEquals('yString1', $data[6]->jMember);
203  $this->assertEquals('xString1', $data[7]->jMember);
204  $this->assertEquals('jString1', $data[8]->jMember);
205  }
206 
211  {
213  $iFakePost = array();
214  $iMetadataAdapter = new SearchDataProviderMetadataAdapter(new I(false), 1, $iFakePost);
215  $jFakePost = array();
216  $jMetadataAdapter = new SearchDataProviderMetadataAdapter(new J(false), 1, $jFakePost);
217  $kFakePost = array();
218  $kMetadataAdapter = new SearchDataProviderMetadataAdapter(new K(false), 1, $kFakePost);
219  $modelClassNamesAndSearchAttributeData = array(
220  array('I' => $iMetadataAdapter->getAdaptedMetadata()),
221  array('J' => $jMetadataAdapter->getAdaptedMetadata()),
222  array('K' => $kMetadataAdapter->getAdaptedMetadata()),
223  );
224  $modelClassNamesAndSortAttributes = array(
225  'I' => 'name',
226  'J' => 'jMember',
227  'K' => 'kMember',
228  );
229  $unionSql = RedBeanModelsDataProvider::makeUnionSql($modelClassNamesAndSearchAttributeData,
230  $modelClassNamesAndSortAttributes, true, 2, 7);
231  $compareSubsetSql = "(";
232  $compareSubsetSql .= "select {$quote}i{$quote}.{$quote}id{$quote} id";
233  $compareSubsetSql .= ", 'I' modelClassName, {$quote}h{$quote}.{$quote}name{$quote} orderByColumn ";
234  $compareSubsetSql .= "from ({$quote}i{$quote}, {$quote}h{$quote}) ";
235  $compareSubsetSql .= " where {$quote}h{$quote}.{$quote}id{$quote} = {$quote}i{$quote}.{$quote}h_id{$quote}";
236  $compareSubsetSql .= ") ";
237  $compareSubsetSql .= "UNION (";
238  $compareSubsetSql .= "select {$quote}j{$quote}.{$quote}id{$quote} id";
239  $compareSubsetSql .= ", 'J' modelClassName, {$quote}j{$quote}.{$quote}jmember{$quote} orderByColumn ";
240  $compareSubsetSql .= "from {$quote}j{$quote} ";
241  $compareSubsetSql .= ") ";
242  $compareSubsetSql .= "UNION (";
243  $compareSubsetSql .= "select {$quote}k{$quote}.{$quote}id{$quote} id";
244  $compareSubsetSql .= ", 'K' modelClassName, {$quote}k{$quote}.{$quote}kmember{$quote} orderByColumn ";
245  $compareSubsetSql .= "from {$quote}k{$quote} ";
246  $compareSubsetSql .= ") ";
247  $compareSubsetSql .= "order by orderByColumn desc ";
248  $compareSubsetSql .= 'limit 7 offset 2';
249  $this->assertEquals($compareSubsetSql, $unionSql);
250 
251  //Make sure the sql runs properly.
252  $dataProvider = new RedBeanModelsDataProvider('anId', $modelClassNamesAndSortAttributes, true,
253  $modelClassNamesAndSearchAttributeData);
254  $data = $dataProvider->getData();
255  //Test results are correct
256  $this->assertEquals(9, count($data));
257  }
258 
263  {
265  $searchAttributeDataForJ['clauses'][1] = array(
266  'attributeName' => 'jMember',
267  'operatorType' => 'oneOf',
268  'value' => array('a', 'b', 'c')
269  );
270  $searchAttributeDataForJ['structure'] = '1';
271  $searchAttributeDataForI['clauses'][1] = array(
272  'attributeName' => 'ks',
273  'relatedAttributeName' => 'kMember',
274  'operatorType' => 'oneOf',
275  'value' => array('d', "e'd", 'f')
276  );
277  $searchAttributeDataForI['structure'] = '1';
278  $modelClassNamesAndSearchAttributeData = array(
279  array('I' => $searchAttributeDataForI),
280  array('J' => $searchAttributeDataForJ),
281  );
282  $modelClassNamesAndSortAttributes = array(
283  'I' => 'name',
284  'J' => 'jMember',
285  );
286  $unionSql = RedBeanModelsDataProvider::makeUnionSql($modelClassNamesAndSearchAttributeData,
287  $modelClassNamesAndSortAttributes, true, 2, 7);
288  $compareSubsetSql = "(";
289  $compareSubsetSql .= "select distinct {$quote}i{$quote}.{$quote}id{$quote} id";
290  $compareSubsetSql .= ", 'I' modelClassName, {$quote}h{$quote}.{$quote}name{$quote} orderByColumn ";
291  $compareSubsetSql .= "from ({$quote}i{$quote}, {$quote}h{$quote}) ";
292  $compareSubsetSql .= "left join {$quote}k{$quote} on {$quote}k{$quote}.{$quote}i_id{$quote} = ";
293  $compareSubsetSql .= "{$quote}i{$quote}.{$quote}id{$quote} ";
294  $compareSubsetSql .= "where ({$quote}k{$quote}.{$quote}kmember{$quote} IN('d','e\'d','f'))"; // Not Coding Standard
295  $compareSubsetSql .= " and {$quote}h{$quote}.{$quote}id{$quote} = {$quote}i{$quote}.{$quote}h_id{$quote}";
296  $compareSubsetSql .= ") ";
297  $compareSubsetSql .= "UNION (";
298  $compareSubsetSql .= "select {$quote}j{$quote}.{$quote}id{$quote} id";
299  $compareSubsetSql .= ", 'J' modelClassName, {$quote}j{$quote}.{$quote}jmember{$quote} orderByColumn ";
300  $compareSubsetSql .= "from {$quote}j{$quote} ";
301  $compareSubsetSql .= "where ({$quote}j{$quote}.{$quote}jmember{$quote} IN('a','b','c'))"; // Not Coding Standard
302  $compareSubsetSql .= ") ";
303  $compareSubsetSql .= "order by orderByColumn desc ";
304  $compareSubsetSql .= 'limit 7 offset 2';
305  $this->assertEquals($compareSubsetSql, $unionSql);
306 
307  //Make sure the sql runs properly.
308  $dataProvider = new RedBeanModelsDataProvider('anId', $modelClassNamesAndSortAttributes, true,
309  $modelClassNamesAndSearchAttributeData);
310  $data = $dataProvider->getData();
311  }
312 
317  {
318  }
319  }
320 ?>
Definition: I.php:37
Definition: K.php:37
Definition: J.php:37
static makeUnionSql(array $modelClassNamesAndSearchAttributeData, array $modelClassNamesAndSortAttributes=null, $sortDescending=false, $offset=null, $limit=null)
Generated on Wed Jul 15 2020 07:10:31
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.