Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
RedBeanModelToTableSchemaAdapterTest.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 testResolveWithEmptyModelClassName()
51  {
52  $modelClassName = null;
53  $schema = RedBeanModelToTableSchemaAdapter::resolve($modelClassName, static::$messageLogger);
54  $this->assertFalse($schema);
55  }
56 
61  {
62  $modelClassName = 'ModelClass';
63  $schema = RedBeanModelToTableSchemaAdapter::resolve($modelClassName, static::$messageLogger);
64  $this->assertFalse($schema);
65  }
66 
71  {
72  $modelClassName = 'MashableActivity';
73  $schema = RedBeanModelToTableSchemaAdapter::resolve($modelClassName, static::$messageLogger);
74  $this->assertFalse($schema);
75  }
76 
81  {
82  $modelClassName = 'OwnedSecurableItem';
83  $expectedSchema = array(
84  'ownedsecurableitem' => array(
85  'columns' => array(
86  array(
87  'name' => 'securableitem_id',
88  'type' => 'INT(11)',
89  'unsigned' => 'UNSIGNED',
90  'notNull' => 'NULL', // Not Coding Standard
91  'collation' => null,
92  'default' => 'DEFAULT NULL', // Not Coding Standard
93  ),
94  array(
95  'name' => 'owner__user_id',
96  'type' => 'INT(11)',
97  'unsigned' => 'UNSIGNED',
98  'notNull' => 'NULL', // Not Coding Standard
99  'collation' => null,
100  'default' => 'DEFAULT NULL', // Not Coding Standard
101  ),
102  ),
103  'indexes' => array(
104  'owner__user_id' => array('columns' => array('owner__user_id'),
105  'unique' => false),
106  'securableitem_id' => array('columns' => array('securableitem_id'),
107  'unique' => false),
108  ),
109  ),
110  );
111  $schema = RedBeanModelToTableSchemaAdapter::resolve($modelClassName, static::$messageLogger);
112  $this->assertNotEmpty($schema);
113  $this->assertEquals($expectedSchema, $schema);
114  }
115 
119  public function testResolve()
120  {
121  $expectedSchema = array('_user' =>
122  array('columns' =>
123  array(
124  array(
125  'name' => 'hash',
126  'type' => 'VARCHAR(60)',
127  'unsigned' => null,
128  'notNull' => 'NULL', // Not Coding Standard
129  'collation' => 'COLLATE utf8_unicode_ci',
130  'default' => 'DEFAULT NULL', // Not Coding Standard
131  ),
132  array(
133  'name' => 'language',
134  'type' => 'VARCHAR(10)',
135  'unsigned' => null,
136  'notNull' => 'NULL', // Not Coding Standard
137  'collation' => 'COLLATE utf8_unicode_ci',
138  'default' => 'DEFAULT NULL', // Not Coding Standard
139  ),
140  array(
141  'name' => 'locale',
142  'type' => 'VARCHAR(10)',
143  'unsigned' => null,
144  'notNull' => 'NULL', // Not Coding Standard
145  'collation' => 'COLLATE utf8_unicode_ci',
146  'default' => 'DEFAULT NULL', // Not Coding Standard
147  ),
148  array(
149  'name' => 'timezone',
150  'type' => 'VARCHAR(64)',
151  'unsigned' => null,
152  'notNull' => 'NULL', // Not Coding Standard
153  'collation' => 'COLLATE utf8_unicode_ci',
154  'default' => 'DEFAULT NULL', // Not Coding Standard
155  ),
156  array(
157  'name' => 'username',
158  'type' => 'VARCHAR(64)',
159  'unsigned' => null,
160  'notNull' => 'NULL', // Not Coding Standard
161  'collation' => 'COLLATE utf8_unicode_ci',
162  'default' => 'DEFAULT NULL', // Not Coding Standard
163  ),
164  array(
165  'name' => 'serializedavatardata',
166  'type' => 'TEXT',
167  'unsigned' => null,
168  'notNull' => 'NULL', // Not Coding Standard
169  'collation' => 'COLLATE utf8_unicode_ci',
170  'default' => 'DEFAULT NULL', // Not Coding Standard
171  ),
172  array(
173  'name' => 'isactive',
174  'type' => 'TINYINT(1) UNSIGNED',
175  'unsigned' => null,
176  'notNull' => 'NULL', // Not Coding Standard
177  'collation' => null,
178  'default' => 'DEFAULT NULL', // Not Coding Standard
179  ),
180  array(
181  'name' => 'isrootuser',
182  'type' => 'TINYINT(1) UNSIGNED',
183  'unsigned' => null,
184  'notNull' => 'NULL', // Not Coding Standard
185  'collation' => null,
186  'default' => 'DEFAULT NULL', // Not Coding Standard
187  ),
188  array(
189  'name' => 'hidefromselecting',
190  'type' => 'TINYINT(1) UNSIGNED',
191  'unsigned' => null,
192  'notNull' => 'NULL', // Not Coding Standard
193  'collation' => null,
194  'default' => 'DEFAULT NULL', // Not Coding Standard
195  ),
196  array(
197  'name' => 'issystemuser',
198  'type' => 'TINYINT(1) UNSIGNED',
199  'unsigned' => null,
200  'notNull' => 'NULL', // Not Coding Standard
201  'collation' => null,
202  'default' => 'DEFAULT NULL', // Not Coding Standard
203  ),
204  array(
205  'name' => 'hidefromleaderboard',
206  'type' => 'TINYINT(1) UNSIGNED',
207  'unsigned' => null,
208  'notNull' => 'NULL', // Not Coding Standard
209  'collation' => null,
210  'default' => 'DEFAULT NULL', // Not Coding Standard
211  ),
212  array(
213  'name' => 'lastlogindatetime',
214  'type' => 'DATETIME',
215  'unsigned' => null,
216  'notNull' => 'NULL', // Not Coding Standard
217  'collation' => null,
218  'default' => 'DEFAULT NULL', // Not Coding Standard
219  ),
220  array(
221  'name' => 'permitable_id',
222  'type' => 'INT(11)',
223  'unsigned' => 'UNSIGNED',
224  'notNull' => 'NULL', // Not Coding Standard
225  'collation' => null,
226  'default' => 'DEFAULT NULL', // Not Coding Standard
227  ),
228  array(
229  'name' => 'person_id',
230  'type' => 'INT(11)',
231  'unsigned' => 'UNSIGNED',
232  'notNull' => 'NULL', // Not Coding Standard
233  'collation' => null,
234  'default' => 'DEFAULT NULL', // Not Coding Standard
235  ),
236  array(
237  'name' => 'currency_id',
238  'type' => 'INT(11)',
239  'unsigned' => 'UNSIGNED',
240  'notNull' => 'NULL', // Not Coding Standard
241  'collation' => null,
242  'default' => 'DEFAULT NULL', // Not Coding Standard
243  ),
244  array(
245  'name' => 'manager__user_id',
246  'type' => 'INT(11)',
247  'unsigned' => 'UNSIGNED',
248  'notNull' => 'NULL', // Not Coding Standard
249  'collation' => null,
250  'default' => 'DEFAULT NULL', // Not Coding Standard
251  ),
252  array(
253  'name' => 'role_id',
254  'type' => 'INT(11)',
255  'unsigned' => 'UNSIGNED',
256  'notNull' => 'NULL', // Not Coding Standard
257  'collation' => null,
258  'default' => 'DEFAULT NULL', // Not Coding Standard
259  ),
260  array(
261  'name' => 'secondaryemail_email_id',
262  'type' => 'INT(11)',
263  'unsigned' => 'UNSIGNED',
264  'notNull' => 'NULL', // Not Coding Standard
265  'collation' => null,
266  'default' => 'DEFAULT NULL', // Not Coding Standard
267  ),
268  ),
269  'indexes' => array(
270  'unique_emanresu' => array(
271  'columns' => array('username'),
272  'unique' => true,
273  ),
274  'permitable_id' => array('columns' => array('permitable_id'),
275  'unique' => false),
276  ),
277  ),
278  );
279  $modelClassName = 'User';
280  $schema = RedBeanModelToTableSchemaAdapter::resolve($modelClassName, static::$messageLogger);
281  $this->assertNotEmpty($schema);
282  $this->assertEquals($expectedSchema, $schema);
283  }
284 
288  public function testResolveForTestModel()
289  {
290  $expectedSchema = array('emailtemplatemodeltestitem' => array(
291  'columns' => array(
292  array(
293  'name' => 'firstname',
294  'type' => 'VARCHAR(32)',
295  'unsigned' => null,
296  'notNull' => 'NULL', // Not Coding Standard
297  'collation' => 'COLLATE utf8_unicode_ci',
298  'default' => 'DEFAULT NULL', // Not Coding Standard
299  ),
300  array(
301  'name' => 'lastname',
302  'type' => 'VARCHAR(32)',
303  'unsigned' => null,
304  'notNull' => 'NULL', // Not Coding Standard
305  'collation' => 'COLLATE utf8_unicode_ci',
306  'default' => 'DEFAULT NULL', // Not Coding Standard
307  ),
308  array(
309  'name' => 'boolean',
310  'type' => 'TINYINT(1) UNSIGNED',
311  'unsigned' => null,
312  'notNull' => 'NULL', // Not Coding Standard
313  'collation' => null,
314  'default' => 'DEFAULT NULL', // Not Coding Standard
315  ),
316  array(
317  'name' => 'boolean2',
318  'type' => 'TINYINT(1) UNSIGNED',
319  'unsigned' => null,
320  'notNull' => 'NULL', // Not Coding Standard
321  'collation' => null,
322  'default' => 'DEFAULT NULL', // Not Coding Standard
323  ),
324  array(
325  'name' => 'date',
326  'type' => 'DATE',
327  'unsigned' => null,
328  'notNull' => 'NULL', // Not Coding Standard
329  'collation' => null,
330  'default' => 'DEFAULT NULL', // Not Coding Standard
331  ),
332  array(
333  'name' => 'date2',
334  'type' => 'DATE',
335  'unsigned' => null,
336  'notNull' => 'NULL', // Not Coding Standard
337  'collation' => null,
338  'default' => 'DEFAULT NULL', // Not Coding Standard
339  ),
340  array(
341  'name' => 'date3',
342  'type' => 'DATE',
343  'unsigned' => null,
344  'notNull' => 'NULL', // Not Coding Standard
345  'collation' => null,
346  'default' => 'DEFAULT NULL', // Not Coding Standard
347  ),
348  array(
349  'name' => 'date4',
350  'type' => 'DATE',
351  'unsigned' => null,
352  'notNull' => 'NULL', // Not Coding Standard
353  'collation' => null,
354  'default' => 'DEFAULT NULL', // Not Coding Standard
355  ),
356  array(
357  'name' => 'datetime',
358  'type' => 'DATETIME',
359  'unsigned' => null,
360  'notNull' => 'NULL', // Not Coding Standard
361  'collation' => null,
362  'default' => 'DEFAULT NULL', // Not Coding Standard
363  ),
364  array(
365  'name' => 'datetime2',
366  'type' => 'DATETIME',
367  'unsigned' => null,
368  'notNull' => 'NULL', // Not Coding Standard
369  'collation' => null,
370  'default' => 'DEFAULT NULL', // Not Coding Standard
371  ),
372  array(
373  'name' => 'datetime3',
374  'type' => 'DATETIME',
375  'unsigned' => null,
376  'notNull' => 'NULL', // Not Coding Standard
377  'collation' => null,
378  'default' => 'DEFAULT NULL', // Not Coding Standard
379  ),
380  array(
381  'name' => 'datetime4',
382  'type' => 'DATETIME',
383  'unsigned' => null,
384  'notNull' => 'NULL', // Not Coding Standard
385  'collation' => null,
386  'default' => 'DEFAULT NULL', // Not Coding Standard
387  ),
388  array(
389  'name' => 'float',
390  'type' => 'DOUBLE',
391  'unsigned' => null,
392  'notNull' => 'NULL', // Not Coding Standard
393  'collation' => null,
394  'default' => 'DEFAULT NULL', // Not Coding Standard
395  ),
396  array(
397  'name' => 'integer',
398  'type' => 'INT(11)',
399  'unsigned' => null,
400  'notNull' => 'NULL', // Not Coding Standard
401  'collation' => null,
402  'default' => 'DEFAULT NULL', // Not Coding Standard
403  ),
404  array(
405  'name' => 'phone',
406  'type' => 'VARCHAR(14)',
407  'unsigned' => null,
408  'notNull' => 'NULL', // Not Coding Standard
409  'collation' => 'COLLATE utf8_unicode_ci',
410  'default' => 'DEFAULT NULL', // Not Coding Standard
411  ),
412  array(
413  'name' => 'string',
414  'type' => 'VARCHAR(64)',
415  'unsigned' => null,
416  'notNull' => 'NULL', // Not Coding Standard
417  'collation' => 'COLLATE utf8_unicode_ci',
418  'default' => 'DEFAULT NULL', // Not Coding Standard
419  ),
420  array(
421  'name' => 'textarea',
422  'type' => 'TEXT',
423  'unsigned' => null,
424  'notNull' => 'NULL', // Not Coding Standard
425  'collation' => 'COLLATE utf8_unicode_ci',
426  'default' => 'DEFAULT NULL', // Not Coding Standard
427  ),
428  array(
429  'name' => 'url',
430  'type' => 'VARCHAR(255)',
431  'unsigned' => null,
432  'notNull' => 'NULL', // Not Coding Standard
433  'collation' => 'COLLATE utf8_unicode_ci',
434  'default' => 'DEFAULT NULL', // Not Coding Standard
435  ),
436  array(
437  'name' => 'ownedsecurableitem_id',
438  'type' => 'INT(11)',
439  'unsigned' => 'UNSIGNED',
440  'notNull' => 'NULL', // Not Coding Standard
441  'collation' => null,
442  'default' => 'DEFAULT NULL', // Not Coding Standard
443  ),
444  array(
445  'name' => 'currencyvalue_id',
446  'type' => 'INT(11)',
447  'unsigned' => 'UNSIGNED',
448  'notNull' => 'NULL', // Not Coding Standard
449  'collation' => null,
450  'default' => 'DEFAULT NULL', // Not Coding Standard
451  ),
452  array(
453  'name' => 'dropdown_customfield_id',
454  'type' => 'INT(11)',
455  'unsigned' => 'UNSIGNED',
456  'notNull' => 'NULL', // Not Coding Standard
457  'collation' => null,
458  'default' => 'DEFAULT NULL', // Not Coding Standard
459  ),
460  array(
461  'name' => 'dropdown2_customfield_id',
462  'type' => 'INT(11)',
463  'unsigned' => 'UNSIGNED',
464  'notNull' => 'NULL', // Not Coding Standard
465  'collation' => null,
466  'default' => 'DEFAULT NULL', // Not Coding Standard
467  ),
468  array(
469  'name' => 'radiodropdown_customfield_id',
470  'type' => 'INT(11)',
471  'unsigned' => 'UNSIGNED',
472  'notNull' => 'NULL', // Not Coding Standard
473  'collation' => null,
474  'default' => 'DEFAULT NULL', // Not Coding Standard
475  ),
476  array(
477  'name' => 'multidropdown_multiplevaluescustomfield_id',
478  'type' => 'INT(11)',
479  'unsigned' => 'UNSIGNED',
480  'notNull' => 'NULL', // Not Coding Standard
481  'collation' => null,
482  'default' => 'DEFAULT NULL', // Not Coding Standard
483  ),
484  array(
485  'name' => 'tagcloud_multiplevaluescustomfield_id',
486  'type' => 'INT(11)',
487  'unsigned' => 'UNSIGNED',
488  'notNull' => 'NULL', // Not Coding Standard
489  'collation' => null,
490  'default' => 'DEFAULT NULL', // Not Coding Standard
491  ),
492  array(
493  'name' => 'primaryemail_email_id',
494  'type' => 'INT(11)',
495  'unsigned' => 'UNSIGNED',
496  'notNull' => 'NULL', // Not Coding Standard
497  'collation' => null,
498  'default' => 'DEFAULT NULL', // Not Coding Standard
499  ),
500  array(
501  'name' => 'primaryaddress_address_id',
502  'type' => 'INT(11)',
503  'unsigned' => 'UNSIGNED',
504  'notNull' => 'NULL', // Not Coding Standard
505  'collation' => null,
506  'default' => 'DEFAULT NULL', // Not Coding Standard
507  ),
508  array(
509  'name' => 'secondaryemail_email_id',
510  'type' => 'INT(11)',
511  'unsigned' => 'UNSIGNED',
512  'notNull' => 'NULL', // Not Coding Standard
513  'collation' => null,
514  'default' => 'DEFAULT NULL', // Not Coding Standard
515  ),
516  array(
517  'name' => 'likecontactstate_contactstate_id',
518  'type' => 'INT(11)',
519  'unsigned' => 'UNSIGNED',
520  'notNull' => 'NULL', // Not Coding Standard
521  'collation' => null,
522  'default' => 'DEFAULT NULL', // Not Coding Standard
523  ),
524  array(
525  'name' => '_user_id',
526  'type' => 'INT(11)',
527  'unsigned' => 'UNSIGNED',
528  'notNull' => 'NULL', // Not Coding Standard
529  'collation' => null,
530  'default' => 'DEFAULT NULL', // Not Coding Standard
531  ),
532  array(
533  'name' => 'user2__user_id',
534  'type' => 'INT(11)',
535  'unsigned' => 'UNSIGNED',
536  'notNull' => 'NULL', // Not Coding Standard
537  'collation' => null,
538  'default' => 'DEFAULT NULL', // Not Coding Standard
539  ),
540  ),
541  'indexes' => array(),
542  ),
543  );
544  $modelClassName = 'EmailTemplateModelTestItem';
545  $schema = RedBeanModelToTableSchemaAdapter::resolve($modelClassName, static::$messageLogger);
546  $this->assertNotEmpty($schema);
547  $this->assertEquals($expectedSchema, $schema);
548  }
549  }
550 ?>
static resolve($modelClassName, &$messageLogger)
static getByUsername($username)
Definition: User.php:49
Generated on Fri Jul 10 2020 07:10:28
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.