public function testCanCurrentUserPerformAction()
 {
     Yii::app()->user->userModel = User::getByUsername('billy');
     $leadForBilly = LeadTestHelper::createLeadbyNameForOwner("billy's lead", User::getByUsername('billy'));
     $betty = User::getByUsername('betty');
     Yii::app()->user->userModel = $betty;
     $leadForBetty = LeadTestHelper::createLeadbyNameForOwner("betty's lead", User::getByUsername('betty'));
     $betty->setRight('LeadsModule', LeadsModule::RIGHT_ACCESS_LEADS, Right::ALLOW);
     $saved = $betty->save();
     $this->assertTrue($saved);
     //make sure betty doesnt have write on billy's lead
     $this->assertEquals(Permission::NONE, $leadForBilly->getEffectivePermissions($betty));
     //make sure betty doesnt have convert lead right already
     $this->assertEquals(Right::DENY, $betty->getEffectiveRight('LeadsModule', LeadsModule::RIGHT_CONVERT_LEADS));
     //test Betty has no right to convert leads
     $actionSecurity = ActionSecurityFactory::createActionSecurityFromActionType('ConvertLead', $leadForBilly, $betty);
     $this->assertFalse($actionSecurity->canUserPerformAction());
     //test Betty has right to convert leads but cant write the lead she doesn't own
     $betty->setRight('LeadsModule', LeadsModule::RIGHT_CONVERT_LEADS, Right::ALLOW);
     $this->assertTrue($betty->save());
     $actionSecurity = ActionSecurityFactory::createActionSecurityFromActionType('ConvertLead', $leadForBilly, $betty);
     $this->assertFalse($actionSecurity->canUserPerformAction());
     //test Betty has right to convert and to write a lead she owns.
     $actionSecurity = ActionSecurityFactory::createActionSecurityFromActionType('ConvertLead', $leadForBetty, $betty);
     $this->assertTrue($actionSecurity->canUserPerformAction());
 }
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     SecurityTestHelper::createSuperAdmin();
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     //Setup test data owned by the super user.
     LeadTestHelper::createLeadbyNameForOwner('superLead', $super);
 }
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     SecurityTestHelper::createSuperAdmin();
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     Currency::makeBaseCurrency();
     //create a lead here
     LeadTestHelper::createLeadbyNameForOwner('superLead', $super);
 }
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     SecurityTestHelper::createSuperAdmin();
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     //Setup test data owned by the super user.
     LeadTestHelper::createLeadbyNameForOwner('superLead', $super);
     //Setup default dashboard.
     Dashboard::getByLayoutIdAndUser(Dashboard::DEFAULT_USER_LAYOUT_ID, $super);
     //Setup test marketingList
     MarketingListTestHelper::createMarketingListByName('MarketingListName', 'MarketingList Description', 'first', '*****@*****.**');
 }
 /**
  * @depends testSuperUserCreateAction
  */
 public function testSuperUserConvertAction()
 {
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $startingLeadState = LeadsUtil::getStartingState();
     $startingContactState = ContactsUtil::getStartingState();
     $leads = Contact::getByName('myNewLead myNewLeadson');
     $this->assertEquals(1, count($leads));
     $lead = $leads[0];
     $this->assertTrue($lead->state == $startingLeadState);
     //Test just going to the convert page.
     $this->setGetArray(array('id' => $lead->id));
     $this->resetPostArray();
     //Test trying to convert by skipping account creation
     $this->runControllerWithNoExceptionsAndGetContent('leads/default/convert');
     $this->setGetArray(array('id' => $lead->id));
     $this->setPostArray(array('AccountSkip' => 'Not Used'));
     $this->runControllerWithRedirectExceptionAndGetContent('leads/default/convert');
     $leadId = $lead->id;
     $lead->forget();
     $contact = Contact::getById($leadId);
     $this->assertTrue($contact->state == $startingContactState);
     //Test trying to convert by creating a new account.
     $lead5 = LeadTestHelper::createLeadbyNameForOwner('superLead5', $super);
     $this->assertTrue($lead5->state == $startingLeadState);
     $this->setGetArray(array('id' => $lead5->id));
     $this->setPostArray(array('Account' => array('name' => 'someAccountName')));
     $this->assertEquals(0, count(Account::getAll()));
     $this->runControllerWithRedirectExceptionAndGetContent('leads/default/convert');
     $this->assertEquals(1, count(Account::getAll()));
     $lead5Id = $lead5->id;
     $lead5->forget();
     $contact5 = Contact::getById($lead5Id);
     $this->assertTrue($contact5->state == $startingContactState);
     $this->assertEquals('someAccountName', $contact5->account->name);
     //Test trying to convert by selecting an existing account
     $account = AccountTestHelper::createAccountbyNameForOwner('someNewAccount', $super);
     $lead6 = LeadTestHelper::createLeadbyNameForOwner('superLead6', $super);
     $this->assertTrue($lead6->state == $startingLeadState);
     $this->setGetArray(array('id' => $lead6->id));
     $this->setPostArray(array('AccountSelectForm' => array('accountId' => $account->id, 'accountName' => 'someNewAccount')));
     $this->assertEquals(2, count(Account::getAll()));
     $this->runControllerWithRedirectExceptionAndGetContent('leads/default/convert');
     $this->assertEquals(2, count(Account::getAll()));
     $lead6Id = $lead6->id;
     $lead6->forget();
     $contact6 = Contact::getById($lead6Id);
     $this->assertTrue($contact6->state == $startingContactState);
     $this->assertEquals($account, $contact6->account);
 }
Beispiel #6
0
 /**
  * @depends testApiServerUrl
  */
 public function testEditLeadWIthIncorrectDataType()
 {
     $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');
     $lead = LeadTestHelper::createLeadbyNameForOwner('Newest Lead', $super);
     // Provide data with wrong type.
     $data['companyName'] = "A";
     $response = ApiRestTestHelper::createApiCall($this->serverUrl . '/test.php/leads/contact/api/create/', 'POST', $headers, array('data' => $data));
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_FAILURE, $response['status']);
     $this->assertEquals(3, count($response['errors']));
     $id = $lead->id;
     $data = array();
     $data['companyName'] = "A";
     $response = ApiRestTestHelper::createApiCall($this->serverUrl . '/test.php/leads/contact/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']));
 }
 /**
  * @deletes selected leads.
  */
 public function testRegularMassDeleteActionsForSelectedIds()
 {
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $confused = User::getByUsername('confused');
     $nobody = User::getByUsername('nobody');
     $this->assertEquals(Right::DENY, $confused->getEffectiveRight('ZurmoModule', ZurmoModule::RIGHT_BULK_DELETE));
     $confused->setRight('ZurmoModule', ZurmoModule::RIGHT_BULK_DELETE);
     //Load MassDelete view for the 3 leads.
     $leads = Contact::getAll();
     $this->assertEquals(8, count($leads));
     $lead1 = LeadTestHelper::createLeadbyNameForOwner('leadDelete1', $confused);
     $lead2 = LeadTestHelper::createLeadbyNameForOwner('leadDelete2', $confused);
     $lead3 = LeadTestHelper::createLeadbyNameForOwner('leadDelete3', $nobody);
     $lead4 = LeadTestHelper::createLeadbyNameForOwner('leadDelete4', $confused);
     $lead5 = LeadTestHelper::createLeadbyNameForOwner('leadDelete5', $confused);
     $lead6 = LeadTestHelper::createLeadbyNameForOwner('leadDelete6', $nobody);
     $selectedIds = $lead1->id . ',' . $lead2->id . ',' . $lead3->id;
     // Not Coding Standard
     $this->setGetArray(array('selectedIds' => $selectedIds, 'selectAll' => ''));
     // Not Coding Standard
     $this->resetPostArray();
     $content = $this->runControllerWithNoExceptionsAndGetContent('leads/default/massDelete');
     $this->assertContains('<strong>3</strong>&#160;Leads selected for removal', $content);
     //calculating leads after adding 4 new records
     $leads = Contact::getAll();
     $this->assertEquals(14, count($leads));
     //Deleting 6 leads for pagination scenario
     //Run Mass Delete using progress save for page1
     $selectedIds = $lead1->id . ',' . $lead2->id . ',' . $lead3->id . ',' . $lead4->id . ',' . $lead5->id . ',' . $lead6->id;
     // Not Coding Standard
     $this->setGetArray(array('selectedIds' => $selectedIds, 'selectAll' => '', 'Contact_page' => 1));
     $this->setPostArray(array('selectedRecordCount' => 6));
     $content = $this->runControllerWithExitExceptionAndGetContent('leads/default/massDelete');
     $leads = Contact::getAll();
     $this->assertEquals(9, count($leads));
     //Run Mass Delete using progress save for page2
     $selectedIds = $lead1->id . ',' . $lead2->id . ',' . $lead3->id . ',' . $lead4->id . ',' . $lead5->id . ',' . $lead6->id;
     // Not Coding Standard
     $this->setGetArray(array('selectedIds' => $selectedIds, 'selectAll' => '', 'Contact_page' => 2));
     $this->setPostArray(array('selectedRecordCount' => 6));
     $content = $this->runControllerWithNoExceptionsAndGetContent('leads/default/massDeleteProgress');
     $leads = Contact::getAll();
     $this->assertEquals(8, count($leads));
 }
 /**
  * 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 testGetDeletedLeads()
 {
     $timestamp = time();
     sleep(1);
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $this->deleteAllModelsAndRecordsFromReadPermissionTable('Contact');
     $job = new ReadPermissionSubscriptionUpdateJob();
     $lead1 = LeadTestHelper::createLeadbyNameForOwner('Michael', $super);
     $lead2 = LeadTestHelper::createLeadbyNameForOwner('Michael2', $super);
     $lead3 = LeadTestHelper::createLeadbyNameForOwner('Michael3', $super);
     $this->assertTrue($job->run());
     sleep(1);
     $leadId1 = $lead1->id;
     $leadId2 = $lead2->id;
     $leadId3 = $lead3->id;
     $lead1->delete();
     $lead2->delete();
     $lead3->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('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($leadId1, $response['data']['items']);
     $this->assertContains($leadId2, $response['data']['items']);
     $data = array('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($leadId3, $response['data']['items']);
 }
 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 testSuperUserConvertActionWithTagCloud()
 {
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     Account::deleteAll();
     DesignerTestHelper::createTagCloudAttribute('tagcloud', false, 'Account');
     $this->setGetArray(array('moduleClassName' => 'AccountsModule', 'viewClassName' => 'AccountConvertToView'));
     $layout = array('panels' => array(array('title' => 'Panel Title', 'panelDetailViewOnly' => 1, 'rows' => array(array('cells' => array(array('element' => 'name'))), array('cells' => array(array('element' => 'tagcloudCstm')))))));
     $this->setPostArray(array('save' => 'Save', 'layout' => $layout));
     $content = $this->runControllerWithExitExceptionAndGetContent('designer/default/LayoutEdit');
     $this->assertContains('Layout saved successfully', $content);
     $lead = LeadTestHelper::createLeadbyNameForOwner('convertwithtagcloud', $super);
     $this->setGetArray(array('id' => $lead->id));
     $this->setPostArray(array('Account' => array('name' => 'mynewaccountfromleadtagcloudconvert', 'tagcloudCstm' => array('values' => 'English,French'))));
     $this->assertEquals(0, Account::getCount());
     $this->runControllerWithRedirectExceptionAndGetContent('leads/default/convert');
     $this->assertEquals(1, Account::getCount());
     $accounts = Account::getAll();
     $this->assertEquals('English, French', strval($accounts[0]->tagcloudCstm));
 }
 public function testGetPersonsAndAccountsByEmailAddress()
 {
     //Create user, contact, lead and accout
     $user = UserTestHelper::createBasicUser('newUser');
     $account = AccountTestHelper::createAccountByNameForOwner('newAccount', $user);
     $lead = LeadTestHelper::createLeadbyNameForOwner('newLead', $user);
     $contact = ContactTestHelper::createContactWithAccountByNameForOwner('newContact', $user, $account);
     $lead->primaryEmail->emailAddress = '*****@*****.**';
     $lead->secondaryEmail->emailAddress = '*****@*****.**';
     $account->primaryEmail->emailAddress = '*****@*****.**';
     $account->secondaryEmail->emailAddress = '*****@*****.**';
     $contact->primaryEmail->emailAddress = '*****@*****.**';
     $contact->secondaryEmail->emailAddress = '*****@*****.**';
     $this->assertTrue($user->save());
     $this->assertTrue($lead->save());
     $this->assertTrue($account->save());
     $this->assertTrue($contact->save());
     //Test with defaults
     $emailAddress = '*****@*****.**';
     $personsOrAccounts = EmailArchivingUtil::getPersonsAndAccountsByEmailAddress($emailAddress);
     $this->assertEmpty($personsOrAccounts);
     $emailAddress = '*****@*****.**';
     $personsOrAccounts = EmailArchivingUtil::getPersonsAndAccountsByEmailAddress($emailAddress);
     $this->assertEmpty($personsOrAccounts);
     $emailAddress = '*****@*****.**';
     $personsOrAccounts = EmailArchivingUtil::getPersonsAndAccountsByEmailAddress($emailAddress);
     $this->assertEmpty($personsOrAccounts);
     $emailAddress = '*****@*****.**';
     $personsOrAccounts = EmailArchivingUtil::getPersonsAndAccountsByEmailAddress($emailAddress);
     $this->assertEmpty($personsOrAccounts);
     //Test user can access contacts
     $emailAddress = '*****@*****.**';
     $personsOrAccounts = EmailArchivingUtil::getPersonsAndAccountsByEmailAddress($emailAddress, true);
     $this->assertNotEmpty($personsOrAccounts);
     $this->assertEquals($personsOrAccounts[0], $contact);
     //Test user can access leads
     $emailAddress = '*****@*****.**';
     $personsOrAccounts = EmailArchivingUtil::getPersonsAndAccountsByEmailAddress($emailAddress, false, true);
     $this->assertNotEmpty($personsOrAccounts);
     $this->assertEquals($personsOrAccounts[0], $lead);
     //Test user can access accounts
     $emailAddress = '*****@*****.**';
     $personsOrAccounts = EmailArchivingUtil::getPersonsAndAccountsByEmailAddress($emailAddress, false, false, true);
     $this->assertNotEmpty($personsOrAccounts);
     $this->assertEquals($personsOrAccounts[0], $account);
     //Test user can access users
     $user->primaryEmail->emailAddress = '*****@*****.**';
     $this->assertTrue($user->save());
     $emailAddress = '*****@*****.**';
     $personsOrAccounts = EmailArchivingUtil::getPersonsAndAccountsByEmailAddress($emailAddress, false, false, false);
     $this->assertNotEmpty($personsOrAccounts);
     $this->assertEquals($personsOrAccounts[0], $user);
 }