You are here

public function JsWebAssertTestForm::buildForm in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/system/tests/modules/js_webassert_test/src/Form/JsWebAssertTestForm.php \Drupal\js_webassert_test\Form\JsWebAssertTestForm::buildForm()

Form for testing the addition of various types of elements via AJAX.

Overrides FormInterface::buildForm

File

core/modules/system/tests/modules/js_webassert_test/src/Form/JsWebAssertTestForm.php, line 26

Class

JsWebAssertTestForm
Test form for JSWebAssert WebDriverTestBase.

Namespace

Drupal\js_webassert_test\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $form['#prefix'] = '<div id="js_webassert_test_form_wrapper">';
  $form['#suffix'] = '</div>';

  // Button to test for the waitForButton() assertion.
  $form['test_button'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Add button'),
    '#button_type' => 'primary',
    '#ajax' => [
      'callback' => 'Drupal\\js_webassert_test\\Form\\JsWebAssertTestForm::addButton',
      'progress' => [
        'type' => 'throbber',
        'message' => NULL,
      ],
      'wrapper' => 'js_webassert_test_form_wrapper',
    ],
  ];

  // Button to test for the waitForLink() assertion.
  $form['test_link'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Add link'),
    '#button_type' => 'primary',
    '#ajax' => [
      'callback' => 'Drupal\\js_webassert_test\\Form\\JsWebAssertTestForm::addLink',
      'progress' => [
        'type' => 'throbber',
        'message' => NULL,
      ],
      'wrapper' => 'js_webassert_test_form_wrapper',
    ],
  ];

  // Button to test for the waitForField() assertion.
  $form['test_field'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Add field'),
    '#button_type' => 'primary',
    '#ajax' => [
      'callback' => 'Drupal\\js_webassert_test\\Form\\JsWebAssertTestForm::addField',
      'progress' => [
        'type' => 'throbber',
        'message' => NULL,
      ],
      'wrapper' => 'js_webassert_test_form_wrapper',
    ],
  ];

  // Button to test for the waitForId() assertion.
  $form['test_id'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Add ID'),
    '#button_type' => 'primary',
    '#ajax' => [
      'callback' => 'Drupal\\js_webassert_test\\Form\\JsWebAssertTestForm::addId',
      'progress' => [
        'type' => 'throbber',
        'message' => NULL,
      ],
      'wrapper' => 'js_webassert_test_form_wrapper',
    ],
  ];

  // Button to test the assertWaitOnAjaxRequest() assertion.
  $form['test_wait_for_element_visible'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Test waitForElementVisible'),
    '#button_type' => 'primary',
    '#ajax' => [
      'callback' => 'Drupal\\js_webassert_test\\Form\\JsWebAssertTestForm::addWaitForElementVisible',
      'progress' => [
        'type' => 'throbber',
        'message' => NULL,
      ],
      'wrapper' => 'js_webassert_test_form_wrapper',
    ],
  ];

  // Button to test the assertWaitOnAjaxRequest() assertion.
  $form['test_assert_wait_on_ajax_request'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Test assertWaitOnAjaxRequest'),
    '#button_type' => 'primary',
    '#ajax' => [
      'callback' => 'Drupal\\js_webassert_test\\Form\\JsWebAssertTestForm::addAssertWaitOnAjaxRequest',
      'progress' => [
        'type' => 'throbber',
        'message' => NULL,
      ],
      'wrapper' => 'js_webassert_test_form_wrapper',
    ],
  ];

  // Button to test the assertNoElementAfterWait() assertion, will pass.
  $form['test_assert_no_element_after_wait_pass'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Test assertNoElementAfterWait: pass'),
    '#button_type' => 'primary',
    '#attached' => [
      'library' => 'js_webassert_test/no_element_after_wait',
    ],
  ];

  // Button to test the assertNoElementAfterWait() assertion, will fail.
  $form['test_assert_no_element_after_wait_fail'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Test assertNoElementAfterWait: fail'),
    '#button_type' => 'primary',
  ];
  return $form;
}