You are here

public function ViewsDataTest::testCacheCallsWithoutWarmCacheAndGetMultipleTables in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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 613
Contains \Drupal\Tests\views\Unit\ViewsDataTest.

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) array(
    '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));
}