function AssetOptimizationTest::doTestAggregation
Same name and namespace in other branches
- 10 core/tests/Drupal/FunctionalTests/Asset/AssetOptimizationTest.php \Drupal\FunctionalTests\Asset\AssetOptimizationTest::doTestAggregation()
Helper to test aggregate file URLs.
Parameters
array $settings: A settings array to pass to ::writeSettings()
1 call to AssetOptimizationTest::doTestAggregation()
- AssetOptimizationTest::testAssetAggregation in core/
tests/ Drupal/ FunctionalTests/ Asset/ AssetOptimizationTest.php - Tests that asset aggregates are rendered and created on disk.
File
-
core/
tests/ Drupal/ FunctionalTests/ Asset/ AssetOptimizationTest.php, line 76
Class
- AssetOptimizationTest
- Tests asset aggregation.
Namespace
Drupal\FunctionalTests\AssetCode
protected function doTestAggregation(array $settings) : void {
$this->writeSettings($settings);
$this->rebuildAll();
$this->config('system.performance')
->set('css', [
'preprocess' => TRUE,
'gzip' => TRUE,
])
->save();
$this->config('system.performance')
->set('js', [
'preprocess' => TRUE,
'gzip' => TRUE,
])
->save();
$this->requestPage();
$session = $this->getSession();
$page = $session->getPage();
// Collect all the URLs for all the script and styles prior to making any
// more requests.
$style_elements = $page->findAll('xpath', '//link[@href and @rel="stylesheet"]');
$script_elements = $page->findAll('xpath', '//script[@src]');
$style_urls = [];
foreach ($style_elements as $element) {
$style_urls[] = $element->getAttribute('href');
}
$script_urls = [];
foreach ($script_elements as $element) {
$script_urls[] = $element->getAttribute('src');
}
foreach ($style_urls as $url) {
$this->assertAggregate($url, TRUE, 'text/css');
// Once the file has been requested once, it's on disk. It is possible for
// a second request to hit the controller, and then find that another
// request has created the file already. Actually simulating this race
// condition is not really possible since it relies on timing. However, by
// changing the case of the part of the URL that is handled by Drupal
// routing, we can force the request to be served by Drupal.
$this->assertAggregate(str_replace($this->fileAssetsPath, strtoupper($this->fileAssetsPath), $url), TRUE, 'text/css');
$this->assertAggregate($url, FALSE, 'text/css');
$this->assertInvalidAggregates($url);
}
foreach ($script_urls as $url) {
$this->assertAggregate($url);
$this->assertAggregate($url, FALSE);
$this->assertInvalidAggregates($url);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.