You are here

public function RenderCacheBackendAdapterTest::test_setMultiple_direct in Render cache 7.2

Tests that RenderCacheBackendAdapter::setMultiple() for direct strategy. @covers ::setMultiple() @covers ::set() @covers ::preserveProperties()

File

tests/src/Cache/RenderCacheBackendAdapterTest.php, line 259
Contains \Drupal\render_cache\Tests\Cache\RenderCacheBackendAdapterTest

Class

RenderCacheBackendAdapterTest
@coversDefaultClass \Drupal\render_cache\Cache\RenderCacheBackendAdapter @group cache

Namespace

Drupal\render_cache\Tests\Cache

Code

public function test_setMultiple_direct() {

  // @todo consider using a data provider instead.
  $cache_info_map = array(
    'direct' => $this
      ->getCacheInfo('render:foo:direct', RenderCache::RENDER_CACHE_STRATEGY_DIRECT_RENDER),
    'late' => $this
      ->getCacheInfo('render:foo:late', RenderCache::RENDER_CACHE_STRATEGY_LATE_RENDER),
  );
  $cache_info_map['late']['cid'] = NULL;
  $build = array();
  foreach ($cache_info_map as $id => $cache_info) {
    $build[$id] = $this->cacheHitData->data;
  }
  $build['late']['#cache']['cid'] = 'foo';
  $build['late']['#cache']['keys'] = 'foo:bar';
  $this->cache
    ->setMultiple($build, $cache_info_map);
  $this
    ->assertEquals($this->cacheHitRenderDirect, $build['direct'], 'Data is the same for direct render strategy');
  $this
    ->assertTrue(empty($build['late']['#cache']['cid']), 'cid property is NULL.');
  $this
    ->assertTrue(empty($build['late']['#cache']['keys']), 'keys property is NULL');

  // Now restore it:
  $build['late']['#cache']['cid'] = 'render:foo:late';
  $this
    ->assertEquals($this->cacheHitLateRender, $build['late'], 'Data is the same for late render strategy');
}