3 namespace Drupal\Tests\tour\Functional;
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;
12 * Tests the Tour entity's cache tags.
16 class TourCacheTagsTest extends PageCacheTagsTestBase {
21 public static $modules = ['tour', 'tour_test'];
26 protected function setUp() {
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')
36 * Tests cache tags presence and invalidation of the Tour entity.
38 * Tests the following cache tags:
41 public function testRenderedTour() {
42 $url = Url::fromRoute('tour_test.1');
44 // Prime the page cache.
45 $this->verifyPageCache($url, 'MISS');
47 // Verify a cache hit, but also the presence of the correct cache tags.
49 'config:tour.tour.tour-test',
50 'config:user.role.anonymous',
54 $this->verifyPageCache($url, 'HIT', $expected_tags);
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');
61 // Verify a cache hit.
62 $this->verifyPageCache($url, 'HIT', $expected_tags);
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');
69 // Verify a cache hit.
71 'config:user.role.anonymous',
75 $this->verifyPageCache($url, 'HIT', $expected_tags);