Newer
Older
Alex Pott
committed
<?php
namespace Drupal\Tests\views\FunctionalJavascript;
use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
Alex Pott
committed
use Drupal\simpletest\ContentTypeCreationTrait;
use Drupal\simpletest\NodeCreationTrait;
use Drupal\views\Tests\ViewTestData;
/**
* Tests the click sorting AJAX functionality of Views exposed forms.
*
* @group views
*/
class ClickSortingAJAXTest extends JavascriptTestBase {
Alex Pott
committed
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
use ContentTypeCreationTrait;
use NodeCreationTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['node', 'views', 'views_test_config'];
public static $testViews = ['test_content_ajax'];
/**
* {@inheritdoc}
*/
protected function setUp() {
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->assertContains('Page B', $rows[0]->getHtml());
$this->assertContains('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->assertContains('Page A', $rows[0]->getHtml());
$this->assertContains('Page B', $rows[1]->getHtml());
}
}