3 namespace Drupal\Tests\views\FunctionalJavascript;
6 use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
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 WebDriverTestBase {
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'];
36 protected function setUp() {
39 ViewTestData::createTestViews(get_class($this), ['views_test_config']);
41 // Create a Content type and some test nodes with titles that start with
43 $this->createContentType(['type' => 'page']);
50 foreach ($titles as $title) {
61 // Create a user privileged enough to use exposed filters and view content.
62 $user = $this->drupalCreateUser([
63 'administer site configuration',
65 'access content overview',
67 $this->drupalLogin($user);
71 * Tests the AJAX callbacks for the glossary view.
73 public function testGlossaryDefault() {
74 // Visit the default Glossary page.
75 $url = Url::fromRoute('view.test_glossary.page_1');
76 $this->drupalGet($url);
78 $session = $this->getSession();
79 $web_assert = $this->assertSession();
81 $page = $session->getPage();
82 $rows = $page->findAll('css', '.view-test-glossary tr');
83 // We expect 2 rows plus the header row.
84 $this->assertCount(3, $rows);
85 // Click on the P link, this should show 4 rows plus the header row.
86 $page->clickLink('P');
87 $web_assert->assertWaitOnAjaxRequest();
88 $rows = $page->findAll('css', '.view-test-glossary tr');
89 $this->assertCount(5, $rows);
93 * Test that the glossary also works on a language prefixed URL.
95 public function testGlossaryLanguagePrefix() {
96 ConfigurableLanguage::createFromLangcode('nl')->save();
98 $config = $this->config('language.negotiation');
99 $config->set('url.prefixes', ['en' => 'en', 'nl' => 'nl'])
102 \Drupal::service('kernel')->rebuildContainer();
104 $url = Url::fromRoute('view.test_glossary.page_1');
105 $this->drupalGet($url);
107 $session = $this->getSession();
108 $web_assert = $this->assertSession();
110 $page = $session->getPage();
112 $rows = $page->findAll('css', '.view-test-glossary tr');
113 // We expect 2 rows plus the header row.
114 $this->assertCount(3, $rows);
115 // Click on the P link, this should show 4 rows plus the header row.
116 $page->clickLink('P');
117 $web_assert->assertWaitOnAjaxRequest();
119 $rows = $page->findAll('css', '.view-test-glossary tr');
120 $this->assertCount(5, $rows);