public function ViewsDataTest::testSingleTableGetCache in Zircon Profile 8.0
Same name and namespace in other branches
- 8 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 330 - Contains \Drupal\Tests\views\Unit\ViewsDataTest.
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
->get();
$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.');
}