function ViewsDataTest::testSingleTableGetCache

Same name in other branches
  1. 8.9.x core/modules/views/tests/src/Unit/ViewsDataTest.php \Drupal\Tests\views\Unit\ViewsDataTest::testSingleTableGetCache()
  2. 10 core/modules/views/tests/src/Unit/ViewsDataTest.php \Drupal\Tests\views\Unit\ViewsDataTest::testSingleTableGetCache()
  3. 11.x core/modules/views/tests/src/Unit/ViewsDataTest.php \Drupal\Tests\views\Unit\ViewsDataTest::testSingleTableGetCache()

Tests the caching of the views data for a specific table.

File

core/modules/views/tests/src/Unit/ViewsDataTest.php, line 294

Class

ViewsDataTest
@coversDefaultClass \Drupal\views\ViewsData @group views

Namespace

Drupal\Tests\views\Unit

Code

public function testSingleTableGetCache() {
    $table_name = 'views_test_data';
    $expected_views_data = $this->viewsDataWithProvider();
    // 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:{$table_name}:en",
    ], [
        'views_data:en',
    ])
        ->willReturn(FALSE);
    $views_data = $this->viewsData
        ->get($table_name);
    $this->assertSame($expected_views_data[$table_name], $views_data, 'Make sure fetching views data by table works as expected.');
    $views_data = $this->viewsData
        ->get($table_name);
    $this->assertSame($expected_views_data[$table_name], $views_data, 'Make sure fetching cached views data by table works as expected.');
    // Test that this data is present if all views data is returned.
    $views_data = $this->viewsData
        ->getAll();
    $this->assertArrayHasKey($table_name, $views_data, 'Make sure the views_test_data info appears in the total views data.');
    $this->assertSame($expected_views_data[$table_name], $views_data[$table_name], 'Make sure the views_test_data has the expected values.');
}

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