public function testSimpleUserImportWhereAllRowsSucceed() { Yii::app()->user->userModel = User::getByUsername('super'); $tasks = Task::getAll(); $this->assertEquals(0, count($tasks)); $import = new Import(); $serializedData['importRulesType'] = 'Tasks'; $serializedData['firstRowIsHeaderRow'] = true; $import->serializedData = serialize($serializedData); $this->assertTrue($import->save()); ImportTestHelper::createTempTableByFileNameAndTableName('simpleImportTest.csv', $import->getTempTableName(), Yii::getPathOfAlias('application.modules.tasks.tests.unit.files')); $this->assertEquals(4, ImportDatabaseUtil::getCount($import->getTempTableName())); // includes header rows. $mappingData = array('column_0' => ImportMappingUtil::makeStringColumnMappingData('name'), 'column_1' => ImportMappingUtil::makeDateTimeColumnMappingData('dueDateTime'), 'column_2' => ImportMappingUtil::makeDateTimeColumnMappingData('completedDateTime'), 'column_3' => ImportMappingUtil::makeBooleanColumnMappingData('completed'), 'column_4' => ImportMappingUtil::makeModelDerivedColumnMappingData('AccountDerived'), 'column_5' => ImportMappingUtil::makeModelDerivedColumnMappingData('ContactDerived'), 'column_6' => ImportMappingUtil::makeModelDerivedColumnMappingData('OpportunityDerived'), 'column_7' => ImportMappingUtil::makeTextAreaColumnMappingData('description')); $importRules = ImportRulesUtil::makeImportRulesByType('Tasks'); $page = 0; $config = array('pagination' => array('pageSize' => 50)); //This way all rows are processed. $dataProvider = new ImportDataProvider($import->getTempTableName(), true, $config); $dataProvider->getPagination()->setCurrentPage($page); $importResultsUtil = new ImportResultsUtil($import); $actionDateTime = substr(DateTimeUtil::convertTimestampToDbFormatDateTime(time()), 0, -3); $messageLogger = new ImportMessageLogger(); ImportUtil::importByDataProvider($dataProvider, $importRules, $mappingData, $importResultsUtil, new ExplicitReadWriteModelPermissions(), $messageLogger); $importResultsUtil->processStatusAndMessagesForEachRow(); //Confirm that 3 models where created. $tasks = Task::getAll(); $this->assertEquals(3, count($tasks)); $tasks = Task::getByName('task1'); $this->assertEquals(1, count($tasks[0])); $this->assertEquals(1, count($tasks[0]->activityItems)); $this->assertEquals('testAccount', $tasks[0]->activityItems[0]->name); $this->assertEquals('Account', get_class($tasks[0]->activityItems[0])); $this->assertNull($tasks[0]->completed); $this->assertEquals($actionDateTime, substr($tasks[0]->latestDateTime, 0, -3)); $tasks = Task::getByName('task2'); $this->assertEquals(1, count($tasks[0])); $this->assertEquals(1, count($tasks[0]->activityItems)); $this->assertEquals('testContact', $tasks[0]->activityItems[0]->firstName); $this->assertEquals('Contact', get_class($tasks[0]->activityItems[0])); $this->assertEquals(1, $tasks[0]->completed); $this->assertEquals('2011-12-22 06:03', substr($tasks[0]->latestDateTime, 0, -3)); $tasks = Task::getByName('task3'); $this->assertEquals(1, count($tasks[0])); $this->assertEquals(1, count($tasks[0]->activityItems)); $this->assertEquals('testOpportunity', $tasks[0]->activityItems[0]->name); $this->assertEquals('Opportunity', get_class($tasks[0]->activityItems[0])); $this->assertNull($tasks[0]->completed); $this->assertEquals($actionDateTime, substr($tasks[0]->latestDateTime, 0, -3)); //Confirm 10 rows were processed as 'created'. $this->assertEquals(3, ImportDatabaseUtil::getCount($import->getTempTableName(), "status = " . ImportRowDataResultsUtil::CREATED)); //Confirm that 0 rows were processed as 'updated'. $this->assertEquals(0, ImportDatabaseUtil::getCount($import->getTempTableName(), "status = " . ImportRowDataResultsUtil::UPDATED)); //Confirm 2 rows were processed as 'errors'. $this->assertEquals(0, ImportDatabaseUtil::getCount($import->getTempTableName(), "status = " . ImportRowDataResultsUtil::ERROR)); $beansWithErrors = ImportDatabaseUtil::getSubset($import->getTempTableName(), "status = " . ImportRowDataResultsUtil::ERROR); $this->assertEquals(0, count($beansWithErrors)); }
public function testSimpleUserImportWhereAllRowsSucceed() { Yii::app()->user->userModel = User::getByUsername('super'); $import = new Import(); $serializedData['importRulesType'] = 'ProductTemplates'; $serializedData['firstRowIsHeaderRow'] = true; $import->serializedData = serialize($serializedData); $this->assertTrue($import->save()); ImportTestHelper::createTempTableByFileNameAndTableName('productTemplates.csv', $import->getTempTableName(), Yii::getPathOfAlias('application.modules.productTemplates.tests.unit.files')); $this->assertEquals(3, ImportDatabaseUtil::getCount($import->getTempTableName())); // includes header rows. $currencies = Currency::getAll(); $mappingData = array('column_0' => ImportMappingUtil::makeStringColumnMappingData('name'), 'column_1' => ImportMappingUtil::makeTextAreaColumnMappingData('description'), 'column_2' => ImportMappingUtil::makeIntegerColumnMappingData('sellPriceFormula__type'), 'column_3' => ImportMappingUtil::makeFloatColumnMappingData('sellPriceFormula__discountOrMarkupPercentage'), 'column_4' => ImportMappingUtil::makeCurrencyColumnMappingData('cost', $currencies[0]), 'column_5' => ImportMappingUtil::makeCurrencyColumnMappingData('listPrice', $currencies[0]), 'column_6' => ImportMappingUtil::makeCurrencyColumnMappingData('sellPrice', $currencies[0]), 'column_7' => ImportMappingUtil::makeIntegerColumnMappingData('priceFrequency'), 'column_8' => ImportMappingUtil::makeIntegerColumnMappingData('type'), 'column_9' => ImportMappingUtil::makeIntegerColumnMappingData('status')); $importRules = ImportRulesUtil::makeImportRulesByType('ProductTemplates'); $page = 0; $config = array('pagination' => array('pageSize' => 50)); //This way all rows are processed. $dataProvider = new ImportDataProvider($import->getTempTableName(), true, $config); $dataProvider->getPagination()->setCurrentPage($page); $importResultsUtil = new ImportResultsUtil($import); $messageLogger = new ImportMessageLogger(); ImportUtil::importByDataProvider($dataProvider, $importRules, $mappingData, $importResultsUtil, new ExplicitReadWriteModelPermissions(), $messageLogger); $importResultsUtil->processStatusAndMessagesForEachRow(); //Confirm that 3 models where created. $productTemplates = ProductTemplate::getAll(); $this->assertEquals(2, count($productTemplates)); $productTemplates = ProductTemplate::getByName('A Gift of Monotheists import'); $this->assertEquals(1, count($productTemplates[0])); $this->assertEquals('A Gift of Monotheists import', $productTemplates[0]->name); $this->assertEquals(2, $productTemplates[0]->sellPriceFormula->type); $this->assertEquals(10, $productTemplates[0]->sellPriceFormula->discountOrMarkupPercentage); $this->assertEquals(180, $productTemplates[0]->sellPrice->value); $this->assertEquals(200, $productTemplates[0]->listPrice->value); $this->assertEquals(200, $productTemplates[0]->cost->value); $this->assertEquals(2, $productTemplates[0]->priceFrequency); $this->assertEquals(2, $productTemplates[0]->type); $this->assertEquals(2, $productTemplates[0]->status); $productTemplates[0]->delete(); $productTemplates = ProductTemplate::getByName('A Gift of Monotheists import Copy'); $this->assertEquals(1, count($productTemplates[0])); $this->assertEquals('A Gift of Monotheists import Copy', $productTemplates[0]->name); $this->assertEquals(2, $productTemplates[0]->sellPriceFormula->type); $this->assertEquals(5, $productTemplates[0]->sellPriceFormula->discountOrMarkupPercentage); $this->assertEquals(180, $productTemplates[0]->sellPrice->value); $this->assertEquals(200, $productTemplates[0]->listPrice->value); $this->assertEquals(200, $productTemplates[0]->cost->value); $this->assertEquals(2, $productTemplates[0]->priceFrequency); $this->assertEquals(2, $productTemplates[0]->type); $this->assertEquals(2, $productTemplates[0]->status); $productTemplates[0]->delete(); //Confirm that 2 rows were processed as 'updated'. $this->assertEquals(0, ImportDatabaseUtil::getCount($import->getTempTableName(), "status = " . ImportRowDataResultsUtil::UPDATED)); //Confirm 2 rows were processed as 'errors'. $this->assertEquals(0, ImportDatabaseUtil::getCount($import->getTempTableName(), "status = " . ImportRowDataResultsUtil::ERROR)); $beansWithErrors = ImportDatabaseUtil::getSubset($import->getTempTableName(), "status = " . ImportRowDataResultsUtil::ERROR); $this->assertEquals(0, count($beansWithErrors)); }
public function testSimpleUserImportWhereAllRowsSucceed() { Yii::app()->user->userModel = User::getByUsername('super'); $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 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 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 testNewlyImportedDataForUpdateEmailDedupe() { $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('abc'); $this->assertEquals(1, count($testModels)); $testModels = Account::getByName('mom'); $this->assertEquals(1, count($testModels)); $testModels = Account::getByName('hello'); $this->assertEquals(0, count($testModels)); $testModels = Account::getByName('dear'); $this->assertEquals(0, count($testModels)); $import = new Import(); $serializedData['importRulesType'] = 'Accounts'; $serializedData['firstRowIsHeaderRow'] = true; $import->serializedData = serialize($serializedData); $this->assertTrue($import->save()); ImportTestHelper::createTempTableByFileNameAndTableName('importEmailUpdateDedupeTest.csv', $import->getTempTableName(), true); $this->assertEquals(3, ImportDatabaseUtil::getCount($import->getTempTableName())); // includes header rows. $emailMappingData = ImportMappingUtil::makeEmailColumnMappingData('primaryEmail__emailAddress'); $emailMappingData['mappingRulesData']['EmailModelAttributeDedupeMappingRuleForm'] = array('dedupeRule' => ImportDedupeRulesRadioDropDownElement::UPDATE_ROW_ON_MATCH_FOUND); $mappingData = array('column_0' => ImportMappingUtil::makeStringColumnMappingData('name'), '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(); //Confirm that 3 models where created. $testModels = Account::getAll(); $this->assertEquals(3, count($testModels)); $testModels = Account::getByName('abc'); $this->assertEquals(0, count($testModels)); $testModels = Account::getByName('mom'); $this->assertEquals(0, count($testModels)); $testModels = Account::getByName('hello'); $this->assertEquals(1, count($testModels)); $testModels = Account::getByName('dear'); $this->assertEquals(1, count($testModels)); }
/** * 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()); }
/** * @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()); }
/** * @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)); }
public function testSimpleUserImportWhereAllRowsSucceed() { Yii::app()->user->userModel = User::getByUsername('super'); $contacts = Contact::getAll(); $this->assertEquals(0, count($contacts)); $import = new Import(); $serializedData['importRulesType'] = 'Leads'; $serializedData['firstRowIsHeaderRow'] = true; $import->serializedData = serialize($serializedData); $this->assertTrue($import->save()); ImportTestHelper::createTempTableByFileNameAndTableName('importTest.csv', $import->getTempTableName(), true, Yii::getPathOfAlias('application.modules.leads.tests.unit.files')); $this->assertEquals(4, ImportDatabaseUtil::getCount($import->getTempTableName())); // includes header rows. $currency = Currency::getByCode(Yii::app()->currencyHelper->getBaseCode()); $mappingData = array('column_0' => ImportMappingUtil::makeStringColumnMappingData('firstName'), 'column_1' => ImportMappingUtil::makeStringColumnMappingData('lastName'), 'column_2' => ImportMappingUtil::makeStringColumnMappingData('jobTitle'), 'column_3' => ImportMappingUtil::makeStringColumnMappingData('officePhone'), 'column_4' => ImportMappingUtil::makeStringColumnMappingData('officeFax'), 'column_5' => ImportMappingUtil::makeStringColumnMappingData('department'), 'column_6' => ImportMappingUtil::makeUrlColumnMappingData('website'), 'column_7' => ImportMappingUtil::makeTextAreaColumnMappingData('description'), 'column_8' => ImportMappingUtil::makeStringColumnMappingData('primaryAddress__city'), 'column_9' => ImportMappingUtil::makeStringColumnMappingData('primaryAddress__country'), 'column_10' => ImportMappingUtil::makeStringColumnMappingData('primaryAddress__postalCode'), 'column_11' => ImportMappingUtil::makeStringColumnMappingData('primaryAddress__state'), 'column_12' => ImportMappingUtil::makeStringColumnMappingData('primaryAddress__street1'), 'column_13' => ImportMappingUtil::makeStringColumnMappingData('primaryAddress__street2'), 'column_14' => ImportMappingUtil::makeEmailColumnMappingData('primaryEmail__emailAddress'), 'column_15' => ImportMappingUtil::makeBooleanColumnMappingData('primaryEmail__isInvalid'), 'column_16' => ImportMappingUtil::makeBooleanColumnMappingData('primaryEmail__optOut'), 'column_17' => ImportMappingUtil::makeDropDownColumnMappingData('source'), 'column_18' => LeadImportTestHelper::makeStateColumnMappingData(), 'column_19' => ImportMappingUtil::makeDropDownColumnMappingData('industry'), 'column_20' => ImportMappingUtil::makeStringColumnMappingData('companyName')); $importRules = ImportRulesUtil::makeImportRulesByType('Leads'); $page = 0; $config = array('pagination' => array('pageSize' => 50)); //This way all rows are processed. $dataProvider = new ImportDataProvider($import->getTempTableName(), true, $config); $dataProvider->getPagination()->setCurrentPage($page); $importResultsUtil = new ImportResultsUtil($import); $messageLogger = new ImportMessageLogger(); ImportUtil::importByDataProvider($dataProvider, $importRules, $mappingData, $importResultsUtil, new ExplicitReadWriteModelPermissions(), $messageLogger); $importResultsUtil->processStatusAndMessagesForEachRow(); //Confirm that 3 models where created. $contacts = Contact::getAll(); $this->assertEquals(3, count($contacts)); $contacts = Contact::getByName('contact1 contact1son'); $this->assertEquals(1, count($contacts[0])); $this->assertEquals('contact1', $contacts[0]->firstName); $this->assertEquals('contact1son', $contacts[0]->lastName); $this->assertEquals('president', $contacts[0]->jobTitle); $this->assertEquals(123456, $contacts[0]->officePhone); $this->assertEquals(555, $contacts[0]->officeFax); $this->assertEquals('executive', $contacts[0]->department); $this->assertEquals('http://www.contact1.com', $contacts[0]->website); $this->assertEquals('desc1', $contacts[0]->description); $this->assertEquals('city1', $contacts[0]->primaryAddress->city); $this->assertEquals('country1', $contacts[0]->primaryAddress->country); $this->assertEquals('postal1', $contacts[0]->primaryAddress->postalCode); $this->assertEquals('state1', $contacts[0]->primaryAddress->state); $this->assertEquals('street11', $contacts[0]->primaryAddress->street1); $this->assertEquals('street21', $contacts[0]->primaryAddress->street2); $this->assertEquals('*****@*****.**', $contacts[0]->primaryEmail->emailAddress); $this->assertEquals(null, $contacts[0]->primaryEmail->isInvalid); $this->assertEquals(null, $contacts[0]->primaryEmail->optOut); $this->assertEquals('Self-Generated', $contacts[0]->source->value); $this->assertEquals('New', $contacts[0]->state->name); $this->assertEquals('Automotive', $contacts[0]->industry->value); $this->assertEquals('company1', $contacts[0]->companyName); $contacts = Contact::getByName('contact2 contact2son'); $this->assertEquals(1, count($contacts[0])); $this->assertEquals('contact2', $contacts[0]->firstName); $this->assertEquals('contact2son', $contacts[0]->lastName); $this->assertEquals('president2', $contacts[0]->jobTitle); $this->assertEquals(223456, $contacts[0]->officePhone); $this->assertEquals(655, $contacts[0]->officeFax); $this->assertEquals('executive2', $contacts[0]->department); $this->assertEquals('http://www.contact2.com', $contacts[0]->website); $this->assertEquals('desc2', $contacts[0]->description); $this->assertEquals('city2', $contacts[0]->primaryAddress->city); $this->assertEquals('country2', $contacts[0]->primaryAddress->country); $this->assertEquals('postal2', $contacts[0]->primaryAddress->postalCode); $this->assertEquals('state2', $contacts[0]->primaryAddress->state); $this->assertEquals('street12', $contacts[0]->primaryAddress->street1); $this->assertEquals('street22', $contacts[0]->primaryAddress->street2); $this->assertEquals('*****@*****.**', $contacts[0]->primaryEmail->emailAddress); $this->assertEquals(null, $contacts[0]->primaryEmail->isInvalid); $this->assertEquals(null, $contacts[0]->primaryEmail->optOut); $this->assertEquals('Tradeshow', $contacts[0]->source->value); $this->assertEquals('Recycled', $contacts[0]->state->name); $this->assertEquals('Banking', $contacts[0]->industry->value); $this->assertEquals('company2', $contacts[0]->companyName); $contacts = Contact::getByName('contact3 contact3son'); $this->assertEquals(1, count($contacts[0])); $this->assertEquals('contact3', $contacts[0]->firstName); $this->assertEquals('contact3son', $contacts[0]->lastName); $this->assertEquals('president3', $contacts[0]->jobTitle); $this->assertEquals(323456, $contacts[0]->officePhone); $this->assertEquals(755, $contacts[0]->officeFax); $this->assertEquals('executive3', $contacts[0]->department); $this->assertEquals('http://www.contact3.com', $contacts[0]->website); $this->assertEquals('desc3', $contacts[0]->description); $this->assertEquals('city3', $contacts[0]->primaryAddress->city); $this->assertEquals('country3', $contacts[0]->primaryAddress->country); $this->assertEquals('postal3', $contacts[0]->primaryAddress->postalCode); $this->assertEquals('state3', $contacts[0]->primaryAddress->state); $this->assertEquals('street13', $contacts[0]->primaryAddress->street1); $this->assertEquals('street23', $contacts[0]->primaryAddress->street2); $this->assertEquals('*****@*****.**', $contacts[0]->primaryEmail->emailAddress); $this->assertEquals('1', $contacts[0]->primaryEmail->isInvalid); $this->assertEquals('1', $contacts[0]->primaryEmail->optOut); $this->assertEquals('Inbound Call', $contacts[0]->source->value); $this->assertEquals('New', $contacts[0]->state->name); $this->assertEquals('Energy', $contacts[0]->industry->value); $this->assertEquals('company3', $contacts[0]->companyName); //Confirm 3 rows were processed as 'created'. $this->assertEquals(3, ImportDatabaseUtil::getCount($import->getTempTableName(), "status = " . ImportRowDataResultsUtil::CREATED)); //Confirm that 0 rows were processed as 'updated'. $this->assertEquals(0, ImportDatabaseUtil::getCount($import->getTempTableName(), "status = " . ImportRowDataResultsUtil::UPDATED)); //Confirm 0 rows were processed as 'errors'. $this->assertEquals(0, ImportDatabaseUtil::getCount($import->getTempTableName(), "status = " . ImportRowDataResultsUtil::ERROR)); $beansWithErrors = ImportDatabaseUtil::getSubset($import->getTempTableName(), "status = " . ImportRowDataResultsUtil::ERROR); $this->assertEquals(0, count($beansWithErrors)); }
public function testImportWithLatestActivityDateTime() { Yii::app()->user->userModel = User::getByUsername('super'); $accounts = Account::deleteAll(); $import = new Import(); $serializedData['importRulesType'] = 'Accounts'; $serializedData['firstRowIsHeaderRow'] = true; $import->serializedData = serialize($serializedData); $this->assertTrue($import->save()); ImportTestHelper::createTempTableByFileNameAndTableName('importWithLatestActivityDateTimeTest.csv', $import->getTempTableName(), true, Yii::getPathOfAlias('application.modules.accounts.tests.unit.files')); $mappingData = array('column_0' => ImportMappingUtil::makeStringColumnMappingData('name'), 'column_1' => ImportMappingUtil::makeDateTimeColumnMappingData('latestActivityDateTime')); $importRules = ImportRulesUtil::makeImportRulesByType('Accounts'); $page = 0; $config = array('pagination' => array('pageSize' => 50)); //This way all rows are processed. $dataProvider = new ImportDataProvider($import->getTempTableName(), true, $config); $dataProvider->getPagination()->setCurrentPage($page); $importResultsUtil = new ImportResultsUtil($import); $messageLogger = new ImportMessageLogger(); ImportUtil::importByDataProvider($dataProvider, $importRules, $mappingData, $importResultsUtil, new ExplicitReadWriteModelPermissions(), $messageLogger); $importResultsUtil->processStatusAndMessagesForEachRow(); //Confirm that 2 models where created. $accounts = Account::getAll(); $this->assertCount(2, $accounts); $accounts = Account::getByName('company1'); $this->assertEquals('2011-12-22 05:03', substr($accounts[0]->latestActivityDateTime, 0, -3)); $accounts = Account::getByName('company2'); $this->assertNull($accounts[0]->latestActivityDateTime); //Confirm 2 rows were processed as 'created'. $this->assertEquals(2, ImportDatabaseUtil::getCount($import->getTempTableName(), "status = " . ImportRowDataResultsUtil::CREATED)); //Confirm that 0 rows were processed as 'updated'. $this->assertEquals(0, ImportDatabaseUtil::getCount($import->getTempTableName(), "status = " . ImportRowDataResultsUtil::UPDATED)); //Confirm 0 rows were processed as 'errors'. $this->assertEquals(0, ImportDatabaseUtil::getCount($import->getTempTableName(), "status = " . ImportRowDataResultsUtil::ERROR)); $beansWithErrors = ImportDatabaseUtil::getSubset($import->getTempTableName(), "status = " . ImportRowDataResultsUtil::ERROR); $this->assertEquals(0, count($beansWithErrors)); }
/** * @depends testImportSwitchingOwnerButShouldStillCreate */ public function testImportWithoutCurrencyValues() { Yii::app()->user->userModel = User::getByUsername('super'); //Unfreeze since the test model is not part of the standard schema. $freezeWhenComplete = false; if (RedBeanDatabase::isFrozen()) { RedBeanDatabase::unfreeze(); $freezeWhenComplete = true; } $testModels = ImportModelTestItem::getAll(); $this->assertEquals(0, count($testModels)); $import = new Import(); $serializedData['importRulesType'] = 'ImportModelTestItem'; $serializedData['firstRowIsHeaderRow'] = true; $import->serializedData = serialize($serializedData); $this->assertTrue($import->save()); ImportTestHelper::createTempTableByFileNameAndTableName('importEmptyCurrencyTest.csv', $import->getTempTableName()); $this->assertEquals(3, ImportDatabaseUtil::getCount($import->getTempTableName())); // includes header rows. $mappingData = array('column_0' => ImportMappingUtil::makeStringColumnMappingData('lastName'), 'column_1' => ImportMappingUtil::makeStringColumnMappingData('string')); $importRules = ImportRulesUtil::makeImportRulesByType('ImportModelTestItem'); $page = 0; $config = array('pagination' => array('pageSize' => 50)); //This way all rows are processed. $dataProvider = new ImportDataProvider($import->getTempTableName(), true, $config); $dataProvider->getPagination()->setCurrentPage($page); $importResultsUtil = new ImportResultsUtil($import); $messageLogger = new ImportMessageLogger(); ImportUtil::importByDataProvider($dataProvider, $importRules, $mappingData, $importResultsUtil, new ExplicitReadWriteModelPermissions(), $messageLogger); $importResultsUtil->processStatusAndMessagesForEachRow(); //Confirm that 2 models where created. $testModels = ImportModelTestItem::getAll(); $this->assertEquals(2, count($testModels)); $jim = User::getByUsername('jim'); foreach ($testModels as $model) { $this->assertEquals(array(Permission::NONE, Permission::NONE), $model->getExplicitActualPermissions($jim)); } //Confirm 10 rows were processed as 'created'. $this->assertEquals(2, ImportDatabaseUtil::getCount($import->getTempTableName(), "status = " . ImportRowDataResultsUtil::CREATED)); //Confirm that 0 rows were processed as 'updated'. $this->assertEquals(0, ImportDatabaseUtil::getCount($import->getTempTableName(), "status = " . ImportRowDataResultsUtil::UPDATED)); //Confirm 2 rows were processed as 'errors'. $this->assertEquals(0, ImportDatabaseUtil::getCount($import->getTempTableName(), "status = " . ImportRowDataResultsUtil::ERROR)); $beansWithErrors = ImportDatabaseUtil::getSubset($import->getTempTableName(), "status = " . ImportRowDataResultsUtil::ERROR); $this->assertEquals(0, count($beansWithErrors)); //Confirm the base code is USD $this->assertEquals('USD', Yii::app()->currencyHelper->getBaseCode()); //Creating an object produces the correct currency code. $testItem = new ImportModelTestItem(); $this->assertEquals('USD', $testItem->currencyValue->currency->code); $testItem->string = 'test'; $testItem->lastName = 'testAlso'; $this->assertTrue($testItem->save()); $testItemId = $testItem->id; $testItem->forget(); //The currency code, even though not set, shows up correctly based on the base code. $testItem = ImportModelTestItem::getById($testItemId); $this->assertEquals('USD', $testItem->currencyValue->currency->code); //Test that the related currency information is not empty for the imported objects. $this->assertEquals('USD', $testModels[0]->currencyValue->currency->code); //Clear out data in table R::exec("delete from " . ImportModelTestItem::getTableName('ImportModelTestItem')); //Re-freeze if needed. if ($freezeWhenComplete) { RedBeanDatabase::freeze(); } }