Update Composer, update everything
This commit is contained in:
parent
ea3e94409f
commit
dda5c284b6
19527 changed files with 1135420 additions and 351004 deletions
|
@ -4,5 +4,5 @@ package: Testing
|
|||
version: VERSION
|
||||
core: 8.x
|
||||
dependencies:
|
||||
- node
|
||||
- migrate
|
||||
- drupal:node
|
||||
- drupal:migrate
|
||||
|
|
|
@ -8,7 +8,8 @@ use Drupal\migrate\Plugin\migrate\source\SourcePluginBase;
|
|||
* A simple migrate source for our tests.
|
||||
*
|
||||
* @MigrateSource(
|
||||
* id = "migrate_external_translated_test"
|
||||
* id = "migrate_external_translated_test",
|
||||
* source_module = "migrate_external_translated_test"
|
||||
* )
|
||||
*/
|
||||
class MigrateExternalTranslatedTestSource extends SourcePluginBase {
|
||||
|
|
|
@ -4,4 +4,4 @@ description: 'Provides test fixtures for testing high water marks.'
|
|||
package: Testing
|
||||
core: 8.x
|
||||
dependencies:
|
||||
- migrate
|
||||
- drupal:migrate
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
name: 'Migration directory test'
|
||||
type: module
|
||||
package: Testing
|
||||
version: VERSION
|
||||
core: 8.x
|
||||
dependencies:
|
||||
- drupal:migrate
|
|
@ -0,0 +1,8 @@
|
|||
id: migration_templates_test
|
||||
label: Migration templates test
|
||||
source:
|
||||
plugin: embedded_data
|
||||
process:
|
||||
id: id
|
||||
destination:
|
||||
plugin: null
|
|
@ -3,7 +3,6 @@
|
|||
namespace Drupal\Tests\migrate\Functional\process;
|
||||
|
||||
use Drupal\migrate\MigrateExecutable;
|
||||
use Drupal\migrate\MigrateMessage;
|
||||
use Drupal\migrate\Plugin\MigrateIdMapInterface;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
@ -42,7 +41,7 @@ class DownloadFunctionalTest extends BrowserTestBase {
|
|||
'uri' => [
|
||||
'plugin' => 'download',
|
||||
'source' => ['url', 'uri'],
|
||||
]
|
||||
],
|
||||
],
|
||||
'destination' => [
|
||||
'plugin' => 'entity:file',
|
||||
|
@ -51,7 +50,7 @@ class DownloadFunctionalTest extends BrowserTestBase {
|
|||
|
||||
$migration = \Drupal::service('plugin.manager.migration')->createStubMigration($definition);
|
||||
|
||||
$executable = new MigrateExecutable($migration, new MigrateMessage());
|
||||
$executable = new MigrateExecutable($migration);
|
||||
$result = $executable->import();
|
||||
|
||||
// Check that the migration has completed.
|
||||
|
|
|
@ -18,13 +18,14 @@ class MigrateBundleTest extends MigrateTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['taxonomy', 'text'];
|
||||
public static $modules = ['taxonomy', 'text', 'user'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->installEntitySchema('user');
|
||||
$this->installEntitySchema('taxonomy_vocabulary');
|
||||
$this->installEntitySchema('taxonomy_term');
|
||||
$this->installConfig(['taxonomy']);
|
||||
|
@ -65,7 +66,7 @@ class MigrateBundleTest extends MigrateTestBase {
|
|||
// Import and validate the term entity was created with the correct bundle.
|
||||
$term_executable = new MigrateExecutable($term_migration, $this);
|
||||
$term_executable->import();
|
||||
/** @var Term $term */
|
||||
/** @var \Drupal\taxonomy\Entity\Term $term */
|
||||
$term = Term::load(1);
|
||||
$this->assertEquals($term->bundle(), 'categories');
|
||||
}
|
||||
|
@ -103,7 +104,7 @@ class MigrateBundleTest extends MigrateTestBase {
|
|||
// Import and validate the term entities were created with the correct bundle.
|
||||
$term_executable = new MigrateExecutable($term_migration, $this);
|
||||
$term_executable->import();
|
||||
/** @var Term $term */
|
||||
/** @var \Drupal\taxonomy\Entity\Term $term */
|
||||
$term = Term::load(1);
|
||||
$this->assertEquals($term->bundle(), 'categories');
|
||||
$term = Term::load(2);
|
||||
|
@ -145,7 +146,7 @@ class MigrateBundleTest extends MigrateTestBase {
|
|||
// Import and validate the term entities were created with the correct bundle.
|
||||
$term_executable = new MigrateExecutable($term_migration, $this);
|
||||
$term_executable->import();
|
||||
/** @var Term $term */
|
||||
/** @var \Drupal\taxonomy\Entity\Term $term */
|
||||
$term = Term::load(1);
|
||||
$this->assertEquals($term->bundle(), 'categories');
|
||||
$term = Term::load(2);
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -2,14 +2,15 @@
|
|||
|
||||
namespace Drupal\Tests\migrate\Kernel;
|
||||
|
||||
use Drupal\entity_test\Entity\EntityTestMul;
|
||||
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;
|
||||
use Drupal\migrate\Row;
|
||||
use Drupal\migrate_entity_test\Entity\StringIdEntityTest;
|
||||
|
||||
/**
|
||||
* Tests the EntityContentBase destination.
|
||||
|
@ -44,6 +45,11 @@ class MigrateEntityContentBaseTest extends KernelTestBase {
|
|||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Enable two required fields with default values: a single-value field and
|
||||
// a multi-value field.
|
||||
\Drupal::state()->set('entity_test.required_default_field', TRUE);
|
||||
\Drupal::state()->set('entity_test.required_multi_default_field', TRUE);
|
||||
$this->installEntitySchema('entity_test_mul');
|
||||
|
||||
ConfigurableLanguage::createFromLangcode('en')->save();
|
||||
|
@ -190,7 +196,7 @@ class MigrateEntityContentBaseTest extends KernelTestBase {
|
|||
];
|
||||
|
||||
$migration = \Drupal::service('plugin.manager.migration')->createStubMigration($definition);
|
||||
$executable = new MigrateExecutable($migration, new MigrateMessage());
|
||||
$executable = new MigrateExecutable($migration);
|
||||
$result = $executable->import();
|
||||
$this->assertEquals(MigrationInterface::RESULT_COMPLETED, $result);
|
||||
|
||||
|
@ -204,4 +210,95 @@ class MigrateEntityContentBaseTest extends KernelTestBase {
|
|||
$this->assertEquals(123456789012, $map_row['destid1']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests empty destinations.
|
||||
*/
|
||||
public function testEmptyDestinations() {
|
||||
$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 an SQL exception.
|
||||
['id' => 123456789012, 'version' => 'bar'],
|
||||
],
|
||||
'ids' => [
|
||||
'id' => ['type' => 'integer', 'size' => 'big'],
|
||||
'version' => ['type' => 'string'],
|
||||
],
|
||||
'constants' => ['null' => NULL],
|
||||
],
|
||||
'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);
|
||||
$executable->import();
|
||||
|
||||
/** @var \Drupal\migrate_entity_test\Entity\StringIdEntityTest $entity */
|
||||
$entity = StringIdEntityTest::load('123');
|
||||
$this->assertSame('foo', $entity->version->value);
|
||||
$entity = StringIdEntityTest::load('123456789012');
|
||||
$this->assertSame('bar', $entity->version->value);
|
||||
|
||||
// Rerun the migration forcing the version to NULL.
|
||||
$definition['process'] = [
|
||||
'id' => 'id',
|
||||
'version' => 'constants/null',
|
||||
];
|
||||
|
||||
$migration = \Drupal::service('plugin.manager.migration')
|
||||
->createStubMigration($definition);
|
||||
$executable = new MigrateExecutable($migration);
|
||||
$executable->import();
|
||||
|
||||
/** @var \Drupal\migrate_entity_test\Entity\StringIdEntityTest $entity */
|
||||
$entity = StringIdEntityTest::load('123');
|
||||
$this->assertNull($entity->version->value);
|
||||
$entity = StringIdEntityTest::load('123456789012');
|
||||
$this->assertNull($entity->version->value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests stub rows.
|
||||
*/
|
||||
public function testStubRows() {
|
||||
// Create a destination.
|
||||
$this->createDestination([]);
|
||||
|
||||
// Import a stub row.
|
||||
$row = new Row([], [], TRUE);
|
||||
$row->setDestinationProperty('type', 'test');
|
||||
$ids = $this->destination->import($row);
|
||||
$this->assertCount(1, $ids);
|
||||
|
||||
// Make sure the entity was saved.
|
||||
$entity = EntityTestMul::load(reset($ids));
|
||||
$this->assertInstanceOf(EntityTestMul::class, $entity);
|
||||
// Make sure the default value was applied to the required fields.
|
||||
$single_field_name = 'required_default_field';
|
||||
$single_default_value = $entity->getFieldDefinition($single_field_name)->getDefaultValueLiteral();
|
||||
$this->assertSame($single_default_value, $entity->get($single_field_name)->getValue());
|
||||
|
||||
$multi_field_name = 'required_multi_default_field';
|
||||
$multi_default_value = $entity->getFieldDefinition($multi_field_name)->getDefaultValueLiteral();
|
||||
$count = 3;
|
||||
$this->assertCount($count, $multi_default_value);
|
||||
for ($i = 0; $i < $count; ++$i) {
|
||||
$this->assertSame($multi_default_value[$i], $entity->get($multi_field_name)->get($i)->getValue());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ use Drupal\migrate\Event\MigrateMapDeleteEvent;
|
|||
use Drupal\migrate\Event\MigrateMapSaveEvent;
|
||||
use Drupal\migrate\Event\MigratePostRowSaveEvent;
|
||||
use Drupal\migrate\Event\MigratePreRowSaveEvent;
|
||||
use Drupal\migrate\MigrateMessage;
|
||||
use Drupal\migrate\Event\MigrateEvents;
|
||||
use Drupal\migrate\MigrateExecutable;
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
|
@ -76,7 +75,7 @@ class MigrateEventsTest extends KernelTestBase {
|
|||
|
||||
$migration = \Drupal::service('plugin.manager.migration')->createStubMigration($definition);
|
||||
|
||||
$executable = new MigrateExecutable($migration, new MigrateMessage());
|
||||
$executable = new MigrateExecutable($migration);
|
||||
// As the import runs, events will be dispatched, recording the received
|
||||
// information in state.
|
||||
$executable->import();
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
namespace Drupal\Tests\migrate\Kernel;
|
||||
|
||||
use Drupal\migrate\Event\MigratePostRowSaveEvent;
|
||||
use Drupal\migrate\MigrateMessage;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate\Event\MigrateEvents;
|
||||
use Drupal\migrate\MigrateExecutable;
|
||||
|
@ -56,7 +55,7 @@ class MigrateInterruptionTest extends KernelTestBase {
|
|||
|
||||
$migration = \Drupal::service('plugin.manager.migration')->createStubMigration($definition);
|
||||
|
||||
$executable = new MigrateExecutable($migration, new MigrateMessage());
|
||||
$executable = new MigrateExecutable($migration);
|
||||
// When the import runs, the first row imported will trigger an
|
||||
// interruption.
|
||||
$result = $executable->import();
|
||||
|
|
|
@ -17,13 +17,14 @@ class MigrateRollbackEntityConfigTest extends MigrateTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['field', 'taxonomy', 'text', 'language', 'config_translation'];
|
||||
public static $modules = ['field', 'taxonomy', 'text', 'language', 'config_translation', 'user'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->installEntitySchema('user');
|
||||
$this->installEntitySchema('taxonomy_vocabulary');
|
||||
$this->installEntitySchema('taxonomy_term');
|
||||
$this->installConfig(['taxonomy']);
|
||||
|
@ -82,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 = [
|
||||
|
@ -105,7 +106,7 @@ class MigrateRollbackEntityConfigTest extends MigrateTestBase {
|
|||
'ids' => $ids,
|
||||
'constants' => [
|
||||
'name' => 'name',
|
||||
]
|
||||
],
|
||||
],
|
||||
'process' => [
|
||||
'vid' => 'id',
|
||||
|
|
|
@ -20,13 +20,14 @@ class MigrateRollbackTest extends MigrateTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['field', 'taxonomy', 'text'];
|
||||
public static $modules = ['field', 'taxonomy', 'text', 'user'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->installEntitySchema('user');
|
||||
$this->installEntitySchema('taxonomy_vocabulary');
|
||||
$this->installEntitySchema('taxonomy_term');
|
||||
$this->installConfig(['taxonomy']);
|
||||
|
@ -68,7 +69,7 @@ class MigrateRollbackTest extends MigrateTestBase {
|
|||
$vocabulary_executable = new MigrateExecutable($vocabulary_migration, $this);
|
||||
$vocabulary_executable->import();
|
||||
foreach ($vocabulary_data_rows as $row) {
|
||||
/** @var Vocabulary $vocabulary */
|
||||
/** @var \Drupal\taxonomy\Entity\Vocabulary $vocabulary */
|
||||
$vocabulary = Vocabulary::load($row['id']);
|
||||
$this->assertTrue($vocabulary);
|
||||
$map_row = $vocabulary_id_map->getRowBySource(['id' => $row['id']]);
|
||||
|
@ -121,7 +122,7 @@ class MigrateRollbackTest extends MigrateTestBase {
|
|||
$map_row['source_row_status'], MigrateIdMapInterface::ROLLBACK_PRESERVE);
|
||||
|
||||
foreach ($term_data_rows as $row) {
|
||||
/** @var Term $term */
|
||||
/** @var \Drupal\taxonomy\Entity\Term $term */
|
||||
$term = Term::load($row['id']);
|
||||
$this->assertTrue($term);
|
||||
$map_row = $term_id_map->getRowBySource(['id' => $row['id']]);
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
namespace Drupal\Tests\migrate\Kernel;
|
||||
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
use Drupal\migrate\MigrateMessage;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate\MigrateExecutable;
|
||||
use Drupal\migrate\Plugin\MigrateIdMapInterface;
|
||||
|
@ -50,7 +49,7 @@ class MigrateSkipRowTest extends KernelTestBase {
|
|||
|
||||
$migration = \Drupal::service('plugin.manager.migration')->createStubMigration($definition);
|
||||
|
||||
$executable = new MigrateExecutable($migration, new MigrateMessage());
|
||||
$executable = new MigrateExecutable($migration);
|
||||
$result = $executable->import();
|
||||
$this->assertEqual($result, MigrationInterface::RESULT_COMPLETED);
|
||||
|
||||
|
@ -85,7 +84,7 @@ class MigrateSkipRowTest extends KernelTestBase {
|
|||
];
|
||||
$migration = \Drupal::service('plugin.manager.migration')->createStubMigration($definition);
|
||||
|
||||
$executable = new MigrateExecutable($migration, new MigrateMessage());
|
||||
$executable = new MigrateExecutable($migration);
|
||||
$result = $executable->import();
|
||||
$this->assertEquals($result, MigrationInterface::RESULT_COMPLETED);
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ abstract class MigrateSourceTestBase extends KernelTestBase {
|
|||
/**
|
||||
* The mocked migration.
|
||||
*
|
||||
* @var MigrationInterface|\Prophecy\Prophecy\ObjectProphecy
|
||||
* @var \Drupal\migrate\Plugin\MigrationInterface|\Prophecy\Prophecy\ObjectProphecy
|
||||
*/
|
||||
protected $migration;
|
||||
|
||||
|
|
|
@ -39,7 +39,9 @@ abstract class MigrateSqlSourceTestBase extends MigrateSourceTestBase {
|
|||
->createTable($table, [
|
||||
// SQLite uses loose affinity typing, so it's OK for every field to
|
||||
// be a text field.
|
||||
'fields' => array_map(function() { return ['type' => 'text']; }, $pilot),
|
||||
'fields' => array_map(function () {
|
||||
return ['type' => 'text'];
|
||||
}, $pilot),
|
||||
]);
|
||||
|
||||
$fields = array_keys($pilot);
|
||||
|
|
|
@ -230,7 +230,9 @@ abstract class MigrateTestBase extends KernelTestBase implements MigrateMessageI
|
|||
$migration = $this->getMigration($migration);
|
||||
}
|
||||
/** @var \Drupal\migrate\Plugin\MigrationInterface $migration */
|
||||
$destination = array_map(function() { return NULL; }, $migration->getDestinationPlugin()->getIds());
|
||||
$destination = array_map(function () {
|
||||
return NULL;
|
||||
}, $migration->getDestinationPlugin()->getIds());
|
||||
$row = new Row($row, $migration->getSourcePlugin()->getIds());
|
||||
$migration->getIdMap()->saveIdMapping($row, $destination, $status);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate\Kernel;
|
||||
|
||||
use Drupal\comment\Entity\CommentType;
|
||||
use Drupal\node\Entity\NodeType;
|
||||
|
||||
/**
|
||||
* Provides methods for testing node and comment combinations.
|
||||
*/
|
||||
trait NodeCommentCombinationTrait {
|
||||
|
||||
/**
|
||||
* Creates a node type with a corresponding comment type.
|
||||
*
|
||||
* @param string $node_type
|
||||
* The node type ID.
|
||||
* @param string $comment_type
|
||||
* (optional) The comment type ID, if not provided defaults to
|
||||
* comment_node_{type}.
|
||||
*/
|
||||
protected function createNodeCommentCombination($node_type, $comment_type = NULL) {
|
||||
if (!$comment_type) {
|
||||
$comment_type = "comment_node_$node_type";
|
||||
}
|
||||
NodeType::create([
|
||||
'type' => $node_type,
|
||||
'label' => $this->randomString(),
|
||||
])->save();
|
||||
|
||||
CommentType::create([
|
||||
'id' => $comment_type,
|
||||
'label' => $this->randomString(),
|
||||
'target_entity_type_id' => 'node',
|
||||
])->save();
|
||||
}
|
||||
|
||||
}
|
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate\Kernel\Plugin;
|
||||
|
||||
use Drupal\Tests\migrate_drupal\Kernel\MigrateDrupalTestBase;
|
||||
|
||||
/**
|
||||
* Tests that migrations exist in the migration_templates directory.
|
||||
*
|
||||
* @group migrate
|
||||
* @group legacy
|
||||
*/
|
||||
class MigrationDirectoryTest extends MigrateDrupalTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['migration_directory_test'];
|
||||
|
||||
/**
|
||||
* Tests that migrations in the migration_templates directory are created.
|
||||
*
|
||||
* @expectedDeprecationMessage Use of the /migration_templates directory to store migration configuration files is deprecated in Drupal 8.1.0 and will be removed before Drupal 9.0.0.
|
||||
*/
|
||||
public function testMigrationDirectory() {
|
||||
/** @var \Drupal\migrate\Plugin\MigrationPluginManager $plugin_manager */
|
||||
$plugin_manager = $this->container->get('plugin.manager.migration');
|
||||
// Tests that a migration in directory 'migration_templates' is discovered.
|
||||
$this->assertTrue($plugin_manager->hasDefinition('migration_templates_test'));
|
||||
}
|
||||
|
||||
}
|
|
@ -7,6 +7,7 @@ use Drupal\KernelTests\KernelTestBase;
|
|||
use Drupal\migrate\Exception\RequirementsException;
|
||||
use Drupal\migrate\Plugin\migrate\source\SqlBase;
|
||||
use Drupal\migrate\Plugin\RequirementsInterface;
|
||||
use Drupal\Tests\field\Traits\EntityReferenceTestTrait;
|
||||
|
||||
/**
|
||||
* Tests the migration plugin manager.
|
||||
|
@ -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();
|
||||
|
@ -89,7 +99,9 @@ class MigrationPluginListTest extends KernelTestBase {
|
|||
// Any database-based source plugins should fail a requirements test in the
|
||||
// absence of a source database connection (e.g., a connection with the
|
||||
// 'migrate' key).
|
||||
$source_plugins = array_map(function ($migration_plugin) { return $migration_plugin->getSourcePlugin(); }, $migration_plugins);
|
||||
$source_plugins = array_map(function ($migration_plugin) {
|
||||
return $migration_plugin->getSourcePlugin();
|
||||
}, $migration_plugins);
|
||||
foreach ($source_plugins as $id => $source_plugin) {
|
||||
if ($source_plugin instanceof RequirementsInterface) {
|
||||
try {
|
||||
|
@ -129,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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,227 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate\Kernel\Plugin;
|
||||
|
||||
use Drupal\KernelTests\FileSystemModuleDiscoveryDataProviderTrait;
|
||||
use Drupal\migrate\Plugin\Exception\BadPluginDefinitionException;
|
||||
use Drupal\migrate_drupal\Plugin\MigrateFieldPluginManager;
|
||||
use Drupal\Tests\migrate_drupal\Kernel\MigrateDrupalTestBase;
|
||||
|
||||
/**
|
||||
* Tests that modules exist for all source and destination plugins.
|
||||
*
|
||||
* @group migrate_drupal_ui
|
||||
*/
|
||||
class MigrationProvidersExistTest extends MigrateDrupalTestBase {
|
||||
|
||||
use FileSystemModuleDiscoveryDataProviderTrait;
|
||||
|
||||
/**
|
||||
* Tests that a missing source_module property raises an exception.
|
||||
*/
|
||||
public function testSourceProvider() {
|
||||
$this->enableModules(['migration_provider_test']);
|
||||
$this->setExpectedException(BadPluginDefinitionException::class, 'The no_source_module plugin must define the source_module property.');
|
||||
$this->container->get('plugin.manager.migration')->getDefinition('migration_provider_no_annotation');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that modules exist for all source plugins.
|
||||
*/
|
||||
public function testProvidersExist() {
|
||||
$this->enableAllModules();
|
||||
|
||||
/** @var \Drupal\migrate\Plugin\MigrateSourcePluginManager $plugin_manager */
|
||||
$plugin_manager = $this->container->get('plugin.manager.migrate.source');
|
||||
|
||||
foreach ($plugin_manager->getDefinitions() as $definition) {
|
||||
$id = $definition['id'];
|
||||
$this->assertArrayHasKey('source_module', $definition, "No source_module property in '$id'");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable all available modules.
|
||||
*/
|
||||
protected function enableAllModules() {
|
||||
// Install all available modules.
|
||||
$module_handler = $this->container->get('module_handler');
|
||||
$modules = $this->coreModuleListDataProvider();
|
||||
$modules_enabled = $module_handler->getModuleList();
|
||||
$modules_to_enable = array_keys(array_diff_key($modules, $modules_enabled));
|
||||
$this->enableModules($modules_to_enable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that modules exist for all field plugins.
|
||||
*/
|
||||
public function testFieldProvidersExist() {
|
||||
$expected_mappings = [
|
||||
'userreference' => [
|
||||
'source_module' => 'userreference',
|
||||
'destination_module' => 'core',
|
||||
],
|
||||
'nodereference' => [
|
||||
'source_module' => 'nodereference',
|
||||
'destination_module' => 'core',
|
||||
],
|
||||
'optionwidgets' => [
|
||||
'source_module' => 'optionwidgets',
|
||||
'destination_module' => 'options',
|
||||
],
|
||||
'list' => [
|
||||
'source_module' => 'list',
|
||||
'destination_module' => 'options',
|
||||
],
|
||||
'options' => [
|
||||
'source_module' => 'options',
|
||||
'destination_module' => 'options',
|
||||
],
|
||||
'filefield' => [
|
||||
'source_module' => 'filefield',
|
||||
'destination_module' => 'file',
|
||||
],
|
||||
'imagefield' => [
|
||||
'source_module' => 'imagefield',
|
||||
'destination_module' => 'image',
|
||||
],
|
||||
'file' => [
|
||||
'source_module' => 'file',
|
||||
'destination_module' => 'file',
|
||||
],
|
||||
'image' => [
|
||||
'source_module' => 'image',
|
||||
'destination_module' => 'image',
|
||||
],
|
||||
'phone' => [
|
||||
'source_module' => 'phone',
|
||||
'destination_module' => 'telephone',
|
||||
],
|
||||
'link' => [
|
||||
'source_module' => 'link',
|
||||
'destination_module' => 'link',
|
||||
],
|
||||
'link_field' => [
|
||||
'source_module' => 'link',
|
||||
'destination_module' => 'link',
|
||||
],
|
||||
'd6_text' => [
|
||||
'source_module' => 'text',
|
||||
'destination_module' => 'text',
|
||||
],
|
||||
'd7_text' => [
|
||||
'source_module' => 'text',
|
||||
'destination_module' => 'text',
|
||||
],
|
||||
'taxonomy_term_reference' => [
|
||||
'source_module' => 'taxonomy',
|
||||
'destination_module' => 'core',
|
||||
],
|
||||
'date' => [
|
||||
'source_module' => 'date',
|
||||
'destination_module' => 'datetime',
|
||||
],
|
||||
'datetime' => [
|
||||
'source_module' => 'date',
|
||||
'destination_module' => 'datetime',
|
||||
],
|
||||
'email' => [
|
||||
'source_module' => 'email',
|
||||
'destination_module' => 'core',
|
||||
],
|
||||
'number_default' => [
|
||||
'source_module' => 'number',
|
||||
'destination_module' => 'core',
|
||||
],
|
||||
'entityreference' => [
|
||||
'source_module' => 'entityreference',
|
||||
'destination_module' => 'core',
|
||||
],
|
||||
];
|
||||
$this->enableAllModules();
|
||||
|
||||
$definitions = $this->container->get('plugin.manager.migrate.field')->getDefinitions();
|
||||
foreach ($definitions as $key => $definition) {
|
||||
$this->assertArrayHasKey($key, $expected_mappings);
|
||||
$this->assertEquals($expected_mappings[$key]['source_module'], $definition['source_module']);
|
||||
$this->assertEquals($expected_mappings[$key]['destination_module'], $definition['destination_module']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test a missing required definition.
|
||||
*
|
||||
* @param array $definitions
|
||||
* A field plugin definition.
|
||||
* @param string $missing_property
|
||||
* The name of the property missing from the definition.
|
||||
*
|
||||
* @dataProvider fieldPluginDefinitionsProvider
|
||||
*/
|
||||
public function testFieldProviderMissingRequiredProperty(array $definitions, $missing_property) {
|
||||
$discovery = $this->getMockBuilder(MigrateFieldPluginManager::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(['getDefinitions'])
|
||||
->getMock();
|
||||
$discovery->method('getDefinitions')
|
||||
->willReturn($definitions);
|
||||
|
||||
$plugin_manager = $this->getMockBuilder(MigrateFieldPluginManager::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(['getDiscovery'])
|
||||
->getMock();
|
||||
$plugin_manager->method('getDiscovery')
|
||||
->willReturn($discovery);
|
||||
|
||||
$this->setExpectedException(BadPluginDefinitionException::class, "The missing_{$missing_property} plugin must define the $missing_property property.");
|
||||
$plugin_manager->getDefinitions();
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for field plugin definitions.
|
||||
*
|
||||
* @return array
|
||||
* Array of plugin definitions.
|
||||
*/
|
||||
public function fieldPluginDefinitionsProvider() {
|
||||
return [
|
||||
'missing_core_scenario' => [
|
||||
'definitions' => [
|
||||
'missing_core' => [
|
||||
'source_module' => 'migrate',
|
||||
'destination_module' => 'migrate',
|
||||
'id' => 'missing_core',
|
||||
'class' => 'foo',
|
||||
'provider' => 'foo',
|
||||
],
|
||||
],
|
||||
'missing_property' => 'core',
|
||||
],
|
||||
'missing_source_scenario' => [
|
||||
'definitions' => [
|
||||
'missing_source_module' => [
|
||||
'core' => [6, 7],
|
||||
'destination_module' => 'migrate',
|
||||
'id' => 'missing_source_module',
|
||||
'class' => 'foo',
|
||||
'provider' => 'foo',
|
||||
],
|
||||
],
|
||||
'missing_property' => 'source_module',
|
||||
],
|
||||
'missing_destination_scenario' => [
|
||||
'definitions' => [
|
||||
'missing_destination_module' => [
|
||||
'core' => [6, 7],
|
||||
'source_module' => 'migrate',
|
||||
'id' => 'missing_destination_module',
|
||||
'class' => 'foo',
|
||||
'provider' => 'foo',
|
||||
],
|
||||
],
|
||||
'missing_property' => 'destination_module',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
|
@ -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,10 +52,10 @@ class MigrationTest extends KernelTestBase {
|
|||
'f1' => 'bar',
|
||||
'f2' => [
|
||||
'plugin' => 'migration',
|
||||
'migration' => 'm1'
|
||||
'migration' => 'm1',
|
||||
],
|
||||
'f3' => [
|
||||
'plugin' => 'iterator',
|
||||
'plugin' => 'sub_process',
|
||||
'process' => [
|
||||
'target_id' => [
|
||||
'plugin' => 'migration',
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ class QueryBatchTest extends KernelTestBase {
|
|||
/**
|
||||
* The mocked migration.
|
||||
*
|
||||
* @var MigrationInterface|\Prophecy\Prophecy\ObjectProphecy
|
||||
* @var \Drupal\migrate\Plugin\MigrationInterface|\Prophecy\Prophecy\ObjectProphecy
|
||||
*/
|
||||
protected $migration;
|
||||
|
||||
|
|
|
@ -7,8 +7,13 @@
|
|||
|
||||
namespace Drupal\Tests\migrate\Kernel;
|
||||
|
||||
use Drupal\migrate\Plugin\migrate\source\TestSqlBase;
|
||||
use Drupal\Core\Database\Query\ConditionInterface;
|
||||
use Drupal\Core\Database\Query\SelectInterface;
|
||||
use Drupal\Core\Database\StatementInterface;
|
||||
use Drupal\migrate\Exception\RequirementsException;
|
||||
use Drupal\Core\Database\Database;
|
||||
use Drupal\migrate\Plugin\migrate\source\SqlBase;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
|
||||
/**
|
||||
* Tests the functionality of SqlBase.
|
||||
|
@ -17,17 +22,47 @@ use Drupal\Core\Database\Database;
|
|||
*/
|
||||
class SqlBaseTest extends MigrateTestBase {
|
||||
|
||||
/**
|
||||
* The (probably mocked) migration under test.
|
||||
*
|
||||
* @var \Drupal\migrate\Plugin\MigrationInterface
|
||||
*/
|
||||
protected $migration;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->migration = $this->getMock(MigrationInterface::class);
|
||||
$this->migration->method('id')->willReturn('fubar');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests different connection types.
|
||||
*/
|
||||
public function testConnectionTypes() {
|
||||
$sql_base = new TestSqlBase();
|
||||
$sql_base = new TestSqlBase([], $this->migration);
|
||||
|
||||
// Check the default values.
|
||||
$sql_base->setConfiguration([]);
|
||||
$this->assertIdentical($sql_base->getDatabase()->getTarget(), 'default');
|
||||
$this->assertIdentical($sql_base->getDatabase()->getKey(), 'migrate');
|
||||
// Verify that falling back to the default 'migrate' connection (defined in
|
||||
// the base class) works.
|
||||
$this->assertSame('default', $sql_base->getDatabase()->getTarget());
|
||||
$this->assertSame('migrate', $sql_base->getDatabase()->getKey());
|
||||
|
||||
// Verify the fallback state key overrides the 'migrate' connection.
|
||||
$target = 'test_fallback_target';
|
||||
$key = 'test_fallback_key';
|
||||
$config = ['target' => $target, 'key' => $key];
|
||||
$database_state_key = 'test_fallback_state';
|
||||
\Drupal::state()->set($database_state_key, $config);
|
||||
\Drupal::state()->set('migrate.fallback_state_key', $database_state_key);
|
||||
// Create a test connection using the default database configuration.
|
||||
Database::addConnectionInfo($key, $target, Database::getConnectionInfo('default')['default']);
|
||||
$this->assertSame($sql_base->getDatabase()->getTarget(), $target);
|
||||
$this->assertSame($sql_base->getDatabase()->getKey(), $key);
|
||||
|
||||
// Verify that setting explicit connection information overrides fallbacks.
|
||||
$target = 'test_db_target';
|
||||
$key = 'test_migrate_connection';
|
||||
$config = ['target' => $target, 'key' => $key];
|
||||
|
@ -35,11 +70,11 @@ class SqlBaseTest extends MigrateTestBase {
|
|||
Database::addConnectionInfo($key, $target, Database::getConnectionInfo('default')['default']);
|
||||
|
||||
// Validate we have injected our custom key and target.
|
||||
$this->assertIdentical($sql_base->getDatabase()->getTarget(), $target);
|
||||
$this->assertIdentical($sql_base->getDatabase()->getKey(), $key);
|
||||
$this->assertSame($sql_base->getDatabase()->getTarget(), $target);
|
||||
$this->assertSame($sql_base->getDatabase()->getKey(), $key);
|
||||
|
||||
// Now test we can have SqlBase create the connection from an info array.
|
||||
$sql_base = new TestSqlBase();
|
||||
$sql_base = new TestSqlBase([], $this->migration);
|
||||
|
||||
$target = 'test_db_target2';
|
||||
$key = 'test_migrate_connection2';
|
||||
|
@ -51,7 +86,7 @@ class SqlBaseTest extends MigrateTestBase {
|
|||
$sql_base->getDatabase();
|
||||
|
||||
// Validate the connection has been created with the right values.
|
||||
$this->assertIdentical(Database::getConnectionInfo($key)[$target], $database);
|
||||
$this->assertSame(Database::getConnectionInfo($key)[$target], $database);
|
||||
|
||||
// Now, test this all works when using state to store db info.
|
||||
$target = 'test_state_db_target';
|
||||
|
@ -63,11 +98,11 @@ class SqlBaseTest extends MigrateTestBase {
|
|||
Database::addConnectionInfo($key, $target, Database::getConnectionInfo('default')['default']);
|
||||
|
||||
// Validate we have injected our custom key and target.
|
||||
$this->assertIdentical($sql_base->getDatabase()->getTarget(), $target);
|
||||
$this->assertIdentical($sql_base->getDatabase()->getKey(), $key);
|
||||
$this->assertSame($sql_base->getDatabase()->getTarget(), $target);
|
||||
$this->assertSame($sql_base->getDatabase()->getKey(), $key);
|
||||
|
||||
// Now test we can have SqlBase create the connection from an info array.
|
||||
$sql_base = new TestSqlBase();
|
||||
$sql_base = new TestSqlBase([], $this->migration);
|
||||
|
||||
$target = 'test_state_db_target2';
|
||||
$key = 'test_state_migrate_connection2';
|
||||
|
@ -81,13 +116,68 @@ class SqlBaseTest extends MigrateTestBase {
|
|||
$sql_base->getDatabase();
|
||||
|
||||
// Validate the connection has been created with the right values.
|
||||
$this->assertIdentical(Database::getConnectionInfo($key)[$target], $database);
|
||||
$this->assertSame(Database::getConnectionInfo($key)[$target], $database);
|
||||
|
||||
// Verify that falling back to 'migrate' when the connection is not defined
|
||||
// throws a RequirementsException.
|
||||
\Drupal::state()->delete('migrate.fallback_state_key');
|
||||
$sql_base->setConfiguration([]);
|
||||
Database::renameConnection('migrate', 'fallback_connection');
|
||||
$this->setExpectedException(RequirementsException::class,
|
||||
'No database connection configured for source plugin');
|
||||
$sql_base->getDatabase();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that SqlBase respects high-water values.
|
||||
*
|
||||
* @param mixed $high_water
|
||||
* (optional) The high-water value to set.
|
||||
* @param array $query_result
|
||||
* (optional) The expected query results.
|
||||
*
|
||||
* @dataProvider highWaterDataProvider
|
||||
*/
|
||||
public function testHighWater($high_water = NULL, array $query_result = []) {
|
||||
$configuration = [
|
||||
'high_water_property' => [
|
||||
'name' => 'order',
|
||||
],
|
||||
];
|
||||
$source = new TestSqlBase($configuration, $this->migration);
|
||||
|
||||
if ($high_water) {
|
||||
$source->getHighWaterStorage()->set($this->migration->id(), $high_water);
|
||||
}
|
||||
|
||||
$statement = $this->createMock(StatementInterface::class);
|
||||
$statement->expects($this->atLeastOnce())->method('setFetchMode')->with(\PDO::FETCH_ASSOC);
|
||||
$query = $this->createMock(SelectInterface::class);
|
||||
$query->method('execute')->willReturn($statement);
|
||||
$query->expects($this->atLeastOnce())->method('orderBy')->with('order', 'ASC');
|
||||
|
||||
$condition_group = $this->getMock(ConditionInterface::class);
|
||||
$query->method('orConditionGroup')->willReturn($condition_group);
|
||||
|
||||
$source->setQuery($query);
|
||||
$source->rewind();
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for ::testHighWater().
|
||||
*
|
||||
* @return array
|
||||
* The scenarios to test.
|
||||
*/
|
||||
public function highWaterDataProvider() {
|
||||
return [
|
||||
'no high-water value set' => [],
|
||||
'high-water value set' => [33],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace Drupal\migrate\Plugin\migrate\source;
|
||||
|
||||
/**
|
||||
* A dummy source to help with testing SqlBase.
|
||||
*
|
||||
|
@ -96,10 +186,22 @@ namespace Drupal\migrate\Plugin\migrate\source;
|
|||
class TestSqlBase extends SqlBase {
|
||||
|
||||
/**
|
||||
* Overrides the constructor so we can create one easily.
|
||||
* The query to execute.
|
||||
*
|
||||
* @var \Drupal\Core\Database\Query\SelectInterface
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->state = \Drupal::state();
|
||||
protected $query;
|
||||
|
||||
/**
|
||||
* Overrides the constructor so we can create one easily.
|
||||
*
|
||||
* @param array $configuration
|
||||
* The plugin instance configuration.
|
||||
* @param \Drupal\migrate\Plugin\MigrationInterface $migration
|
||||
* (optional) The migration being run.
|
||||
*/
|
||||
public function __construct(array $configuration = [], MigrationInterface $migration = NULL) {
|
||||
parent::__construct($configuration, 'sql_base', [], $migration, \Drupal::state());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -133,6 +235,25 @@ class TestSqlBase extends SqlBase {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function query() {}
|
||||
public function query() {
|
||||
return $this->query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the query to execute.
|
||||
*
|
||||
* @param \Drupal\Core\Database\Query\SelectInterface $query
|
||||
* The query to execute.
|
||||
*/
|
||||
public function setQuery(SelectInterface $query) {
|
||||
$this->query = $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getHighWaterStorage() {
|
||||
return parent::getHighWaterStorage();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@ 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.
|
||||
|
@ -52,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');
|
||||
}
|
||||
|
@ -100,14 +99,8 @@ class DownloadTest extends FileTestBase {
|
|||
* 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.
|
||||
|
|
|
@ -4,7 +4,6 @@ namespace Drupal\Tests\migrate\Kernel\process;
|
|||
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
use Drupal\migrate\MigrateExecutable;
|
||||
use Drupal\migrate\MigrateMessage;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
|
||||
/**
|
||||
|
@ -66,7 +65,7 @@ class ExtractTest extends KernelTestBase {
|
|||
|
||||
$migration = \Drupal::service('plugin.manager.migration')->createStubMigration($definition);
|
||||
|
||||
$executable = new MigrateExecutable($migration, new MigrateMessage());
|
||||
$executable = new MigrateExecutable($migration);
|
||||
$result = $executable->import();
|
||||
|
||||
// Migration needs to succeed before further assertions are made.
|
||||
|
|
|
@ -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([], []);
|
||||
|
|
|
@ -4,7 +4,6 @@ namespace Drupal\Tests\migrate\Kernel\process;
|
|||
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
use Drupal\migrate\MigrateExecutable;
|
||||
use Drupal\migrate\MigrateMessage;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
|
||||
/**
|
||||
|
@ -94,7 +93,7 @@ class HandleMultiplesTest extends KernelTestBase {
|
|||
|
||||
$migration = \Drupal::service('plugin.manager.migration')->createStubMigration($definition);
|
||||
|
||||
$executable = new MigrateExecutable($migration, new MigrateMessage());
|
||||
$executable = new MigrateExecutable($migration);
|
||||
$result = $executable->import();
|
||||
|
||||
// Migration needs to succeed before further assertions are made.
|
||||
|
|
|
@ -3,12 +3,13 @@
|
|||
namespace Drupal\Tests\migrate\Unit\Event;
|
||||
|
||||
use Drupal\migrate\Event\EventBase;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\migrate\Event\EventBase
|
||||
* @group migrate
|
||||
*/
|
||||
class EventBaseTest extends \PHPUnit_Framework_TestCase {
|
||||
class EventBaseTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* Test getMigration method.
|
||||
|
|
|
@ -3,12 +3,13 @@
|
|||
namespace Drupal\Tests\migrate\Unit\Event;
|
||||
|
||||
use Drupal\migrate\Event\MigrateImportEvent;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\migrate\Event\MigrateImportEvent
|
||||
* @group migrate
|
||||
*/
|
||||
class MigrateImportEventTest extends \PHPUnit_Framework_TestCase {
|
||||
class MigrateImportEventTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* Test getMigration method.
|
||||
|
|
|
@ -7,7 +7,7 @@ use Drupal\Tests\UnitTestCase;
|
|||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\migrate\Exception\RequirementsException
|
||||
* @group migration
|
||||
* @group migrate
|
||||
*/
|
||||
class RequirementsExceptionTest extends UnitTestCase {
|
||||
|
||||
|
|
|
@ -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');
|
||||
|
@ -439,6 +439,33 @@ class MigrateExecutableTest extends MigrateTestCase {
|
|||
$this->executable->processRow($row);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the processRow method.
|
||||
*/
|
||||
public function testProcessRowEmptyDestination() {
|
||||
$expected = [
|
||||
'test' => 'test destination',
|
||||
'test1' => 'test1 destination',
|
||||
'test2' => NULL,
|
||||
];
|
||||
$row = new Row();
|
||||
$plugins = [];
|
||||
foreach ($expected as $key => $value) {
|
||||
$plugin = $this->prophesize(MigrateProcessInterface::class);
|
||||
$plugin->getPluginDefinition()->willReturn([]);
|
||||
$plugin->transform(NULL, $this->executable, $row, $key)->willReturn($value);
|
||||
$plugin->multiple()->willReturn(TRUE);
|
||||
$plugins[$key][0] = $plugin->reveal();
|
||||
}
|
||||
$this->migration->method('getProcessPlugins')->willReturn($plugins);
|
||||
$this->executable->processRow($row);
|
||||
foreach ($expected as $key => $value) {
|
||||
$this->assertSame($value, $row->getDestinationProperty($key));
|
||||
}
|
||||
$this->assertCount(2, $row->getDestination());
|
||||
$this->assertSame(['test2'], $row->getEmptyDestinationProperties());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a mock migration source instance.
|
||||
*
|
||||
|
|
|
@ -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);
|
||||
|
@ -211,10 +211,10 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
|
|||
}
|
||||
|
||||
// Truncate and check that 4 messages were deleted.
|
||||
$this->assertEquals($id_map->messageCount(), 4);
|
||||
$this->assertSame($id_map->messageCount(), 4);
|
||||
$id_map->clearMessages();
|
||||
$count = $id_map->messageCount();
|
||||
$this->assertEquals($count, 0);
|
||||
$this->assertSame($count, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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,
|
||||
|
@ -284,7 +284,7 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
|
|||
// Test count message multiple times starting from 0.
|
||||
foreach ($expected_results as $key => $expected_result) {
|
||||
$count = $id_map->messageCount();
|
||||
$this->assertEquals($expected_result, $count);
|
||||
$this->assertSame($expected_result, $count);
|
||||
$id_map->saveMessage(['source_id_property' => $key], $message);
|
||||
}
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
|
@ -684,21 +686,21 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
|
|||
$row = new Row($source, ['source_id_property' => []]);
|
||||
$destination = ['destination_id_property' => 'destination_value_failed'];
|
||||
$id_map->saveIdMapping($row, $destination, MigrateIdMapInterface::STATUS_FAILED);
|
||||
$this->assertSame(0, (int) $id_map->importedCount());
|
||||
$this->assertSame(0, $id_map->importedCount());
|
||||
|
||||
// Add an imported row and assert single count.
|
||||
$source = ['source_id_property' => 'source_value_imported'];
|
||||
$row = new Row($source, ['source_id_property' => []]);
|
||||
$destination = ['destination_id_property' => 'destination_value_imported'];
|
||||
$id_map->saveIdMapping($row, $destination, MigrateIdMapInterface::STATUS_IMPORTED);
|
||||
$this->assertSame(1, (int) $id_map->importedCount());
|
||||
$this->assertSame(1, $id_map->importedCount());
|
||||
|
||||
// Add a row needing update and assert multiple imported rows.
|
||||
$source = ['source_id_property' => 'source_value_update'];
|
||||
$row = new Row($source, ['source_id_property' => []]);
|
||||
$destination = ['destination_id_property' => 'destination_value_update'];
|
||||
$id_map->saveIdMapping($row, $destination, MigrateIdMapInterface::STATUS_NEEDS_UPDATE);
|
||||
$this->assertSame(2, (int) $id_map->importedCount());
|
||||
$this->assertSame(2, $id_map->importedCount());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -712,7 +714,7 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
|
|||
public function testProcessedCount() {
|
||||
$id_map = $this->getIdMap();
|
||||
// Assert zero rows have been processed before adding rows.
|
||||
$this->assertSame(0, (int) $id_map->processedCount());
|
||||
$this->assertSame(0, $id_map->processedCount());
|
||||
$row_statuses = [
|
||||
MigrateIdMapInterface::STATUS_IMPORTED,
|
||||
MigrateIdMapInterface::STATUS_NEEDS_UPDATE,
|
||||
|
@ -727,11 +729,11 @@ class MigrateSqlIdMapTest extends MigrateTestCase {
|
|||
$id_map->saveIdMapping($row, $destination, $status);
|
||||
if ($status == MigrateIdMapInterface::STATUS_IMPORTED) {
|
||||
// Assert a single row has been processed.
|
||||
$this->assertSame(1, (int) $id_map->processedCount());
|
||||
$this->assertSame(1, $id_map->processedCount());
|
||||
}
|
||||
}
|
||||
// Assert multiple rows have been processed.
|
||||
$this->assertSame(count($row_statuses), (int) $id_map->processedCount());
|
||||
$this->assertSame(count($row_statuses), $id_map->processedCount());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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,13 +775,13 @@ 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);
|
||||
}
|
||||
$id_map = $this->getIdMap();
|
||||
$this->assertSame($num_update_rows, (int) $id_map->updateCount());
|
||||
$this->assertSame($num_update_rows, $id_map->updateCount());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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,13 +823,13 @@ 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);
|
||||
}
|
||||
|
||||
$this->assertSame($num_error_rows, (int) $this->getIdMap()->errorCount());
|
||||
$this->assertSame($num_error_rows, $this->getIdMap()->errorCount());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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;
|
||||
|
||||
|
@ -61,12 +61,12 @@ abstract class MigrateTestCase extends UnitTestCase {
|
|||
// on the test class and use a return callback.
|
||||
$migration->expects($this->any())
|
||||
->method('getStatus')
|
||||
->willReturnCallback(function() {
|
||||
->willReturnCallback(function () {
|
||||
return $this->migrationStatus;
|
||||
});
|
||||
$migration->expects($this->any())
|
||||
->method('setStatus')
|
||||
->willReturnCallback(function($status) {
|
||||
->willReturnCallback(function ($status) {
|
||||
$this->migrationStatus = $status;
|
||||
});
|
||||
|
||||
|
@ -78,11 +78,6 @@ abstract class MigrateTestCase extends UnitTestCase {
|
|||
|
||||
$configuration = &$this->migrationConfiguration;
|
||||
|
||||
$migration->method('getHighWaterProperty')
|
||||
->willReturnCallback(function () use ($configuration) {
|
||||
return isset($configuration['high_water_property']) ? $configuration['high_water_property'] : '';
|
||||
});
|
||||
|
||||
$migration->method('set')
|
||||
->willReturnCallback(function ($argument, $value) use (&$configuration) {
|
||||
$configuration[$argument] = $value;
|
||||
|
@ -147,7 +142,9 @@ abstract class MigrateTestCase extends UnitTestCase {
|
|||
protected function createSchemaFromRow(array $row) {
|
||||
// SQLite uses loose ("affinity") typing, so it is OK for every column to be
|
||||
// a text field.
|
||||
$fields = array_map(function() { return ['type' => 'text']; }, $row);
|
||||
$fields = array_map(function () {
|
||||
return ['type' => 'text'];
|
||||
}, $row);
|
||||
return ['fields' => $fields];
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ class MigrationPluginManagerTest extends UnitTestCase {
|
|||
/**
|
||||
* A plugin manager.
|
||||
*
|
||||
* @param \Drupal\migrate\Plugin\MigrationPluginManager $pluginManager
|
||||
* @var \Drupal\migrate\Plugin\MigrationPluginManager
|
||||
*/
|
||||
protected $pluginManager;
|
||||
|
||||
|
@ -183,7 +183,7 @@ class TestMigrationMock extends Migration {
|
|||
/**
|
||||
* The values passed into set().
|
||||
*
|
||||
* @var array $set
|
||||
* @var array
|
||||
*/
|
||||
public $set = [];
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ use Drupal\Tests\UnitTestCase;
|
|||
/**
|
||||
* @coversDefaultClass \Drupal\migrate\Plugin\Migration
|
||||
*
|
||||
* @group Migration
|
||||
* @group migrate
|
||||
*/
|
||||
class MigrationTest extends UnitTestCase {
|
||||
|
||||
|
|
|
@ -8,17 +8,11 @@
|
|||
namespace Drupal\Tests\migrate\Unit\Plugin\migrate\destination;
|
||||
|
||||
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\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,33 +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\EntityManagerInterface
|
||||
*/
|
||||
protected $entityManager;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->migration = $this->prophesize(MigrationInterface::class);
|
||||
$this->storage = $this->prophesize(EntityStorageInterface::class);
|
||||
$this->entityManager = $this->prophesize(EntityManagerInterface::class);
|
||||
}
|
||||
class EntityContentBaseTest extends EntityTestBase {
|
||||
|
||||
/**
|
||||
* Test basic entity save.
|
||||
|
@ -104,16 +72,13 @@ class EntityContentBaseTest extends UnitTestCase {
|
|||
*/
|
||||
public function testUntranslatable() {
|
||||
// An entity type without a language.
|
||||
$entity_type = $this->prophesize(ContentEntityType::class);
|
||||
$entity_type->getKey('langcode')->willReturn('');
|
||||
$entity_type->getKey('id')->willReturn('id');
|
||||
$this->entityType->getKey('langcode')->willReturn('');
|
||||
$this->entityType->getKey('id')->willReturn('id');
|
||||
$this->entityManager->getBaseFieldDefinitions('foo')
|
||||
->willReturn(['id' => BaseFieldDefinitionTest::create('integer')]);
|
||||
|
||||
$this->storage->getEntityType()->willReturn($entity_type->reveal());
|
||||
|
||||
$destination = new EntityTestDestination(
|
||||
[ 'translations' => TRUE ],
|
||||
['translations' => TRUE],
|
||||
'',
|
||||
[],
|
||||
$this->migration->reveal(),
|
||||
|
@ -122,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();
|
||||
}
|
||||
|
||||
|
@ -150,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';
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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';
|
||||
}
|
||||
|
||||
}
|
|
@ -9,6 +9,7 @@ namespace Drupal\Tests\migrate\Unit\destination;
|
|||
|
||||
use Drupal\Core\Entity\ContentEntityInterface;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate\Plugin\migrate\destination\EntityRevision as RealEntityRevision;
|
||||
use Drupal\migrate\Row;
|
||||
|
@ -48,6 +49,12 @@ class EntityRevisionTest extends UnitTestCase {
|
|||
// Setup mocks to be used when creating a revision destination.
|
||||
$this->migration = $this->prophesize(MigrationInterface::class);
|
||||
$this->storage = $this->prophesize('\Drupal\Core\Entity\EntityStorageInterface');
|
||||
|
||||
$entity_type = $this->prophesize(EntityTypeInterface::class);
|
||||
$entity_type->getSingularLabel()->willReturn('crazy');
|
||||
$entity_type->getPluralLabel()->willReturn('craziness');
|
||||
$this->storage->getEntityType()->willReturn($entity_type->reveal());
|
||||
|
||||
$this->entityManager = $this->prophesize('\Drupal\Core\Entity\EntityManagerInterface');
|
||||
$this->fieldTypeManager = $this->prophesize('\Drupal\Core\Field\FieldTypePluginManagerInterface');
|
||||
}
|
||||
|
@ -169,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.
|
||||
*
|
||||
|
@ -223,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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -44,8 +44,8 @@ class PerComponentEntityDisplayTest extends MigrateTestCase {
|
|||
->method('save')
|
||||
->with();
|
||||
$plugin = new TestPerComponentEntityDisplay($entity);
|
||||
$this->assertSame($plugin->import($row), ['entity_type_test', 'bundle_test', 'view_mode_test', 'field_name_test']);
|
||||
$this->assertSame($plugin->getTestValues(), ['entity_type_test', 'bundle_test', 'view_mode_test']);
|
||||
$this->assertSame(['entity_type_test', 'bundle_test', 'view_mode_test', 'field_name_test'], $plugin->import($row));
|
||||
$this->assertSame(['entity_type_test', 'bundle_test', 'view_mode_test'], $plugin->getTestValues());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -44,8 +44,8 @@ class PerComponentEntityFormDisplayTest extends MigrateTestCase {
|
|||
->method('save')
|
||||
->with();
|
||||
$plugin = new TestPerComponentEntityFormDisplay($entity);
|
||||
$this->assertSame($plugin->import($row), ['entity_type_test', 'bundle_test', 'form_mode_test', 'field_name_test']);
|
||||
$this->assertSame($plugin->getTestValues(), ['entity_type_test', 'bundle_test', 'form_mode_test']);
|
||||
$this->assertSame(['entity_type_test', 'bundle_test', 'form_mode_test', 'field_name_test'], $plugin->import($row));
|
||||
$this->assertSame(['entity_type_test', 'bundle_test', 'form_mode_test'], $plugin->getTestValues());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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();
|
||||
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 function as callable.
|
||||
* Data provider for ::testCallback().
|
||||
*/
|
||||
public function testCallbackWithFunction() {
|
||||
$this->plugin->setCallable('strtolower');
|
||||
$value = $this->plugin->transform('FooBar', $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame($value, 'foobar');
|
||||
public function providerCallback() {
|
||||
return [
|
||||
'function' => ['strtolower'],
|
||||
'class method' => [[self::class, 'strtolower']],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test callback with a class method as callable.
|
||||
* Test callback exceptions.
|
||||
*
|
||||
* @dataProvider providerCallbackExceptions
|
||||
*/
|
||||
public function testCallbackWithClassMethod() {
|
||||
$this->plugin->setCallable(['\Drupal\Component\Utility\Unicode', 'strtolower']);
|
||||
$value = $this->plugin->transform('FooBar', $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame($value, 'foobar');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class TestCallback extends Callback {
|
||||
public function __construct() {
|
||||
}
|
||||
|
||||
public function setCallable($callable) {
|
||||
$this->configuration['callable'] = $callable;
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ class ConcatTest extends MigrateProcessTestCase {
|
|||
*/
|
||||
public function testConcatWithoutDelimiter() {
|
||||
$value = $this->plugin->transform(['foo', 'bar'], $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame($value, 'foobar');
|
||||
$this->assertSame('foobar', $value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -47,12 +47,13 @@ class ConcatTest extends MigrateProcessTestCase {
|
|||
public function testConcatWithDelimiter() {
|
||||
$this->plugin->setDelimiter('_');
|
||||
$value = $this->plugin->transform(['foo', 'bar'], $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame($value, 'foo_bar');
|
||||
$this->assertSame('foo_bar', $value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class TestConcat extends Concat {
|
||||
|
||||
public function __construct() {
|
||||
}
|
||||
|
||||
|
|
|
@ -2,18 +2,15 @@
|
|||
|
||||
namespace Drupal\Tests\migrate\Unit\process;
|
||||
|
||||
@trigger_error('The ' . __NAMESPACE__ . '\DedupeEntityTest is deprecated in
|
||||
Drupal 8.4.0 and will be removed before Drupal 9.0.0. Instead, use ' . __NAMESPACE__ . '\MakeUniqueEntityFieldTest', E_USER_DEPRECATED);
|
||||
|
||||
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
|
||||
* @group migrate
|
||||
* @group legacy
|
||||
*/
|
||||
class DedupeEntityTest extends MigrateProcessTestCase {
|
||||
|
||||
|
@ -21,7 +18,6 @@ class DedupeEntityTest extends MigrateProcessTestCase {
|
|||
* The mock entity query.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\Query\QueryInterface
|
||||
* @var \Drupal\Core\Entity\Query\QueryFactory
|
||||
*/
|
||||
protected $entityQuery;
|
||||
|
||||
|
@ -80,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);
|
||||
}
|
||||
|
@ -168,7 +164,9 @@ class DedupeEntityTest extends MigrateProcessTestCase {
|
|||
->will($this->returnValue($this->entityQuery));
|
||||
$this->entityQuery->expects($this->exactly($count + 1))
|
||||
->method('execute')
|
||||
->will($this->returnCallback(function () use (&$count) { return $count--;}));
|
||||
->will($this->returnCallback(function () use (&$count) {
|
||||
return $count--;
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -199,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]],
|
||||
|
|
|
@ -29,7 +29,7 @@ class ExplodeTest extends MigrateProcessTestCase {
|
|||
*/
|
||||
public function testTransform() {
|
||||
$value = $this->plugin->transform('foo,bar,tik', $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame($value, ['foo', 'bar', 'tik']);
|
||||
$this->assertSame(['foo', 'bar', 'tik'], $value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -38,7 +38,7 @@ class ExplodeTest extends MigrateProcessTestCase {
|
|||
public function testTransformLimit() {
|
||||
$plugin = new Explode(['delimiter' => '_', 'limit' => 2], 'map', []);
|
||||
$value = $plugin->transform('foo_bar_tik', $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame($value, ['foo', 'bar_tik']);
|
||||
$this->assertSame(['foo', 'bar_tik'], $value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -49,7 +49,7 @@ class ExplodeTest extends MigrateProcessTestCase {
|
|||
|
||||
$concat = new Concat([], 'map', []);
|
||||
$concatenated = $concat->transform($exploded, $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame($concatenated, 'foobartik');
|
||||
$this->assertSame('foobartik', $concatenated);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -25,7 +25,7 @@ class ExtractTest extends MigrateProcessTestCase {
|
|||
*/
|
||||
public function testExtract() {
|
||||
$value = $this->plugin->transform(['foo' => 'bar'], $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame($value, 'bar');
|
||||
$this->assertSame('bar', $value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -50,7 +50,7 @@ class ExtractTest extends MigrateProcessTestCase {
|
|||
public function testExtractFailDefault() {
|
||||
$plugin = new Extract(['index' => ['foo'], 'default' => 'test'], 'map', []);
|
||||
$value = $plugin->transform(['bar' => 'foo'], $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame($value, 'test', '');
|
||||
$this->assertSame('test', $value, '');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
149
web/core/modules/migrate/tests/src/Unit/process/FileCopyTest.php
Normal file
149
web/core/modules/migrate/tests/src/Unit/process/FileCopyTest.php
Normal file
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,8 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate\Unit\process;
|
||||
use Drupal\migrate\Plugin\migrate\process\Flatten;
|
||||
|
||||
use Drupal\migrate\Plugin\migrate\process\Flatten;
|
||||
|
||||
/**
|
||||
* Tests the flatten plugin.
|
||||
|
@ -17,7 +17,7 @@ class FlattenTest extends MigrateProcessTestCase {
|
|||
public function testFlatten() {
|
||||
$plugin = new Flatten([], 'flatten', []);
|
||||
$flattened = $plugin->transform([1, 2, [3, 4, [5]], [], [7, 8]], $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame($flattened, [1, 2, 3, 4, 5, 7, 8]);
|
||||
$this->assertSame([1, 2, 3, 4, 5, 7, 8], $flattened);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -56,6 +56,40 @@ class FormatDateTest extends MigrateProcessTestCase {
|
|||
$this->plugin->transform('January 5, 1955', $this->migrateExecutable, $this->row, 'field_date');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that "timezone" configuration key triggers deprecation error.
|
||||
*
|
||||
* @covers ::transform
|
||||
*
|
||||
* @dataProvider providerTestDeprecatedTimezoneConfigurationKey
|
||||
*
|
||||
* @group legacy
|
||||
* @expectedDeprecation Configuration key "timezone" is deprecated in 8.4.x and will be removed before Drupal 9.0.0, use "from_timezone" and "to_timezone" instead. See https://www.drupal.org/node/2885746
|
||||
*/
|
||||
public function testDeprecatedTimezoneConfigurationKey($configuration, $value, $expected) {
|
||||
$this->plugin = new FormatDate($configuration, 'test_format_date', []);
|
||||
$actual = $this->plugin->transform($value, $this->migrateExecutable, $this->row, 'field_date');
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testDeprecatedTimezoneConfigurationKey.
|
||||
*/
|
||||
public function providerTestDeprecatedTimezoneConfigurationKey() {
|
||||
return [
|
||||
[
|
||||
'configuration' => [
|
||||
'from_format' => 'Y-m-d\TH:i:sO',
|
||||
'to_format' => 'c e',
|
||||
'timezone' => 'America/Managua',
|
||||
],
|
||||
'value' => '2004-12-19T10:19:42-0600',
|
||||
'expected' => '2004-12-19T10:19:42-06:00 -06:00',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests transformation.
|
||||
*
|
||||
|
@ -96,10 +130,10 @@ class FormatDateTest extends MigrateProcessTestCase {
|
|||
'datetime_datetime' => [
|
||||
'configuration' => [
|
||||
'from_format' => 'm/d/Y H:i:s',
|
||||
'to_format' => 'Y-m-d\TH:i:s',
|
||||
'to_format' => 'Y-m-d\TH:i:s e',
|
||||
],
|
||||
'value' => '01/05/1955 10:43:22',
|
||||
'expected' => '1955-01-05T10:43:22',
|
||||
'expected' => '1955-01-05T10:43:22 Australia/Sydney',
|
||||
],
|
||||
'empty_values' => [
|
||||
'configuration' => [
|
||||
|
@ -109,14 +143,37 @@ class FormatDateTest extends MigrateProcessTestCase {
|
|||
'value' => '',
|
||||
'expected' => '',
|
||||
],
|
||||
'timezone' => [
|
||||
'timezone_from_to' => [
|
||||
'configuration' => [
|
||||
'from_format' => 'Y-m-d\TH:i:sO',
|
||||
'to_format' => 'Y-m-d\TH:i:s',
|
||||
'timezone' => 'America/Managua',
|
||||
'from_format' => 'Y-m-d H:i:s',
|
||||
'to_format' => 'Y-m-d H:i:s e',
|
||||
'from_timezone' => 'America/Managua',
|
||||
'to_timezone' => 'UTC',
|
||||
],
|
||||
'value' => '2004-12-19T10:19:42-0600',
|
||||
'expected' => '2004-12-19T10:19:42',
|
||||
'value' => '2004-12-19 10:19:42',
|
||||
'expected' => '2004-12-19 16:19:42 UTC',
|
||||
],
|
||||
'timezone_from' => [
|
||||
'configuration' => [
|
||||
'from_format' => 'Y-m-d h:i:s',
|
||||
'to_format' => 'Y-m-d h:i:s e',
|
||||
'from_timezone' => 'America/Managua',
|
||||
],
|
||||
'value' => '2004-11-19 10:25:33',
|
||||
// Unit tests use Australia/Sydney timezone, so date value will be
|
||||
// converted from America/Managua to Australia/Sydney timezone.
|
||||
'expected' => '2004-11-20 03:25:33 Australia/Sydney',
|
||||
],
|
||||
'timezone_to' => [
|
||||
'configuration' => [
|
||||
'from_format' => 'Y-m-d H:i:s',
|
||||
'to_format' => 'Y-m-d H:i:s e',
|
||||
'to_timezone' => 'America/Managua',
|
||||
],
|
||||
'value' => '2004-12-19 10:19:42',
|
||||
// Unit tests use Australia/Sydney timezone, so date value will be
|
||||
// converted from Australia/Sydney to America/Managua timezone.
|
||||
'expected' => '2004-12-18 17:19:42 America/Managua',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
|
|
@ -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,9 +19,9 @@ 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($value, 'source_value');
|
||||
$this->assertSame('source_value', $value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -45,12 +32,14 @@ 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) { return $map[$argument]; } ));
|
||||
->will($this->returnCallback(function ($argument) use ($map) {
|
||||
return $map[$argument];
|
||||
}));
|
||||
$value = $this->plugin->transform(NULL, $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame($value, ['source_value1', 'source_value2']);
|
||||
$this->assertSame(['source_value1', 'source_value2'], $value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -61,9 +50,9 @@ 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($value, 'source_value');
|
||||
$this->assertSame('source_value', $value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -76,44 +65,59 @@ 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) { return $map[$argument]; } ));
|
||||
->will($this->returnCallback(function ($argument) use ($map) {
|
||||
return $map[$argument];
|
||||
}));
|
||||
$value = $this->plugin->transform(NULL, $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame($value, ['source_value1', 'source_value2', 'source_value3', 'source_value4']);
|
||||
$this->assertSame(['source_value1', 'source_value2', 'source_value3', 'source_value4'], $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
|
@ -31,6 +31,9 @@ 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();
|
||||
|
@ -73,10 +76,10 @@ class IteratorTest extends MigrateTestCase {
|
|||
// values ended up in the proper destinations, and that the value of the
|
||||
// key (@id) is the same as the destination ID (42).
|
||||
$new_value = $plugin->transform($current_value, $migrate_executable, $row, 'test');
|
||||
$this->assertSame(count($new_value), 1);
|
||||
$this->assertSame(count($new_value[42]), 2);
|
||||
$this->assertSame($new_value[42]['foo'], 'test');
|
||||
$this->assertSame($new_value[42]['id'], 42);
|
||||
$this->assertSame(1, count($new_value));
|
||||
$this->assertSame(2, count($new_value[42]));
|
||||
$this->assertSame('test', $new_value[42]['foo']);
|
||||
$this->assertSame(42, $new_value[42]['id']);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
@ -18,7 +17,6 @@ class MakeUniqueEntityFieldTest extends MigrateProcessTestCase {
|
|||
* The mock entity query.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\Query\QueryInterface
|
||||
* @var \Drupal\Core\Entity\Query\QueryFactory
|
||||
*/
|
||||
protected $entityQuery;
|
||||
|
||||
|
@ -77,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);
|
||||
}
|
||||
|
@ -165,7 +163,9 @@ class MakeUniqueEntityFieldTest extends MigrateProcessTestCase {
|
|||
->will($this->returnValue($this->entityQuery));
|
||||
$this->entityQuery->expects($this->exactly($count + 1))
|
||||
->method('execute')
|
||||
->will($this->returnCallback(function () use (&$count) { return $count--;}));
|
||||
->will($this->returnCallback(function () use (&$count) {
|
||||
return $count--;
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -196,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;
|
||||
|
@ -11,6 +12,7 @@ use Drupal\migrate\Plugin\MigrateIdMapInterface;
|
|||
use Drupal\migrate\Plugin\MigratePluginManager;
|
||||
use Drupal\migrate\Plugin\MigrateSourceInterface;
|
||||
use Drupal\migrate\Plugin\MigrationPluginManagerInterface;
|
||||
use Drupal\migrate\Row;
|
||||
use Prophecy\Argument;
|
||||
|
||||
/**
|
||||
|
@ -100,6 +102,8 @@ class MigrationLookupTest extends MigrateProcessTestCase {
|
|||
'migration' => 'foobaz',
|
||||
];
|
||||
$migration_plugin->id()->willReturn(uniqid());
|
||||
$migration_plugin_manager->createInstances(['foobaz'])
|
||||
->willReturn(['foobaz' => $migration_plugin->reveal()]);
|
||||
$migration = new MigrationLookup($configuration, 'migration_lookup', [], $migration_plugin->reveal(), $migration_plugin_manager->reveal(), $process_plugin_manager->reveal());
|
||||
$this->setExpectedException(MigrateSkipProcessException::class);
|
||||
$migration->transform(0, $this->migrateExecutable, $this->row, 'foo');
|
||||
|
@ -199,4 +203,100 @@ class MigrationLookupTest extends MigrateProcessTestCase {
|
|||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that a message is successfully created if import fails.
|
||||
*/
|
||||
public function testImportException() {
|
||||
$migration_plugin = $this->prophesize(MigrationInterface::class);
|
||||
$migration_plugin_manager = $this->prophesize(MigrationPluginManagerInterface::class);
|
||||
$process_plugin_manager = $this->prophesize(MigratePluginManager::class);
|
||||
|
||||
$destination_id_map = $this->prophesize(MigrateIdMapInterface::class);
|
||||
$destination_migration = $this->prophesize('Drupal\migrate\Plugin\Migration');
|
||||
$destination_migration->getIdMap()->willReturn($destination_id_map->reveal());
|
||||
$migration_plugin_manager->createInstances(['destination_migration'])
|
||||
->willReturn(['destination_migration' => $destination_migration->reveal()]);
|
||||
$destination_id_map->lookupDestinationId([1])->willReturn(NULL);
|
||||
$destination_id_map->saveMessage(Argument::any(), Argument::any())->willReturn(NULL);
|
||||
$destination_id_map->saveIdMapping(Argument::any(), Argument::any(), Argument::any())->shouldNotBeCalled();
|
||||
|
||||
$configuration = [
|
||||
'no_stub' => FALSE,
|
||||
'migration' => 'destination_migration',
|
||||
];
|
||||
|
||||
$destination_migration->id()->willReturn('destination_migration');
|
||||
$destination_migration->getDestinationPlugin(TRUE)->shouldBeCalled();
|
||||
$destination_migration->getProcess()->willReturn([]);
|
||||
$destination_migration->getSourceConfiguration()->willReturn([]);
|
||||
|
||||
$source_plugin = $this->prophesize(MigrateSourceInterface::class);
|
||||
$source_plugin->getIds()->willReturn(['nid']);
|
||||
$destination_migration->getSourcePlugin()->willReturn($source_plugin->reveal());
|
||||
$destination_plugin = $this->prophesize(MigrateDestinationInterface::class);
|
||||
$e = new \Exception();
|
||||
$destination_plugin->import(Argument::any())->willThrow($e);
|
||||
$destination_migration->getDestinationPlugin(TRUE)->willReturn($destination_plugin->reveal());
|
||||
|
||||
$migration = new MigrationLookup($configuration, '', [], $migration_plugin->reveal(), $migration_plugin_manager->reveal(), $process_plugin_manager->reveal());
|
||||
$migration->transform(1, $this->migrateExecutable, $this->row, '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests processing multiple source IDs.
|
||||
*/
|
||||
public function testMultipleSourceIds() {
|
||||
$migration_plugin = $this->prophesize(MigrationInterface::class);
|
||||
$migration_plugin_manager = $this->prophesize(MigrationPluginManagerInterface::class);
|
||||
$process_plugin_manager = $this->prophesize(MigratePluginManager::class);
|
||||
$foobaz_migration = $this->prophesize(MigrationInterface::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);
|
||||
|
||||
$migration_plugin_manager->createInstances(['foobaz'])
|
||||
->willReturn(['foobaz' => $foobaz_migration->reveal()]);
|
||||
|
||||
$process_plugin_manager->createInstance('get', ['source' => ['string_id', 'integer_id']], $migration_plugin->reveal())
|
||||
->willReturn($get_migration->reveal());
|
||||
|
||||
$foobaz_migration->getIdMap()->willReturn($id_map->reveal());
|
||||
$foobaz_migration->getDestinationPlugin(TRUE)->willReturn($destination_plugin->reveal());
|
||||
$foobaz_migration->getProcess()->willReturn([]);
|
||||
$foobaz_migration->getSourcePlugin()->willReturn($source_plugin->reveal());
|
||||
$foobaz_migration->id()->willReturn('foobaz');
|
||||
$foobaz_migration->getSourceConfiguration()->willReturn([]);
|
||||
|
||||
$get_migration->transform(NULL, $this->migrateExecutable, $this->row, 'foo')
|
||||
->willReturn(['example_string', 99]);
|
||||
|
||||
$source_plugin_ids = [
|
||||
'string_id' => [
|
||||
'type' => 'string',
|
||||
'max_length' => 128,
|
||||
'is_ascii' => TRUE,
|
||||
'alias' => 'wpt',
|
||||
],
|
||||
'integer_id' => [
|
||||
'type' => 'integer',
|
||||
'unsigned' => FALSE,
|
||||
'alias' => 'wpt',
|
||||
],
|
||||
];
|
||||
|
||||
$stub_row = new Row(['string_id' => 'example_string', 'integer_id' => 99], $source_plugin_ids, TRUE);
|
||||
$destination_plugin->import($stub_row)->willReturn([2]);
|
||||
|
||||
$source_plugin->getIds()->willReturn($source_plugin_ids);
|
||||
|
||||
$configuration = [
|
||||
'migration' => 'foobaz',
|
||||
'source_ids' => ['foobaz' => ['string_id', 'integer_id']],
|
||||
];
|
||||
$migration = new MigrationLookup($configuration, 'migration', [], $migration_plugin->reveal(), $migration_plugin_manager->reveal(), $process_plugin_manager->reveal());
|
||||
$result = $migration->transform(NULL, $this->migrateExecutable, $this->row, 'foo');
|
||||
$this->assertEquals(2, $result);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,9 +2,6 @@
|
|||
|
||||
namespace Drupal\Tests\migrate\Unit\process;
|
||||
|
||||
@trigger_error('The ' . __NAMESPACE__ . '\MigrationTest is deprecated in
|
||||
Drupal 8.4.0 and will be removed before Drupal 9.0.0. Instead, use ' . __NAMESPACE__ . '\MigrationLookupTest', E_USER_DEPRECATED);
|
||||
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\migrate\MigrateSkipProcessException;
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
|
@ -17,11 +14,9 @@ use Drupal\migrate\Plugin\MigrationPluginManagerInterface;
|
|||
use Prophecy\Argument;
|
||||
|
||||
/**
|
||||
* @deprecated in Drupal 8.4.x, to be removed before Drupal 9.0.x. Use
|
||||
* \Drupal\Tests\migrate\Unit\process\MigrationLookupTest instead.
|
||||
*
|
||||
* @coversDefaultClass \Drupal\migrate\Plugin\migrate\process\Migration
|
||||
* @group migrate
|
||||
* @group legacy
|
||||
*/
|
||||
class MigrationTest extends MigrateProcessTestCase {
|
||||
|
||||
|
@ -129,6 +124,8 @@ class MigrationTest extends MigrateProcessTestCase {
|
|||
'migration' => 'foobaz',
|
||||
];
|
||||
$this->migration_plugin->id()->willReturn(uniqid());
|
||||
$this->migration_plugin_manager->createInstances(['foobaz'])
|
||||
->willReturn(['foobaz' => $this->migration_plugin->reveal()]);
|
||||
$migration = new Migration($configuration, 'migration', [], $this->migration_plugin->reveal(), $this->migration_plugin_manager->reveal(), $this->process_plugin_manager->reveal());
|
||||
$this->setExpectedException(MigrateSkipProcessException::class);
|
||||
$migration->transform(0, $this->migrateExecutable, $this->row, 'foo');
|
||||
|
|
|
@ -31,7 +31,7 @@ class SkipOnEmptyTest extends MigrateProcessTestCase {
|
|||
$configuration['method'] = 'process';
|
||||
$value = (new SkipOnEmpty($configuration, 'skip_on_empty', []))
|
||||
->transform(' ', $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame($value, ' ');
|
||||
$this->assertSame(' ', $value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -51,7 +51,7 @@ class SkipOnEmptyTest extends MigrateProcessTestCase {
|
|||
$configuration['method'] = 'row';
|
||||
$value = (new SkipOnEmpty($configuration, 'skip_on_empty', []))
|
||||
->transform(' ', $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame($value, ' ');
|
||||
$this->assertSame(' ', $value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
|
@ -27,7 +28,7 @@ class StaticMapTest extends MigrateProcessTestCase {
|
|||
*/
|
||||
public function testMapWithSourceString() {
|
||||
$value = $this->plugin->transform('foo', $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame($value, ['bar' => 'baz']);
|
||||
$this->assertSame(['bar' => 'baz'], $value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -35,7 +36,7 @@ class StaticMapTest extends MigrateProcessTestCase {
|
|||
*/
|
||||
public function testMapWithSourceList() {
|
||||
$value = $this->plugin->transform(['foo', 'bar'], $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame($value, 'baz');
|
||||
$this->assertSame('baz', $value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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');
|
||||
}
|
||||
|
||||
|
@ -62,7 +63,7 @@ class StaticMapTest extends MigrateProcessTestCase {
|
|||
$configuration['default_value'] = 'test';
|
||||
$this->plugin = new StaticMap($configuration, 'map', []);
|
||||
$value = $this->plugin->transform(['bar'], $this->migrateExecutable, $this->row, 'destinationproperty');
|
||||
$this->assertSame($value, 'test');
|
||||
$this->assertSame('test', $value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,82 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\migrate\Unit\process;
|
||||
|
||||
use Drupal\migrate\MigrateExecutable;
|
||||
use Drupal\migrate\Plugin\migrate\process\Get;
|
||||
use Drupal\migrate\Plugin\migrate\process\SubProcess;
|
||||
use Drupal\migrate\Row;
|
||||
use Drupal\Tests\migrate\Unit\MigrateTestCase;
|
||||
|
||||
/**
|
||||
* Tests the sub_process process plugin.
|
||||
*
|
||||
* @group migrate
|
||||
*/
|
||||
class SubProcessTest extends MigrateTestCase {
|
||||
|
||||
/**
|
||||
* The sub_process plugin being tested.
|
||||
*
|
||||
* @var \Drupal\migrate\Plugin\migrate\process\SubProcess
|
||||
*/
|
||||
protected $plugin;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $migrationConfiguration = [
|
||||
'id' => 'test',
|
||||
];
|
||||
|
||||
/**
|
||||
* Tests the sub_process process plugin.
|
||||
*/
|
||||
public function testSubProcess() {
|
||||
$migration = $this->getMigration();
|
||||
// Set up the properties for the sub_process.
|
||||
$configuration = [
|
||||
'process' => [
|
||||
'foo' => 'source_foo',
|
||||
'id' => 'source_id',
|
||||
],
|
||||
'key' => '@id',
|
||||
];
|
||||
$plugin = new SubProcess($configuration, 'sub_process', []);
|
||||
// Manually create the plugins. Migration::getProcessPlugins does this
|
||||
// normally but the plugin system is not available.
|
||||
foreach ($configuration['process'] as $destination => $source) {
|
||||
$sub_process_plugins[$destination][] = new Get(['source' => $source], 'get', []);
|
||||
}
|
||||
$migration->expects($this->at(1))
|
||||
->method('getProcessPlugins')
|
||||
->willReturn($sub_process_plugins);
|
||||
// Set up the key plugins.
|
||||
$key_plugin['key'][] = new Get(['source' => '@id'], 'get', []);
|
||||
$migration->expects($this->at(2))
|
||||
->method('getProcessPlugins')
|
||||
->will($this->returnValue($key_plugin));
|
||||
$event_dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
|
||||
$migrate_executable = new MigrateExecutable($migration, $this->getMock('Drupal\migrate\MigrateMessageInterface'), $event_dispatcher);
|
||||
|
||||
// The current value of the pipeline.
|
||||
$current_value = [
|
||||
[
|
||||
'source_foo' => 'test',
|
||||
'source_id' => 42,
|
||||
],
|
||||
];
|
||||
// This is not used but the interface requires it, so create an empty row.
|
||||
$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
|
||||
// key (@id) is the same as the destination ID (42).
|
||||
$new_value = $plugin->transform($current_value, $migrate_executable, $row, 'test');
|
||||
$this->assertSame(1, count($new_value));
|
||||
$this->assertSame(2, count($new_value[42]));
|
||||
$this->assertSame('test', $new_value[42]['foo']);
|
||||
$this->assertSame(42, $new_value[42]['id']);
|
||||
}
|
||||
|
||||
}
|
|
@ -4,7 +4,6 @@ namespace Drupal\Tests\migrate\Unit\process;
|
|||
|
||||
use Drupal\migrate\Plugin\migrate\process\UrlEncode;
|
||||
use Drupal\migrate\MigrateExecutable;
|
||||
use Drupal\migrate\MigrateMessage;
|
||||
use Drupal\migrate\Row;
|
||||
use Drupal\Tests\migrate\Unit\MigrateTestCase;
|
||||
|
||||
|
@ -56,7 +55,7 @@ class UrlEncodeTest extends MigrateTestCase {
|
|||
* Encoded URL.
|
||||
*/
|
||||
protected function doTransform($value) {
|
||||
$executable = new MigrateExecutable($this->getMigration(), new MigrateMessage());
|
||||
$executable = new MigrateExecutable($this->getMigration());
|
||||
$row = new Row();
|
||||
|
||||
return (new UrlEncode([], 'urlencode', []))
|
||||
|
|
Reference in a new issue