You are here

function AttachedAssetsTest::testAggregation in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/system/src/Tests/Common/AttachedAssetsTest.php \Drupal\system\Tests\Common\AttachedAssetsTest::testAggregation()

Integration test for CSS/JS aggregation.

File

core/modules/system/src/Tests/Common/AttachedAssetsTest.php, line 177
Contains \Drupal\system\Tests\Common\AttachedAssetsTest.

Class

AttachedAssetsTest
Tests #attached assets: attached asset libraries and JavaScript settings.

Namespace

Drupal\system\Tests\Common

Code

function testAggregation() {
  $build['#attached']['library'][] = 'core/drupal.timezone';
  $build['#attached']['library'][] = 'core/drupal.vertical-tabs';
  $assets = AttachedAssets::createFromRenderArray($build);
  $this
    ->assertEqual(1, count($this->assetResolver
    ->getCssAssets($assets, TRUE)), 'There is a sole aggregated CSS asset.');
  list($header_js, $footer_js) = $this->assetResolver
    ->getJsAssets($assets, TRUE);
  $this
    ->assertEqual([], \Drupal::service('asset.js.collection_renderer')
    ->render($header_js), 'There are 0 JavaScript assets in the header.');
  $rendered_footer_js = \Drupal::service('asset.js.collection_renderer')
    ->render($footer_js);
  $this
    ->assertEqual(2, count($rendered_footer_js), 'There are 2 JavaScript assets in the footer.');
  $this
    ->assertEqual('drupal-settings-json', $rendered_footer_js[0]['#attributes']['data-drupal-selector'], 'The first of the two JavaScript assets in the footer has drupal settings.');
  $this
    ->assertEqual('http://', substr($rendered_footer_js[1]['#attributes']['src'], 0, 7), 'The second of the two JavaScript assets in the footer has the sole aggregated JavaScript asset.');
}