Chris@0: drupalCreateContentType(); Chris@0: $nodes_per_char = [ Chris@0: 'd' => 1, Chris@0: 'r' => 4, Chris@0: 'u' => 10, Chris@0: 'p' => 2, Chris@0: 'a' => 3, Chris@0: 'l' => 6, Chris@0: ]; Chris@0: $nodes_by_char = []; Chris@0: foreach ($nodes_per_char as $char => $count) { Chris@0: $setting = [ Chris@17: 'type' => $type->id(), Chris@0: ]; Chris@0: for ($i = 0; $i < $count; $i++) { Chris@0: $node = $setting; Chris@0: $node['title'] = $char . $this->randomString(3); Chris@0: $node = $this->drupalCreateNode($node); Chris@0: $nodes_by_char[$char][] = $node; Chris@0: } Chris@0: } Chris@0: Chris@0: // Execute glossary view Chris@0: $view = Views::getView('glossary'); Chris@0: $view->setDisplay('attachment_1'); Chris@0: $view->executeDisplay('attachment_1'); Chris@0: Chris@0: // Check that the amount of nodes per char. Chris@0: foreach ($view->result as $item) { Chris@0: $this->assertEqual($nodes_per_char[$item->title_truncated], $item->num_records); Chris@0: } Chris@0: Chris@0: // Enable the glossary to be displayed. Chris@0: $view->storage->enable()->save(); Chris@0: $this->container->get('router.builder')->rebuildIfNeeded(); Chris@0: $url = Url::fromRoute('view.glossary.page_1'); Chris@0: Chris@0: // Verify cache tags. Chris@0: $this->assertPageCacheContextsAndTags( Chris@0: $url, Chris@0: [ Chris@0: 'timezone', Chris@0: 'languages:' . LanguageInterface::TYPE_CONTENT, Chris@0: 'languages:' . LanguageInterface::TYPE_INTERFACE, Chris@0: 'theme', Chris@0: 'url', Chris@0: 'user.node_grants:view', Chris@0: 'user.permissions', Chris@0: 'route', Chris@0: ], Chris@0: [ Chris@0: 'config:views.view.glossary', Chris@0: // Listed for letter 'a' Chris@0: 'node:' . $nodes_by_char['a'][0]->id(), 'node:' . $nodes_by_char['a'][1]->id(), 'node:' . $nodes_by_char['a'][2]->id(), Chris@0: // Link for letter 'd'. Chris@0: 'node:1', Chris@0: // Link for letter 'p'. Chris@0: 'node:16', Chris@0: // Link for letter 'r'. Chris@0: 'node:2', Chris@0: // Link for letter 'l'. Chris@0: 'node:21', Chris@0: // Link for letter 'u'. Chris@0: 'node:6', Chris@0: 'node_list', Chris@0: 'user:0', Chris@0: 'user_list', Chris@0: 'http_response', Chris@0: 'rendered', Chris@0: // FinishResponseSubscriber adds this cache tag to responses that have Chris@0: // the 'user.permissions' cache context for anonymous users. Chris@0: 'config:user.role.anonymous', Chris@0: ] Chris@0: ); Chris@0: Chris@0: // Check the actual page response. Chris@0: $this->drupalGet($url); Chris@0: $this->assertResponse(200); Chris@0: foreach ($nodes_per_char as $char => $count) { Chris@0: $href = Url::fromRoute('view.glossary.page_1', ['arg_0' => $char])->toString(); Chris@17: $label = mb_strtoupper($char); Chris@0: // Get the summary link for a certain character. Filter by label and href Chris@0: // to ensure that both of them are correct. Chris@0: $result = $this->xpath('//a[contains(@href, :href) and normalize-space(text())=:label]/..', [':href' => $href, ':label' => $label]); Chris@0: $this->assertTrue(count($result)); Chris@0: // The rendered output looks like "X | (count)" so let's Chris@0: // figure out the int. Chris@0: $result_count = explode(' ', trim(str_replace(['|', '(', ')'], '', $result[0]->getText())))[1]; Chris@0: $this->assertEqual($result_count, $count, 'The expected number got rendered.'); Chris@0: } Chris@0: } Chris@0: Chris@0: }