You are here

public function PasswordTest::test in Feeds 8.3

Tests if users with passwords can login after import.

@dataProvider providerPasswordTypes

Parameters

string $source: The CSV field to import.

array $settings: The settings for the password target.

File

tests/src/Functional/Feeds/Target/PasswordTest.php, line 84

Class

PasswordTest
@coversDefaultClass \Drupal\feeds\Feeds\Target\Password @group feeds

Namespace

Drupal\Tests\feeds\Functional\Feeds\Target

Code

public function test($source, array $settings = []) {
  $this->feedType
    ->addCustomSource($source, [
    'value' => $source,
  ]);
  $this->feedType
    ->addMapping([
    'target' => 'pass',
    'map' => [
      'value' => $source,
    ],
    'settings' => $settings,
  ]);
  $this->feedType
    ->save();

  // Create an account for Gomez, to ensure passwords can also be imported for
  // existing users. Give Gomez a password different from the one that gets
  // imported to ensure that their password gets updated.
  $this->userStorage
    ->create([
    'name' => 'Gomez',
    'mail' => 'gomez@example.com',
    'pass' => 'temporary',
    'status' => 1,
  ])
    ->save();

  // Create a feed and import.
  $feed = $this
    ->createFeed($this->feedType
    ->id(), [
    'source' => $this
      ->resourcesPath() . '/csv/users.csv',
  ]);
  $this
    ->batchImport($feed);

  // Assert result.
  $this
    ->assertSession()
    ->pageTextContains('Created 2 users');
  $this
    ->assertSession()
    ->pageTextContains('Updated 1 user');

  // Try to login as each successful imported user.
  $this
    ->feedsLoginUser('Morticia', 'mort');
  $this
    ->feedsLoginUser('Fester', 'fest');
  $this
    ->feedsLoginUser('Gomez', 'gome');
}