function ViewsDataTest::testCacheCallsWithWarmCacheAndDifferentTable

Same name and namespace in other branches
  1. 9 core/modules/views/tests/src/Unit/ViewsDataTest.php \Drupal\Tests\views\Unit\ViewsDataTest::testCacheCallsWithWarmCacheAndDifferentTable()
  2. 8.9.x core/modules/views/tests/src/Unit/ViewsDataTest.php \Drupal\Tests\views\Unit\ViewsDataTest::testCacheCallsWithWarmCacheAndDifferentTable()
  3. 11.x 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 443

Class

ViewsDataTest
@coversDefaultClass \Drupal\views\ViewsData[[api-linebreak]] @group views

Namespace

Drupal\Tests\views\Unit

Code

public function testCacheCallsWithWarmCacheAndDifferentTable() : void {
  $expected_views_data = $this->viewsDataWithProvider();
  $this->moduleHandler
    ->expects($this->never())
    ->method('invokeAllWith');
  // Setup a warm cache backend for a single table.
  $gets = [
    'views_data:views_test_data_2:en',
    'views_data:en',
  ];
  $this->cacheBackend
    ->expects($this->exactly(count($gets)))
    ->method('get')
    ->with($this->callback(function (string $key) use (&$gets) : bool {
    return $key === array_shift($gets);
  }))
    ->willReturnOnConsecutiveCalls(FALSE, (object) [
    'data' => $expected_views_data,
  ]);
  $this->cacheBackend
    ->expects($this->once())
    ->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);
  }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.