Update Composer, update everything
This commit is contained in:
parent
ea3e94409f
commit
dda5c284b6
19527 changed files with 1135420 additions and 351004 deletions
22
web/core/modules/block_content/tests/fixtures/update/drupal-8.views_block_content-2976334.php
vendored
Normal file
22
web/core/modules/block_content/tests/fixtures/update/drupal-8.views_block_content-2976334.php
vendored
Normal file
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains database additions to drupal-8.bare.standard.php.gz for testing the
|
||||
* upgrade path of https://www.drupal.org/project/drupal/issues/2976334.
|
||||
*/
|
||||
|
||||
use Drupal\Core\Database\Database;
|
||||
use Drupal\Core\Serialization\Yaml;
|
||||
|
||||
$connection = Database::getConnection();
|
||||
|
||||
// Override configuration for 'block_content' View with extra display with with
|
||||
// overridden filters.
|
||||
$config = Yaml::decode(file_get_contents(__DIR__ . '/views.view.block_content_2976334.yml'));
|
||||
$connection->update('config')
|
||||
->fields([
|
||||
'data' => serialize($config),
|
||||
])
|
||||
->condition('name', 'views.view.' . $config['id'])
|
||||
->execute();
|
602
web/core/modules/block_content/tests/fixtures/update/views.view.block_content_2976334.yml
vendored
Normal file
602
web/core/modules/block_content/tests/fixtures/update/views.view.block_content_2976334.yml
vendored
Normal file
|
@ -0,0 +1,602 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
module:
|
||||
- block_content
|
||||
- user
|
||||
id: block_content
|
||||
label: 'Custom block library'
|
||||
module: views
|
||||
description: 'Find and manage custom blocks.'
|
||||
tag: default
|
||||
base_table: block_content_field_data
|
||||
base_field: id
|
||||
core: 8.x
|
||||
display:
|
||||
default:
|
||||
display_plugin: default
|
||||
id: default
|
||||
display_title: Master
|
||||
position: 0
|
||||
display_options:
|
||||
access:
|
||||
type: perm
|
||||
options:
|
||||
perm: 'administer blocks'
|
||||
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: mini
|
||||
options:
|
||||
items_per_page: 50
|
||||
offset: 0
|
||||
id: 0
|
||||
total_pages: null
|
||||
tags:
|
||||
previous: '‹ Previous'
|
||||
next: 'Next ›'
|
||||
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
|
||||
style:
|
||||
type: table
|
||||
options:
|
||||
grouping: { }
|
||||
row_class: ''
|
||||
default_row_class: true
|
||||
override: true
|
||||
sticky: false
|
||||
caption: ''
|
||||
summary: ''
|
||||
description: ''
|
||||
columns:
|
||||
info: info
|
||||
type: type
|
||||
changed: changed
|
||||
operations: operations
|
||||
info:
|
||||
info:
|
||||
sortable: true
|
||||
default_sort_order: asc
|
||||
align: ''
|
||||
separator: ''
|
||||
empty_column: false
|
||||
responsive: ''
|
||||
type:
|
||||
sortable: true
|
||||
default_sort_order: asc
|
||||
align: ''
|
||||
separator: ''
|
||||
empty_column: false
|
||||
responsive: ''
|
||||
changed:
|
||||
sortable: true
|
||||
default_sort_order: desc
|
||||
align: ''
|
||||
separator: ''
|
||||
empty_column: false
|
||||
responsive: ''
|
||||
operations:
|
||||
sortable: false
|
||||
default_sort_order: asc
|
||||
align: ''
|
||||
separator: ''
|
||||
empty_column: false
|
||||
responsive: ''
|
||||
default: changed
|
||||
empty_table: true
|
||||
row:
|
||||
type: fields
|
||||
fields:
|
||||
info:
|
||||
id: info
|
||||
table: block_content_field_data
|
||||
field: info
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
label: 'Block description'
|
||||
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:
|
||||
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
|
||||
entity_type: null
|
||||
entity_field: info
|
||||
plugin_id: field
|
||||
type:
|
||||
id: type
|
||||
table: block_content_field_data
|
||||
field: type
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
label: 'Block type'
|
||||
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: target_id
|
||||
type: entity_reference_label
|
||||
settings:
|
||||
link: false
|
||||
group_column: target_id
|
||||
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
|
||||
entity_type: block_content
|
||||
entity_field: type
|
||||
plugin_id: field
|
||||
changed:
|
||||
id: changed
|
||||
table: block_content_field_data
|
||||
field: changed
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
label: Updated
|
||||
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
|
||||
entity_type: block_content
|
||||
entity_field: changed
|
||||
type: timestamp
|
||||
settings:
|
||||
date_format: short
|
||||
custom_date_format: ''
|
||||
timezone: ''
|
||||
plugin_id: field
|
||||
operations:
|
||||
id: operations
|
||||
table: block_content
|
||||
field: operations
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
label: Operations
|
||||
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
|
||||
destination: true
|
||||
entity_type: block_content
|
||||
plugin_id: entity_operations
|
||||
filters:
|
||||
info:
|
||||
id: info
|
||||
table: block_content_field_data
|
||||
field: info
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
operator: contains
|
||||
value: ''
|
||||
group: 1
|
||||
exposed: true
|
||||
expose:
|
||||
operator_id: info_op
|
||||
label: 'Block description'
|
||||
description: ''
|
||||
use_operator: false
|
||||
operator: info_op
|
||||
identifier: info
|
||||
required: false
|
||||
remember: false
|
||||
multiple: false
|
||||
remember_roles:
|
||||
authenticated: authenticated
|
||||
anonymous: '0'
|
||||
administrator: '0'
|
||||
is_grouped: false
|
||||
group_info:
|
||||
label: ''
|
||||
description: ''
|
||||
identifier: ''
|
||||
optional: true
|
||||
widget: select
|
||||
multiple: false
|
||||
remember: false
|
||||
default_group: All
|
||||
default_group_multiple: { }
|
||||
group_items: { }
|
||||
entity_type: block_content
|
||||
entity_field: info
|
||||
plugin_id: string
|
||||
type:
|
||||
id: type
|
||||
table: block_content_field_data
|
||||
field: type
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
operator: in
|
||||
value: { }
|
||||
group: 1
|
||||
exposed: true
|
||||
expose:
|
||||
operator_id: type_op
|
||||
label: 'Block type'
|
||||
description: ''
|
||||
use_operator: false
|
||||
operator: type_op
|
||||
identifier: type
|
||||
required: false
|
||||
remember: false
|
||||
multiple: false
|
||||
remember_roles:
|
||||
authenticated: authenticated
|
||||
anonymous: '0'
|
||||
administrator: '0'
|
||||
reduce: false
|
||||
is_grouped: false
|
||||
group_info:
|
||||
label: ''
|
||||
description: ''
|
||||
identifier: ''
|
||||
optional: true
|
||||
widget: select
|
||||
multiple: false
|
||||
remember: false
|
||||
default_group: All
|
||||
default_group_multiple: { }
|
||||
group_items: { }
|
||||
entity_type: block_content
|
||||
entity_field: type
|
||||
plugin_id: bundle
|
||||
sorts: { }
|
||||
title: 'Custom block library'
|
||||
header: { }
|
||||
footer: { }
|
||||
empty:
|
||||
area_text_custom:
|
||||
id: area_text_custom
|
||||
table: views
|
||||
field: area_text_custom
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
empty: true
|
||||
tokenize: false
|
||||
content: 'There are no custom blocks available.'
|
||||
plugin_id: text_custom
|
||||
block_content_listing_empty:
|
||||
admin_label: ''
|
||||
empty: true
|
||||
field: block_content_listing_empty
|
||||
group_type: group
|
||||
id: block_content_listing_empty
|
||||
label: ''
|
||||
relationship: none
|
||||
table: block_content
|
||||
plugin_id: block_content_listing_empty
|
||||
entity_type: block_content
|
||||
relationships: { }
|
||||
arguments: { }
|
||||
display_extenders: { }
|
||||
cache_metadata:
|
||||
contexts:
|
||||
- 'languages:language_content'
|
||||
- 'languages:language_interface'
|
||||
- url
|
||||
- url.query_args
|
||||
- user.permissions
|
||||
max-age: 0
|
||||
tags: { }
|
||||
page_1:
|
||||
display_plugin: page
|
||||
id: page_1
|
||||
display_title: Page
|
||||
position: 1
|
||||
display_options:
|
||||
display_extenders: { }
|
||||
path: admin/structure/block/block-content
|
||||
menu:
|
||||
type: tab
|
||||
title: 'Custom block library'
|
||||
description: ''
|
||||
parent: block.admin_display
|
||||
weight: 0
|
||||
context: '0'
|
||||
menu_name: admin
|
||||
cache_metadata:
|
||||
contexts:
|
||||
- 'languages:language_content'
|
||||
- 'languages:language_interface'
|
||||
- url
|
||||
- url.query_args
|
||||
- user.permissions
|
||||
max-age: 0
|
||||
tags: { }
|
||||
page_2:
|
||||
display_plugin: page
|
||||
id: page_2
|
||||
display_title: 'Page 2'
|
||||
position: 2
|
||||
display_options:
|
||||
display_extenders: { }
|
||||
path: extra-view-display
|
||||
filters:
|
||||
type:
|
||||
id: type
|
||||
table: block_content_field_data
|
||||
field: type
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
operator: in
|
||||
value: { }
|
||||
group: 1
|
||||
exposed: true
|
||||
expose:
|
||||
operator_id: type_op
|
||||
label: 'Block type'
|
||||
description: ''
|
||||
use_operator: false
|
||||
operator: type_op
|
||||
identifier: type
|
||||
required: false
|
||||
remember: false
|
||||
multiple: false
|
||||
remember_roles:
|
||||
authenticated: authenticated
|
||||
anonymous: '0'
|
||||
administrator: '0'
|
||||
reduce: false
|
||||
is_grouped: false
|
||||
group_info:
|
||||
label: ''
|
||||
description: ''
|
||||
identifier: ''
|
||||
optional: true
|
||||
widget: select
|
||||
multiple: false
|
||||
remember: false
|
||||
default_group: All
|
||||
default_group_multiple: { }
|
||||
group_items: { }
|
||||
entity_type: block_content
|
||||
entity_field: type
|
||||
plugin_id: bundle
|
||||
info:
|
||||
id: info
|
||||
table: block_content_field_data
|
||||
field: info
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
operator: 'contains'
|
||||
value: block2
|
||||
group: 1
|
||||
exposed: false
|
||||
expose:
|
||||
operator_id: ''
|
||||
label: ''
|
||||
description: ''
|
||||
use_operator: false
|
||||
operator: ''
|
||||
identifier: ''
|
||||
required: false
|
||||
remember: false
|
||||
multiple: false
|
||||
remember_roles:
|
||||
authenticated: authenticated
|
||||
placeholder: ''
|
||||
is_grouped: false
|
||||
group_info:
|
||||
label: ''
|
||||
description: ''
|
||||
identifier: ''
|
||||
optional: true
|
||||
widget: select
|
||||
multiple: false
|
||||
remember: false
|
||||
default_group: All
|
||||
default_group_multiple: { }
|
||||
group_items: { }
|
||||
entity_type: block_content
|
||||
entity_field: info
|
||||
plugin_id: string
|
||||
defaults:
|
||||
filters: false
|
||||
filter_groups: false
|
||||
filter_groups:
|
||||
operator: AND
|
||||
groups:
|
||||
1: AND
|
||||
cache_metadata:
|
||||
max-age: 0
|
||||
contexts:
|
||||
- 'languages:language_content'
|
||||
- 'languages:language_interface'
|
||||
- url
|
||||
- url.query_args
|
||||
- user.permissions
|
||||
tags: { }
|
|
@ -5,4 +5,4 @@ package: Testing
|
|||
version: VERSION
|
||||
core: 8.x
|
||||
dependencies:
|
||||
- block_content
|
||||
- drupal:block_content
|
||||
|
|
|
@ -0,0 +1,80 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\block_content_test\Plugin\EntityReferenceSelection;
|
||||
|
||||
use Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection;
|
||||
|
||||
/**
|
||||
* Test EntityReferenceSelection with conditions on the 'reusable' field.
|
||||
*/
|
||||
class TestSelection extends DefaultSelection {
|
||||
|
||||
/**
|
||||
* The condition type.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $conditionType;
|
||||
|
||||
/**
|
||||
* Whether to set the condition for reusable or non-reusable blocks.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $isReusable;
|
||||
|
||||
/**
|
||||
* Sets the test mode.
|
||||
*
|
||||
* @param string $condition_type
|
||||
* The condition type.
|
||||
* @param bool $is_reusable
|
||||
* Whether to set the condition for reusable or non-reusable blocks.
|
||||
*/
|
||||
public function setTestMode($condition_type = NULL, $is_reusable = NULL) {
|
||||
$this->conditionType = $condition_type;
|
||||
$this->isReusable = $is_reusable;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function buildEntityQuery($match = NULL, $match_operator = 'CONTAINS') {
|
||||
$query = parent::buildEntityQuery($match, $match_operator);
|
||||
if ($this->conditionType) {
|
||||
/** @var \Drupal\Core\Database\Query\ConditionInterface $add_condition */
|
||||
$add_condition = NULL;
|
||||
switch ($this->conditionType) {
|
||||
case 'base':
|
||||
$add_condition = $query;
|
||||
break;
|
||||
|
||||
case 'group':
|
||||
$group = $query->andConditionGroup()
|
||||
->exists('type');
|
||||
$add_condition = $group;
|
||||
$query->condition($group);
|
||||
break;
|
||||
|
||||
case "nested_group":
|
||||
$query->exists('type');
|
||||
$sub_group = $query->andConditionGroup()
|
||||
->exists('type');
|
||||
$add_condition = $sub_group;
|
||||
$group = $query->andConditionGroup()
|
||||
->exists('type')
|
||||
->condition($sub_group);
|
||||
$query->condition($group);
|
||||
break;
|
||||
}
|
||||
if ($this->isReusable) {
|
||||
$add_condition->condition('reusable', 1);
|
||||
}
|
||||
else {
|
||||
$add_condition->condition('reusable', 0);
|
||||
}
|
||||
}
|
||||
return $query;
|
||||
}
|
||||
|
||||
}
|
|
@ -5,5 +5,5 @@ package: Testing
|
|||
version: VERSION
|
||||
core: 8.x
|
||||
dependencies:
|
||||
- block_content
|
||||
- views
|
||||
- drupal:block_content
|
||||
- drupal:views
|
||||
|
|
|
@ -7,7 +7,7 @@ use Drupal\block_content\Entity\BlockContentType;
|
|||
use Drupal\Core\Cache\Cache;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\system\Tests\Entity\EntityCacheTagsTestBase;
|
||||
use Drupal\Tests\system\Functional\Entity\EntityCacheTagsTestBase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
|
@ -29,7 +29,7 @@ class BlockContentCacheTagsTest extends EntityCacheTagsTestBase {
|
|||
$block_content_type = BlockContentType::create([
|
||||
'id' => 'basic',
|
||||
'label' => 'basic',
|
||||
'revision' => FALSE
|
||||
'revision' => FALSE,
|
||||
]);
|
||||
$block_content_type->save();
|
||||
block_content_add_body_field($block_content_type->id());
|
||||
|
@ -76,7 +76,7 @@ class BlockContentCacheTagsTest extends EntityCacheTagsTestBase {
|
|||
// Render the block.
|
||||
// @todo The request stack manipulation won't be necessary once
|
||||
// https://www.drupal.org/node/2367555 is fixed and the
|
||||
// corresponding $request->isMethodSafe() checks are removed from
|
||||
// corresponding $request->isMethodCacheable() checks are removed from
|
||||
// Drupal\Core\Render\Renderer.
|
||||
$request_stack = $this->container->get('request_stack');
|
||||
$request_stack->push(new Request());
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Functional;
|
||||
|
||||
/**
|
||||
* Tests views contextual links on block content.
|
||||
*
|
||||
* @group block_content
|
||||
*/
|
||||
class BlockContentContextualLinksTest extends BlockContentTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = [
|
||||
'contextual',
|
||||
];
|
||||
|
||||
/**
|
||||
* Tests contextual links.
|
||||
*/
|
||||
public function testBlockContentContextualLinks() {
|
||||
$block_content = $this->createBlockContent();
|
||||
|
||||
$block = $this->placeBlock('block_content:' . $block_content->uuid());
|
||||
|
||||
$user = $this->drupalCreateUser([
|
||||
'administer blocks',
|
||||
'access contextual links',
|
||||
]);
|
||||
$this->drupalLogin($user);
|
||||
|
||||
$this->drupalGet('<front>');
|
||||
$this->assertSession()->elementAttributeContains('css', 'div[data-contextual-id]', 'data-contextual-id', 'block:block=' . $block->id() . ':langcode=en|block_content:block_content=' . $block_content->id() . ':');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,308 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Functional;
|
||||
|
||||
use Drupal\block_content\Entity\BlockContent;
|
||||
use Drupal\Core\Database\Database;
|
||||
|
||||
/**
|
||||
* Create a block and test saving it.
|
||||
*
|
||||
* @group block_content
|
||||
*/
|
||||
class BlockContentCreationTest extends BlockContentTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* Enable dummy module that implements hook_block_insert() for exceptions and
|
||||
* field_ui to edit display settings.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['block_content_test', 'dblog', 'field_ui'];
|
||||
|
||||
/**
|
||||
* Permissions to grant admin user.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $permissions = [
|
||||
'administer blocks',
|
||||
'administer block_content display',
|
||||
];
|
||||
|
||||
/**
|
||||
* Sets the test up.
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->drupalLogin($this->adminUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a "Basic page" block and verifies its consistency in the database.
|
||||
*/
|
||||
public function testBlockContentCreation() {
|
||||
$this->drupalLogin($this->adminUser);
|
||||
|
||||
// Create a block.
|
||||
$edit = [];
|
||||
$edit['info[0][value]'] = 'Test Block';
|
||||
$edit['body[0][value]'] = $this->randomMachineName(16);
|
||||
$this->drupalPostForm('block/add/basic', $edit, t('Save'));
|
||||
|
||||
// Check that the Basic block has been created.
|
||||
$this->assertRaw(format_string('@block %name has been created.', [
|
||||
'@block' => 'basic',
|
||||
'%name' => $edit['info[0][value]'],
|
||||
]), 'Basic block created.');
|
||||
|
||||
// Check that the view mode setting is hidden because only one exists.
|
||||
$this->assertNoFieldByXPath('//select[@name="settings[view_mode]"]', NULL, 'View mode setting hidden because only one exists');
|
||||
|
||||
// Check that the block exists in the database.
|
||||
$blocks = \Drupal::entityTypeManager()
|
||||
->getStorage('block_content')
|
||||
->loadByProperties(['info' => $edit['info[0][value]']]);
|
||||
$block = reset($blocks);
|
||||
$this->assertTrue($block, 'Custom Block found in database.');
|
||||
|
||||
// Check that attempting to create another block with the same value for
|
||||
// 'info' returns an error.
|
||||
$this->drupalPostForm('block/add/basic', $edit, t('Save'));
|
||||
|
||||
// Check that the Basic block has been created.
|
||||
$this->assertRaw(format_string('A custom block with block description %value already exists.', [
|
||||
'%value' => $edit['info[0][value]'],
|
||||
]));
|
||||
$this->assertResponse(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a "Basic page" block with multiple view modes.
|
||||
*/
|
||||
public function testBlockContentCreationMultipleViewModes() {
|
||||
// Add a new view mode and verify if it is selected as expected.
|
||||
$this->drupalLogin($this->drupalCreateUser(['administer display modes']));
|
||||
$this->drupalGet('admin/structure/display-modes/view/add/block_content');
|
||||
$edit = [
|
||||
'id' => 'test_view_mode',
|
||||
'label' => 'Test View Mode',
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
$this->assertRaw(t('Saved the %label view mode.', ['%label' => $edit['label']]));
|
||||
|
||||
$this->drupalLogin($this->adminUser);
|
||||
|
||||
// Create a block.
|
||||
$edit = [];
|
||||
$edit['info[0][value]'] = 'Test Block';
|
||||
$edit['body[0][value]'] = $this->randomMachineName(16);
|
||||
$this->drupalPostForm('block/add/basic', $edit, t('Save'));
|
||||
|
||||
// Check that the Basic block has been created.
|
||||
$this->assertRaw(format_string('@block %name has been created.', [
|
||||
'@block' => 'basic',
|
||||
'%name' => $edit['info[0][value]'],
|
||||
]), 'Basic block created.');
|
||||
|
||||
// Save our block permanently
|
||||
$this->drupalPostForm(NULL, ['region' => 'content'], t('Save block'));
|
||||
|
||||
// Set test_view_mode as a custom display to be available on the list.
|
||||
$this->drupalGet('admin/structure/block/block-content');
|
||||
$this->drupalGet('admin/structure/block/block-content/types');
|
||||
$this->clickLink(t('Manage display'));
|
||||
$this->drupalGet('admin/structure/block/block-content/manage/basic/display');
|
||||
$custom_view_mode = [
|
||||
'display_modes_custom[test_view_mode]' => 1,
|
||||
];
|
||||
$this->drupalPostForm(NULL, $custom_view_mode, t('Save'));
|
||||
|
||||
// Go to the configure page and change the view mode.
|
||||
$this->drupalGet('admin/structure/block/manage/testblock');
|
||||
|
||||
// Test the available view mode options.
|
||||
$this->assertOption('edit-settings-view-mode', 'default', 'The default view mode is available.');
|
||||
$this->assertOption('edit-settings-view-mode', 'test_view_mode', 'The test view mode is available.');
|
||||
|
||||
$view_mode['settings[view_mode]'] = 'test_view_mode';
|
||||
$this->drupalPostForm(NULL, $view_mode, t('Save block'));
|
||||
|
||||
// Check that the view mode setting is shown because more than one exists.
|
||||
$this->drupalGet('admin/structure/block/manage/testblock');
|
||||
$this->assertFieldByXPath('//select[@name="settings[view_mode]"]', NULL, 'View mode setting shown because multiple exist');
|
||||
|
||||
// Change the view mode.
|
||||
$view_mode['region'] = 'content';
|
||||
$view_mode['settings[view_mode]'] = 'test_view_mode';
|
||||
$this->drupalPostForm(NULL, $view_mode, t('Save block'));
|
||||
|
||||
// Go to the configure page and verify the view mode has changed.
|
||||
$this->drupalGet('admin/structure/block/manage/testblock');
|
||||
$this->assertFieldByXPath('//select[@name="settings[view_mode]"]/option[@selected="selected"]', 'test_view_mode', 'View mode changed to Test View Mode');
|
||||
|
||||
// Check that the block exists in the database.
|
||||
$blocks = \Drupal::entityTypeManager()
|
||||
->getStorage('block_content')
|
||||
->loadByProperties(['info' => $edit['info[0][value]']]);
|
||||
$block = reset($blocks);
|
||||
$this->assertTrue($block, 'Custom Block found in database.');
|
||||
|
||||
// Check that attempting to create another block with the same value for
|
||||
// 'info' returns an error.
|
||||
$this->drupalPostForm('block/add/basic', $edit, t('Save'));
|
||||
|
||||
// Check that the Basic block has been created.
|
||||
$this->assertRaw(format_string('A custom block with block description %value already exists.', [
|
||||
'%value' => $edit['info[0][value]'],
|
||||
]));
|
||||
$this->assertResponse(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a default custom block.
|
||||
*
|
||||
* Creates a custom block from defaults and ensures that the 'basic block'
|
||||
* type is being used.
|
||||
*/
|
||||
public function testDefaultBlockContentCreation() {
|
||||
$edit = [];
|
||||
$edit['info[0][value]'] = $this->randomMachineName(8);
|
||||
$edit['body[0][value]'] = $this->randomMachineName(16);
|
||||
// Don't pass the custom block type in the url so the default is forced.
|
||||
$this->drupalPostForm('block/add', $edit, t('Save'));
|
||||
|
||||
// Check that the block has been created and that it is a basic block.
|
||||
$this->assertRaw(format_string('@block %name has been created.', [
|
||||
'@block' => 'basic',
|
||||
'%name' => $edit['info[0][value]'],
|
||||
]), 'Basic block created.');
|
||||
|
||||
// Check that the block exists in the database.
|
||||
$blocks = \Drupal::entityTypeManager()
|
||||
->getStorage('block_content')
|
||||
->loadByProperties(['info' => $edit['info[0][value]']]);
|
||||
$block = reset($blocks);
|
||||
$this->assertTrue($block, 'Default Custom Block found in database.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that a transaction rolls back the failed creation.
|
||||
*/
|
||||
public function testFailedBlockCreation() {
|
||||
// Create a block.
|
||||
try {
|
||||
$this->createBlockContent('fail_creation');
|
||||
$this->fail('Expected exception has not been thrown.');
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
$this->pass('Expected exception has been thrown.');
|
||||
}
|
||||
|
||||
if (Database::getConnection()->supportsTransactions()) {
|
||||
// Check that the block does not exist in the database.
|
||||
$id = db_select('block_content_field_data', 'b')
|
||||
->fields('b', ['id'])
|
||||
->condition('info', 'fail_creation')
|
||||
->execute()
|
||||
->fetchField();
|
||||
$this->assertFalse($id, 'Transactions supported, and block not found in database.');
|
||||
}
|
||||
else {
|
||||
// Check that the block exists in the database.
|
||||
$id = db_select('block_content_field_data', 'b')
|
||||
->fields('b', ['id'])
|
||||
->condition('info', 'fail_creation')
|
||||
->execute()
|
||||
->fetchField();
|
||||
$this->assertTrue($id, 'Transactions not supported, and block found in database.');
|
||||
|
||||
// Check that the failed rollback was logged.
|
||||
$records = db_query("SELECT wid FROM {watchdog} WHERE message LIKE 'Explicit rollback failed%'")->fetchAll();
|
||||
$this->assertTrue(count($records) > 0, 'Transactions not supported, and rollback error logged to watchdog.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test deleting a block.
|
||||
*/
|
||||
public function testBlockDelete() {
|
||||
// Create a block.
|
||||
$edit = [];
|
||||
$edit['info[0][value]'] = $this->randomMachineName(8);
|
||||
$body = $this->randomMachineName(16);
|
||||
$edit['body[0][value]'] = $body;
|
||||
$this->drupalPostForm('block/add/basic', $edit, t('Save'));
|
||||
|
||||
// Place the block.
|
||||
$instance = [
|
||||
'id' => mb_strtolower($edit['info[0][value]']),
|
||||
'settings[label]' => $edit['info[0][value]'],
|
||||
'region' => 'sidebar_first',
|
||||
];
|
||||
$block = BlockContent::load(1);
|
||||
$url = 'admin/structure/block/add/block_content:' . $block->uuid() . '/' . $this->config('system.theme')->get('default');
|
||||
$this->drupalPostForm($url, $instance, t('Save block'));
|
||||
|
||||
$block = BlockContent::load(1);
|
||||
|
||||
// Test getInstances method.
|
||||
$this->assertEqual(1, count($block->getInstances()));
|
||||
|
||||
// Navigate to home page.
|
||||
$this->drupalGet('');
|
||||
$this->assertText($body);
|
||||
|
||||
// Delete the block.
|
||||
$this->drupalGet('block/1/delete');
|
||||
$this->assertText(\Drupal::translation()->formatPlural(1, 'This will also remove 1 placed block instance.', 'This will also remove @count placed block instance.'));
|
||||
|
||||
$this->drupalPostForm(NULL, [], 'Delete');
|
||||
$this->assertRaw(t('The custom block %name has been deleted.', ['%name' => $edit['info[0][value]']]));
|
||||
|
||||
// Create another block and force the plugin cache to flush.
|
||||
$edit2 = [];
|
||||
$edit2['info[0][value]'] = $this->randomMachineName(8);
|
||||
$body2 = $this->randomMachineName(16);
|
||||
$edit2['body[0][value]'] = $body2;
|
||||
$this->drupalPostForm('block/add/basic', $edit2, t('Save'));
|
||||
|
||||
$this->assertNoRaw('Error message');
|
||||
|
||||
// Create another block with no instances, and test we don't get a
|
||||
// confirmation message about deleting instances.
|
||||
$edit3 = [];
|
||||
$edit3['info[0][value]'] = $this->randomMachineName(8);
|
||||
$body = $this->randomMachineName(16);
|
||||
$edit3['body[0][value]'] = $body;
|
||||
$this->drupalPostForm('block/add/basic', $edit3, t('Save'));
|
||||
|
||||
// Show the delete confirm form.
|
||||
$this->drupalGet('block/3/delete');
|
||||
$this->assertNoText('This will also remove');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that placed content blocks create a dependency in the block placement.
|
||||
*/
|
||||
public function testConfigDependencies() {
|
||||
$block = $this->createBlockContent();
|
||||
// Place the block.
|
||||
$block_placement_id = mb_strtolower($block->label());
|
||||
$instance = [
|
||||
'id' => $block_placement_id,
|
||||
'settings[label]' => $block->label(),
|
||||
'region' => 'sidebar_first',
|
||||
];
|
||||
$block = BlockContent::load(1);
|
||||
$url = 'admin/structure/block/add/block_content:' . $block->uuid() . '/' . $this->config('system.theme')->get('default');
|
||||
$this->drupalPostForm($url, $instance, t('Save block'));
|
||||
|
||||
$dependencies = \Drupal::service('config.manager')->findConfigEntityDependentsAsEntities('content', [$block->getConfigDependencyName()]);
|
||||
$block_placement = reset($dependencies);
|
||||
$this->assertEqual($block_placement_id, $block_placement->id(), "The block placement config entity has a dependency on the block content entity.");
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,124 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Functional;
|
||||
|
||||
use Drupal\block_content\Entity\BlockContent;
|
||||
|
||||
/**
|
||||
* Tests the listing of custom blocks.
|
||||
*
|
||||
* Tests the fallback block content list when Views is disabled.
|
||||
*
|
||||
* @group block_content
|
||||
* @see \Drupal\block\BlockContentListBuilder
|
||||
* @see \Drupal\block_content\Tests\BlockContentListViewsTest
|
||||
*/
|
||||
class BlockContentListTest extends BlockContentTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['block', 'block_content', 'config_translation'];
|
||||
|
||||
/**
|
||||
* Tests the custom block listing page.
|
||||
*/
|
||||
public function testListing() {
|
||||
$this->drupalLogin($this->drupalCreateUser(['administer blocks', 'translate configuration']));
|
||||
$this->drupalGet('admin/structure/block/block-content');
|
||||
|
||||
// Test for the page title.
|
||||
$this->assertTitle(t('Custom block library') . ' | Drupal');
|
||||
|
||||
// Test for the table.
|
||||
$element = $this->xpath('//div[@class="layout-content"]//table');
|
||||
$this->assertTrue($element, 'Configuration entity list table found.');
|
||||
|
||||
// Test the table header.
|
||||
$elements = $this->xpath('//div[@class="layout-content"]//table/thead/tr/th');
|
||||
$this->assertEqual(count($elements), 2, 'Correct number of table header cells found.');
|
||||
|
||||
// Test the contents of each th cell.
|
||||
$expected_items = [t('Block description'), t('Operations')];
|
||||
foreach ($elements as $key => $element) {
|
||||
$this->assertEqual($element->getText(), $expected_items[$key]);
|
||||
}
|
||||
|
||||
$label = 'Antelope';
|
||||
$new_label = 'Albatross';
|
||||
// Add a new entity using the operations link.
|
||||
$link_text = t('Add custom block');
|
||||
$this->assertLink($link_text);
|
||||
$this->clickLink($link_text);
|
||||
$this->assertResponse(200);
|
||||
$edit = [];
|
||||
$edit['info[0][value]'] = $label;
|
||||
$edit['body[0][value]'] = $this->randomMachineName(16);
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
|
||||
// Confirm that once the user returns to the listing, the text of the label
|
||||
// (versus elsewhere on the page).
|
||||
$this->assertFieldByXpath('//td', $label, 'Label found for added block.');
|
||||
|
||||
// Check the number of table row cells.
|
||||
$elements = $this->xpath('//div[@class="layout-content"]//table/tbody/tr[@class="odd"]/td');
|
||||
$this->assertEqual(count($elements), 2, 'Correct number of table row cells found.');
|
||||
// Check the contents of each row cell. The first cell contains the label,
|
||||
// the second contains the machine name, and the third contains the
|
||||
// operations list.
|
||||
$this->assertIdentical($elements[0]->getText(), $label);
|
||||
|
||||
// Edit the entity using the operations link.
|
||||
$blocks = $this->container
|
||||
->get('entity.manager')
|
||||
->getStorage('block_content')
|
||||
->loadByProperties(['info' => $label]);
|
||||
$block = reset($blocks);
|
||||
if (!empty($block)) {
|
||||
$this->assertLinkByHref('block/' . $block->id());
|
||||
$this->clickLink(t('Edit'));
|
||||
$this->assertResponse(200);
|
||||
$this->assertTitle(strip_tags(t('Edit custom block %label', ['%label' => $label]) . ' | Drupal'));
|
||||
$edit = ['info[0][value]' => $new_label];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
}
|
||||
else {
|
||||
$this->fail('Did not find Albatross block in the database.');
|
||||
}
|
||||
|
||||
// Confirm that once the user returns to the listing, the text of the label
|
||||
// (versus elsewhere on the page).
|
||||
$this->assertFieldByXpath('//td', $new_label, 'Label found for updated custom block.');
|
||||
|
||||
// Delete the added entity using the operations link.
|
||||
$this->assertLinkByHref('block/' . $block->id() . '/delete');
|
||||
$delete_text = t('Delete');
|
||||
$this->clickLink($delete_text);
|
||||
$this->assertResponse(200);
|
||||
$this->assertTitle(strip_tags(t('Are you sure you want to delete the custom block %label?', ['%label' => $new_label]) . ' | Drupal'));
|
||||
$this->drupalPostForm(NULL, [], $delete_text);
|
||||
|
||||
// Verify that the text of the label and machine name does not appear in
|
||||
// the list (though it may appear elsewhere on the page).
|
||||
$this->assertNoFieldByXpath('//td', $new_label, 'No label found for deleted custom block.');
|
||||
|
||||
// Confirm that the empty text is displayed.
|
||||
$this->assertText(t('There are no custom blocks yet.'));
|
||||
|
||||
$block_content = BlockContent::create([
|
||||
'info' => 'Non-reusable block',
|
||||
'type' => 'basic',
|
||||
'reusable' => FALSE,
|
||||
]);
|
||||
$block_content->save();
|
||||
|
||||
$this->drupalGet('admin/structure/block/block-content');
|
||||
// Confirm that the empty text is displayed.
|
||||
$this->assertSession()->pageTextContains('There are no custom blocks yet.');
|
||||
// Confirm the non-reusable block is not on the page.
|
||||
$this->assertSession()->pageTextNotContains('Non-reusable block');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,132 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Functional;
|
||||
|
||||
use Drupal\block_content\Entity\BlockContent;
|
||||
|
||||
/**
|
||||
* Tests the Views-powered listing of custom blocks.
|
||||
*
|
||||
* @group block_content
|
||||
* @see \Drupal\block\BlockContentListBuilder
|
||||
* @see \Drupal\block_content\Tests\BlockContentListTest
|
||||
*/
|
||||
class BlockContentListViewsTest extends BlockContentTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['block', 'block_content', 'config_translation', 'views'];
|
||||
|
||||
/**
|
||||
* Tests the custom block listing page.
|
||||
*/
|
||||
public function testListing() {
|
||||
$this->drupalLogin($this->drupalCreateUser(['administer blocks', 'translate configuration']));
|
||||
$this->drupalGet('admin/structure/block/block-content');
|
||||
|
||||
// Test for the page title.
|
||||
$this->assertTitle(t('Custom block library') . ' | Drupal');
|
||||
|
||||
// Test for the exposed filters.
|
||||
$this->assertFieldByName('info');
|
||||
$this->assertFieldByName('type');
|
||||
|
||||
// Test for the table.
|
||||
$element = $this->xpath('//div[@class="layout-content"]//table');
|
||||
$this->assertTrue($element, 'Views table found.');
|
||||
|
||||
// Test the table header.
|
||||
$elements = $this->xpath('//div[@class="layout-content"]//table/thead/tr/th');
|
||||
$this->assertEqual(count($elements), 4, 'Correct number of table header cells found.');
|
||||
|
||||
// Test the contents of each th cell.
|
||||
$expected_items = ['Block description', 'Block type', 'Updated Sort ascending', 'Operations'];
|
||||
foreach ($elements as $key => $element) {
|
||||
if ($element->find('xpath', 'a')) {
|
||||
$this->assertIdentical(trim($element->find('xpath', 'a')->getText()), $expected_items[$key]);
|
||||
}
|
||||
else {
|
||||
$this->assertIdentical(trim($element->getText()), $expected_items[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
$label = 'Antelope';
|
||||
$new_label = 'Albatross';
|
||||
// Add a new entity using the operations link.
|
||||
$link_text = t('Add custom block');
|
||||
$this->assertLink($link_text);
|
||||
$this->clickLink($link_text);
|
||||
$this->assertResponse(200);
|
||||
$edit = [];
|
||||
$edit['info[0][value]'] = $label;
|
||||
$edit['body[0][value]'] = $this->randomMachineName(16);
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
|
||||
// Confirm that once the user returns to the listing, the text of the label
|
||||
// (versus elsewhere on the page).
|
||||
$this->assertFieldByXpath('//td/a', $label, 'Label found for added block.');
|
||||
|
||||
// Check the number of table row cells.
|
||||
$elements = $this->xpath('//div[@class="layout-content"]//table/tbody/tr/td');
|
||||
$this->assertEqual(count($elements), 4, 'Correct number of table row cells found.');
|
||||
// Check the contents of each row cell. The first cell contains the label,
|
||||
// the second contains the machine name, and the third contains the
|
||||
// operations list.
|
||||
$this->assertIdentical($elements[0]->find('xpath', 'a')->getText(), $label);
|
||||
|
||||
// Edit the entity using the operations link.
|
||||
$blocks = $this->container
|
||||
->get('entity.manager')
|
||||
->getStorage('block_content')
|
||||
->loadByProperties(['info' => $label]);
|
||||
$block = reset($blocks);
|
||||
if (!empty($block)) {
|
||||
$this->assertLinkByHref('block/' . $block->id());
|
||||
$this->clickLink(t('Edit'));
|
||||
$this->assertResponse(200);
|
||||
$this->assertTitle(strip_tags(t('Edit custom block %label', ['%label' => $label]) . ' | Drupal'));
|
||||
$edit = ['info[0][value]' => $new_label];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
}
|
||||
else {
|
||||
$this->fail('Did not find Albatross block in the database.');
|
||||
}
|
||||
|
||||
// Confirm that once the user returns to the listing, the text of the label
|
||||
// (versus elsewhere on the page).
|
||||
$this->assertFieldByXpath('//td/a', $new_label, 'Label found for updated custom block.');
|
||||
|
||||
// Delete the added entity using the operations link.
|
||||
$this->assertLinkByHref('block/' . $block->id() . '/delete');
|
||||
$delete_text = t('Delete');
|
||||
$this->clickLink($delete_text);
|
||||
$this->assertResponse(200);
|
||||
$this->assertTitle(strip_tags(t('Are you sure you want to delete the custom block %label?', ['%label' => $new_label]) . ' | Drupal'));
|
||||
$this->drupalPostForm(NULL, [], $delete_text);
|
||||
|
||||
// Verify that the text of the label and machine name does not appear in
|
||||
// the list (though it may appear elsewhere on the page).
|
||||
$this->assertNoFieldByXpath('//td', $new_label, 'No label found for deleted custom block.');
|
||||
|
||||
// Confirm that the empty text is displayed.
|
||||
$this->assertText('There are no custom blocks available.');
|
||||
$this->assertLink('custom block');
|
||||
|
||||
$block_content = BlockContent::create([
|
||||
'info' => 'Non-reusable block',
|
||||
'type' => 'basic',
|
||||
'reusable' => FALSE,
|
||||
]);
|
||||
$block_content->save();
|
||||
|
||||
$this->drupalGet('admin/structure/block/block-content');
|
||||
// Confirm that the empty text is displayed.
|
||||
$this->assertSession()->pageTextContains('There are no custom blocks available.');
|
||||
// Confirm the non-reusable block is not on the page.
|
||||
$this->assertSession()->pageTextNotContains('Non-reusable block');
|
||||
}
|
||||
|
||||
}
|
|
@ -31,7 +31,7 @@ class BlockContentRevisionsTest extends BlockContentTestBase {
|
|||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
/** @var UserInterface $user */
|
||||
/** @var \Drupal\user\Entity\UserInterface $user */
|
||||
$user = User::load(1);
|
||||
|
||||
// Create initial block.
|
||||
|
|
|
@ -39,7 +39,7 @@ class BlockContentSaveTest extends BlockContentTestBase {
|
|||
'info' => $info,
|
||||
'body' => ['value' => $this->randomMachineName(32)],
|
||||
'type' => 'basic',
|
||||
'id' => $test_id
|
||||
'id' => $test_id,
|
||||
];
|
||||
$block = BlockContent::create($block_array);
|
||||
$block->enforceIsNew(TRUE);
|
||||
|
|
|
@ -13,6 +13,8 @@ abstract class BlockContentTestBase extends BrowserTestBase {
|
|||
|
||||
/**
|
||||
* Profile to use.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $profile = 'testing';
|
||||
|
||||
|
@ -29,7 +31,7 @@ abstract class BlockContentTestBase extends BrowserTestBase {
|
|||
* @var array
|
||||
*/
|
||||
protected $permissions = [
|
||||
'administer blocks'
|
||||
'administer blocks',
|
||||
];
|
||||
|
||||
/**
|
||||
|
@ -78,7 +80,7 @@ abstract class BlockContentTestBase extends BrowserTestBase {
|
|||
$block_content = BlockContent::create([
|
||||
'info' => $title,
|
||||
'type' => $bundle,
|
||||
'langcode' => 'en'
|
||||
'langcode' => 'en',
|
||||
]);
|
||||
if ($block_content && $save === TRUE) {
|
||||
$block_content->save();
|
||||
|
|
|
@ -0,0 +1,204 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Functional;
|
||||
|
||||
use Drupal\block_content\Entity\BlockContent;
|
||||
use Drupal\block_content\Entity\BlockContentType;
|
||||
use Drupal\Tests\content_translation\Functional\ContentTranslationUITestBase;
|
||||
|
||||
/**
|
||||
* Tests the block content translation UI.
|
||||
*
|
||||
* @group block_content
|
||||
*/
|
||||
class BlockContentTranslationUITest extends ContentTranslationUITestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = [
|
||||
'language',
|
||||
'content_translation',
|
||||
'block',
|
||||
'field_ui',
|
||||
'block_content',
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $defaultCacheContexts = [
|
||||
'languages:language_interface',
|
||||
'session',
|
||||
'theme',
|
||||
'url.path',
|
||||
'url.query_args',
|
||||
'user.permissions',
|
||||
'user.roles:authenticated',
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
$this->entityTypeId = 'block_content';
|
||||
$this->bundle = 'basic';
|
||||
$this->testLanguageSelector = FALSE;
|
||||
parent::setUp();
|
||||
|
||||
$this->drupalPlaceBlock('page_title_block');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setupBundle() {
|
||||
// Create the basic bundle since it is provided by standard.
|
||||
$bundle = BlockContentType::create([
|
||||
'id' => $this->bundle,
|
||||
'label' => $this->bundle,
|
||||
'revision' => FALSE,
|
||||
]);
|
||||
$bundle->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getTranslatorPermissions() {
|
||||
return array_merge(parent::getTranslatorPermissions(), [
|
||||
'translate any entity',
|
||||
'access administration pages',
|
||||
'administer blocks',
|
||||
'administer block_content fields',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a custom block.
|
||||
*
|
||||
* @param bool|string $title
|
||||
* (optional) Title of block. When no value is given uses a random name.
|
||||
* Defaults to FALSE.
|
||||
* @param bool|string $bundle
|
||||
* (optional) Bundle name. When no value is given, defaults to
|
||||
* $this->bundle. Defaults to FALSE.
|
||||
*
|
||||
* @return \Drupal\block_content\Entity\BlockContent
|
||||
* Created custom block.
|
||||
*/
|
||||
protected function createBlockContent($title = FALSE, $bundle = FALSE) {
|
||||
$title = $title ?: $this->randomMachineName();
|
||||
$bundle = $bundle ?: $this->bundle;
|
||||
$block_content = BlockContent::create([
|
||||
'info' => $title,
|
||||
'type' => $bundle,
|
||||
'langcode' => 'en',
|
||||
]);
|
||||
$block_content->save();
|
||||
return $block_content;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getNewEntityValues($langcode) {
|
||||
return ['info' => mb_strtolower($this->randomMachineName())] + parent::getNewEntityValues($langcode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an edit array containing the values to be posted.
|
||||
*/
|
||||
protected function getEditValues($values, $langcode, $new = FALSE) {
|
||||
$edit = parent::getEditValues($values, $langcode, $new);
|
||||
foreach ($edit as $property => $value) {
|
||||
if ($property == 'info') {
|
||||
$edit['info[0][value]'] = $value;
|
||||
unset($edit[$property]);
|
||||
}
|
||||
}
|
||||
return $edit;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doTestBasicTranslation() {
|
||||
parent::doTestBasicTranslation();
|
||||
|
||||
// Ensure that a block translation can be created using the same description
|
||||
// as in the original language.
|
||||
$default_langcode = $this->langcodes[0];
|
||||
$values = $this->getNewEntityValues($default_langcode);
|
||||
$storage = \Drupal::entityManager()->getStorage($this->entityTypeId);
|
||||
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
|
||||
$entity = $storage->create(['type' => 'basic'] + $values);
|
||||
$entity->save();
|
||||
$entity->addTranslation('it', $values);
|
||||
|
||||
try {
|
||||
$message = 'Blocks can have translations with the same "info" value.';
|
||||
$entity->save();
|
||||
$this->pass($message);
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
$this->fail($message);
|
||||
}
|
||||
|
||||
// Check that the translate operation link is shown.
|
||||
$this->drupalGet('admin/structure/block/block-content');
|
||||
$this->assertLinkByHref('block/' . $entity->id() . '/translations');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that no metadata is stored for a disabled bundle.
|
||||
*/
|
||||
public function testDisabledBundle() {
|
||||
// Create a bundle that does not have translation enabled.
|
||||
$disabled_bundle = $this->randomMachineName();
|
||||
$bundle = BlockContentType::create([
|
||||
'id' => $disabled_bundle,
|
||||
'label' => $disabled_bundle,
|
||||
'revision' => FALSE,
|
||||
]);
|
||||
$bundle->save();
|
||||
|
||||
// Create a block content for each bundle.
|
||||
$enabled_block_content = $this->createBlockContent();
|
||||
$disabled_block_content = $this->createBlockContent(FALSE, $bundle->id());
|
||||
|
||||
// Make sure that only a single row was inserted into the block table.
|
||||
$rows = db_query('SELECT * FROM {block_content_field_data} WHERE id = :id', [':id' => $enabled_block_content->id()])->fetchAll();
|
||||
$this->assertEqual(1, count($rows));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doTestTranslationEdit() {
|
||||
$storage = $this->container->get('entity_type.manager')
|
||||
->getStorage($this->entityTypeId);
|
||||
$storage->resetCache([$this->entityId]);
|
||||
$entity = $storage->load($this->entityId);
|
||||
$languages = $this->container->get('language_manager')->getLanguages();
|
||||
|
||||
foreach ($this->langcodes as $langcode) {
|
||||
// We only want to test the title for non-english translations.
|
||||
if ($langcode != 'en') {
|
||||
$options = ['language' => $languages[$langcode]];
|
||||
$url = $entity->urlInfo('edit-form', $options);
|
||||
$this->drupalGet($url);
|
||||
|
||||
$title = t('<em>Edit @type</em> @title [%language translation]', [
|
||||
'@type' => $entity->bundle(),
|
||||
'@title' => $entity->getTranslation($langcode)->label(),
|
||||
'%language' => $languages[$langcode]->getName(),
|
||||
]);
|
||||
$this->assertRaw($title);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,250 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Functional;
|
||||
|
||||
use Drupal\block_content\Entity\BlockContentType;
|
||||
use Drupal\Component\Utility\Html;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\Tests\system\Functional\Menu\AssertBreadcrumbTrait;
|
||||
|
||||
/**
|
||||
* Ensures that custom block type functions work correctly.
|
||||
*
|
||||
* @group block_content
|
||||
*/
|
||||
class BlockContentTypeTest extends BlockContentTestBase {
|
||||
|
||||
use AssertBreadcrumbTrait;
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['field_ui'];
|
||||
|
||||
/**
|
||||
* Permissions to grant admin user.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $permissions = [
|
||||
'administer blocks',
|
||||
'administer block_content fields',
|
||||
];
|
||||
|
||||
/**
|
||||
* Whether or not to create an initial block type.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $autoCreateBasicBlockType = FALSE;
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->drupalPlaceBlock('page_title_block');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests creating a block type programmatically and via a form.
|
||||
*/
|
||||
public function testBlockContentTypeCreation() {
|
||||
// Log in a test user.
|
||||
$this->drupalLogin($this->adminUser);
|
||||
|
||||
// Test the page with no block-types.
|
||||
$this->drupalGet('block/add');
|
||||
$this->assertResponse(200);
|
||||
$this->assertText('You have not created any block types yet');
|
||||
$this->clickLink('block type creation page');
|
||||
|
||||
// Create a block type via the user interface.
|
||||
$edit = [
|
||||
'id' => 'foo',
|
||||
'label' => 'title for foo',
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
$block_type = BlockContentType::load('foo');
|
||||
$this->assertTrue($block_type, 'The new block type has been created.');
|
||||
|
||||
$field_definitions = \Drupal::entityManager()->getFieldDefinitions('block_content', 'foo');
|
||||
$this->assertTrue(isset($field_definitions['body']), 'Body field created when using the UI to create block content types.');
|
||||
|
||||
// Check that the block type was created in site default language.
|
||||
$default_langcode = \Drupal::languageManager()->getDefaultLanguage()->getId();
|
||||
$this->assertEqual($block_type->language()->getId(), $default_langcode);
|
||||
|
||||
// Create block types programmatically.
|
||||
$this->createBlockContentType('basic', TRUE);
|
||||
$field_definitions = \Drupal::entityManager()->getFieldDefinitions('block_content', 'basic');
|
||||
$this->assertTrue(isset($field_definitions['body']), "Body field for 'basic' block type created when using the testing API to create block content types.");
|
||||
|
||||
$this->createBlockContentType('other');
|
||||
$field_definitions = \Drupal::entityManager()->getFieldDefinitions('block_content', 'other');
|
||||
$this->assertFalse(isset($field_definitions['body']), "Body field for 'other' block type not created when using the testing API to create block content types.");
|
||||
|
||||
$block_type = BlockContentType::load('other');
|
||||
$this->assertTrue($block_type, 'The new block type has been created.');
|
||||
|
||||
$this->drupalGet('block/add/' . $block_type->id());
|
||||
$this->assertResponse(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests editing a block type using the UI.
|
||||
*/
|
||||
public function testBlockContentTypeEditing() {
|
||||
$this->drupalPlaceBlock('system_breadcrumb_block');
|
||||
// Now create an initial block-type.
|
||||
$this->createBlockContentType('basic', TRUE);
|
||||
|
||||
$this->drupalLogin($this->adminUser);
|
||||
// We need two block types to prevent /block/add redirecting.
|
||||
$this->createBlockContentType('other');
|
||||
|
||||
$field_definitions = \Drupal::entityManager()->getFieldDefinitions('block_content', 'other');
|
||||
$this->assertFalse(isset($field_definitions['body']), 'Body field was not created when using the API to create block content types.');
|
||||
|
||||
// Verify that title and body fields are displayed.
|
||||
$this->drupalGet('block/add/basic');
|
||||
$this->assertRaw('Block description', 'Block info field was found.');
|
||||
$this->assertNotEmpty($this->cssSelect('#edit-body-0-value'), 'Body field was found.');
|
||||
|
||||
// Change the block type name.
|
||||
$edit = [
|
||||
'label' => 'Bar',
|
||||
];
|
||||
$this->drupalGet('admin/structure/block/block-content/manage/basic');
|
||||
$this->assertTitle(format_string('Edit @type custom block type | Drupal', ['@type' => 'basic']));
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
$front_page_path = Url::fromRoute('<front>')->toString();
|
||||
$this->assertBreadcrumb('admin/structure/block/block-content/manage/basic/fields', [
|
||||
$front_page_path => 'Home',
|
||||
'admin/structure/block' => 'Block layout',
|
||||
'admin/structure/block/block-content' => 'Custom block library',
|
||||
'admin/structure/block/block-content/manage/basic' => 'Edit Bar',
|
||||
]);
|
||||
\Drupal::entityManager()->clearCachedFieldDefinitions();
|
||||
|
||||
$this->drupalGet('block/add');
|
||||
$this->assertRaw('Bar', 'New name was displayed.');
|
||||
$this->clickLink('Bar');
|
||||
$this->assertUrl(\Drupal::url('block_content.add_form', ['block_content_type' => 'basic'], ['absolute' => TRUE]), [], 'Original machine name was used in URL.');
|
||||
|
||||
// Remove the body field.
|
||||
$this->drupalPostForm('admin/structure/block/block-content/manage/basic/fields/block_content.basic.body/delete', [], t('Delete'));
|
||||
// Resave the settings for this type.
|
||||
$this->drupalPostForm('admin/structure/block/block-content/manage/basic', [], t('Save'));
|
||||
// Check that the body field doesn't exist.
|
||||
$this->drupalGet('block/add/basic');
|
||||
$this->assertEmpty($this->cssSelect('#edit-body-0-value'), 'Body field was not found.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests deleting a block type that still has content.
|
||||
*/
|
||||
public function testBlockContentTypeDeletion() {
|
||||
// Now create an initial block-type.
|
||||
$this->createBlockContentType('basic', TRUE);
|
||||
|
||||
// Create a block type programmatically.
|
||||
$type = $this->createBlockContentType('foo');
|
||||
|
||||
$this->drupalLogin($this->adminUser);
|
||||
|
||||
// Add a new block of this type.
|
||||
$block = $this->createBlockContent(FALSE, 'foo');
|
||||
// Attempt to delete the block type, which should not be allowed.
|
||||
$this->drupalGet('admin/structure/block/block-content/manage/' . $type->id() . '/delete');
|
||||
$this->assertRaw(
|
||||
t('%label is used by 1 custom block on your site. You can not remove this block type until you have removed all of the %label blocks.', ['%label' => $type->label()]),
|
||||
'The block type will not be deleted until all blocks of that type are removed.'
|
||||
);
|
||||
$this->assertNoText(t('This action cannot be undone.'), 'The block type deletion confirmation form is not available.');
|
||||
|
||||
// Delete the block.
|
||||
$block->delete();
|
||||
// Attempt to delete the block type, which should now be allowed.
|
||||
$this->drupalGet('admin/structure/block/block-content/manage/' . $type->id() . '/delete');
|
||||
$this->assertRaw(
|
||||
t('Are you sure you want to delete the custom block type %type?', ['%type' => $type->id()]),
|
||||
'The block type is available for deletion.'
|
||||
);
|
||||
$this->assertText(t('This action cannot be undone.'), 'The custom block type deletion confirmation form is available.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that redirects work as expected when multiple block types exist.
|
||||
*/
|
||||
public function testsBlockContentAddTypes() {
|
||||
// Now create an initial block-type.
|
||||
$this->createBlockContentType('basic', TRUE);
|
||||
|
||||
$this->drupalLogin($this->adminUser);
|
||||
// Create two block types programmatically.
|
||||
$type = $this->createBlockContentType('foo');
|
||||
$type = $this->createBlockContentType('bar');
|
||||
|
||||
// Get the custom block storage.
|
||||
$storage = $this->container
|
||||
->get('entity.manager')
|
||||
->getStorage('block_content');
|
||||
|
||||
// Install all themes.
|
||||
\Drupal::service('theme_handler')->install(['bartik', 'seven', 'stark']);
|
||||
$theme_settings = $this->config('system.theme');
|
||||
foreach (['bartik', 'seven', 'stark'] as $default_theme) {
|
||||
// Change the default theme.
|
||||
$theme_settings->set('default', $default_theme)->save();
|
||||
\Drupal::service('router.builder')->rebuild();
|
||||
|
||||
// For each installed theme, go to its block page and test the redirects.
|
||||
foreach (['bartik', 'seven', 'stark'] as $theme) {
|
||||
// Test that adding a block from the 'place blocks' form sends you to the
|
||||
// block configure form.
|
||||
$path = $theme == $default_theme ? 'admin/structure/block' : "admin/structure/block/list/$theme";
|
||||
$this->drupalGet($path);
|
||||
$this->clickLink('Place block');
|
||||
$this->clickLink(t('Add custom block'));
|
||||
// The seven theme has markup inside the link, we cannot use clickLink().
|
||||
if ($default_theme == 'seven') {
|
||||
$options = $theme != $default_theme ? ['query' => ['theme' => $theme]] : [];
|
||||
$this->assertLinkByHref(\Drupal::url('block_content.add_form', ['block_content_type' => 'foo'], $options));
|
||||
$this->drupalGet('block/add/foo', $options);
|
||||
}
|
||||
else {
|
||||
$this->clickLink('foo');
|
||||
}
|
||||
// Create a new block.
|
||||
$edit = ['info[0][value]' => $this->randomMachineName(8)];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
$blocks = $storage->loadByProperties(['info' => $edit['info[0][value]']]);
|
||||
if (!empty($blocks)) {
|
||||
$block = reset($blocks);
|
||||
$this->assertUrl(\Drupal::url('block.admin_add', ['plugin_id' => 'block_content:' . $block->uuid(), 'theme' => $theme], ['absolute' => TRUE]));
|
||||
$this->drupalPostForm(NULL, ['region' => 'content'], t('Save block'));
|
||||
$this->assertUrl(\Drupal::url('block.admin_display_theme', ['theme' => $theme], ['absolute' => TRUE, 'query' => ['block-placement' => Html::getClass($edit['info[0][value]'])]]));
|
||||
}
|
||||
else {
|
||||
$this->fail('Could not load created block.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Test that adding a block from the 'custom blocks list' doesn't send you
|
||||
// to the block configure form.
|
||||
$this->drupalGet('admin/structure/block/block-content');
|
||||
$this->clickLink(t('Add custom block'));
|
||||
$this->clickLink('foo');
|
||||
$edit = ['info[0][value]' => $this->randomMachineName(8)];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
$blocks = $storage->loadByProperties(['info' => $edit['info[0][value]']]);
|
||||
if (!empty($blocks)) {
|
||||
$this->assertUrl(\Drupal::url('entity.block_content.collection', [], ['absolute' => TRUE]));
|
||||
}
|
||||
else {
|
||||
$this->fail('Could not load created block.');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Functional;
|
||||
|
||||
/**
|
||||
* Tests block content validation constraints.
|
||||
*
|
||||
* @group block_content
|
||||
*/
|
||||
class BlockContentValidationTest extends BlockContentTestBase {
|
||||
|
||||
/**
|
||||
* Tests the block content validation constraints.
|
||||
*/
|
||||
public function testValidation() {
|
||||
// Add a block.
|
||||
$description = $this->randomMachineName();
|
||||
$block = $this->createBlockContent($description, 'basic');
|
||||
// Validate the block.
|
||||
$violations = $block->validate();
|
||||
// Make sure we have no violations.
|
||||
$this->assertEqual(count($violations), 0);
|
||||
// Save the block.
|
||||
$block->save();
|
||||
|
||||
// Add another block with the same description.
|
||||
$block = $this->createBlockContent($description, 'basic');
|
||||
// Validate this block.
|
||||
$violations = $block->validate();
|
||||
// Make sure we have 1 violation.
|
||||
$this->assertEqual(count($violations), 1);
|
||||
// Make sure the violation is on the info property
|
||||
$this->assertEqual($violations[0]->getPropertyPath(), 'info');
|
||||
// Make sure the message is correct.
|
||||
$this->assertEqual($violations[0]->getMessage(), format_string('A custom block with block description %value already exists.', [
|
||||
'%value' => $block->label(),
|
||||
]));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Functional\Hal;
|
||||
|
||||
use Drupal\Core\Cache\Cache;
|
||||
use Drupal\Tests\block_content\Functional\Rest\BlockContentResourceTestBase;
|
||||
use Drupal\Tests\hal\Functional\EntityResource\HalEntityNormalizationTrait;
|
||||
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class BlockContentHalJsonAnonTest extends BlockContentResourceTestBase {
|
||||
|
||||
use HalEntityNormalizationTrait;
|
||||
use AnonResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['hal'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'hal_json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getExpectedNormalizedEntity() {
|
||||
$default_normalization = parent::getExpectedNormalizedEntity();
|
||||
|
||||
$normalization = $this->applyHalFieldNormalization($default_normalization);
|
||||
|
||||
return $normalization + [
|
||||
'_links' => [
|
||||
'self' => [
|
||||
'href' => $this->baseUrl . '/block/1?_format=hal_json',
|
||||
],
|
||||
'type' => [
|
||||
'href' => $this->baseUrl . '/rest/type/block_content/basic',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getNormalizedPostEntity() {
|
||||
return parent::getNormalizedPostEntity() + [
|
||||
'_links' => [
|
||||
'type' => [
|
||||
'href' => $this->baseUrl . '/rest/type/block_content/basic',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getExpectedCacheContexts() {
|
||||
// The 'url.site' cache context is added for '_links' in the response.
|
||||
return Cache::mergeTags(parent::getExpectedCacheContexts(), ['url.site']);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Functional\Hal;
|
||||
|
||||
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class BlockContentHalJsonBasicAuthTest extends BlockContentHalJsonAnonTest {
|
||||
|
||||
use BasicAuthResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['basic_auth'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'basic_auth';
|
||||
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Functional\Hal;
|
||||
|
||||
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class BlockContentHalJsonCookieTest extends BlockContentHalJsonAnonTest {
|
||||
|
||||
use CookieResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'cookie';
|
||||
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Functional\Hal;
|
||||
|
||||
use Drupal\Tests\block_content\Functional\Rest\BlockContentTypeResourceTestBase;
|
||||
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class BlockContentTypeHalJsonAnonTest extends BlockContentTypeResourceTestBase {
|
||||
|
||||
use AnonResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['hal'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'hal_json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Functional\Hal;
|
||||
|
||||
use Drupal\Tests\block_content\Functional\Rest\BlockContentTypeResourceTestBase;
|
||||
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class BlockContentTypeHalJsonBasicAuthTest extends BlockContentTypeResourceTestBase {
|
||||
|
||||
use BasicAuthResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['hal', 'basic_auth'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'hal_json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'basic_auth';
|
||||
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Functional\Hal;
|
||||
|
||||
use Drupal\Tests\block_content\Functional\Rest\BlockContentTypeResourceTestBase;
|
||||
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class BlockContentTypeHalJsonCookieTest extends BlockContentTypeResourceTestBase {
|
||||
|
||||
use CookieResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['hal'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'hal_json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'cookie';
|
||||
|
||||
}
|
|
@ -3,7 +3,6 @@
|
|||
namespace Drupal\Tests\block_content\Functional;
|
||||
|
||||
use Drupal\block_content\Entity\BlockContent;
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
|
||||
/**
|
||||
* Create a block and test block edit functionality.
|
||||
|
@ -28,7 +27,7 @@ class PageEditTest extends BlockContentTestBase {
|
|||
$body_key = 'body[0][value]';
|
||||
// Create block to edit.
|
||||
$edit = [];
|
||||
$edit['info[0][value]'] = Unicode::strtolower($this->randomMachineName(8));
|
||||
$edit['info[0][value]'] = mb_strtolower($this->randomMachineName(8));
|
||||
$edit[$body_key] = $this->randomMachineName(16);
|
||||
$this->drupalPostForm('block/add/basic', $edit, t('Save'));
|
||||
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class BlockContentJsonAnonTest extends BlockContentResourceTestBase {
|
||||
|
||||
use AnonResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/json';
|
||||
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class BlockContentJsonBasicAuthTest extends BlockContentResourceTestBase {
|
||||
|
||||
use BasicAuthResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['basic_auth'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'basic_auth';
|
||||
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class BlockContentJsonCookieTest extends BlockContentResourceTestBase {
|
||||
|
||||
use CookieResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'cookie';
|
||||
|
||||
}
|
|
@ -0,0 +1,203 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Functional\Rest;
|
||||
|
||||
use Drupal\block_content\Entity\BlockContent;
|
||||
use Drupal\block_content\Entity\BlockContentType;
|
||||
use Drupal\Core\Cache\Cache;
|
||||
use Drupal\Tests\rest\Functional\BcTimestampNormalizerUnixTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase;
|
||||
|
||||
/**
|
||||
* ResourceTestBase for BlockContent entity.
|
||||
*/
|
||||
abstract class BlockContentResourceTestBase extends EntityResourceTestBase {
|
||||
|
||||
use BcTimestampNormalizerUnixTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['block_content'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $entityTypeId = 'block_content';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $patchProtectedFieldNames = [
|
||||
'changed' => NULL,
|
||||
];
|
||||
|
||||
/**
|
||||
* @var \Drupal\block_content\BlockContentInterface
|
||||
*/
|
||||
protected $entity;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUpAuthorization($method) {
|
||||
$this->grantPermissionsToTestedRole(['administer blocks']);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function createEntity() {
|
||||
if (!BlockContentType::load('basic')) {
|
||||
$block_content_type = BlockContentType::create([
|
||||
'id' => 'basic',
|
||||
'label' => 'basic',
|
||||
'revision' => TRUE,
|
||||
]);
|
||||
$block_content_type->save();
|
||||
block_content_add_body_field($block_content_type->id());
|
||||
}
|
||||
|
||||
// Create a "Llama" custom block.
|
||||
$block_content = BlockContent::create([
|
||||
'info' => 'Llama',
|
||||
'type' => 'basic',
|
||||
'body' => [
|
||||
'value' => 'The name "llama" was adopted by European settlers from native Peruvians.',
|
||||
'format' => 'plain_text',
|
||||
],
|
||||
])
|
||||
->setUnpublished();
|
||||
$block_content->save();
|
||||
return $block_content;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getExpectedNormalizedEntity() {
|
||||
return [
|
||||
'id' => [
|
||||
[
|
||||
'value' => 1,
|
||||
],
|
||||
],
|
||||
'uuid' => [
|
||||
[
|
||||
'value' => $this->entity->uuid(),
|
||||
],
|
||||
],
|
||||
'langcode' => [
|
||||
[
|
||||
'value' => 'en',
|
||||
],
|
||||
],
|
||||
'reusable' => [
|
||||
[
|
||||
'value' => TRUE,
|
||||
],
|
||||
],
|
||||
'type' => [
|
||||
[
|
||||
'target_id' => 'basic',
|
||||
'target_type' => 'block_content_type',
|
||||
'target_uuid' => BlockContentType::load('basic')->uuid(),
|
||||
],
|
||||
],
|
||||
'info' => [
|
||||
[
|
||||
'value' => 'Llama',
|
||||
],
|
||||
],
|
||||
'revision_log' => [],
|
||||
'changed' => [
|
||||
$this->formatExpectedTimestampItemValues($this->entity->getChangedTime()),
|
||||
],
|
||||
'revision_id' => [
|
||||
[
|
||||
'value' => 1,
|
||||
],
|
||||
],
|
||||
'revision_created' => [
|
||||
$this->formatExpectedTimestampItemValues((int) $this->entity->getRevisionCreationTime()),
|
||||
],
|
||||
'revision_user' => [],
|
||||
'revision_translation_affected' => [
|
||||
[
|
||||
'value' => TRUE,
|
||||
],
|
||||
],
|
||||
'default_langcode' => [
|
||||
[
|
||||
'value' => TRUE,
|
||||
],
|
||||
],
|
||||
'body' => [
|
||||
[
|
||||
'value' => 'The name "llama" was adopted by European settlers from native Peruvians.',
|
||||
'format' => 'plain_text',
|
||||
'summary' => NULL,
|
||||
'processed' => "<p>The name "llama" was adopted by European settlers from native Peruvians.</p>\n",
|
||||
],
|
||||
],
|
||||
'status' => [
|
||||
[
|
||||
'value' => FALSE,
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getNormalizedPostEntity() {
|
||||
return [
|
||||
'type' => [
|
||||
[
|
||||
'target_id' => 'basic',
|
||||
],
|
||||
],
|
||||
'info' => [
|
||||
[
|
||||
'value' => 'Dramallama',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getExpectedUnauthorizedAccessMessage($method) {
|
||||
if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) {
|
||||
return parent::getExpectedUnauthorizedAccessMessage($method);
|
||||
}
|
||||
|
||||
return parent::getExpectedUnauthorizedAccessMessage($method);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getExpectedUnauthorizedAccessCacheability() {
|
||||
// @see \Drupal\block_content\BlockContentAccessControlHandler()
|
||||
return parent::getExpectedUnauthorizedAccessCacheability()
|
||||
->addCacheTags(['block_content:1']);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getExpectedCacheTags() {
|
||||
return Cache::mergeTags(parent::getExpectedCacheTags(), ['config:filter.format.plain_text']);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getExpectedCacheContexts() {
|
||||
return Cache::mergeContexts(['url.site'], $this->container->getParameter('renderer.config')['required_cache_contexts']);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class BlockContentTypeJsonAnonTest extends BlockContentTypeResourceTestBase {
|
||||
|
||||
use AnonResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/json';
|
||||
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class BlockContentTypeJsonBasicAuthTest extends BlockContentTypeResourceTestBase {
|
||||
|
||||
use BasicAuthResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['basic_auth'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'basic_auth';
|
||||
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class BlockContentTypeJsonCookieTest extends BlockContentTypeResourceTestBase {
|
||||
|
||||
use CookieResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'cookie';
|
||||
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase;
|
||||
use Drupal\block_content\Entity\BlockContentType;
|
||||
|
||||
abstract class BlockContentTypeResourceTestBase extends EntityResourceTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['block_content'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $entityTypeId = 'block_content_type';
|
||||
|
||||
/**
|
||||
* @var \Drupal\block_content\Entity\BlockContentTypeInterface
|
||||
*/
|
||||
protected $entity;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUpAuthorization($method) {
|
||||
$this->grantPermissionsToTestedRole(['administer blocks']);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function createEntity() {
|
||||
$block_content_type = BlockContentType::create([
|
||||
'id' => 'pascal',
|
||||
'label' => 'Pascal',
|
||||
'revision' => FALSE,
|
||||
'description' => 'Provides a competitive alternative to the "basic" type',
|
||||
]);
|
||||
|
||||
$block_content_type->save();
|
||||
|
||||
return $block_content_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getExpectedNormalizedEntity() {
|
||||
return [
|
||||
'dependencies' => [],
|
||||
'description' => 'Provides a competitive alternative to the "basic" type',
|
||||
'id' => 'pascal',
|
||||
'label' => 'Pascal',
|
||||
'langcode' => 'en',
|
||||
'revision' => 0,
|
||||
'status' => TRUE,
|
||||
'uuid' => $this->entity->uuid(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getNormalizedPostEntity() {
|
||||
// @todo Update in https://www.drupal.org/node/2300677.
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class BlockContentTypeXmlAnonTest extends BlockContentTypeResourceTestBase {
|
||||
|
||||
use AnonResourceTestTrait;
|
||||
use XmlEntityNormalizationQuirksTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'xml';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'text/xml; charset=UTF-8';
|
||||
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class BlockContentTypeXmlBasicAuthTest extends BlockContentTypeResourceTestBase {
|
||||
|
||||
use BasicAuthResourceTestTrait;
|
||||
use XmlEntityNormalizationQuirksTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['basic_auth'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'xml';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'text/xml; charset=UTF-8';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'basic_auth';
|
||||
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class BlockContentTypeXmlCookieTest extends BlockContentTypeResourceTestBase {
|
||||
|
||||
use CookieResourceTestTrait;
|
||||
use XmlEntityNormalizationQuirksTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'xml';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'text/xml; charset=UTF-8';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'cookie';
|
||||
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class BlockContentXmlAnonTest extends BlockContentResourceTestBase {
|
||||
|
||||
use AnonResourceTestTrait;
|
||||
use XmlEntityNormalizationQuirksTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'xml';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'text/xml; charset=UTF-8';
|
||||
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class BlockContentXmlBasicAuthTest extends BlockContentResourceTestBase {
|
||||
|
||||
use BasicAuthResourceTestTrait;
|
||||
use XmlEntityNormalizationQuirksTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['basic_auth'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'xml';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'text/xml; charset=UTF-8';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'basic_auth';
|
||||
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class BlockContentXmlCookieTest extends BlockContentResourceTestBase {
|
||||
|
||||
use CookieResourceTestTrait;
|
||||
use XmlEntityNormalizationQuirksTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'xml';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'text/xml; charset=UTF-8';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'cookie';
|
||||
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Functional;
|
||||
|
||||
use Drupal\block_content\Entity\BlockContent;
|
||||
use Drupal\simpletest\BlockCreationTrait;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Tests unpublishing of block_content entities.
|
||||
*
|
||||
* @group block_content
|
||||
*/
|
||||
class UnpublishedBlockTest extends BrowserTestBase {
|
||||
|
||||
use BlockCreationTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['block_content'];
|
||||
|
||||
/**
|
||||
* Tests unpublishing of block_content entities.
|
||||
*/
|
||||
public function testViewShowsCorrectStates() {
|
||||
$block_content = BlockContent::create([
|
||||
'info' => 'Test block',
|
||||
'type' => 'basic',
|
||||
]);
|
||||
$block_content->save();
|
||||
|
||||
$this->placeBlock('block_content:' . $block_content->uuid());
|
||||
|
||||
$this->drupalGet('<front>');
|
||||
$page = $this->getSession()->getPage();
|
||||
$this->assertTrue($page->has('css', '.block-block-content' . $block_content->uuid()));
|
||||
|
||||
$block_content->setUnpublished();
|
||||
$block_content->save();
|
||||
|
||||
$this->drupalGet('<front>');
|
||||
$page = $this->getSession()->getPage();
|
||||
$this->assertFalse($page->has('css', '.block-block-content' . $block_content->uuid()));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,153 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Functional\Update;
|
||||
|
||||
use Drupal\block_content\Entity\BlockContent;
|
||||
use Drupal\FunctionalTests\Update\UpdatePathTestBase;
|
||||
|
||||
/**
|
||||
* Tests 'reusable' field related update functions for the Block Content module.
|
||||
*
|
||||
* @group Update
|
||||
* @group block_content
|
||||
* @group legacy
|
||||
*/
|
||||
class BlockContentReusableUpdateTest extends UpdatePathTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setDatabaseDumpFiles() {
|
||||
$this->databaseDumpFiles = [
|
||||
__DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.bare.standard.php.gz',
|
||||
// Override the 'block_content' view with an extra display with overridden
|
||||
// filters. This extra display should also have a filter added for
|
||||
// 'reusable' field so that it does not expose non-reusable fields. This
|
||||
// display also has a filter that only shows blocks that contain 'block2'
|
||||
// in the 'info' field.
|
||||
__DIR__ . '/../../../fixtures/update/drupal-8.views_block_content-2976334.php',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests adding 'reusable' entity base field to the block content entity type.
|
||||
*
|
||||
* @see block_content_update_8600()
|
||||
* @see block_content_post_update_add_views_reusable_filter()
|
||||
*/
|
||||
public function testReusableFieldAddition() {
|
||||
$assert_session = $this->assertSession();
|
||||
$entity_definition_update_manager = \Drupal::entityDefinitionUpdateManager();
|
||||
|
||||
// Ensure that 'reusable' field is not present before updates.
|
||||
$this->assertEmpty($entity_definition_update_manager->getFieldStorageDefinition('reusable', 'block_content'));
|
||||
|
||||
// Ensure that 'reusable' filter is not present before updates.
|
||||
$view_config = \Drupal::configFactory()->get('views.view.block_content');
|
||||
$this->assertFalse($view_config->isNew());
|
||||
$this->assertEmpty($view_config->get('display.default.display_options.filters.reusable'));
|
||||
$this->assertEmpty($view_config->get('display.page_2.display_options.filters.reusable'));
|
||||
// Run updates.
|
||||
$this->runUpdates();
|
||||
|
||||
// Ensure that 'reusable' filter is present after updates.
|
||||
\Drupal::configFactory()->clearStaticCache();
|
||||
$view_config = \Drupal::configFactory()->get('views.view.block_content');
|
||||
$this->assertNotEmpty($view_config->get('display.default.display_options.filters.reusable'));
|
||||
$this->assertNotEmpty($view_config->get('display.page_2.display_options.filters.reusable'));
|
||||
|
||||
// Check that the field exists and is configured correctly.
|
||||
$reusable_field = $entity_definition_update_manager->getFieldStorageDefinition('reusable', 'block_content');
|
||||
$this->assertEquals('Reusable', $reusable_field->getLabel());
|
||||
$this->assertEquals('A boolean indicating whether this block is reusable.', $reusable_field->getDescription());
|
||||
$this->assertEquals(FALSE, $reusable_field->isRevisionable());
|
||||
$this->assertEquals(FALSE, $reusable_field->isTranslatable());
|
||||
|
||||
$after_block1 = BlockContent::create([
|
||||
'info' => 'After update block1',
|
||||
'type' => 'basic_block',
|
||||
]);
|
||||
$after_block1->save();
|
||||
// Add second block that will be shown with the 'info' filter on the
|
||||
// additional view display.
|
||||
$after_block2 = BlockContent::create([
|
||||
'info' => 'After update block2',
|
||||
'type' => 'basic_block',
|
||||
]);
|
||||
$after_block2->save();
|
||||
|
||||
$this->assertTrue($after_block1->isReusable());
|
||||
$this->assertTrue($after_block2->isReusable());
|
||||
|
||||
$admin_user = $this->drupalCreateUser(['administer blocks']);
|
||||
$this->drupalLogin($admin_user);
|
||||
|
||||
$block_non_reusable = BlockContent::create([
|
||||
'info' => 'block1 non reusable',
|
||||
'type' => 'basic_block',
|
||||
'reusable' => FALSE,
|
||||
]);
|
||||
$block_non_reusable->save();
|
||||
// Add second block that would be shown with the 'info' filter on the
|
||||
// additional view display if the 'reusable' filter was not added.
|
||||
$block2_non_reusable = BlockContent::create([
|
||||
'info' => 'block2 non reusable',
|
||||
'type' => 'basic_block',
|
||||
'reusable' => FALSE,
|
||||
]);
|
||||
$block2_non_reusable->save();
|
||||
$this->assertFalse($block_non_reusable->isReusable());
|
||||
$this->assertFalse($block2_non_reusable->isReusable());
|
||||
|
||||
// Ensure the Custom Block view shows the reusable blocks only.
|
||||
$this->drupalGet('admin/structure/block/block-content');
|
||||
$assert_session->statusCodeEquals('200');
|
||||
$assert_session->responseContains('view-id-block_content');
|
||||
$assert_session->pageTextContains($after_block1->label());
|
||||
$assert_session->pageTextContains($after_block2->label());
|
||||
$assert_session->pageTextNotContains($block_non_reusable->label());
|
||||
$assert_session->pageTextNotContains($block2_non_reusable->label());
|
||||
|
||||
// Ensure the view's other display also only shows reusable blocks and still
|
||||
// filters on the 'info' field.
|
||||
$this->drupalGet('extra-view-display');
|
||||
$assert_session->statusCodeEquals('200');
|
||||
$assert_session->responseContains('view-id-block_content');
|
||||
$assert_session->pageTextNotContains($after_block1->label());
|
||||
$assert_session->pageTextContains($after_block2->label());
|
||||
$assert_session->pageTextNotContains($block_non_reusable->label());
|
||||
$assert_session->pageTextNotContains($block2_non_reusable->label());
|
||||
|
||||
// Ensure the Custom Block listing without Views installed shows the only
|
||||
// reusable blocks.
|
||||
$this->drupalGet('admin/structure/block/block-content');
|
||||
$this->container->get('module_installer')->uninstall(['views_ui', 'views']);
|
||||
$this->drupalGet('admin/structure/block/block-content');
|
||||
$assert_session->statusCodeEquals('200');
|
||||
$assert_session->responseNotContains('view-id-block_content');
|
||||
$assert_session->pageTextContains($after_block1->label());
|
||||
$assert_session->pageTextContains($after_block2->label());
|
||||
$assert_session->pageTextNotContains($block_non_reusable->label());
|
||||
$assert_session->pageTextNotContains($block2_non_reusable->label());
|
||||
|
||||
$this->drupalGet('block/' . $after_block1->id());
|
||||
$assert_session->statusCodeEquals('200');
|
||||
|
||||
// Ensure the non-reusable block is not accessible in the form.
|
||||
$this->drupalGet('block/' . $block_non_reusable->id());
|
||||
$assert_session->statusCodeEquals('403');
|
||||
|
||||
$this->drupalLogout();
|
||||
|
||||
$this->drupalLogin($this->createUser([
|
||||
'access user profiles',
|
||||
'administer blocks',
|
||||
]));
|
||||
$this->drupalGet('block/' . $after_block1->id());
|
||||
$assert_session->statusCodeEquals('200');
|
||||
|
||||
$this->drupalGet('block/' . $block_non_reusable->id());
|
||||
$assert_session->statusCodeEquals('403');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Functional\Update;
|
||||
|
||||
use Drupal\Core\Field\BaseFieldDefinition;
|
||||
use Drupal\FunctionalTests\Update\UpdatePathTestBase;
|
||||
|
||||
/**
|
||||
* Tests update functions for the Block Content module.
|
||||
*
|
||||
* @group Update
|
||||
* @group legacy
|
||||
*/
|
||||
class BlockContentUpdateTest extends UpdatePathTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setDatabaseDumpFiles() {
|
||||
$this->databaseDumpFiles = [
|
||||
__DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.bare.standard.php.gz',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the revision metadata fields and revision data table additions.
|
||||
*/
|
||||
public function testSimpleUpdates() {
|
||||
$entity_definition_update_manager = \Drupal::entityDefinitionUpdateManager();
|
||||
$entity_type = $entity_definition_update_manager->getEntityType('block_content');
|
||||
$this->assertNull($entity_type->getRevisionDataTable());
|
||||
|
||||
$this->runUpdates();
|
||||
|
||||
$post_revision_created = $entity_definition_update_manager->getFieldStorageDefinition('revision_created', 'block_content');
|
||||
$post_revision_user = $entity_definition_update_manager->getFieldStorageDefinition('revision_user', 'block_content');
|
||||
$this->assertTrue($post_revision_created instanceof BaseFieldDefinition, "Revision created field found");
|
||||
$this->assertTrue($post_revision_user instanceof BaseFieldDefinition, "Revision user field found");
|
||||
|
||||
$this->assertEqual('created', $post_revision_created->getType(), "Field is type created");
|
||||
$this->assertEqual('entity_reference', $post_revision_user->getType(), "Field is type entity_reference");
|
||||
|
||||
$entity_type = $entity_definition_update_manager->getEntityType('block_content');
|
||||
$this->assertEqual('block_content_field_revision', $entity_type->getRevisionDataTable());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests adding a status field to the block content entity type.
|
||||
*
|
||||
* @see block_content_update_8400()
|
||||
*/
|
||||
public function testStatusFieldAddition() {
|
||||
$schema = \Drupal::database()->schema();
|
||||
$entity_definition_update_manager = \Drupal::entityDefinitionUpdateManager();
|
||||
|
||||
// Run updates.
|
||||
$this->runUpdates();
|
||||
|
||||
// Check that the field exists and has the correct label.
|
||||
$updated_field = $entity_definition_update_manager->getFieldStorageDefinition('status', 'block_content');
|
||||
$this->assertEqual('Publishing status', $updated_field->getLabel());
|
||||
|
||||
$content_translation_status = $entity_definition_update_manager->getFieldStorageDefinition('content_translation_status', 'block_content');
|
||||
$this->assertNull($content_translation_status);
|
||||
|
||||
$this->assertFalse($schema->fieldExists('block_content_field_revision', 'content_translation_status'));
|
||||
$this->assertFalse($schema->fieldExists('block_content_field_data', 'content_translation_status'));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,108 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Functional\Views;
|
||||
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
|
||||
/**
|
||||
* Tests block_content field filters with translations.
|
||||
*
|
||||
* @group block_content
|
||||
*/
|
||||
class BlockContentFieldFilterTest extends BlockContentTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['language'];
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = ['test_field_filters'];
|
||||
|
||||
/**
|
||||
* List of block_content infos by language.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $blockContentInfos = [];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setUp($import_test_views = TRUE) {
|
||||
parent::setUp($import_test_views);
|
||||
|
||||
// Add two new languages.
|
||||
ConfigurableLanguage::createFromLangcode('fr')->save();
|
||||
ConfigurableLanguage::createFromLangcode('es')->save();
|
||||
|
||||
// Make the body field translatable. The info is already translatable by
|
||||
// definition.
|
||||
$field_storage = FieldStorageConfig::loadByName('block_content', 'body');
|
||||
$field_storage->setTranslatable(TRUE);
|
||||
$field_storage->save();
|
||||
|
||||
// Set up block_content infos.
|
||||
$this->blockContentInfos = [
|
||||
'en' => 'Food in Paris',
|
||||
'es' => 'Comida en Paris',
|
||||
'fr' => 'Nouriture en Paris',
|
||||
];
|
||||
|
||||
// Create block_content with translations.
|
||||
$block_content = $this->createBlockContent(['info' => $this->blockContentInfos['en'], 'langcode' => 'en', 'type' => 'basic', 'body' => [['value' => $this->blockContentInfos['en']]]]);
|
||||
foreach (['es', 'fr'] as $langcode) {
|
||||
$translation = $block_content->addTranslation($langcode, ['info' => $this->blockContentInfos[$langcode]]);
|
||||
$translation->body->value = $this->blockContentInfos[$langcode];
|
||||
}
|
||||
$block_content->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests body and info filters.
|
||||
*/
|
||||
public function testFilters() {
|
||||
// Test the info filter page, which filters for info contains 'Comida'.
|
||||
// Should show just the Spanish translation, once.
|
||||
$this->assertPageCounts('test-info-filter', ['es' => 1, 'fr' => 0, 'en' => 0], 'Comida info filter');
|
||||
|
||||
// Test the body filter page, which filters for body contains 'Comida'.
|
||||
// Should show just the Spanish translation, once.
|
||||
$this->assertPageCounts('test-body-filter', ['es' => 1, 'fr' => 0, 'en' => 0], 'Comida body filter');
|
||||
|
||||
// Test the info Paris filter page, which filters for info contains
|
||||
// 'Paris'. Should show each translation once.
|
||||
$this->assertPageCounts('test-info-paris', ['es' => 1, 'fr' => 1, 'en' => 1], 'Paris info filter');
|
||||
|
||||
// Test the body Paris filter page, which filters for body contains
|
||||
// 'Paris'. Should show each translation once.
|
||||
$this->assertPageCounts('test-body-paris', ['es' => 1, 'fr' => 1, 'en' => 1], 'Paris body filter');
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the given block_content translation counts are correct.
|
||||
*
|
||||
* @param string $path
|
||||
* Path of the page to test.
|
||||
* @param array $counts
|
||||
* Array whose keys are languages, and values are the number of times
|
||||
* that translation should be shown on the given page.
|
||||
* @param string $message
|
||||
* Message suffix to display.
|
||||
*/
|
||||
protected function assertPageCounts($path, $counts, $message) {
|
||||
// Get the text of the page.
|
||||
$this->drupalGet($path);
|
||||
$text = $this->getTextContent();
|
||||
|
||||
foreach ($counts as $langcode => $count) {
|
||||
$this->assertEqual(substr_count($text, $this->blockContentInfos[$langcode]), $count, 'Translation ' . $langcode . ' has count ' . $count . ' with ' . $message);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Functional\Views;
|
||||
|
||||
/**
|
||||
* Tests the block_content integration into views.
|
||||
*
|
||||
* @group block_content
|
||||
*/
|
||||
class BlockContentIntegrationTest extends BlockContentTestBase {
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = ['test_block_content_view'];
|
||||
|
||||
/**
|
||||
* Tests basic block_content view with a block_content_type argument.
|
||||
*/
|
||||
public function testBlockContentViewTypeArgument() {
|
||||
// Create two content types with three block_contents each.
|
||||
$types = [];
|
||||
$all_ids = [];
|
||||
$block_contents = [];
|
||||
for ($i = 0; $i < 2; $i++) {
|
||||
$type = $this->createBlockContentType();
|
||||
$types[] = $type;
|
||||
|
||||
for ($j = 0; $j < 5; $j++) {
|
||||
// Ensure the right order of the block_contents.
|
||||
$block_content = $this->createBlockContent(['type' => $type->id()]);
|
||||
$block_contents[$type->id()][$block_content->id()] = $block_content;
|
||||
$all_ids[] = $block_content->id();
|
||||
}
|
||||
}
|
||||
|
||||
$this->drupalGet('test-block_content-view');
|
||||
$this->assertResponse(404);
|
||||
|
||||
$this->drupalGet('test-block_content-view/all');
|
||||
$this->assertResponse(200);
|
||||
$this->assertIds($all_ids);
|
||||
/* @var \Drupal\block_content\Entity\BlockContentType[] $types*/
|
||||
foreach ($types as $type) {
|
||||
$this->drupalGet("test-block_content-view/{$type->id()}");
|
||||
$this->assertIds(array_keys($block_contents[$type->id()]));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures that a list of block_contents appear on the page.
|
||||
*
|
||||
* @param array $expected_ids
|
||||
* An array of block_content IDs.
|
||||
*/
|
||||
protected function assertIds(array $expected_ids = []) {
|
||||
$result = $this->xpath('//span[@class="field-content"]');
|
||||
$ids = [];
|
||||
foreach ($result as $element) {
|
||||
$ids[] = $element->getText();
|
||||
}
|
||||
$this->assertEqual($ids, $expected_ids);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Functional\Views;
|
||||
|
||||
/**
|
||||
* Tests the redirect destination on block content on entity operations.
|
||||
*
|
||||
* @group block_content
|
||||
*/
|
||||
class BlockContentRedirectTest extends BlockContentTestBase {
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = ['test_block_content_redirect_destination'];
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['block', 'block_content', 'views'];
|
||||
|
||||
/**
|
||||
* Tests the redirect destination when editing block content.
|
||||
*/
|
||||
public function testRedirectDestination() {
|
||||
$this->drupalLogin($this->drupalCreateUser(['administer blocks']));
|
||||
$this->drupalGet('admin/structure/block/block-content');
|
||||
|
||||
// Create a custom block.
|
||||
$this->clickLink('custom block');
|
||||
$edit = [];
|
||||
$edit['info[0][value]'] = 'Test redirect destination';
|
||||
$edit['body[0][value]'] = $this->randomMachineName(16);
|
||||
$this->drupalPostForm(NULL, $edit, 'Save');
|
||||
|
||||
// Check the block content is present in the view redirect destination.
|
||||
$this->drupalGet('admin/content/redirect_destination');
|
||||
$this->assertText('Test redirect destination');
|
||||
|
||||
// Edit the created block and save.
|
||||
$this->clickLink('Edit');
|
||||
$this->drupalPostForm(NULL, [], 'Save');
|
||||
$this->assertUrl('admin/content/redirect_destination');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,107 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Functional\Views;
|
||||
|
||||
use Drupal\block_content\Entity\BlockContent;
|
||||
use Drupal\block_content\Entity\BlockContentType;
|
||||
use Drupal\Component\Render\FormattableMarkup;
|
||||
use Drupal\Tests\views\Functional\ViewTestBase;
|
||||
use Drupal\views\Tests\ViewTestData;
|
||||
|
||||
/**
|
||||
* Base class for all block_content tests.
|
||||
*/
|
||||
abstract class BlockContentTestBase extends ViewTestBase {
|
||||
|
||||
/**
|
||||
* Admin user
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
protected $adminUser;
|
||||
|
||||
/**
|
||||
* Permissions to grant admin user.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $permissions = [
|
||||
'administer blocks',
|
||||
];
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['block', 'block_content', 'block_content_test_views'];
|
||||
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp($import_test_views);
|
||||
// Ensure the basic bundle exists. This is provided by the standard profile.
|
||||
$this->createBlockContentType(['id' => 'basic']);
|
||||
|
||||
$this->adminUser = $this->drupalCreateUser($this->permissions);
|
||||
|
||||
if ($import_test_views) {
|
||||
ViewTestData::createTestViews(get_class($this), ['block_content_test_views']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a custom block.
|
||||
*
|
||||
* @param array $settings
|
||||
* (optional) An associative array of settings for the block_content, as
|
||||
* used in entity_create().
|
||||
*
|
||||
* @return \Drupal\block_content\Entity\BlockContent
|
||||
* Created custom block.
|
||||
*/
|
||||
protected function createBlockContent(array $settings = []) {
|
||||
$status = 0;
|
||||
$settings += [
|
||||
'info' => $this->randomMachineName(),
|
||||
'type' => 'basic',
|
||||
'langcode' => 'en',
|
||||
];
|
||||
if ($block_content = BlockContent::create($settings)) {
|
||||
$status = $block_content->save();
|
||||
}
|
||||
$this->assertEqual($status, SAVED_NEW, new FormattableMarkup('Created block content %info.', ['%info' => $block_content->label()]));
|
||||
return $block_content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a custom block type (bundle).
|
||||
*
|
||||
* @param array $values
|
||||
* An array of settings to change from the defaults.
|
||||
*
|
||||
* @return \Drupal\block_content\Entity\BlockContentType
|
||||
* Created custom block type.
|
||||
*/
|
||||
protected function createBlockContentType(array $values = []) {
|
||||
// Find a non-existent random type name.
|
||||
if (!isset($values['id'])) {
|
||||
do {
|
||||
$id = strtolower($this->randomMachineName(8));
|
||||
} while (BlockContentType::load($id));
|
||||
}
|
||||
else {
|
||||
$id = $values['id'];
|
||||
}
|
||||
$values += [
|
||||
'id' => $id,
|
||||
'label' => $id,
|
||||
'revision' => FALSE,
|
||||
];
|
||||
$bundle = BlockContentType::create($values);
|
||||
$status = $bundle->save();
|
||||
block_content_add_body_field($bundle->id());
|
||||
|
||||
$this->assertEqual($status, SAVED_NEW, new FormattableMarkup('Created block content type %bundle.', ['%bundle' => $bundle->id()]));
|
||||
return $bundle;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Functional\Views;
|
||||
|
||||
use Drupal\Tests\block_content\Functional\BlockContentTestBase;
|
||||
|
||||
/**
|
||||
* Tests block_content wizard and generic entity integration.
|
||||
*
|
||||
* @group block_content
|
||||
*/
|
||||
class BlockContentWizardTest extends BlockContentTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['block_content', 'views_ui'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->drupalLogin($this->drupalCreateUser(['administer views']));
|
||||
$this->createBlockContentType('Basic block');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests creating a 'block_content' entity view.
|
||||
*/
|
||||
public function testViewAddBlockContent() {
|
||||
$view = [];
|
||||
$view['label'] = $this->randomMachineName(16);
|
||||
$view['id'] = strtolower($this->randomMachineName(16));
|
||||
$view['description'] = $this->randomMachineName(16);
|
||||
$view['page[create]'] = FALSE;
|
||||
$view['show[wizard_key]'] = 'block_content';
|
||||
$this->drupalPostForm('admin/structure/views/add', $view, t('Save and edit'));
|
||||
|
||||
$view_storage_controller = $this->container->get('entity_type.manager')->getStorage('view');
|
||||
/** @var \Drupal\views\Entity\View $view */
|
||||
$view = $view_storage_controller->load($view['id']);
|
||||
|
||||
$display_options = $view->getDisplay('default')['display_options'];
|
||||
|
||||
$this->assertEquals('block_content', $display_options['filters']['reusable']['entity_type']);
|
||||
$this->assertEquals('reusable', $display_options['filters']['reusable']['entity_field']);
|
||||
$this->assertEquals('boolean', $display_options['filters']['reusable']['plugin_id']);
|
||||
$this->assertEquals('1', $display_options['filters']['reusable']['value']);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Functional\Views;
|
||||
|
||||
use Drupal\views\Views;
|
||||
|
||||
/**
|
||||
* Tests the Drupal\block_content\Plugin\views\field\Type handler.
|
||||
*
|
||||
* @group block_content
|
||||
*/
|
||||
class FieldTypeTest extends BlockContentTestBase {
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = ['test_field_type'];
|
||||
|
||||
public function testFieldType() {
|
||||
$block_content = $this->createBlockContent();
|
||||
$expected_result[] = [
|
||||
'id' => $block_content->id(),
|
||||
'type' => $block_content->bundle(),
|
||||
];
|
||||
$column_map = [
|
||||
'id' => 'id',
|
||||
'type:target_id' => 'type',
|
||||
];
|
||||
|
||||
$view = Views::getView('test_field_type');
|
||||
$this->executeView($view);
|
||||
$this->assertIdenticalResultset($view, $expected_result, $column_map, 'The correct block_content type was displayed.');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,92 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Functional\Views;
|
||||
|
||||
use Drupal\block_content\Entity\BlockContentType;
|
||||
use Drupal\block_content\Entity\BlockContent;
|
||||
use Drupal\Tests\views\Functional\ViewTestBase;
|
||||
use Drupal\views\Views;
|
||||
use Drupal\views\Tests\ViewTestData;
|
||||
|
||||
/**
|
||||
* Tests the integration of block_content_revision table of block_content module.
|
||||
*
|
||||
* @group block_content
|
||||
*/
|
||||
class RevisionRelationshipsTest extends ViewTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['block_content' , 'block_content_test_views'];
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = ['test_block_content_revision_id', 'test_block_content_revision_revision_id'];
|
||||
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp($import_test_views);
|
||||
BlockContentType::create([
|
||||
'id' => 'basic',
|
||||
'label' => 'basic',
|
||||
'revision' => TRUE,
|
||||
]);
|
||||
ViewTestData::createTestViews(get_class($this), ['block_content_test_views']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a block_content with revision and rest result count for both views.
|
||||
*/
|
||||
public function testBlockContentRevisionRelationship() {
|
||||
$block_content = BlockContent::create([
|
||||
'info' => $this->randomMachineName(),
|
||||
'type' => 'basic',
|
||||
'langcode' => 'en',
|
||||
]);
|
||||
$block_content->save();
|
||||
// Create revision of the block_content.
|
||||
$block_content_revision = clone $block_content;
|
||||
$block_content_revision->setNewRevision();
|
||||
$block_content_revision->save();
|
||||
$column_map = [
|
||||
'revision_id' => 'revision_id',
|
||||
'id_1' => 'id_1',
|
||||
'block_content_field_data_block_content_field_revision_id' => 'block_content_field_data_block_content_field_revision_id',
|
||||
];
|
||||
|
||||
// Here should be two rows.
|
||||
$view_id = Views::getView('test_block_content_revision_id');
|
||||
$this->executeView($view_id, [$block_content->id()]);
|
||||
$resultset_id = [
|
||||
[
|
||||
'revision_id' => '1',
|
||||
'id_1' => '1',
|
||||
'block_content_field_data_block_content_field_revision_id' => '1',
|
||||
],
|
||||
[
|
||||
'revision_id' => '2',
|
||||
'id_1' => '1',
|
||||
'block_content_field_data_block_content_field_revision_id' => '1',
|
||||
],
|
||||
];
|
||||
$this->assertIdenticalResultset($view_id, $resultset_id, $column_map);
|
||||
|
||||
// There should be only one row with active revision 2.
|
||||
$view_revision_id = Views::getView('test_block_content_revision_revision_id');
|
||||
$this->executeView($view_revision_id, [$block_content->id()]);
|
||||
$resultset_revision_id = [
|
||||
[
|
||||
'revision_id' => '2',
|
||||
'id_1' => '1',
|
||||
'block_content_field_data_block_content_field_revision_id' => '1',
|
||||
],
|
||||
];
|
||||
$this->assertIdenticalResultset($view_revision_id, $resultset_revision_id, $column_map);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,300 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Kernel;
|
||||
|
||||
use Drupal\block_content\BlockContentAccessControlHandler;
|
||||
use Drupal\block_content\Entity\BlockContent;
|
||||
use Drupal\block_content\Entity\BlockContentType;
|
||||
use Drupal\Core\Access\AccessibleInterface;
|
||||
use Drupal\Core\Access\AccessResult;
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
use Drupal\user\Entity\Role;
|
||||
use Drupal\user\Entity\User;
|
||||
|
||||
/**
|
||||
* Tests the block content entity access handler.
|
||||
*
|
||||
* @coversDefaultClass \Drupal\block_content\BlockContentAccessControlHandler
|
||||
*
|
||||
* @group block_content
|
||||
*/
|
||||
class BlockContentAccessHandlerTest extends KernelTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = [
|
||||
'block',
|
||||
'block_content',
|
||||
'system',
|
||||
'user',
|
||||
];
|
||||
|
||||
/**
|
||||
* The BlockContent access controller to test.
|
||||
*
|
||||
* @var \Drupal\block_content\BlockContentAccessControlHandler
|
||||
*/
|
||||
protected $accessControlHandler;
|
||||
|
||||
/**
|
||||
* The BlockContent entity used for testing.
|
||||
*
|
||||
* @var \Drupal\block_content\Entity\BlockContent
|
||||
*/
|
||||
protected $blockEntity;
|
||||
|
||||
/**
|
||||
* The test role.
|
||||
*
|
||||
* @var \Drupal\user\RoleInterface
|
||||
*/
|
||||
protected $role;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->installSchema('system', ['sequence']);
|
||||
$this->installSchema('system', ['sequences']);
|
||||
$this->installSchema('user', ['users_data']);
|
||||
$this->installEntitySchema('user');
|
||||
$this->installEntitySchema('block_content');
|
||||
|
||||
// Create a block content type.
|
||||
$block_content_type = BlockContentType::create([
|
||||
'id' => 'square',
|
||||
'label' => 'A square block type',
|
||||
'description' => "Provides a block type that is square.",
|
||||
]);
|
||||
$block_content_type->save();
|
||||
|
||||
$this->blockEntity = BlockContent::create([
|
||||
'info' => 'The Block',
|
||||
'type' => 'square',
|
||||
]);
|
||||
$this->blockEntity->save();
|
||||
|
||||
// Create user 1 test does not have all permissions.
|
||||
User::create([
|
||||
'name' => 'admin',
|
||||
])->save();
|
||||
|
||||
$this->role = Role::create([
|
||||
'id' => 'roly',
|
||||
'label' => 'roly poly',
|
||||
]);
|
||||
$this->role->save();
|
||||
$this->accessControlHandler = new BlockContentAccessControlHandler(\Drupal::entityTypeManager()->getDefinition('block_content'), \Drupal::service('event_dispatcher'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::checkAccess
|
||||
*
|
||||
* @dataProvider providerTestAccess
|
||||
*/
|
||||
public function testAccess($operation, $published, $reusable, $permissions, $parent_access, $expected_access) {
|
||||
$published ? $this->blockEntity->setPublished() : $this->blockEntity->setUnpublished();
|
||||
$reusable ? $this->blockEntity->setReusable() : $this->blockEntity->setNonReusable();
|
||||
|
||||
$user = User::create([
|
||||
'name' => 'Someone',
|
||||
'mail' => 'hi@example.com',
|
||||
]);
|
||||
|
||||
if ($permissions) {
|
||||
foreach ($permissions as $permission) {
|
||||
$this->role->grantPermission($permission);
|
||||
}
|
||||
$this->role->save();
|
||||
}
|
||||
$user->addRole($this->role->id());
|
||||
$user->save();
|
||||
|
||||
if ($parent_access) {
|
||||
$parent_entity = $this->prophesize(AccessibleInterface::class);
|
||||
$expected_parent_result = NULL;
|
||||
switch ($parent_access) {
|
||||
case 'allowed':
|
||||
$expected_parent_result = AccessResult::allowed();
|
||||
break;
|
||||
|
||||
case 'neutral':
|
||||
$expected_parent_result = AccessResult::neutral();
|
||||
break;
|
||||
|
||||
case 'forbidden':
|
||||
$expected_parent_result = AccessResult::forbidden();
|
||||
break;
|
||||
}
|
||||
$parent_entity->access($operation, $user, TRUE)
|
||||
->willReturn($expected_parent_result)
|
||||
->shouldBeCalled();
|
||||
|
||||
$this->blockEntity->setAccessDependency($parent_entity->reveal());
|
||||
|
||||
}
|
||||
$this->blockEntity->save();
|
||||
|
||||
$result = $this->accessControlHandler->access($this->blockEntity, $operation, $user, TRUE);
|
||||
switch ($expected_access) {
|
||||
case 'allowed':
|
||||
$this->assertTrue($result->isAllowed());
|
||||
break;
|
||||
|
||||
case 'forbidden':
|
||||
$this->assertTrue($result->isForbidden());
|
||||
break;
|
||||
|
||||
case 'neutral':
|
||||
$this->assertTrue($result->isNeutral());
|
||||
break;
|
||||
|
||||
default:
|
||||
$this->fail('Unexpected access type');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Dataprovider for testAccess().
|
||||
*/
|
||||
public function providerTestAccess() {
|
||||
$cases = [
|
||||
'view:published:reusable' => [
|
||||
'view',
|
||||
TRUE,
|
||||
TRUE,
|
||||
[],
|
||||
NULL,
|
||||
'allowed',
|
||||
],
|
||||
'view:unpublished:reusable' => [
|
||||
'view',
|
||||
FALSE,
|
||||
TRUE,
|
||||
[],
|
||||
NULL,
|
||||
'neutral',
|
||||
],
|
||||
'view:unpublished:reusable:admin' => [
|
||||
'view',
|
||||
FALSE,
|
||||
TRUE,
|
||||
['administer blocks'],
|
||||
NULL,
|
||||
'allowed',
|
||||
],
|
||||
'view:published:reusable:admin' => [
|
||||
'view',
|
||||
TRUE,
|
||||
TRUE,
|
||||
['administer blocks'],
|
||||
NULL,
|
||||
'allowed',
|
||||
],
|
||||
'view:published:non_reusable' => [
|
||||
'view',
|
||||
TRUE,
|
||||
FALSE,
|
||||
[],
|
||||
NULL,
|
||||
'forbidden',
|
||||
],
|
||||
'view:published:non_reusable:parent_allowed' => [
|
||||
'view',
|
||||
TRUE,
|
||||
FALSE,
|
||||
[],
|
||||
'allowed',
|
||||
'allowed',
|
||||
],
|
||||
'view:published:non_reusable:parent_neutral' => [
|
||||
'view',
|
||||
TRUE,
|
||||
FALSE,
|
||||
[],
|
||||
'neutral',
|
||||
'neutral',
|
||||
],
|
||||
'view:published:non_reusable:parent_forbidden' => [
|
||||
'view',
|
||||
TRUE,
|
||||
FALSE,
|
||||
[],
|
||||
'forbidden',
|
||||
'forbidden',
|
||||
],
|
||||
];
|
||||
foreach (['update', 'delete'] as $operation) {
|
||||
$cases += [
|
||||
$operation . ':published:reusable' => [
|
||||
$operation,
|
||||
TRUE,
|
||||
TRUE,
|
||||
[],
|
||||
NULL,
|
||||
'neutral',
|
||||
],
|
||||
$operation . ':unpublished:reusable' => [
|
||||
$operation,
|
||||
FALSE,
|
||||
TRUE,
|
||||
[],
|
||||
NULL,
|
||||
'neutral',
|
||||
],
|
||||
$operation . ':unpublished:reusable:admin' => [
|
||||
$operation,
|
||||
FALSE,
|
||||
TRUE,
|
||||
['administer blocks'],
|
||||
NULL,
|
||||
'allowed',
|
||||
],
|
||||
$operation . ':published:reusable:admin' => [
|
||||
$operation,
|
||||
TRUE,
|
||||
TRUE,
|
||||
['administer blocks'],
|
||||
NULL,
|
||||
'allowed',
|
||||
],
|
||||
$operation . ':published:non_reusable' => [
|
||||
$operation,
|
||||
TRUE,
|
||||
FALSE,
|
||||
[],
|
||||
NULL,
|
||||
'forbidden',
|
||||
],
|
||||
$operation . ':published:non_reusable:parent_allowed' => [
|
||||
$operation,
|
||||
TRUE,
|
||||
FALSE,
|
||||
[],
|
||||
'allowed',
|
||||
'neutral',
|
||||
],
|
||||
$operation . ':published:non_reusable:parent_neutral' => [
|
||||
$operation,
|
||||
TRUE,
|
||||
FALSE,
|
||||
[],
|
||||
'neutral',
|
||||
'neutral',
|
||||
],
|
||||
$operation . ':published:non_reusable:parent_forbidden' => [
|
||||
$operation,
|
||||
TRUE,
|
||||
FALSE,
|
||||
[],
|
||||
'forbidden',
|
||||
'forbidden',
|
||||
],
|
||||
];
|
||||
return $cases;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Kernel;
|
||||
|
||||
use Drupal\block_content\Entity\BlockContent;
|
||||
use Drupal\block_content\Entity\BlockContentType;
|
||||
use Drupal\Component\Plugin\PluginBase;
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
|
||||
/**
|
||||
* Tests block content plugin deriver.
|
||||
*
|
||||
* @group block_content
|
||||
*/
|
||||
class BlockContentDeriverTest extends KernelTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['block', 'block_content', 'system', 'user'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
$this->installSchema('system', ['sequence']);
|
||||
$this->installEntitySchema('user');
|
||||
$this->installEntitySchema('block_content');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that only reusable blocks are derived.
|
||||
*/
|
||||
public function testReusableBlocksOnlyAreDerived() {
|
||||
// Create a block content type.
|
||||
$block_content_type = BlockContentType::create([
|
||||
'id' => 'spiffy',
|
||||
'label' => 'Mucho spiffy',
|
||||
'description' => "Provides a block type that increases your site's spiffiness by up to 11%",
|
||||
]);
|
||||
$block_content_type->save();
|
||||
// And a block content entity.
|
||||
$block_content = BlockContent::create([
|
||||
'info' => 'Spiffy prototype',
|
||||
'type' => 'spiffy',
|
||||
]);
|
||||
$block_content->save();
|
||||
|
||||
// Ensure the reusable block content is provided as a derivative block
|
||||
// plugin.
|
||||
/** @var \Drupal\Core\Block\BlockManagerInterface $block_manager */
|
||||
$block_manager = $this->container->get('plugin.manager.block');
|
||||
$plugin_id = 'block_content' . PluginBase::DERIVATIVE_SEPARATOR . $block_content->uuid();
|
||||
$this->assertTrue($block_manager->hasDefinition($plugin_id));
|
||||
|
||||
// Set the block not to be reusable.
|
||||
$block_content->setNonReusable();
|
||||
$block_content->save();
|
||||
|
||||
// Ensure the non-reusable block content is not provided a derivative block
|
||||
// plugin.
|
||||
$this->assertFalse($block_manager->hasDefinition($plugin_id));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,189 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Kernel;
|
||||
|
||||
use Drupal\block_content\Entity\BlockContent;
|
||||
use Drupal\block_content\Entity\BlockContentType;
|
||||
use Drupal\block_content_test\Plugin\EntityReferenceSelection\TestSelection;
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
|
||||
/**
|
||||
* Tests EntityReference selection handlers don't return non-reusable blocks.
|
||||
*
|
||||
* @see block_content_query_entity_reference_alter()
|
||||
*
|
||||
* @group block_content
|
||||
*/
|
||||
class BlockContentEntityReferenceSelectionTest extends KernelTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = [
|
||||
'block',
|
||||
'block_content',
|
||||
'block_content_test',
|
||||
'system',
|
||||
'user',
|
||||
];
|
||||
|
||||
/**
|
||||
* The entity type manager.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
|
||||
*/
|
||||
protected $entityTypeManager;
|
||||
|
||||
/**
|
||||
* Test reusable block.
|
||||
*
|
||||
* @var \Drupal\block_content\BlockContentInterface
|
||||
*/
|
||||
protected $blockReusable;
|
||||
|
||||
/**
|
||||
* Test non-reusable block.
|
||||
*
|
||||
* @var \Drupal\block_content\BlockContentInterface
|
||||
*/
|
||||
protected $blockNonReusable;
|
||||
|
||||
/**
|
||||
* Test selection handler.
|
||||
*
|
||||
* @var \Drupal\block_content_test\Plugin\EntityReferenceSelection\TestSelection
|
||||
*/
|
||||
protected $selectionHandler;
|
||||
|
||||
/**
|
||||
* Test block expectations.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $expectations;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
$this->installSchema('system', ['sequence']);
|
||||
$this->installSchema('system', ['sequences']);
|
||||
$this->installEntitySchema('user');
|
||||
$this->installEntitySchema('block_content');
|
||||
|
||||
// Create a block content type.
|
||||
$block_content_type = BlockContentType::create([
|
||||
'id' => 'spiffy',
|
||||
'label' => 'Mucho spiffy',
|
||||
'description' => "Provides a block type that increases your site's spiffiness by up to 11%",
|
||||
]);
|
||||
$block_content_type->save();
|
||||
$this->entityTypeManager = $this->container->get('entity_type.manager');
|
||||
|
||||
// And reusable block content entities.
|
||||
$this->blockReusable = BlockContent::create([
|
||||
'info' => 'Reusable Block',
|
||||
'type' => 'spiffy',
|
||||
]);
|
||||
$this->blockReusable->save();
|
||||
$this->blockNonReusable = BlockContent::create([
|
||||
'info' => 'Non-reusable Block',
|
||||
'type' => 'spiffy',
|
||||
'reusable' => FALSE,
|
||||
]);
|
||||
$this->blockNonReusable->save();
|
||||
|
||||
$configuration = [
|
||||
'target_type' => 'block_content',
|
||||
'target_bundles' => ['spiffy' => 'spiffy'],
|
||||
'sort' => ['field' => '_none'],
|
||||
];
|
||||
$this->selectionHandler = new TestSelection($configuration, '', '', $this->container->get('entity.manager'), $this->container->get('module_handler'), \Drupal::currentUser());
|
||||
|
||||
// Setup the 3 expectation cases.
|
||||
$this->expectations = [
|
||||
'both_blocks' => [
|
||||
'spiffy' => [
|
||||
$this->blockReusable->id() => $this->blockReusable->label(),
|
||||
$this->blockNonReusable->id() => $this->blockNonReusable->label(),
|
||||
],
|
||||
],
|
||||
'block_reusable' => ['spiffy' => [$this->blockReusable->id() => $this->blockReusable->label()]],
|
||||
'block_non_reusable' => ['spiffy' => [$this->blockNonReusable->id() => $this->blockNonReusable->label()]],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests to make sure queries without the expected tags are not altered.
|
||||
*
|
||||
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
|
||||
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
|
||||
*/
|
||||
public function testQueriesNotAltered() {
|
||||
// Ensure that queries without all the tags are not altered.
|
||||
$query = $this->entityTypeManager->getStorage('block_content')->getQuery();
|
||||
$this->assertCount(2, $query->execute());
|
||||
|
||||
$query = $this->entityTypeManager->getStorage('block_content')->getQuery();
|
||||
$query->addTag('block_content_access');
|
||||
$this->assertCount(2, $query->execute());
|
||||
|
||||
$query = $this->entityTypeManager->getStorage('block_content')->getQuery();
|
||||
$query->addTag('entity_query_block_content');
|
||||
$this->assertCount(2, $query->execute());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test with no conditions set.
|
||||
*
|
||||
* @throws \Drupal\Core\Entity\EntityStorageException
|
||||
*/
|
||||
public function testNoConditions() {
|
||||
$this->assertEquals(
|
||||
$this->expectations['block_reusable'],
|
||||
$this->selectionHandler->getReferenceableEntities()
|
||||
);
|
||||
|
||||
$this->blockNonReusable->setReusable();
|
||||
$this->blockNonReusable->save();
|
||||
|
||||
// Ensure that the block is now returned as a referenceable entity.
|
||||
$this->assertEquals(
|
||||
$this->expectations['both_blocks'],
|
||||
$this->selectionHandler->getReferenceableEntities()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests setting 'reusable' condition on different levels.
|
||||
*
|
||||
* @dataProvider fieldConditionProvider
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function testFieldConditions($condition_type, $is_reusable) {
|
||||
$this->selectionHandler->setTestMode($condition_type, $is_reusable);
|
||||
$this->assertEquals(
|
||||
$is_reusable ? $this->expectations['block_reusable'] : $this->expectations['block_non_reusable'],
|
||||
$this->selectionHandler->getReferenceableEntities()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides possible fields and condition types.
|
||||
*/
|
||||
public function fieldConditionProvider() {
|
||||
$cases = [];
|
||||
foreach (['base', 'group', 'nested_group'] as $condition_type) {
|
||||
foreach ([TRUE, FALSE] as $reusable) {
|
||||
$cases["$condition_type:" . ($reusable ? 'reusable' : 'non-reusable')] = [
|
||||
$condition_type,
|
||||
$reusable,
|
||||
];
|
||||
}
|
||||
}
|
||||
return $cases;
|
||||
}
|
||||
|
||||
}
|
|
@ -35,7 +35,7 @@ class MigrateBlockContentEntityFormDisplayTest extends MigrateDrupal7TestBase {
|
|||
*
|
||||
* @param string $id
|
||||
* The entity ID.
|
||||
* @param string $component
|
||||
* @param string $component_id
|
||||
* The ID of the form component.
|
||||
*/
|
||||
protected function assertDisplay($id, $component_id) {
|
||||
|
|
|
@ -37,7 +37,7 @@ class MigrateBlockContentTest extends MigrateDrupal6TestBase {
|
|||
* Tests the Drupal 6 custom block to Drupal 8 migration.
|
||||
*/
|
||||
public function testBlockMigration() {
|
||||
/** @var BlockContent $block */
|
||||
/** @var \Drupal\block_content\Entity\BlockContent $block */
|
||||
$block = BlockContent::load(1);
|
||||
$this->assertIdentical('My block 1', $block->label());
|
||||
$this->assertTrue(REQUEST_TIME <= $block->getChangedTime() && $block->getChangedTime() <= time());
|
||||
|
|
|
@ -0,0 +1,73 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Kernel\Migrate\d6;
|
||||
|
||||
use Drupal\block_content\Entity\BlockContent;
|
||||
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
|
||||
|
||||
/**
|
||||
* Tests migration of i18n custom block strings.
|
||||
*
|
||||
* @group migrate_drupal_6
|
||||
*/
|
||||
class MigrateCustomBlockContentTranslationTest extends MigrateDrupal6TestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = [
|
||||
'block_content',
|
||||
'content_translation',
|
||||
'language',
|
||||
// Required for translation migrations.
|
||||
'migrate_drupal_multilingual',
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->installConfig(['block_content']);
|
||||
$this->installEntitySchema('block_content');
|
||||
$this->executeMigrations([
|
||||
'language',
|
||||
'd6_filter_format',
|
||||
'block_content_type',
|
||||
'block_content_body_field',
|
||||
'd6_custom_block',
|
||||
'd6_custom_block_translation',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the Drupal 6 i18n custom block strings to Drupal 8 migration.
|
||||
*/
|
||||
public function testCustomBlockContentTranslation() {
|
||||
/** @var \Drupal\block_content\Entity\BlockContent $block */
|
||||
$block = BlockContent::load(1)->getTranslation('fr');
|
||||
$this->assertSame('fr - Static Block', $block->label());
|
||||
$this->assertGreaterThanOrEqual(REQUEST_TIME, $block->getChangedTime());
|
||||
$this->assertLessThanOrEqual(time(), $block->getChangedTime());
|
||||
$this->assertSame('fr', $block->language()->getId());
|
||||
$this->assertSame('<h3>fr - My first custom block body</h3>', $block->body->value);
|
||||
$this->assertSame('full_html', $block->body->format);
|
||||
|
||||
$block = $block->getTranslation('zu');
|
||||
$this->assertSame('My block 1', $block->label());
|
||||
$this->assertGreaterThanOrEqual(REQUEST_TIME, $block->getChangedTime());
|
||||
$this->assertLessThanOrEqual(time(), $block->getChangedTime());
|
||||
$this->assertSame('zu', $block->language()->getId());
|
||||
$this->assertSame('<h3>zu - My first custom block body</h3>', $block->body->value);
|
||||
$this->assertSame('full_html', $block->body->format);
|
||||
|
||||
$block = BlockContent::load(2)->getTranslation('fr');
|
||||
$this->assertSame('Encore un bloc statique', $block->label());
|
||||
$this->assertGreaterThanOrEqual(REQUEST_TIME, $block->getChangedTime());
|
||||
$this->assertLessThanOrEqual(time(), $block->getChangedTime());
|
||||
$this->assertSame('fr', $block->language()->getId());
|
||||
$this->assertSame('Nom de vocabulaire beaucoup plus long que trente-deux caractères', $block->body->value);
|
||||
$this->assertSame('full_html', $block->body->format);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Kernel\Migrate\d7;
|
||||
|
||||
use Drupal\block_content\Entity\BlockContent;
|
||||
use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
|
||||
|
||||
/**
|
||||
* Tests migration of i18n custom block strings.
|
||||
*
|
||||
* @group migrate_drupal_7
|
||||
*/
|
||||
class MigrateCustomBlockContentTranslationTest extends MigrateDrupal7TestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = [
|
||||
'block_content',
|
||||
'content_translation',
|
||||
'filter',
|
||||
'language',
|
||||
'text',
|
||||
// Required for translation migrations.
|
||||
'migrate_drupal_multilingual',
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->installConfig(['block_content']);
|
||||
$this->installEntitySchema('block_content');
|
||||
$this->executeMigrations([
|
||||
'language',
|
||||
'd7_filter_format',
|
||||
'block_content_type',
|
||||
'block_content_body_field',
|
||||
'd7_custom_block',
|
||||
'd7_custom_block_translation',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the Drupal 7 i18n custom block strings to Drupal 8 migration.
|
||||
*/
|
||||
public function testCustomBlockContentTranslation() {
|
||||
/** @var \Drupal\block_content\Entity\BlockContent $block */
|
||||
$block = BlockContent::load(1)->getTranslation('fr');
|
||||
$this->assertSame('fr - Mildly amusing limerick of the day', $block->label());
|
||||
$this->assertGreaterThanOrEqual($block->getChangedTime(), \Drupal::time()->getRequestTime());
|
||||
$this->assertLessThanOrEqual(time(), $block->getChangedTime());
|
||||
$this->assertSame('fr', $block->language()->getId());
|
||||
$translation = "fr - A fellow jumped off a high wall\r\nAnd had a most terrible fall\r\nHe went back to bed\r\nWith a bump on his head\r\nThat's why you don't jump off a wall";
|
||||
$this->assertSame($translation, $block->body->value);
|
||||
$this->assertSame('filtered_html', $block->body->format);
|
||||
|
||||
$block = $block->getTranslation('is');
|
||||
$this->assertSame('is - Mildly amusing limerick of the day', $block->label());
|
||||
$this->assertGreaterThanOrEqual($block->getChangedTime(), \Drupal::time()->getRequestTime());
|
||||
$this->assertLessThanOrEqual(time(), $block->getChangedTime());
|
||||
$this->assertSame('is', $block->language()->getId());
|
||||
$text = "A fellow jumped off a high wall\r\nAnd had a most terrible fall\r\nHe went back to bed\r\nWith a bump on his head\r\nThat's why you don't jump off a wall";
|
||||
$this->assertSame($text, $block->body->value);
|
||||
$this->assertSame('filtered_html', $block->body->format);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,139 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Kernel\Plugin\migrate\source\d6;
|
||||
|
||||
use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase;
|
||||
|
||||
/**
|
||||
* Tests i18n custom block translations source plugin.
|
||||
*
|
||||
* @covers \Drupal\block_content\Plugin\migrate\source\d6\BoxTranslation
|
||||
*
|
||||
* @group content_translation
|
||||
*/
|
||||
class BoxTranslationTest extends MigrateSqlSourceTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['block_content', 'migrate_drupal'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function providerSource() {
|
||||
$tests = [];
|
||||
|
||||
// The source data.
|
||||
$tests[0]['database']['boxes'] = [
|
||||
[
|
||||
'bid' => 1,
|
||||
'body' => 'box 1 body',
|
||||
'info' => 'box 1 title',
|
||||
'format' => '2',
|
||||
],
|
||||
[
|
||||
'bid' => 2,
|
||||
'body' => 'box 2 body',
|
||||
'info' => 'box 2 title',
|
||||
'format' => '2',
|
||||
],
|
||||
];
|
||||
|
||||
$tests[0]['database']['i18n_strings'] = [
|
||||
[
|
||||
'lid' => 1,
|
||||
'objectid' => 1,
|
||||
'type' => 'block',
|
||||
'property' => 'title',
|
||||
'objectindex' => 1,
|
||||
'format' => 0,
|
||||
],
|
||||
[
|
||||
'lid' => 2,
|
||||
'objectid' => 1,
|
||||
'type' => 'block',
|
||||
'property' => 'body',
|
||||
'objectindex' => 1,
|
||||
'format' => 0,
|
||||
],
|
||||
[
|
||||
'lid' => 3,
|
||||
'objectid' => 2,
|
||||
'type' => 'block',
|
||||
'property' => 'body',
|
||||
'objectindex' => 2,
|
||||
'format' => 2,
|
||||
],
|
||||
];
|
||||
|
||||
$tests[0]['database']['locales_target'] = [
|
||||
[
|
||||
'lid' => 1,
|
||||
'language' => 'fr',
|
||||
'translation' => 'fr - title translation',
|
||||
'plid' => 0,
|
||||
'plural' => 0,
|
||||
'i18n_status' => 0,
|
||||
],
|
||||
[
|
||||
'lid' => 2,
|
||||
'language' => 'fr',
|
||||
'translation' => 'fr - body translation',
|
||||
'plid' => 0,
|
||||
'plural' => 0,
|
||||
'i18n_status' => 0,
|
||||
],
|
||||
[
|
||||
'lid' => 3,
|
||||
'language' => 'zu',
|
||||
'translation' => 'zu - body translation',
|
||||
'plid' => 0,
|
||||
'plural' => 0,
|
||||
'i18n_status' => 0,
|
||||
],
|
||||
];
|
||||
|
||||
$tests[0]['expected_results'] = [
|
||||
[
|
||||
'lid' => '1',
|
||||
'property' => 'title',
|
||||
'language' => 'fr',
|
||||
'translation' => 'fr - title translation',
|
||||
'bid' => '1',
|
||||
'format' => '2',
|
||||
'title_translated' => 'fr - title translation',
|
||||
'body_translated' => 'fr - body translation',
|
||||
'title' => 'box 1 title',
|
||||
'body' => 'box 1 body',
|
||||
],
|
||||
[
|
||||
'lid' => '2',
|
||||
'property' => 'body',
|
||||
'language' => 'fr',
|
||||
'translation' => 'fr - body translation',
|
||||
'bid' => '1',
|
||||
'format' => '2',
|
||||
'title_translated' => 'fr - title translation',
|
||||
'body_translated' => 'fr - body translation',
|
||||
'title' => 'box 1 title',
|
||||
'body' => 'box 1 body',
|
||||
],
|
||||
[
|
||||
'lid' => '3',
|
||||
'property' => 'body',
|
||||
'language' => 'zu',
|
||||
'translation' => 'zu - body translation',
|
||||
'bid' => '2',
|
||||
'format' => '2',
|
||||
'title_translated' => NULL,
|
||||
'body_translated' => 'zu - body translation',
|
||||
'title' => 'box 2 title',
|
||||
'body' => 'box 2 body',
|
||||
],
|
||||
];
|
||||
|
||||
return $tests;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,148 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Kernel\Plugin\migrate\source\d7;
|
||||
|
||||
use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase;
|
||||
|
||||
/**
|
||||
* Tests i18n custom block translations source plugin.
|
||||
*
|
||||
* @covers \Drupal\block_content\Plugin\migrate\source\d7\BlockCustomTranslation
|
||||
*
|
||||
* @group content_translation
|
||||
*/
|
||||
class BlockCustomTranslationTest extends MigrateSqlSourceTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['block_content', 'migrate_drupal'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function providerSource() {
|
||||
$tests = [];
|
||||
|
||||
// The source data.
|
||||
$tests[0]['database']['block_custom'] = [
|
||||
[
|
||||
'bid' => 1,
|
||||
'body' => 'box 1 body',
|
||||
'info' => 'box 1 title',
|
||||
'format' => '2',
|
||||
],
|
||||
[
|
||||
'bid' => 2,
|
||||
'body' => 'box 2 body',
|
||||
'info' => 'box 2 title',
|
||||
'format' => '2',
|
||||
],
|
||||
];
|
||||
|
||||
$tests[0]['database']['i18n_string'] = [
|
||||
[
|
||||
'lid' => 1,
|
||||
'objectid' => 1,
|
||||
'type' => 'block',
|
||||
'property' => 'title',
|
||||
'objectindex' => 1,
|
||||
'format' => 0,
|
||||
],
|
||||
[
|
||||
'lid' => 2,
|
||||
'objectid' => 1,
|
||||
'type' => 'block',
|
||||
'property' => 'body',
|
||||
'objectindex' => 1,
|
||||
'format' => 0,
|
||||
],
|
||||
[
|
||||
'lid' => 3,
|
||||
'objectid' => 2,
|
||||
'type' => 'block',
|
||||
'property' => 'body',
|
||||
'objectindex' => 2,
|
||||
'format' => 2,
|
||||
],
|
||||
];
|
||||
|
||||
$tests[0]['database']['locales_target'] = [
|
||||
[
|
||||
'lid' => 1,
|
||||
'language' => 'fr',
|
||||
'translation' => 'fr - title translation',
|
||||
'plid' => 0,
|
||||
'plural' => 0,
|
||||
'i18n_status' => 0,
|
||||
],
|
||||
[
|
||||
'lid' => 2,
|
||||
'language' => 'fr',
|
||||
'translation' => 'fr - body translation',
|
||||
'plid' => 0,
|
||||
'plural' => 0,
|
||||
'i18n_status' => 0,
|
||||
],
|
||||
[
|
||||
'lid' => 3,
|
||||
'language' => 'zu',
|
||||
'translation' => 'zu - body translation',
|
||||
'plid' => 0,
|
||||
'plural' => 0,
|
||||
'i18n_status' => 0,
|
||||
],
|
||||
];
|
||||
|
||||
$tests[0]['database']['system'] = [
|
||||
[
|
||||
'type' => 'module',
|
||||
'name' => 'system',
|
||||
'schema_version' => '7001',
|
||||
'status' => '1',
|
||||
],
|
||||
];
|
||||
|
||||
$tests[0]['expected_results'] = [
|
||||
[
|
||||
'lid' => '1',
|
||||
'property' => 'title',
|
||||
'language' => 'fr',
|
||||
'translation' => 'fr - title translation',
|
||||
'bid' => '1',
|
||||
'format' => '2',
|
||||
'title_translated' => 'fr - title translation',
|
||||
'body_translated' => 'fr - body translation',
|
||||
'title' => 'box 1 title',
|
||||
'body' => 'box 1 body',
|
||||
],
|
||||
[
|
||||
'lid' => '2',
|
||||
'property' => 'body',
|
||||
'language' => 'fr',
|
||||
'translation' => 'fr - body translation',
|
||||
'bid' => '1',
|
||||
'format' => '2',
|
||||
'title_translated' => 'fr - title translation',
|
||||
'body_translated' => 'fr - body translation',
|
||||
'title' => 'box 1 title',
|
||||
'body' => 'box 1 body',
|
||||
],
|
||||
[
|
||||
'lid' => '3',
|
||||
'property' => 'body',
|
||||
'language' => 'zu',
|
||||
'translation' => 'zu - body translation',
|
||||
'bid' => '2',
|
||||
'format' => '2',
|
||||
'title_translated' => NULL,
|
||||
'body_translated' => 'zu - body translation',
|
||||
'title' => 'box 2 title',
|
||||
'body' => 'box 2 body',
|
||||
],
|
||||
];
|
||||
|
||||
return $tests;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Unit\Access;
|
||||
|
||||
use Drupal\block_content\Access\AccessGroupAnd;
|
||||
use Drupal\Core\Access\AccessResult;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
||||
/**
|
||||
* Tests accessible groups.
|
||||
*
|
||||
* @group block_content
|
||||
*/
|
||||
class AccessGroupAndTest extends UnitTestCase {
|
||||
|
||||
use AccessibleTestingTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->account = $this->prophesize(AccountInterface::class)->reveal();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Drupal\block_content\Access\AccessGroupAnd
|
||||
*/
|
||||
public function testGroups() {
|
||||
$allowedAccessible = $this->createAccessibleDouble(AccessResult::allowed());
|
||||
$forbiddenAccessible = $this->createAccessibleDouble(AccessResult::forbidden());
|
||||
$neutralAccessible = $this->createAccessibleDouble(AccessResult::neutral());
|
||||
|
||||
// Ensure that groups with no dependencies return a neutral access result.
|
||||
$this->assertTrue((new AccessGroupAnd())->access('view', $this->account, TRUE)->isNeutral());
|
||||
|
||||
$andNeutral = new AccessGroupAnd();
|
||||
$andNeutral->addDependency($allowedAccessible)->addDependency($neutralAccessible);
|
||||
$this->assertTrue($andNeutral->access('view', $this->account, TRUE)->isNeutral());
|
||||
|
||||
$andForbidden = $andNeutral;
|
||||
$andForbidden->addDependency($forbiddenAccessible);
|
||||
$this->assertTrue($andForbidden->access('view', $this->account, TRUE)->isForbidden());
|
||||
|
||||
// Ensure that groups added to other groups works.
|
||||
$andGroupsForbidden = new AccessGroupAnd();
|
||||
$andGroupsForbidden->addDependency($andNeutral)->addDependency($andForbidden);
|
||||
$this->assertTrue($andGroupsForbidden->access('view', $this->account, TRUE)->isForbidden());
|
||||
// Ensure you can add a non-group accessible object.
|
||||
$andGroupsForbidden->addDependency($allowedAccessible);
|
||||
$this->assertTrue($andGroupsForbidden->access('view', $this->account, TRUE)->isForbidden());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Unit\Access;
|
||||
|
||||
use Drupal\Core\Access\AccessibleInterface;
|
||||
use Drupal\Core\Access\AccessResultInterface;
|
||||
|
||||
/**
|
||||
* Helper methods testing accessible interfaces.
|
||||
*/
|
||||
trait AccessibleTestingTrait {
|
||||
|
||||
/**
|
||||
* The test account.
|
||||
*
|
||||
* @var \Drupal\Core\Session\AccountInterface
|
||||
*/
|
||||
protected $account;
|
||||
|
||||
/**
|
||||
* Creates AccessibleInterface object from access result object for testing.
|
||||
*
|
||||
* @param \Drupal\Core\Access\AccessResultInterface $accessResult
|
||||
* The accessible result to return.
|
||||
*
|
||||
* @return \Drupal\Core\Access\AccessibleInterface
|
||||
* The AccessibleInterface object.
|
||||
*/
|
||||
private function createAccessibleDouble(AccessResultInterface $accessResult) {
|
||||
$accessible = $this->prophesize(AccessibleInterface::class);
|
||||
$accessible->access('view', $this->account, TRUE)
|
||||
->willReturn($accessResult);
|
||||
return $accessible->reveal();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,159 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Unit\Access;
|
||||
|
||||
use Drupal\block_content\Access\AccessGroupAnd;
|
||||
use Drupal\Core\Access\AccessResult;
|
||||
use Drupal\block_content\Access\RefinableDependentAccessInterface;
|
||||
use Drupal\block_content\Access\RefinableDependentAccessTrait;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\block_content\Access\RefinableDependentAccessTrait
|
||||
*
|
||||
* @group block_content
|
||||
*/
|
||||
class DependentAccessTest extends UnitTestCase {
|
||||
use AccessibleTestingTrait;
|
||||
|
||||
/**
|
||||
* An accessible object that results in forbidden access result.
|
||||
*
|
||||
* @var \Drupal\Core\Access\AccessibleInterface
|
||||
*/
|
||||
protected $forbidden;
|
||||
|
||||
/**
|
||||
* An accessible object that results in neutral access result.
|
||||
*
|
||||
* @var \Drupal\Core\Access\AccessibleInterface
|
||||
*/
|
||||
protected $neutral;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->account = $this->prophesize(AccountInterface::class)->reveal();
|
||||
$this->forbidden = $this->createAccessibleDouble(AccessResult::forbidden('Because I said so'));
|
||||
$this->neutral = $this->createAccessibleDouble(AccessResult::neutral('I have no opinion'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that the previous dependency is replaced when using set.
|
||||
*
|
||||
* @covers ::setAccessDependency
|
||||
*
|
||||
* @dataProvider providerTestSetFirst
|
||||
*/
|
||||
public function testSetAccessDependency($use_set_first) {
|
||||
$testRefinable = new RefinableDependentAccessTraitTestClass();
|
||||
|
||||
if ($use_set_first) {
|
||||
$testRefinable->setAccessDependency($this->forbidden);
|
||||
}
|
||||
else {
|
||||
$testRefinable->addAccessDependency($this->forbidden);
|
||||
}
|
||||
$accessResult = $testRefinable->getAccessDependency()->access('view', $this->account, TRUE);
|
||||
$this->assertTrue($accessResult->isForbidden());
|
||||
$this->assertEquals('Because I said so', $accessResult->getReason());
|
||||
|
||||
// Calling setAccessDependency() replaces the existing dependency.
|
||||
$testRefinable->setAccessDependency($this->neutral);
|
||||
$dependency = $testRefinable->getAccessDependency();
|
||||
$this->assertFalse($dependency instanceof AccessGroupAnd);
|
||||
$accessResult = $dependency->access('view', $this->account, TRUE);
|
||||
$this->assertTrue($accessResult->isNeutral());
|
||||
$this->assertEquals('I have no opinion', $accessResult->getReason());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests merging a new dependency with existing non-group access dependency.
|
||||
*
|
||||
* @dataProvider providerTestSetFirst
|
||||
*/
|
||||
public function testMergeNonGroup($use_set_first) {
|
||||
$testRefinable = new RefinableDependentAccessTraitTestClass();
|
||||
if ($use_set_first) {
|
||||
$testRefinable->setAccessDependency($this->forbidden);
|
||||
}
|
||||
else {
|
||||
$testRefinable->addAccessDependency($this->forbidden);
|
||||
}
|
||||
|
||||
$accessResult = $testRefinable->getAccessDependency()->access('view', $this->account, TRUE);
|
||||
$this->assertTrue($accessResult->isForbidden());
|
||||
$this->assertEquals('Because I said so', $accessResult->getReason());
|
||||
|
||||
$testRefinable->addAccessDependency($this->neutral);
|
||||
/** @var \Drupal\block_content\Access\AccessGroupAnd $dependency */
|
||||
$dependency = $testRefinable->getAccessDependency();
|
||||
// Ensure the new dependency create a new AND group when merged.
|
||||
$this->assertTrue($dependency instanceof AccessGroupAnd);
|
||||
$dependencies = $dependency->getDependencies();
|
||||
$accessResultForbidden = $dependencies[0]->access('view', $this->account, TRUE);
|
||||
$this->assertTrue($accessResultForbidden->isForbidden());
|
||||
$this->assertEquals('Because I said so', $accessResultForbidden->getReason());
|
||||
$accessResultNeutral = $dependencies[1]->access('view', $this->account, TRUE);
|
||||
$this->assertTrue($accessResultNeutral->isNeutral());
|
||||
$this->assertEquals('I have no opinion', $accessResultNeutral->getReason());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests merging a new dependency with an existing access group dependency.
|
||||
*
|
||||
* @dataProvider providerTestSetFirst
|
||||
*/
|
||||
public function testMergeGroup($use_set_first) {
|
||||
$andGroup = new AccessGroupAnd();
|
||||
$andGroup->addDependency($this->forbidden);
|
||||
$testRefinable = new RefinableDependentAccessTraitTestClass();
|
||||
if ($use_set_first) {
|
||||
$testRefinable->setAccessDependency($andGroup);
|
||||
}
|
||||
else {
|
||||
$testRefinable->addAccessDependency($andGroup);
|
||||
}
|
||||
|
||||
$testRefinable->addAccessDependency($this->neutral);
|
||||
/** @var \Drupal\block_content\Access\AccessGroupAnd $dependency */
|
||||
$dependency = $testRefinable->getAccessDependency();
|
||||
|
||||
// Ensure the new dependency is merged with the existing group.
|
||||
$this->assertTrue($dependency instanceof AccessGroupAnd);
|
||||
$dependencies = $dependency->getDependencies();
|
||||
$accessResultForbidden = $dependencies[0]->access('view', $this->account, TRUE);
|
||||
$this->assertTrue($accessResultForbidden->isForbidden());
|
||||
$this->assertEquals('Because I said so', $accessResultForbidden->getReason());
|
||||
$accessResultNeutral = $dependencies[1]->access('view', $this->account, TRUE);
|
||||
$this->assertTrue($accessResultNeutral->isNeutral());
|
||||
$this->assertEquals('I have no opinion', $accessResultNeutral->getReason());
|
||||
}
|
||||
|
||||
/**
|
||||
* Dataprovider for all test methods.
|
||||
*
|
||||
* Provides test cases for calling setAccessDependency() or
|
||||
* mergeAccessDependency() first. A call to either should behave the same on a
|
||||
* new RefinableDependentAccessInterface object.
|
||||
*/
|
||||
public function providerTestSetFirst() {
|
||||
return [
|
||||
[TRUE],
|
||||
[FALSE],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test class that implements RefinableDependentAccessInterface.
|
||||
*/
|
||||
class RefinableDependentAccessTraitTestClass implements RefinableDependentAccessInterface {
|
||||
|
||||
use RefinableDependentAccessTrait;
|
||||
|
||||
}
|
|
@ -19,9 +19,9 @@ class BlockContentLocalTasksTest extends LocalTaskIntegrationTestBase {
|
|||
];
|
||||
parent::setUp();
|
||||
|
||||
$config_factory = $this->getConfigFactoryStub(['system.theme' => [
|
||||
'default' => 'test_c',
|
||||
]]);
|
||||
$config_factory = $this->getConfigFactoryStub([
|
||||
'system.theme' => ['default' => 'test_c'],
|
||||
]);
|
||||
|
||||
$themes = [];
|
||||
$themes['test_a'] = (object) [
|
||||
|
|
Reference in a new issue