Commit 54ba27d8 authored by webchick's avatar webchick

Issue #2417549 by alexpott, znerol, benjy, Berdir:...

Issue #2417549 by alexpott, znerol, benjy, Berdir: Drupal\migrate_drupal\Tests\d6\MigrateFileTest fail in MigrateTestBase
parent 5728e48d
<?php
/**
* @file
* Contains \Drupal\migrate\Tests\MigrateDumpAlterInterface.
*/
namespace Drupal\migrate\Tests;
use Drupal\simpletest\TestBase;
/**
* Allows tests to alter dumps after they've loaded.
*
* @s
* @see \Drupal\migrate_drupal\Tests\d6\MigrateFileTest
*/
interface MigrateDumpAlterInterface {
/**
* Allows tests to alter dumps after they've loaded.
*
* @param \Drupal\simpletest\TestBase $test
* The test that is being run.
*/
public static function migrateDumpAlter(TestBase $test);
}
......@@ -79,6 +79,9 @@ protected function tearDown() {
*/
protected function prepare(MigrationInterface $migration, array $files = array()) {
$this->loadDumps($files);
if ($this instanceof MigrateDumpAlterInterface) {
static::migrateDumpAlter($this);
}
}
/**
......
......@@ -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);
}
}
// Run every migration in the order specified by the storage controller.
foreach (entity_load_multiple('migration', static::$migrations) as $migration) {
......
......@@ -158,9 +158,6 @@ protected function setUp() {
$config->set('default', 'bartik');
$config->set('admin', 'seven');
$config->save();
// We need a temp file for testing the MigrateFileTest.
file_put_contents('/tmp/some-temp-file.jpg', '');
}
/**
......
......@@ -7,16 +7,26 @@
namespace Drupal\migrate_drupal\Tests\d6;
use Drupal\Component\Utility\Random;
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate\Tests\MigrateDumpAlterInterface;
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 {
class MigrateFileTest extends MigrateDrupal6TestBase implements MigrateDumpAlterInterface {
/**
* The filename of a file used to test temporary file migration.
*
* @var string
*/
protected static $tempFilename;
/**
* Modules to enable.
......@@ -29,9 +39,6 @@ class MigrateFileTest extends MigrateDrupal6TestBase {
* {@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',
......@@ -45,7 +52,6 @@ protected function setUp() {
$executable = new MigrateExecutable($migration, $this);
$executable->import();
$this->standalone = TRUE;
file_put_contents('/tmp/some-temp-file.jpg', '');
}
/**
......@@ -79,7 +85,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);
......@@ -90,7 +96,37 @@ public function testFiles() {
// Ensure that a temporary file has been migrated.
$file = entity_load('file', 6);
$this->assertIdentical('temporary://some-temp-file.jpg', $file->getFileUri());
$this->assertIdentical('temporary://' . static::getUniqueFilename(), $file->getFileUri());
}
/**
* @return string
* A filename based upon the test.
*/
public static function getUniqueFilename() {
return static::$tempFilename;
}
/**
* {@inheritdoc}
*/
public static function migrateDumpAlter(TestBase $test) {
// Creates a random filename and updates the source database.
$random = new Random();
$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' => $file_path,
))
->execute();
return static::$tempFilename;
}
}
......@@ -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;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment