public function testSequentialProcessViewFactory()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $import = new Import();
     $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))));
     $serializedData['importRulesType'] = 'ImportModelTestItem';
     $serializedData['mappingData'] = $mappingData;
     $import->serializedData = serialize($serializedData);
     $this->assertTrue($import->save());
     ImportTestHelper::createTempTableByFileNameAndTableName('importAnalyzerTest.csv', $import->getTempTableName());
     $config = array('pagination' => array('pageSize' => 2));
     $dataProvider = new ImportDataProvider($import->getTempTableName(), true, $config);
     $sequentialProcess = new ImportDataAnalysisSequentialProcess($import, $dataProvider);
     $sequentialProcess->run(null, null);
     $route = 'default/someAction';
     $view = SequentialProcessViewFactory::makeBySequentialProcess($sequentialProcess, $route);
     $content = $view->render();
     $this->assertNotNull($content);
     $this->assertEquals('SequentialProcessView', get_class($view));
     //Now process the first run. Will process page 0.
     $sequentialProcess = new ImportDataAnalysisSequentialProcess($import, $dataProvider);
     $sequentialProcess->run('processColumns', null);
     $route = 'default/someAction';
     $view = SequentialProcessViewFactory::makeBySequentialProcess($sequentialProcess, $route);
     $content = $view->render();
     $this->assertNotNull($content);
     $this->assertEquals('SequentialProcessView', get_class($view));
     $this->assertEquals(array('columnNameToProcess' => 'column_1'), $sequentialProcess->getNextParams());
 }
 public function testImportDataAnalysisResults()
 {
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $import = new Import();
     $serializedData['importRulesType'] = 'Users';
     $import->serializedData = serialize($serializedData);
     $this->assertTrue($import->save());
     ImportTestHelper::createTempTableByFileNameAndTableName('importAnalyzerTest.csv', $import->getTempTableName(), Yii::getPathOfAlias('application.modules.users.tests.unit.files'));
     $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))));
     $serializedData = unserialize($import->serializedData);
     $serializedData['mappingData'] = $mappingData;
     $import->serializedData = serialize($serializedData);
     $this->assertTrue($import->save());
     $importRules = ImportRulesUtil::makeImportRulesByType('Users');
     $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 large for this field. These values will be truncated to a length of 64 upon import.', 'sanitizerUtilType' => 'Truncate', 'moreAvailable' => false)), 'column_1' => array(array('message' => '1 value(s) are too large for this field. These values will be truncated to a length of 32 upon import.', 'sanitizerUtilType' => 'Truncate', 'moreAvailable' => false)), 'column_2' => array(array('message' => '2 user status value(s) are not valid. Users that have these values will be set to active upon import.', 'sanitizerUtilType' => 'UserStatus', 'moreAvailable' => false)));
     $this->assertEquals($compareData, $messagesData);
     $importInstructionsData = $importDataAnalyzer->getImportInstructionsData();
     $compareInstructionsData = array();
     $this->assertEquals($compareInstructionsData, $importInstructionsData);
 }
 public function testImportDataAnalysisResults()
 {
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $import = new Import();
     $serializedData['importRulesType'] = 'Contacts';
     $import->serializedData = serialize($serializedData);
     $this->assertTrue($import->save());
     ImportTestHelper::createTempTableByFileNameAndTableName('importAnalyzerTest.csv', $import->getTempTableName(), true, Yii::getPathOfAlias('application.modules.contacts.tests.unit.files'));
     $mappingData = array('column_0' => array('attributeIndexOrDerivedType' => 'ContactState', 'type' => 'importColumn', 'mappingRulesData' => array('DefaultContactStateIdMappingRuleForm' => array('defaultStateId' => null))));
     $serializedData = unserialize($import->serializedData);
     $serializedData['mappingData'] = $mappingData;
     $import->serializedData = serialize($serializedData);
     $this->assertTrue($import->save());
     $importRules = ImportRulesUtil::makeImportRulesByType('Contacts');
     $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'));
     $importDataAnalyzer->analyzePage();
     $data = $dataProvider->getData();
     $this->assertEquals(13, count($data));
     $compareData = array();
     $compareData['column_0'] = array();
     $compareData['column_0'][] = 'Is invalid.';
     $this->assertEquals($compareData, unserialize($data[0]->serializedAnalysisMessages));
     $this->assertEquals(ImportDataAnalyzer::STATUS_SKIP, $data[0]->analysisStatus);
     $compareData = array();
     $compareData['column_0'] = array();
     $compareData['column_0'][] = 'Is invalid.';
     $this->assertEquals($compareData, unserialize($data[1]->serializedAnalysisMessages));
     $this->assertEquals(ImportDataAnalyzer::STATUS_SKIP, $data[1]->analysisStatus);
     $compareData = array();
     $compareData['column_0'] = array();
     $compareData['column_0'][] = 'Is invalid.';
     $this->assertEquals($compareData, unserialize($data[2]->serializedAnalysisMessages));
     $this->assertEquals(ImportDataAnalyzer::STATUS_SKIP, $data[2]->analysisStatus);
     $this->assertNull($data[3]->serializedAnalysisMessages);
     $this->assertEquals(ImportDataAnalyzer::STATUS_CLEAN, $data[3]->analysisStatus);
     $this->assertNull($data[4]->serializedAnalysisMessages);
     $this->assertEquals(ImportDataAnalyzer::STATUS_CLEAN, $data[4]->analysisStatus);
     $this->assertNull($data[5]->serializedAnalysisMessages);
     $this->assertEquals(ImportDataAnalyzer::STATUS_CLEAN, $data[5]->analysisStatus);
     $this->assertNull($data[6]->serializedAnalysisMessages);
     $this->assertEquals(ImportDataAnalyzer::STATUS_CLEAN, $data[6]->analysisStatus);
     $this->assertNull($data[7]->serializedAnalysisMessages);
     $this->assertEquals(ImportDataAnalyzer::STATUS_CLEAN, $data[7]->analysisStatus);
     $this->assertNull($data[8]->serializedAnalysisMessages);
     $this->assertEquals(ImportDataAnalyzer::STATUS_CLEAN, $data[8]->analysisStatus);
     $this->assertNull($data[9]->serializedAnalysisMessages);
     $this->assertEquals(ImportDataAnalyzer::STATUS_CLEAN, $data[9]->analysisStatus);
     $this->assertNull($data[10]->serializedAnalysisMessages);
     $this->assertEquals(ImportDataAnalyzer::STATUS_CLEAN, $data[10]->analysisStatus);
     $this->assertNull($data[11]->serializedAnalysisMessages);
     $this->assertEquals(ImportDataAnalyzer::STATUS_CLEAN, $data[11]->analysisStatus);
     $this->assertNull($data[12]->serializedAnalysisMessages);
     $this->assertEquals(ImportDataAnalyzer::STATUS_CLEAN, $data[12]->analysisStatus);
 }
示例#4
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 testImportDataAnalysisResults()
 {
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $import = new Import();
     $serializedData['importRulesType'] = 'Users';
     $import->serializedData = serialize($serializedData);
     $this->assertTrue($import->save());
     ImportTestHelper::createTempTableByFileNameAndTableName('importAnalyzerTest.csv', $import->getTempTableName(), Yii::getPathOfAlias('application.modules.users.tests.unit.files'));
     $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))));
     $serializedData = unserialize($import->serializedData);
     $serializedData['mappingData'] = $mappingData;
     $import->serializedData = serialize($serializedData);
     $this->assertTrue($import->save());
     $importRules = ImportRulesUtil::makeImportRulesByType('Users');
     $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'));
     $importDataAnalyzer->analyzePage();
     $data = $dataProvider->getData();
     $this->assertEquals(10, count($data));
     $this->assertNull($data[0]->serializedAnalysisMessages);
     $this->assertEquals(ImportDataAnalyzer::STATUS_CLEAN, $data[0]->analysisStatus);
     $this->assertNull($data[1]->serializedAnalysisMessages);
     $this->assertEquals(ImportDataAnalyzer::STATUS_CLEAN, $data[1]->analysisStatus);
     $this->assertNull($data[2]->serializedAnalysisMessages);
     $this->assertEquals(ImportDataAnalyzer::STATUS_CLEAN, $data[2]->analysisStatus);
     $this->assertNull($data[3]->serializedAnalysisMessages);
     $this->assertEquals(ImportDataAnalyzer::STATUS_CLEAN, $data[3]->analysisStatus);
     $compareData = array();
     $compareData['column_0'] = array();
     $compareData['column_0'][] = 'Is too long. Maximum length is 64. This value will truncated upon import.';
     $this->assertEquals($compareData, unserialize($data[4]->serializedAnalysisMessages));
     $this->assertEquals(ImportDataAnalyzer::STATUS_WARN, $data[4]->analysisStatus);
     $this->assertNull($data[5]->serializedAnalysisMessages);
     $this->assertEquals(ImportDataAnalyzer::STATUS_CLEAN, $data[5]->analysisStatus);
     $this->assertNull($data[6]->serializedAnalysisMessages);
     $this->assertEquals(ImportDataAnalyzer::STATUS_CLEAN, $data[6]->analysisStatus);
     $compareData = array();
     $compareData['column_2'] = array();
     $compareData['column_2'][] = 'Status value is invalid. This status will be set to active upon import.';
     $this->assertEquals($compareData, unserialize($data[7]->serializedAnalysisMessages));
     $this->assertEquals(ImportDataAnalyzer::STATUS_WARN, $data[7]->analysisStatus);
     $compareData = array();
     $compareData['column_1'] = array();
     $compareData['column_1'][] = 'Is too long. Maximum length is 32. This value will truncated upon import.';
     $this->assertEquals($compareData, unserialize($data[8]->serializedAnalysisMessages));
     $this->assertEquals(ImportDataAnalyzer::STATUS_WARN, $data[8]->analysisStatus);
     $compareData = array();
     $compareData['column_2'] = array();
     $compareData['column_2'][] = 'Status value is invalid. This status will be set to active upon import.';
     $this->assertEquals($compareData, unserialize($data[9]->serializedAnalysisMessages));
     $this->assertEquals(ImportDataAnalyzer::STATUS_WARN, $data[9]->analysisStatus);
 }
 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);
 }
 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 testProcessStatusAndMessagesForEachRow()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $import = new Import();
     $serializedData['importRulesType'] = 'ImportModelTestItem';
     $import->serializedData = serialize($serializedData);
     $this->assertTrue($import->save());
     $testTableName = $import->getTempTableName();
     $this->assertTrue(ImportTestHelper::createTempTableByFileNameAndTableName('importTest.csv', $testTableName));
     $count = ImportDatabaseUtil::getCount($testTableName);
     $this->assertEquals(5, $count);
     //Now add import results.
     $resultsUtil = new ImportResultsUtil($import);
     $rowDataResultsUtil = new ImportRowDataResultsUtil(2);
     $rowDataResultsUtil->setStatusToUpdated();
     $rowDataResultsUtil->addMessage('the first message');
     $resultsUtil->addRowDataResults($rowDataResultsUtil);
     $rowDataResultsUtil = new ImportRowDataResultsUtil(3);
     $rowDataResultsUtil->setStatusToCreated();
     $rowDataResultsUtil->addMessage('the second message');
     $resultsUtil->addRowDataResults($rowDataResultsUtil);
     $rowDataResultsUtil = new ImportRowDataResultsUtil(4);
     $rowDataResultsUtil->setStatusToError();
     $rowDataResultsUtil->addMessage('the third message');
     $resultsUtil->addRowDataResults($rowDataResultsUtil);
     $resultsUtil->processStatusAndMessagesForEachRow();
     $sql = 'select * from ' . $testTableName . ' where id != 1';
     $tempTableData = R::getAll($sql);
     $compareData = array(array('id' => 2, 'column_0' => 'abc', 'column_1' => '123', 'column_2' => 'a', 'status' => 1, 'serializedmessages' => serialize(array('the first message'))), array('id' => 3, 'column_0' => 'def', 'column_1' => '563', 'column_2' => 'b', 'status' => 2, 'serializedmessages' => serialize(array('the second message'))), array('id' => 4, 'column_0' => 'efg', 'column_1' => '456', 'column_2' => 'a', 'status' => 3, 'serializedmessages' => serialize(array('the third message'))), array('id' => 5, 'column_0' => 'we1s', 'column_1' => null, 'column_2' => 'b', 'status' => null, 'serializedmessages' => null));
     $this->assertEquals($compareData, $tempTableData);
 }
 public function testRun()
 {
     $quote = DatabaseCompatibilityUtil::getQuote();
     //Create 2 imports, and set one with a date over a week ago (8 days ago) for the modifiedDateTime
     $import = new Import();
     $serializedData['importRulesType'] = 'ImportModelTestItem';
     $import->serializedData = serialize($serializedData);
     $this->assertTrue($import->save());
     ImportTestHelper::createTempTableByFileNameAndTableName('importAnalyzerTest.csv', $import->getTempTableName(), true);
     $modifiedDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time() - 60 * 60 * 24 * 8);
     $sql = "Update item set modifieddatetime = '" . $modifiedDateTime . "' where id = " . $import->getClassId('Item');
     ZurmoRedBean::exec($sql);
     $staleImportId = $import->id;
     $import2 = new Import();
     $serializedData['importRulesType'] = 'ImportModelTestItem';
     $import2->serializedData = serialize($serializedData);
     $this->assertTrue($import2->save());
     ImportTestHelper::createTempTableByFileNameAndTableName('importAnalyzerTest.csv', $import2->getTempTableName(), true);
     $this->assertEquals(2, Import::getCount());
     $tableExists = ZurmoRedBean::$writer->doesTableExist($import->getTempTableName());
     $this->assertTrue($tableExists);
     $job = new ImportCleanupJob();
     $this->assertTrue($job->run());
     $tableExists = ZurmoRedBean::$writer->doesTableExist($import->getTempTableName());
     $this->assertFalse($tableExists);
     $imports = Import::getAll();
     $this->assertEquals(1, count($imports));
     $this->assertEquals($import2->id, $imports[0]->id);
 }
 public function testSequentialProcessViewFactory()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $freezeWhenComplete = false;
     //Unfreeze since the test model is not part of the standard schema.
     if (RedBeanDatabase::isFrozen()) {
         RedBeanDatabase::unfreeze();
         $freezeWhenComplete = true;
     }
     $testModels = ImportModelTestItem::getAll();
     $this->assertEquals(0, count($testModels));
     $import = new Import();
     $mappingData = array('column_0' => array('attributeIndexOrDerivedType' => 'string', 'type' => 'importColumn', 'mappingRulesData' => array('DefaultValueModelAttributeMappingRuleForm' => array('defaultValue' => null))), 'column_23' => array('attributeIndexOrDerivedType' => 'FullName', 'type' => 'importColumn', 'mappingRulesData' => array('FullNameDefaultValueModelAttributeMappingRuleForm' => array('defaultValue' => null))));
     $serializedData['importRulesType'] = 'ImportModelTestItem';
     $serializedData['mappingData'] = $mappingData;
     $serializedData['firstRowIsHeaderRow'] = true;
     $import->serializedData = serialize($serializedData);
     $this->assertTrue($import->save());
     ImportTestHelper::createTempTableByFileNameAndTableName('importAnalyzerTest.csv', $import->getTempTableName());
     $config = array('pagination' => array('pageSize' => 2));
     $dataProvider = new ImportDataProvider($import->getTempTableName(), true, $config);
     $sequentialProcess = new ImportCreateUpdateModelsSequentialProcess($import, $dataProvider);
     $sequentialProcess->run(null, null);
     $route = 'default/someAction';
     $view = SequentialProcessViewFactory::makeBySequentialProcess($sequentialProcess, $route);
     $content = $view->render();
     $this->assertNotNull($content);
     $this->assertEquals('SequentialProcessView', get_class($view));
     $this->assertEquals('processRows', $sequentialProcess->getNextStep());
     //Now process the first run. Will process page 0.
     $sequentialProcess = new ImportCreateUpdateModelsSequentialProcess($import, $dataProvider);
     $sequentialProcess->run('processRows', null);
     $route = 'default/someAction';
     $view = SequentialProcessViewFactory::makeBySequentialProcess($sequentialProcess, $route);
     $content = $view->render();
     $this->assertNotNull($content);
     $this->assertEquals('SequentialProcessView', get_class($view));
     $this->assertEquals(array('page' => 1), $sequentialProcess->getNextParams());
     //Confirm 2 models were successfully added.
     $testModels = ImportModelTestItem::getAll();
     $this->assertEquals(2, count($testModels));
     //Re-freeze if needed.
     if ($freezeWhenComplete) {
         RedBeanDatabase::freeze();
     }
 }
 /**
  * @depends testImportDataAnalysisResults
  */
 public function testImportDataAnalysisUsingBatchAnalyzers()
 {
     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(), Yii::getPathOfAlias('application.modules.contacts.tests.unit.files'));
     $config = array('pagination' => array('pageSize' => 2));
     $dataProvider = new ImportDataProvider($import->getTempTableName(), true, $config);
     //Test contact state sanitization by batch.
     $dataAnalyzer = new ContactStateBatchAttributeValueDataAnalyzer('Contacts', null);
     $dataAnalyzer->runAndMakeMessages($dataProvider, 'column_0');
     $messages = $dataAnalyzer->getMessages();
     $this->assertEquals(1, count($messages));
     $compareMessage = '3 value(s) are not valid. Rows that have these values will be skipped during import.';
     $this->assertEquals($compareMessage, $messages[0]);
 }
示例#14
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));
 }
 /**
  * @depends testSetFormByPostForStep2
  */
 public function testImportFileHasAtLeastOneImportRow()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $import = new Import();
     $import->serializedData = serialize(array());
     $this->assertTrue($import->save());
     $this->assertTrue(ImportTestHelper::createTempTableByFileNameAndTableName('headerRowOnlyImportTest.csv', $import->getTempTableName(), true));
     $importWizardForm = new ImportWizardForm();
     $this->assertTrue(ImportWizardUtil::importFileHasAtLeastOneImportRow($importWizardForm, $import));
     //Now set that the first row is a header row and the check will fail.
     $importWizardForm->firstRowIsHeaderRow = true;
     $this->assertFalse(ImportWizardUtil::importFileHasAtLeastOneImportRow($importWizardForm, $import));
     ZurmoRedBean::$writer->dropTableByTableName($import->getTempTableName());
 }
示例#16
0
 /**
  * @depends testSimpleImportWithStringAndFullNameWhichAreRequiredAttributeOnImportTestModelItem
  */
 public function testSettingExplicitReadWriteModelPermissionsDuringImport()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $testModels = ImportModelTestItem::getAll();
     $this->assertEquals(0, count($testModels));
     //Add a read only user for import. Then all models should be readable by jim in addition to super.
     $explicitReadWriteModelPermissions = new ExplicitReadWriteModelPermissions();
     $explicitReadWriteModelPermissions->addReadOnlyPermitable(User::getByUsername('jim'));
     //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('importAnalyzerTest.csv', $import->getTempTableName());
     $this->assertEquals(13, ImportDatabaseUtil::getCount($import->getTempTableName()));
     // includes header rows.
     $mappingData = array('column_0' => array('attributeIndexOrDerivedType' => 'string', 'type' => 'importColumn', 'mappingRulesData' => array('DefaultValueModelAttributeMappingRuleForm' => array('defaultValue' => null))), 'column_23' => array('attributeIndexOrDerivedType' => 'FullName', 'type' => 'importColumn', 'mappingRulesData' => array('FullNameDefaultValueModelAttributeMappingRuleForm' => array('defaultValue' => null))));
     $importRules = ImportRulesUtil::makeImportRulesByType('ImportModelTestItem');
     $page = 0;
     $config = array('pagination' => array('pageSize' => 3));
     //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, $explicitReadWriteModelPermissions, $messageLogger);
     $importResultsUtil->processStatusAndMessagesForEachRow();
     //Confirm that 3 models where created.
     $testModels = ImportModelTestItem::getAll();
     $this->assertEquals(3, count($testModels));
     $jim = User::getByUsername('jim');
     foreach ($testModels as $model) {
         $this->assertEquals(array(Permission::READ, Permission::NONE), $model->getExplicitActualPermissions($jim));
     }
     //Clear out data in table
     R::exec("delete from " . ImportModelTestItem::getTableName('ImportModelTestItem'));
     //Now test with read/write permissions being set.
     $explicitReadWriteModelPermissions = new ExplicitReadWriteModelPermissions();
     $explicitReadWriteModelPermissions->addReadWritePermitable(User::getByUsername('jim'));
     $dataProvider = new ImportDataProvider($import->getTempTableName(), true, $config);
     $dataProvider->getPagination()->setCurrentPage($page);
     $importResultsUtil = new ImportResultsUtil($import);
     $messageLogger = new ImportMessageLogger();
     ImportUtil::importByDataProvider($dataProvider, $importRules, $mappingData, $importResultsUtil, $explicitReadWriteModelPermissions, $messageLogger);
     $importResultsUtil->processStatusAndMessagesForEachRow();
     //Confirm that 3 models where created.
     $testModels = ImportModelTestItem::getAll();
     $this->assertEquals(3, count($testModels));
     $jim = User::getByUsername('jim');
     foreach ($testModels as $model) {
         $this->assertEquals(array(Permission::READ_WRITE_CHANGE_PERMISSIONS_CHANGE_OWNER, Permission::NONE), $model->getExplicitActualPermissions($jim));
     }
     //Re-freeze if needed.
     if ($freezeWhenComplete) {
         RedBeanDatabase::freeze();
     }
 }
 /**
  * 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);
 }
 /**
  * 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());
 }
示例#19
0
 /**
  * @depends testImportDataAnalysisResults
  */
 public function testMinimumLengthsUsingBatchAnalyzers()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $import = new Import();
     $serializedData['importRulesType'] = 'ImportModelTestItem';
     $import->serializedData = serialize($serializedData);
     $this->assertTrue($import->save());
     ImportTestHelper::createTempTableByFileNameAndTableName('importAnalyzerMinLengthsTest.csv', $import->getTempTableName());
     $config = array('pagination' => array('pageSize' => 10));
     $mappingData = array('column_0' => array('attributeIndexOrDerivedType' => 'string', 'type' => 'importColumn', 'mappingRulesData' => array('DefaultValueModelAttributeMappingRuleForm' => array('defaultValue' => null))), 'column_1' => array('attributeIndexOrDerivedType' => 'FullName', 'type' => 'importColumn', 'mappingRulesData' => array('FullNameDefaultValueModelAttributeMappingRuleForm' => array('defaultValue' => null))));
     $serializedData = unserialize($import->serializedData);
     $serializedData['mappingData'] = $mappingData;
     $import->serializedData = serialize($serializedData);
     $this->assertTrue($import->save());
     $importRules = ImportRulesUtil::makeImportRulesByType('ImportModelTestItem');
     //This test csv has a header row.
     $dataProvider = new ImportDataProvider($import->getTempTableName(), true, $config);
     //Run data analyzer
     $importDataAnalyzer = new ImportDataAnalyzer($importRules, $dataProvider, $mappingData, array_keys($mappingData));
     $importDataAnalyzer->analyzePage();
     $data = $dataProvider->getData();
     $this->assertNull($data[0]->serializedAnalysisMessages);
     $this->assertEquals(ImportDataAnalyzer::STATUS_CLEAN, $data[0]->analysisStatus);
     $compareData = array();
     $compareData['column_1'] = array();
     $compareData['column_1'][] = 'Is too short.';
     $this->assertEquals($compareData, unserialize($data[1]->serializedAnalysisMessages));
     $this->assertEquals(ImportDataAnalyzer::STATUS_SKIP, $data[1]->analysisStatus);
     $compareData = array();
     $compareData['column_0'] = array();
     $compareData['column_0'][] = 'Is too short. Minimum length is 3.';
     $this->assertEquals($compareData, unserialize($data[2]->serializedAnalysisMessages));
     $this->assertEquals(ImportDataAnalyzer::STATUS_SKIP, $data[2]->analysisStatus);
     $compareData = array();
     $compareData['column_0'] = array();
     $compareData['column_0'][] = 'Is too short. Minimum length is 3.';
     $compareData['column_1'] = array();
     $compareData['column_1'][] = 'Is too short.';
     $this->assertEquals($compareData, unserialize($data[3]->serializedAnalysisMessages));
     $this->assertEquals(ImportDataAnalyzer::STATUS_SKIP, $data[3]->analysisStatus);
 }
示例#20
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());
 }
 /**
  * @param Import $import
  * @param bool $firstRowIsHeaderRow
  * @return ImportDataProvider
  */
 protected function makeDataProviderForSampleRow($import, $firstRowIsHeaderRow)
 {
     assert('$import instanceof Import');
     assert('is_bool($firstRowIsHeaderRow)');
     $config = array('pagination' => array('pageSize' => 1));
     return new ImportDataProvider($import->getTempTableName(), $firstRowIsHeaderRow, $config);
 }
示例#22
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));
 }
示例#23
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));
 }
示例#24
0
 protected function makeImportCompleteView(Import $import, ImportWizardForm $importWizardForm, $setCurrentPageToFirst = false)
 {
     $pageSize = Yii::app()->pagination->resolveActiveForCurrentUserByType('listPageSize');
     $config = array('pagination' => array('pageSize' => $pageSize));
     if ($setCurrentPageToFirst) {
         $config['pagination']['currentPage'] = 0;
     }
     $importErrorsDataProvider = new ImportDataProvider($import->getTempTableName(), (bool) $importWizardForm->firstRowIsHeaderRow, $config, ImportRowDataResultsUtil::ERROR);
     $errorListView = new ImportErrorsListView($this->getId(), $this->getModule()->getId(), 'NotUsed', $importErrorsDataProvider);
     $importCompleteView = new ImportWizardCreateUpdateModelsCompleteView($this->getId(), $this->getModule()->getId(), $importWizardForm, (int) ImportRowDataResultsUtil::getCreatedCount($import->getTempTableName()), (int) ImportRowDataResultsUtil::getUpdatedCount($import->getTempTableName()), (int) ImportRowDataResultsUtil::getErrorCount($import->getTempTableName()), $errorListView);
     return $importCompleteView;
 }
 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));
 }
示例#26
0
 public function actionCreateDemoImportForAnalysis($firstRowIsHeaderRow = true)
 {
     if (!Group::isUserASuperAdministrator(Yii::app()->user->userModel)) {
         throw new NotSupportedException();
     }
     $import = new Import();
     $serializedData['importRulesType'] = 'Accounts';
     $mappingData = array('column_0' => array('attributeIndexOrDerivedType' => 'name', 'type' => 'importColumn', 'mappingRulesData' => array('DefaultValueModelAttributeMappingRuleForm' => array('defaultValue' => null))), 'column_1' => array('attributeIndexOrDerivedType' => 'officePhone', 'type' => 'importColumn', 'mappingRulesData' => array('DefaultValueModelAttributeMappingRuleForm' => array('defaultValue' => null))), 'column_2' => array('attributeIndexOrDerivedType' => 'officeFax', 'type' => 'importColumn', 'mappingRulesData' => array('DefaultValueModelAttributeMappingRuleForm' => array('defaultValue' => null))), 'column_3' => array('attributeIndexOrDerivedType' => 'employees', 'type' => 'importColumn', 'mappingRulesData' => array('DefaultValueModelAttributeMappingRuleForm' => array('defaultValue' => null))), 'column_4' => array('attributeIndexOrDerivedType' => 'annualRevenue', 'type' => 'importColumn', 'mappingRulesData' => array('DefaultValueModelAttributeMappingRuleForm' => array('defaultValue' => null))), 'column_5' => array('attributeIndexOrDerivedType' => 'description', 'type' => 'importColumn', 'mappingRulesData' => array('DefaultValueModelAttributeMappingRuleForm' => array('defaultValue' => null))), 'column_6' => array('attributeIndexOrDerivedType' => 'website', 'type' => 'importColumn', 'mappingRulesData' => array('DefaultValueModelAttributeMappingRuleForm' => array('defaultValue' => null))), 'column_7' => array('attributeIndexOrDerivedType' => null, 'type' => 'importColumn', 'mappingRulesData' => array()));
     $serializedData['mappingData'] = $mappingData;
     $serializedData['rowColumnDelimiter'] = ',';
     // Not Coding Standard
     $serializedData['rowColumnEnclosure'] = '"';
     $serializedData['firstRowIsHeaderRow'] = $firstRowIsHeaderRow;
     $import->serializedData = serialize($serializedData);
     $saved = $import->save();
     if (!$saved) {
         throw new FailedToSaveModelException();
     }
     $this->createImportTempTable(8, $import->getTempTableName());
     //Make header row
     if ($firstRowIsHeaderRow) {
         $newBean = ZurmoRedBean::dispense($import->getTempTableName());
         $newBean->column_0 = 'Header #1';
         $newBean->column_1 = 'Header #2';
         $newBean->column_2 = 'Header #3';
         $newBean->column_3 = 'Header #4';
         $newBean->column_4 = 'Header #5';
         $newBean->column_5 = 'Header #6';
         $newBean->column_6 = 'Header #7';
         $newBean->column_7 = 'Header #8';
         ZurmoRedBean::store($newBean);
     }
     //Make data rows that are clean
     for ($i = 0; $i < 3; $i++) {
         $newBean = ZurmoRedBean::dispense($import->getTempTableName());
         $newBean->column_0 = 'aa1' . $i;
         $newBean->column_1 = 'aa2' . $i;
         $newBean->column_2 = 'aa3' . $i;
         $newBean->column_3 = 'aa4' . $i;
         $newBean->column_4 = 'aa5' . $i;
         $newBean->column_5 = 'aa6' . $i;
         $newBean->column_6 = 'aa7' . $i;
         $newBean->column_7 = 'aa8' . $i;
         $newBean->analysisStatus = ImportDataAnalyzer::STATUS_CLEAN;
         $analysisData = array();
         $analysisData['column_0'] = array();
         $analysisData['column_0'][] = 'a test message 1';
         $analysisData['column_0'][] = 'a test message 2';
         $analysisData['column_2'] = array();
         $analysisData['column_2'][] = 'a test message 1';
         $analysisData['column_2'][] = 'a test message 2';
         $newBean->serializedAnalysisMessages = serialize($analysisData);
         ZurmoRedBean::store($newBean);
     }
     //Make data rows that have a warning
     for ($i = 0; $i < 3; $i++) {
         $newBean = ZurmoRedBean::dispense($import->getTempTableName());
         $newBean->column_0 = 'ba1' . $i;
         $newBean->column_1 = 'ba2' . $i;
         $newBean->column_2 = 'ba3' . $i;
         $newBean->column_3 = 'ba4' . $i;
         $newBean->column_4 = 'ba5' . $i;
         $newBean->column_5 = 'ba6' . $i;
         $newBean->column_6 = 'ba7' . $i;
         $newBean->column_7 = 'ba8' . $i;
         $newBean->analysisStatus = ImportDataAnalyzer::STATUS_WARN;
         $analysisData = array();
         $analysisData['column_0'] = array();
         $analysisData['column_0'][] = 'a test message 1';
         $analysisData['column_0'][] = 'a test message 2';
         $analysisData['column_2'] = array();
         $analysisData['column_2'][] = 'a test message 1';
         $analysisData['column_2'][] = 'a test message 2';
         $newBean->serializedAnalysisMessages = serialize($analysisData);
         ZurmoRedBean::store($newBean);
     }
     //Make data rows that are skipped
     for ($i = 0; $i < 10; $i++) {
         $newBean = ZurmoRedBean::dispense($import->getTempTableName());
         $newBean->column_0 = 'ca1' . $i;
         $newBean->column_1 = 'ca2' . $i;
         $newBean->column_2 = 'ca3' . $i;
         $newBean->column_3 = 'ca4' . $i;
         $newBean->column_4 = 'ca5' . $i;
         $newBean->column_5 = 'ca6' . $i;
         $newBean->column_6 = 'ca7' . $i;
         $newBean->column_7 = 'ca8' . $i;
         $newBean->analysisStatus = ImportDataAnalyzer::STATUS_SKIP;
         $analysisData = array();
         $analysisData['column_0'] = array();
         $analysisData['column_0'][] = 'a test message 1';
         $analysisData['column_0'][] = 'a test message 2';
         $analysisData['column_2'] = array();
         $analysisData['column_2'][] = 'a test message 1';
         $analysisData['column_2'][] = 'a test message 2';
         $newBean->serializedAnalysisMessages = serialize($analysisData);
         ZurmoRedBean::store($newBean);
     }
     ZurmoRedBean::store($newBean);
     echo 'the import id is: ' . $import->id;
 }
 /**
  * @depends testImportDataAnalysisUsingBatchAnalyzers
  */
 public function testMinimumLengthsUsingBatchAnalyzers()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $import = new Import();
     $serializedData['importRulesType'] = 'ImportModelTestItem';
     $import->serializedData = serialize($serializedData);
     $this->assertTrue($import->save());
     ImportTestHelper::createTempTableByFileNameAndTableName('importAnalyzerMinLengthsTest.csv', $import->getTempTableName());
     $config = array('pagination' => array('pageSize' => 2));
     $dataProvider = new ImportDataProvider($import->getTempTableName(), true, $config);
     //test that strings have minimum lengths (string min 3)
     $dataAnalyzer = new MinimumLengthBatchAttributeValueDataAnalyzer('ImportModelTestItem', 'string');
     $dataAnalyzer->runAndMakeMessages($dataProvider, 'column_0');
     $messages = $dataAnalyzer->getMessages();
     $this->assertEquals(1, count($messages));
     $compareMessage = '2 value(s) are too short for this field. These rows will be skipped during import.';
     $this->assertEquals($compareMessage, $messages[0]);
     //test that a full name has the minimum required last name length. (min 2)
     $dataAnalyzer = new FullNameBatchAttributeValueDataAnalyzer('ImportModelTestItem', null);
     $dataAnalyzer->runAndMakeMessages($dataProvider, 'column_1');
     $messages = $dataAnalyzer->getMessages();
     $this->assertEquals(1, count($messages));
     $compareMessage = '2 value(s) are too short for this field. These rows will be skipped during import.';
     $this->assertEquals($compareMessage, $messages[0]);
 }
 /**
  * @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);
 }
 /**
  * @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));
 }
 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);
 }