ThrobberTest.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace Drupal\FunctionalJavascriptTests\Ajax;
  3. use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
  4. /**
  5. * Tests the throbber.
  6. *
  7. * @group Ajax
  8. */
  9. class ThrobberTest extends WebDriverTestBase {
  10. /**
  11. * {@inheritdoc}
  12. */
  13. public static $modules = [
  14. 'node',
  15. 'views',
  16. 'views_ui',
  17. 'views_ui_test_field',
  18. 'hold_test',
  19. ];
  20. /**
  21. * {@inheritdoc}
  22. */
  23. protected $defaultTheme = 'stark';
  24. /**
  25. * {@inheritdoc}
  26. */
  27. public function setUp() {
  28. parent::setUp();
  29. $admin_user = $this->drupalCreateUser([
  30. 'administer views',
  31. ]);
  32. $this->drupalLogin($admin_user);
  33. }
  34. /**
  35. * Tests theming throbber element.
  36. */
  37. public function testThemingThrobberElement() {
  38. $session = $this->getSession();
  39. $web_assert = $this->assertSession();
  40. $page = $session->getPage();
  41. $custom_ajax_progress_indicator_fullscreen = <<<JS
  42. Drupal.theme.ajaxProgressIndicatorFullscreen = function () {
  43. return '<div class="custom-ajax-progress-fullscreen"></div>';
  44. };
  45. JS;
  46. $custom_ajax_progress_throbber = <<<JS
  47. Drupal.theme.ajaxProgressThrobber = function (message) {
  48. return '<div class="custom-ajax-progress-throbber"></div>';
  49. };
  50. JS;
  51. $custom_ajax_progress_message = <<<JS
  52. Drupal.theme.ajaxProgressMessage = function (message) {
  53. return '<div class="custom-ajax-progress-message">Hold door!</div>';
  54. };
  55. JS;
  56. $this->drupalGet('admin/structure/views/view/content');
  57. $web_assert->assertNoElementAfterWait('css', '.ajax-progress-fullscreen');
  58. // Test theming fullscreen throbber.
  59. $session->executeScript($custom_ajax_progress_indicator_fullscreen);
  60. hold_test_response(TRUE);
  61. $page->clickLink('Content: Published (grouped)');
  62. $this->assertNotNull($web_assert->waitForElement('css', '.custom-ajax-progress-fullscreen'), 'Custom ajaxProgressIndicatorFullscreen.');
  63. hold_test_response(FALSE);
  64. $web_assert->assertNoElementAfterWait('css', '.custom-ajax-progress-fullscreen');
  65. // Test theming throbber message.
  66. $web_assert->waitForElementVisible('css', '[data-drupal-selector="edit-options-group-info-add-group"]');
  67. $session->executeScript($custom_ajax_progress_message);
  68. hold_test_response(TRUE);
  69. $page->pressButton('Add another item');
  70. $this->assertNotNull($web_assert->waitForElement('css', '.ajax-progress-throbber .custom-ajax-progress-message'), 'Custom ajaxProgressMessage.');
  71. hold_test_response(FALSE);
  72. $web_assert->assertNoElementAfterWait('css', '.ajax-progress-throbber');
  73. // Test theming throbber.
  74. $web_assert->waitForElementVisible('css', '[data-drupal-selector="edit-options-group-info-group-items-3-title"]');
  75. $session->executeScript($custom_ajax_progress_throbber);
  76. hold_test_response(TRUE);
  77. $page->pressButton('Add another item');
  78. $this->assertNotNull($web_assert->waitForElement('css', '.custom-ajax-progress-throbber'), 'Custom ajaxProgressThrobber.');
  79. hold_test_response(FALSE);
  80. $web_assert->assertNoElementAfterWait('css', '.custom-ajax-progress-throbber');
  81. }
  82. }