public function testSuperUserThatContactsAndLeadsShowZeroModelUserInterfaceCorrectly() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); $this->assertEquals(0, Contact::getCount()); //At this point the zero model ui should show up for contacts and leads $content = $this->runControllerWithNoExceptionsAndGetContent('contacts/default/list'); $this->assertContains('Arthur Conan', $content); $content = $this->runControllerWithNoExceptionsAndGetContent('leads/default/list'); $this->assertContains('Thomas Paine', $content); $contact = ContactTestHelper::createContactByNameForOwner('Jimmy', $super); //At this point leads should still show the zero model message $content = $this->runControllerWithNoExceptionsAndGetContent('contacts/default/list'); $this->assertNotContains('Arthur Conan', $content); $content = $this->runControllerWithNoExceptionsAndGetContent('leads/default/list'); $this->assertContains('Thomas Paine', $content); $this->assertTrue($contact->delete()); $this->assertEquals(0, Contact::getCount()); //Create lead. $lead = LeadTestHelper::createLeadByNameForOwner('Jammy', $super); //At this point contacts should still show the zero model message $content = $this->runControllerWithNoExceptionsAndGetContent('contacts/default/list'); $this->assertContains('Arthur Conan', $content); $content = $this->runControllerWithNoExceptionsAndGetContent('leads/default/list'); $this->assertNotContains('Thomas Paine', $content); }
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); }
/** * Walkthrough test for synchronous download */ public function testDownloadDefaultControllerActions() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); $account = AccountTestHelper::createAccountByNameForOwner('superAccount', $super); $leads = array(); for ($i = 0; $i < 2; $i++) { $leads[] = LeadTestHelper::createLeadWithAccountByNameForOwner('superContact' . $i, $super, $account); } // Check if access is denied if user doesn't have access privileges at all to export actions Yii::app()->user->userModel = User::getByUsername('nobody'); $nobody = $this->logoutCurrentUserLoginNewUserAndGetByUsername('nobody'); $this->runControllerShouldResultInAccessFailureAndGetContent('leads/default/list'); // Check if user have access to module action, but not to export action // Now test peon with elevated rights to accounts $nobody->setRight('LeadsModule', LeadsModule::RIGHT_ACCESS_LEADS); $nobody->setRight('LeadsModule', LeadsModule::RIGHT_CREATE_LEADS); $nobody->setRight('LeadsModule', LeadsModule::RIGHT_DELETE_LEADS); $nobody->setRight('ExportModule', ExportModule::RIGHT_ACCESS_EXPORT); $this->assertTrue($nobody->save()); // Check if access is denied if user doesn't have access privileges at all to export actions $nobody = $this->logoutCurrentUserLoginNewUserAndGetByUsername('nobody'); Yii::app()->user->userModel = User::getByUsername('nobody'); $this->runControllerWithNoExceptionsAndGetContent('leads/default/list'); $this->setGetArray(array('Contact_page' => '1', 'export' => '', 'ajax' => '', 'selectAll' => '', 'selectedIds' => '')); $response = $this->runControllerWithRedirectExceptionAndGetUrl('leads/default/export'); $this->assertTrue(strstr($response, 'leads/default/index') !== false); $this->setGetArray(array('LeadsSearchForm' => array('anyMixedAttributesScope' => array(0 => 'All'), 'anyMixedAttributes' => '', 'fullName' => 'superContact', 'officePhone' => ''), 'multiselect_ContactsSearchForm_anyMixedAttributesScope' => 'All', 'Contact_page' => '1', 'export' => '', 'ajax' => '', 'selectAll' => '1', 'selectedIds' => '')); $response = $this->runControllerWithRedirectExceptionAndGetUrl('leads/default/export'); $this->assertTrue(strstr($response, 'leads/default/index') !== false); $this->setGetArray(array('LeadsSearchForm' => array('anyMixedAttributesScope' => array(0 => 'All'), 'anyMixedAttributes' => '', 'fullName' => 'superContact', 'officePhone' => ''), 'multiselect_ContactsSearchForm_anyMixedAttributesScope' => 'All', 'Contact_page' => '1', 'export' => '', 'ajax' => '', 'selectAll' => '', 'selectedIds' => "{$leads[0]->id}, {$leads[1]->id}")); $response = $this->runControllerWithRedirectExceptionAndGetUrl('leads/default/export'); $this->assertTrue(strstr($response, 'leads/default/index') !== false); $this->assertContains('There is no data to export.', Yii::app()->user->getFlash('notification')); //give nobody access to read and write Yii::app()->user->userModel = $super; foreach ($leads as $lead) { $lead->addPermissions($nobody, Permission::READ_WRITE_CHANGE_PERMISSIONS); ReadPermissionsOptimizationUtil::securableItemGivenPermissionsForUser($lead, $nobody); $this->assertTrue($lead->save()); } //Now the nobody user should be able to access the edit view and still the details view. Yii::app()->user->userModel = $nobody; $this->setGetArray(array('LeadsSearchForm' => array('anyMixedAttributesScope' => array(0 => 'All'), 'anyMixedAttributes' => '', 'fullName' => 'superContact', 'officePhone' => ''), 'multiselect_ContactsSearchForm_anyMixedAttributesScope' => 'All', 'Contact_page' => '1', 'export' => '', 'ajax' => '', 'selectAll' => '1', 'selectedIds' => '')); $response = $this->runControllerWithExitExceptionAndGetContent('leads/default/export'); $this->assertEquals('Testing download.', $response); $this->setGetArray(array('LeadsSearchForm' => array('anyMixedAttributesScope' => array(0 => 'All'), 'anyMixedAttributes' => '', 'fullName' => 'superContact', 'officePhone' => ''), 'multiselect_ContactsSearchForm_anyMixedAttributesScope' => 'All', 'Contact_page' => '1', 'export' => '', 'ajax' => '', 'selectAll' => '', 'selectedIds' => "{$leads[0]->id}, {$leads[1]->id}")); $response = $this->runControllerWithExitExceptionAndGetContent('leads/default/export'); $this->assertEquals('Testing download.', $response); // No mathces $this->setGetArray(array('LeadsSearchForm' => array('anyMixedAttributesScope' => array(0 => 'All'), 'anyMixedAttributes' => '', 'fullName' => 'missingName', 'officePhone' => ''), 'multiselect_ContactsSearchForm_anyMixedAttributesScope' => 'All', 'Contact_page' => '1', 'export' => '', 'ajax' => '', 'selectAll' => '1', 'selectedIds' => '')); $response = $this->runControllerWithRedirectExceptionAndGetUrl('leads/default/export'); $this->assertTrue(strstr($response, 'leads/default/index') !== false); }
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', '*****@*****.**'); }
public function testResolveLinkMessageToModel() { Yii::app()->user->userModel = User::getByUsername('super'); $account = AccountTestHelper::createAccountByNameForOwner('account', Yii::app()->user->userModel); $content = ImportUtil::resolveLinkMessageToModel($account); $this->assertContains('accounts/default/details?id', $content); $contact = ContactTestHelper::createContactByNameForOwner('contact', Yii::app()->user->userModel); $content = ImportUtil::resolveLinkMessageToModel($contact); $this->assertContains('contacts/default/details?id', $content); $lead = LeadTestHelper::createLeadByNameForOwner('lead', Yii::app()->user->userModel); $content = ImportUtil::resolveLinkMessageToModel($lead); $this->assertContains('leads/default/details?id', $content); }
/** * @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); }
/** * @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> 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)); }
/** * @depends testUnprivilegedUserViewUpdateDeleteContacts */ public function testBasicSearchContacts() { $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; Contact::deleteAll(); $authenticationData = $this->login(); $headers = array('Accept: application/json', 'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'], 'ZURMO_TOKEN: ' . $authenticationData['token'], 'ZURMO_API_REQUEST_TYPE: REST'); //Setup test data owned by the super user. $account = AccountTestHelper::createAccountByNameForOwner('superAccount', $super); $account2 = AccountTestHelper::createAccountByNameForOwner('superAccount2', $super); ContactTestHelper::createContactWithAccountByNameForOwner('First Contact', $super, $account); ContactTestHelper::createContactWithAccountByNameForOwner('Second Contact', $super, $account); ContactTestHelper::createContactWithAccountByNameForOwner('Third Contact', $super, $account); ContactTestHelper::createContactWithAccountByNameForOwner('Forth Contact', $super, $account2); ContactTestHelper::createContactWithAccountByNameForOwner('Fifth Contact', $super, $account2); LeadTestHelper::createLeadWithAccountByNameForOwner('First Lead', $super, $account); LeadTestHelper::createLeadWithAccountByNameForOwner('Second Lead', $super, $account2); $searchParams = array('pagination' => array('page' => 1, 'pageSize' => 3), 'search' => array('firstName' => ''), 'sort' => 'firstName'); $searchParamsQuery = http_build_query($searchParams); $response = $this->createApiCallWithRelativeUrl('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 Contact', $response['data']['items'][0]['firstName']); $this->assertEquals('First Contact', $response['data']['items'][1]['firstName']); $this->assertEquals('Forth Contact', $response['data']['items'][2]['firstName']); // Second page $searchParams['pagination']['page'] = 2; $searchParamsQuery = http_build_query($searchParams); $response = $this->createApiCallWithRelativeUrl('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 Contact', $response['data']['items'][0]['firstName']); $this->assertEquals('Third Contact', $response['data']['items'][1]['firstName']); // Search by name $searchParams['pagination']['page'] = 1; $searchParams['search']['firstName'] = 'First Contact'; $searchParamsQuery = http_build_query($searchParams); $response = $this->createApiCallWithRelativeUrl('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 Contact', $response['data']['items'][0]['firstName']); // No results $searchParams['pagination']['page'] = 1; $searchParams['search']['firstName'] = 'First Contact 2'; $searchParamsQuery = http_build_query($searchParams); $response = $this->createApiCallWithRelativeUrl('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('firstName' => ''), 'sort' => 'firstName.desc'); $searchParamsQuery = http_build_query($searchParams); $response = $this->createApiCallWithRelativeUrl('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 Contact', $response['data']['items'][0]['firstName']); $this->assertEquals('Second Contact', $response['data']['items'][1]['firstName']); $this->assertEquals('Forth Contact', $response['data']['items'][2]['firstName']); // Second page $searchParams['pagination']['page'] = 2; $searchParamsQuery = http_build_query($searchParams); $response = $this->createApiCallWithRelativeUrl('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 Contact', $response['data']['items'][0]['firstName']); $this->assertEquals('Fifth Contact', $response['data']['items'][1]['firstName']); // Search by custom fields, order by name desc $searchParams = array('pagination' => array('page' => 1, 'pageSize' => 3), 'search' => array('account' => array('id' => $account2->id), 'owner' => array('id' => $super->id)), 'sort' => 'firstName.desc'); $searchParamsQuery = http_build_query($searchParams); $response = $this->createApiCallWithRelativeUrl('list/filter/' . $searchParamsQuery, 'GET', $headers); $response = json_decode($response, true); $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']); $this->assertEquals(2, $response['data']['totalCount']); $this->assertEquals(2, count($response['data']['items'])); $this->assertEquals(1, $response['data']['currentPage']); $this->assertEquals('Forth Contact', $response['data']['items'][0]['firstName']); $this->assertEquals('Fifth Contact', $response['data']['items'][1]['firstName']); }
/** * Walkthrough test for synchronous download */ public function testAsynchronousDownloadDefaultControllerActions() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); $account = AccountTestHelper::createAccountByNameForOwner('superAccount2', $super); $notificationsBeforeCount = count(Notification::getAll()); $notificationMessagesBeforeCount = count(NotificationMessage::getAll()); $contacts = Contact::getAll(); if (count($contacts)) { foreach ($contacts as $contact) { $contact->delete(); } } $leads = array(); for ($i = 0; $i <= ExportModule::$asynchronusThreshold + 1; $i++) { $leads[] = LeadTestHelper::createLeadWithAccountByNameForOwner('superContact' . $i, $super, $account); } $this->setGetArray(array('Contact_page' => '1', 'export' => '', 'ajax' => '', 'selectAll' => '1', 'selectedIds' => '')); $this->runControllerWithRedirectExceptionAndGetUrl('leads/default/export'); // Start background job $job = new ExportJob(); $this->assertTrue($job->run()); $exportItems = ExportItem::getAll(); $this->assertEquals(1, count($exportItems)); $fileModel = $exportItems[0]->exportFileModel; $this->assertEquals(1, $exportItems[0]->isCompleted); $this->assertEquals('csv', $exportItems[0]->exportFileType); $this->assertEquals('leads', $exportItems[0]->exportFileName); $this->assertTrue($fileModel instanceof ExportFileModel); $this->assertEquals($notificationsBeforeCount + 1, count(Notification::getAll())); $this->assertEquals($notificationMessagesBeforeCount + 1, count(NotificationMessage::getAll())); // Check export job, when many ids are selected. // This will probably never happen, but we need test for this case too. $notificationsBeforeCount = count(Notification::getAll()); $notificationMessagesBeforeCount = count(NotificationMessage::getAll()); // Now test case when multiple ids are selected $exportItems = ExportItem::getAll(); if (count($exportItems)) { foreach ($exportItems as $exportItem) { $exportItem->delete(); } } $selectedIds = ""; foreach ($leads as $lead) { $selectedIds .= $lead->id . ","; // Not Coding Standard } $this->setGetArray(array('LeadsSearchForm' => array('anyMixedAttributesScope' => array(0 => 'All'), 'anyMixedAttributes' => '', 'fullName' => '', 'officePhone' => ''), 'multiselect_ContactsSearchForm_anyMixedAttributesScope' => 'All', 'Contact_page' => '1', 'export' => '', 'ajax' => '', 'selectAll' => '', 'selectedIds' => "{$selectedIds}")); $this->runControllerWithRedirectExceptionAndGetUrl('leads/default/export'); // Start background job $job = new ExportJob(); $this->assertTrue($job->run()); $exportItems = ExportItem::getAll(); $this->assertEquals(1, count($exportItems)); $fileModel = $exportItems[0]->exportFileModel; $this->assertEquals(1, $exportItems[0]->isCompleted); $this->assertEquals('csv', $exportItems[0]->exportFileType); $this->assertEquals('leads', $exportItems[0]->exportFileName); $this->assertTrue($fileModel instanceof ExportFileModel); $this->assertEquals($notificationsBeforeCount + 1, count(Notification::getAll())); $this->assertEquals($notificationMessagesBeforeCount + 1, count(NotificationMessage::getAll())); }
/** * 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); }
/** * @depends testMakingAlreadyPlacedNonrequiredStandardAttributeRequiredAndThenMakingItUnrequired */ public function testRequiredContactAttributesProperlyAreRequiredToBePlacedInLeadLayouts() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); $contact = ContactTestHelper::createContactByNameForOwner('aTestContact', $super); $lead = LeadTestHelper::createLeadByNameForOwner('aTestLead', $super); $content = $this->runControllerWithNoExceptionsAndGetContent('contacts/default/create'); $this->assertNotContains('There are required fields missing from the following layout', $content); $content = $this->runControllerWithNoExceptionsAndGetContent('contacts/default/list'); $this->assertNotContains('There are required fields missing from the following layout', $content); $this->setGetArray(array('id' => $contact->id)); $content = $this->runControllerWithNoExceptionsAndGetContent('contacts/default/edit'); $this->assertNotContains('There are required fields missing from the following layout', $content); //Now check lead layouts. $content = $this->runControllerWithNoExceptionsAndGetContent('leads/default/create'); $this->assertNotContains('There are required fields missing from the following layout', $content); $content = $this->runControllerWithNoExceptionsAndGetContent('leads/default/list'); $this->assertNotContains('There are required fields missing from the following layout', $content); $this->setGetArray(array('id' => $lead->id)); $content = $this->runControllerWithNoExceptionsAndGetContent('leads/default/edit'); $this->assertNotContains('There are required fields missing from the following layout', $content); //Now create an attribute that is required. $this->createTextCustomFieldByModule('ContactsModule', 'text'); $content = $this->runControllerWithExitExceptionAndGetContent('contacts/default/create'); $this->assertContains('There are required fields missing from the following layout', $content); $content = $this->runControllerWithNoExceptionsAndGetContent('contacts/default/list'); $this->assertNotContains('There are required fields missing from the following layout', $content); $this->setGetArray(array('id' => $contact->id)); $content = $this->runControllerWithExitExceptionAndGetContent('contacts/default/edit'); $this->assertContains('There are required fields missing from the following layout', $content); //Now check lead layouts. They should follow the same pattern as contacts. $content = $this->runControllerWithExitExceptionAndGetContent('leads/default/create'); $this->assertContains('There are required fields missing from the following layout', $content); $content = $this->runControllerWithNoExceptionsAndGetContent('leads/default/list'); $this->assertNotContains('There are required fields missing from the following layout', $content); $this->setGetArray(array('id' => $lead->id)); $content = $this->runControllerWithExitExceptionAndGetContent('leads/default/edit'); $this->assertContains('There are required fields missing from the following layout', $content); }
public static function setUpBeforeClass() { parent::setUpBeforeClass(); SecurityTestHelper::createSuperAdmin(); SecurityTestHelper::createUsers(); self::$super = User::getByUsername('super'); Yii::app()->user->userModel = self::$super; $loaded = ContactsModule::loadStartingData(); if (!$loaded) { throw new NotSupportedException(); } $emailSignature = new EmailSignature(); $emailSignature->htmlContent = 'my email signature'; self::$super->emailSignatures->add($emailSignature); self::$super->save(); $currencies = Currency::getAll(); $currencyValue = new CurrencyValue(); $currencyValue->value = 100; $currencyValue->currency = $currencies[0]; $multiDropDownCustomFieldData = new CustomFieldData(); $multiDropDownCustomFieldData->name = 'multiDropDown'; $multiDropDownCustomFieldData->serializedData = serialize(array('Ten', 11, 'XII')); $saved = $multiDropDownCustomFieldData->save(); assert('$saved'); // Not Coding Standard $multiDropDownCustomFieldValue1 = new CustomFieldValue(); $multiDropDownCustomFieldValue1->value = 'Ten'; $multiDropDownCustomFieldValue2 = new CustomFieldValue(); $multiDropDownCustomFieldValue2->value = 11; $multiDropDownCustomFieldValue3 = new CustomFieldValue(); $multiDropDownCustomFieldValue3->value = 'XII'; $tagCustomFieldData = new CustomFieldData(); $tagCustomFieldData->name = 'tagCloud'; $tagCustomFieldData->serializedData = serialize(array('Apache', 'PHP')); $saved = $tagCustomFieldData->save(); assert('$saved'); // Not Coding Standard $tagCustomFieldValue1 = new CustomFieldValue(); $tagCustomFieldValue1->value = 'PHP'; $tagCustomFieldValue2 = new CustomFieldValue(); $tagCustomFieldValue2->value = 'Apache'; $primaryEmail = new Email(); $primaryEmail->emailAddress = "*****@*****.**"; $primaryEmail->isInvalid = true; $primaryEmail->optOut = false; $secondaryEmail = new Email(); $secondaryEmail->emailAddress = "*****@*****.**"; $secondaryEmail->isInvalid = false; $secondaryEmail->optOut = true; $address = new Address(); $address->street1 = "SomeStreet1"; $address->street2 = "SomeStreet2"; $address->city = "SomeCity"; $address->state = "SomeState"; $address->postalCode = 1111; $address->country = "SomeCountry"; $likeContactState = new ContactState(); $likeContactState->name = 'Customer'; $likeContactState->order = 0; static::$hash = StringUtil::generateRandomString(60); $users = User::getAll(); $user = new User(); $user->lastName = 'Kevin'; $user->hash = static::$hash; $user->language = 'es'; $user->timeZone = 'America/Chicago'; $user->username = '******'; $user->currency = $currencies[0]; $user->manager = $users[0]; //Custom attribute $attributeForm = new TextAttributeForm(); $attributeForm->attributeName = 'custom'; $attributeForm->attributeLabels = array('en' => 'test label en'); $modelAttributesAdapterClassName = $attributeForm::getModelAttributeAdapterNameForSavingAttributeFormData(); $adapter = new $modelAttributesAdapterClassName(new EmailTemplateModelTestItem()); $adapter->setAttributeMetadataFromForm($attributeForm); //Custom attribute with underscore and number $attributeForm = new TextAttributeForm(); $attributeForm->attributeName = 'custom_attr_2'; $attributeForm->attributeLabels = array('en' => 'custom test label en'); $modelAttributesAdapterClassName = $attributeForm::getModelAttributeAdapterNameForSavingAttributeFormData(); $adapter = new $modelAttributesAdapterClassName(new EmailTemplateModelTestItem()); $adapter->setAttributeMetadataFromForm($attributeForm); $model = new EmailTemplateModelTestItem(); $model->string = 'We will add a $100 discount to this deal'; $model->firstName = 'James'; $model->lastName = 'Jackson'; $model->phone = 1122334455; $model->boolean = true; $model->date = '2008-12-31'; $model->dateTime = '2008-12-31 07:48:04'; $model->textArea = 'Multiple Lines\\nOf Text'; $model->url = 'http://www.zurmo.com/'; $model->integer = 999; $model->float = 999.999; $model->currencyValue = $currencyValue; $model->dropDown->value = "DropdownSelectedValue"; $model->radioDropDown->value = "RadioDropdownSelectedValue"; $model->primaryEmail = $primaryEmail; $model->secondaryEmail = $secondaryEmail; $model->primaryAddress = $address; $model->likeContactState = $likeContactState; $model->user = $user; $model->multiDropDown->data = $multiDropDownCustomFieldData; $model->tagCloud->data = $tagCustomFieldData; $model->multiDropDown->values->add($multiDropDownCustomFieldValue1); $model->multiDropDown->values->add($multiDropDownCustomFieldValue2); $model->multiDropDown->values->add($multiDropDownCustomFieldValue3); $model->tagCloud->values->add($tagCustomFieldValue1); $model->tagCloud->values->add($tagCustomFieldValue2); $model->customCstm = 'text custom'; $model->custom_attr_2Cstm = 'text custom 2'; $saved = $model->save(); assert('$saved'); // Not Coding Standard self::$emailTemplate = $model; self::$content = '[[STRING]] [[FIRST^NAME]] [[LAST^NAME]] [[PHONE]]'; self::$compareContent = 'We will add a $100 discount to this deal' . ' James Jackson 1122334455'; self::$account = AccountTestHelper::createAccountByNameForOwner('Account1', self::$super); self::$account->billingAddress = new Address(); self::$account->billingAddress->street1 = 'AccountStreet1'; $saved = self::$account->save(); if (!$saved) { throw new FailedToSaveModelException(); } self::$contact = ContactTestHelper::createContactWithAccountByNameForOwner('Jason', self::$super, self::$account); self::$lead = LeadTestHelper::createLeadByNameForOwner('Laura', self::$super); }