You are here

function BasicAuthTest::testUnauthorizedErrorMessage in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/basic_auth/src/Tests/Authentication/BasicAuthTest.php \Drupal\basic_auth\Tests\Authentication\BasicAuthTest::testUnauthorizedErrorMessage()

Tests if a comprehensive message is displayed when the route is denied.

File

core/modules/basic_auth/src/Tests/Authentication/BasicAuthTest.php, line 162
Contains \Drupal\basic_auth\Tests\Authentication\BasicAuthTest.

Class

BasicAuthTest
Tests for BasicAuth authentication provider.

Namespace

Drupal\basic_auth\Tests\Authentication

Code

function testUnauthorizedErrorMessage() {
  $account = $this
    ->drupalCreateUser();
  $url = Url::fromRoute('router_test.11');

  // Case when no credentials are passed.
  $this
    ->drupalGet($url);
  $this
    ->assertResponse('401', 'The user is blocked when no credentials are passed.');
  $this
    ->assertNoText('Exception', "No raw exception is displayed on the page.");
  $this
    ->assertText('Please log in to access this page.', "A user friendly access unauthorized message is displayed.");

  // Case when empty credentials are passed.
  $this
    ->basicAuthGet($url, NULL, NULL);
  $this
    ->assertResponse('403', 'The user is blocked when empty credentials are passed.');
  $this
    ->assertText('Access denied', "A user friendly access denied message is displayed");

  // Case when wrong credentials are passed.
  $this
    ->basicAuthGet($url, $account
    ->getUsername(), $this
    ->randomMachineName());
  $this
    ->assertResponse('403', 'The user is blocked when wrong credentials are passed.');
  $this
    ->assertText('Access denied', "A user friendly access denied message is displayed");
}