ClickSortingAJAXTest.php in Drupal 10
File
core/modules/views/tests/src/FunctionalJavascript/ClickSortingAJAXTest.php
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 ClickSortingAJAXTest extends WebDriverTestBase {
use ContentTypeCreationTrait;
use NodeCreationTrait;
protected static $modules = [
'node',
'views',
'views_test_config',
];
protected $defaultTheme = 'stark';
public static $testViews = [
'test_content_ajax',
];
protected function setUp() : void {
parent::setUp();
ViewTestData::createTestViews(self::class, [
'views_test_config',
]);
$this
->createContentType([
'type' => 'page',
]);
$this
->createNode([
'title' => 'Page A',
'changed' => REQUEST_TIME,
]);
$this
->createNode([
'title' => 'Page B',
'changed' => REQUEST_TIME + 1000,
]);
$user = $this
->drupalCreateUser([
'administer site configuration',
'access content',
'access content overview',
]);
$this
->drupalLogin($user);
}
public function testClickSorting() {
$this
->drupalGet('test-content-ajax');
$session_assert = $this
->assertSession();
$page = $this
->getSession()
->getPage();
$rows = $page
->findAll('css', 'tbody tr');
$this
->assertCount(2, $rows);
$this
->assertStringContainsString('Page B', $rows[0]
->getHtml());
$this
->assertStringContainsString('Page A', $rows[1]
->getHtml());
$page
->clickLink('Title');
$session_assert
->assertWaitOnAjaxRequest();
$rows = $page
->findAll('css', 'tbody tr');
$this
->assertCount(2, $rows);
$this
->assertStringContainsString('Page A', $rows[0]
->getHtml());
$this
->assertStringContainsString('Page B', $rows[1]
->getHtml());
}
}