function ViewsDataTest::testNonExistingTableGetCache

Same name and namespace in other branches
  1. 8.9.x core/modules/views/tests/src/Unit/ViewsDataTest.php \Drupal\Tests\views\Unit\ViewsDataTest::testNonExistingTableGetCache()
  2. 10 core/modules/views/tests/src/Unit/ViewsDataTest.php \Drupal\Tests\views\Unit\ViewsDataTest::testNonExistingTableGetCache()
  3. 11.x 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 329

Class

ViewsDataTest
@coversDefaultClass \Drupal\views\ViewsData[[api-linebreak]] @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->exactly(2))
    ->method('get')
    ->withConsecutive([
    "views_data:{$random_table_name}:en",
  ], [
    'views_data:en',
  ])
    ->willReturn(FALSE);
  // All views data should be requested on the first try.
  $views_data = $this->viewsData
    ->get($random_table_name);
  $this->assertSame([], $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([], $views_data, 'Make sure fetching views data for an invalid table returns an empty array.');
}

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