Skip to content
Snippets Groups Projects
Commit 3ff77eda authored by ad0z's avatar ad0z Committed by Rohit Joshi
Browse files

Resolve #3339320 "Add some test"

parent 69e5d76c
No related branches found
No related tags found
1 merge request!1Resolve #3339320 "Add some test"
Pipeline #72256 passed with warnings
################
# DrupalCI GitLabCI template
#
# Gitlab-ci.yml to replicate DrupalCI testing for Contrib
#
# With thanks to:
# * The GitLab Acceleration Initiative participants
# * DrupalSpoons
################
################
# Guidelines
#
# This template is designed to give any Contrib maintainer everything they need to test, without requiring modification. It is also designed to keep up to date with Core Development automatically through the use of include files that can be centrally maintained.
#
# However, you can modify this template if you have additional needs for your project.
################
################
# Includes
#
# Additional configuration can be provided through includes.
# One advantage of include files is that if they are updated upstream, the changes affect all pipelines using that include.
#
# Includes can be overridden by re-declaring anything provided in an include, here in gitlab-ci.yml
# https://docs.gitlab.com/ee/ci/yaml/includes.html#override-included-configuration-values
################
include:
################
# DrupalCI includes:
# As long as you include this, any future includes added by the Drupal Association will be accessible to your pipelines automatically.
# View these include files at https://git.drupalcode.org/project/gitlab_templates/
################
- project: $_GITLAB_TEMPLATES_REPO
ref: $_GITLAB_TEMPLATES_REF
file:
- '/includes/include.drupalci.main.yml'
# EXPERIMENTAL: For Drupal 7, remove the above line and uncomment the below.
# - '/includes/include.drupalci.main-d7.yml'
- '/includes/include.drupalci.variables.yml'
- '/includes/include.drupalci.workflows.yml'
################
# Pipeline configuration variables
#
# These are the variables provided to the Run Pipeline form that a user may want to override.
#
# Docs at https://git.drupalcode.org/project/gitlab_templates/-/blob/1.0.x/includes/include.drupalci.variables.yml
################
# variables:
# SKIP_ESLINT: '1'
###################################################################################
#
# *
# /(
# ((((,
# /(((((((
# ((((((((((*
# ,(((((((((((((((
# ,(((((((((((((((((((
# ((((((((((((((((((((((((*
# *(((((((((((((((((((((((((((((
# ((((((((((((((((((((((((((((((((((*
# *(((((((((((((((((( .((((((((((((((((((
# ((((((((((((((((((. /(((((((((((((((((*
# /((((((((((((((((( .(((((((((((((((((,
# ,(((((((((((((((((( ((((((((((((((((((
# .(((((((((((((((((((( .(((((((((((((((((
# ((((((((((((((((((((((( ((((((((((((((((/
# (((((((((((((((((((((((((((/ ,(((((((((((((((*
# .((((((((((((((/ /(((((((((((((. ,(((((((((((((((
# *(((((((((((((( ,(((((((((((((/ *((((((((((((((.
# ((((((((((((((, /(((((((((((((. ((((((((((((((,
# (((((((((((((/ ,(((((((((((((* ,(((((((((((((,
# *((((((((((((( .((((((((((((((( ,(((((((((((((
# ((((((((((((/ /((((((((((((((((((. ,((((((((((((/
# ((((((((((((( *(((((((((((((((((((((((* *((((((((((((
# ((((((((((((( ,(((((((((((((..((((((((((((( *((((((((((((
# ((((((((((((, /((((((((((((* /((((((((((((/ ((((((((((((
# ((((((((((((( /((((((((((((/ (((((((((((((* ((((((((((((
# (((((((((((((/ /(((((((((((( ,((((((((((((, *((((((((((((
# (((((((((((((( *(((((((((((/ *((((((((((((. ((((((((((((/
# *((((((((((((((((((((((((((, /(((((((((((((((((((((((((
# ((((((((((((((((((((((((( ((((((((((((((((((((((((,
# .(((((((((((((((((((((((/ ,(((((((((((((((((((((((
# ((((((((((((((((((((((/ ,(((((((((((((((((((((/
# *((((((((((((((((((((( (((((((((((((((((((((,
# ,(((((((((((((((((((((, ((((((((((((((((((((/
# ,(((((((((((((((((((((* /((((((((((((((((((((
# ((((((((((((((((((((((, ,/((((((((((((((((((((,
# ,(((((((((((((((((((((((((((((((((((((((((((((((((((
# .(((((((((((((((((((((((((((((((((((((((((((((
# .((((((((((((((((((((((((((((((((((((,.
# .,(((((((((((((((((((((((((.
#
###################################################################################
uuid: 13792ee9-2ace-49b0-ba67-abdf56640134
langcode: en
status: true
dependencies:
config:
- core.entity_view_mode.node.teaser
module:
- node
id: views_role_based_global_text_test
label: 'Views Role Based Global Text Test'
module: views
description: ''
tag: ''
base_table: node_field_data
base_field: nid
display:
default:
id: default
display_title: Default
display_plugin: default
position: 0
display_options:
title: 'Views Role Based Global Text Test'
fields:
title:
id: title
table: node_field_data
field: title
relationship: none
group_type: group
admin_label: ''
entity_type: node
entity_field: title
plugin_id: field
label: ''
exclude: false
alter:
alter_text: false
make_link: false
absolute: false
word_boundary: false
ellipsis: false
strip_tags: false
trim: false
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
settings:
link_to_entity: true
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
pager:
type: mini
options:
offset: 0
items_per_page: 10
total_pages: null
id: 0
tags:
next: ››
previous: ‹‹
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
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
access:
type: none
options: { }
cache:
type: tag
options: { }
empty: { }
sorts:
created:
id: created
table: node_field_data
field: created
relationship: none
group_type: group
admin_label: ''
entity_type: node
entity_field: created
plugin_id: date
order: DESC
expose:
label: ''
field_identifier: ''
exposed: false
granularity: second
arguments: { }
filters:
status:
id: status
table: node_field_data
field: status
entity_type: node
entity_field: status
plugin_id: boolean
value: '1'
group: 1
expose:
operator: ''
style:
type: default
options:
row_class: ''
default_row_class: true
uses_fields: false
row:
type: 'entity:node'
options:
view_mode: teaser
query:
type: views_query
options:
query_comment: ''
disable_sql_rewrite: false
distinct: false
replica: false
query_tags: { }
relationships: { }
header:
area:
id: area
table: views
field: area
relationship: none
group_type: group
admin_label: ''
plugin_id: text
empty: true
content:
value: 'test header content'
format: plain_text
tokenize: false
roles_fieldset:
roles:
anonymous: 0
authenticated: 0
content_editor: 0
administrator: 0
negate: 0
footer: { }
display_extenders: { }
cache_metadata:
max-age: -1
contexts:
- 'languages:language_content'
- 'languages:language_interface'
- url.query_args
- 'user.node_grants:view'
tags: { }
page_1:
id: page_1
display_title: Page
display_plugin: page
position: 1
display_options:
display_extenders: { }
path: views-role-based-global-text-test
cache_metadata:
max-age: -1
contexts:
- 'languages:language_content'
- 'languages:language_interface'
- url.query_args
- 'user.node_grants:view'
tags: { }
name: 'Views Role Based Global Text Test'
description: 'Support module for testing Views Role Based Global Text.'
core: 8.x
core_version_requirement: ^8 || ^9 || ^10
type: module
dependencies:
- views_role_based_global_text:views_role_based_global_text
- drupal:views
- drupal:user
- drupal:node
<?php
namespace Drupal\Tests\views_role_based_global_text\Functional;
use Drupal\views\Views;
/**
* Configuration tests class for Views Field Permissions browser tests.
*/
class ViewsRoleBasedGlobalTextConfigurationTest extends ViewsRoleBasedGlobalTextTestBase {
/**
* Tests the "Views Field Permissions" in field handler edit form.
*/
public function testConfigurationSubmitting() {
$this->drupalGet('/admin/structure/views/nojs/handler/views_role_based_global_text_test/page_1/header/area');
$this->submitForm(
[
'options[roles_fieldset][roles][authenticated]' => TRUE,
'options[roles_fieldset][roles][anonymous]' => FALSE,
'options[roles_fieldset][negate]' => TRUE,
],
'Apply'
);
$this->drupalGet('admin/structure/views/view/views_role_based_global_text_test');
$this->submitForm([], 'Save');
// Load view and init handlers.
$view = Views::getView('views_role_based_global_text_test');
$view->setDisplay();
$view->initHandlers();
// Check if header area options are saved.
$handler = $view->display_handler->getHandler('header', 'area');
$this->assertTrue(in_array('authenticated', $handler->options['roles_fieldset']['roles']), 'Control option saved successfully.');
$this->assertFalse(in_array('anonymous', $handler->options['roles_fieldset']['roles']), 'Control option saved successfully.');
$this->assertEquals(1, $handler->options['roles_fieldset']['negate'], 'Negate option saved successfully.');
}
}
<?php
namespace Drupal\Tests\views_role_based_global_text\Functional;
use Drupal\Tests\BrowserTestBase;
/**
* Base class for Views Role Based Global Text browser tests.
*/
abstract class ViewsRoleBasedGlobalTextTestBase extends BrowserTestBase {
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
protected static $modules = [
'views_ui',
'views_role_based_global_text_test',
];
/**
* {@inheritdoc}
*/
protected $strictConfigSchema = FALSE;
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
// Create admin user.
$admin_user = $this->drupalCreateUser(['administer site configuration', 'administer views']);
$this->drupalLogin($admin_user);
}
}
<?php
namespace Drupal\Tests\views_role_based_global_text\Functional;
use Drupal\views\Views;
/**
* View access tests class for Views Field Permissions browser tests.
*/
class ViewsRoleBasedGlobalTextViewAccessTest extends ViewsRoleBasedGlobalTextTestBase {
/**
* Tests access with no roles selected.
*/
public function testNoRolesSelected() {
$view = Views::getView('views_role_based_global_text_test');
$view->setDisplay();
$view->initHandlers();
$view->setHandlerOption('page_1', 'header', 'area', 'roles_fieldset', [
'roles' => [],
'negate' => 0,
]);
$view->save();
// Test as authenticated or anonymous user, both should have access.
$this->assertTrue(\Drupal::currentUser()->isAuthenticated(), 'Current user is authenticated.');
$this->drupalGet('/views-role-based-global-text-test');
$this->assertSession()->pageTextContains('test header content');
$this->drupalLogout();
$this->drupalGet('/views-role-based-global-text-test');
$this->assertFalse(\Drupal::currentUser()->isAuthenticated(), 'Current user is not authenticated.');
$this->assertSession()->pageTextContains('test header content');
}
/**
* Tests roles access based on configuration.
*/
public function testRolesSelected() {
$view = Views::getView('views_role_based_global_text_test');
$view->setDisplay();
$view->initHandlers();
$view->setHandlerOption('page_1', 'header', 'area', 'roles_fieldset', [
'roles' => [
'authenticated' => 'authenticated',
'anonymous' => 0,
],
'negate' => 0,
]);
$view->save();
// Test as authenticated user.
$this->assertTrue(\Drupal::currentUser()->isAuthenticated(), 'Current user is authenticated.');
$this->drupalGet('/views-role-based-global-text-test');
$this->assertSession()->pageTextContains('test header content');
// Test as anonymous user with no authenticated user role.
$this->drupalLogout();
$this->drupalGet('/views-role-based-global-text-test');
$this->assertFalse(\Drupal::currentUser()->isAuthenticated(), 'Current user is not authenticated.');
$this->assertSession()->pageTextNotContains('test header content');
}
/**
* Tests the negate configuration option.
*/
public function testViewAccessNegateOptionSelected() {
$view = Views::getView('views_role_based_global_text_test');
$view->setDisplay();
$view->initHandlers();
$view->setHandlerOption('page_1', 'header', 'area', 'roles_fieldset', [
'roles' => [
'authenticated' => 'authenticated',
],
'negate' => 1,
]);
$view->save();
// Test as authenticated user.
$this->assertTrue(\Drupal::currentUser()->isAuthenticated(), 'Current user is authenticated.');
$this->drupalGet('/views-role-based-global-text-test');
$this->assertSession()->pageTextNotContains('test header content');
// Test as anonymous user with no authenticated user role.
$this->drupalLogout();
$this->drupalGet('/views-role-based-global-text-test');
$this->assertFalse(\Drupal::currentUser()->isAuthenticated(), 'Current user is not authenticated.');
$this->assertSession()->pageTextContains('test header content');
}
}
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