You are here

public function PathautoUserWebTest::testUserOperations in Pathauto 8

Test user operations.

File

tests/src/Functional/PathautoUserWebTest.php, line 67

Class

PathautoUserWebTest
Tests pathauto user UI integration.

Namespace

Drupal\Tests\pathauto\Functional

Code

public function testUserOperations() {
  $account = $this
    ->drupalCreateUser();

  // Delete all current URL aliases.
  $this
    ->deleteAllAliases();

  // Find the position of just created account in the user_admin_people view.
  $view = Views::getView('user_admin_people');
  $view
    ->initDisplay();
  $view
    ->preview('page_1');
  foreach ($view->result as $key => $row) {
    if ($view->field['name']
      ->getValue($row) == $account
      ->getDisplayName()) {
      break;
    }
  }
  $edit = [
    'action' => 'pathauto_update_alias_user',
    "user_bulk_form[{$key}]" => TRUE,
  ];
  $this
    ->drupalPostForm('admin/people', $edit, t('Apply to selected items'));
  $this
    ->assertText('Update URL alias was applied to 1 item.');
  $this
    ->assertEntityAlias($account, '/users/' . mb_strtolower($account
    ->getDisplayName()));
  $this
    ->assertEntityAlias($this->adminUser, '/user/' . $this->adminUser
    ->id());
}