You are here

public function ModalPageTest::testIfModalByParameterIsLoaded in Modal 4.1.x

Tests modal by parameter behaviour.

File

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

Class

ModalPageTest
Tests that modal is working.

Namespace

Drupal\Tests\modal_page\Functional

Code

public function testIfModalByParameterIsLoaded() {
  $assert_session = $this
    ->assertSession();

  // Set the modal type to parameter.
  $modal = \Drupal::service('entity_type.manager')
    ->getStorage('modal')
    ->load('thank_you_for_installing_modal_page');
  $modal
    ->setType('parameter');
  $modal
    ->setParameters('welcome');
  $modal
    ->save();
  $this
    ->drupalGet('admin/structure');

  // Ensure the modal is not loaded.
  $assert_session
    ->responseNotContains('Thank you for installing Modal Page');

  // Check that the modal is loaded.
  $this
    ->drupalGet('admin/structure', [
    'query' => [
      'modal' => 'welcome',
    ],
  ]);
  $assert_session
    ->responseContains('Thank you for installing Modal Page');

  // Set the modal parameter.
  $modal = \Drupal::service('entity_type.manager')
    ->getStorage('modal')
    ->load('thank_you_for_installing_modal_page');
  $modal
    ->setParameters("welcome\r\nwelcome_2");
  $modal
    ->save();

  // Check that the modal is loaded.
  $this
    ->drupalGet('admin/structure', [
    'query' => [
      'modal' => 'welcome',
    ],
  ]);
  $assert_session
    ->responseContains('Thank you for installing Modal Page');

  // Check that the modal is loaded.
  $this
    ->drupalGet('admin', [
    'query' => [
      'modal' => 'welcome_2',
    ],
  ]);
  $assert_session
    ->responseContains('Thank you for installing Modal Page');
}