You are here

public function PageLoadProgressAdminSettingsFormTest::testPageLoadProgressSettings in Page Load Progress 8

Test the page_load_progress settings form.

File

tests/src/Functional/PageLoadProgressAdminSettingsFormTest.php, line 59

Class

PageLoadProgressAdminSettingsFormTest
Tests for the page_load_progress module.

Namespace

Drupal\Tests\page_load_progress\Functional

Code

public function testPageLoadProgressSettings() {

  // Verify if we can successfully access the page_load_progress form.
  $this
    ->drupalGet(Url::fromRoute('page_load_progress.admin_settings'));
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->pageTextContains('Page Load Progress | Drupal');

  // Verify every field exists.
  $this
    ->assertSession()
    ->fieldExists('edit-page-load-progress-time');
  $this
    ->assertSession()
    ->fieldExists('edit-page-load-progress-request-path');
  $this
    ->assertSession()
    ->fieldExists('page_load_progress_request_path_negate_condition');
  $this
    ->assertSession()
    ->fieldExists('edit-page-load-progress-internal-links');
  $this
    ->assertSession()
    ->fieldExists('edit-page-load-progress-esc-key');

  // Validate default form values.
  $this
    ->assertSession()
    ->fieldValueEquals('edit-page-load-progress-time', 10);
  $this
    ->assertSession()
    ->fieldValueEquals('edit-page-load-progress-request-path', '');
  $this
    ->assertSession()
    ->fieldValueEquals('page_load_progress_request_path_negate_condition', 1);
  $this
    ->assertSession()
    ->fieldValueEquals('edit-page-load-progress-internal-links', FALSE);
  $this
    ->assertSession()
    ->fieldValueEquals('edit-page-load-progress-esc-key', TRUE);

  // Verify the custom CSS class is injected on form submission.
  $this
    ->assertSession()
    ->elementExists('css', '.page-load-progress-submit');

  // Verify that there's no access bypass.
  $this
    ->drupalLogout();
  $this
    ->drupalGet(Url::fromRoute('page_load_progress.admin_settings'));
  $this
    ->assertSession()
    ->statusCodeEquals(403);
}