1<?php 2 3namespace Drupal\Tests\user\Kernel\Migrate\d6; 4 5use Drupal\file\Entity\File; 6use Drupal\file\FileInterface; 7use Drupal\Tests\file\Kernel\Migrate\d6\FileMigrationTestTrait; 8use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase; 9 10/** 11 * User pictures migration. 12 * 13 * @group migrate_drupal_6 14 */ 15class MigrateUserPictureD6FileTest extends MigrateDrupal6TestBase { 16 17 use FileMigrationTestTrait; 18 19 /** 20 * {@inheritdoc} 21 */ 22 protected function setUp(): void { 23 parent::setUp(); 24 25 $this->installEntitySchema('file'); 26 $this->executeMigration('d6_user_picture_file'); 27 } 28 29 /** 30 * Tests the Drupal 6 user pictures to Drupal 8 migration. 31 */ 32 public function testUserPictures() { 33 $file_ids = []; 34 foreach ($this->migration->getIdMap() as $destination_ids) { 35 $file_ids[] = reset($destination_ids); 36 } 37 $files = File::loadMultiple($file_ids); 38 /** @var \Drupal\file\FileInterface $file */ 39 $file = array_shift($files); 40 $this->assertSame('image-test.jpg', $file->getFilename()); 41 $this->assertSame('public://image-test.jpg', $file->getFileUri()); 42 $this->assertSame('2', $file->getOwnerId()); 43 $this->assertSame('1901', $file->getSize()); 44 $this->assertSame('image/jpeg', $file->getMimeType()); 45 46 $file = array_shift($files); 47 $this->assertSame('image-test.png', $file->getFilename()); 48 $this->assertSame('public://image-test.png', $file->getFileUri()); 49 $this->assertSame('8', $file->getOwnerId()); 50 $this->assertEmpty($files); 51 52 // Tests the D6 user pictures migration in combination with D6 file. 53 $this->setUpMigratedFiles(); 54 $this->assertEntity(1, 'image-test.jpg', '1901', 'public://image-test.jpg', 'image/jpeg', '2'); 55 $this->assertEntity(2, 'image-test.png', '125', 'public://image-test.png', 'image/png', '8'); 56 $this->assertEntity(3, 'Image1.png', '39325', 'public://image-1.png', 'image/png', '1'); 57 $this->assertEntity(4, 'Image2.jpg', '1831', 'public://image-2.jpg', 'image/jpeg', '1'); 58 $this->assertEntity(5, 'Image-test.gif', '183', 'public://image-test.gif', 'image/jpeg', '1'); 59 $this->assertEntity(6, 'html-1.txt', '24', 'public://html-1.txt', 'text/plain', '1'); 60 } 61 62 /** 63 * Asserts a file entity. 64 * 65 * @param int $fid 66 * The file ID. 67 * @param string $name 68 * The expected file name. 69 * @param int $size 70 * The expected file size. 71 * @param string $uri 72 * The expected file URI. 73 * @param string $type 74 * The expected MIME type. 75 * @param int $uid 76 * The expected file owner ID. 77 */ 78 protected function assertEntity($fid, $name, $size, $uri, $type, $uid) { 79 /** @var \Drupal\file\FileInterface $file */ 80 $file = File::load($fid); 81 $this->assertInstanceOf(FileInterface::class, $file); 82 $this->assertSame($name, $file->getFilename()); 83 $this->assertSame($size, $file->getSize()); 84 $this->assertSame($uri, $file->getFileUri()); 85 $this->assertSame($type, $file->getMimeType()); 86 $this->assertSame($uid, $file->getOwnerId()); 87 } 88 89} 90