X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Ffile%2Ftests%2Fsrc%2FKernel%2FMigrate%2Fd7%2FMigratePrivateFileTest.php;fp=web%2Fcore%2Fmodules%2Ffile%2Ftests%2Fsrc%2FKernel%2FMigrate%2Fd7%2FMigratePrivateFileTest.php;h=7b6f763208b2bedfd0471a3c2111784b122c1d7f;hp=0000000000000000000000000000000000000000;hb=bfbba508964731508b9bd6d5835c2edc858db95b;hpb=cb9a80db11fc6b014e5b1e693a5a391c95eb5d9a diff --git a/web/core/modules/file/tests/src/Kernel/Migrate/d7/MigratePrivateFileTest.php b/web/core/modules/file/tests/src/Kernel/Migrate/d7/MigratePrivateFileTest.php new file mode 100644 index 000000000..7b6f76320 --- /dev/null +++ b/web/core/modules/file/tests/src/Kernel/Migrate/d7/MigratePrivateFileTest.php @@ -0,0 +1,98 @@ +setSetting('file_private_path', $this->container->get('site.path') . '/private'); + $this->installEntitySchema('file'); + $fs = $this->container->get('file_system'); + + // Ensure that the private files directory exists. + $fs->mkdir('private://sites/default/private/', NULL, TRUE); + // Put test file in the source directory. + file_put_contents('private://sites/default/private/Babylon5.txt', str_repeat('*', 3)); + + /** @var \Drupal\migrate\Plugin\Migration $migration */ + $migration = $this->getMigration('d7_file_private'); + // Set the source plugin's source_file_private_path configuration value, + // which would normally be set by the user running the migration. + $source = $migration->getSourceConfiguration(); + $source['constants']['source_base_path'] = $fs->realpath('private://'); + $migration->set('source', $source); + $this->executeMigration($migration); + } + + /** + * {@inheritdoc} + */ + public function register(ContainerBuilder $container) { + parent::register($container); + $container->register('stream_wrapper.private', 'Drupal\Core\StreamWrapper\PrivateStream') + ->addTag('stream_wrapper', ['scheme' => 'private']); + } + + /** + * Tests a single file entity. + * + * @param int $id + * The file ID. + * @param string $name + * The expected file name. + * @param string $uri + * The expected URI. + * @param string $mime + * The expected MIME type. + * @param int $size + * The expected file size. + * @param int $created + * The expected creation time. + * @param int $changed + * The expected modification time. + * @param int $uid + * The expected owner ID. + */ + protected function assertEntity($id, $name, $uri, $mime, $size, $created, $changed, $uid) { + /** @var \Drupal\file\FileInterface $file */ + $file = File::load($id); + $this->assertInstanceOf(FileInterface::class, $file); + $this->assertSame($name, $file->getFilename()); + $this->assertSame($uri, $file->getFileUri()); + $this->assertFileExists($uri); + $this->assertSame($mime, $file->getMimeType()); + $this->assertSame($size, $file->getSize()); + // isPermanent(), isTemporary(), etc. are determined by the status column. + $this->assertTrue($file->isPermanent()); + $this->assertSame($created, $file->getCreatedTime()); + $this->assertSame($changed, $file->getChangedTime()); + $this->assertSame($uid, $file->getOwnerId()); + } + + /** + * Tests that all expected files are migrated. + */ + public function testFileMigration() { + $this->assertEntity(3, 'Babylon5.txt', 'private://Babylon5.txt', 'text/plain', '3', '1486104045', '1486104045', '1'); + } + +}