function ViewsDataTest::testCacheCallsWithWarmCacheAndDifferentTable

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

Tests the cache calls for a different table than the one in cache.

Warm cache:

  • all tables
  • views_test_data

Not warm cache:

  • views_test_data_2

File

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

Class

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

Namespace

Drupal\Tests\views\Unit

Code

public function testCacheCallsWithWarmCacheAndDifferentTable() {
    $expected_views_data = $this->viewsDataWithProvider();
    $this->moduleHandler
        ->expects($this->never())
        ->method('invokeAllWith');
    // Setup a warm cache backend for a single table.
    $this->cacheBackend
        ->expects($this->exactly(2))
        ->method('get')
        ->withConsecutive([
        'views_data:views_test_data_2:en',
    ], [
        'views_data:en',
    ])
        ->willReturnOnConsecutiveCalls(FALSE, (object) [
        'data' => $expected_views_data,
    ]);
    $this->cacheBackend
        ->expects($this->once())
        ->method('set')
        ->with('views_data:views_test_data_2:en', $expected_views_data['views_test_data_2']);
    // Requests a different table as the cache contains. This will fail to get a
    // table specific cache entry, load the cache entry for all tables and save
    // a cache entry for this table but not all.
    for ($i = 0; $i < 5; $i++) {
        $views_data = $this->viewsData
            ->get('views_test_data_2');
        $this->assertSame($expected_views_data['views_test_data_2'], $views_data);
    }
}

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