EntityLookupTest.php in Migrate Plus 8.4
File
tests/src/Kernel/Plugin/migrate/process/EntityLookupTest.php
View source
<?php
namespace Drupal\Tests\migrate_plus\Kernel\Plugin\migrate\process;
use Drupal\KernelTests\KernelTestBase;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\Plugin\MigrateDestinationInterface;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\Row;
use Drupal\Tests\user\Traits\UserCreationTrait;
class EntityLookupTest extends KernelTestBase {
use UserCreationTrait;
public static $modules = [
'migrate_plus',
'migrate',
'user',
'system',
];
protected function setUp() {
parent::setUp();
$this
->installSchema('system', [
'sequences',
]);
$this
->installEntitySchema('user');
}
public function testLookupEntityWithoutBundles() {
$known_user = $this
->createUser([], 'lucuma');
$migration_prophecy = $this
->prophesize(MigrationInterface::class);
$migrate_destination_prophecy = $this
->prophesize(MigrateDestinationInterface::class);
$migrate_destination_prophecy
->getPluginId()
->willReturn('user');
$migrate_destination = $migrate_destination_prophecy
->reveal();
$migration_prophecy
->getDestinationPlugin()
->willReturn($migrate_destination);
$migration_prophecy
->getProcess()
->willReturn([]);
$migration = $migration_prophecy
->reveal();
$configuration = [
'entity_type' => 'user',
'value_key' => 'name',
];
$plugin = \Drupal::service('plugin.manager.migrate.process')
->createInstance('entity_lookup', $configuration, $migration);
$executable = $this
->prophesize(MigrateExecutableInterface::class)
->reveal();
$row = new Row();
$value = $plugin
->transform('lucuma', $executable, $row, 'name');
$this
->assertSame($known_user
->id(), $value);
$value = $plugin
->transform('orange', $executable, $row, 'name');
$this
->assertNull($value);
}
}