/** * Test tag cloud and multi-select attribute import. * @depends testImportNameAndRelatedNameWithApostrophes */ public function testSetDataAnalyzerMultiSelectAndTagCloudImport() { $super = User::getByUsername('super'); $jim = User::getByUsername('jim'); Yii::app()->user->userModel = $jim; $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('importMultiSelectDropDownTest.csv', $import->getTempTableName(), true); $this->assertEquals(6, ImportDatabaseUtil::getCount($import->getTempTableName())); // includes header rows. $multiDropDownInstructionsData = array(CustomFieldsInstructionData::ADD_MISSING_VALUES => array('Multi 5', 'Multi 4'), CustomFieldsInstructionData::MAP_MISSING_VALUES => array()); $tagCloudInstructionsData = array(CustomFieldsInstructionData::ADD_MISSING_VALUES => array('Cloud 5', 'Cloud 4'), CustomFieldsInstructionData::MAP_MISSING_VALUES => array()); $mappingData = array('column_0' => ImportMappingUtil::makeStringColumnMappingData('string'), 'column_1' => ImportMappingUtil::makeStringColumnMappingData('lastName'), 'column_2' => ImportMappingUtil::makeMultiSelectDropDownColumnMappingData('multiDropDown', null, $multiDropDownInstructionsData), 'column_3' => ImportMappingUtil::makeTagCloudColumnMappingData('tagCloud', null, $tagCloudInstructionsData)); $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 the missing custom field values were properly added. $customFieldData = CustomFieldData::getByName('ImportTestMultiDropDown'); $values = array('Multi 1', 'Multi 2', 'Multi 3', 'Multi 4', 'Multi 5'); $this->assertEquals($values, unserialize($customFieldData->serializedData)); $customFieldData = CustomFieldData::getByName('ImportTestTagCloud'); $values = array('Cloud 1', 'Cloud 2', 'Cloud 3', 'Cloud 4', 'Cloud 5'); $this->assertEquals($values, unserialize($customFieldData->serializedData)); //Confirm that 5 models where created. $testModels = ImportModelTestItem::getAll(); $this->assertEquals(5, count($testModels)); foreach ($testModels as $model) { $this->assertEquals(array(Permission::NONE, Permission::NONE), $model->getExplicitActualPermissions($jim)); } //Confirm the values of the multi-select and tag cloud are as expected. $this->assertEquals(0, $testModels[2]->multiDropDown->values->count()); $this->assertEquals(2, $testModels[2]->tagCloud->values->count()); $this->assertEquals(2, $testModels[3]->multiDropDown->values->count()); $this->assertEquals(0, $testModels[3]->tagCloud->values->count()); $this->assertEquals(2, $testModels[1]->multiDropDown->values->count()); $this->assertEquals('Multi 4', $testModels[1]->multiDropDown->values[0]->value); $this->assertEquals('Multi 2', $testModels[1]->multiDropDown->values[1]->value); $this->assertEquals(2, $testModels[1]->tagCloud->values->count()); $this->assertEquals('Cloud 1', $testModels[1]->tagCloud->values[0]->value); $this->assertEquals('Cloud 4', $testModels[1]->tagCloud->values[1]->value); $this->assertEquals(2, $testModels[4]->multiDropDown->values->count()); $this->assertEquals('Multi 1', $testModels[4]->multiDropDown->values[0]->value); $this->assertEquals('Multi 5', $testModels[4]->multiDropDown->values[1]->value); $this->assertEquals(2, $testModels[4]->tagCloud->values->count()); $this->assertEquals('Cloud 5', $testModels[4]->tagCloud->values[0]->value); $this->assertEquals('Cloud 2', $testModels[4]->tagCloud->values[1]->value); //Confirm 10 rows were processed as 'created'. $this->assertEquals(5, 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)); //Clear out data in table ImportModelTestItem::deleteAll(); }