3 namespace Drupal\Tests\views\FunctionalJavascript;
5 use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
6 use Drupal\simpletest\ContentTypeCreationTrait;
7 use Drupal\simpletest\NodeCreationTrait;
8 use Drupal\views\Tests\ViewTestData;
11 * Tests the click sorting AJAX functionality of Views exposed forms.
15 class ClickSortingAJAXTest extends WebDriverTestBase {
17 use ContentTypeCreationTrait;
18 use NodeCreationTrait;
23 public static $modules = ['node', 'views', 'views_test_config'];
25 public static $testViews = ['test_content_ajax'];
30 protected function setUp() {
33 ViewTestData::createTestViews(self::class, ['views_test_config']);
35 // Create a Content type and two test nodes.
36 $this->createContentType(['type' => 'page']);
37 $this->createNode(['title' => 'Page A', 'changed' => REQUEST_TIME]);
38 $this->createNode(['title' => 'Page B', 'changed' => REQUEST_TIME + 1000]);
40 // Create a user privileged enough to view content.
41 $user = $this->drupalCreateUser([
42 'administer site configuration',
44 'access content overview',
46 $this->drupalLogin($user);
50 * Tests if sorting via AJAX works for the "Content" View.
52 public function testClickSorting() {
53 // Visit the content page.
54 $this->drupalGet('test-content-ajax');
56 $session_assert = $this->assertSession();
58 $page = $this->getSession()->getPage();
60 // Ensure that the Content we're testing for is in the right order, default
61 // sorting is by changed timestamp so the last created node should be first.
62 /** @var \Behat\Mink\Element\NodeElement[] $rows */
63 $rows = $page->findAll('css', 'tbody tr');
64 $this->assertCount(2, $rows);
65 $this->assertContains('Page B', $rows[0]->getHtml());
66 $this->assertContains('Page A', $rows[1]->getHtml());
68 // Now sort by title and check if the order changed.
69 $page->clickLink('Title');
70 $session_assert->assertWaitOnAjaxRequest();
71 $rows = $page->findAll('css', 'tbody tr');
72 $this->assertCount(2, $rows);
73 $this->assertContains('Page A', $rows[0]->getHtml());
74 $this->assertContains('Page B', $rows[1]->getHtml());