public function testProperlyDeletingActivityItems()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $count = ZurmoRedBean::getRow('select count(*) count from activity_item');
     $this->assertEquals(0, $count['count']);
     $account = AccountTestHelper::createAccountByNameForOwner('anAccount', Yii::app()->user->userModel);
     $deleted = $account->delete();
     $this->assertTrue($deleted);
     $count = ZurmoRedBean::getRow('select count(*) count from activity_item');
     $this->assertEquals(0, $count['count']);
     $account2 = AccountTestHelper::createAccountByNameForOwner('anAccount2', Yii::app()->user->userModel);
     $opportunity = OpportunityTestHelper::createOpportunityByNameForOwner('anOpp', Yii::app()->user->userModel);
     $task = TaskTestHelper::createTaskWithOwnerAndRelatedAccount('aTask', Yii::app()->user->userModel, $account2);
     $task->activityItems->add($opportunity);
     $this->assertTrue($task->save());
     $taskId = $task->id;
     $task->forget();
     RedBeansCache::forgetAll();
     $count = ZurmoRedBean::getRow('select count(*) count from activity_item');
     $this->assertEquals(2, $count['count']);
     $deleted = $account2->delete();
     $this->assertTrue($deleted);
     $account2->forget();
     $count = ZurmoRedBean::getRow('select count(*) count from activity_item');
     $this->assertEquals(1, $count['count']);
     RedBeansCache::forgetAll();
     //Make sure things render ok even with the account deleted.
     $content = ActivitiesUtil::renderSummaryContent(Task::getById($taskId), 'someUrl', LatestActivitiesConfigurationForm::OWNED_BY_FILTER_ALL, 'HomeModule');
 }
 public function testKanbanViewForContactDetails()
 {
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $superContactId = self::getModelIdByModelNameAndName('Contact', 'superContact superContactson');
     $contact = Contact::getById($superContactId);
     $task = TaskTestHelper::createTaskWithOwnerAndRelatedItem('MyTask', $super, $contact, Task::STATUS_IN_PROGRESS);
     $taskNew = TaskTestHelper::createTaskWithOwnerAndRelatedItem('MyTask New', $super, $contact, Task::STATUS_NEW);
     $this->setGetArray(array('id' => $task->id, 'kanbanBoard' => '1'));
     $content = $this->runControllerWithNoExceptionsAndGetContent('contacts/default/details');
     $matcher = array('tag' => 'h4', 'ancestor' => array('tag' => 'li', 'id' => 'items_' . $task->id, 'tag' => 'ul', 'id' => 'task-sortable-rows-3'), 'content' => 'MyTask');
     $this->assertTag($matcher, $content);
     $matcher = array('tag' => 'h4', 'ancestor' => array('tag' => 'li', 'id' => 'items_' . $taskNew->id, 'tag' => 'ul', 'id' => 'task-sortable-rows-1'), 'content' => 'MyTask New');
     $this->assertTag($matcher, $content);
 }
 public function createTaskWithRelatedAccount($firstName, $taskName)
 {
     $account = AccountTestHelper::createAccountByNameForOwner($firstName, Yii::app()->user->userModel);
     $this->assertNull($account->latestActivityDateTime);
     $task = TaskTestHelper::createTaskByNameForOwner($taskName, Yii::app()->user->userModel);
     $task->activityItems->add($account);
     $this->assertTrue($task->save());
     $this->assertNull($task->activityItems[0]->latestActivityDateTime);
     $taskId = $task->id;
     $accountId = $account->id;
     $task->forget();
     $account->forget();
     return array($taskId, $accountId);
 }
 public function testCopy()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $user = Yii::app()->user->userModel;
     $project = new Project();
     $project->name = 'Project 1';
     $project->owner = $user;
     $project->description = 'Description';
     $user = UserTestHelper::createBasicUser('Steven');
     $account = new Account();
     $account->owner = $user;
     $account->name = DataUtil::purifyHtml("Tom & Jerry's Account");
     $this->assertTrue($account->save());
     $id = $account->id;
     unset($account);
     $account = Account::getById($id);
     $this->assertEquals("Tom & Jerry's Account", $account->name);
     $contact = ContactTestHelper::createContactByNameForOwner('Jerry', $user);
     $opportunity = OpportunityTestHelper::createOpportunityByNameForOwner('Jerry Opp', $user);
     $this->assertTrue($project->save());
     $this->assertEquals(1, count($project->auditEvents));
     $id = $project->id;
     $project->forget();
     unset($project);
     $project = Project::getById($id);
     ProjectZurmoControllerUtil::resolveProjectManyManyAccountsFromPost($project, array('accountIds' => $account->id));
     ProjectZurmoControllerUtil::resolveProjectManyManyContactsFromPost($project, array('contactIds' => $contact->id));
     ProjectZurmoControllerUtil::resolveProjectManyManyOpportunitiesFromPost($project, array('opportunityIds' => $opportunity->id));
     $this->assertEquals('Project 1', $project->name);
     $this->assertEquals('Description', $project->description);
     $this->assertEquals(1, $project->accounts->count());
     $this->assertEquals(1, $project->contacts->count());
     $this->assertEquals(1, $project->opportunities->count());
     $task = TaskTestHelper::createTaskByNameWithProjectAndStatus('MyFirstKanbanTask', Yii::app()->user->userModel, $project, Task::STATUS_IN_PROGRESS);
     $kanbanItem1 = KanbanItem::getByTask($task->id);
     $this->assertEquals(KanbanItem::TYPE_IN_PROGRESS, $kanbanItem1->type);
     $this->assertEquals($task->project->id, $kanbanItem1->kanbanRelatedItem->id);
     $copyToProject = new Project();
     ProjectZurmoCopyModelUtil::copy($project, $copyToProject);
     ProjectZurmoCopyModelUtil::processAfterCopy($project, $copyToProject);
     $this->assertTrue($copyToProject->save());
     $this->assertEquals($copyToProject->name, $project->name);
     $this->assertEquals($copyToProject->description, $project->description);
     $this->assertEquals($copyToProject->status, $project->status);
     $project = Project::getByName('Project 1');
     $this->assertEquals(2, count($project));
     $tasks = Task::getAll();
     $this->assertEquals(2, count($tasks));
 }
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     SecurityTestHelper::createSuperAdmin();
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     Currency::makeBaseCurrency();
     //Create a account for testing.
     $account = AccountTestHelper::createAccountByNameForOwner('superAccount', $super);
     //Create a opportunity for testing.
     OpportunityTestHelper::createOpportunityWithAccountByNameForOwner('superOpp', $super, $account);
     //Create a two contacts for testing.
     ContactTestHelper::createContactWithAccountByNameForOwner('superContact1', $super, $account);
     ContactTestHelper::createContactWithAccountByNameForOwner('superContact2', $super, $account);
     //Create a task for testing.
     TaskTestHelper::createTaskWithOwnerAndRelatedAccount('superTask', $super, $account);
 }
 public function testResolveRelatedContactsAndSetLatestActivityDateTime()
 {
     $contact = ContactTestHelper::createContactByNameForOwner('contact2', Yii::app()->user->userModel);
     $this->assertNull($contact->latestActivityDateTime);
     $contact2 = ContactTestHelper::createContactByNameForOwner('contact3', Yii::app()->user->userModel);
     $this->assertNull($contact2->latestActivityDateTime);
     $task = TaskTestHelper::createTaskByNameForOwner('task3', Yii::app()->user->userModel);
     $task->activityItems->add($contact);
     $task->activityItems->add($contact2);
     $this->assertTrue($task->save());
     $this->assertNull($task->activityItems[0]->latestActivityDateTime);
     $this->assertNull($task->activityItems[1]->latestActivityDateTime);
     $taskId = $task->id;
     $contactId = $contact->id;
     $contact2Id = $contact2->id;
     $task->forget();
     $contact->forget();
     $contact2->forget();
     //Retrieve the task, so the related activity item is an Item and needs to be casted down
     $task = Task::getById($taskId);
     $dateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
     ContactLatestActivityDateTimeObserver::resolveRelatedModelsAndSetLatestActivityDateTime($task->activityItems, $dateTime, 'Contact');
     $task->forget();
     $contact = Contact::getById($contactId);
     $this->assertEquals($dateTime, $contact->latestActivityDateTime);
     $contact2 = Contact::getById($contact2Id);
     $this->assertEquals($dateTime, $contact2->latestActivityDateTime);
 }
 public function testProcessForActivityItems()
 {
     $account = AccountTestHelper::createAccountByNameForOwner('testAccount', Yii::app()->user->userModel);
     $task = TaskTestHelper::createTaskWithOwnerAndRelatedAccount('testTask', Yii::app()->user->userModel, $account);
     $meeting = MeetingTestHelper::createMeetingWithOwnerAndRelatedAccount('testMeetig', Yii::app()->user->userModel, $account);
     $contact = ContactTestHelper::createContactByNameForOwner('testContact', Yii::app()->user->userModel);
     $opportunity = OpportunityTestHelper::createOpportunityByNameForOwner('testOpportunity', Yii::app()->user->userModel);
     $task->activityItems->add($contact);
     $task->activityItems->add($opportunity);
     $meeting->activityItems->add($contact);
     $meeting->activityItems->add($opportunity);
     $this->assertTrue($task->save());
     $this->assertTrue($meeting->save());
     $emailTemplate = new EmailTemplate();
     $emailTemplate->builtType = EmailTemplate::BUILT_TYPE_PASTED_HTML;
     $emailTemplate->modelClassName = 'Task';
     $emailTemplate->type = 1;
     $emailTemplate->name = 'some template';
     $emailTemplate->subject = 'some subject [[NAME]]';
     $emailTemplate->htmlContent = 'Account: [[ACCOUNT__NAME]] Contact: [[CONTACT__FIRST^NAME]] Opportunity: [[OPPORTUNITY__NAME]]';
     $emailTemplate->textContent = 'Account: [[ACCOUNT__NAME]] Contact: [[CONTACT__FIRST^NAME]] Opportunity: [[OPPORTUNITY__NAME]]';
     $this->assertTrue($emailTemplate->save());
     $message = new EmailMessageForWorkflowForm('Task', Workflow::TYPE_ON_SAVE);
     $recipients = array(array('type' => WorkflowEmailMessageRecipientForm::TYPE_DYNAMIC_TRIGGERED_MODEL_USER, 'audienceType' => EmailMessageRecipient::TYPE_TO, 'dynamicUserType' => DynamicTriggeredModelUserWorkflowEmailMessageRecipientForm::DYNAMIC_USER_TYPE_CREATED_BY_USER));
     $message->emailTemplateId = $emailTemplate->id;
     $message->sendFromType = EmailMessageForWorkflowForm::SEND_FROM_TYPE_CUSTOM;
     $message->sendFromAddress = '*****@*****.**';
     $message->sendFromName = 'Jason';
     $message->setAttributes(array(EmailMessageForWorkflowForm::EMAIL_MESSAGE_RECIPIENTS => $recipients));
     $helper = new WorkflowEmailMessageProcessingHelper($message, $task, Yii::app()->user->userModel);
     $this->assertEquals(0, Yii::app()->emailHelper->getQueuedCount());
     $this->assertEquals(0, Yii::app()->emailHelper->getSentCount());
     $helper->process();
     $this->assertEquals(1, Yii::app()->emailHelper->getQueuedCount());
     $this->assertEquals(0, Yii::app()->emailHelper->getSentCount());
     $emailMessages = EmailMessage::getAllByFolderType(EmailFolder::TYPE_OUTBOX);
     $this->assertEquals('some subject testTask', $emailMessages[0]->subject);
     $this->assertEquals('Account: testAccount Contact: testContact Opportunity: testOpportunity', $emailMessages[0]->content->textContent);
     $this->assertEquals('Account: testAccount Contact: testContact Opportunity: testOpportunity', $emailMessages[0]->content->htmlContent);
     $this->assertEquals('Jason', $emailMessages[0]->sender->fromName);
     $this->assertEquals('*****@*****.**', $emailMessages[0]->sender->fromAddress);
     $this->assertEquals(1, $emailMessages[0]->recipients->count());
     $this->assertEquals('*****@*****.**', $emailMessages[0]->recipients[0]->toAddress);
     $taskId = $task->id;
     $task->forgetAll();
     $task = Task::getById($taskId);
     $message = new EmailMessageForWorkflowForm('Task', Workflow::TYPE_ON_SAVE);
     $recipients = array(array('type' => WorkflowEmailMessageRecipientForm::TYPE_DYNAMIC_TRIGGERED_MODEL_USER, 'audienceType' => EmailMessageRecipient::TYPE_TO, 'dynamicUserType' => DynamicTriggeredModelUserWorkflowEmailMessageRecipientForm::DYNAMIC_USER_TYPE_CREATED_BY_USER));
     $message->emailTemplateId = $emailTemplate->id;
     $message->sendFromType = EmailMessageForWorkflowForm::SEND_FROM_TYPE_CUSTOM;
     $message->sendFromAddress = '*****@*****.**';
     $message->sendFromName = 'Jason';
     $message->setAttributes(array(EmailMessageForWorkflowForm::EMAIL_MESSAGE_RECIPIENTS => $recipients));
     $helper = new WorkflowEmailMessageProcessingHelper($message, $task, Yii::app()->user->userModel);
     $this->assertEquals(1, Yii::app()->emailHelper->getQueuedCount());
     $this->assertEquals(0, Yii::app()->emailHelper->getSentCount());
     $helper->process();
     $this->assertEquals(2, Yii::app()->emailHelper->getQueuedCount());
     $this->assertEquals(0, Yii::app()->emailHelper->getSentCount());
     $emailMessages = EmailMessage::getAllByFolderType(EmailFolder::TYPE_OUTBOX);
     $this->assertEquals('some subject testTask', $emailMessages[1]->subject);
     $this->assertEquals('Account: testAccount Contact: testContact Opportunity: testOpportunity', $emailMessages[1]->content->textContent);
     $this->assertEquals('Account: testAccount Contact: testContact Opportunity: testOpportunity', $emailMessages[1]->content->htmlContent);
     $this->assertEquals('Jason', $emailMessages[1]->sender->fromName);
     $this->assertEquals('*****@*****.**', $emailMessages[1]->sender->fromAddress);
     $this->assertEquals(1, $emailMessages[1]->recipients->count());
     $this->assertEquals('*****@*****.**', $emailMessages[1]->recipients[0]->toAddress);
     $emailMessages[0]->delete();
     $emailMessages[1]->delete();
 }
 public function testKanbanViewForOpportunityDetails()
 {
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $opportunities = Opportunity::getByName('superOpp');
     $task = TaskTestHelper::createTaskWithOwnerAndRelatedItem('MyTask', $super, $opportunities[0], Task::STATUS_IN_PROGRESS);
     $taskNew = TaskTestHelper::createTaskWithOwnerAndRelatedItem('MyTask New', $super, $opportunities[0], Task::STATUS_NEW);
     $this->setGetArray(array('id' => $task->id, 'kanbanBoard' => '1'));
     $content = $this->runControllerWithNoExceptionsAndGetContent('opportunities/default/details');
     $matcher = array('tag' => 'h4', 'ancestor' => array('tag' => 'li', 'id' => 'items_' . $task->id, 'tag' => 'ul', 'id' => 'task-sortable-rows-3'), 'content' => 'MyTask');
     $this->assertTag($matcher, $content);
     $matcher = array('tag' => 'h4', 'ancestor' => array('tag' => 'li', 'id' => 'items_' . $taskNew->id, 'tag' => 'ul', 'id' => 'task-sortable-rows-1'), 'content' => 'MyTask New');
     $this->assertTag($matcher, $content);
 }
 public function testGetAddedOrDeletedModelsFromReadSubscriptionTable()
 {
     ReadPermissionsSubscriptionUtil::buildTables();
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $task = TaskTestHelper::createTaskByNameForOwner('Test Task', $super);
     ReadPermissionsSubscriptionUtil::updateAllReadSubscriptionTables(false);
     $sql = "SELECT * FROM task_read_subscription WHERE userid = " . $super->id;
     $permissionTableRows = R::getAll($sql);
     $this->assertEquals(1, count($permissionTableRows));
     $addedModelIds = ReadPermissionsSubscriptionUtil::getAddedOrDeletedModelsFromReadSubscriptionTable('TestService', 'Task', 0, ReadPermissionsSubscriptionUtil::TYPE_ADD, $super);
     $this->asserttrue(is_array($addedModelIds));
     $this->assertEquals(1, count($addedModelIds));
     ModelCreationApiSyncUtil::insertItem('TestService', $task->id, 'Task', '2013-05-03 15:16:06');
     $addedModelIds = ReadPermissionsSubscriptionUtil::getAddedOrDeletedModelsFromReadSubscriptionTable('TestService', 'Task', 0, ReadPermissionsSubscriptionUtil::TYPE_ADD, $super);
     $this->asserttrue(is_array($addedModelIds));
     $this->assertEquals(0, count($addedModelIds));
 }
Example #10
0
 /**
  * @depends testApiServerUrl
  */
 public function testEditTaskWIthIncorrectDataType()
 {
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $authenticationData = $this->login();
     $headers = array('Accept: application/json', 'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'], 'ZURMO_TOKEN: ' . $authenticationData['token'], 'ZURMO_API_REQUEST_TYPE: REST');
     $task = TaskTestHelper::createTaskByNameForOwner('Newest Task', $super);
     // Provide data with wrong type.
     $data['dueDateTime'] = "A";
     $response = ApiRestTestHelper::createApiCall($this->serverUrl . '/test.php/tasks/task/api/create/', 'POST', $headers, array('data' => $data));
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_FAILURE, $response['status']);
     $this->assertEquals(2, count($response['errors']));
     $id = $task->id;
     $data = array();
     $data['dueDateTime'] = "A";
     $response = ApiRestTestHelper::createApiCall($this->serverUrl . '/test.php/tasks/task/api/update/' . $id, 'PUT', $headers, array('data' => $data));
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_FAILURE, $response['status']);
     $this->assertEquals(1, count($response['errors']));
 }
 /**
  * @covers sortKanbanColumnItems
  * @covers checkKanbanTypeByStatusAndUpdateIfRequired
  */
 public function testSortKanbanColumnItems()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $project = ProjectTestHelper::createProjectByNameForOwner('MyKanbanProject', Yii::app()->user->userModel);
     $dueStamp = DateTimeUtil::convertTimestampToDbFormatDateTime(time() + 10000);
     //First kanban task
     $task = TaskTestHelper::createTaskByNameWithProjectAndStatus('MyFirstKanbanTask', Yii::app()->user->userModel, $project, Task::STATUS_IN_PROGRESS);
     $kanbanItem1 = KanbanItem::getByTask($task->id);
     $this->assertEquals(KanbanItem::TYPE_IN_PROGRESS, $kanbanItem1->type);
     $this->assertEquals($task->project->id, $kanbanItem1->kanbanRelatedItem->id);
     $task2 = TaskTestHelper::createTaskByNameWithProjectAndStatus('MySecondKanbanTask', Yii::app()->user->userModel, $project, Task::STATUS_IN_PROGRESS);
     $kanbanItem2 = KanbanItem::getByTask($task2->id);
     $this->assertEquals(KanbanItem::TYPE_IN_PROGRESS, $kanbanItem2->type);
     $this->assertEquals($task2->project->id, $kanbanItem2->kanbanRelatedItem->id);
     $task3 = TaskTestHelper::createTaskByNameWithProjectAndStatus('MyThirdKanbanTask', Yii::app()->user->userModel, $project, Task::STATUS_IN_PROGRESS);
     $kanbanItem3 = KanbanItem::getByTask($task3->id);
     $this->assertEquals(KanbanItem::TYPE_IN_PROGRESS, $kanbanItem3->type);
     $this->assertEquals($task3->project->id, $kanbanItem3->kanbanRelatedItem->id);
     $sourceKanbanType = TasksUtil::resolveKanbanItemTypeForTaskStatus(Task::STATUS_IN_PROGRESS);
     TasksUtil::sortKanbanColumnItems($sourceKanbanType, $task->project);
     $kanbanItem = KanbanItem::getByTask($task->id);
     $kanbanItem2 = KanbanItem::getByTask($task2->id);
     $kanbanItem3 = KanbanItem::getByTask($task3->id);
     $this->assertEquals($task->id, $kanbanItem->task->id);
     $this->assertEquals(1, $kanbanItem->sortOrder);
     $this->assertEquals($task2->id, $kanbanItem2->task->id);
     $this->assertEquals(2, $kanbanItem2->sortOrder);
     $this->assertEquals($task3->id, $kanbanItem3->task->id);
     $this->assertEquals(3, $kanbanItem3->sortOrder);
     //Update status and check checkKanbanTypeByStatusAndUpdateIfRequired
     $task->status = Task::STATUS_NEW;
     $this->assertTrue($task->save());
     TasksUtil::checkKanbanTypeByStatusAndUpdateIfRequired($task);
     $kanbanItem = KanbanItem::getByTask($task->id);
     $this->assertEquals(KanbanItem::TYPE_SOMEDAY, $kanbanItem->type);
     $kanbanItem2 = KanbanItem::getByTask($task2->id);
     $this->assertEquals(KanbanItem::TYPE_IN_PROGRESS, $kanbanItem2->type);
     $kanbanItem3 = KanbanItem::getByTask($task3->id);
     $this->assertEquals(KanbanItem::TYPE_IN_PROGRESS, $kanbanItem3->type);
     $this->assertEquals($task->id, $kanbanItem->task->id);
     $this->assertEquals(1, $kanbanItem->sortOrder);
     $this->assertEquals($task2->id, $kanbanItem2->task->id);
     $this->assertEquals(1, $kanbanItem2->sortOrder);
     $this->assertEquals($task3->id, $kanbanItem3->task->id);
     $this->assertEquals(2, $kanbanItem3->sortOrder);
 }
 protected function addTask()
 {
     $this->checkActivityItemRelationCount('Task', 'First Task', 0);
     TaskTestHelper::createTaskWithOwnerAndRelatedAccount('First Task', Yii::app()->user->userModel, $this->selectedModels[1]);
 }
 /**
  * @depends testBaseUrlMergeTag
  */
 public function testActivityItemsMergeTag()
 {
     $account = AccountTestHelper::createAccountByNameForOwner('testAccount', self::$super);
     $task = TaskTestHelper::createTaskWithOwnerAndRelatedAccount('testTask', self::$super, $account);
     $content = '[[ACCOUNT__NAME]]';
     $mergeTagsUtil = MergeTagsUtilFactory::make(EmailTemplate::TYPE_WORKFLOW, null, $content);
     $resolvedContent = $mergeTagsUtil->resolveMergeTags($task, $this->invalidTags);
     $this->assertEquals('testAccount', $resolvedContent);
     $content = '[[CONTACT__NAME]]';
     $mergeTagsUtil = MergeTagsUtilFactory::make(EmailTemplate::TYPE_WORKFLOW, null, $content);
     $resolvedContent = $mergeTagsUtil->resolveMergeTags($task, $this->invalidTags);
     $this->assertFalse($resolvedContent);
     $this->assertContains('CONTACT__NAME', $this->invalidTags);
 }
 public function testRenderSummaryContentWithTask()
 {
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $billy = User::getByUsername('billy');
     $account = AccountTestHelper::createAccountByNameForOwner('taskAccount', $super);
     $task = TaskTestHelper::createTaskWithOwnerAndRelatedAccount('aTask', $super, $account);
     $content = ActivitiesUtil::renderSummaryContent($task, 'someUrl', LatestActivitiesConfigurationForm::OWNED_BY_FILTER_ALL, 'HomeModule');
     $content = ActivitiesUtil::renderSummaryContent($task, 'someUrl', LatestActivitiesConfigurationForm::OWNED_BY_FILTER_USER, 'HomeModule');
     $content = ActivitiesUtil::renderSummaryContent($task, 'someUrl', LatestActivitiesConfigurationForm::OWNED_BY_FILTER_ALL, 'UserModule');
     $content = ActivitiesUtil::renderSummaryContent($task, 'someUrl', LatestActivitiesConfigurationForm::OWNED_BY_FILTER_USER, 'UserModule');
 }
 public function testUpdateStatusOnDragInKanbanView()
 {
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $project = ProjectTestHelper::createProjectByNameForOwner('a new project', $super);
     $task = TaskTestHelper::createTaskByNameForOwner('My Kanban Task', Yii::app()->user->userModel);
     $task->project = $project;
     $task->status = Task::STATUS_IN_PROGRESS;
     $taskId = $task->id;
     $this->assertTrue($task->save());
     $task1 = TaskTestHelper::createTaskByNameForOwner('My Kanban Task 1', Yii::app()->user->userModel);
     $task1->project = $project;
     $task1->status = Task::STATUS_NEW;
     $this->assertTrue($task1->save());
     $task1Id = $task1->id;
     $taskArray = array($task, $task1);
     foreach ($taskArray as $row => $data) {
         $kanbanItem = KanbanItem::getByTask($data->id);
         if ($kanbanItem == null) {
             //Create KanbanItem here
             $kanbanItem = TasksUtil::createKanbanItemFromTask($data);
         }
         $kanbanItemsArray[] = $kanbanItem;
     }
     $this->assertEquals(KanbanItem::TYPE_SOMEDAY, $kanbanItemsArray[1]->type);
     $this->assertEquals(1, $kanbanItemsArray[1]->sortOrder);
     $this->assertEquals(1, $kanbanItemsArray[0]->sortOrder);
     $this->setGetArray(array('items' => array($task1->id, $task->id), 'type' => KanbanItem::TYPE_IN_PROGRESS));
     $content = $this->runControllerWithNoExceptionsAndGetContent('tasks/default/updateStatusOnDragInKanbanView', false);
     $contentArray = CJSON::decode($content);
     $this->assertContains('Finish', $contentArray['button']);
     $task1 = Task::getById($task1Id);
     $this->assertEquals(Task::STATUS_IN_PROGRESS, $task1->status);
     $kanbanItem = KanbanItem::getByTask($task1Id);
     $this->assertEquals(KanbanItem::TYPE_IN_PROGRESS, $kanbanItem->type);
     $kanbanItem = KanbanItem::getByTask($taskId);
     $this->assertEquals(2, $kanbanItem->sortOrder);
 }
 public function testSuperUserSearchForDuplicateModelsAction()
 {
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $this->setGetArray(array('attribute' => 'lastName', 'value' => 'fakeValue'));
     $this->runControllerWithNoExceptionsAndGetContent('leads/default/searchForDuplicateModels', true);
     $contact = LeadTestHelper::createLeadbyNameForOwner('test', $super);
     TaskTestHelper::createTaskWithOwnerAndRelatedItem('task for test', $super, $contact);
     //Test search by lastName
     $this->setGetArray(array('attribute' => 'lastName', 'value' => 'testson'));
     $content = $this->runControllerWithNoExceptionsAndGetContent('leads/default/searchForDuplicateModels');
     $object = json_decode($content);
     $this->assertEquals('There is 1 possible match. <span class="underline">Click here</span> to view.', $object->message);
     $this->assertContains('CreateModelsToMergeListAndChartView', $object->content);
     //The dupe contact has one task
     $this->assertTag(array('tag' => 'span', 'attributes' => array('class' => 'total-tasks'), 'descendant' => array('tag' => 'strong', 'content' => '1')), $object->content);
     //Test search by phone
     $contact->mobilePhone = '123456789';
     $this->assertTrue($contact->save());
     $this->setGetArray(array('attribute' => 'officePhone', 'value' => '123456789'));
     $content = $this->runControllerWithNoExceptionsAndGetContent('leads/default/searchForDuplicateModels');
     $object = json_decode($content);
     $this->assertEquals('There is 1 possible match. <span class="underline">Click here</span> to view.', $object->message);
     $this->assertContains('CreateModelsToMergeListAndChartView', $object->content);
     //Test search by email
     $contact->secondaryEmail->emailAddress = 'a@a.a';
     $this->assertTrue($contact->save());
     $this->setGetArray(array('attribute' => 'primaryEmail', 'value' => 'a@a.a'));
     $content = $this->runControllerWithNoExceptionsAndGetContent('leads/default/searchForDuplicateModels');
     $object = json_decode($content);
     $this->assertEquals('There is 1 possible match. <span class="underline">Click here</span> to view.', $object->message);
     $this->assertContains('CreateModelsToMergeListAndChartView', $object->content);
 }
 public function testGetAddedOrDeletedModelsFromReadSubscriptionTable()
 {
     ReadPermissionsSubscriptionUtil::buildTables();
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $messageLogger = new DebuggingMessageLogger();
     $task = TaskTestHelper::createTaskByNameForOwner('Test Task', $super);
     // Because ReadPermissionsSubscriptionUtil::updateAllReadSubscriptionTables completed in previous test
     // status need to be ReadPermissionsSubscriptionUtil::STATUS_COMPLETED
     $this->assertEquals(ReadPermissionsSubscriptionUtil::STATUS_COMPLETED, ReadPermissionsSubscriptionUtil::getReadPermissionUpdateStatus());
     $this->assertTrue(ReadPermissionsSubscriptionUtil::isReadPermissionSubscriptionUpdateCompleted());
     ReadPermissionsSubscriptionUtil::updateAllReadSubscriptionTables($messageLogger);
     $this->assertEquals(ReadPermissionsSubscriptionUtil::STATUS_COMPLETED, ReadPermissionsSubscriptionUtil::getReadPermissionUpdateStatus());
     $this->assertTrue(ReadPermissionsSubscriptionUtil::isReadPermissionSubscriptionUpdateCompleted());
     $sql = "SELECT * FROM task_read_subscription WHERE userid = " . $super->id;
     $permissionTableRows = ZurmoRedBean::getAll($sql);
     $this->assertEquals(1, count($permissionTableRows));
     $addedModelIds = ReadPermissionsSubscriptionUtil::getAddedOrDeletedModelsFromReadSubscriptionTable('TestService', 'Task', 0, ReadPermissionsSubscriptionUtil::TYPE_ADD, $super);
     $this->asserttrue(is_array($addedModelIds));
     $this->assertEquals(1, count($addedModelIds));
     ModelCreationApiSyncUtil::insertItem('TestService', $task->id, 'Task', '2013-05-03 15:16:06');
     $addedModelIds = ReadPermissionsSubscriptionUtil::getAddedOrDeletedModelsFromReadSubscriptionTable('TestService', 'Task', 0, ReadPermissionsSubscriptionUtil::TYPE_ADD, $super);
     $this->asserttrue(is_array($addedModelIds));
     $this->assertEquals(0, count($addedModelIds));
 }
 /**
  * Test if all deleted items was pulled from read permission tables via API.
  * Please note that here we do not test if data are inserted in read permission tables correctly, that is
  * part of read permission subscription tests
  * @throws NotFoundException
  */
 public function testGetDeletedTasks()
 {
     $timestamp = time();
     sleep(1);
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $this->deleteAllModelsAndRecordsFromReadPermissionTable('Task');
     $job = new ReadPermissionSubscriptionUpdateJob();
     $task1 = TaskTestHelper::createTaskByNameForOwner('Task1', $super);
     $task2 = TaskTestHelper::createTaskByNameForOwner('Task2', $super);
     $task3 = TaskTestHelper::createTaskByNameForOwner('Task3', $super);
     $this->assertTrue($job->run());
     sleep(1);
     $taskId1 = $task1->id;
     $taskId2 = $task2->id;
     $taskId3 = $task3->id;
     $task1->delete();
     $task2->delete();
     $task3->delete();
     $this->assertTrue($job->run());
     $authenticationData = $this->login();
     $headers = array('Accept: application/json', 'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'], 'ZURMO_TOKEN: ' . $authenticationData['token'], 'ZURMO_API_REQUEST_TYPE: REST');
     $data = array('userId' => $super->id, 'sinceTimestamp' => $timestamp, 'pagination' => array('pageSize' => 2, 'page' => 1));
     $response = $this->createApiCallWithRelativeUrl('getDeletedItems/', 'POST', $headers, array('data' => $data));
     $response = json_decode($response, true);
     $this->assertEquals(3, $response['data']['totalCount']);
     $this->assertEquals(2, $response['data']['pageSize']);
     $this->assertEquals(1, $response['data']['currentPage']);
     $this->assertContains($taskId1, $response['data']['items']);
     $this->assertContains($taskId2, $response['data']['items']);
     $data = array('userId' => $super->id, 'sinceTimestamp' => 0, 'pagination' => array('pageSize' => 2, 'page' => 2));
     $response = $this->createApiCallWithRelativeUrl('getDeletedItems/', 'POST', $headers, array('data' => $data));
     $response = json_decode($response, true);
     $this->assertEquals(3, $response['data']['totalCount']);
     $this->assertEquals(2, $response['data']['pageSize']);
     $this->assertEquals(2, $response['data']['currentPage']);
     $this->assertContains($taskId3, $response['data']['items']);
 }
 /**
  * @depends testRegularUserControllerActionsWithElevationToAccessAndCreate
  */
 public function testRegularUserControllerActionsWithElevationToModels()
 {
     //Create superAccount owned by user super.
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $superAccount = AccountTestHelper::createAccountByNameForOwner('AccountsForElevationToModelTest', $super);
     //Test nobody, access to edit and details of superAccount should fail.
     $nobody = $this->logoutCurrentUserLoginNewUserAndGetByUsername('nobody');
     $this->setGetArray(array('id' => $superAccount->id));
     $this->runControllerShouldResultInAccessFailureAndGetContent('accounts/default/details');
     //give nobody access to read
     Yii::app()->user->userModel = $super;
     $superAccount->addPermissions($nobody, Permission::READ);
     $this->assertTrue($superAccount->save());
     AllPermissionsOptimizationUtil::securableItemGivenReadPermissionsForUser($superAccount, $nobody);
     //Now the nobody user can access the details view.
     Yii::app()->user->userModel = $nobody;
     $this->setGetArray(array('id' => $superAccount->id));
     $this->runControllerWithNoExceptionsAndGetContent('accounts/default/details');
     //create task for an superAccount using the super user
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $task = TaskTestHelper::createTaskWithOwnerAndRelatedAccount('taskCreatedByNobody', $super, $superAccount);
     //Test nobody, access to edit and details of task should fail.
     Yii::app()->user->userModel = $nobody;
     $this->setGetArray(array('id' => $task->id));
     $this->resetPostArray();
     $this->runControllerShouldResultInAccessFailureAndGetContent('tasks/default/modalEdit');
     $this->setGetArray(array('id' => $task->id));
     $this->resetPostArray();
     //give nobody access to details view only
     Yii::app()->user->userModel = $super;
     $task->addPermissions($nobody, Permission::READ);
     $this->assertTrue($task->save());
     AllPermissionsOptimizationUtil::securableItemGivenReadPermissionsForUser($task, $nobody);
     //Now access to tasks view by Nobody should not fail.
     Yii::app()->user->userModel = $nobody;
     $this->setGetArray(array('id' => $task->id));
     $this->resetPostArray();
     $this->runControllerWithNoExceptionsAndGetContent('tasks/default/modalDetails');
     //Now access to tasks edit by Nobody should fail
     $this->setGetArray(array('id' => $task->id));
     $this->resetPostArray();
     $this->runControllerShouldResultInAccessFailureAndGetContent('tasks/default/modalEdit');
     //give nobody access to both details and edit view
     Yii::app()->user->userModel = $super;
     $task->addPermissions($nobody, Permission::READ_WRITE_CHANGE_PERMISSIONS);
     $this->assertTrue($task->save());
     AllPermissionsOptimizationUtil::securableItemLostReadPermissionsForUser($task, $nobody);
     AllPermissionsOptimizationUtil::securableItemGivenPermissionsForUser($task, $nobody);
     //Now access to tasks view and edit by Nobody should not fail.
     $this->setGetArray(array('id' => $task->id));
     $this->resetPostArray();
     $this->runControllerWithNoExceptionsAndGetContent('tasks/default/modalDetails');
     $this->setGetArray(array('id' => $task->id));
     $this->resetPostArray();
     $this->runControllerWithNoExceptionsAndGetContent('tasks/default/modalEdit');
     //revoke the permission from the nobody user to access the task
     Yii::app()->user->userModel = $super;
     $task->removePermissions($nobody, Permission::READ_WRITE_CHANGE_PERMISSIONS);
     $this->assertTrue($task->save());
     AllPermissionsOptimizationUtil::securableItemLostPermissionsForUser($task, $nobody);
     //Now nobodys, access to edit and details of tasks should fail.
     Yii::app()->user->userModel = $nobody;
     $this->setGetArray(array('id' => $task->id));
     $this->resetPostArray();
     $this->runControllerShouldResultInAccessFailureAndGetContent('tasks/default/modalEdit');
     $this->setGetArray(array('id' => $task->id));
     $this->resetPostArray();
     $this->runControllerShouldResultInAccessFailureAndGetContent('tasks/default/modalDetails');
     //create some roles
     Yii::app()->user->userModel = $super;
     $parentRole = new Role();
     $parentRole->name = 'AAA';
     $this->assertTrue($parentRole->save());
     $childRole = new Role();
     $childRole->name = 'BBB';
     $this->assertTrue($childRole->save());
     $userInParentRole = User::getByUsername('confused');
     $userInChildRole = User::getByUsername('nobody');
     $childRole->users->add($userInChildRole);
     $this->assertTrue($childRole->save());
     $parentRole->users->add($userInParentRole);
     $parentRole->roles->add($childRole);
     $this->assertTrue($parentRole->save());
     $userInChildRole->forget();
     $userInChildRole = User::getByUsername('nobody');
     $userInParentRole->forget();
     $userInParentRole = User::getByUsername('confused');
     $parentRoleId = $parentRole->id;
     $parentRole->forget();
     $parentRole = Role::getById($parentRoleId);
     $childRoleId = $childRole->id;
     $childRole->forget();
     $childRole = Role::getById($childRoleId);
     //create account owned by super
     $account2 = AccountTestHelper::createAccountByNameForOwner('AccountsParentRolePermission', $super);
     //Test userInParentRole, access to details and edit should fail.
     Yii::app()->user->userModel = $userInParentRole;
     $this->setGetArray(array('id' => $account2->id));
     $this->runControllerShouldResultInAccessFailureAndGetContent('accounts/default/details');
     //give userInChildRole access to READ
     Yii::app()->user->userModel = $super;
     $account2->addPermissions($userInChildRole, Permission::READ);
     $this->assertTrue($account2->save());
     AllPermissionsOptimizationUtil::securableItemGivenReadPermissionsForUser($account2, $userInChildRole);
     //Test userInChildRole, access to details should not fail.
     Yii::app()->user->userModel = $userInChildRole;
     $this->setGetArray(array('id' => $account2->id));
     $this->runControllerWithNoExceptionsAndGetContent('accounts/default/details');
     //Test userInParentRole, access to details should not fail.
     Yii::app()->user->userModel = $userInParentRole;
     $this->setGetArray(array('id' => $account2->id));
     $this->runControllerWithNoExceptionsAndGetContent('accounts/default/details');
     //create a task owned by super
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $task2 = TaskTestHelper::createTaskWithOwnerAndRelatedAccount('taskCreatedBySuperForRole', $super, $account2);
     //Test userInParentRole, access to tasks details and edit should fail.
     Yii::app()->user->userModel = $userInParentRole;
     $this->setGetArray(array('id' => $task2->id));
     $this->resetPostArray();
     $this->runControllerShouldResultInAccessFailureAndGetContent('tasks/default/modalEdit');
     $this->setGetArray(array('id' => $task2->id));
     $this->resetPostArray();
     $this->runControllerShouldResultInAccessFailureAndGetContent('tasks/default/modalDetails');
     //give userInChildRole access to READ permision for tasks
     Yii::app()->user->userModel = $super;
     $task2->addPermissions($userInChildRole, Permission::READ);
     $this->assertTrue($task2->save());
     AllPermissionsOptimizationUtil::securableItemGivenReadPermissionsForUser($task2, $userInChildRole);
     //Test userInChildRole, access to tasks details should not fail.
     Yii::app()->user->userModel = $userInChildRole;
     $this->setGetArray(array('id' => $task2->id));
     $this->resetPostArray();
     $this->runControllerWithNoExceptionsAndGetContent('tasks/default/modalDetails');
     //Test userInParentRole, access to tasks details should not fail.
     Yii::app()->user->userModel = $userInParentRole;
     $this->setGetArray(array('id' => $task2->id));
     $this->resetPostArray();
     $this->runControllerWithNoExceptionsAndGetContent('tasks/default/modalDetails');
     //give userInChildRole access to read and write for the tasks
     Yii::app()->user->userModel = $super;
     $task2->addPermissions($userInChildRole, Permission::READ_WRITE_CHANGE_PERMISSIONS);
     $this->assertTrue($task2->save());
     AllPermissionsOptimizationUtil::securableItemLostReadPermissionsForUser($task2, $userInChildRole);
     AllPermissionsOptimizationUtil::securableItemGivenPermissionsForUser($task2, $userInChildRole);
     //Test userInChildRole, access to tasks edit should not fail.
     Yii::app()->user->userModel = $userInChildRole;
     $this->setGetArray(array('id' => $task2->id));
     $this->resetPostArray();
     $this->runControllerWithNoExceptionsAndGetContent('tasks/default/modalEdit');
     //Test userInParentRole, access to tasks edit should not fail.
     Yii::app()->user->userModel = $userInParentRole;
     $this->setGetArray(array('id' => $task2->id));
     $this->resetPostArray();
     $this->runControllerWithNoExceptionsAndGetContent('tasks/default/modalEdit');
     //revoke userInChildRole access to read and write tasks
     Yii::app()->user->userModel = $super;
     $task2->removePermissions($userInChildRole, Permission::READ_WRITE_CHANGE_PERMISSIONS);
     $this->assertTrue($task2->save());
     AllPermissionsOptimizationUtil::securableItemLostPermissionsForUser($task2, $userInChildRole);
     //Test userInChildRole, access to detail and edit should fail.
     Yii::app()->user->userModel = $userInChildRole;
     $this->setGetArray(array('id' => $task2->id));
     $this->runControllerShouldResultInAccessFailureAndGetContent('tasks/default/modalDetails');
     $this->setGetArray(array('id' => $task2->id));
     $this->runControllerShouldResultInAccessFailureAndGetContent('tasks/default/modalEdit');
     //Test userInParentRole, access to detail and edit should fail.
     Yii::app()->user->userModel = $userInParentRole;
     $this->setGetArray(array('id' => $task2->id));
     $this->runControllerShouldResultInAccessFailureAndGetContent('tasks/default/modalDetails');
     $this->setGetArray(array('id' => $task2->id));
     $this->runControllerShouldResultInAccessFailureAndGetContent('tasks/default/modalEdit');
     //clear up the role relationships between users so not to effect next assertions
     $parentRole->users->remove($userInParentRole);
     $parentRole->roles->remove($childRole);
     $this->assertTrue($parentRole->save());
     $childRole->users->remove($userInChildRole);
     $this->assertTrue($childRole->save());
     //create some groups and assign users to groups
     Yii::app()->user->userModel = $super;
     $parentGroup = new Group();
     $parentGroup->name = 'AAA';
     $this->assertTrue($parentGroup->save());
     $childGroup = new Group();
     $childGroup->name = 'BBB';
     $this->assertTrue($childGroup->save());
     $userInChildGroup = User::getByUsername('confused');
     $userInParentGroup = User::getByUsername('nobody');
     $childGroup->users->add($userInChildGroup);
     $this->assertTrue($childGroup->save());
     $parentGroup->users->add($userInParentGroup);
     $parentGroup->groups->add($childGroup);
     $this->assertTrue($parentGroup->save());
     $parentGroup->forget();
     $childGroup->forget();
     $parentGroup = Group::getByName('AAA');
     $childGroup = Group::getByName('BBB');
     //Add access for the confused user to accounts and creation of accounts.
     $userInChildGroup->setRight('AccountsModule', AccountsModule::RIGHT_ACCESS_ACCOUNTS);
     $userInChildGroup->setRight('AccountsModule', AccountsModule::RIGHT_CREATE_ACCOUNTS);
     $this->assertTrue($userInChildGroup->save());
     //create account owned by super
     $account3 = AccountTestHelper::createAccountByNameForOwner('testingAccountsParentGroupPermission', $super);
     //Test userInParentGroup, access to details should fail.
     Yii::app()->user->userModel = $userInParentGroup;
     $this->setGetArray(array('id' => $account3->id));
     $this->runControllerShouldResultInAccessFailureAndGetContent('accounts/default/details');
     //Test userInChildGroup, access to details should fail.
     Yii::app()->user->userModel = $userInChildGroup;
     $this->setGetArray(array('id' => $account3->id));
     $this->runControllerShouldResultInAccessFailureAndGetContent('accounts/default/details');
     //give parentGroup access to READ
     Yii::app()->user->userModel = $super;
     $account3->addPermissions($parentGroup, Permission::READ);
     $this->assertTrue($account3->save());
     AllPermissionsOptimizationUtil::securableItemGivenReadPermissionsForGroup($account3, $parentGroup);
     //Test userInParentGroup, access to details should not fail.
     Yii::app()->user->userModel = $userInParentGroup;
     $this->setGetArray(array('id' => $account3->id));
     $this->runControllerWithNoExceptionsAndGetContent('accounts/default/details');
     //Test userInChildGroup, access to details should not fail.
     Yii::app()->user->userModel = $userInChildGroup;
     $this->setGetArray(array('id' => $account3->id));
     $this->runControllerWithNoExceptionsAndGetContent('accounts/default/details');
     //create a task owned by super
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $task3 = TaskTestHelper::createTaskWithOwnerAndRelatedAccount('taskCreatedBySuperForGroup', $super, $account3);
     //Add access for the confused user to accounts and creation of accounts.
     $userInChildGroup->setRight('TasksModule', TasksModule::RIGHT_ACCESS_TASKS);
     $userInChildGroup->setRight('TasksModule', TasksModule::RIGHT_CREATE_TASKS);
     $this->assertTrue($userInChildGroup->save());
     //Test userInParentGroup, access to tasks details and edit should fail.
     Yii::app()->user->userModel = $userInParentGroup;
     $this->setGetArray(array('id' => $task3->id));
     $this->resetPostArray();
     $this->runControllerShouldResultInAccessFailureAndGetContent('tasks/default/modalEdit');
     $this->setGetArray(array('id' => $task3->id));
     $this->resetPostArray();
     $this->runControllerShouldResultInAccessFailureAndGetContent('tasks/default/modalDetails');
     //Test userInChildGroup, access to tasks details and edit should fail.
     Yii::app()->user->userModel = $userInChildGroup;
     $this->setGetArray(array('id' => $task3->id));
     $this->runControllerShouldResultInAccessFailureAndGetContent('tasks/default/modalDetails');
     $this->setGetArray(array('id' => $task3->id));
     $this->runControllerShouldResultInAccessFailureAndGetContent('tasks/default/modalEdit');
     //give parentGroup access to READ
     Yii::app()->user->userModel = $super;
     $task3->addPermissions($parentGroup, Permission::READ);
     $this->assertTrue($task3->save());
     AllPermissionsOptimizationUtil::securableItemGivenReadPermissionsForGroup($task3, $parentGroup);
     //Test userInParentGroup, access to tasks details should not fail.
     Yii::app()->user->userModel = $userInParentGroup;
     $this->setGetArray(array('id' => $task3->id));
     $this->runControllerWithNoExceptionsAndGetContent('tasks/default/modalDetails');
     //Test userInChildGroup, access to tasks details should not fail.
     Yii::app()->user->userModel = $userInChildGroup;
     $this->setGetArray(array('id' => $task3->id));
     $this->runControllerWithNoExceptionsAndGetContent('tasks/default/modalDetails');
     //give parentGroup access to read and write
     Yii::app()->user->userModel = $super;
     $task3->addPermissions($parentGroup, Permission::READ_WRITE_CHANGE_PERMISSIONS);
     $this->assertTrue($task3->save());
     AllPermissionsOptimizationUtil::securableItemLostReadPermissionsForGroup($task3, $parentGroup);
     AllPermissionsOptimizationUtil::securableItemGivenPermissionsForGroup($task3, $parentGroup);
     //Test userInParentGroup, access to edit tasks should not fail.
     Yii::app()->user->userModel = $userInParentGroup;
     $this->setGetArray(array('id' => $task3->id));
     $this->runControllerWithNoExceptionsAndGetContent('tasks/default/modalEdit');
     //Test userInChildGroup, access to edit tasks should not fail.
     Yii::app()->user->userModel = $userInChildGroup;
     $this->logoutCurrentUserLoginNewUserAndGetByUsername($userInChildGroup->username);
     $this->setGetArray(array('id' => $task3->id));
     $this->runControllerWithNoExceptionsAndGetContent('tasks/default/modalEdit');
     //revoke parentGroup access to tasks read and write
     Yii::app()->user->userModel = $super;
     $task3->removePermissions($parentGroup, Permission::READ_WRITE_CHANGE_PERMISSIONS);
     $this->assertTrue($task3->save());
     AllPermissionsOptimizationUtil::securableItemLostPermissionsForGroup($task3, $parentGroup);
     //Test userInChildGroup, access to tasks detail should fail.
     Yii::app()->user->userModel = $userInChildGroup;
     $this->setGetArray(array('id' => $task3->id));
     $this->runControllerShouldResultInAccessFailureAndGetContent('tasks/default/modalDetails');
     $this->setGetArray(array('id' => $task3->id));
     $this->runControllerShouldResultInAccessFailureAndGetContent('tasks/default/modalEdit');
     //Test userInParentGroup, access to tasks detail should fail.
     Yii::app()->user->userModel = $userInParentGroup;
     $this->setGetArray(array('id' => $task3->id));
     $this->runControllerShouldResultInAccessFailureAndGetContent('tasks/default/modalDetails');
     $this->setGetArray(array('id' => $task3->id));
     $this->runControllerShouldResultInAccessFailureAndGetContent('tasks/default/modalEdit');
     //clear up the role relationships between users so not to effect next assertions
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $userInParentGroup->forget();
     $userInChildGroup->forget();
     $childGroup->forget();
     $parentGroup->forget();
     $userInParentGroup = User::getByUsername('nobody');
     $userInChildGroup = User::getByUsername('confused');
     $childGroup = Group::getByName('BBB');
     $parentGroup = Group::getByName('AAA');
     $parentGroup->users->remove($userInParentGroup);
     $parentGroup->groups->remove($childGroup);
     $this->assertTrue($parentGroup->save());
     $childGroup->users->remove($userInChildGroup);
     $this->assertTrue($childGroup->save());
 }