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. 10 core/modules/views/tests/src/Unit/ViewsDataTest.php \Drupal\Tests\views\Unit\ViewsDataTest::testCacheCallsWithoutWarmCacheAndGetMultipleTables()
  3. 11.x 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 607

Class

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

Namespace

Drupal\Tests\views\Unit

Code

public function testCacheCallsWithoutWarmCacheAndGetMultipleTables() {
    $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.
    $this->cacheBackend
        ->expects($this->at(0))
        ->method('get')
        ->with("views_data:{$table_name}:en")
        ->will($this->returnValue(FALSE));
    $this->cacheBackend
        ->expects($this->at(1))
        ->method('get')
        ->with('views_data:en')
        ->will($this->returnValue((object) [
        'data' => $expected_views_data,
    ]));
    $this->cacheBackend
        ->expects($this->at(2))
        ->method('set')
        ->with("views_data:{$table_name}:en", $expected_views_data[$table_name]);
    $this->cacheBackend
        ->expects($this->at(3))
        ->method('get')
        ->with("views_data:{$table_name_2}:en")
        ->will($this->returnValue(FALSE));
    $this->cacheBackend
        ->expects($this->at(4))
        ->method('set')
        ->with("views_data:{$table_name_2}:en", $expected_views_data[$table_name_2]);
    $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.