class EntityExistsTest
Same name and namespace in other branches
- 11.x core/modules/migrate/tests/src/Kernel/Plugin/EntityExistsTest.php \Drupal\Tests\migrate\Kernel\Plugin\EntityExistsTest
- 10 core/modules/migrate/tests/src/Kernel/Plugin/EntityExistsTest.php \Drupal\Tests\migrate\Kernel\Plugin\EntityExistsTest
- 8.9.x core/modules/migrate/tests/src/Kernel/Plugin/EntityExistsTest.php \Drupal\Tests\migrate\Kernel\Plugin\EntityExistsTest
Tests the EntityExists process plugin.
@group migrate
Hierarchy
- class \Drupal\KernelTests\KernelTestBase implements \Drupal\Core\DependencyInjection\ServiceProviderInterface uses \Drupal\KernelTests\AssertLegacyTrait, \Drupal\KernelTests\AssertContentTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\ExtensionListTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\migrate\Kernel\Plugin\EntityExistsTest extends \Drupal\KernelTests\KernelTestBase
Expanded class hierarchy of EntityExistsTest
File
-
core/
modules/ migrate/ tests/ src/ Kernel/ Plugin/ EntityExistsTest.php, line 15
Namespace
Drupal\Tests\migrate\Kernel\PluginView source
class EntityExistsTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'migrate',
'system',
'user',
];
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->installSchema('system', [
'sequences',
]);
$this->installEntitySchema('user');
}
/**
* Tests the EntityExists plugin.
*/
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();
// Ensure that the entity ID is returned if it really exists.
$value = $plugin->transform($uid, $executable, $row, 'buffalo');
$this->assertSame($uid, $value);
// Ensure that the plugin returns FALSE if the entity doesn't exist.
$value = $plugin->transform(420, $executable, $row, 'buffalo');
$this->assertFalse($value);
// Make sure the plugin can gracefully handle an array as input.
$value = $plugin->transform([
$uid,
420,
], $executable, $row, 'buffalo');
$this->assertSame($uid, $value);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.