function ViewsDataTest::testNonExistingTableGetCache
Tests building the views data with a non existing table.
File
- 
              core/modules/ views/ tests/ src/ Unit/ ViewsDataTest.php, line 340 
Class
- ViewsDataTest
- @coversDefaultClass \Drupal\views\ViewsData[[api-linebreak]] @group views
Namespace
Drupal\Tests\views\UnitCode
public function testNonExistingTableGetCache() : void {
  $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());
  $gets = [
    "views_data:{$random_table_name}:en",
    'views_data:en',
  ];
  $this->cacheBackend
    ->expects($this->exactly(count($gets)))
    ->method('get')
    ->with($this->callback(function (string $key) use (&$gets) : bool {
    return $key === array_shift($gets);
  }))
    ->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.
