Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
RedBeanModelMemberRulesToColumnAdapterTest.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  protected static $messageLogger;
40 
41  public static function setUpBeforeClass()
42  {
43  parent::setUpBeforeClass();
44  SecurityTestHelper::createSuperAdmin();
45  $super = User::getByUsername('super');
46  Yii::app()->user->userModel = $super;
47  static::$messageLogger = new MessageLogger();
48  }
49 
50  public function testResolveWithEmptyRules()
51  {
52  // using AuditEvent everywhere as it can't have bean, neither can its parent.
53  $modelClassName = 'AuditEvent';
54  $rules = array();
55  $column = RedBeanModelMemberRulesToColumnAdapter::resolve($modelClassName,
56  $rules,
57  static::$messageLogger);
58  $this->assertFalse($column);
59  }
60 
65  {
66  $modelClassName = 'AuditEvent';
67  $rules = array(
68  array('attributeName', 'required'),
69  );
70  $column = RedBeanModelMemberRulesToColumnAdapter::resolve($modelClassName,
71  $rules,
72  static::$messageLogger);
73  $this->assertFalse($column);
74  }
75 
80  {
81  $modelClassName = 'AuditEvent';
82  $rules = array(
83  array('attributeName', 'default', 'value' => 10),
84  );
85  $column = RedBeanModelMemberRulesToColumnAdapter::resolve($modelClassName,
86  $rules,
87  static::$messageLogger);
88  $this->assertFalse($column);
89  }
90 
95  {
96  $modelClassName = 'AuditEvent';
97  $rules = array(
98  array('attributeName', 'numerical'),
99  );
100  $column = RedBeanModelMemberRulesToColumnAdapter::resolve($modelClassName,
101  $rules,
102  static::$messageLogger);
103  $this->assertNotEmpty($column);
104  $this->assertArrayHasKey('name', $column);
105  $this->assertArrayHasKey('type', $column);
106  $this->assertArrayHasKey('unsigned', $column);
107  $this->assertArrayHasKey('notNull', $column);
108  $this->assertArrayHasKey('collation', $column);
109  $this->assertArrayHasKey('default', $column);
110  $this->assertEquals('attributename', $column['name']);
111  $this->assertEquals('INT(11)', $column['type']);
112  $this->assertNull($column['unsigned']);
113  $this->assertEquals('NULL', $column['notNull']); // Not Coding Standard
114  $this->assertNull($column['collation']);
115  $this->assertEquals('DEFAULT NULL', $column['default']); // Not Coding Standard
116  }
117 
122  {
123  $modelClassName = 'AuditEvent';
124  $rules = array(
125  array('attributeName', 'type', 'type' => 'string'),
126  );
127  $column = RedBeanModelMemberRulesToColumnAdapter::resolve($modelClassName,
128  $rules,
129  static::$messageLogger);
130  $this->assertNotEmpty($column);
131  $this->assertArrayHasKey('name', $column);
132  $this->assertArrayHasKey('type', $column);
133  $this->assertArrayHasKey('unsigned', $column);
134  $this->assertArrayHasKey('notNull', $column);
135  $this->assertArrayHasKey('collation', $column);
136  $this->assertArrayHasKey('default', $column);
137  $this->assertEquals('attributename', $column['name']);
138  $this->assertEquals('TEXT', $column['type']);
139  $this->assertNull($column['unsigned']);
140  $this->assertEquals('NULL', $column['notNull']); // Not Coding Standard
141  $this->assertEquals('COLLATE utf8_unicode_ci', $column['collation']);
142  $this->assertEquals('DEFAULT NULL', $column['default']); // Not Coding Standard
143  }
144 
149  {
150  $modelClassName = 'AuditEvent';
151  $rules = array(
152  array('attributeName', 'type', 'type' => 'dummy'),
153  );
154  $column = RedBeanModelMemberRulesToColumnAdapter::resolve($modelClassName,
155  $rules,
156  static::$messageLogger);
157  $this->assertFalse($column);
158  }
159 
164  {
165  $modelClassName = 'AuditEvent';
166  $rules = array(
167  array('attributeName', 'numerical', 'min' => 0, 'precision' => 3),
168  );
169  $column = RedBeanModelMemberRulesToColumnAdapter::resolve($modelClassName,
170  $rules,
171  static::$messageLogger);
172  $this->assertFalse($column);
173  }
174 
179  {
180  $unsigned = null;
182  if (!$assumedSigned)
183  {
184  $unsigned = 'UNSIGNED';
185  }
186  $modelClassName = 'AuditEvent';
187  $rules = array(
188  array('attributeName', 'type', 'type' => 'float'),
189  array('attributeName', 'numerical'),
190  );
191  $column = RedBeanModelMemberRulesToColumnAdapter::resolve($modelClassName,
192  $rules,
193  static::$messageLogger);
194  $this->assertNotEmpty($column);
195  $this->assertArrayHasKey('name', $column);
196  $this->assertArrayHasKey('type', $column);
197  $this->assertArrayHasKey('unsigned', $column);
198  $this->assertArrayHasKey('notNull', $column);
199  $this->assertArrayHasKey('collation', $column);
200  $this->assertArrayHasKey('default', $column);
201  $this->assertEquals('attributename', $column['name']);
202  $this->assertEquals('DOUBLE', $column['type']);
203  $this->assertEquals($unsigned, $column['unsigned']);
204  $this->assertEquals('NULL', $column['notNull']); // Not Coding Standard
205  $this->assertNull($column['collation']);
206  $this->assertEquals('DEFAULT NULL', $column['default']); // Not Coding Standard
207  }
208 
213  {
214  $unsigned = null;
216  if (!$assumedSigned)
217  {
218  $unsigned = 'UNSIGNED';
219  }
220  $modelClassName = 'AuditEvent';
221  $rules = array(
222  array('attributeName', 'numerical'),
223  array('attributeName', 'type', 'type' => 'float'),
224  );
225  $column = RedBeanModelMemberRulesToColumnAdapter::resolve($modelClassName,
226  $rules,
227  static::$messageLogger);
228  $this->assertNotEmpty($column);
229  $this->assertArrayHasKey('name', $column);
230  $this->assertArrayHasKey('type', $column);
231  $this->assertArrayHasKey('unsigned', $column);
232  $this->assertArrayHasKey('notNull', $column);
233  $this->assertArrayHasKey('collation', $column);
234  $this->assertArrayHasKey('default', $column);
235  $this->assertEquals('attributename', $column['name']);
236  $this->assertEquals('DOUBLE', $column['type']);
237  $this->assertEquals($unsigned, $column['unsigned']);
238  $this->assertEquals('NULL', $column['notNull']); // Not Coding Standard
239  $this->assertNull($column['collation']);
240  $this->assertEquals('DEFAULT NULL', $column['default']); // Not Coding Standard
241  }
242 
247  {
248  $modelClassName = 'AuditEvent';
249  $rules = array(
250  array('attributeName', 'type', 'type' => 'string'),
251  array('attributeName', 'length', 'max' => 100),
252  );
253  $column = RedBeanModelMemberRulesToColumnAdapter::resolve($modelClassName,
254  $rules,
255  static::$messageLogger);
256  $this->assertNotEmpty($column);
257  $this->assertArrayHasKey('name', $column);
258  $this->assertArrayHasKey('type', $column);
259  $this->assertArrayHasKey('unsigned', $column);
260  $this->assertArrayHasKey('notNull', $column);
261  $this->assertArrayHasKey('collation', $column);
262  $this->assertArrayHasKey('default', $column);
263  $this->assertEquals('attributename', $column['name']);
264  $this->assertEquals('VARCHAR(100)', $column['type']);
265  $this->assertNull($column['unsigned']);
266  $this->assertEquals('NULL', $column['notNull']); // Not Coding Standard
267  $this->assertEquals('COLLATE utf8_unicode_ci', $column['collation']);
268  $this->assertEquals('DEFAULT NULL', $column['default']); // Not Coding Standard
269  }
270 
275  {
276  $modelClassName = 'AuditEvent';
277  $rules = array(
278  array('attributeName', 'length', 'max' => 100),
279  array('attributeName', 'type', 'type' => 'string'),
280  );
281  $column = RedBeanModelMemberRulesToColumnAdapter::resolve($modelClassName,
282  $rules,
283  static::$messageLogger);
284  $this->assertNotEmpty($column);
285  $this->assertArrayHasKey('name', $column);
286  $this->assertArrayHasKey('type', $column);
287  $this->assertArrayHasKey('unsigned', $column);
288  $this->assertArrayHasKey('notNull', $column);
289  $this->assertArrayHasKey('collation', $column);
290  $this->assertArrayHasKey('default', $column);
291  $this->assertEquals('attributename', $column['name']);
292  $this->assertEquals('VARCHAR(100)', $column['type']);
293  $this->assertNull($column['unsigned']);
294  $this->assertEquals('NULL', $column['notNull']); // Not Coding Standard
295  $this->assertEquals('COLLATE utf8_unicode_ci', $column['collation']);
296  $this->assertEquals('DEFAULT NULL', $column['default']); // Not Coding Standard
297  }
298 
303  {
304  $modelClassName = 'AuditEvent';
305  $rules = array(
306  array('attributeName', 'type', 'type' => 'string'),
307  array('attributeName', 'length', 'max' => 10),
308  );
309  $column = RedBeanModelMemberRulesToColumnAdapter::resolve($modelClassName,
310  $rules,
311  static::$messageLogger);
312  $this->assertNotEmpty($column);
313  $this->assertArrayHasKey('name', $column);
314  $this->assertArrayHasKey('type', $column);
315  $this->assertArrayHasKey('unsigned', $column);
316  $this->assertArrayHasKey('notNull', $column);
317  $this->assertArrayHasKey('collation', $column);
318  $this->assertArrayHasKey('default', $column);
319  $this->assertEquals('attributename', $column['name']);
320  $this->assertEquals('VARCHAR(10)', $column['type']);
321  $this->assertNull($column['unsigned']);
322  $this->assertEquals('NULL', $column['notNull']); // Not Coding Standard
323  $this->assertEquals('COLLATE utf8_unicode_ci', $column['collation']);
324  $this->assertEquals('DEFAULT NULL', $column['default']); // Not Coding Standard
325 
326  $rules = array(
327  array('attributeName', 'type', 'type' => 'string'),
328  array('attributeName', 'length', 'max' => 255),
329  );
330  $column = RedBeanModelMemberRulesToColumnAdapter::resolve($modelClassName,
331  $rules,
332  static::$messageLogger);
333  $this->assertNotEmpty($column);
334  $this->assertArrayHasKey('type', $column);
335  $this->assertEquals('VARCHAR(255)', $column['type']);
336 
337  $rules = array(
338  array('attributeName', 'type', 'type' => 'string'),
339  array('attributeName', 'length', 'max' => 655361),
340  );
341  $column = RedBeanModelMemberRulesToColumnAdapter::resolve($modelClassName,
342  $rules,
343  static::$messageLogger);
344  $this->assertNotEmpty($column);
345  $this->assertArrayHasKey('type', $column);
346  $this->assertEquals('LONGTEXT', $column['type']);
347  }
348 
353  {
354  $modelClassName = 'AuditEvent';
355  $rules = array(
356  array('attributeName', 'email'),
357  );
358  $column = RedBeanModelMemberRulesToColumnAdapter::resolve($modelClassName,
359  $rules,
360  static::$messageLogger);
361  $this->assertNotEmpty($column);
362  $this->assertArrayHasKey('name', $column);
363  $this->assertArrayHasKey('type', $column);
364  $this->assertArrayHasKey('unsigned', $column);
365  $this->assertArrayHasKey('notNull', $column);
366  $this->assertArrayHasKey('collation', $column);
367  $this->assertArrayHasKey('default', $column);
368  $this->assertEquals('attributename', $column['name']);
369  $this->assertEquals('VARCHAR(255)', $column['type']);
370  $this->assertNull($column['unsigned']);
371  $this->assertEquals('NULL', $column['notNull']); // Not Coding Standard
372  $this->assertEquals('COLLATE utf8_unicode_ci', $column['collation']);
373  $this->assertEquals('DEFAULT NULL', $column['default']); // Not Coding Standard
374  }
375 
380  {
381  $modelClassName = 'AuditEvent';
382  $rules = array(
383  array('attributeName', 'email'),
384  array('attributeName', 'type', 'type' => 'string'),
385  );
386  $column = RedBeanModelMemberRulesToColumnAdapter::resolve($modelClassName,
387  $rules,
388  static::$messageLogger);
389  $this->assertNotEmpty($column);
390  $this->assertArrayHasKey('name', $column);
391  $this->assertArrayHasKey('type', $column);
392  $this->assertArrayHasKey('unsigned', $column);
393  $this->assertArrayHasKey('notNull', $column);
394  $this->assertArrayHasKey('collation', $column);
395  $this->assertArrayHasKey('default', $column);
396  $this->assertEquals('attributename', $column['name']);
397  $this->assertEquals('VARCHAR(255)', $column['type']);
398  $this->assertNull($column['unsigned']);
399  $this->assertEquals('NULL', $column['notNull']); // Not Coding Standard
400  $this->assertEquals('COLLATE utf8_unicode_ci', $column['collation']);
401  $this->assertEquals('DEFAULT NULL', $column['default']); // Not Coding Standard
402  }
403 
408  {
409  $modelClassName = 'AuditEvent';
410  $rules = array(
411  array('attributeName', 'type', 'type' => 'string'),
412  array('attributeName', 'email'),
413  );
414  $column = RedBeanModelMemberRulesToColumnAdapter::resolve($modelClassName,
415  $rules,
416  static::$messageLogger);
417  $this->assertNotEmpty($column);
418  $this->assertArrayHasKey('name', $column);
419  $this->assertArrayHasKey('type', $column);
420  $this->assertArrayHasKey('unsigned', $column);
421  $this->assertArrayHasKey('notNull', $column);
422  $this->assertArrayHasKey('collation', $column);
423  $this->assertArrayHasKey('default', $column);
424  $this->assertEquals('attributename', $column['name']);
425  $this->assertEquals('VARCHAR(255)', $column['type']);
426  $this->assertNull($column['unsigned']);
427  $this->assertEquals('NULL', $column['notNull']); // Not Coding Standard
428  $this->assertEquals('COLLATE utf8_unicode_ci', $column['collation']);
429  $this->assertEquals('DEFAULT NULL', $column['default']); // Not Coding Standard
430  }
431 
436  {
437  $modelClassName = 'AuditEvent';
438  $rules = array(
439  array('attributeName', 'email'),
440  array('attributeName', 'type', 'type' => 'string'),
441  array('attributeName', 'length', 'max' => 64),
442  );
443  $column = RedBeanModelMemberRulesToColumnAdapter::resolve($modelClassName,
444  $rules,
445  static::$messageLogger);
446  $this->assertNotEmpty($column);
447  $this->assertArrayHasKey('name', $column);
448  $this->assertArrayHasKey('type', $column);
449  $this->assertArrayHasKey('unsigned', $column);
450  $this->assertArrayHasKey('notNull', $column);
451  $this->assertArrayHasKey('collation', $column);
452  $this->assertArrayHasKey('default', $column);
453  $this->assertEquals('attributename', $column['name']);
454  $this->assertEquals('VARCHAR(64)', $column['type']);
455  $this->assertNull($column['unsigned']);
456  $this->assertEquals('NULL', $column['notNull']); // Not Coding Standard
457  $this->assertEquals('COLLATE utf8_unicode_ci', $column['collation']);
458  $this->assertEquals('DEFAULT NULL', $column['default']); // Not Coding Standard
459  }
460 
465  {
466  $modelClassName = 'AuditEvent';
467  $rules = array(
468  array('attributeName', 'type', 'type' => 'string'),
469  array('attributeName', 'length', 'max' => 64),
470  array('attributeName', 'email'),
471  );
472  $column = RedBeanModelMemberRulesToColumnAdapter::resolve($modelClassName,
473  $rules,
474  static::$messageLogger);
475  $this->assertNotEmpty($column);
476  $this->assertArrayHasKey('name', $column);
477  $this->assertArrayHasKey('type', $column);
478  $this->assertArrayHasKey('unsigned', $column);
479  $this->assertArrayHasKey('notNull', $column);
480  $this->assertArrayHasKey('collation', $column);
481  $this->assertArrayHasKey('default', $column);
482  $this->assertEquals('attributename', $column['name']);
483  $this->assertEquals('VARCHAR(64)', $column['type']);
484  $this->assertNull($column['unsigned']);
485  $this->assertEquals('NULL', $column['notNull']); // Not Coding Standard
486  $this->assertEquals('COLLATE utf8_unicode_ci', $column['collation']);
487  $this->assertEquals('DEFAULT NULL', $column['default']); // Not Coding Standard
488  }
489 
493  public function testResolveWithUrlValidator()
494  {
495  $modelClassName = 'AuditEvent';
496  $rules = array(
497  array('attributeName', 'url'),
498  );
499  $column = RedBeanModelMemberRulesToColumnAdapter::resolve($modelClassName,
500  $rules,
501  static::$messageLogger);
502  $this->assertNotEmpty($column);
503  $this->assertArrayHasKey('name', $column);
504  $this->assertArrayHasKey('type', $column);
505  $this->assertArrayHasKey('unsigned', $column);
506  $this->assertArrayHasKey('notNull', $column);
507  $this->assertArrayHasKey('collation', $column);
508  $this->assertArrayHasKey('default', $column);
509  $this->assertEquals('attributename', $column['name']);
510  $this->assertEquals('VARCHAR(255)', $column['type']);
511  $this->assertNull($column['unsigned']);
512  $this->assertEquals('NULL', $column['notNull']); // Not Coding Standard
513  $this->assertEquals('COLLATE utf8_unicode_ci', $column['collation']);
514  $this->assertEquals('DEFAULT NULL', $column['default']); // Not Coding Standard
515  }
516 
521  {
522  $modelClassName = 'AuditEvent';
523  $rules = array(
524  array('attributeName', 'url'),
525  array('attributeName', 'type', 'type' => 'string'),
526  );
527  $column = RedBeanModelMemberRulesToColumnAdapter::resolve($modelClassName,
528  $rules,
529  static::$messageLogger);
530  $this->assertNotEmpty($column);
531  $this->assertArrayHasKey('name', $column);
532  $this->assertArrayHasKey('type', $column);
533  $this->assertArrayHasKey('unsigned', $column);
534  $this->assertArrayHasKey('notNull', $column);
535  $this->assertArrayHasKey('collation', $column);
536  $this->assertArrayHasKey('default', $column);
537  $this->assertEquals('attributename', $column['name']);
538  $this->assertEquals('VARCHAR(255)', $column['type']);
539  $this->assertNull($column['unsigned']);
540  $this->assertEquals('NULL', $column['notNull']); // Not Coding Standard
541  $this->assertEquals('COLLATE utf8_unicode_ci', $column['collation']);
542  $this->assertEquals('DEFAULT NULL', $column['default']); // Not Coding Standard
543  }
544 
549  {
550  $modelClassName = 'AuditEvent';
551  $rules = array(
552  array('attributeName', 'type', 'type' => 'string'),
553  array('attributeName', 'url'),
554  );
555  $column = RedBeanModelMemberRulesToColumnAdapter::resolve($modelClassName,
556  $rules,
557  static::$messageLogger);
558  $this->assertNotEmpty($column);
559  $this->assertArrayHasKey('name', $column);
560  $this->assertArrayHasKey('type', $column);
561  $this->assertArrayHasKey('unsigned', $column);
562  $this->assertArrayHasKey('notNull', $column);
563  $this->assertArrayHasKey('collation', $column);
564  $this->assertArrayHasKey('default', $column);
565  $this->assertEquals('attributename', $column['name']);
566  $this->assertEquals('VARCHAR(255)', $column['type']);
567  $this->assertNull($column['unsigned']);
568  $this->assertEquals('NULL', $column['notNull']); // Not Coding Standard
569  $this->assertEquals('COLLATE utf8_unicode_ci', $column['collation']);
570  $this->assertEquals('DEFAULT NULL', $column['default']); // Not Coding Standard
571  }
572 
577  {
578  $modelClassName = 'AuditEvent';
579  $rules = array(
580  array('attributeName', 'url'),
581  array('attributeName', 'type', 'type' => 'string'),
582  array('attributeName', 'length', 'max' => 64),
583  );
584  $column = RedBeanModelMemberRulesToColumnAdapter::resolve($modelClassName,
585  $rules,
586  static::$messageLogger);
587  $this->assertNotEmpty($column);
588  $this->assertArrayHasKey('name', $column);
589  $this->assertArrayHasKey('type', $column);
590  $this->assertArrayHasKey('unsigned', $column);
591  $this->assertArrayHasKey('notNull', $column);
592  $this->assertArrayHasKey('collation', $column);
593  $this->assertArrayHasKey('default', $column);
594  $this->assertEquals('attributename', $column['name']);
595  $this->assertEquals('VARCHAR(64)', $column['type']);
596  $this->assertNull($column['unsigned']);
597  $this->assertEquals('NULL', $column['notNull']); // Not Coding Standard
598  $this->assertEquals('COLLATE utf8_unicode_ci', $column['collation']);
599  $this->assertEquals('DEFAULT NULL', $column['default']); // Not Coding Standard
600  }
601 
606  {
607  $modelClassName = 'AuditEvent';
608  $rules = array(
609  array('attributeName', 'type', 'type' => 'string'),
610  array('attributeName', 'length', 'max' => 64),
611  array('attributeName', 'url'),
612  );
613  $column = RedBeanModelMemberRulesToColumnAdapter::resolve($modelClassName,
614  $rules,
615  static::$messageLogger);
616  $this->assertNotEmpty($column);
617  $this->assertArrayHasKey('name', $column);
618  $this->assertArrayHasKey('type', $column);
619  $this->assertArrayHasKey('unsigned', $column);
620  $this->assertArrayHasKey('notNull', $column);
621  $this->assertArrayHasKey('collation', $column);
622  $this->assertArrayHasKey('default', $column);
623  $this->assertEquals('attributename', $column['name']);
624  $this->assertEquals('VARCHAR(64)', $column['type']);
625  $this->assertNull($column['unsigned']);
626  $this->assertEquals('NULL', $column['notNull']); // Not Coding Standard
627  $this->assertEquals('COLLATE utf8_unicode_ci', $column['collation']);
628  $this->assertEquals('DEFAULT NULL', $column['default']); // Not Coding Standard
629  }
630 
635  {
636  $unsigned = null;
638  if (!$assumedSigned)
639  {
640  $unsigned = 'UNSIGNED';
641  }
642  $maxAllowed = DatabaseCompatibilityUtil::resolveIntegerMaxAllowedValuesByType($assumedSigned);
643  $modelClassName = 'AuditEvent';
644  $types = array_keys($maxAllowed);
645  foreach ($types as $type)
646  {
647  $dbType = strtoupper($type);
648  if ($type == 'integer')
649  {
650  $dbType = 'INT';
651  }
652  $dbType .= '(11)';
653  $max = ($maxAllowed[$type] - ($maxAllowed[$type]/5));
654  $rules = array(
655  array('attributeName' . $type, 'type', 'type' => 'integer'),
656  array('attributeName' . $type, 'numerical', 'max' => $max),
657  );
658  $column = RedBeanModelMemberRulesToColumnAdapter::resolve($modelClassName,
659  $rules,
660  static::$messageLogger);
661  $this->assertNotEmpty($column);
662  $this->assertArrayHasKey('name', $column);
663  $this->assertArrayHasKey('type', $column);
664  $this->assertArrayHasKey('unsigned', $column);
665  $this->assertArrayHasKey('notNull', $column);
666  $this->assertArrayHasKey('collation', $column);
667  $this->assertArrayHasKey('default', $column);
668  $this->assertEquals('attributename' . $type, $column['name']);
669  $this->assertEquals($dbType, $column['type']);
670  $this->assertEquals($unsigned, $column['unsigned']);
671  $this->assertEquals('NULL', $column['notNull']); // Not Coding Standard
672  $this->assertNull($column['collation']);
673  $this->assertEquals('DEFAULT NULL', $column['default']); // Not Coding Standard
674  }
675  }
676 
681  {
683  if (!$assumedSigned)
684  {
685  return;
686  }
687  $maxAllowed = DatabaseCompatibilityUtil::resolveIntegerMaxAllowedValuesByType($assumedSigned);
688  $modelClassName = 'AuditEvent';
689  $types = array_keys($maxAllowed);
690  foreach ($types as $type)
691  {
692  $dbType = strtoupper($type);
693  if ($type == 'integer')
694  {
695  $dbType = 'INT';
696  }
697  $dbType .= '(11)';
698  $max = ($maxAllowed[$type] - ($maxAllowed[$type]/5));
699  $minAllowed = static::calculateMinByMaxAndSigned($maxAllowed[$type], $assumedSigned);
700  $minAllowed = ($minAllowed + $max/5);
701  $rules = array(
702  array('attributeName' . $type, 'type', 'type' => 'integer'),
703  array('attributeName' . $type, 'numerical', 'min' => $minAllowed, 'max' => $max),
704  );
705  $column = RedBeanModelMemberRulesToColumnAdapter::resolve($modelClassName,
706  $rules,
707  static::$messageLogger);
708  $this->assertNotEmpty($column);
709  $this->assertArrayHasKey('name', $column);
710  $this->assertArrayHasKey('type', $column);
711  $this->assertArrayHasKey('unsigned', $column);
712  $this->assertArrayHasKey('notNull', $column);
713  $this->assertArrayHasKey('collation', $column);
714  $this->assertArrayHasKey('default', $column);
715  $this->assertEquals('attributename' . $type, $column['name']);
716  $this->assertEquals($dbType, $column['type']);
717  $this->assertNull($column['unsigned']);
718  $this->assertEquals('NULL', $column['notNull']); // Not Coding Standard
719  $this->assertNull($column['collation']);
720  $this->assertEquals('DEFAULT NULL', $column['default']); // Not Coding Standard
721  }
722  }
723 
728  {
729  $modelClassName = 'AuditEvent';
731  $this->assertNull($uniqueIndexes);
732  }
733 
738  {
739  $unsigned = null;
741  if (!$assumedSigned)
742  {
743  $unsigned = 'UNSIGNED';
744  }
745  $modelClassName = 'AuditEvent';
746  $rules = array(
747  array('attributeName', 'unique'),
748  array('attributeName', 'type', 'type' => 'integer'),
749  );
750  $column = RedBeanModelMemberRulesToColumnAdapter::resolve($modelClassName,
751  $rules,
752  static::$messageLogger);
753  $this->assertNotEmpty($column);
754  $this->assertArrayHasKey('name', $column);
755  $this->assertArrayHasKey('type', $column);
756  $this->assertArrayHasKey('unsigned', $column);
757  $this->assertArrayHasKey('notNull', $column);
758  $this->assertArrayHasKey('collation', $column);
759  $this->assertArrayHasKey('default', $column);
760  $this->assertEquals('attributename', $column['name']);
761  $this->assertEquals('INT(11)', $column['type']);
762  $this->assertEquals($unsigned, $column['unsigned']);
763  $this->assertEquals('NULL', $column['notNull']); // Not Coding Standard
764  $this->assertNull($column['collation']);
765  $this->assertEquals('DEFAULT NULL', $column['default']); // Not Coding Standard
766 
768  $this->assertNotEmpty($uniqueIndex);
769  $this->assertCount(1, $uniqueIndex);
770  $indexName = key($uniqueIndex);
771  $this->assertCount(2, $uniqueIndex[$indexName]);
772  $this->assertArrayHasKey('members', $uniqueIndex[$indexName]);
773  $this->assertArrayHasKey('unique', $uniqueIndex[$indexName]);
774  $this->assertCount(1, $uniqueIndex[$indexName]['members']);
775  $this->assertEquals('attributeName', $uniqueIndex[$indexName]['members'][0]);
776  $this->assertTrue($uniqueIndex[$indexName]['unique']);
777  }
778 
779  protected static function calculateMinByMaxAndSigned($max, $signed = false)
780  {
781  if (!$signed)
782  {
783  return 0;
784  }
785  else
786  {
787  return -1 * $max;
788  }
789  }
790  }
791 ?>
static resolve($modelClassName, array $rules, &$messageLogger)
static getByUsername($username)
Definition: User.php:49
Generated on Sun Aug 9 2020 07:10:26
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.