public function testSanitizeValueBySanitizerTypesForPasswordTypeThatIsNotRequired()
 {
     //Test a non-required password with no value or default value.
     $importSanitizeResultsUtil = new ImportSanitizeResultsUtil();
     $columnMappingData = array('type' => 'importColumn', 'mappingRulesData' => array('PasswordDefaultValueModelAttributeMappingRuleForm' => array('defaultValue' => null)));
     $sanitizerUtilTypes = PasswordAttributeImportRules::getSanitizerUtilTypesInProcessingOrder();
     $sanitizedValue = ImportSanitizerUtil::sanitizeValueBySanitizerTypes($sanitizerUtilTypes, 'User', 'hash', null, 'column_0', $columnMappingData, $importSanitizeResultsUtil);
     $this->assertNull($sanitizedValue);
     $this->assertTrue($importSanitizeResultsUtil->shouldSaveModel());
     $messages = $importSanitizeResultsUtil->getMessages();
     $this->assertEquals(0, count($messages));
     //Test a non-required password with a valid value, and a default value. The valid value should come through.
     $importSanitizeResultsUtil = new ImportSanitizeResultsUtil();
     $columnMappingData = array('type' => 'importColumn', 'mappingRulesData' => array('PasswordDefaultValueModelAttributeMappingRuleForm' => array('defaultValue' => 'something valid')));
     $sanitizerUtilTypes = PasswordAttributeImportRules::getSanitizerUtilTypesInProcessingOrder();
     $sanitizedValue = ImportSanitizerUtil::sanitizeValueBySanitizerTypes($sanitizerUtilTypes, 'User', 'hash', 'aValue', 'column_0', $columnMappingData, $importSanitizeResultsUtil);
     $this->assertEquals('aValue', $sanitizedValue);
     $this->assertTrue($importSanitizeResultsUtil->shouldSaveModel());
     $messages = $importSanitizeResultsUtil->getMessages();
     $this->assertEquals(0, count($messages));
     //Test a non-required password with a value that is too long and no specified default value.
     $importSanitizeResultsUtil = new ImportSanitizeResultsUtil();
     $columnMappingData = array('type' => 'importColumn', 'mappingRulesData' => array('PasswordDefaultValueModelAttributeMappingRuleForm' => array('defaultValue' => null)));
     $sanitizerUtilTypes = PasswordAttributeImportRules::getSanitizerUtilTypesInProcessingOrder();
     $value = self::getStringByLength(85);
     $sanitizedValue = ImportSanitizerUtil::sanitizeValueBySanitizerTypes($sanitizerUtilTypes, 'User', 'hash', $value, 'column_0', $columnMappingData, $importSanitizeResultsUtil);
     $this->assertEquals(substr($value, 0, 32), $sanitizedValue);
     $this->assertTrue($importSanitizeResultsUtil->shouldSaveModel());
     $messages = $importSanitizeResultsUtil->getMessages();
     $this->assertEquals(0, count($messages));
 }
 /**
  * Given a value and mapping data, run each sanitizer and process any messages or error information into the
  * ImportSanitizeResultsUtil object provided.
  * @param mixed $value
  * @param array $columnMappingData
  * @param object $importSanitizeResultsUtil
  */
 public function resolveValueForImport($value, $columnMappingData, ImportSanitizeResultsUtil $importSanitizeResultsUtil)
 {
     assert('is_array($columnMappingData)');
     $modelClassName = $this->getModelClassName();
     $value = ImportSanitizerUtil::sanitizeValueBySanitizerTypes(static::getSanitizerUtilTypesInProcessingOrder(), $this->getModelClassName(), $this->getModelAttributeName(), $value, $columnMappingData, $importSanitizeResultsUtil);
     return array($this->getModelAttributeName() => $value);
 }
 /**
  * Given an 'id' value, sanitize this value based on the id being either a zurmo model id or an external
  * system id.  This methods requires that there is only one sanitizer type to process.
  * (non-PHPdoc)
  * @see NonDerivedAttributeImportRules::resolveValueForImport()
  */
 public function resolveValueForImport($value, $columnName, $columnMappingData, ImportSanitizeResultsUtil $importSanitizeResultsUtil)
 {
     assert('is_string($columnName)');
     assert('is_array($columnMappingData)');
     $sanitizerUtilTypes = static::getSanitizerUtilTypesInProcessingOrder();
     if (count($sanitizerUtilTypes) == 1 && $sanitizerUtilTypes[0] == 'SelfIdValueType') {
         $modelClassName = $this->getModelClassName();
         try {
             $value = ImportSanitizerUtil::sanitizeValueBySanitizerTypes(static::getSanitizerUtilTypesInProcessingOrder(), $this->getModelClassName(), $this->getModelAttributeName(), $value, $columnName, $columnMappingData, $importSanitizeResultsUtil);
             if ($value != null) {
                 return array($this->getModelAttributeName() => $value);
             } else {
                 return array();
             }
         } catch (ExternalSystemIdNotFoundException $e) {
             if ($value != null) {
                 return array(ExternalSystemIdUtil::EXTERNAL_SYSTEM_ID_COLUMN_NAME => $value);
             } else {
                 return array();
             }
         }
     } else {
         throw new NotSupportedException();
     }
 }
 /**
  * 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);
 }
 public function resolveValueForImport($value, $columnMappingData, ImportSanitizeResultsUtil $importSanitizeResultsUtil)
 {
     $attributeNames = $this->getRealModelAttributeNames();
     assert('count($attributeNames) == 1');
     assert('$attributeNames[0] == "state"');
     $modelClassName = $this->getModelClassName();
     $value = ImportSanitizerUtil::sanitizeValueBySanitizerTypes(static::getSanitizerUtilTypesInProcessingOrder(), $modelClassName, null, $value, $columnMappingData, $importSanitizeResultsUtil);
     return array('state' => $value);
 }
 public function resolveValueForImport($value, $columnMappingData, ImportSanitizeResultsUtil $importSanitizeResultsUtil)
 {
     $modelClassName = $this->getModelClassName();
     $derivedModelClassName = static::getDerivedModelClassName();
     $sanitizedValue = ImportSanitizerUtil::sanitizeValueBySanitizerTypes(static::getSanitizerUtilTypesInProcessingOrder(), $modelClassName, null, $value, $columnMappingData, $importSanitizeResultsUtil);
     if ($sanitizedValue == null && $columnMappingData['mappingRulesData']['DefaultModelNameIdDerivedAttributeMappingRuleForm']['defaultModelId'] != null) {
         $modelId = $columnMappingData['mappingRulesData']['DefaultModelNameIdDerivedAttributeMappingRuleForm']['defaultModelId'];
         $sanitizedValue = $derivedModelClassName::getById((int) $modelId);
     }
     return array(static::getDerivedAttributeName() => $sanitizedValue);
 }
 public function resolveValueForImport($value, $columnMappingData, ImportSanitizeResultsUtil $importSanitizeResultsUtil)
 {
     $attributeNames = $this->getRealModelAttributeNames();
     assert('$attributeNames[0] == "firstName"');
     assert('$attributeNames[1] == "lastName"');
     $modelClassName = $this->getModelClassName();
     $sanitizedValue = ImportSanitizerUtil::sanitizeValueBySanitizerTypes(static::getSanitizerUtilTypesInProcessingOrder(), $modelClassName, null, $value, $columnMappingData, $importSanitizeResultsUtil);
     @(list($firstName, $lastName) = explode(' ', trim($sanitizedValue)));
     if ($lastName == null) {
         $lastName = $firstName;
         $firstName = null;
     }
     return array('firstName' => $firstName, 'lastName' => $lastName);
 }
 public function resolveValueForImport($value, $columnMappingData, ImportSanitizeResultsUtil $importSanitizeResultsUtil)
 {
     assert('is_array($columnMappingData)');
     $modelClassName = $this->getModelClassName();
     $value = ImportSanitizerUtil::sanitizeValueBySanitizerTypes(static::getSanitizerUtilTypesInProcessingOrder(), $modelClassName, null, $value, $columnMappingData, $importSanitizeResultsUtil);
     if ($value == null) {
         $mappingRuleFormClassName = 'UserStatusDefaultValueMappingRuleForm';
         $mappingRuleData = $columnMappingData['mappingRulesData'][$mappingRuleFormClassName];
         assert('$mappingRuleData != null');
         if (isset($mappingRuleData['defaultValue'])) {
             $value = $mappingRuleData['defaultValue'];
         } else {
             //The default value dropdown will be either active or inactive. There is no blank.
             throw new NotSupportedException();
         }
     }
     return array('status' => $value);
 }
 public function resolveValueForImport($value, $columnMappingData, ImportSanitizeResultsUtil $importSanitizeResultsUtil)
 {
     $attributeNames = $this->getRealModelAttributeNames();
     assert('count($attributeNames) == 1');
     assert('$attributeNames[0] == "hash"');
     assert('is_array($columnMappingData)');
     $modelClassName = $this->getModelClassName();
     $value = ImportSanitizerUtil::sanitizeValueBySanitizerTypes(static::getSanitizerUtilTypesInProcessingOrder(), $modelClassName, 'hash', $value, $columnMappingData, $importSanitizeResultsUtil);
     if ($value == null) {
         $mappingRuleFormClassName = 'PasswordDefaultValueModelAttributeMappingRuleForm';
         $mappingRuleData = $columnMappingData['mappingRulesData'][$mappingRuleFormClassName];
         assert('$mappingRuleData != null');
         if (isset($mappingRuleData['defaultValue'])) {
             $value = $mappingRuleData['defaultValue'];
         }
     }
     return array('hash' => md5($value));
 }
 public function testSanitizeValueBySanitizerTypesForContactStateTypeThatIsRequired()
 {
     $contactStates = ContactState::getAll();
     $this->assertEquals(6, count($contactStates));
     //Test a required contact state with no value or default value.
     $importSanitizeResultsUtil = new ImportSanitizeResultsUtil();
     $columnMappingData = array('type' => 'importColumn', 'mappingRulesData' => array('DefaultContactStateIdMappingRuleForm' => array('defaultStateId' => null)));
     $sanitizerUtilTypes = ContactStateAttributeImportRules::getSanitizerUtilTypesInProcessingOrder();
     $sanitizedValue = ImportSanitizerUtil::sanitizeValueBySanitizerTypes($sanitizerUtilTypes, 'Contact', null, null, 'column_0', $columnMappingData, $importSanitizeResultsUtil);
     $this->assertNull($sanitizedValue);
     $this->assertFalse($importSanitizeResultsUtil->shouldSaveModel());
     $messages = $importSanitizeResultsUtil->getMessages();
     $this->assertEquals(1, count($messages));
     $compareMessage = 'Contact - The status is required.  Neither a value nor a default was specified.';
     $this->assertEquals($compareMessage, $messages[0]);
     //Test a required contact state with a valid value, and a default value. The valid value should come through.
     $importSanitizeResultsUtil = new ImportSanitizeResultsUtil();
     $columnMappingData = array('type' => 'importColumn', 'mappingRulesData' => array('DefaultContactStateIdMappingRuleForm' => array('defaultStateId' => $contactStates[4]->id)));
     $sanitizerUtilTypes = ContactStateAttributeImportRules::getSanitizerUtilTypesInProcessingOrder();
     $sanitizedValue = ImportSanitizerUtil::sanitizeValueBySanitizerTypes($sanitizerUtilTypes, 'Contact', null, $contactStates[5]->id, 'column_0', $columnMappingData, $importSanitizeResultsUtil);
     $this->assertEquals($contactStates[5], $sanitizedValue);
     $this->assertTrue($importSanitizeResultsUtil->shouldSaveModel());
     $messages = $importSanitizeResultsUtil->getMessages();
     $this->assertEquals(0, count($messages));
     //Test a required contact state with no value, and a default value.
     $importSanitizeResultsUtil = new ImportSanitizeResultsUtil();
     $columnMappingData = array('type' => 'importColumn', 'mappingRulesData' => array('DefaultContactStateIdMappingRuleForm' => array('defaultStateId' => $contactStates[4]->id)));
     $sanitizerUtilTypes = ContactStateAttributeImportRules::getSanitizerUtilTypesInProcessingOrder();
     $sanitizedValue = ImportSanitizerUtil::sanitizeValueBySanitizerTypes($sanitizerUtilTypes, 'Contact', null, null, 'column_0', $columnMappingData, $importSanitizeResultsUtil);
     $this->assertEquals($contactStates[4], $sanitizedValue);
     $this->assertTrue($importSanitizeResultsUtil->shouldSaveModel());
     $messages = $importSanitizeResultsUtil->getMessages();
     $this->assertEquals(0, count($messages));
     //Test a required contact state with a value that is invalid
     $importSanitizeResultsUtil = new ImportSanitizeResultsUtil();
     $columnMappingData = array('type' => 'importColumn', 'mappingRulesData' => array('DefaultContactStateIdMappingRuleForm' => array('defaultValue' => null)));
     $sanitizerUtilTypes = ContactStateAttributeImportRules::getSanitizerUtilTypesInProcessingOrder();
     $sanitizedValue = ImportSanitizerUtil::sanitizeValueBySanitizerTypes($sanitizerUtilTypes, 'Contact', null, 'somethingnotright', 'column_0', $columnMappingData, $importSanitizeResultsUtil);
     $this->assertFalse($importSanitizeResultsUtil->shouldSaveModel());
     $messages = $importSanitizeResultsUtil->getMessages();
     $this->assertEquals(1, count($messages));
     $compareMessage = 'Contact - Status specified does not exist.';
     $this->assertEquals($compareMessage, $messages[0]);
     //Test a required contact state with a state that is for leads, not contacts.
     $importSanitizeResultsUtil = new ImportSanitizeResultsUtil();
     $columnMappingData = array('type' => 'importColumn', 'mappingRulesData' => array('DefaultContactStateIdMappingRuleForm' => array('defaultValue' => null)));
     $sanitizerUtilTypes = ContactStateAttributeImportRules::getSanitizerUtilTypesInProcessingOrder();
     $sanitizedValue = ImportSanitizerUtil::sanitizeValueBySanitizerTypes($sanitizerUtilTypes, 'Contact', null, $contactStates[1]->id, 'column_0', $columnMappingData, $importSanitizeResultsUtil);
     $this->assertFalse($importSanitizeResultsUtil->shouldSaveModel());
     $messages = $importSanitizeResultsUtil->getMessages();
     $this->assertEquals(1, count($messages));
     $compareMessage = 'Contact - Status specified is invalid.';
     $this->assertEquals($compareMessage, $messages[0]);
 }
 /**
  * Given a value and mapping data, run each sanitizer and process any messages or error information into the
  * ImportSanitizeResultsUtil object provided.
  * @param mixed $value
  * @param string $columnName
  * @param array $columnMappingData
  * @param ImportSanitizeResultsUtil $importSanitizeResultsUtil
  * @return mixed $value
  */
 public function resolveValueForImport($value, $columnName, $columnMappingData, ImportSanitizeResultsUtil $importSanitizeResultsUtil)
 {
     assert('is_string($columnName)');
     assert('is_array($columnMappingData)');
     $modelClassName = $this->getModelClassName();
     $value = ImportSanitizerUtil::sanitizeValueBySanitizerTypes(static::getSanitizerUtilTypesInProcessingOrder(), $this->getModelClassName(), $this->getModelAttributeName(), $value, $columnName, $columnMappingData, $importSanitizeResultsUtil, $this->penultimateModelClassName, $this->penultimateAttributeName, $this->getExplicitReadWriteModelPermissions());
     return array($this->getModelAttributeName() => $value);
 }
예제 #12
0
 public function testSanitizeValueBySanitizerTypesForUserTypeThatIsRequired()
 {
     $billy = UserTestHelper::createBasicUser('billy');
     $jimmy = UserTestHelper::createBasicUser('jimmy');
     $sally = UserTestHelper::createBasicUser('sally');
     //Update the external system id.
     $columnName = ExternalSystemIdUtil::EXTERNAL_SYSTEM_ID_COLUMN_NAME;
     RedBeanColumnTypeOptimizer::externalIdColumn(User::getTableName('User'), $columnName);
     $externalSystemIdColumnName = ExternalSystemIdUtil::EXTERNAL_SYSTEM_ID_COLUMN_NAME;
     R::exec("update " . User::getTableName('User') . " set {$externalSystemIdColumnName} = 'K' where id = {$jimmy->id}");
     //Test a required user with no value or default value.
     $importSanitizeResultsUtil = new ImportSanitizeResultsUtil();
     $columnMappingData = array('type' => 'importColumn', 'mappingRulesData' => array('DefaultModelNameIdMappingRuleForm' => array('defaultModelId' => null), 'UserValueTypeModelAttributeMappingRuleForm' => array('type' => UserValueTypeModelAttributeMappingRuleForm::ZURMO_USER_ID)));
     $sanitizerUtilTypes = UserAttributeImportRules::getSanitizerUtilTypesInProcessingOrder();
     $sanitizedValue = ImportSanitizerUtil::sanitizeValueBySanitizerTypes($sanitizerUtilTypes, 'ImportModelTestItem', 'owner', null, 'column_0', $columnMappingData, $importSanitizeResultsUtil);
     $this->assertNull($sanitizedValue);
     $this->assertFalse($importSanitizeResultsUtil->shouldSaveModel());
     $messages = $importSanitizeResultsUtil->getMessages();
     $this->assertEquals(1, count($messages));
     $compareMessage = 'Import - Owner Id is required and was not specified.';
     $this->assertEquals($compareMessage, $messages[0]);
     //Test a required string with no value, but a valid default value, a user id.
     $importSanitizeResultsUtil = new ImportSanitizeResultsUtil();
     $columnMappingData = array('type' => 'importColumn', 'mappingRulesData' => array('DefaultModelNameIdMappingRuleForm' => array('defaultModelId' => $billy->id), 'UserValueTypeModelAttributeMappingRuleForm' => array('type' => UserValueTypeModelAttributeMappingRuleForm::ZURMO_USER_ID)));
     $sanitizerUtilTypes = UserAttributeImportRules::getSanitizerUtilTypesInProcessingOrder();
     $sanitizedValue = ImportSanitizerUtil::sanitizeValueBySanitizerTypes($sanitizerUtilTypes, 'ImportModelTestItem', 'owner', null, 'column_0', $columnMappingData, $importSanitizeResultsUtil);
     $this->assertEquals($billy, $sanitizedValue);
     $this->assertTrue($importSanitizeResultsUtil->shouldSaveModel());
     $messages = $importSanitizeResultsUtil->getMessages();
     $this->assertEquals(0, count($messages));
     //Test a required string with a valid user id.
     $importSanitizeResultsUtil = new ImportSanitizeResultsUtil();
     $columnMappingData = array('type' => 'importColumn', 'mappingRulesData' => array('DefaultModelNameIdMappingRuleForm' => array('defaultModelId' => null), 'UserValueTypeModelAttributeMappingRuleForm' => array('type' => UserValueTypeModelAttributeMappingRuleForm::ZURMO_USER_ID)));
     $sanitizerUtilTypes = UserAttributeImportRules::getSanitizerUtilTypesInProcessingOrder();
     $sanitizedValue = ImportSanitizerUtil::sanitizeValueBySanitizerTypes($sanitizerUtilTypes, 'ImportModelTestItem', 'owner', $billy->id, 'column_0', $columnMappingData, $importSanitizeResultsUtil);
     $this->assertEquals($billy, $sanitizedValue);
     $this->assertTrue($importSanitizeResultsUtil->shouldSaveModel());
     $messages = $importSanitizeResultsUtil->getMessages();
     $this->assertEquals(0, count($messages));
     //Test a required string with a valid external system user id.
     $importSanitizeResultsUtil = new ImportSanitizeResultsUtil();
     $columnMappingData = array('type' => 'importColumn', 'mappingRulesData' => array('DefaultModelNameIdMappingRuleForm' => array('defaultModelId' => null), 'UserValueTypeModelAttributeMappingRuleForm' => array('type' => UserValueTypeModelAttributeMappingRuleForm::EXTERNAL_SYSTEM_USER_ID)));
     $sanitizerUtilTypes = UserAttributeImportRules::getSanitizerUtilTypesInProcessingOrder();
     $sanitizedValue = ImportSanitizerUtil::sanitizeValueBySanitizerTypes($sanitizerUtilTypes, 'ImportModelTestItem', 'owner', 'K', 'column_0', $columnMappingData, $importSanitizeResultsUtil);
     $this->assertEquals($jimmy, $sanitizedValue);
     $this->assertTrue($importSanitizeResultsUtil->shouldSaveModel());
     $messages = $importSanitizeResultsUtil->getMessages();
     $this->assertEquals(0, count($messages));
     //Test a required string with a valid username.
     $importSanitizeResultsUtil = new ImportSanitizeResultsUtil();
     $columnMappingData = array('type' => 'importColumn', 'mappingRulesData' => array('DefaultModelNameIdMappingRuleForm' => array('defaultModelId' => null), 'UserValueTypeModelAttributeMappingRuleForm' => array('type' => UserValueTypeModelAttributeMappingRuleForm::ZURMO_USERNAME)));
     $sanitizerUtilTypes = UserAttributeImportRules::getSanitizerUtilTypesInProcessingOrder();
     $sanitizedValue = ImportSanitizerUtil::sanitizeValueBySanitizerTypes($sanitizerUtilTypes, 'ImportModelTestItem', 'owner', 'sally', 'column_0', $columnMappingData, $importSanitizeResultsUtil);
     $this->assertEquals($sally, $sanitizedValue);
     $this->assertTrue($importSanitizeResultsUtil->shouldSaveModel());
     $messages = $importSanitizeResultsUtil->getMessages();
     $this->assertEquals(0, count($messages));
 }