You are here

public function ViewsDataTest::testCacheCallsWithWarmCacheAndInvalidTable 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::testCacheCallsWithWarmCacheAndInvalidTable()

Tests the cache calls for an not existing table:

Warm cache:

  • all tables
  • views_test_data

Not warm cache:

  • $non_existing_table

File

core/modules/views/tests/src/Unit/ViewsDataTest.php, line 497
Contains \Drupal\Tests\views\Unit\ViewsDataTest.

Class

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

Namespace

Drupal\Tests\views\Unit

Code

public function testCacheCallsWithWarmCacheAndInvalidTable() {
  $expected_views_data = $this
    ->viewsDataWithProvider();
  $non_existing_table = $this
    ->randomMachineName();
  $this->moduleHandler
    ->expects($this
    ->never())
    ->method('getImplementations');

  // Setup a warm cache backend for a single table.
  $this->cacheBackend
    ->expects($this
    ->at(0))
    ->method('get')
    ->with("views_data:{$non_existing_table}:en");
  $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:{$non_existing_table}:en", array());

  // Initialize the views data cache and request a non-existing table. This
  // will result in the same cache requests as we explicitly write an empty
  // cache entry for non-existing tables to avoid unnecessary requests in
  // those situations. We do have to load the cache entry for all tables to
  // check if the table does exist or not.
  for ($i = 0; $i < 5; $i++) {
    $views_data = $this->viewsData
      ->get($non_existing_table);
    $this
      ->assertSame(array(), $views_data);
  }
}