summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorxjm2015-11-12 16:03:47 (GMT)
committerxjm2015-11-12 16:04:02 (GMT)
commit1f4013c50543a556c23fcb9b4745a2261e3506cb (patch)
tree8670f29dbdd087137a37490925f00f96ce47c1db
parent8485135f1a1b057f1e69f86b17fb0854bc6e2933 (diff)
Issue #2340623 by ceng, R.Muilwijk, dawehner, klausi, Rj-dupe-1, xjm, sebas5384: Views REST export does not support exposed filters
-rw-r--r--core/modules/rest/src/Plugin/views/display/RestExport.php2
-rw-r--r--core/modules/rest/src/Tests/Views/StyleSerializerTest.php62
-rw-r--r--core/modules/rest/tests/modules/rest_test_views/test_views/views.view.test_serializer_node_exposed_filter.yml172
3 files changed, 234 insertions, 2 deletions
diff --git a/core/modules/rest/src/Plugin/views/display/RestExport.php b/core/modules/rest/src/Plugin/views/display/RestExport.php
index 427becf..68bd407 100644
--- a/core/modules/rest/src/Plugin/views/display/RestExport.php
+++ b/core/modules/rest/src/Plugin/views/display/RestExport.php
@@ -151,7 +151,7 @@ class RestExport extends PathPluginBase implements ResponseDisplayPluginInterfac
* {@inheritdoc}
*/
public function usesExposed() {
- return FALSE;
+ return TRUE;
}
/**
diff --git a/core/modules/rest/src/Tests/Views/StyleSerializerTest.php b/core/modules/rest/src/Tests/Views/StyleSerializerTest.php
index 5f378ee..e3b8d26 100644
--- a/core/modules/rest/src/Tests/Views/StyleSerializerTest.php
+++ b/core/modules/rest/src/Tests/Views/StyleSerializerTest.php
@@ -50,7 +50,7 @@ class StyleSerializerTest extends PluginTestBase {
*
* @var array
*/
- public static $testViews = array('test_serializer_display_field', 'test_serializer_display_entity', 'test_serializer_node_display_field');
+ public static $testViews = array('test_serializer_display_field', 'test_serializer_display_entity', 'test_serializer_node_display_field', 'test_serializer_node_exposed_filter');
/**
* A user with administrative privileges to look at test entity and configure views.
@@ -609,4 +609,64 @@ class StyleSerializerTest extends PluginTestBase {
}
$this->assertEqual($serializer->serialize($expected, 'json'), (string) $renderer->renderRoot($build));
}
+
+ /**
+ * Tests the exposed filter works.
+ *
+ * There is an exposed filter on the title field which takes a title query
+ * parameter. This is set to filter nodes by those whose title starts with
+ * the value provided.
+ */
+ public function testRestViewExposedFilter() {
+ $this->drupalCreateContentType(array('type' => 'page'));
+ $node0 = $this->drupalCreateNode(array('title' => 'Node 1'));
+ $node1 = $this->drupalCreateNode(array('title' => 'Node 11'));
+ $node2 = $this->drupalCreateNode(array('title' => 'Node 111'));
+
+ // Test that no filter brings back all three nodes.
+ $result = $this->drupalGetJSON('test/serialize/node-exposed-filter');
+
+ $expected = array(
+ 0 => array(
+ 'nid' => $node0->id(),
+ 'body' => $node0->body->processed,
+ ),
+ 1 => array(
+ 'nid' => $node1->id(),
+ 'body' => $node1->body->processed,
+ ),
+ 2 => array(
+ 'nid' => $node2->id(),
+ 'body' => $node2->body->processed,
+ ),
+ );
+
+ $this->assertEqual($result, $expected, 'Querying a view with no exposed filter returns all nodes.');
+
+ // Test that title starts with 'Node 11' query finds 2 of the 3 nodes.
+ $result = $this->drupalGetJSON('test/serialize/node-exposed-filter', ['query' => ['title' => 'Node 11']]);
+
+ $expected = array(
+ 0 => array(
+ 'nid' => $node1->id(),
+ 'body' => $node1->body->processed,
+ ),
+ 1 => array(
+ 'nid' => $node2->id(),
+ 'body' => $node2->body->processed,
+ ),
+ );
+
+ $cache_contexts = [
+ 'languages:language_content',
+ 'languages:language_interface',
+ 'theme',
+ 'request_format',
+ 'user.node_grants:view',
+ 'url',
+ ];
+
+ $this->assertEqual($result, $expected, 'Querying a view with a starts with exposed filter on the title returns nodes whose title starts with value provided.');
+ $this->assertCacheContexts($cache_contexts);
+ }
}
diff --git a/core/modules/rest/tests/modules/rest_test_views/test_views/views.view.test_serializer_node_exposed_filter.yml b/core/modules/rest/tests/modules/rest_test_views/test_views/views.view.test_serializer_node_exposed_filter.yml
new file mode 100644
index 0000000..b5af1e9
--- /dev/null
+++ b/core/modules/rest/tests/modules/rest_test_views/test_views/views.view.test_serializer_node_exposed_filter.yml
@@ -0,0 +1,172 @@
+langcode: en
+status: true
+dependencies:
+ config:
+ - field.storage.node.body
+ module:
+ - field
+ - node
+ - rest
+ - rest_test_views
+ - user
+id: test_serializer_node_exposed_filter
+label: 'Test serializer display for exposed filters'
+module: rest_test_views
+description: ''
+tag: ''
+base_table: node_field_data
+base_field: nid
+core: 8.x
+display:
+ default:
+ display_plugin: default
+ id: default
+ display_title: Master
+ position: null
+ display_options:
+ access:
+ type: perm
+ options:
+ perm: 'access content'
+ cache:
+ type: tag
+ query:
+ type: views_query
+ exposed_form:
+ type: basic
+ style:
+ type: serializer
+ row:
+ type: data_field
+ fields:
+ nid:
+ id: nid
+ table: node
+ field: nid
+ plugin_id: field
+ entity_type: node
+ entity_field: nid
+ body:
+ id: body
+ table: node__body
+ field: body
+ relationship: none
+ group_type: group
+ admin_label: ''
+ label: Body
+ exclude: false
+ alter:
+ alter_text: false
+ text: ''
+ make_link: false
+ path: ''
+ absolute: false
+ external: false
+ replace_spaces: false
+ path_case: none
+ trim_whitespace: false
+ alt: ''
+ rel: ''
+ link_class: ''
+ prefix: ''
+ suffix: ''
+ target: ''
+ nl2br: false
+ max_length: 0
+ word_boundary: true
+ ellipsis: true
+ more_link: false
+ more_link_text: ''
+ more_link_path: ''
+ strip_tags: false
+ trim: false
+ preserve_tags: ''
+ html: false
+ element_type: ''
+ element_class: ''
+ element_label_type: ''
+ element_label_class: ''
+ element_label_colon: true
+ element_wrapper_type: ''
+ element_wrapper_class: ''
+ element_default_classes: true
+ empty: ''
+ hide_empty: false
+ empty_zero: false
+ hide_alter_empty: true
+ click_sort_column: value
+ type: text_default
+ settings: { }
+ group_column: value
+ group_columns: { }
+ group_rows: true
+ delta_limit: 0
+ delta_offset: 0
+ delta_reversed: false
+ delta_first_last: false
+ multi_type: separator
+ separator: ', '
+ field_api_classes: false
+ plugin_id: field
+ entity_type: node
+ entity_field: body
+ filters:
+ title:
+ id: title
+ table: node_field_data
+ field: title
+ relationship: none
+ group_type: group
+ admin_label: ''
+ operator: starts
+ value: ''
+ group: 1
+ exposed: true
+ expose:
+ operator_id: title_op
+ label: Title
+ description: ''
+ use_operator: false
+ operator: title_op
+ identifier: title
+ required: false
+ remember: false
+ multiple: false
+ remember_roles:
+ authenticated: authenticated
+ anonymous: '0'
+ administrator: '0'
+ is_grouped: false
+ group_info:
+ label: ''
+ description: ''
+ identifier: ''
+ optional: true
+ widget: select
+ multiple: false
+ remember: false
+ default_group: All
+ default_group_multiple: { }
+ group_items: { }
+ entity_type: node
+ entity_field: title
+ plugin_id: string
+ title: 'Test serialize'
+ arguments: { }
+ rest_export_1:
+ display_plugin: rest_export
+ id: rest_export_1
+ display_title: serializer
+ position: null
+ display_options:
+ defaults:
+ access: false
+ style: false
+ row: false
+ path: test/serialize/node-exposed-filter
+ access:
+ type: none
+ style:
+ type: serializer
+ row:
+ type: data_field