public function ViewsDataTest::testSingleTableGetCache in Drupal 8
Tests the caching of the views data for a specific table.
File
- core/
modules/ views/ tests/ src/ Unit/ ViewsDataTest.php, line 324
Class
- ViewsDataTest
- @coversDefaultClass \Drupal\views\ViewsData @group views
Namespace
Drupal\Tests\views\UnitCode
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
->at(0))
->method('get')
->with("views_data:{$table_name}:en")
->will($this
->returnValue(FALSE));
$this->cacheBackend
->expects($this
->at(1))
->method('get')
->with("views_data:en")
->will($this
->returnValue(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.');
}