You are here

public function EntityBrowserContext::submit in Lightning Media 8.3

Same name and namespace in other branches
  1. 8 tests/contexts/EntityBrowserContext.behat.inc \Acquia\LightningExtension\Context\EntityBrowserContext::submit()
  2. 8.2 tests/contexts/EntityBrowserContext.behat.inc \Acquia\LightningExtension\Context\EntityBrowserContext::submit()

Submits the entity browser.

@When I submit the entity browser

1 call to EntityBrowserContext::submit()
EntityBrowserContext::selectItems in tests/contexts/EntityBrowserContext.behat.inc
Selects several items from an entity browser.

File

tests/contexts/EntityBrowserContext.behat.inc, line 125

Class

EntityBrowserContext
Contains step definitions for interacting with entity browser instances.

Namespace

Acquia\LightningExtension\Context

Code

public function submit() {
  $session = $this
    ->getSession();
  $button = $this
    ->assertSession()
    ->elementExists('css', '[data-drupal-selector="edit-submit"]')
    ->getXpath();
  $frame = $session
    ->evaluateScript('window.name') ?: $session
    ->evaluateScript('window.active_iframe.name');
  Assert::notEmpty($frame);

  // Switch out of the iFrame, because it will be destroyed as soon as we
  // press the button.
  $session
    ->switchToIFrame();

  // If there are single quotes in the button's XPath query, WebDriver needs
  // them to be escaped.
  if ($session
    ->getDriver() instanceof Selenium2Driver) {
    $button = addslashes($button);
  }
  $js = <<<END
document.evaluate('{<span class="php-variable">$button</span>}', window.{<span class="php-variable">$frame</span>}.document, null).iterateNext().click();
END;
  $session
    ->executeScript($js);
  $this
    ->awaitAjax();
}