You are here

public function ContentEntityTest::testUserSource in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/ContentEntityTest.php \Drupal\Tests\migrate_drupal\Kernel\Plugin\migrate\source\ContentEntityTest::testUserSource()

Tests user source plugin.

@dataProvider migrationConfigurationProvider

File

core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/ContentEntityTest.php, line 276

Class

ContentEntityTest
Tests the entity content source plugin.

Namespace

Drupal\Tests\migrate_drupal\Kernel\Plugin\migrate\source

Code

public function testUserSource(array $configuration) {
  $migration = $this->migrationPluginManager
    ->createStubMigration($this
    ->migrationDefinition('content_entity:user', $configuration));
  $user_source = $migration
    ->getSourcePlugin();
  $this
    ->assertSame('users', $user_source
    ->__toString());
  if (!$configuration['include_translations']) {

    // Confirm that the query does not return a row for the anonymous user.
    $this
      ->assertEquals(1, $user_source
      ->count());
  }
  $this
    ->assertIds($user_source, $configuration);
  $fields = $user_source
    ->fields();
  $this
    ->assertArrayHasKey('name', $fields);
  $this
    ->assertArrayHasKey('pass', $fields);
  $this
    ->assertArrayHasKey('mail', $fields);
  $this
    ->assertArrayHasKey('uid', $fields);
  $this
    ->assertArrayHasKey('roles', $fields);
  $user_source
    ->rewind();
  $values = $user_source
    ->current()
    ->getSource();
  $this
    ->assertEquals('example@example.com', $values['mail'][0]['value']);
  $this
    ->assertEquals('user123', $values['name'][0]['value']);
  $this
    ->assertEquals(1, $values['uid']);
  $this
    ->assertEquals(1, $values['field_entity_reference'][0]['target_id']);
}