/** * @depends testCreateStateValues */ public function testGetSetConvertToAccountSetting() { $this->assertEquals(2, LeadsModule::getConvertToAccountSetting()); $this->assertEquals(2, LeadsModule::CONVERT_ACCOUNT_NOT_REQUIRED); $metadata = LeadsModule::getMetadata(); $metadata['global']['convertToAccountSetting'] = LeadsModule::CONVERT_ACCOUNT_REQUIRED; LeadsModule::setMetadata($metadata); $this->assertEquals(3, LeadsModule::getConvertToAccountSetting()); }
/** * Given a post data array, map the lead to account attributes * but only if the post data does not contain a set attribute. * This method is used when a posted form has an empty value on * an input field. We do not want to set the mapped field since * the use of setAttributes will pick up the correct information * from the posted data. This will allow form validation to work * properly in the case where a mapped field is cleared to blank * in the input field and submitted. Such an event should trigger * a form validation error. * @see LeadsUtil::attributesToAccount * @param $contact Contact model * @param $account Account model * @param $postData array of posted form data * @return Account, with mapped attributes from Contact */ public static function attributesToAccountWithNoPostData(Contact $contact, Account $account, array $postData) { assert('is_array($postData)'); assert('!empty($contact->id)'); $metadata = LeadsModule::getMetadata(); $map = $metadata['global']['convertToAccountAttributesMapping']; foreach ($map as $contactAttributeName => $accountAttributeName) { if (!isset($postData[$accountAttributeName])) { $account->{$accountAttributeName} = $contact->{$contactAttributeName}; } } return $account; }
/** * @depends testUserCanAccessAccountsButCannotCreateAccountShowConvertAction */ public function testLeadConversionMisconfigurationScenarios() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); $bubby = UserTestHelper::createBasicUser('bubby'); $lead = LeadTestHelper::createLeadbyNameForOwner('BelinaLead1', $bubby); $bubby->setRight('LeadsModule', LeadsModule::RIGHT_CONVERT_LEADS, Right::ALLOW); $bubby->setRight('LeadsModule', LeadsModule::RIGHT_ACCESS_LEADS, Right::ALLOW); $this->assertTrue($bubby->save()); //Scenario #1 - User does not have access to contacts $this->assertEquals(Right::DENY, $bubby->getEffectiveRight('ContactsModule', ContactsModule::RIGHT_ACCESS_CONTACTS)); $bubby = $this->logoutCurrentUserLoginNewUserAndGetByUsername('bubby'); //View will not show up properly. $this->setGetArray(array('id' => $lead->id)); $content = $this->runControllerWithExitExceptionAndGetContent('leads/default/convert'); $this->assertContains('Conversion requires access to the contacts module which you do not have. Please contact your administrator.', $content); //Scenario #2 - User cannot access accounts and an account is required for conversion $bubby->setRight('ContactsModule', ContactsModule::RIGHT_CREATE_CONTACTS, Right::ALLOW); $bubby->setRight('ContactsModule', ContactsModule::RIGHT_ACCESS_CONTACTS, Right::ALLOW); $this->assertTrue($bubby->save()); $metadata = LeadsModule::getMetadata(); $metadata['global']['convertToAccountSetting'] = LeadsModule::CONVERT_ACCOUNT_REQUIRED; LeadsModule::setMetadata($metadata); //At this point because the account is required, the view will not come up properly. $this->setGetArray(array('id' => $lead->id)); $content = $this->runControllerWithExitExceptionAndGetContent('leads/default/convert'); $this->assertContains('Conversion is set to require an account. Currently you do not have access to the accounts module.', $content); //Scenario #3 - User cannot access opportunities and an opportunity is required for conversion $metadata = LeadsModule::getMetadata(); $metadata['global']['convertToAccountSetting'] = LeadsModule::CONVERT_ACCOUNT_NOT_REQUIRED; $metadata['global']['convertToOpportunitySetting'] = LeadsModule::CONVERT_OPPORTUNITY_REQUIRED; LeadsModule::setMetadata($metadata); //At this point because the opportunity is required, the view will not come up properly. $this->setGetArray(array('id' => $lead->id)); $this->runControllerWithRedirectExceptionAndGetContent('leads/default/convert'); $this->setGetArray(array('id' => $lead->id)); $content = $this->runControllerWithExitExceptionAndGetContent('leads/default/convertFinal'); $this->assertContains('Conversion is set to require an opportunity. Currently you do not have access to the opportunities module.', $content); }
public static function getConvertToAccountSetting() { $metadata = LeadsModule::getMetadata(); return $metadata['global']['convertToAccountSetting']; }
public static function getConvertToOpportunitySetting() { $metadata = LeadsModule::getMetadata(); if (isset($metadata['global']['convertToOpportunitySetting'])) { return (int) $metadata['global']['convertToOpportunitySetting']; } else { return (int) LeadsModule::CONVERT_OPPORTUNITY_NOT_REQUIRED; } }