function AssetOptimizationTest::assertAggregate

Same name and namespace in other branches
  1. 10 core/tests/Drupal/FunctionalTests/Asset/AssetOptimizationTest.php \Drupal\FunctionalTests\Asset\AssetOptimizationTest::assertAggregate()

Asserts the aggregate header.

Parameters

string $url: The source URL.

bool $from_php: (optional) Is the result from PHP or disk? Defaults to TRUE (PHP).

string|null $content_type: The expected content type, or NULL to skip checking.

1 call to AssetOptimizationTest::assertAggregate()
AssetOptimizationTest::doTestAggregation in core/tests/Drupal/FunctionalTests/Asset/AssetOptimizationTest.php
Helper to test aggregate file URLs.

File

core/tests/Drupal/FunctionalTests/Asset/AssetOptimizationTest.php, line 133

Class

AssetOptimizationTest
Tests asset aggregation.

Namespace

Drupal\FunctionalTests\Asset

Code

protected function assertAggregate(string $url, bool $from_php = TRUE, ?string $content_type = NULL) : void {
    $url = $this->getAbsoluteUrl($url);
    if (!stripos($url, $this->fileAssetsPath) !== FALSE) {
        return;
    }
    $session = $this->getSession();
    $session->visit($url);
    $this->assertSession()
        ->statusCodeEquals(200);
    $headers = $session->getResponseHeaders();
    if (isset($content_type)) {
        $this->assertStringContainsString($content_type, $headers['Content-Type'][0]);
    }
    if ($from_php) {
        $this->assertStringContainsString('no-store', $headers['Cache-Control'][0]);
        $this->assertArrayHasKey('X-Generator', $headers);
    }
    else {
        $this->assertArrayNotHasKey('X-Generator', $headers);
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.