function ViewsDataTest::testCacheCallsWithSameTableMultipleTimes

Same name and namespace in other branches
  1. 11.x core/modules/views/tests/src/Unit/ViewsDataTest.php \Drupal\Tests\views\Unit\ViewsDataTest::testCacheCallsWithSameTableMultipleTimes()
  2. 10 core/modules/views/tests/src/Unit/ViewsDataTest.php \Drupal\Tests\views\Unit\ViewsDataTest::testCacheCallsWithSameTableMultipleTimes()
  3. 9 core/modules/views/tests/src/Unit/ViewsDataTest.php \Drupal\Tests\views\Unit\ViewsDataTest::testCacheCallsWithSameTableMultipleTimes()
  4. 8.9.x core/modules/views/tests/src/Unit/ViewsDataTest.php \Drupal\Tests\views\Unit\ViewsDataTest::testCacheCallsWithSameTableMultipleTimes()

Tests the cache backend behavior with requesting the same table multiple.

File

core/modules/views/tests/src/Unit/ViewsDataTest.php, line 407

Class

ViewsDataTest
Tests Drupal\views\ViewsData.

Namespace

Drupal\Tests\views\Unit

Code

public function testCacheCallsWithSameTableMultipleTimes() : void {
  $expected_views_data = $this->viewsDataWithProvider();
  $this->setUpMockCacheBackend();
  $this->setUpMockChainedFastBackend();
  $this->setUpMockModuleHandlerWithExpectation();
  $this->cacheBackend
    ->expects($this->once())
    ->method('get')
    ->with('views_data:en')
    ->willReturn(FALSE);
  $this->chainedFastBackend
    ->expects($this->once())
    ->method('get')
    ->with('views_data:views_test_data:en')
    ->willReturn(FALSE);
  $this->cacheBackend
    ->expects($this->once())
    ->method('set')
    ->with('views_data:en', $expected_views_data);
  $this->chainedFastBackend
    ->expects($this->once())
    ->method('set')
    ->with('views_data:views_test_data:en', $expected_views_data['views_test_data']);
  // Request the same table 5 times. The caches are empty at this point, so
  // what will happen is that it will first check for a cache entry for the
  // given table, get a cache miss, then try the cache entry for all tables,
  // which does not exist yet either. As a result, it rebuilds the information
  // and writes a cache entry for all tables and the requested table.
  $table_name = 'views_test_data';
  for ($i = 0; $i < 5; $i++) {
    $views_data = $this->viewsData
      ->get($table_name);
    $this->assertSame($expected_views_data['views_test_data'], $views_data);
  }
}

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