function ViewsDataTest::testCacheCallsWithSameTableMultipleTimesAndWarmCache

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

Tests the cache calls for a single table and warm cache.

Warm cache:

  • all tables
  • views_test_data

File

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

Class

ViewsDataTest
@coversDefaultClass <a href="/api/drupal/core%21modules%21views%21src%21ViewsData.php/class/ViewsData/10" title="Class to manage and lazy load cached views data." class="local">\Drupal\views\ViewsData</a> @group views

Namespace

Drupal\Tests\views\Unit

Code

public function testCacheCallsWithSameTableMultipleTimesAndWarmCache() : void {
    $expected_views_data = $this->viewsDataWithProvider();
    $this->moduleHandler
        ->expects($this->never())
        ->method('invokeAllWith');
    // Setup a warm cache backend for a single table.
    $this->cacheBackend
        ->expects($this->once())
        ->method('get')
        ->with('views_data:views_test_data:en')
        ->willReturn((object) [
        'data' => $expected_views_data['views_test_data'],
    ]);
    $this->cacheBackend
        ->expects($this->never())
        ->method('set');
    // We have a warm cache now, so this will only request the tables-specific
    // cache entry and return that.
    for ($i = 0; $i < 5; $i++) {
        $views_data = $this->viewsData
            ->get('views_test_data');
        $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.