You are here

public function ViewsDataTest::testCacheCallsWithWarmCacheAndDifferentTable in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/views/tests/src/Unit/ViewsDataTest.php \Drupal\Tests\views\Unit\ViewsDataTest::testCacheCallsWithWarmCacheAndDifferentTable()

Tests the cache calls for a different table than the one in cache:

Warm cache:

  • all tables
  • views_test_data

Not warm cache:

  • views_test_data_2

File

core/modules/views/tests/src/Unit/ViewsDataTest.php, line 462
Contains \Drupal\Tests\views\Unit\ViewsDataTest.

Class

ViewsDataTest
@coversDefaultClass \Drupal\views\ViewsData @group views

Namespace

Drupal\Tests\views\Unit

Code

public function testCacheCallsWithWarmCacheAndDifferentTable() {
  $expected_views_data = $this
    ->viewsDataWithProvider();
  $this->moduleHandler
    ->expects($this
    ->never())
    ->method('getImplementations');

  // Setup a warm cache backend for a single table.
  $this->cacheBackend
    ->expects($this
    ->at(0))
    ->method('get')
    ->with('views_data:views_test_data_2:en');
  $this->cacheBackend
    ->expects($this
    ->at(1))
    ->method('get')
    ->with('views_data:en')
    ->will($this
    ->returnValue((object) array(
    'data' => $expected_views_data,
  )));
  $this->cacheBackend
    ->expects($this
    ->at(2))
    ->method('set')
    ->with('views_data:views_test_data_2:en', $expected_views_data['views_test_data_2']);

  // Requests a different table as the cache contains. This will fail to get a
  // table specific cache entry, load the cache entry for all tables and save
  // a cache entry for this table but not all.
  for ($i = 0; $i < 5; $i++) {
    $views_data = $this->viewsData
      ->get('views_test_data_2');
    $this
      ->assertSame($expected_views_data['views_test_data_2'], $views_data);
  }
}