Chris@0: config('system.performance'); Chris@0: $config->set('cache.page.max_age', 300); Chris@0: $config->save(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Return the build id of the current form. Chris@0: */ Chris@0: protected function getFormBuildId() { Chris@0: $build_id_fields = $this->xpath('//input[@name="form_build_id"]'); Chris@0: $this->assertEquals(count($build_id_fields), 1, 'One form build id field on the page'); Chris@0: return $build_id_fields[0]->getValue(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Create a simple form, then submit the form via AJAX to change to it. Chris@0: */ Chris@0: public function testSimpleAJAXFormValue() { Chris@0: $this->drupalGet('ajax_forms_test_get_form'); Chris@0: $build_id_initial = $this->getFormBuildId(); Chris@0: Chris@0: // Changing the value of a select input element, triggers a AJAX Chris@0: // request/response. The callback on the form responds with three AJAX Chris@0: // commands: Chris@0: // - UpdateBuildIdCommand Chris@0: // - HtmlCommand Chris@0: // - DataCommand Chris@0: $session = $this->getSession(); Chris@0: $session->getPage()->selectFieldOption('select', 'green'); Chris@0: Chris@0: // Wait for the DOM to update. The HtmlCommand will update Chris@0: // #ajax_selected_color to reflect the color change. Chris@17: $green_span = $this->assertSession()->waitForElement('css', "#ajax_selected_color:contains('green')"); Chris@17: $this->assertNotNull($green_span, 'DOM update: The selected color SPAN is green.'); Chris@0: Chris@0: // Confirm the operation of the UpdateBuildIdCommand. Chris@0: $build_id_first_ajax = $this->getFormBuildId(); Chris@0: $this->assertNotEquals($build_id_initial, $build_id_first_ajax, 'Build id is changed in the form_build_id element on first AJAX submission'); Chris@0: Chris@0: // Changing the value of a select input element, triggers a AJAX Chris@0: // request/response. Chris@0: $session->getPage()->selectFieldOption('select', 'red'); Chris@0: Chris@0: // Wait for the DOM to update. Chris@17: $red_span = $this->assertSession()->waitForElement('css', "#ajax_selected_color:contains('red')"); Chris@17: $this->assertNotNull($red_span, 'DOM update: The selected color SPAN is red.'); Chris@0: Chris@0: // Confirm the operation of the UpdateBuildIdCommand. Chris@0: $build_id_second_ajax = $this->getFormBuildId(); Chris@0: $this->assertNotEquals($build_id_first_ajax, $build_id_second_ajax, 'Build id changes on subsequent AJAX submissions'); Chris@0: Chris@0: // Emulate a push of the reload button and then repeat the test sequence Chris@0: // this time with a page loaded from the cache. Chris@0: $session->reload(); Chris@0: $build_id_from_cache_initial = $this->getFormBuildId(); Chris@0: $this->assertEquals($build_id_initial, $build_id_from_cache_initial, 'Build id is the same as on the first request'); Chris@0: Chris@0: // Changing the value of a select input element, triggers a AJAX Chris@0: // request/response. Chris@0: $session->getPage()->selectFieldOption('select', 'green'); Chris@0: Chris@0: // Wait for the DOM to update. Chris@17: $green_span2 = $this->assertSession()->waitForElement('css', "#ajax_selected_color:contains('green')"); Chris@17: $this->assertNotNull($green_span2, 'DOM update: After reload - the selected color SPAN is green.'); Chris@0: Chris@0: $build_id_from_cache_first_ajax = $this->getFormBuildId(); Chris@0: $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'); Chris@0: $this->assertNotEquals($build_id_first_ajax, $build_id_from_cache_first_ajax, 'Build id from first user is not reused'); Chris@0: Chris@0: // Changing the value of a select input element, triggers a AJAX Chris@0: // request/response. Chris@0: $session->getPage()->selectFieldOption('select', 'red'); Chris@0: Chris@0: // Wait for the DOM to update. Chris@17: $red_span2 = $this->assertSession()->waitForElement('css', "#ajax_selected_color:contains('red')"); Chris@17: $this->assertNotNull($red_span2, 'DOM update: After reload - the selected color SPAN is red.'); Chris@0: Chris@0: $build_id_from_cache_second_ajax = $this->getFormBuildId(); Chris@0: $this->assertNotEquals($build_id_from_cache_first_ajax, $build_id_from_cache_second_ajax, 'Build id changes on subsequent AJAX submissions'); Chris@0: Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests that updating the text field trigger an AJAX request/response. Chris@0: * Chris@0: * @see \Drupal\system\Tests\Ajax\ElementValidationTest::testAjaxElementValidation() Chris@0: */ Chris@0: public function testAjaxElementValidation() { Chris@0: $this->drupalGet('ajax_validation_test'); Chris@0: // Changing the value of the textfield will trigger an AJAX Chris@0: // request/response. Chris@17: $field = $this->getSession()->getPage()->findField('drivertext'); Chris@17: $field->setValue('some dumb text'); Chris@17: $field->blur(); Chris@0: Chris@0: // When the AJAX command updates the DOM a