You are here

public function EntityLookupAccessTest::testEntityLookupAccessCheck in Migrate Plus 8.4

Tests entity_lookup access_check configuration key.

File

tests/src/Kernel/Plugin/migrate/process/EntityLookupAccessTest.php, line 98

Class

EntityLookupAccessTest
Tests Entity Lookup access check.

Namespace

Drupal\Tests\migrate_plus\Kernel\Plugin\migrate\process

Code

public function testEntityLookupAccessCheck() {
  $configuration_base = [
    'entity_type' => 'profile',
    'value_key' => 'profile_id',
  ];

  // Set access_check true.
  $configuration = $configuration_base + [
    'access_check' => TRUE,
  ];
  $plugin = \Drupal::service('plugin.manager.migrate.process')
    ->createInstance('entity_lookup', $configuration, $this->migration);

  // Check the profile is not found.
  $value = $plugin
    ->transform('1', $this->executable, $this->row, 'profile_id');
  $this
    ->assertNull($value);

  // Retest with access check false.
  $configuration = $configuration_base + [
    'access_check' => FALSE,
  ];
  $plugin = \Drupal::service('plugin.manager.migrate.process')
    ->createInstance('entity_lookup', $configuration, $this->migration);

  // Check the profile is found.
  $value = $plugin
    ->transform('1', $this->executable, $this->row, 'profile_id');
  $this
    ->assertSame('1', $value);
}