You are here

public function ContainerRebuildWebTest::testContainerInvalidation in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/system/tests/src/Functional/DrupalKernel/ContainerRebuildWebTest.php \Drupal\Tests\system\Functional\DrupalKernel\ContainerRebuildWebTest::testContainerInvalidation()
  2. 9 core/modules/system/tests/src/Functional/DrupalKernel/ContainerRebuildWebTest.php \Drupal\Tests\system\Functional\DrupalKernel\ContainerRebuildWebTest::testContainerInvalidation()

Tests container invalidation.

File

core/modules/system/tests/src/Functional/DrupalKernel/ContainerRebuildWebTest.php, line 44

Class

ContainerRebuildWebTest
Ensures that the container rebuild works as expected.

Namespace

Drupal\Tests\system\Functional\DrupalKernel

Code

public function testContainerInvalidation() {
  $assert = $this
    ->assertSession();

  // Ensure that parameter is not set.
  $this
    ->drupalGet('<front>');
  $assert
    ->responseHeaderEquals('container_rebuild_test_parameter', NULL);

  // Ensure that after setting the parameter, without a container rebuild the
  // parameter is still not set.
  $this
    ->writeSettings([
    'settings' => [
      'container_rebuild_test_parameter' => (object) [
        'value' => 'rebuild_me_please',
        'required' => TRUE,
      ],
    ],
  ]);
  $this
    ->drupalGet('<front>');
  $assert
    ->responseHeaderEquals('container_rebuild_test_parameter', NULL);

  // Ensure that after container invalidation the parameter is set.
  \Drupal::service('kernel')
    ->invalidateContainer();
  $this
    ->drupalGet('<front>');
  $assert
    ->responseHeaderEquals('container_rebuild_test_parameter', 'rebuild_me_please');
}