You are here

public function ModalPageTest::testIfModalByPageIsLoaded in Modal 4.1.x

Tests modal by page behaviour.

File

tests/src/Functional/ModalPageTest.php, line 47

Class

ModalPageTest
Tests that modal is working.

Namespace

Drupal\Tests\modal_page\Functional

Code

public function testIfModalByPageIsLoaded() {
  $assert_session = $this
    ->assertSession();
  $this
    ->drupalGet('admin/structure');

  // Check if modal is loaded.
  $assert_session
    ->responseContains('Thank you for installing Modal Page');

  // Check if modal is not loaded.
  $this
    ->drupalGet('admin');
  $assert_session
    ->responseNotContains('Thank you for installing Modal Page');

  // Set the modal to be loaded on front page.
  $modal = \Drupal::service('entity_type.manager')
    ->getStorage('modal')
    ->load('thank_you_for_installing_modal_page');
  $modal
    ->setPages('<front>');
  $modal
    ->save();

  // Check if modal is loaded on front page.
  $this
    ->drupalGet('<front>');
  $assert_session
    ->responseContains('Thank you for installing Modal Page');

  // Set the modal to be displayed on front page and admin/*.
  $modal = \Drupal::service('entity_type.manager')
    ->getStorage('modal')
    ->load('thank_you_for_installing_modal_page');
  $modal
    ->setPages("<front>\r\n/admin/*");
  $modal
    ->save();

  // Check if modal is loaded on front page.
  $this
    ->drupalGet('<front>');
  $assert_session
    ->responseContains('Thank you for installing Modal Page');

  // Check if modal loaded and on admin/*.
  $this
    ->drupalGet('admin/structure');
  $assert_session
    ->responseContains('Thank you for installing Modal Page');
}