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 = ['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();
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')
70 $nodes = Node::loadMultiple([1, 2]);
72 $this->assertIdentical(1, count($node->upload));
73 $this->assertIdentical('1', $node->upload[0]->target_id);
74 $this->assertIdentical('file 1-1-1', $node->upload[0]->description);
75 $this->assertIdentical(FALSE, $node->upload[0]->isDisplayed());
78 $this->assertIdentical(2, count($node->upload));
79 $this->assertIdentical('3', $node->upload[0]->target_id);
80 $this->assertIdentical('file 2-3-3', $node->upload[0]->description);
81 $this->assertIdentical(FALSE, $node->upload[0]->isDisplayed());
82 $this->assertIdentical('2', $node->upload[1]->target_id);
83 $this->assertIdentical(TRUE, $node->upload[1]->isDisplayed());
84 $this->assertIdentical('file 2-3-2', $node->upload[1]->description);