diff --git a/core/modules/system/tests/modules/unversioned_assets_test/unversioned_assets_test.info.yml b/core/modules/system/tests/modules/unversioned_assets_test/unversioned_assets_test.info.yml new file mode 100644 index 0000000000..1c4b86ff32 --- /dev/null +++ b/core/modules/system/tests/modules/unversioned_assets_test/unversioned_assets_test.info.yml @@ -0,0 +1,5 @@ +name: 'Unversioned assets test' +type: module +description: 'Tests that aggregates change when unversioned assets change' +package: Testing +version: VERSION diff --git a/core/modules/system/tests/modules/unversioned_assets_test/unversioned_assets_test.module b/core/modules/system/tests/modules/unversioned_assets_test/unversioned_assets_test.module new file mode 100644 index 0000000000..2a119fc796 --- /dev/null +++ b/core/modules/system/tests/modules/unversioned_assets_test/unversioned_assets_test.module @@ -0,0 +1,18 @@ + -10]; + } +} diff --git a/core/tests/Drupal/FunctionalTests/Asset/UnversionedAssetTest.php b/core/tests/Drupal/FunctionalTests/Asset/UnversionedAssetTest.php new file mode 100644 index 0000000000..0862171499 --- /dev/null +++ b/core/tests/Drupal/FunctionalTests/Asset/UnversionedAssetTest.php @@ -0,0 +1,99 @@ +fileAssetsPath = $this->publicFilesDirectory; + file_put_contents('public://test.css', '.original-content{display:none;}'); + // Test aggregation with a custom file_assets_path. + $this->config('system.performance')->set('css', [ + 'preprocess' => TRUE, + 'gzip' => TRUE, + ])->save(); + $this->config('system.performance')->set('js', [ + 'preprocess' => TRUE, + 'gzip' => TRUE, + ])->save(); + $this->drupalGet(''); + $session = $this->getSession(); + $page = $session->getPage(); + + $style_elements = $page->findAll('xpath', '//link[@rel="stylesheet"]'); + $this->assertNotEmpty($style_elements); + $href = NULL; + foreach ($style_elements as $element) { + if ($element->hasAttribute('href')) { + $href = $element->getAttribute('href'); + $url = $this->getAbsoluteUrl($href); + // Not every script or style on a page is aggregated. + if (!str_contains($url, $this->fileAssetsPath)) { + continue; + } + $session = $this->getSession(); + $session->visit($url); + $this->assertSession()->statusCodeEquals(200); + $aggregate = $session = $session->getPage()->getContent(); + $this->assertStringContainsString('original-content', $aggregate); + $this->assertStringNotContainsString('extra-stuff', $aggregate); + } + } + $file = file_get_contents('public://test.css') . '.extra-stuff{display:none;}'; + file_put_contents('public://test.css', $file); + // At this point the HTML is cached in the page cache, and the URLs + // themselves are cached in the assert resolver cache with a compound cache + // key. Delete the full contents of both bins so that the URLs have to be + // generated again. + \Drupal::service('cache.data')->deleteAll(); + \Drupal::service('cache.page')->deleteAll(); + $this->drupalGet(''); + $session = $this->getSession(); + $page = $session->getPage(); + $style_elements = $page->findAll('xpath', '//link[@rel="stylesheet"]'); + $this->assertNotEmpty($style_elements); + foreach ($style_elements as $element) { + if ($element->hasAttribute('href')) { + $new_href = $element->getAttribute('href'); + $this->assertNotSame($new_href, $href); + $url = $this->getAbsoluteUrl($new_href); + // Not every script or style on a page is aggregated. + if (!str_contains($url, $this->fileAssetsPath)) { + continue; + } + $session = $this->getSession(); + $session->visit($url); + $this->assertSession()->statusCodeEquals(200); + $aggregate = $session = $session->getPage()->getContent(); + $this->assertStringContainsString('original-content', $aggregate); + $this->assertStringContainsString('extra-stuff', $aggregate); + } + } + } + +}