function ClickSortingAJAXTest::testClickSorting

Same name in other branches
  1. 8.9.x core/modules/views/tests/src/FunctionalJavascript/ClickSortingAJAXTest.php \Drupal\Tests\views\FunctionalJavascript\ClickSortingAJAXTest::testClickSorting()
  2. 10 core/modules/views/tests/src/FunctionalJavascript/ClickSortingAJAXTest.php \Drupal\Tests\views\FunctionalJavascript\ClickSortingAJAXTest::testClickSorting()
  3. 11.x core/modules/views/tests/src/FunctionalJavascript/ClickSortingAJAXTest.php \Drupal\Tests\views\FunctionalJavascript\ClickSortingAJAXTest::testClickSorting()

Tests if sorting via AJAX works for the "Content" View.

File

core/modules/views/tests/src/FunctionalJavascript/ClickSortingAJAXTest.php, line 57

Class

ClickSortingAJAXTest
Tests the click sorting AJAX functionality of Views exposed forms.

Namespace

Drupal\Tests\views\FunctionalJavascript

Code

public function testClickSorting() {
    // Visit the content page.
    $this->drupalGet('test-content-ajax');
    $session_assert = $this->assertSession();
    $page = $this->getSession()
        ->getPage();
    // Ensure that the Content we're testing for is in the right order, default
    // sorting is by changed timestamp so the last created node should be first.
    
    /** @var \Behat\Mink\Element\NodeElement[] $rows */
    $rows = $page->findAll('css', 'tbody tr');
    $this->assertCount(2, $rows);
    $this->assertStringContainsString('Page B', $rows[0]->getHtml());
    $this->assertStringContainsString('Page A', $rows[1]->getHtml());
    // Now sort by title and check if the order changed.
    $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());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.