Upgraded drupal core with security updates
[yaffs-website] / web / core / tests / Drupal / FunctionalTests / Breadcrumb / Breadcrumb404Test.php
1 <?php
2
3 namespace Drupal\FunctionalTests\Breadcrumb;
4
5 use Drupal\simpletest\BlockCreationTrait;
6 use Drupal\Tests\BrowserTestBase;
7
8 /**
9  * Tests the breadcrumb of 404 pages.
10  *
11  * @group breadcrumb
12  */
13 class Breadcrumb404Test extends BrowserTestBase {
14
15   use BlockCreationTrait;
16
17   /**
18    * {@inheritdoc}
19    */
20   public static $modules = ['system', 'block'];
21
22   /**
23    * Tests that different 404s don't create unnecessary cache entries.
24    */
25   public function testBreadcrumbOn404Pages() {
26     $this->placeBlock('system_breadcrumb_block', ['id' => 'breadcrumb']);
27
28     // Prime the cache first.
29     $this->drupalGet('/not-found-1');
30     $base_count = count($this->getBreadcrumbCacheEntries());
31
32     $this->drupalGet('/not-found-2');
33     $next_count = count($this->getBreadcrumbCacheEntries());
34     $this->assertEquals($base_count, $next_count);
35
36     $this->drupalGet('/not-found-3');
37     $next_count = count($this->getBreadcrumbCacheEntries());
38     $this->assertEquals($base_count, $next_count);
39   }
40
41   /**
42    * Gets the breadcrumb cache entries.
43    *
44    * @return array
45    *   The breadcrumb cache entries.
46    */
47   protected function getBreadcrumbCacheEntries() {
48     $database = \Drupal::database();
49     $cache_entries = $database->select('cache_render')
50       ->fields('cache_render')
51       ->condition('cid', $database->escapeLike('entity_view:block:breadcrumb') . '%', 'LIKE')
52       ->execute()
53       ->fetchAllAssoc('cid');
54     return $cache_entries;
55   }
56
57 }