3 namespace Drupal\Tests\file\Kernel\Migrate\d7;
5 use Drupal\file\Entity\File;
6 use Drupal\file\FileInterface;
7 use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
10 * Migrates all files in the file_managed table.
14 class MigrateFileTest extends MigrateDrupal7TestBase {
16 use FileMigrationSetupTrait;
18 public static $modules = ['file'];
23 protected function setUp() {
26 $this->fileMigrationSetup();
30 * Tests a single file entity.
35 * The expected file name.
39 * The expected MIME type.
41 * The expected file size.
43 * The expected creation time.
45 * The expected modification time.
47 * The expected owner ID.
49 protected function assertEntity($id, $name, $uri, $mime, $size, $created, $changed, $uid) {
50 /** @var \Drupal\file\FileInterface $file */
51 $file = File::load($id);
52 $this->assertTrue($file instanceof FileInterface);
53 $this->assertIdentical($name, $file->getFilename());
54 $this->assertIdentical($uri, $file->getFileUri());
55 $this->assertTrue(file_exists($uri));
56 $this->assertIdentical($mime, $file->getMimeType());
57 $this->assertIdentical($size, $file->getSize());
58 // isPermanent(), isTemporary(), etc. are determined by the status column.
59 $this->assertTrue($file->isPermanent());
60 $this->assertIdentical($created, $file->getCreatedTime());
61 $this->assertIdentical($changed, $file->getChangedTime());
62 $this->assertIdentical($uid, $file->getOwnerId());
66 * Tests that all expected files are migrated.
68 public function testFileMigration() {
69 $this->assertEntity(1, 'cube.jpeg', 'public://cube.jpeg', 'image/jpeg', '3620', '1421727515', '1421727515', '1');