class ModalFormTest

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

@group form_api_example

Hierarchy

  • class \Drupal\Tests\form_api_example\FunctionalJavascript\ModalFormTest extends \Drupal\FunctionalJavascriptTests\WebDriverTestBase

Expanded class hierarchy of ModalFormTest

Related topics

File

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

Namespace

Drupal\Tests\form_api_example\FunctionalJavascript
View source
class ModalFormTest extends WebDriverTestBase {
    
    /**
     * {@inheritdoc}
     */
    protected $defaultTheme = 'classy';
    
    /**
     * Our module dependencies.
     *
     * @var string[]
     */
    public static $modules = [
        'form_api_example',
    ];
    
    /**
     * 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.
     */
    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.');
    }

}

Members

Title Sort descending Modifiers Object type Summary
ModalFormTest::$defaultTheme protected property
ModalFormTest::$modules public static property Our module dependencies.
ModalFormTest::testModalForm public function Functional test of the modal form example.