3611829e8c9479a0f0723978559d8018d0512cc7
[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\JavascriptTestBase;
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 JavascriptTestBase {
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    * @var
35    * The additional language to use.
36    */
37   protected $language;
38
39   /**
40    * {@inheritdoc}
41    */
42   protected function setUp() {
43     parent::setUp();
44
45     ViewTestData::createTestViews(get_class($this), ['views_test_config']);
46
47     // Create a Content type and some test nodes with titles that start with
48     // different letters.
49     $this->createContentType(['type' => 'page']);
50
51     $titles = [
52       'Page One',
53       'Page Two',
54       'Another page',
55     ];
56     foreach ($titles as $title) {
57       $this->createNode([
58         'title' => $title,
59         'language' => 'en',
60       ]);
61       $this->createNode([
62         'title' => $title,
63         'language' => 'nl',
64       ]);
65     }
66
67     // Create a user privileged enough to use exposed filters and view content.
68     $user = $this->drupalCreateUser([
69       'administer site configuration',
70       'access content',
71       'access content overview',
72     ]);
73     $this->drupalLogin($user);
74   }
75
76   /**
77    * Tests the AJAX callbacks for the glossary view.
78    */
79   public function testGlossaryDefault() {
80     // Visit the default Glossary page.
81     $url = Url::fromRoute('view.test_glossary.page_1');
82     $this->drupalGet($url);
83
84     $session = $this->getSession();
85     $web_assert = $this->assertSession();
86
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);
96   }
97
98   /**
99    * Test that the glossary also works on a language prefixed URL.
100    */
101   public function testGlossaryLanguagePrefix() {
102     $this->language = ConfigurableLanguage::createFromLangcode('nl')->save();
103
104     $config = $this->config('language.negotiation');
105     $config->set('url.prefixes', ['en' => 'en', 'nl' => 'nl'])
106       ->save();
107
108     \Drupal::service('kernel')->rebuildContainer();
109
110     $url = Url::fromRoute('view.test_glossary.page_1');
111     $this->drupalGet($url);
112
113     $session = $this->getSession();
114     $web_assert = $this->assertSession();
115
116     $page = $session->getPage();
117
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();
124
125     $rows = $page->findAll('css', '.view-test-glossary tr');
126     $this->assertCount(5, $rows);
127   }
128
129 }