class BlockExposedFilterAJAXTest in Drupal 10
Same name and namespace in other branches
- 8 core/modules/views/tests/src/FunctionalJavascript/BlockExposedFilterAJAXTest.php \Drupal\Tests\views\FunctionalJavascript\BlockExposedFilterAJAXTest
- 9 core/modules/views/tests/src/FunctionalJavascript/BlockExposedFilterAJAXTest.php \Drupal\Tests\views\FunctionalJavascript\BlockExposedFilterAJAXTest
Tests the exposed filter ajax functionality in a block.
@group views
Hierarchy
- class \Drupal\Tests\BrowserTestBase extends \PHPUnit\Framework\TestCase uses \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, FunctionalTestSetupTrait, TestSetupTrait, BlockCreationTrait, ConfigTestTrait, ExtensionListTestTrait, ContentTypeCreationTrait, NodeCreationTrait, RandomGeneratorTrait, TestRequirementsTrait, PhpUnitWarnings, UiHelperTrait, UserCreationTrait, XdebugRequestTrait
- class \Drupal\FunctionalJavascriptTests\WebDriverTestBase
- class \Drupal\Tests\views\FunctionalJavascript\BlockExposedFilterAJAXTest uses ContentTypeCreationTrait, NodeCreationTrait
- class \Drupal\FunctionalJavascriptTests\WebDriverTestBase
Expanded class hierarchy of BlockExposedFilterAJAXTest
File
- core/
modules/ views/ tests/ src/ FunctionalJavascript/ BlockExposedFilterAJAXTest.php, line 15
Namespace
Drupal\Tests\views\FunctionalJavascriptView source
class BlockExposedFilterAJAXTest extends WebDriverTestBase {
use ContentTypeCreationTrait;
use NodeCreationTrait;
/**
* {@inheritdoc}
*/
protected static $modules = [
'node',
'views',
'block',
'views_test_config',
];
public static $testViews = [
'test_block_exposed_ajax',
'test_block_exposed_ajax_with_page',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
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',
]));
}
/**
* Tests if exposed filtering and reset works with a views block and ajax.
*/
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();
// Ensure that the Content we're testing for is present.
$html = $page
->getHtml();
$this
->assertStringContainsString('Page A', $html);
$this
->assertStringContainsString('Page B', $html);
$this
->assertStringContainsString('Article A', $html);
// Filter by page type.
$this
->submitForm([
'type' => 'page',
], 'Apply');
$this
->assertSession()
->waitForElementRemoved('xpath', '//*[text()="Article A"]');
// Verify that only the page nodes are present.
$html = $page
->getHtml();
$this
->assertStringContainsString('Page A', $html);
$this
->assertStringContainsString('Page B', $html);
$this
->assertStringNotContainsString('Article A', $html);
// Reset the form.
$this
->submitForm([], 'Reset');
// Assert we are still on the node page.
$html = $page
->getHtml();
// Repeat the original tests.
$this
->assertStringContainsString('Page A', $html);
$this
->assertStringContainsString('Page B', $html);
$this
->assertStringContainsString('Article A', $html);
$this
->assertSession()
->addressEquals('node/' . $node
->id());
$block
->delete();
// Do the same test with a block that has a page display to test the user
// is redirected to the page display.
$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');
}
}