BlockInterestCohortTest.php in Drupal 10
File
core/tests/Drupal/KernelTests/Core/Http/BlockInterestCohortTest.php
View source
<?php
namespace Drupal\KernelTests\Core\Http;
use Drupal\Core\Site\Settings;
use Drupal\KernelTests\KernelTestBase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\HttpKernel\HttpKernelInterface;
class BlockInterestCohortTest extends KernelTestBase {
public function testDefaultBlocking() {
$request = Request::create('/');
$response = \Drupal::service('http_kernel')
->handle($request);
$this
->assertSame('interest-cohort=()', $response->headers
->get('Permissions-Policy'));
}
public function testExistingInterestCohortPolicy() {
$headers['Permissions-Policy'] = 'interest-cohort=*';
$kernel = \Drupal::service('http_kernel');
$request = Request::create('/');
$response = new Response('', 200, $headers);
$event = new ResponseEvent($kernel, $request, HttpKernelInterface::MAIN_REQUEST, $response);
\Drupal::service('finish_response_subscriber')
->onRespond($event);
$this
->assertSame($headers['Permissions-Policy'], $response->headers
->get('Permissions-Policy'));
}
public function testExistingPolicyHeader() {
$headers['Permissions-Policy'] = 'geolocation=()';
$kernel = \Drupal::service('http_kernel');
$request = Request::create('/');
$response = new Response('', 200, $headers);
$event = new ResponseEvent($kernel, $request, HttpKernelInterface::MAIN_REQUEST, $response);
\Drupal::service('finish_response_subscriber')
->onRespond($event);
$this
->assertSame($headers['Permissions-Policy'], $response->headers
->get('Permissions-Policy'));
}
public function testSubrequestBlocking() {
$request = Request::create('/');
$response = \Drupal::service('http_kernel')
->handle($request, HttpKernelInterface::SUB_REQUEST);
$this
->assertFalse($response->headers
->has('Permissions-Policy'));
}
public function testDisableBlockSetting() {
$settings = Settings::getAll();
$settings['block_interest_cohort'] = FALSE;
new Settings($settings);
$request = Request::create('/');
$response = \Drupal::service('http_kernel')
->handle($request);
$this
->assertFalse($response->headers
->has('Permissions-Policy'));
}
}