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));
 }
 /**
  * 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);
 }
 /**
  * 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);
 }
Example #4
0
 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);
 }
 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;
         }
     }
 }
 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' => '*****@*****.**', '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, '*****@*****.**');
     $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);
 }
 public function testSimpleUserImportWhereAllRowsSucceed()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $contacts = Contact::getAll();
     $this->assertEquals(0, count($contacts));
     $import = new Import();
     $serializedData['importRulesType'] = 'Leads';
     $serializedData['firstRowIsHeaderRow'] = true;
     $import->serializedData = serialize($serializedData);
     $this->assertTrue($import->save());
     ImportTestHelper::createTempTableByFileNameAndTableName('importTest.csv', $import->getTempTableName(), true, Yii::getPathOfAlias('application.modules.leads.tests.unit.files'));
     $this->assertEquals(4, ImportDatabaseUtil::getCount($import->getTempTableName()));
     // includes header rows.
     $currency = Currency::getByCode(Yii::app()->currencyHelper->getBaseCode());
     $mappingData = array('column_0' => ImportMappingUtil::makeStringColumnMappingData('firstName'), 'column_1' => ImportMappingUtil::makeStringColumnMappingData('lastName'), 'column_2' => ImportMappingUtil::makeStringColumnMappingData('jobTitle'), 'column_3' => ImportMappingUtil::makeStringColumnMappingData('officePhone'), 'column_4' => ImportMappingUtil::makeStringColumnMappingData('officeFax'), 'column_5' => ImportMappingUtil::makeStringColumnMappingData('department'), 'column_6' => ImportMappingUtil::makeUrlColumnMappingData('website'), 'column_7' => ImportMappingUtil::makeTextAreaColumnMappingData('description'), 'column_8' => ImportMappingUtil::makeStringColumnMappingData('primaryAddress__city'), 'column_9' => ImportMappingUtil::makeStringColumnMappingData('primaryAddress__country'), 'column_10' => ImportMappingUtil::makeStringColumnMappingData('primaryAddress__postalCode'), 'column_11' => ImportMappingUtil::makeStringColumnMappingData('primaryAddress__state'), 'column_12' => ImportMappingUtil::makeStringColumnMappingData('primaryAddress__street1'), 'column_13' => ImportMappingUtil::makeStringColumnMappingData('primaryAddress__street2'), 'column_14' => ImportMappingUtil::makeEmailColumnMappingData('primaryEmail__emailAddress'), 'column_15' => ImportMappingUtil::makeBooleanColumnMappingData('primaryEmail__isInvalid'), 'column_16' => ImportMappingUtil::makeBooleanColumnMappingData('primaryEmail__optOut'), 'column_17' => ImportMappingUtil::makeDropDownColumnMappingData('source'), 'column_18' => LeadImportTestHelper::makeStateColumnMappingData(), 'column_19' => ImportMappingUtil::makeDropDownColumnMappingData('industry'), 'column_20' => ImportMappingUtil::makeStringColumnMappingData('companyName'));
     $importRules = ImportRulesUtil::makeImportRulesByType('Leads');
     $page = 0;
     $config = array('pagination' => array('pageSize' => 50));
     //This way all rows are processed.
     $dataProvider = new ImportDataProvider($import->getTempTableName(), true, $config);
     $dataProvider->getPagination()->setCurrentPage($page);
     $importResultsUtil = new ImportResultsUtil($import);
     $messageLogger = new ImportMessageLogger();
     ImportUtil::importByDataProvider($dataProvider, $importRules, $mappingData, $importResultsUtil, new ExplicitReadWriteModelPermissions(), $messageLogger);
     $importResultsUtil->processStatusAndMessagesForEachRow();
     //Confirm that 3 models where created.
     $contacts = Contact::getAll();
     $this->assertEquals(3, count($contacts));
     $contacts = Contact::getByName('contact1 contact1son');
     $this->assertEquals(1, count($contacts[0]));
     $this->assertEquals('contact1', $contacts[0]->firstName);
     $this->assertEquals('contact1son', $contacts[0]->lastName);
     $this->assertEquals('president', $contacts[0]->jobTitle);
     $this->assertEquals(123456, $contacts[0]->officePhone);
     $this->assertEquals(555, $contacts[0]->officeFax);
     $this->assertEquals('executive', $contacts[0]->department);
     $this->assertEquals('http://www.contact1.com', $contacts[0]->website);
     $this->assertEquals('desc1', $contacts[0]->description);
     $this->assertEquals('city1', $contacts[0]->primaryAddress->city);
     $this->assertEquals('country1', $contacts[0]->primaryAddress->country);
     $this->assertEquals('postal1', $contacts[0]->primaryAddress->postalCode);
     $this->assertEquals('state1', $contacts[0]->primaryAddress->state);
     $this->assertEquals('street11', $contacts[0]->primaryAddress->street1);
     $this->assertEquals('street21', $contacts[0]->primaryAddress->street2);
     $this->assertEquals('*****@*****.**', $contacts[0]->primaryEmail->emailAddress);
     $this->assertEquals(null, $contacts[0]->primaryEmail->isInvalid);
     $this->assertEquals(null, $contacts[0]->primaryEmail->optOut);
     $this->assertEquals('Self-Generated', $contacts[0]->source->value);
     $this->assertEquals('New', $contacts[0]->state->name);
     $this->assertEquals('Automotive', $contacts[0]->industry->value);
     $this->assertEquals('company1', $contacts[0]->companyName);
     $contacts = Contact::getByName('contact2 contact2son');
     $this->assertEquals(1, count($contacts[0]));
     $this->assertEquals('contact2', $contacts[0]->firstName);
     $this->assertEquals('contact2son', $contacts[0]->lastName);
     $this->assertEquals('president2', $contacts[0]->jobTitle);
     $this->assertEquals(223456, $contacts[0]->officePhone);
     $this->assertEquals(655, $contacts[0]->officeFax);
     $this->assertEquals('executive2', $contacts[0]->department);
     $this->assertEquals('http://www.contact2.com', $contacts[0]->website);
     $this->assertEquals('desc2', $contacts[0]->description);
     $this->assertEquals('city2', $contacts[0]->primaryAddress->city);
     $this->assertEquals('country2', $contacts[0]->primaryAddress->country);
     $this->assertEquals('postal2', $contacts[0]->primaryAddress->postalCode);
     $this->assertEquals('state2', $contacts[0]->primaryAddress->state);
     $this->assertEquals('street12', $contacts[0]->primaryAddress->street1);
     $this->assertEquals('street22', $contacts[0]->primaryAddress->street2);
     $this->assertEquals('*****@*****.**', $contacts[0]->primaryEmail->emailAddress);
     $this->assertEquals(null, $contacts[0]->primaryEmail->isInvalid);
     $this->assertEquals(null, $contacts[0]->primaryEmail->optOut);
     $this->assertEquals('Tradeshow', $contacts[0]->source->value);
     $this->assertEquals('Recycled', $contacts[0]->state->name);
     $this->assertEquals('Banking', $contacts[0]->industry->value);
     $this->assertEquals('company2', $contacts[0]->companyName);
     $contacts = Contact::getByName('contact3 contact3son');
     $this->assertEquals(1, count($contacts[0]));
     $this->assertEquals('contact3', $contacts[0]->firstName);
     $this->assertEquals('contact3son', $contacts[0]->lastName);
     $this->assertEquals('president3', $contacts[0]->jobTitle);
     $this->assertEquals(323456, $contacts[0]->officePhone);
     $this->assertEquals(755, $contacts[0]->officeFax);
     $this->assertEquals('executive3', $contacts[0]->department);
     $this->assertEquals('http://www.contact3.com', $contacts[0]->website);
     $this->assertEquals('desc3', $contacts[0]->description);
     $this->assertEquals('city3', $contacts[0]->primaryAddress->city);
     $this->assertEquals('country3', $contacts[0]->primaryAddress->country);
     $this->assertEquals('postal3', $contacts[0]->primaryAddress->postalCode);
     $this->assertEquals('state3', $contacts[0]->primaryAddress->state);
     $this->assertEquals('street13', $contacts[0]->primaryAddress->street1);
     $this->assertEquals('street23', $contacts[0]->primaryAddress->street2);
     $this->assertEquals('*****@*****.**', $contacts[0]->primaryEmail->emailAddress);
     $this->assertEquals('1', $contacts[0]->primaryEmail->isInvalid);
     $this->assertEquals('1', $contacts[0]->primaryEmail->optOut);
     $this->assertEquals('Inbound Call', $contacts[0]->source->value);
     $this->assertEquals('New', $contacts[0]->state->name);
     $this->assertEquals('Energy', $contacts[0]->industry->value);
     $this->assertEquals('company3', $contacts[0]->companyName);
     //Confirm 3 rows were processed as 'created'.
     $this->assertEquals(3, ImportDatabaseUtil::getCount($import->getTempTableName(), "status = " . ImportRowDataResultsUtil::CREATED));
     //Confirm that 0 rows were processed as 'updated'.
     $this->assertEquals(0, ImportDatabaseUtil::getCount($import->getTempTableName(), "status = " . ImportRowDataResultsUtil::UPDATED));
     //Confirm 0 rows were processed as 'errors'.
     $this->assertEquals(0, ImportDatabaseUtil::getCount($import->getTempTableName(), "status = " . ImportRowDataResultsUtil::ERROR));
     $beansWithErrors = ImportDatabaseUtil::getSubset($import->getTempTableName(), "status = " . ImportRowDataResultsUtil::ERROR);
     $this->assertEquals(0, count($beansWithErrors));
 }
 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 = '*****@*****.**';
     $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('*****@*****.**', $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);
 }
 /**
  * @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);
 }
 /**
  * @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' => '*****@*****.**'), '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('*****@*****.**', $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);
 }
 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);
 }
 /**
  * @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));
 }
 /**
  * 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());
 }
 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);
 }
 /**
  * @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);
 }
 /**
  * @depends testContactStateWorkflowAttributeFormSetGetAndValidate
  */
 public function testCurrencyValueWorkflowAttributeFormSetGetAndValidate()
 {
     $currency = Currency::getByCode('USD');
     $form = new CurrencyValueWorkflowActionAttributeForm('WorkflowModelTestItem', 'currencyValue');
     $form->type = WorkflowActionAttributeForm::TYPE_STATIC;
     $form->shouldSetValue = true;
     $form->value = 362.24;
     $form->currencyId = $currency->id;
     $form->currencyIdType = CurrencyValueWorkflowActionAttributeForm::CURRENCY_ID_TYPE_STATIC;
     $validated = $form->validate();
     $this->assertTrue($validated);
     $form->currencyId = null;
     $validated = $form->validate();
     $this->assertFalse($validated);
 }
 public function testSuperUserCreateFromRelationAction()
 {
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $products = Product::getAll();
     $productsCount = count($products);
     $accountId = self::getModelIdByModelNameAndName('Account', 'superAccount');
     $contactId = self::getModelIdByModelNameAndName('Contact', 'superContact superContactson');
     $opportunityId = self::getModelIdByModelNameAndName('Opportunity', 'superOpportunity');
     //Create a new product from a related account.
     $this->setGetArray(array('relationAttributeName' => 'account', 'relationModelId' => $accountId, 'relationModuleId' => 'accounts', 'redirectUrl' => 'someRedirect'));
     $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);
     $product['name'] = 'myUltraNewProduct';
     $product['quantity'] = 50;
     $product['priceFrequency'] = ProductTemplate::PRICE_FREQUENCY_ONE_TIME;
     $product['sellPrice'] = $currencyValue1Array;
     $product['type'] = ProductTemplate::TYPE_PRODUCT;
     $product['stage']['value'] = Product::OPEN_STAGE;
     $this->setPostArray(array('Product' => $product));
     $this->runControllerWithRedirectExceptionAndGetContent('products/default/createFromRelation');
     $products = Product::getByName('myUltraNewProduct');
     $this->assertEquals(1, count($products));
     $this->assertTrue($products[0]->id > 0);
     $this->assertTrue($products[0]->owner == $super);
     $this->assertEquals($accountId, $products[0]->account->id);
     $this->assertEquals('50', $products[0]->quantity);
     $this->assertEquals('500.54', $products[0]->sellPrice->value);
     $this->assertEquals(ProductTemplate::PRICE_FREQUENCY_ONE_TIME, $products[0]->priceFrequency);
     $this->assertEquals(ProductTemplate::TYPE_PRODUCT, $products[0]->type);
     $this->assertEquals(Product::OPEN_STAGE, $products[0]->stage->value);
     $products = Product::getAll();
     $this->assertEquals(++$productsCount, count($products));
     //Create a new product from a related contact.
     $this->setGetArray(array('relationAttributeName' => 'contact', 'relationModelId' => $contactId, 'relationModuleId' => 'contacts', 'redirectUrl' => 'someRedirect'));
     $product['name'] = 'myUltraNewProduct2';
     $product['quantity'] = 51;
     $product['priceFrequency'] = ProductTemplate::PRICE_FREQUENCY_ANNUALLY;
     $product['sellPrice'] = $currencyValue1Array;
     $product['type'] = ProductTemplate::TYPE_SERVICE;
     $product['stage']['value'] = Product::OPEN_STAGE;
     $this->setPostArray(array('Product' => $product));
     $this->runControllerWithRedirectExceptionAndGetContent('products/default/createFromRelation');
     $products = Product::getByName('myUltraNewProduct2');
     $this->assertEquals(1, count($products));
     $this->assertTrue($products[0]->id > 0);
     $this->assertTrue($products[0]->owner == $super);
     $this->assertEquals($accountId, $products[0]->account->id);
     $this->assertEquals($contactId, $products[0]->contact->id);
     $this->assertEquals('51', $products[0]->quantity);
     $this->assertEquals('500.54', $products[0]->sellPrice->value);
     $this->assertEquals(ProductTemplate::PRICE_FREQUENCY_ANNUALLY, $products[0]->priceFrequency);
     $this->assertEquals(ProductTemplate::TYPE_SERVICE, $products[0]->type);
     $this->assertEquals(Product::OPEN_STAGE, $products[0]->stage->value);
     $products = Product::getAll();
     $this->assertEquals(++$productsCount, count($products));
     //Create a new product from a related opportunity.
     $this->setGetArray(array('relationAttributeName' => 'opportunity', 'relationModelId' => $opportunityId, 'relationModuleId' => 'opportunities', 'redirectUrl' => 'someRedirect'));
     $product['name'] = 'myUltraNewProduct3';
     $product['quantity'] = 51;
     $product['priceFrequency'] = ProductTemplate::PRICE_FREQUENCY_ANNUALLY;
     $product['sellPrice'] = $currencyValue1Array;
     $product['type'] = ProductTemplate::TYPE_SERVICE;
     $product['stage']['value'] = Product::OPEN_STAGE;
     $this->setPostArray(array('Product' => $product));
     $this->runControllerWithRedirectExceptionAndGetContent('products/default/createFromRelation');
     $products = Product::getByName('myUltraNewProduct3');
     $this->assertEquals(1, count($products));
     $this->assertTrue($products[0]->id > 0);
     $this->assertTrue($products[0]->owner == $super);
     $this->assertEquals($accountId, $products[0]->account->id);
     $this->assertEquals($opportunityId, $products[0]->opportunity->id);
     $this->assertEquals('51', $products[0]->quantity);
     $this->assertEquals('500.54', $products[0]->sellPrice->value);
     $this->assertEquals(ProductTemplate::PRICE_FREQUENCY_ANNUALLY, $products[0]->priceFrequency);
     $this->assertEquals(ProductTemplate::TYPE_SERVICE, $products[0]->type);
     $this->assertEquals(Product::OPEN_STAGE, $products[0]->stage->value);
     $products = Product::getAll();
     $this->assertEquals(++$productsCount, count($products));
 }
 /**
  * @depends testCreateSecondAccountForUserAfterTheCustomFieldsArePlacedForAccountsModule
  */
 public function testMultiValueCustomFieldContentAfterCreateAndEditPlacedForAccountsModule()
 {
     $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());
     //Create a new account based on the custom fields.
     $this->resetGetArray();
     $this->setPostArray(array('Account' => array('name' => 'myThirdAccount', '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' => '*****@*****.**', '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), 'checkboxCstm' => '1', 'currencyCstm' => array('value' => 45, 'currency' => array('id' => $baseCurrency->id)), 'dateCstm' => $date, 'datetimeCstm' => $datetime, 'decimalCstm' => '123', 'picklistCstm' => array('value' => 'a'), 'multiselectCstm' => array('values' => array('gg', 'ff')), 'tagcloudCstm' => array('values' => array('reading', 'writing')), 'countrylistCstm' => array('value' => 'bbbb'), 'statelistCstm' => array('value' => 'bbb1'), 'citylistCstm' => array('value' => 'bb1'), 'integerCstm' => '12', 'phoneCstm' => '259-784-2169', 'radioCstm' => array('value' => 'd'), 'textCstm' => 'This is a test Text', 'textareaCstm' => 'This is a test TextArea', 'urlCstm' => 'http://wwww.abc.com')));
     $this->runControllerWithRedirectExceptionAndGetUrl('accounts/default/create');
     //Check the details if they are saved properly for the custom fields.
     $account = Account::getByName('myThirdAccount');
     //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, 'myThirdAccount');
     $this->assertEquals(2, $account[0]->multiselectCstm->values->count());
     $this->assertEquals(2, $account[0]->tagcloudCstm->values->count());
     $this->assertContains('gg', $account[0]->multiselectCstm->values);
     $this->assertContains('ff', $account[0]->multiselectCstm->values);
     $this->assertContains('reading', $account[0]->tagcloudCstm->values);
     $this->assertContains('writing', $account[0]->tagcloudCstm->values);
     unset($account);
     $account = Account::getByName('myThirdAccount');
     $accountId = $account[0]->id;
     //Edit and save the account.
     $this->setGetArray(array('id' => $accountId));
     $this->setPostArray(array('Account' => array('name' => 'myThirdAccount', 'multiselectCstm' => array('values' => array('ff')), 'tagcloudCstm' => array('values' => array('writing'))), 'save' => 'Save'));
     $this->runControllerWithRedirectExceptionAndGetUrl('accounts/default/edit');
     //Check the details if they are saved properly for the custom fields.
     $account = Account::getByName('myThirdAccount');
     //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(1, $account[0]->multiselectCstm->values->count());
     $this->assertContains('ff', $account[0]->multiselectCstm->values);
     $this->assertNotContains('gg', $account[0]->multiselectCstm->values);
     $this->assertNotContains('hh', $account[0]->multiselectCstm->values);
     $this->assertNotContains('rr', $account[0]->multiselectCstm->values);
     $this->assertEquals(1, $account[0]->tagcloudCstm->values->count());
     $this->assertContains('writing', $account[0]->tagcloudCstm->values);
 }
 /**
  * @depends testSimpleUserImportWhereAllRowsSucceed
  */
 public function testImportContactWithAccount()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     Contact::deleteAll();
     $account = AccountTestHelper::createAccountByNameForOwner('Account', Yii::app()->user->userModel);
     $accountId = $account->id;
     $import = new Import();
     $serializedData['importRulesType'] = 'Contacts';
     $serializedData['firstRowIsHeaderRow'] = true;
     $import->serializedData = serialize($serializedData);
     $this->assertTrue($import->save());
     ImportTestHelper::createTempTableByFileNameAndTableName('importTest.csv', $import->getTempTableName(), true, Yii::getPathOfAlias('application.modules.contacts.tests.unit.files'));
     //update the ids of the account column to match the parent account.
     ZurmoRedBean::exec("update " . $import->getTempTableName() . " set column_17 = " . $accountId . " where id != 1 limit 4");
     $this->assertEquals(4, ImportDatabaseUtil::getCount($import->getTempTableName()));
     // includes header rows.
     $currency = Currency::getByCode(Yii::app()->currencyHelper->getBaseCode());
     $accountMappingData = array('attributeIndexOrDerivedType' => 'account', 'type' => 'importColumn', 'mappingRulesData' => array('RelatedModelValueTypeMappingRuleForm' => array('type' => RelatedModelValueTypeMappingRuleForm::ZURMO_MODEL_ID)));
     $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' => $accountMappingData, 'column_18' => ImportMappingUtil::makeDropDownColumnMappingData('source'), 'column_19' => ContactImportTestHelper::makeStateColumnMappingData(), 'column_20' => ImportMappingUtil::makeDropDownColumnMappingData('industry'));
     $importRules = ImportRulesUtil::makeImportRulesByType('Contacts');
     $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));
     $this->assertTrue($contacts[0]->account->isSame($account));
     //test the account has 3 contacts
     $account->forget();
     $account = Account::getById($accountId);
     $this->assertEquals(3, $account->contacts->count());
 }
 /**
  * @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
 }
 public function testSuperUserModifyActiveCurrenciesInCollection()
 {
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     //Create second currency.
     $currency = new Currency();
     $currency->code = 'EUR';
     $currency->rateToBase = 1.5;
     $saved = $currency->save();
     $this->assertTrue($saved);
     $EURCurrencyId = $currency->id;
     $currencies = Currency::getAll();
     $this->assertEquals(2, count($currencies));
     $this->assertEquals(1, $currencies[0]->active);
     $this->assertEquals(1, $currencies[1]->active);
     //Make EUR inactive.
     $this->resetGetArray();
     $this->setPostArray(array('CurrencyCollection' => array('EUR' => array('active' => ''), 'USD' => array('active' => '1'))));
     $content = $this->runControllerWithNoExceptionsAndGetContent('zurmo/currency/configurationList');
     $this->assertContains('Changes to active currencies saved successfully.', $content);
     //Confirm that the EUR is inactive and the USD is still active.
     $currency = Currency::getByCode('EUR');
     $this->assertEquals(0, $currency->active);
     $currency = Currency::getByCode('USD');
     $this->assertEquals(1, $currency->active);
     //Attempt to also make the USD inactive, this should fail since at least one currency must be active.
     $this->resetGetArray();
     $this->setPostArray(array('CurrencyCollection' => array('EUR' => array('active' => ''), 'USD' => array('active' => ''))));
     $content = $this->runControllerWithNoExceptionsAndGetContent('zurmo/currency/configurationList');
     $this->assertContains('You must have at least one active currency.', $content);
     //Confirm that the EUR is inactive and the USD is still active.
     $currency = Currency::getByCode('EUR');
     $this->assertEquals(0, $currency->active);
     $currency = Currency::getByCode('USD');
     $this->assertEquals(1, $currency->active);
 }
 /**
  * @depends testConstructDerivedWithUserDefaultCurrency
  */
 public function testIsCurrencyInUseByIdAndChangRateIfValueChangesOrCurrencyChanges()
 {
     $currencyHelper = Yii::app()->currencyHelper;
     $euro = Currency::getByCode('EUR');
     $this->assertFalse(CurrencyValue::isCurrencyInUseById($euro->id));
     $opportunity = new Opportunity();
     $opportunity->name = 'Tyfe';
     $opportunity->stage->value = 'Starting Up';
     $opportunity->closeDate = '2008-10-05';
     $opportunity->amount->value = 456.78;
     $opportunity->amount->currency = $euro;
     $this->assertTrue($opportunity->save());
     $this->assertEquals(1.5, $opportunity->amount->rateToBase);
     $this->assertTrue(CurrencyValue::isCurrencyInUseById($euro->id));
     //change the currency rate for the euro.
     $euro->rateToBase = 3;
     $this->assertTrue($euro->save());
     //Now test saving the opportunity again but not changing the amount value. The rate should stay the same.
     $id = $opportunity->id;
     unset($opportunity);
     $opportunity = Opportunity::getById($id);
     $this->assertEquals(456.78, $opportunity->amount->value);
     $opportunity->amount->value = 456.78;
     $this->assertTrue($opportunity->save());
     $this->assertEquals(456.78, $opportunity->amount->value);
     $this->assertEquals(1.5, $opportunity->amount->rateToBase);
     //Now change amount. the exchange rate should change.
     $opportunity->amount->value = 566.0;
     $this->assertTrue($opportunity->save());
     $this->assertEquals(3, $opportunity->amount->rateToBase);
     //Now change the currency only. should change rate.
     $id = $opportunity->id;
     unset($opportunity);
     $opportunity = Opportunity::getById($id);
     $opportunity->amount->currency = Currency::getByCode('USD');
     $this->assertTrue($opportunity->save());
     $this->assertEquals(1, $opportunity->amount->rateToBase);
 }
 /**
  * @depends testDeleteOfTheProductUserForTheCustomFieldsPlacedForProductsModule
  */
 public function testWhetherSearchWorksForTheCustomFieldsPlacedForProductsModuleAfterDeletingTheProduct()
 {
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     //Retrieve the account id, the super user id and product Id.
     $accountId = self::getModelIdByModelNameAndName('Account', 'superAccount');
     $superUserId = $super->id;
     $baseCurrency = Currency::getByCode(Yii::app()->currencyHelper->getBaseCode());
     //Search a created Product using the customfields.
     $this->resetPostArray();
     $this->setGetArray(array('ProductsSearchForm' => ProductsDesignerWalkthroughHelperUtil::fetchProductsSearchFormGetData($accountId, $superUserId, $baseCurrency->id), 'ajax' => 'list-view'));
     //TODO Need to ask Jason
     $content = $this->runControllerWithNoExceptionsAndGetContent('products/default');
     //Assert that the edit Product does not exits after the search.
     $this->assertTrue(strpos($content, "No results found.") > 0);
 }
Example #24
0
 public function testProductSaveWithPermissions()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $contacts = Contact::getAll();
     $accounts = Account::getByName('superAccount');
     $opportunities = Opportunity::getByName('superOpportunity');
     $productTemplates = ProductTemplate::getByName('superProductTemplate');
     $account = $accounts[0];
     $user = $account->owner;
     $everyoneGroup = Group::getByName(Group::EVERYONE_GROUP_NAME);
     $explicitReadWriteModelPermissions = new ExplicitReadWriteModelPermissions();
     $currencyHelper = Yii::app()->currencyHelper;
     $currencyCode = $currencyHelper->getBaseCode();
     $currency = Currency::getByCode($currencyCode);
     $postData = array('productTemplate' => array('id' => $productTemplates[0]->id), 'name' => 'ProductPermissionTest', 'quantity' => 6, 'account' => array('id' => $accounts[0]->id), 'contact' => array('id' => $contacts[0]->id), 'opportunity' => array('id' => ''), 'type' => ProductTemplate::TYPE_PRODUCT, 'priceFrequency' => ProductTemplate::PRICE_FREQUENCY_ONE_TIME, 'sellPrice' => array('currency' => array('id' => $currency->id), 'value' => 210), 'stage' => array('value' => 'Open'), 'owner' => array('id' => $user->id), 'explicitReadWriteModelPermissions' => array('type' => ExplicitReadWriteModelPermissionsUtil::MIXED_TYPE_EVERYONE_GROUP, 'nonEveryoneGroup' => ''));
     $model = new Product();
     $sanitizedPostData = PostUtil::sanitizePostByDesignerTypeForSavingModel($model, $postData);
     if ($model instanceof SecurableItem) {
         $explicitReadWriteModelPermissions = ExplicitReadWriteModelPermissionsUtil::resolveByPostDataAndModelThenMake($sanitizedPostData, $model);
     } else {
         $explicitReadWriteModelPermissions = null;
     }
     $readyToUseData = ExplicitReadWriteModelPermissionsUtil::removeIfExistsFromPostData($sanitizedPostData);
     $sanitizedOwnerData = PostUtil::sanitizePostDataToJustHavingElementForSavingModel($readyToUseData, 'owner');
     $sanitizedDataWithoutOwner = PostUtil::removeElementFromPostDataForSavingModel($readyToUseData, 'owner');
     $model->setAttributes($sanitizedDataWithoutOwner);
     if ($model->validate()) {
         $modelToStringValue = strval($model);
         if ($sanitizedOwnerData != null) {
             $model->setAttributes($sanitizedOwnerData);
         }
         if ($model instanceof OwnedSecurableItem) {
             $passedOwnerValidation = $model->validate(array('owner'));
         } else {
             $passedOwnerValidation = true;
         }
         if ($passedOwnerValidation && $model->save(false)) {
             if ($explicitReadWriteModelPermissions != null) {
                 $success = ExplicitReadWriteModelPermissionsUtil::resolveExplicitReadWriteModelPermissions($model, $explicitReadWriteModelPermissions);
                 //todo: handle if success is false, means adding/removing permissions save failed.
             }
             $savedSuccessfully = true;
         }
     } else {
     }
     $this->assertEquals('ProductPermissionTest', $model->name);
 }
Example #25
0
 protected function attemptToUpdateActiveCurrenciesFromPostAndGetMessageBoxContent()
 {
     if (isset($_POST['CurrencyCollection'])) {
         $currencyCollectionActiveData = $_POST['CurrencyCollection'];
         $atLeastOneCurrencyIsActive = false;
         foreach ($currencyCollectionActiveData as $currencyCode => $currencyData) {
             assert('isset($currencyData["active"])');
             if ($currencyData['active']) {
                 $atLeastOneCurrencyIsActive = true;
             }
         }
         if (!$atLeastOneCurrencyIsActive) {
             Yii::app()->user->setFlash('notification', Zurmo::t('ZurmoModule', 'You must have at least one active currency.'));
         } else {
             foreach ($currencyCollectionActiveData as $currencyCode => $currencyData) {
                 $currency = Currency::getByCode($currencyCode);
                 if ($currencyData['active']) {
                     $currency->active = 1;
                 } else {
                     $currency->active = 0;
                 }
                 $saved = $currency->save();
                 assert('$saved');
             }
             Yii::app()->user->setFlash('notification', Zurmo::t('ZurmoModule', 'Changes to active currencies saved successfully.'));
         }
     }
 }
 /**
  * @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);
 }
 /**
  * Resolve the active currency for the current user.  If the user does not have a currency, it will fall back
  * to the base system currency.  If the base system currency does not exist, it will attempt to make it.
  * @throws NotSupportedException
  */
 public function getActiveCurrencyForCurrentUser()
 {
     if (Yii::app()->user->userModel->currency->id > 0) {
         return Yii::app()->user->userModel->currency;
     }
     try {
         $code = $this->getBaseCode();
         if (null != ($currency = Currency::getCachedCurrencyByCode($code))) {
             return $currency;
         }
         $currency = Currency::getByCode($code);
     } catch (NotFoundException $e) {
         $currency = Currency::makeBaseCurrency();
     }
     if ($currency->id <= 0) {
         throw new NotSupportedException();
     }
     Currency::setCachedCurrency($currency);
     return $currency;
 }