EntityExistsTest.php in Drupal 8
File
core/modules/migrate/tests/src/Kernel/Plugin/EntityExistsTest.php
View source
<?php
namespace Drupal\Tests\migrate\Kernel\Plugin;
use Drupal\KernelTests\KernelTestBase;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\Row;
use Drupal\user\Entity\User;
class EntityExistsTest extends KernelTestBase {
public static $modules = [
'migrate',
'system',
'user',
];
protected function setUp() {
parent::setUp();
$this
->installSchema('system', [
'sequences',
]);
$this
->installEntitySchema('user');
}
public function testEntityExists() {
$user = User::create([
'name' => $this
->randomString(),
]);
$user
->save();
$uid = $user
->id();
$plugin = \Drupal::service('plugin.manager.migrate.process')
->createInstance('entity_exists', [
'entity_type' => 'user',
]);
$executable = $this
->prophesize(MigrateExecutableInterface::class)
->reveal();
$row = new Row();
$value = $plugin
->transform($uid, $executable, $row, 'buffalo');
$this
->assertSame($uid, $value);
$value = $plugin
->transform(420, $executable, $row, 'buffalo');
$this
->assertFalse($value);
$value = $plugin
->transform([
$uid,
420,
], $executable, $row, 'buffalo');
$this
->assertSame($uid, $value);
}
}