3 namespace Drupal\Tests\file\Kernel\Migrate\d6;
5 use Drupal\file\Entity\File;
6 use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
7 use Drupal\node\Entity\Node;
10 * Migrate association data between nodes and files.
12 * @group migrate_drupal_6
14 class MigrateUploadTest extends MigrateDrupal6TestBase {
19 public static $modules = ['language', 'menu_ui'];
24 protected function setUp() {
27 $this->installEntitySchema('file');
28 $this->installEntitySchema('node');
29 $this->installSchema('file', ['file_usage']);
30 $this->installSchema('node', ['node_access']);
32 $id_mappings = ['d6_file' => []];
33 // Create new file entities.
34 for ($i = 1; $i <= 3; $i++) {
35 $file = File::create([
38 'filename' => 'druplicon.txt',
39 'uri' => "public://druplicon-$i.txt",
40 'filemime' => 'text/plain',
43 'status' => FILE_STATUS_PERMANENT,
45 $file->enforceIsNew();
46 file_put_contents($file->getFileUri(), 'hello world');
48 // Save it, inserting a new record.
50 $id_mappings['d6_file'][] = [[$i], [$i]];
52 $this->prepareMigrations($id_mappings);
54 $this->migrateContent(['translations']);
55 // Since we are only testing a subset of the file migration, do not check
56 // that the full file migration has been run.
57 $migration = $this->getMigration('d6_upload');
58 $migration->set('requirements', []);
59 $this->executeMigration($migration);
63 * Test upload migration from Drupal 6 to Drupal 8.
65 public function testUpload() {
66 $this->container->get('entity.manager')
68 ->resetCache([1, 2, 12]);
70 $nodes = Node::loadMultiple([1, 2, 12]);
72 $this->assertEquals('en', $node->langcode->value);
73 $this->assertIdentical(1, count($node->upload));
74 $this->assertIdentical('1', $node->upload[0]->target_id);
75 $this->assertIdentical('file 1-1-1', $node->upload[0]->description);
76 $this->assertIdentical(FALSE, $node->upload[0]->isDisplayed());
79 $this->assertEquals('en', $node->langcode->value);
80 $this->assertIdentical(2, count($node->upload));
81 $this->assertIdentical('3', $node->upload[0]->target_id);
82 $this->assertIdentical('file 2-3-3', $node->upload[0]->description);
83 $this->assertIdentical(FALSE, $node->upload[0]->isDisplayed());
84 $this->assertIdentical('2', $node->upload[1]->target_id);
85 $this->assertIdentical(TRUE, $node->upload[1]->isDisplayed());
86 $this->assertIdentical('file 2-3-2', $node->upload[1]->description);
89 $this->assertEquals('zu', $node->langcode->value);
90 $this->assertEquals(1, count($node->upload));
91 $this->assertEquals('3', $node->upload[0]->target_id);
92 $this->assertEquals('file 12-15-3', $node->upload[0]->description);
93 $this->assertEquals(FALSE, $node->upload[0]->isDisplayed());