comparison core/tests/Drupal/FunctionalJavascriptTests/Ajax/ThrobberTest.php @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents
children
comparison
equal deleted inserted replaced
16:c2387f117808 17:129ea1e6d783
1 <?php
2
3 namespace Drupal\FunctionalJavascriptTests\Ajax;
4
5 use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
6
7 /**
8 * Tests the throbber.
9 *
10 * @group Ajax
11 */
12 class ThrobberTest extends WebDriverTestBase {
13
14 /**
15 * {@inheritdoc}
16 */
17 public static $modules = [
18 'node',
19 'views',
20 'views_ui',
21 'views_ui_test_field',
22 'hold_test',
23 ];
24
25 /**
26 * {@inheritdoc}
27 */
28 public function setUp() {
29 parent::setUp();
30
31 $admin_user = $this->drupalCreateUser([
32 'administer views',
33 ]);
34 $this->drupalLogin($admin_user);
35 }
36
37 /**
38 * Tests theming throbber element.
39 */
40 public function testThemingThrobberElement() {
41 $session = $this->getSession();
42 $web_assert = $this->assertSession();
43 $page = $session->getPage();
44
45 $custom_ajax_progress_indicator_fullscreen = <<<JS
46 Drupal.theme.ajaxProgressIndicatorFullscreen = function () {
47 return '<div class="custom-ajax-progress-fullscreen"></div>';
48 };
49 JS;
50 $custom_ajax_progress_throbber = <<<JS
51 Drupal.theme.ajaxProgressThrobber = function (message) {
52 return '<div class="custom-ajax-progress-throbber"></div>';
53 };
54 JS;
55 $custom_ajax_progress_message = <<<JS
56 Drupal.theme.ajaxProgressMessage = function (message) {
57 return '<div class="custom-ajax-progress-message">Hold door!</div>';
58 };
59 JS;
60
61 $this->drupalGet('admin/structure/views/view/content');
62 $this->waitForNoElement('.ajax-progress-fullscreen');
63
64 // Test theming fullscreen throbber.
65 $session->executeScript($custom_ajax_progress_indicator_fullscreen);
66 hold_test_response(TRUE);
67 $page->clickLink('Content: Published (grouped)');
68 $this->assertNotNull($web_assert->waitForElement('css', '.custom-ajax-progress-fullscreen'), 'Custom ajaxProgressIndicatorFullscreen.');
69 hold_test_response(FALSE);
70 $this->waitForNoElement('.custom-ajax-progress-fullscreen');
71
72 // Test theming throbber message.
73 $web_assert->waitForElementVisible('css', '[data-drupal-selector="edit-options-group-info-add-group"]');
74 $session->executeScript($custom_ajax_progress_message);
75 hold_test_response(TRUE);
76 $page->pressButton('Add another item');
77 $this->assertNotNull($web_assert->waitForElement('css', '.ajax-progress-throbber .custom-ajax-progress-message'), 'Custom ajaxProgressMessage.');
78 hold_test_response(FALSE);
79 $this->waitForNoElement('.ajax-progress-throbber');
80
81 // Test theming throbber.
82 $web_assert->waitForElementVisible('css', '[data-drupal-selector="edit-options-group-info-group-items-3-title"]');
83 $session->executeScript($custom_ajax_progress_throbber);
84 hold_test_response(TRUE);
85 $page->pressButton('Add another item');
86 $this->assertNotNull($web_assert->waitForElement('css', '.custom-ajax-progress-throbber'), 'Custom ajaxProgressThrobber.');
87 hold_test_response(FALSE);
88 $this->waitForNoElement('.custom-ajax-progress-throbber');
89 }
90
91 /**
92 * Waits for an element to be removed from the page.
93 *
94 * @param string $selector
95 * CSS selector.
96 * @param int $timeout
97 * (optional) Timeout in milliseconds, defaults to 10000.
98 *
99 * @todo Remove in https://www.drupal.org/node/2892440.
100 */
101 protected function waitForNoElement($selector, $timeout = 10000) {
102 $condition = "(typeof jQuery !== 'undefined' && jQuery('$selector').length === 0)";
103 $this->assertJsCondition($condition, $timeout);
104 }
105
106 }