Version 1
[yaffs-website] / web / core / modules / file / tests / src / Kernel / Migrate / d6 / MigrateUploadTest.php
1 <?php
2
3 namespace Drupal\Tests\file\Kernel\Migrate\d6;
4
5 use Drupal\file\Entity\File;
6 use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
7 use Drupal\node\Entity\Node;
8
9 /**
10  * Migrate association data between nodes and files.
11  *
12  * @group migrate_drupal_6
13  */
14 class MigrateUploadTest extends MigrateDrupal6TestBase {
15
16   /**
17    * {@inheritdoc}
18    */
19   public static $modules = ['menu_ui'];
20
21   /**
22    * {@inheritdoc}
23    */
24   protected function setUp() {
25     parent::setUp();
26
27     $this->installEntitySchema('file');
28     $this->installEntitySchema('node');
29     $this->installSchema('file', ['file_usage']);
30     $this->installSchema('node', ['node_access']);
31
32     $id_mappings = ['d6_file' => []];
33     // Create new file entities.
34     for ($i = 1; $i <= 3; $i++) {
35       $file = File::create([
36         'fid' => $i,
37         'uid' => 1,
38         'filename' => 'druplicon.txt',
39         'uri' => "public://druplicon-$i.txt",
40         'filemime' => 'text/plain',
41         'created' => 1,
42         'changed' => 1,
43         'status' => FILE_STATUS_PERMANENT,
44       ]);
45       $file->enforceIsNew();
46       file_put_contents($file->getFileUri(), 'hello world');
47
48       // Save it, inserting a new record.
49       $file->save();
50       $id_mappings['d6_file'][] = [[$i], [$i]];
51     }
52     $this->prepareMigrations($id_mappings);
53
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);
60   }
61
62   /**
63    * Test upload migration from Drupal 6 to Drupal 8.
64    */
65   public function testUpload() {
66     $this->container->get('entity.manager')
67       ->getStorage('node')
68       ->resetCache([1, 2]);
69
70     $nodes = Node::loadMultiple([1, 2]);
71     $node = $nodes[1];
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());
76
77     $node = $nodes[2];
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);
85   }
86
87 }