All Data Structures Functions Variables Pages
ListViewMergeUtilBaseTest.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 $selectedModels = array();
40 
41  public $modelClass;
42 
43  public static function setUpBeforeClass()
44  {
45  parent::setUpBeforeClass();
46  SecurityTestHelper::createSuperAdmin();
47  }
48 
49  protected function processSetPrimaryModelForListViewMerge()
50  {
51  Yii::app()->user->userModel = User::getByUsername('super');
52  $this->setFirstModel();
53  $this->setSecondModel();
54  $modelsList = ListViewMergeUtil::getSelectedModelsListForMerge($this->modelClass,
55  array('selectedIds' => $this->selectedModels[0]->id .
56  ',' . // Not Coding Standard
57  $this->selectedModels[1]->id));
58  $formModel = new ModelsListDuplicateMergedModelForm();
59  $formModel->selectedModels = $modelsList;
61  array('primaryModelId' => $this->selectedModels[0]->id));
62  $this->primaryModel = $formModel->primaryModel;
63  $this->assertEquals($this->selectedModels[0]->id, $formModel->primaryModel->id);
64  }
65 
66  protected function runProcessCopyRelationsAndDeleteNonPrimaryModelsInMerge()
67  {
68  Yii::app()->user->userModel = User::getByUsername('super');
69  $this->setSelectedModels();
70  $this->setRelatedModels();
72  array('selectedIds' => $this->selectedModels[0]->id .
73  ',' . // Not Coding Standard
74  $this->selectedModels[1]->id));
75  $this->validatePrimaryModelData();
76  }
77 
78  protected function getPrimaryModel()
79  {
80  return $this->selectedModels[0];
81  }
82 
83  protected function validateActivityItem($activityModelClass, $activityName, $relationClassName, $relationFieldName, $relationFieldValue)
84  {
85  $this->checkActivityItemRelationCount($activityModelClass, $activityName, 1);
86  $activities = $activityModelClass::getByName($activityName);
87  $relationClass = $activities[0]->activityItems->offsetGet(0);
88  $this->assertEquals(get_class($relationClass), $relationClassName);
89  $this->assertEquals($relationFieldValue, $relationClass->$relationFieldName);
90  }
91 
92  protected function checkActivityItemRelationCount($activityModelClass, $activityName, $count)
93  {
94  $activities = $activityModelClass::getByName($activityName);
95  $this->assertCount($count, $activities);
96  }
97 
98  protected function addProject($relatedFieldName)
99  {
100  $primaryModel = $this->getPrimaryModel();
101  $this->assertEquals(0, count($primaryModel->projects));
102  $project = ProjectTestHelper::createProjectByNameForOwner($this->modelClass . ' Project', Yii::app()->user->userModel);
103  $project->$relatedFieldName->add($this->selectedModels[1]);
104  $saved = $project->save();
105  assert('$saved'); // Not Coding Standard
106  }
107 
108  protected function validateProject()
109  {
110  $primaryModel = $this->getPrimaryModel();
111  $this->assertEquals(1, count($primaryModel->projects));
112  $project = $primaryModel->projects[0];
113  $this->assertEquals($this->modelClass . ' Project', $project->name);
114  }
115 
116  protected function addProduct($relatedFieldName)
117  {
118  $primaryModel = $this->getPrimaryModel();
119  $this->assertEquals(0, count($primaryModel->products));
120  $product = ProductTestHelper::createProductByNameForOwner($this->modelClass . ' Product', Yii::app()->user->userModel);
121  $product->$relatedFieldName = $this->selectedModels[1];
122  $saved = $product->save();
123  assert('$saved'); // Not Coding Standard
124  }
125 
126  protected function validateProduct()
127  {
128  $primaryModel = $this->getPrimaryModel();
129  $this->assertEquals(1, count($primaryModel->products));
130  $product = $primaryModel->products[0];
131  $this->assertEquals($this->modelClass . ' Product', $product->name);
132  }
133 
134  protected function addMeeting()
135  {
136  $this->checkActivityItemRelationCount('Meeting', 'First Meeting', 0);
137  MeetingTestHelper::createMeetingWithOwnerAndRelatedAccount('First Meeting', Yii::app()->user->userModel, $this->selectedModels[1]);
138  }
139 
140  protected function validateMeeting($fieldName, $fieldValue)
141  {
142  $this->validateActivityItem('Meeting', 'First Meeting', $this->modelClass, $fieldName, $fieldValue);
143  }
144 
145  protected function addNote()
146  {
147  $this->checkActivityItemRelationCount('Note', 'First Note', 0);
148  NoteTestHelper::createNoteWithOwnerAndRelatedAccount('First Note', Yii::app()->user->userModel, $this->selectedModels[1]);
149  }
150 
151  protected function validateNote($fieldName, $fieldValue)
152  {
153  $this->validateActivityItem('Note', 'First Note', $this->modelClass, $fieldName, $fieldValue);
154  }
155 
156  protected function addTask()
157  {
158  $this->checkActivityItemRelationCount('Task', 'First Task', 0);
159  TaskTestHelper::createTaskWithOwnerAndRelatedAccount('First Task', Yii::app()->user->userModel, $this->selectedModels[1]);
160  }
161 
162  protected function validateTask($fieldName, $fieldValue)
163  {
164  $this->validateActivityItem('Task', 'First Task', $this->modelClass, $fieldName, $fieldValue);
165  }
166 
167  protected function processResolveFormLayoutMetadataForOneColumnDisplay()
168  {
169  $modelClass = $this->modelClass;
170  $viewClassName = $modelClass . 'sMergedEditAndDetailsView';
171  $layoutMetadata = ListViewMergeUtil::resolveFormLayoutMetadataForOneColumnDisplay($viewClassName::getMetadata());
172  $rows = $layoutMetadata['global']['panels'][0]['rows'];
173  $modifiedElementsData = array();
174  foreach ($rows as $row)
175  {
176  $modifiedElementsData[] = $row['cells'][0]['elements'][0];
177  }
178  if ($this->modelClass == 'Contact')
179  {
180  $this->assertEquals('title', $modifiedElementsData[0]['attributeName']);
181  $this->assertEquals('DropDown', $modifiedElementsData[0]['type']);
182 
183  $this->assertEquals('firstName', $modifiedElementsData[1]['attributeName']);
184  $this->assertEquals('Text', $modifiedElementsData[1]['type']);
185 
186  $this->assertEquals('lastName', $modifiedElementsData[2]['attributeName']);
187  $this->assertEquals('Text', $modifiedElementsData[2]['type']);
188  }
189  }
190  }
191 ?>
static processCopyRelationsAndDeleteNonPrimaryModelsInMerge($primaryModel, $getData)
static getSelectedModelsListForMerge($modelClassName, $getData)
static getByUsername($username)
Definition: User.php:49
static setPrimaryModelForListViewMerge($model, $getData)
static resolveFormLayoutMetadataForOneColumnDisplay($metadata)
Generated on Sun May 24 2020 07:10:37