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 <a href="/api/drupal/core%21modules%21views%21src%21ViewsData.php/class/ViewsData/9" title="Class to manage and lazy load cached views data." class="local">\Drupal\views\ViewsData</a> @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.