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