Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
ModelDataProviderUtilRecursiveDataTest.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  ********************************************************************************/
65  {
66  public static function setUpBeforeClass()
67  {
68  parent::setUpBeforeClass();
69  SecurityTestHelper::createSuperAdmin();
70  }
71 
72  public static function getDependentTestModelClassNames()
73  {
74  return array('AAA', 'BBB', 'CCC', 'DDD', 'EEE', 'FFF', 'GGG', 'HHH');
75  }
76 
80  public function testHasOneToHasOneToHasOne()
81  {
83  $searchAttributeData = array();
84  $searchAttributeData['clauses'] = array(
85  1 => array(
86  'attributeName' => 'bbb',
87  'relatedModelData' => array(
88  'attributeName' => 'ccc',
89  'relatedModelData' => array(
90  'attributeName' => 'eee',
91  'relatedModelData' => array(
92  'attributeName' => 'eeeMember',
93  'operatorType' => 'equals',
94  'value' => 'somevalue',
95  ),
96  ),
97  ),
98  ),
99  );
100  $searchAttributeData['structure'] = '1';
101  //Build the query 'where' and 'joins'. Confirm they are as expected
102  $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('AAA');
103  $where = ModelDataProviderUtil::makeWhere('AAA', $searchAttributeData, $joinTablesAdapter);
104  $compareWhere = "({$quote}eee{$quote}.{$quote}eeemember{$quote} = 'somevalue')";
105  $this->assertEquals($compareWhere, $where);
106  $this->assertEquals(0, $joinTablesAdapter->getFromTableJoinCount());
107  $this->assertEquals(3, $joinTablesAdapter->getLeftTableJoinCount());
108  $leftTables = $joinTablesAdapter->getLeftTablesAndAliases();
109  $this->assertEquals('bbb', $leftTables[0]['tableName']);
110  $this->assertEquals('ccc', $leftTables[1]['tableName']);
111  $this->assertEquals('eee', $leftTables[2]['tableName']);
112  //Only stringing hasOne relations together so it makes sense not to need distinct
113  $this->assertFalse($joinTablesAdapter->getSelectDistinct());
114 
115  //Now test that the subsetSQL query produced is correct.
116  $subsetSql = AAA::makeSubsetOrCountSqlQuery('aaa', $joinTablesAdapter, 1, 5, $where,
117  null, false, $joinTablesAdapter->getSelectDistinct());
118  $compareSubsetSql = "select {$quote}aaa{$quote}.{$quote}id{$quote} id ";
119  $compareSubsetSql .= "from {$quote}aaa{$quote} ";
120  $compareSubsetSql .= "left join {$quote}bbb{$quote} on ";
121  $compareSubsetSql .= "{$quote}bbb{$quote}.{$quote}id{$quote} = {$quote}aaa{$quote}.{$quote}bbb_id{$quote} ";
122  $compareSubsetSql .= "left join {$quote}ccc{$quote} on ";
123  $compareSubsetSql .= "{$quote}ccc{$quote}.{$quote}id{$quote} = {$quote}bbb{$quote}.{$quote}ccc_id{$quote} ";
124  $compareSubsetSql .= "left join {$quote}eee{$quote} on ";
125  $compareSubsetSql .= "{$quote}eee{$quote}.{$quote}id{$quote} = {$quote}ccc{$quote}.{$quote}eee_id{$quote} ";
126  $compareSubsetSql .= "where " . $compareWhere . ' ';
127  $compareSubsetSql .= 'limit 5 offset 1';
128  $this->assertEquals($compareSubsetSql, $subsetSql);
129  //Make sure the sql runs properly.
130  $data = AAA::getSubset($joinTablesAdapter, 0, 5, $where, null, null, $joinTablesAdapter->getSelectDistinct());
131  }
132 
139  {
141  $searchAttributeData = array();
142  $searchAttributeData['clauses'] = array(
143  1 => array(
144  'attributeName' => 'bbb',
145  'relatedModelData' => array(
146  'attributeName' => 'ccc',
147  'relatedModelData' => array(
148  'attributeName' => 'eee',
149  'relatedAttributeName' => 'eeeMember',
150  'operatorType' => 'equals',
151  'value' => 'somevalue',
152  ),
153  ),
154  ),
155  );
156  $searchAttributeData['structure'] = '1';
157  //Build the query 'where' and 'joins'. Confirm they are as expected
158  $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('AAA');
159  $where = ModelDataProviderUtil::makeWhere('AAA', $searchAttributeData, $joinTablesAdapter);
160  $compareWhere = "({$quote}eee{$quote}.{$quote}eeemember{$quote} = 'somevalue')";
161  $this->assertEquals($compareWhere, $where);
162  $this->assertEquals(0, $joinTablesAdapter->getFromTableJoinCount());
163  $this->assertEquals(3, $joinTablesAdapter->getLeftTableJoinCount());
164  $leftTables = $joinTablesAdapter->getLeftTablesAndAliases();
165  $this->assertEquals('bbb', $leftTables[0]['tableName']);
166  $this->assertEquals('ccc', $leftTables[1]['tableName']);
167  $this->assertEquals('eee', $leftTables[2]['tableName']);
168  //Only stringing hasOne relations together so it makes sense not to need distinct
169  $this->assertFalse($joinTablesAdapter->getSelectDistinct());
170 
171  //Now test that the subsetSQL query produced is correct.
172  $subsetSql = AAA::makeSubsetOrCountSqlQuery('aaa', $joinTablesAdapter, 1, 5, $where,
173  null, false, $joinTablesAdapter->getSelectDistinct());
174  $compareSubsetSql = "select {$quote}aaa{$quote}.{$quote}id{$quote} id ";
175  $compareSubsetSql .= "from {$quote}aaa{$quote} ";
176  $compareSubsetSql .= "left join {$quote}bbb{$quote} on ";
177  $compareSubsetSql .= "{$quote}bbb{$quote}.{$quote}id{$quote} = {$quote}aaa{$quote}.{$quote}bbb_id{$quote} ";
178  $compareSubsetSql .= "left join {$quote}ccc{$quote} on ";
179  $compareSubsetSql .= "{$quote}ccc{$quote}.{$quote}id{$quote} = {$quote}bbb{$quote}.{$quote}ccc_id{$quote} ";
180  $compareSubsetSql .= "left join {$quote}eee{$quote} on ";
181  $compareSubsetSql .= "{$quote}eee{$quote}.{$quote}id{$quote} = {$quote}ccc{$quote}.{$quote}eee_id{$quote} ";
182  $compareSubsetSql .= "where " . $compareWhere . ' ';
183  $compareSubsetSql .= 'limit 5 offset 1';
184  $this->assertEquals($compareSubsetSql, $subsetSql);
185  //Make sure the sql runs properly.
186  $data = AAA::getSubset($joinTablesAdapter, 0, 5, $where, null, null, $joinTablesAdapter->getSelectDistinct());
187  }
188 
193  public function testHasOneToHasManyToHasOne()
194  {
196  $searchAttributeData = array();
197  $searchAttributeData['clauses'] = array(
198  1 => array(
199  'attributeName' => 'bbb',
200  'relatedModelData' => array(
201  'attributeName' => 'fff',
202  'relatedModelData' => array(
203  'attributeName' => 'eee',
204  'relatedModelData' => array(
205  'attributeName' => 'eeeMember',
206  'operatorType' => 'equals',
207  'value' => 'somevalue',
208  ),
209  ),
210  ),
211  ),
212  );
213  //Build the query 'where' and 'joins'. Confirm they are as expected
214  $searchAttributeData['structure'] = '1';
215  //Build the query 'where' and 'joins'. Confirm they are as expected
216  $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('AAA');
217  $where = ModelDataProviderUtil::makeWhere('AAA', $searchAttributeData, $joinTablesAdapter);
218  $compareWhere = "({$quote}eee{$quote}.{$quote}eeemember{$quote} = 'somevalue')";
219  $this->assertEquals($compareWhere, $where);
220  $this->assertEquals(0, $joinTablesAdapter->getFromTableJoinCount());
221  $this->assertEquals(3, $joinTablesAdapter->getLeftTableJoinCount());
222  $leftTables = $joinTablesAdapter->getLeftTablesAndAliases();
223  $this->assertEquals('bbb', $leftTables[0]['tableName']);
224  $this->assertEquals('fff', $leftTables[1]['tableName']);
225  $this->assertEquals('eee', $leftTables[2]['tableName']);
226  //Stringing together some hasMany relations, so we need to select distinct.
227  $this->assertTrue($joinTablesAdapter->getSelectDistinct());
228 
229  //Now test that the subsetSQL query produced is correct.
230  $subsetSql = AAA::makeSubsetOrCountSqlQuery('aaa', $joinTablesAdapter, 1, 5, $where,
231  null, false, $joinTablesAdapter->getSelectDistinct());
232  $compareSubsetSql = "select distinct {$quote}aaa{$quote}.{$quote}id{$quote} id ";
233  $compareSubsetSql .= "from {$quote}aaa{$quote} ";
234  $compareSubsetSql .= "left join {$quote}bbb{$quote} on ";
235  $compareSubsetSql .= "{$quote}bbb{$quote}.{$quote}id{$quote} = {$quote}aaa{$quote}.{$quote}bbb_id{$quote} ";
236  $compareSubsetSql .= "left join {$quote}fff{$quote} on ";
237  $compareSubsetSql .= "{$quote}fff{$quote}.{$quote}bbb_id{$quote} = {$quote}bbb{$quote}.{$quote}id{$quote} ";
238  $compareSubsetSql .= "left join {$quote}eee{$quote} on ";
239  $compareSubsetSql .= "{$quote}eee{$quote}.{$quote}id{$quote} = {$quote}fff{$quote}.{$quote}eee_id{$quote} ";
240  $compareSubsetSql .= "where " . $compareWhere . ' ';
241  $compareSubsetSql .= 'limit 5 offset 1';
242  $this->assertEquals($compareSubsetSql, $subsetSql);
243  //Make sure the sql runs properly.
244  $data = AAA::getSubset($joinTablesAdapter, 0, 5, $where, null, null, $joinTablesAdapter->getSelectDistinct());
245  }
246 
252  {
254  $searchAttributeData = array();
255  $searchAttributeData['clauses'] = array(
256  1 => array(
257  'attributeName' => 'bbb',
258  'relatedModelData' => array(
259  'attributeName' => 'ddd',
260  'relatedModelData' => array(
261  'attributeName' => 'eee',
262  'relatedModelData' => array(
263  'attributeName' => 'eeeMember',
264  'operatorType' => 'equals',
265  'value' => 'somevalue',
266  ),
267  ),
268  ),
269  ),
270  );
271  //Build the query 'where' and 'joins'. Confirm they are as expected
272  $searchAttributeData['structure'] = '1';
273  //Build the query 'where' and 'joins'. Confirm they are as expected
274  $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('CCC');
275  $where = ModelDataProviderUtil::makeWhere('CCC', $searchAttributeData, $joinTablesAdapter);
276  $compareWhere = "({$quote}eee{$quote}.{$quote}eeemember{$quote} = 'somevalue')";
277  $this->assertEquals($compareWhere, $where);
278  $this->assertEquals(0, $joinTablesAdapter->getFromTableJoinCount());
279  $this->assertEquals(4, $joinTablesAdapter->getLeftTableJoinCount());
280  $leftTables = $joinTablesAdapter->getLeftTablesAndAliases();
281  $this->assertEquals('bbb', $leftTables[0]['tableName']);
282  $this->assertEquals('bbb_ddd', $leftTables[1]['tableName']);
283  $this->assertEquals('ddd', $leftTables[2]['tableName']);
284  $this->assertEquals('eee', $leftTables[3]['tableName']);
285  //Stringing together some hasMany relations, so we need to select distinct.
286  $this->assertTrue($joinTablesAdapter->getSelectDistinct());
287 
288  //Now test that the subsetSQL query produced is correct.
289  $subsetSql = CCC::makeSubsetOrCountSqlQuery('ccc', $joinTablesAdapter, 1, 5, $where,
290  null, false, $joinTablesAdapter->getSelectDistinct());
291  $compareSubsetSql = "select distinct {$quote}ccc{$quote}.{$quote}id{$quote} id ";
292  $compareSubsetSql .= "from {$quote}ccc{$quote} ";
293  $compareSubsetSql .= "left join {$quote}bbb{$quote} on ";
294  $compareSubsetSql .= "{$quote}bbb{$quote}.{$quote}ccc_id{$quote} = {$quote}ccc{$quote}.{$quote}id{$quote} ";
295  $compareSubsetSql .= "left join {$quote}bbb_ddd{$quote} on ";
296  $compareSubsetSql .= "{$quote}bbb_ddd{$quote}.{$quote}bbb_id{$quote} = {$quote}bbb{$quote}.{$quote}id{$quote} ";
297  $compareSubsetSql .= "left join {$quote}ddd{$quote} on ";
298  $compareSubsetSql .= "{$quote}ddd{$quote}.{$quote}id{$quote} = {$quote}bbb_ddd{$quote}.{$quote}ddd_id{$quote} ";
299  $compareSubsetSql .= "left join {$quote}eee{$quote} on ";
300  $compareSubsetSql .= "{$quote}eee{$quote}.{$quote}id{$quote} = {$quote}ddd{$quote}.{$quote}eee_id{$quote} ";
301  $compareSubsetSql .= "where " . $compareWhere . ' ';
302  $compareSubsetSql .= 'limit 5 offset 1';
303  $this->assertEquals($compareSubsetSql, $subsetSql);
304  //Make sure the sql runs properly.
305  $data = CCC::getSubset($joinTablesAdapter, 0, 5, $where, null, null, $joinTablesAdapter->getSelectDistinct());
306  }
307 
312  public function testHasManyToHasOneToHasOne()
313  {
315  $searchAttributeData = array();
316  $searchAttributeData['clauses'] = array(
317  1 => array(
318  'attributeName' => 'bbb',
319  'relatedModelData' => array(
320  'attributeName' => 'ggg',
321  'relatedModelData' => array(
322  'attributeName' => 'eee',
323  'relatedModelData' => array(
324  'attributeName' => 'eeeMember',
325  'operatorType' => 'equals',
326  'value' => 'somevalue',
327  ),
328  ),
329  ),
330  ),
331  );
332  //Build the query 'where' and 'joins'. Confirm they are as expected
333  $searchAttributeData['structure'] = '1';
334  //Build the query 'where' and 'joins'. Confirm they are as expected
335  $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('CCC');
336  $where = ModelDataProviderUtil::makeWhere('CCC', $searchAttributeData, $joinTablesAdapter);
337  $compareWhere = "({$quote}eee{$quote}.{$quote}eeemember{$quote} = 'somevalue')";
338  $this->assertEquals($compareWhere, $where);
339  $this->assertEquals(0, $joinTablesAdapter->getFromTableJoinCount());
340  $this->assertEquals(3, $joinTablesAdapter->getLeftTableJoinCount());
341  $leftTables = $joinTablesAdapter->getLeftTablesAndAliases();
342  $this->assertEquals('bbb', $leftTables[0]['tableName']);
343  $this->assertEquals('ggg', $leftTables[1]['tableName']);
344  $this->assertEquals('eee', $leftTables[2]['tableName']);
345  //Stringing together some hasMany relations, so we need to select distinct.
346  $this->assertTrue($joinTablesAdapter->getSelectDistinct());
347 
348  //Now test that the subsetSQL query produced is correct.
349  $subsetSql = CCC::makeSubsetOrCountSqlQuery('ccc', $joinTablesAdapter, 1, 5, $where,
350  null, false, $joinTablesAdapter->getSelectDistinct());
351  $compareSubsetSql = "select distinct {$quote}ccc{$quote}.{$quote}id{$quote} id ";
352  $compareSubsetSql .= "from {$quote}ccc{$quote} ";
353  $compareSubsetSql .= "left join {$quote}bbb{$quote} on ";
354  $compareSubsetSql .= "{$quote}bbb{$quote}.{$quote}ccc_id{$quote} = {$quote}ccc{$quote}.{$quote}id{$quote} ";
355  $compareSubsetSql .= "left join {$quote}ggg{$quote} on ";
356  $compareSubsetSql .= "{$quote}ggg{$quote}.{$quote}id{$quote} = {$quote}bbb{$quote}.{$quote}ggg_id{$quote} ";
357  $compareSubsetSql .= "left join {$quote}eee{$quote} on ";
358  $compareSubsetSql .= "{$quote}eee{$quote}.{$quote}id{$quote} = {$quote}ggg{$quote}.{$quote}eee_id{$quote} ";
359  $compareSubsetSql .= "where " . $compareWhere . ' ';
360  $compareSubsetSql .= 'limit 5 offset 1';
361  $this->assertEquals($compareSubsetSql, $subsetSql);
362  //Make sure the sql runs properly.
363  $data = CCC::getSubset($joinTablesAdapter, 0, 5, $where, null, null, $joinTablesAdapter->getSelectDistinct());
364  }
365 
371  {
373  $searchAttributeData = array();
374  $searchAttributeData['clauses'] = array(
375  1 => array(
376  'attributeName' => 'bbb',
377  'relatedModelData' => array(
378  'attributeName' => 'fff',
379  'relatedModelData' => array(
380  'attributeName' => 'eee',
381  'relatedModelData' => array(
382  'attributeName' => 'eeeMember',
383  'operatorType' => 'equals',
384  'value' => 'somevalue',
385  ),
386  ),
387  ),
388  ),
389  );
390  //Build the query 'where' and 'joins'. Confirm they are as expected
391  $searchAttributeData['structure'] = '1';
392  //Build the query 'where' and 'joins'. Confirm they are as expected
393  $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('DDD');
394  $where = ModelDataProviderUtil::makeWhere('DDD', $searchAttributeData, $joinTablesAdapter);
395  $compareWhere = "({$quote}eee{$quote}.{$quote}eeemember{$quote} = 'somevalue')";
396  $this->assertEquals($compareWhere, $where);
397  $this->assertEquals(0, $joinTablesAdapter->getFromTableJoinCount());
398  $this->assertEquals(4, $joinTablesAdapter->getLeftTableJoinCount());
399  $leftTables = $joinTablesAdapter->getLeftTablesAndAliases();
400  $this->assertEquals('bbb_ddd', $leftTables[0]['tableName']);
401  $this->assertEquals('bbb', $leftTables[1]['tableName']);
402  $this->assertEquals('fff', $leftTables[2]['tableName']);
403  $this->assertEquals('eee', $leftTables[3]['tableName']);
404  //Stringing together some hasMany relations, so we need to select distinct.
405  $this->assertTrue($joinTablesAdapter->getSelectDistinct());
406 
407  //Now test that the subsetSQL query produced is correct.
408  $subsetSql = CCC::makeSubsetOrCountSqlQuery('ddd', $joinTablesAdapter, 1, 5, $where,
409  null, false, $joinTablesAdapter->getSelectDistinct());
410  $compareSubsetSql = "select distinct {$quote}ddd{$quote}.{$quote}id{$quote} id ";
411  $compareSubsetSql .= "from {$quote}ddd{$quote} ";
412  $compareSubsetSql .= "left join {$quote}bbb_ddd{$quote} on ";
413  $compareSubsetSql .= "{$quote}bbb_ddd{$quote}.{$quote}ddd_id{$quote} = {$quote}ddd{$quote}.{$quote}id{$quote} ";
414  $compareSubsetSql .= "left join {$quote}bbb{$quote} on ";
415  $compareSubsetSql .= "{$quote}bbb{$quote}.{$quote}id{$quote} = {$quote}bbb_ddd{$quote}.{$quote}bbb_id{$quote} ";
416  $compareSubsetSql .= "left join {$quote}fff{$quote} on ";
417  $compareSubsetSql .= "{$quote}fff{$quote}.{$quote}bbb_id{$quote} = {$quote}bbb{$quote}.{$quote}id{$quote} ";
418  $compareSubsetSql .= "left join {$quote}eee{$quote} on ";
419  $compareSubsetSql .= "{$quote}eee{$quote}.{$quote}id{$quote} = {$quote}fff{$quote}.{$quote}eee_id{$quote} ";
420  $compareSubsetSql .= "where " . $compareWhere . ' ';
421  $compareSubsetSql .= 'limit 5 offset 1';
422  $this->assertEquals($compareSubsetSql, $subsetSql);
423  //Make sure the sql runs properly.
424  $data = DDD::getSubset($joinTablesAdapter, 0, 5, $where, null, null, $joinTablesAdapter->getSelectDistinct());
425  }
426 
432  {
434  $searchAttributeData = array();
435  $searchAttributeData['clauses'] = array(
436  1 => array(
437  'attributeName' => 'bbb',
438  'relatedModelData' => array(
439  'attributeName' => 'ggg',
440  'relatedModelData' => array(
441  'attributeName' => 'eee',
442  'relatedModelData' => array(
443  'attributeName' => 'eeeMember',
444  'operatorType' => 'equals',
445  'value' => 'somevalue',
446  ),
447  ),
448  ),
449  ),
450  );
451  //Build the query 'where' and 'joins'. Confirm they are as expected
452  $searchAttributeData['structure'] = '1';
453  //Build the query 'where' and 'joins'. Confirm they are as expected
454  $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('DDD');
455  $where = ModelDataProviderUtil::makeWhere('DDD', $searchAttributeData, $joinTablesAdapter);
456  $compareWhere = "({$quote}eee{$quote}.{$quote}eeemember{$quote} = 'somevalue')";
457  $this->assertEquals($compareWhere, $where);
458  $this->assertEquals(0, $joinTablesAdapter->getFromTableJoinCount());
459  $this->assertEquals(4, $joinTablesAdapter->getLeftTableJoinCount());
460  $leftTables = $joinTablesAdapter->getLeftTablesAndAliases();
461  $this->assertEquals('bbb_ddd', $leftTables[0]['tableName']);
462  $this->assertEquals('bbb', $leftTables[1]['tableName']);
463  $this->assertEquals('ggg', $leftTables[2]['tableName']);
464  $this->assertEquals('eee', $leftTables[3]['tableName']);
465  //Stringing together some hasMany relations, so we need to select distinct.
466  $this->assertTrue($joinTablesAdapter->getSelectDistinct());
467 
468  //Now test that the subsetSQL query produced is correct.
469  $subsetSql = CCC::makeSubsetOrCountSqlQuery('ddd', $joinTablesAdapter, 1, 5, $where,
470  null, false, $joinTablesAdapter->getSelectDistinct());
471  $compareSubsetSql = "select distinct {$quote}ddd{$quote}.{$quote}id{$quote} id ";
472  $compareSubsetSql .= "from {$quote}ddd{$quote} ";
473  $compareSubsetSql .= "left join {$quote}bbb_ddd{$quote} on ";
474  $compareSubsetSql .= "{$quote}bbb_ddd{$quote}.{$quote}ddd_id{$quote} = {$quote}ddd{$quote}.{$quote}id{$quote} ";
475  $compareSubsetSql .= "left join {$quote}bbb{$quote} on ";
476  $compareSubsetSql .= "{$quote}bbb{$quote}.{$quote}id{$quote} = {$quote}bbb_ddd{$quote}.{$quote}bbb_id{$quote} ";
477  $compareSubsetSql .= "left join {$quote}ggg{$quote} on ";
478  $compareSubsetSql .= "{$quote}ggg{$quote}.{$quote}id{$quote} = {$quote}bbb{$quote}.{$quote}ggg_id{$quote} ";
479  $compareSubsetSql .= "left join {$quote}eee{$quote} on ";
480  $compareSubsetSql .= "{$quote}eee{$quote}.{$quote}id{$quote} = {$quote}ggg{$quote}.{$quote}eee_id{$quote} ";
481  $compareSubsetSql .= "where " . $compareWhere . ' ';
482  $compareSubsetSql .= 'limit 5 offset 1';
483  $this->assertEquals($compareSubsetSql, $subsetSql);
484  //Make sure the sql runs properly.
485  $data = DDD::getSubset($joinTablesAdapter, 0, 5, $where, null, null, $joinTablesAdapter->getSelectDistinct());
486  }
487 
493  {
495  $searchAttributeData = array();
496  $searchAttributeData['clauses'] = array(
497  1 => array(
498  'attributeName' => 'bbb',
499  'relatedModelData' => array(
500  'attributeName' => 'ggg',
501  'relatedModelData' => array(
502  'attributeName' => 'eee',
503  'relatedModelData' => array(
504  'attributeName' => 'eeeMember',
505  'operatorType' => 'equals',
506  'value' => 'somevalue',
507  ),
508  ),
509  ),
510  ),
511  2 => array(
512  'attributeName' => 'bbb',
513  'relatedModelData' => array(
514  'attributeName' => 'ggg',
515  'relatedModelData' => array(
516  'attributeName' => 'eee',
517  'relatedModelData' => array(
518  'attributeName' => 'eeeMember2',
519  'operatorType' => 'equals',
520  'value' => 'somevalue',
521  ),
522  ),
523  ),
524  )
525  );
526  //Build the query 'where' and 'joins'. Confirm they are as expected
527  $searchAttributeData['structure'] = '1 and 2';
528  //Build the query 'where' and 'joins'. Confirm they are as expected
529  $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('DDD');
530  $where = ModelDataProviderUtil::makeWhere('DDD', $searchAttributeData, $joinTablesAdapter);
531  $compareWhere = "({$quote}eee{$quote}.{$quote}eeemember{$quote} = 'somevalue') and ";
532  $compareWhere .= "({$quote}eee{$quote}.{$quote}eeemember2{$quote} = 'somevalue')";
533  $this->assertEquals($compareWhere, $where);
534  $this->assertEquals(0, $joinTablesAdapter->getFromTableJoinCount());
535  $this->assertEquals(4, $joinTablesAdapter->getLeftTableJoinCount());
536  $leftTables = $joinTablesAdapter->getLeftTablesAndAliases();
537  $this->assertEquals('bbb_ddd', $leftTables[0]['tableName']);
538  $this->assertEquals('bbb', $leftTables[1]['tableName']);
539  $this->assertEquals('ggg', $leftTables[2]['tableName']);
540  $this->assertEquals('eee', $leftTables[3]['tableName']);
541  //Stringing together some hasMany relations, so we need to select distinct.
542  $this->assertTrue($joinTablesAdapter->getSelectDistinct());
543 
544  //Now test that the subsetSQL query produced is correct.
545  $subsetSql = CCC::makeSubsetOrCountSqlQuery('ddd', $joinTablesAdapter, 1, 5, $where,
546  null, false, $joinTablesAdapter->getSelectDistinct());
547  $compareSubsetSql = "select distinct {$quote}ddd{$quote}.{$quote}id{$quote} id ";
548  $compareSubsetSql .= "from {$quote}ddd{$quote} ";
549  $compareSubsetSql .= "left join {$quote}bbb_ddd{$quote} on ";
550  $compareSubsetSql .= "{$quote}bbb_ddd{$quote}.{$quote}ddd_id{$quote} = {$quote}ddd{$quote}.{$quote}id{$quote} ";
551  $compareSubsetSql .= "left join {$quote}bbb{$quote} on ";
552  $compareSubsetSql .= "{$quote}bbb{$quote}.{$quote}id{$quote} = {$quote}bbb_ddd{$quote}.{$quote}bbb_id{$quote} ";
553  $compareSubsetSql .= "left join {$quote}ggg{$quote} on ";
554  $compareSubsetSql .= "{$quote}ggg{$quote}.{$quote}id{$quote} = {$quote}bbb{$quote}.{$quote}ggg_id{$quote} ";
555  $compareSubsetSql .= "left join {$quote}eee{$quote} on ";
556  $compareSubsetSql .= "{$quote}eee{$quote}.{$quote}id{$quote} = {$quote}ggg{$quote}.{$quote}eee_id{$quote} ";
557  $compareSubsetSql .= "where " . $compareWhere . ' ';
558  $compareSubsetSql .= 'limit 5 offset 1';
559  $this->assertEquals($compareSubsetSql, $subsetSql);
560  //Make sure the sql runs properly.
561  $data = DDD::getSubset($joinTablesAdapter, 0, 5, $where, null, null, $joinTablesAdapter->getSelectDistinct());
562  }
563 
569  {
571  $searchAttributeData = array();
572  $searchAttributeData['clauses'] = array(
573  1 => array(
574  'attributeName' => 'aaa',
575  'relatedModelData' => array(
576  'attributeName' => 'bbb',
577  'relatedModelData' => array(
578  'attributeName' => 'ggg',
579  'relatedModelData' => array(
580  'attributeName' => 'gggMember',
581  'operatorType' => 'equals',
582  'value' => 'somevalue',
583  ),
584  ),
585  ),
586  ),
587  );
588  //Build the query 'where' and 'joins'. Confirm they are as expected
589  $searchAttributeData['structure'] = '1';
590  //Build the query 'where' and 'joins'. Confirm they are as expected
591  $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('HHH');
592  $where = ModelDataProviderUtil::makeWhere('HHH', $searchAttributeData, $joinTablesAdapter);
593  $compareWhere = "({$quote}ggg{$quote}.{$quote}gggmember{$quote} = 'somevalue')";
594  $this->assertEquals($compareWhere, $where);
595  $this->assertEquals(0, $joinTablesAdapter->getFromTableJoinCount());
596  $this->assertEquals(3, $joinTablesAdapter->getLeftTableJoinCount());
597  $leftTables = $joinTablesAdapter->getLeftTablesAndAliases();
598  $this->assertEquals('aaa', $leftTables[0]['tableName']);
599  $this->assertEquals('bbb', $leftTables[1]['tableName']);
600  $this->assertEquals('ggg', $leftTables[2]['tableName']);
601  //Stringing together some hasMany relations, so we need to select distinct.
602  $this->assertFalse($joinTablesAdapter->getSelectDistinct());
603 
604  //Now test that the subsetSQL query produced is correct.
605  $subsetSql = CCC::makeSubsetOrCountSqlQuery('hhh', $joinTablesAdapter, 1, 5, $where,
606  null, false, $joinTablesAdapter->getSelectDistinct());
607  $compareSubsetSql = "select {$quote}hhh{$quote}.{$quote}id{$quote} id ";
608  $compareSubsetSql .= "from {$quote}hhh{$quote} ";
609  $compareSubsetSql .= "left join {$quote}aaa{$quote} on ";
610  $compareSubsetSql .= "{$quote}aaa{$quote}.{$quote}hhh_id{$quote} = {$quote}hhh{$quote}.{$quote}id{$quote} ";
611  $compareSubsetSql .= "left join {$quote}bbb{$quote} on ";
612  $compareSubsetSql .= "{$quote}bbb{$quote}.{$quote}id{$quote} = {$quote}aaa{$quote}.{$quote}bbb_id{$quote} ";
613  $compareSubsetSql .= "left join {$quote}ggg{$quote} on ";
614  $compareSubsetSql .= "{$quote}ggg{$quote}.{$quote}id{$quote} = {$quote}bbb{$quote}.{$quote}ggg_id{$quote} ";
615  $compareSubsetSql .= "where " . $compareWhere . ' ';
616  $compareSubsetSql .= 'limit 5 offset 1';
617  $this->assertEquals($compareSubsetSql, $subsetSql);
618  //Make sure the sql runs properly.
619  $data = HHH::getSubset($joinTablesAdapter, 0, 5, $where, null, null, $joinTablesAdapter->getSelectDistinct());
620  }
621 
627  {
629  $searchAttributeData = array();
630  $searchAttributeData['clauses'] = array(
631  1 => array(
632  'attributeName' => 'aaa',
633  'relatedModelData' => array(
634  'attributeName' => 'bbb',
635  'relatedModelData' => array(
636  'attributeName' => 'ggg',
637  'relatedModelData' => array(
638  'attributeName' => 'gggMember',
639  'operatorType' => 'equals',
640  'value' => 'somevalue',
641  ),
642  ),
643  ),
644  ),
645  2 => array(
646  'attributeName' => 'aaa',
647  'relatedModelData' => array(
648  'attributeName' => 'bbb',
649  'relatedModelData' => array(
650  'attributeName' => 'ggg',
651  'relatedModelData' => array(
652  'attributeName' => 'gggMember2',
653  'operatorType' => 'equals',
654  'value' => 'somevalue',
655  ),
656  ),
657  ),
658  )
659  );
660  //Build the query 'where' and 'joins'. Confirm they are as expected
661  $searchAttributeData['structure'] = '1 and 2';
662  //Build the query 'where' and 'joins'. Confirm they are as expected
663  $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('HHH');
664  $where = ModelDataProviderUtil::makeWhere('HHH', $searchAttributeData, $joinTablesAdapter);
665  $compareWhere = "({$quote}ggg{$quote}.{$quote}gggmember{$quote} = 'somevalue') and ";
666  $compareWhere .= "({$quote}ggg{$quote}.{$quote}gggmember2{$quote} = 'somevalue')";
667  $this->assertEquals($compareWhere, $where);
668  $this->assertEquals(0, $joinTablesAdapter->getFromTableJoinCount());
669  $this->assertEquals(3, $joinTablesAdapter->getLeftTableJoinCount());
670  $leftTables = $joinTablesAdapter->getLeftTablesAndAliases();
671  $this->assertEquals('aaa', $leftTables[0]['tableName']);
672  $this->assertEquals('bbb', $leftTables[1]['tableName']);
673  $this->assertEquals('ggg', $leftTables[2]['tableName']);
674  //Stringing together some hasMany relations, so we need to select distinct.
675  $this->assertFalse($joinTablesAdapter->getSelectDistinct());
676 
677  //Now test that the subsetSQL query produced is correct.
678  $subsetSql = CCC::makeSubsetOrCountSqlQuery('hhh', $joinTablesAdapter, 1, 5, $where,
679  null, false, $joinTablesAdapter->getSelectDistinct());
680  $compareSubsetSql = "select {$quote}hhh{$quote}.{$quote}id{$quote} id ";
681  $compareSubsetSql .= "from {$quote}hhh{$quote} ";
682  $compareSubsetSql .= "left join {$quote}aaa{$quote} on ";
683  $compareSubsetSql .= "{$quote}aaa{$quote}.{$quote}hhh_id{$quote} = {$quote}hhh{$quote}.{$quote}id{$quote} ";
684  $compareSubsetSql .= "left join {$quote}bbb{$quote} on ";
685  $compareSubsetSql .= "{$quote}bbb{$quote}.{$quote}id{$quote} = {$quote}aaa{$quote}.{$quote}bbb_id{$quote} ";
686  $compareSubsetSql .= "left join {$quote}ggg{$quote} on ";
687  $compareSubsetSql .= "{$quote}ggg{$quote}.{$quote}id{$quote} = {$quote}bbb{$quote}.{$quote}ggg_id{$quote} ";
688  $compareSubsetSql .= "where " . $compareWhere . ' ';
689  $compareSubsetSql .= 'limit 5 offset 1';
690  $this->assertEquals($compareSubsetSql, $subsetSql);
691  //Make sure the sql runs properly.
692  $data = HHH::getSubset($joinTablesAdapter, 0, 5, $where, null, null, $joinTablesAdapter->getSelectDistinct());
693  }
694  }
695 ?>
static getSubset(RedBeanModelJoinTablesQueryAdapter $joinTablesAdapter=null, $offset=null, $count=null, $where=null, $orderBy=null, $modelClassName=null, $selectDistinct=false)
static makeSubsetOrCountSqlQuery($tableName, RedBeanModelJoinTablesQueryAdapter $joinTablesAdapter, $offset=null, $count=null, $where=null, $orderBy=null, $selectCount=false, $selectDistinct=false, array $quotedExtraSelectColumnNameAndAliases=array())
static makeWhere($modelClassName, array $metadata, $joinTablesAdapter, $onTableAliasName=null)
Generated on Sun Jul 5 2020 07:10:28
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.