function ViewsDataTest::testFullyLoadedPropertySetAfterCacheLoad

Same name and namespace in other branches
  1. main core/modules/views/tests/src/Unit/ViewsDataTest.php \Drupal\Tests\views\Unit\ViewsDataTest::testFullyLoadedPropertySetAfterCacheLoad()

Tests that fullyLoaded is TRUE when data is loaded from cache.

When views data is retrieved from cache, fullyLoaded should still be set to TRUE after the data retrieval is complete.

File

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

Class

ViewsDataTest
Tests Drupal\views\ViewsData.

Namespace

Drupal\Tests\views\Unit

Code

public function testFullyLoadedPropertySetAfterCacheLoad() : void {
  $expected_views_data = $this->viewsDataWithProvider();
  // Use reflection to access the protected fullyLoaded property.
  $reflection = new \ReflectionClass($this->viewsData);
  $fullyLoaded_property = $reflection->getProperty('fullyLoaded');
  // Verify fullyLoaded starts as FALSE.
  $this->assertFalse($fullyLoaded_property->getValue($this->viewsData));
  // Mock that data is already cached.
  $this->cacheBackend
    ->expects($this->once())
    ->method('get')
    ->with("views_data:en")
    ->willReturn((object) [
    'data' => $expected_views_data,
  ]);
  // No module hooks should be invoked since data comes from cache.
  $this->moduleHandler
    ->expects($this->never())
    ->method('invokeAllWith');
  // Request all views data from cache.
  $views_data = $this->viewsData
    ->getAll();
  // After getAll() completes with cached data, fullyLoaded should be TRUE.
  $this->assertTrue($fullyLoaded_property->getValue($this->viewsData));
  $this->assertSame($expected_views_data, $views_data);
}

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