updated core to 8.6.1 via composer
This commit is contained in:
+2
-2
@@ -4,5 +4,5 @@ package: Testing
|
||||
version: VERSION
|
||||
core: 8.x
|
||||
dependencies:
|
||||
- node
|
||||
- migrate
|
||||
- drupal:node
|
||||
- drupal:migrate
|
||||
|
||||
+1
-1
@@ -4,4 +4,4 @@ description: 'Provides test fixtures for testing high water marks.'
|
||||
package: Testing
|
||||
core: 8.x
|
||||
dependencies:
|
||||
- migrate
|
||||
- drupal:migrate
|
||||
|
||||
+1
-1
@@ -4,4 +4,4 @@ description: 'Provides a database table and records for SQL import with batch te
|
||||
package: Testing
|
||||
core: 8.x
|
||||
dependencies:
|
||||
- migrate
|
||||
- drupal:migrate
|
||||
|
||||
+1
-1
@@ -4,4 +4,4 @@ package: Testing
|
||||
version: VERSION
|
||||
core: 8.x
|
||||
dependencies:
|
||||
- migrate
|
||||
- drupal:migrate
|
||||
|
||||
@@ -41,7 +41,7 @@ class DownloadFunctionalTest extends BrowserTestBase {
|
||||
'uri' => [
|
||||
'plugin' => 'download',
|
||||
'source' => ['url', 'uri'],
|
||||
]
|
||||
],
|
||||
],
|
||||
'destination' => [
|
||||
'plugin' => 'entity:file',
|
||||
|
||||
@@ -34,7 +34,7 @@ class MigrateConfigRollbackTest extends MigrateTestBase {
|
||||
$ids = [
|
||||
'id' =>
|
||||
[
|
||||
'type' => 'string'
|
||||
'type' => 'string',
|
||||
],
|
||||
];
|
||||
$definition = [
|
||||
@@ -100,12 +100,12 @@ class MigrateConfigRollbackTest extends MigrateTestBase {
|
||||
$ids = [
|
||||
'id' =>
|
||||
[
|
||||
'type' => 'string'
|
||||
'type' => 'string',
|
||||
],
|
||||
'language' =>
|
||||
[
|
||||
'type' => 'string'
|
||||
]
|
||||
'type' => 'string',
|
||||
],
|
||||
];
|
||||
$definition = [
|
||||
'id' => 'i18n_config',
|
||||
|
||||
@@ -83,14 +83,14 @@ class MigrateRollbackEntityConfigTest extends MigrateTestBase {
|
||||
'name' => '1',
|
||||
'language' => 'fr',
|
||||
'property' => 'name',
|
||||
'translation' => 'fr - categories'
|
||||
'translation' => 'fr - categories',
|
||||
],
|
||||
[
|
||||
'id' => '2',
|
||||
'name' => '2',
|
||||
'language' => 'fr',
|
||||
'property' => 'name',
|
||||
'translation' => 'fr - tags'
|
||||
'translation' => 'fr - tags',
|
||||
],
|
||||
];
|
||||
$ids = [
|
||||
@@ -106,7 +106,7 @@ class MigrateRollbackEntityConfigTest extends MigrateTestBase {
|
||||
'ids' => $ids,
|
||||
'constants' => [
|
||||
'name' => 'name',
|
||||
]
|
||||
],
|
||||
],
|
||||
'process' => [
|
||||
'vid' => 'id',
|
||||
|
||||
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate\Kernel\Plugin;
|
||||
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\node\Entity\Node;
|
||||
use Drupal\Tests\migrate\Kernel\MigrateTestBase;
|
||||
use Drupal\Tests\node\Traits\ContentTypeCreationTrait;
|
||||
|
||||
/**
|
||||
* Tests the EntityRevision destination plugin.
|
||||
*
|
||||
* @group migrate
|
||||
*/
|
||||
class EntityRevisionTest extends MigrateTestBase {
|
||||
|
||||
use ContentTypeCreationTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = [
|
||||
'content_translation',
|
||||
'field',
|
||||
'filter',
|
||||
'language',
|
||||
'node',
|
||||
'system',
|
||||
'text',
|
||||
'user',
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->installConfig('node');
|
||||
$this->installSchema('node', ['node_access']);
|
||||
$this->installEntitySchema('node');
|
||||
$this->installEntitySchema('user');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that EntityRevision correctly handles revision translations.
|
||||
*/
|
||||
public function testRevisionTranslation() {
|
||||
ConfigurableLanguage::createFromLangcode('fr')->save();
|
||||
|
||||
/** @var \Drupal\node\NodeInterface $node */
|
||||
$node = Node::create([
|
||||
'type' => $this->createContentType()->id(),
|
||||
'title' => 'Default 1',
|
||||
]);
|
||||
$node->addTranslation('fr', [
|
||||
'title' => 'French 1',
|
||||
]);
|
||||
$node->save();
|
||||
$node->setNewRevision();
|
||||
$node->setTitle('Default 2');
|
||||
$node->getTranslation('fr')->setTitle('French 2');
|
||||
$node->save();
|
||||
|
||||
$migration = [
|
||||
'source' => [
|
||||
'plugin' => 'embedded_data',
|
||||
'data_rows' => [
|
||||
[
|
||||
'nid' => $node->id(),
|
||||
'vid' => $node->getRevisionId(),
|
||||
'langcode' => 'fr',
|
||||
'title' => 'Titre nouveau, tabarnak!',
|
||||
],
|
||||
],
|
||||
'ids' => [
|
||||
'nid' => [
|
||||
'type' => 'integer',
|
||||
],
|
||||
'vid' => [
|
||||
'type' => 'integer',
|
||||
],
|
||||
'langcode' => [
|
||||
'type' => 'string',
|
||||
],
|
||||
],
|
||||
],
|
||||
'process' => [
|
||||
'nid' => 'nid',
|
||||
'vid' => 'vid',
|
||||
'langcode' => 'langcode',
|
||||
'title' => 'title',
|
||||
],
|
||||
'destination' => [
|
||||
'plugin' => 'entity_revision:node',
|
||||
'translations' => TRUE,
|
||||
],
|
||||
];
|
||||
|
||||
/** @var \Drupal\migrate\Plugin\MigrationInterface $migration */
|
||||
$migration = $this->container
|
||||
->get('plugin.manager.migration')
|
||||
->createStubMigration($migration);
|
||||
|
||||
$this->executeMigration($migration);
|
||||
|
||||
// The entity_revision destination uses the revision ID and langcode as its
|
||||
// keys (the langcode is only used if the destination is configured for
|
||||
// translation), so we should be able to look up the source IDs by revision
|
||||
// ID and langcode.
|
||||
$source_ids = $migration->getIdMap()->lookupSourceID([
|
||||
'vid' => $node->getRevisionId(),
|
||||
'langcode' => 'fr',
|
||||
]);
|
||||
$this->assertNotEmpty($source_ids);
|
||||
$this->assertSame($node->id(), $source_ids['nid']);
|
||||
$this->assertSame($node->getRevisionId(), $source_ids['vid']);
|
||||
$this->assertSame('fr', $source_ids['langcode']);
|
||||
|
||||
// Confirm the french revision was used in the migration, instead of the
|
||||
// default revision.
|
||||
/** @var \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager */
|
||||
$entity_type_manager = \Drupal::entityTypeManager();
|
||||
$revision = $entity_type_manager->getStorage('node')->loadRevision(1);
|
||||
$this->assertSame('Default 1', $revision->label());
|
||||
$this->assertSame('French 1', $revision->getTranslation('fr')->label());
|
||||
$revision = $entity_type_manager->getStorage('node')->loadRevision(2);
|
||||
$this->assertSame('Default 2', $revision->label());
|
||||
$this->assertSame('Titre nouveau, tabarnak!', $revision->getTranslation('fr')->label());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace Drupal\Tests\migrate\Kernel\Plugin;
|
||||
|
||||
use Drupal\Core\Database\Database;
|
||||
use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait;
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
use Drupal\migrate\Exception\RequirementsException;
|
||||
use Drupal\migrate\Plugin\migrate\source\SqlBase;
|
||||
@@ -16,6 +17,8 @@ use Drupal\migrate\Plugin\RequirementsInterface;
|
||||
*/
|
||||
class MigrationPluginListTest extends KernelTestBase {
|
||||
|
||||
use EntityReferenceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@@ -30,6 +33,7 @@ class MigrationPluginListTest extends KernelTestBase {
|
||||
'book',
|
||||
'comment',
|
||||
'contact',
|
||||
'content_translation',
|
||||
'dblog',
|
||||
'field',
|
||||
'file',
|
||||
@@ -41,6 +45,7 @@ class MigrationPluginListTest extends KernelTestBase {
|
||||
'menu_link_content',
|
||||
'menu_ui',
|
||||
'node',
|
||||
'options',
|
||||
'path',
|
||||
'search',
|
||||
'shortcut',
|
||||
@@ -59,6 +64,11 @@ class MigrationPluginListTest extends KernelTestBase {
|
||||
* @covers ::getDefinitions
|
||||
*/
|
||||
public function testGetDefinitions() {
|
||||
// Create an entity reference field to make sure that migrations derived by
|
||||
// EntityReferenceTranslationDeriver do not get discovered without
|
||||
// migrate_drupal enabled.
|
||||
$this->createEntityReferenceField('user', 'user', 'field_entity_reference', 'Entity Reference', 'node');
|
||||
|
||||
// Make sure retrieving all the core migration plugins does not throw any
|
||||
// errors.
|
||||
$migration_plugins = $this->container->get('plugin.manager.migration')->getDefinitions();
|
||||
@@ -131,6 +141,11 @@ class MigrationPluginListTest extends KernelTestBase {
|
||||
$migration_plugins = $this->container->get('plugin.manager.migration')->getDefinitions();
|
||||
// All the plugins provided by core depend on migrate_drupal.
|
||||
$this->assertNotEmpty($migration_plugins);
|
||||
|
||||
// Test that migrations derived by EntityReferenceTranslationDeriver are
|
||||
// discovered now that migrate_drupal is enabled.
|
||||
$this->assertArrayHasKey('d6_entity_reference_translation:user__user', $migration_plugins);
|
||||
$this->assertArrayHasKey('d7_entity_reference_translation:user__user', $migration_plugins);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -31,16 +31,12 @@ class MigrationProvidersExistTest extends MigrateDrupalTestBase {
|
||||
public function testProvidersExist() {
|
||||
$this->enableAllModules();
|
||||
|
||||
/** @var \Drupal\migrate\Plugin\MigrationPluginManager $plugin_manager */
|
||||
$plugin_manager = $this->container->get('plugin.manager.migration');
|
||||
/** @var \Drupal\migrate\Plugin\MigrateSourcePluginManager $plugin_manager */
|
||||
$plugin_manager = $this->container->get('plugin.manager.migrate.source');
|
||||
|
||||
// Instantiate all migrations.
|
||||
$migrations = array_keys($plugin_manager->getDefinitions());
|
||||
$migrations = $plugin_manager->createInstances($migrations);
|
||||
|
||||
/** @var \Drupal\migrate\Plugin\MigrationInterface $migration */
|
||||
foreach ($migrations as $migration) {
|
||||
$this->assertInternalType('string', $migration->getSourcePlugin()->getSourceModule());
|
||||
foreach ($plugin_manager->getDefinitions() as $definition) {
|
||||
$id = $definition['id'];
|
||||
$this->assertArrayHasKey('source_module', $definition, "No source_module property in '$id'");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
namespace Drupal\Tests\migrate\Kernel\Plugin;
|
||||
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
use Drupal\migrate\MigrateException;
|
||||
use Drupal\migrate\MigrateSkipRowException;
|
||||
|
||||
/**
|
||||
* Tests the migration plugin.
|
||||
@@ -27,6 +29,17 @@ class MigrationTest extends KernelTestBase {
|
||||
$this->assertEquals([], $migration->getProcessPlugins([]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests Migration::getProcessPlugins() throws an exception.
|
||||
*
|
||||
* @covers ::getProcessPlugins
|
||||
*/
|
||||
public function testGetProcessPluginsException() {
|
||||
$migration = \Drupal::service('plugin.manager.migration')->createStubMigration([]);
|
||||
$this->setExpectedException(MigrateException::class, 'Invalid process configuration for foobar');
|
||||
$migration->getProcessPlugins(['foobar' => ['plugin' => 'get']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests Migration::getMigrationDependencies()
|
||||
*
|
||||
@@ -39,7 +52,7 @@ class MigrationTest extends KernelTestBase {
|
||||
'f1' => 'bar',
|
||||
'f2' => [
|
||||
'plugin' => 'migration',
|
||||
'migration' => 'm1'
|
||||
'migration' => 'm1',
|
||||
],
|
||||
'f3' => [
|
||||
'plugin' => 'sub_process',
|
||||
@@ -50,10 +63,32 @@ class MigrationTest extends KernelTestBase {
|
||||
],
|
||||
],
|
||||
],
|
||||
'f4' => [
|
||||
'plugin' => 'migration_lookup',
|
||||
'migration' => 'm3',
|
||||
],
|
||||
'f5' => [
|
||||
'plugin' => 'sub_process',
|
||||
'process' => [
|
||||
'target_id' => [
|
||||
'plugin' => 'migration_lookup',
|
||||
'migration' => 'm4',
|
||||
],
|
||||
],
|
||||
],
|
||||
'f6' => [
|
||||
'plugin' => 'iterator',
|
||||
'process' => [
|
||||
'target_id' => [
|
||||
'plugin' => 'migration_lookup',
|
||||
'migration' => 'm5',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
$migration = $plugin_manager->createStubMigration($plugin_definition);
|
||||
$this->assertSame(['required' => [], 'optional' => ['m1', 'm2']], $migration->getMigrationDependencies());
|
||||
$this->assertSame(['required' => [], 'optional' => ['m1', 'm2', 'm3', 'm4', 'm5']], $migration->getMigrationDependencies());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -81,4 +116,15 @@ class MigrationTest extends KernelTestBase {
|
||||
$this->assertEquals(TRUE, $migration->isTrackLastImported());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests Migration::getDestinationPlugin()
|
||||
*
|
||||
* @covers ::getDestinationPlugin
|
||||
*/
|
||||
public function testGetDestinationPlugin() {
|
||||
$migration = \Drupal::service('plugin.manager.migration')->createStubMigration(['destination' => ['no_stub' => TRUE]]);
|
||||
$this->setExpectedException(MigrateSkipRowException::class, "Stub requested but not made because no_stub configuration is set.");
|
||||
$migration->getDestinationPlugin(TRUE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ class DownloadTest extends FileTestBase {
|
||||
$destination_uri = $this->createUri('another_existing_file.txt');
|
||||
|
||||
// Test non-destructive download.
|
||||
$actual_destination = $this->doTransform($destination_uri, ['rename' => TRUE]);
|
||||
$actual_destination = $this->doTransform($destination_uri, ['file_exists' => 'rename']);
|
||||
$this->assertSame('public://another_existing_file_0.txt', $actual_destination, 'Import returned a renamed destination');
|
||||
$this->assertFileExists($actual_destination, 'Downloaded file was created');
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ use Drupal\migrate\Plugin\migrate\process\FileCopy;
|
||||
use Drupal\migrate\MigrateExecutableInterface;
|
||||
use Drupal\migrate\Plugin\MigrateProcessInterface;
|
||||
use Drupal\migrate\Row;
|
||||
use GuzzleHttp\Client;
|
||||
|
||||
/**
|
||||
* Tests the file_copy process plugin.
|
||||
@@ -50,17 +51,17 @@ class FileCopyTest extends FileTestBase {
|
||||
// Test a local to local copy.
|
||||
[
|
||||
$this->root . '/core/modules/simpletest/files/image-test.jpg',
|
||||
'public://file1.jpg'
|
||||
'public://file1.jpg',
|
||||
],
|
||||
// Test a temporary file using an absolute path.
|
||||
[
|
||||
$file_absolute,
|
||||
'temporary://test.jpg'
|
||||
'temporary://test.jpg',
|
||||
],
|
||||
// Test a temporary file using a relative path.
|
||||
[
|
||||
$file_absolute,
|
||||
'temporary://core/modules/simpletest/files/test.jpg'
|
||||
'temporary://core/modules/simpletest/files/test.jpg',
|
||||
],
|
||||
];
|
||||
foreach ($data_sets as $data) {
|
||||
@@ -76,30 +77,52 @@ class FileCopyTest extends FileTestBase {
|
||||
|
||||
/**
|
||||
* Test successful file reuse.
|
||||
*
|
||||
* @dataProvider providerSuccessfulReuse
|
||||
*
|
||||
* @param string $source_path
|
||||
* Source path to copy from.
|
||||
* @param string $destination_path
|
||||
* The destination path to copy to.
|
||||
*/
|
||||
public function testSuccessfulReuse() {
|
||||
$source_path = $this->root . '/core/modules/simpletest/files/image-test.jpg';
|
||||
$destination_path = 'public://file1.jpg';
|
||||
$file_reuse = file_unmanaged_copy($source_path, $destination_path);
|
||||
public function testSuccessfulReuse($source_path, $destination_path) {
|
||||
$file_reuse = $this->doTransform($source_path, $destination_path);
|
||||
clearstatcache(TRUE, $destination_path);
|
||||
|
||||
$timestamp = (new \SplFileInfo($file_reuse))->getMTime();
|
||||
$this->assertInternalType('int', $timestamp);
|
||||
|
||||
// We need to make sure the modified timestamp on the file is sooner than
|
||||
// the attempted migration.
|
||||
sleep(1);
|
||||
$configuration = ['reuse' => TRUE];
|
||||
$configuration = ['file_exists' => 'use existing'];
|
||||
$this->doTransform($source_path, $destination_path, $configuration);
|
||||
clearstatcache(TRUE, $destination_path);
|
||||
$modified_timestamp = (new \SplFileInfo($destination_path))->getMTime();
|
||||
$this->assertEquals($timestamp, $modified_timestamp);
|
||||
|
||||
$configuration = ['reuse' => FALSE];
|
||||
$this->doTransform($source_path, $destination_path, $configuration);
|
||||
$this->doTransform($source_path, $destination_path);
|
||||
clearstatcache(TRUE, $destination_path);
|
||||
$modified_timestamp = (new \SplFileInfo($destination_path))->getMTime();
|
||||
$this->assertGreaterThan($timestamp, $modified_timestamp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides the source and destination path files.
|
||||
*/
|
||||
public function providerSuccessfulReuse() {
|
||||
return [
|
||||
[
|
||||
'local_source_path' => static::getDrupalRoot() . '/core/modules/simpletest/files/image-test.jpg',
|
||||
'local_destination_path' => 'public://file1.jpg',
|
||||
],
|
||||
[
|
||||
'remote_source_path' => 'https://www.drupal.org/favicon.ico',
|
||||
'remote_destination_path' => 'public://file2.jpg',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test successful moves.
|
||||
*/
|
||||
@@ -113,17 +136,17 @@ class FileCopyTest extends FileTestBase {
|
||||
// Test a local to local copy.
|
||||
[
|
||||
$local_file,
|
||||
'public://file1.jpg'
|
||||
'public://file1.jpg',
|
||||
],
|
||||
// Test a temporary file using an absolute path.
|
||||
[
|
||||
$file_1_absolute,
|
||||
'temporary://test.jpg'
|
||||
'temporary://test.jpg',
|
||||
],
|
||||
// Test a temporary file using a relative path.
|
||||
[
|
||||
$file_2_absolute,
|
||||
'temporary://core/modules/simpletest/files/test.jpg'
|
||||
'temporary://core/modules/simpletest/files/test.jpg',
|
||||
],
|
||||
];
|
||||
foreach ($data_sets as $data) {
|
||||
@@ -179,7 +202,7 @@ class FileCopyTest extends FileTestBase {
|
||||
$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]);
|
||||
$actual_destination = $this->doTransform($source, $destination, ['file_exists' => 'rename']);
|
||||
$this->assertFileExists($expected_destination, 'File was renamed on import');
|
||||
$this->assertSame($actual_destination, $expected_destination, 'The importer returned the renamed filename.');
|
||||
}
|
||||
@@ -222,6 +245,9 @@ class FileCopyTest extends FileTestBase {
|
||||
* The URI of the copied file.
|
||||
*/
|
||||
protected function doTransform($source_path, $destination_path, $configuration = []) {
|
||||
// Prepare a mock HTTP client.
|
||||
$this->container->set('http_client', $this->createMock(Client::class));
|
||||
|
||||
$plugin = FileCopy::create($this->container, $configuration, 'file_copy', []);
|
||||
$executable = $this->prophesize(MigrateExecutableInterface::class)->reveal();
|
||||
$row = new Row([], []);
|
||||
|
||||
@@ -95,9 +95,9 @@ class MigrateExecutableTest extends MigrateTestCase {
|
||||
->will($this->returnValue(['id' => 'test']));
|
||||
|
||||
$this->idMap->expects($this->once())
|
||||
->method('lookupDestinationId')
|
||||
->method('lookupDestinationIds')
|
||||
->with(['id' => 'test'])
|
||||
->will($this->returnValue(['test']));
|
||||
->will($this->returnValue([['test']]));
|
||||
|
||||
$source->expects($this->once())
|
||||
->method('current')
|
||||
@@ -137,9 +137,9 @@ class MigrateExecutableTest extends MigrateTestCase {
|
||||
->will($this->returnValue(['id' => 'test']));
|
||||
|
||||
$this->idMap->expects($this->once())
|
||||
->method('lookupDestinationId')
|
||||
->method('lookupDestinationIds')
|
||||
->with(['id' => 'test'])
|
||||
->will($this->returnValue(['test']));
|
||||
->will($this->returnValue([['test']]));
|
||||
|
||||
$source->expects($this->once())
|
||||
->method('current')
|
||||
@@ -213,9 +213,9 @@ class MigrateExecutableTest extends MigrateTestCase {
|
||||
->method('saveMessage');
|
||||
|
||||
$this->idMap->expects($this->once())
|
||||
->method('lookupDestinationId')
|
||||
->method('lookupDestinationIds')
|
||||
->with(['id' => 'test'])
|
||||
->will($this->returnValue(['test']));
|
||||
->will($this->returnValue([['test']]));
|
||||
|
||||
$this->message->expects($this->once())
|
||||
->method('display')
|
||||
@@ -269,9 +269,9 @@ class MigrateExecutableTest extends MigrateTestCase {
|
||||
->method('saveMessage');
|
||||
|
||||
$this->idMap->expects($this->once())
|
||||
->method('lookupDestinationId')
|
||||
->method('lookupDestinationIds')
|
||||
->with(['id' => 'test'])
|
||||
->will($this->returnValue(['test']));
|
||||
->will($this->returnValue([['test']]));
|
||||
|
||||
$this->assertSame(MigrationInterface::RESULT_COMPLETED, $this->executable->import());
|
||||
}
|
||||
@@ -319,7 +319,7 @@ class MigrateExecutableTest extends MigrateTestCase {
|
||||
->method('saveMessage');
|
||||
|
||||
$this->idMap->expects($this->never())
|
||||
->method('lookupDestinationId');
|
||||
->method('lookupDestinationIds');
|
||||
|
||||
$this->assertSame(MigrationInterface::RESULT_COMPLETED, $this->executable->import());
|
||||
}
|
||||
@@ -367,9 +367,9 @@ class MigrateExecutableTest extends MigrateTestCase {
|
||||
->method('saveMessage');
|
||||
|
||||
$this->idMap->expects($this->once())
|
||||
->method('lookupDestinationId')
|
||||
->method('lookupDestinationIds')
|
||||
->with(['id' => 'test'])
|
||||
->will($this->returnValue(['test']));
|
||||
->will($this->returnValue([['test']]));
|
||||
|
||||
$this->message->expects($this->once())
|
||||
->method('display')
|
||||
@@ -384,7 +384,7 @@ class MigrateExecutableTest extends MigrateTestCase {
|
||||
public function testProcessRow() {
|
||||
$expected = [
|
||||
'test' => 'test destination',
|
||||
'test1' => 'test1 destination'
|
||||
'test1' => 'test1 destination',
|
||||
];
|
||||
foreach ($expected as $key => $value) {
|
||||
$plugins[$key][0] = $this->getMock('Drupal\migrate\Plugin\MigrateProcessInterface');
|
||||
|
||||
@@ -28,7 +28,7 @@ class MigrateSqlIdMapEnsureTablesTest extends MigrateTestCase {
|
||||
'type' => 'varchar',
|
||||
'length' => 64,
|
||||
'not null' => 1,
|
||||
'description' => 'Hash of source ids. Used as primary key'
|
||||
'description' => 'Hash of source ids. Used as primary key',
|
||||
];
|
||||
$fields['sourceid1'] = [
|
||||
'type' => 'int',
|
||||
@@ -101,7 +101,7 @@ class MigrateSqlIdMapEnsureTablesTest extends MigrateTestCase {
|
||||
'type' => 'varchar',
|
||||
'length' => 64,
|
||||
'not null' => 1,
|
||||
'description' => 'Hash of source ids. Used as primary key'
|
||||
'description' => 'Hash of source ids. Used as primary key',
|
||||
];
|
||||
$fields['level'] = [
|
||||
'type' => 'int',
|
||||
|
||||
@@ -166,7 +166,7 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
|
||||
$expected_result = [
|
||||
[
|
||||
'sourceid1' => 'source_value',
|
||||
'source_ids_hash' => $this->getIdMap()->getSourceIDsHash($source),
|
||||
'source_ids_hash' => $this->getIdMap()->getSourceIdsHash($source),
|
||||
'destid1' => 2,
|
||||
] + $this->idMapDefaults(),
|
||||
];
|
||||
@@ -178,7 +178,7 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
|
||||
$id_map->saveIdMapping($row, ['destination_id_property' => 3]);
|
||||
$expected_result[] = [
|
||||
'sourceid1' => 'source_value_1',
|
||||
'source_ids_hash' => $this->getIdMap()->getSourceIDsHash($source),
|
||||
'source_ids_hash' => $this->getIdMap()->getSourceIdsHash($source),
|
||||
'destid1' => 3,
|
||||
] + $this->idMapDefaults();
|
||||
$this->queryResultTest($this->getIdMapContents(), $expected_result);
|
||||
@@ -236,7 +236,7 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
|
||||
$id_map->saveIdMapping($row, $destination, $status);
|
||||
$expected_results[] = [
|
||||
'sourceid1' => 'source_value_' . $status,
|
||||
'source_ids_hash' => $this->getIdMap()->getSourceIDsHash($source),
|
||||
'source_ids_hash' => $this->getIdMap()->getSourceIdsHash($source),
|
||||
'destid1' => 'destination_value_' . $status,
|
||||
'source_row_status' => $status,
|
||||
'rollback_action' => MigrateIdMapInterface::ROLLBACK_DELETE,
|
||||
@@ -348,14 +348,14 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
|
||||
$row = [
|
||||
'sourceid1' => 'source_id_value_1',
|
||||
'sourceid2' => 'source_id_value_2',
|
||||
'source_ids_hash' => $this->getIdMap()->getSourceIDsHash(['source_id_property' => 'source_id_value_1']),
|
||||
'source_ids_hash' => $this->getIdMap()->getSourceIdsHash(['source_id_property' => 'source_id_value_1']),
|
||||
'destid1' => 'destination_id_value_1',
|
||||
] + $this->idMapDefaults();
|
||||
$this->saveMap($row);
|
||||
$row = [
|
||||
'sourceid1' => 'source_id_value_3',
|
||||
'sourceid2' => 'source_id_value_4',
|
||||
'source_ids_hash' => $this->getIdMap()->getSourceIDsHash(['source_id_property' => 'source_id_value_3', 'sourceid2' => 'source_id_value_4']),
|
||||
'source_ids_hash' => $this->getIdMap()->getSourceIdsHash(['source_id_property' => 'source_id_value_3', 'sourceid2' => 'source_id_value_4']),
|
||||
'destid1' => 'destination_id_value_2',
|
||||
] + $this->idMapDefaults();
|
||||
$this->saveMap($row);
|
||||
@@ -419,7 +419,7 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
|
||||
$expected_result[] = "destination_id_value_$i";
|
||||
$this->destinationIds["destination_id_property_$i"] = [];
|
||||
}
|
||||
$row['source_ids_hash'] = $this->getIdMap()->getSourceIDsHash($source_id_values);
|
||||
$row['source_ids_hash'] = $this->getIdMap()->getSourceIdsHash($source_id_values);
|
||||
$this->saveMap($row);
|
||||
$id_map = $this->getIdMap();
|
||||
// Test for a valid hit.
|
||||
@@ -458,7 +458,7 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
|
||||
foreach ($rows as $row) {
|
||||
$values = array_combine($db_keys, $row);
|
||||
$source_values = array_slice($row, 0, count($source_keys));
|
||||
$values['source_ids_hash'] = $this->getIdMap()->getSourceIDsHash($source_values);
|
||||
$values['source_ids_hash'] = $this->getIdMap()->getSourceIdsHash($source_values);
|
||||
$this->saveMap($values);
|
||||
}
|
||||
|
||||
@@ -517,6 +517,8 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
|
||||
$this->assertEquals([[101, 'en'], [101, 'fr'], [101, 'de']], $id_map->lookupDestinationIds(['nid' => 1]));
|
||||
$this->assertEquals([[102, 'en']], $id_map->lookupDestinationIds(['nid' => 2]));
|
||||
$this->assertEquals([], $id_map->lookupDestinationIds(['nid' => 99]));
|
||||
$this->assertEquals([[101, 'en'], [101, 'fr'], [101, 'de']], $id_map->lookupDestinationIds(['nid' => 1, 'language' => NULL]));
|
||||
$this->assertEquals([[102, 'en']], $id_map->lookupDestinationIds(['nid' => 2, 'language' => NULL]));
|
||||
// Out-of-order partial associative list.
|
||||
$this->assertEquals([[101, 'en'], [102, 'en']], $id_map->lookupDestinationIds(['language' => 'en']));
|
||||
$this->assertEquals([[101, 'fr']], $id_map->lookupDestinationIds(['language' => 'fr']));
|
||||
@@ -527,14 +529,14 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
|
||||
$this->fail('Too many source IDs should throw');
|
||||
}
|
||||
catch (MigrateException $e) {
|
||||
$this->assertEquals("Extra unknown items in source IDs", $e->getMessage());
|
||||
$this->assertEquals("Extra unknown items in source IDs: array (\n 0 => 3,\n)", $e->getMessage());
|
||||
}
|
||||
try {
|
||||
$id_map->lookupDestinationIds(['nid' => 1, 'aaa' => '2']);
|
||||
$this->fail('Unknown source ID key should throw');
|
||||
}
|
||||
catch (MigrateException $e) {
|
||||
$this->assertEquals("Extra unknown items in source IDs", $e->getMessage());
|
||||
$this->assertEquals("Extra unknown items in source IDs: array (\n 'aaa' => '2',\n)", $e->getMessage());
|
||||
}
|
||||
|
||||
// Verify that we are looking up by source_id_hash when all source IDs are
|
||||
@@ -554,14 +556,14 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
|
||||
$row = [
|
||||
'sourceid1' => 'source_id_value_1',
|
||||
'sourceid2' => 'source_id_value_2',
|
||||
'source_ids_hash' => $this->getIdMap()->getSourceIDsHash(['source_id_property' => 'source_id_value_1']),
|
||||
'source_ids_hash' => $this->getIdMap()->getSourceIdsHash(['source_id_property' => 'source_id_value_1']),
|
||||
'destid1' => 'destination_id_value_1',
|
||||
] + $this->idMapDefaults();
|
||||
$this->saveMap($row);
|
||||
$row = [
|
||||
'sourceid1' => 'source_id_value_3',
|
||||
'sourceid2' => 'source_id_value_4',
|
||||
'source_ids_hash' => $this->getIdMap()->getSourceIDsHash(['source_id_property' => 'source_id_value_3']),
|
||||
'source_ids_hash' => $this->getIdMap()->getSourceIdsHash(['source_id_property' => 'source_id_value_3']),
|
||||
'destid1' => 'destination_id_value_2',
|
||||
] + $this->idMapDefaults();
|
||||
$this->saveMap($row);
|
||||
@@ -577,7 +579,7 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testLookupSourceIDMapping().
|
||||
* Data provider for testLookupSourceIdMapping().
|
||||
*
|
||||
* Scenarios to test (for both hits and misses) are:
|
||||
* - Single-value destination ID to single-value source ID.
|
||||
@@ -588,7 +590,7 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
|
||||
* @return array
|
||||
* An array of data values.
|
||||
*/
|
||||
public function lookupSourceIDMappingDataProvider() {
|
||||
public function lookupSourceIdMappingDataProvider() {
|
||||
return [
|
||||
[1, 1],
|
||||
[2, 2],
|
||||
@@ -605,9 +607,9 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
|
||||
* @param int $num_destination_fields
|
||||
* Number of destination fields to test.
|
||||
*
|
||||
* @dataProvider lookupSourceIDMappingDataProvider
|
||||
* @dataProvider lookupSourceIdMappingDataProvider
|
||||
*/
|
||||
public function testLookupSourceIDMapping($num_source_fields, $num_destination_fields) {
|
||||
public function testLookupSourceIdMapping($num_source_fields, $num_destination_fields) {
|
||||
// Adjust the migration configuration according to the number of source and
|
||||
// destination fields.
|
||||
$this->sourceIds = [];
|
||||
@@ -629,14 +631,14 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
|
||||
$nonexistent_id_values["destination_id_property_$i"] = "nonexistent_destination_id_value_$i";
|
||||
$this->destinationIds["destination_id_property_$i"] = [];
|
||||
}
|
||||
$row['source_ids_hash'] = $this->getIdMap()->getSourceIDsHash($source_ids_values);
|
||||
$row['source_ids_hash'] = $this->getIdMap()->getSourceIdsHash($source_ids_values);
|
||||
$this->saveMap($row);
|
||||
$id_map = $this->getIdMap();
|
||||
// Test for a valid hit.
|
||||
$source_id = $id_map->lookupSourceID($destination_id_values);
|
||||
$source_id = $id_map->lookupSourceId($destination_id_values);
|
||||
$this->assertSame($expected_result, $source_id);
|
||||
// Test for a miss.
|
||||
$source_id = $id_map->lookupSourceID($nonexistent_id_values);
|
||||
$source_id = $id_map->lookupSourceId($nonexistent_id_values);
|
||||
$this->assertSame(0, count($source_id));
|
||||
}
|
||||
|
||||
@@ -765,7 +767,7 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
$row = $this->idMapDefaults();
|
||||
$row['sourceid1'] = "source_id_value_$i";
|
||||
$row['source_ids_hash'] = $this->getIdMap()->getSourceIDsHash(['source_id_property' => $row['sourceid1']]);
|
||||
$row['source_ids_hash'] = $this->getIdMap()->getSourceIdsHash(['source_id_property' => $row['sourceid1']]);
|
||||
$row['destid1'] = "destination_id_value_$i";
|
||||
$row['source_row_status'] = MigrateIdMapInterface::STATUS_IMPORTED;
|
||||
$this->saveMap($row);
|
||||
@@ -773,7 +775,7 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
|
||||
for (; $i < 5 + $num_update_rows; $i++) {
|
||||
$row = $this->idMapDefaults();
|
||||
$row['sourceid1'] = "source_id_value_$i";
|
||||
$row['source_ids_hash'] = $this->getIdMap()->getSourceIDsHash(['source_id_property' => $row['sourceid1']]);
|
||||
$row['source_ids_hash'] = $this->getIdMap()->getSourceIdsHash(['source_id_property' => $row['sourceid1']]);
|
||||
$row['destid1'] = "destination_id_value_$i";
|
||||
$row['source_row_status'] = MigrateIdMapInterface::STATUS_NEEDS_UPDATE;
|
||||
$this->saveMap($row);
|
||||
@@ -813,7 +815,7 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
$row = $this->idMapDefaults();
|
||||
$row['sourceid1'] = "source_id_value_$i";
|
||||
$row['source_ids_hash'] = $this->getIdMap()->getSourceIDsHash(['source_id_property' => $row['sourceid1']]);
|
||||
$row['source_ids_hash'] = $this->getIdMap()->getSourceIdsHash(['source_id_property' => $row['sourceid1']]);
|
||||
$row['destid1'] = "destination_id_value_$i";
|
||||
$row['source_row_status'] = MigrateIdMapInterface::STATUS_IMPORTED;
|
||||
$this->saveMap($row);
|
||||
@@ -821,7 +823,7 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
|
||||
for (; $i < 5 + $num_error_rows; $i++) {
|
||||
$row = $this->idMapDefaults();
|
||||
$row['sourceid1'] = "source_id_value_$i";
|
||||
$row['source_ids_hash'] = $this->getIdMap()->getSourceIDsHash(['source_id_property' => $row['sourceid1']]);
|
||||
$row['source_ids_hash'] = $this->getIdMap()->getSourceIdsHash(['source_id_property' => $row['sourceid1']]);
|
||||
$row['destid1'] = "destination_id_value_$i";
|
||||
$row['source_row_status'] = MigrateIdMapInterface::STATUS_FAILED;
|
||||
$this->saveMap($row);
|
||||
@@ -849,7 +851,7 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
|
||||
$id_map->saveIdMapping($row, $destination, $status);
|
||||
$expected_results[] = [
|
||||
'sourceid1' => 'source_value_' . $status,
|
||||
'source_ids_hash' => $this->getIdMap()->getSourceIDsHash($source),
|
||||
'source_ids_hash' => $this->getIdMap()->getSourceIdsHash($source),
|
||||
'destid1' => 'destination_value_' . $status,
|
||||
'source_row_status' => $status,
|
||||
'rollback_action' => MigrateIdMapInterface::ROLLBACK_DELETE,
|
||||
@@ -978,7 +980,7 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
|
||||
for ($i = 0; $i < 3; $i++) {
|
||||
$row = $this->idMapDefaults();
|
||||
$row['sourceid1'] = "source_id_value_$i";
|
||||
$row['source_ids_hash'] = $this->getIdMap()->getSourceIDsHash(['source_id_property' => $row['sourceid1']]);
|
||||
$row['source_ids_hash'] = $this->getIdMap()->getSourceIdsHash(['source_id_property' => $row['sourceid1']]);
|
||||
$row['destid1'] = "destination_id_value_$i";
|
||||
$row['source_row_status'] = MigrateIdMapInterface::STATUS_IMPORTED;
|
||||
$expected_results[serialize(['sourceid1' => $row['sourceid1']])] = ['destid1' => $row['destid1']];
|
||||
@@ -1010,4 +1012,27 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
|
||||
return $contents;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the delayed creation of the "map" and "message" migrate tables.
|
||||
*/
|
||||
public function testMapTableCreation() {
|
||||
$id_map = $this->getIdMap();
|
||||
$map_table_name = $id_map->mapTableName();
|
||||
$message_table_name = $id_map->messageTableName();
|
||||
|
||||
// Check that tables names do exist.
|
||||
$this->assertEquals('migrate_map_sql_idmap_test', $map_table_name);
|
||||
$this->assertEquals('migrate_message_sql_idmap_test', $message_table_name);
|
||||
|
||||
// Check that tables don't exist.
|
||||
$this->assertFalse($this->database->schema()->tableExists($map_table_name));
|
||||
$this->assertFalse($this->database->schema()->tableExists($message_table_name));
|
||||
|
||||
$id_map->getDatabase();
|
||||
|
||||
// Check that tables do exist.
|
||||
$this->assertTrue($this->database->schema()->tableExists($map_table_name));
|
||||
$this->assertTrue($this->database->schema()->tableExists($message_table_name));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ abstract class MigrateSqlSourceTestCase extends MigrateTestCase {
|
||||
/**
|
||||
* The tested source plugin.
|
||||
*
|
||||
* @var \Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase.
|
||||
* @var \Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase
|
||||
*/
|
||||
protected $source;
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ abstract class MigrateTestCase extends UnitTestCase {
|
||||
/**
|
||||
* Local store for mocking setStatus()/getStatus().
|
||||
*
|
||||
* @var \Drupal\migrate\Plugin\MigrationInterface::STATUS_*
|
||||
* @var int
|
||||
*/
|
||||
protected $migrationStatus = MigrationInterface::STATUS_IDLE;
|
||||
|
||||
|
||||
+2
-63
@@ -8,17 +8,11 @@
|
||||
namespace Drupal\Tests\migrate\Unit\Plugin\migrate\destination;
|
||||
|
||||
use Drupal\Core\Entity\ContentEntityInterface;
|
||||
use Drupal\Core\Entity\EntityManagerInterface;
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\Core\Field\BaseFieldDefinition;
|
||||
use Drupal\Core\Field\FieldTypePluginManagerInterface;
|
||||
use Drupal\migrate\MigrateException;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate\Plugin\migrate\destination\EntityContentBase;
|
||||
use Drupal\migrate\Plugin\MigrateIdMapInterface;
|
||||
use Drupal\migrate\Row;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
||||
/**
|
||||
* Tests base entity migration destination functionality.
|
||||
@@ -26,43 +20,7 @@ use Drupal\Tests\UnitTestCase;
|
||||
* @coversDefaultClass \Drupal\migrate\Plugin\migrate\destination\EntityContentBase
|
||||
* @group migrate
|
||||
*/
|
||||
class EntityContentBaseTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* @var \Drupal\migrate\Plugin\MigrationInterface
|
||||
*/
|
||||
protected $migration;
|
||||
|
||||
/**
|
||||
* @var \Drupal\Core\Entity\EntityStorageInterface
|
||||
*/
|
||||
protected $storage;
|
||||
|
||||
/**
|
||||
* @var \Drupal\Core\Entity\EntityTypeInterface
|
||||
*/
|
||||
protected $entityType;
|
||||
|
||||
/**
|
||||
* @var \Drupal\Core\Entity\EntityManagerInterface
|
||||
*/
|
||||
protected $entityManager;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->migration = $this->prophesize(MigrationInterface::class);
|
||||
$this->storage = $this->prophesize(EntityStorageInterface::class);
|
||||
|
||||
$this->entityType = $this->prophesize(EntityTypeInterface::class);
|
||||
$this->entityType->getPluralLabel()->willReturn('wonkiness');
|
||||
$this->storage->getEntityType()->willReturn($this->entityType->reveal());
|
||||
|
||||
$this->entityManager = $this->prophesize(EntityManagerInterface::class);
|
||||
}
|
||||
class EntityContentBaseTest extends EntityTestBase {
|
||||
|
||||
/**
|
||||
* Test basic entity save.
|
||||
@@ -129,7 +87,7 @@ class EntityContentBaseTest extends UnitTestCase {
|
||||
$this->entityManager->reveal(),
|
||||
$this->prophesize(FieldTypePluginManagerInterface::class)->reveal()
|
||||
);
|
||||
$this->setExpectedException(MigrateException::class, 'This entity type does not support translation');
|
||||
$this->setExpectedException(MigrateException::class, 'The "foo" entity type does not support translations.');
|
||||
$destination->getIds();
|
||||
}
|
||||
|
||||
@@ -157,22 +115,3 @@ class EntityTestDestination extends EntityContentBase {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+113
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate\Unit\Plugin\migrate\destination;
|
||||
|
||||
use Drupal\Core\Entity\EntityManagerInterface;
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\Core\Field\FieldTypePluginManagerInterface;
|
||||
use Drupal\migrate\MigrateException;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate\Plugin\migrate\destination\EntityRevision;
|
||||
use Drupal\migrate\Row;
|
||||
|
||||
/**
|
||||
* Tests entity revision destination functionality.
|
||||
*
|
||||
* @coversDefaultClass \Drupal\migrate\Plugin\migrate\destination\EntityRevision
|
||||
* @group migrate
|
||||
*/
|
||||
class EntityRevisionTest extends EntityTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->migration = $this->prophesize(MigrationInterface::class);
|
||||
$this->storage = $this->prophesize(EntityStorageInterface::class);
|
||||
|
||||
$this->entityType = $this->prophesize(EntityTypeInterface::class);
|
||||
$this->entityType->getSingularLabel()->willReturn('foo');
|
||||
$this->entityType->getPluralLabel()->willReturn('bar');
|
||||
$this->storage->getEntityType()->willReturn($this->entityType->reveal());
|
||||
$this->storage->getEntityTypeId()->willReturn('foo');
|
||||
|
||||
$this->entityManager = $this->prophesize(EntityManagerInterface::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that revision destination fails for unrevisionable entities.
|
||||
*/
|
||||
public function testUnrevisionable() {
|
||||
$this->entityType->getKey('id')->willReturn('id');
|
||||
$this->entityType->getKey('revision')->willReturn('');
|
||||
$this->entityManager->getBaseFieldDefinitions('foo')
|
||||
->willReturn([
|
||||
'id' => BaseFieldDefinitionTest::create('integer'),
|
||||
]);
|
||||
|
||||
$destination = new EntityRevisionTestDestination(
|
||||
[],
|
||||
'',
|
||||
[],
|
||||
$this->migration->reveal(),
|
||||
$this->storage->reveal(),
|
||||
[],
|
||||
$this->entityManager->reveal(),
|
||||
$this->prophesize(FieldTypePluginManagerInterface::class)->reveal()
|
||||
);
|
||||
$this->setExpectedException(MigrateException::class, 'The "foo" entity type does not support revisions.');
|
||||
$destination->getIds();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that translation destination fails for untranslatable entities.
|
||||
*/
|
||||
public function testUntranslatable() {
|
||||
$this->entityType->getKey('id')->willReturn('id');
|
||||
$this->entityType->getKey('revision')->willReturn('vid');
|
||||
$this->entityType->getKey('langcode')->willReturn('');
|
||||
$this->entityManager->getBaseFieldDefinitions('foo')
|
||||
->willReturn([
|
||||
'id' => BaseFieldDefinitionTest::create('integer'),
|
||||
'vid' => BaseFieldDefinitionTest::create('integer'),
|
||||
]);
|
||||
|
||||
$destination = new EntityRevisionTestDestination(
|
||||
['translations' => TRUE],
|
||||
'',
|
||||
[],
|
||||
$this->migration->reveal(),
|
||||
$this->storage->reveal(),
|
||||
[],
|
||||
$this->entityManager->reveal(),
|
||||
$this->prophesize(FieldTypePluginManagerInterface::class)->reveal()
|
||||
);
|
||||
$this->setExpectedException(MigrateException::class, 'The "foo" entity type does not support translations.');
|
||||
$destination->getIds();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Stub class for testing EntityRevision methods.
|
||||
*/
|
||||
class EntityRevisionTestDestination extends EntityRevision {
|
||||
|
||||
private $entity = NULL;
|
||||
|
||||
public function setEntity($entity) {
|
||||
$this->entity = $entity;
|
||||
}
|
||||
|
||||
protected function getEntity(Row $row, array $old_destination_id_values) {
|
||||
return $this->entity;
|
||||
}
|
||||
|
||||
public static function getEntityTypeId($plugin_id) {
|
||||
return 'foo';
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\migrate\Unit\Plugin\migrate\destination\EntityTestBase
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\migrate\Unit\Plugin\migrate\destination;
|
||||
|
||||
use Drupal\Core\Entity\EntityManagerInterface;
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\Core\Field\BaseFieldDefinition;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
||||
/**
|
||||
* Base test class forentity migration destination functionality.
|
||||
*/
|
||||
class EntityTestBase extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* @var \Drupal\migrate\Plugin\MigrationInterface
|
||||
*/
|
||||
protected $migration;
|
||||
|
||||
/**
|
||||
* @var \Drupal\Core\Entity\EntityStorageInterface
|
||||
*/
|
||||
protected $storage;
|
||||
|
||||
/**
|
||||
* @var \Drupal\Core\Entity\EntityTypeInterface
|
||||
*/
|
||||
protected $entityType;
|
||||
|
||||
/**
|
||||
* @var \Drupal\Core\Entity\EntityManagerInterface
|
||||
*/
|
||||
protected $entityManager;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->migration = $this->prophesize(MigrationInterface::class);
|
||||
$this->storage = $this->prophesize(EntityStorageInterface::class);
|
||||
|
||||
$this->entityType = $this->prophesize(EntityTypeInterface::class);
|
||||
$this->entityType->getPluralLabel()->willReturn('wonkiness');
|
||||
$this->storage->getEntityType()->willReturn($this->entityType->reveal());
|
||||
$this->storage->getEntityTypeId()->willReturn('foo');
|
||||
|
||||
$this->entityManager = $this->prophesize(EntityManagerInterface::class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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';
|
||||
}
|
||||
|
||||
}
|
||||
@@ -176,7 +176,6 @@ class EntityRevisionTest extends UnitTestCase {
|
||||
$this->assertEquals([1234], $destination->save($entity->reveal(), []));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Helper method to create an entity revision destination with mock services.
|
||||
*
|
||||
@@ -230,6 +229,8 @@ class EntityRevision extends RealEntityRevision {
|
||||
* workings of its implementation which would trickle into mock assertions. An
|
||||
* empty implementation avoids this.
|
||||
*/
|
||||
protected function updateEntity(EntityInterface $entity, Row $row) {}
|
||||
protected function updateEntity(EntityInterface $entity, Row $row) {
|
||||
return $entity;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -53,13 +53,16 @@ class PerComponentEntityDisplayTest extends MigrateTestCase {
|
||||
class TestPerComponentEntityDisplay extends ComponentEntityDisplayBase {
|
||||
const MODE_NAME = 'view_mode';
|
||||
protected $testValues;
|
||||
|
||||
public function __construct($entity) {
|
||||
$this->entity = $entity;
|
||||
}
|
||||
|
||||
protected function getEntity($entity_type, $bundle, $view_mode) {
|
||||
$this->testValues = func_get_args();
|
||||
return $this->entity;
|
||||
}
|
||||
|
||||
public function getTestValues() {
|
||||
return $this->testValues;
|
||||
}
|
||||
|
||||
@@ -53,13 +53,16 @@ class PerComponentEntityFormDisplayTest extends MigrateTestCase {
|
||||
class TestPerComponentEntityFormDisplay extends PerComponentEntityFormDisplay {
|
||||
const MODE_NAME = 'form_mode';
|
||||
protected $testValues;
|
||||
|
||||
public function __construct($entity) {
|
||||
$this->entity = $entity;
|
||||
}
|
||||
|
||||
protected function getEntity($entity_type, $bundle, $form_mode) {
|
||||
$this->testValues = func_get_args();
|
||||
return $this->entity;
|
||||
}
|
||||
|
||||
public function getTestValues() {
|
||||
return $this->testValues;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\migrate\Unit\process\CallbackTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\migrate\Unit\process;
|
||||
|
||||
use Drupal\migrate\Plugin\migrate\process\Callback;
|
||||
@@ -17,39 +12,66 @@ use Drupal\migrate\Plugin\migrate\process\Callback;
|
||||
class CallbackTest extends MigrateProcessTestCase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* Test callback with valid "callable".
|
||||
*
|
||||
* @dataProvider providerCallback
|
||||
*/
|
||||
protected function setUp() {
|
||||
$this->plugin = new TestCallback();
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test callback with a function as callable.
|
||||
*/
|
||||
public function testCallbackWithFunction() {
|
||||
$this->plugin->setCallable('strtolower');
|
||||
public function testCallback($callable) {
|
||||
$configuration = ['callable' => $callable];
|
||||
$this->plugin = new Callback($configuration, 'map', []);
|
||||
$value = $this->plugin->transform('FooBar', $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame('foobar', $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test callback with a class method as callable.
|
||||
* Data provider for ::testCallback().
|
||||
*/
|
||||
public function testCallbackWithClassMethod() {
|
||||
$this->plugin->setCallable(['\Drupal\Component\Utility\Unicode', 'strtolower']);
|
||||
$value = $this->plugin->transform('FooBar', $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame('foobar', $value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class TestCallback extends Callback {
|
||||
public function __construct() {
|
||||
}
|
||||
|
||||
public function setCallable($callable) {
|
||||
$this->configuration['callable'] = $callable;
|
||||
public function providerCallback() {
|
||||
return [
|
||||
'function' => ['strtolower'],
|
||||
'class method' => [[self::class, 'strtolower']],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test callback excpetions.
|
||||
*
|
||||
* @dataProvider providerCallbackExceptions
|
||||
*/
|
||||
public function testCallbackExceptions($message, $configuration) {
|
||||
$this->setExpectedException(\InvalidArgumentException::class, $message);
|
||||
$this->plugin = new Callback($configuration, 'map', []);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for ::testCallbackExceptions().
|
||||
*/
|
||||
public function providerCallbackExceptions() {
|
||||
return [
|
||||
'not set' => [
|
||||
'message' => 'The "callable" must be set.',
|
||||
'configuration' => [],
|
||||
],
|
||||
'invalid method' => [
|
||||
'message' => 'The "callable" must be a valid function or method.',
|
||||
'configuration' => ['callable' => 'nonexistent_callable'],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes a string lowercase for testing purposes.
|
||||
*
|
||||
* @param string $string
|
||||
* The input string.
|
||||
*
|
||||
* @return string
|
||||
* The lowercased string.
|
||||
*
|
||||
* @see \Drupal\Tests\migrate\Unit\process\CallbackTest::providerCallback()
|
||||
*/
|
||||
public static function strToLower($string) {
|
||||
return mb_strtolower($string);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -53,6 +53,7 @@ class ConcatTest extends MigrateProcessTestCase {
|
||||
}
|
||||
|
||||
class TestConcat extends Concat {
|
||||
|
||||
public function __construct() {
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\Core\Entity\Query\QueryInterface;
|
||||
use Drupal\migrate\Plugin\migrate\process\DedupeEntity;
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\migrate\Plugin\migrate\process\DedupeEntity
|
||||
@@ -18,7 +17,7 @@ class DedupeEntityTest extends MigrateProcessTestCase {
|
||||
/**
|
||||
* The mock entity query.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\Query\QueryInterface|\Drupal\Core\Entity\Query\QueryFactory
|
||||
* @var \Drupal\Core\Entity\Query\QueryInterface
|
||||
*/
|
||||
protected $entityQuery;
|
||||
|
||||
@@ -77,7 +76,7 @@ class DedupeEntityTest extends MigrateProcessTestCase {
|
||||
$this->entityQueryExpects($count);
|
||||
$value = $this->randomMachineName(32);
|
||||
$actual = $plugin->transform($value, $this->migrateExecutable, $this->row, 'testproperty');
|
||||
$expected = Unicode::substr($value, $start, $length);
|
||||
$expected = mb_substr($value, $start, $length);
|
||||
$expected .= $count ? $postfix . $count : '';
|
||||
$this->assertSame($expected, $actual);
|
||||
}
|
||||
@@ -198,7 +197,7 @@ class DedupeEntityTest extends MigrateProcessTestCase {
|
||||
|
||||
// Entity 'forums' is pre-existing, entity 'test_vocab' was migrated.
|
||||
$this->idMap
|
||||
->method('lookupSourceID')
|
||||
->method('lookupSourceId')
|
||||
->will($this->returnValueMap([
|
||||
[['test_field' => 'forums'], FALSE],
|
||||
[['test_field' => 'test_vocab'], ['source_id' => 42]],
|
||||
|
||||
@@ -0,0 +1,149 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate\Unit\process;
|
||||
|
||||
use Drupal\Core\File\FileSystemInterface;
|
||||
use Drupal\Core\StreamWrapper\StreamWrapperManagerInterface;
|
||||
use Drupal\migrate\Plugin\migrate\process\FileCopy;
|
||||
use Drupal\migrate\Plugin\MigrateProcessInterface;
|
||||
|
||||
/**
|
||||
* Flag for dealing with existing files: Appends number until name is unique.
|
||||
*/
|
||||
define('FILE_EXISTS_RENAME', 0);
|
||||
|
||||
/**
|
||||
* Flag for dealing with existing files: Replace the existing file.
|
||||
*/
|
||||
define('FILE_EXISTS_REPLACE', 1);
|
||||
|
||||
/**
|
||||
* Flag for dealing with existing files: Do nothing and return FALSE.
|
||||
*/
|
||||
define('FILE_EXISTS_ERROR', 2);
|
||||
|
||||
/**
|
||||
* Tests the file copy process plugin.
|
||||
*
|
||||
* @group migrate
|
||||
* @group legacy
|
||||
*
|
||||
* @coversDefaultClass \Drupal\migrate\Plugin\migrate\process\FileCopy
|
||||
*/
|
||||
class FileCopyTest extends MigrateProcessTestCase {
|
||||
|
||||
/**
|
||||
* Tests that the rename configuration key will trigger a deprecation notice.
|
||||
*
|
||||
* @dataProvider providerDeprecationNoticeRename
|
||||
*
|
||||
* @param array $configuration
|
||||
* The plugin configuration.
|
||||
* @param $expected
|
||||
* The expected value of the plugin configuration.
|
||||
*
|
||||
* @expectedDeprecation Using the key 'rename' is deprecated, use 'file_exists' => 'rename' instead. See https://www.drupal.org/node/2981389.
|
||||
*/
|
||||
public function testDeprecationNoticeRename($configuration, $expected) {
|
||||
$this->assertPlugin($configuration, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testDeprecationNoticeRename.
|
||||
*/
|
||||
public function providerDeprecationNoticeRename() {
|
||||
return [
|
||||
[['rename' => TRUE], FILE_EXISTS_RENAME],
|
||||
[['rename' => FALSE], FILE_EXISTS_REPLACE],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the reuse configuration key will trigger a deprecation notice.
|
||||
*
|
||||
* @dataProvider providerDeprecationNoticeReuse
|
||||
*
|
||||
* @param array $configuration
|
||||
* The plugin configuration.
|
||||
* @param $expected
|
||||
* The expected value of the plugin configuration.
|
||||
*
|
||||
* @expectedDeprecation Using the key 'reuse' is deprecated, use 'file_exists' => 'use existing' instead. See https://www.drupal.org/node/2981389.
|
||||
*/
|
||||
public function testDeprecationNoticeReuse($configuration, $expected) {
|
||||
$this->assertPlugin($configuration, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testDeprecationNoticeReuse.
|
||||
*/
|
||||
public function providerDeprecationNoticeReuse() {
|
||||
return [
|
||||
[['reuse' => TRUE], FILE_EXISTS_ERROR],
|
||||
[['reuse' => FALSE], FILE_EXISTS_REPLACE],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the plugin constructor correctly sets the configuration.
|
||||
*
|
||||
* @dataProvider providerFileProcessBaseConstructor
|
||||
*
|
||||
* @param array $configuration
|
||||
* The plugin configuration.
|
||||
* @param $expected
|
||||
* The expected value of the plugin configuration.
|
||||
*/
|
||||
public function testFileProcessBaseConstructor($configuration, $expected) {
|
||||
$this->assertPlugin($configuration, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testFileProcessBaseConstructor.
|
||||
*/
|
||||
public function providerFileProcessBaseConstructor() {
|
||||
return [
|
||||
[['file_exists' => 'replace'], FILE_EXISTS_REPLACE],
|
||||
[['file_exists' => 'rename'], FILE_EXISTS_RENAME],
|
||||
[['file_exists' => 'use existing'], FILE_EXISTS_ERROR],
|
||||
[['file_exists' => 'foobar'], FILE_EXISTS_REPLACE],
|
||||
[[], FILE_EXISTS_REPLACE],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a TestFileCopy process plugin.
|
||||
*
|
||||
* @param array $configuration
|
||||
* The plugin configuration.
|
||||
* @param $expected
|
||||
* The expected value of the plugin configuration.
|
||||
*/
|
||||
protected function assertPlugin($configuration, $expected) {
|
||||
$stream_wrapper_manager = $this->prophesize(StreamWrapperManagerInterface::class)->reveal();
|
||||
$file_system = $this->prophesize(FileSystemInterface::class)->reveal();
|
||||
$download_plugin = $this->prophesize(MigrateProcessInterface::class)->reveal();
|
||||
$this->plugin = new TestFileCopy($configuration, 'test', [], $stream_wrapper_manager, $file_system, $download_plugin);
|
||||
$plugin_config = $this->plugin->getConfiguration();
|
||||
$this->assertArrayHasKey('file_exists', $plugin_config);
|
||||
$this->assertSame($expected, $plugin_config['file_exists']);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Class for testing FileCopy.
|
||||
*/
|
||||
class TestFileCopy extends FileCopy {
|
||||
|
||||
/**
|
||||
* Gets this plugin's configuration.
|
||||
*
|
||||
* @return array
|
||||
* An array of this plugin's configuration.
|
||||
*/
|
||||
public function getConfiguration() {
|
||||
return $this->configuration;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -85,7 +85,7 @@ class FormatDateTest extends MigrateProcessTestCase {
|
||||
'timezone' => 'America/Managua',
|
||||
],
|
||||
'value' => '2004-12-19T10:19:42-0600',
|
||||
'expected' => '2004-12-19T10:19:42-06:00 -06:00'
|
||||
'expected' => '2004-12-19T10:19:42-06:00 -06:00',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -1,13 +1,8 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\migrate\Unit\process\GetTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\migrate\Unit\process;
|
||||
|
||||
use Drupal\migrate\Plugin\migrate\process\TestGet;
|
||||
use Drupal\migrate\Plugin\migrate\process\Get;
|
||||
|
||||
/**
|
||||
* Tests the get process plugin.
|
||||
@@ -16,14 +11,6 @@ use Drupal\migrate\Plugin\migrate\process\TestGet;
|
||||
*/
|
||||
class GetTest extends MigrateProcessTestCase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
$this->plugin = new TestGet();
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the Get plugin when source is a string.
|
||||
*/
|
||||
@@ -32,7 +19,7 @@ class GetTest extends MigrateProcessTestCase {
|
||||
->method('getSourceProperty')
|
||||
->with('test')
|
||||
->will($this->returnValue('source_value'));
|
||||
$this->plugin->setSource('test');
|
||||
$this->plugin = new Get(['source' => 'test'], '', []);
|
||||
$value = $this->plugin->transform(NULL, $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame('source_value', $value);
|
||||
}
|
||||
@@ -45,7 +32,7 @@ class GetTest extends MigrateProcessTestCase {
|
||||
'test1' => 'source_value1',
|
||||
'test2' => 'source_value2',
|
||||
];
|
||||
$this->plugin->setSource(['test1', 'test2']);
|
||||
$this->plugin = new Get(['source' => ['test1', 'test2']], '', []);
|
||||
$this->row->expects($this->exactly(2))
|
||||
->method('getSourceProperty')
|
||||
->will($this->returnCallback(function ($argument) use ($map) {
|
||||
@@ -63,7 +50,7 @@ class GetTest extends MigrateProcessTestCase {
|
||||
->method('getSourceProperty')
|
||||
->with('@test')
|
||||
->will($this->returnValue('source_value'));
|
||||
$this->plugin->setSource('@@test');
|
||||
$this->plugin = new Get(['source' => '@@test'], '', []);
|
||||
$value = $this->plugin->transform(NULL, $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame('source_value', $value);
|
||||
}
|
||||
@@ -78,7 +65,7 @@ class GetTest extends MigrateProcessTestCase {
|
||||
'@test3' => 'source_value3',
|
||||
'test4' => 'source_value4',
|
||||
];
|
||||
$this->plugin->setSource(['test1', '@@test2', '@@test3', 'test4']);
|
||||
$this->plugin = new Get(['source' => ['test1', '@@test2', '@@test3', 'test4']], '', []);
|
||||
$this->row->expects($this->exactly(4))
|
||||
->method('getSourceProperty')
|
||||
->will($this->returnCallback(function ($argument) use ($map) {
|
||||
@@ -90,34 +77,47 @@ class GetTest extends MigrateProcessTestCase {
|
||||
|
||||
/**
|
||||
* Tests the Get plugin when source has integer values.
|
||||
*
|
||||
* @dataProvider integerValuesDataProvider
|
||||
*/
|
||||
public function testIntegerValues() {
|
||||
$this->row->expects($this->exactly(2))
|
||||
public function testIntegerValues($source, $expected_value) {
|
||||
$this->row->expects($this->atMost(2))
|
||||
->method('getSourceProperty')
|
||||
->willReturnOnConsecutiveCalls('val1', 'val2');
|
||||
|
||||
$this->plugin->setSource([0 => 0, 1 => 'test']);
|
||||
$this->plugin = new Get(['source' => $source], '', []);
|
||||
$return = $this->plugin->transform(NULL, $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame([0 => 'val1', 1 => 'val2'], $return);
|
||||
$this->assertSame($expected_value, $return);
|
||||
}
|
||||
|
||||
$this->plugin->setSource([FALSE]);
|
||||
$return = $this->plugin->transform(NULL, $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame([NULL], $return);
|
||||
/**
|
||||
* Provides data for the successful lookup test.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function integerValuesDataProvider() {
|
||||
return [
|
||||
[
|
||||
'source' => [0 => 0, 1 => 'test'],
|
||||
'expected_value' => [0 => 'val1', 1 => 'val2'],
|
||||
],
|
||||
[
|
||||
'source' => [FALSE],
|
||||
'expected_value' => [NULL],
|
||||
],
|
||||
[
|
||||
'source' => [NULL],
|
||||
'expected_value' => [NULL],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
$this->plugin->setSource([NULL]);
|
||||
$return = $this->plugin->transform(NULL, $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame([NULL], $return);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace Drupal\migrate\Plugin\migrate\process;
|
||||
|
||||
class TestGet extends Get {
|
||||
public function __construct() {
|
||||
}
|
||||
public function setSource($source) {
|
||||
$this->configuration['source'] = $source;
|
||||
/**
|
||||
* Tests the Get plugin for syntax errors, e.g. "Invalid tag_line detected" by
|
||||
* creating a prophecy of the class.
|
||||
*/
|
||||
public function testPluginSyntax() {
|
||||
$this->assertNotNull($this->prophesize(Get::class));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ class IteratorTest extends MigrateTestCase {
|
||||
/**
|
||||
* The iterator plugin being tested.
|
||||
*
|
||||
* @var \Drupal\migrate\Plugin\migrate\process\TestIterator
|
||||
* @var \Drupal\migrate\Plugin\migrate\process\Iterator
|
||||
*/
|
||||
protected $plugin;
|
||||
|
||||
@@ -33,6 +33,7 @@ class IteratorTest extends MigrateTestCase {
|
||||
* Tests the iterator process plugin.
|
||||
*
|
||||
* @group legacy
|
||||
* @expectedDeprecation The Drupal\migrate\Plugin\migrate\process\Iterator is deprecated in Drupal 8.4.x and will be removed before Drupal 9.0.0. Instead, use Drupal\migrate\Plugin\migrate\process\SubProcess
|
||||
*/
|
||||
public function testIterator() {
|
||||
$migration = $this->getMigration();
|
||||
|
||||
@@ -6,7 +6,6 @@ use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\Core\Entity\Query\QueryInterface;
|
||||
use Drupal\migrate\Plugin\migrate\process\MakeUniqueEntityField;
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\migrate\Plugin\migrate\process\MakeUniqueEntityField
|
||||
@@ -17,7 +16,7 @@ class MakeUniqueEntityFieldTest extends MigrateProcessTestCase {
|
||||
/**
|
||||
* The mock entity query.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\Query\QueryInterface|\Drupal\Core\Entity\Query\QueryFactory
|
||||
* @var \Drupal\Core\Entity\Query\QueryInterface
|
||||
*/
|
||||
protected $entityQuery;
|
||||
|
||||
@@ -76,7 +75,7 @@ class MakeUniqueEntityFieldTest extends MigrateProcessTestCase {
|
||||
$this->entityQueryExpects($count);
|
||||
$value = $this->randomMachineName(32);
|
||||
$actual = $plugin->transform($value, $this->migrateExecutable, $this->row, 'testproperty');
|
||||
$expected = Unicode::substr($value, $start, $length);
|
||||
$expected = mb_substr($value, $start, $length);
|
||||
$expected .= $count ? $postfix . $count : '';
|
||||
$this->assertSame($expected, $actual);
|
||||
}
|
||||
@@ -197,7 +196,7 @@ class MakeUniqueEntityFieldTest extends MigrateProcessTestCase {
|
||||
|
||||
// Entity 'forums' is pre-existing, entity 'test_vocab' was migrated.
|
||||
$this->idMap
|
||||
->method('lookupSourceID')
|
||||
->method('lookupSourceId')
|
||||
->will($this->returnValueMap([
|
||||
[['test_field' => 'forums'], FALSE],
|
||||
[['test_field' => 'test_vocab'], ['source_id' => 42]],
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate\Unit\process;
|
||||
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\Core\Menu\MenuLinkManagerInterface;
|
||||
use Drupal\migrate\MigrateSkipRowException;
|
||||
use Drupal\migrate\Plugin\migrate\process\MenuLinkParent;
|
||||
use Drupal\migrate\Plugin\MigrateProcessInterface;
|
||||
|
||||
/**
|
||||
* Tests the menu link parent process plugin.
|
||||
*
|
||||
* @coversDefaultClass \Drupal\migrate\Plugin\migrate\process\MenuLinkParent
|
||||
* @group migrate
|
||||
*/
|
||||
class MenuLinkParentTest extends MigrateProcessTestCase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$migration_plugin = $this->prophesize(MigrateProcessInterface::class);
|
||||
$menu_link_manager = $this->prophesize(MenuLinkManagerInterface::class);
|
||||
$menu_link_storage = $this->prophesize(EntityStorageInterface::class);
|
||||
$this->plugin = new MenuLinkParent([], 'map', [], $migration_plugin->reveal(), $menu_link_manager->reveal(), $menu_link_storage->reveal());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::transform
|
||||
*/
|
||||
public function testTransformException() {
|
||||
$this->setExpectedException(MigrateSkipRowException::class, "No parent link found for plid '1' in menu 'admin'.");
|
||||
$this->plugin->transform([1, 'admin', NULL], $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,6 +4,7 @@ namespace Drupal\Tests\migrate\Unit\process;
|
||||
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\migrate\MigrateSkipProcessException;
|
||||
use Drupal\migrate\Plugin\migrate\process\Get;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate\Plugin\migrate\process\MigrationLookup;
|
||||
use Drupal\migrate\Plugin\MigrateDestinationInterface;
|
||||
@@ -249,7 +250,7 @@ class MigrationLookupTest extends MigrateProcessTestCase {
|
||||
$migration_plugin_manager = $this->prophesize(MigrationPluginManagerInterface::class);
|
||||
$process_plugin_manager = $this->prophesize(MigratePluginManager::class);
|
||||
$foobaz_migration = $this->prophesize(MigrationInterface::class);
|
||||
$get_migration = $this->prophesize(MigrationLookup::class);
|
||||
$get_migration = $this->prophesize(Get::class);
|
||||
$id_map = $this->prophesize(MigrateIdMapInterface::class);
|
||||
$destination_plugin = $this->prophesize(MigrateDestinationInterface::class);
|
||||
$source_plugin = $this->prophesize(MigrateSourceInterface::class);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Drupal\Tests\migrate\Unit\process;
|
||||
|
||||
use Drupal\Component\Utility\Variable;
|
||||
use Drupal\migrate\MigrateException;
|
||||
use Drupal\migrate\MigrateSkipRowException;
|
||||
use Drupal\migrate\Plugin\migrate\process\StaticMap;
|
||||
@@ -50,7 +51,7 @@ class StaticMapTest extends MigrateProcessTestCase {
|
||||
* Tests when the source is invalid.
|
||||
*/
|
||||
public function testMapwithInvalidSource() {
|
||||
$this->setExpectedException(MigrateSkipRowException::class);
|
||||
$this->setExpectedException(MigrateSkipRowException::class, sprintf("No static mapping found for '%s' and no default value provided for destination '%s'.", Variable::export(['bar']), 'destinationproperty'));
|
||||
$this->plugin->transform(['bar'], $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user