085fd821d527f52df4c89a55dcd2b34307c4f625
[yaffs-website] / web / core / modules / views / tests / src / FunctionalJavascript / ClickSortingAJAXTest.php
1 <?php
2
3 namespace Drupal\Tests\views\FunctionalJavascript;
4
5 use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
6 use Drupal\simpletest\ContentTypeCreationTrait;
7 use Drupal\simpletest\NodeCreationTrait;
8 use Drupal\views\Tests\ViewTestData;
9
10 /**
11  * Tests the click sorting AJAX functionality of Views exposed forms.
12  *
13  * @group views
14  */
15 class ClickSortingAJAXTest extends WebDriverTestBase {
16
17   use ContentTypeCreationTrait;
18   use NodeCreationTrait;
19
20   /**
21    * {@inheritdoc}
22    */
23   public static $modules = ['node', 'views', 'views_test_config'];
24
25   public static $testViews = ['test_content_ajax'];
26
27   /**
28    * {@inheritdoc}
29    */
30   protected function setUp() {
31     parent::setUp();
32
33     ViewTestData::createTestViews(self::class, ['views_test_config']);
34
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]);
39
40     // Create a user privileged enough to view content.
41     $user = $this->drupalCreateUser([
42       'administer site configuration',
43       'access content',
44       'access content overview',
45     ]);
46     $this->drupalLogin($user);
47   }
48
49   /**
50    * Tests if sorting via AJAX works for the "Content" View.
51    */
52   public function testClickSorting() {
53     // Visit the content page.
54     $this->drupalGet('test-content-ajax');
55
56     $session_assert = $this->assertSession();
57
58     $page = $this->getSession()->getPage();
59
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());
67
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());
75   }
76
77 }