CacheableResponseSubscriberTest.php in Purge 8.3        
                          
                  
                        
  
  
  
  
  
File
  tests/src/Kernel/TagsHeader/CacheableResponseSubscriberTest.php
  
    View source  
  <?php
namespace Drupal\Tests\purge\Kernel\TagsHeader;
use Drupal\Tests\purge\Kernel\KernelTestBase;
use Symfony\Component\HttpFoundation\Request;
class CacheableResponseSubscriberTest extends KernelTestBase {
  
  public static $modules = [
    'system',
    'purge_tagsheader_test',
  ];
  
  protected function assertCacheTagsHeader($path, $header_name) : void {
    $request = Request::create($path);
    $response = $this->container
      ->get('http_kernel')
      ->handle($request);
    $this
      ->assertEquals(200, $response
      ->getStatusCode());
    $header = $response->headers
      ->get($header_name);
    $this
      ->assertNotNull($header, "{$header_name} header exists.");
    $this
      ->assertTrue(is_string($header));
    $this
      ->assertTrue(strpos($header, 'config:user.role.anonymous') !== FALSE);
    $this
      ->assertTrue(strpos($header, 'rendered') !== FALSE);
  }
  
  public function setUp($switch_to_memory_queue = TRUE) : void {
    parent::setUp();
    \Drupal::service('router.builder')
      ->rebuild();
  }
  
  public function testHeaderPresence() : void {
    $this
      ->assertCacheTagsHeader('/system/401', 'Header-A');
    $this
      ->assertCacheTagsHeader('/system/401', 'Header-B');
    $this
      ->assertCacheTagsHeader('/system/401', 'Header-C');
  }
}