public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     $super = SecurityTestHelper::createSuperAdmin();
     Yii::app()->user->userModel = $super;
     Yii::app()->timeZoneHelper->load();
     MeetingTestHelper::createCategories();
 }
Exemplo n.º 2
0
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     SecurityTestHelper::createSuperAdmin();
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $account = AccountTestHelper::createAccountByNameForOwner('anAccount', $super);
     MeetingTestHelper::createCategories();
 }
 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 three contacts for testing.
     ContactTestHelper::createContactWithAccountByNameForOwner('superContact1', $super, $account);
     ContactTestHelper::createContactWithAccountByNameForOwner('superContact2', $super, $account);
     ContactTestHelper::createContactWithAccountByNameForOwner('superContact3', $super, $account);
     //Create a meeting for testing.
     MeetingTestHelper::createMeetingWithOwnerAndRelatedAccount('superMeeting', $super, $account);
 }
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     SecurityTestHelper::createSuperAdmin();
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $account = AccountTestHelper::createAccountByNameForOwner('anAccount', $super);
     MeetingTestHelper::createCategories();
     MeetingTestHelper::createMeetingWithOwnerAndRelatedAccount('aMeeting', $super, $account);
     $savedCalendar = new SavedCalendar();
     $savedCalendar->name = 'aSavedCalendar';
     $savedCalendar->timeZone = 'America/Chicago';
     $savedCalendar->location = 'Newyork';
     $savedCalendar->moduleClassName = 'MeetingsModule';
     $savedCalendar->startAttributeName = 'startDateTime';
     $savedCalendar->endAttributeName = 'endDateTime';
     $savedCalendar->color = '#c05d91';
     $savedCalendar->owner = $super;
     $savedCalendar->save();
 }
Exemplo n.º 5
0
 /**
  * @depends testApiServerUrl
  */
 public function testEditMeetingWIthIncorrectDataType()
 {
     $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');
     $meeting = MeetingTestHelper::createMeetingByNameForOwner('Newest Meeting', $super);
     // Provide data with wrong type.
     $data['startDateTime'] = "A";
     $response = ApiRestTestHelper::createApiCall($this->serverUrl . '/test.php/meetings/meeting/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 = $meeting->id;
     $data = array();
     $data['startDateTime'] = "A";
     $response = ApiRestTestHelper::createApiCall($this->serverUrl . '/test.php/meetings/meeting/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']));
 }
 public function testRenderSummaryContentWithMeeting()
 {
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $billy = User::getByUsername('billy');
     $account = AccountTestHelper::createAccountByNameForOwner('meetingAccount', $super);
     $meeting = MeetingTestHelper::createMeetingWithOwnerAndRelatedAccount('aMeeting', $super, $account);
     $content = ActivitiesUtil::renderSummaryContent($meeting, 'someUrl', LatestActivitiesConfigurationForm::OWNED_BY_FILTER_ALL, 'HomeModule');
     $content = ActivitiesUtil::renderSummaryContent($meeting, 'someUrl', LatestActivitiesConfigurationForm::OWNED_BY_FILTER_USER, 'HomeModule');
     $content = ActivitiesUtil::renderSummaryContent($meeting, 'someUrl', LatestActivitiesConfigurationForm::OWNED_BY_FILTER_ALL, 'UserModule');
     $content = ActivitiesUtil::renderSummaryContent($meeting, 'someUrl', LatestActivitiesConfigurationForm::OWNED_BY_FILTER_USER, 'UserModule');
 }
 /**
  * @depends testRegularUserControllerActionsWithElevationToAccessAndCreate
  */
 public function testRegularUserControllerActionsWithElevationToModels()
 {
     //Create superAccount owned by user super.
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $superAccount = AccountTestHelper::createAccountByNameForOwner('AccountsForElevationToModelTest', $super);
     //Test nobody, access to 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 meeting for an superAccount using the super user
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $meeting = MeetingTestHelper::createMeetingWithOwnerAndRelatedAccount('meetingCreatedByNobody', $super, $superAccount);
     //Test nobody, access to edit, details and delete of meeting should fail.
     Yii::app()->user->userModel = $nobody;
     $this->setGetArray(array('id' => $meeting->id));
     $this->resetPostArray();
     $this->runControllerShouldResultInAccessFailureAndGetContent('meetings/default/edit');
     $this->setGetArray(array('id' => $meeting->id));
     $this->resetPostArray();
     $this->runControllerShouldResultInAccessFailureAndGetContent('meetings/default/details');
     $this->setGetArray(array('id' => $meeting->id));
     $this->resetPostArray();
     $this->runControllerShouldResultInAccessFailureAndGetContent('meetings/default/delete');
     //give nobody access to details view only
     Yii::app()->user->userModel = $super;
     $meeting->addPermissions($nobody, Permission::READ);
     $this->assertTrue($meeting->save());
     AllPermissionsOptimizationUtil::securableItemGivenReadPermissionsForUser($meeting, $nobody);
     //Now access to meetings view by Nobody should not fail.
     Yii::app()->user->userModel = $nobody;
     $this->setGetArray(array('id' => $meeting->id));
     $this->resetPostArray();
     $this->runControllerWithNoExceptionsAndGetContent('meetings/default/details');
     //Now access to meetings edit and delete by Nobody should fail
     $this->setGetArray(array('id' => $meeting->id));
     $this->resetPostArray();
     $this->runControllerShouldResultInAccessFailureAndGetContent('meetings/default/edit');
     $this->setGetArray(array('id' => $meeting->id));
     $this->resetPostArray();
     $this->runControllerShouldResultInAccessFailureAndGetContent('meetings/default/delete');
     //give nobody access to both details and edit view
     Yii::app()->user->userModel = $super;
     $meeting->addPermissions($nobody, Permission::READ_WRITE_CHANGE_PERMISSIONS);
     $this->assertTrue($meeting->save());
     AllPermissionsOptimizationUtil::securableItemLostReadPermissionsForUser($meeting, $nobody);
     AllPermissionsOptimizationUtil::securableItemGivenPermissionsForUser($meeting, $nobody);
     //Now access to meetings view and edit by Nobody should not fail.
     Yii::app()->user->userModel = $nobody;
     $this->setGetArray(array('id' => $meeting->id));
     $this->resetPostArray();
     $this->runControllerWithNoExceptionsAndGetContent('meetings/default/details');
     $this->setGetArray(array('id' => $meeting->id));
     $this->resetPostArray();
     $this->runControllerWithNoExceptionsAndGetContent('meetings/default/edit');
     //Now access to meetings delete by Nobody should fail
     $this->setGetArray(array('id' => $meeting->id));
     $this->resetPostArray();
     $this->runControllerShouldResultInAccessFailureAndGetContent('meetings/default/delete');
     //revoke the permission from the nobody user to access the meeting
     Yii::app()->user->userModel = $super;
     $meeting->removePermissions($nobody, Permission::READ_WRITE_CHANGE_PERMISSIONS);
     $this->assertTrue($meeting->save());
     AllPermissionsOptimizationUtil::securableItemLostPermissionsForUser($meeting, $nobody);
     //Now nobodys, access to edit, details and delete of meetings should fail.
     Yii::app()->user->userModel = $nobody;
     $this->setGetArray(array('id' => $meeting->id));
     $this->resetPostArray();
     $this->runControllerShouldResultInAccessFailureAndGetContent('meetings/default/edit');
     $this->setGetArray(array('id' => $meeting->id));
     $this->resetPostArray();
     $this->runControllerShouldResultInAccessFailureAndGetContent('meetings/default/details');
     $this->setGetArray(array('id' => $meeting->id));
     $this->resetPostArray();
     $this->runControllerShouldResultInAccessFailureAndGetContent('meetings/default/delete');
     //give nobody access to both details and edit view
     Yii::app()->user->userModel = $super;
     $meeting->addPermissions($nobody, Permission::READ_WRITE_DELETE);
     $this->assertTrue($meeting->save());
     AllPermissionsOptimizationUtil::securableItemGivenPermissionsForUser($meeting, $nobody);
     //Now nobodys, access to delete of meetings should not fail.
     Yii::app()->user->userModel = $nobody;
     $this->setGetArray(array('id' => $meeting->id));
     $this->resetPostArray();
     $this->runControllerWithRedirectExceptionAndGetContent('meetings/default/delete');
     //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 meeting owned by super
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $meeting2 = MeetingTestHelper::createMeetingWithOwnerAndRelatedAccount('meetingCreatedBySuperForRole', $super, $account2);
     //Test userInChildRole, access to meetings details, edit and delete should fail.
     Yii::app()->user->userModel = $userInChildRole;
     $this->setGetArray(array('id' => $meeting2->id));
     $this->resetPostArray();
     $this->runControllerShouldResultInAccessFailureAndGetContent('meetings/default/edit');
     $this->setGetArray(array('id' => $meeting2->id));
     $this->resetPostArray();
     $this->runControllerShouldResultInAccessFailureAndGetContent('meetings/default/details');
     $this->setGetArray(array('id' => $meeting2->id));
     $this->resetPostArray();
     $this->runControllerShouldResultInAccessFailureAndGetContent('meetings/default/delete');
     //Test userInParentRole, access to meetings details, edit and delete should fail.
     Yii::app()->user->userModel = $userInParentRole;
     $this->setGetArray(array('id' => $meeting2->id));
     $this->resetPostArray();
     $this->runControllerShouldResultInAccessFailureAndGetContent('meetings/default/edit');
     $this->setGetArray(array('id' => $meeting2->id));
     $this->resetPostArray();
     $this->runControllerShouldResultInAccessFailureAndGetContent('meetings/default/details');
     $this->setGetArray(array('id' => $meeting2->id));
     $this->resetPostArray();
     $this->runControllerShouldResultInAccessFailureAndGetContent('meetings/default/delete');
     //give userInChildRole access to READ permision for meetings
     Yii::app()->user->userModel = $super;
     $meeting2->addPermissions($userInChildRole, Permission::READ);
     $this->assertTrue($meeting2->save());
     AllPermissionsOptimizationUtil::securableItemGivenReadPermissionsForUser($meeting2, $userInChildRole);
     //Test userInChildRole, access to meetings details should not fail.
     Yii::app()->user->userModel = $userInChildRole;
     $this->setGetArray(array('id' => $meeting2->id));
     $this->resetPostArray();
     $this->runControllerWithNoExceptionsAndGetContent('meetings/default/details');
     //Test userInChildRole, access to meetings edit and delete should fail.
     $this->setGetArray(array('id' => $meeting2->id));
     $this->resetPostArray();
     $this->runControllerShouldResultInAccessFailureAndGetContent('meetings/default/edit');
     $this->setGetArray(array('id' => $meeting2->id));
     $this->resetPostArray();
     $this->runControllerShouldResultInAccessFailureAndGetContent('meetings/default/delete');
     //Test userInParentRole, access to meetings details should not fail.
     Yii::app()->user->userModel = $userInParentRole;
     $this->setGetArray(array('id' => $meeting2->id));
     $this->resetPostArray();
     $this->runControllerWithNoExceptionsAndGetContent('meetings/default/details');
     //Test userInParentRole, access to meetings edit and delete should fail.
     $this->setGetArray(array('id' => $meeting2->id));
     $this->resetPostArray();
     $this->runControllerShouldResultInAccessFailureAndGetContent('meetings/default/edit');
     $this->setGetArray(array('id' => $meeting2->id));
     $this->resetPostArray();
     $this->runControllerShouldResultInAccessFailureAndGetContent('meetings/default/delete');
     //give userInChildRole access to read and write for the meetings
     Yii::app()->user->userModel = $super;
     $meeting2->addPermissions($userInChildRole, Permission::READ_WRITE_CHANGE_PERMISSIONS);
     $this->assertTrue($meeting2->save());
     AllPermissionsOptimizationUtil::securableItemLostReadPermissionsForUser($meeting2, $userInChildRole);
     AllPermissionsOptimizationUtil::securableItemGivenPermissionsForUser($meeting2, $userInChildRole);
     //Test userInChildRole, access to meetings edit should not fail.
     Yii::app()->user->userModel = $userInChildRole;
     $this->setGetArray(array('id' => $meeting2->id));
     $this->resetPostArray();
     $this->runControllerWithNoExceptionsAndGetContent('meetings/default/edit');
     //Test userInChildRole, access to meetings delete should fail.
     $this->setGetArray(array('id' => $meeting2->id));
     $this->resetPostArray();
     $this->runControllerShouldResultInAccessFailureAndGetContent('meetings/default/delete');
     //Test userInParentRole, access to meetings edit should not fail.
     Yii::app()->user->userModel = $userInParentRole;
     $this->setGetArray(array('id' => $meeting2->id));
     $this->resetPostArray();
     $this->runControllerWithNoExceptionsAndGetContent('meetings/default/edit');
     //Test userInParentRole, access to meetings delete should fail.
     $this->setGetArray(array('id' => $meeting2->id));
     $this->resetPostArray();
     $this->runControllerShouldResultInAccessFailureAndGetContent('meetings/default/delete');
     //revoke userInChildRole access to read and write meetings
     Yii::app()->user->userModel = $super;
     $meeting2->removePermissions($userInChildRole, Permission::READ_WRITE_CHANGE_PERMISSIONS);
     $this->assertTrue($meeting2->save());
     AllPermissionsOptimizationUtil::securableItemLostPermissionsForUser($meeting2, $userInChildRole);
     //Test userInChildRole, access to detail, edit and delete should fail.
     Yii::app()->user->userModel = $userInChildRole;
     $this->setGetArray(array('id' => $meeting2->id));
     $this->runControllerShouldResultInAccessFailureAndGetContent('meetings/default/details');
     $this->setGetArray(array('id' => $meeting2->id));
     $this->runControllerShouldResultInAccessFailureAndGetContent('meetings/default/edit');
     $this->setGetArray(array('id' => $meeting2->id));
     $this->resetPostArray();
     $this->runControllerShouldResultInAccessFailureAndGetContent('meetings/default/delete');
     //Test userInParentRole, access to detail, edit and delete should fail.
     Yii::app()->user->userModel = $userInParentRole;
     $this->setGetArray(array('id' => $meeting2->id));
     $this->runControllerShouldResultInAccessFailureAndGetContent('meetings/default/details');
     $this->setGetArray(array('id' => $meeting2->id));
     $this->runControllerShouldResultInAccessFailureAndGetContent('meetings/default/edit');
     $this->setGetArray(array('id' => $meeting2->id));
     $this->resetPostArray();
     $this->runControllerShouldResultInAccessFailureAndGetContent('meetings/default/delete');
     //give userInChildRole access to read and write for the meetings
     Yii::app()->user->userModel = $super;
     $meeting2->addPermissions($userInChildRole, Permission::READ_WRITE_DELETE);
     $this->assertTrue($meeting2->save());
     AllPermissionsOptimizationUtil::securableItemGivenPermissionsForUser($meeting2, $userInChildRole);
     //Test userInParentRole, access to delete should not fail.
     Yii::app()->user->userModel = $userInParentRole;
     $this->setGetArray(array('id' => $meeting2->id));
     $this->resetPostArray();
     $this->runControllerWithRedirectExceptionAndGetContent('meetings/default/delete');
     //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);
     $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 meeting owned by super
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $meeting3 = MeetingTestHelper::createMeetingWithOwnerAndRelatedAccount('mettingCreatedBySuperForGroup', $super, $account3);
     //Add access for the confused user to accounts and creation of accounts.
     $userInChildGroup->setRight('MeetingsModule', MeetingsModule::RIGHT_ACCESS_MEETINGS);
     $userInChildGroup->setRight('MeetingsModule', MeetingsModule::RIGHT_CREATE_MEETINGS);
     $userInChildGroup->setRight('MeetingsModule', MeetingsModule::RIGHT_DELETE_MEETINGS);
     $this->assertTrue($userInChildGroup->save());
     //Test userInParentGroup, access to meetings details and edit should fail.
     Yii::app()->user->userModel = $userInParentGroup;
     $this->setGetArray(array('id' => $meeting3->id));
     $this->resetPostArray();
     $this->runControllerShouldResultInAccessFailureAndGetContent('meetings/default/edit');
     $this->setGetArray(array('id' => $meeting3->id));
     $this->resetPostArray();
     $this->runControllerShouldResultInAccessFailureAndGetContent('meetings/default/details');
     $this->setGetArray(array('id' => $meeting3->id));
     $this->resetPostArray();
     $this->runControllerShouldResultInAccessFailureAndGetContent('meetings/default/delete');
     //Test userInChildGroup, access to meetings details and edit should fail.
     Yii::app()->user->userModel = $userInChildGroup;
     $this->setGetArray(array('id' => $meeting3->id));
     $this->runControllerShouldResultInAccessFailureAndGetContent('meetings/default/details');
     $this->setGetArray(array('id' => $meeting3->id));
     $this->runControllerShouldResultInAccessFailureAndGetContent('meetings/default/edit');
     $this->setGetArray(array('id' => $meeting3->id));
     $this->resetPostArray();
     $this->runControllerShouldResultInAccessFailureAndGetContent('meetings/default/delete');
     //give parentGroup access to READ
     Yii::app()->user->userModel = $super;
     $meeting3->addPermissions($parentGroup, Permission::READ);
     $this->assertTrue($meeting3->save());
     AllPermissionsOptimizationUtil::securableItemGivenReadPermissionsForGroup($meeting3, $parentGroup);
     //Test userInParentGroup, access to meetings details should not fail.
     Yii::app()->user->userModel = $userInParentGroup;
     $this->setGetArray(array('id' => $meeting3->id));
     $this->runControllerWithNoExceptionsAndGetContent('meetings/default/details');
     //Test userInParentGroup, access to meetings edit and delete should fail.
     $this->setGetArray(array('id' => $meeting3->id));
     $this->runControllerShouldResultInAccessFailureAndGetContent('meetings/default/edit');
     $this->setGetArray(array('id' => $meeting3->id));
     $this->resetPostArray();
     $this->runControllerShouldResultInAccessFailureAndGetContent('meetings/default/delete');
     //Test userInChildGroup, access to meetings details should not fail.
     Yii::app()->user->userModel = $userInChildGroup;
     $this->setGetArray(array('id' => $meeting3->id));
     $this->runControllerWithNoExceptionsAndGetContent('meetings/default/details');
     //Test userInChildGroup, access to meetings edit and delete should fail.
     $this->setGetArray(array('id' => $meeting3->id));
     $this->runControllerShouldResultInAccessFailureAndGetContent('meetings/default/edit');
     $this->setGetArray(array('id' => $meeting3->id));
     $this->resetPostArray();
     $this->runControllerShouldResultInAccessFailureAndGetContent('meetings/default/delete');
     //give parentGroup access to read and write
     Yii::app()->user->userModel = $super;
     $meeting3->addPermissions($parentGroup, Permission::READ_WRITE_CHANGE_PERMISSIONS);
     $this->assertTrue($meeting3->save());
     AllPermissionsOptimizationUtil::securableItemLostReadPermissionsForGroup($meeting3, $parentGroup);
     AllPermissionsOptimizationUtil::securableItemGivenPermissionsForGroup($meeting3, $parentGroup);
     //Test userInParentGroup, access to edit meetings should not fail.
     Yii::app()->user->userModel = $userInParentGroup;
     $this->setGetArray(array('id' => $meeting3->id));
     $this->runControllerWithNoExceptionsAndGetContent('meetings/default/edit');
     //Test userInParentGroup, access to meetings delete should fail.
     $this->setGetArray(array('id' => $meeting3->id));
     $this->resetPostArray();
     $this->runControllerShouldResultInAccessFailureAndGetContent('meetings/default/delete');
     //Test userInChildGroup, access to edit meetings should not fail.
     Yii::app()->user->userModel = $userInChildGroup;
     $this->logoutCurrentUserLoginNewUserAndGetByUsername($userInChildGroup->username);
     $this->setGetArray(array('id' => $meeting3->id));
     $this->runControllerWithNoExceptionsAndGetContent('meetings/default/edit');
     //Test userInChildGroup, access to meetings delete should fail.
     $this->setGetArray(array('id' => $meeting3->id));
     $this->resetPostArray();
     $this->runControllerShouldResultInAccessFailureAndGetContent('meetings/default/delete');
     //revoke parentGroup access to meetings read and write
     Yii::app()->user->userModel = $super;
     $meeting3->removePermissions($parentGroup, Permission::READ_WRITE_CHANGE_PERMISSIONS);
     $this->assertTrue($meeting3->save());
     AllPermissionsOptimizationUtil::securableItemLostPermissionsForGroup($meeting3, $parentGroup);
     //Test userInChildGroup, access to meetings detail, edit and delete should fail.
     Yii::app()->user->userModel = $userInChildGroup;
     $this->setGetArray(array('id' => $meeting3->id));
     $this->runControllerShouldResultInAccessFailureAndGetContent('meetings/default/details');
     $this->setGetArray(array('id' => $meeting3->id));
     $this->runControllerShouldResultInAccessFailureAndGetContent('meetings/default/edit');
     $this->setGetArray(array('id' => $meeting3->id));
     $this->resetPostArray();
     $this->runControllerShouldResultInAccessFailureAndGetContent('meetings/default/delete');
     //Test userInParentGroup, access to meetings detail, edit and delete should fail.
     Yii::app()->user->userModel = $userInParentGroup;
     $this->setGetArray(array('id' => $meeting3->id));
     $this->runControllerShouldResultInAccessFailureAndGetContent('meetings/default/details');
     $this->setGetArray(array('id' => $meeting3->id));
     $this->runControllerShouldResultInAccessFailureAndGetContent('meetings/default/edit');
     $this->setGetArray(array('id' => $meeting3->id));
     $this->resetPostArray();
     $this->runControllerShouldResultInAccessFailureAndGetContent('meetings/default/delete');
     //give parentGroup access to read and write
     Yii::app()->user->userModel = $super;
     $meeting3->addPermissions($parentGroup, Permission::READ_WRITE_DELETE);
     $this->assertTrue($meeting3->save());
     AllPermissionsOptimizationUtil::securableItemGivenPermissionsForGroup($meeting3, $parentGroup);
     //Test userInChildGroup, access to meetings delete should not fail.
     Yii::app()->user->userModel = $userInChildGroup;
     $this->setGetArray(array('id' => $meeting3->id));
     $this->resetPostArray();
     $this->runControllerWithRedirectExceptionAndGetContent('meetings/default/delete');
     //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 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 testGetManyManyRelationshipModelIds()
 {
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $alisa = UserTestHelper::createBasicUser('Alisa');
     $alicia = UserTestHelper::createBasicUser('Alicia');
     $authenticationData = $this->login();
     $headers = array('Accept: application/json', 'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'], 'ZURMO_TOKEN: ' . $authenticationData['token'], 'ZURMO_API_REQUEST_TYPE: REST');
     $meeting = MeetingTestHelper::createMeetingByNameForOwner('Meeting With User Attendees', $super);
     $data = array('id' => $meeting->id, 'modelClassName' => 'Meeting', 'relationName' => 'userAttendees');
     $response = $this->createApiCallWithRelativeUrl('getUserAttendees/', 'POST', $headers, array('data' => $data));
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']);
     $this->assertEmpty($response['data']);
     $meeting->userAttendees->add($alisa);
     $meeting->userAttendees->add($alicia);
     $this->assertTrue($meeting->save());
     $response = $this->createApiCallWithRelativeUrl('getUserAttendees/', 'POST', $headers, array('data' => $data));
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']);
     $this->assertEquals(2, count($response['data']['userAttendees']));
     $this->assertEquals('User', $response['data']['userAttendees'][0]['class']);
     $this->assertEquals($alisa->id, $response['data']['userAttendees'][0]['id']);
     $this->assertEquals('User', $response['data']['userAttendees'][1]['class']);
     $this->assertEquals($alicia->id, $response['data']['userAttendees'][1]['id']);
     $data = array('id' => $meeting->id, 'modelClassName' => 'NonExistingModel', 'relationName' => 'userAttendees');
     $response = $this->createApiCallWithRelativeUrl('getUserAttendees/', 'POST', $headers, array('data' => $data));
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_FAILURE, $response['status']);
     $this->assertEquals('The specified class name was invalid.', $response['message']);
     $data = array('id' => $meeting->id, 'modelClassName' => 'Meeting', 'relationName' => 'owner');
     $response = $this->createApiCallWithRelativeUrl('getUserAttendees/', 'POST', $headers, array('data' => $data));
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_FAILURE, $response['status']);
     $this->assertEquals('The specified relationship name does not exist or is not MANY_MANY type.', $response['message']);
 }
 protected function addMeeting()
 {
     $this->checkActivityItemRelationCount('Meeting', 'First Meeting', 0);
     MeetingTestHelper::createMeetingWithOwnerAndRelatedAccount('First Meeting', Yii::app()->user->userModel, $this->selectedModels[1]);
 }
 public function createMeetingWithRelatedAccount($firstName, $meetingName, $usePastStartDateTime = false)
 {
     $account = AccountTestHelper::createAccountByNameForOwner($firstName, Yii::app()->user->userModel);
     $this->assertNull($account->latestActivityDateTime);
     $meeting = MeetingTestHelper::createMeetingByNameForOwner($meetingName, Yii::app()->user->userModel);
     $meeting->activityItems->add($account);
     if ($usePastStartDateTime) {
         $meeting->startDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time() - 10000);
     }
     $this->assertTrue($meeting->save());
     $this->assertNull($meeting->activityItems[0]->latestActivityDateTime);
     $meetingId = $meeting->id;
     $accountId = $account->id;
     $meeting->forget();
     $account->forget();
     return array($meetingId, $accountId);
 }
 public function testGetMeetingWithAttendees()
 {
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $evelina = UserTestHelper::createBasicUser('Evelina');
     $amelia = UserTestHelper::createBasicUser('Amelia');
     $amelia->primaryEmail->emailAddress = '*****@*****.**';
     $this->assertTrue($amelia->save());
     $contact1 = ContactTestHelper::createContactByNameForOwner('TestContact3', $super);
     $contact2 = ContactTestHelper::createContactByNameForOwner('TestContact4', $super);
     $contact2->primaryEmail->emailAddress = '*****@*****.**';
     $this->assertTrue($contact2->save());
     $authenticationData = $this->login();
     $headers = array('Accept: application/json', 'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'], 'ZURMO_TOKEN: ' . $authenticationData['token'], 'ZURMO_API_REQUEST_TYPE: REST');
     $meeting = MeetingTestHelper::createMeetingByNameForOwner('Meeting 2 With User Attendees', $super);
     $response = $this->createApiCallWithRelativeUrl('read/?id=' . $meeting->id, 'GET', $headers);
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']);
     $this->assertTrue(isset($response['data']['attendees']));
     $this->assertTrue(isset($response['data']['attendees']['Organizer']));
     $this->assertEquals($super->id, $response['data']['attendees']['Organizer']['id']);
     $this->assertEquals($super->firstName, $response['data']['attendees']['Organizer']['firstName']);
     $this->assertEquals($super->lastName, $response['data']['attendees']['Organizer']['lastName']);
     $this->assertEquals($super->username, $response['data']['attendees']['Organizer']['username']);
     $this->assertFalse(isset($response['data']['attendees']['Organizer']['email']));
     $meeting->activityItems->add($contact1);
     $meeting->activityItems->add($contact2);
     $this->assertTrue($meeting->save());
     $response = $this->createApiCallWithRelativeUrl('read/?id=' . $meeting->id, 'GET', $headers);
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']);
     $this->assertEquals(2, count($response['data']['attendees']['Contact']));
     $this->assertEquals($contact1->id, $response['data']['attendees']['Contact'][0]['id']);
     $this->assertEquals($contact1->firstName, $response['data']['attendees']['Contact'][0]['firstName']);
     $this->assertEquals($contact1->lastName, $response['data']['attendees']['Contact'][0]['lastName']);
     $this->assertEquals($contact2->id, $response['data']['attendees']['Contact'][1]['id']);
     $this->assertEquals($contact2->firstName, $response['data']['attendees']['Contact'][1]['firstName']);
     $this->assertEquals($contact2->lastName, $response['data']['attendees']['Contact'][1]['lastName']);
     $this->assertEquals($contact2->primaryEmail->emailAddress, $response['data']['attendees']['Contact'][1]['email']);
     $meeting->userAttendees->add($evelina);
     $meeting->userAttendees->add($amelia);
     $this->assertTrue($meeting->save());
     $response = $this->createApiCallWithRelativeUrl('read/?id=' . $meeting->id, 'GET', $headers);
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']);
     $this->assertEquals(2, count($response['data']['attendees']['Contact']));
     $this->assertEquals($contact1->id, $response['data']['attendees']['Contact'][0]['id']);
     $this->assertEquals($contact1->firstName, $response['data']['attendees']['Contact'][0]['firstName']);
     $this->assertEquals($contact1->lastName, $response['data']['attendees']['Contact'][0]['lastName']);
     $this->assertEquals($contact2->id, $response['data']['attendees']['Contact'][1]['id']);
     $this->assertEquals($contact2->firstName, $response['data']['attendees']['Contact'][1]['firstName']);
     $this->assertEquals($contact2->lastName, $response['data']['attendees']['Contact'][1]['lastName']);
     $this->assertEquals(2, count($response['data']['attendees']['User']));
     $this->assertEquals($evelina->id, $response['data']['attendees']['User'][0]['id']);
     $this->assertEquals($evelina->firstName, $response['data']['attendees']['User'][0]['firstName']);
     $this->assertEquals($evelina->lastName, $response['data']['attendees']['User'][0]['lastName']);
     $this->assertEquals($evelina->username, $response['data']['attendees']['User'][0]['username']);
     $this->assertEquals($amelia->id, $response['data']['attendees']['User'][1]['id']);
     $this->assertEquals($amelia->primaryEmail->emailAddress, $response['data']['attendees']['User'][1]['email']);
     $this->assertEquals($amelia->firstName, $response['data']['attendees']['User'][1]['firstName']);
     $this->assertEquals($amelia->lastName, $response['data']['attendees']['User'][1]['lastName']);
     $this->assertEquals($amelia->username, $response['data']['attendees']['User'][1]['username']);
     $this->assertTrue(isset($response['data']['attendees']['Organizer']));
     $this->assertEquals($super->id, $response['data']['attendees']['Organizer']['id']);
     $this->assertEquals($super->firstName, $response['data']['attendees']['Organizer']['firstName']);
     $this->assertEquals($super->lastName, $response['data']['attendees']['Organizer']['lastName']);
     $this->assertEquals($super->username, $response['data']['attendees']['Organizer']['username']);
     // Test with opportunity and account activity items
     $account = AccountTestHelper::createAccountByNameForOwner('Account 2', $super);
     $opportunity = OpportunityTestHelper::createOpportunityByNameForOwner('TestOpportunity 2', $super);
     $meeting2 = MeetingTestHelper::createMeetingByNameForOwner('Meeting 3 With Account and Opportunity', $super);
     $meeting2->activityItems->add($account);
     $meeting2->activityItems->add($opportunity);
     $this->assertTrue($meeting2->save());
     $searchParams = array('pagination' => array('page' => 1, 'pageSize' => 3), 'search' => array('name' => 'Meeting 3 With Account and Opportunity'), 'sort' => 'name');
     $searchParamsQuery = http_build_query($searchParams);
     $response = $this->createApiCallWithRelativeUrl('list/filter/' . $searchParamsQuery, 'GET', $headers);
     $response = json_decode($response, true);
     $this->assertEquals(1, count($response['data']['items']));
     $this->assertEquals($account->id, $response['data']['items'][0]['attendees']['Account'][0]['id']);
     $this->assertEquals($account->name, $response['data']['items'][0]['attendees']['Account'][0]['name']);
     $this->assertEquals($opportunity->id, $response['data']['items'][0]['attendees']['Opportunity'][0]['id']);
     $this->assertEquals($opportunity->name, $response['data']['items'][0]['attendees']['Opportunity'][0]['name']);
     // Test with regular user if he can get user attendees
     $michael = UserTestHelper::createBasicUser('Michael');
     $michael->primaryEmail->emailAddress = '*****@*****.**';
     $this->assertTrue($michael->save());
     $michael->setRight('UsersModule', UsersModule::RIGHT_LOGIN_VIA_WEB_API);
     $michael->setRight('MeetingsModule', MeetingsModule::getAccessRight());
     $michael->setRight('MeetingsModule', MeetingsModule::getCreateRight());
     $saved = $michael->save();
     $this->assertTrue($saved);
     $michaelMeeting = MeetingTestHelper::createMeetingByNameForOwner('Meeting 4 With User', $michael);
     $michaelMeeting->userAttendees->add($evelina);
     $this->assertTrue($michaelMeeting->save());
     $authenticationData = $this->login('michael', 'michael');
     $headers = array('Accept: application/json', 'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'], 'ZURMO_TOKEN: ' . $authenticationData['token'], 'ZURMO_API_REQUEST_TYPE: REST');
     $response = $this->createApiCallWithRelativeUrl('read/?id=' . $michaelMeeting->id, 'GET', $headers);
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']);
     $this->assertEquals(1, count($response['data']['attendees']['User']));
     $this->assertEquals($evelina->id, $response['data']['attendees']['User'][0]['id']);
     $this->assertEquals($evelina->firstName, $response['data']['attendees']['User'][0]['firstName']);
     $this->assertEquals($evelina->lastName, $response['data']['attendees']['User'][0]['lastName']);
     $this->assertEquals($evelina->username, $response['data']['attendees']['User'][0]['username']);
     $this->assertTrue(isset($response['data']['attendees']['Organizer']));
     $this->assertEquals($michael->id, $response['data']['attendees']['Organizer']['id']);
     $this->assertEquals($michael->firstName, $response['data']['attendees']['Organizer']['firstName']);
     $this->assertEquals($michael->lastName, $response['data']['attendees']['Organizer']['lastName']);
     $this->assertEquals($michael->username, $response['data']['attendees']['Organizer']['username']);
     $this->assertEquals($michael->primaryEmail->emailAddress, $response['data']['attendees']['Organizer']['email']);
 }
 public function testSuperUserSearchForDuplicateModelsAction()
 {
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $this->setGetArray(array('attribute' => 'name', 'value' => 'fakeValue'));
     $this->runControllerWithNoExceptionsAndGetContent('accounts/default/searchForDuplicateModels', true);
     $account = AccountTestHelper::createAccountByNameForOwner('testAccount', $super);
     MeetingTestHelper::createMeetingWithOwnerAndRelatedAccount('test meeting', $super, $account);
     //Test search by name
     $this->setGetArray(array('attribute' => 'name', 'value' => 'testAccount'));
     $content = $this->runControllerWithNoExceptionsAndGetContent('accounts/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 officePhone
     $account->officePhone = '123456789';
     $this->assertTrue($account->save());
     $this->setGetArray(array('attribute' => 'officePhone', 'value' => '123456789'));
     $content = $this->runControllerWithNoExceptionsAndGetContent('accounts/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 account has one meeting
     $this->assertTag(array('tag' => 'span', 'attributes' => array('class' => 'total-meetings'), 'descendant' => array('tag' => 'strong', 'content' => '1')), $object->content);
     //Test search by email
     $account->primaryEmail->emailAddress = 'a@a.a';
     $this->assertTrue($account->save());
     $this->setGetArray(array('attribute' => 'primaryEmail', 'value' => 'a@a.a'));
     $content = $this->runControllerWithNoExceptionsAndGetContent('accounts/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);
 }