function ViewsDataTest::testFullyLoadedPropertySetAfterDataLoad

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

Tests that fullyLoaded is only set to TRUE after data is completely loaded.

This test ensures that the fullyLoaded property is not set prematurely.

File

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

Class

ViewsDataTest
Tests Drupal\views\ViewsData.

Namespace

Drupal\Tests\views\Unit

Code

public function testFullyLoadedPropertySetAfterDataLoad() : 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));
  $this->setupMockedModuleHandler();
  $this->moduleHandler
    ->expects($this->once())
    ->method('alter')
    ->with('views_data', $expected_views_data);
  $this->cacheBackend
    ->expects($this->once())
    ->method('get')
    ->with("views_data:en")
    ->willReturn(FALSE);
  // Request all views data.
  $views_data = $this->viewsData
    ->getAll();
  // After getAll() completes, 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.