View source
<?php
namespace Drupal\Tests\views\FunctionalJavascript;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
use Drupal\Tests\node\Traits\ContentTypeCreationTrait;
use Drupal\Tests\node\Traits\NodeCreationTrait;
use Drupal\views\Tests\ViewTestData;
class BlockExposedFilterAJAXTest extends WebDriverTestBase {
use ContentTypeCreationTrait;
use NodeCreationTrait;
protected static $modules = [
'node',
'views',
'block',
'views_test_config',
];
public static $testViews = [
'test_block_exposed_ajax',
'test_block_exposed_ajax_with_page',
];
protected $defaultTheme = 'stark';
protected function setUp() : void {
parent::setUp();
ViewTestData::createTestViews(self::class, [
'views_test_config',
]);
$this
->createContentType([
'type' => 'page',
]);
$this
->createContentType([
'type' => 'article',
]);
$this
->createNode([
'title' => 'Page A',
]);
$this
->createNode([
'title' => 'Page B',
]);
$this
->createNode([
'title' => 'Article A',
'type' => 'article',
]);
$this
->drupalLogin($this
->drupalCreateUser([
'access content',
]));
}
public function testExposedFilteringAndReset() {
$node = $this
->createNode();
$block = $this
->drupalPlaceBlock('views_block:test_block_exposed_ajax-block_1');
$this
->drupalGet($node
->toUrl());
$page = $this
->getSession()
->getPage();
$html = $page
->getHtml();
$this
->assertStringContainsString('Page A', $html);
$this
->assertStringContainsString('Page B', $html);
$this
->assertStringContainsString('Article A', $html);
$this
->submitForm([
'type' => 'page',
], 'Apply');
$this
->assertSession()
->waitForElementRemoved('xpath', '//*[text()="Article A"]');
$html = $page
->getHtml();
$this
->assertStringContainsString('Page A', $html);
$this
->assertStringContainsString('Page B', $html);
$this
->assertStringNotContainsString('Article A', $html);
$this
->submitForm([], 'Reset');
$html = $page
->getHtml();
$this
->assertStringContainsString('Page A', $html);
$this
->assertStringContainsString('Page B', $html);
$this
->assertStringContainsString('Article A', $html);
$this
->assertSession()
->addressEquals('node/' . $node
->id());
$block
->delete();
$this
->drupalPlaceBlock('views_block:test_block_exposed_ajax_with_page-block_1');
$this
->drupalGet($node
->toUrl());
$this
->submitForm([
'type' => 'page',
], 'Apply');
$this
->assertSession()
->waitForElementRemoved('xpath', '//*[text()="Article A"]');
$this
->submitForm([], 'Reset');
$this
->assertSession()
->addressEquals('some-path');
}
}