public function testSaveAndRetrievePortlet() { $user = UserTestHelper::createBasicUser('Billy'); $contacts = Contact::getByName('superContact superContactson'); $portlet = new Portlet(); $portlet->column = 2; $portlet->position = 5; $portlet->layoutId = 'Test'; $portlet->collapsed = true; $portlet->viewType = 'ContactsForAccountRelatedList'; $portlet->serializedViewData = serialize(array('title' => 'Testing Title')); $portlet->user = $user; $this->assertTrue($portlet->save()); $portlet = Portlet::getById($portlet->id); $params = array('controllerId' => 'test', 'relationModuleId' => 'test', 'relationModel' => $contacts[0], 'redirectUrl' => 'someRedirect'); $portlet->params = $params; $unserializedViewData = unserialize($portlet->serializedViewData); $this->assertEquals(2, $portlet->column); $this->assertEquals(5, $portlet->position); $this->assertEquals('Testing Title', $portlet->getTitle()); $this->assertEquals(false, $portlet->isEditable()); $this->assertEquals('Test', $portlet->layoutId); //$this->assertEquals(true, $portlet->collapsed); //reenable once working $this->assertEquals('ContactsForAccountRelatedList', $portlet->viewType); $this->assertEquals($user->id, $portlet->user->id); $view = $portlet->getView(); }
public function testGetItemIdsByModelAndUser() { $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; $headquarters = Account::getByName('Headquarters'); $headquarters = $headquarters[0]; $division1 = Account::getByName('Division1'); $division1 = $division1[0]; $division2 = Account::getByName('Division2'); $division2 = $division2[0]; $ceo = Contact::getByName('ceo ceoson'); $ceo = $ceo[0]; $div1President = Contact::getByName('div1 President div1 Presidentson'); $div1President = $div1President[0]; $div2President = Contact::getByName('div2 President div2 Presidentson'); $div2President = $div2President[0]; $opportunity = Opportunity::getByName('big opp'); $opportunity = $opportunity[0]; $opportunityDiv1 = Opportunity::getByName('div1 small opp'); $opportunityDiv1 = $opportunityDiv1[0]; $opportunityDiv2 = Opportunity::getByName('div2 small opp'); $opportunityDiv2 = $opportunityDiv2[0]; //Headquarter rollup should include all items created so far. $this->assertEquals(2, $headquarters->accounts->count()); $itemIds = ModelRollUpUtil::getItemIdsByModelAndUser($headquarters, $super); $compareItemIds = array(); $this->assertEquals(9, count($itemIds)); $this->assertTrue(in_array($headquarters->getClassId('Item'), $itemIds)); $this->assertTrue(in_array($division1->getClassId('Item'), $itemIds)); $this->assertTrue(in_array($division2->getClassId('Item'), $itemIds)); $this->assertTrue(in_array($ceo->getClassId('Item'), $itemIds)); $this->assertTrue(in_array($div1President->getClassId('Item'), $itemIds)); $this->assertTrue(in_array($div2President->getClassId('Item'), $itemIds)); $this->assertTrue(in_array($opportunity->getClassId('Item'), $itemIds)); $this->assertTrue(in_array($opportunityDiv1->getClassId('Item'), $itemIds)); $this->assertTrue(in_array($opportunityDiv2->getClassId('Item'), $itemIds)); //Ceo rollup would only include the ceo and his opportunity $itemIds = ModelRollUpUtil::getItemIdsByModelAndUser($ceo, $super); $compareItemIds = array(); $this->assertEquals(2, count($itemIds)); $this->assertTrue(in_array($ceo->getClassId('Item'), $itemIds)); $this->assertTrue(in_array($opportunity->getClassId('Item'), $itemIds)); //Big Opp rollup will only include big opp and ceo $itemIds = ModelRollUpUtil::getItemIdsByModelAndUser($opportunity, $super); $compareItemIds = array(); $this->assertEquals(2, count($itemIds)); $this->assertTrue(in_array($ceo->getClassId('Item'), $itemIds)); $this->assertTrue(in_array($opportunity->getClassId('Item'), $itemIds)); //Division 1 rollup will only include things related to division 1 $itemIds = ModelRollUpUtil::getItemIdsByModelAndUser($division1, $super); $compareItemIds = array(); $this->assertEquals(3, count($itemIds)); $this->assertTrue(in_array($division1->getClassId('Item'), $itemIds)); $this->assertTrue(in_array($div1President->getClassId('Item'), $itemIds)); $this->assertTrue(in_array($opportunityDiv1->getClassId('Item'), $itemIds)); }
protected function validatePrimaryModelData() { $this->assertEmpty(Contact::getByName('shozin shozinson')); $this->validateTask('firstName', 'shozin'); $this->validateTask('lastName', 'shozinson'); $this->validateNote('firstName', 'shozin'); $this->validateNote('lastName', 'shozinson'); $this->validateMeeting('firstName', 'shozin'); $this->validateMeeting('lastName', 'shozinson'); }
public function testSuperUserEditControllerAction() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); //Default Controller actions requiring some sort of parameter via POST or GET //Load Model Edit Views $contacts = Contact::getByName('superContact superContactson'); $products = Product::getAll(); $this->assertEquals(1, count($contacts)); $this->assertEquals(1, count($products)); $superProductId = self::getModelIdByModelNameAndName('Product', 'My Product 1'); $this->setGetArray(array('id' => $superProductId)); $this->runControllerWithNoExceptionsAndGetContent('products/default/edit'); //Save product. $superProduct = Product::getById($superProductId); $this->setPostArray(array('Product' => array('contact' => array('id' => $contacts[0]->id), 'opportunity' => array('id' => ''), 'owner' => array('id' => $super->id), 'explicitReadWriteModelPermissions' => array('type' => ExplicitReadWriteModelPermissionsUtil::MIXED_TYPE_EVERYONE_GROUP, 'nonEveryoneGroup' => '')))); //Test having a failed validation on the product during save. $this->setGetArray(array('id' => $superProductId)); $content = $this->runControllerWithRedirectExceptionAndGetContent('products/default/edit'); }
public function testSuperUserCompleteMatchVariations() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); $this->runControllerWithNoExceptionsAndGetContent('emailMessages/default/matchingList'); $message1 = EmailMessageTestHelper::createArchivedUnmatchedReceivedMessage($super); $message1Id = $message1->id; $message2 = EmailMessageTestHelper::createArchivedUnmatchedReceivedMessage($super); $message2Id = $message2->id; $message3 = EmailMessageTestHelper::createArchivedUnmatchedReceivedMessage($super); $contact = ContactTestHelper::createContactByNameForOwner('gail', $super); $startingContactState = ContactsUtil::getStartingState(); $startingLeadState = LeadsUtil::getStartingState(); //test validating selecting an existing contact $this->setGetArray(array('id' => $message1->id)); $this->setPostArray(array('ajax' => 'select-contact-form-' . $message1->id, 'AnyContactSelectForm' => array($message1->id => array('contactId' => $contact->id, 'contactName' => 'Some Name')))); $this->runControllerWithExitExceptionAndGetContent('emailMessages/default/completeMatch'); //test validating creating a new contact $this->setGetArray(array('id' => $message1->id)); $this->setPostArray(array('ajax' => 'contact-inline-create-form-' . $message1->id, 'Contact' => array($message1->id => array('firstName' => 'Gail', 'lastName' => 'Green', 'officePhone' => '456765421', 'state' => array('id' => $startingContactState->id))))); $this->runControllerWithExitExceptionAndGetContent('emailMessages/default/completeMatch'); //test validating creating a new lead $this->setGetArray(array('id' => $message1->id)); $this->setPostArray(array('ajax' => 'lead-inline-create-form-' . $message1->id, 'Lead' => array($message1->id => array('firstName' => 'Gail', 'lastName' => 'Green', 'officePhone' => '456765421', 'state' => array('id' => $startingLeadState->id))))); $this->runControllerWithExitExceptionAndGetContent('emailMessages/default/completeMatch'); //test selecting existing contact and saving $this->assertNull($contact->primaryEmail->emailAddress); $this->setGetArray(array('id' => $message1->id)); $this->setPostArray(array('AnyContactSelectForm' => array($message1->id => array('contactId' => $contact->id, 'contactName' => 'Some Name')))); $this->runControllerWithNoExceptionsAndGetContent('emailMessages/default/completeMatch', true); $message1->forget(); $message1 = EmailMessage::getById($message1Id); $this->assertNull($contact->primaryEmail->emailAddress); $this->assertCount(1, $message1->sender->personsOrAccounts); $this->assertTrue($message1->sender->personsOrAccounts[0]->isSame($contact)); $this->assertEquals('Archived', $message1->folder); //assert subject of the email going to edit. $this->setGetArray(array('id' => $contact->id)); $this->runControllerWithNoExceptionsAndGetContent('contacts/default/details'); $this->assertEquals('A test unmatched archived received email', $message1->subject); //edit subject of email message. $this->setGetArray(array('id' => $message1->id)); $createEmailMessageFormData = array('subject' => 'A test unmatched archived received email edited'); $this->setPostArray(array('ajax' => 'edit-form', 'EmailMessage' => $createEmailMessageFormData)); $this->runControllerWithRedirectExceptionAndGetUrl('emailMessages/default/edit'); //assert subject is edited or not. $this->setGetArray(array('id' => $contact->id)); $this->runControllerWithNoExceptionsAndGetContent('contacts/default/details'); $this->assertEquals('A test unmatched archived received email edited', $message1->subject); //delete email message. $this->setGetArray(array('id' => $message1->id)); $this->runControllerWithRedirectExceptionAndGetUrl('emailMessages/default/delete', true); //assert subject not present. try { EmailMessage::getById($message1->id); $this->fail(); } catch (NotFoundException $e) { //success } //Test the default permission was setted $everyoneGroup = Group::getByName(Group::EVERYONE_GROUP_NAME); $explicitReadWriteModelPermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem($message1); $readWritePermitables = $explicitReadWriteModelPermissions->getReadWritePermitables(); $this->assertEquals($everyoneGroup, $readWritePermitables[$everyoneGroup->getClassId('Permitable')]); //test creating new contact and saving $this->assertEquals(1, Contact::getCount()); $this->setGetArray(array('id' => $message2->id)); $this->setPostArray(array('Contact' => array($message2->id => array('firstName' => 'George', 'lastName' => 'Patton', 'officePhone' => '456765421', 'state' => array('id' => $startingContactState->id))))); $this->runControllerWithNoExceptionsAndGetContent('emailMessages/default/completeMatch', true); $message2->forget(); $message2 = EmailMessage::getById($message2Id); $this->assertEquals(2, Contact::getCount()); $contacts = Contact::getByName('George Patton'); $contact = $contacts[0]; $this->assertCount(1, $message2->sender->personsOrAccounts); $this->assertTrue($message2->sender->personsOrAccounts[0]->isSame($contact)); $this->assertEquals('Archived', $message2->folder); //Test the default permission was setted $explicitReadWriteModelPermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem($message2); $readWritePermitables = $explicitReadWriteModelPermissions->getReadWritePermitables(); $this->assertEquals($everyoneGroup, $readWritePermitables[$everyoneGroup->getClassId('Permitable')]); //test creating new lead and saving $this->assertEquals(2, Contact::getCount()); $this->setGetArray(array('id' => $message3->id)); $this->setPostArray(array('Lead' => array($message3->id => array('firstName' => 'Billy', 'lastName' => 'Kid', 'officePhone' => '456765421', 'state' => array('id' => $startingLeadState->id))))); $this->runControllerWithNoExceptionsAndGetContent('emailMessages/default/completeMatch', true); $this->assertEquals(3, Contact::getCount()); $contacts = Contact::getByName('Billy Kid'); $contact = $contacts[0]; $this->assertCount(1, $message3->sender->personsOrAccounts); $this->assertTrue($message3->sender->personsOrAccounts[0]->isSame($contact)); $this->assertEquals('Archived', $message3->folder); //Test the default permission was setted $explicitReadWriteModelPermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem($message3); $readWritePermitables = $explicitReadWriteModelPermissions->getReadWritePermitables(); $this->assertEquals($everyoneGroup, $readWritePermitables[$everyoneGroup->getClassId('Permitable')]); }
public function testSimpleUserImportWhereAllRowsSucceed() { Yii::app()->user->userModel = User::getByUsername('super'); $contacts = Contact::getAll(); $this->assertEquals(0, count($contacts)); $import = new Import(); $serializedData['importRulesType'] = 'Leads'; $serializedData['firstRowIsHeaderRow'] = true; $import->serializedData = serialize($serializedData); $this->assertTrue($import->save()); ImportTestHelper::createTempTableByFileNameAndTableName('importTest.csv', $import->getTempTableName(), true, Yii::getPathOfAlias('application.modules.leads.tests.unit.files')); $this->assertEquals(4, ImportDatabaseUtil::getCount($import->getTempTableName())); // includes header rows. $currency = Currency::getByCode(Yii::app()->currencyHelper->getBaseCode()); $mappingData = array('column_0' => ImportMappingUtil::makeStringColumnMappingData('firstName'), 'column_1' => ImportMappingUtil::makeStringColumnMappingData('lastName'), 'column_2' => ImportMappingUtil::makeStringColumnMappingData('jobTitle'), 'column_3' => ImportMappingUtil::makeStringColumnMappingData('officePhone'), 'column_4' => ImportMappingUtil::makeStringColumnMappingData('officeFax'), 'column_5' => ImportMappingUtil::makeStringColumnMappingData('department'), 'column_6' => ImportMappingUtil::makeUrlColumnMappingData('website'), 'column_7' => ImportMappingUtil::makeTextAreaColumnMappingData('description'), 'column_8' => ImportMappingUtil::makeStringColumnMappingData('primaryAddress__city'), 'column_9' => ImportMappingUtil::makeStringColumnMappingData('primaryAddress__country'), 'column_10' => ImportMappingUtil::makeStringColumnMappingData('primaryAddress__postalCode'), 'column_11' => ImportMappingUtil::makeStringColumnMappingData('primaryAddress__state'), 'column_12' => ImportMappingUtil::makeStringColumnMappingData('primaryAddress__street1'), 'column_13' => ImportMappingUtil::makeStringColumnMappingData('primaryAddress__street2'), 'column_14' => ImportMappingUtil::makeEmailColumnMappingData('primaryEmail__emailAddress'), 'column_15' => ImportMappingUtil::makeBooleanColumnMappingData('primaryEmail__isInvalid'), 'column_16' => ImportMappingUtil::makeBooleanColumnMappingData('primaryEmail__optOut'), 'column_17' => ImportMappingUtil::makeDropDownColumnMappingData('source'), 'column_18' => LeadImportTestHelper::makeStateColumnMappingData(), 'column_19' => ImportMappingUtil::makeDropDownColumnMappingData('industry'), 'column_20' => ImportMappingUtil::makeStringColumnMappingData('companyName')); $importRules = ImportRulesUtil::makeImportRulesByType('Leads'); $page = 0; $config = array('pagination' => array('pageSize' => 50)); //This way all rows are processed. $dataProvider = new ImportDataProvider($import->getTempTableName(), true, $config); $dataProvider->getPagination()->setCurrentPage($page); $importResultsUtil = new ImportResultsUtil($import); $messageLogger = new ImportMessageLogger(); ImportUtil::importByDataProvider($dataProvider, $importRules, $mappingData, $importResultsUtil, new ExplicitReadWriteModelPermissions(), $messageLogger); $importResultsUtil->processStatusAndMessagesForEachRow(); //Confirm that 3 models where created. $contacts = Contact::getAll(); $this->assertEquals(3, count($contacts)); $contacts = Contact::getByName('contact1 contact1son'); $this->assertEquals(1, count($contacts[0])); $this->assertEquals('contact1', $contacts[0]->firstName); $this->assertEquals('contact1son', $contacts[0]->lastName); $this->assertEquals('president', $contacts[0]->jobTitle); $this->assertEquals(123456, $contacts[0]->officePhone); $this->assertEquals(555, $contacts[0]->officeFax); $this->assertEquals('executive', $contacts[0]->department); $this->assertEquals('http://www.contact1.com', $contacts[0]->website); $this->assertEquals('desc1', $contacts[0]->description); $this->assertEquals('city1', $contacts[0]->primaryAddress->city); $this->assertEquals('country1', $contacts[0]->primaryAddress->country); $this->assertEquals('postal1', $contacts[0]->primaryAddress->postalCode); $this->assertEquals('state1', $contacts[0]->primaryAddress->state); $this->assertEquals('street11', $contacts[0]->primaryAddress->street1); $this->assertEquals('street21', $contacts[0]->primaryAddress->street2); $this->assertEquals('*****@*****.**', $contacts[0]->primaryEmail->emailAddress); $this->assertEquals(null, $contacts[0]->primaryEmail->isInvalid); $this->assertEquals(null, $contacts[0]->primaryEmail->optOut); $this->assertEquals('Self-Generated', $contacts[0]->source->value); $this->assertEquals('New', $contacts[0]->state->name); $this->assertEquals('Automotive', $contacts[0]->industry->value); $this->assertEquals('company1', $contacts[0]->companyName); $contacts = Contact::getByName('contact2 contact2son'); $this->assertEquals(1, count($contacts[0])); $this->assertEquals('contact2', $contacts[0]->firstName); $this->assertEquals('contact2son', $contacts[0]->lastName); $this->assertEquals('president2', $contacts[0]->jobTitle); $this->assertEquals(223456, $contacts[0]->officePhone); $this->assertEquals(655, $contacts[0]->officeFax); $this->assertEquals('executive2', $contacts[0]->department); $this->assertEquals('http://www.contact2.com', $contacts[0]->website); $this->assertEquals('desc2', $contacts[0]->description); $this->assertEquals('city2', $contacts[0]->primaryAddress->city); $this->assertEquals('country2', $contacts[0]->primaryAddress->country); $this->assertEquals('postal2', $contacts[0]->primaryAddress->postalCode); $this->assertEquals('state2', $contacts[0]->primaryAddress->state); $this->assertEquals('street12', $contacts[0]->primaryAddress->street1); $this->assertEquals('street22', $contacts[0]->primaryAddress->street2); $this->assertEquals('*****@*****.**', $contacts[0]->primaryEmail->emailAddress); $this->assertEquals(null, $contacts[0]->primaryEmail->isInvalid); $this->assertEquals(null, $contacts[0]->primaryEmail->optOut); $this->assertEquals('Tradeshow', $contacts[0]->source->value); $this->assertEquals('Recycled', $contacts[0]->state->name); $this->assertEquals('Banking', $contacts[0]->industry->value); $this->assertEquals('company2', $contacts[0]->companyName); $contacts = Contact::getByName('contact3 contact3son'); $this->assertEquals(1, count($contacts[0])); $this->assertEquals('contact3', $contacts[0]->firstName); $this->assertEquals('contact3son', $contacts[0]->lastName); $this->assertEquals('president3', $contacts[0]->jobTitle); $this->assertEquals(323456, $contacts[0]->officePhone); $this->assertEquals(755, $contacts[0]->officeFax); $this->assertEquals('executive3', $contacts[0]->department); $this->assertEquals('http://www.contact3.com', $contacts[0]->website); $this->assertEquals('desc3', $contacts[0]->description); $this->assertEquals('city3', $contacts[0]->primaryAddress->city); $this->assertEquals('country3', $contacts[0]->primaryAddress->country); $this->assertEquals('postal3', $contacts[0]->primaryAddress->postalCode); $this->assertEquals('state3', $contacts[0]->primaryAddress->state); $this->assertEquals('street13', $contacts[0]->primaryAddress->street1); $this->assertEquals('street23', $contacts[0]->primaryAddress->street2); $this->assertEquals('*****@*****.**', $contacts[0]->primaryEmail->emailAddress); $this->assertEquals('1', $contacts[0]->primaryEmail->isInvalid); $this->assertEquals('1', $contacts[0]->primaryEmail->optOut); $this->assertEquals('Inbound Call', $contacts[0]->source->value); $this->assertEquals('New', $contacts[0]->state->name); $this->assertEquals('Energy', $contacts[0]->industry->value); $this->assertEquals('company3', $contacts[0]->companyName); //Confirm 3 rows were processed as 'created'. $this->assertEquals(3, ImportDatabaseUtil::getCount($import->getTempTableName(), "status = " . ImportRowDataResultsUtil::CREATED)); //Confirm that 0 rows were processed as 'updated'. $this->assertEquals(0, ImportDatabaseUtil::getCount($import->getTempTableName(), "status = " . ImportRowDataResultsUtil::UPDATED)); //Confirm 0 rows were processed as 'errors'. $this->assertEquals(0, ImportDatabaseUtil::getCount($import->getTempTableName(), "status = " . ImportRowDataResultsUtil::ERROR)); $beansWithErrors = ImportDatabaseUtil::getSubset($import->getTempTableName(), "status = " . ImportRowDataResultsUtil::ERROR); $this->assertEquals(0, count($beansWithErrors)); }
/** * Check if only new messages are pulled from dropdown * Also check case if message will be matched with user/contact/account primary email * * @depends testRunCaseFour */ public function testRunCaseFive() { $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; $user = User::getByUsername('steve'); Yii::app()->imap->connect(); ContactTestHelper::createContactByNameForOwner('contact', $user); $contacts = Contact::getByName('contact contactson'); $contacts[0]->primaryEmail->emailAddress = Yii::app()->params['emailTestAccounts']['testEmailAddress']; $this->assertTrue($contacts[0]->save()); AccountTestHelper::createAccountByNameForOwner('account', $user); $accounts = Account::getByName('account'); $accounts[0]->primaryEmail->emailAddress = Yii::app()->params['emailTestAccounts']['testEmailAddress']; $this->assertTrue($accounts[0]->save()); $john = User::getByUsername('john'); $john->primaryEmail->emailAddress = Yii::app()->params['emailTestAccounts']['testEmailAddress']; $this->assertTrue($john->save()); EmailMessage::deleteAll(); Yii::app()->imap->deleteMessages(true); // Check if there are no emails in dropbox $job = new EmailArchivingJob(); $this->assertTrue($job->run()); $this->assertEquals(0, EmailMessage::getCount()); $imapStats = Yii::app()->imap->getMessageBoxStatsDetailed(); $this->assertEquals(0, $imapStats->Nmsgs); //Now user send email to another user, and to dropbox $pathToFiles = Yii::getPathOfAlias('application.modules.emailMessages.tests.unit.files'); Yii::app()->emailHelper->sendRawEmail("Email from Steve 3", $user->primaryEmail->emailAddress, array(Yii::app()->params['emailTestAccounts']['testEmailAddress']), 'Email from Steve', '<strong>Email</strong> from Steve', null, array(Yii::app()->imap->imapUsername), null, self::$userMailer); sleep(30); $job = new EmailArchivingJob(); $this->assertTrue($job->run()); $imapStats = Yii::app()->imap->getMessageBoxStatsDetailed(); $this->assertEquals(0, $imapStats->Nmsgs); $this->assertEquals(2, EmailMessage::getCount()); $emailMessages = EmailMessage::getAll(); $emailMessage = $emailMessages[1]; $this->assertEquals('Email from Steve 3', $emailMessage->subject); $this->assertEquals('Email from Steve', trim($emailMessage->content->textContent)); $this->assertEquals('<!-- zurmo css inline --><strong>Email</strong> from Steve', preg_replace("/\r|\n/", "", $emailMessage->content->htmlContent)); $this->assertEquals($user->primaryEmail->emailAddress, $emailMessage->sender->fromAddress); $this->assertEquals(1, count($emailMessage->recipients)); $recipient = $emailMessage->recipients[0]; $this->assertCount(3, $recipient->personsOrAccounts); $this->assertEquals($recipient->toAddress, Yii::app()->params['emailTestAccounts']['testEmailAddress']); $this->assertEquals(EmailMessageRecipient::TYPE_TO, $recipient->type); $this->assertEquals(EmailFolder::TYPE_ARCHIVED, $emailMessage->folder->type); $job = new EmailArchivingJob(); $this->assertTrue($job->run()); $imapStats = Yii::app()->imap->getMessageBoxStatsDetailed(); $this->assertEquals(0, $imapStats->Nmsgs); $this->assertEquals(2, EmailMessage::getCount()); $this->assertEquals(1, Notification::getCountByTypeAndUser('EmailMessageArchivingEmailAddressNotMatching', $user)); }
/** * @depends testAttributesToAccount */ public function testAttributesToAccountWithNoPostData() { Yii::app()->user->userModel = User::getByUsername('super'); $postData = array('name' => ''); $contacts = Contact::getByName('Super Man'); $this->assertEquals(1, count($contacts)); $contact = $contacts[0]; $this->assertEquals('ABC Company', $contact->companyName); $this->assertEquals('1234567890', $contact->officePhone); $account = new Account(); $this->assertEmpty($account->name); $this->assertEmpty($account->officePhone); $account = LeadsUtil::attributesToAccountWithNoPostData($contact, $account, $postData); $this->assertEquals('1234567890', $account->officePhone); $this->assertEquals(null, $account->name); $postData = array(); $contacts = Contact::getByName('Super Man'); $this->assertEquals(1, count($contacts)); $contact = $contacts[0]; $this->assertEquals('ABC Company', $contact->companyName); $this->assertEquals('1234567890', $contact->officePhone); $account = new Account(); $this->assertEmpty($account->name); $this->assertEmpty($account->officePhone); $account = LeadsUtil::attributesToAccountWithNoPostData($contact, $account, $postData); $this->assertEquals('1234567890', $account->officePhone); $this->assertEquals('ABC Company', $account->name); }
public function testResolveContactWithLink() { $contacts = Contact::getByName('test testson'); $content = CampaignItemSummaryListViewColumnAdapter::resolveContactWithLink($contacts[0]); $this->assertContains('test testson', $content); //Benny dont have access to contact Yii::app()->user->userModel = User::getByUsername('benny'); $content = CampaignItemSummaryListViewColumnAdapter::resolveContactWithLink($contacts[0]); $this->assertContains('You cannot see this contact due to limited access', $content); }
public function testAttachRecipientsToMessage() { $billy = User::getByUsername('billy'); Yii::app()->user->userModel = $billy; $emailMessage = new EmailMessage(); //Attach non personOrAccount recipient EmailMessageUtil::attachRecipientsToMessage(array('*****@*****.**', '*****@*****.**', '*****@*****.**'), $emailMessage, EmailMessageRecipient::TYPE_TO); $this->assertEquals('3', count($emailMessage->recipients)); $this->assertLessThan(0, $emailMessage->recipients[0]->personOrAccount->id); $this->assertLessThan(0, $emailMessage->recipients[1]->personOrAccount->id); $this->assertLessThan(0, $emailMessage->recipients[2]->personOrAccount->id); $this->assertEquals(EmailMessageRecipient::TYPE_TO, $emailMessage->recipients[0]->type); $this->assertEquals(EmailMessageRecipient::TYPE_TO, $emailMessage->recipients[1]->type); $this->assertEquals(EmailMessageRecipient::TYPE_TO, $emailMessage->recipients[2]->type); //Attach personOrAccount recipient EmailMessageUtil::attachRecipientsToMessage(array('*****@*****.**', '*****@*****.**'), $emailMessage, EmailMessageRecipient::TYPE_BCC); $this->assertEquals('5', count($emailMessage->recipients)); $contacts = Contact::getByName('sally sallyson'); $this->assertEquals($emailMessage->recipients[3]->personOrAccount->id, $contacts[0]->id); $this->assertEquals(EmailMessageRecipient::TYPE_BCC, $emailMessage->recipients[3]->type); //User billy dont have permision to molly contact Yii::app()->user->userModel = User::getByUsername('super'); $contacts = Contact::getByName('molly mollyson'); $this->assertNotEquals($emailMessage->recipients[4]->personOrAccount->id, $contacts[0]->id); $this->assertEquals($emailMessage->recipients[4]->toAddress, $contacts[0]->primaryEmail->emailAddress); $this->assertEquals(EmailMessageRecipient::TYPE_BCC, $emailMessage->recipients[4]->type); //Attach an empty email EmailMessageUtil::attachRecipientsToMessage(array(''), $emailMessage, EmailMessageRecipient::TYPE_CC); $this->assertEquals('5', count($emailMessage->recipients)); }
/** * @depends testSuperUserCreateFromRelationAction */ public function testSuperUserCopyAction() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); $contacts = Contact::getByName('myNewContact myNewContactson'); $this->assertCount(1, $contacts); $postArray = array('Contact' => array('firstName' => 'myNewContact', 'lastName' => 'myNewContactson', 'jobTitle' => 'job title', 'account' => array('name' => 'Linked account'), 'department' => 'Some department', 'officePhone' => '456765421', 'mobilePhone' => '958462315', 'officeFax' => '123456789', 'primaryEmail' => array('emailAddress' => '*****@*****.**'), 'secondaryEmail' => array('emailAddress' => '*****@*****.**'), 'primaryAddress' => array('street1' => 'Street1', 'street2' => 'Street2', 'city' => 'City', 'state' => 'State', 'postalCode' => '12345', 'country' => 'Country'), 'secondaryAddress' => array('street1' => 'Street1', 'street2' => 'Street2', 'city' => 'City', 'state' => 'State', 'postalCode' => '12345', 'country' => 'Country'), 'description' => 'some description')); $this->updateModelValuesFromPostArray($contacts[0], $postArray); $this->assertModelHasValuesFromPostArray($contacts[0], $postArray); $this->assertTrue($contacts[0]->save()); $this->assertTrue($this->checkCopyActionResponseAttributeValuesFromPostArray($contacts[0], $postArray)); $postArray['Contact']['firstName'] = 'myClonedContact'; $postArray['Contact']['lastName'] = 'myClonedContactson'; $postArray['Contact']['state'] = array('id' => LeadsUtil::getStartingState()->id); $this->setGetArray(array('id' => $contacts[0]->id)); $this->setPostArray($postArray); $this->runControllerWithRedirectExceptionAndGetUrl('contacts/default/copy'); $contacts = Contact::getByName('myClonedContact myClonedContactson'); $this->assertCount(1, $contacts); $this->assertTrue($contacts[0]->owner->isSame($super)); unset($postArray['Contact']['state']); $this->assertModelHasValuesFromPostArray($contacts[0], $postArray); $contacts = Contact::getAll(); $this->assertCount(15, $contacts); $contacts = Contact::getByName('myClonedContact myClonedContactson'); $this->assertCount(1, $contacts); $this->assertTrue($contacts[0]->delete()); }
/** * @depends testOptOutAction */ public function testSubscribeActionAfterOptOutActionDisableOptOut() { $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); $marketingList = MarketingList::getByName('marketingList 04'); $this->assertNotEmpty($marketingList); $marketingList = $marketingList[0]; $marketingListId = $marketingList->id; $contact = Contact::getByName('contact 05 contact 05son'); $this->assertNotEmpty($contact); $contact = $contact[0]; $this->assertEquals(1, $contact->primaryEmail->optOut); $personId = $contact->getClassId('Person'); $member = MarketingListMember::getByMarketingListIdContactIdAndSubscribed($marketingList->id, $contact->id, 1); $this->assertNotEmpty($member); Yii::app()->user->userModel = null; $hash = EmailMessageActivityUtil::resolveHashForUnsubscribeAndManageSubscriptionsUrls($personId, $marketingListId, 1, 'AutoresponderItem', false); $this->setGetArray(array('hash' => $hash)); @$this->runControllerWithRedirectExceptionAndGetUrl($this->subscribeUrl); $content = $this->runControllerWithNoExceptionsAndGetContent($this->manageSubscriptionsUrl); $this->assertTrue(strpos($content, '<td>marketingList 01</td>') !== false); $this->assertTrue(strpos($content, '<td>marketingList 03</td>') !== false); $this->assertTrue(strpos($content, 'marketingLists/external/subscribe?hash=') !== false); $this->assertTrue(strpos($content, 'id="marketingListsManage' . 'SubscriptionListView-toggleUnsubscribed_') !== false); $this->assertTrue(strpos($content, 'id="marketingListsManage' . 'SubscriptionListView-toggleUnsubscribed_') !== false); $this->assertTrue(strpos($content, 'type="radio" name="marketingListsManage' . 'SubscriptionListView-toggleUnsubscribed_') !== false); $this->assertTrue(strpos($content, 'id="marketingListsManageSubscriptionListView-toggleUnsubscribed_' . $marketingListId . '_0" checked="checked" type="radio" name="marketingListsManage' . 'SubscriptionListView-toggleUnsubscribed_' . $marketingListId) !== false); $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); $contact = Contact::getByName('contact 05 contact 05son'); $this->assertNotEmpty($contact); $contact = $contact[0]; $this->assertEquals(0, $contact->primaryEmail->optOut); }
public function testSuperUserCompleteMatchVariations() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); $this->runControllerWithNoExceptionsAndGetContent('emailMessages/default/matchingList'); $message1 = EmailMessageTestHelper::createArchivedUnmatchedReceivedMessage($super); $message2 = EmailMessageTestHelper::createArchivedUnmatchedReceivedMessage($super); $message3 = EmailMessageTestHelper::createArchivedUnmatchedReceivedMessage($super); $contact = ContactTestHelper::createContactByNameForOwner('gail', $super); $startingContactState = ContactsUtil::getStartingState(); $startingLeadState = LeadsUtil::getStartingState(); //test validating selecting an existing contact $this->setGetArray(array('id' => $message1->id)); $this->setPostArray(array('ajax' => 'select-contact-form-' . $message1->id, 'AnyContactSelectForm' => array($message1->id => array('contactId' => $contact->id, 'contactName' => 'Some Name')))); $this->runControllerWithExitExceptionAndGetContent('emailMessages/default/completeMatch'); //test validating creating a new contact $this->setGetArray(array('id' => $message1->id)); $this->setPostArray(array('ajax' => 'contact-inline-create-form-' . $message1->id, 'Contact' => array($message1->id => array('firstName' => 'Gail', 'lastName' => 'Green', 'officePhone' => '456765421', 'state' => array('id' => $startingContactState->id))))); $this->runControllerWithExitExceptionAndGetContent('emailMessages/default/completeMatch'); //test validating creating a new lead $this->setGetArray(array('id' => $message1->id)); $this->setPostArray(array('ajax' => 'lead-inline-create-form-' . $message1->id, 'Lead' => array($message1->id => array('firstName' => 'Gail', 'lastName' => 'Green', 'officePhone' => '456765421', 'state' => array('id' => $startingLeadState->id))))); $this->runControllerWithExitExceptionAndGetContent('emailMessages/default/completeMatch'); //test selecting existing contact and saving $this->assertNull($contact->primaryEmail->emailAddress); $this->setGetArray(array('id' => $message1->id)); $this->setPostArray(array('AnyContactSelectForm' => array($message1->id => array('contactId' => $contact->id, 'contactName' => 'Some Name')))); $this->runControllerWithNoExceptionsAndGetContent('emailMessages/default/completeMatch', true); $this->assertEquals('*****@*****.**', $contact->primaryEmail->emailAddress); $this->assertTrue($message1->sender->personOrAccount->isSame($contact)); $this->assertEquals('Archived', $message1->folder); //test creating new contact and saving $this->assertEquals(1, Contact::getCount()); $this->setGetArray(array('id' => $message2->id)); $this->setPostArray(array('Contact' => array($message2->id => array('firstName' => 'George', 'lastName' => 'Patton', 'officePhone' => '456765421', 'state' => array('id' => $startingContactState->id))))); $this->runControllerWithNoExceptionsAndGetContent('emailMessages/default/completeMatch', true); $this->assertEquals(2, Contact::getCount()); $contacts = Contact::getByName('George Patton'); $contact = $contacts[0]; $this->assertTrue($message2->sender->personOrAccount->isSame($contact)); $this->assertEquals('Archived', $message2->folder); //test creating new lead and saving $this->assertEquals(2, Contact::getCount()); $this->setGetArray(array('id' => $message3->id)); $this->setPostArray(array('Lead' => array($message3->id => array('firstName' => 'Billy', 'lastName' => 'Kid', 'officePhone' => '456765421', 'state' => array('id' => $startingLeadState->id))))); $this->runControllerWithNoExceptionsAndGetContent('emailMessages/default/completeMatch', true); $this->assertEquals(3, Contact::getCount()); $contacts = Contact::getByName('Billy Kid'); $contact = $contacts[0]; $this->assertTrue($message3->sender->personOrAccount->isSame($contact)); $this->assertEquals('Archived', $message3->folder); }
protected function setSelectedModels() { $contacts = Contact::getByName('Super Man'); $this->selectedModels[] = $contacts[0]; $contacts = Contact::getByName('shozin shozinson'); $this->selectedModels[] = $contacts[0]; }
/** * @depends testSuperUserCreateAction */ public function testSuperUserCreateFromRelationAction() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); $currencies = Currency::getAll(); $opportunities = Opportunity::getAll(); $this->assertEquals(12, count($opportunities)); $account = Account::getByName('superAccount2'); $contact = Contact::getByName('superContact2 superContact2son'); $this->assertEquals(1, count($contact)); //Create a new contact from a related account. $this->setGetArray(array('relationAttributeName' => 'account', 'relationModelId' => $account[0]->id, 'relationModuleId' => 'accounts', 'redirectUrl' => 'someRedirect')); $this->setPostArray(array('Opportunity' => array('name' => 'myUltraNewOpportunity', 'description' => '456765421', 'closeDate' => '11/1/11', 'amount' => array('value' => '545', 'currency' => array('id' => $currencies[0]->id)), 'stage' => array('value' => 'Negotiating')))); $this->runControllerWithRedirectExceptionAndGetContent('opportunities/default/createFromRelation'); $opportunities = Opportunity::getByName('myUltraNewOpportunity'); $this->assertEquals(1, count($opportunities)); $this->assertTrue($opportunities[0]->id > 0); $this->assertTrue($opportunities[0]->owner == $super); $this->assertTrue($opportunities[0]->account == $account[0]); $this->assertEquals('456765421', $opportunities[0]->description); $this->assertEquals('545', $opportunities[0]->amount->value); $this->assertEquals('2011-11-01', $opportunities[0]->closeDate); $this->assertEquals('Negotiating', $opportunities[0]->stage->value); $opportunities = Opportunity::getAll(); $this->assertEquals(13, count($opportunities)); //Create a new contact from a related opportunity $this->setGetArray(array('relationAttributeName' => 'contacts', 'relationModelId' => $contact[0]->id, 'relationModuleId' => 'contacts', 'redirectUrl' => 'someRedirect')); $this->setPostArray(array('Opportunity' => array('name' => 'mySuperNewOpportunity', 'description' => '456765421', 'closeDate' => '11/1/11', 'amount' => array('value' => '545', 'currency' => array('id' => $currencies[0]->id)), 'stage' => array('value' => 'Negotiating')))); $this->runControllerWithRedirectExceptionAndGetContent('opportunities/default/createFromRelation'); $opportunities = Opportunity::getByName('mySuperNewOpportunity'); $this->assertEquals(1, count($opportunities)); $this->assertTrue($opportunities[0]->id > 0); $this->assertTrue($opportunities[0]->owner == $super); $this->assertEquals(1, $opportunities[0]->contacts->count()); $this->assertTrue($opportunities[0]->contacts[0] == $contact[0]); $this->assertEquals('456765421', $opportunities[0]->description); $this->assertEquals('545', $opportunities[0]->amount->value); $this->assertEquals('2011-11-01', $opportunities[0]->closeDate); $this->assertEquals('Negotiating', $opportunities[0]->stage->value); $opportunities = Opportunity::getAll(); $this->assertEquals(14, count($opportunities)); //todo: test save with account. }
/** * @depends testWhetherSearchWorksForTheCustomFieldsPlacedForLeadsModuleAfterEditingTheLeadUser */ public function testDeleteOfTheLeadUserForTheCustomFieldsPlacedForLeadsModule() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); //Retrieve the lead id. $leadId = self::getModelIdByModelNameAndName('Contact', 'Sarah Williams Edit'); //Set the lead id so as to delete the lead. $this->setGetArray(array('id' => $leadId)); $this->runControllerWithRedirectExceptionAndGetUrl('leads/default/delete'); //Check whether the lead is deleted. $lead = Contact::getByName('Sarah Williams Edit'); $this->assertEquals(0, count($lead)); }
/** * @depends testCreateStateValues */ public function testSaveContactFromPostWithoutAccount() { Yii::app()->user->userModel = User::getByUsername('super'); //Save contact without account. $startingState = ContactsUtil::getStartingState(); $contacts = Contact::getByName('jilly simpson'); $this->assertEmpty($contacts); $fakePostData = array('firstName' => 'jilly', 'lastName' => 'simpson', 'account' => array('id' => ''), 'state' => array('id' => $startingState->id)); $contact = new Contact(); $contact->setAttributes($fakePostData); $saved = $contact->save(); $this->assertTrue($saved); $contactId = $contact->id; $contact->forget(); //Now try to make a change to that contact. Still no account. $fakePostData = array('firstName' => 'jilly', 'lastName' => 'simpson', 'officePhone' => '12345', 'account' => array('id' => ''), 'state' => array('id' => $startingState->id)); $contact = Contact::getById($contactId); $contact->setAttributes($fakePostData); $saved = $contact->save(); $this->assertTrue($saved); //Create a contact not through post without an account. $contact = ContactTestHelper::createContactByNameForOwner('shozin', Yii::app()->user->userModel); $contactId = $contact->id; $contact->forget(); //Now try to make a change to that contact via post. Still no account. $fakePostData = array('firstName' => 'shozin', 'lastName' => 'shozinson', 'officePhone' => '12345', 'account' => array('id' => ''), 'state' => array('id' => $startingState->id)); $contact = Contact::getById($contactId); $contact->setAttributes($fakePostData); $saved = $contact->save(); $this->assertTrue($saved); }
/** * @depends testListLead */ public function testUnprivilegedUserViewUpdateDeleteLead() { Yii::app()->user->userModel = User::getByUsername('super'); $notAllowedUser = UserTestHelper::createBasicUser('Steven'); $notAllowedUser->setRight('UsersModule', UsersModule::RIGHT_LOGIN_VIA_WEB_API); $saved = $notAllowedUser->save(); $authenticationData = $this->login('steven', 'steven'); $headers = array('Accept: application/json', 'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'], 'ZURMO_TOKEN: ' . $authenticationData['token'], 'ZURMO_API_REQUEST_TYPE: REST'); $everyoneGroup = Group::getByName(Group::EVERYONE_GROUP_NAME); $this->assertTrue($everyoneGroup->save()); $leads = Contact::getByName('Michael Smith'); $this->assertEquals(1, count($leads)); $data['department'] = "Support"; // Test with unprivileged user to view, edit and delete account. $authenticationData = $this->login('steven', 'steven'); $headers = array('Accept: application/json', 'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'], 'ZURMO_TOKEN: ' . $authenticationData['token'], 'ZURMO_API_REQUEST_TYPE: REST'); $response = ApiRestTestHelper::createApiCall($this->serverUrl . '/test.php/leads/contact/api/read/' . $leads[0]->id, 'GET', $headers); $response = json_decode($response, true); $this->assertEquals(ApiResponse::STATUS_FAILURE, $response['status']); $this->assertEquals('You do not have rights to perform this action.', $response['message']); $response = ApiRestTestHelper::createApiCall($this->serverUrl . '/test.php/leads/contact/api/update/' . $leads[0]->id, 'PUT', $headers, array('data' => $data)); $response = json_decode($response, true); $this->assertEquals(ApiResponse::STATUS_FAILURE, $response['status']); $this->assertEquals('You do not have rights to perform this action.', $response['message']); $response = ApiRestTestHelper::createApiCall($this->serverUrl . '/test.php/leads/contact/api/delete/' . $leads[0]->id, 'DELETE', $headers); $response = json_decode($response, true); $this->assertEquals(ApiResponse::STATUS_FAILURE, $response['status']); $this->assertEquals('You do not have rights to perform this action.', $response['message']); //now check if user have rights, but no permissions. $notAllowedUser->setRight('LeadsModule', LeadsModule::getAccessRight()); $notAllowedUser->setRight('LeadsModule', LeadsModule::getCreateRight()); $notAllowedUser->setRight('LeadsModule', LeadsModule::getDeleteRight()); $saved = $notAllowedUser->save(); $this->assertTrue($saved); $response = ApiRestTestHelper::createApiCall($this->serverUrl . '/test.php/leads/contact/api/read/' . $leads[0]->id, 'GET', $headers); $response = json_decode($response, true); $this->assertEquals(ApiResponse::STATUS_FAILURE, $response['status']); $this->assertEquals('You do not have permissions for this action.', $response['message']); $response = ApiRestTestHelper::createApiCall($this->serverUrl . '/test.php/leads/contact/api/update/' . $leads[0]->id, 'PUT', $headers, array('data' => $data)); $response = json_decode($response, true); $this->assertEquals(ApiResponse::STATUS_FAILURE, $response['status']); $this->assertEquals('You do not have permissions for this action.', $response['message']); $response = ApiRestTestHelper::createApiCall($this->serverUrl . '/test.php/leads/contact/api/delete/' . $leads[0]->id, 'DELETE', $headers); $response = json_decode($response, true); $this->assertEquals(ApiResponse::STATUS_FAILURE, $response['status']); $this->assertEquals('You do not have permissions for this action.', $response['message']); // Update unprivileged user permissions $authenticationData = $this->login(); $headers = array('Accept: application/json', 'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'], 'ZURMO_TOKEN: ' . $authenticationData['token'], 'ZURMO_API_REQUEST_TYPE: REST'); unset($data); $data['explicitReadWriteModelPermissions'] = array('type' => ExplicitReadWriteModelPermissionsUtil::MIXED_TYPE_EVERYONE_GROUP); $response = ApiRestTestHelper::createApiCall($this->serverUrl . '/test.php/leads/contact/api/update/' . $leads[0]->id, 'PUT', $headers, array('data' => $data)); $response = json_decode($response, true); $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']); $authenticationData = $this->login('steven', 'steven'); $headers = array('Accept: application/json', 'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'], 'ZURMO_TOKEN: ' . $authenticationData['token'], 'ZURMO_API_REQUEST_TYPE: REST'); $response = ApiRestTestHelper::createApiCall($this->serverUrl . '/test.php/leads/contact/api/read/' . $leads[0]->id, 'GET', $headers); $response = json_decode($response, true); $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']); unset($data); $data['department'] = "Support"; $response = ApiRestTestHelper::createApiCall($this->serverUrl . '/test.php/leads/contact/api/update/' . $leads[0]->id, 'PUT', $headers, array('data' => $data)); $response = json_decode($response, true); $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']); $this->assertEquals('Support', $response['data']['department']); $response = ApiRestTestHelper::createApiCall($this->serverUrl . '/test.php/leads/contact/api/delete/' . $leads[0]->id, 'DELETE', $headers); $response = json_decode($response, true); $this->assertEquals(ApiResponse::STATUS_FAILURE, $response['status']); $this->assertEquals('You do not have permissions for this action.', $response['message']); // Test with privileged user $authenticationData = $this->login(); $headers = array('Accept: application/json', 'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'], 'ZURMO_TOKEN: ' . $authenticationData['token'], 'ZURMO_API_REQUEST_TYPE: REST'); //Test Delete $response = ApiRestTestHelper::createApiCall($this->serverUrl . '/test.php/leads/contact/api/delete/' . $leads[0]->id, 'DELETE', $headers); $response = json_decode($response, true); $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']); $response = ApiRestTestHelper::createApiCall($this->serverUrl . '/test.php/leads/contact/api/read/' . $leads[0]->id, 'GET', $headers); $response = json_decode($response, true); $this->assertEquals(ApiResponse::STATUS_FAILURE, $response['status']); }
/** * @depends testGetGlobalSearchResultsByPartialTermUsingScope */ public function testGetGlobalSearchResultsByPartialTermWithRegularUserAndElevationStepsForRegularUser() { //Unfrozen, there are too many attributes that have to be columns in the database at this point, so //now this is just a frozen test. if (RedBeanDatabase::isFrozen()) { $super = User::getByUsername('super'); $jimmy = User::getByUsername('jimmy'); Yii::app()->user->userModel = $super; //Jimmy does not have read access, so he should not be able to see any results. $this->assertEquals(Right::DENY, $jimmy->getEffectiveRight('AccountsModule', AccountsModule::RIGHT_ACCESS_ACCOUNTS)); $this->assertEquals(Right::DENY, $jimmy->getEffectiveRight('ContactsModule', ContactsModule::RIGHT_ACCESS_CONTACTS)); $this->assertEquals(Right::DENY, $jimmy->getEffectiveRight('OpportunitiesModule', OpportunitiesModule::RIGHT_ACCESS_OPPORTUNITIES)); Yii::app()->user->userModel = $jimmy; $data = ModelAutoCompleteUtil::getGlobalSearchResultsByPartialTerm('animal', 5, Yii::app()->user->userModel); $this->assertEquals(array(array('href' => '', 'label' => 'No Results Found', 'iconClass' => '')), $data); //Give Jimmy access to the module, he still will not be able to see results. Yii::app()->user->userModel = $super; $jimmy->setRight('AccountsModule', AccountsModule::RIGHT_ACCESS_ACCOUNTS); $jimmy->setRight('ContactsModule', ContactsModule::RIGHT_ACCESS_CONTACTS); $jimmy->setRight('LeadsModule', LeadsModule::RIGHT_ACCESS_LEADS); $jimmy->setRight('OpportunitiesModule', OpportunitiesModule::RIGHT_ACCESS_OPPORTUNITIES); $this->assertTrue($jimmy->save()); Yii::app()->user->userModel = $jimmy; $data = ModelAutoCompleteUtil::getGlobalSearchResultsByPartialTerm('animal', 5, Yii::app()->user->userModel); $this->assertEquals(array(array('href' => '', 'label' => 'No Results Found', 'iconClass' => '')), $data); //Give Jimmy read on 1 model. The search then should pick up this model. Yii::app()->user->userModel = $super; $accounts = Account::getByName('The Zoo'); $this->assertEquals(1, count($accounts)); $account = $accounts[0]; $this->assertEquals(Permission::NONE, $account->getEffectivePermissions($jimmy)); $account->addPermissions($jimmy, Permission::READ); $this->assertTrue($account->save()); ReadPermissionsOptimizationUtil::securableItemGivenPermissionsForUser($account, $jimmy); Yii::app()->user->userModel = $jimmy; $data = ModelAutoCompleteUtil::getGlobalSearchResultsByPartialTerm('animal', 5, Yii::app()->user->userModel); $this->assertEquals(1, count($data)); $this->assertEquals('The Zoo', $data[0]['label']); //Give Jimmy read on 2 more models. The search then should pick up these models. Yii::app()->user->userModel = $super; $contacts = Contact::getByName('Big Elephant'); $this->assertEquals(1, count($contacts)); $contact = $contacts[0]; $this->assertEquals(Permission::NONE, $contact->getEffectivePermissions($jimmy)); $contact->addPermissions($jimmy, Permission::READ); $this->assertTrue($contact->save()); ReadPermissionsOptimizationUtil::securableItemGivenPermissionsForUser($contact, $jimmy); $opportunities = Opportunity::getByName('Animal Crackers'); $this->assertEquals(1, count($opportunities)); $opportunity = $opportunities[0]; $this->assertEquals(Permission::NONE, $opportunity->getEffectivePermissions($jimmy)); $opportunity->addPermissions($jimmy, Permission::READ); $this->assertTrue($opportunity->save()); ReadPermissionsOptimizationUtil::securableItemGivenPermissionsForUser($opportunity, $jimmy); Yii::app()->user->userModel = $jimmy; $data = ModelAutoCompleteUtil::getGlobalSearchResultsByPartialTerm('animal', 5, Yii::app()->user->userModel); $this->assertEquals(3, count($data)); $this->assertEquals('The Zoo', $data[0]['label']); $this->assertEquals('Big Elephant', $data[1]['label']); $this->assertEquals('Animal Crackers', $data[2]['label']); } }
/** * @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); }
/** * Test get contacts that are releted with particular opportunity(MANY_MANY relationship) * @depends testDynamicSearchContacts */ public function testGetContactsThatAreRelatedWithOpportunity() { $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; $firstOpportunity = OpportunityTestHelper::createOpportunityByNameForOwner('First Opportunity', $super); $secondOpportunity = OpportunityTestHelper::createOpportunityByNameForOwner('Second Opportunity', $super); $contacts = Contact::getByName('First Contact First Contactson'); $firstContact = $contacts[0]; $contacts = Contact::getByName('Second Contact Second Contactson'); $secondContact = $contacts[0]; $contacts = Contact::getByName('Third Contact Third Contactson'); $thirdContact = $contacts[0]; $contacts = Contact::getByName('Forth Contact Forth Contactson'); $forthContact = $contacts[0]; $firstOpportunity->contacts->add($firstContact); $firstOpportunity->contacts->add($secondContact); $firstOpportunity->contacts->add($thirdContact); $firstOpportunity->save(); $authenticationData = $this->login(); $headers = array('Accept: application/json', 'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'], 'ZURMO_TOKEN: ' . $authenticationData['token'], 'ZURMO_API_REQUEST_TYPE: REST'); $data = array('dynamicSearch' => array('dynamicClauses' => array(array('attributeIndexOrDerivedType' => 'opportunities' . FormModelUtil::RELATION_DELIMITER . 'id', 'structurePosition' => 1, 'opportunities' => array('id' => $firstOpportunity->id))), 'dynamicStructure' => '1'), 'pagination' => array('page' => 1, 'pageSize' => 2), 'sort' => 'firstName.desc'); $response = $this->createApiCallWithRelativeUrl('list/filter/', 'POST', $headers, array('data' => $data)); $response = json_decode($response, true); $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']); $this->assertEquals(2, count($response['data']['items'])); $this->assertEquals(3, $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']); // Get second page $data['pagination']['page'] = 2; $response = $this->createApiCallWithRelativeUrl('list/filter/', 'POST', $headers, array('data' => $data)); $response = json_decode($response, true); $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']); $this->assertEquals(1, count($response['data']['items'])); $this->assertEquals(3, $response['data']['totalCount']); $this->assertEquals(2, $response['data']['currentPage']); $this->assertEquals('First Contact', $response['data']['items'][0]['firstName']); }
/** * @depends testCreateNewActivity */ public function testGetByTypeAndModelIdAndPersonIdAndUrl() { $type = AutoresponderItemActivity::TYPE_OPEN; $url = null; $persons = Person::getAll(); $this->assertNotEmpty($persons); $person = $persons[0]; $autoresponderItems = AutoresponderItem::getAll(); $this->assertNotEmpty($autoresponderItems); $autoresponderItem = $autoresponderItems[0]; $activities = AutoresponderItemActivity::getByTypeAndModelIdAndPersonIdAndUrl($type, $autoresponderItem->id, $person->id, $url); $this->assertNotEmpty($activities); $this->assertCount(1, $activities); $activity = $activities[0]; $this->assertEquals($type, $activity->type); $this->assertEquals(1, $activity->quantity); $this->assertEquals($person, $activity->person); $this->assertEquals($autoresponderItem, $activity->autoresponderItem); // now try same thing but with a url this time. $contact = Contact::getByName('contact 02 contact 02son'); $personId = $contact[0]->getClassId('Person'); $person = Person::getById($personId); $type = AutoresponderItemActivity::TYPE_CLICK; $url = 'http://www.zurmo.com'; $activities = AutoresponderItemActivity::getByTypeAndModelIdAndPersonIdAndUrl($type, $autoresponderItem->id, $personId, $url); $this->assertNotEmpty($activities); $this->assertCount(1, $activities); $activity = $activities[0]; $this->assertEquals($type, $activity->type); $this->assertEquals(1, $activity->quantity); $this->assertEquals($person, $activity->person); $this->assertEquals($autoresponderItem, $activity->autoresponderItem); }
/** * @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 and by skipping opportunity creation $this->runControllerWithNoExceptionsAndGetContent('leads/default/convert'); $this->setGetArray(array('id' => $lead->id)); $this->setPostArray(array('AccountSkip' => 'Not Used')); $this->runControllerWithRedirectExceptionAndGetContent('leads/default/convert'); $this->setGetArray(array('id' => $lead->id)); $this->setPostArray(array('OpportunitySkip' => 'Not Used')); $this->runControllerWithRedirectExceptionAndGetContent('leads/default/convertFinal'); $leadId = $lead->id; $lead->forget(); $contact = Contact::getById($leadId); $this->assertTrue($contact->state == $startingContactState); //Test trying to convert by creating a new account and by skipping opportunity creation. $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, Account::getCount()); $this->runControllerWithRedirectExceptionAndGetContent('leads/default/convert'); $this->setGetArray(array('id' => $lead5->id)); $this->setPostArray(array('OpportunitySkip' => 'Not Used')); $this->runControllerWithRedirectExceptionAndGetContent('leads/default/convertFinal'); $this->assertEquals(1, Account::getCount()); $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 and by skipping opportunity creation. $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, Account::getCount()); $this->runControllerWithRedirectExceptionAndGetContent('leads/default/convert'); $this->setGetArray(array('id' => $lead6->id)); $this->setPostArray(array('OpportunitySkip' => 'Not Used')); $this->runControllerWithRedirectExceptionAndGetContent('leads/default/convertFinal'); $this->assertEquals(2, Account::getCount()); $lead6Id = $lead6->id; $lead6->forget(); $contact6 = Contact::getById($lead6Id); $this->assertTrue($contact6->state == $startingContactState); $this->assertEquals($account, $contact6->account); //Test trying to convert by skipping account creation and by creating new opportunity $this->runControllerWithRedirectExceptionAndGetContent('leads/default/convert'); $leadOpp = LeadTestHelper::createLeadbyNameForOwner('superLeadOpp', $super); $this->setGetArray(array('id' => $leadOpp->id)); $this->setPostArray(array('AccountSkip' => 'Not Used')); $this->runControllerWithRedirectExceptionAndGetContent('leads/default/convert'); $this->setGetArray(array('id' => $leadOpp->id)); $this->setPostArray(array('Opportunity' => array('name' => 'someOpportunityName', 'amount' => array('currency' => array('id' => '1'), 'value' => '100'), 'closeDate' => '6/19/2014', 'stage' => array('value' => 'Negotiating'), 'probability' => '50'))); $this->assertEquals(0, Opportunity::getCount()); $this->assertEquals(2, Account::getCount()); $this->runControllerWithRedirectExceptionAndGetContent('leads/default/convertFinal'); $leadId = $leadOpp->id; $leadOpp->forget(); $contact = Contact::getById($leadId); $this->assertTrue($contact->state == $startingContactState); $this->assertEquals(1, Opportunity::getCount()); $this->assertEquals(2, Account::getCount()); }