Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\Tests\views\FunctionalJavascript;
|
Chris@0
|
4
|
Chris@0
|
5 use Drupal\Core\Url;
|
Chris@17
|
6 use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
|
Chris@0
|
7 use Drupal\language\Entity\ConfigurableLanguage;
|
Chris@18
|
8 use Drupal\Tests\node\Traits\ContentTypeCreationTrait;
|
Chris@18
|
9 use Drupal\Tests\node\Traits\NodeCreationTrait;
|
Chris@0
|
10 use Drupal\views\Tests\ViewTestData;
|
Chris@0
|
11
|
Chris@0
|
12 /**
|
Chris@0
|
13 * Tests the basic AJAX functionality of the Glossary View.
|
Chris@0
|
14 *
|
Chris@0
|
15 * @group node
|
Chris@0
|
16 */
|
Chris@17
|
17 class GlossaryViewTest extends WebDriverTestBase {
|
Chris@0
|
18
|
Chris@0
|
19 use ContentTypeCreationTrait;
|
Chris@0
|
20 use NodeCreationTrait;
|
Chris@0
|
21
|
Chris@0
|
22 /**
|
Chris@0
|
23 * {@inheritdoc}
|
Chris@0
|
24 */
|
Chris@0
|
25 public static $modules = ['language', 'node', 'views', 'views_test_config'];
|
Chris@0
|
26
|
Chris@0
|
27 /**
|
Chris@0
|
28 * @var array
|
Chris@0
|
29 * The test Views to enable.
|
Chris@0
|
30 */
|
Chris@0
|
31 public static $testViews = ['test_glossary'];
|
Chris@0
|
32
|
Chris@0
|
33 /**
|
Chris@0
|
34 * {@inheritdoc}
|
Chris@0
|
35 */
|
Chris@0
|
36 protected function setUp() {
|
Chris@0
|
37 parent::setUp();
|
Chris@0
|
38
|
Chris@0
|
39 ViewTestData::createTestViews(get_class($this), ['views_test_config']);
|
Chris@0
|
40
|
Chris@0
|
41 // Create a Content type and some test nodes with titles that start with
|
Chris@0
|
42 // different letters.
|
Chris@0
|
43 $this->createContentType(['type' => 'page']);
|
Chris@0
|
44
|
Chris@0
|
45 $titles = [
|
Chris@0
|
46 'Page One',
|
Chris@0
|
47 'Page Two',
|
Chris@0
|
48 'Another page',
|
Chris@0
|
49 ];
|
Chris@0
|
50 foreach ($titles as $title) {
|
Chris@0
|
51 $this->createNode([
|
Chris@0
|
52 'title' => $title,
|
Chris@0
|
53 'language' => 'en',
|
Chris@0
|
54 ]);
|
Chris@0
|
55 $this->createNode([
|
Chris@0
|
56 'title' => $title,
|
Chris@0
|
57 'language' => 'nl',
|
Chris@0
|
58 ]);
|
Chris@0
|
59 }
|
Chris@0
|
60
|
Chris@0
|
61 // Create a user privileged enough to use exposed filters and view content.
|
Chris@0
|
62 $user = $this->drupalCreateUser([
|
Chris@0
|
63 'administer site configuration',
|
Chris@0
|
64 'access content',
|
Chris@0
|
65 'access content overview',
|
Chris@0
|
66 ]);
|
Chris@0
|
67 $this->drupalLogin($user);
|
Chris@0
|
68 }
|
Chris@0
|
69
|
Chris@0
|
70 /**
|
Chris@0
|
71 * Tests the AJAX callbacks for the glossary view.
|
Chris@0
|
72 */
|
Chris@0
|
73 public function testGlossaryDefault() {
|
Chris@0
|
74 // Visit the default Glossary page.
|
Chris@0
|
75 $url = Url::fromRoute('view.test_glossary.page_1');
|
Chris@0
|
76 $this->drupalGet($url);
|
Chris@0
|
77
|
Chris@0
|
78 $session = $this->getSession();
|
Chris@0
|
79 $web_assert = $this->assertSession();
|
Chris@0
|
80
|
Chris@0
|
81 $page = $session->getPage();
|
Chris@0
|
82 $rows = $page->findAll('css', '.view-test-glossary tr');
|
Chris@0
|
83 // We expect 2 rows plus the header row.
|
Chris@0
|
84 $this->assertCount(3, $rows);
|
Chris@0
|
85 // Click on the P link, this should show 4 rows plus the header row.
|
Chris@0
|
86 $page->clickLink('P');
|
Chris@0
|
87 $web_assert->assertWaitOnAjaxRequest();
|
Chris@0
|
88 $rows = $page->findAll('css', '.view-test-glossary tr');
|
Chris@0
|
89 $this->assertCount(5, $rows);
|
Chris@0
|
90 }
|
Chris@0
|
91
|
Chris@0
|
92 /**
|
Chris@0
|
93 * Test that the glossary also works on a language prefixed URL.
|
Chris@0
|
94 */
|
Chris@0
|
95 public function testGlossaryLanguagePrefix() {
|
Chris@14
|
96 ConfigurableLanguage::createFromLangcode('nl')->save();
|
Chris@0
|
97
|
Chris@0
|
98 $config = $this->config('language.negotiation');
|
Chris@0
|
99 $config->set('url.prefixes', ['en' => 'en', 'nl' => 'nl'])
|
Chris@0
|
100 ->save();
|
Chris@0
|
101
|
Chris@0
|
102 \Drupal::service('kernel')->rebuildContainer();
|
Chris@0
|
103
|
Chris@0
|
104 $url = Url::fromRoute('view.test_glossary.page_1');
|
Chris@0
|
105 $this->drupalGet($url);
|
Chris@0
|
106
|
Chris@0
|
107 $session = $this->getSession();
|
Chris@0
|
108 $web_assert = $this->assertSession();
|
Chris@0
|
109
|
Chris@0
|
110 $page = $session->getPage();
|
Chris@0
|
111
|
Chris@0
|
112 $rows = $page->findAll('css', '.view-test-glossary tr');
|
Chris@0
|
113 // We expect 2 rows plus the header row.
|
Chris@0
|
114 $this->assertCount(3, $rows);
|
Chris@0
|
115 // Click on the P link, this should show 4 rows plus the header row.
|
Chris@0
|
116 $page->clickLink('P');
|
Chris@0
|
117 $web_assert->assertWaitOnAjaxRequest();
|
Chris@0
|
118
|
Chris@0
|
119 $rows = $page->findAll('css', '.view-test-glossary tr');
|
Chris@0
|
120 $this->assertCount(5, $rows);
|
Chris@0
|
121 }
|
Chris@0
|
122
|
Chris@0
|
123 }
|