diff -u b/core/modules/migrate_drupal_ui/tests/src/Functional/d7/FilePathTest.php b/core/modules/migrate_drupal_ui/tests/src/Functional/d7/FilePathTest.php --- b/core/modules/migrate_drupal_ui/tests/src/Functional/d7/FilePathTest.php +++ b/core/modules/migrate_drupal_ui/tests/src/Functional/d7/FilePathTest.php @@ -7,9 +7,7 @@ use Drupal\Tests\migrate_drupal_ui\Functional\MigrateUpgradeTestBase; /** - * Tests Drupal 7 file migrations from the Migrate UI. - * - * Files are created in the test site temp directory. + * Tests the Drupal 7 public and private file migrations. * * @group migrate_drupal_ui */ @@ -33,25 +31,11 @@ protected $fs; /** - * The path to the source private files. - * - * @var string - */ - protected $private; - - /** - * The path to the source public files. - * - * @var string - */ - protected $public; - - /** - * The path to the source temporary files. + * The file path variables in the source database. * - * @var string + * @var string[] */ - protected $temporary; + protected $basePath = []; /** * The file path variables in the source database. @@ -71,13 +55,6 @@ ]; /** - * The entity storage for node. - * - * @var \Drupal\Core\Entity\EntityStorageInterface - */ - protected $nodeStorage; - - /** * {@inheritdoc} */ protected function setUp(): void { @@ -111,9 +88,9 @@ $this->variable['public'] = $file_public_path; $this->variable['temporary'] = $file_temporary_path; - $this->private = $private; - $this->public = $public; - $this->temporary = $temporary; + $this->basePath['private'] = $private; + $this->basePath['public'] = $public; + $this->basePath['temporary'] = $temporary; // Create the source files. $this->makeFiles(); @@ -148,8 +125,7 @@ if (count($drivers) !== 1) { $edit['driver'] = $driver; } - // Set the public and private base paths to be submitted on the Credential - // Form. + // Set the public and private base paths for the Credential Form. $edit['source_private_file_path'] = $this->fs->realpath($this->getSourcePath('private')); $edit['source_base_path'] = $this->fs->realpath($this->getSourcePath('public')); $edits = $this->translatePostValues($edit); @@ -169,6 +145,7 @@ ]); $store->set('migrations', $migration_array); + // Perform the migrations. $this->drupalPostForm(NULL, [], 'Perform upgrade'); $this->resetAll(); $this->assertFileMigrations(); @@ -219,24 +196,25 @@ /** * Creates files for the test. + * + * The source files are written to a subdirectory of the temporary files + * directory of the test sites. The subdirectory path always ends with the + * path to the relevant scheme as set in the source variable table. */ protected function makeFiles() { // Get file information from the source database. $files = $this->getManagedFiles(); foreach ($files as $file) { $scheme = preg_replace('/:.*/', '', $file['uri']); - // The source files are written to a subdirectory of the temporary files - // directory of the test sites. The subdirectory path always ends with - // the path to the relevant scheme as set in the source variable table. - $base_path = $this->getSourcePath($scheme); + $path = isset($this->variable[$scheme]) ? $this->variable[$scheme] : ''; - $base_path = $base_path . '/' . $path; + $base_path = $this->getSourcePath($scheme) . '/' . $path; $filepath = $base_path . '/' . $file['filename']; + // Create the file. $source_file = @fopen($filepath, 'w'); if (!$source_file) { // If fopen didn't work, make sure there's a writable directory in // place. - /** @var \Drupal\Core\File\FileSystem $this ->fs */ $this->fs = \Drupal::service('file_system'); $dir = $this->fs->dirname($filepath); if (!$this->fs->prepareDirectory($dir, FileSystemInterface:: CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS)) { @@ -254,31 +232,18 @@ /** * Gets the source base path for the Credential form. + * + * @param string $scheme + * The file scheme. */ public function getSourcePath($scheme) { - switch ($scheme) { - case 'private': - $sub_path = $this->private; - break; - - case 'public': - $sub_path = $this->public; - break; - - case 'temporary': - $sub_path = $this->temporary; - break; - - default: - $sub_path = ''; - break; - } + $base_path = isset($this->basePath[$scheme]) ? $this->basePath[$scheme] : ''; // Puts the source files in the site temp directory. - return $this->tempFilesDirectory . '/' . $sub_path; + return $this->tempFilesDirectory . '/' . $base_path; } /** - * Gets the file data from the source database. + * Gets the file data. * * @return string[][] * Data from the source file_managed table.