You are here

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

Tests building the views data with a non existing table.

File

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

Class

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

Namespace

Drupal\Tests\views\Unit

Code

public function testNonExistingTableGetCache() {
  $random_table_name = $this
    ->randomMachineName();

  // Views data should be invoked once.
  $this
    ->setupMockedModuleHandler();
  $this->moduleHandler
    ->expects($this
    ->once())
    ->method('alter')
    ->with('views_data', $this
    ->viewsDataWithProvider());
  $this->cacheBackend
    ->expects($this
    ->at(0))
    ->method('get')
    ->with("views_data:{$random_table_name}:en")
    ->will($this
    ->returnValue(FALSE));
  $this->cacheBackend
    ->expects($this
    ->at(1))
    ->method('get')
    ->with("views_data:en")
    ->will($this
    ->returnValue(FALSE));

  // All views data should be requested on the first try.
  $views_data = $this->viewsData
    ->get($random_table_name);
  $this
    ->assertSame(array(), $views_data, 'Make sure fetching views data for an invalid table returns an empty array.');

  // Test no data is rebuilt when requesting an invalid table again.
  $views_data = $this->viewsData
    ->get($random_table_name);
  $this
    ->assertSame(array(), $views_data, 'Make sure fetching views data for an invalid table returns an empty array.');
}