function ViewsDataTest::testCacheCallsWithSameTableMultipleTimes

Same name in other branches
  1. 8.9.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. 11.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 359

Class

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

Namespace

Drupal\Tests\views\Unit

Code

public function testCacheCallsWithSameTableMultipleTimes() {
    $expected_views_data = $this->viewsDataWithProvider();
    $this->setupMockedModuleHandler();
    $this->cacheBackend
        ->expects($this->exactly(2))
        ->method('get')
        ->withConsecutive([
        'views_data:views_test_data:en',
    ], [
        'views_data:en',
    ]);
    $this->cacheBackend
        ->expects($this->exactly(2))
        ->method('set')
        ->withConsecutive([
        'views_data:en',
        $expected_views_data,
    ], [
        '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.