Issue #2208811 by Pol, ivanjaros, dawehner, wizonesolutions: views_embed_view() cannot handle arguments
parent
d04b472386
commit
40d6c147c5
|
@ -23,7 +23,7 @@ class ModuleTest extends ViewUnitTestBase {
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public static $testViews = array('test_view_status', 'test_view');
|
public static $testViews = array('test_view_status', 'test_view', 'test_argument');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Modules to enable.
|
* Modules to enable.
|
||||||
|
@ -268,6 +268,71 @@ class ModuleTest extends ViewUnitTestBase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests views.module: views_embed_view().
|
||||||
|
*/
|
||||||
|
public function testViewsEmbedView() {
|
||||||
|
$this->enableModules(array('user'));
|
||||||
|
|
||||||
|
$result = views_embed_view('test_argument');
|
||||||
|
$this->assertEqual(count($result['#view']->result), 5);
|
||||||
|
|
||||||
|
$result = views_embed_view('test_argument', 'default', 1);
|
||||||
|
$this->assertEqual(count($result['#view']->result), 1);
|
||||||
|
|
||||||
|
$result = views_embed_view('test_argument', 'default', '1,2');
|
||||||
|
$this->assertEqual(count($result['#view']->result), 2);
|
||||||
|
|
||||||
|
$result = views_embed_view('test_argument', 'default', '1,2', 'John');
|
||||||
|
$this->assertEqual(count($result['#view']->result), 1);
|
||||||
|
|
||||||
|
$result = views_embed_view('test_argument', 'default', '1,2', 'John,George');
|
||||||
|
$this->assertEqual(count($result['#view']->result), 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests the \Drupal\views\ViewsExecutable::preview() method.
|
||||||
|
*/
|
||||||
|
public function testViewsPreview() {
|
||||||
|
$this->enableModules(array('user'));
|
||||||
|
|
||||||
|
$view = Views::getView('test_argument');
|
||||||
|
$result = $view->preview('default');
|
||||||
|
$this->assertEqual(count($result['#view']->result), 5);
|
||||||
|
|
||||||
|
$view = Views::getView('test_argument');
|
||||||
|
$result = $view->preview('default', array('0' => 1));
|
||||||
|
$this->assertEqual(count($result['#view']->result), 1);
|
||||||
|
|
||||||
|
$view = Views::getView('test_argument');
|
||||||
|
$result = $view->preview('default', array('3' => 1));
|
||||||
|
$this->assertEqual(count($result['#view']->result), 1);
|
||||||
|
|
||||||
|
$view = Views::getView('test_argument');
|
||||||
|
$result = $view->preview('default', array('0' => '1,2'));
|
||||||
|
$this->assertEqual(count($result['#view']->result), 2);
|
||||||
|
|
||||||
|
$view = Views::getView('test_argument');
|
||||||
|
$result = $view->preview('default', array('3' => '1,2'));
|
||||||
|
$this->assertEqual(count($result['#view']->result), 2);
|
||||||
|
|
||||||
|
$view = Views::getView('test_argument');
|
||||||
|
$result = $view->preview('default', array('0' => '1,2', '1' => 'John'));
|
||||||
|
$this->assertEqual(count($result['#view']->result), 1);
|
||||||
|
|
||||||
|
$view = Views::getView('test_argument');
|
||||||
|
$result = $view->preview('default', array('3' => '1,2', '4' => 'John'));
|
||||||
|
$this->assertEqual(count($result['#view']->result), 1);
|
||||||
|
|
||||||
|
$view = Views::getView('test_argument');
|
||||||
|
$result = $view->preview('default', array('0' => '1,2', '1' => 'John,George'));
|
||||||
|
$this->assertEqual(count($result['#view']->result), 2);
|
||||||
|
|
||||||
|
$view = Views::getView('test_argument');
|
||||||
|
$result = $view->preview('default', array('3' => '1,2', '4' => 'John,George'));
|
||||||
|
$this->assertEqual(count($result['#view']->result), 2);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper to return an expected views option array.
|
* Helper to return an expected views option array.
|
||||||
*
|
*
|
||||||
|
|
|
@ -118,7 +118,7 @@ abstract class ViewUnitTestBase extends KernelTestBase {
|
||||||
* @param array $args
|
* @param array $args
|
||||||
* (optional) An array of the view arguments to use for the view.
|
* (optional) An array of the view arguments to use for the view.
|
||||||
*/
|
*/
|
||||||
protected function executeView($view, $args = array()) {
|
protected function executeView($view, array $args = array()) {
|
||||||
$view->setDisplay();
|
$view->setDisplay();
|
||||||
$view->preExecute($args);
|
$view->preExecute($args);
|
||||||
$view->execute();
|
$view->execute();
|
||||||
|
|
|
@ -483,8 +483,10 @@ class ViewExecutable implements \Serializable {
|
||||||
* Set the arguments that come to this view. Usually from the URL
|
* Set the arguments that come to this view. Usually from the URL
|
||||||
* but possibly from elsewhere.
|
* but possibly from elsewhere.
|
||||||
*/
|
*/
|
||||||
public function setArguments($args) {
|
public function setArguments(array $args) {
|
||||||
$this->args = $args;
|
// The array keys of the arguments will be incorrect if set by
|
||||||
|
// views_embed_view() or \Drupal\views\ViewExecutable:preview().
|
||||||
|
$this->args = array_values($args);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -0,0 +1,129 @@
|
||||||
|
langcode: en
|
||||||
|
status: true
|
||||||
|
dependencies: { }
|
||||||
|
label: ''
|
||||||
|
module: views
|
||||||
|
description: ''
|
||||||
|
tag: ''
|
||||||
|
base_table: views_test_data
|
||||||
|
base_field: nid
|
||||||
|
core: '8'
|
||||||
|
id: test_argument
|
||||||
|
display:
|
||||||
|
default:
|
||||||
|
display_options:
|
||||||
|
defaults:
|
||||||
|
fields: false
|
||||||
|
pager: false
|
||||||
|
sorts: false
|
||||||
|
arguments: false
|
||||||
|
fields:
|
||||||
|
age:
|
||||||
|
field: age
|
||||||
|
id: age
|
||||||
|
relationship: none
|
||||||
|
table: views_test_data
|
||||||
|
id:
|
||||||
|
field: id
|
||||||
|
id: id
|
||||||
|
relationship: none
|
||||||
|
table: views_test_data
|
||||||
|
name:
|
||||||
|
field: name
|
||||||
|
id: name
|
||||||
|
relationship: none
|
||||||
|
table: views_test_data
|
||||||
|
pager:
|
||||||
|
options:
|
||||||
|
offset: 0
|
||||||
|
type: none
|
||||||
|
sorts:
|
||||||
|
id:
|
||||||
|
field: id
|
||||||
|
id: id
|
||||||
|
order: ASC
|
||||||
|
relationship: none
|
||||||
|
table: views_test_data
|
||||||
|
arguments:
|
||||||
|
id:
|
||||||
|
id: id
|
||||||
|
table: views_test_data
|
||||||
|
field: id
|
||||||
|
relationship: none
|
||||||
|
group_type: group
|
||||||
|
admin_label: ''
|
||||||
|
default_action: ignore
|
||||||
|
exception:
|
||||||
|
value: all
|
||||||
|
title_enable: false
|
||||||
|
title: All
|
||||||
|
title_enable: false
|
||||||
|
title: ''
|
||||||
|
default_argument_type: fixed
|
||||||
|
default_argument_options:
|
||||||
|
argument: ''
|
||||||
|
default_argument_skip_url: false
|
||||||
|
summary_options:
|
||||||
|
base_path: ''
|
||||||
|
count: true
|
||||||
|
items_per_page: 25
|
||||||
|
override: false
|
||||||
|
summary:
|
||||||
|
sort_order: asc
|
||||||
|
number_of_records: 0
|
||||||
|
format: default_summary
|
||||||
|
specify_validation: false
|
||||||
|
validate:
|
||||||
|
type: none
|
||||||
|
fail: 'not found'
|
||||||
|
validate_options: { }
|
||||||
|
break_phrase: true
|
||||||
|
not: false
|
||||||
|
entity_type: node
|
||||||
|
entity_field: nid
|
||||||
|
plugin_id: numeric
|
||||||
|
name:
|
||||||
|
id: title
|
||||||
|
table: views_test_data
|
||||||
|
field: name
|
||||||
|
relationship: none
|
||||||
|
group_type: group
|
||||||
|
admin_label: ''
|
||||||
|
default_action: ignore
|
||||||
|
exception:
|
||||||
|
value: all
|
||||||
|
title_enable: false
|
||||||
|
title: All
|
||||||
|
title_enable: false
|
||||||
|
title: ''
|
||||||
|
default_argument_type: fixed
|
||||||
|
default_argument_options:
|
||||||
|
argument: ''
|
||||||
|
default_argument_skip_url: false
|
||||||
|
summary_options:
|
||||||
|
base_path: ''
|
||||||
|
count: true
|
||||||
|
items_per_page: 25
|
||||||
|
override: false
|
||||||
|
summary:
|
||||||
|
sort_order: asc
|
||||||
|
number_of_records: 0
|
||||||
|
format: default_summary
|
||||||
|
specify_validation: false
|
||||||
|
validate:
|
||||||
|
type: none
|
||||||
|
fail: 'not found'
|
||||||
|
validate_options: { }
|
||||||
|
glossary: false
|
||||||
|
limit: 0
|
||||||
|
case: none
|
||||||
|
path_case: none
|
||||||
|
transform_dash: false
|
||||||
|
break_phrase: true
|
||||||
|
entity_type: node
|
||||||
|
entity_field: name
|
||||||
|
plugin_id: string
|
||||||
|
display_plugin: default
|
||||||
|
display_title: Master
|
||||||
|
id: default
|
||||||
|
position: 0
|
Loading…
Reference in New Issue