Updated Drupal to 8.6. This goes with the following updates because it's possible...
[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 = ['language', '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(['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);
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, 12]);
69
70     $nodes = Node::loadMultiple([1, 2, 12]);
71     $node = $nodes[1];
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());
77
78     $node = $nodes[2];
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);
87
88     $node = $nodes[12];
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());
94   }
95
96 }