Commit 2a27ee89 authored by catch's avatar catch

Issue #2660446 by tduong: Test the node argument_default plugin

parent cce99d5a
......@@ -7,6 +7,8 @@
namespace Drupal\views\Tests\Plugin;
use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
use Drupal\views\Views;
use Drupal\views_test_data\Plugin\views\argument_default\ArgumentDefaultTest as ArgumentDefaultTestPlugin;
......@@ -23,14 +25,19 @@ class ArgumentDefaultTest extends PluginTestBase {
*
* @var array
*/
public static $testViews = array('test_view', 'test_argument_default_fixed', 'test_argument_default_current_user');
public static $testViews = array(
'test_view',
'test_argument_default_fixed',
'test_argument_default_current_user',
'test_argument_default_node',
);
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('node', 'views_ui');
public static $modules = array('node', 'views_ui', 'block');
protected function setUp() {
parent::setUp();
......@@ -80,7 +87,7 @@ public function testArgumentDefaultPlugin() {
/**
* Tests the use of a default argument plugin that provides no options.
*/
function testArgumentDefaultNoOptions() {
public function testArgumentDefaultNoOptions() {
$admin_user = $this->drupalCreateUser(array('administer views', 'administer site configuration'));
$this->drupalLogin($admin_user);
......@@ -104,7 +111,7 @@ function testArgumentDefaultNoOptions() {
/**
* Tests fixed default argument.
*/
function testArgumentDefaultFixed() {
public function testArgumentDefaultFixed() {
$random = $this->randomMachineName();
$view = Views::getView('test_argument_default_fixed');
$view->setDisplay();
......@@ -128,8 +135,37 @@ function testArgumentDefaultFixed() {
//function testArgumentDefaultPhp() {}
/**
* @todo Test node default argument.
* Test node default argument.
*/
//function testArgumentDefaultNode() {}
public function testArgumentDefaultNode() {
// Create a user that has permission to place a view block.
$permissions = array(
'administer views',
'administer blocks',
'bypass node access',
'access user profiles',
'view all revisions',
);
$views_admin = $this->drupalCreateUser($permissions);
$this->drupalLogin($views_admin);
// Create nodes where should show themselves again as view block.
$node_type = NodeType::create(['type' => 'page', 'label' => 'Page']);
$node_type->save();
$node1 = Node::create(['title' => 'Test node 1', 'type' => 'page']);
$node1->save();
$node2 = Node::create(['title' => 'Test node 2', 'type' => 'page']);
$node2->save();
// Place the block, visit the pages that display the block, and check that
// the nodes we expect appear in the respective pages.
$id = 'view-block-id';
$this->drupalPlaceBlock("views_block:test_argument_default_node-block_1", ['id' => $id]);
$xpath = '//*[@id="block-' . $id . '"]';
$this->drupalGet('node/' . $node1->id());
$this->assertTrue(strpos($this->xpath($xpath)[0]->asXml(), $node1->getTitle()));
$this->drupalGet('node/' . $node2->id());
$this->assertTrue(strpos($this->xpath($xpath)[0]->asXml(), $node2->getTitle()));
}
}
langcode: en
status: true
dependencies:
config:
- node.type.page
module:
- node
- user
id: test_argument_default_node
label: 'Test argument_default node'
module: 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: 0
display_options:
access:
type: perm
options:
perm: 'access content'
cache:
type: tag
options: { }
query:
type: views_query
options:
disable_sql_rewrite: false
distinct: false
replica: false
query_comment: ''
query_tags: { }
exposed_form:
type: basic
options:
submit_button: Apply
reset_button: false
reset_button_label: Reset
exposed_sorts_label: 'Sort by'
expose_sort_order: true
sort_asc_label: Asc
sort_desc_label: Desc
pager:
type: none
options:
items_per_page: null
offset: 0
style:
type: default
row:
type: fields
fields:
title:
id: title
table: node_field_data
field: title
settings:
link_to_entity: true
plugin_id: field
relationship: none
group_type: group
admin_label: ''
label: ''
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: string
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
filters:
status:
value: true
table: node_field_data
field: status
plugin_id: boolean
entity_type: node
entity_field: status
id: status
expose:
operator: ''
group: 1
type:
id: type
table: node_field_data
field: type
value:
page: page
entity_type: node
entity_field: type
plugin_id: bundle
sorts:
title:
id: title
table: node_field_data
field: title
order: DESC
entity_type: node
entity_field: title
plugin_id: standard
relationship: none
group_type: group
admin_label: ''
exposed: false
expose:
label: ''
title: 'Test argument_default node'
header: { }
footer: { }
empty: { }
relationships: { }
arguments:
nid:
id: nid
table: node_field_data
field: nid
relationship: none
group_type: group
admin_label: ''
default_action: default
exception:
value: all
title_enable: false
title: All
title_enable: false
title: ''
default_argument_type: node
default_argument_options: { }
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: false
not: false
entity_type: node
entity_field: nid
plugin_id: node_nid
display_extenders: { }
cache_metadata:
max-age: -1
contexts:
- 'languages:language_content'
- 'languages:language_interface'
- url
- 'user.node_grants:view'
- user.permissions
tags: { }
block_1:
display_plugin: block
id: block_1
display_title: Block
position: 1
display_options:
display_extenders: { }
cache_metadata:
max-age: -1
contexts:
- 'languages:language_content'
- 'languages:language_interface'
- url
- 'user.node_grants:view'
- user.permissions
tags: { }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment