From 489c6f757947f8effa03354f101d80b19261e450 Mon Sep 17 00:00:00 2001
From: webchick <webchick@24967.no-reply.drupal.org>
Date: Fri, 2 Nov 2012 14:25:55 -0700
Subject: [PATCH] Issue #1828498 by dawehner: Fixed Query settings aren't
 saved.

---
 .../views/display/DisplayPluginBase.php       |  2 +-
 .../Drupal/views/Plugin/views/query/Sql.php   |  1 -
 .../lib/Drupal/views/Tests/UI/QueryTest.php   | 53 +++++++++++++++++++
 .../Plugin/views/query/QueryTest.php          | 23 ++++++++
 4 files changed, 77 insertions(+), 2 deletions(-)
 create mode 100644 core/modules/views/lib/Drupal/views/Tests/UI/QueryTest.php

diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php b/core/modules/views/lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php
index 726381f4b360..46e79e1f415c 100644
--- a/core/modules/views/lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php
+++ b/core/modules/views/lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php
@@ -2212,7 +2212,7 @@ public function submitOptionsForm(&$form, &$form_state) {
         }
         break;
       case 'query':
-        $plugin = $this->get_plugin('query');
+        $plugin = $this->getPlugin('query');
         if ($plugin) {
           $plugin->submitOptionsForm($form['query']['options'], $form_state);
           $this->setOption('query', $form_state['values'][$section]);
diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/query/Sql.php b/core/modules/views/lib/Drupal/views/Plugin/views/query/Sql.php
index 991d38e7dd96..43e52cade84f 100644
--- a/core/modules/views/lib/Drupal/views/Plugin/views/query/Sql.php
+++ b/core/modules/views/lib/Drupal/views/Plugin/views/query/Sql.php
@@ -246,7 +246,6 @@ public function buildOptionsForm(&$form, &$form_state) {
       '#default_value' => implode(', ', $this->options['query_tags']),
       '#element_validate' => array('views_element_validate_tags'),
     );
-    $form_state['build_info']['files']['foo'] = drupal_get_path('module', 'views') . '/lib/Drupal/views/Plugin/Query/SqlQuery.php';
   }
 
   /**
diff --git a/core/modules/views/lib/Drupal/views/Tests/UI/QueryTest.php b/core/modules/views/lib/Drupal/views/Tests/UI/QueryTest.php
new file mode 100644
index 000000000000..83f0bfa23180
--- /dev/null
+++ b/core/modules/views/lib/Drupal/views/Tests/UI/QueryTest.php
@@ -0,0 +1,53 @@
+<?php
+
+/**
+ * @file
+ * Definition of Drupal\views\Tests\UI\QueryTest.
+ */
+
+namespace Drupal\views\Tests\UI;
+
+use Drupal\views\Tests\ViewTestBase;
+use Drupal\views_test_data\Plugin\views\query\QueryTest as QueryTestPlugin;
+
+/**
+ * Tests query plugins.
+ */
+class QueryTest extends UITestBase {
+
+  public static function getInfo() {
+    return array(
+      'name' => 'Query: UI',
+      'description' => 'Tests query plugins UI.',
+      'group' => 'Views UI'
+    );
+  }
+
+  /**
+   * Overrides \Drupal\views\Tests\ViewTestBase::viewsData().
+   */
+  protected function viewsData() {
+    $data = parent::viewsData();
+    $data['views_test_data']['table']['base']['query_id'] = 'query_test';
+
+    return $data;
+  }
+
+  /**
+   * Tests query plugins settings.
+   */
+  public function testQueryUI() {
+    // Save some query settings.
+    $query_settings_path = "admin/structure/views/nojs/display/test_view/default/query";
+    $random_value = $this->randomName();
+    $this->drupalPost($query_settings_path, array('query[options][test_setting]' => $random_value), t('Apply'));
+    $this->drupalPost(NULL, array(), t('Save'));
+
+    // Check that the settings are saved into the view itself.
+    $view = views_get_view('test_view');
+    $view->initDisplay();
+    $view->initQuery();
+    $this->assertEqual($random_value, $view->query->options['test_setting'], 'Query settings got saved');
+  }
+
+}
diff --git a/core/modules/views/tests/views_test_data/lib/Drupal/views_test_data/Plugin/views/query/QueryTest.php b/core/modules/views/tests/views_test_data/lib/Drupal/views_test_data/Plugin/views/query/QueryTest.php
index eab54df0fca2..4ee2a487f1fa 100644
--- a/core/modules/views/tests/views_test_data/lib/Drupal/views_test_data/Plugin/views/query/QueryTest.php
+++ b/core/modules/views/tests/views_test_data/lib/Drupal/views_test_data/Plugin/views/query/QueryTest.php
@@ -27,6 +27,29 @@ class QueryTest extends QueryPluginBase {
   protected $allItems = array();
   protected $orderBy = array();
 
+  /**
+   * Implements \Drupal\views\Plugin\views\query\QueryPluginBase::defineOptions().
+   */
+  protected function defineOptions() {
+    $options = parent::defineOptions();
+    $options['test_setting'] = array('default' => '');
+
+    return $options;
+  }
+
+  /**
+   * Implements \Drupal\views\Plugin\views\query\QueryPluginBase::buildOptionsForm().
+   */
+  public function buildOptionsForm(&$form, &$form_state) {
+    parent::buildOptionsForm($form, $form_state);
+
+    $form['test_setting'] = array(
+      '#title' => t('Test setting'),
+      '#type' => 'textfield',
+      '#default_value' => $this->options['test_setting'],
+    );
+  }
+
   /**
    * Sets the allItems property.
    *
-- 
GitLab