Same filename and directory in other branches
- 8.9.x core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxFormCacheTest.php
- 9 core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxFormCacheTest.php
Namespace
Drupal\FunctionalJavascriptTests\Ajax
File
core/tests/Drupal/FunctionalJavascriptTests/Ajax/AjaxFormCacheTest.php
View source
<?php
declare (strict_types=1);
namespace Drupal\FunctionalJavascriptTests\Ajax;
use Drupal\Core\Url;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
class AjaxFormCacheTest extends WebDriverTestBase {
protected static $modules = [
'ajax_test',
'ajax_forms_test',
];
protected $defaultTheme = 'stark';
public function testFormCacheUsage() {
$key_value_expirable = \Drupal::service('keyvalue.expirable')
->get('form');
$this
->drupalLogin($this->rootUser);
$this
->assertCount(0, $key_value_expirable
->getAll());
$uncached_form_url = Url::fromRoute('ajax_forms_test.commands_form');
$this
->drupalGet($uncached_form_url);
$this
->drupalGet($uncached_form_url);
$this
->drupalGet($uncached_form_url);
$this
->assertCount(0, $key_value_expirable
->getAll());
}
public function testBlockForms() {
$this->container
->get('module_installer')
->install([
'block',
'search',
]);
$this
->rebuildContainer();
$this
->drupalLogin($this->rootUser);
$this
->drupalPlaceBlock('search_form_block', [
'weight' => -5,
]);
$this
->drupalPlaceBlock('ajax_forms_test_block');
$this
->drupalGet('');
$session = $this
->getSession();
$session
->getPage()
->selectFieldOption('edit-test1', 'option1');
$opt1_selector = $this
->assertSession()
->waitForElement('css', "select[data-drupal-selector='edit-test1'] option:contains('Option 1!!!')");
$this
->assertNotEmpty($opt1_selector);
$this
->assertTrue($opt1_selector
->isSelected());
$page = $session
->getPage();
$opt3_selector = $page
->find('xpath', '//select[@data-drupal-selector="edit-test1"]//option[@value="option3"]');
$this
->assertNotEmpty($opt3_selector);
$page
->findButton('edit-submit')
->click();
$this
->assertSession()
->waitForButton('edit-submit');
$updated_page = $session
->getPage();
$updated_page
->hasContent('Submission successful.');
}
public function testQueryString() {
$this->container
->get('module_installer')
->install([
'block',
]);
$this
->drupalLogin($this->rootUser);
$this
->drupalPlaceBlock('ajax_forms_test_block');
$url = Url::fromRoute('entity.user.canonical', [
'user' => $this->rootUser
->id(),
], [
'query' => [
'foo' => 'bar',
],
]);
$this
->drupalGet($url);
$session = $this
->getSession();
$session
->getPage()
->selectFieldOption('edit-test1', 'option1');
$opt1_selector = $this
->assertSession()
->waitForElement('css', "option:contains('Option 1!!!')");
$this
->assertNotEmpty($opt1_selector);
$url
->setOption('query', [
'foo' => 'bar',
]);
$this
->assertSession()
->addressEquals($url);
}
}
Classes