comparison core/modules/migrate/tests/src/Kernel/MigrateExternalTranslatedTest.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4c8ae668cc8c
1 <?php
2
3 namespace Drupal\Tests\migrate\Kernel;
4
5 use Drupal\language\Entity\ConfigurableLanguage;
6 use Drupal\migrate\MigrateExecutable;
7 use Drupal\node\Entity\NodeType;
8
9 /**
10 * Tests migrating non-Drupal translated content.
11 *
12 * Ensure it's possible to migrate in translations, even if there's no nid or
13 * tnid property on the source.
14 *
15 * @group migrate
16 */
17 class MigrateExternalTranslatedTest extends MigrateTestBase {
18
19 /**
20 * {@inheritdoc}
21 */
22 public static $modules = ['system', 'user', 'language', 'node', 'field', 'migrate_external_translated_test'];
23
24 /**
25 * {@inheritdoc}
26 */
27 public function setUp() {
28 parent::setUp();
29 $this->installSchema('system', ['sequences']);
30 $this->installSchema('node', ['node_access']);
31 $this->installEntitySchema('user');
32 $this->installEntitySchema('node');
33
34 // Create some languages.
35 ConfigurableLanguage::createFromLangcode('en')->save();
36 ConfigurableLanguage::createFromLangcode('fr')->save();
37 ConfigurableLanguage::createFromLangcode('es')->save();
38
39 // Create a content type.
40 NodeType::create([
41 'type' => 'external_test',
42 'name' => 'Test node type',
43 ])->save();
44 }
45
46 /**
47 * Test importing and rolling back our data.
48 */
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()));
53
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()));
58
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);
64
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");
70
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");
76
77 $this->assertNull($storage->load(4), "No node 4 migrated");
78
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();
84 }
85
86 $this->assertEquals(0, count($storage->loadMultiple()));
87 }
88
89 }