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 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 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 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(); }
/** * @depends testUnprivilegedUserViewUpdateDeleteTasks */ public function testSearchTasks() { $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; $anotherUser = User::getByUsername('steven'); $authenticationData = $this->login(); $headers = array('Accept: application/json', 'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'], 'ZURMO_TOKEN: ' . $authenticationData['token'], 'ZURMO_API_REQUEST_TYPE: REST'); $firstAccount = AccountTestHelper::createAccountByNameTypeAndIndustryForOwner('First Account', 'Customer', 'Automotive', $super); $secondAccount = AccountTestHelper::createAccountByNameTypeAndIndustryForOwner('Second Account', 'Customer', 'Automotive', $super); TaskTestHelper::createTaskWithOwnerAndRelatedAccount('First Task', $super, $firstAccount); TaskTestHelper::createTaskWithOwnerAndRelatedAccount('Second Task', $super, $firstAccount); TaskTestHelper::createTaskWithOwnerAndRelatedAccount('Third Task', $super, $secondAccount); TaskTestHelper::createTaskWithOwnerAndRelatedAccount('Forth Task', $anotherUser, $secondAccount); TaskTestHelper::createTaskWithOwnerAndRelatedAccount('Fifth Task', $super, $firstAccount); $searchParams = array('pagination' => array('page' => 1, 'pageSize' => 3), 'search' => array('name' => ''), 'sort' => 'name'); $searchParamsQuery = http_build_query($searchParams); $response = ApiRestTestHelper::createApiCall($this->serverUrl . '/test.php/tasks/task/api/list/filter/' . $searchParamsQuery, 'GET', $headers); $response = json_decode($response, true); $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']); $this->assertEquals(3, count($response['data']['items'])); $this->assertEquals(5, $response['data']['totalCount']); $this->assertEquals(1, $response['data']['currentPage']); $this->assertEquals('Fifth Task', $response['data']['items'][0]['name']); $this->assertEquals('First Task', $response['data']['items'][1]['name']); $this->assertEquals('Forth Task', $response['data']['items'][2]['name']); // Second page $searchParams['pagination']['page'] = 2; $searchParamsQuery = http_build_query($searchParams); $response = ApiRestTestHelper::createApiCall($this->serverUrl . '/test.php/tasks/task/api/list/filter/' . $searchParamsQuery, 'GET', $headers); $response = json_decode($response, true); $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']); $this->assertEquals(2, count($response['data']['items'])); $this->assertEquals(5, $response['data']['totalCount']); $this->assertEquals(2, $response['data']['currentPage']); $this->assertEquals('Second Task', $response['data']['items'][0]['name']); $this->assertEquals('Third Task', $response['data']['items'][1]['name']); // Search by name $searchParams['pagination']['page'] = 1; $searchParams['search']['name'] = 'First Task'; $searchParamsQuery = http_build_query($searchParams); $response = ApiRestTestHelper::createApiCall($this->serverUrl . '/test.php/tasks/task/api/list/filter/' . $searchParamsQuery, 'GET', $headers); $response = json_decode($response, true); $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']); $this->assertEquals(1, count($response['data']['items'])); $this->assertEquals(1, $response['data']['totalCount']); $this->assertEquals(1, $response['data']['currentPage']); $this->assertEquals('First Task', $response['data']['items'][0]['name']); // No results $searchParams['pagination']['page'] = 1; $searchParams['search']['name'] = 'First Task 2'; $searchParamsQuery = http_build_query($searchParams); $response = ApiRestTestHelper::createApiCall($this->serverUrl . '/test.php/tasks/task/api/list/filter/' . $searchParamsQuery, 'GET', $headers); $response = json_decode($response, true); $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']); $this->assertEquals(0, $response['data']['totalCount']); $this->assertFalse(isset($response['data']['items'])); // Search by name desc. $searchParams = array('pagination' => array('page' => 1, 'pageSize' => 3), 'search' => array('name' => ''), 'sort' => 'name.desc'); $searchParamsQuery = http_build_query($searchParams); $response = ApiRestTestHelper::createApiCall($this->serverUrl . '/test.php/tasks/task/api/list/filter/' . $searchParamsQuery, 'GET', $headers); $response = json_decode($response, true); $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']); $this->assertEquals(3, count($response['data']['items'])); $this->assertEquals(5, $response['data']['totalCount']); $this->assertEquals(1, $response['data']['currentPage']); $this->assertEquals('Third Task', $response['data']['items'][0]['name']); $this->assertEquals('Second Task', $response['data']['items'][1]['name']); $this->assertEquals('Forth Task', $response['data']['items'][2]['name']); // Second page $searchParams['pagination']['page'] = 2; $searchParamsQuery = http_build_query($searchParams); $response = ApiRestTestHelper::createApiCall($this->serverUrl . '/test.php/tasks/task/api/list/filter/' . $searchParamsQuery, 'GET', $headers); $response = json_decode($response, true); $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']); $this->assertEquals(2, count($response['data']['items'])); $this->assertEquals(5, $response['data']['totalCount']); $this->assertEquals(2, $response['data']['currentPage']); $this->assertEquals('First Task', $response['data']['items'][0]['name']); $this->assertEquals('Fifth Task', $response['data']['items'][1]['name']); // Search by owner, order by name desc $searchParams = array('pagination' => array('page' => 1, 'pageSize' => 3), 'search' => array('owner' => array('id' => $super->id)), 'sort' => 'name.desc'); $searchParamsQuery = http_build_query($searchParams); $response = ApiRestTestHelper::createApiCall($this->serverUrl . '/test.php/tasks/task/api/list/filter/' . $searchParamsQuery, 'GET', $headers); $response = json_decode($response, true); $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']); $this->assertEquals(4, $response['data']['totalCount']); $this->assertEquals(3, count($response['data']['items'])); $this->assertEquals(1, $response['data']['currentPage']); $this->assertEquals('Third Task', $response['data']['items'][0]['name']); $this->assertEquals('Second Task', $response['data']['items'][1]['name']); $this->assertEquals('First Task', $response['data']['items'][2]['name']); // Second page $searchParams['pagination']['page'] = 2; $searchParamsQuery = http_build_query($searchParams); $response = ApiRestTestHelper::createApiCall($this->serverUrl . '/test.php/tasks/task/api/list/filter/' . $searchParamsQuery, 'GET', $headers); $response = json_decode($response, true); $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']); $this->assertEquals(1, count($response['data']['items'])); $this->assertEquals(4, $response['data']['totalCount']); $this->assertEquals(2, $response['data']['currentPage']); $this->assertEquals('Fifth Task', $response['data']['items'][0]['name']); // Search by account, order by name desc $searchParams = array('pagination' => array('page' => 1, 'pageSize' => 3), 'search' => array('activityItems' => array('id' => $firstAccount->getClassId('Item'))), 'sort' => 'name.desc'); $searchParamsQuery = http_build_query($searchParams); $response = ApiRestTestHelper::createApiCall($this->serverUrl . '/test.php/tasks/task/api/list/filter/' . $searchParamsQuery, 'GET', $headers); $response = json_decode($response, true); $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']); $this->assertEquals(3, $response['data']['totalCount']); $this->assertEquals(3, count($response['data']['items'])); $this->assertEquals(1, $response['data']['currentPage']); $this->assertEquals('Second Task', $response['data']['items'][0]['name']); $this->assertEquals('First Task', $response['data']['items'][1]['name']); $this->assertEquals('Fifth Task', $response['data']['items'][2]['name']); }
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); }
/** * @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()); }
public function testKanbanViewForAccountDetails() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); AccountTestHelper::createAccountByNameForOwner('superAccount', $super); $accounts = Account::getByName('superAccount'); $task = TaskTestHelper::createTaskWithOwnerAndRelatedAccount('MyTask', $super, $accounts[0], Task::STATUS_IN_PROGRESS); $taskNew = TaskTestHelper::createTaskWithOwnerAndRelatedAccount('MyTask New', $super, $accounts[0], Task::STATUS_NEW); $this->setGetArray(array('id' => $accounts[0]->id, 'kanbanBoard' => '1')); $content = $this->runControllerWithNoExceptionsAndGetContent('accounts/default/details'); $matcher = array('tag' => 'a', 'ancestor' => array('tag' => 'li', 'id' => 'items_' . $task->id, 'tag' => 'ul', 'id' => 'task-sortable-rows-3'), 'content' => 'MyTask'); $this->assertTag($matcher, $content); $matcher = array('tag' => 'a', 'ancestor' => array('tag' => 'li', 'id' => 'items_' . $taskNew->id, 'tag' => 'ul', 'id' => 'task-sortable-rows-1'), 'content' => 'MyTask New'); $this->assertTag($matcher, $content); }