Breadcrumb404Test.php 1.5 KB

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