class ClickSortingAJAXTest
Same name and namespace in other branches
- 11.x core/modules/views/tests/src/FunctionalJavascript/ClickSortingAJAXTest.php \Drupal\Tests\views\FunctionalJavascript\ClickSortingAJAXTest
Tests the click sorting AJAX functionality of Views exposed forms.
@group views
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\FunctionalTests\AssertLegacyTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait implements \PHPUnit\Framework\TestCase
- class \Drupal\FunctionalJavascriptTests\WebDriverTestBase implements \Drupal\Tests\BrowserTestBase
- class \Drupal\Tests\views\FunctionalJavascript\ClickSortingAJAXTest uses \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\node\Traits\NodeCreationTrait implements \Drupal\FunctionalJavascriptTests\WebDriverTestBase
- class \Drupal\FunctionalJavascriptTests\WebDriverTestBase implements \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of ClickSortingAJAXTest
File
-
core/
modules/ views/ tests/ src/ FunctionalJavascript/ ClickSortingAJAXTest.php, line 15
Namespace
Drupal\Tests\views\FunctionalJavascriptView source
class ClickSortingAJAXTest extends WebDriverTestBase {
use ContentTypeCreationTrait;
use NodeCreationTrait;
/**
* {@inheritdoc}
*/
protected static $modules = [
'node',
'views',
'views_test_config',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
public static $testViews = [
'test_content_ajax',
];
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
ViewTestData::createTestViews(self::class, [
'views_test_config',
]);
// Create a Content type and two test nodes.
$this->createContentType([
'type' => 'page',
]);
$this->createNode([
'title' => 'Page A',
'changed' => REQUEST_TIME,
]);
$this->createNode([
'title' => 'Page B',
'changed' => REQUEST_TIME + 1000,
]);
// Create a user privileged enough to view content.
$user = $this->drupalCreateUser([
'administer site configuration',
'access content',
'access content overview',
]);
$this->drupalLogin($user);
}
/**
* Tests if sorting via AJAX works for the "Content" View.
*/
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.