Skip to content
Snippets Groups Projects
Commit df6e7c15 authored by Daniel Wehner's avatar Daniel Wehner Committed by Tim Plunkett
Browse files

Issue #1777194 by dawehner, aspilicious: One handler test to rule them all.

parent d27e8b5b
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -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));
}
}
}
......
......@@ -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.
......
<?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);
}
}
}
}
}
}
......@@ -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;
}
}
/**
......
......@@ -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 {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment