class TourCacheTagsTest in Drupal 10
Same name and namespace in other branches
- 8 core/modules/tour/tests/src/Functional/TourCacheTagsTest.php \Drupal\Tests\tour\Functional\TourCacheTagsTest
- 9 core/modules/tour/tests/src/Functional/TourCacheTagsTest.php \Drupal\Tests\tour\Functional\TourCacheTagsTest
Tests the Tour entity's cache tags.
@group tour
Hierarchy
- class \Drupal\Tests\BrowserTestBase extends \PHPUnit\Framework\TestCase uses \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, FunctionalTestSetupTrait, TestSetupTrait, BlockCreationTrait, ConfigTestTrait, ExtensionListTestTrait, ContentTypeCreationTrait, NodeCreationTrait, RandomGeneratorTrait, TestRequirementsTrait, PhpUnitWarnings, UiHelperTrait, UserCreationTrait, XdebugRequestTrait
- class \Drupal\Tests\system\Functional\Cache\PageCacheTagsTestBase
- class \Drupal\Tests\tour\Functional\TourCacheTagsTest
- class \Drupal\Tests\system\Functional\Cache\PageCacheTagsTestBase
Expanded class hierarchy of TourCacheTagsTest
File
- core/
modules/ tour/ tests/ src/ Functional/ TourCacheTagsTest.php, line 16
Namespace
Drupal\Tests\tour\FunctionalView source
class TourCacheTagsTest extends PageCacheTagsTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'tour',
'tour_test',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
// Give anonymous users permission to view nodes, so that we can verify the
// cache tags of cached versions of node pages.
Role::load(RoleInterface::ANONYMOUS_ID)
->grantPermission('access tour')
->save();
}
/**
* Tests cache tags presence and invalidation of the Tour entity.
*
* Tests the following cache tags:
* - 'tour:<tour ID>'
*/
public function testRenderedTour() {
$url = Url::fromRoute('tour_test.1');
// Prime the page cache.
$this
->verifyPageCache($url, 'MISS');
// Verify a cache hit, but also the presence of the correct cache tags.
$expected_tags = [
'config:tour.tour.tour-test',
'config:user.role.anonymous',
'http_response',
'rendered',
];
$this
->verifyPageCache($url, 'HIT', $expected_tags);
// Verify that after modifying the tour, there is a cache miss.
Tour::load('tour-test')
->save();
$this
->verifyPageCache($url, 'MISS');
// Verify a cache hit.
$this
->verifyPageCache($url, 'HIT', $expected_tags);
// Verify that after deleting the tour, there is a cache miss.
Tour::load('tour-test')
->delete();
$this
->verifyPageCache($url, 'MISS');
// Verify a cache hit.
$expected_tags = [
'config:user.role.anonymous',
'http_response',
'rendered',
];
$this
->verifyPageCache($url, 'HIT', $expected_tags);
}
}