public function ViewsDataTest::testCacheCallsWithSameTableMultipleTimes in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/views/tests/src/Unit/ViewsDataTest.php \Drupal\Tests\views\Unit\ViewsDataTest::testCacheCallsWithSameTableMultipleTimes()
Tests the cache backend behavior with requesting the same table multiple
File
- core/
modules/ views/ tests/ src/ Unit/ ViewsDataTest.php, line 397 - Contains \Drupal\Tests\views\Unit\ViewsDataTest.
Class
- ViewsDataTest
- @coversDefaultClass \Drupal\views\ViewsData @group views
Namespace
Drupal\Tests\views\UnitCode
public function testCacheCallsWithSameTableMultipleTimes() {
$expected_views_data = $this
->viewsDataWithProvider();
$this
->setupMockedModuleHandler();
$this->cacheBackend
->expects($this
->at(0))
->method('get')
->with('views_data:views_test_data:en');
$this->cacheBackend
->expects($this
->at(1))
->method('get')
->with('views_data:en');
$this->cacheBackend
->expects($this
->at(2))
->method('set')
->with('views_data:en', $expected_views_data);
$this->cacheBackend
->expects($this
->at(3))
->method('set')
->with('views_data:views_test_data:en', $expected_views_data['views_test_data']);
// Request the same table 5 times. The caches are empty at this point, so
// what will happen is that it will first check for a cache entry for the
// given table, get a cache miss, then try the cache entry for all tables,
// which does not exist yet either. As a result, it rebuilds the information
// and writes a cache entry for all tables and the requested table.
$table_name = 'views_test_data';
for ($i = 0; $i < 5; $i++) {
$views_data = $this->viewsData
->get($table_name);
$this
->assertSame($expected_views_data['views_test_data'], $views_data);
}
}