Skip to content
Snippets Groups Projects
Commit 6c2bfb98 authored by Nikolay Lobachev's avatar Nikolay Lobachev
Browse files

Issue #3311730 by LOBsTerr: Provide tests

parent b5749c2f
No related branches found
No related tags found
1 merge request!2Issue #3311730: Provide tests
......@@ -31,6 +31,10 @@ function group_join_link_group_content_delete(GroupContentInterface $group_conte
function _group_join_link_invalidate_views_cache_tags(GroupContentInterface $group_content) {
if ($group_content->getContentPlugin()->getPluginId() == 'group_membership') {
$group_id = $group_content->getGroup()->id();
Cache::invalidateTags(['group_list', 'group_content_list', "group:{$group_id}", "group_content:{$group_content->id()}"]);
Cache::invalidateTags([
'group_list',
'group_content_list', "group:{$group_id}",
"group_content:{$group_content->id()}",
]);
}
}
......@@ -100,7 +100,10 @@ final class JoinLeaveLink extends FieldPluginBase {
return $build;
}
$link_params = ['group' => $group->id(), 'destination' => $this->currentPath->getPath()];
$link_params = [
'group' => $group->id(),
'destination' => $this->currentPath->getPath(),
];
if (empty($group->getMember($this->currentUser))) {
if ($group->hasPermission('join group', $this->currentUser)) {
$build = Link::createFromRoute('Join group', 'entity.group.join', $link_params)->toString();
......
langcode: en
status: true
dependencies:
module:
- group
- group_join_link
id: groups_list
label: 'Groups list'
module: views
description: ''
tag: ''
base_table: groups_field_data
base_field: id
display:
default:
id: default
display_title: Default
display_plugin: default
position: 0
display_options:
title: 'Groups list'
fields:
label:
id: label
table: groups_field_data
field: label
relationship: none
group_type: group
admin_label: ''
entity_type: null
entity_field: label
plugin_id: field
label: Title
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
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
group_join_leave_link:
id: group_join_leave_link
table: groups
field: group_join_leave_link
relationship: none
group_type: group
admin_label: ''
entity_type: group
plugin_id: group_join_leave_link
label: 'Join / Leave link'
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
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: { }
arguments: { }
filters:
status:
id: status
table: groups_field_data
field: status
entity_type: group
entity_field: status
plugin_id: boolean
value: '1'
group: 1
expose:
operator: ''
operator_limit_selection: false
operator_list: { }
style:
type: table
row:
type: fields
query:
type: views_query
options:
query_comment: ''
disable_sql_rewrite: false
distinct: false
replica: false
query_tags: { }
relationships: { }
header: { }
footer: { }
display_extenders: { }
cache_metadata:
max-age: -1
contexts:
- 'languages:language_content'
- 'languages:language_interface'
- url.query_args
tags: { }
page_1:
id: page_1
display_title: Page
display_plugin: page
position: 1
display_options:
display_extenders: { }
path: groups-list
cache_metadata:
max-age: -1
contexts:
- 'languages:language_content'
- 'languages:language_interface'
- url.query_args
tags: { }
name: 'Test group join link'
type: 'module'
description: 'Test group join link.'
package: 'Testing'
core_version_requirement: ^8 || ^9 || ^10
dependencies:
- 'drupal:views'
<?php
namespace Drupal\Tests\group_join_link\Functional;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Tests\group\Functional\GroupBrowserTestBase;
/**
* Tests for views group leave / join links.
*
* @group group
*/
class GroupViewLeaveJoinLinkTest extends GroupBrowserTestBase {
use StringTranslationTrait;
/**
* {@inheritdoc}
*/
public static $modules = [
'group',
'group_test_config',
'group_join_link',
'views',
'test_group_join_link',
];
/**
* The group we will use to test methods on.
*
* @var \Drupal\group\Entity\Group
*/
protected $group;
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
$this->group = $this->createGroup(['type' => 'default']);
}
/**
* Test link for outsider without join permission.
*/
public function testLinkForOuitsiderWithoutJoinPermissions() {
$account = $this->createUser();
$this->drupalLogin($account);
$this->group->getGroupType()->getOutsiderRole()->revokePermission('join group')->save();
$this->drupalGet('/groups-list');
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->linkNotExists('Join');
}
/**
* Test link for outsider with join permission.
*/
public function testLinkForOuitsiderWithJoinPermissions() {
$account = $this->createUser();
$this->drupalLogin($account);
$this->group->getGroupType()->getOutsiderRole()->grantPermission('join group')->save();
$this->drupalGet('/groups-list');
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->linkExists('Join');
}
/**
* Test link for member without leave permission.
*/
public function testLinkForMemberWithoutLeavePermissions() {
$account = $this->createUser();
$this->drupalLogin($account);
$this->group->addMember($account);
$this->group->getGroupType()->getMemberRole()->revokePermission('leave group')->save();
$this->drupalGet('/groups-list');
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->linkNotExists('Leave');
}
/**
* Test link for member with leave permission.
*/
public function testLinkForMemberWithLeavePermissions() {
$account = $this->createUser();
$this->drupalLogin($account);
$this->group->getGroupType()->getMemberRole()->grantPermission('leave group')->save();
$this->group->addMember($account);
$this->drupalGet('/groups-list');
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->linkExists('Leave');
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment