From 1f4013c50543a556c23fcb9b4745a2261e3506cb Mon Sep 17 00:00:00 2001 From: xjm <xjm@65776.no-reply.drupal.org> Date: Thu, 12 Nov 2015 10:03:47 -0600 Subject: [PATCH] Issue #2340623 by ceng, R.Muilwijk, dawehner, klausi, Rj-dupe-1, xjm, sebas5384: Views REST export does not support exposed filters --- .../src/Plugin/views/display/RestExport.php | 2 +- .../src/Tests/Views/StyleSerializerTest.php | 62 ++++++- ...ew.test_serializer_node_exposed_filter.yml | 172 ++++++++++++++++++ 3 files changed, 234 insertions(+), 2 deletions(-) create mode 100644 core/modules/rest/tests/modules/rest_test_views/test_views/views.view.test_serializer_node_exposed_filter.yml diff --git a/core/modules/rest/src/Plugin/views/display/RestExport.php b/core/modules/rest/src/Plugin/views/display/RestExport.php index 427becfacf60..68bd407cd289 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 @@ public function getType() { * {@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 5f378ee2f67f..e3b8d263c2e7 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 @@ public function testGroupRows() { } $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 000000000000..b5af1e96b54b --- /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 -- GitLab