Skip to content
Snippets Groups Projects
Commit 63ef6069 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2410539 by cafuego, jibran, larowlan: Views schema prevents saving of...

Issue #2410539 by cafuego, jibran, larowlan: Views schema prevents saving of view with disabled display through code
parent ef2a4a08
No related branches found
No related tags found
No related merge requests found
......@@ -4,6 +4,9 @@ views_display:
type: mapping
label: 'Display options'
mapping:
enabled:
type: boolean
label: 'Status'
title:
type: text
label: 'Display title'
......
<?php
/**
* @file
* Contains \Drupal\views\Tests\Plugin\DisabledDisplayTest.
*/
namespace Drupal\views\Tests\Plugin;
/**
* Tests the ability to disable and enable view displays.
*
* @group views
* @see \Drupal\views\Plugin\views\display\Feed
*/
class DisabledDisplayTest extends PluginTestBase {
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = array('test_disabled_display');
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('block', 'node', 'views');
protected function setUp() {
parent::setUp();
$this->enableViewsTestModule();
$admin_user = $this->drupalCreateUser(array('administer site configuration'));
$this->drupalLogin($admin_user);
}
/**
* Tests that views displays can be disabled.
*
* This method only checks the page displays via a HTTP request, but should
* the .enabled property disappear from the schema both the load and save
* calls will start failing.
*/
public function testDisabledDisplays() {
// The displays defined in this view.
$display_ids = array('attachment_1', 'block_1', 'embed_1', 'feed_1', 'page_2');
$this->drupalCreateContentType(['type' => 'page']);
$this->drupalCreateNode();
// Load the test view and initialize its displays.
$view = $this->container->get('entity.manager')->getStorage('view')->load('test_disabled_display');
$view->getExecutable()->setDisplay();
// Enabled page display should return content.
$this->drupalGet('test-disabled-display');
$result = $this->xpath('//h1');
$this->assertEqual($result[0], 'test_disabled_display', 'The enabled page_1 display is accessible.');
// Disabled page view should 404.
$this->drupalGet('test-disabled-display-2');
$this->assertResponse(404);
// Enable each disabled display and save the view.
foreach ($display_ids as $display_id) {
$view->getExecutable()->displayHandlers->get($display_id)->setOption('enabled', TRUE);
$view->save();
$enabled = $view->getExecutable()->displayHandlers->get($display_id)->isEnabled();
$this->assertTrue($enabled, 'Display ' . $display_id . ' is now enabled');
}
// Check that the originally disabled page_2 display is now enabled.
$this->drupalGet('test-disabled-display-2');
$result = $this->xpath('//h1');
$this->assertEqual($result[0], 'test_disabled_display', 'The enabled page_2 display is accessible.');
// Disable each disabled display and save the view.
foreach ($display_ids as $display_id) {
$view->getExecutable()->displayHandlers->get($display_id)->setOption('enabled', FALSE);
$view->save();
$enabled = $view->getExecutable()->displayHandlers->get($display_id)->isEnabled();
$this->assertFalse($enabled, 'Display ' . $display_id . ' is now disabled');
}
// Check that the page_1 display still works.
$this->drupalGet('test-disabled-display');
$this->assertResponse(200);
// Check that the page_2 display is now disabled again.
$this->drupalGet('test-disabled-display-2');
$this->assertResponse(404);
}
}
langcode: und
status: true
dependencies:
config:
- core.entity_view_mode.node.teaser
module:
- node
- user
id: test_disabled_display
label: test_disabled_display
module: views
description: ''
tag: ''
base_table: node
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: none
options: { }
query:
type: views_query
options:
disable_sql_rewrite: false
distinct: false
replica: false
query_comment: false
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: full
options:
items_per_page: 10
offset: 0
id: 0
total_pages: null
expose:
items_per_page: false
items_per_page_label: 'Items per page'
items_per_page_options: '5, 10, 25, 50'
items_per_page_options_all: false
items_per_page_options_all_label: '- All -'
offset: false
offset_label: Offset
tags:
previous: ' previous'
next: 'next ›'
first: '« first'
last: 'last »'
quantity: 9
style:
type: default
row:
type: 'entity:node'
options:
view_mode: teaser
fields:
title:
id: title
table: node_field_data
field: title
entity_type: node
entity_field: title
label: ''
alter:
alter_text: false
make_link: false
absolute: false
trim: false
word_boundary: false
ellipsis: false
strip_tags: false
html: false
hide_empty: false
empty_zero: false
link_to_node: true
plugin_id: node
relationship: none
group_type: group
admin_label: ''
exclude: 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_alter_empty: true
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
sorts:
created:
id: created
table: node_field_data
field: created
order: DESC
entity_type: node
entity_field: created
plugin_id: date
relationship: none
group_type: group
admin_label: ''
exposed: false
expose:
label: ''
granularity: second
title: test_disabled_display
header: { }
footer: { }
empty: { }
relationships: { }
arguments: { }
display_extenders: { }
field_langcode: '***LANGUAGE_language_content***'
field_langcode_add_to_query: null
attachment_1:
display_plugin: attachment
id: attachment_1
display_title: 'Attachment Disabled'
position: 1
display_options:
display_extenders: { }
field_langcode: '***LANGUAGE_language_content***'
field_langcode_add_to_query: null
displays:
page_2: page_2
display_description: ''
enabled: false
block_1:
display_plugin: block
id: block_1
display_title: 'Block Disabled'
position: 1
display_options:
display_extenders: { }
field_langcode: '***LANGUAGE_language_content***'
field_langcode_add_to_query: null
display_description: ''
enabled: false
embed_1:
display_plugin: embed
id: embed_1
display_title: 'Embed Disabled'
position: 1
display_options:
display_extenders: { }
field_langcode: '***LANGUAGE_language_content***'
field_langcode_add_to_query: null
display_description: ''
enabled: false
feed_1:
display_plugin: feed
id: feed_1
display_title: 'Feed Disabled'
position: 1
display_options:
display_extenders: { }
field_langcode: '***LANGUAGE_language_content***'
field_langcode_add_to_query: null
display_description: ''
enabled: false
path: test-disabled-display.xml
page_1:
display_plugin: page
id: page_1
display_title: Page
position: 1
display_options:
display_extenders: { }
field_langcode: '***LANGUAGE_language_content***'
field_langcode_add_to_query: null
path: test-disabled-display
page_2:
display_plugin: page
id: page_2
display_title: 'Page Disabled'
position: 2
display_options:
display_extenders: { }
field_langcode: '***LANGUAGE_language_content***'
field_langcode_add_to_query: null
path: test-disabled-display-2
display_description: ''
enabled: false
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment