function ViewsDataTest::testSingleTableGetCache
Same name in other branches
- 9 core/modules/views/tests/src/Unit/ViewsDataTest.php \Drupal\Tests\views\Unit\ViewsDataTest::testSingleTableGetCache()
- 10 core/modules/views/tests/src/Unit/ViewsDataTest.php \Drupal\Tests\views\Unit\ViewsDataTest::testSingleTableGetCache()
- 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 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.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.