Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / tour / tests / src / Functional / TourCacheTagsTest.php
1 <?php
2
3 namespace Drupal\Tests\tour\Functional;
4
5 use Drupal\Core\Url;
6 use Drupal\Tests\system\Functional\Cache\PageCacheTagsTestBase;
7 use Drupal\tour\Entity\Tour;
8 use Drupal\user\Entity\Role;
9 use Drupal\user\RoleInterface;
10
11 /**
12  * Tests the Tour entity's cache tags.
13  *
14  * @group tour
15  */
16 class TourCacheTagsTest extends PageCacheTagsTestBase {
17
18   /**
19    * {@inheritdoc}
20    */
21   public static $modules = ['tour', 'tour_test'];
22
23   /**
24    * {@inheritdoc}
25    */
26   protected function setUp() {
27     parent::setUp();
28
29     // Give anonymous users permission to view nodes, so that we can verify the
30     // cache tags of cached versions of node pages.
31     Role::load(RoleInterface::ANONYMOUS_ID)->grantPermission('access tour')
32       ->save();
33   }
34
35   /**
36    * Tests cache tags presence and invalidation of the Tour entity.
37    *
38    * Tests the following cache tags:
39    * - 'tour:<tour ID>'
40    */
41   public function testRenderedTour() {
42     $url = Url::fromRoute('tour_test.1');
43
44     // Prime the page cache.
45     $this->verifyPageCache($url, 'MISS');
46
47     // Verify a cache hit, but also the presence of the correct cache tags.
48     $expected_tags = [
49       'config:tour.tour.tour-test',
50       'config:user.role.anonymous',
51       'http_response',
52       'rendered',
53     ];
54     $this->verifyPageCache($url, 'HIT', $expected_tags);
55
56     // Verify that after modifying the tour, there is a cache miss.
57     $this->pass('Test modification of tour.', 'Debug');
58     Tour::load('tour-test')->save();
59     $this->verifyPageCache($url, 'MISS');
60
61     // Verify a cache hit.
62     $this->verifyPageCache($url, 'HIT', $expected_tags);
63
64     // Verify that after deleting the tour, there is a cache miss.
65     $this->pass('Test deletion of tour.', 'Debug');
66     Tour::load('tour-test')->delete();
67     $this->verifyPageCache($url, 'MISS');
68
69     // Verify a cache hit.
70     $expected_tags = [
71       'config:user.role.anonymous',
72       'http_response',
73       'rendered',
74     ];
75     $this->verifyPageCache($url, 'HIT', $expected_tags);
76   }
77
78 }