function ContentExportTest::testExportedPasswordIsPreserved

Tests that an exported user account can be logged in with after import.

File

core/tests/Drupal/FunctionalTests/DefaultContent/ContentExportTest.php, line 146

Class

ContentExportTest
Tests exporting content in YAML format.

Namespace

Drupal\FunctionalTests\DefaultContent

Code

public function testExportedPasswordIsPreserved() : void {
  $account = $this->createUser();
  $this->assertNotEmpty($account->passRaw);
  // Export the account to temporary file.
  $process = $this->runDrupalCommand([
    'content:export',
    'user',
    $account->id(),
  ]);
  $this->assertSame(0, $process->wait());
  $dir = 'public://content';
  mkdir($dir);
  file_put_contents($dir . '/user.yml', $process->getOutput());
  // Delete the account and re-import it.
  $account->delete();
  $this->container
    ->get(Importer::class)
    ->importContent(new Finder($dir));
  // Ensure the import succeeded, and that we can log in with the imported
  // account. We want to use the standard login form, rather than a one-time
  // login link, to ensure the password is preserved.
  $this->assertIsObject(user_load_by_name($account->getAccountName()));
  $this->useOneTimeLoginLinks = FALSE;
  $this->drupalLogin($account);
  $this->assertSession()
    ->addressMatches('/\\/user\\/[0-9]+$/');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.