Update to Drupal 8.2.2. For more information, see https://www.drupal.org/project/drupal/releases/8.2.2
This commit is contained in:
parent
23ffed3665
commit
507b45a0ed
378 changed files with 11434 additions and 5542 deletions
|
@ -0,0 +1,6 @@
|
|||
name: 'Migrate entity test'
|
||||
type: module
|
||||
description: 'Support module for entity destination test.'
|
||||
package: Testing
|
||||
version: VERSION
|
||||
core: 8.x
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\migrate_entity_test\Entity;
|
||||
|
||||
use Drupal\Core\Entity\ContentEntityBase;
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\Core\Field\BaseFieldDefinition;
|
||||
|
||||
/**
|
||||
* Defines a content entity type that has a string ID.
|
||||
*
|
||||
* @ContentEntityType(
|
||||
* id = "migrate_string_id_entity_test",
|
||||
* label = @Translation("String id entity test"),
|
||||
* base_table = "migrate_entity_test_string_id",
|
||||
* entity_keys = {
|
||||
* "id" = "id",
|
||||
* }
|
||||
* )
|
||||
*/
|
||||
class StringIdEntityTest extends ContentEntityBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
|
||||
return [
|
||||
'id' => BaseFieldDefinition::create('integer')
|
||||
->setSetting('size', 'big')
|
||||
->setLabel('ID'),
|
||||
'version' => BaseFieldDefinition::create('string')
|
||||
->setLabel('Version'),
|
||||
];
|
||||
}
|
||||
|
||||
}
|
|
@ -18,9 +18,11 @@ function migrate_prepare_row_test_migrate_prepare_row(Row $row, MigrateSourceInt
|
|||
// Test both options for save_to_map.
|
||||
$data = $row->getSourceProperty('data');
|
||||
if ($data == 'skip_and_record') {
|
||||
// Record mapping but don't record a message.
|
||||
throw new MigrateSkipRowException('', TRUE);
|
||||
}
|
||||
elseif ($data == 'skip_and_dont_record') {
|
||||
throw new MigrateSkipRowException('', FALSE);
|
||||
// Don't record mapping but record a message.
|
||||
throw new MigrateSkipRowException('skip_and_dont_record message', FALSE);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\migrate_prepare_row_test\Plugin\migrate\process;
|
||||
|
||||
use Drupal\migrate\MigrateExecutableInterface;
|
||||
use Drupal\migrate\MigrateSkipRowException;
|
||||
use Drupal\migrate\ProcessPluginBase;
|
||||
use Drupal\migrate\Row;
|
||||
|
||||
/**
|
||||
* Provides a testing process plugin that skips rows.
|
||||
*
|
||||
* @MigrateProcessPlugin(
|
||||
* id = "test_skip_row_process"
|
||||
* )
|
||||
*/
|
||||
class TestSkipRowProcess extends ProcessPluginBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
|
||||
// Test both options for save_to_map.
|
||||
$data = $row->getSourceProperty('data');
|
||||
if ($data == 'skip_and_record (use plugin)') {
|
||||
throw new MigrateSkipRowException('', TRUE);
|
||||
}
|
||||
elseif ($data == 'skip_and_dont_record (use plugin)') {
|
||||
throw new MigrateSkipRowException('', FALSE);
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
}
|
|
@ -4,6 +4,8 @@ namespace Drupal\Tests\migrate\Kernel;
|
|||
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\migrate\MigrateExecutable;
|
||||
use Drupal\migrate\MigrateMessage;
|
||||
use Drupal\migrate\Plugin\migrate\destination\EntityContentBase;
|
||||
use Drupal\migrate\Plugin\MigrateIdMapInterface;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
|
@ -123,7 +125,7 @@ class MigrateEntityContentBaseTest extends KernelTestBase {
|
|||
|
||||
// Import some rows.
|
||||
foreach ($destination_rows as $idx => $destination_row) {
|
||||
$row = new Row([], []);
|
||||
$row = new Row();
|
||||
foreach ($destination_row as $key => $value) {
|
||||
$row->setDestinationProperty($key, $value);
|
||||
}
|
||||
|
@ -156,4 +158,50 @@ class MigrateEntityContentBaseTest extends KernelTestBase {
|
|||
$this->assertTranslations(4, 'fr');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests creation of ID columns table with definitions taken from entity type.
|
||||
*/
|
||||
public function testEntityWithStringId() {
|
||||
$this->enableModules(['migrate_entity_test']);
|
||||
$this->installEntitySchema('migrate_string_id_entity_test');
|
||||
|
||||
$definition = [
|
||||
'source' => [
|
||||
'plugin' => 'embedded_data',
|
||||
'data_rows' => [
|
||||
['id' => 123, 'version' => 'foo'],
|
||||
// This integer needs an 'int' schema with 'big' size. If 'destid1'
|
||||
// is not correctly taking the definition from the destination entity
|
||||
// type, the import will fail with a SQL exception.
|
||||
['id' => 123456789012, 'version' => 'bar'],
|
||||
],
|
||||
'ids' => [
|
||||
'id' => ['type' => 'integer', 'size' => 'big'],
|
||||
'version' => ['type' => 'string'],
|
||||
],
|
||||
],
|
||||
'process' => [
|
||||
'id' => 'id',
|
||||
'version' => 'version',
|
||||
],
|
||||
'destination' => [
|
||||
'plugin' => 'entity:migrate_string_id_entity_test',
|
||||
],
|
||||
];
|
||||
|
||||
$migration = \Drupal::service('plugin.manager.migration')->createStubMigration($definition);
|
||||
$executable = new MigrateExecutable($migration, new MigrateMessage());
|
||||
$result = $executable->import();
|
||||
$this->assertEquals(MigrationInterface::RESULT_COMPLETED, $result);
|
||||
|
||||
/** @var \Drupal\migrate\Plugin\MigrateIdMapInterface $id_map_plugin */
|
||||
$id_map_plugin = $migration->getIdMap();
|
||||
|
||||
// Check that the destination has been stored.
|
||||
$map_row = $id_map_plugin->getRowBySource(['id' => 123, 'version' => 'foo']);
|
||||
$this->assertEquals(123, $map_row['destid1']);
|
||||
$map_row = $id_map_plugin->getRowBySource(['id' => 123456789012, 'version' => 'bar']);
|
||||
$this->assertEquals(123456789012, $map_row['destid1']);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -54,14 +54,49 @@ class MigrateSkipRowTest extends KernelTestBase {
|
|||
$result = $executable->import();
|
||||
$this->assertEqual($result, MigrationInterface::RESULT_COMPLETED);
|
||||
|
||||
/** @var \Drupal\migrate\Plugin\MigrateIdMapInterface $id_map_plugin */
|
||||
$id_map_plugin = $migration->getIdMap();
|
||||
// The first row is recorded in the map as ignored.
|
||||
$map_row = $id_map_plugin->getRowBySource(['id' => 1]);
|
||||
$this->assertEqual(MigrateIdMapInterface::STATUS_IGNORED, $map_row['source_row_status']);
|
||||
// Check that no message has been logged for the first exception.
|
||||
$messages = $id_map_plugin->getMessageIterator(['id' => 1])->fetchAll();
|
||||
$this->assertEmpty($messages);
|
||||
|
||||
// The second row is not recorded in the map.
|
||||
$map_row = $id_map_plugin->getRowBySource(['id' => 2]);
|
||||
$this->assertFalse($map_row);
|
||||
// Check that the correct message has been logged for the second exception.
|
||||
$messages = $id_map_plugin->getMessageIterator(['id' => 2])->fetchAll();
|
||||
$this->assertCount(1, $messages);
|
||||
$message = reset($messages);
|
||||
$this->assertEquals('skip_and_dont_record message', $message->message);
|
||||
$this->assertEquals(MigrationInterface::MESSAGE_INFORMATIONAL, $message->level);
|
||||
|
||||
// Insert a custom processor in the process flow.
|
||||
$definition['process']['value'] = [
|
||||
'source' => 'data',
|
||||
'plugin' => 'test_skip_row_process',
|
||||
];
|
||||
// Change data to avoid triggering again hook_migrate_prepare_row().
|
||||
$definition['source']['data_rows'] = [
|
||||
['id' => '1', 'data' => 'skip_and_record (use plugin)'],
|
||||
['id' => '2', 'data' => 'skip_and_dont_record (use plugin)'],
|
||||
];
|
||||
$migration = \Drupal::service('plugin.manager.migration')->createStubMigration($definition);
|
||||
|
||||
$executable = new MigrateExecutable($migration, new MigrateMessage());
|
||||
$result = $executable->import();
|
||||
$this->assertEquals($result, MigrationInterface::RESULT_COMPLETED);
|
||||
|
||||
$id_map_plugin = $migration->getIdMap();
|
||||
|
||||
// The first row is recorded in the map as ignored.
|
||||
$map_row = $id_map_plugin->getRowBySource(['id' => 1]);
|
||||
$this->assertEquals(MigrateIdMapInterface::STATUS_IGNORED, $map_row['source_row_status']);
|
||||
// The second row is not recorded in the map.
|
||||
$map_row = $id_map_plugin->getRowBySource(['id' => 2]);
|
||||
$this->assertFalse($map_row);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ class CopyFileTest extends FileTestBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['system'];
|
||||
public static $modules = ['migrate', 'system'];
|
||||
|
||||
/**
|
||||
* The file system service.
|
||||
|
@ -172,7 +172,7 @@ class CopyFileTest extends FileTestBase {
|
|||
protected function doImport($source_path, $destination_path, $configuration = []) {
|
||||
$plugin = FileCopy::create($this->container, $configuration, 'file_copy', []);
|
||||
$executable = $this->prophesize(MigrateExecutableInterface::class)->reveal();
|
||||
$row = new Row([], []);
|
||||
$row = new Row();
|
||||
|
||||
$result = $plugin->transform([$source_path, $destination_path], $executable, $row, 'foobaz');
|
||||
|
||||
|
|
128
core/modules/migrate/tests/src/Kernel/process/DownloadTest.php
Normal file
128
core/modules/migrate/tests/src/Kernel/process/DownloadTest.php
Normal file
|
@ -0,0 +1,128 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate\Kernel\process;
|
||||
|
||||
use Drupal\Core\StreamWrapper\StreamWrapperInterface;
|
||||
use Drupal\KernelTests\Core\File\FileTestBase;
|
||||
use Drupal\migrate\MigrateException;
|
||||
use Drupal\migrate\Plugin\migrate\process\Download;
|
||||
use Drupal\migrate\MigrateExecutableInterface;
|
||||
use Drupal\migrate\Row;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
|
||||
/**
|
||||
* Tests the download process plugin.
|
||||
*
|
||||
* @group migrate
|
||||
*/
|
||||
class DownloadTest extends FileTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['system'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->container->get('stream_wrapper_manager')->registerWrapper('temporary', 'Drupal\Core\StreamWrapper\TemporaryStream', StreamWrapperInterface::LOCAL_NORMAL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests a download that overwrites an existing local file.
|
||||
*/
|
||||
public function testOverwritingDownload() {
|
||||
// Create a pre-existing file at the destination, to test overwrite behavior.
|
||||
$destination_uri = $this->createUri('existing_file.txt');
|
||||
|
||||
// Test destructive download.
|
||||
$actual_destination = $this->doTransform($destination_uri);
|
||||
$this->assertSame($destination_uri, $actual_destination, 'Import returned a destination that was not renamed');
|
||||
$this->assertFileNotExists('public://existing_file_0.txt', 'Import did not rename the file');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests a download that renames the downloaded file if there's a collision.
|
||||
*/
|
||||
public function testNonDestructiveDownload() {
|
||||
// Create a pre-existing file at the destination, to test overwrite behavior.
|
||||
$destination_uri = $this->createUri('another_existing_file.txt');
|
||||
|
||||
// Test non-destructive download.
|
||||
$actual_destination = $this->doTransform($destination_uri, ['rename' => TRUE]);
|
||||
$this->assertSame('public://another_existing_file_0.txt', $actual_destination, 'Import returned a renamed destination');
|
||||
$this->assertFileExists($actual_destination, 'Downloaded file was created');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that an exception is thrown if the destination URI is not writable.
|
||||
*/
|
||||
public function testWriteProectedDestination() {
|
||||
// Create a pre-existing file at the destination, to test overwrite behavior.
|
||||
$destination_uri = $this->createUri('not-writable.txt');
|
||||
|
||||
// Make the destination non-writable.
|
||||
$this->container
|
||||
->get('file_system')
|
||||
->chmod($destination_uri, 0444);
|
||||
|
||||
// Pass or fail, we'll need to make the file writable again so the test
|
||||
// can clean up after itself.
|
||||
$fix_permissions = function () use ($destination_uri) {
|
||||
$this->container
|
||||
->get('file_system')
|
||||
->chmod($destination_uri, 0755);
|
||||
};
|
||||
|
||||
try {
|
||||
$this->doTransform($destination_uri);
|
||||
$fix_permissions();
|
||||
$this->fail('MigrateException was not thrown for non-writable destination URI.');
|
||||
}
|
||||
catch (MigrateException $e) {
|
||||
$this->assertTrue(TRUE, 'MigrateException was thrown for non-writable destination URI.');
|
||||
$fix_permissions();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs an input value through the download plugin.
|
||||
*
|
||||
* @param string $destination_uri
|
||||
* The destination URI to download to.
|
||||
* @param array $configuration
|
||||
* (optional) Configuration for the download plugin.
|
||||
*
|
||||
* @return string
|
||||
* The local URI of the downloaded file.
|
||||
*/
|
||||
protected function doTransform($destination_uri, $configuration = []) {
|
||||
// The HTTP client will return a file with contents 'It worked!'
|
||||
$body = fopen('data://text/plain;base64,SXQgd29ya2VkIQ==', 'r');
|
||||
|
||||
// Prepare a mock HTTP client.
|
||||
$this->container->set('http_client', $this->getMock(Client::class));
|
||||
$this->container->get('http_client')
|
||||
->method('get')
|
||||
->willReturn(new Response(200, [], $body));
|
||||
|
||||
// Instantiate the plugin statically so it can pull dependencies out of
|
||||
// the container.
|
||||
$plugin = Download::create($this->container, $configuration, 'download', []);
|
||||
|
||||
// Execute the transformation.
|
||||
$executable = $this->getMock(MigrateExecutableInterface::class);
|
||||
$row = new Row([], []);
|
||||
|
||||
// Return the downloaded file's local URI.
|
||||
$value = [
|
||||
'http://drupal.org/favicon.ico',
|
||||
$destination_uri,
|
||||
];
|
||||
return $plugin->transform($value, $executable, $row, 'foobaz');
|
||||
}
|
||||
|
||||
}
|
111
core/modules/migrate/tests/src/Kernel/process/ExtractTest.php
Normal file
111
core/modules/migrate/tests/src/Kernel/process/ExtractTest.php
Normal file
|
@ -0,0 +1,111 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate\Kernel\process;
|
||||
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
use Drupal\migrate\MigrateExecutable;
|
||||
use Drupal\migrate\MigrateMessage;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
|
||||
/**
|
||||
* Tests the extract process plugin.
|
||||
*
|
||||
* @group migrate
|
||||
*/
|
||||
class ExtractTest extends KernelTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['migrate'];
|
||||
|
||||
/**
|
||||
* Returns test migration definition.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDefinition() {
|
||||
return [
|
||||
'source' => [
|
||||
'plugin' => 'embedded_data',
|
||||
'data_rows' => [],
|
||||
'ids' => [
|
||||
'id' => ['type' => 'string'],
|
||||
],
|
||||
],
|
||||
'process' => [
|
||||
'first' => [
|
||||
'plugin' => 'extract',
|
||||
'index' => [0],
|
||||
'source' => 'simple_array',
|
||||
],
|
||||
'second' => [
|
||||
'plugin' => 'extract',
|
||||
'index' => [1],
|
||||
'source' => 'complex_array',
|
||||
],
|
||||
],
|
||||
'destination' => [
|
||||
'plugin' => 'config',
|
||||
'config_name' => 'migrate_test.settings',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests multiple value handling.
|
||||
*
|
||||
* @dataProvider multipleValueProviderSource
|
||||
*
|
||||
* @param array $source_data
|
||||
* @param array $expected_data
|
||||
*/
|
||||
public function testMultipleValueExplode(array $source_data, array $expected_data) {
|
||||
$definition = $this->getDefinition();
|
||||
$definition['source']['data_rows'] = [$source_data];
|
||||
|
||||
$migration = \Drupal::service('plugin.manager.migration')->createStubMigration($definition);
|
||||
|
||||
$executable = new MigrateExecutable($migration, new MigrateMessage());
|
||||
$result = $executable->import();
|
||||
|
||||
// Migration needs to succeed before further assertions are made.
|
||||
$this->assertSame(MigrationInterface::RESULT_COMPLETED, $result);
|
||||
|
||||
// Compare with expected data.
|
||||
$this->assertEquals($expected_data, \Drupal::config('migrate_test.settings')->get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides multiple source data for "extract" process plugin test.
|
||||
*/
|
||||
public function multipleValueProviderSource() {
|
||||
$tests = [
|
||||
[
|
||||
'source_data' => [
|
||||
'id' => '1',
|
||||
'simple_array' => ['alpha', 'beta'],
|
||||
'complex_array' => [['alpha', 'beta'], ['psi', 'omega']],
|
||||
],
|
||||
'expected_data' => [
|
||||
'first' => 'alpha',
|
||||
'second' => ['psi', 'omega'],
|
||||
],
|
||||
],
|
||||
[
|
||||
'source_data' => [
|
||||
'id' => '2',
|
||||
'simple_array' => ['one'],
|
||||
'complex_array' => [0, 1],
|
||||
],
|
||||
'expected_data' => [
|
||||
'first' => 'one',
|
||||
'second' => 1,
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
return $tests;
|
||||
}
|
||||
|
||||
}
|
180
core/modules/migrate/tests/src/Kernel/process/FileCopyTest.php
Normal file
180
core/modules/migrate/tests/src/Kernel/process/FileCopyTest.php
Normal file
|
@ -0,0 +1,180 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate\Kernel\process;
|
||||
|
||||
use Drupal\Core\StreamWrapper\StreamWrapperInterface;
|
||||
use Drupal\KernelTests\Core\File\FileTestBase;
|
||||
use Drupal\migrate\Plugin\migrate\process\FileCopy;
|
||||
use Drupal\migrate\MigrateExecutableInterface;
|
||||
use Drupal\migrate\Plugin\MigrateProcessInterface;
|
||||
use Drupal\migrate\Row;
|
||||
|
||||
/**
|
||||
* Tests the file_copy process plugin.
|
||||
*
|
||||
* @group migrate
|
||||
*/
|
||||
class FileCopyTest extends FileTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['migrate', 'system'];
|
||||
|
||||
/**
|
||||
* The file system service.
|
||||
*
|
||||
* @var \Drupal\Core\File\FileSystemInterface
|
||||
*/
|
||||
protected $fileSystem;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->fileSystem = $this->container->get('file_system');
|
||||
$this->container->get('stream_wrapper_manager')->registerWrapper('temporary', 'Drupal\Core\StreamWrapper\TemporaryStream', StreamWrapperInterface::LOCAL_NORMAL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test successful imports/copies.
|
||||
*/
|
||||
public function testSuccessfulCopies() {
|
||||
$file = $this->createUri(NULL, NULL, 'temporary');
|
||||
$file_absolute = $this->fileSystem->realpath($file);
|
||||
$data_sets = [
|
||||
// Test a local to local copy.
|
||||
[
|
||||
$this->root . '/core/modules/simpletest/files/image-test.jpg',
|
||||
'public://file1.jpg'
|
||||
],
|
||||
// Test a temporary file using an absolute path.
|
||||
[
|
||||
$file_absolute,
|
||||
'temporary://test.jpg'
|
||||
],
|
||||
// Test a temporary file using a relative path.
|
||||
[
|
||||
$file_absolute,
|
||||
'temporary://core/modules/simpletest/files/test.jpg'
|
||||
],
|
||||
];
|
||||
foreach ($data_sets as $data) {
|
||||
list($source_path, $destination_path) = $data;
|
||||
$actual_destination = $this->doTransform($source_path, $destination_path);
|
||||
$message = sprintf('File %s exists', $destination_path);
|
||||
$this->assertFileExists($destination_path, $message);
|
||||
// Make sure we didn't accidentally do a move.
|
||||
$this->assertFileExists($source_path, $message);
|
||||
$this->assertSame($actual_destination, $destination_path, 'The import returned the copied filename.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test successful moves.
|
||||
*/
|
||||
public function testSuccessfulMoves() {
|
||||
$file_1 = $this->createUri(NULL, NULL, 'temporary');
|
||||
$file_1_absolute = $this->fileSystem->realpath($file_1);
|
||||
$file_2 = $this->createUri(NULL, NULL, 'temporary');
|
||||
$file_2_absolute = $this->fileSystem->realpath($file_2);
|
||||
$local_file = $this->createUri(NULL, NULL, 'public');
|
||||
$data_sets = [
|
||||
// Test a local to local copy.
|
||||
[
|
||||
$local_file,
|
||||
'public://file1.jpg'
|
||||
],
|
||||
// Test a temporary file using an absolute path.
|
||||
[
|
||||
$file_1_absolute,
|
||||
'temporary://test.jpg'
|
||||
],
|
||||
// Test a temporary file using a relative path.
|
||||
[
|
||||
$file_2_absolute,
|
||||
'temporary://core/modules/simpletest/files/test.jpg'
|
||||
],
|
||||
];
|
||||
foreach ($data_sets as $data) {
|
||||
list($source_path, $destination_path) = $data;
|
||||
$actual_destination = $this->doTransform($source_path, $destination_path, ['move' => TRUE]);
|
||||
$message = sprintf('File %s exists', $destination_path);
|
||||
$this->assertFileExists($destination_path, $message);
|
||||
$message = sprintf('File %s does not exist', $source_path);
|
||||
$this->assertFileNotExists($source_path, $message);
|
||||
$this->assertSame($actual_destination, $destination_path, 'The importer returned the moved filename.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that non-existent files throw an exception.
|
||||
*
|
||||
* @expectedException \Drupal\migrate\MigrateException
|
||||
*
|
||||
* @expectedExceptionMessage File '/non/existent/file' does not exist
|
||||
*/
|
||||
public function testNonExistentSourceFile() {
|
||||
$source = '/non/existent/file';
|
||||
$this->doTransform($source, 'public://wontmatter.jpg');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the 'rename' overwrite mode.
|
||||
*/
|
||||
public function testRenameFile() {
|
||||
$source = $this->createUri(NULL, NULL, 'temporary');
|
||||
$destination = $this->createUri('foo.txt', NULL, 'public');
|
||||
$expected_destination = 'public://foo_0.txt';
|
||||
$actual_destination = $this->doTransform($source, $destination, ['rename' => TRUE]);
|
||||
$this->assertFileExists($expected_destination, 'File was renamed on import');
|
||||
$this->assertSame($actual_destination, $expected_destination, 'The importer returned the renamed filename.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that remote URIs are delegated to the download plugin.
|
||||
*/
|
||||
public function testDownloadRemoteUri() {
|
||||
$download_plugin = $this->getMock(MigrateProcessInterface::class);
|
||||
$download_plugin->expects($this->once())->method('transform');
|
||||
|
||||
$plugin = new FileCopy(
|
||||
[],
|
||||
$this->randomMachineName(),
|
||||
[],
|
||||
$this->container->get('stream_wrapper_manager'),
|
||||
$this->container->get('file_system'),
|
||||
$download_plugin
|
||||
);
|
||||
|
||||
$plugin->transform(
|
||||
['http://drupal.org/favicon.ico', '/destination/path'],
|
||||
$this->getMock(MigrateExecutableInterface::class),
|
||||
new Row([], []),
|
||||
$this->randomMachineName()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Do an import using the destination.
|
||||
*
|
||||
* @param string $source_path
|
||||
* Source path to copy from.
|
||||
* @param string $destination_path
|
||||
* The destination path to copy to.
|
||||
* @param array $configuration
|
||||
* Process plugin configuration settings.
|
||||
*
|
||||
* @return string
|
||||
* The URI of the copied file.
|
||||
*/
|
||||
protected function doTransform($source_path, $destination_path, $configuration = []) {
|
||||
$plugin = FileCopy::create($this->container, $configuration, 'file_copy', []);
|
||||
$executable = $this->prophesize(MigrateExecutableInterface::class)->reveal();
|
||||
$row = new Row([], []);
|
||||
|
||||
return $plugin->transform([$source_path, $destination_path], $executable, $row, 'foobaz');
|
||||
}
|
||||
|
||||
}
|
|
@ -398,7 +398,7 @@ class MigrateExecutableTest extends MigrateTestCase {
|
|||
->method('getProcessPlugins')
|
||||
->with(NULL)
|
||||
->will($this->returnValue($plugins));
|
||||
$row = new Row(array(), array());
|
||||
$row = new Row();
|
||||
$this->executable->processRow($row);
|
||||
foreach ($expected as $key => $value) {
|
||||
$this->assertSame($row->getDestinationProperty($key), $value);
|
||||
|
@ -414,7 +414,7 @@ class MigrateExecutableTest extends MigrateTestCase {
|
|||
->method('getProcessPlugins')
|
||||
->with(NULL)
|
||||
->will($this->returnValue(array('test' => array())));
|
||||
$row = new Row(array(), array());
|
||||
$row = new Row();
|
||||
$this->executable->processRow($row);
|
||||
$this->assertSame($row->getDestination(), array());
|
||||
}
|
||||
|
|
|
@ -286,7 +286,7 @@ class MigrateSourceTest extends MigrateTestCase {
|
|||
// Get a new migration with an id.
|
||||
$migration = $this->getMigration();
|
||||
$source = new StubSourcePlugin([], '', [], $migration);
|
||||
$row = new Row([], []);
|
||||
$row = new Row();
|
||||
|
||||
$module_handler = $this->prophesize(ModuleHandlerInterface::class);
|
||||
$module_handler->invokeAll('migrate_prepare_row', [$row, $source, $migration])
|
||||
|
@ -328,7 +328,7 @@ class MigrateSourceTest extends MigrateTestCase {
|
|||
|
||||
$migration = $this->getMigration();
|
||||
$source = new StubSourcePlugin([], '', [], $migration);
|
||||
$row = new Row([], []);
|
||||
$row = new Row();
|
||||
|
||||
$module_handler = $this->prophesize(ModuleHandlerInterface::class);
|
||||
// Return a failure from a prepare row hook.
|
||||
|
@ -357,7 +357,7 @@ class MigrateSourceTest extends MigrateTestCase {
|
|||
|
||||
$migration = $this->getMigration();
|
||||
$source = new StubSourcePlugin([], '', [], $migration);
|
||||
$row = new Row([], []);
|
||||
$row = new Row();
|
||||
|
||||
$module_handler = $this->prophesize(ModuleHandlerInterface::class);
|
||||
// Return a failure from a prepare row hook.
|
||||
|
@ -386,7 +386,7 @@ class MigrateSourceTest extends MigrateTestCase {
|
|||
|
||||
$migration = $this->getMigration();
|
||||
$source = new StubSourcePlugin([], '', [], $migration);
|
||||
$row = new Row([], []);
|
||||
$row = new Row();
|
||||
|
||||
$module_handler = $this->prophesize(ModuleHandlerInterface::class);
|
||||
// Return a failure from a prepare row hook.
|
||||
|
|
|
@ -147,7 +147,7 @@ abstract class MigrateSqlSourceTestCase extends MigrateTestCase {
|
|||
public function testSourceCount() {
|
||||
$count = $this->source->count();
|
||||
$this->assertTrue(is_numeric($count));
|
||||
$this->assertEquals($count, $this->expectedCount);
|
||||
$this->assertEquals($this->expectedCount, $count);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -11,6 +11,7 @@ use Drupal\Core\Entity\ContentEntityInterface;
|
|||
use Drupal\Core\Entity\ContentEntityType;
|
||||
use Drupal\Core\Entity\EntityManagerInterface;
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\Core\Field\BaseFieldDefinition;
|
||||
use Drupal\Core\Field\FieldTypePluginManagerInterface;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate\Plugin\migrate\destination\EntityContentBase;
|
||||
|
@ -74,7 +75,7 @@ class EntityContentBaseTest extends UnitTestCase {
|
|||
->willReturn(5);
|
||||
$destination->setEntity($entity->reveal());
|
||||
// Ensure the id is saved entity id is returned from import.
|
||||
$this->assertEquals([5], $destination->import(new Row([], [])));
|
||||
$this->assertEquals([5], $destination->import(new Row()));
|
||||
// Assert that import set the rollback action.
|
||||
$this->assertEquals(MigrateIdMapInterface::ROLLBACK_DELETE, $destination->rollbackAction());
|
||||
}
|
||||
|
@ -95,7 +96,7 @@ class EntityContentBaseTest extends UnitTestCase {
|
|||
$this->entityManager->reveal(),
|
||||
$this->prophesize(FieldTypePluginManagerInterface::class)->reveal());
|
||||
$destination->setEntity(FALSE);
|
||||
$destination->import(new Row([], []));
|
||||
$destination->import(new Row());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -109,6 +110,8 @@ class EntityContentBaseTest extends UnitTestCase {
|
|||
$entity_type = $this->prophesize(ContentEntityType::class);
|
||||
$entity_type->getKey('langcode')->willReturn('');
|
||||
$entity_type->getKey('id')->willReturn('id');
|
||||
$this->entityManager->getBaseFieldDefinitions('foo')
|
||||
->willReturn(['id' => BaseFieldDefinitionTest::create('integer')]);
|
||||
|
||||
$this->storage->getEntityType()->willReturn($entity_type->reveal());
|
||||
|
||||
|
@ -144,4 +147,27 @@ class EntityTestDestination extends EntityContentBase {
|
|||
return $this->entity;
|
||||
}
|
||||
|
||||
public static function getEntityTypeId($plugin_id) {
|
||||
return 'foo';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Stub class for BaseFieldDefinition.
|
||||
*/
|
||||
class BaseFieldDefinitionTest extends BaseFieldDefinition {
|
||||
|
||||
public static function create($type) {
|
||||
return new static([]);
|
||||
}
|
||||
|
||||
public function getSettings() {
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getType() {
|
||||
return 'integer';
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ class RowTest extends UnitTestCase {
|
|||
* Tests object creation: empty.
|
||||
*/
|
||||
public function testRowWithoutData() {
|
||||
$row = new Row(array(), array());
|
||||
$row = new Row();
|
||||
$this->assertSame(array(), $row->getSource(), 'Empty row');
|
||||
}
|
||||
|
||||
|
|
|
@ -67,7 +67,7 @@ class EntityRevisionTest extends UnitTestCase {
|
|||
$this->storage->loadRevision(12)
|
||||
->shouldBeCalled()
|
||||
->willReturn($entity->reveal());
|
||||
$row = new Row([], []);
|
||||
$row = new Row();
|
||||
$this->assertEquals($entity->reveal(), $destination->getEntity($row, [12, 13]));
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ class PerComponentEntityDisplayTest extends MigrateTestCase {
|
|||
'field_name' => 'field_name_test',
|
||||
'options' => array('test setting'),
|
||||
);
|
||||
$row = new Row(array(), array());
|
||||
$row = new Row();
|
||||
foreach ($values as $key => $value) {
|
||||
$row->setDestinationProperty($key, $value);
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ class PerComponentEntityFormDisplayTest extends MigrateTestCase {
|
|||
'field_name' => 'field_name_test',
|
||||
'options' => array('test setting'),
|
||||
);
|
||||
$row = new Row(array(), array());
|
||||
$row = new Row();
|
||||
foreach ($values as $key => $value) {
|
||||
$row->setDestinationProperty($key, $value);
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ class IteratorTest extends MigrateTestCase {
|
|||
),
|
||||
);
|
||||
// This is not used but the interface requires it, so create an empty row.
|
||||
$row = new Row(array(), array());
|
||||
$row = new Row();
|
||||
|
||||
// After transformation, check to make sure that source_foo and source_id's
|
||||
// values ended up in the proper destinations, and that the value of the
|
||||
|
|
|
@ -57,7 +57,7 @@ class UrlEncodeTest extends MigrateTestCase {
|
|||
*/
|
||||
protected function doTransform($value) {
|
||||
$executable = new MigrateExecutable($this->getMigration(), new MigrateMessage());
|
||||
$row = new Row([], []);
|
||||
$row = new Row();
|
||||
|
||||
return (new UrlEncode([], 'urlencode', []))
|
||||
->transform($value, $executable, $row, 'foobaz');
|
||||
|
|
Reference in a new issue