Commit 4c67cda1 authored by tim.plunkett's avatar tim.plunkett

Issue #1641694 by Rob Loach, chrisdolby, dawehner, tim.plunkett: Convert query test to PSR-0.

parent 504216ff
......@@ -8,7 +8,6 @@
namespace Drupal\views\Tests;
use Drupal\simpletest\WebTestBase;
use ViewsSqlTest;
use Drupal\views\View;
use views_test_plugin_access_test_dynamic;
......
......@@ -7,8 +7,6 @@
namespace Drupal\views\Tests;
use ViewsSqlTest;
/**
* Tests the views analyze system.
*/
......
......@@ -7,7 +7,6 @@
namespace Drupal\views\Tests;
use ViewsSqlTest;
use Drupal\views\View;
/**
......
......@@ -7,7 +7,6 @@
namespace Drupal\views\Tests;
use ViewsSqlTest;
use Drupal\views\View;
/**
......
......@@ -7,8 +7,6 @@
namespace Drupal\views\Tests;
use ViewsSqlTest;
/**
* Basic test class for Views query builder tests.
*/
......
......@@ -7,7 +7,6 @@
namespace Drupal\views\Tests;
use ViewsSqlTest;
use Drupal\views\View;
/**
......
......@@ -7,7 +7,7 @@
namespace Drupal\views\Tests\Comment;
use ViewsSqlTest;
use Drupal\views\Tests\ViewsSqlTest;
use Drupal\views\View;
/**
......
......@@ -7,8 +7,6 @@
namespace Drupal\views\Tests\Comment;
use ViewsSqlTest;
/**
* Tests the filter_comment_user_uid handler.
*
......
......@@ -7,8 +7,6 @@
namespace Drupal\views\Tests;
use ViewsSqlTest;
/**
* Tests exposed forms.
*/
......
......@@ -8,7 +8,6 @@
namespace Drupal\views\Tests\Field;
use Drupal\simpletest\WebTestBase;
use ViewsSqlTest;
/**
* Test the produced views_data.
......
......@@ -19,7 +19,7 @@
namespace Drupal\views\Tests\Field;
use Drupal\simpletest\WebTestBase;
use ViewsSqlTest;
use Drupal\views\Tests\ViewsSqlTest;
/**
* Provides some helper methods for testing fieldapi integration into views.
......
......@@ -8,7 +8,6 @@
namespace Drupal\views\Tests\Field;
use Drupal\simpletest\WebTestBase;
use ViewsSqlTest;
use Drupal\views\View;
/**
......
......@@ -7,8 +7,6 @@
namespace Drupal\views\Tests;
use ViewsSqlTest;
/**
* Tests glossary view ( summary of arguments ).
*/
......
......@@ -7,7 +7,7 @@
namespace Drupal\views\Tests\Handler;
use ViewsSqlTest;
use Drupal\views\Tests\ViewsSqlTest;
/**
* Tests the text area handler.
......
......@@ -7,7 +7,7 @@
namespace Drupal\views\Tests\Handler;
use ViewsSqlTest;
use Drupal\views\Tests\ViewsSqlTest;
/**
* Tests the core views_handler_argument_null handler.
......
......@@ -7,7 +7,7 @@
namespace Drupal\views\Tests\Handler;
use ViewsSqlTest;
use Drupal\views\Tests\ViewsSqlTest;
use Drupal\views\View;
/**
......
......@@ -7,7 +7,7 @@
namespace Drupal\views\Tests\Handler;
use ViewsSqlTest;
use Drupal\views\Tests\ViewsSqlTest;
/**
* Tests the core views_handler_field_boolean handler.
......
......@@ -7,7 +7,7 @@
namespace Drupal\views\Tests\Handler;
use ViewsSqlTest;
use Drupal\views\Tests\ViewsSqlTest;
/**
* Tests the views_handler_field_counter handler.
......
......@@ -7,7 +7,7 @@
namespace Drupal\views\Tests\Handler;
use ViewsSqlTest;
use Drupal\views\Tests\ViewsSqlTest;
/**
* Tests the core views_handler_field_custom handler.
......
......@@ -7,7 +7,7 @@
namespace Drupal\views\Tests\Handler;
use ViewsSqlTest;
use Drupal\views\Tests\ViewsSqlTest;
/**
* Tests the core views_handler_field_date handler.
......
......@@ -7,7 +7,7 @@
namespace Drupal\views\Tests\Handler;
use ViewsSqlTest;
use Drupal\views\Tests\ViewsSqlTest;
/**
* Tests the core views_handler_field_file_size handler.
......
......@@ -7,7 +7,7 @@
namespace Drupal\views\Tests\Handler;
use ViewsSqlTest;
use Drupal\views\Tests\ViewsSqlTest;
/**
* Tests the core views_handler_field_math handler.
......
......@@ -7,7 +7,7 @@
namespace Drupal\views\Tests\Handler;
use ViewsSqlTest;
use Drupal\views\Tests\ViewsSqlTest;
/**
* Tests the generic field handler
......
......@@ -7,7 +7,7 @@
namespace Drupal\views\Tests\Handler;
use ViewsSqlTest;
use Drupal\views\Tests\ViewsSqlTest;
/**
* Tests the core views_handler_field_url handler.
*/
......
......@@ -7,7 +7,7 @@
namespace Drupal\views\Tests\Handler;
use ViewsSqlTest;
use Drupal\views\Tests\ViewsSqlTest;
/**
* Tests the core views_handler_field_css handler.
......
......@@ -7,7 +7,7 @@
namespace Drupal\views\Tests\Handler;
use ViewsSqlTest;
use Drupal\views\Tests\ViewsSqlTest;
/**
* Tests the combine filter handler.
......
......@@ -7,7 +7,7 @@
namespace Drupal\views\Tests\Handler;
use ViewsSqlTest;
use Drupal\views\Tests\ViewsSqlTest;
use Drupal\views\View;
/**
......
......@@ -7,7 +7,7 @@
namespace Drupal\views\Tests\Handler;
use ViewsSqlTest;
use Drupal\views\Tests\ViewsSqlTest;
/**
* Tests the core views_handler_filter_equality handler.
......
......@@ -7,7 +7,7 @@
namespace Drupal\views\Tests\Handler;
use ViewsSqlTest;
use Drupal\views\Tests\ViewsSqlTest;
/**
* Tests the core views_handler_filter_in_operator handler.
......
......@@ -7,7 +7,7 @@
namespace Drupal\views\Tests\Handler;
use ViewsSqlTest;
use Drupal\views\Tests\ViewsSqlTest;
/**
* Tests the numeric filter handler.
......
......@@ -7,7 +7,7 @@
namespace Drupal\views\Tests\Handler;
use ViewsSqlTest;
use Drupal\views\Tests\ViewsSqlTest;
/**
* Tests the core views_handler_filter_string handler.
......
......@@ -7,7 +7,7 @@
namespace Drupal\views\Tests\Handler;
use ViewsSqlTest;
use Drupal\views\Tests\ViewsSqlTest;
/**
* Tests for core views_handler_sort_date handler.
......
......@@ -7,7 +7,7 @@
namespace Drupal\views\Tests\Handler;
use ViewsSqlTest;
use Drupal\views\Tests\ViewsSqlTest;
/**
* Tests for core views_handler_sort_random handler.
......
......@@ -7,7 +7,7 @@
namespace Drupal\views\Tests\Handler;
use ViewsSqlTest;
use Drupal\views\Tests\ViewsSqlTest;
/**
* Tests for core views_handler_sort handler.
......
......@@ -7,8 +7,6 @@
namespace Drupal\views\Tests;
use ViewsSqlTest;
/**
* Tests abstract handlers of views.
*/
......
......@@ -7,8 +7,6 @@
namespace Drupal\views\Tests;
use ViewsSqlTest;
/**
* Tests basic functions from the Views module.
*/
......
......@@ -7,7 +7,6 @@
namespace Drupal\views\Tests;
use ViewsSqlTest;
use Drupal\views\View;
/**
......
......@@ -7,7 +7,7 @@
namespace Drupal\views\Tests\Plugins;
use ViewsSqlTest;
use Drupal\views\Tests\ViewsSqlTest;
use Drupal\views\View;
/**
......
......@@ -8,7 +8,6 @@
namespace Drupal\views\Tests;
use Drupal\views\View;
use ViewsSqlTest;
/**
* Tests aggregate functionality of views, for example count.
......
......@@ -7,7 +7,7 @@
namespace Drupal\views\Tests\Style;
use ViewsSqlTest;
use Drupal\views\Tests\ViewsSqlTest;
use Drupal\views\View;
/**
......
......@@ -9,7 +9,7 @@
use stdClass;
use DOMDocument;
use ViewsSqlTest;
use Drupal\views\Tests\ViewsSqlTest;
/**
* Tests some general style plugin related functionality.
......
......@@ -8,7 +8,7 @@
namespace Drupal\views\Tests\Style;
use DOMDocument;
use ViewsSqlTest;
use Drupal\views\Tests\ViewsSqlTest;
/**
* Tests the default/unformatted row style.
......
......@@ -7,7 +7,6 @@
namespace Drupal\views\Tests;
use ViewsSqlTest;
use Drupal\views\View;
/**
......
......@@ -7,7 +7,6 @@
namespace Drupal\views\Tests;
use ViewsSqlTest;
use Drupal\views\View;
/**
......
......@@ -8,7 +8,7 @@
namespace Drupal\views\Tests\User;
use Drupal\views\View;
use ViewsSqlTest;
use Drupal\views\Tests\ViewsSqlTest;
/**
* Tests the field username handler.
......
......@@ -8,7 +8,7 @@
namespace Drupal\views\Tests\User;
use Drupal\views\View;
use ViewsSqlTest;
use Drupal\views\Tests\ViewsSqlTest;
/**
* Tests views user argument default plugin.
......
......@@ -8,7 +8,7 @@
namespace Drupal\views\Tests\User;
use Drupal\views\View;
use ViewsSqlTest;
use Drupal\views\Tests\ViewsSqlTest;
/**
* Tests views user argument argument handler.
......
......@@ -8,7 +8,7 @@
namespace Drupal\views\Tests\User;
use Drupal\views\View;
use ViewsSqlTest;
use Drupal\views\Tests\ViewsSqlTest;
/**
* Tests basic user module integration into views.
......
......@@ -7,7 +7,6 @@
namespace Drupal\views\Tests;
use ViewsSqlTest;
use Drupal\views\View;
/**
......
<?php
/**
* @file
* Tests for Views query features.
* Definition of Drupal\views\Tests\ViewsSqlTest
*/
namespace Drupal\views\Tests;
use Drupal\simpletest\WebTestBase;
use Drupal\views\View;
/**
* Abstract class for views testing.
*/
abstract class ViewsTestCase extends WebTestBase {
/**
* 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.
*
* @param $view
* An executed View.
* @param $expected_result
* An expected result set.
* @param $column_map
* An associative array mapping the columns of the result set from the view
* (as keys) and the expected result set (as values).
*/
protected function assertIdenticalResultset($view, $expected_result, $column_map = array(), $message = 'Identical result set') {
return $this->assertIdenticalResultsetHelper($view, $expected_result, $column_map, $message, 'assertIdentical');
}
/**
* Helper function: verify a result set returned by view..
*
* Inverse of ViewsTestCase::assertIdenticalResultset().
*
* @param $view
* An executed View.
* @param $expected_result
* An expected result set.
* @param $column_map
* An associative array mapping the columns of the result set from the view
* (as keys) and the expected result set (as values).
*/
protected function assertNotIdenticalResultset($view, $expected_result, $column_map = array(), $message = 'Identical result set') {
return $this->assertIdenticalResultsetHelper($view, $expected_result, $column_map, $message, 'assertNotIdentical');
}
protected function assertIdenticalResultsetHelper($view, $expected_result, $column_map, $message, $assert_method) {
// 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) (is_object($value) ? $value->$expected_column : $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->$assert_method($result, $expected_result, $message);
}
/**
* Helper function: order an array of array based on a column.
*/
protected function orderResultSet($result_set, $column, $reverse = FALSE) {
$this->sort_column = $column;
$this->sort_order = $reverse ? -1 : 1;
usort($result_set, array($this, 'helperCompareFunction'));
return $result_set;
}
protected $sort_column = NULL;
protected $sort_order = 1;
/**
* Helper comparison function for orderResultSet().
*/
protected function helperCompareFunction($a, $b) {
$value1 = $a[$this->sort_column];
$value2 = $b[$this->sort_column];
if ($value1 == $value2) {
return 0;
}
return $this->sort_order * (($value1 < $value2) ? -1 : 1);
}
/**
* Helper function to check whether a button with a certain id exists and has a certain label.
*/
protected function helperButtonHasLabel($id, $expected_label, $message = 'Label has the expected value: %label.') {
return $this->assertFieldById($id, $expected_label, t($message, array('%label' => $expected_label)));
}
/**
* Helper function to execute a view with debugging.
*
* @param view $view
* @param array $args
*/
protected function executeView($view, $args = array()) {
$view->set_display();
$view->pre_execute($args);
$view->execute();
$this->verbose('<pre>Executed view: ' . ((string) $view->build_info['query']) . '</pre>');
}
}