You are here

protected function ViewsTestCase::assertIdenticalResultset in Views (for Drupal 7) 6.3

Same name and namespace in other branches
  1. 7.3 tests/views_query.test \ViewsTestCase::assertIdenticalResultset()

Helper function: verify a result set returned by view.

The comparison is done on the string representation of the columns of the column map, taking the order of the rows into account, but not the order of the columns.

Parameters

$view: An executed View.

$expected_result: An expected result set.

$column_map: An associative array mapping the columns of the result set from the view (as keys) and the expected result set (as values).

File

tests/views_query.test, line 27
Tests for Views query features.

Class

ViewsTestCase
Abstract class for views testing

Code

protected function assertIdenticalResultset($view, $expected_result, $column_map, $message = 'Identical result set') {

  // Convert $view->result to an array of arrays.
  $result = array();
  foreach ($view->result as $key => $value) {
    $row = array();
    foreach ($column_map as $view_column => $expected_column) {

      // The comparison will be done on the string representation of the value.
      $row[$expected_column] = (string) $value->{$view_column};
    }
    $result[$key] = $row;
  }

  // Remove the columns we don't need from the expected result.
  foreach ($expected_result as $key => $value) {
    $row = array();
    foreach ($column_map as $expected_column) {

      // The comparison will be done on the string representation of the value.
      $row[$expected_column] = (string) $value[$expected_column];
    }
    $expected_result[$key] = $row;
  }

  // Reset the numbering of the arrays.
  $result = array_values($result);
  $expected_result = array_values($expected_result);
  $this
    ->verbose('<pre>Returned data set: ' . print_r($result, TRUE) . "\n\nExpected: " . print_r($expected_result, TRUE));

  // Do the actual comparison.
  return $this
    ->assertIdentical($result, $expected_result, $message);
}