You are here

DisableFlocTest.php in Analytics 8

File

tests/src/Functional/DisableFlocTest.php
View source
<?php

namespace Drupal\Tests\analytics\Functional;

use Drupal\Tests\BrowserTestBase;

/**
 * Tests disabling FLoC via response header.
 *
 * @group analytics
 */
class DisableFlocTest extends BrowserTestBase {

  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'user',
    'analytics',
  ];

  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'stark';

  /**
   * Tests adding the Permissions-Policy header.
   */
  public function testDisableFloc() {
    $this
      ->drupalGet('<front>');
    $this
      ->assertSession()
      ->responseHeaderEquals('Permissions-Policy', NULL);
    $account = $this
      ->createUser([
      'administer analytics',
    ]);
    $this
      ->drupalLogin($account);
    $this
      ->drupalPostForm('admin/config/services/analytics/settings', [
      'privacy[disable_floc]' => TRUE,
    ], 'Save configuration');

    // Log out the user to test that the page cache was invalidated.
    $this
      ->drupalLogout();
    $this
      ->drupalGet('<front>');
    $this
      ->assertSession()
      ->responseHeaderEquals('Permissions-Policy', 'interest-cohort=()');
  }

}

Classes

Namesort descending Description
DisableFlocTest Tests disabling FLoC via response header.