本文整理汇总了PHP中Currency::getByCode方法的典型用法代码示例。如果您正苦于以下问题:PHP Currency::getByCode方法的具体用法?PHP Currency::getByCode怎么用?PHP Currency::getByCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Currency
的用法示例。
在下文中一共展示了Currency::getByCode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testCurrencySanitizationUsingNumberSanitizerUtil
public function testCurrencySanitizationUsingNumberSanitizerUtil()
{
$currency = Currency::getByCode(Yii::app()->currencyHelper->getBaseCode());
//Test a pure number as the value
$importSanitizeResultsUtil = new ImportSanitizeResultsUtil();
$columnMappingData = ImportMappingUtil::makeCurrencyColumnMappingData('currencyValue', $currency);
$sanitizerUtilTypes = CurrencyValueAttributeImportRules::getSanitizerUtilTypesInProcessingOrder();
$sanitizedValue = ImportSanitizerUtil::sanitizeValueBySanitizerTypes($sanitizerUtilTypes, 'ImportModelTestItem', 'currencyValue', '500.34', 'column_0', $columnMappingData, $importSanitizeResultsUtil);
$this->assertEquals('500.34', $sanitizedValue);
$this->assertTrue($importSanitizeResultsUtil->shouldSaveModel());
$messages = $importSanitizeResultsUtil->getMessages();
$this->assertEquals(0, count($messages));
//Test with dollar signs. Should strip out dollar signs
$importSanitizeResultsUtil = new ImportSanitizeResultsUtil();
$columnMappingData = ImportMappingUtil::makeCurrencyColumnMappingData('currencyValue', $currency);
$sanitizerUtilTypes = CurrencyValueAttributeImportRules::getSanitizerUtilTypesInProcessingOrder();
$sanitizedValue = ImportSanitizerUtil::sanitizeValueBySanitizerTypes($sanitizerUtilTypes, 'ImportModelTestItem', 'currencyValue', '$500.34', 'column_0', $columnMappingData, $importSanitizeResultsUtil);
$this->assertEquals('500.34', $sanitizedValue);
$this->assertTrue($importSanitizeResultsUtil->shouldSaveModel());
$messages = $importSanitizeResultsUtil->getMessages();
$this->assertEquals(0, count($messages));
//Test with commmas. Should strip out commas
$importSanitizeResultsUtil = new ImportSanitizeResultsUtil();
$columnMappingData = ImportMappingUtil::makeCurrencyColumnMappingData('currencyValue', $currency);
$sanitizerUtilTypes = CurrencyValueAttributeImportRules::getSanitizerUtilTypesInProcessingOrder();
$sanitizedValue = ImportSanitizerUtil::sanitizeValueBySanitizerTypes($sanitizerUtilTypes, 'ImportModelTestItem', 'currencyValue', '15,500.34', 'column_0', $columnMappingData, $importSanitizeResultsUtil);
$this->assertEquals('15500.34', $sanitizedValue);
$this->assertTrue($importSanitizeResultsUtil->shouldSaveModel());
$messages = $importSanitizeResultsUtil->getMessages();
$this->assertEquals(0, count($messages));
}
示例2: resolveValueForImport
/**
* There is a special way you can import rateToBase and currencyCode for an amount attribute.
* if the column data is formatted like: $54.67__1.2__USD then it will split the column and properly
* handle rate and currency code. Eventually this will be exposed in the user interface
*
* @param mixed $value
* @param string $columnName
* @param array $columnMappingData
* @param ImportSanitizeResultsUtil $importSanitizeResultsUtil
* @return array
*/
public function resolveValueForImport($value, $columnName, $columnMappingData, ImportSanitizeResultsUtil $importSanitizeResultsUtil)
{
assert('is_string($columnName)');
$attributeNames = $this->getRealModelAttributeNames();
$modelClassName = $this->getModelClassName();
$parts = explode(FormModelUtil::DELIMITER, $value);
if (count($parts) == 3) {
$value = $parts[0];
$rateToBase = $parts[1];
try {
$currency = Currency::getByCode($parts[2]);
} catch (NotFoundException $e) {
$currency = null;
$importSanitizeResultsUtil->addMessage('Currency Code: ' . $parts[2] . ' is invalid.');
$importSanitizeResultsUtil->setModelShouldNotBeSaved();
}
} else {
$rateToBase = $columnMappingData['mappingRulesData']['CurrencyRateToBaseModelAttributeMappingRuleForm']['rateToBase'];
$currency = Currency::getById((int) $columnMappingData['mappingRulesData']['CurrencyIdModelAttributeMappingRuleForm']['id']);
}
$sanitizedValue = ImportSanitizerUtil::sanitizeValueBySanitizerTypes(static::getSanitizerUtilTypesInProcessingOrder(), $modelClassName, $this->getModelAttributeName(), $value, $columnName, $columnMappingData, $importSanitizeResultsUtil);
if ($sanitizedValue == null) {
$sanitizedValue = 0;
}
$currencyValue = new CurrencyValue();
$currencyValue->setScenario('importModel');
$currencyValue->value = $sanitizedValue;
$currencyValue->rateToBase = $rateToBase;
$currencyValue->currency = $currency;
return array($this->getModelAttributeName() => $currencyValue);
}
示例3: resolveCurrencyValueConversionRateForCurrentUserForDisplay
/**
* Given a value that is in the base currency, convert the value to the display currency for the current user.
* @param Number $valueInBaseCurrency
*/
protected function resolveCurrencyValueConversionRateForCurrentUserForDisplay($valueInBaseCurrency)
{
assert('is_numeric($valueInBaseCurrency)');
if (Yii::app()->currencyHelper->getCodeForCurrentUserForDisplay() == Yii::app()->currencyHelper->getBaseCode()) {
return $valueInBaseCurrency;
}
$currency = Currency::getByCode(Yii::app()->currencyHelper->getCodeForCurrentUserForDisplay());
return $valueInBaseCurrency * (1 / $currency->rateToBase);
}
示例4: testCreateCurrencyAndIsActiveByDefaultAndSettingActiveToFalse
public function testCreateCurrencyAndIsActiveByDefaultAndSettingActiveToFalse()
{
$currency = new Currency();
$currency->code = 'EUR';
$currency->rateToBase = 2;
$this->assertTrue($currency->save());
$currency->forget();
$currency = Currency::getByCode('EUR');
$this->assertEquals(1, $currency->active);
$currency->active = false;
$this->assertTrue($currency->save());
$currency->forget();
$currency = Currency::getByCode('EUR');
$this->assertEquals(0, $currency->active);
}
示例5: sanitizeValue
public function sanitizeValue($value)
{
$resolvedAcceptableValues = ArrayUtil::resolveArrayToLowerCase(static::getAcceptableValues());
if ($value != null) {
if (!in_array(strtolower($value), $resolvedAcceptableValues)) {
return null;
}
$currency = Currency::getByCode($value);
if ($currency != null) {
return $currency;
}
}
if (isset($this->mappingRuleData['defaultValue']) && $this->mappingRuleData['defaultValue'] != null) {
$currency = Currency::getById(intval($this->mappingRuleData['defaultValue']));
if ($currency != null) {
return $currency;
}
}
}
示例6: testEditAnAccountUserAfterTheCustomDateFieldNullValueBugForAccountsModule
public function testEditAnAccountUserAfterTheCustomDateFieldNullValueBugForAccountsModule()
{
$super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
$baseCurrency = Currency::getByCode(Yii::app()->currencyHelper->getBaseCode());
$account = Account::getByName('myNewAccount');
$accountId = $account[0]->id;
//Edit and save the account.
$this->setGetArray(array('id' => $accountId));
$this->setPostArray(array('Account' => array('name' => 'myNewAccount', 'officePhone' => '259-784-2169', 'industry' => array('value' => 'Automotive'), 'officeFax' => '299-845-7863', 'employees' => '930', 'annualRevenue' => '474000000', 'type' => array('value' => 'Prospect'), 'website' => 'http://www.Unnamed.com', 'primaryEmail' => array('emailAddress' => 'info@myNewAccount.com', 'optOut' => '1', 'isInvalid' => '0'), 'secondaryEmail' => array('emailAddress' => '', 'optOut' => '0', 'isInvalid' => '0'), 'billingAddress' => array('street1' => '6466 South Madison Creek', 'street2' => '', 'city' => 'Chicago', 'state' => 'IL', 'postalCode' => '60652', 'country' => 'USA'), 'shippingAddress' => array('street1' => '27054 West Michigan Lane', 'street2' => '', 'city' => 'Austin', 'state' => 'TX', 'postalCode' => '78759', 'country' => 'USA'), 'description' => 'This is a Description', 'explicitReadWriteModelPermissions' => array('type' => null), 'datenotreqCstm' => '')));
//setting null value
$this->runControllerWithRedirectExceptionAndGetUrl('accounts/default/edit');
//Check the details if they are saved properly for the custom fields.
$account = Account::getByName('myNewAccount');
//Retrieve the permission for the account.
$explicitReadWriteModelPermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem(Account::getById($account[0]->id));
$readWritePermitables = $explicitReadWriteModelPermissions->getReadWritePermitables();
$readOnlyPermitables = $explicitReadWriteModelPermissions->getReadOnlyPermitables();
$this->assertEquals(1, count($account));
$this->assertEquals($account[0]->name, 'myNewAccount');
$this->assertEquals($account[0]->officePhone, '259-784-2169');
$this->assertEquals($account[0]->industry->value, 'Automotive');
$this->assertEquals($account[0]->officeFax, '299-845-7863');
$this->assertEquals($account[0]->employees, '930');
$this->assertEquals($account[0]->annualRevenue, '474000000');
$this->assertEquals($account[0]->type->value, 'Prospect');
$this->assertEquals($account[0]->website, 'http://www.Unnamed.com');
$this->assertEquals($account[0]->primaryEmail->emailAddress, 'info@myNewAccount.com');
$this->assertEquals($account[0]->primaryEmail->optOut, '1');
$this->assertEquals($account[0]->primaryEmail->isInvalid, '0');
$this->assertEquals($account[0]->secondaryEmail->emailAddress, '');
$this->assertEquals($account[0]->secondaryEmail->optOut, '0');
$this->assertEquals($account[0]->secondaryEmail->isInvalid, '0');
$this->assertEquals($account[0]->billingAddress->street1, '6466 South Madison Creek');
$this->assertEquals($account[0]->billingAddress->street2, '');
$this->assertEquals($account[0]->billingAddress->city, 'Chicago');
$this->assertEquals($account[0]->billingAddress->state, 'IL');
$this->assertEquals($account[0]->billingAddress->postalCode, '60652');
$this->assertEquals($account[0]->billingAddress->country, 'USA');
$this->assertEquals($account[0]->shippingAddress->street1, '27054 West Michigan Lane');
$this->assertEquals($account[0]->shippingAddress->street2, '');
$this->assertEquals($account[0]->shippingAddress->city, 'Austin');
$this->assertEquals($account[0]->shippingAddress->state, 'TX');
$this->assertEquals($account[0]->shippingAddress->postalCode, '78759');
$this->assertEquals($account[0]->shippingAddress->country, 'USA');
$this->assertEquals($account[0]->description, 'This is a Description');
$this->assertEquals(0, count($readWritePermitables));
$this->assertEquals(0, count($readOnlyPermitables));
$this->assertEquals($account[0]->datenotreqCstm, null);
}
开发者ID:RamaKavanan,项目名称:InitialVersion,代码行数:49,代码来源:AccountsSuperUserCustomDateNullValueBugWalkthroughTest.php
示例7: testSimpleUserImportWhereAllRowsSucceed
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('a@a.com', $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('b@b.com', $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('c@c.com', $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'.
//.........这里部分代码省略.........
示例8: testCopy
public function testCopy()
{
Yii::app()->user->userModel = User::getByUsername('sally');
$currencyValue = new CurrencyValue();
$currencyValue->value = 100;
$currencyValue->currency = Currency::getByCode('EUR');
$testItem = new ModelToArrayAdapterTestItem();
$testItem->firstName = 'Bob';
$testItem->lastName = 'Bobson';
$testItem->boolean = true;
$testItem->date = '2002-04-03';
$testItem->dateTime = '2002-04-03 02:00:43';
$testItem->float = 54.22;
$testItem->integer = 10;
$testItem->phone = '21313213';
$testItem->string = 'aString';
$testItem->textArea = 'Some Text Area';
$testItem->url = 'http://www.asite.com';
$testItem->primaryEmail->emailAddress = 'bob.bobson@something.com';
$testItem->primaryAddress->street1 = 'some street';
$testItem->owner = Yii::app()->user->userModel;
$testItem->currencyValue = $currencyValue;
$customFieldValue = new CustomFieldValue();
$customFieldValue->value = 'Multi 1';
$testItem->multiDropDown->values->add($customFieldValue);
$customFieldValue = new CustomFieldValue();
$customFieldValue->value = 'Multi 3';
$testItem->multiDropDown->values->add($customFieldValue);
$customFieldValue = new CustomFieldValue();
$customFieldValue->value = 'Cloud 2';
$testItem->tagCloud->values->add($customFieldValue);
$customFieldValue = new CustomFieldValue();
$customFieldValue->value = 'Cloud 3';
$testItem->tagCloud->values->add($customFieldValue);
$testItem->dropDown->value = 'Sample';
$testItem2 = new ModelToArrayAdapterTestItem2();
$testItem2->name = 'John';
$this->assertTrue($testItem2->save());
$testItem4 = new ModelToArrayAdapterTestItem4();
$testItem4->name = 'John';
$this->assertTrue($testItem4->save());
//HAS_MANY and MANY_MANY relationships should be ignored.
$testItem3_1 = new ModelToArrayAdapterTestItem3();
$testItem3_1->name = 'Kevin';
$this->assertTrue($testItem3_1->save());
$testItem3_2 = new ModelToArrayAdapterTestItem3();
$testItem3_2->name = 'Jim';
$this->assertTrue($testItem3_2->save());
$testItem->hasOne = $testItem2;
$testItem->hasMany->add($testItem3_1);
$testItem->hasMany->add($testItem3_2);
$testItem->hasOneAlso = $testItem4;
$this->assertTrue($testItem->save());
$testItem->addPermissions(self::$groupA, Permission::READ_WRITE_CHANGE_PERMISSIONS_CHANGE_OWNER);
$this->assertTrue($testItem->save());
$id = $testItem->id;
$testItem->forget();
unset($testItem);
//Switch to super and copy the model
Yii::app()->user->userModel = User::getByUsername('super');
$testItem = ModelToArrayAdapterTestItem::getById($id);
$copyToItem = new ModelToArrayAdapterTestItem();
ZurmoCopyModelUtil::copy($testItem, $copyToItem);
$this->assertEquals('Bob', $copyToItem->firstName);
$this->assertEquals('Bobson', $copyToItem->lastName);
$this->assertEquals(true, $copyToItem->boolean);
$this->assertEquals('2002-04-03', $copyToItem->date);
$this->assertEquals('2002-04-03 02:00:43', $copyToItem->dateTime);
$this->assertEquals(54.22, $copyToItem->float);
$this->assertEquals(10, $copyToItem->integer);
$this->assertEquals('21313213', $copyToItem->phone);
$this->assertEquals('aString', $copyToItem->string);
$this->assertEquals('Some Text Area', $copyToItem->textArea);
$this->assertEquals('http://www.asite.com', $copyToItem->url);
$this->assertEquals('bob.bobson@something.com', $copyToItem->primaryEmail->emailAddress);
$this->assertEquals('some street', $copyToItem->primaryAddress->street1);
$this->assertEquals('Sample', $copyToItem->dropDown->value);
$this->assertEquals(2, $copyToItem->multiDropDown->values->count());
$this->assertTrue($copyToItem->multiDropDown->values[0] == 'Multi 1' || $copyToItem->multiDropDown->values[0] == 'Multi 3');
$this->assertEquals(2, $copyToItem->tagCloud->values->count());
$this->assertTrue($copyToItem->tagCloud->values[0] == 'Cloud 2' || $copyToItem->tagCloud->values[0] == 'Cloud 3');
$this->assertEquals(100, $copyToItem->currencyValue->value);
$this->assertEquals(2, $copyToItem->currencyValue->rateToBase);
$this->assertEquals('EUR', $copyToItem->currencyValue->currency->code);
$this->assertTrue($copyToItem->owner->isSame(self::$sally));
$this->assertTrue($copyToItem->createdByUser->id < 0);
$this->assertEquals(Yii::app()->user->userModel->id, $copyToItem->modifiedByUser->id);
$this->assertEquals(0, $copyToItem->hasMany->count());
$this->assertTrue($copyToItem->hasOne->isSame($testItem2));
$this->assertTrue($copyToItem->hasOneAlso->isSame($testItem4));
$explicitReadWriteModelPermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem($copyToItem);
$permitables = $explicitReadWriteModelPermissions->getReadWritePermitables();
$this->assertEquals(1, count($permitables));
$this->assertEquals('AAA', $permitables[self::$groupA->getClassId('Permitable')]->name);
}
示例9: testWhetherSearchWorksForTheCustomFieldsPlacedForOpportunitiesModuleAfterDeletingTheOpportunity
/**
* @depends testDeleteOfTheOpportunityUserForTheCustomFieldsPlacedForOpportunitiesModule
*/
public function testWhetherSearchWorksForTheCustomFieldsPlacedForOpportunitiesModuleAfterDeletingTheOpportunity()
{
$super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
//Retrieve the account id, the super user id and opportunity Id.
$accountId = self::getModelIdByModelNameAndName('Account', 'superAccount');
$superUserId = $super->id;
$baseCurrency = Currency::getByCode(Yii::app()->currencyHelper->getBaseCode());
//Search a created Opportunity using the customfields.
$this->resetPostArray();
$this->setGetArray(array('OpportunitiesSearchForm' => OpportunitiesDesignerWalkthroughHelperUtil::fetchOpportunitiesSearchFormGetData($accountId, $superUserId, $baseCurrency->id), 'ajax' => 'list-view'));
$content = $this->runControllerWithNoExceptionsAndGetContent('opportunities/default');
//Assert that the edit Opportunity does not exits after the search.
$this->assertContains("No results found", $content);
}
开发者ID:KulturedKitsch,项目名称:kulturedkitsch.info,代码行数:17,代码来源:OpportunitiesDesignerSuperUserWalkthroughTest.php
示例10: testResolveUpdateRelatedActionWithStaticValues
/**
* @depends testResolveUpdateActionWithDynamicValues
*/
public function testResolveUpdateRelatedActionWithStaticValues()
{
$contactStates = ContactState::getAll();
$this->assertTrue($contactStates[0]->id > 0);
$contactState = $contactStates[0];
$currency = Currency::getByCode('USD');
$bobby = User::getByUsername('bobby');
$workflow = new Workflow();
$workflow->setType(Workflow::TYPE_ON_SAVE);
$workflow->setModuleClassName('WorkflowsTest2Module');
$data = array();
$data[ComponentForWorkflowForm::TYPE_ACTIONS][0]['type'] = ActionForWorkflowForm::TYPE_UPDATE_RELATED;
$data[ComponentForWorkflowForm::TYPE_ACTIONS][0]['relation'] = 'hasMany2';
$data[ComponentForWorkflowForm::TYPE_ACTIONS][0][ActionForWorkflowForm::ACTION_ATTRIBUTES] = array('boolean' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => '1'), 'boolean2' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => '0'), 'currencyValue' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => '362.24', 'currencyId' => $currency->id), 'date' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => '2/24/2012'), 'dateTime' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => '2/24/2012 03:00 AM'), 'dropDown' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => 'Value 1'), 'float' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => '54.25'), 'integer' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => '32'), 'likeContactState' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => $contactState->id), 'multiDropDown' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => array('Multi Value 1', 'Multi Value 2')), 'owner' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => $bobby->id), 'phone' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => '8471112222'), 'primaryAddress___street1' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => '123 Main Street'), 'primaryEmail___emailAddress' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => 'info@zurmo.com'), 'radioDropDown' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => 'Radio Value 1'), 'string' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => 'jason'), 'tagCloud' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => array('Tag Value 1', 'Tag Value 2')), 'textArea' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => 'some description'), 'url' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => 'http://www.zurmo.com'));
DataToWorkflowUtil::resolveActions($data, $workflow);
$actions = $workflow->getActions();
$this->assertCount(1, $actions);
$this->assertEquals(ActionForWorkflowForm::TYPE_UPDATE_RELATED, $actions[0]->type);
$this->assertEquals('hasMany2', $actions[0]->relation);
$this->assertEquals(ActionForWorkflowForm::RELATION_FILTER_ALL, $actions[0]->relationFilter);
$this->assertEquals(19, $actions[0]->getActionAttributeFormsCount());
$this->assertTrue($actions[0]->getActionAttributeFormByName('boolean') instanceof CheckBoxWorkflowActionAttributeForm);
$this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('boolean')->type);
$this->assertEquals('1', $actions[0]->getActionAttributeFormByName('boolean')->value);
$this->assertTrue($actions[0]->getActionAttributeFormByName('boolean2') instanceof CheckBoxWorkflowActionAttributeForm);
$this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('boolean2')->type);
$this->assertEquals('0', $actions[0]->getActionAttributeFormByName('boolean2')->value);
$this->assertTrue($actions[0]->getActionAttributeFormByName('currencyValue') instanceof CurrencyValueWorkflowActionAttributeForm);
$this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('currencyValue')->type);
$this->assertEquals(362.24, $actions[0]->getActionAttributeFormByName('currencyValue')->value);
$this->assertEquals($currency->id, $actions[0]->getActionAttributeFormByName('currencyValue')->currencyId);
$this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('currencyValue')->currencyIdType);
$this->assertTrue($actions[0]->getActionAttributeFormByName('date') instanceof DateWorkflowActionAttributeForm);
$this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('date')->type);
$this->assertEquals('2012-02-24', $actions[0]->getActionAttributeFormByName('date')->value);
$this->assertTrue($actions[0]->getActionAttributeFormByName('dateTime') instanceof DateTimeWorkflowActionAttributeForm);
$this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('dateTime')->type);
$compareDateTime = DateTimeUtil::convertDateTimeLocaleFormattedDisplayToDbFormattedDateTimeWithSecondsAsZero('2/24/2012 03:00 AM');
$this->assertEquals($compareDateTime, $actions[0]->getActionAttributeFormByName('dateTime')->value);
$this->assertTrue($actions[0]->getActionAttributeFormByName('dropDown') instanceof DropDownWorkflowActionAttributeForm);
$this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('dropDown')->type);
$this->assertEquals('Value 1', $actions[0]->getActionAttributeFormByName('dropDown')->value);
$this->assertTrue($actions[0]->getActionAttributeFormByName('float') instanceof DecimalWorkflowActionAttributeForm);
$this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('float')->type);
$this->assertEquals('54.25', $actions[0]->getActionAttributeFormByName('float')->value);
$this->assertTrue($actions[0]->getActionAttributeFormByName('integer') instanceof IntegerWorkflowActionAttributeForm);
$this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('integer')->type);
$this->assertEquals('32', $actions[0]->getActionAttributeFormByName('integer')->value);
$this->assertTrue($actions[0]->getActionAttributeFormByName('likeContactState') instanceof ContactStateWorkflowActionAttributeForm);
$this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('likeContactState')->type);
$this->assertEquals($contactState->id, $actions[0]->getActionAttributeFormByName('likeContactState')->value);
$this->assertTrue($actions[0]->getActionAttributeFormByName('multiDropDown') instanceof MultiSelectDropDownWorkflowActionAttributeForm);
$this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('multiDropDown')->type);
$this->assertEquals(array('Multi Value 1', 'Multi Value 2'), $actions[0]->getActionAttributeFormByName('multiDropDown')->value);
$this->assertTrue($actions[0]->getActionAttributeFormByName('owner') instanceof UserWorkflowActionAttributeForm);
$this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('owner')->type);
$this->assertEquals($bobby->id, $actions[0]->getActionAttributeFormByName('owner')->value);
$this->assertTrue($actions[0]->getActionAttributeFormByName('phone') instanceof PhoneWorkflowActionAttributeForm);
$this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('phone')->type);
$this->assertEquals('8471112222', $actions[0]->getActionAttributeFormByName('phone')->value);
$this->assertTrue($actions[0]->getActionAttributeFormByName('primaryAddress___street1') instanceof TextWorkflowActionAttributeForm);
$this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('primaryAddress___street1')->type);
$this->assertEquals('123 Main Street', $actions[0]->getActionAttributeFormByName('primaryAddress___street1')->value);
$this->assertTrue($actions[0]->getActionAttributeFormByName('primaryEmail___emailAddress') instanceof EmailWorkflowActionAttributeForm);
$this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('primaryEmail___emailAddress')->type);
$this->assertEquals('info@zurmo.com', $actions[0]->getActionAttributeFormByName('primaryEmail___emailAddress')->value);
$this->assertTrue($actions[0]->getActionAttributeFormByName('radioDropDown') instanceof RadioDropDownWorkflowActionAttributeForm);
$this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('radioDropDown')->type);
$this->assertEquals('Radio Value 1', $actions[0]->getActionAttributeFormByName('radioDropDown')->value);
$this->assertTrue($actions[0]->getActionAttributeFormByName('string') instanceof TextWorkflowActionAttributeForm);
$this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('string')->type);
$this->assertEquals('jason', $actions[0]->getActionAttributeFormByName('string')->value);
$this->assertTrue($actions[0]->getActionAttributeFormByName('tagCloud') instanceof TagCloudWorkflowActionAttributeForm);
$this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('tagCloud')->type);
$this->assertEquals(array('Tag Value 1', 'Tag Value 2'), $actions[0]->getActionAttributeFormByName('tagCloud')->value);
$this->assertTrue($actions[0]->getActionAttributeFormByName('textArea') instanceof TextAreaWorkflowActionAttributeForm);
$this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('textArea')->type);
$this->assertEquals('some description', $actions[0]->getActionAttributeFormByName('textArea')->value);
$this->assertTrue($actions[0]->getActionAttributeFormByName('url') instanceof UrlWorkflowActionAttributeForm);
$this->assertEquals('Static', $actions[0]->getActionAttributeFormByName('url')->type);
$this->assertEquals('http://www.zurmo.com', $actions[0]->getActionAttributeFormByName('url')->value);
}
示例11: testSuperUserCreateAction
public function testSuperUserCreateAction()
{
$super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
Yii::app()->user->userModel = $super;
$this->resetGetArray();
$currency = new Currency();
$currency->code = 'USD';
$currency->rateToBase = 1;
$currency->save();
$currencyRec = Currency::getByCode('USD');
$currencyValue1Array = array('currency' => array('id' => $currencyRec->id), 'value' => 500.54);
$currencyValue2Array = array('currency' => array('id' => $currencyRec->id), 'value' => 400.54);
$currencyValue3Array = array('currency' => array('id' => $currencyRec->id), 'value' => 300.54);
$productTemplate = array();
$productTemplate['name'] = 'Red Widget';
$productTemplate['description'] = 'Description';
$productTemplate['priceFrequency'] = ProductTemplate::PRICE_FREQUENCY_ONE_TIME;
$productTemplate['cost'] = $currencyValue1Array;
$productTemplate['listPrice'] = $currencyValue2Array;
$productTemplate['sellPrice'] = $currencyValue3Array;
$productTemplate['type'] = ProductTemplate::TYPE_PRODUCT;
$productTemplate['status'] = ProductTemplate::STATUS_ACTIVE;
$sellPriceFormulaArray = array('type' => SellPriceFormula::TYPE_DISCOUNT_FROM_LIST, 'discountOrMarkupPercentage' => 10);
$productTemplate['sellPriceFormula'] = $sellPriceFormulaArray;
$this->setPostArray(array('ProductTemplate' => $productTemplate));
$redirectUrl = $this->runControllerWithRedirectExceptionAndGetUrl('productTemplates/default/create');
$productTemplates = ProductTemplate::getByName('Red Widget');
$this->assertEquals(1, count($productTemplates));
$this->assertTrue($productTemplates[0]->id > 0);
$this->assertEquals(400.54, $productTemplates[0]->listPrice->value);
$this->assertEquals(500.54, $productTemplates[0]->cost->value);
$this->assertEquals(300.54, $productTemplates[0]->sellPrice->value);
$compareRedirectUrl = Yii::app()->createUrl('productTemplates/default/details', array('id' => $productTemplates[0]->id));
$this->assertEquals($compareRedirectUrl, $redirectUrl);
}
示例12: testGetActiveCurrencyForCurrentUser
/**
* @depends testGetActiveCurrenciesOrSelectedCurrenciesData
*/
public function testGetActiveCurrencyForCurrentUser()
{
$super = User::getByUsername('super');
Yii::app()->user->userModel = $super;
$activeCurrency = Yii::app()->currencyHelper->getActiveCurrencyForCurrentUser();
$usdCurrency = Currency::getByCode('USD');
$this->assertTrue($activeCurrency->isSame($usdCurrency));
$eurCurrency = Currency::getByCode('EUR');
$super->currency = $eurCurrency;
$this->assertTrue($super->save());
$activeCurrency = Yii::app()->currencyHelper->getActiveCurrencyForCurrentUser();
$this->assertTrue($activeCurrency->isSame($eurCurrency));
$super->currency = null;
$this->assertTrue($super->save());
$activeCurrency = Yii::app()->currencyHelper->getActiveCurrencyForCurrentUser();
$this->assertTrue($activeCurrency->isSame($usdCurrency));
}
示例13: testImportWithRateAndCurrencyCodeSpecified
/**
* There is a special way you can import rateToBase and currencyCode for an amount attribute.
* if the column data is formatted like: $54.67__1.2__USD then it will split the column and properly
* handle rate and currency code. Eventually this will be exposed in the user interface
*/
public function testImportWithRateAndCurrencyCodeSpecified()
{
Yii::app()->user->userModel = User::getByUsername('super');
$account = AccountTestHelper::createAccountByNameForOwner('Account', Yii::app()->user->userModel);
$accountId = $account->id;
$contracts = Contract::getAll();
$this->assertEquals(0, count($contracts));
$import = new Import();
$serializedData['importRulesType'] = 'Contracts';
$serializedData['firstRowIsHeaderRow'] = true;
$import->serializedData = serialize($serializedData);
$this->assertTrue($import->save());
ImportTestHelper::createTempTableByFileNameAndTableName('importTestIncludingRateAndCurrencyCode.csv', $import->getTempTableName(), true, Yii::getPathOfAlias('application.modules.contracts.tests.unit.files'));
//update the ids of the account column to match the parent account.
ZurmoRedBean::exec("update " . $import->getTempTableName() . " set column_3 = " . $account->id . " where id != 1 limit 4");
$this->assertEquals(4, ImportDatabaseUtil::getCount($import->getTempTableName()));
// includes header rows.
$currency = Currency::getByCode(Yii::app()->currencyHelper->getBaseCode());
$mappingData = array('column_0' => ImportMappingUtil::makeStringColumnMappingData('name'), 'column_1' => ImportMappingUtil::makeDateColumnMappingData('closeDate'), 'column_2' => ImportMappingUtil::makeIntegerColumnMappingData('description'), 'column_3' => ImportMappingUtil::makeHasOneColumnMappingData('account'), 'column_4' => ImportMappingUtil::makeDropDownColumnMappingData('stage'), 'column_5' => ImportMappingUtil::makeDropDownColumnMappingData('source'), 'column_6' => ImportMappingUtil::makeCurrencyColumnMappingData('amount', $currency));
$importRules = ImportRulesUtil::makeImportRulesByType('Contracts');
$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.
$contracts = Contract::getAll();
$this->assertEquals(3, count($contracts));
$contracts = Contract::getByName('opp1');
$this->assertEquals(1, count($contracts[0]));
$this->assertEquals('opp1', $contracts[0]->name);
$this->assertEquals('1980-06-03', $contracts[0]->closeDate);
$this->assertEquals(10, $contracts[0]->probability);
$this->assertEquals('desc1', $contracts[0]->description);
$this->assertTrue($contracts[0]->account->isSame($account));
$this->assertEquals('Prospecting', $contracts[0]->stage->value);
$this->assertEquals('Self-Generated', $contracts[0]->source->value);
$this->assertEquals(500, $contracts[0]->amount->value);
$this->assertEquals(1, $contracts[0]->amount->rateToBase);
$this->assertEquals('USD', $contracts[0]->amount->currency->code);
$contracts = Contract::getByName('opp2');
$this->assertEquals(1, count($contracts[0]));
$this->assertEquals('opp2', $contracts[0]->name);
$this->assertEquals('1980-06-04', $contracts[0]->closeDate);
$this->assertEquals(25, $contracts[0]->probability);
$this->assertEquals('desc2', $contracts[0]->description);
$this->assertTrue($contracts[0]->account->isSame($account));
$this->assertEquals('Qualification', $contracts[0]->stage->value);
$this->assertEquals('Inbound Call', $contracts[0]->source->value);
$this->assertEquals(501, $contracts[0]->amount->value);
// $this->assertEquals(2.7, $contracts[0]->amount->rateToBase);
$this->assertEquals('GBP', $contracts[0]->amount->currency->code);
$contracts = Contract::getByName('opp3');
$this->assertEquals(1, count($contracts[0]));
$this->assertEquals('opp3', $contracts[0]->name);
$this->assertEquals('1980-06-05', $contracts[0]->closeDate);
$this->assertEquals(50, $contracts[0]->probability);
$this->assertEquals('desc3', $contracts[0]->description);
$this->assertTrue($contracts[0]->account->isSame($account));
$this->assertEquals('Negotiating', $contracts[0]->stage->value);
$this->assertEquals('Tradeshow', $contracts[0]->source->value);
$this->assertEquals(502, $contracts[0]->amount->value);
// $this->assertEquals(3.2, $contracts[0]->amount->rateToBase);
$this->assertEquals('EUR', $contracts[0]->amount->currency->code);
//Confirm 10 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 2 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));
//test the account has 3 contracts
$account->forget();
$account = Account::getById($accountId);
$this->assertEquals(3, $account->contracts->count());
}
示例14: testSuperUserCreateAction
public function testSuperUserCreateAction()
{
$super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
Yii::app()->user->userModel = $super;
$this->resetGetArray();
$currency = new Currency();
$currency->code = 'USD';
$currency->rateToBase = 1;
$currency->save();
$currencyRec = Currency::getByCode('USD');
$currencyValue1Array = array('currency' => array('id' => $currencyRec->id), 'value' => 500.54);
ProductTemplateTestHelper::createProductTemplateByName("My Catalog Item 1");
$productTemplate = ProductTemplate::getByName('My Catalog Item 1');
$product = array();
$product['name'] = 'Red Widget';
$product['quantity'] = 5;
$product['priceFrequency'] = ProductTemplate::PRICE_FREQUENCY_ONE_TIME;
$product['sellPrice'] = $currencyValue1Array;
$product['type'] = ProductTemplate::TYPE_PRODUCT;
$product['stage']['value'] = Product::OPEN_STAGE;
$product['productTemplate'] = array('id' => $productTemplate[0]->id);
$this->setPostArray(array('Product' => $product, 'Product_owner_name' => 'Super User'));
$redirectUrl = $this->runControllerWithRedirectExceptionAndGetUrl('products/default/create');
$products = Product::getByName('Red Widget');
$this->assertEquals(1, count($products));
$this->assertTrue($products[0]->id > 0);
$this->assertEquals(500.54, $products[0]->sellPrice->value);
$compareRedirectUrl = Yii::app()->createUrl('products/default/details', array('id' => $products[0]->id));
$this->assertEquals($compareRedirectUrl, $redirectUrl);
}
示例15: testEditOfTheLeadUserForTheCustomFieldsPlacedForLeadsModule
/**
* @depends testEditOfTheLeadUserForTheTagCloudFieldAfterRemovingAllTagsPlacedForLeadsModule
*/
public function testEditOfTheLeadUserForTheCustomFieldsPlacedForLeadsModule()
{
$super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
//Retrieve the the super user id.
$superUserId = $super->id;
//Retrieve the lead id.
$leadId = self::getModelIdByModelNameAndName('Contact', 'Sarah Williams Edit');
//Set the date and datetime variable values here.
$date = Yii::app()->dateFormatter->format(DateTimeUtil::getLocaleDateFormatForInput(), time());
$dateAssert = date('Y-m-d');
$datetime = Yii::app()->dateFormatter->format(DateTimeUtil::getLocaleDateTimeFormatForInput(), time());
$datetimeAssert = date('Y-m-d H:i:') . "00";
$baseCurrency = Currency::getByCode(Yii::app()->currencyHelper->getBaseCode());
//Retrieve the Lead State (Status) Id based on the name.
$leadState = ContactState::getByName('In Progress');
$leadStateId = $leadState[0]->id;
$explicitReadWriteModelPermission = ExplicitReadWriteModelPermissionsUtil::MIXED_TYPE_EVERYONE_GROUP;
//Edit and save the lead.
$this->setGetArray(array('id' => $leadId));
$this->setPostArray(array('Contact' => array('title' => array('value' => 'Mrs.'), 'firstName' => 'Sarah', 'lastName' => 'Williams Edit', 'jobTitle' => 'Sales Director Edit', 'companyName' => 'ABC Telecom Edit', 'industry' => array('value' => 'Banking'), 'website' => 'http://www.companyedit.com', 'department' => 'Sales Edit', 'officePhone' => '739-742-3005', 'source' => array('value' => 'Inbound Call'), 'mobilePhone' => '285-300-8232', 'officeFax' => '255-454-1914', 'state' => array('id' => $leadStateId), 'owner' => array('id' => $superUserId), 'primaryEmail' => array('emailAddress' => 'info@myNewLead.com', 'optOut' => '0', 'isInvalid' => '0'), 'secondaryEmail' => array('emailAddress' => 'info@myNewLeadEdit.com', 'optOut' => '0', 'isInvalid' => '0'), 'primaryAddress' => array('street1' => '26378 South Arlington Ave', 'street2' => '', 'city' => 'San Jose', 'state' => 'CA', 'postalCode' => '95131', 'country' => 'USA'), 'secondaryAddress' => array('street1' => '1652 North Cedar Court', 'street2' => '', 'city' => 'Phoenix', 'state' => 'AZ', 'postalCode' => '85003', 'country' => 'USA'), 'explicitReadWriteModelPermissions' => array('type' => $explicitReadWriteModelPermission), 'description' => 'This is a Edit Description', 'checkboxCstm' => '0', 'currencyCstm' => array('value' => 40, 'currency' => array('id' => $baseCurrency->id)), 'dateCstm' => $date, 'datetimeCstm' => $datetime, 'decimalCstm' => '12', 'picklistCstm' => array('value' => 'b'), 'multiselectCstm' => array('values' => array('gg', 'hh')), 'tagcloudCstm' => array('values' => array('reading', 'surfing')), 'countrylistCstm' => array('value' => 'aaaa'), 'statelistCstm' => array('value' => 'aaa1'), 'citylistCstm' => array('value' => 'ab1'), 'integerCstm' => '11', 'phoneCstm' => '259-784-2069', 'radioCstm' => array('value' => 'e'), 'textCstm' => 'This is a test Edit Text', 'textareaCstm' => 'This is a test Edit TextArea', 'urlCstm' => 'http://wwww.abc-edit.com'), 'save' => 'Save'));
$this->runControllerWithRedirectExceptionAndGetUrl('leads/default/edit');
//Check the details if they are saved properly for the custom fields after the edit.
$lead = Contact::getById($leadId);
//Retrieve the permission of the lead.
$explicitReadWriteModelPermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem($lead);
$readWritePermitables = $explicitReadWriteModelPermissions->getReadWritePermitables();
$readOnlyPermitables = $explicitReadWriteModelPermissions->getReadOnlyPermitables();
$this->assertEquals($lead->title->value, 'Mrs.');
$this->assertEquals($lead->firstName, 'Sarah');
$this->assertEquals($lead->lastName, 'Williams Edit');
$this->assertEquals($lead->state->id, $leadStateId);
$this->assertEquals($lead->jobTitle, 'Sales Director Edit');
$this->assertEquals($lead->companyName, 'ABC Telecom Edit');
$this->assertEquals($lead->industry->value, 'Banking');
$this->assertEquals($lead->website, 'http://www.companyedit.com');
$this->assertEquals($lead->department, 'Sales Edit');
$this->assertEquals($lead->officePhone, '739-742-3005');
$this->assertEquals($lead->source->value, 'Inbound Call');
$this->assertEquals($lead->mobilePhone, '285-300-8232');
$this->assertEquals($lead->officeFax, '255-454-1914');
$this->assertEquals($lead->primaryEmail->emailAddress, 'info@myNewLead.com');
$this->assertEquals($lead->primaryEmail->optOut, '0');
$this->assertEquals($lead->primaryEmail->isInvalid, '0');
$this->assertEquals($lead->secondaryEmail->emailAddress, 'info@myNewLeadEdit.com');
$this->assertEquals($lead->secondaryEmail->optOut, '0');
$this->assertEquals($lead->secondaryEmail->isInvalid, '0');
$this->assertEquals($lead->primaryAddress->street1, '26378 South Arlington Ave');
$this->assertEquals($lead->primaryAddress->street2, '');
$this->assertEquals($lead->primaryAddress->city, 'San Jose');
$this->assertEquals($lead->primaryAddress->state, 'CA');
$this->assertEquals($lead->primaryAddress->postalCode, '95131');
$this->assertEquals($lead->primaryAddress->country, 'USA');
$this->assertEquals($lead->secondaryAddress->street1, '1652 North Cedar Court');
$this->assertEquals($lead->secondaryAddress->street2, '');
$this->assertEquals($lead->secondaryAddress->city, 'Phoenix');
$this->assertEquals($lead->secondaryAddress->state, 'AZ');
$this->assertEquals($lead->secondaryAddress->postalCode, '85003');
$this->assertEquals($lead->secondaryAddress->country, 'USA');
$this->assertEquals(1, count($readWritePermitables));
$this->assertEquals(0, count($readOnlyPermitables));
$this->assertEquals($lead->description, 'This is a Edit Description');
$this->assertEquals($lead->checkboxCstm, '0');
$this->assertEquals($lead->currencyCstm->value, 40);
$this->assertEquals($lead->currencyCstm->currency->id, $baseCurrency->id);
$this->assertEquals($lead->dateCstm, $dateAssert);
$this->assertEquals($lead->datetimeCstm, $datetimeAssert);
$this->assertEquals($lead->decimalCstm, '12');
$this->assertEquals($lead->picklistCstm->value, 'b');
$this->assertEquals($lead->integerCstm, 11);
$this->assertEquals($lead->phoneCstm, '259-784-2069');
$this->assertEquals($lead->radioCstm->value, 'e');
$this->assertEquals($lead->textCstm, 'This is a test Edit Text');
$this->assertEquals($lead->textareaCstm, 'This is a test Edit TextArea');
$this->assertEquals($lead->urlCstm, 'http://wwww.abc-edit.com');
$this->assertEquals($lead->countrylistCstm->value, 'aaaa');
$this->assertEquals($lead->statelistCstm->value, 'aaa1');
$this->assertEquals($lead->citylistCstm->value, 'ab1');
$this->assertContains('gg', $lead->multiselectCstm->values);
$this->assertContains('hh', $lead->multiselectCstm->values);
$this->assertContains('reading', $lead->tagcloudCstm->values);
$this->assertContains('surfing', $lead->tagcloudCstm->values);
$metadata = CalculatedDerivedAttributeMetadata::getByNameAndModelClassName('calcnumber', 'Contact');
$testCalculatedValue = CalculatedNumberUtil::calculateByFormulaAndModelAndResolveFormat($metadata->getFormula(), $lead);
$this->assertEquals(23, $testCalculatedValue);
}