/**
  * @depends testAppendCustomFieldsInstructionDataForAddMissingValues
  */
 public function testAppendCustomFieldsInstructionDataForMapMissingValues()
 {
     $import = new Import();
     $customFieldsInstructionData = new CustomFieldsInstructionData();
     $this->assertNull($import->serializedData);
     $missingCustomFieldValues = array(CustomFieldsInstructionData::MAP_MISSING_VALUES => array('a' => 'b2', 'b' => 'b2', 'c' => 'c2'));
     $customFieldsInstructionData->addByInstructionsDataAndColumnName($missingCustomFieldValues, 'column_0');
     $adapter = new ImportToCustomFieldsInstructionDataAdapter($import);
     $adapter->appendCustomFieldsInstructionData($customFieldsInstructionData);
     $compareData = array('column_0' => array('customFieldsInstructionData' => array(CustomFieldsInstructionData::MAP_MISSING_VALUES => array('a' => 'b2', 'b' => 'b2', 'c' => 'c2'))));
     $unserializedData = unserialize($import->serializedData);
     $this->assertEquals($compareData, $unserializedData['mappingData']);
     //Now append the existing and that it doesn't duplicate existing values
     $customFieldsInstructionData = new CustomFieldsInstructionData();
     $missingCustomFieldValues = array(CustomFieldsInstructionData::MAP_MISSING_VALUES => array('a' => 'a2', 'd' => 'd2'));
     $customFieldsInstructionData->addByInstructionsDataAndColumnName($missingCustomFieldValues, 'column_0');
     $adapter = new ImportToCustomFieldsInstructionDataAdapter($import);
     $adapter->appendCustomFieldsInstructionData($customFieldsInstructionData);
     $compareData = array('column_0' => array('customFieldsInstructionData' => array(CustomFieldsInstructionData::MAP_MISSING_VALUES => array('a' => 'b2', 'b' => 'b2', 'c' => 'c2', 'd' => 'd2'))));
     $unserializedData = unserialize($import->serializedData);
     $this->assertEquals($compareData, $unserializedData['mappingData']);
 }
 public function testResolveForNewData()
 {
     $customFieldsInstructionData = new CustomFieldsInstructionData();
     $instructionsData[CustomFieldsInstructionData::ADD_MISSING_VALUES] = array('a', 'b', 'c');
     $instructionsData[CustomFieldsInstructionData::MAP_MISSING_VALUES] = array('d' => 'dx', 'e' => 'ex', 'f' => 'fx');
     $customFieldsInstructionData->addByInstructionsDataAndColumnName($instructionsData, 'column_0');
     $newCustomFieldsInstructionData = new CustomFieldsInstructionData();
     $instructionsData[CustomFieldsInstructionData::ADD_MISSING_VALUES] = array('a2', 'b', 'c2');
     $instructionsData[CustomFieldsInstructionData::MAP_MISSING_VALUES] = array('d2' => 'd2x', 'e' => 'ex', 'f2' => 'f2x');
     $newCustomFieldsInstructionData->addByInstructionsDataAndColumnName($instructionsData, 'column_0');
     $customFieldsInstructionData->resolveForNewData($newCustomFieldsInstructionData);
     $compareData = array('column_0' => array('a', 'b', 'c', 'a2', 'c2'));
     $this->assertEquals($compareData, $customFieldsInstructionData->getMissingValuesToAdd());
     $compareData = array('column_0' => array('d' => 'dx', 'd2' => 'd2x', 'e' => 'ex', 'f' => 'fx', 'f2' => 'f2x'));
     $this->assertEquals($compareData, $customFieldsInstructionData->getMissingValuesToMap());
     $this->assertTrue($customFieldsInstructionData->hasDataByColumnName('column_0'));
     $this->assertFalse($customFieldsInstructionData->hasDataByColumnName('column_1'));
     $compareData = array(CustomFieldsInstructionData::ADD_MISSING_VALUES => array('a', 'b', 'c', 'a2', 'c2'), CustomFieldsInstructionData::MAP_MISSING_VALUES => array('d' => 'dx', 'd2' => 'd2x', 'e' => 'ex', 'f' => 'fx', 'f2' => 'f2x'));
     $this->assertEquals($compareData, $customFieldsInstructionData->getDataByColumnName('column_0'));
 }
 protected function populateCustomFieldsInstructionDataByMappingData(CustomFieldsInstructionData $instructionsData, array $mappingData)
 {
     foreach ($mappingData as $columnName => $columnMappingData) {
         if (isset($mappingData[$columnName]['customFieldsInstructionData'])) {
             $instructionsData->addByInstructionsDataAndColumnName($mappingData[$columnName]['customFieldsInstructionData'], $columnName);
         }
     }
 }
 /**
  * Appends missingValuesToAdd and missingValuesToMap with new data
  * @param CustomFieldsInstructionData $newInstructionsData
  */
 public function resolveForNewData(CustomFieldsInstructionData $newInstructionsData)
 {
     foreach ($newInstructionsData->getMissingValuesToAdd() as $columnName => $columnData) {
         foreach ($columnData as $missingValueToAdd) {
             $this->resolveMissingValueToAdd($missingValueToAdd, $columnName);
         }
     }
     foreach ($newInstructionsData->getMissingValuesToMap() as $columnName => $columnData) {
         foreach ($columnData as $missingValueToMap => $mapToValue) {
             $this->resolveMissingValueToMap($missingValueToMap, $mapToValue, $columnName);
         }
     }
 }