public function ViewsDataTest::testNonExistingTableGetCache in Drupal 8
Tests building the views data with a non existing table.
File
- core/
modules/ views/ tests/ src/ Unit/ ViewsDataTest.php, line 360
Class
- ViewsDataTest
- @coversDefaultClass \Drupal\views\ViewsData @group views
Namespace
Drupal\Tests\views\UnitCode
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([], $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.');
}