AjaxFormImageButtonTest.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. namespace Drupal\FunctionalJavascriptTests\Ajax;
  3. use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
  4. /**
  5. * Tests the Ajax image buttons work with key press events.
  6. *
  7. * @group Ajax
  8. */
  9. class AjaxFormImageButtonTest extends WebDriverTestBase {
  10. /**
  11. * {@inheritdoc}
  12. */
  13. public static $modules = ['ajax_forms_test'];
  14. /**
  15. * Tests image buttons can be operated with the keyboard ENTER key.
  16. */
  17. public function testAjaxImageButton() {
  18. // Get a Field UI manage-display page.
  19. $this->drupalGet('ajax_forms_image_button_form');
  20. $assertSession = $this->assertSession();
  21. $session = $this->getSession();
  22. $enter_key_event = <<<JS
  23. jQuery('#edit-image-button')
  24. .trigger(jQuery.Event('keypress', {
  25. which: 13
  26. }));
  27. JS;
  28. // PhantomJS driver has buggy behavior with key events, we send a JavaScript
  29. // key event instead.
  30. // @todo: use WebDriver event when we remove PhantomJS driver.
  31. $session->executeScript($enter_key_event);
  32. $this->assertNotEmpty($assertSession->waitForElementVisible('css', '#ajax-1-more-div'), 'Page updated after image button pressed');
  33. }
  34. }