You are here

function ViewsCacheTest::testExposedFilterSameResultsCaching in Views (for Drupal 7) 7.3

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

Make sure the output is different.

File

tests/views_cache.test, line 253
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
    ->set_display();
  $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
    ->copy();

  // 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
    ->drupalSetContent($second_output);
  $element = $this
    ->xpath('//input[@name="name" and @value="Ringo"]');
  $this
    ->assertTrue(!empty($element), t('Input field of exposed filter has the second value.'));
  $view
    ->destroy();
  $clone
    ->destroy();
}