You are here

public function RenderStackTest::test_collectAndRemoveAssets in Render cache 7.2

@covers ::collectAndRemoveAssets()

File

tests/src/Cache/RenderStackTest.php, line 359
Contains \Drupal\render_cache\Tests\Cache\RenderStackTest

Class

RenderStackTest
@coversDefaultClass \Drupal\render_cache\Cache\RenderStack @group cache

Namespace

Drupal\render_cache\Tests\Cache

Code

public function test_collectAndRemoveAssets() {
  $render = array();
  $render[] = array(
    '#cache' => array(
      'tags' => array(
        'node:1',
      ),
    ),
  );
  $render[] = array(
    '#cache' => array(
      'max-age' => 600,
      'downstream-ttl' => 300,
    ),
  );
  $render[] = array(
    '#attached' => array(
      'css' => 'test.css',
    ),
  );
  $render[] = array(
    '#post_render_cache' => array(
      'test_post_render_cache' => array(),
    ),
  );
  $render[] = array(
    'child_1' => array(
      '#markup' => 'foo',
      '#cache' => array(
        'tags' => array(
          'node:2',
        ),
      ),
    ),
  );
  $render_result = array();
  $render_result[0] = array();
  $render_result[1] = array();
  $render_result[2] = array(
    '#attached' => array(
      'css' => 'test.css',
    ),
  );
  $render_result[3] = array();
  $render_result[4] = array(
    'child_1' => array(
      '#markup' => 'foo',
    ),
  );
  $storage = array(
    '#cache' => array(
      'tags' => array(
        'node:1',
        'node:2',
      ),
      'max-age' => array(
        600,
      ),
      'downstream-ttl' => array(
        300,
      ),
    ),
    '#post_render_cache' => array(
      'test_post_render_cache' => array(),
    ),
  );
  $this
    ->assertEquals($storage, $this->renderStack
    ->collectAndRemoveAssets($render), 'Collected assets match after collectAndRemoveAssets.');
  $this
    ->assertEquals($render_result, $render, 'Render array matches after collectAndRemoveAssets.');
}