1 views_cache.test ViewsCacheTest::testExposedFilterSameResultsCaching()

Test caching of different exposed filter values with the same view result.

Make sure the output is different.

File

core/modules/views/tests/views_cache.test, line 242
Definition of ViewsCacheTest.

Class

ViewsCacheTest
Basic test for pluggable caching.

Code

function testExposedFilterSameResultsCaching() {
  // Create the view with time-based cache with hour lifetimes and add exposed
  // filter to it with "Starts with" operator.
  $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 the view before setting exposed input.
  $clone = $view->clone_view();

  // Pass "Rin" to the exposed filter and check that only one row returned.
  $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.'));

  // Pass full "Ringo" to the exposed filter at the second time and make sure
  // results are the same.
  $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.'));

  // Check that output is not the same and it contains full "Ringo" word in
  // default value of exposed input.
  $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();
}