All Data Structures Functions Variables Pages
TaskAjaxSuperUserWalkthroughTest.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 
41  {
42  protected static $super;
43 
44  protected static $myUser;
45 
46  protected static $sally;
47 
48  public static function setUpBeforeClass()
49  {
50  parent::setUpBeforeClass();
51  SecurityTestHelper::createSuperAdmin();
52  self::$super = User::getByUsername('super');
53  self::$myUser = UserTestHelper::createBasicUser('myuser');
54  self::$sally = UserTestHelper::createBasicUser('sally');
55  Yii::app()->user->userModel = self::$super;
56  //Setup test data owned by the super user.
57  $account = AccountTestHelper::createAccountByNameForOwner('superAccount', self::$super);
58  }
59 
60  public function testInlineCreateCommentFromAjax()
61  {
62  $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
63 
64  $task = new Task();
65  $task->name = 'aTest';
66  $nowStamp = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
67  $this->assertTrue($task->save());
68 
69  $this->setGetArray(array('id' => $task->id, 'uniquePageId' => 'CommentInlineEditForModelView'));
70  $this->runControllerWithNoExceptionsAndGetContent('tasks/default/inlineCreateCommentFromAjax');
71  }
72 
76  public function testUpdateDueDateTimeViaAjax()
77  {
78  $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
79  $tasks = Task::getByName('aTest');
80  $task = $tasks[0];
81  $taskId = $task->id;
82  $this->setGetArray(array('id' => $task->id, 'dateTime' => '7/23/13 12:00 am'));
83  $this->runControllerWithNoExceptionsAndGetContent('tasks/default/updateDueDateTimeViaAjax', true);
84  $task = Task::getById($taskId);
85  $displayDateTime = DateTimeUtil::convertDbFormattedDateTimeToLocaleFormattedDisplay($task->dueDateTime);
86  $this->assertEquals('7/23/13 12:00 AM', $displayDateTime);
87  }
88 
93  {
94  //Login with super and check subscribe unsubscribe from modal detail view when super
95  //is not owner or requested by user
96  $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
97  $task = new Task();
98  $task->name = 'SubscriberTask';
99  $task->owner = self::$sally;
100  $task->requestedByUser = self::$myUser;
101  $this->assertTrue($task->save());
102  $this->assertEquals(2, $task->notificationSubscribers->count());
103  $this->setGetArray(array('id' => $task->id));
105  $content = $this->runControllerWithNoExceptionsAndGetContent('tasks/default/addSubscriber', false);
106  $this->assertContains('gravatar', $content);
107  $this->assertContains('users/default/details', $content);
108  $this->assertContains($super->getFullName(), $content);
109  $this->assertEquals(3, $task->notificationSubscribers->count());
110 
111  $this->setGetArray(array('id' => $task->id));
112  $content = $this->runControllerWithNoExceptionsAndGetContent('tasks/default/removeSubscriber', false);
113  $this->assertNotContains($super->getFullName(), $content);
114  $this->assertEquals(2, $task->notificationSubscribers->count());
115  $task->owner = $super;
116  $this->assertTrue($task->save());
117  $this->assertEquals(3, $task->notificationSubscribers->count());
118 
119  //Super user is owner so even if it is removed, it would be restored
120  $this->setGetArray(array('id' => $task->id));
121  $content = $this->runControllerWithNoExceptionsAndGetContent('tasks/default/removeSubscriber', false);
122  $this->assertContains($super->getFullName(), $content);
123  $this->assertEquals(3, $task->notificationSubscribers->count());
124  }
125 
126  public function testAddAndRemoveSubscriberViaAjaxWithNormalUser()
127  {
128  //Adk Jason as why permission error is coming up here
129  $sally = $this->logoutCurrentUserLoginNewUserAndGetByUsername('sally');
130  $task = new Task();
131  $task->name = 'NewSubscriberTask';
132  $task->owner = $sally;
133  $task->requestedByUser = self::$myUser;
134  $this->assertTrue($task->save());
135  $this->setGetArray(array('id' => $task->id));
136  $this->runControllerShouldResultInAccessFailureAndGetContent('tasks/default/removeSubscriber');
137  $this->setGetArray(array('id' => $task->id));
138  $this->runControllerShouldResultInAccessFailureAndGetContent('tasks/default/addSubscriber');
139 
140  //Now test peon with elevated rights to accounts
141  $sally->setRight('TasksModule', TasksModule::RIGHT_ACCESS_TASKS);
142  $sally->setRight('TasksModule', TasksModule::RIGHT_CREATE_TASKS);
143  $sally->setRight('TasksModule', TasksModule::RIGHT_DELETE_TASKS);
144  $this->assertTrue($sally->save());
145  $task->addPermissions($sally, Permission::READ_WRITE_CHANGE_PERMISSIONS);
146  $this->assertTrue($task->save());
148 
149  //Test nobody with elevated rights.
150  Yii::app()->user->userModel = User::getByUsername('sally');
151 
152  $this->setGetArray(array('id' => $task->id));
153  $content = $this->runControllerWithNoExceptionsAndGetContent('tasks/default/removeSubscriber', false);
154  $this->assertContains($sally->getFullName(), $content);
155  $this->assertEquals(2, $task->notificationSubscribers->count());
156 
157  //Now super user would be added as a subscriber as he becomes the owner
158  $task->owner = self::$super;
159  $this->assertTrue($task->save());
160 
161  $content = $this->runControllerWithNoExceptionsAndGetContent('tasks/default/removeSubscriber', false);
162  $this->assertNotContains($sally->getFullName(), $content);
163  $this->assertEquals(2, $task->notificationSubscribers->count());
164 
165  $isSallyFound = $this->checkIfUserFoundInSubscribersList($task, $sally->id);
166  $this->assertFalse($isSallyFound);
167 
168  $content = $this->runControllerWithNoExceptionsAndGetContent('tasks/default/addSubscriber', false);
169  $this->assertContains($sally->getFullName(), $content);
170  $this->assertEquals(3, $task->notificationSubscribers->count());
171 
172  $isSallyFound = $this->checkIfUserFoundInSubscribersList($task, $sally->id);
173  $this->assertTrue($isSallyFound);
174  }
175 
176  public function testAddAndRemoveKanbanSubscriberViaAjaxAsSuperUser()
177  {
178  //Login with super and check subscribe unsubscribe from modal detail view when super
179  //is not owner or requested by user
180  $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
181  $task = new Task();
182  $task->name = 'KanbanSubscriberTask';
183  $task->owner = self::$sally;
184  $task->requestedByUser = self::$myUser;
185  $this->assertTrue($task->save());
186  $this->assertEquals(2, $task->notificationSubscribers->count());
187  $this->setGetArray(array('id' => $task->id));
189  $content = $this->runControllerWithNoExceptionsAndGetContent('tasks/default/addKanbanSubscriber', false);
190  $this->assertContains('gravatar', $content);
191  $this->assertContains('users/default/details', $content);
192  $this->assertContains($super->getFullName(), $content);
193  $this->assertEquals(3, $task->notificationSubscribers->count());
194 
195  $this->setGetArray(array('id' => $task->id));
196  $content = $this->runControllerWithNoExceptionsAndGetContent('tasks/default/removeKanbanSubscriber', false);
197  $this->assertNotContains($super->getFullName(), $content);
198  $this->assertEquals(2, $task->notificationSubscribers->count());
199  $task->owner = $super;
200  $this->assertTrue($task->save());
201  $this->assertEquals(3, $task->notificationSubscribers->count());
202 
203  //Super user is owner so even if it is removed, it would be restored
204  $this->setGetArray(array('id' => $task->id));
205  $content = $this->runControllerWithNoExceptionsAndGetContent('tasks/default/removeKanbanSubscriber', false);
206  $this->assertContains($super->getFullName(), $content);
207  $this->assertEquals(3, $task->notificationSubscribers->count());
208  }
209 
210  public function testAddAndRemoveKanbanSubscriberViaAjaxWithNormalUser()
211  {
212  //Adk Jason as why permission error is coming up here
213  $myuser = $this->logoutCurrentUserLoginNewUserAndGetByUsername('myuser');
214  $task = new Task();
215  $task->name = 'NewKanbanSubscriberTask';
216  $task->owner = $myuser;
217  $task->requestedByUser = self::$sally;
218  $this->assertTrue($task->save());
219  $this->setGetArray(array('id' => $task->id));
220  $this->runControllerShouldResultInAccessFailureAndGetContent('tasks/default/removeKanbanSubscriber');
221  $this->setGetArray(array('id' => $task->id));
222  $this->runControllerShouldResultInAccessFailureAndGetContent('tasks/default/addKanbanSubscriber');
223 
224  //Now test peon with elevated rights to accounts
225  $myuser->setRight('TasksModule', TasksModule::RIGHT_ACCESS_TASKS);
226  $myuser->setRight('TasksModule', TasksModule::RIGHT_CREATE_TASKS);
227  $myuser->setRight('TasksModule', TasksModule::RIGHT_DELETE_TASKS);
228  $this->assertTrue($myuser->save());
229  $task->addPermissions($myuser, Permission::READ_WRITE_CHANGE_PERMISSIONS);
230  $this->assertTrue($task->save());
232 
233  //Test nobody with elevated rights.
234  Yii::app()->user->userModel = User::getByUsername('myuser');
235 
236  $this->setGetArray(array('id' => $task->id));
237  $content = $this->runControllerWithNoExceptionsAndGetContent('tasks/default/removeKanbanSubscriber', false);
238  $this->assertContains($myuser->getFullName(), $content);
239  $this->assertEquals(2, $task->notificationSubscribers->count());
240 
241  //Now super user would be added as a subscriber as he becomes the owner
242  $task->owner = self::$super;
243  $this->assertTrue($task->save());
244 
245  $content = $this->runControllerWithNoExceptionsAndGetContent('tasks/default/removeKanbanSubscriber', false);
246  $this->assertNotContains($myuser->getFullName(), $content);
247  $this->assertEquals(2, $task->notificationSubscribers->count());
248  $isMyUserFound = $this->checkIfUserFoundInSubscribersList($task, $myuser->id);
249  $this->assertFalse($isMyUserFound);
250 
251  $content = $this->runControllerWithNoExceptionsAndGetContent('tasks/default/addKanbanSubscriber', false);
252  $this->assertContains($myuser->getFullName(), $content);
253  $this->assertEquals(3, $task->notificationSubscribers->count());
254  $isMyUserFound = $this->checkIfUserFoundInSubscribersList($task, $myuser->id);
255  $this->assertTrue($isMyUserFound);
256  }
257 
262  {
263  $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
264 
265  $accountId = self::getModelIdByModelNameAndName('Account', 'superAccount');
266  $this->setGetArray(array(
267  'relationAttributeName' => 'Account',
268  'relationModelId' => $accountId,
269  'relationModuleId' => 'accounts',
270  'modalId' => 'relatedModalContainer-tasks',
271  'portletId' => '12',
272  'uniqueLayoutId' => 'AccountDetailsAndRelationsView_12'
273  ));
274  $this->runControllerWithNoExceptionsAndGetContent('tasks/default/modalCreateFromRelation');
275  $tasks = Task::getAll();
276  $this->assertEquals(5, count($tasks));
277  $this->setGetArray(array(
278  'relationAttributeName' => 'Account',
279  'relationModelId' => $accountId,
280  'relationModuleId' => 'accounts',
281  'portletId' => '12',
282  'uniqueLayoutId' => 'AccountDetailsAndRelationsView_12'
283  ));
284  $this->setPostArray(array(
285  'Task' => array('name' => 'Task for test cases'),
286  'ActivityItemForm' => array('Account' => array('id' => $accountId))
287  ));
288 
289  $content = $this->runControllerWithNoExceptionsAndGetContent('tasks/default/modalSaveFromRelation');
290  $this->assertContains('Task for test cases', $content);
291  $tasks = Task::getAll();
292  $this->assertEquals(6, count($tasks));
293 
294  $this->setGetArray(array(
295  'id' => $tasks[5]->id
296  )
297  );
298  $content = $this->runControllerWithNoExceptionsAndGetContent('tasks/default/modalDetails');
299  $this->assertContains('Task for test cases', $content);
300 
301  $this->setGetArray(array(
302  'id' => $tasks[5]->id
303  ));
304  $content = $this->runControllerWithNoExceptionsAndGetContent('tasks/default/modalEdit');
305 
306  $this->setGetArray(array(
307  'id' => $tasks[5]->id
308  ));
309  unset($_POST['Task']);
310  $content = $this->runControllerWithNoExceptionsAndGetContent('tasks/default/modalCopy');
311  $this->assertContains('Task for test cases', $content);
312  }
313 
314  public function testUpdateStatusOnDragInKanbanView()
315  {
316  $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
317  $project = ProjectTestHelper::createProjectByNameForOwner('a new project', $super);
318  $task = TaskTestHelper::createTaskByNameForOwner('My Kanban Task', Yii::app()->user->userModel);
319  $task->project = $project;
320  $task->status = Task::STATUS_IN_PROGRESS;
321  $taskId = $task->id;
322  $this->assertTrue($task->save());
323 
324  $task1 = TaskTestHelper::createTaskByNameForOwner('My Kanban Task 1', Yii::app()->user->userModel);
325  $task1->project = $project;
326  $task1->status = Task::STATUS_NEW;
327  $this->assertTrue($task1->save());
328  $task1Id = $task1->id;
329  $taskArray = array($task, $task1);
330 
331  foreach ($taskArray as $row => $data)
332  {
333  $kanbanItem = KanbanItem::getByTask($data->id);
334  if ($kanbanItem == null)
335  {
336  //Create KanbanItem here
337  $kanbanItem = TasksUtil::createKanbanItemFromTask($data);
338  }
339  $kanbanItemsArray[] = $kanbanItem;
340  }
341  $this->assertEquals(KanbanItem::TYPE_SOMEDAY, $kanbanItemsArray[1]->type);
342  $this->assertEquals(1, $kanbanItemsArray[1]->sortOrder);
343  $this->assertEquals(1, $kanbanItemsArray[0]->sortOrder);
344 
345  $this->setGetArray(array('items' => array($task1->id, $task->id), 'type' => KanbanItem::TYPE_IN_PROGRESS));
346  $content = $this->runControllerWithNoExceptionsAndGetContent('tasks/default/updateStatusOnDragInKanbanView', false);
347  $contentArray = CJSON::decode($content);
348  $this->assertContains('Finish', $contentArray['button']);
349  $task1 = Task::getById($task1Id);
350  $this->assertEquals(Task::STATUS_IN_PROGRESS, $task1->status);
351  $kanbanItem = KanbanItem::getByTask($task1Id);
352  $this->assertEquals(KanbanItem::TYPE_IN_PROGRESS, $kanbanItem->type);
353 
354  $kanbanItem = KanbanItem::getByTask($taskId);
355  $this->assertEquals(2, $kanbanItem->sortOrder);
356  }
357 
362  {
363  $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
364  $tasks = Task::getByName('My Kanban Task');
365  $task = $tasks[0];
366  $taskId = $task->id;
367  $this->setGetArray(array('targetStatus' => Task::STATUS_AWAITING_ACCEPTANCE,
368  'taskId' => $task->id,
369  'sourceKanbanType' => KanbanItem::TYPE_IN_PROGRESS));
370  $this->runControllerWithNoExceptionsAndGetContent('tasks/default/updateStatusInKanbanView', false);
371  $task = Task::getById($taskId);
372  $this->assertEquals(Task::STATUS_AWAITING_ACCEPTANCE, $task->status);
373  }
374 
375  private function checkIfUserFoundInSubscribersList($task, $compareId)
376  {
377  $isUserFound = false;
378  $modelDerivationPathToItem = RuntimeUtil::getModelDerivationPathToItem('User');
379  foreach ($task->notificationSubscribers as $subscriber)
380  {
381  $user = $subscriber->person->castDown(array($modelDerivationPathToItem));
382  if ($user->id == $compareId)
383  {
384  $isUserFound = true;
385  }
386  }
387  return $isUserFound;
388  }
389  }
390 ?>
static securableItemGivenPermissionsForUser(SecurableItem $securableItem, User $user)
static getByUsername($username)
Definition: User.php:49
Definition: Task.php:37
static createKanbanItemFromTask(Task $task)
Definition: TasksUtil.php:354
static getModelDerivationPathToItem($modelClassName)
Definition: RuntimeUtil.php:79
static doNotificationSubscribersContainPerson(OwnedSecurableItem $model, Item $item)
static getById($id, $modelClassName=null)
logoutCurrentUserLoginNewUserAndGetByUsername($username)
runControllerWithNoExceptionsAndGetContent($route, $empty=false)
static getAll($orderBy=null, $sortDescending=false, $modelClassName=null)
static getByTask($taskId)
Definition: KanbanItem.php:160
Generated on Fri Jun 5 2020 07:10:35