Exemplo n.º 1
0
 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));
 }
Exemplo n.º 2
0
 public function testMakeColumnNamesAndAttributeIndexOrDerivedTypeLabels()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $mappingData = array('column_0' => array('type' => 'importColumn', 'attributeIndexOrDerivedType' => 'string', 'mappingRulesData' => null), 'column_1' => array('type' => 'importColumn', 'attributeIndexOrDerivedType' => null, 'mappingRulesData' => null), 'column_2' => array('type' => 'importColumn', 'attributeIndexOrDerivedType' => 'FullName', 'mappingRulesData' => null));
     $data = ImportMappingUtil::makeColumnNamesAndAttributeIndexOrDerivedTypeLabels($mappingData, 'ImportModelTestItem');
     $compareData = array('column_0' => 'String', 'column_1' => null, 'column_2' => 'Full Name');
     $this->assertEquals($compareData, $data);
 }
Exemplo n.º 3
0
 public function testSimpleUserImportWhereAllRowsSucceed()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $tasks = Task::getAll();
     $this->assertEquals(0, count($tasks));
     $import = new Import();
     $serializedData['importRulesType'] = 'Tasks';
     $serializedData['firstRowIsHeaderRow'] = true;
     $import->serializedData = serialize($serializedData);
     $this->assertTrue($import->save());
     ImportTestHelper::createTempTableByFileNameAndTableName('simpleImportTest.csv', $import->getTempTableName(), Yii::getPathOfAlias('application.modules.tasks.tests.unit.files'));
     $this->assertEquals(4, ImportDatabaseUtil::getCount($import->getTempTableName()));
     // includes header rows.
     $mappingData = array('column_0' => ImportMappingUtil::makeStringColumnMappingData('name'), 'column_1' => ImportMappingUtil::makeDateTimeColumnMappingData('dueDateTime'), 'column_2' => ImportMappingUtil::makeDateTimeColumnMappingData('completedDateTime'), 'column_3' => ImportMappingUtil::makeBooleanColumnMappingData('completed'), 'column_4' => ImportMappingUtil::makeModelDerivedColumnMappingData('AccountDerived'), 'column_5' => ImportMappingUtil::makeModelDerivedColumnMappingData('ContactDerived'), 'column_6' => ImportMappingUtil::makeModelDerivedColumnMappingData('OpportunityDerived'), 'column_7' => ImportMappingUtil::makeTextAreaColumnMappingData('description'));
     $importRules = ImportRulesUtil::makeImportRulesByType('Tasks');
     $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);
     $actionDateTime = substr(DateTimeUtil::convertTimestampToDbFormatDateTime(time()), 0, -3);
     $messageLogger = new ImportMessageLogger();
     ImportUtil::importByDataProvider($dataProvider, $importRules, $mappingData, $importResultsUtil, new ExplicitReadWriteModelPermissions(), $messageLogger);
     $importResultsUtil->processStatusAndMessagesForEachRow();
     //Confirm that 3 models where created.
     $tasks = Task::getAll();
     $this->assertEquals(3, count($tasks));
     $tasks = Task::getByName('task1');
     $this->assertEquals(1, count($tasks[0]));
     $this->assertEquals(1, count($tasks[0]->activityItems));
     $this->assertEquals('testAccount', $tasks[0]->activityItems[0]->name);
     $this->assertEquals('Account', get_class($tasks[0]->activityItems[0]));
     $this->assertNull($tasks[0]->completed);
     $this->assertEquals($actionDateTime, substr($tasks[0]->latestDateTime, 0, -3));
     $tasks = Task::getByName('task2');
     $this->assertEquals(1, count($tasks[0]));
     $this->assertEquals(1, count($tasks[0]->activityItems));
     $this->assertEquals('testContact', $tasks[0]->activityItems[0]->firstName);
     $this->assertEquals('Contact', get_class($tasks[0]->activityItems[0]));
     $this->assertEquals(1, $tasks[0]->completed);
     $this->assertEquals('2011-12-22 06:03', substr($tasks[0]->latestDateTime, 0, -3));
     $tasks = Task::getByName('task3');
     $this->assertEquals(1, count($tasks[0]));
     $this->assertEquals(1, count($tasks[0]->activityItems));
     $this->assertEquals('testOpportunity', $tasks[0]->activityItems[0]->name);
     $this->assertEquals('Opportunity', get_class($tasks[0]->activityItems[0]));
     $this->assertNull($tasks[0]->completed);
     $this->assertEquals($actionDateTime, substr($tasks[0]->latestDateTime, 0, -3));
     //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));
 }
 public function testSimpleUserImportWhereAllRowsSucceed()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $import = new Import();
     $serializedData['importRulesType'] = 'ProductTemplates';
     $serializedData['firstRowIsHeaderRow'] = true;
     $import->serializedData = serialize($serializedData);
     $this->assertTrue($import->save());
     ImportTestHelper::createTempTableByFileNameAndTableName('productTemplates.csv', $import->getTempTableName(), Yii::getPathOfAlias('application.modules.productTemplates.tests.unit.files'));
     $this->assertEquals(3, ImportDatabaseUtil::getCount($import->getTempTableName()));
     // includes header rows.
     $currencies = Currency::getAll();
     $mappingData = array('column_0' => ImportMappingUtil::makeStringColumnMappingData('name'), 'column_1' => ImportMappingUtil::makeTextAreaColumnMappingData('description'), 'column_2' => ImportMappingUtil::makeIntegerColumnMappingData('sellPriceFormula__type'), 'column_3' => ImportMappingUtil::makeFloatColumnMappingData('sellPriceFormula__discountOrMarkupPercentage'), 'column_4' => ImportMappingUtil::makeCurrencyColumnMappingData('cost', $currencies[0]), 'column_5' => ImportMappingUtil::makeCurrencyColumnMappingData('listPrice', $currencies[0]), 'column_6' => ImportMappingUtil::makeCurrencyColumnMappingData('sellPrice', $currencies[0]), 'column_7' => ImportMappingUtil::makeIntegerColumnMappingData('priceFrequency'), 'column_8' => ImportMappingUtil::makeIntegerColumnMappingData('type'), 'column_9' => ImportMappingUtil::makeIntegerColumnMappingData('status'));
     $importRules = ImportRulesUtil::makeImportRulesByType('ProductTemplates');
     $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.
     $productTemplates = ProductTemplate::getAll();
     $this->assertEquals(2, count($productTemplates));
     $productTemplates = ProductTemplate::getByName('A Gift of Monotheists import');
     $this->assertEquals(1, count($productTemplates[0]));
     $this->assertEquals('A Gift of Monotheists import', $productTemplates[0]->name);
     $this->assertEquals(2, $productTemplates[0]->sellPriceFormula->type);
     $this->assertEquals(10, $productTemplates[0]->sellPriceFormula->discountOrMarkupPercentage);
     $this->assertEquals(180, $productTemplates[0]->sellPrice->value);
     $this->assertEquals(200, $productTemplates[0]->listPrice->value);
     $this->assertEquals(200, $productTemplates[0]->cost->value);
     $this->assertEquals(2, $productTemplates[0]->priceFrequency);
     $this->assertEquals(2, $productTemplates[0]->type);
     $this->assertEquals(2, $productTemplates[0]->status);
     $productTemplates[0]->delete();
     $productTemplates = ProductTemplate::getByName('A Gift of Monotheists import Copy');
     $this->assertEquals(1, count($productTemplates[0]));
     $this->assertEquals('A Gift of Monotheists import Copy', $productTemplates[0]->name);
     $this->assertEquals(2, $productTemplates[0]->sellPriceFormula->type);
     $this->assertEquals(5, $productTemplates[0]->sellPriceFormula->discountOrMarkupPercentage);
     $this->assertEquals(180, $productTemplates[0]->sellPrice->value);
     $this->assertEquals(200, $productTemplates[0]->listPrice->value);
     $this->assertEquals(200, $productTemplates[0]->cost->value);
     $this->assertEquals(2, $productTemplates[0]->priceFrequency);
     $this->assertEquals(2, $productTemplates[0]->type);
     $this->assertEquals(2, $productTemplates[0]->status);
     $productTemplates[0]->delete();
     //Confirm that 2 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));
 }
 public function testSimpleUserImportWhereAllRowsSucceed()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $account = AccountTestHelper::createAccountByNameForOwner('Account', Yii::app()->user->userModel);
     $contact = ContactTestHelper::createContactByNameForOwner('Contact', Yii::app()->user->userModel);
     $accountContactAffiliations = AccountContactAffiliation::getAll();
     $this->assertEquals(0, count($accountContactAffiliations));
     $import = new Import();
     $serializedData['importRulesType'] = 'AccountContactAffiliations';
     $serializedData['firstRowIsHeaderRow'] = true;
     $import->serializedData = serialize($serializedData);
     $this->assertTrue($import->save());
     ImportTestHelper::createTempTableByFileNameAndTableName('importTest.csv', $import->getTempTableName(), true, Yii::getPathOfAlias('application.modules.accountContactAffiliations.tests.unit.files'));
     //update the ids of the account column to match the parent account.
     ZurmoRedBean::exec("update " . $import->getTempTableName() . " set column_2 = " . $account->id . " where id != 1 limit 4");
     ZurmoRedBean::exec("update " . $import->getTempTableName() . " set column_1 = " . $contact->id . " where id != 1 limit 4");
     $this->assertEquals(4, ImportDatabaseUtil::getCount($import->getTempTableName()));
     // includes header rows.
     $mappingData = array('column_0' => ImportMappingUtil::makeDropDownColumnMappingData('role'), 'column_1' => ImportMappingUtil::makeHasOneColumnMappingData('contact'), 'column_2' => ImportMappingUtil::makeHasOneColumnMappingData('account'));
     $importRules = ImportRulesUtil::makeImportRulesByType('AccountContactAffiliations');
     $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.
     $accountContactAffiliations = AccountContactAffiliation::getAll();
     $this->assertEquals(3, count($accountContactAffiliations));
     $this->assertEquals('0', $accountContactAffiliations[0]->primary);
     $this->assertTrue($accountContactAffiliations[0]->account->isSame($account));
     $this->assertTrue($accountContactAffiliations[0]->contact->isSame($contact));
     $this->assertEquals('', $accountContactAffiliations[0]->role->value);
     $this->assertEquals('0', $accountContactAffiliations[1]->primary);
     $this->assertTrue($accountContactAffiliations[1]->account->isSame($account));
     $this->assertTrue($accountContactAffiliations[1]->contact->isSame($contact));
     $this->assertEquals('Support', $accountContactAffiliations[1]->role->value);
     $this->assertEquals('0', $accountContactAffiliations[2]->primary);
     $this->assertTrue($accountContactAffiliations[2]->account->isSame($account));
     $this->assertTrue($accountContactAffiliations[2]->contact->isSame($contact));
     $this->assertEquals('Technical', $accountContactAffiliations[2]->role->value);
     //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));
 }
 public function testImportDataAnalysisResults()
 {
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $import = new Import();
     $serializedData['importRulesType'] = 'Tasks';
     $import->serializedData = serialize($serializedData);
     $this->assertTrue($import->save());
     $accountTableName = Account::getTableName('Account');
     $contactTableName = Contact::getTableName('Contact');
     $opportunityTableName = Opportunity::getTableName('Opportunity');
     $account1 = AccountTestHelper::createAccountByNameForOwner('account1', $super);
     $account2 = AccountTestHelper::createAccountByNameForOwner('account2', $super);
     $account3 = AccountTestHelper::createAccountByNameForOwner('account3', $super);
     $contact1 = ContactTestHelper::createContactByNameForOwner('contact1', $super);
     $contact2 = ContactTestHelper::createContactByNameForOwner('contact2', $super);
     $contact3 = ContactTestHelper::createContactByNameForOwner('contact3', $super);
     $opportunity1 = OpportunityTestHelper::createOpportunityByNameForOwner('opportunity1', $super);
     $opportunity2 = OpportunityTestHelper::createOpportunityByNameForOwner('opportunity2', $super);
     $opportunity3 = OpportunityTestHelper::createOpportunityByNameForOwner('opportunity3', $super);
     //Make models externally linked for testing.
     ImportTestHelper::updateModelsExternalId($account2, 'ACC');
     ImportTestHelper::updateModelsExternalId($contact2, 'CON');
     ImportTestHelper::updateModelsExternalId($opportunity2, 'OPP');
     ImportTestHelper::createTempTableByFileNameAndTableName('importAnalyzerTest.csv', $import->getTempTableName(), Yii::getPathOfAlias('application.modules.tasks.tests.unit.files'));
     R::exec("update " . $import->getTempTableName() . " set column_0 = " . $account3->id . " where id != 1 limit 3");
     R::exec("update " . $import->getTempTableName() . " set column_2 = " . $contact3->id . " where id != 1 limit 4");
     R::exec("update " . $import->getTempTableName() . " set column_4 = " . $opportunity3->id . " where id != 1 limit 5");
     $mappingData = array('column_0' => ImportMappingUtil::makeModelDerivedColumnMappingData('AccountDerived', IdValueTypeMappingRuleForm::ZURMO_MODEL_ID), 'column_1' => ImportMappingUtil::makeModelDerivedColumnMappingData('AccountDerived'), 'column_2' => ImportMappingUtil::makeModelDerivedColumnMappingData('ContactDerived', IdValueTypeMappingRuleForm::ZURMO_MODEL_ID), 'column_3' => ImportMappingUtil::makeModelDerivedColumnMappingData('ContactDerived'), 'column_4' => ImportMappingUtil::makeModelDerivedColumnMappingData('OpportunityDerived', IdValueTypeMappingRuleForm::ZURMO_MODEL_ID), 'column_5' => ImportMappingUtil::makeModelDerivedColumnMappingData('OpportunityDerived'));
     $serializedData = unserialize($import->serializedData);
     $serializedData['mappingData'] = $mappingData;
     $import->serializedData = serialize($serializedData);
     $this->assertTrue($import->save());
     $importRules = ImportRulesUtil::makeImportRulesByType('Tasks');
     $config = array('pagination' => array('pageSize' => 2));
     //This test csv has a header row.
     $dataProvider = new ImportDataProvider($import->getTempTableName(), true, $config);
     //Run data analyzer
     $importDataAnalyzer = new ImportDataAnalyzer($importRules, $dataProvider);
     foreach ($mappingData as $columnName => $columnMappingData) {
         $importDataAnalyzer->analyzeByColumnNameAndColumnMappingData($columnName, $columnMappingData);
     }
     $messagesData = $importDataAnalyzer->getMessagesData();
     $compareData = array('column_0' => array(array('message' => '3 record(s) will be updated and 7 record(s) will be skipped during import.', 'sanitizerUtilType' => 'AccountDerivedIdValueType', 'moreAvailable' => false)), 'column_1' => array(array('message' => '3 record(s) will be updated and 7 record(s) will be skipped during import.', 'sanitizerUtilType' => 'AccountDerivedIdValueType', 'moreAvailable' => false)), 'column_2' => array(array('message' => '4 record(s) will be updated and 6 record(s) will be skipped during import.', 'sanitizerUtilType' => 'ContactDerivedIdValueType', 'moreAvailable' => false)), 'column_3' => array(array('message' => '3 record(s) will be updated and 7 record(s) will be skipped during import.', 'sanitizerUtilType' => 'ContactDerivedIdValueType', 'moreAvailable' => false)), 'column_4' => array(array('message' => '5 record(s) will be updated and 5 record(s) will be skipped during import.', 'sanitizerUtilType' => 'OpportunityDerivedIdValueType', 'moreAvailable' => false)), 'column_5' => array(array('message' => '3 record(s) will be updated and 7 record(s) will be skipped during import.', 'sanitizerUtilType' => 'OpportunityDerivedIdValueType', 'moreAvailable' => false)));
     $this->assertEquals($compareData, $messagesData);
     $importInstructionsData = $importDataAnalyzer->getImportInstructionsData();
     $compareInstructionsData = array();
     $this->assertEquals($compareInstructionsData, $importInstructionsData);
 }
Exemplo n.º 7
0
 public function testSimpleUserImportWhereAllRowsSucceed()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $import = new Import();
     $serializedData['importRulesType'] = 'Projects';
     $serializedData['firstRowIsHeaderRow'] = true;
     $import->serializedData = serialize($serializedData);
     $this->assertTrue($import->save());
     ImportTestHelper::createTempTableByFileNameAndTableName('projectsSample.csv', $import->getTempTableName(), true, Yii::getPathOfAlias('application.modules.projects.tests.unit.files'));
     $this->assertEquals(3, ImportDatabaseUtil::getCount($import->getTempTableName()));
     // includes header rows.
     $ownerColumnMappingData = array('attributeIndexOrDerivedType' => 'owner', 'type' => 'importColumn', 'mappingRulesData' => array('DefaultModelNameIdMappingRuleForm' => array('defaultModelId' => null), 'UserValueTypeModelAttributeMappingRuleForm' => array('type' => UserValueTypeModelAttributeMappingRuleForm::ZURMO_USERNAME)));
     $mappingData = array('column_0' => $ownerColumnMappingData, 'column_1' => ImportMappingUtil::makeStringColumnMappingData('name'), 'column_2' => ImportMappingUtil::makeTextAreaColumnMappingData('description'), 'column_3' => ImportMappingUtil::makeDropDownColumnMappingData('status'));
     $importRules = ImportRulesUtil::makeImportRulesByType('Projects');
     $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 2 models where created.
     $projects = Project::getAll();
     $this->assertEquals(2, count($projects));
     $projects = Project::getByName('My first project');
     $this->assertEquals(1, count($projects[0]));
     $this->assertEquals('super', $projects[0]->owner->username);
     $this->assertEquals('My first project', $projects[0]->name);
     $this->assertEquals(2, $projects[0]->status);
     //todo ask Jason for it
     //$this->assertEquals('My first project Desc',   $projects[0]->description);
     $projects[0]->delete();
     $projects = Project::getByName('My second project');
     $this->assertEquals(1, count($projects[0]));
     $this->assertEquals('super', $projects[0]->owner->username);
     $this->assertEquals('My second project', $projects[0]->name);
     $this->assertEquals(1, $projects[0]->status);
     //$this->assertEquals('My second project Desc',  $projects[0]->description);
     $projects[0]->delete();
     //Confirm that 2 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));
 }
 public function testResolveMappingDataForView()
 {
     $testTableName = 'testimporttable';
     $this->assertTrue(ImportTestHelper::createTempTableByFileNameAndTableName('importTest.csv', $testTableName, true));
     $mappingData = ImportMappingUtil::makeMappingDataByTableName($testTableName);
     $compareData = array('column_0' => array('type' => 'importColumn', 'attributeIndexOrDerivedType' => null, 'mappingRulesData' => null), 'column_1' => array('type' => 'importColumn', 'attributeIndexOrDerivedType' => null, 'mappingRulesData' => null), 'column_2' => array('type' => 'importColumn', 'attributeIndexOrDerivedType' => null, 'mappingRulesData' => null));
     $this->assertEquals($compareData, $mappingData);
     $mappingData['column_3'] = array('type' => 'extraColumn', 'attributeIndexOrDerivedType' => 'xyz', 'mappingRulesData' => null);
     $headerRow = ZurmoRedBean::$writer->getFirstRowByTableName($testTableName);
     $sampleBean = ImportDatabaseUtil::getSubset($testTableName, null, 1, 1);
     $mappingDataMetadata = ImportWizardMappingViewUtil::resolveMappingDataForView($mappingData, current($sampleBean), $headerRow);
     $compareData = array('column_0' => array('type' => 'importColumn', 'attributeIndexOrDerivedType' => null, 'mappingRulesData' => null, 'headerValue' => 'name', 'sampleValue' => 'abc'), 'column_1' => array('type' => 'importColumn', 'attributeIndexOrDerivedType' => null, 'mappingRulesData' => null, 'headerValue' => 'phone', 'sampleValue' => '123'), 'column_2' => array('type' => 'importColumn', 'attributeIndexOrDerivedType' => null, 'mappingRulesData' => null, 'headerValue' => 'industry', 'sampleValue' => 'a'), 'column_3' => array('type' => 'extraColumn', 'attributeIndexOrDerivedType' => 'xyz', 'mappingRulesData' => null, 'headerValue' => null, 'sampleValue' => null));
     $this->assertEquals($compareData, $mappingDataMetadata);
     $sampleBean = ImportDatabaseUtil::getSubset($testTableName, null, 1);
     $mappingDataMetadata = ImportWizardMappingViewUtil::resolveMappingDataForView($mappingData, current($sampleBean), null);
     $compareData = array('column_0' => array('type' => 'importColumn', 'attributeIndexOrDerivedType' => null, 'mappingRulesData' => null, 'sampleValue' => 'name'), 'column_1' => array('type' => 'importColumn', 'attributeIndexOrDerivedType' => null, 'mappingRulesData' => null, 'sampleValue' => 'phone'), 'column_2' => array('type' => 'importColumn', 'attributeIndexOrDerivedType' => null, 'mappingRulesData' => null, 'sampleValue' => 'industry'), 'column_3' => array('type' => 'extraColumn', 'attributeIndexOrDerivedType' => 'xyz', 'mappingRulesData' => null, 'sampleValue' => null));
     $this->assertEquals($compareData, $mappingDataMetadata);
 }
Exemplo n.º 9
0
 public function testSimpleUserImportWhereAllRowsSucceed()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $users = User::getAll();
     $this->assertEquals(1, count($users));
     $import = new Import();
     $serializedData['importRulesType'] = 'User';
     $serializedData['firstRowIsHeaderRow'] = true;
     $import->serializedData = serialize($serializedData);
     $this->assertTrue($import->save());
     ImportTestHelper::createTempTableByFileNameAndTableName('importAnalyzerTest.csv', $import->getTempTableName(), Yii::getPathOfAlias('application.modules.users.tests.unit.files'));
     $this->assertEquals(11, ImportDatabaseUtil::getCount($import->getTempTableName()));
     // includes header rows.
     $mappingData = array('column_0' => array('attributeIndexOrDerivedType' => 'username', 'type' => 'importColumn', 'mappingRulesData' => array()), 'column_1' => array('attributeIndexOrDerivedType' => 'Password', 'type' => 'importColumn', 'mappingRulesData' => array('PasswordDefaultValueModelAttributeMappingRuleForm' => array('defaultValue' => null))), 'column_2' => array('attributeIndexOrDerivedType' => 'UserStatus', 'type' => 'importColumn', 'mappingRulesData' => array('UserStatusDefaultValueMappingRuleForm' => array('defaultValue' => UserStatusUtil::ACTIVE))), 'column_3' => ImportMappingUtil::makeStringColumnMappingData('firstName'), 'column_4' => ImportMappingUtil::makeStringColumnMappingData('lastName'));
     $importRules = ImportRulesUtil::makeImportRulesByType('Users');
     $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 10 models where created.
     $users = User::getAll();
     $this->assertEquals(11, count($users));
     $activeUser = User::getByUsername('myusername7');
     $userStatus = UserStatusUtil::makeByUser($activeUser);
     $this->assertTrue($userStatus->isActive());
     $inactiveUser = User::getByUsername('myusername8');
     $userStatus = UserStatusUtil::makeByUser($inactiveUser);
     $this->assertFalse($userStatus->isActive());
     //Confirm 10 rows were processed as 'created'.
     $this->assertEquals(10, 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));
 }
Exemplo n.º 10
0
 /**
  * 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 testImportDataAnalysisResults()
 {
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $import = new Import();
     $serializedData['importRulesType'] = 'Tasks';
     $import->serializedData = serialize($serializedData);
     $this->assertTrue($import->save());
     $account1 = AccountTestHelper::createAccountByNameForOwner('account1', $super);
     $account2 = AccountTestHelper::createAccountByNameForOwner('account2', $super);
     $account3 = AccountTestHelper::createAccountByNameForOwner('account3', $super);
     $contact1 = ContactTestHelper::createContactByNameForOwner('contact1', $super);
     $contact2 = ContactTestHelper::createContactByNameForOwner('contact2', $super);
     $contact3 = ContactTestHelper::createContactByNameForOwner('contact3', $super);
     $opportunity1 = OpportunityTestHelper::createOpportunityByNameForOwner('opportunity1', $super);
     $opportunity2 = OpportunityTestHelper::createOpportunityByNameForOwner('opportunity2', $super);
     $opportunity3 = OpportunityTestHelper::createOpportunityByNameForOwner('opportunity3', $super);
     //Make models externally linked for testing.
     ImportTestHelper::updateModelsExternalId($account2, 'ACC');
     ImportTestHelper::updateModelsExternalId($contact2, 'CON');
     ImportTestHelper::updateModelsExternalId($opportunity2, 'OPP');
     ImportTestHelper::createTempTableByFileNameAndTableName('importAnalyzerTest.csv', $import->getTempTableName(), true, Yii::getPathOfAlias('application.modules.tasks.tests.unit.files'));
     ZurmoRedBean::exec("update " . $import->getTempTableName() . " set column_0 = " . $account3->id . " where id != 1 limit 3");
     ZurmoRedBean::exec("update " . $import->getTempTableName() . " set column_2 = " . $contact3->id . " where id != 1 limit 4");
     ZurmoRedBean::exec("update " . $import->getTempTableName() . " set column_4 = " . $opportunity3->id . " where id != 1 limit 5");
     $mappingData = array('column_0' => ImportMappingUtil::makeModelDerivedColumnMappingData('AccountDerived', IdValueTypeMappingRuleForm::ZURMO_MODEL_ID), 'column_1' => ImportMappingUtil::makeModelDerivedColumnMappingData('AccountDerived'), 'column_2' => ImportMappingUtil::makeModelDerivedColumnMappingData('ContactDerived', IdValueTypeMappingRuleForm::ZURMO_MODEL_ID), 'column_3' => ImportMappingUtil::makeModelDerivedColumnMappingData('ContactDerived'), 'column_4' => ImportMappingUtil::makeModelDerivedColumnMappingData('OpportunityDerived', IdValueTypeMappingRuleForm::ZURMO_MODEL_ID), 'column_5' => ImportMappingUtil::makeModelDerivedColumnMappingData('OpportunityDerived'), 'column_6' => ImportMappingUtil::makeIntegerColumnMappingData('status'));
     $serializedData = unserialize($import->serializedData);
     $serializedData['mappingData'] = $mappingData;
     $import->serializedData = serialize($serializedData);
     $this->assertTrue($import->save());
     $importRules = ImportRulesUtil::makeImportRulesByType('Tasks');
     $config = array('pagination' => array('pageSize' => 15));
     //This test csv has a header row.
     $dataProvider = new ImportDataProvider($import->getTempTableName(), true, $config);
     //Run data analyzer
     $importDataAnalyzer = new ImportDataAnalyzer($importRules, $dataProvider, $mappingData, array('column_0', 'column_1', 'column_2', 'column_3', 'column_4', 'column_5', 'column_6'));
     $importDataAnalyzer->analyzePage();
     $data = $dataProvider->getData();
     $this->assertEquals(10, count($data));
     $compareData = array();
     $compareData['column_0'][] = 'Is an existing record and will be updated.';
     $compareData['column_1'][] = 'Was not found and this row will be skipped during import.';
     $compareData['column_2'][] = 'Is an existing record and will be updated.';
     $compareData['column_3'][] = 'Was not found and this row will be skipped during import.';
     $compareData['column_4'][] = 'Is an existing record and will be updated.';
     $compareData['column_5'][] = 'Was not found and this row will be skipped during import.';
     $compareData['column_6'][] = 'Status specified is invalid and this row will be skipped during import.';
     $this->assertEquals($compareData, unserialize($data[0]->serializedAnalysisMessages));
     $this->assertEquals(ImportDataAnalyzer::STATUS_SKIP, $data[0]->analysisStatus);
     $compareData = array();
     $compareData['column_0'][] = 'Is an existing record and will be updated.';
     $compareData['column_1'][] = 'Is an existing record and will be updated.';
     $compareData['column_2'][] = 'Is an existing record and will be updated.';
     $compareData['column_3'][] = 'Was not found and this row will be skipped during import.';
     $compareData['column_4'][] = 'Is an existing record and will be updated.';
     $compareData['column_5'][] = 'Was not found and this row will be skipped during import.';
     $compareData['column_6'][] = 'Status specified is invalid and this row will be skipped during import.';
     $this->assertEquals($compareData, unserialize($data[1]->serializedAnalysisMessages));
     $this->assertEquals(ImportDataAnalyzer::STATUS_SKIP, $data[1]->analysisStatus);
     $compareData = array();
     $compareData['column_0'][] = 'Is an existing record and will be updated.';
     $compareData['column_1'][] = 'Is an existing record and will be updated.';
     $compareData['column_2'][] = 'Is an existing record and will be updated.';
     $compareData['column_3'][] = 'Was not found and this row will be skipped during import.';
     $compareData['column_4'][] = 'Is an existing record and will be updated.';
     $compareData['column_5'][] = 'Was not found and this row will be skipped during import.';
     $compareData['column_6'][] = 'Status specified is invalid and this row will be skipped during import.';
     $this->assertEquals($compareData, unserialize($data[2]->serializedAnalysisMessages));
     $this->assertEquals(ImportDataAnalyzer::STATUS_SKIP, $data[2]->analysisStatus);
     $compareData = array();
     $compareData['column_0'][] = 'Was not found and this row will be skipped during import.';
     $compareData['column_1'][] = 'Is an existing record and will be updated.';
     $compareData['column_2'][] = 'Is an existing record and will be updated.';
     $compareData['column_3'][] = 'Was not found and this row will be skipped during import.';
     $compareData['column_4'][] = 'Is an existing record and will be updated.';
     $compareData['column_5'][] = 'Was not found and this row will be skipped during import.';
     $compareData['column_6'][] = 'Status specified is invalid and this row will be skipped during import.';
     $this->assertEquals($compareData, unserialize($data[3]->serializedAnalysisMessages));
     $this->assertEquals(ImportDataAnalyzer::STATUS_SKIP, $data[3]->analysisStatus);
     $compareData = array();
     $compareData['column_0'][] = 'Was not found and this row will be skipped during import.';
     $compareData['column_1'][] = 'Was not found and this row will be skipped during import.';
     $compareData['column_2'][] = 'Was not found and this row will be skipped during import.';
     $compareData['column_3'][] = 'Is an existing record and will be updated.';
     $compareData['column_4'][] = 'Is an existing record and will be updated.';
     $compareData['column_5'][] = 'Was not found and this row will be skipped during import.';
     $compareData['column_6'][] = 'Status specified is invalid and this row will be skipped during import.';
     $this->assertEquals($compareData, unserialize($data[4]->serializedAnalysisMessages));
     $this->assertEquals(ImportDataAnalyzer::STATUS_SKIP, $data[4]->analysisStatus);
     $compareData = array();
     $compareData['column_0'][] = 'Was not found and this row will be skipped during import.';
     $compareData['column_1'][] = 'Was not found and this row will be skipped during import.';
     $compareData['column_2'][] = 'Was not found and this row will be skipped during import.';
     $compareData['column_3'][] = 'Is an existing record and will be updated.';
     $compareData['column_4'][] = 'Was not found and this row will be skipped during import.';
     $compareData['column_5'][] = 'Was not found and this row will be skipped during import.';
     $compareData['column_6'][] = 'Status specified is invalid and this row will be skipped during import.';
     $this->assertEquals($compareData, unserialize($data[5]->serializedAnalysisMessages));
     $this->assertEquals(ImportDataAnalyzer::STATUS_SKIP, $data[5]->analysisStatus);
     $compareData = array();
     $compareData['column_0'][] = 'Was not found and this row will be skipped during import.';
     $compareData['column_1'][] = 'Was not found and this row will be skipped during import.';
     $compareData['column_2'][] = 'Was not found and this row will be skipped during import.';
     $compareData['column_3'][] = 'Is an existing record and will be updated.';
     $compareData['column_4'][] = 'Was not found and this row will be skipped during import.';
     $compareData['column_6'][] = 'Status specified is invalid and this row will be skipped during import.';
     $compareData['column_5'][] = 'Is an existing record and will be updated.';
     $this->assertEquals($compareData, unserialize($data[6]->serializedAnalysisMessages));
     $this->assertEquals(ImportDataAnalyzer::STATUS_SKIP, $data[6]->analysisStatus);
     $compareData = array();
     $compareData['column_0'][] = 'Was not found and this row will be skipped during import.';
     $compareData['column_1'][] = 'Was not found and this row will be skipped during import.';
     $compareData['column_2'][] = 'Was not found and this row will be skipped during import.';
     $compareData['column_3'][] = 'Was not found and this row will be skipped during import.';
     $compareData['column_4'][] = 'Was not found and this row will be skipped during import.';
     $compareData['column_6'][] = 'Status specified is invalid and this row will be skipped during import.';
     $compareData['column_5'][] = 'Is an existing record and will be updated.';
     $this->assertEquals($compareData, unserialize($data[7]->serializedAnalysisMessages));
     $this->assertEquals(ImportDataAnalyzer::STATUS_SKIP, $data[7]->analysisStatus);
     $compareData = array();
     $compareData['column_0'][] = 'Was not found and this row will be skipped during import.';
     $compareData['column_1'][] = 'Was not found and this row will be skipped during import.';
     $compareData['column_2'][] = 'Was not found and this row will be skipped during import.';
     $compareData['column_3'][] = 'Was not found and this row will be skipped during import.';
     $compareData['column_4'][] = 'Was not found and this row will be skipped during import.';
     $compareData['column_5'][] = 'Is an existing record and will be updated.';
     $compareData['column_6'][] = 'Status specified is invalid and this row will be skipped during import.';
     $this->assertEquals($compareData, unserialize($data[8]->serializedAnalysisMessages));
     $this->assertEquals(ImportDataAnalyzer::STATUS_SKIP, $data[8]->analysisStatus);
     //Will result with no problems since it is all blank.
     $this->assertFalse(unserialize($data[9]->serializedAnalysisMessages));
     $this->assertEquals(ImportDataAnalyzer::STATUS_CLEAN, $data[9]->analysisStatus);
 }
Exemplo n.º 12
0
 /**
  * @depends testParentAccountHasCorrectAttributeImportType
  */
 public function testSimpleUserImportWhereAllRowsSucceed()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $parentAccount = AccountTestHelper::createAccountByNameForOwner('parentAccount', Yii::app()->user->userModel);
     $parentAccountId = $parentAccount->id;
     $accounts = Account::getAll();
     $this->assertEquals(1, count($accounts));
     $import = new Import();
     $serializedData['importRulesType'] = 'Accounts';
     $serializedData['firstRowIsHeaderRow'] = true;
     $import->serializedData = serialize($serializedData);
     $this->assertTrue($import->save());
     ImportTestHelper::createTempTableByFileNameAndTableName('importTest.csv', $import->getTempTableName(), Yii::getPathOfAlias('application.modules.accounts.tests.unit.files'));
     //update the ids of the account column to match the parent account.
     R::exec("update " . $import->getTempTableName() . " set column_16 = " . $parentAccount->id . " where id != 1 limit 4");
     $this->assertEquals(4, ImportDatabaseUtil::getCount($import->getTempTableName()));
     // includes header rows.
     $mappingData = array('column_0' => ImportMappingUtil::makeStringColumnMappingData('name'), 'column_1' => ImportMappingUtil::makeStringColumnMappingData('officePhone'), 'column_2' => ImportMappingUtil::makeStringColumnMappingData('officeFax'), 'column_3' => ImportMappingUtil::makeIntegerColumnMappingData('employees'), 'column_4' => ImportMappingUtil::makeUrlColumnMappingData('website'), 'column_5' => ImportMappingUtil::makeFloatColumnMappingData('annualRevenue'), 'column_6' => ImportMappingUtil::makeTextAreaColumnMappingData('description'), 'column_7' => ImportMappingUtil::makeStringColumnMappingData('billingAddress__city'), 'column_8' => ImportMappingUtil::makeStringColumnMappingData('billingAddress__country'), 'column_9' => ImportMappingUtil::makeStringColumnMappingData('billingAddress__postalCode'), 'column_10' => ImportMappingUtil::makeStringColumnMappingData('billingAddress__state'), 'column_11' => ImportMappingUtil::makeStringColumnMappingData('billingAddress__street1'), 'column_12' => ImportMappingUtil::makeStringColumnMappingData('billingAddress__street2'), 'column_13' => ImportMappingUtil::makeEmailColumnMappingData('primaryEmail__emailAddress'), 'column_14' => ImportMappingUtil::makeBooleanColumnMappingData('primaryEmail__isInvalid'), 'column_15' => ImportMappingUtil::makeBooleanColumnMappingData('primaryEmail__optOut'), 'column_16' => ImportMappingUtil::makeHasOneColumnMappingData('account'), 'column_17' => ImportMappingUtil::makeDropDownColumnMappingData('industry'), 'column_18' => ImportMappingUtil::makeDropDownColumnMappingData('type'));
     $importRules = ImportRulesUtil::makeImportRulesByType('Accounts');
     $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.
     $accounts = Account::getAll();
     $this->assertEquals(4, count($accounts));
     $accounts = Account::getByName('account1');
     $this->assertEquals(1, count($accounts[0]));
     $this->assertEquals(123456, $accounts[0]->officePhone);
     $this->assertEquals(555, $accounts[0]->officeFax);
     $this->assertEquals(1, $accounts[0]->employees);
     $this->assertEquals('http://www.account1.com', $accounts[0]->website);
     $this->assertEquals(100, $accounts[0]->annualRevenue);
     $this->assertEquals('desc1', $accounts[0]->description);
     $this->assertEquals('city1', $accounts[0]->billingAddress->city);
     $this->assertEquals('country1', $accounts[0]->billingAddress->country);
     $this->assertEquals('postal1', $accounts[0]->billingAddress->postalCode);
     $this->assertEquals('state1', $accounts[0]->billingAddress->state);
     $this->assertEquals('street11', $accounts[0]->billingAddress->street1);
     $this->assertEquals('street21', $accounts[0]->billingAddress->street2);
     $this->assertEquals('*****@*****.**', $accounts[0]->primaryEmail->emailAddress);
     $this->assertEquals(null, $accounts[0]->primaryEmail->isInvalid);
     $this->assertEquals(null, $accounts[0]->primaryEmail->optOut);
     $this->assertTrue($accounts[0]->account->isSame($parentAccount));
     $this->assertEquals('Automotive', $accounts[0]->industry->value);
     $this->assertEquals('Prospect', $accounts[0]->type->value);
     $accounts = Account::getByName('account2');
     $this->assertEquals(1, count($accounts[0]));
     $this->assertEquals(223456, $accounts[0]->officePhone);
     $this->assertEquals(666, $accounts[0]->officeFax);
     $this->assertEquals(2, $accounts[0]->employees);
     $this->assertEquals('http://www.account2.com', $accounts[0]->website);
     $this->assertEquals(200, $accounts[0]->annualRevenue);
     $this->assertEquals('desc2', $accounts[0]->description);
     $this->assertEquals('city2', $accounts[0]->billingAddress->city);
     $this->assertEquals('country2', $accounts[0]->billingAddress->country);
     $this->assertEquals('postal2', $accounts[0]->billingAddress->postalCode);
     $this->assertEquals('state2', $accounts[0]->billingAddress->state);
     $this->assertEquals('street12', $accounts[0]->billingAddress->street1);
     $this->assertEquals('street22', $accounts[0]->billingAddress->street2);
     $this->assertEquals('*****@*****.**', $accounts[0]->primaryEmail->emailAddress);
     $this->assertEquals('1', $accounts[0]->primaryEmail->isInvalid);
     $this->assertEquals('1', $accounts[0]->primaryEmail->optOut);
     $this->assertTrue($accounts[0]->account->isSame($parentAccount));
     $this->assertEquals('Banking', $accounts[0]->industry->value);
     $this->assertEquals('Customer', $accounts[0]->type->value);
     $accounts = Account::getByName('account3');
     $this->assertEquals(1, count($accounts[0]));
     $this->assertEquals(323456, $accounts[0]->officePhone);
     $this->assertEquals(777, $accounts[0]->officeFax);
     $this->assertEquals(3, $accounts[0]->employees);
     $this->assertEquals('http://www.account3.com', $accounts[0]->website);
     $this->assertEquals(300, $accounts[0]->annualRevenue);
     $this->assertEquals('desc3', $accounts[0]->description);
     $this->assertEquals('city3', $accounts[0]->billingAddress->city);
     $this->assertEquals('country3', $accounts[0]->billingAddress->country);
     $this->assertEquals('postal3', $accounts[0]->billingAddress->postalCode);
     $this->assertEquals('state3', $accounts[0]->billingAddress->state);
     $this->assertEquals('street13', $accounts[0]->billingAddress->street1);
     $this->assertEquals('street23', $accounts[0]->billingAddress->street2);
     $this->assertEquals('*****@*****.**', $accounts[0]->primaryEmail->emailAddress);
     $this->assertEquals(null, $accounts[0]->primaryEmail->isInvalid);
     $this->assertEquals(null, $accounts[0]->primaryEmail->optOut);
     $this->assertTrue($accounts[0]->account->isSame($parentAccount));
     $this->assertEquals('Energy', $accounts[0]->industry->value);
     $this->assertEquals('Vendor', $accounts[0]->type->value);
     //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 parent account has 3 children
     $parentAccount->forget();
     $parentAccount = Account::getById($parentAccountId);
     $this->assertEquals(3, $parentAccount->accounts->count());
 }
 protected function processColumns($params)
 {
     $completionPosition = 1;
     if (!isset($params["columnNameToProcess"])) {
         $params["columnNameToProcess"] = $this->getNextMappedColumnName($this->mappingData);
     } else {
         assert('is_string($params["columnNameToProcess"])');
     }
     $completionPosition = array_search($params["columnNameToProcess"], $this->sanitizableColumnNames) + 1;
     if ($completionPosition != count($this->sanitizableColumnNames)) {
         $completionPosition++;
     }
     $this->subSequenceCompletionPercentage = $completionPosition / count($this->sanitizableColumnNames) * 100;
     //Run data analyzer
     if ($this->mappingData[$params["columnNameToProcess"]]['attributeIndexOrDerivedType'] == null) {
         throw new NotSupportedException();
     }
     $importDataAnalyzer = new ImportDataAnalyzer($this->importRules, $this->dataProvider);
     $importDataAnalyzer->analyzeByColumnNameAndColumnMappingData($params["columnNameToProcess"], $this->mappingData[$params["columnNameToProcess"]]);
     $messagesData = $importDataAnalyzer->getMessagesData();
     $importInstructionsData = $importDataAnalyzer->getImportInstructionsData();
     $unserializedData = unserialize($this->import->serializedData);
     $unserializedData['mappingData'] = ImportMappingUtil::resolveImportInstructionsDataIntoMappingData($this->mappingData, $importInstructionsData);
     $this->import->serializedData = serialize($unserializedData);
     ImportUtil::setDataAnalyzerMessagesDataToImport($this->import, $messagesData, true);
     $saved = $this->import->save();
     if (!$saved) {
         throw new FailedToSaveModelException();
     }
     $nextColumnName = $this->getNextMappedColumnName($this->mappingData, $params['columnNameToProcess']);
     if ($nextColumnName == null) {
         $this->nextStep = null;
         $this->nextMessage = null;
         $this->complete = true;
         return null;
     } else {
         $params['columnNameToProcess'] = $nextColumnName;
         $this->nextStep = 'processColumns';
         $this->setNextMessageByStep($this->nextStep);
         $attributeImportRules = AttributeImportRulesFactory::makeByImportRulesTypeAndAttributeIndexOrDerivedType($this->importRules->getType(), $this->mappingData[$params["columnNameToProcess"]]['attributeIndexOrDerivedType']);
         $this->nextMessage .= ' ' . $attributeImportRules->getDisplayLabel();
         return $params;
     }
 }
Exemplo n.º 14
0
 /**
  * @depends testSimpleUserImportWhereAllRowsSucceed
  */
 public function testUserImportWithOptionalFields()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $users = User::getAll();
     $this->assertEquals(11, count($users));
     $import = new Import();
     $serializedData['importRulesType'] = 'User';
     $serializedData['firstRowIsHeaderRow'] = true;
     $import->serializedData = serialize($serializedData);
     $this->assertTrue($import->save());
     ImportTestHelper::createTempTableByFileNameAndTableName('importAnalyzerWithOptionalFields.csv', $import->getTempTableName(), true, Yii::getPathOfAlias('application.modules.users.tests.unit.files'));
     $this->assertEquals(11, ImportDatabaseUtil::getCount($import->getTempTableName()));
     // includes header rows.
     $defaultLanguage = Yii::app()->language;
     $localeIds = ZurmoLocale::getSelectableLocaleIds();
     $defaultLocale = $localeIds[0];
     $timezoneIdentifiers = DateTimeZone::listIdentifiers();
     $defaultTimeZone = $timezoneIdentifiers[0];
     $defaultCurrency = Yii::app()->currencyHelper->getActiveCurrencyForCurrentUser();
     $defaultCurrencyId = $defaultCurrency->id;
     $mappingData = array('column_0' => array('attributeIndexOrDerivedType' => 'username', 'type' => 'importColumn', 'mappingRulesData' => array()), 'column_1' => array('attributeIndexOrDerivedType' => 'Password', 'type' => 'importColumn', 'mappingRulesData' => array('PasswordDefaultValueModelAttributeMappingRuleForm' => array('defaultValue' => null))), 'column_3' => ImportMappingUtil::makeStringColumnMappingData('firstName'), 'column_4' => ImportMappingUtil::makeStringColumnMappingData('lastName'), 'column_5' => array('attributeIndexOrDerivedType' => 'language', 'type' => 'extraColumn', 'mappingRulesData' => array('DefaultValueModelAttributeMappingRuleForm' => array('defaultValue' => $defaultLanguage))), 'column_6' => array('attributeIndexOrDerivedType' => 'locale', 'type' => 'extraColumn', 'mappingRulesData' => array('DefaultValueModelAttributeMappingRuleForm' => array('defaultValue' => $defaultLocale))), 'column_7' => array('attributeIndexOrDerivedType' => 'timeZone', 'type' => 'extraColumn', 'mappingRulesData' => array('DefaultValueModelAttributeMappingRuleForm' => array('defaultValue' => $defaultTimeZone))), 'column_8' => array('attributeIndexOrDerivedType' => 'currency', 'type' => 'extraColumn', 'mappingRulesData' => array('DefaultValueModelAttributeMappingRuleForm' => array('defaultValue' => $defaultCurrencyId))));
     $importRules = ImportRulesUtil::makeImportRulesByType('Users');
     $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 10 new models are created.
     $users = User::getAll();
     $this->assertEquals(21, count($users));
     $user = User::getByUsername('myusername11');
     $this->assertEquals($defaultLanguage, $user->language);
     $this->assertEquals($defaultLocale, $user->locale);
     $this->assertEquals($defaultTimeZone, $user->timeZone);
     $this->assertEquals($defaultCurrency, $user->currency);
     //Confirm 10 rows were processed as 'created'.
     $this->assertEquals(10, 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));
 }
Exemplo n.º 15
0
 /**
  * Validation used in the saveMappingData scenario to make sure the mapping data is correct based on
  * user input. Runs several different validations on the data.  This does not validate the validity of the
  * mapping rules data itself. That is done seperately.
  * @see MappingRuleFormAndElementTypeUtil::validateMappingRuleForms
  * @param string $attribute
  * @param array $params
  */
 public function validateMappingData($attribute, $params)
 {
     assert('$this->importRulesType != null');
     assert('$this->mappingData != null');
     $atLeastOneAttributeMappedOrHasRules = false;
     $attributeMappedOrHasRulesMoreThanOnce = false;
     $mappedAttributes = array();
     $importRulesClassName = ImportRulesUtil::getImportRulesClassNameByType($this->importRulesType);
     foreach ($this->mappingData as $columnName => $data) {
         if ($data['attributeIndexOrDerivedType'] != null) {
             $atLeastOneAttributeMappedOrHasRules = true;
             if (in_array($data['attributeIndexOrDerivedType'], $mappedAttributes)) {
                 $attributeMappedOrHasRulesMoreThanOnce = true;
             } else {
                 $mappedAttributes[] = $data['attributeIndexOrDerivedType'];
             }
         }
     }
     if ($attributeMappedOrHasRulesMoreThanOnce) {
         $this->addError('mappingData', Zurmo::t('ImportModule', 'You can only map each field once.'));
     }
     if (!$atLeastOneAttributeMappedOrHasRules) {
         $this->addError('mappingData', Zurmo::t('ImportModule', 'You must map at least one of your import columns.'));
     }
     $mappedAttributeIndicesOrDerivedAttributeTypes = ImportMappingUtil::getMappedAttributeIndicesOrDerivedAttributeTypesByMappingData($this->mappingData);
     $requiredAttributeCollection = $importRulesClassName::getRequiredAttributesCollectionNotIncludingReadOnly();
     $mappedAttributeImportRulesCollection = AttributeImportRulesFactory::makeCollection($this->importRulesType, $mappedAttributeIndicesOrDerivedAttributeTypes);
     if (!ImportRulesUtil::areAllRequiredAttributesMappedOrHaveRules($requiredAttributeCollection, $mappedAttributeImportRulesCollection)) {
         $attributesLabelContent = null;
         foreach ($requiredAttributeCollection as $noteUsed => $attributeData) {
             if ($attributesLabelContent != null) {
                 $attributesLabelContent .= ', ';
             }
             $attributesLabelContent .= $attributeData['attributeLabel'];
         }
         $this->addError('mappingData', Zurmo::t('ImportModule', 'All required fields must be mapped or added: {attributesLabelContent}', array('{attributesLabelContent}' => $attributesLabelContent)));
     }
     try {
         ImportRulesUtil::checkIfAnyAttributesAreDoubleMapped($mappedAttributeImportRulesCollection);
     } catch (ImportAttributeMappedMoreThanOnceException $e) {
         $this->addError('mappingData', Zurmo::t('ImportModule', 'The following field is mapped more than once. {message}', array('{message}' => $e->getMessage())));
     }
 }
Exemplo n.º 16
0
 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));
 }
Exemplo n.º 17
0
 /**
  * Step 4 ajax process.  When you click the 'Add Field' button in the user interface, this ajax action
  * is called and makes an extra row to display for mapping.
  */
 public function actionMappingAddExtraMappingRow($id, $columnCount)
 {
     $import = Import::getById((int) $_GET['id']);
     $importWizardForm = ImportWizardUtil::makeFormByImport($import);
     $importRulesClassName = ImportRulesUtil::getImportRulesClassNameByType($importWizardForm->importRulesType);
     $mappableAttributeIndicesAndDerivedTypes = $importRulesClassName::getMappableAttributeIndicesAndDerivedTypes();
     $extraColumnName = ImportMappingUtil::makeExtraColumnNameByColumnCount((int) $columnCount);
     $mappingDataMetadata = ImportWizardMappingViewUtil::makeExtraColumnMappingDataForViewByColumnName($extraColumnName);
     $extraColumnView = new ImportWizardMappingExtraColumnView($importWizardForm, $mappingDataMetadata, $mappableAttributeIndicesAndDerivedTypes);
     $view = new AjaxPageView($extraColumnView);
     echo $view->render();
 }
 /**
  * @depends testNewlyImportedDataForUpdateEmailDedupe
  */
 public function testImportedDataForNameUpdateDedupe()
 {
     $jim = User::getByUsername('jim');
     Yii::app()->user->userModel = $jim;
     //Confirm Jim can can only view ImportModelTestItems he owns.
     $item = NamedSecurableItem::getByName('ImportModule');
     $this->assertEquals(Permission::NONE, $item->getEffectivePermissions($jim));
     $testModels = Account::getByName('hello');
     $this->assertEquals(1, count($testModels));
     $import = new Import();
     $serializedData['importRulesType'] = 'Accounts';
     $serializedData['firstRowIsHeaderRow'] = true;
     $import->serializedData = serialize($serializedData);
     $this->assertTrue($import->save());
     ImportTestHelper::createTempTableByFileNameAndTableName('importDedupeNameTest.csv', $import->getTempTableName(), true);
     $this->assertEquals(2, ImportDatabaseUtil::getCount($import->getTempTableName()));
     // includes header rows.
     $emailMappingData = ImportMappingUtil::makeEmailColumnMappingData('primaryEmail__emailAddress');
     $emailMappingData['mappingRulesData']['EmailModelAttributeDedupeMappingRuleForm'] = array('dedupeRule' => ImportDedupeRulesRadioDropDownElement::DO_NOT_DEDUPE);
     $nameMappingData = ImportMappingUtil::makeEmailColumnMappingData('name');
     $nameMappingData['mappingRulesData']['NameModelAttributeDedupeMappingRuleForm'] = array('dedupeRule' => ImportDedupeRulesRadioDropDownElement::UPDATE_ROW_ON_MATCH_FOUND);
     $mappingData = array('column_0' => $nameMappingData, 'column_1' => $emailMappingData);
     $importRules = ImportRulesUtil::makeImportRulesByType('Accounts');
     $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();
     $testModels = Account::getByName('hello');
     $this->assertEquals(1, count($testModels));
     $this->assertEquals('*****@*****.**', $testModels[0]->primaryEmail->emailAddress);
 }
 /**
  * Process csv and get data
  * @param array $mappingData
  * @param array $data
  */
 protected function processSantizerCSVAndGetData(&$mappingData, &$data)
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $import = new Import();
     $serializedData['importRulesType'] = 'ProductTemplates';
     $serializedData['firstRowIsHeaderRow'] = true;
     $import->serializedData = serialize($serializedData);
     $this->assertTrue($import->save());
     ImportTestHelper::createTempTableByFileNameAndTableName('productTemplatesSanitizer.csv', $import->getTempTableName(), true, Yii::getPathOfAlias('application.modules.productTemplates.tests.unit.files'));
     $this->assertEquals(5, ImportDatabaseUtil::getCount($import->getTempTableName()));
     // includes header rows.
     $currencies = Currency::getAll();
     $mappingData = array('column_0' => ImportMappingUtil::makeStringColumnMappingData('name'), 'column_1' => ImportMappingUtil::makeTextAreaColumnMappingData('description'), 'column_2' => ImportMappingUtil::makeIntegerColumnMappingData('sellPriceFormula__type'), 'column_3' => ImportMappingUtil::makeFloatColumnMappingData('sellPriceFormula__discountOrMarkupPercentage'), 'column_4' => ImportMappingUtil::makeCurrencyColumnMappingData('cost', $currencies[0]), 'column_5' => ImportMappingUtil::makeCurrencyColumnMappingData('listPrice', $currencies[0]), 'column_6' => ImportMappingUtil::makeCurrencyColumnMappingData('sellPrice', $currencies[0]), 'column_7' => ImportMappingUtil::makeIntegerColumnMappingData('priceFrequency'), 'column_8' => ImportMappingUtil::makeIntegerColumnMappingData('type'), 'column_9' => ImportMappingUtil::makeIntegerColumnMappingData('status'));
     $importRules = ImportRulesUtil::makeImportRulesByType('ProductTemplates');
     $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);
     $data = $dataProvider->getData(true);
 }
Exemplo n.º 20
0
 /**
  * @depends testImportDataAnalysisResultsForMultiSelectMissingMappingRuleForm
  */
 public function testImportDataAnalysisResults()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $import = new Import();
     $serializedData['importRulesType'] = 'ImportModelTestItem';
     $import->serializedData = serialize($serializedData);
     $this->assertTrue($import->save());
     ImportTestHelper::createTempTableByFileNameAndTableName('importAnalyzerTest.csv', $import->getTempTableName());
     R::exec("update " . $import->getTempTableName() . " set column_8 = " . Yii::app()->user->userModel->id . " where id != 1 limit 4");
     $externalSystemIdColumnName = ExternalSystemIdUtil::EXTERNAL_SYSTEM_ID_COLUMN_NAME;
     //Add test ImportModelTestItem models for use in this test.
     $importModelTestItemModel1 = ImportTestHelper::createImportModelTestItem('aaa', 'aba');
     $importModelTestItemModel2 = ImportTestHelper::createImportModelTestItem('ddw', 'daf');
     //Update for of the import rows to point to model 1.  This is for the ZURMO_MODEL_ID mapping rule form type value.
     R::exec("update " . $import->getTempTableName() . " set column_10 = " . $importModelTestItemModel1->id . " where id != 1 limit 3");
     //Update model2 to have an externalSystemId.
     R::exec("update " . ImportModelTestItem::getTableName('ImportModelTestItem') . " set {$externalSystemIdColumnName} = 'B' where id = {$importModelTestItemModel2->id}");
     //Add test ImportModelTestItem2 models for use in this test.
     $importModelTestItem2Model1 = ImportTestHelper::createImportModelTestItem2('aaa');
     $importModelTestItem2Model2 = ImportTestHelper::createImportModelTestItem2('bbb');
     $importModelTestItem2Model3 = ImportTestHelper::createImportModelTestItem2('ccc');
     //Update for of the import rows to point to model 1.  This is for the ZURMO_MODEL_ID mapping.
     R::exec("update " . $import->getTempTableName() . " set column_14 = " . $importModelTestItem2Model1->id . " where id != 1 limit 4");
     //Update model2 to have an externalSystemId.
     R::exec("update " . ImportModelTestItem2::getTableName('ImportModelTestItem2') . " set {$externalSystemIdColumnName} = 'B' where id = {$importModelTestItem2Model2->id}");
     //Add test ImportModelTestItem3 models for use in this test.
     $importModelTestItem3Model1 = ImportTestHelper::createImportModelTestItem3('aaa');
     $importModelTestItem3Model2 = ImportTestHelper::createImportModelTestItem3('dd');
     //Update for of the import rows to point to model 1.  This is for the ZURMO_MODEL_ID mapping rule form type value.
     R::exec("update " . $import->getTempTableName() . " set column_17 = " . $importModelTestItem3Model1->id . " where id != 1 limit 3");
     //Update model2 to have an externalSystemId.
     R::exec("update " . ImportModelTestItem3::getTableName('ImportModelTestItem3') . " set {$externalSystemIdColumnName} = 'K' where id = {$importModelTestItem3Model2->id}");
     //Add test ImportModelTestItem4 models for use in this test.
     $importModelTestItem4Model1 = ImportTestHelper::createImportModelTestItem4('aaa');
     $importModelTestItem4Model2 = ImportTestHelper::createImportModelTestItem4('dd');
     //Update for of the import rows to point to model 1.  This is for the ZURMO_MODEL_ID mapping rule form type value.
     R::exec("update " . $import->getTempTableName() . " set column_12 = " . $importModelTestItem4Model1->id . " where id != 1 limit 5");
     //Update model2 to have an externalSystemId.
     R::exec("update " . ImportModelTestItem3::getTableName('ImportModelTestItem4') . " set {$externalSystemIdColumnName} = 'J' where id = {$importModelTestItem4Model2->id}");
     $mappingData = array('column_0' => array('attributeIndexOrDerivedType' => 'string', 'type' => 'importColumn', 'mappingRulesData' => array('DefaultValueModelAttributeMappingRuleForm' => array('defaultValue' => null))), 'column_1' => array('attributeIndexOrDerivedType' => 'phone', 'type' => 'importColumn', 'mappingRulesData' => array('DefaultValueModelAttributeMappingRuleForm' => array('defaultValue' => null))), 'column_2' => array('attributeIndexOrDerivedType' => 'float', 'type' => 'importColumn', 'mappingRulesData' => array('DefaultValueModelAttributeMappingRuleForm' => array('defaultValue' => null))), 'column_3' => array('attributeIndexOrDerivedType' => 'boolean', 'type' => 'importColumn'), 'column_4' => array('attributeIndexOrDerivedType' => 'date', 'type' => 'importColumn', 'mappingRulesData' => array('DefaultValueModelAttributeMappingRuleForm' => array('defaultValue' => null), 'ValueFormatMappingRuleForm' => array('format' => 'MM-dd-yyyy'))), 'column_5' => array('attributeIndexOrDerivedType' => 'dateTime', 'type' => 'importColumn', 'mappingRulesData' => array('DefaultValueModelAttributeMappingRuleForm' => array('defaultValue' => null), 'ValueFormatMappingRuleForm' => array('format' => 'MM-dd-yyyy hh:mm'))), 'column_6' => array('attributeIndexOrDerivedType' => 'dropDown', 'type' => 'importColumn', 'mappingRulesData' => array('DefaultValueDropDownModelAttributeMappingRuleForm' => array('defaultValue' => null))), 'column_7' => array('attributeIndexOrDerivedType' => 'createdByUser', 'type' => 'importColumn', 'mappingRulesData' => array('UserValueTypeModelAttributeMappingRuleForm' => array('type' => UserValueTypeModelAttributeMappingRuleForm::ZURMO_USERNAME))), 'column_8' => array('attributeIndexOrDerivedType' => 'modifiedByUser', 'type' => 'importColumn', 'mappingRulesData' => array('UserValueTypeModelAttributeMappingRuleForm' => array('type' => UserValueTypeModelAttributeMappingRuleForm::ZURMO_USER_ID))), 'column_9' => array('attributeIndexOrDerivedType' => 'owner', 'type' => 'importColumn', 'mappingRulesData' => array('DefaultModelNameIdMappingRuleForm' => array('defaultModelId' => null), 'UserValueTypeModelAttributeMappingRuleForm' => array('type' => UserValueTypeModelAttributeMappingRuleForm::EXTERNAL_SYSTEM_USER_ID))), 'column_10' => array('attributeIndexOrDerivedType' => 'id', 'type' => 'importColumn', 'mappingRulesData' => array('IdValueTypeMappingRuleForm' => array('type' => IdValueTypeMappingRuleForm::ZURMO_MODEL_ID))), 'column_11' => array('attributeIndexOrDerivedType' => 'id', 'type' => 'importColumn', 'mappingRulesData' => array('IdValueTypeMappingRuleForm' => array('type' => IdValueTypeMappingRuleForm::EXTERNAL_SYSTEM_ID))), 'column_12' => array('attributeIndexOrDerivedType' => 'hasOneAlso', 'type' => 'importColumn', 'mappingRulesData' => array('DefaultModelNameIdMappingRuleForm' => array('defaultModelId' => null), 'IdValueTypeMappingRuleForm' => array('type' => IdValueTypeMappingRuleForm::ZURMO_MODEL_ID))), 'column_13' => array('attributeIndexOrDerivedType' => 'hasOneAlso', 'type' => 'importColumn', 'mappingRulesData' => array('DefaultModelNameIdMappingRuleForm' => array('defaultModelId' => null), 'IdValueTypeMappingRuleForm' => array('type' => IdValueTypeMappingRuleForm::EXTERNAL_SYSTEM_ID))), 'column_14' => array('attributeIndexOrDerivedType' => 'hasOne', 'type' => 'importColumn', 'mappingRulesData' => array('RelatedModelValueTypeMappingRuleForm' => array('type' => RelatedModelValueTypeMappingRuleForm::ZURMO_MODEL_ID))), 'column_15' => array('attributeIndexOrDerivedType' => 'hasOne', 'type' => 'importColumn', 'mappingRulesData' => array('RelatedModelValueTypeMappingRuleForm' => array('type' => RelatedModelValueTypeMappingRuleForm::EXTERNAL_SYSTEM_ID))), 'column_16' => array('attributeIndexOrDerivedType' => 'hasOne', 'type' => 'importColumn', 'mappingRulesData' => array('RelatedModelValueTypeMappingRuleForm' => array('type' => RelatedModelValueTypeMappingRuleForm::ZURMO_MODEL_NAME))), 'column_17' => array('attributeIndexOrDerivedType' => 'ImportModelTestItem3Derived', 'type' => 'importColumn', 'mappingRulesData' => array('IdValueTypeMappingRuleForm' => array('type' => IdValueTypeMappingRuleForm::ZURMO_MODEL_ID))), 'column_18' => array('attributeIndexOrDerivedType' => 'ImportModelTestItem3Derived', 'type' => 'importColumn', 'mappingRulesData' => array('IdValueTypeMappingRuleForm' => array('type' => IdValueTypeMappingRuleForm::EXTERNAL_SYSTEM_ID))), 'column_19' => array('attributeIndexOrDerivedType' => 'url', 'type' => 'importColumn', 'mappingRulesData' => array('DefaultValueModelAttributeMappingRuleForm' => array('defaultValue' => null))), 'column_20' => array('attributeIndexOrDerivedType' => 'textArea', 'type' => 'importColumn'), 'column_21' => array('attributeIndexOrDerivedType' => 'integer', 'type' => 'importColumn', 'mappingRulesData' => array('DefaultValueModelAttributeMappingRuleForm' => array('defaultValue' => null))), 'column_22' => array('attributeIndexOrDerivedType' => 'currencyValue', 'type' => 'importColumn', 'mappingRulesData' => array('DefaultValueModelAttributeMappingRuleForm' => array('defaultValue' => null))), 'column_23' => array('attributeIndexOrDerivedType' => 'FullName', 'type' => 'importColumn', 'mappingRulesData' => array('FullNameDefaultValueModelAttributeMappingRuleForm' => array('defaultValue' => null))), 'column_24' => array('attributeIndexOrDerivedType' => 'multiDropDown', 'type' => 'importColumn', 'mappingRulesData' => array('DefaultValueMultiSelectDropDownModelAttributeMappingRuleForm' => array('defaultValue' => null))), 'column_25' => array('attributeIndexOrDerivedType' => 'tagCloud', 'type' => 'importColumn', 'mappingRulesData' => array('DefaultValueMultiSelectDropDownModelAttributeMappingRuleForm' => array('defaultValue' => null))));
     $serializedData = unserialize($import->serializedData);
     $serializedData['mappingData'] = $mappingData;
     $import->serializedData = serialize($serializedData);
     $this->assertTrue($import->save());
     $importRules = ImportRulesUtil::makeImportRulesByType('ImportModelTestItem');
     $config = array('pagination' => array('pageSize' => 2));
     //This test csv has a header row.
     $dataProvider = new ImportDataProvider($import->getTempTableName(), true, $config);
     //Run data analyzer
     $importDataAnalyzer = new ImportDataAnalyzer($importRules, $dataProvider);
     foreach ($mappingData as $columnName => $columnMappingData) {
         $importDataAnalyzer->analyzeByColumnNameAndColumnMappingData($columnName, $columnMappingData);
     }
     $messagesData = $importDataAnalyzer->getMessagesData();
     $compareData = array('column_0' => array(array('message' => '1 value(s) are too short for this field. These rows will be skipped during import.', 'sanitizerUtilType' => 'MinimumLength', 'moreAvailable' => false), array('message' => '1 value(s) are too large for this field. These values will be truncated to a length of 64 upon import.', 'sanitizerUtilType' => 'Truncate', 'moreAvailable' => false), array('message' => '1 value(s) are missing and are required. These rows will be skipped on import.', 'sanitizerUtilType' => 'Required', 'moreAvailable' => false)), 'column_1' => array(array('message' => '2 value(s) are too large for this field. These values will be truncated to a length of 14 upon import.', 'sanitizerUtilType' => 'Truncate', 'moreAvailable' => false)), 'column_2' => array(array('message' => '2 value(s) are invalid. These rows will be skipped during import.', 'sanitizerUtilType' => 'Number', 'moreAvailable' => false)), 'column_3' => array(array('message' => '2 value(s) have invalid check box values. These values will be set to false upon import.', 'sanitizerUtilType' => 'Boolean', 'moreAvailable' => false)), 'column_4' => array(array('message' => '2 value(s) have invalid date formats. These values will be cleared during import.', 'sanitizerUtilType' => 'Date', 'moreAvailable' => false)), 'column_5' => array(array('message' => '2 value(s) have invalid date time formats. These values will be cleared during import.', 'sanitizerUtilType' => 'DateTime', 'moreAvailable' => false)), 'column_6' => array(array('message' => '2 dropdown value(s) are missing from the field. These values will be added upon import.', 'sanitizerUtilType' => 'DropDown', 'moreAvailable' => false)), 'column_7' => array(array('message' => '2 username(s) specified were not found. These values will not be used during the import.', 'sanitizerUtilType' => 'UserValueType', 'moreAvailable' => false)), 'column_8' => array(array('message' => '1 zurmo user id(s) across 7 row(s) were not found. These values will not be used during the import.', 'sanitizerUtilType' => 'UserValueType', 'moreAvailable' => false)), 'column_9' => array(array('message' => '2 external system user id(s) specified were not found. These values will not be used during the import.', 'sanitizerUtilType' => 'UserValueType', 'moreAvailable' => false), array('message' => '1 value(s) are missing and are required. These rows will be skipped on import.', 'sanitizerUtilType' => 'ModelIdRequired', 'moreAvailable' => false)), 'column_10' => array(array('message' => '3 record(s) will be updated and 9 record(s) will be skipped during import.', 'sanitizerUtilType' => 'SelfIdValueType', 'moreAvailable' => false)), 'column_11' => array(array('message' => '1 record(s) will be updated and 11 record(s) will be created during the import.', 'sanitizerUtilType' => 'SelfIdValueType', 'moreAvailable' => false)), 'column_12' => array(array('message' => '5 record(s) will be updated and 7 record(s) will be skipped during import.', 'sanitizerUtilType' => 'ModelIdValueType', 'moreAvailable' => false)), 'column_13' => array(array('message' => '2 record(s) will be updated and 10 record(s) will be skipped during import.', 'sanitizerUtilType' => 'ModelIdValueType', 'moreAvailable' => false)), 'column_14' => array(array('message' => '4 record(s) will be updated and 8 record(s) will be skipped during import.', 'sanitizerUtilType' => 'RelatedModelNameOrIdValueType', 'moreAvailable' => false)), 'column_15' => array(array('message' => '1 record(s) will be updated and 11 record(s) will be skipped during import.', 'sanitizerUtilType' => 'RelatedModelNameOrIdValueType', 'moreAvailable' => false)), 'column_16' => array(array('message' => '1 record(s) will be updated and 11 record(s) will be created during the import.', 'sanitizerUtilType' => 'RelatedModelNameOrIdValueType', 'moreAvailable' => false)), 'column_17' => array(array('message' => '3 record(s) will be updated and 9 record(s) will be skipped during import.', 'sanitizerUtilType' => 'ImportModelTestItem3DerivedIdValueType', 'moreAvailable' => false)), 'column_18' => array(array('message' => '2 record(s) will be updated and 10 record(s) will be skipped during import.', 'sanitizerUtilType' => 'ImportModelTestItem3DerivedIdValueType', 'moreAvailable' => false)), 'column_19' => array(array('message' => '1 value(s) have urls that are invalid. These values will be cleared during import.', 'sanitizerUtilType' => 'Url', 'moreAvailable' => false)), 'column_21' => array(array('message' => '1 value(s) are invalid. These rows will be skipped during import.', 'sanitizerUtilType' => 'Number', 'moreAvailable' => false)), 'column_22' => array(array('message' => '1 value(s) are invalid. These rows will be skipped during import.', 'sanitizerUtilType' => 'Number', 'moreAvailable' => false)), 'column_23' => array(array('message' => '1 value(s) are too large for this field. These rows will be skipped during import.', 'sanitizerUtilType' => 'FullName', 'moreAvailable' => false)), 'column_24' => array(array('message' => '2 dropdown value(s) are missing from the field. These values will be added upon import.', 'sanitizerUtilType' => 'MultiSelectDropDown', 'moreAvailable' => false)), 'column_25' => array(array('message' => '2 dropdown value(s) are missing from the field. These values will be added upon import.', 'sanitizerUtilType' => 'MultiSelectDropDown', 'moreAvailable' => false)));
     $this->assertEquals($compareData, $messagesData);
     $importInstructionsData = $importDataAnalyzer->getImportInstructionsData();
     $compareInstructionsData = array('column_6' => array('DropDown' => array(DropDownSanitizerUtil::ADD_MISSING_VALUE => array('neverpresent', 'notpresent'))));
     $compareInstructionsData['column_24'] = array('MultiSelectDropDown' => array(DropDownSanitizerUtil::ADD_MISSING_VALUE => array('Multi 5', 'Multi 4')));
     $compareInstructionsData['column_25'] = array('MultiSelectDropDown' => array(DropDownSanitizerUtil::ADD_MISSING_VALUE => array('Cloud 5', 'Cloud 4')));
     $this->assertEquals($compareInstructionsData, $importInstructionsData);
     ImportUtil::setDataAnalyzerMessagesDataToImport($import, $messagesData);
     $compareData = unserialize($import->serializedData);
     $compareData = $compareData['dataAnalyzerMessagesData'];
     $this->assertEquals($compareData, $messagesData);
     $newMappingData = ImportMappingUtil::resolveImportInstructionsDataIntoMappingData($mappingData, $importInstructionsData);
     $compareMappingData = $mappingData;
     $compareMappingData['column_6']['importInstructionsData'] = $compareInstructionsData['column_6'];
     $compareMappingData['column_24']['importInstructionsData'] = $compareInstructionsData['column_24'];
     $compareMappingData['column_25']['importInstructionsData'] = $compareInstructionsData['column_25'];
     $this->assertEquals($compareMappingData, $newMappingData);
 }
Exemplo n.º 21
0
 /**
  * Given an array of file upload data, set the form from this.  Keep the existing importRulesType value
  * but clear out any other form attributes since with a new file uploaded, those other attribute values will
  * need to be redone.
  * @param object $importWizardForm
  * @param array $fileUploadData
  */
 public static function setFormByFileUploadDataAndTableName($importWizardForm, $fileUploadData, $tableName)
 {
     assert('$importWizardForm instanceof ImportWizardForm');
     assert('is_array($fileUploadData)');
     assert('is_string($tableName)');
     foreach (self::$importToFormAttributeMap as $attributeName) {
         if ($attributeName != 'importRulesType') {
             $importWizardForm->{$attributeName} = null;
         }
     }
     $importWizardForm->explicitReadWriteModelPermissions = new ExplicitReadWriteModelPermissions();
     $importWizardForm->fileUploadData = $fileUploadData;
     try {
         $importWizardForm->mappingData = ImportMappingUtil::makeMappingDataByTableName($tableName);
     } catch (NoRowsInTableException $e) {
         throw new FailedFileUploadException(Zurmo::t('ImportModule', 'Import file has no rows to use.'));
     }
 }
Exemplo n.º 22
0
 public function testImportWithLatestActivityDateTime()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $accounts = Account::deleteAll();
     $import = new Import();
     $serializedData['importRulesType'] = 'Accounts';
     $serializedData['firstRowIsHeaderRow'] = true;
     $import->serializedData = serialize($serializedData);
     $this->assertTrue($import->save());
     ImportTestHelper::createTempTableByFileNameAndTableName('importWithLatestActivityDateTimeTest.csv', $import->getTempTableName(), true, Yii::getPathOfAlias('application.modules.accounts.tests.unit.files'));
     $mappingData = array('column_0' => ImportMappingUtil::makeStringColumnMappingData('name'), 'column_1' => ImportMappingUtil::makeDateTimeColumnMappingData('latestActivityDateTime'));
     $importRules = ImportRulesUtil::makeImportRulesByType('Accounts');
     $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 2 models where created.
     $accounts = Account::getAll();
     $this->assertCount(2, $accounts);
     $accounts = Account::getByName('company1');
     $this->assertEquals('2011-12-22 05:03', substr($accounts[0]->latestActivityDateTime, 0, -3));
     $accounts = Account::getByName('company2');
     $this->assertNull($accounts[0]->latestActivityDateTime);
     //Confirm 2 rows were processed as 'created'.
     $this->assertEquals(2, 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));
 }
 /**
  * @depends testSimpleUserImportWhereAllRowsSucceed
  */
 public function testSimpleUserImportWithRelationsWhereAllRowsSucceed()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     //Create account
     $sampleAccount = Account::getByName('sampleAccount');
     $accountId = $sampleAccount[0]->id;
     //Create Contact
     $contact = ContactTestHelper::createContactByNameForOwner("My Contact", Yii::app()->user->userModel);
     $import = new Import();
     $serializedData['importRulesType'] = 'Products';
     $serializedData['firstRowIsHeaderRow'] = true;
     $import->serializedData = serialize($serializedData);
     $this->assertTrue($import->save());
     ImportTestHelper::createTempTableByFileNameAndTableName('productsSampleWithRelations.csv', $import->getTempTableName(), true, Yii::getPathOfAlias('application.modules.products.tests.unit.files'));
     //update the ids of the account column to match the parent account.
     ZurmoRedBean::exec("update " . $import->getTempTableName() . " set column_9 = " . $contact->id . " where id != 1 limit 3");
     $this->assertEquals(3, ImportDatabaseUtil::getCount($import->getTempTableName()));
     // includes header rows.
     $currencies = Currency::getAll();
     $ownerColumnMappingData = array('attributeIndexOrDerivedType' => 'owner', 'type' => 'importColumn', 'mappingRulesData' => array('DefaultModelNameIdMappingRuleForm' => array('defaultModelId' => null), 'UserValueTypeModelAttributeMappingRuleForm' => array('type' => UserValueTypeModelAttributeMappingRuleForm::ZURMO_USERNAME)));
     $mappingData = array('column_0' => $ownerColumnMappingData, 'column_1' => ImportMappingUtil::makeStringColumnMappingData('name'), 'column_2' => ImportMappingUtil::makeTextAreaColumnMappingData('description'), 'column_3' => ImportMappingUtil::makeIntegerColumnMappingData('quantity'), 'column_4' => ImportMappingUtil::makeHasOneColumnMappingData('account', RelatedModelValueTypeMappingRuleForm::ZURMO_MODEL_NAME), 'column_5' => ImportMappingUtil::makeStringColumnMappingData('stage'), 'column_6' => ImportMappingUtil::makeCurrencyColumnMappingData('sellPrice', $currencies[0]), 'column_7' => ImportMappingUtil::makeIntegerColumnMappingData('priceFrequency'), 'column_8' => ImportMappingUtil::makeIntegerColumnMappingData('type'));
     $importRules = ImportRulesUtil::makeImportRulesByType('Products');
     $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.
     $products = Product::getAll();
     $this->assertEquals(2, count($products));
     $products = Product::getByName('A Bend in the River November Issue import');
     $this->assertEquals(1, count($products));
     $this->assertEquals('super', $products[0]->owner->username);
     $this->assertEquals('A Bend in the River November Issue import', $products[0]->name);
     $this->assertEquals(6, $products[0]->quantity);
     $this->assertEquals('sampleAccount', $products[0]->account->name);
     $this->assertEquals('Open', $products[0]->stage->value);
     $this->assertEquals('Test Desc', $products[0]->description);
     $this->assertEquals(210, $products[0]->sellPrice->value);
     $this->assertEquals(2, $products[0]->priceFrequency);
     $this->assertEquals(2, $products[0]->type);
     //$this->assertEquals('My Contact',              $products[0]->contact->firstName);
     $products = Product::getByName('A Bend in the River November Issue import copy');
     $this->assertEquals(1, count($products));
     $this->assertEquals('super', $products[0]->owner->username);
     $this->assertEquals('A Bend in the River November Issue import copy', $products[0]->name);
     $this->assertEquals(6, $products[0]->quantity);
     $this->assertEquals('sampleAccount', $products[0]->account->name);
     $this->assertEquals('Open', $products[0]->stage->value);
     $this->assertEquals('Test Desc 1', $products[0]->description);
     $this->assertEquals(210, $products[0]->sellPrice->value);
     $this->assertEquals(2, $products[0]->priceFrequency);
     $this->assertEquals(2, $products[0]->type);
     //$this->assertEquals('My Contact',              $products[0]->contact->firstName);
     //Confirm that 2 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));
 }
Exemplo n.º 24
0
 /**
  * @depends testImportSwitchingOwnerButShouldStillCreate
  */
 public function testImportWithoutCurrencyValues()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     //Unfreeze since the test model is not part of the standard schema.
     $freezeWhenComplete = false;
     if (RedBeanDatabase::isFrozen()) {
         RedBeanDatabase::unfreeze();
         $freezeWhenComplete = true;
     }
     $testModels = ImportModelTestItem::getAll();
     $this->assertEquals(0, count($testModels));
     $import = new Import();
     $serializedData['importRulesType'] = 'ImportModelTestItem';
     $serializedData['firstRowIsHeaderRow'] = true;
     $import->serializedData = serialize($serializedData);
     $this->assertTrue($import->save());
     ImportTestHelper::createTempTableByFileNameAndTableName('importEmptyCurrencyTest.csv', $import->getTempTableName());
     $this->assertEquals(3, ImportDatabaseUtil::getCount($import->getTempTableName()));
     // includes header rows.
     $mappingData = array('column_0' => ImportMappingUtil::makeStringColumnMappingData('lastName'), 'column_1' => ImportMappingUtil::makeStringColumnMappingData('string'));
     $importRules = ImportRulesUtil::makeImportRulesByType('ImportModelTestItem');
     $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 2 models where created.
     $testModels = ImportModelTestItem::getAll();
     $this->assertEquals(2, count($testModels));
     $jim = User::getByUsername('jim');
     foreach ($testModels as $model) {
         $this->assertEquals(array(Permission::NONE, Permission::NONE), $model->getExplicitActualPermissions($jim));
     }
     //Confirm 10 rows were processed as 'created'.
     $this->assertEquals(2, 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));
     //Confirm the base code is USD
     $this->assertEquals('USD', Yii::app()->currencyHelper->getBaseCode());
     //Creating an object produces the correct currency code.
     $testItem = new ImportModelTestItem();
     $this->assertEquals('USD', $testItem->currencyValue->currency->code);
     $testItem->string = 'test';
     $testItem->lastName = 'testAlso';
     $this->assertTrue($testItem->save());
     $testItemId = $testItem->id;
     $testItem->forget();
     //The currency code, even though not set, shows up correctly based on the base code.
     $testItem = ImportModelTestItem::getById($testItemId);
     $this->assertEquals('USD', $testItem->currencyValue->currency->code);
     //Test that the related currency information is not empty for the imported objects.
     $this->assertEquals('USD', $testModels[0]->currencyValue->currency->code);
     //Clear out data in table
     R::exec("delete from " . ImportModelTestItem::getTableName('ImportModelTestItem'));
     //Re-freeze if needed.
     if ($freezeWhenComplete) {
         RedBeanDatabase::freeze();
     }
 }