3 namespace Drupal\Tests\migrate\Kernel;
5 use Drupal\language\Entity\ConfigurableLanguage;
6 use Drupal\migrate\MigrateExecutable;
7 use Drupal\node\Entity\NodeType;
10 * Tests migrating non-Drupal translated content.
12 * Ensure it's possible to migrate in translations, even if there's no nid or
13 * tnid property on the source.
17 class MigrateExternalTranslatedTest extends MigrateTestBase {
22 public static $modules = ['system', 'user', 'language', 'node', 'field', 'migrate_external_translated_test'];
27 public function setUp() {
29 $this->installSchema('system', ['sequences']);
30 $this->installSchema('node', ['node_access']);
31 $this->installEntitySchema('user');
32 $this->installEntitySchema('node');
34 // Create some languages.
35 ConfigurableLanguage::createFromLangcode('en')->save();
36 ConfigurableLanguage::createFromLangcode('fr')->save();
37 ConfigurableLanguage::createFromLangcode('es')->save();
39 // Create a content type.
41 'type' => 'external_test',
42 'name' => 'Test node type',
47 * Test importing and rolling back our data.
49 public function testMigrations() {
50 /** @var \Drupal\Core\Entity\ContentEntityStorageInterface $storage */
51 $storage = $this->container->get('entity.manager')->getStorage('node');
52 $this->assertEquals(0, count($storage->loadMultiple()));
54 // Run the migrations.
55 $migration_ids = ['external_translated_test_node', 'external_translated_test_node_translation'];
56 $this->executeMigrations($migration_ids);
57 $this->assertEquals(3, count($storage->loadMultiple()));
59 $node = $storage->load(1);
60 $this->assertEquals('en', $node->language()->getId());
61 $this->assertEquals('Cat', $node->title->value);
62 $this->assertEquals('Chat', $node->getTranslation('fr')->title->value);
63 $this->assertEquals('Gato', $node->getTranslation('es')->title->value);
65 $node = $storage->load(2);
66 $this->assertEquals('en', $node->language()->getId());
67 $this->assertEquals('Dog', $node->title->value);
68 $this->assertEquals('Chien', $node->getTranslation('fr')->title->value);
69 $this->assertFalse($node->hasTranslation('es'), "No spanish translation for node 2");
71 $node = $storage->load(3);
72 $this->assertEquals('en', $node->language()->getId());
73 $this->assertEquals('Monkey', $node->title->value);
74 $this->assertFalse($node->hasTranslation('fr'), "No french translation for node 3");
75 $this->assertFalse($node->hasTranslation('es'), "No spanish translation for node 3");
77 $this->assertNull($storage->load(4), "No node 4 migrated");
79 // Roll back the migrations.
80 foreach ($migration_ids as $migration_id) {
81 $migration = $this->getMigration($migration_id);
82 $executable = new MigrateExecutable($migration, $this);
83 $executable->rollback();
86 $this->assertEquals(0, count($storage->loadMultiple()));