public function CacheTest::testTimeResultCachingWithFilter in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/views/src/Tests/Plugin/CacheTest.php \Drupal\views\Tests\Plugin\CacheTest::testTimeResultCachingWithFilter()
Tests result caching with filters.
See also
views_plugin_cache_time
File
- core/
modules/ views/ src/ Tests/ Plugin/ CacheTest.php, line 113 - Contains \Drupal\views\Tests\Plugin\CacheTest.
Class
- CacheTest
- Tests pluggable caching for views.
Namespace
Drupal\views\Tests\PluginCode
public function testTimeResultCachingWithFilter() {
// Check that we can find the test filter plugin.
$plugin = $this->container
->get('plugin.manager.views.filter')
->createInstance('test_filter');
$this
->assertTrue($plugin instanceof FilterPlugin, 'Test filter plugin found.');
$view = Views::getView('test_filter');
$view
->initDisplay();
$view->display_handler
->overrideOption('cache', array(
'type' => 'time',
'options' => array(
'results_lifespan' => '3600',
'output_lifespan' => '3600',
),
));
// Change the filtering.
$view->displayHandlers
->get('default')
->overrideOption('filters', array(
'test_filter' => array(
'id' => 'test_filter',
'table' => 'views_test_data',
'field' => 'name',
'operator' => '=',
'value' => 'John',
'group' => 0,
),
));
$this
->executeView($view);
// Get the cache item.
$cid1 = $view->display_handler
->getPlugin('cache')
->generateResultsKey();
// Build the expected result.
$dataset = array(
array(
'name' => 'John',
),
);
// Verify the result.
$this
->assertEqual(1, count($view->result), 'The number of returned rows match.');
$this
->assertIdenticalResultSet($view, $dataset, array(
'views_test_data_name' => 'name',
));
$view
->destroy();
$view
->initDisplay();
// Change the filtering.
$view->displayHandlers
->get('default')
->overrideOption('filters', array(
'test_filter' => array(
'id' => 'test_filter',
'table' => 'views_test_data',
'field' => 'name',
'operator' => '=',
'value' => 'Ringo',
'group' => 0,
),
));
$this
->executeView($view);
// Get the cache item.
$cid2 = $view->display_handler
->getPlugin('cache')
->generateResultsKey();
$this
->assertNotEqual($cid1, $cid2, "Results keys are different.");
// Build the expected result.
$dataset = array(
array(
'name' => 'Ringo',
),
);
// Verify the result.
$this
->assertEqual(1, count($view->result), 'The number of returned rows match.');
$this
->assertIdenticalResultSet($view, $dataset, array(
'views_test_data_name' => 'name',
));
}