function ViewsDataTest::testCacheCallsWithoutWarmCacheAndGetMultipleTables

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

Tests the cache calls for multiple tables without warm caches.

@covers ::get

File

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

Class

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

Namespace

Drupal\Tests\views\Unit

Code

public function testCacheCallsWithoutWarmCacheAndGetMultipleTables() : void {
    $expected_views_data = $this->viewsDataWithProvider();
    $table_name = 'views_test_data';
    $table_name_2 = 'views_test_data_2';
    // Setup a warm cache backend for all table data, but not single tables.
    $gets = [
        "views_data:{$table_name}:en",
        'views_data:en',
        "views_data:{$table_name_2}: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,
    ], FALSE);
    $sets = [
        "views_data:{$table_name}:en",
        $expected_views_data[$table_name],
        "views_data:{$table_name_2}:en",
        $expected_views_data[$table_name_2],
    ];
    $this->cacheBackend
        ->expects($this->exactly(count($sets) / 2))
        ->method('set')
        ->with($this->callback(function (string $key) use (&$sets) : bool {
        return $key === array_shift($sets);
    }), $this->callback(function (array $data) use (&$sets) : bool {
        return $data === array_shift($sets);
    }));
    $this->assertSame($expected_views_data[$table_name], $this->viewsData
        ->get($table_name));
    $this->assertSame($expected_views_data[$table_name_2], $this->viewsData
        ->get($table_name_2));
    // Should only be invoked the first time.
    $this->assertSame($expected_views_data[$table_name], $this->viewsData
        ->get($table_name));
    $this->assertSame($expected_views_data[$table_name_2], $this->viewsData
        ->get($table_name_2));
}

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