You are here

protected function FeedsJavascriptTestBase::submitFormWithDropButton in Feeds 8.3

Fills and submits a form where the submit button is hidden in a dropbutton.

Parameters

array $edit: Field data in an associative array. Changes the current input fields (where possible) to the values indicated.

A checkbox can be set to TRUE to be checked and should be set to FALSE to be unchecked.

string $submit: Value of the submit button whose click is to be emulated. For example, 'Save'. The processing of the request depends on this value. For example, a form may have one button with the value 'Save' and another button with the value 'Delete', and execute different code depending on which one is clicked.

string $form_html_id: (optional) HTML ID of the form to be submitted. On some pages there are many identical forms, so just using the value of the submit button is not enough. For example: 'trigger-node-presave-assign-form'. Note that this is not the Drupal $form_id, but rather the HTML ID of the form, which is typically the same thing but with hyphens replacing the underscores.

1 call to FeedsJavascriptTestBase::submitFormWithDropButton()
CsvParserTest::testMapCustomSource in tests/src/FunctionalJavascript/Feeds/Parser/CsvParserTest.php
Tests adding a custom mapping source.

File

tests/src/FunctionalJavascript/FeedsJavascriptTestBase.php, line 312

Class

FeedsJavascriptTestBase
Base class for Feeds javascript tests.

Namespace

Drupal\Tests\feeds\FunctionalJavascript

Code

protected function submitFormWithDropButton(array $edit, $submit, $form_html_id = NULL) {
  $assert_session = $this
    ->assertSession();

  // Get the form.
  if (isset($form_html_id)) {
    $form = $assert_session
      ->elementExists('xpath', "//form[@id='{$form_html_id}']");
    $submit_button = $assert_session
      ->buttonExists($submit, $form);
    $action = $form
      ->getAttribute('action');
  }
  else {
    $submit_button = $assert_session
      ->buttonExists($submit);
    $form = $assert_session
      ->elementExists('xpath', './ancestor::form', $submit_button);
    $action = $form
      ->getAttribute('action');
  }

  // Edit the form values.
  foreach ($edit as $name => $value) {
    $field = $assert_session
      ->fieldExists($name, $form);
    $field
      ->setValue($value);
  }

  // Submit form.
  $this
    ->prepareRequest();

  // Click dropbutton and wait until the secondary action becomes visible.
  $this
    ->click('#edit-actions .dropbutton-toggle button');
  $assert_session
    ->waitForElementVisible('css', '#edit-actions .dropbutton-widget .secondary-action');
  $submit_button
    ->press();

  // Ensure that any changes to variables in the other thread are picked up.
  $this
    ->refreshVariables();

  // Check if there are any meta refresh redirects (like Batch API pages).
  if ($this
    ->checkForMetaRefresh()) {

    // We are finished with all meta refresh redirects, so reset the counter.
    $this->metaRefreshCount = 0;
  }
}