Chris@17: get('form'); Chris@17: $this->drupalLogin($this->rootUser); Chris@17: Chris@17: // Ensure that the cache is empty. Chris@17: $this->assertEqual(0, count($key_value_expirable->getAll())); Chris@17: Chris@17: // Visit an AJAX form that is not cached, 3 times. Chris@17: $uncached_form_url = Url::fromRoute('ajax_forms_test.commands_form'); Chris@17: $this->drupalGet($uncached_form_url); Chris@17: $this->drupalGet($uncached_form_url); Chris@17: $this->drupalGet($uncached_form_url); Chris@17: Chris@17: // The number of cache entries should not have changed. Chris@17: $this->assertEqual(0, count($key_value_expirable->getAll())); Chris@17: } Chris@17: Chris@17: /** Chris@17: * Tests AJAX forms in blocks. Chris@17: */ Chris@17: public function testBlockForms() { Chris@17: $this->container->get('module_installer')->install(['block', 'search']); Chris@17: $this->rebuildContainer(); Chris@17: $this->container->get('router.builder')->rebuild(); Chris@17: $this->drupalLogin($this->rootUser); Chris@17: Chris@17: $this->drupalPlaceBlock('search_form_block', ['weight' => -5]); Chris@17: $this->drupalPlaceBlock('ajax_forms_test_block'); Chris@17: Chris@17: $this->drupalGet(''); Chris@17: $session = $this->getSession(); Chris@17: Chris@17: // Select first option and trigger ajax update. Chris@17: $session->getPage()->selectFieldOption('edit-test1', 'option1'); Chris@17: Chris@17: // DOM update: The InsertCommand in the AJAX response changes the text Chris@17: // in the option element to 'Option1!!!'. Chris@17: $opt1_selector = $this->assertSession()->waitForElement('css', "select[data-drupal-selector='edit-test1'] option:contains('Option 1!!!')"); Chris@17: $this->assertNotEmpty($opt1_selector); Chris@17: $this->assertTrue($opt1_selector->isSelected()); Chris@17: Chris@17: // Confirm option 3 exists. Chris@17: $page = $session->getPage(); Chris@17: $opt3_selector = $page->find('xpath', '//select[@data-drupal-selector="edit-test1"]//option[@value="option3"]'); Chris@17: $this->assertNotEmpty($opt3_selector); Chris@17: Chris@17: // Confirm success message appears after a submit. Chris@17: $page->findButton('edit-submit')->click(); Chris@17: $this->assertSession()->waitForButton('edit-submit'); Chris@17: $updated_page = $session->getPage(); Chris@17: $updated_page->hasContent('Submission successful.'); Chris@17: } Chris@17: Chris@17: /** Chris@17: * Tests AJAX forms on pages with a query string. Chris@17: */ Chris@17: public function testQueryString() { Chris@17: $this->container->get('module_installer')->install(['block']); Chris@17: $this->drupalLogin($this->rootUser); Chris@17: Chris@17: $this->drupalPlaceBlock('ajax_forms_test_block'); Chris@17: Chris@17: $url = Url::fromRoute('entity.user.canonical', ['user' => $this->rootUser->id()], ['query' => ['foo' => 'bar']]); Chris@17: $this->drupalGet($url); Chris@17: Chris@17: $session = $this->getSession(); Chris@17: // Select first option and trigger ajax update. Chris@17: $session->getPage()->selectFieldOption('edit-test1', 'option1'); Chris@17: Chris@17: // DOM update: The InsertCommand in the AJAX response changes the text Chris@17: // in the option element to 'Option1!!!'. Chris@17: $opt1_selector = $this->assertSession()->waitForElement('css', "option:contains('Option 1!!!')"); Chris@17: $this->assertNotEmpty($opt1_selector); Chris@17: Chris@17: $url->setOption('query', [ Chris@17: 'foo' => 'bar', Chris@17: FormBuilderInterface::AJAX_FORM_REQUEST => 1, Chris@17: MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax', Chris@17: ]); Chris@17: $this->assertUrl($url); Chris@17: } Chris@17: Chris@17: }