All Data Structures Functions Variables Pages
TasksUtilTest.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 function setUpBeforeClass()
40  {
41  parent::setUpBeforeClass();
42  SecurityTestHelper::createSuperAdmin();
43  $super = User::getByUsername('super');
44  Yii::app()->user->userModel = $super;
45  TaskTestHelper::createTaskByNameForOwner('My Task', $super);
46  AccountTestHelper::createAccountByNameForOwner('anAccount', $super);
47  }
48 
49  public function setUp()
50  {
51  parent::setUp();
52  Yii::app()->user->userModel = User::getByUsername('super');
53  }
54 
59  {
60  Yii::app()->user->userModel = User::getByUsername('super');
61  $mark = UserTestHelper::createBasicUser('mark');
62  $user = UserTestHelper::createBasicUser('steven');
63 
64  $task = new Task();
65  $task->name = 'MyTest';
66  $this->assertTrue($task->save());
67 
68  $task->requestedByUser = $user;
69  $this->assertTrue($task->save());
70  $explicitReadWriteModelPermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem($task);
71  $this->assertEquals($explicitReadWriteModelPermissions->getReadWritePermitablesCount(), 0);
72  TasksUtil::resolveExplicitPermissionsForRequestedByUser($task, $mark, $user, $explicitReadWriteModelPermissions);
73  $this->assertEquals($explicitReadWriteModelPermissions->getReadWritePermitablesCount(), 1);
74  $this->assertEquals($explicitReadWriteModelPermissions->getReadWritePermitablesToRemoveCount(), 1);
75  }
76 
80  public function testGetModalDetailsTitle()
81  {
83  $this->assertEquals('Collaborate On This Task', $title);
84  }
85 
90  {
92  $this->assertEquals('Create Task', $title);
93 
95  $this->assertEquals('Edit Task', $title);
96 
98  $this->assertEquals('Copy Task', $title);
99  }
100 
104  public function testGetModalEditTitle()
105  {
106  $title = TasksUtil::getModalEditTitle();
107  $this->assertEquals('Edit Task', $title);
108  }
109 
114  {
115  $kanbanItemType = TasksUtil::resolveKanbanItemTypeForTaskStatus(Task::STATUS_AWAITING_ACCEPTANCE);
116  $this->assertEquals(KanbanItem::TYPE_IN_PROGRESS, $kanbanItemType);
117 
118  $kanbanItemType = TasksUtil::resolveKanbanItemTypeForTaskStatus(Task::STATUS_NEW);
119  $this->assertEquals(KanbanItem::TYPE_SOMEDAY, $kanbanItemType);
120  }
121 
126  {
127  $tasks = Task::getByName('MyTest');
128  $task = $tasks[0];
129  $checkListItem = new TaskCheckListItem();
130  $checkListItem->name = 'Test Item 1';
131  $this->assertTrue($checkListItem->unrestrictedSave());
132  $task->checkListItems->add($checkListItem);
133  $task->save(false);
134 
135  $checkListItem = new TaskCheckListItem();
136  $checkListItem->name = 'Test Item 2';
137  $checkListItem->completed = true;
138  $this->assertTrue($checkListItem->unrestrictedSave());
139  $task->checkListItems->add($checkListItem);
140  $task->save(false);
141 
142  $this->assertEquals(2, count($task->checkListItems));
143  $percent = TasksUtil::getTaskCompletionPercentage($task);
144  $this->assertEquals(50, $percent);
145  }
146 
151  {
152  $status = TasksUtil::getDefaultTaskStatusForKanbanItemType(KanbanItem::TYPE_SOMEDAY);
153  $this->assertEquals(Task::STATUS_NEW, $status);
154  }
155 
160  {
161  $task = TaskTestHelper::createTaskByNameForOwner('My Kanban Task', Yii::app()->user->userModel);
162  $task->status = Task::STATUS_IN_PROGRESS;
163  $accounts = Account::getByName('anAccount');
164  $task->activityItems->add($accounts[0]);
165  $this->assertTrue($task->save());
166  $kanbanItem = TasksUtil::createKanbanItemFromTask($task);
167  $this->assertEquals($kanbanItem->type, KanbanItem::TYPE_IN_PROGRESS);
168  }
169 
174  {
175  $tasks = Task::getByName('MyTest');
176  $task = $tasks[0];
177  $this->assertEquals(2, count($task->checkListItems));
179  $this->assertContains('completion-percentage-bar', $content);
180  }
181 
186  {
187  $tasks = Task::getByName('MyTest');
188  $task = $tasks[0];
189  $this->assertEquals(2, count($task->checkListItems));
191  $this->assertEquals(1, $count);
192  }
193 
198  {
199  $tasks = Task::getByName('MyTest');
200  $task = $tasks[0];
201  $content = TasksUtil::renderCompletionDateTime($task);
202  $this->assertContains('Completed On:', $content);
203  }
204 
209  {
210  Yii::app()->user->userModel = User::getByUsername('super');
211  $accounts = Account::getByName('anAccount');
212 
213  $user = UserTestHelper::createBasicUser('Tilly');
214  $dueStamp = DateTimeUtil::convertTimestampToDbFormatDateTime(time() + 10000);
215  $task = new Task();
216  $task->name = 'MyFirstRelatedTask';
217  $task->owner = $user;
218  $task->requestedByUser = $user;
219  $task->dueDateTime = $dueStamp;
220  $task->activityItems->add($accounts[0]);
221  $this->assertTrue($task->save());
222  $id = $task->id;
223  unset($task);
224  $task = Task::getById($id);
225  $model = TasksUtil::resolveFirstRelatedModel($task);
226  $this->assertEquals('anAccount', $model->name);
227  }
228 
235  {
236  Yii::app()->user->userModel = User::getByUsername('super');
237  $project = ProjectTestHelper::createProjectByNameForOwner('MyRelatedProject', Yii::app()->user->userModel);
238  $dueStamp = DateTimeUtil::convertTimestampToDbFormatDateTime(time() + 10000);
239  $task = new Task();
240  $task->name = 'MyFirstRelatedTask';
241  $task->dueDateTime = $dueStamp;
242  $task->project = $project;
243  $this->assertTrue($task->save());
244  $id = $task->id;
245  unset($task);
246  $task = Task::getById($id);
247  $model = TasksUtil::resolveFirstRelatedModel($task);
248  $this->assertEquals('MyRelatedProject', $model->name);
250  $this->assertEquals('MyRelatedProject', $content);
251  }
252 
257  public function testSortKanbanColumnItems()
258  {
259  Yii::app()->user->userModel = User::getByUsername('super');
260  $project = ProjectTestHelper::createProjectByNameForOwner('MyKanbanProject', Yii::app()->user->userModel);
261  $dueStamp = DateTimeUtil::convertTimestampToDbFormatDateTime(time() + 10000);
262 
263  //First kanban task
264  $task = TaskTestHelper::createTaskByNameWithProjectAndStatus('MyFirstKanbanTask',
265  Yii::app()->user->userModel,
266  $project,
267  Task::STATUS_IN_PROGRESS);
268  $kanbanItem1 = KanbanItem::getByTask($task->id);
269  $this->assertEquals(KanbanItem::TYPE_IN_PROGRESS, $kanbanItem1->type);
270  $this->assertEquals($task->project->id, $kanbanItem1->kanbanRelatedItem->id);
271  $task2 = TaskTestHelper::createTaskByNameWithProjectAndStatus('MySecondKanbanTask',
272  Yii::app()->user->userModel,
273  $project,
274  Task::STATUS_IN_PROGRESS);
275  $kanbanItem2 = KanbanItem::getByTask($task2->id);
276  $this->assertEquals(KanbanItem::TYPE_IN_PROGRESS, $kanbanItem2->type);
277  $this->assertEquals($task2->project->id, $kanbanItem2->kanbanRelatedItem->id);
278  $task3 = TaskTestHelper::createTaskByNameWithProjectAndStatus('MyThirdKanbanTask',
279  Yii::app()->user->userModel,
280  $project,
281  Task::STATUS_IN_PROGRESS);
282  $kanbanItem3 = KanbanItem::getByTask($task3->id);
283  $this->assertEquals(KanbanItem::TYPE_IN_PROGRESS, $kanbanItem3->type);
284  $this->assertEquals($task3->project->id, $kanbanItem3->kanbanRelatedItem->id);
285  $sourceKanbanType = TasksUtil::resolveKanbanItemTypeForTaskStatus(Task::STATUS_IN_PROGRESS);
286  TasksUtil::sortKanbanColumnItems($sourceKanbanType, $task->project);
287  $kanbanItem = KanbanItem::getByTask($task->id);
288  $kanbanItem2 = KanbanItem::getByTask($task2->id);
289  $kanbanItem3 = KanbanItem::getByTask($task3->id);
290  $this->assertEquals($task->id, $kanbanItem->task->id);
291  $this->assertEquals(1, $kanbanItem->sortOrder);
292  $this->assertEquals($task2->id, $kanbanItem2->task->id);
293  $this->assertEquals(2, $kanbanItem2->sortOrder);
294  $this->assertEquals($task3->id, $kanbanItem3->task->id);
295  $this->assertEquals(3, $kanbanItem3->sortOrder);
296 
297  //Update status and check checkKanbanTypeByStatusAndUpdateIfRequired
298  $task->status = Task::STATUS_NEW;
299  $this->assertTrue($task->save());
301 
302  $kanbanItem = KanbanItem::getByTask($task->id);
303  $this->assertEquals(KanbanItem::TYPE_SOMEDAY, $kanbanItem->type);
304  $kanbanItem2 = KanbanItem::getByTask($task2->id);
305  $this->assertEquals(KanbanItem::TYPE_IN_PROGRESS, $kanbanItem2->type);
306  $kanbanItem3 = KanbanItem::getByTask($task3->id);
307  $this->assertEquals(KanbanItem::TYPE_IN_PROGRESS, $kanbanItem3->type);
308 
309  $this->assertEquals($task->id, $kanbanItem->task->id);
310  $this->assertEquals(1, $kanbanItem->sortOrder);
311  $this->assertEquals($task2->id, $kanbanItem2->task->id);
312  $this->assertEquals(1, $kanbanItem2->sortOrder);
313  $this->assertEquals($task3->id, $kanbanItem3->task->id);
314  $this->assertEquals(2, $kanbanItem3->sortOrder);
315  }
316 
321  {
322  $tasks = Task::getByName('MyFirstKanbanTask');
323  $task = $tasks[0];
324  $tasks = Task::getByName('MySecondKanbanTask');
325  $task2 = $tasks[0];
326  $tasks = Task::getByName('MyThirdKanbanTask');
327  $task3 = $tasks[0];
328  $kanbanItem = KanbanItem::getByTask($task->id);
329  $task->setScenario('kanbanViewButtonClick');
330  TasksUtil::processKanbanItemUpdateOnButtonAction(Task::STATUS_IN_PROGRESS, $task->id, $kanbanItem->type);
331  $kanbanItem = KanbanItem::getByTask($task->id);
332  $kanbanItem2 = KanbanItem::getByTask($task2->id);
333  $kanbanItem3 = KanbanItem::getByTask($task3->id);
334  $this->assertEquals($task->id, $kanbanItem->task->id);
335  $this->assertEquals(3, $kanbanItem->sortOrder);
336  $this->assertEquals($task2->id, $kanbanItem2->task->id);
337  $this->assertEquals(1, $kanbanItem2->sortOrder);
338  $this->assertEquals($task3->id, $kanbanItem3->task->id);
339  $this->assertEquals(2, $kanbanItem3->sortOrder);
340  }
341 
346  {
347  $tasks = Task::getByName('MyFirstKanbanTask');
348  $task = $tasks[0];
349  $tasks = Task::getByName('MySecondKanbanTask');
350  $task2 = $tasks[0];
351  $tasks = Task::getByName('MyThirdKanbanTask');
352  $task3 = $tasks[0];
353  $kanbanItem2 = KanbanItem::getByTask($task2->id);
354  $task2->setScenario('kanbanViewButtonClick');
355  //Check for target status waiting for acceptance(should not change sort order)
356  TasksUtil::processKanbanItemUpdateOnButtonAction(Task::STATUS_AWAITING_ACCEPTANCE, $task2->id, $kanbanItem2->type);
357  $kanbanItem = KanbanItem::getByTask($task->id);
358  $kanbanItem2 = KanbanItem::getByTask($task2->id);
359  $kanbanItem3 = KanbanItem::getByTask($task3->id);
360  $this->assertEquals($task->id, $kanbanItem->task->id);
361  $this->assertEquals(3, $kanbanItem->sortOrder);
362  $this->assertEquals($task2->id, $kanbanItem2->task->id);
363  $this->assertEquals(1, $kanbanItem2->sortOrder);
364  $this->assertEquals($task3->id, $kanbanItem3->task->id);
365  $this->assertEquals(2, $kanbanItem3->sortOrder);
366 
367  $task2->setScenario('kanbanViewButtonClick');
368  //Check for target status rejected(should not change sort order)
369  TasksUtil::processKanbanItemUpdateOnButtonAction(Task::STATUS_REJECTED, $task2->id, $kanbanItem2->type);
370  $kanbanItem = KanbanItem::getByTask($task->id);
371  $kanbanItem2 = KanbanItem::getByTask($task2->id);
372  $kanbanItem3 = KanbanItem::getByTask($task3->id);
373  $this->assertEquals($task->id, $kanbanItem->task->id);
374  $this->assertEquals(3, $kanbanItem->sortOrder);
375  $this->assertEquals($task2->id, $kanbanItem2->task->id);
376  $this->assertEquals(1, $kanbanItem2->sortOrder);
377  $this->assertEquals($task3->id, $kanbanItem3->task->id);
378  $this->assertEquals(2, $kanbanItem3->sortOrder);
379 
380  $task2->setScenario('kanbanViewButtonClick');
381  //Check for target status in progress(should not change sort order)
382  TasksUtil::processKanbanItemUpdateOnButtonAction(Task::STATUS_IN_PROGRESS, $task2->id, $kanbanItem2->type);
383  $kanbanItem = KanbanItem::getByTask($task->id);
384  $kanbanItem2 = KanbanItem::getByTask($task2->id);
385  $kanbanItem3 = KanbanItem::getByTask($task3->id);
386  $this->assertEquals($task->id, $kanbanItem->task->id);
387  $this->assertEquals(3, $kanbanItem->sortOrder);
388  $this->assertEquals($task2->id, $kanbanItem2->task->id);
389  $this->assertEquals(1, $kanbanItem2->sortOrder);
390  $this->assertEquals($task3->id, $kanbanItem3->task->id);
391  $this->assertEquals(2, $kanbanItem3->sortOrder);
392 
393  $task2->setScenario('kanbanViewButtonClick');
394  //Check for target status completed(should change sort order)
395  TasksUtil::processKanbanItemUpdateOnButtonAction(Task::STATUS_COMPLETED, $task2->id, $kanbanItem2->type);
396  $kanbanItem = KanbanItem::getByTask($task->id);
397  $kanbanItem2 = KanbanItem::getByTask($task2->id);
398  $kanbanItem3 = KanbanItem::getByTask($task3->id);
399  $this->assertEquals($task->id, $kanbanItem->task->id);
400  $this->assertEquals(2, $kanbanItem->sortOrder);
401  $this->assertEquals($task2->id, $kanbanItem2->task->id);
402  $this->assertEquals(KanbanItem::TYPE_COMPLETED, $kanbanItem2->type);
403  $this->assertEquals(1, $kanbanItem2->sortOrder);
404  $this->assertEquals($task3->id, $kanbanItem3->task->id);
405  $this->assertEquals(1, $kanbanItem3->sortOrder);
406  }
407  }
408 ?>
static getDefaultTaskStatusForKanbanItemType($kanbanItemType)
Definition: TasksUtil.php:343
static makeBySecurableItem(SecurableItem $securableItem)
static getTaskCompletionPercentage(Task $task)
Definition: TasksUtil.php:310
static getModalTitleForCreateTask($renderType="Create")
Definition: TasksUtil.php:93
static resolveKanbanItemTypeForTaskStatus($status)
Definition: TasksUtil.php:260
static getByUsername($username)
Definition: User.php:49
static resolveFirstRelatedModelStringValue(Task $task)
Definition: TasksUtil.php:569
testTaskCompletionPercentage()
testProcessKanbanItemUpdateWithSourceKanbanTypeAsSomeDay()
static sortKanbanColumnItems($kanbanType, Item $childObjectOfItem)
Definition: TasksUtil.php:745
testGetTaskCompletedCheckListItems()
static renderCompletionProgressBarContent(Task $task)
Definition: TasksUtil.php:378
static getTaskCompletedCheckListItems(Task $task)
Definition: TasksUtil.php:395
Definition: Task.php:37
static resolveExplicitPermissionsForRequestedByUser(Task $task, Permitable $origRequestedByUser, Permitable $requestedByUser, ExplicitReadWriteModelPermissions $explicitReadWriteModelPermissions)
Definition: TasksUtil.php:60
static createKanbanItemFromTask(Task $task)
Definition: TasksUtil.php:354
static resolveFirstRelatedModel(Task $task)
Definition: TasksUtil.php:584
static processKanbanItemUpdateOnButtonAction($targetStatus, $taskId, $sourceKanbanType)
Definition: TasksUtil.php:666
testRenderCompletionDateTime()
static checkKanbanTypeByStatusAndUpdateIfRequired(Task $task)
Definition: TasksUtil.php:760
static getModalEditTitle()
Definition: TasksUtil.php:81
testResolveFirstRelatedModelForProject()
static getById($id, $modelClassName=null)
testResolveExplicitPermissionsForRequestedByUser()
testResolveFirstRelatedModel()
testRenderCompletionProgressBarContent()
testGetModalTitleForCreateTask()
testCreateKanbanItemFromTask()
testGetDefaultTaskStatusForKanbanItemType()
testResolveKanbanItemTypeForTaskStatus()
testProcessKanbanItemUpdateWithSourceKanbanTypeAsInProgress()
static renderCompletionDateTime(Task $task)
Definition: TasksUtil.php:625
static getByTask($taskId)
Definition: KanbanItem.php:160
static getModalDetailsTitle()
Definition: TasksUtil.php:71
Generated on Fri Jun 5 2020 07:10:35