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

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents 4c8ae668cc8c
children
comparison
equal deleted inserted replaced
16:c2387f117808 17:129ea1e6d783
1 <?php 1 <?php
2 2
3 namespace Drupal\FunctionalJavascriptTests\Ajax; 3 namespace Drupal\FunctionalJavascriptTests\Ajax;
4 4
5 use Drupal\FunctionalJavascriptTests\JavascriptTestBase; 5 use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
6 6
7 /** 7 /**
8 * Performs tests on AJAX forms in cached pages. 8 * Performs tests on AJAX forms in cached pages.
9 * 9 *
10 * @group Ajax 10 * @group Ajax
11 */ 11 */
12 class AjaxFormPageCacheTest extends JavascriptTestBase { 12 class AjaxFormPageCacheTest extends WebDriverTestBase {
13 13
14 /** 14 /**
15 * {@inheritdoc} 15 * {@inheritdoc}
16 */ 16 */
17 public static $modules = ['ajax_test', 'ajax_forms_test']; 17 public static $modules = ['ajax_test', 'ajax_forms_test'];
39 /** 39 /**
40 * Create a simple form, then submit the form via AJAX to change to it. 40 * Create a simple form, then submit the form via AJAX to change to it.
41 */ 41 */
42 public function testSimpleAJAXFormValue() { 42 public function testSimpleAJAXFormValue() {
43 $this->drupalGet('ajax_forms_test_get_form'); 43 $this->drupalGet('ajax_forms_test_get_form');
44 $this->assertEquals($this->drupalGetHeader('X-Drupal-Cache'), 'MISS', 'Page was not cached.');
45 $build_id_initial = $this->getFormBuildId(); 44 $build_id_initial = $this->getFormBuildId();
46 45
47 // Changing the value of a select input element, triggers a AJAX 46 // Changing the value of a select input element, triggers a AJAX
48 // request/response. The callback on the form responds with three AJAX 47 // request/response. The callback on the form responds with three AJAX
49 // commands: 48 // commands:
53 $session = $this->getSession(); 52 $session = $this->getSession();
54 $session->getPage()->selectFieldOption('select', 'green'); 53 $session->getPage()->selectFieldOption('select', 'green');
55 54
56 // Wait for the DOM to update. The HtmlCommand will update 55 // Wait for the DOM to update. The HtmlCommand will update
57 // #ajax_selected_color to reflect the color change. 56 // #ajax_selected_color to reflect the color change.
58 $green_div = $this->assertSession()->waitForElement('css', "#ajax_selected_color div:contains('green')"); 57 $green_span = $this->assertSession()->waitForElement('css', "#ajax_selected_color:contains('green')");
59 $this->assertNotNull($green_div, 'DOM update: The selected color DIV is green.'); 58 $this->assertNotNull($green_span, 'DOM update: The selected color SPAN is green.');
60 59
61 // Confirm the operation of the UpdateBuildIdCommand. 60 // Confirm the operation of the UpdateBuildIdCommand.
62 $build_id_first_ajax = $this->getFormBuildId(); 61 $build_id_first_ajax = $this->getFormBuildId();
63 $this->assertNotEquals($build_id_initial, $build_id_first_ajax, 'Build id is changed in the form_build_id element on first AJAX submission'); 62 $this->assertNotEquals($build_id_initial, $build_id_first_ajax, 'Build id is changed in the form_build_id element on first AJAX submission');
64 63
65 // Changing the value of a select input element, triggers a AJAX 64 // Changing the value of a select input element, triggers a AJAX
66 // request/response. 65 // request/response.
67 $session->getPage()->selectFieldOption('select', 'red'); 66 $session->getPage()->selectFieldOption('select', 'red');
68 67
69 // Wait for the DOM to update. 68 // Wait for the DOM to update.
70 $red_div = $this->assertSession()->waitForElement('css', "#ajax_selected_color div:contains('red')"); 69 $red_span = $this->assertSession()->waitForElement('css', "#ajax_selected_color:contains('red')");
71 $this->assertNotNull($red_div, 'DOM update: The selected color DIV is red.'); 70 $this->assertNotNull($red_span, 'DOM update: The selected color SPAN is red.');
72 71
73 // Confirm the operation of the UpdateBuildIdCommand. 72 // Confirm the operation of the UpdateBuildIdCommand.
74 $build_id_second_ajax = $this->getFormBuildId(); 73 $build_id_second_ajax = $this->getFormBuildId();
75 $this->assertNotEquals($build_id_first_ajax, $build_id_second_ajax, 'Build id changes on subsequent AJAX submissions'); 74 $this->assertNotEquals($build_id_first_ajax, $build_id_second_ajax, 'Build id changes on subsequent AJAX submissions');
76 75
77 // Emulate a push of the reload button and then repeat the test sequence 76 // Emulate a push of the reload button and then repeat the test sequence
78 // this time with a page loaded from the cache. 77 // this time with a page loaded from the cache.
79 $session->reload(); 78 $session->reload();
80 $this->assertEquals($this->drupalGetHeader('X-Drupal-Cache'), 'HIT', 'Page was cached.');
81 $build_id_from_cache_initial = $this->getFormBuildId(); 79 $build_id_from_cache_initial = $this->getFormBuildId();
82 $this->assertEquals($build_id_initial, $build_id_from_cache_initial, 'Build id is the same as on the first request'); 80 $this->assertEquals($build_id_initial, $build_id_from_cache_initial, 'Build id is the same as on the first request');
83 81
84 // Changing the value of a select input element, triggers a AJAX 82 // Changing the value of a select input element, triggers a AJAX
85 // request/response. 83 // request/response.
86 $session->getPage()->selectFieldOption('select', 'green'); 84 $session->getPage()->selectFieldOption('select', 'green');
87 85
88 // Wait for the DOM to update. 86 // Wait for the DOM to update.
89 $green_div2 = $this->assertSession()->waitForElement('css', "#ajax_selected_color div:contains('green')"); 87 $green_span2 = $this->assertSession()->waitForElement('css', "#ajax_selected_color:contains('green')");
90 $this->assertNotNull($green_div2, 'DOM update: After reload - the selected color DIV is green.'); 88 $this->assertNotNull($green_span2, 'DOM update: After reload - the selected color SPAN is green.');
91 89
92 $build_id_from_cache_first_ajax = $this->getFormBuildId(); 90 $build_id_from_cache_first_ajax = $this->getFormBuildId();
93 $this->assertNotEquals($build_id_from_cache_initial, $build_id_from_cache_first_ajax, 'Build id is changed in the simpletest-DOM on first AJAX submission'); 91 $this->assertNotEquals($build_id_from_cache_initial, $build_id_from_cache_first_ajax, 'Build id is changed in the simpletest-DOM on first AJAX submission');
94 $this->assertNotEquals($build_id_first_ajax, $build_id_from_cache_first_ajax, 'Build id from first user is not reused'); 92 $this->assertNotEquals($build_id_first_ajax, $build_id_from_cache_first_ajax, 'Build id from first user is not reused');
95 93
96 // Changing the value of a select input element, triggers a AJAX 94 // Changing the value of a select input element, triggers a AJAX
97 // request/response. 95 // request/response.
98 $session->getPage()->selectFieldOption('select', 'red'); 96 $session->getPage()->selectFieldOption('select', 'red');
99 97
100 // Wait for the DOM to update. 98 // Wait for the DOM to update.
101 $red_div2 = $this->assertSession()->waitForElement('css', "#ajax_selected_color div:contains('red')"); 99 $red_span2 = $this->assertSession()->waitForElement('css', "#ajax_selected_color:contains('red')");
102 $this->assertNotNull($red_div2, 'DOM update: After reload - the selected color DIV is red.'); 100 $this->assertNotNull($red_span2, 'DOM update: After reload - the selected color SPAN is red.');
103 101
104 $build_id_from_cache_second_ajax = $this->getFormBuildId(); 102 $build_id_from_cache_second_ajax = $this->getFormBuildId();
105 $this->assertNotEquals($build_id_from_cache_first_ajax, $build_id_from_cache_second_ajax, 'Build id changes on subsequent AJAX submissions'); 103 $this->assertNotEquals($build_id_from_cache_first_ajax, $build_id_from_cache_second_ajax, 'Build id changes on subsequent AJAX submissions');
106 104
107 } 105 }
113 */ 111 */
114 public function testAjaxElementValidation() { 112 public function testAjaxElementValidation() {
115 $this->drupalGet('ajax_validation_test'); 113 $this->drupalGet('ajax_validation_test');
116 // Changing the value of the textfield will trigger an AJAX 114 // Changing the value of the textfield will trigger an AJAX
117 // request/response. 115 // request/response.
118 $this->getSession()->getPage()->fillField('drivertext', 'some dumb text'); 116 $field = $this->getSession()->getPage()->findField('drivertext');
117 $field->setValue('some dumb text');
118 $field->blur();
119 119
120 // When the AJAX command updates the DOM a <ul> unsorted list 120 // When the AJAX command updates the DOM a <ul> unsorted list
121 // "message__list" structure will appear on the page echoing back the 121 // "message__list" structure will appear on the page echoing back the
122 // "some dumb text" message. 122 // "some dumb text" message.
123 $placeholder = $this->assertSession()->waitForElement('css', "ul.messages__list li.messages__item em:contains('some dumb text')"); 123 $placeholder = $this->assertSession()->waitForElement('css', "ul.messages__list li.messages__item em:contains('some dumb text')");