diff --git a/core/modules/migrate/src/Tests/MigrateDumpAlterInterface.php b/core/modules/migrate/src/Tests/MigrateDumpAlterInterface.php new file mode 100644 index 0000000..9ecf825 --- /dev/null +++ b/core/modules/migrate/src/Tests/MigrateDumpAlterInterface.php @@ -0,0 +1,27 @@ +loadDumps($files); + if ($this instanceof MigrateDumpAlterInterface) { + static::migrateDumpAlter($this->databasePrefix); + } } /** diff --git a/core/modules/migrate_drupal/src/Tests/MigrateFullDrupalTestBase.php b/core/modules/migrate_drupal/src/Tests/MigrateFullDrupalTestBase.php index 956a4e6..2796f1e 100644 --- a/core/modules/migrate_drupal/src/Tests/MigrateFullDrupalTestBase.php +++ b/core/modules/migrate_drupal/src/Tests/MigrateFullDrupalTestBase.php @@ -54,6 +54,11 @@ public function testDrupal() { $this->loadDumps($dumps); $classes = $this->getTestClassesList(); + foreach ($classes as $class) { + if (is_subclass_of($class, '\Drupal\migrate\Tests\MigrateDumpAlterInterface')) { + $class::migrateDumpAlter($this->databasePrefix); + } + } // Run every migration in the order specified by the storage controller. foreach (entity_load_multiple('migration', static::$migrations) as $migration) { diff --git a/core/modules/migrate_drupal/src/Tests/Table/d6/Files.php b/core/modules/migrate_drupal/src/Tests/Table/d6/Files.php index 8341fd7..3b42917 100644 --- a/core/modules/migrate_drupal/src/Tests/Table/d6/Files.php +++ b/core/modules/migrate_drupal/src/Tests/Table/d6/Files.php @@ -12,7 +12,6 @@ namespace Drupal\migrate_drupal\Tests\Table\d6; -use Drupal\migrate_drupal\Tests\d6\MigrateFileTest; use Drupal\migrate_drupal\Tests\Dump\DrupalDumpBase; /** @@ -21,7 +20,6 @@ class Files extends DrupalDumpBase { public function load() { - $temp_filename = MigrateFileTest::getUniqueFilename(); $this->createTable("files", array( 'primary key' => array( 'fid', @@ -129,8 +127,8 @@ public function load() { ))->values(array( 'fid' => '6', 'uid' => '1', - 'filename' => $temp_filename, - 'filepath' => '/tmp/' . $temp_filename, + 'filename' => 'some-temp-file.jpg', + 'filepath' => '/tmp/some-temp-file.jpg', 'filemime' => 'image/jpeg', 'filesize' => '24', 'status' => '0', diff --git a/core/modules/migrate_drupal/src/Tests/d6/MigrateDrupal6Test.php b/core/modules/migrate_drupal/src/Tests/d6/MigrateDrupal6Test.php index f671cb4..33835a7 100644 --- a/core/modules/migrate_drupal/src/Tests/d6/MigrateDrupal6Test.php +++ b/core/modules/migrate_drupal/src/Tests/d6/MigrateDrupal6Test.php @@ -158,17 +158,6 @@ protected function setUp() { $config->set('default', 'bartik'); $config->set('admin', 'seven'); $config->save(); - - // We need a temp file for testing the MigrateFileTest. - MigrateFileTest::createUniqueTempFile($this->testId); - } - - /** - * {@inheritdoc} - */ - protected function tearDown() { - unlink('/tmp/' . MigrateFileTest::getUniqueFilename()); - parent::tearDown(); } /** diff --git a/core/modules/migrate_drupal/src/Tests/d6/MigrateFileTest.php b/core/modules/migrate_drupal/src/Tests/d6/MigrateFileTest.php index da40278..b38e8b5 100644 --- a/core/modules/migrate_drupal/src/Tests/d6/MigrateFileTest.php +++ b/core/modules/migrate_drupal/src/Tests/d6/MigrateFileTest.php @@ -9,6 +9,8 @@ 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; @@ -17,7 +19,7 @@ * * @group migrate_drupal */ -class MigrateFileTest extends MigrateDrupal6TestBase { +class MigrateFileTest extends MigrateDrupal6TestBase implements MigrateDumpAlterInterface, MigrateTearDownInterface { protected static $tempFilename; @@ -36,7 +38,6 @@ protected function setUp() { // to test files which start and finish in the same place. $this->tempFilesDirectory = '/tmp'; parent::setUp(); - static::createUniqueTempFile($this->databasePrefix); $dumps = array( $this->getDumpDirectory() . '/Files.php', ); @@ -54,9 +55,8 @@ protected function setUp() { /** * {@inheritdoc} */ - protected function tearDown() { + public static function migrateTearDown() { unlink('/tmp/' . static::getUniqueFilename()); - parent::tearDown(); } /** @@ -113,14 +113,28 @@ public static function getUniqueFilename() { } /** - * Creates a + * Creates a random filename and updates the source database. + * * @return string * A filename based upon the test. + * + * @see \Drupal\migrate_drupal\Tests\Dump\Files */ - public static function createUniqueTempFile($test_id) { + 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()); + } $random = new Random(); static::$tempFilename = $test_id . $random->name() . '.jpg'; file_put_contents('/tmp/' . static::$tempFilename, ''); + Database::getConnection('default', 'migrate')->update('files') + ->condition('fid', 6) + ->fields(array( + 'filename' => static::$tempFilename, + 'filepath' => '/tmp/' . static::$tempFilename, + )) + ->execute(); return static::$tempFilename; }