Issue #2806285 by maxocub, Gábor Hojtsy, quietone, catch: If the default language is not set, the migration log show an error

8.3.x
Alex Pott 2016-10-27 22:01:17 -07:00
parent 59451585a9
commit ecd6148ee5
4 changed files with 53 additions and 6 deletions

View File

@ -10,9 +10,22 @@ source:
process: process:
default_langcode: default_langcode:
- -
plugin: callback plugin: default_value
callable: get_object_vars
source: language_default source: language_default
default_value:
'language': 'en'
# Encode and decode to turn the default_language variable, which is
# an stdClass, into an array so it can be passed to extract.
-
plugin: callback
callable:
- '\Drupal\Component\Serialization\Json'
- 'encode'
-
plugin: callback
callable:
- '\Drupal\Component\Serialization\Json'
- 'decode'
- -
plugin: extract plugin: extract
index: index:

View File

@ -38,7 +38,7 @@ trait MigrateDefaultLanguageTrait {
// default_langcode config should be set. // default_langcode config should be set.
$default_language = ConfigurableLanguage::load($langcode); $default_language = ConfigurableLanguage::load($langcode);
$this->assertNotNull($default_language); $this->assertNotNull($default_language);
$this->assertIdentical($langcode, $this->config('system.site')->get('default_langcode')); $this->assertSame($langcode, $this->config('system.site')->get('default_langcode'));
} }
else { else {
// Otherwise, the migration log should contain an error message. // Otherwise, the migration log should contain an error message.
@ -46,11 +46,31 @@ trait MigrateDefaultLanguageTrait {
$count = 0; $count = 0;
foreach ($messages as $message) { foreach ($messages as $message) {
$count++; $count++;
$this->assertEqual($message->message, "The language '$langcode' does not exist on this site."); $this->assertSame($message->message, "The language '$langcode' does not exist on this site.");
$this->assertEqual($message->level, MigrationInterface::MESSAGE_ERROR); $this->assertSame((int) $message->level, MigrationInterface::MESSAGE_ERROR);
} }
$this->assertEqual($count, 1); $this->assertSame($count, 1);
} }
} }
/**
* Helper method to test migrating the default language when no default language is set.
*/
protected function doTestMigrationWithUnsetVariable() {
// Delete the language_default variable.
$this->sourceDatabase->delete('variable')
->condition('name', 'language_default' )
->execute();
$this->startCollectingMessages();
$this->executeMigrations(['language', 'default_language']);
$messages = $this->migration->getIdMap()->getMessageIterator()->fetchAll();
// Make sure there's no migration exceptions.
$this->assertEmpty($messages);
// Make sure the default langcode is 'en', since it was the default on D6 & D7.
$this->assertSame('en', $this->config('system.site')->get('default_langcode'));
}
} }

View File

@ -33,4 +33,11 @@ class MigrateDefaultLanguageTest extends MigrateDrupal6TestBase {
$this->doTestMigration('tv', FALSE); $this->doTestMigration('tv', FALSE);
} }
/**
* Tests language_default migration with unset variable.
*/
public function testMigrationWithUnsetVariable() {
$this->doTestMigrationWithUnsetVariable();
}
} }

View File

@ -33,4 +33,11 @@ class MigrateDefaultLanguageTest extends MigrateDrupal7TestBase {
$this->doTestMigration('tv', FALSE); $this->doTestMigration('tv', FALSE);
} }
/**
* Tests language_default migration with unset variable.
*/
public function testMigrationWithUnsetVariable() {
$this->doTestMigrationWithUnsetVariable();
}
} }