function ModalFormTest::testModalForm

Same name in other branches
  1. 3.x modules/form_api_example/tests/src/FunctionalJavascript/ModalFormTest.php \Drupal\Tests\form_api_example\FunctionalJavascript\ModalFormTest::testModalForm()
  2. 4.0.x modules/form_api_example/tests/src/FunctionalJavascript/ModalFormTest.php \Drupal\Tests\form_api_example\FunctionalJavascript\ModalFormTest::testModalForm()

Functional test of the modal form example.

Steps:

  • Visit form route.
  • Click on 'see this form as a modal'.
  • Check that modal exists.
  • Enter a value.
  • Click 'submit'
  • Check that we have a new modal.
  • Click the close X.
  • Verify that the modal went away.

File

form_api_example/tests/src/FunctionalJavascript/ModalFormTest.php, line 40

Class

ModalFormTest
@group form_api_example

Namespace

Drupal\Tests\form_api_example\FunctionalJavascript

Code

public function testModalForm() {
    // Visit form route.
    $modal_route_nojs = Url::fromRoute('form_api_example.modal_form', [
        'nojs' => 'nojs',
    ]);
    $this->drupalGet($modal_route_nojs);
    // Get Mink stuff.
    $assert = $this->assertSession();
    $session = $this->getSession();
    $page = $this->getSession()
        ->getPage();
    // Click on 'see this form as a modal'.
    $this->clickLink('ajax-example-modal-link');
    $this->assertNotEmpty($assert->waitForElementVisible('css', '.ui-dialog'));
    // Enter a value.
    $this->assertNotEmpty($input = $page->find('css', 'div.ui-dialog input[name="title"]'));
    $input->setValue('test_title');
    // Click 'submit'.
    $this->assertNotEmpty($submit = $page->find('css', 'button.ui-button.form-submit'));
    $submit->click();
    $assert->assertWaitOnAjaxRequest();
    // Check that we have a result modal.
    $assert->elementContains('css', 'span.ui-dialog-title', 'test_title');
    // Click the close X.
    $this->assertNotEmpty($close = $page->find('css', 'button.ui-dialog-titlebar-close'));
    $close->click();
    $assert->assertWaitOnAjaxRequest();
    // Verify that the modal went away.
    $assert->pageTextNotContains('appears in this modal dialog.');
}