function ViewsDataTest::testNonExistingTableGetCache

Same name in other branches
  1. 9 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 360

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([], $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.