From df6e7c15c9add09873475a771c740c9a062f6901 Mon Sep 17 00:00:00 2001 From: dereine <dereine@99340.no-reply.drupal.org> Date: Sun, 30 Sep 2012 17:35:39 -0400 Subject: [PATCH] Issue #1777194 by dawehner, aspilicious: One handler test to rule them all. --- lib/Drupal/views/ManyToOneHelper.php | 8 +- .../views/Plugin/views/join/Subquery.php | 15 ++- .../views/Tests/Handler/HandlerAllTest.php | 106 ++++++++++++++++++ lib/Drupal/views/ViewExecutable.php | 4 + .../Plugin/views/field/TaxonomyIndexTid.php | 2 +- 5 files changed, 128 insertions(+), 7 deletions(-) create mode 100644 lib/Drupal/views/Tests/Handler/HandlerAllTest.php diff --git a/lib/Drupal/views/ManyToOneHelper.php b/lib/Drupal/views/ManyToOneHelper.php index 280fa35f0fd7..18320eba02ea 100644 --- a/lib/Drupal/views/ManyToOneHelper.php +++ b/lib/Drupal/views/ManyToOneHelper.php @@ -307,7 +307,13 @@ function add_filter() { $this->handler->query->add_where_expression($options['group'], "$field $operator", $placeholders); } else { - $this->handler->query->add_where($options['group'], $field, $value, $operator); + $placeholder = $this->placeholder(); + if (count($this->handler->value) > 1) { + $this->query->add_where_expression(0, "$field $operator($placeholder)", array($placeholder => $value)); + } + else { + $this->handler->query->add_where_expression(0, "$field $operator $placeholder", array($placeholder => $value)); + } } } diff --git a/lib/Drupal/views/Plugin/views/join/Subquery.php b/lib/Drupal/views/Plugin/views/join/Subquery.php index 41583b669b0e..913c866a72f0 100644 --- a/lib/Drupal/views/Plugin/views/join/Subquery.php +++ b/lib/Drupal/views/Plugin/views/join/Subquery.php @@ -7,6 +7,7 @@ namespace Drupal\views\Plugin\views\join; use Drupal\Core\Annotation\Plugin; +use Drupal\Component\Plugin\Discovery\DiscoveryInterface; /** * Join handler for relationships that join with a subquery as the left field. @@ -23,9 +24,13 @@ */ class Subquery extends JoinPluginBase { - function construct($table = NULL, $left_table = NULL, $left_field = NULL, $field = NULL, $extra = array(), $type = 'LEFT') { - parent::construct($table, $left_table, $left_field, $field, $extra, $type); - $this->left_query = $this->definition['left_query']; + /** + * Constructs a Subquery object. + */ + public function __construct(array $configuration, $plugin_id, DiscoveryInterface $discovery) { + parent::__construct($configuration, $plugin_id, $discovery); + + $this->left_query = $this->configuration['left_query']; } /** @@ -41,11 +46,11 @@ function construct($table = NULL, $left_table = NULL, $left_field = NULL, $field * */ public function buildJoin($select_query, $table, $view_query) { - if (empty($this->definition['table formula'])) { + if (empty($this->configuration['table formula'])) { $right_table = "{" . $this->table . "}"; } else { - $right_table = $this->definition['table formula']; + $right_table = $this->configuration['table formula']; } // Add our join condition, using a subquery on the left instead of a field. diff --git a/lib/Drupal/views/Tests/Handler/HandlerAllTest.php b/lib/Drupal/views/Tests/Handler/HandlerAllTest.php new file mode 100644 index 000000000000..8b5bb3a9fd34 --- /dev/null +++ b/lib/Drupal/views/Tests/Handler/HandlerAllTest.php @@ -0,0 +1,106 @@ +<?php + +/** + * @file + * Definition of Drupal\views\Tests\Handler\HandlerAllTest. + */ + +namespace Drupal\views\Tests\Handler; + +use Drupal\views\ViewExecutable; +use Drupal\views\Plugin\views\HandlerBase; +use Drupal\views\Plugin\views\filter\InOperator; + +/** + * Creates views with instances of all handlers... + */ +class HandlerAllTest extends HandlerTestBase { + + /** + * Modules to enable. + * + * @var array + */ + public static $modules = array( + 'aggregator', + 'book', + 'block', + 'comment', + 'contact', + 'field', + 'filter', + 'file', + 'language', + 'locale', + 'node', + 'search', + 'statistics', + 'system', + 'taxonomy', + 'translation', + 'user' + ); + + public static function getInfo() { + return array( + 'name' => 'Handlers: All', + 'description' => 'Test instances of all handlers.', + 'group' => 'Views Handlers', + ); + } + + /** + * Tests most of the handlers. + */ + public function testHandlers() { + $object_types = array_keys(ViewExecutable::viewsHandlerTypes()); + foreach (views_fetch_data() as $base_table => $info) { + if (!isset($info['table']['base'])) { + continue; + } + + $view = views_new_view(); + $view->base_table = $base_table; + $view = new ViewExecutable($view); + + // @todo The groupwise relationship is currently broken. + $exclude[] = 'taxonomy_term_data:tid_representative'; + $exclude[] = 'users:uid_representative'; + + // Go through all fields and there through all handler types. + foreach ($info as $field => $field_info) { + // Table is a reserved key for the metainformation. + if ($field != 'table' && !in_array("$base_table:$field", $exclude)) { + foreach ($object_types as $type) { + if (isset($field_info[$type]['id'])) { + $options = array(); + if ($type == 'filter') { + $handler = views_get_handler($base_table, $field, $type); + if ($handler instanceof InOperator) { + $options['value'] = array(1); + } + } + $view->addItem('default', $type, $base_table, $field, $options); + } + } + } + } + + // Go through each step invidiually to see whether some parts are failing. + $view->build(); + $view->preExecute(); + $view->execute(); + $view->render(); + + // Make sure all handlers extend the HandlerBase. + foreach ($object_types as $type) { + if (isset($view->{$type})) { + foreach ($view->{$type} as $handler) { + $this->assertTrue($handler instanceof HandlerBase); + } + } + } + } + } + +} diff --git a/lib/Drupal/views/ViewExecutable.php b/lib/Drupal/views/ViewExecutable.php index 215ba2df6247..e311ebdcbfaf 100644 --- a/lib/Drupal/views/ViewExecutable.php +++ b/lib/Drupal/views/ViewExecutable.php @@ -516,6 +516,10 @@ public function usePager() { if (!empty($this->pager)) { return $this->pager->use_pager(); } + // Maybe other code stores something on the view object, so allow that. + else { + $this->{$name} = $value; + } } /** diff --git a/lib/Views/taxonomy/Plugin/views/field/TaxonomyIndexTid.php b/lib/Views/taxonomy/Plugin/views/field/TaxonomyIndexTid.php index c4ec9146cc42..8da53dde52e8 100644 --- a/lib/Views/taxonomy/Plugin/views/field/TaxonomyIndexTid.php +++ b/lib/Views/taxonomy/Plugin/views/field/TaxonomyIndexTid.php @@ -26,7 +26,7 @@ class TaxonomyIndexTid extends PrerenderList { public function init(ViewExecutable $view, &$options) { parent::init($view, $options); // @todo: Wouldn't it be possible to use $this->base_table and no if here? - if ($view->base_table == 'node_revision') { + if ($view->storage->base_table == 'node_revision') { $this->additional_fields['nid'] = array('table' => 'node_revision', 'field' => 'nid'); } else { -- GitLab