BlockFilterTest.php in Drupal 10
File
core/modules/block/tests/src/FunctionalJavascript/BlockFilterTest.php
View source
<?php
namespace Drupal\Tests\block\FunctionalJavascript;
use Behat\Mink\Element\NodeElement;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
class BlockFilterTest extends WebDriverTestBase {
protected static $modules = [
'user',
'block',
];
protected $defaultTheme = 'stark';
protected function setUp() : void {
parent::setUp();
$admin_user = $this
->drupalCreateUser([
'administer blocks',
]);
$this
->drupalLogin($admin_user);
}
public function testBlockFilter() {
$this
->drupalGet('admin/structure/block');
$assertSession = $this
->assertSession();
$session = $this
->getSession();
$page = $session
->getPage();
$page
->find('css', '#edit-blocks-region-header-title')
->click();
$filter = $assertSession
->waitForElement('css', '.block-filter-text');
$block_rows = $page
->findAll('css', '.block-add-table tbody tr');
$filter
->setValue('ad');
$session
->wait(10000, 'jQuery("#drupal-live-announce").html().indexOf("blocks are available") > -1');
$visible_rows = $this
->filterVisibleElements($block_rows);
if (count($block_rows) > 0) {
$this
->assertNotSameSize($block_rows, $visible_rows);
}
$expected_message = count($visible_rows) . ' blocks are available in the modified list.';
$assertSession
->elementTextContains('css', '#drupal-live-announce', $expected_message);
$filter
->setValue('Powered by');
$session
->wait(10000, 'jQuery("#drupal-live-announce").html().indexOf("block is available") > -1');
$visible_rows = $this
->filterVisibleElements($block_rows);
$this
->assertCount(1, $visible_rows);
$expected_message = '1 block is available in the modified list.';
$assertSession
->elementTextContains('css', '#drupal-live-announce', $expected_message);
$filter
->setValue('Pan-Galactic Gargle Blaster');
$session
->wait(10000, 'jQuery("#drupal-live-announce").html().indexOf("0 blocks are available") > -1');
$visible_rows = $this
->filterVisibleElements($block_rows);
$this
->assertCount(0, $visible_rows);
$expected_message = '0 blocks are available in the modified list.';
$assertSession
->elementTextContains('css', '#drupal-live-announce', $expected_message);
}
protected function filterVisibleElements(array $elements) {
$elements = array_filter($elements, function (NodeElement $element) {
return $element
->isVisible();
});
return $elements;
}
}