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