Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
DesignerTest.php
1 <?php
2  /*********************************************************************************
3  * Zurmo is a customer relationship management program developed by
4  * Zurmo, Inc. Copyright (C) 2017 Zurmo Inc.
5  *
6  * Zurmo is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License version 3 as published by the
8  * Free Software Foundation with the addition of the following permission added
9  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10  * IN WHICH THE COPYRIGHT IS OWNED BY ZURMO, ZURMO DISCLAIMS THE WARRANTY
11  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12  *
13  * Zurmo is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Affero General Public License along with
19  * this program; if not, see http://www.gnu.org/licenses or write to the Free
20  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  * 02110-1301 USA.
22  *
23  * You can contact Zurmo, Inc. with a mailing address at 27 North Wacker Drive
24  * Suite 370 Chicago, IL 60606. or at email address contact@zurmo.com.
25  *
26  * The interactive user interfaces in original and modified versions
27  * of this program must display Appropriate Legal Notices, as required under
28  * Section 5 of the GNU Affero General Public License version 3.
29  *
30  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31  * these Appropriate Legal Notices must retain the display of the Zurmo
32  * logo and Zurmo copyright notice. If the display of the logo is not reasonably
33  * feasible for technical reasons, the Appropriate Legal Notices must display the words
34  * "Copyright Zurmo Inc. 2017. All rights reserved".
35  ********************************************************************************/
36 
38  {
39  public static $activateDefaultLanguages = true;
40 
41  public static function setUpBeforeClass()
42  {
43  parent::setUpBeforeClass();
44  SecurityTestHelper::createSuperAdmin();
45  }
46 
53  {
54  $attributeForm = AttributesFormFactory::createAttributeFormByAttributeName(new Task(), 'completedDateTime');
55  $attributeForm->setScenario('createAttribute');
56  $validated = $attributeForm->validate();
57  $this->assertFalse($validated);
58  $attributeForm->setScenario('updateAttribute');
59  $validated = $attributeForm->validate();
60  $this->assertTrue($validated);
61  }
62 
67  {
68  Yii::app()->user->userModel = User::getByUsername('super');
69  $model = new Account();
70  $modelAttributesAdapter = new ModelAttributesAdapter($model);
71  $editableMetadata = AccountsListView::getMetadata();
73  $modelAttributesAdapter->getAttributes(),
75  $editableMetadata
76  );
77  $adapter = new LayoutMetadataAdapter('AccountsListView',
78  'AccountsModule',
79  $editableMetadata,
81  $attributesLayoutAdapter->getPlaceableLayoutAttributes(),
82  $attributesLayoutAdapter->getRequiredDerivedLayoutAttributeTypes()
83  );
84  $selectedListAttributes = array('name', 'officePhone');
85  $data = $adapter->resolveMetadataFromSelectedListAttributes('AccountsListView', $selectedListAttributes);
86  $compareMetadata = array(
87  'nonPlaceableAttributeNames' => array(
88  'account',
89  ),
90  'panels' =>
91  array(
92  array(
93  'rows' => array(
94  array(
95  'cells' => array(
96  array('elements' => array(
97  array('attributeName' => 'name', 'type' => 'Text', 'isLink' => true)
98  )
99  ),
100  ),
101  ),
102  array(
103  'cells' => array(
104  array('elements' => array(
105  array('attributeName' => 'officePhone', 'type' => 'Phone')
106  )
107  ),
108  )
109  )
110  )
111  )
112  )
113  );
114  $this->assertEquals($compareMetadata, $data['global']);
115  }
116 
120  public function testSetMetadataFromLayout()
121  {
122  Yii::app()->user->userModel = User::getByUsername('super');
123 
124  $layout = array('panels' =>
125  array(
126  array(
127  'rows' => array(
128  array(
129  'cells' => array(
130  array('element' => 'id'),
131  ),
132  ),
133  array(
134  'cells' => array(
135  array('element' => 'name', 'detailViewOnly' => 1),
136  )
137  )
138  )
139  )
140  )
141  );
142  $compareMetadata = array('panels' =>
143  array(
144  array(
145  'rows' => array(
146  array(
147  'cells' => array(
148  array('elements' => array(
149  array('attributeName' => 'id', 'type' => 'Text')
150  )
151  ),
152  ),
153  ),
154  array(
155  'cells' => array(
156  array('elements' => array(
157  array('attributeName' => 'name', 'type' => 'Text', 'isLink' => true)
158  )
159  ),
160  )
161  )
162  )
163  )
164  )
165  );
166  $model = new Account();
167  $modelAttributesAdapter = new ModelAttributesAdapter($model);
168  $editableMetadata = AccountsListView::getMetadata();
169  $this->assertNotEquals($editableMetadata['global']['panels'], $layout);
171  $modelAttributesAdapter->getAttributes(),
172  new ListViewDesignerRules(),
173  $editableMetadata
174  );
175  $adapter = new LayoutMetadataAdapter('AccountsListView',
176  'AccountsModule',
177  $editableMetadata,
178  new ListViewDesignerRules(),
179  $attributesLayoutAdapter->getPlaceableLayoutAttributes(),
180  $attributesLayoutAdapter->getRequiredDerivedLayoutAttributeTypes()
181  );
182  $this->assertTrue($adapter->setMetadataFromLayout($layout, array()));
183  $editableMetadataNew = AccountsListView::getMetadata();
184  $this->assertNotEquals($editableMetadataNew, $editableMetadata);
185  $this->assertEquals($editableMetadataNew['global']['panels'], $compareMetadata['panels']);
186  $this->assertNotEmpty($adapter->getMessage());
187 
188  $layout = array('panels' =>
189  array(
190  array(
191  'rows' => array(
192  array(
193  'cells' => array(
194  array('element' => 'id'),
195  ),
196  ),
197  array(
198  'cells' => array(
199  array('element' => 'name', 'detailViewOnly' => 1),
200  )
201  ),
202  array(
203  'cells' => array(
204  array('element' => 'owner'),
205  )
206  )
207  )
208  )
209  )
210  );
211  //DetailViewOnly is setted
212  $compareMetadata = array('panels' =>
213  array(
214  array(
215  'rows' => array(
216  array(
217  'cells' => array(
218  array('elements' => array(
219  array('attributeName' => null,
220  'type' => 'Null') // Not Coding Standard
221  )
222  ),
223  ),
224  ),
225  array(
226  'cells' => array(
227  array('elements' => array(
228  array('attributeName' => 'name',
229  'type' => 'Text')
230  ),
231  'detailViewOnly' => 1
232  ),
233  )
234  ),
235  array(
236  'cells' => array(
237  array('elements' => array(
238  array('attributeName' => 'owner',
239  'type' => 'User')
240  ),
241  'detailViewOnly' => 1
242  ),
243  )
244  )
245  )
246  )
247  )
248  );
249  $editableMetadata = AccountEditAndDetailsView::getMetadata();
250  $this->assertNotEquals($editableMetadata['global']['panels'], $layout);
252  $modelAttributesAdapter->getAttributes(),
254  $editableMetadata
255  );
256  $adapter = new LayoutMetadataAdapter('AccountEditAndDetailsView',
257  'AccountsModule',
258  $editableMetadata,
260  $attributesLayoutAdapter->getPlaceableLayoutAttributes(),
261  $attributesLayoutAdapter->getRequiredDerivedLayoutAttributeTypes()
262  );
263  $this->assertTrue($adapter->setMetadataFromLayout($layout, array()));
264  $editableMetadataNew = AccountEditAndDetailsView::getMetadata();
265  $this->assertNotEquals($editableMetadataNew, $editableMetadata);
266  $this->assertEquals($editableMetadataNew['global']['panels'], $compareMetadata['panels']);
267  $this->assertEquals('Layout saved successfully.', $adapter->getMessage());
268  }
269 
274  {
275  Yii::app()->user->userModel = User::getByUsername('super');
276 
277  $model = new Account();
278  $modelAttributes = $model->getAttributes();
279  $this->assertTrue(isset($modelAttributes['contacts']));
280  $adapter = new ModelAttributesAdapter($model);
281  $adaptedAttributes = $adapter->getAttributes();
282  $this->assertNotEmpty($adaptedAttributes['createdDateTime']['attributeLabel']);
283  $this->assertNotEmpty($adaptedAttributes['officePhone'] ['attributeLabel']);
284  $this->assertFalse(isset($adaptedAttributes['contacts']));
285  $this->assertTrue(isset($adaptedAttributes['id']));
286  $this->assertTrue(isset($adaptedAttributes['id']['attributeLabel']));
287  $this->assertEquals('Id', $adaptedAttributes['id']['attributeLabel']);
288  }
289 
294  {
295  Yii::app()->user->userModel = User::getByUsername('super');
296 
297  $layout = array('panels' => array());
298  $model = new Account();
299  $modelAttributesAdapter = new ModelAttributesAdapter($model);
300  $editableMetadata = AccountsListView::getMetadata();
302  $modelAttributesAdapter->getAttributes(),
303  new ListViewDesignerRules(),
304  $editableMetadata
305  );
306  $adapter = new LayoutMetadataAdapter('AccountsListView',
307  'AccountsModule',
308  $editableMetadata,
309  new ListViewDesignerRules(),
310  $attributesLayoutAdapter->getPlaceableLayoutAttributes(),
311  $attributesLayoutAdapter->getRequiredDerivedLayoutAttributeTypes()
312  );
313  $this->assertFalse($adapter->setMetadataFromLayout($layout, array()));
314  $this->assertNotEmpty($adapter->getMessage());
315  }
316 
321  {
322  Yii::app()->user->userModel = User::getByUsername('super');
323 
324  $layout = array('panels' =>
325  array(
326  array(
327  'rows' => array(
328  array(
329  'cells' => array(
330  array('element' => 'officePhone'),
331  ),
332  ),
333  )
334  )
335  )
336  );
337  $model = new Account();
338  $modelAttributesAdapter = new ModelAttributesAdapter($model);
339  $editableMetadata = AccountEditAndDetailsView::getMetadata();
341  $modelAttributesAdapter->getAttributes(),
343  $editableMetadata
344  );
345  $adapter = new LayoutMetadataAdapter('AccountEditAndDetailsView',
346  'AccountsModule',
347  $editableMetadata,
349  $attributesLayoutAdapter->getPlaceableLayoutAttributes(),
350  $attributesLayoutAdapter->getRequiredDerivedLayoutAttributeTypes()
351  );
352  $this->assertFalse($adapter->setMetadataFromLayout($layout, array()));
353  $this->assertNotEmpty($adapter->getMessage());
354  $this->assertEquals($adapter->getMessage(), 'All required fields must be placed in this layout.');
355  }
356 
361  {
362  $layout = array('panels' =>
363  array(
364  array(
365  'rows' => array(
366  array(
367  'cells' => array(
368  array('element' => 'username'),
369  ),
370  ),
371  )
372  )
373  )
374  );
375  $layout2 = array('panels' =>
376  array(
377  array(
378  'rows' => array(
379  array(
380  'cells' => array(
381  array('element' => 'TitleFullName'),
382  ),
383  ),
384  array(
385  'cells' => array(
386  array('element' => 'username'),
387  ),
388  ),
389  )
390  )
391  )
392  );
393  $model = new User();
394  $editableMetadata = UserCreateView::getMetadata();
395  $modelAttributesAdapter = new ModelAttributesAdapter($model);
397  $modelAttributesAdapter->getAttributes(),
399  $editableMetadata
400  );
401  $adapter = new LayoutMetadataAdapter('UserCreateView',
402  'UsersModule',
403  $editableMetadata,
405  $attributesLayoutAdapter->getPlaceableLayoutAttributes(),
406  $attributesLayoutAdapter->getRequiredDerivedLayoutAttributeTypes()
407  );
408  $this->assertFalse($adapter->setMetadataFromLayout($layout, array()));
409  $this->assertNotEmpty($adapter->getMessage());
410  $this->assertEquals($adapter->getMessage(), 'All required fields must be placed in this layout.');
411  $this->assertTrue($adapter->setMetadataFromLayout($layout2, array()));
412  }
413 
418  {
419  Yii::app()->user->userModel = User::getByUsername('super');
420 
421  //First create a dependency
422  $mappingData = array(array('attributeName' => 'type'),
423  array('attributeName' => 'officePhone',
424  'valuesToParentValues' =>
425  array('b1' => 'a1',
426  'b2' => 'a2',
427  'b3' => 'a3',
428  'b4' => 'a4'
429  )));
431  $metadata->setScenario('nonAutoBuild');
432  $metadata->name = 'aName';
433  $metadata->modelClassName = 'Account';
434  $metadata->serializedMetadata = serialize(array('attributeLabels' => array('a' => 'b'),
435  'mappingData' => $mappingData));
436  $this->assertTrue($metadata->save());
437 
438  $layout = array('panels' =>
439  array(
440  array(
441  'rows' => array(
442  array(
443  'cells' => array(
444  array('element' => 'aName'),
445  ),
446  ),
447  array(
448  'cells' => array(
449  array('element' => 'type'),
450  ),
451  ),
452  array(
453  'cells' => array(
454  array('element' => 'officeFax'),
455  ),
456  ),
457  array(
458  'cells' => array(
459  array('element' => 'employees'),
460  ),
461  ),
462  )
463  )
464  )
465  );
466  $model = new Account();
467  $editableMetadata = AccountEditAndDetailsView::getMetadata();
468  $modelAttributesAdapter = new ModelAttributesAdapter($model);
470  $modelAttributesAdapter->getAttributes(),
472  $editableMetadata
473  );
474 
475  $adapter = new LayoutMetadataAdapter('AccountEditAndDetailsView',
476  'AccountsModule',
477  $editableMetadata,
479  $attributesLayoutAdapter->getPlaceableLayoutAttributes(),
480  $attributesLayoutAdapter->getRequiredDerivedLayoutAttributeTypes()
481  );
482  $x = $adapter->setMetadataFromLayout($layout, array());
483  $this->assertFalse($adapter->setMetadataFromLayout($layout, array()));
484  $this->assertEquals($adapter->getMessage(), 'All required fields must be placed in this layout.');
485  }
486 
490  public function testMakeLayoutAttributes()
491  {
492  Yii::app()->user->userModel = User::getByUsername('super');
493 
494  $adapter = new ModelAttributesAdapter(new Account());
495  $adaptedAttributes = $adapter->getAttributes();
496  $metadata = array();
497  $metadata['global']['panels'][] = array(
498  'rows' => array(
499  array('cells' =>
500  array(
501  array(
502  'elements' => array(
503  array('attributeName' => 'name', 'type' => 'Text'),
504  ),
505  ),
506  array(
507  'elements' => array(
508  array('attributeName' => 'officePhone', 'type' => 'Phone'),
509  ),
510  ),
511  )
512  ),
513  array('cells' =>
514  array(
515  array(
516  'elements' => array(
517  array('attributeName' => 'owner', 'type' => 'User'),
518  ),
519  ),
520  array(
521  'elements' => array(
522  array('attributeName' => null, 'type' => 'Null'), // Not Coding Standard
523  ),
524  ),
525  )
526  ),
527  ),
528  );
530  $adaptedAttributes,
532  $metadata
533  );
534  $designerLayoutAdapter = $attributeLayoutAdapter->makeDesignerLayoutAttributes();
535  $this->assertEquals(count($designerLayoutAdapter->get()), count($adaptedAttributes));
536  $attributeName = $designerLayoutAdapter->getByAttributeNameAndType('name', 'Text');
537  $this->assertFalse($attributeName['availableToSelect']);
538  $this->assertEquals($attributeName['attributeIdPrefix'], 'name');
539  $attributeFax = $designerLayoutAdapter->getByAttributeNameAndType('officeFax', 'Phone');
540  $this->assertTrue($attributeFax['availableToSelect']);
541  $this->assertEquals($attributeFax['attributeIdPrefix'], 'officeFax');
542  }
543 
548  {
549  $editableListViewMetadata = AccountsListView::getMetadata();
550  $editableEditViewMetadata = AccountEditAndDetailsView::getMetadata();
551  $listViewDesignerRules = new ListViewDesignerRules();
552  $editViewDesignerRules = new EditAndDetailsViewDesignerRules();
553  $formattedMetadata = $listViewDesignerRules->formatEditableMetadataForLayoutParsing($editableListViewMetadata);
554  $this->assertEquals($formattedMetadata, $editableListViewMetadata);
555  $this->assertNotEmpty($formattedMetadata['global']['panels'][0]['rows'][0]);
556  $formattedMetadata = $editViewDesignerRules->formatEditableMetadataForLayoutParsing($editableEditViewMetadata);
557  $this->assertNotEquals($formattedMetadata, $editableEditViewMetadata);
558  }
559 
563  public function testGetStandardAttributes()
564  {
565  Yii::app()->user->userModel = User::getByUsername('super');
566 
567  $account = new Account();
568  $adapter = new ModelAttributesAdapter($account);
569  $attributes = $adapter->getStandardAttributes();
570  $this->assertEquals(21, count($attributes));
571  $this->assertEquals('Name', $attributes['name'] ['attributeLabel']);
572  $this->assertEquals('Industry', $attributes['industry'] ['attributeLabel']);
573  $this->assertEquals('Type', $attributes['type'] ['attributeLabel']);
574  $this->assertEquals('Latest Activity Date Time', $attributes['latestActivityDateTime']['attributeLabel']);
575 
576  $this->assertEquals('Text', $attributes['name'] ['elementType']);
577  $this->assertEquals('DropDown', $attributes['industry'] ['elementType']);
578  $this->assertEquals('DropDown', $attributes['type'] ['elementType']);
579  $this->assertEquals('DateTime', $attributes['latestActivityDateTime']['elementType']);
580  $this->assertEquals('Account', $attributes['account'] ['elementType']);
581 
582  $this->assertTrue(!isset($attributes['notes']));
583  }
584 
589  {
590  Yii::app()->user->userModel = User::getByUsername('super');
591 
592  $account = new Account();
593  $adapter = new ModelAttributesAdapter($account);
594  $attributes = $adapter->getCustomAttributes();
595  $this->assertEquals(0, count($attributes));
596  }
597 
602  {
603  Yii::app()->user->userModel = User::getByUsername('super');
604 
605  $account = new Account();
606  $attributeForm = AttributesFormFactory::createAttributeFormByAttributeName($account, 'name');
607  $this->assertTrue($attributeForm instanceof TextAttributeForm);
608  $this->assertEquals('name', $attributeForm->attributeName);
609  $compareAttributeLabels = array(
610  'de' => 'Name',
611  'en' => 'Name',
612  'es' => 'Nombre',
613  'fr' => 'Nom',
614  'it' => 'Nome',
615  );
616  $this->assertEquals($compareAttributeLabels, $attributeForm->attributeLabels);
617  $this->assertEquals(64, $attributeForm->maxLength);
618  $this->assertEquals(true, $attributeForm->isRequired);
619  $this->assertEquals(true, $attributeForm->isAudited);
620  $this->assertEquals(null, $attributeForm->defaultValue);
621  $this->assertEquals(true, $attributeForm->isAudited);
622 
623  $attributeForm = AttributesFormFactory::createAttributeFormByAttributeName($account, 'officePhone');
624  $this->assertTrue($attributeForm instanceof PhoneAttributeForm);
625  $attributeForm = AttributesFormFactory::createAttributeFormByAttributeName($account, 'description');
626  $this->assertTrue($attributeForm instanceof TextAreaAttributeForm);
627  $attributeForm = AttributesFormFactory::createAttributeFormByAttributeName($account, 'industry');
628  $this->assertTrue($attributeForm instanceof DropDownAttributeForm);
629  $attributeForm = AttributesFormFactory::createAttributeFormByAttributeName($account, 'owner');
630  $this->assertTrue($attributeForm instanceof UserAttributeForm);
631  $attributeForm = AttributesFormFactory::createAttributeFormByAttributeName($account, 'createdDateTime');
632  $this->assertTrue($attributeForm instanceof DateTimeAttributeForm);
633  $attributeForm = AttributesFormFactory::createAttributeFormByAttributeName($account, 'modifiedDateTime');
634  $this->assertTrue($attributeForm instanceof DateTimeAttributeForm);
635  }
636 
641  {
642  Yii::app()->user->userModel = User::getByUsername('super');
643 
644  $values = array(
645  'Automotive',
646  'Adult Entertainment',
647  'Financial Services',
648  'Mercenaries & Armaments',
649  );
650  $industryFieldData = CustomFieldData::getByName('Industries');
651  $industryFieldData->forget();
652  unset($industryFieldData);
653  $industryFieldData = CustomFieldData::getByName('Industries');
654  $industryFieldData->serializedData = serialize($values);
655  $this->assertTrue($industryFieldData->save());
656 
657  $account = new Account();
658  $attributeForm = new DropDownAttributeForm($account, 'industry');
659  $attributeForm->attributeLabels = array(
660  'de' => 'Industry de',
661  'en' => 'Industry',
662  'es' => 'Industry es',
663  'fr' => 'Industry fr',
664  'it' => 'Industry it',
665  );
666  $attributeForm->isAudited = true;
667  $attributeForm->isRequired = false;
668  $this->assertEquals($values, $attributeForm->customFieldDataData);
669 
670  $modelAttributesAdapterClassName = $attributeForm::getModelAttributeAdapterNameForSavingAttributeFormData();
671  $adapter = new $modelAttributesAdapterClassName(new Account());
672  try
673  {
674  $adapter->setAttributeMetadataFromForm($attributeForm);
675  }
677  {
678  echo $e->getMessage();
679  $this->fail();
680  }
681 
683  $account = new Account();
684  $attributeForm = AttributesFormFactory::createAttributeFormByAttributeName($account, 'industry');
685  $this->assertEquals('industry', $attributeForm->attributeName);
686  $compareAttributeLabels = array(
687  'de' => 'Industry de',
688  'en' => 'Industry',
689  'es' => 'Industry es',
690  'fr' => 'Industry fr',
691  'it' => 'Industry it',
692  );
693  $this->assertEquals($compareAttributeLabels, $attributeForm->attributeLabels);
694  $this->assertEquals(true, $attributeForm->isAudited);
695  $this->assertEquals(false, $attributeForm->isRequired);
696  $this->assertEquals($values, $attributeForm->customFieldDataData);
697  }
698 
703  {
704  Yii::app()->user->userModel = User::getByUsername('super');
705 
706  $account = new Account();
707  $values = unserialize($account->industry->data->serializedData);
708 
709  $attributeForm = AttributesFormFactory::createAttributeFormByAttributeName($account, 'industry');
710  $this->assertTrue($attributeForm instanceof DropDownAttributeForm);
711  $this->assertEquals($values, $attributeForm->customFieldDataData);
712 
713  $modelAttributesAdapterClassName = $attributeForm::getModelAttributeAdapterNameForSavingAttributeFormData();
714  $adapter = new $modelAttributesAdapterClassName(new Account());
715  try
716  {
717  $adapter->setAttributeMetadataFromForm($attributeForm);
718  }
720  {
721  echo $e->getMessage();
722  $this->fail();
723  }
724  // This needs to test some things.
725 
726  $attributeForm = AttributesFormFactory::createAttributeFormByAttributeName($account, 'industry');
727  $this->assertEquals($values, $attributeForm->customFieldDataData);
728  }
729 
734  {
735  Yii::app()->user->userModel = User::getByUsername('super');
736 
737  $adapter = new ModelAttributesAdapter(new Account());
738  $attributes = $adapter->getCustomAttributes();
739  $this->assertEquals(0, count($attributes));
740 
741  $attributeForm = new DropDownAttributeForm();
742  $attributeForm->attributeName = 'testText';
743  $attributeForm->attributeLabels = array(
744  'de' => 'Test Text de',
745  'en' => 'Test Text en',
746  'es' => 'Test Text es',
747  'fr' => 'Test Text fr',
748  'it' => 'Test Text it',
749  );
750  $attributeForm->isAudited = true;
751  $attributeForm->isRequired = false;
752  $attributeForm->customFieldDataName = 'Industries';
753 
754  $modelAttributesAdapterClassName = $attributeForm::getModelAttributeAdapterNameForSavingAttributeFormData();
755  $adapter = new $modelAttributesAdapterClassName(new Account());
756  try
757  {
758  $adapter->setAttributeMetadataFromForm($attributeForm);
759  }
761  {
762  echo $e->getMessage();
763  $this->fail();
764  }
765 
766  $account = new Account();
767  $this->assertTrue($account->isAttribute('testTextCstm'));
768 
769  $adapter = new ModelAttributesAdapter($account);
770  $attributes = $adapter->getCustomAttributes();
771  $this->assertEquals(1, count($attributes));
772  $this->assertEquals('Test Text en', $attributes['testTextCstm']['attributeLabel']);
773  $this->assertEquals('DropDown', $attributes['testTextCstm']['elementType']);
774  }
775 
779  public function testRemoveAttributeByName()
780  {
781  Yii::app()->user->userModel = User::getByUsername('super');
782 
783  ModelMetadataUtil::removeAttribute('Account', 'officePhone');
784  ModelMetadataUtil::removeAttribute('Account', 'doesNotExist');
785 
786  $account = new Account();
787  $this->assertFalse($account->isAttribute('officePhone'));
788  unset($account);
789 
790  $attributeForm = new TextAttributeForm();
791  $attributeForm->attributeName = 'testText2';
792  $attributeForm->attributeLabels = array(
793  'de' => 'Test Text2 de',
794  'en' => 'Test Text2 en',
795  'es' => 'Test Text2 es',
796  'fr' => 'Test Text2 fr',
797  'it' => 'Test Text2 it',
798  );
799  $attributeForm->isAudited = true;
800  $attributeForm->isRequired = false;
801  $attributeForm->maxLength = 60;
802 
803  $modelAttributesAdapterClassName = $attributeForm::getModelAttributeAdapterNameForSavingAttributeFormData();
804  $adapter = new $modelAttributesAdapterClassName(new Account());
805  try
806  {
807  $adapter->setAttributeMetadataFromForm($attributeForm);
808  }
810  {
811  echo $e->getMessage();
812  $this->fail();
813  }
814 
815  $account = new Account();
816  $this->assertTrue ($account->isAttribute('testText2Cstm'));
817  unset($account);
818 
819  $adapter->removeAttributeMetadata('testText2Cstm');
820 
821  $account = new Account();
822  $this->assertFalse($account->isAttribute('testText2Cstm'));
823  unset($account);
824  }
825 
830  {
831  Yii::app()->user->userModel = User::getByUsername('super');
832 
833  $attributeForm = new TextAttributeForm();
834  $attributeForm->attributeName = 'testText2';
835  $attributeForm->attributeLabels = array(
836  'de' => 'Test Text2 de',
837  'en' => 'Test Text2 en',
838  'es' => 'Test Text2 es',
839  'fr' => 'Test Text2 fr',
840  'it' => 'Test Text2 it',
841  );
842  $attributeForm->isAudited = true;
843  $attributeForm->isRequired = false;
844  $attributeForm->maxLength = 60;
845 
846  $modelAttributesAdapterClassName = $attributeForm::getModelAttributeAdapterNameForSavingAttributeFormData();
847  $adapter = new $modelAttributesAdapterClassName(new Account());
848  try
849  {
850  $adapter->setAttributeMetadataFromForm($attributeForm);
851  }
853  {
854  echo $e->getMessage();
855  $this->fail();
856  }
857 
858  $adapter = new ModelAttributesAdapter(new Account());
859  $this->assertFalse($adapter->isStandardAttribute('testText2'));
860  $this->assertTrue($adapter->isStandardAttribute('name'));
861  }
862 
867  {
869  $this->assertTrue($adapter->canUpdateProperty('attributeLabels'));
870  $this->assertTrue($adapter->canUpdateProperty('isRequired'));
871  $this->assertTrue($adapter->canUpdateProperty('isAudited'));
872  $adapter->setUpdateRequiredFieldStatus(false);
873  $this->assertFalse($adapter->canUpdateProperty('isRequired'));
874  $this->assertTrue($adapter->canUpdateProperty('isAudited'));
875  }
876 
881  {
882  $adapter = new ModelAttributesAdapter(new User());
883  $adaptedAttributes = $adapter->getAttributes();
884  $metadata = array();
885  $metadata['global']['panels'] = array();
886  $metadata['global']['derivedAttributeTypes'] = array(
887  'TitleFullName',
888  );
890  $adaptedAttributes,
892  $metadata
893  );
894  $requiredTypes = $attributeLayoutAdapter->getRequiredDerivedLayoutAttributeTypes();
895  $compareTypes = array(
896  'TitleFullName',
897  );
898  $this->assertEquals($compareTypes, $requiredTypes);
899  }
900 
908  {
909  $super = User::getByUsername('super');
910  Yii::app()->user->userModel = $super;
911 
912  //Create account
913  $account = AccountTestHelper::createAccountByNameForOwner('test', $super);
914  $accountId = $account->id;
915  $account->forget();
916 
917  $originalMetadata = Account::getMetadata();
918  $attributeLabels = array('en' => 'newRelation');
919  ModelMetadataUtil::addOrUpdateCustomFieldRelation('Account', 'newRelation', $attributeLabels,
920  null, false, false, 'DropDown', 'Things', array('thing 1', 'thing 2'),
921  array('fr' => array('thing 1 fr', 'thing 2 fr')));
922  $adapter = new ModelAttributesAdapter(new Account());
923  $adapter->resolveDatabaseSchemaForModel('Account');
924  $metadata = Account::getMetadata();
925  $this->assertNotEquals($originalMetadata, $metadata);
926 
927  $this->assertEquals($originalMetadata['Account']['rules'], $metadata['Account']['rules']);
928  $newRelation = $metadata['Account']['relations']['newRelationCstm'];
929  $this->assertEquals(array(RedBeanModel::HAS_ONE, 'OwnedCustomField', RedBeanModel::OWNED,
930  RedBeanModel::LINK_TYPE_SPECIFIC, 'newRelationCstm'), $newRelation);
931  $this->assertEquals('Things', $metadata['Account']['customFields']['newRelationCstm']);
932 
933  //on a new account, does the serialized data show correctly.
934  $account = new Account();
935  $this->assertEquals(array('thing 1', 'thing 2'), unserialize($account->newRelationCstm->data->serializedData));
936 
937  ForgetAllCacheUtil::forgetAllCaches();
938 
939  //retrieve account and make sure the serialized data shows correctly.
940  //This will not be cached.
941  $account = Account::getById($accountId);
942  $this->assertNotNull($account->industry->data->serializedData);
943  $this->assertEquals(array('thing 1', 'thing 2'), unserialize($account->newRelationCstm->data->serializedData));
944 
945  //This will pull from cached. Clear the php cache first, which simulates a new page request without destroying
946  //the persistent cache.
948  $account = Account::getById($accountId);
949 
950  //Test pulling a different CustomField first. This simulates caching the customField
951  $this->assertEquals(array('thing 1', 'thing 2'), unserialize($account->newRelationCstm->data->serializedData));
952  }
953 
958  {
959  Yii::app()->user->userModel = User::getByUsername('super');
960  $account = new Account();
961 
962  //Name for example, is required by default.
963  $adapter = new ModelAttributesAdapter($account);
964  $this->assertTrue($adapter->isStandardAttributeRequiredByDefault('name'));
965 
966  //Industry is not required by default.
967  $adapter = new DropDownModelAttributesAdapter($account);
968  $this->assertFalse($adapter->isStandardAttributeRequiredByDefault('industry'));
969 
970  $attributeForm = AttributesFormFactory::createAttributeFormByAttributeName($account, 'industry');
971  $this->assertFalse($attributeForm->isRequired);
972  $this->assertTrue($attributeForm->canUpdateAttributeProperty('isRequired'));
973 
974  //Now make industry required.
975  $attributeForm->isRequired = true;
976 
977  $modelAttributesAdapterClassName = $attributeForm::getModelAttributeAdapterNameForSavingAttributeFormData();
978  $adapter = new $modelAttributesAdapterClassName(new Account());
979  try
980  {
981  $adapter->setAttributeMetadataFromForm($attributeForm);
982  }
984  {
985  echo $e->getMessage();
986  $this->fail();
987  }
989 
990  $account = new Account();
991  $adapter = new DropDownModelAttributesAdapter($account);
992  $this->assertFalse($adapter->isStandardAttributeRequiredByDefault('industry'));
993  $attributeForm = AttributesFormFactory::createAttributeFormByAttributeName($account, 'industry');
994  $this->assertTrue($attributeForm->isRequired);
995  $this->assertTrue($attributeForm->canUpdateAttributeProperty('isRequired'));
996  }
997 
1002  {
1003  Yii::app()->user->userModel = User::getByUsername('super');
1004  //Testing an attribute that is not on the specified model, but requires a casting up.
1005  $contact = new Contact();
1006  $adapter = new ModelAttributesAdapter($contact);
1007  $this->assertTrue($adapter->isStandardAttributeRequiredByDefault('lastName'));
1008  }
1009 
1014  {
1015  Yii::app()->user->userModel = User::getByUsername('super');
1016 
1017  $education = array(
1018  'aaaa',
1019  'bbbb',
1020  );
1021  $education_labels = array('fr' => array('aaaa fr', 'bbbb fr'),
1022  'de' => array('aaaa de', 'bbbb de'),
1023  );
1024  $educationFieldData = CustomFieldData::getByName('Education');
1025  $educationFieldData->serializedData = serialize($education);
1026  $this->assertTrue($educationFieldData->save());
1027 
1028  $attributeForm = new DropDownAttributeForm();
1029  $attributeForm->attributeName = 'testEducation';
1030  $attributeForm->attributeLabels = array(
1031  'de' => 'Test Education 2 de',
1032  'en' => 'Test Education 2 en',
1033  'es' => 'Test Education 2 es',
1034  'fr' => 'Test Education 2 fr',
1035  'it' => 'Test Education 2 it',
1036  );
1037  $attributeForm->isAudited = true;
1038  $attributeForm->isRequired = false;
1039  $attributeForm->customFieldDataData = $education;
1040  $attributeForm->customFieldDataName = 'Education';
1041  $attributeForm->customFieldDataLabels = $education_labels;
1042 
1043  $modelAttributesAdapterClassName = $attributeForm::getModelAttributeAdapterNameForSavingAttributeFormData();
1044  $adapter = new $modelAttributesAdapterClassName(new Account());
1045  try
1046  {
1047  $adapter->setAttributeMetadataFromForm($attributeForm);
1048  }
1050  {
1051  echo $e->getMessage();
1052  $this->fail();
1053  }
1054 
1055  $stream = array(
1056  'aaa1',
1057  'aaa2',
1058  'bbb1',
1059  'bbb2',
1060  );
1061  $stream_labels = array('fr' => array('aaa1 fr', 'aaa2 fr', 'bbb1 fr', 'bbb2 fr'),
1062  'de' => array('aaa1 de', 'aaa2 de', 'bbb1 de', 'bbb2 de'),
1063  );
1064  $streamFieldData = CustomFieldData::getByName('Stream');
1065  $streamFieldData->serializedData = serialize($stream);
1066  $this->assertTrue($streamFieldData->save());
1067 
1068  $attributeForm = new DropDownAttributeForm();
1069  $attributeForm->attributeName = 'testStream';
1070  $attributeForm->attributeLabels = array(
1071  'de' => 'Test Stream 2 de',
1072  'en' => 'Test Stream 2 en',
1073  'es' => 'Test Stream 2 es',
1074  'fr' => 'Test Stream 2 fr',
1075  'it' => 'Test Stream 2 it',
1076  );
1077  $attributeForm->isAudited = true;
1078  $attributeForm->isRequired = true;
1079  $attributeForm->customFieldDataData = $stream;
1080  $attributeForm->customFieldDataName = 'Stream';
1081  $attributeForm->customFieldDataLabels = $stream_labels;
1082 
1083  $modelAttributesAdapterClassName = $attributeForm::getModelAttributeAdapterNameForSavingAttributeFormData();
1084  $adapter = new $modelAttributesAdapterClassName(new Account());
1085  try
1086  {
1087  $adapter->setAttributeMetadataFromForm($attributeForm);
1088  }
1090  {
1091  echo $e->getMessage();
1092  $this->fail();
1093  }
1094 
1095  $attributeName = "testQualification";
1096  $attributeForm = new DropDownDependencyAttributeForm();
1097  $attributeForm->attributeName = $attributeName;
1098  $attributeForm->attributeLabels = array(
1099  'de' => 'Test Qualification Value 2 de',
1100  'en' => 'Test Qualification Value 2 en',
1101  'es' => 'Test Qualification Value 2 es',
1102  'fr' => 'Test Qualification Value 2 fr',
1103  'it' => 'Test Qualification Value 2 it',
1104  );
1105  $attributeForm->mappingData = array(
1106  array('attributeName' => 'testEducation'),
1107  array('attributeName' => 'testStream',
1108  'valuesToParentValues' => array('aaa1' => 'aaaa',
1109  'aaa2' => 'aaaa',
1110  'bbb1' => 'bbbb',
1111  'bbb2' => 'bbbb'
1112  )));
1113 
1114  $modelAttributesAdapterClassName = $attributeForm::getModelAttributeAdapterNameForSavingAttributeFormData();
1115  $adapter = new $modelAttributesAdapterClassName(new Account());
1116  try
1117  {
1118  $adapter->setAttributeMetadataFromForm($attributeForm);
1119  }
1121  {
1122  echo $e->getMessage();
1123  $this->fail();
1124  }
1125 
1126  $layout = array('panels' =>
1127  array(
1128  array(
1129  'rows' => array(
1130  array('cells' =>
1131  array(
1132  array(
1133  'element' => 'createdDateTime',
1134  ),
1135  array(
1136  'element' => 'modifiedDateTime',
1137  ),
1138  )
1139  ),
1140  array('cells' =>
1141  array(
1142  array(
1143  'element' => 'owner',
1144  ),
1145  array(
1146  'element' => 'name',
1147  ),
1148  )
1149  ),
1150  array('cells' =>
1151  array(
1152  array(
1153  'element' => 'industry',
1154  ),
1155  )
1156  ),
1157  )
1158  )
1159  )
1160  );
1161  $layout2 = array('panels' =>
1162  array(
1163  array(
1164  'rows' => array(
1165  array('cells' =>
1166  array(
1167  array(
1168  'element' => 'createdDateTime',
1169  ),
1170  array(
1171  'element' => 'modifiedDateTime',
1172  ),
1173  )
1174  ),
1175  array('cells' =>
1176  array(
1177  array(
1178  'element' => 'owner',
1179  ),
1180  array(
1181  'element' => 'name',
1182  ),
1183  )
1184  ),
1185  array('cells' =>
1186  array(
1187  array(
1188  'element' => 'industry',
1189  ),
1190  )
1191  ),
1192  array('cells' =>
1193  array(
1194  array(
1195  'element' => 'testEducationCstm',
1196  ),
1197  array(
1198  'element' => 'testStreamCstm',
1199  ),
1200  )
1201  ),
1202  )
1203  )
1204  )
1205  );
1206 
1207  $model = new Account();
1208  $editableMetadata = AccountEditAndDetailsView::getMetadata();
1209  $modelAttributesAdapter = new ModelAttributesAdapter($model);
1211  $modelAttributesAdapter->getAttributes(),
1213  $editableMetadata
1214  );
1215 
1216  $adapter = new LayoutMetadataAdapter('AccountEditAndDetailsView',
1217  'AccountsModule',
1218  $editableMetadata,
1220  $attributesLayoutAdapter->getPlaceableLayoutAttributes(),
1221  $attributesLayoutAdapter->getRequiredDerivedLayoutAttributeTypes()
1222  );
1223 
1224  $this->assertFalse($adapter->setMetadataFromLayout($layout, array()));
1225  $this->assertNotEmpty($adapter->getMessage());
1226  $this->assertEquals($adapter->getMessage(), 'All required fields must be placed in this layout.');
1227  $this->assertTrue($adapter->setMetadataFromLayout($layout2, array()));
1228  $this->assertEquals($adapter->getMessage(), 'Layout saved successfully.');
1229  }
1230  }
1231 ?>
testExistingAttributeWillAlwaysSaveAsValidLength()
testGetRequiredDerivedLayoutAttributeTypes()
testGetModelAttributesAdapter()
testSetMetadataFromLayoutWithOutRequiredField()
static getMetadata()
static getByUsername($username)
Definition: User.php:49
static addOrUpdateCustomFieldRelation($modelClassName, $relationName, $attributeLabels, $defaultValue, $isRequired, $isAudited, $elementType, $customFieldDataName, $customFieldDataData=null, $customFieldDataLabels=null, $relationModelClassName= 'OwnedCustomField', $owned=true)
Definition: User.php:37
static forgetAll($onlyForgetPhpCache=false)
testGetStandardAttributes()
testSetMetadataFormLayoutWithAndWithOutRequiredCustomFieldForDropDownDependencyAttribute()
testSetAndGetCustomAttributes()
testSetMetadataFromLayoutWithOutPanels()
testAttributePropertyFormAdapterCanUpdateProperty()
const OWNED
Definition: BeanModel.php:87
static makeAttributesLayoutAdapter($attributeCollection, DesignerRules $designerRules, $editableMetadata)
static forgetAll()
const HAS_ONE
Definition: BeanModel.php:64
testSetMetadataFromLayoutWithAndWithOutRequiredDerivedField()
testExistingModelsShowCustomFieldDataCorrectlyWhenAttributeIsAddedAsDatabaseColumn()
testSetNewAttributeFromAttributeForm()
Definition: Task.php:37
testFormatEditableMetadataForLayoutParsing()
testMakeLayoutAttributes()
testMakeAttributeFormByAttributeName()
static getByName($name, $shouldCache=true)
testSetMetadataFromLayoutWithAndWithOutOnlyUniqueFields()
testResolveMetadataFromSelectedListAttributes()
testSetMetadataFromLayout()
static getById($id, $modelClassName=null)
setMetadataFromLayout($layout, $savableMetadata)
testIsStandardAttributeRequiredByDefault()
testStandardAttributeThatBecomesRequiredCanStillBeChangedToBeUnrequired()
testGetCustomAttributesWhenThereArentAny()
static removeAttribute($modelClassName, $attributeName)
testModelAttributesAdapterIsStandardAttribute()
testSetStandardDropDownAttributeFromAttributeForm()
static getMetadata()
testRemoveAttributeByName()
Generated on Thu Aug 6 2020 07:10:30
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.