- <?php
- * @file
- * Definition of ViewsCacheTest.
- */
-
- require_once BACKDROP_ROOT . '/core/modules/views/tests/views_query.test';
-
- * Basic test for pluggable caching.
- *
- * @see views_plugin_cache
- */
- class ViewsCacheTest extends ViewsSqlTest {
- protected $profile = 'minimal';
-
-
- * Build and return a basic view of the views_test table.
- *
- * @return view
- */
- protected function getBasicView() {
-
- $view = new view();
- $view->name = 'test_view';
- $view->add_display('default');
- $view->base_table = 'views_test';
-
-
- $display = $view->new_display('default', 'Default', 'default');
- $display->override_option('fields', array(
- 'id' => array(
- 'id' => 'id',
- 'table' => 'views_test',
- 'field' => 'id',
- 'relationship' => 'none',
- ),
- 'name' => array(
- 'id' => 'name',
- 'table' => 'views_test',
- 'field' => 'name',
- 'relationship' => 'none',
- ),
- 'age' => array(
- 'id' => 'age',
- 'table' => 'views_test',
- 'field' => 'age',
- 'relationship' => 'none',
- ),
- ));
-
-
- $display->override_option('sorts', array(
- 'id' => array(
- 'order' => 'ASC',
- 'id' => 'id',
- 'table' => 'views_test',
- 'field' => 'id',
- 'relationship' => 'none',
- ),
- ));
-
- return $view;
- }
-
-
- * Tests time based caching.
- *
- * @see views_plugin_cache_time
- */
- function testTimeCaching() {
-
- $view = $this->getBasicView();
- $view->set_display();
- $view->display_handler->override_option('cache', array(
- 'type' => 'time',
- 'results_lifespan' => '3600',
- 'output_lifespan' => '3600',
- ));
-
- $this->executeView($view);
-
- $this->assertEqual(5, count($view->result), t('The number of returned rows match.'));
-
-
- $record = array(
- 'name' => 'Rod Davis',
- 'age' => 29,
- 'job' => 'Banjo',
- );
- backdrop_write_record('views_test', $record);
-
-
- $view = $this->getBasicView();
- $view->set_display();
- $view->display_handler->override_option('cache', array(
- 'type' => 'time',
- 'results_lifespan' => '3600',
- 'output_lifespan' => '3600',
- ));
-
- $this->executeView($view);
-
- $this->assertEqual(5, count($view->result), t('The number of returned rows match.'));
- }
-
-
- * Tests no caching.
- *
- * @see views_plugin_cache_time
- */
- function testNoneCaching() {
-
- $view = $this->getBasicView();
- $view->set_display();
- $view->display_handler->override_option('cache', array(
- 'type' => 'none',
- ));
-
- $this->executeView($view);
-
- $this->assertEqual(5, count($view->result), t('The number of returned rows match.'));
-
-
- $record = array(
- 'name' => 'Rod Davis',
- 'age' => 29,
- 'job' => 'Banjo',
- );
-
- backdrop_write_record('views_test', $record);
-
-
- $view = $this->getBasicView();
- $view->set_display();
- $view->display_handler->override_option('cache', array(
- 'type' => 'none',
- ));
-
- $this->executeView($view);
-
- $this->assertEqual(6, count($view->result), t('The number of returned rows match.'));
- }
-
-
- * Tests css/js storage and restoring mechanism.
- */
- function testHeaderStorage() {
-
-
-
- $view = $this->getBasicView();
- $view->init_display();
- $view->name = 'test_cache_header_storage';
- $view->display_handler->override_option('cache', array(
- 'type' => 'time',
- 'output_lifespan' => '3600',
- ));
-
- $view->preview();
- $view->destroy();
- unset($view->pre_render_called);
- backdrop_static_reset('backdrop_add_css');
- backdrop_static_reset('backdrop_add_js');
-
- $view->init_display();
- $view->preview();
- $css = backdrop_add_css();
- $css_path = backdrop_get_path('module', 'views_test') . '/views_cache.test.css';
- $js_path = backdrop_get_path('module', 'views_test') . '/views_cache.test.js';
- $js = backdrop_add_js();
-
- $this->assertTrue(isset($css[$css_path]), 'Make sure the css is added for cached views.');
- $this->assertTrue(isset($js[$js_path]), 'Make sure the js is added for cached views.');
- $this->assertFalse(!empty($view->pre_render_called), 'Make sure hook_views_pre_render is not called for the cached view.');
- $view->destroy();
-
-
-
- $view->name = 'test_cache_header_storage_2';
-
- $system_css_path = backdrop_get_path('module', 'system') . '/css/system.maintenance.css';
- backdrop_add_css($system_css_path);
- $system_js_path = backdrop_get_path('module', 'user') . '/js/user.permissions.js';
- backdrop_add_js($system_js_path);
-
- $view->init_display();
- $view->preview();
- $view->destroy();
- backdrop_static_reset('backdrop_add_css');
- backdrop_static_reset('backdrop_add_js');
-
- $view->init_display();
- $view->preview();
-
- $css = backdrop_add_css();
- $js = backdrop_add_js();
-
- $this->assertFalse(isset($css[$system_css_path]), 'Make sure that unrelated css is not added.');
- $this->assertFalse(isset($js[$system_js_path]), 'Make sure that unrelated js is not added.');
-
- }
-
-
- * Check that HTTP headers are cached for views.
- */
- function testHttpHeadersCaching() {
-
- for ($i = 0; $i < 5; $i++) {
- $this->backdropCreateNode();
- }
-
-
- $this->backdropGet('test_feed_http_headers_caching');
- $first_content = $this->backdropGetContent();
- $first_content_type = $this->backdropGetHeader('content-type');
- $expected_type = 'application/rss+xml';
- $this->assertIdentical(0, strpos(trim($first_content_type), $expected_type), t('Expected content type returned.'));
-
-
- $xml = simplexml_load_string($first_content);
- $items = $xml->xpath('/rss/channel/item');
- $this->assertEqual(5, count($items), t('The number of RSS feed items matched.'));
-
-
-
- $this->backdropCreateNode();
-
-
- $this->backdropGet('test_feed_http_headers_caching');
- $second_content = $this->backdropGetContent();
- $this->assertEqual($first_content, $second_content, t('The second result fetched from cache.'));
- $second_content_type = $this->backdropGetHeader('content-type');
- $this->assertEqual($first_content_type, $second_content_type, t('Content types of responses are equal.'));
- }
-
-
- * Test caching of different exposed filter values with the same view result.
- *
- * Make sure the output is different.
- */
- function testExposedFilterSameResultsCaching() {
-
-
- $view = $this->getBasicView();
- $view->init_display();
- $view->name = 'test_cache_filter_same_results';
- $view->display_handler->override_option('cache', array(
- 'type' => 'time',
- 'results_lifespan' => '3600',
- 'output_lifespan' => '3600',
- ));
- $view->display_handler->override_option('filters', array(
- 'name' => array(
- 'id' => 'name',
- 'table' => 'views_test',
- 'field' => 'name',
- 'relationship' => 'none',
- 'operator' => 'starts',
- 'exposed' => TRUE,
- 'expose' => array(
- 'operator_id' => 'name_op',
- 'operator' => 'name_op',
- 'identifier' => 'name',
- ),
- ),
- ));
-
-
- $clone = $view->clone_view();
-
-
- $view->set_exposed_input(array(
- 'name' => 'Rin',
- ));
- $this->executeView($view);
- $first_result = $view->result;
- $first_output = $view->render();
- $this->assertEqual(1, count($first_result), t('The number of rows returned by the first view match.'));
-
-
-
- $clone->set_exposed_input(array(
- 'name' => 'Ringo',
- ));
- $this->executeView($clone);
- $second_result = $clone->result;
- $second_output = $clone->render();
- $this->assertEqual($first_result, $second_result, t('Results of both views are the same.'));
-
-
-
- $this->assertNotEqual($first_output, $second_output, t('Output of the second view is different.'));
-
- $this->backdropSetContent($second_output);
- $this->assertFieldByXPath('//input[@name="name" and @value="Ringo"]', FALSE, t('Input field of exposed filter has the second value.'));
-
- $view->destroy();
- $clone->destroy();
- }
-
- }