3 namespace Drupal\Tests\views\FunctionalJavascript;
6 use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
7 use Drupal\language\Entity\ConfigurableLanguage;
8 use Drupal\simpletest\ContentTypeCreationTrait;
9 use Drupal\simpletest\NodeCreationTrait;
10 use Drupal\views\Tests\ViewTestData;
13 * Tests the basic AJAX functionality of the Glossary View.
17 class GlossaryViewTest extends JavascriptTestBase {
19 use ContentTypeCreationTrait;
20 use NodeCreationTrait;
25 public static $modules = ['language', 'node', 'views', 'views_test_config'];
29 * The test Views to enable.
31 public static $testViews = ['test_glossary'];
35 * The additional language to use.
42 protected function setUp() {
45 ViewTestData::createTestViews(get_class($this), ['views_test_config']);
47 // Create a Content type and some test nodes with titles that start with
49 $this->createContentType(['type' => 'page']);
56 foreach ($titles as $title) {
67 // Create a user privileged enough to use exposed filters and view content.
68 $user = $this->drupalCreateUser([
69 'administer site configuration',
71 'access content overview',
73 $this->drupalLogin($user);
77 * Tests the AJAX callbacks for the glossary view.
79 public function testGlossaryDefault() {
80 // Visit the default Glossary page.
81 $url = Url::fromRoute('view.test_glossary.page_1');
82 $this->drupalGet($url);
84 $session = $this->getSession();
85 $web_assert = $this->assertSession();
87 $page = $session->getPage();
88 $rows = $page->findAll('css', '.view-test-glossary tr');
89 // We expect 2 rows plus the header row.
90 $this->assertCount(3, $rows);
91 // Click on the P link, this should show 4 rows plus the header row.
92 $page->clickLink('P');
93 $web_assert->assertWaitOnAjaxRequest();
94 $rows = $page->findAll('css', '.view-test-glossary tr');
95 $this->assertCount(5, $rows);
99 * Test that the glossary also works on a language prefixed URL.
101 public function testGlossaryLanguagePrefix() {
102 $this->language = ConfigurableLanguage::createFromLangcode('nl')->save();
104 $config = $this->config('language.negotiation');
105 $config->set('url.prefixes', ['en' => 'en', 'nl' => 'nl'])
108 \Drupal::service('kernel')->rebuildContainer();
110 $url = Url::fromRoute('view.test_glossary.page_1');
111 $this->drupalGet($url);
113 $session = $this->getSession();
114 $web_assert = $this->assertSession();
116 $page = $session->getPage();
118 $rows = $page->findAll('css', '.view-test-glossary tr');
119 // We expect 2 rows plus the header row.
120 $this->assertCount(3, $rows);
121 // Click on the P link, this should show 4 rows plus the header row.
122 $page->clickLink('P');
123 $web_assert->assertWaitOnAjaxRequest();
125 $rows = $page->findAll('css', '.view-test-glossary tr');
126 $this->assertCount(5, $rows);