diff --git a/core/modules/migrate/src/Tests/MigrateDumpAlterInterface.php b/core/modules/migrate/src/Tests/MigrateDumpAlterInterface.php index 9ecf825..94b8a3d 100644 --- a/core/modules/migrate/src/Tests/MigrateDumpAlterInterface.php +++ b/core/modules/migrate/src/Tests/MigrateDumpAlterInterface.php @@ -7,6 +7,8 @@ namespace Drupal\migrate\Tests; +use Drupal\simpletest\TestBase; + /** * Allows tests to alter dumps after they've loaded. * @@ -18,10 +20,9 @@ /** * Allows tests to alter dumps after they've loaded. * - * @param $database_prefix - * The simpletest database prefix. Can be used to ensure uniqueness to the - * specific test. + * @param \Drupal\simpletest\TestBase $test + * The test that is being run. */ - public static function migrateDumpAlter($database_prefix); + public static function migrateDumpAlter(TestBase $test); } diff --git a/core/modules/migrate/src/Tests/MigrateTearDownInterface.php b/core/modules/migrate/src/Tests/MigrateTearDownInterface.php deleted file mode 100644 index 06f68ac..0000000 --- a/core/modules/migrate/src/Tests/MigrateTearDownInterface.php +++ /dev/null @@ -1,20 +0,0 @@ -loadDumps($files); if ($this instanceof MigrateDumpAlterInterface) { - static::migrateDumpAlter($this->databasePrefix); + static::migrateDumpAlter($this); } } diff --git a/core/modules/migrate_drupal/src/Tests/MigrateFullDrupalTestBase.php b/core/modules/migrate_drupal/src/Tests/MigrateFullDrupalTestBase.php index 2796f1e..09dd3cd 100644 --- a/core/modules/migrate_drupal/src/Tests/MigrateFullDrupalTestBase.php +++ b/core/modules/migrate_drupal/src/Tests/MigrateFullDrupalTestBase.php @@ -56,7 +56,7 @@ public function testDrupal() { $classes = $this->getTestClassesList(); foreach ($classes as $class) { if (is_subclass_of($class, '\Drupal\migrate\Tests\MigrateDumpAlterInterface')) { - $class::migrateDumpAlter($this->databasePrefix); + $class::migrateDumpAlter($this); } } diff --git a/core/modules/migrate_drupal/src/Tests/d6/MigrateFileTest.php b/core/modules/migrate_drupal/src/Tests/d6/MigrateFileTest.php index b38e8b5..6e383bc 100644 --- a/core/modules/migrate_drupal/src/Tests/d6/MigrateFileTest.php +++ b/core/modules/migrate_drupal/src/Tests/d6/MigrateFileTest.php @@ -10,16 +10,16 @@ use Drupal\Component\Utility\Random; use Drupal\migrate\MigrateExecutable; use Drupal\migrate\Tests\MigrateDumpAlterInterface; -use Drupal\migrate\Tests\MigrateTearDownInterface; use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase; use Drupal\Core\Database\Database; +use Drupal\simpletest\TestBase; /** * file migration. * * @group migrate_drupal */ -class MigrateFileTest extends MigrateDrupal6TestBase implements MigrateDumpAlterInterface, MigrateTearDownInterface { +class MigrateFileTest extends MigrateDrupal6TestBase implements MigrateDumpAlterInterface { protected static $tempFilename; @@ -34,9 +34,6 @@ class MigrateFileTest extends MigrateDrupal6TestBase implements MigrateDumpAlter * {@inheritdoc} */ protected function setUp() { - // Set the temp file of the site to the same as the D6 site, this allows us - // to test files which start and finish in the same place. - $this->tempFilesDirectory = '/tmp'; parent::setUp(); $dumps = array( $this->getDumpDirectory() . '/Files.php', @@ -53,13 +50,6 @@ protected function setUp() { } /** - * {@inheritdoc} - */ - public static function migrateTearDown() { - unlink('/tmp/' . static::getUniqueFilename()); - } - - /** * Tests the Drupal 6 files to Drupal 8 migration. */ public function testFiles() { @@ -90,7 +80,7 @@ public function testFiles() { ->execute(); Database::getConnection('default', 'migrate') ->update('variable') - ->fields(array('value' => serialize('/tmp'))) + ->fields(array('value' => serialize($this->getTempFilesDirectory()))) ->condition('name', 'file_directory_temp') ->execute(); $executable = new MigrateExecutable($migration, $this); @@ -113,28 +103,24 @@ public static function getUniqueFilename() { } /** - * Creates a random filename and updates the source database. - * - * @return string - * A filename based upon the test. - * - * @see \Drupal\migrate_drupal\Tests\Dump\Files + * {@inheritdoc} */ - public static function migrateDumpAlter($test_id) { - // If it is already set recreate the file and update again. - if (isset(static::$tempFilename)) { - unlink('/tmp/' . static::getUniqueFilename()); - } + public static function migrateDumpAlter(TestBase $test) { + // Creates a random filename and updates the source database. $random = new Random(); - static::$tempFilename = $test_id . $random->name() . '.jpg'; - file_put_contents('/tmp/' . static::$tempFilename, ''); - Database::getConnection('default', 'migrate')->update('files') + $temp_directory = $test->getTempFilesDirectory(); + static::$tempFilename = $test->getDatabasePrefix() . $random->name() . '.jpg'; + $file_path = $temp_directory . '/' . static::$tempFilename; + file_put_contents($file_path, ''); + Database::getConnection('default', 'migrate') + ->update('files') ->condition('fid', 6) ->fields(array( 'filename' => static::$tempFilename, - 'filepath' => '/tmp/' . static::$tempFilename, + 'filepath' => $file_path, )) ->execute(); + return static::$tempFilename; } diff --git a/core/modules/simpletest/src/TestBase.php b/core/modules/simpletest/src/TestBase.php index a95bade..9a38774 100644 --- a/core/modules/simpletest/src/TestBase.php +++ b/core/modules/simpletest/src/TestBase.php @@ -1652,4 +1652,24 @@ protected function config($name) { return \Drupal::configFactory()->getEditable($name); } + /** + * Gets the database prefix. + * + * @return string + * The database prefix + */ + public function getDatabasePrefix() { + return $this->databasePrefix; + } + + /** + * Gets the temporary files directory. + * + * @return string + * The temporary files directory. + */ + public function getTempFilesDirectory() { + return $this->tempFilesDirectory; + } + }