public static function resolveValue($attribute, ReportResultsRowData $data) { list($notUsed, $displayAttributeKey) = explode(ReportResultsRowData::ATTRIBUTE_NAME_PREFIX, $attribute); $displayAttributes = $data->getDisplayAttributes(); $metadata = CalculatedDerivedAttributeMetadata::getByNameAndModelClassName($displayAttributes[$displayAttributeKey]->getResolvedAttribute(), $displayAttributes[$displayAttributeKey]->getResolvedAttributeModelClassName()); return CalculatedNumberUtil::calculateByFormulaAndModelAndResolveFormat($metadata->getFormula(), $data->getModel($attribute)); }
/** * @depends testEditOfTheNoteForTheTagCloudFieldAfterRemovingAllTagsPlacedForNotesModule */ public function testEditOfTheNoteForTheCustomFieldsPlacedForNotesModule() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); //Set the date and datetime variable values here. $date = Yii::app()->dateFormatter->format(DateTimeUtil::getLocaleDateFormat(), time()); $dateAssert = date('Y-m-d'); $datetime = Yii::app()->dateFormatter->format(DateTimeUtil::getLocaleDateTimeFormat(), time()); $datetimeAssert = date('Y-m-d H:i:') . "00"; //Get the super user, account, opportunity and contact id. $superUserId = $super->id; $superAccount = Account::getByName('superAccount'); $superContactId = self::getModelIdByModelNameAndName('Contact', 'superContact2 superContact2son'); $superOpportunityId = self::getModelIdByModelNameAndName('Opportunity', 'superOpp'); $baseCurrency = Currency::getByCode(Yii::app()->currencyHelper->getBaseCode()); $explicitReadWriteModelPermission = ExplicitReadWriteModelPermissionsUtil::MIXED_TYPE_EVERYONE_GROUP; //Retrieve the note Id based on the created note. $note = Note::getByName('Note Edit Description'); //Edit a note based on the custom fields. $this->setGetArray(array('id' => $note[0]->id)); $this->setPostArray(array('Note' => array('occurredOnDateTime' => $datetime, 'description' => 'Note Edit Description', 'explicitReadWriteModelPermissions' => array('type' => $explicitReadWriteModelPermission), 'owner' => array('id' => $superUserId), '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'), 'ActivityItemForm' => array('Account' => array('id' => $superAccount[0]->id), 'Contact' => array('id' => $superContactId), 'Opportunity' => array('id' => $superOpportunityId)))); $this->runControllerWithRedirectExceptionAndGetUrl('notes/default/edit'); //Check the details if they are saved properly for the custom fields. $note = Note::getByName('Note Edit Description'); //Retrieve the permission of the note. $explicitReadWriteModelPermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem(Note::getById($note[0]->id)); $readWritePermitables = $explicitReadWriteModelPermissions->getReadWritePermitables(); $readOnlyPermitables = $explicitReadWriteModelPermissions->getReadOnlyPermitables(); $this->assertEquals($note[0]->description, 'Note Edit Description'); $this->assertEquals($note[0]->occurredOnDateTime, $datetimeAssert); $this->assertEquals($note[0]->owner->id, $superUserId); $this->assertEquals($note[0]->activityItems->count(), 3); $this->assertEquals(1, count($readWritePermitables)); $this->assertEquals(0, count($readOnlyPermitables)); $this->assertEquals($note[0]->checkboxCstm, '0'); $this->assertEquals($note[0]->currencyCstm->value, 40); $this->assertEquals($note[0]->currencyCstm->currency->id, $baseCurrency->id); $this->assertEquals($note[0]->dateCstm, $dateAssert); $this->assertEquals($note[0]->datetimeCstm, $datetimeAssert); $this->assertEquals($note[0]->decimalCstm, '12'); $this->assertEquals($note[0]->picklistCstm->value, 'b'); $this->assertEquals($note[0]->integerCstm, 11); $this->assertEquals($note[0]->phoneCstm, '259-784-2069'); $this->assertEquals($note[0]->radioCstm->value, 'e'); $this->assertEquals($note[0]->textCstm, 'This is a test Edit Text'); $this->assertEquals($note[0]->textareaCstm, 'This is a test Edit TextArea'); $this->assertEquals($note[0]->urlCstm, 'http://wwww.abc-edit.com'); $this->assertEquals($note[0]->countrylistCstm->value, 'aaaa'); $this->assertEquals($note[0]->statelistCstm->value, 'aaa1'); $this->assertEquals($note[0]->citylistCstm->value, 'ab1'); $this->assertContains('gg', $note[0]->multiselectCstm->values); $this->assertContains('hh', $note[0]->multiselectCstm->values); $this->assertContains('reading', $note[0]->tagcloudCstm->values); $this->assertContains('surfing', $note[0]->tagcloudCstm->values); $metadata = CalculatedDerivedAttributeMetadata::getByNameAndModelClassName('calcnumber', 'Note'); $testCalculatedValue = CalculatedNumberUtil::calculateByFormulaAndModelAndResolveFormat($metadata->getFormula(), $note[0]); $this->assertEquals(23, $testCalculatedValue); }
/** * @depends testCreateDropDownWithMixedCaseAttributeName */ public function testPopulateCustomAttributes() { $currencies = Currency::getAll(); $account = new Account(); $account->name = 'my test account'; $account->owner = Yii::app()->user->userModel; $account->testCheckBox2Cstm = 0; $account->testCurrency2Cstm->value = 728.89; $account->testCurrency2Cstm->currency = $currencies[0]; $account->testDate2Cstm = '2008-09-03'; $account->testDate3Cstm = '2008-09-02'; $account->testDateTime2Cstm = '2008-09-02 03:03:03'; $account->testDateTime3Cstm = '2008-09-01 03:03:03'; $account->testDecimal2Cstm = 45.67; $account->testDecimal3Cstm = 31.05; $account->testAirPlaneCstm->value = 'A380'; //Dive Bomber $account->testInteger2Cstm = 56; $account->testInteger3Cstm = 21; $account->testPhone2Cstm = '345345234'; $account->testPhone3Cstm = '345345221'; $account->testAirPlanePartsCstm->value = 'Seat'; // Wheel $account->testText2Cstm = 'some test stuff'; $account->testText3Cstm = 'some test stuff 3'; $account->testTextArea2Cstm = 'some test text area stuff'; $account->testTextArea3Cstm = 'some test text area stuff 3'; $account->testUrl2Cstm = 'https://www.zurmo.com'; $account->testUrl3Cstm = 'www.zurmo.org'; $account->playMyFavoriteSongCstm->value = 'song2'; // song 3 $account->testCountryCstm->value = 'bbbb'; $account->testStateCstm->value = 'bbb2'; $account->testCityCstm->value = 'bc2'; $account->testEducationCstm->value = 'cccc'; $account->testStreamCstm->value = 'ccc3'; //Set value to Multiselect list. $customHobbyValue1 = new CustomFieldValue(); $customHobbyValue1->value = 'Reading'; $account->testHobbies1Cstm->values->add($customHobbyValue1); $customHobbyValue2 = new CustomFieldValue(); $customHobbyValue2->value = 'Singing'; $account->testHobbies2Cstm->values->add($customHobbyValue2); //Set value to Tagcloud. $customLanguageValue1 = new CustomFieldValue(); $customLanguageValue1->value = 'English'; $account->testLanguages1Cstm->values->add($customLanguageValue1); $customLanguageValue2 = new CustomFieldValue(); $customLanguageValue2->value = 'Spanish'; $account->testLanguages2Cstm->values->add($customLanguageValue2); unset($customHobbyValue1); unset($customHobbyValue2); unset($customLanguageValue1); unset($customLanguageValue2); $saved = $account->save(); $this->assertTrue($saved); $accountId = $account->id; $account->forget(); unset($account); $account = Account::getById($accountId); $this->assertEquals(0, $account->testCheckBox2Cstm); $this->assertEquals(false, (bool) $account->testCheckBox2Cstm); $this->assertEquals(728.89, $account->testCurrency2Cstm->value); $this->assertEquals(1, $account->testCurrency2Cstm->rateToBase); $this->assertEquals('2008-09-03', $account->testDate2Cstm); $this->assertEquals('2008-09-02 03:03:03', $account->testDateTime2Cstm); $this->assertEquals(45.67, $account->testDecimal2Cstm); $this->assertEquals('A380', $account->testAirPlaneCstm->value); $this->assertEquals(56, $account->testInteger2Cstm); $this->assertEquals(345345234, $account->testPhone2Cstm); $this->assertEquals('Seat', $account->testAirPlanePartsCstm->value); $this->assertEquals('some test stuff', $account->testText2Cstm); $this->assertEquals('some test text area stuff', $account->testTextArea2Cstm); $this->assertEquals('https://www.zurmo.com', $account->testUrl2Cstm); $this->assertEquals('http://www.zurmo.org', $account->testUrl3Cstm); $this->assertEquals('song2', $account->playMyFavoriteSongCstm->value); $this->assertContains('Writing', $account->testHobbies1Cstm->values); $this->assertContains('Reading', $account->testHobbies1Cstm->values); $this->assertContains('Singing', $account->testHobbies2Cstm->values); $this->assertContains('English', $account->testLanguages1Cstm->values); $this->assertContains('French', $account->testLanguages1Cstm->values); $this->assertContains('Spanish', $account->testLanguages2Cstm->values); $this->assertEquals('bbbb', $account->testCountryCstm->value); $this->assertEquals('bbb2', $account->testStateCstm->value); $this->assertEquals('bc2', $account->testCityCstm->value); $this->assertEquals('cccc', $account->testEducationCstm->value); $this->assertEquals('ccc3', $account->testStreamCstm->value); $metadata = CalculatedDerivedAttributeMetadata::getByNameAndModelClassName('testCalculatedValue', 'Account'); $testCalculatedValue = CalculatedNumberUtil::calculateByFormulaAndModelAndResolveFormat($metadata->getFormula(), $account); $this->assertEquals('$774.56', $testCalculatedValue); unset($testCalculatedValue); $account->forget(); unset($account); $account = Account::getById($accountId); //Switch values around to cover for any default value pollution on the assertions above. $account->testCheckBox2Cstm = 1; $account->testCurrency2Cstm->value = 728.92; $account->testCurrency2Cstm->currency = $currencies[0]; $account->testDate2Cstm = '2008-09-04'; $account->testDateTime2Cstm = '2008-09-03 03:03:03'; $account->testDecimal2Cstm = 45.68; $account->testAirPlaneCstm->value = 'Dive Bomber'; $account->testInteger2Cstm = 57; $account->testPhone2Cstm = '3453452344'; $account->testAirPlanePartsCstm->value = 'Wheel'; $account->testText2Cstm = 'some test stuff2'; $account->testTextArea2Cstm = 'some test text area stuff2'; $account->testUrl2Cstm = 'http://www.zurmo.org'; $account->playMyFavoriteSongCstm->value = 'song3'; $account->testCountryCstm->value = 'cccc'; $account->testStateCstm->value = 'ccc3'; $account->testCityCstm->value = 'ca3'; $account->testEducationCstm->value = 'aaaa'; $account->testStreamCstm->value = 'aaa1'; $account->testHobbies1Cstm->values->removeAll(); $account->testHobbies2Cstm->values->removeAll(); $account->testLanguages1Cstm->values->removeAll(); $account->testLanguages2Cstm->values->removeAll(); $this->assertEquals(0, $account->testHobbies1Cstm->values->count()); $this->assertEquals(0, $account->testHobbies2Cstm->values->count()); $this->assertEquals(0, $account->testLanguages1Cstm->values->count()); $this->assertEquals(0, $account->testLanguages2Cstm->values->count()); //Set multiple value to Multiselect list. $customHobbyValue1 = new CustomFieldValue(); $customHobbyValue1->value = 'Writing'; $account->testHobbies1Cstm->values->add($customHobbyValue1); $customHobbyValue2 = new CustomFieldValue(); $customHobbyValue2->value = 'Reading'; $account->testHobbies1Cstm->values->add($customHobbyValue2); $customHobbyValue3 = new CustomFieldValue(); $customHobbyValue3->value = 'Singing'; $account->testHobbies2Cstm->values->add($customHobbyValue3); $customHobbyValue4 = new CustomFieldValue(); $customHobbyValue4->value = 'Surfing'; $account->testHobbies2Cstm->values->add($customHobbyValue4); $customHobbyValue5 = new CustomFieldValue(); $customHobbyValue5->value = 'Reading'; $account->testHobbies2Cstm->values->add($customHobbyValue5); //Set multiple value to Tagcloud. $customLanguageValue1 = new CustomFieldValue(); $customLanguageValue1->value = 'English'; $account->testLanguages1Cstm->values->add($customLanguageValue1); $customLanguageValue2 = new CustomFieldValue(); $customLanguageValue2->value = 'Danish'; $account->testLanguages1Cstm->values->add($customLanguageValue2); $customLanguageValue3 = new CustomFieldValue(); $customLanguageValue3->value = 'Spanish'; $account->testLanguages1Cstm->values->add($customLanguageValue3); $customLanguageValue4 = new CustomFieldValue(); $customLanguageValue4->value = 'French'; $account->testLanguages2Cstm->values->add($customLanguageValue4); $customLanguageValue5 = new CustomFieldValue(); $customLanguageValue5->value = 'Spanish'; $account->testLanguages2Cstm->values->add($customLanguageValue5); $saved = $account->save(); $this->assertTrue($saved); $accountId = $account->id; $account->forget(); unset($account); $account = Account::getById($accountId); $this->assertEquals(1, $account->testCheckBox2Cstm); $this->assertEquals(true, (bool) $account->testCheckBox2Cstm); $this->assertEquals(728.92, $account->testCurrency2Cstm->value); $this->assertEquals(1, $account->testCurrency2Cstm->rateToBase); $this->assertEquals('2008-09-04', $account->testDate2Cstm); $this->assertEquals('2008-09-03 03:03:03', $account->testDateTime2Cstm); $this->assertEquals(45.68, $account->testDecimal2Cstm); $this->assertEquals('Dive Bomber', $account->testAirPlaneCstm->value); $this->assertEquals(57, $account->testInteger2Cstm); $this->assertEquals(3453452344, $account->testPhone2Cstm); $this->assertEquals('Wheel', $account->testAirPlanePartsCstm->value); $this->assertEquals('some test stuff2', $account->testText2Cstm); $this->assertEquals('some test text area stuff2', $account->testTextArea2Cstm); $this->assertEquals('http://www.zurmo.org', $account->testUrl2Cstm); $this->assertEquals('song3', $account->playMyFavoriteSongCstm->value); $this->assertEquals(2, $account->testHobbies1Cstm->values->count()); $this->assertEquals(3, $account->testHobbies2Cstm->values->count()); $this->assertEquals(3, $account->testLanguages1Cstm->values->count()); $this->assertEquals(2, $account->testLanguages2Cstm->values->count()); $this->assertContains('Writing', $account->testHobbies1Cstm->values); $this->assertContains('Reading', $account->testHobbies1Cstm->values); $this->assertContains('Singing', $account->testHobbies2Cstm->values); $this->assertContains('Surfing', $account->testHobbies2Cstm->values); $this->assertContains('Reading', $account->testHobbies2Cstm->values); $this->assertContains('English', $account->testLanguages1Cstm->values); $this->assertContains('Danish', $account->testLanguages1Cstm->values); $this->assertContains('Spanish', $account->testLanguages1Cstm->values); $this->assertContains('French', $account->testLanguages2Cstm->values); $this->assertContains('Spanish', $account->testLanguages2Cstm->values); $this->assertEquals('cccc', $account->testCountryCstm->value); $this->assertEquals('ccc3', $account->testStateCstm->value); $this->assertEquals('ca3', $account->testCityCstm->value); $this->assertEquals('aaaa', $account->testEducationCstm->value); $this->assertEquals('aaa1', $account->testStreamCstm->value); }
public function testIsFormulaValid() { $this->assertFalse(CalculatedNumberUtil::isFormulaValid('IF(4 + 5;"string";"")', 'TestOperatorTypeModel')); // Not Coding Standard $this->assertFalse(CalculatedNumberUtil::isFormulaValid('IF(4 >=! 5;"string";"")', 'TestOperatorTypeModel')); // Not Coding Standard $this->assertFalse(CalculatedNumberUtil::isFormulaValid('IF(4>=5;>string";"")', 'TestOperatorTypeModel')); // Not Coding Standard $this->assertFalse(CalculatedNumberUtil::isFormulaValid('IF(4>=5;"string":"")', 'TestOperatorTypeModel')); // Not Coding Standard $this->assertFalse(CalculatedNumberUtil::isFormulaValid('IF(4 == 5;"true string";"false string")', 'TestOperatorTypeModel')); // Not Coding Standard $this->assertTrue(CalculatedNumberUtil::isFormulaValid("IF(4 == 5;'true string';'false string')", 'TestOperatorTypeModel')); // Not Coding Standard $this->assertTrue(CalculatedNumberUtil::isFormulaValid('IF(4 <= 5;emailStandard;urlStandard)', 'TestOperatorTypeModel')); // Not Coding Standard $this->assertTrue(CalculatedNumberUtil::isFormulaValid('IF(4 < 5;emailStandard;urlStandard)', 'TestOperatorTypeModel')); // Not Coding Standard $this->assertTrue(CalculatedNumberUtil::isFormulaValid('IF(4 > 5;emailStandard;urlStandard)', 'TestOperatorTypeModel')); // Not Coding Standard $this->assertTrue(CalculatedNumberUtil::isFormulaValid('IF(4 >= 5;emailStandard;urlStandard)', 'TestOperatorTypeModel')); // Not Coding Standard $this->assertTrue(CalculatedNumberUtil::isFormulaValid('IF(4 != 5;emailStandard;urlStandard)', 'TestOperatorTypeModel')); // Not Coding Standard $this->assertTrue(CalculatedNumberUtil::isFormulaValid("IF(emailStandard == 'email';emailStandard;urlStandard)", 'TestOperatorTypeModel')); // Not Coding Standard $this->assertTrue(CalculatedNumberUtil::isFormulaValid('(4 + 5)', 'TestOperatorTypeModel')); $this->assertTrue(CalculatedNumberUtil::isFormulaValid('(integerStandard + 5)', 'TestOperatorTypeModel')); $this->assertTrue(CalculatedNumberUtil::isFormulaValid('(integerStandard + floatStandard)', 'TestOperatorTypeModel')); $this->assertFalse(CalculatedNumberUtil::isFormulaValid('(integerStandard + floatStandard + jj)', 'TestOperatorTypeModel')); $this->assertFalse(CalculatedNumberUtil::isFormulaValid(')4(', 'TestOperatorTypeModel')); $this->assertTrue(CalculatedNumberUtil::isFormulaValid('(integerStandard + integerS)', 'TestOperatorTypeModel')); }
/** * @depends testEditOfTheProductTemplateForTheTagCloudFieldAfterRemovingAllTagsPlacedForProductTemplatesModule */ public function testEditOfTheProductTemplateForTheCustomFieldsPlacedForProductTemplatesModule() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); //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 account id, the super user id and opportunity Id. $superUserId = $super->id; $productTemplate = ProductTemplate::getByName('myEditProductTemplate'); $productTemplateId = $productTemplate[0]->id; //Edit a new ProductTemplate based on the custom fields. $this->setGetArray(array('id' => $productTemplateId)); $this->setPostArray(array('ProductTemplate' => array('name' => 'myEditProductTemplate', 'type' => ProductTemplate::TYPE_PRODUCT, 'description' => 'Test Description', 'sellPrice' => array('currency' => array('id' => $baseCurrency->id), 'value' => 200), 'cost' => array('currency' => array('id' => $baseCurrency->id), 'value' => 200), 'listPrice' => array('currency' => array('id' => $baseCurrency->id), 'value' => 200), 'priceFrequency' => 2, 'status' => ProductTemplate::STATUS_ACTIVE, 'sellPriceFormula' => array('type' => SellPriceFormula::TYPE_EDITABLE), 'checkboxCstm' => '0', 'currencyCstm' => array('value' => 40, 'currency' => array('id' => $baseCurrency->id)), 'decimalCstm' => '12', 'dateCstm' => $date, 'datetimeCstm' => $datetime, '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'))); $this->runControllerWithRedirectExceptionAndGetUrl('productTemplates/default/edit'); //Check the details if they are saved properly for the custom fields. $productTemplateId = self::getModelIdByModelNameAndName('ProductTemplate', 'myEditProductTemplate'); $productTemplate = ProductTemplate::getById($productTemplateId); $this->assertEquals($productTemplate->name, 'myEditProductTemplate'); $this->assertEquals($productTemplate->sellPrice->value, 200.0); $this->assertEquals($productTemplate->cost->value, 200.0); $this->assertEquals($productTemplate->listPrice->value, 200.0); $this->assertEquals($productTemplate->description, 'Test Description'); $this->assertEquals($productTemplate->type, ProductTemplate::TYPE_PRODUCT); $this->assertEquals($productTemplate->status, ProductTemplate::STATUS_ACTIVE); $this->assertEquals($productTemplate->priceFrequency, 2); $this->assertEquals($productTemplate->sellPriceFormula->type, SellPriceFormula::TYPE_EDITABLE); $this->assertEquals($productTemplate->checkboxCstm, '0'); $this->assertEquals($productTemplate->currencyCstm->value, 40); $this->assertEquals($productTemplate->currencyCstm->currency->id, $baseCurrency->id); $this->assertEquals($productTemplate->dateCstm, $dateAssert); $this->assertEquals($productTemplate->datetimeCstm, $datetimeAssert); $this->assertEquals($productTemplate->decimalCstm, '12'); $this->assertEquals($productTemplate->picklistCstm->value, 'b'); $this->assertEquals($productTemplate->integerCstm, 11); $this->assertEquals($productTemplate->phoneCstm, '259-784-2069'); $this->assertEquals($productTemplate->radioCstm->value, 'e'); $this->assertEquals($productTemplate->textCstm, 'This is a test Edit Text'); $this->assertEquals($productTemplate->textareaCstm, 'This is a test Edit TextArea'); $this->assertEquals($productTemplate->urlCstm, 'http://wwww.abc-edit.com'); $this->assertEquals($productTemplate->dateCstm, $dateAssert); $this->assertEquals($productTemplate->datetimeCstm, $datetimeAssert); $this->assertEquals($productTemplate->countrylistCstm->value, 'aaaa'); $this->assertEquals($productTemplate->statelistCstm->value, 'aaa1'); $this->assertEquals($productTemplate->citylistCstm->value, 'ab1'); $this->assertContains('gg', $productTemplate->multiselectCstm->values); $this->assertContains('hh', $productTemplate->multiselectCstm->values); $this->assertContains('reading', $productTemplate->tagcloudCstm->values); $this->assertContains('surfing', $productTemplate->tagcloudCstm->values); $metadata = CalculatedDerivedAttributeMetadata::getByNameAndModelClassName('calcnumber', 'ProductTemplate'); $testCalculatedValue = CalculatedNumberUtil::calculateByFormulaAndModelAndResolveFormat($metadata->getFormula(), $productTemplate); $this->assertEquals(132, intval(str_replace(',', "", $testCalculatedValue))); // Not Coding Standard }
/** * @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' => '*****@*****.**', 'optOut' => '0', 'isInvalid' => '0'), 'secondaryEmail' => array('emailAddress' => '*****@*****.**', '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, '*****@*****.**'); $this->assertEquals($lead->primaryEmail->optOut, '0'); $this->assertEquals($lead->primaryEmail->isInvalid, '0'); $this->assertEquals($lead->secondaryEmail->emailAddress, '*****@*****.**'); $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); }
/** * (non-PHPdoc) * @see Element::renderControlNonEditable() */ protected function renderControlNonEditable() { $formula = $this->calculatedDerivedAttributeMetadata->getFormula(); return CalculatedNumberUtil::calculateByFormulaAndModelAndResolveFormat($formula, $this->model); }
/** * @depends testEditOfTheProductForTheTagCloudFieldAfterRemovingAllTagsPlacedForProductsModule */ public function testEditOfTheProductForTheCustomFieldsPlacedForProductsModule() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); //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 account id, the super user id and product Id. $accountId = self::getModelIdByModelNameAndName('Account', 'superAccount'); $superUserId = $super->id; $explicitReadWriteModelPermission = ExplicitReadWriteModelPermissionsUtil::MIXED_TYPE_EVERYONE_GROUP; $product = Product::getByName('myEditProduct'); $productId = $product[0]->id; //Edit a new Product based on the custom fields. $this->setGetArray(array('id' => $productId)); $this->setPostArray(array('Product' => array('name' => 'myEditProduct', 'owner' => array('id' => $superUserId), 'type' => 1, 'sellPrice' => array('currency' => array('id' => $baseCurrency->id), 'value' => 200), 'account' => array('id' => $accountId), 'quantity' => 10, 'priceFrequency' => 2, 'stage' => array('value' => 'Open'), 'explicitReadWriteModelPermissions' => array('type' => $explicitReadWriteModelPermission), 'checkboxCstm' => '0', 'currencyCstm' => array('value' => 40, 'currency' => array('id' => $baseCurrency->id)), 'decimalCstm' => '12', 'dateCstm' => $date, 'datetimeCstm' => $datetime, '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'))); $this->runControllerWithRedirectExceptionAndGetUrl('products/default/edit'); //Check the details if they are saved properly for the custom fields. $productId = self::getModelIdByModelNameAndName('Product', 'myEditProduct'); $product = Product::getById($productId); //Retrieve the permission of the product. $explicitReadWriteModelPermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem($product); $readWritePermitables = $explicitReadWriteModelPermissions->getReadWritePermitables(); $readOnlyPermitables = $explicitReadWriteModelPermissions->getReadOnlyPermitables(); $this->assertEquals($product->name, 'myEditProduct'); $this->assertEquals($product->quantity, 10); $this->assertEquals($product->sellPrice->value, 200.0); $this->assertEquals($product->account->id, $accountId); $this->assertEquals($product->type, 1); $this->assertEquals($product->stage->value, 'Open'); $this->assertEquals($product->owner->id, $superUserId); $this->assertEquals(1, count($readWritePermitables)); $this->assertEquals(0, count($readOnlyPermitables)); $this->assertEquals($product->checkboxCstm, '0'); $this->assertEquals($product->currencyCstm->value, 40); $this->assertEquals($product->currencyCstm->currency->id, $baseCurrency->id); $this->assertEquals($product->dateCstm, $dateAssert); $this->assertEquals($product->datetimeCstm, $datetimeAssert); $this->assertEquals($product->decimalCstm, '12'); $this->assertEquals($product->picklistCstm->value, 'b'); $this->assertEquals($product->integerCstm, 11); $this->assertEquals($product->phoneCstm, '259-784-2069'); $this->assertEquals($product->radioCstm->value, 'e'); $this->assertEquals($product->textCstm, 'This is a test Edit Text'); $this->assertEquals($product->textareaCstm, 'This is a test Edit TextArea'); $this->assertEquals($product->urlCstm, 'http://wwww.abc-edit.com'); $this->assertEquals($product->dateCstm, $dateAssert); $this->assertEquals($product->datetimeCstm, $datetimeAssert); $this->assertEquals($product->countrylistCstm->value, 'aaaa'); $this->assertEquals($product->statelistCstm->value, 'aaa1'); $this->assertEquals($product->citylistCstm->value, 'ab1'); $this->assertContains('gg', $product->multiselectCstm->values); $this->assertContains('hh', $product->multiselectCstm->values); $this->assertContains('reading', $product->tagcloudCstm->values); $this->assertContains('surfing', $product->tagcloudCstm->values); $metadata = CalculatedDerivedAttributeMetadata::getByNameAndModelClassName('calcnumber', 'Product'); $testCalculatedValue = CalculatedNumberUtil::calculateByFormulaAndModelAndResolveFormat($metadata->getFormula(), $product); $this->assertEquals(132, intval(str_replace(',', '', $testCalculatedValue))); // Not Coding Standard }
/** * @depends testEditOfTheAccountUserForTheTagCloudFieldAfterRemovingAllTagsPlacedForAccountsModule */ public function testEditOfTheAccountUserForTheCustomFieldsPlacedForAccountsModule() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); //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()); $explicitReadWriteModelPermission = ExplicitReadWriteModelPermissionsUtil::MIXED_TYPE_EVERYONE_GROUP; //Get the account id from the recently created account. $account = Account::getByName('myEditAccount'); $accountId = $account[0]->id; //Edit and save the account. $this->setGetArray(array('id' => $accountId)); $this->setPostArray(array('Account' => array('name' => 'myEditAccount', 'officePhone' => '259-734-2169', 'industry' => array('value' => 'Energy'), 'officeFax' => '299-825-7863', 'employees' => '630', 'annualRevenue' => '472000000', 'type' => array('value' => 'Customer'), 'website' => 'http://www.UnnamedEdit.com', 'primaryEmail' => array('emailAddress' => '*****@*****.**', 'optOut' => '0', 'isInvalid' => '0'), 'secondaryEmail' => array('emailAddress' => '', 'optOut' => '0', 'isInvalid' => '0'), 'billingAddress' => array('street1' => '26378 South Arlington Ave', 'street2' => '', 'city' => 'San Jose', 'state' => 'CA', 'postalCode' => '95131', 'country' => 'USA'), 'shippingAddress' => array('street1' => '8519 East Franklin Center', 'street2' => '', 'city' => 'Chicago', 'state' => 'IL', 'postalCode' => '60652', 'country' => 'USA'), 'description' => 'This is a Edit Description', 'explicitReadWriteModelPermissions' => array('type' => $explicitReadWriteModelPermission), 'dateCstm' => $date, 'datetimeCstm' => $datetime, 'checkboxCstm' => '0', 'currencyCstm' => array('value' => 40, 'currency' => array('id' => $baseCurrency->id)), '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('accounts/default/edit'); //Check the details if they are saved properly for the custom fields after the edit. $account = Account::getByName('myEditAccount'); //Retrieve the permission of 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, 'myEditAccount'); $this->assertEquals($account[0]->officePhone, '259-734-2169'); $this->assertEquals($account[0]->industry->value, 'Energy'); $this->assertEquals($account[0]->officeFax, '299-825-7863'); $this->assertEquals($account[0]->employees, '630'); $this->assertEquals($account[0]->annualRevenue, '472000000'); $this->assertEquals($account[0]->type->value, 'Customer'); $this->assertEquals($account[0]->website, 'http://www.UnnamedEdit.com'); $this->assertEquals($account[0]->primaryEmail->emailAddress, '*****@*****.**'); $this->assertEquals($account[0]->primaryEmail->optOut, '0'); $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, '26378 South Arlington Ave'); $this->assertEquals($account[0]->billingAddress->street2, ''); $this->assertEquals($account[0]->billingAddress->city, 'San Jose'); $this->assertEquals($account[0]->billingAddress->state, 'CA'); $this->assertEquals($account[0]->billingAddress->postalCode, '95131'); $this->assertEquals($account[0]->billingAddress->country, 'USA'); $this->assertEquals($account[0]->shippingAddress->street1, '8519 East Franklin Center'); $this->assertEquals($account[0]->shippingAddress->street2, ''); $this->assertEquals($account[0]->shippingAddress->city, 'Chicago'); $this->assertEquals($account[0]->shippingAddress->state, 'IL'); $this->assertEquals($account[0]->shippingAddress->postalCode, '60652'); $this->assertEquals($account[0]->shippingAddress->country, 'USA'); $this->assertEquals($account[0]->description, 'This is a Edit Description'); $this->assertEquals(1, count($readWritePermitables)); $this->assertEquals(0, count($readOnlyPermitables)); $this->assertEquals($account[0]->checkboxCstm, '0'); $this->assertEquals($account[0]->currencyCstm->value, 40); $this->assertEquals($account[0]->currencyCstm->currency->id, $baseCurrency->id); $this->assertEquals($account[0]->dateCstm, $dateAssert); $this->assertEquals($account[0]->datetimeCstm, $datetimeAssert); $this->assertEquals($account[0]->decimalCstm, '12'); $this->assertEquals($account[0]->picklistCstm->value, 'b'); $this->assertEquals($account[0]->integerCstm, 11); $this->assertEquals($account[0]->phoneCstm, '259-784-2069'); $this->assertEquals($account[0]->radioCstm->value, 'e'); $this->assertEquals($account[0]->textCstm, 'This is a test Edit Text'); $this->assertEquals($account[0]->textareaCstm, 'This is a test Edit TextArea'); $this->assertEquals($account[0]->urlCstm, 'http://wwww.abc-edit.com'); $this->assertEquals($account[0]->countrylistCstm->value, 'aaaa'); $this->assertEquals($account[0]->statelistCstm->value, 'aaa1'); $this->assertEquals($account[0]->citylistCstm->value, 'ab1'); $this->assertContains('gg', $account[0]->multiselectCstm->values); $this->assertContains('hh', $account[0]->multiselectCstm->values); $this->assertContains('reading', $account[0]->tagcloudCstm->values); $this->assertContains('surfing', $account[0]->tagcloudCstm->values); $metadata = CalculatedDerivedAttributeMetadata::getByNameAndModelClassName('calcnumber', 'Account'); $testCalculatedValue = CalculatedNumberUtil::calculateByFormulaAndModelAndResolveFormat($metadata->getFormula(), $account[0]); $this->assertEquals('472,000,630', $testCalculatedValue); // Not Coding Standard }
public function validateFormula($attribute, $params) { assert('$attribute == "formula"'); assert('$this->modelClassName != null'); $modelClassName = $this->modelClassName; $model = new $modelClassName(false); $adapter = new ModelNumberOrCurrencyAttributesAdapter($model); if (!CalculatedNumberUtil::isFormulaValid($this->{$attribute}, $adapter)) { $this->addError('formula', Zurmo::t('DesignerModule', 'The formula is invalid.')); } }
public function validateFormula($attribute, $params) { assert('$attribute == "formula"'); assert('$this->modelClassName != null'); if (!CalculatedNumberUtil::isFormulaValid($this->{$attribute}, $this->modelClassName)) { $this->addError('formula', Zurmo::t('DesignerModule', 'The formula is invalid.')); } }
public function testIsFormulaValid() { $model = new TestOperatorTypeModel(); $adapter = new ModelNumberOrCurrencyAttributesAdapter($model); $this->assertTrue(CalculatedNumberUtil::isFormulaValid('(4 + 5)', $adapter)); $this->assertTrue(CalculatedNumberUtil::isFormulaValid('(integerStandard + 5)', $adapter)); $this->assertTrue(CalculatedNumberUtil::isFormulaValid('(integerStandard + floatStandard)', $adapter)); $this->assertFalse(CalculatedNumberUtil::isFormulaValid('(integerStandard + floatStandard + jj)', $adapter)); $this->assertFalse(CalculatedNumberUtil::isFormulaValid(')4(', $adapter)); }