contrib modules updates
This commit is contained in:
+3
-3
@@ -6,8 +6,8 @@ package: Testing
|
||||
dependencies:
|
||||
- entity
|
||||
|
||||
# Information added by Drupal.org packaging script on 2018-06-08
|
||||
version: '8.x-1.0-beta4'
|
||||
# Information added by Drupal.org packaging script on 2018-10-11
|
||||
version: '8.x-1.0-rc1'
|
||||
core: '8.x'
|
||||
project: 'entity'
|
||||
datestamp: 1528452194
|
||||
datestamp: 1539272605
|
||||
|
||||
+3
-3
@@ -6,8 +6,8 @@ package: Testing
|
||||
dependencies:
|
||||
- entity
|
||||
|
||||
# Information added by Drupal.org packaging script on 2018-06-08
|
||||
version: '8.x-1.0-beta4'
|
||||
# Information added by Drupal.org packaging script on 2018-10-11
|
||||
version: '8.x-1.0-rc1'
|
||||
core: '8.x'
|
||||
project: 'entity'
|
||||
datestamp: 1528452194
|
||||
datestamp: 1539272605
|
||||
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
config:
|
||||
- field.storage.entity_test_enhanced.assigned
|
||||
id: entity_test_enhanced.first.assigned
|
||||
field_name: assigned
|
||||
entity_type: entity_test_enhanced
|
||||
bundle: first
|
||||
label: Assigned
|
||||
description: ''
|
||||
required: false
|
||||
translatable: false
|
||||
default_value: { }
|
||||
default_value_callback: ''
|
||||
settings: { }
|
||||
field_type: string
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
config:
|
||||
- field.storage.entity_test_enhanced.assigned
|
||||
id: entity_test_enhanced.second.assigned
|
||||
field_name: assigned
|
||||
entity_type: entity_test_enhanced
|
||||
bundle: second
|
||||
label: Assigned
|
||||
description: ''
|
||||
required: false
|
||||
translatable: false
|
||||
default_value: { }
|
||||
default_value_callback: ''
|
||||
settings: { }
|
||||
field_type: string
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
module:
|
||||
- entity_module_test
|
||||
id: entity_test_enhanced.assigned
|
||||
field_name: assigned
|
||||
entity_type: entity_test_enhanced
|
||||
type: string
|
||||
settings:
|
||||
max_length: 255
|
||||
is_ascii: false
|
||||
case_sensitive: true
|
||||
module: core
|
||||
locked: false
|
||||
cardinality: 1
|
||||
translatable: true
|
||||
indexes: { }
|
||||
persist_with_no_fields: false
|
||||
custom_storage: false
|
||||
+170
@@ -0,0 +1,170 @@
|
||||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
module:
|
||||
- entity_module_test
|
||||
id: entity_test_enhanced
|
||||
label: 'Enhanced entities'
|
||||
module: views
|
||||
description: ''
|
||||
tag: ''
|
||||
base_table: entity_test_enhanced_field_data
|
||||
base_field: id
|
||||
core: 8.x
|
||||
display:
|
||||
default:
|
||||
display_plugin: default
|
||||
id: default
|
||||
display_title: Master
|
||||
position: 0
|
||||
display_options:
|
||||
access:
|
||||
type: none
|
||||
options: { }
|
||||
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: 10
|
||||
offset: 0
|
||||
id: 0
|
||||
total_pages: null
|
||||
expose:
|
||||
items_per_page: false
|
||||
items_per_page_label: 'Items per page'
|
||||
items_per_page_options: '5, 10, 25, 50'
|
||||
items_per_page_options_all: false
|
||||
items_per_page_options_all_label: '- All -'
|
||||
offset: false
|
||||
offset_label: Offset
|
||||
tags:
|
||||
previous: ‹‹
|
||||
next: ››
|
||||
style:
|
||||
type: default
|
||||
options:
|
||||
grouping: { }
|
||||
row_class: ''
|
||||
default_row_class: true
|
||||
uses_fields: false
|
||||
row:
|
||||
type: fields
|
||||
options:
|
||||
inline: { }
|
||||
separator: ''
|
||||
hide_empty: false
|
||||
default_field_elements: true
|
||||
fields:
|
||||
name:
|
||||
table: entity_test_enhanced_field_data
|
||||
field: name
|
||||
id: name
|
||||
entity_type: null
|
||||
entity_field: name
|
||||
plugin_id: field
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
label: ''
|
||||
exclude: false
|
||||
alter:
|
||||
alter_text: false
|
||||
text: ''
|
||||
make_link: false
|
||||
path: ''
|
||||
absolute: false
|
||||
external: false
|
||||
replace_spaces: false
|
||||
path_case: none
|
||||
trim_whitespace: false
|
||||
alt: ''
|
||||
rel: ''
|
||||
link_class: ''
|
||||
prefix: ''
|
||||
suffix: ''
|
||||
target: ''
|
||||
nl2br: false
|
||||
max_length: 0
|
||||
word_boundary: true
|
||||
ellipsis: true
|
||||
more_link: false
|
||||
more_link_text: ''
|
||||
more_link_path: ''
|
||||
strip_tags: false
|
||||
trim: false
|
||||
preserve_tags: ''
|
||||
html: false
|
||||
element_type: ''
|
||||
element_class: ''
|
||||
element_label_type: ''
|
||||
element_label_class: ''
|
||||
element_label_colon: true
|
||||
element_wrapper_type: ''
|
||||
element_wrapper_class: ''
|
||||
element_default_classes: true
|
||||
empty: ''
|
||||
hide_empty: false
|
||||
empty_zero: false
|
||||
hide_alter_empty: true
|
||||
click_sort_column: value
|
||||
type: string
|
||||
settings: { }
|
||||
group_column: value
|
||||
group_columns: { }
|
||||
group_rows: true
|
||||
delta_limit: 0
|
||||
delta_offset: 0
|
||||
delta_reversed: false
|
||||
delta_first_last: false
|
||||
multi_type: separator
|
||||
separator: ', '
|
||||
field_api_classes: false
|
||||
filters: { }
|
||||
sorts:
|
||||
id:
|
||||
id: id
|
||||
table: entity_test_enhanced_field_data
|
||||
field: id
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
order: ASC
|
||||
exposed: false
|
||||
expose:
|
||||
label: ''
|
||||
entity_type: entity_test_enhanced
|
||||
entity_field: id
|
||||
plugin_id: standard
|
||||
header: { }
|
||||
footer: { }
|
||||
empty: { }
|
||||
relationships: { }
|
||||
arguments: { }
|
||||
display_extenders: { }
|
||||
cache_metadata:
|
||||
max-age: -1
|
||||
contexts:
|
||||
- 'languages:language_content'
|
||||
- 'languages:language_interface'
|
||||
- url.query_args
|
||||
tags: { }
|
||||
+170
@@ -0,0 +1,170 @@
|
||||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
module:
|
||||
- entity_module_test
|
||||
id: entity_test_enhanced_revisions
|
||||
label: 'Enhanced entities (Revisions)'
|
||||
module: views
|
||||
description: ''
|
||||
tag: ''
|
||||
base_table: entity_test_enhanced_field_revision
|
||||
base_field: nid
|
||||
core: 8.x
|
||||
display:
|
||||
default:
|
||||
display_plugin: default
|
||||
id: default
|
||||
display_title: Master
|
||||
position: 0
|
||||
display_options:
|
||||
access:
|
||||
type: none
|
||||
options: { }
|
||||
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: 10
|
||||
offset: 0
|
||||
id: 0
|
||||
total_pages: null
|
||||
expose:
|
||||
items_per_page: false
|
||||
items_per_page_label: 'Items per page'
|
||||
items_per_page_options: '5, 10, 25, 50'
|
||||
items_per_page_options_all: false
|
||||
items_per_page_options_all_label: '- All -'
|
||||
offset: false
|
||||
offset_label: Offset
|
||||
tags:
|
||||
previous: ‹‹
|
||||
next: ››
|
||||
style:
|
||||
type: default
|
||||
options:
|
||||
grouping: { }
|
||||
row_class: ''
|
||||
default_row_class: true
|
||||
uses_fields: false
|
||||
row:
|
||||
type: fields
|
||||
options:
|
||||
inline: { }
|
||||
separator: ''
|
||||
hide_empty: false
|
||||
default_field_elements: true
|
||||
fields:
|
||||
name:
|
||||
table: entity_test_enhanced_field_revision
|
||||
field: name
|
||||
id: name
|
||||
entity_type: null
|
||||
entity_field: name
|
||||
plugin_id: field
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
label: ''
|
||||
exclude: false
|
||||
alter:
|
||||
alter_text: false
|
||||
text: ''
|
||||
make_link: false
|
||||
path: ''
|
||||
absolute: false
|
||||
external: false
|
||||
replace_spaces: false
|
||||
path_case: none
|
||||
trim_whitespace: false
|
||||
alt: ''
|
||||
rel: ''
|
||||
link_class: ''
|
||||
prefix: ''
|
||||
suffix: ''
|
||||
target: ''
|
||||
nl2br: false
|
||||
max_length: 0
|
||||
word_boundary: true
|
||||
ellipsis: true
|
||||
more_link: false
|
||||
more_link_text: ''
|
||||
more_link_path: ''
|
||||
strip_tags: false
|
||||
trim: false
|
||||
preserve_tags: ''
|
||||
html: false
|
||||
element_type: ''
|
||||
element_class: ''
|
||||
element_label_type: ''
|
||||
element_label_class: ''
|
||||
element_label_colon: true
|
||||
element_wrapper_type: ''
|
||||
element_wrapper_class: ''
|
||||
element_default_classes: true
|
||||
empty: ''
|
||||
hide_empty: false
|
||||
empty_zero: false
|
||||
hide_alter_empty: true
|
||||
click_sort_column: value
|
||||
type: string
|
||||
settings: { }
|
||||
group_column: value
|
||||
group_columns: { }
|
||||
group_rows: true
|
||||
delta_limit: 0
|
||||
delta_offset: 0
|
||||
delta_reversed: false
|
||||
delta_first_last: false
|
||||
multi_type: separator
|
||||
separator: ', '
|
||||
field_api_classes: false
|
||||
filters: { }
|
||||
sorts:
|
||||
vid:
|
||||
id: vid
|
||||
table: entity_test_enhanced_field_revision
|
||||
field: vid
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
order: ASC
|
||||
exposed: false
|
||||
expose:
|
||||
label: ''
|
||||
entity_type: entity_test_enhanced
|
||||
entity_field: vid
|
||||
plugin_id: standard
|
||||
header: { }
|
||||
footer: { }
|
||||
empty: { }
|
||||
relationships: { }
|
||||
arguments: { }
|
||||
display_extenders: { }
|
||||
cache_metadata:
|
||||
max-age: -1
|
||||
contexts:
|
||||
- 'languages:language_content'
|
||||
- 'languages:language_interface'
|
||||
- url.query_args
|
||||
tags: { }
|
||||
+170
@@ -0,0 +1,170 @@
|
||||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
module:
|
||||
- entity_module_test
|
||||
id: entity_test_enhanced_with_owner
|
||||
label: 'Enhanced entities with an owner'
|
||||
module: views
|
||||
description: ''
|
||||
tag: ''
|
||||
base_table: entity_test_enhanced_with_owner_field_data
|
||||
base_field: id
|
||||
core: 8.x
|
||||
display:
|
||||
default:
|
||||
display_plugin: default
|
||||
id: default
|
||||
display_title: Master
|
||||
position: 0
|
||||
display_options:
|
||||
access:
|
||||
type: none
|
||||
options: { }
|
||||
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: 10
|
||||
offset: 0
|
||||
id: 0
|
||||
total_pages: null
|
||||
expose:
|
||||
items_per_page: false
|
||||
items_per_page_label: 'Items per page'
|
||||
items_per_page_options: '5, 10, 25, 50'
|
||||
items_per_page_options_all: false
|
||||
items_per_page_options_all_label: '- All -'
|
||||
offset: false
|
||||
offset_label: Offset
|
||||
tags:
|
||||
previous: ‹‹
|
||||
next: ››
|
||||
style:
|
||||
type: default
|
||||
options:
|
||||
grouping: { }
|
||||
row_class: ''
|
||||
default_row_class: true
|
||||
uses_fields: false
|
||||
row:
|
||||
type: fields
|
||||
options:
|
||||
inline: { }
|
||||
separator: ''
|
||||
hide_empty: false
|
||||
default_field_elements: true
|
||||
fields:
|
||||
name:
|
||||
table: entity_test_enhanced_with_owner_field_data
|
||||
field: name
|
||||
id: name
|
||||
entity_type: null
|
||||
entity_field: name
|
||||
plugin_id: field
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
label: ''
|
||||
exclude: false
|
||||
alter:
|
||||
alter_text: false
|
||||
text: ''
|
||||
make_link: false
|
||||
path: ''
|
||||
absolute: false
|
||||
external: false
|
||||
replace_spaces: false
|
||||
path_case: none
|
||||
trim_whitespace: false
|
||||
alt: ''
|
||||
rel: ''
|
||||
link_class: ''
|
||||
prefix: ''
|
||||
suffix: ''
|
||||
target: ''
|
||||
nl2br: false
|
||||
max_length: 0
|
||||
word_boundary: true
|
||||
ellipsis: true
|
||||
more_link: false
|
||||
more_link_text: ''
|
||||
more_link_path: ''
|
||||
strip_tags: false
|
||||
trim: false
|
||||
preserve_tags: ''
|
||||
html: false
|
||||
element_type: ''
|
||||
element_class: ''
|
||||
element_label_type: ''
|
||||
element_label_class: ''
|
||||
element_label_colon: true
|
||||
element_wrapper_type: ''
|
||||
element_wrapper_class: ''
|
||||
element_default_classes: true
|
||||
empty: ''
|
||||
hide_empty: false
|
||||
empty_zero: false
|
||||
hide_alter_empty: true
|
||||
click_sort_column: value
|
||||
type: string
|
||||
settings: { }
|
||||
group_column: value
|
||||
group_columns: { }
|
||||
group_rows: true
|
||||
delta_limit: 0
|
||||
delta_offset: 0
|
||||
delta_reversed: false
|
||||
delta_first_last: false
|
||||
multi_type: separator
|
||||
separator: ', '
|
||||
field_api_classes: false
|
||||
filters: { }
|
||||
sorts:
|
||||
id:
|
||||
id: id
|
||||
table: entity_test_enhanced_with_owner_field_data
|
||||
field: id
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
order: ASC
|
||||
exposed: false
|
||||
expose:
|
||||
label: ''
|
||||
entity_type: entity_test_enhanced_with_owner
|
||||
entity_field: id
|
||||
plugin_id: standard
|
||||
header: { }
|
||||
footer: { }
|
||||
empty: { }
|
||||
relationships: { }
|
||||
arguments: { }
|
||||
display_extenders: { }
|
||||
cache_metadata:
|
||||
max-age: -1
|
||||
contexts:
|
||||
- 'languages:language_content'
|
||||
- 'languages:language_interface'
|
||||
- url.query_args
|
||||
tags: { }
|
||||
+170
@@ -0,0 +1,170 @@
|
||||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
module:
|
||||
- entity_module_test
|
||||
id: entity_test_enhanced_with_owner_revisions
|
||||
label: 'Enhanced entities with an owner (Revisions)'
|
||||
module: views
|
||||
description: ''
|
||||
tag: ''
|
||||
base_table: entity_test_enhanced_with_owner_field_revision
|
||||
base_field: nid
|
||||
core: 8.x
|
||||
display:
|
||||
default:
|
||||
display_plugin: default
|
||||
id: default
|
||||
display_title: Master
|
||||
position: 0
|
||||
display_options:
|
||||
access:
|
||||
type: none
|
||||
options: { }
|
||||
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: 10
|
||||
offset: 0
|
||||
id: 0
|
||||
total_pages: null
|
||||
expose:
|
||||
items_per_page: false
|
||||
items_per_page_label: 'Items per page'
|
||||
items_per_page_options: '5, 10, 25, 50'
|
||||
items_per_page_options_all: false
|
||||
items_per_page_options_all_label: '- All -'
|
||||
offset: false
|
||||
offset_label: Offset
|
||||
tags:
|
||||
previous: ‹‹
|
||||
next: ››
|
||||
style:
|
||||
type: default
|
||||
options:
|
||||
grouping: { }
|
||||
row_class: ''
|
||||
default_row_class: true
|
||||
uses_fields: false
|
||||
row:
|
||||
type: fields
|
||||
options:
|
||||
inline: { }
|
||||
separator: ''
|
||||
hide_empty: false
|
||||
default_field_elements: true
|
||||
fields:
|
||||
name:
|
||||
table: entity_test_enhanced_with_owner_field_revision
|
||||
field: name
|
||||
id: name
|
||||
entity_type: null
|
||||
entity_field: name
|
||||
plugin_id: field
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
label: ''
|
||||
exclude: false
|
||||
alter:
|
||||
alter_text: false
|
||||
text: ''
|
||||
make_link: false
|
||||
path: ''
|
||||
absolute: false
|
||||
external: false
|
||||
replace_spaces: false
|
||||
path_case: none
|
||||
trim_whitespace: false
|
||||
alt: ''
|
||||
rel: ''
|
||||
link_class: ''
|
||||
prefix: ''
|
||||
suffix: ''
|
||||
target: ''
|
||||
nl2br: false
|
||||
max_length: 0
|
||||
word_boundary: true
|
||||
ellipsis: true
|
||||
more_link: false
|
||||
more_link_text: ''
|
||||
more_link_path: ''
|
||||
strip_tags: false
|
||||
trim: false
|
||||
preserve_tags: ''
|
||||
html: false
|
||||
element_type: ''
|
||||
element_class: ''
|
||||
element_label_type: ''
|
||||
element_label_class: ''
|
||||
element_label_colon: true
|
||||
element_wrapper_type: ''
|
||||
element_wrapper_class: ''
|
||||
element_default_classes: true
|
||||
empty: ''
|
||||
hide_empty: false
|
||||
empty_zero: false
|
||||
hide_alter_empty: true
|
||||
click_sort_column: value
|
||||
type: string
|
||||
settings: { }
|
||||
group_column: value
|
||||
group_columns: { }
|
||||
group_rows: true
|
||||
delta_limit: 0
|
||||
delta_offset: 0
|
||||
delta_reversed: false
|
||||
delta_first_last: false
|
||||
multi_type: separator
|
||||
separator: ', '
|
||||
field_api_classes: false
|
||||
filters: { }
|
||||
sorts:
|
||||
vid:
|
||||
id: vid
|
||||
table: entity_test_enhanced_with_owner_field_revision
|
||||
field: vid
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
order: ASC
|
||||
exposed: false
|
||||
expose:
|
||||
label: ''
|
||||
entity_type: entity_test_enhanced_with_owner
|
||||
entity_field: vid
|
||||
plugin_id: standard
|
||||
header: { }
|
||||
footer: { }
|
||||
empty: { }
|
||||
relationships: { }
|
||||
arguments: { }
|
||||
display_extenders: { }
|
||||
cache_metadata:
|
||||
max-age: -1
|
||||
contexts:
|
||||
- 'languages:language_content'
|
||||
- 'languages:language_interface'
|
||||
- url.query_args
|
||||
tags: { }
|
||||
-16
@@ -1,16 +0,0 @@
|
||||
entity_module_test.entity_test_enhanced_bundle.*:
|
||||
type: config_entity
|
||||
label: 'Entity test with enhancements - Bundle'
|
||||
mapping:
|
||||
id:
|
||||
type: string
|
||||
label: 'Type'
|
||||
label:
|
||||
type: label
|
||||
label: 'Label'
|
||||
description:
|
||||
type: text
|
||||
label: 'Description'
|
||||
new_revision:
|
||||
type: boolean
|
||||
label: 'New revision'
|
||||
+5
-3
@@ -2,9 +2,11 @@ name: Entity test
|
||||
type: module
|
||||
package: Testing
|
||||
# core: 8.x
|
||||
dependencies:
|
||||
- field
|
||||
|
||||
# Information added by Drupal.org packaging script on 2018-06-08
|
||||
version: '8.x-1.0-beta4'
|
||||
# Information added by Drupal.org packaging script on 2018-10-11
|
||||
version: '8.x-1.0-rc1'
|
||||
core: '8.x'
|
||||
project: 'entity'
|
||||
datestamp: 1528452194
|
||||
datestamp: 1539272605
|
||||
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Implements hook_entity_bundle_info().
|
||||
*/
|
||||
function entity_module_test_entity_bundle_info() {
|
||||
$bundles['entity_test_enhanced']['default']['label'] = t('Default');
|
||||
$bundles['entity_test_enhanced']['first']['label'] = t('First');
|
||||
$bundles['entity_test_enhanced']['second']['label'] = t('Second');
|
||||
$bundles['entity_test_enhanced_with_owner']['default']['label'] = t('Default');
|
||||
$bundles['entity_test_enhanced_with_owner']['first']['label'] = t('First');
|
||||
$bundles['entity_test_enhanced_with_owner']['second']['label'] = t('Second');
|
||||
|
||||
return $bundles;
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
services:
|
||||
entity_module_test.query_access_subscriber:
|
||||
class: Drupal\entity_module_test\EventSubscriber\QueryAccessSubscriber
|
||||
tags:
|
||||
- { name: event_subscriber }
|
||||
+11
-3
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace Drupal\entity_module_test\Entity;
|
||||
|
||||
use Drupal\Core\Entity\EntityPublishedInterface;
|
||||
use Drupal\Core\Entity\EntityPublishedTrait;
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\Core\Field\BaseFieldDefinition;
|
||||
use Drupal\entity\Revision\RevisionableContentEntityBase;
|
||||
@@ -21,7 +23,8 @@ use Drupal\entity\Revision\RevisionableContentEntityBase;
|
||||
* ),
|
||||
* handlers = {
|
||||
* "storage" = "\Drupal\Core\Entity\Sql\SqlContentEntityStorage",
|
||||
* "access" = "\Drupal\Core\Entity\EntityAccessControlHandler",
|
||||
* "access" = "\Drupal\entity\EntityAccessControlHandler",
|
||||
* "query_access" = "\Drupal\entity\QueryAccess\QueryAccessHandler",
|
||||
* "permission_provider" = "\Drupal\entity\EntityPermissionProvider",
|
||||
* "form" = {
|
||||
* "add" = "\Drupal\entity\Form\RevisionableContentEntityForm",
|
||||
@@ -37,6 +40,7 @@ use Drupal\entity\Revision\RevisionableContentEntityBase;
|
||||
* "collection" = "\Drupal\entity\Menu\EntityCollectionLocalActionProvider",
|
||||
* },
|
||||
* "list_builder" = "\Drupal\Core\Entity\EntityListBuilder",
|
||||
* "views_data" = "\Drupal\views\EntityViewsData",
|
||||
* },
|
||||
* base_table = "entity_test_enhanced",
|
||||
* data_table = "entity_test_enhanced_field_data",
|
||||
@@ -51,6 +55,8 @@ use Drupal\entity\Revision\RevisionableContentEntityBase;
|
||||
* "bundle" = "type",
|
||||
* "revision" = "vid",
|
||||
* "langcode" = "langcode",
|
||||
* "label" = "name",
|
||||
* "published" = "status",
|
||||
* },
|
||||
* links = {
|
||||
* "add-page" = "/entity_test_enhanced/add",
|
||||
@@ -63,16 +69,18 @@ use Drupal\entity\Revision\RevisionableContentEntityBase;
|
||||
* "revision-revert-form" = "/entity_test_enhanced/{entity_test_enhanced}/revisions/{entity_test_enhanced_revision}/revert",
|
||||
* "version-history" = "/entity_test_enhanced/{entity_test_enhanced}/revisions",
|
||||
* },
|
||||
* bundle_entity_type = "entity_test_enhanced_bundle",
|
||||
* )
|
||||
*/
|
||||
class EnhancedEntity extends RevisionableContentEntityBase {
|
||||
class EnhancedEntity extends RevisionableContentEntityBase implements EntityPublishedInterface {
|
||||
|
||||
use EntityPublishedTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
|
||||
$fields = parent::baseFieldDefinitions($entity_type);
|
||||
$fields += static::publishedBaseFieldDefinitions($entity_type);
|
||||
|
||||
$fields['name'] = BaseFieldDefinition::create('string')
|
||||
->setLabel('Name')
|
||||
|
||||
-84
@@ -1,84 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\entity_module_test\Entity;
|
||||
|
||||
use Drupal\Core\Config\Entity\ConfigEntityBundleBase;
|
||||
use Drupal\Core\Entity\EntityDescriptionInterface;
|
||||
use Drupal\Core\Entity\RevisionableEntityBundleInterface;
|
||||
|
||||
/**
|
||||
* Provides bundles for the test entity.
|
||||
*
|
||||
* @ConfigEntityType(
|
||||
* id = "entity_test_enhanced_bundle",
|
||||
* label = @Translation("Entity test with enhancments - Bundle"),
|
||||
* admin_permission = "administer entity_test_enhanced",
|
||||
* config_prefix = "entity_test_enhanced_bundle",
|
||||
* bundle_of = "entity_test_enhanced",
|
||||
* handlers = {
|
||||
* "access" = "\Drupal\entity\BundleEntityAccessControlHandler",
|
||||
* },
|
||||
* entity_keys = {
|
||||
* "id" = "id",
|
||||
* "label" = "label"
|
||||
* },
|
||||
* config_export = {
|
||||
* "id",
|
||||
* "label",
|
||||
* "description"
|
||||
* },
|
||||
* )
|
||||
*/
|
||||
class EnhancedEntityBundle extends ConfigEntityBundleBase implements EntityDescriptionInterface, RevisionableEntityBundleInterface {
|
||||
|
||||
/**
|
||||
* The bundle ID.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* The bundle label.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $label;
|
||||
|
||||
/**
|
||||
* The bundle description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description;
|
||||
|
||||
/**
|
||||
* Should new entities of this bundle have a new revision by default.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $new_revision = FALSE;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDescription() {
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setDescription($description) {
|
||||
$this->description = $description;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function shouldCreateNewRevision() {
|
||||
return $this->new_revision;
|
||||
}
|
||||
|
||||
}
|
||||
+145
@@ -0,0 +1,145 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\entity_module_test\Entity;
|
||||
|
||||
use Drupal\Core\Entity\EntityPublishedInterface;
|
||||
use Drupal\Core\Entity\EntityPublishedTrait;
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\Core\Field\BaseFieldDefinition;
|
||||
use Drupal\entity\Revision\RevisionableContentEntityBase;
|
||||
use Drupal\user\EntityOwnerInterface;
|
||||
use Drupal\user\UserInterface;
|
||||
|
||||
/**
|
||||
* Provides a test entity which uses all the capabilities of entity module.
|
||||
*
|
||||
* @ContentEntityType(
|
||||
* id = "entity_test_enhanced_with_owner",
|
||||
* label = @Translation("Enhanced entity with owner"),
|
||||
* label_collection = @Translation("Enhanced entities with owner"),
|
||||
* label_singular = @Translation("enhanced entity with owner"),
|
||||
* label_plural = @Translation("enhanced entities with owner"),
|
||||
* label_count = @PluralTranslation(
|
||||
* singular = "@count enhanced entity with owner",
|
||||
* plural = "@count enhanced entities with owner",
|
||||
* ),
|
||||
* handlers = {
|
||||
* "storage" = "\Drupal\Core\Entity\Sql\SqlContentEntityStorage",
|
||||
* "access" = "\Drupal\entity\UncacheableEntityAccessControlHandler",
|
||||
* "query_access" = "\Drupal\entity\QueryAccess\UncacheableQueryAccessHandler",
|
||||
* "permission_provider" = "\Drupal\entity\UncacheableEntityPermissionProvider",
|
||||
* "form" = {
|
||||
* "add" = "\Drupal\entity\Form\RevisionableContentEntityForm",
|
||||
* "edit" = "\Drupal\entity\Form\RevisionableContentEntityForm",
|
||||
* "delete" = "\Drupal\Core\Entity\EntityDeleteForm",
|
||||
* },
|
||||
* "route_provider" = {
|
||||
* "html" = "\Drupal\entity\Routing\DefaultHtmlRouteProvider",
|
||||
* "revision" = "\Drupal\entity\Routing\RevisionRouteProvider",
|
||||
* "delete-multiple" = "\Drupal\entity\Routing\DeleteMultipleRouteProvider",
|
||||
* },
|
||||
* "local_action_provider" = {
|
||||
* "collection" = "\Drupal\entity\Menu\EntityCollectionLocalActionProvider",
|
||||
* },
|
||||
* "list_builder" = "\Drupal\Core\Entity\EntityListBuilder",
|
||||
* "views_data" = "\Drupal\views\EntityViewsData",
|
||||
* },
|
||||
* base_table = "entity_test_enhanced_with_owner",
|
||||
* data_table = "entity_test_enhanced_with_owner_field_data",
|
||||
* revision_table = "entity_test_enhanced_with_owner_revision",
|
||||
* revision_data_table = "entity_test_enhanced_with_owner_field_revision",
|
||||
* translatable = TRUE,
|
||||
* revisionable = TRUE,
|
||||
* admin_permission = "administer entity_test_enhanced_with_owner",
|
||||
* permission_granularity = "bundle",
|
||||
* entity_keys = {
|
||||
* "id" = "id",
|
||||
* "bundle" = "type",
|
||||
* "revision" = "vid",
|
||||
* "langcode" = "langcode",
|
||||
* "label" = "name",
|
||||
* "uid" = "user_id",
|
||||
* "published" = "status",
|
||||
* },
|
||||
* links = {
|
||||
* "add-page" = "/entity_test_enhanced_with_owner/add",
|
||||
* "add-form" = "/entity_test_enhanced_with_owner/add/{type}",
|
||||
* "edit-form" = "/entity_test_enhanced_with_owner/{entity_test_enhanced_with_owner}/edit",
|
||||
* "canonical" = "/entity_test_enhanced_with_owner/{entity_test_enhanced_with_owner}",
|
||||
* "collection" = "/entity_test_enhanced_with_owner",
|
||||
* },
|
||||
* )
|
||||
*/
|
||||
class EnhancedEntityWithOwner extends RevisionableContentEntityBase implements EntityOwnerInterface, EntityPublishedInterface {
|
||||
|
||||
use EntityPublishedTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getOwner() {
|
||||
return $this->get('user_id')->entity;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getOwnerId() {
|
||||
return $this->get('user_id')->target_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setOwnerId($uid) {
|
||||
$this->set('user_id', $uid);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setOwner(UserInterface $account) {
|
||||
$this->set('user_id', $account->id());
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
|
||||
$fields = parent::baseFieldDefinitions($entity_type);
|
||||
$fields += static::publishedBaseFieldDefinitions($entity_type);
|
||||
|
||||
$fields['name'] = BaseFieldDefinition::create('string')
|
||||
->setLabel('Name')
|
||||
->setRevisionable(TRUE)
|
||||
->setDisplayOptions('view', [
|
||||
'label' => 'hidden',
|
||||
'type' => 'string',
|
||||
'weight' => -5,
|
||||
]);
|
||||
|
||||
$fields['user_id'] = BaseFieldDefinition::create('entity_reference')
|
||||
->setLabel(t('User ID'))
|
||||
->setDescription(t('The ID of the associated user.'))
|
||||
->setSetting('target_type', 'user')
|
||||
->setSetting('handler', 'default')
|
||||
// Default EntityTest entities to have the root user as the owner, to
|
||||
// simplify testing.
|
||||
->setDefaultValue([0 => ['target_id' => 1]])
|
||||
->setTranslatable(TRUE)
|
||||
->setDisplayOptions('form', [
|
||||
'type' => 'entity_reference_autocomplete',
|
||||
'weight' => -1,
|
||||
'settings' => [
|
||||
'match_operator' => 'CONTAINS',
|
||||
'size' => '60',
|
||||
'placeholder' => '',
|
||||
],
|
||||
]);
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
}
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\entity_module_test\EventSubscriber;
|
||||
|
||||
use Drupal\entity\QueryAccess\ConditionGroup;
|
||||
use Drupal\entity\QueryAccess\QueryAccessEvent;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
|
||||
class QueryAccessSubscriber implements EventSubscriberInterface {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getSubscribedEvents() {
|
||||
return [
|
||||
'entity.query_access.entity_test_enhanced' => 'onQueryAccess',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Modifies the access conditions based on the current user.
|
||||
*
|
||||
* This is just a convenient example for testing. A real subscriber would
|
||||
* ignore the account and extend the conditions to cover additional factors,
|
||||
* such as a custom entity field.
|
||||
*
|
||||
* @param \Drupal\entity\QueryAccess\QueryAccessEvent $event
|
||||
* The event.
|
||||
*/
|
||||
public function onQueryAccess(QueryAccessEvent $event) {
|
||||
$conditions = $event->getConditions();
|
||||
$email = $event->getAccount()->getEmail();
|
||||
|
||||
if ($email == 'user1@example.com') {
|
||||
// This user should not have access to any entities.
|
||||
$conditions->alwaysFalse();
|
||||
}
|
||||
elseif ($email == 'user2@example.com') {
|
||||
// This user should have access to entities with the IDs 1, 2, and 3.
|
||||
// The query access handler might have already set ->alwaysFalse()
|
||||
// due to the user not having any other access, so we make sure
|
||||
// to undo it with $conditions->alwaysFalse(TRUE).
|
||||
$conditions->alwaysFalse(FALSE);
|
||||
$conditions->addCondition('id', ['1', '2', '3']);
|
||||
}
|
||||
elseif ($email == 'user3@example.com') {
|
||||
// This user should only have access to entities assigned to "marketing",
|
||||
// or unassigned entities.
|
||||
$conditions->alwaysFalse(FALSE);
|
||||
$conditions->addCondition((new ConditionGroup('OR'))
|
||||
->addCondition('assigned', NULL, 'IS NULL')
|
||||
// Confirm that explicitly specifying the property name works.
|
||||
->addCondition('assigned.value', 'marketing')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-6
@@ -3,7 +3,6 @@
|
||||
namespace Drupal\Tests\entity\Functional;
|
||||
|
||||
use Drupal\entity_module_test\Entity\EnhancedEntity;
|
||||
use Drupal\entity_module_test\Entity\EnhancedEntityBundle;
|
||||
use Drupal\Tests\block\Traits\BlockCreationTrait;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
@@ -33,11 +32,6 @@ class CollectionRouteAccessTest extends BrowserTestBase {
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
EnhancedEntityBundle::create([
|
||||
'id' => 'default',
|
||||
'label' => 'Default',
|
||||
])->save();
|
||||
|
||||
$this->placeBlock('local_tasks_block');
|
||||
$this->placeBlock('system_breadcrumb_block');
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
namespace Drupal\Tests\entity\Functional;
|
||||
|
||||
use Drupal\entity_module_test\Entity\EnhancedEntity;
|
||||
use Drupal\entity_module_test\Entity\EnhancedEntityBundle;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
@@ -35,10 +34,6 @@ class DeleteMultipleFormTest extends BrowserTestBase {
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
EnhancedEntityBundle::create([
|
||||
'id' => 'default',
|
||||
'label' => 'Default',
|
||||
])->save();
|
||||
$this->account = $this->drupalCreateUser(['administer entity_test_enhanced']);
|
||||
$this->drupalLogin($this->account);
|
||||
}
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@ class EntityLocalActionTest extends BrowserTestBase {
|
||||
*/
|
||||
public function testCollectionLocalAction() {
|
||||
$this->drupalGet('/entity_test_enhanced');
|
||||
$this->assertSession()->linkByHrefExists('/entity_test_enhanced/add');
|
||||
$this->assertSession()->linkByHrefExists('/entity_test_enhanced/add?destination=/entity_test_enhanced');
|
||||
$this->assertSession()->linkExists('Add enhanced entity');
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
namespace Drupal\Tests\entity\Functional;
|
||||
|
||||
use Drupal\entity_module_test\Entity\EnhancedEntity;
|
||||
use Drupal\entity_module_test\Entity\EnhancedEntityBundle;
|
||||
use Drupal\Tests\block\Traits\BlockCreationTrait;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
@@ -40,11 +39,6 @@ class RevisionRouteAccessTest extends BrowserTestBase {
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
EnhancedEntityBundle::create([
|
||||
'id' => 'default',
|
||||
'label' => 'Default',
|
||||
])->save();
|
||||
|
||||
$this->placeBlock('local_tasks_block');
|
||||
$this->placeBlock('system_breadcrumb_block');
|
||||
|
||||
|
||||
-56
@@ -1,56 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\entity\Kernel;
|
||||
|
||||
use Drupal\entity_module_test\Entity\EnhancedEntityBundle;
|
||||
use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
|
||||
|
||||
/**
|
||||
* Tests the bundle entity access control handler.
|
||||
*
|
||||
* @group entity
|
||||
*/
|
||||
class BundleEntityAccessControlHandlerTest extends EntityKernelTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = [
|
||||
'entity',
|
||||
'entity_module_test',
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->installEntitySchema('entity_test_enhanced');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the "view label" access checking.
|
||||
*/
|
||||
public function testAccess() {
|
||||
$bundle = EnhancedEntityBundle::create([
|
||||
'id' => 'default',
|
||||
'label' => 'Default',
|
||||
]);
|
||||
$bundle->save();
|
||||
|
||||
// The default user has no permissions related to entity_test_enhanced.
|
||||
$this->assertFalse($bundle->access('view label'));
|
||||
|
||||
$permissions = [
|
||||
'administer entity_test_enhanced',
|
||||
'view entity_test_enhanced',
|
||||
'view default entity_test_enhanced',
|
||||
];
|
||||
foreach ($permissions as $permission) {
|
||||
$account = $this->createUser([], [$permission]);
|
||||
$this->assertTrue($bundle->access('view label', $account));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,7 +4,6 @@ namespace Drupal\Tests\entity\Kernel;
|
||||
|
||||
use Drupal\entity\Plugin\Action\DeleteAction;
|
||||
use Drupal\entity_module_test\Entity\EnhancedEntity;
|
||||
use Drupal\entity_module_test\Entity\EnhancedEntityBundle;
|
||||
use Drupal\system\Entity\Action;
|
||||
use Drupal\user\Entity\User;
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
@@ -40,12 +39,6 @@ class DeleteActionTest extends KernelTestBase {
|
||||
$this->installEntitySchema('entity_test_enhanced');
|
||||
$this->installSchema('system', ['key_value_expire', 'sequences']);
|
||||
|
||||
$bundle = EnhancedEntityBundle::create([
|
||||
'id' => 'default',
|
||||
'label' => 'Default',
|
||||
]);
|
||||
$bundle->save();
|
||||
|
||||
$this->user = User::create([
|
||||
'name' => 'username',
|
||||
'status' => 1,
|
||||
|
||||
+106
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\entity\Kernel\QueryAccess;
|
||||
|
||||
use Drupal\entity\QueryAccess\Condition;
|
||||
use Drupal\entity\QueryAccess\ConditionGroup;
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
|
||||
/**
|
||||
* Tests the condition group class.
|
||||
*
|
||||
* ConditionGroup uses \Drupal\Core\Cache\Cache internally, which makes it
|
||||
* impossible to use a unit test (due to Cache accessing the global container).
|
||||
*
|
||||
* @coversDefaultClass \Drupal\entity\QueryAccess\ConditionGroup
|
||||
* @group entity
|
||||
*/
|
||||
class ConditionGroupTest extends KernelTestBase {
|
||||
|
||||
/**
|
||||
* ::covers getConjunction
|
||||
* ::covers addCondition
|
||||
* ::covers getConditions
|
||||
* ::covers count.
|
||||
*/
|
||||
public function testGetters() {
|
||||
$condition_group = new ConditionGroup();
|
||||
$condition_group->addCondition('uid', '2');
|
||||
$this->assertEquals('AND', $condition_group->getConjunction());
|
||||
$expected_conditions = [
|
||||
new Condition('uid', '2'),
|
||||
];
|
||||
$this->assertEquals($expected_conditions, $condition_group->getConditions());
|
||||
$this->assertEquals(1, $condition_group->count());
|
||||
$this->assertEquals("uid = '2'", $condition_group->__toString());
|
||||
|
||||
$condition_group = new ConditionGroup('OR');
|
||||
$condition_group->addCondition('type', ['article', 'page']);
|
||||
$condition_group->addCondition('status', '1', '<>');
|
||||
$this->assertEquals('OR', $condition_group->getConjunction());
|
||||
$expected_conditions = [
|
||||
new Condition('type', ['article', 'page']),
|
||||
new Condition('status', '1', '<>'),
|
||||
];
|
||||
$expected_lines = [
|
||||
"(",
|
||||
" type IN ['article', 'page']",
|
||||
" OR",
|
||||
" status <> '1'",
|
||||
")",
|
||||
];
|
||||
$this->assertEquals($expected_conditions, $condition_group->getConditions());
|
||||
$this->assertEquals(2, $condition_group->count());
|
||||
$this->assertEquals(implode("\n", $expected_lines), $condition_group->__toString());
|
||||
|
||||
// Nested condition group with a single condition.
|
||||
$condition_group = new ConditionGroup();
|
||||
$condition_group->addCondition('type', ['article', 'page']);
|
||||
$condition_group->addCondition((new ConditionGroup('AND'))
|
||||
->addCondition('status', '1')
|
||||
);
|
||||
$expected_conditions = [
|
||||
new Condition('type', ['article', 'page']),
|
||||
new Condition('status', '1'),
|
||||
];
|
||||
$expected_lines = [
|
||||
"(",
|
||||
" type IN ['article', 'page']",
|
||||
" AND",
|
||||
" status = '1'",
|
||||
")",
|
||||
];
|
||||
$this->assertEquals($expected_conditions, $condition_group->getConditions());
|
||||
$this->assertEquals('AND', $condition_group->getConjunction());
|
||||
$this->assertEquals(2, $condition_group->count());
|
||||
$this->assertEquals(implode("\n", $expected_lines), $condition_group->__toString());
|
||||
|
||||
// Nested condition group with multiple conditions.
|
||||
$condition_group = new ConditionGroup();
|
||||
$condition_group->addCondition('type', ['article', 'page']);
|
||||
$nested_condition_group = new ConditionGroup('OR');
|
||||
$nested_condition_group->addCondition('uid', '1');
|
||||
$nested_condition_group->addCondition('status', '1');
|
||||
$condition_group->addCondition($nested_condition_group);
|
||||
$expected_conditions = [
|
||||
new Condition('type', ['article', 'page']),
|
||||
$nested_condition_group,
|
||||
];
|
||||
$expected_lines = [
|
||||
"(",
|
||||
" type IN ['article', 'page']",
|
||||
" AND",
|
||||
" (",
|
||||
" uid = '1'",
|
||||
" OR",
|
||||
" status = '1'",
|
||||
" )",
|
||||
")",
|
||||
];
|
||||
$this->assertEquals($expected_conditions, $condition_group->getConditions());
|
||||
$this->assertEquals('AND', $condition_group->getConjunction());
|
||||
$this->assertEquals(2, $condition_group->count());
|
||||
$this->assertEquals(implode("\n", $expected_lines), $condition_group->__toString());
|
||||
}
|
||||
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\entity\Kernel\QueryAccess;
|
||||
|
||||
use Drupal\entity\QueryAccess\QueryAccessHandler;
|
||||
use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
|
||||
|
||||
/**
|
||||
* Tests the query access event.
|
||||
*
|
||||
* @group entity
|
||||
*/
|
||||
class QueryAccessEventTest extends EntityKernelTestBase {
|
||||
|
||||
/**
|
||||
* The query access handler.
|
||||
*
|
||||
* @var \Drupal\entity\QueryAccess\QueryAccessHandler
|
||||
*/
|
||||
protected $handler;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = [
|
||||
'entity',
|
||||
'entity_module_test',
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->installEntitySchema('entity_test_enhanced');
|
||||
|
||||
// Create uid: 1 here so that it's skipped in test cases.
|
||||
$admin_user = $this->createUser();
|
||||
|
||||
$entity_type_manager = $this->container->get('entity_type.manager');
|
||||
$entity_type = $entity_type_manager->getDefinition('entity_test_enhanced');
|
||||
$this->handler = QueryAccessHandler::createInstance($this->container, $entity_type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the event.
|
||||
*/
|
||||
public function testEvent() {
|
||||
// By default, the first user should have full access, and the second
|
||||
// user should have no access. The QueryAccessSubscriber flips that.
|
||||
$first_user = $this->createUser(['mail' => 'user1@example.com'], ['administer entity_test_enhanced']);
|
||||
$second_user = $this->createUser(['mail' => 'user2@example.com']);
|
||||
|
||||
$conditions = $this->handler->getConditions('view', $first_user);
|
||||
$this->assertTrue($conditions->isAlwaysFalse());
|
||||
|
||||
$conditions = $this->handler->getConditions('view', $second_user);
|
||||
$this->assertFalse($conditions->isAlwaysFalse());
|
||||
}
|
||||
|
||||
}
|
||||
+137
@@ -0,0 +1,137 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\entity\Kernel\QueryAccess;
|
||||
|
||||
use Drupal\entity\QueryAccess\Condition;
|
||||
use Drupal\entity\QueryAccess\QueryAccessHandler;
|
||||
use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
|
||||
|
||||
/**
|
||||
* Tests the query access handler.
|
||||
*
|
||||
* Uses the "entity_test_enhanced" entity type, which has no owner.
|
||||
* UncacheableQueryAccessHandlerTest uses the "entity_test_enhanced_with_owner"
|
||||
* entity type, which has an owner. This ensures both sides (owner and
|
||||
* no owner) are covered.
|
||||
*
|
||||
* @coversDefaultClass \Drupal\entity\QueryAccess\QueryAccessHandler
|
||||
* @group entity
|
||||
*/
|
||||
class QueryAccessHandlerTest extends EntityKernelTestBase {
|
||||
|
||||
/**
|
||||
* The query access handler.
|
||||
*
|
||||
* @var \Drupal\entity\QueryAccess\QueryAccessHandler
|
||||
*/
|
||||
protected $handler;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = [
|
||||
'entity',
|
||||
'entity_module_test',
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->installEntitySchema('entity_test_enhanced');
|
||||
|
||||
// Create uid: 1 here so that it's skipped in test cases.
|
||||
$admin_user = $this->createUser();
|
||||
|
||||
$entity_type_manager = $this->container->get('entity_type.manager');
|
||||
$entity_type = $entity_type_manager->getDefinition('entity_test_enhanced');
|
||||
$this->handler = QueryAccessHandler::createInstance($this->container, $entity_type);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getConditions
|
||||
*/
|
||||
public function testNoAccess() {
|
||||
foreach (['view', 'update', 'delete'] as $operation) {
|
||||
$user = $this->createUser([], ['access content']);
|
||||
$conditions = $this->handler->getConditions($operation, $user);
|
||||
$this->assertEquals(0, $conditions->count());
|
||||
$this->assertEquals(['user.permissions'], $conditions->getCacheContexts());
|
||||
$this->assertTrue($conditions->isAlwaysFalse());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getConditions
|
||||
*/
|
||||
public function testAdmin() {
|
||||
foreach (['view', 'update', 'delete'] as $operation) {
|
||||
$user = $this->createUser([], ['administer entity_test_enhanced']);
|
||||
$conditions = $this->handler->getConditions($operation, $user);
|
||||
$this->assertEquals(0, $conditions->count());
|
||||
$this->assertEquals(['user.permissions'], $conditions->getCacheContexts());
|
||||
$this->assertFalse($conditions->isAlwaysFalse());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getConditions
|
||||
*/
|
||||
public function testView() {
|
||||
// Entity type permission.
|
||||
$user = $this->createUser([], ['view entity_test_enhanced']);
|
||||
$conditions = $this->handler->getConditions('view', $user);
|
||||
$expected_conditions = [
|
||||
new Condition('status', '1'),
|
||||
];
|
||||
$this->assertEquals(1, $conditions->count());
|
||||
$this->assertEquals($expected_conditions, $conditions->getConditions());
|
||||
$this->assertEquals(['user.permissions'], $conditions->getCacheContexts());
|
||||
$this->assertFalse($conditions->isAlwaysFalse());
|
||||
|
||||
// Bundle permission.
|
||||
$user = $this->createUser([], ['view first entity_test_enhanced']);
|
||||
$conditions = $this->handler->getConditions('view', $user);
|
||||
$expected_conditions = [
|
||||
new Condition('type', ['first']),
|
||||
new Condition('status', '1'),
|
||||
];
|
||||
$this->assertEquals('AND', $conditions->getConjunction());
|
||||
$this->assertEquals(2, $conditions->count());
|
||||
$this->assertEquals($expected_conditions, $conditions->getConditions());
|
||||
$this->assertEquals(['user.permissions'], $conditions->getCacheContexts());
|
||||
$this->assertFalse($conditions->isAlwaysFalse());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getConditions
|
||||
*/
|
||||
public function testUpdateDelete() {
|
||||
foreach (['update', 'delete'] as $operation) {
|
||||
// Entity type permission.
|
||||
$user = $this->createUser([], ["$operation entity_test_enhanced"]);
|
||||
$conditions = $this->handler->getConditions($operation, $user);
|
||||
$this->assertEquals(0, $conditions->count());
|
||||
$this->assertEquals(['user.permissions'], $conditions->getCacheContexts());
|
||||
$this->assertFalse($conditions->isAlwaysFalse());
|
||||
|
||||
// Bundle permission.
|
||||
$user = $this->createUser([], [
|
||||
"$operation first entity_test_enhanced",
|
||||
"$operation second entity_test_enhanced",
|
||||
]);
|
||||
$conditions = $this->handler->getConditions($operation, $user);
|
||||
$expected_conditions = [
|
||||
new Condition('type', ['first', 'second']),
|
||||
];
|
||||
$this->assertEquals('OR', $conditions->getConjunction());
|
||||
$this->assertEquals(1, $conditions->count());
|
||||
$this->assertEquals($expected_conditions, $conditions->getConditions());
|
||||
$this->assertEquals(['user.permissions'], $conditions->getCacheContexts());
|
||||
$this->assertFalse($conditions->isAlwaysFalse());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+343
@@ -0,0 +1,343 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\entity\Kernel\QueryAccess;
|
||||
|
||||
use Drupal\entity_module_test\Entity\EnhancedEntity;
|
||||
use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
|
||||
use Drupal\views\Tests\ViewResultAssertionTrait;
|
||||
use Drupal\views\Views;
|
||||
|
||||
/**
|
||||
* Test query access filtering for EntityQuery and Views.
|
||||
*
|
||||
* @group entity
|
||||
*
|
||||
* @see \Drupal\entity\QueryAccess\QueryAccessHandler
|
||||
* @see \Drupal\entity\QueryAccess\EntityQueryAlter
|
||||
* @see \Drupal\entity\QueryAccess\ViewsQueryAlter
|
||||
*/
|
||||
class QueryAccessTest extends EntityKernelTestBase {
|
||||
|
||||
use ViewResultAssertionTrait;
|
||||
|
||||
/**
|
||||
* The test entities.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\ContentEntityInterface[]
|
||||
*/
|
||||
protected $entities;
|
||||
|
||||
/**
|
||||
* The entity_test_enhanced storage.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityStorageInterface
|
||||
*/
|
||||
protected $storage;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = [
|
||||
'entity',
|
||||
'entity_module_test',
|
||||
'user',
|
||||
'views',
|
||||
'system',
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->installEntitySchema('entity_test_enhanced');
|
||||
$this->installConfig(['entity_module_test']);
|
||||
|
||||
// Create uid: 1 here so that it's skipped in test cases.
|
||||
$admin_user = $this->createUser();
|
||||
|
||||
$first_entity = EnhancedEntity::create([
|
||||
'type' => 'first',
|
||||
'label' => 'First',
|
||||
'status' => 1,
|
||||
]);
|
||||
$first_entity->save();
|
||||
|
||||
$first_entity->set('name', 'First!');
|
||||
$first_entity->set('status', 0);
|
||||
$first_entity->setNewRevision(TRUE);
|
||||
$first_entity->save();
|
||||
|
||||
$second_entity = EnhancedEntity::create([
|
||||
'type' => 'first',
|
||||
'label' => 'Second',
|
||||
'status' => 0,
|
||||
]);
|
||||
$second_entity->save();
|
||||
|
||||
$second_entity->set('name', 'Second!');
|
||||
$second_entity->set('status', 1);
|
||||
$second_entity->setNewRevision(TRUE);
|
||||
$second_entity->save();
|
||||
|
||||
$third_entity = EnhancedEntity::create([
|
||||
'type' => 'second',
|
||||
'label' => 'Third',
|
||||
'status' => 1,
|
||||
]);
|
||||
$third_entity->save();
|
||||
|
||||
$third_entity->set('name', 'Third!');
|
||||
$third_entity->setNewRevision(TRUE);
|
||||
$third_entity->save();
|
||||
|
||||
$this->entities = [$first_entity, $second_entity, $third_entity];
|
||||
$this->storage = \Drupal::entityTypeManager()->getStorage('entity_test_enhanced');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests EntityQuery filtering.
|
||||
*/
|
||||
public function testEntityQuery() {
|
||||
// Admin permission, full access.
|
||||
$admin_user = $this->createUser([], ['administer entity_test_enhanced']);
|
||||
\Drupal::currentUser()->setAccount($admin_user);
|
||||
|
||||
$result = $this->storage->getQuery()->sort('id')->execute();
|
||||
$this->assertEquals([
|
||||
$this->entities[0]->id(),
|
||||
$this->entities[1]->id(),
|
||||
$this->entities[2]->id(),
|
||||
], array_values($result));
|
||||
|
||||
// No view permissions, no access.
|
||||
$user = $this->createUser([], ['access content']);
|
||||
\Drupal::currentUser()->setAccount($user);
|
||||
|
||||
$result = $this->storage->getQuery()->execute();
|
||||
$this->assertEmpty($result);
|
||||
|
||||
// View (published-only).
|
||||
$user = $this->createUser([], ['view entity_test_enhanced']);
|
||||
\Drupal::currentUser()->setAccount($user);
|
||||
|
||||
$result = $this->storage->getQuery()->sort('id')->execute();
|
||||
$this->assertEquals([
|
||||
$this->entities[1]->id(),
|
||||
$this->entities[2]->id(),
|
||||
], array_values($result));
|
||||
|
||||
// View $bundle (published-only).
|
||||
$user = $this->createUser([], ['view first entity_test_enhanced']);
|
||||
\Drupal::currentUser()->setAccount($user);
|
||||
|
||||
$result = $this->storage->getQuery()->sort('id')->execute();
|
||||
$this->assertEquals([
|
||||
$this->entities[1]->id(),
|
||||
], array_values($result));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests EntityQuery filtering when all revisions are queried.
|
||||
*/
|
||||
public function testEntityQueryWithRevisions() {
|
||||
// Admin permission, full access.
|
||||
$admin_user = $this->createUser([], ['administer entity_test_enhanced']);
|
||||
\Drupal::currentUser()->setAccount($admin_user);
|
||||
|
||||
$result = $this->storage->getQuery()->allRevisions()->sort('id')->execute();
|
||||
$this->assertEquals([
|
||||
'1' => $this->entities[0]->id(),
|
||||
'2' => $this->entities[0]->id(),
|
||||
'3' => $this->entities[1]->id(),
|
||||
'4' => $this->entities[1]->id(),
|
||||
'5' => $this->entities[2]->id(),
|
||||
'6' => $this->entities[2]->id(),
|
||||
], $result);
|
||||
|
||||
// No view permissions, no access.
|
||||
$user = $this->createUser([], ['access content']);
|
||||
\Drupal::currentUser()->setAccount($user);
|
||||
|
||||
$result = $this->storage->getQuery()->execute();
|
||||
$this->assertEmpty($result);
|
||||
|
||||
// View (published-only).
|
||||
$user = $this->createUser([], ['view entity_test_enhanced']);
|
||||
\Drupal::currentUser()->setAccount($user);
|
||||
|
||||
$result = $this->storage->getQuery()->allRevisions()->sort('id')->execute();
|
||||
$this->assertEquals([
|
||||
'1' => $this->entities[0]->id(),
|
||||
'4' => $this->entities[1]->id(),
|
||||
'5' => $this->entities[2]->id(),
|
||||
'6' => $this->entities[2]->id(),
|
||||
], $result);
|
||||
|
||||
// View $bundle (published-only).
|
||||
$user = $this->createUser([], ['view first entity_test_enhanced']);
|
||||
\Drupal::currentUser()->setAccount($user);
|
||||
|
||||
$result = $this->storage->getQuery()->allRevisions()->sort('id')->execute();
|
||||
$this->assertEquals([
|
||||
'1' => $this->entities[0]->id(),
|
||||
'4' => $this->entities[1]->id(),
|
||||
], $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests Views filtering.
|
||||
*/
|
||||
public function testViews() {
|
||||
// Admin permission, full access.
|
||||
$admin_user = $this->createUser([], ['administer entity_test_enhanced']);
|
||||
\Drupal::currentUser()->setAccount($admin_user);
|
||||
|
||||
$view = Views::getView('entity_test_enhanced');
|
||||
$view->execute();
|
||||
$this->assertIdenticalResultset($view, [
|
||||
['id' => $this->entities[0]->id()],
|
||||
['id' => $this->entities[1]->id()],
|
||||
['id' => $this->entities[2]->id()],
|
||||
], ['id' => 'id']);
|
||||
|
||||
// No view permissions, no access.
|
||||
$user = $this->createUser([], ['access content']);
|
||||
\Drupal::currentUser()->setAccount($user);
|
||||
|
||||
$view = Views::getView('entity_test_enhanced');
|
||||
$view->execute();
|
||||
$this->assertIdenticalResultset($view, []);
|
||||
|
||||
// View (published-only).
|
||||
$user = $this->createUser([], ['view entity_test_enhanced']);
|
||||
\Drupal::currentUser()->setAccount($user);
|
||||
|
||||
$view = Views::getView('entity_test_enhanced');
|
||||
$view->execute();
|
||||
$this->assertIdenticalResultset($view, [
|
||||
['id' => $this->entities[1]->id()],
|
||||
['id' => $this->entities[2]->id()],
|
||||
], ['id' => 'id']);
|
||||
|
||||
// View $bundle (published-only).
|
||||
$user = $this->createUser([], ['view first entity_test_enhanced']);
|
||||
\Drupal::currentUser()->setAccount($user);
|
||||
|
||||
$view = Views::getView('entity_test_enhanced');
|
||||
$view->execute();
|
||||
$this->assertIdenticalResultset($view, [
|
||||
['id' => $this->entities[1]->id()],
|
||||
], ['id' => 'id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests Views filtering when all revisions are queried.
|
||||
*/
|
||||
public function testViewsWithRevisions() {
|
||||
// Admin permission, full access.
|
||||
$admin_user = $this->createUser([], ['administer entity_test_enhanced']);
|
||||
\Drupal::currentUser()->setAccount($admin_user);
|
||||
|
||||
$view = Views::getView('entity_test_enhanced_revisions');
|
||||
$view->execute();
|
||||
$this->assertIdenticalResultset($view, [
|
||||
['vid' => '1', 'id' => $this->entities[0]->id()],
|
||||
['vid' => '2', 'id' => $this->entities[0]->id()],
|
||||
['vid' => '3', 'id' => $this->entities[1]->id()],
|
||||
['vid' => '4', 'id' => $this->entities[1]->id()],
|
||||
['vid' => '5', 'id' => $this->entities[2]->id()],
|
||||
['vid' => '6', 'id' => $this->entities[2]->id()],
|
||||
], ['vid' => 'vid']);
|
||||
|
||||
// No view permissions, no access.
|
||||
$user = $this->createUser([], ['access content']);
|
||||
\Drupal::currentUser()->setAccount($user);
|
||||
|
||||
$view = Views::getView('entity_test_enhanced');
|
||||
$view->execute();
|
||||
$this->assertIdenticalResultset($view, []);
|
||||
|
||||
// View (published-only).
|
||||
$user = $this->createUser([], ['view entity_test_enhanced']);
|
||||
\Drupal::currentUser()->setAccount($user);
|
||||
|
||||
$view = Views::getView('entity_test_enhanced_revisions');
|
||||
$view->execute();
|
||||
$this->assertIdenticalResultset($view, [
|
||||
['vid' => '1', 'id' => $this->entities[0]->id()],
|
||||
['vid' => '4', 'id' => $this->entities[1]->id()],
|
||||
['vid' => '5', 'id' => $this->entities[2]->id()],
|
||||
['vid' => '6', 'id' => $this->entities[2]->id()],
|
||||
], ['vid' => 'vid']);
|
||||
|
||||
// View $bundle (published-only).
|
||||
$user = $this->createUser([], ['view first entity_test_enhanced']);
|
||||
\Drupal::currentUser()->setAccount($user);
|
||||
|
||||
$view = Views::getView('entity_test_enhanced_revisions');
|
||||
$view->execute();
|
||||
$this->assertIdenticalResultset($view, [
|
||||
['vid' => '1', 'id' => $this->entities[0]->id()],
|
||||
['vid' => '4', 'id' => $this->entities[1]->id()],
|
||||
], ['vid' => 'vid']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests filtering based on a configurable field.
|
||||
*
|
||||
* QueryAccessSubscriber adds a condition that ensures that the field value
|
||||
* is either empty or matches "marketing".
|
||||
*
|
||||
* @see \Drupal\entity_module_test\EventSubscriber\QueryAccessSubscriber
|
||||
*/
|
||||
public function testConfigurableField() {
|
||||
$this->entities[0]->set('assigned', 'marketing');
|
||||
$this->entities[0]->save();
|
||||
// The field is case sensitive, so the third entity should be ignored.
|
||||
$this->entities[2]->set('assigned', 'MarKeTing');
|
||||
$this->entities[2]->save();
|
||||
$user = $this->createUser([
|
||||
'mail' => 'user3@example.com',
|
||||
], ['access content']);
|
||||
\Drupal::currentUser()->setAccount($user);
|
||||
|
||||
// EntityQuery.
|
||||
$result = $this->storage->getQuery()->sort('id')->execute();
|
||||
$this->assertEquals([
|
||||
$this->entities[0]->id(),
|
||||
$this->entities[1]->id(),
|
||||
], array_values($result));
|
||||
|
||||
// EntityQuery with revisions.
|
||||
$result = $this->storage->getQuery()->allRevisions()->sort('id')->execute();
|
||||
$this->assertEquals([
|
||||
'1' => $this->entities[0]->id(),
|
||||
'2' => $this->entities[0]->id(),
|
||||
'3' => $this->entities[1]->id(),
|
||||
'4' => $this->entities[1]->id(),
|
||||
'5' => $this->entities[2]->id(),
|
||||
], $result);
|
||||
|
||||
// View.
|
||||
$view = Views::getView('entity_test_enhanced');
|
||||
$view->execute();
|
||||
$this->assertIdenticalResultset($view, [
|
||||
['id' => $this->entities[0]->id()],
|
||||
['id' => $this->entities[1]->id()],
|
||||
], ['id' => 'id']);
|
||||
|
||||
// View with revisions.
|
||||
$view = Views::getView('entity_test_enhanced_revisions');
|
||||
$view->execute();
|
||||
$this->assertIdenticalResultset($view, [
|
||||
['vid' => '1', 'id' => $this->entities[0]->id()],
|
||||
['vid' => '2', 'id' => $this->entities[0]->id()],
|
||||
['vid' => '3', 'id' => $this->entities[1]->id()],
|
||||
['vid' => '4', 'id' => $this->entities[1]->id()],
|
||||
['vid' => '5', 'id' => $this->entities[2]->id()],
|
||||
], ['vid' => 'vid']);
|
||||
}
|
||||
|
||||
}
|
||||
+203
@@ -0,0 +1,203 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\entity\Kernel\QueryAccess;
|
||||
|
||||
use Drupal\entity\QueryAccess\Condition;
|
||||
use Drupal\entity\QueryAccess\ConditionGroup;
|
||||
use Drupal\entity\QueryAccess\UncacheableQueryAccessHandler;
|
||||
use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
|
||||
|
||||
/**
|
||||
* Tests the uncacheable query access handler.
|
||||
*
|
||||
* Uses the "entity_test_enhanced_with_owner" entity type, which has an owner.
|
||||
* QueryAccessHandlerTest uses the "entity_test_enhanced" entity type, which
|
||||
* has no owner. This ensures both sides (owner and no owner) are covered.
|
||||
*
|
||||
* @coversDefaultClass \Drupal\entity\QueryAccess\UncacheableQueryAccessHandler
|
||||
* @group entity
|
||||
*/
|
||||
class UncacheableQueryAccessHandlerTest extends EntityKernelTestBase {
|
||||
|
||||
/**
|
||||
* The query access handler.
|
||||
*
|
||||
* @var \Drupal\entity\QueryAccess\UncacheableQueryAccessHandler
|
||||
*/
|
||||
protected $handler;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = [
|
||||
'entity',
|
||||
'entity_module_test',
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->installEntitySchema('entity_test_enhanced_with_owner');
|
||||
|
||||
// Create uid: 1 here so that it's skipped in test cases.
|
||||
$admin_user = $this->createUser();
|
||||
|
||||
$entity_type_manager = $this->container->get('entity_type.manager');
|
||||
$entity_type = $entity_type_manager->getDefinition('entity_test_enhanced_with_owner');
|
||||
$this->handler = UncacheableQueryAccessHandler::createInstance($this->container, $entity_type);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getConditions
|
||||
*/
|
||||
public function testNoAccess() {
|
||||
foreach (['view', 'update', 'delete'] as $operation) {
|
||||
$user = $this->createUser([], ['access content']);
|
||||
$conditions = $this->handler->getConditions($operation, $user);
|
||||
$this->assertEquals(0, $conditions->count());
|
||||
$this->assertEquals(['user.permissions'], $conditions->getCacheContexts());
|
||||
$this->assertTrue($conditions->isAlwaysFalse());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getConditions
|
||||
*/
|
||||
public function testAdmin() {
|
||||
foreach (['view', 'update', 'delete'] as $operation) {
|
||||
$user = $this->createUser([], ['administer entity_test_enhanced_with_owner']);
|
||||
$conditions = $this->handler->getConditions($operation, $user);
|
||||
$this->assertEquals(0, $conditions->count());
|
||||
$this->assertEquals(['user.permissions'], $conditions->getCacheContexts());
|
||||
$this->assertFalse($conditions->isAlwaysFalse());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getConditions
|
||||
*/
|
||||
public function testView() {
|
||||
// Any permission.
|
||||
$user = $this->createUser([], ['view any entity_test_enhanced_with_owner']);
|
||||
$conditions = $this->handler->getConditions('view', $user);
|
||||
$expected_conditions = [
|
||||
new Condition('status', '1'),
|
||||
];
|
||||
$this->assertEquals(1, $conditions->count());
|
||||
$this->assertEquals($expected_conditions, $conditions->getConditions());
|
||||
$this->assertEquals(['user.permissions'], $conditions->getCacheContexts());
|
||||
$this->assertFalse($conditions->isAlwaysFalse());
|
||||
|
||||
// Own permission.
|
||||
$user = $this->createUser([], ['view own entity_test_enhanced_with_owner']);
|
||||
$conditions = $this->handler->getConditions('view', $user);
|
||||
$expected_conditions = [
|
||||
new Condition('user_id', $user->id()),
|
||||
new Condition('status', '1'),
|
||||
];
|
||||
$this->assertEquals('AND', $conditions->getConjunction());
|
||||
$this->assertEquals(2, $conditions->count());
|
||||
$this->assertEquals($expected_conditions, $conditions->getConditions());
|
||||
$this->assertEquals(['user', 'user.permissions'], $conditions->getCacheContexts());
|
||||
$this->assertFalse($conditions->isAlwaysFalse());
|
||||
|
||||
// Any permission for the first bundle, own permission for the second.
|
||||
$user = $this->createUser([], [
|
||||
'view any first entity_test_enhanced_with_owner',
|
||||
'view own second entity_test_enhanced_with_owner',
|
||||
]);
|
||||
$conditions = $this->handler->getConditions('view', $user);
|
||||
$expected_conditions = [
|
||||
(new ConditionGroup('OR'))
|
||||
->addCacheContexts(['user', 'user.permissions'])
|
||||
->addCondition('type', ['first'])
|
||||
->addCondition((new ConditionGroup('AND'))
|
||||
->addCondition('user_id', $user->id())
|
||||
->addCondition('type', ['second'])
|
||||
),
|
||||
new Condition('status', '1'),
|
||||
];
|
||||
$this->assertEquals('AND', $conditions->getConjunction());
|
||||
$this->assertEquals(2, $conditions->count());
|
||||
$this->assertEquals($expected_conditions, $conditions->getConditions());
|
||||
$this->assertEquals(['user', 'user.permissions'], $conditions->getCacheContexts());
|
||||
$this->assertFalse($conditions->isAlwaysFalse());
|
||||
|
||||
// View own unpublished permission.
|
||||
$user = $this->createUser([], ['view own unpublished entity_test_enhanced_with_owner']);
|
||||
$conditions = $this->handler->buildConditions('view', $user);
|
||||
$expected_conditions = [
|
||||
new Condition('user_id', $user->id()),
|
||||
new Condition('status', '0'),
|
||||
];
|
||||
$this->assertEquals(2, $conditions->count());
|
||||
$this->assertEquals($expected_conditions, $conditions->getConditions());
|
||||
$this->assertEquals(['user'], $conditions->getCacheContexts());
|
||||
$this->assertFalse($conditions->isAlwaysFalse());
|
||||
|
||||
// Both view any and view own unpublished permissions.
|
||||
$user = $this->createUser([], [
|
||||
'view any entity_test_enhanced_with_owner',
|
||||
'view own unpublished entity_test_enhanced_with_owner',
|
||||
]);
|
||||
$conditions = $this->handler->buildConditions('view', $user);
|
||||
$expected_conditions = [
|
||||
new Condition('status', '1'),
|
||||
(new ConditionGroup('AND'))
|
||||
->addCondition('user_id', $user->id())
|
||||
->addCondition('status', '0')
|
||||
->addCacheContexts(['user']),
|
||||
];
|
||||
$this->assertEquals(2, $conditions->count());
|
||||
$this->assertEquals($expected_conditions, $conditions->getConditions());
|
||||
$this->assertEquals(['user', 'user.permissions'], $conditions->getCacheContexts());
|
||||
$this->assertFalse($conditions->isAlwaysFalse());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getConditions
|
||||
*/
|
||||
public function testUpdateDelete() {
|
||||
foreach (['update', 'delete'] as $operation) {
|
||||
// Any permission.
|
||||
$user = $this->createUser([], ["$operation any entity_test_enhanced_with_owner"]);
|
||||
$conditions = $this->handler->getConditions($operation, $user);
|
||||
$this->assertEquals(0, $conditions->count());
|
||||
$this->assertEquals(['user.permissions'], $conditions->getCacheContexts());
|
||||
$this->assertFalse($conditions->isAlwaysFalse());
|
||||
|
||||
// Own permission.
|
||||
$user = $this->createUser([], ["$operation own entity_test_enhanced_with_owner"]);
|
||||
$conditions = $this->handler->getConditions($operation, $user);
|
||||
$expected_conditions = [
|
||||
new Condition('user_id', $user->id()),
|
||||
];
|
||||
$this->assertEquals(1, $conditions->count());
|
||||
$this->assertEquals($expected_conditions, $conditions->getConditions());
|
||||
$this->assertEquals(['user', 'user.permissions'], $conditions->getCacheContexts());
|
||||
$this->assertFalse($conditions->isAlwaysFalse());
|
||||
|
||||
// Any permission for the first bundle, own permission for the second.
|
||||
$user = $this->createUser([], [
|
||||
"$operation any first entity_test_enhanced_with_owner",
|
||||
"$operation own second entity_test_enhanced_with_owner",
|
||||
]);
|
||||
$conditions = $this->handler->getConditions($operation, $user);
|
||||
$expected_conditions = [
|
||||
new Condition('type', ['first']),
|
||||
(new ConditionGroup('AND'))
|
||||
->addCondition('user_id', $user->id())
|
||||
->addCondition('type', ['second']),
|
||||
];
|
||||
$this->assertEquals('OR', $conditions->getConjunction());
|
||||
$this->assertEquals(2, $conditions->count());
|
||||
$this->assertEquals($expected_conditions, $conditions->getConditions());
|
||||
$this->assertEquals(['user', 'user.permissions'], $conditions->getCacheContexts());
|
||||
$this->assertFalse($conditions->isAlwaysFalse());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+511
@@ -0,0 +1,511 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\entity\Kernel\QueryAccess;
|
||||
|
||||
use Drupal\entity_module_test\Entity\EnhancedEntityWithOwner;
|
||||
use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
|
||||
use Drupal\views\Tests\ViewResultAssertionTrait;
|
||||
use Drupal\views\Views;
|
||||
|
||||
/**
|
||||
* Test uncacheable query access filtering for EntityQuery and Views.
|
||||
*
|
||||
* @group entity
|
||||
*
|
||||
* @see \Drupal\entity\QueryAccess\UncacheableQueryAccessHandler
|
||||
* @see \Drupal\entity\QueryAccess\EntityQueryAlter
|
||||
* @see \Drupal\entity\QueryAccess\ViewsQueryAlter
|
||||
*/
|
||||
class UncacheableQueryAccessTest extends EntityKernelTestBase {
|
||||
|
||||
use ViewResultAssertionTrait;
|
||||
|
||||
/**
|
||||
* The test entities.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\ContentEntityInterface[]
|
||||
*/
|
||||
protected $entities;
|
||||
|
||||
/**
|
||||
* The entity_test_enhanced storage.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityStorageInterface
|
||||
*/
|
||||
protected $storage;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = [
|
||||
'entity',
|
||||
'entity_module_test',
|
||||
'user',
|
||||
'views',
|
||||
'system',
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->installEntitySchema('entity_test_enhanced_with_owner');
|
||||
$this->installConfig(['entity_module_test']);
|
||||
|
||||
// Create uid: 1 here so that it's skipped in test cases.
|
||||
$admin_user = $this->createUser();
|
||||
|
||||
$first_entity = EnhancedEntityWithOwner::create([
|
||||
'type' => 'first',
|
||||
'name' => 'First',
|
||||
'status' => 1,
|
||||
]);
|
||||
$first_entity->save();
|
||||
|
||||
$first_entity->set('name', 'First!');
|
||||
$first_entity->set('status', 0);
|
||||
$first_entity->setNewRevision(TRUE);
|
||||
$first_entity->save();
|
||||
|
||||
$second_entity = EnhancedEntityWithOwner::create([
|
||||
'type' => 'first',
|
||||
'name' => 'Second',
|
||||
'status' => 0,
|
||||
]);
|
||||
$second_entity->save();
|
||||
|
||||
$second_entity->set('name', 'Second!');
|
||||
$second_entity->set('status', 1);
|
||||
$second_entity->setNewRevision(TRUE);
|
||||
$second_entity->save();
|
||||
|
||||
$third_entity = EnhancedEntityWithOwner::create([
|
||||
'type' => 'second',
|
||||
'name' => 'Third',
|
||||
'status' => 1,
|
||||
]);
|
||||
$third_entity->save();
|
||||
|
||||
$third_entity->set('name', 'Third!');
|
||||
$third_entity->setNewRevision(TRUE);
|
||||
$third_entity->save();
|
||||
|
||||
$this->entities = [$first_entity, $second_entity, $third_entity];
|
||||
$this->storage = \Drupal::entityTypeManager()->getStorage('entity_test_enhanced_with_owner');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests EntityQuery filtering.
|
||||
*/
|
||||
public function testEntityQuery() {
|
||||
// Admin permission, full access.
|
||||
$admin_user = $this->createUser([], ['administer entity_test_enhanced_with_owner']);
|
||||
\Drupal::currentUser()->setAccount($admin_user);
|
||||
|
||||
$result = $this->storage->getQuery()->sort('id')->execute();
|
||||
$this->assertEquals([
|
||||
$this->entities[0]->id(),
|
||||
$this->entities[1]->id(),
|
||||
$this->entities[2]->id(),
|
||||
], array_values($result));
|
||||
|
||||
// No view permissions, no access.
|
||||
$user = $this->createUser([], ['access content']);
|
||||
\Drupal::currentUser()->setAccount($user);
|
||||
|
||||
$result = $this->storage->getQuery()->execute();
|
||||
$this->assertEmpty($result);
|
||||
|
||||
// View own (published-only).
|
||||
$user = $this->createUser([], ['view own entity_test_enhanced_with_owner']);
|
||||
\Drupal::currentUser()->setAccount($user);
|
||||
|
||||
$this->entities[0]->set('user_id', $user->id());
|
||||
$this->entities[0]->save();
|
||||
$this->entities[1]->set('user_id', $user->id());
|
||||
$this->entities[1]->save();
|
||||
|
||||
$result = $this->storage->getQuery()->sort('id')->execute();
|
||||
$this->assertEquals([
|
||||
$this->entities[1]->id(),
|
||||
], array_values($result));
|
||||
|
||||
// View any (published-only).
|
||||
$user = $this->createUser([], ['view any entity_test_enhanced_with_owner']);
|
||||
\Drupal::currentUser()->setAccount($user);
|
||||
|
||||
$result = $this->storage->getQuery()->sort('id')->execute();
|
||||
$this->assertEquals([
|
||||
$this->entities[1]->id(),
|
||||
$this->entities[2]->id(),
|
||||
], array_values($result));
|
||||
|
||||
// View own unpublished.
|
||||
$user = $this->createUser([], ['view own unpublished entity_test_enhanced_with_owner']);
|
||||
\Drupal::currentUser()->setAccount($user);
|
||||
|
||||
$this->entities[0]->set('user_id', $user->id());
|
||||
$this->entities[0]->save();
|
||||
$this->entities[1]->set('user_id', $user->id());
|
||||
$this->entities[1]->save();
|
||||
|
||||
$result = $this->storage->getQuery()->sort('id')->execute();
|
||||
$this->assertEquals([
|
||||
$this->entities[0]->id(),
|
||||
], array_values($result));
|
||||
|
||||
// View own unpublished + view any (published-only).
|
||||
$user = $this->createUser([], [
|
||||
'view own unpublished entity_test_enhanced_with_owner',
|
||||
'view any entity_test_enhanced_with_owner',
|
||||
]);
|
||||
\Drupal::currentUser()->setAccount($user);
|
||||
|
||||
$this->entities[0]->set('user_id', $user->id());
|
||||
$this->entities[0]->save();
|
||||
|
||||
$result = $this->storage->getQuery()->sort('id')->execute();
|
||||
$this->assertEquals([
|
||||
$this->entities[0]->id(),
|
||||
$this->entities[1]->id(),
|
||||
$this->entities[2]->id(),
|
||||
], array_values($result));
|
||||
|
||||
// View own $first_bundle + View any $second_bundle.
|
||||
$user = $this->createUser([], [
|
||||
'view own first entity_test_enhanced_with_owner',
|
||||
'view any second entity_test_enhanced_with_owner',
|
||||
]);
|
||||
\Drupal::currentUser()->setAccount($user);
|
||||
|
||||
$this->entities[1]->set('user_id', $user->id());
|
||||
$this->entities[1]->save();
|
||||
|
||||
$result = $this->storage->getQuery()->sort('id')->execute();
|
||||
$this->assertEquals([
|
||||
$this->entities[1]->id(),
|
||||
$this->entities[2]->id(),
|
||||
], array_values($result));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests EntityQuery filtering when all revisions are queried.
|
||||
*/
|
||||
public function testEntityQueryWithRevisions() {
|
||||
// Admin permission, full access.
|
||||
$admin_user = $this->createUser([], ['administer entity_test_enhanced_with_owner']);
|
||||
\Drupal::currentUser()->setAccount($admin_user);
|
||||
|
||||
$result = $this->storage->getQuery()->allRevisions()->sort('id')->execute();
|
||||
$this->assertEquals([
|
||||
'1' => $this->entities[0]->id(),
|
||||
'2' => $this->entities[0]->id(),
|
||||
'3' => $this->entities[1]->id(),
|
||||
'4' => $this->entities[1]->id(),
|
||||
'5' => $this->entities[2]->id(),
|
||||
'6' => $this->entities[2]->id(),
|
||||
], $result);
|
||||
|
||||
// No view permissions, no access.
|
||||
$user = $this->createUser([], ['access content']);
|
||||
\Drupal::currentUser()->setAccount($user);
|
||||
|
||||
$result = $this->storage->getQuery()->allRevisions()->execute();
|
||||
$this->assertEmpty($result);
|
||||
|
||||
// View own (published-only).
|
||||
$user = $this->createUser([], ['view own entity_test_enhanced_with_owner']);
|
||||
\Drupal::currentUser()->setAccount($user);
|
||||
|
||||
// The user_id field is not revisionable, which means that updating it
|
||||
// will modify both revisions for each entity.
|
||||
$this->entities[0]->set('user_id', $user->id());
|
||||
$this->entities[0]->save();
|
||||
$this->entities[1]->set('user_id', $user->id());
|
||||
$this->entities[1]->save();
|
||||
|
||||
$result = $this->storage->getQuery()->allRevisions()->sort('id')->execute();
|
||||
$this->assertEquals([
|
||||
'1' => $this->entities[0]->id(),
|
||||
'4' => $this->entities[1]->id(),
|
||||
], $result);
|
||||
|
||||
// View any (published-only).
|
||||
$user = $this->createUser([], ['view any entity_test_enhanced_with_owner']);
|
||||
\Drupal::currentUser()->setAccount($user);
|
||||
|
||||
$result = $this->storage->getQuery()->allRevisions()->sort('id')->execute();
|
||||
$this->assertEquals([
|
||||
'1' => $this->entities[0]->id(),
|
||||
'4' => $this->entities[1]->id(),
|
||||
'5' => $this->entities[2]->id(),
|
||||
'6' => $this->entities[2]->id(),
|
||||
], $result);
|
||||
|
||||
// View own unpublished.
|
||||
$user = $this->createUser([], ['view own unpublished entity_test_enhanced_with_owner']);
|
||||
\Drupal::currentUser()->setAccount($user);
|
||||
|
||||
$this->entities[0]->set('user_id', $user->id());
|
||||
$this->entities[0]->save();
|
||||
$this->entities[1]->set('user_id', $user->id());
|
||||
$this->entities[1]->save();
|
||||
|
||||
$result = $this->storage->getQuery()->allRevisions()->sort('id')->execute();
|
||||
$this->assertEquals([
|
||||
'2' => $this->entities[0]->id(),
|
||||
'3' => $this->entities[1]->id(),
|
||||
], $result);
|
||||
|
||||
// View own unpublished + view any (published-only).
|
||||
$user = $this->createUser([], [
|
||||
'view own unpublished entity_test_enhanced_with_owner',
|
||||
'view any entity_test_enhanced_with_owner',
|
||||
]);
|
||||
\Drupal::currentUser()->setAccount($user);
|
||||
|
||||
$this->entities[0]->set('user_id', $user->id());
|
||||
$this->entities[0]->save();
|
||||
|
||||
$result = $this->storage->getQuery()->allRevisions()->sort('id')->execute();
|
||||
$this->assertEquals([
|
||||
'1' => $this->entities[0]->id(),
|
||||
'2' => $this->entities[0]->id(),
|
||||
'4' => $this->entities[1]->id(),
|
||||
'5' => $this->entities[2]->id(),
|
||||
'6' => $this->entities[2]->id(),
|
||||
], $result);
|
||||
|
||||
// View own $first_bundle + View any $second_bundle.
|
||||
$user = $this->createUser([], [
|
||||
'view own first entity_test_enhanced_with_owner',
|
||||
'view any second entity_test_enhanced_with_owner',
|
||||
]);
|
||||
\Drupal::currentUser()->setAccount($user);
|
||||
|
||||
$this->entities[1]->set('user_id', $user->id());
|
||||
$this->entities[1]->save();
|
||||
|
||||
$result = $this->storage->getQuery()->allRevisions()->sort('id')->execute();
|
||||
$this->assertEquals([
|
||||
'4' => $this->entities[1]->id(),
|
||||
'5' => $this->entities[2]->id(),
|
||||
'6' => $this->entities[2]->id(),
|
||||
], $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests Views filtering.
|
||||
*/
|
||||
public function testViews() {
|
||||
// Admin permission, full access.
|
||||
$admin_user = $this->createUser([], ['administer entity_test_enhanced_with_owner']);
|
||||
\Drupal::currentUser()->setAccount($admin_user);
|
||||
|
||||
$view = Views::getView('entity_test_enhanced_with_owner');
|
||||
$view->execute();
|
||||
$this->assertIdenticalResultset($view, [
|
||||
['id' => $this->entities[0]->id()],
|
||||
['id' => $this->entities[1]->id()],
|
||||
['id' => $this->entities[2]->id()],
|
||||
], ['id' => 'id']);
|
||||
|
||||
// No view permissions, no access.
|
||||
$user = $this->createUser([], ['access content']);
|
||||
\Drupal::currentUser()->setAccount($user);
|
||||
|
||||
$view = Views::getView('entity_test_enhanced_with_owner');
|
||||
$view->execute();
|
||||
$this->assertIdenticalResultset($view, []);
|
||||
|
||||
// View own (published-only).
|
||||
$user = $this->createUser([], ['view own entity_test_enhanced_with_owner']);
|
||||
\Drupal::currentUser()->setAccount($user);
|
||||
|
||||
$this->entities[0]->set('user_id', $user->id());
|
||||
$this->entities[0]->save();
|
||||
$this->entities[1]->set('user_id', $user->id());
|
||||
$this->entities[1]->save();
|
||||
|
||||
$view = Views::getView('entity_test_enhanced_with_owner');
|
||||
$view->execute();
|
||||
$this->assertIdenticalResultset($view, [
|
||||
['id' => $this->entities[1]->id()],
|
||||
], ['id' => 'id']);
|
||||
|
||||
// View any (published-only).
|
||||
$user = $this->createUser([], ['view any entity_test_enhanced_with_owner']);
|
||||
\Drupal::currentUser()->setAccount($user);
|
||||
|
||||
$view = Views::getView('entity_test_enhanced_with_owner');
|
||||
$view->execute();
|
||||
$this->assertIdenticalResultset($view, [
|
||||
['id' => $this->entities[1]->id()],
|
||||
['id' => $this->entities[2]->id()],
|
||||
], ['id' => 'id']);
|
||||
|
||||
// View own unpublished.
|
||||
$user = $this->createUser([], ['view own unpublished entity_test_enhanced_with_owner']);
|
||||
\Drupal::currentUser()->setAccount($user);
|
||||
|
||||
$this->entities[0]->set('user_id', $user->id());
|
||||
$this->entities[0]->save();
|
||||
$this->entities[1]->set('user_id', $user->id());
|
||||
$this->entities[1]->save();
|
||||
|
||||
$view = Views::getView('entity_test_enhanced_with_owner');
|
||||
$view->execute();
|
||||
$this->assertIdenticalResultset($view, [
|
||||
['id' => $this->entities[0]->id()],
|
||||
], ['id' => 'id']);
|
||||
|
||||
// View own unpublished + view any (published-only).
|
||||
$user = $this->createUser([], [
|
||||
'view own unpublished entity_test_enhanced_with_owner',
|
||||
'view any entity_test_enhanced_with_owner',
|
||||
]);
|
||||
\Drupal::currentUser()->setAccount($user);
|
||||
|
||||
$this->entities[0]->set('user_id', $user->id());
|
||||
$this->entities[0]->save();
|
||||
|
||||
$view = Views::getView('entity_test_enhanced_with_owner');
|
||||
$view->execute();
|
||||
$this->assertIdenticalResultset($view, [
|
||||
['id' => $this->entities[0]->id()],
|
||||
['id' => $this->entities[1]->id()],
|
||||
['id' => $this->entities[2]->id()],
|
||||
], ['id' => 'id']);
|
||||
|
||||
// View own $first_bundle + View any $second_bundle.
|
||||
$user = $this->createUser([], [
|
||||
'view own first entity_test_enhanced_with_owner',
|
||||
'view any second entity_test_enhanced_with_owner',
|
||||
]);
|
||||
\Drupal::currentUser()->setAccount($user);
|
||||
|
||||
$this->entities[1]->set('user_id', $user->id());
|
||||
$this->entities[1]->save();
|
||||
|
||||
$view = Views::getView('entity_test_enhanced_with_owner');
|
||||
$view->execute();
|
||||
$this->assertIdenticalResultset($view, [
|
||||
['id' => $this->entities[1]->id()],
|
||||
['id' => $this->entities[2]->id()],
|
||||
], ['id' => 'id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests Views filtering when all revisions are queried.
|
||||
*/
|
||||
public function testViewsWithRevisions() {
|
||||
// Admin permission, full access.
|
||||
$admin_user = $this->createUser([], ['administer entity_test_enhanced_with_owner']);
|
||||
\Drupal::currentUser()->setAccount($admin_user);
|
||||
|
||||
$view = Views::getView('entity_test_enhanced_with_owner_revisions');
|
||||
$view->execute();
|
||||
$this->assertIdenticalResultset($view, [
|
||||
['vid' => '1', 'id' => $this->entities[0]->id()],
|
||||
['vid' => '2', 'id' => $this->entities[0]->id()],
|
||||
['vid' => '3', 'id' => $this->entities[1]->id()],
|
||||
['vid' => '4', 'id' => $this->entities[1]->id()],
|
||||
['vid' => '5', 'id' => $this->entities[2]->id()],
|
||||
['vid' => '6', 'id' => $this->entities[2]->id()],
|
||||
], ['vid' => 'vid']);
|
||||
|
||||
// No view permissions, no access.
|
||||
$user = $this->createUser([], ['access content']);
|
||||
\Drupal::currentUser()->setAccount($user);
|
||||
|
||||
$view = Views::getView('entity_test_enhanced_with_owner_revisions');
|
||||
$view->execute();
|
||||
$this->assertIdenticalResultset($view, []);
|
||||
|
||||
// View own (published-only).
|
||||
$user = $this->createUser([], ['view own entity_test_enhanced_with_owner']);
|
||||
\Drupal::currentUser()->setAccount($user);
|
||||
|
||||
$this->entities[0]->set('user_id', $user->id());
|
||||
$this->entities[0]->save();
|
||||
$this->entities[1]->set('user_id', $user->id());
|
||||
$this->entities[1]->save();
|
||||
|
||||
$view = Views::getView('entity_test_enhanced_with_owner_revisions');
|
||||
$view->execute();
|
||||
$this->assertIdenticalResultset($view, [
|
||||
['vid' => '1', 'id' => $this->entities[0]->id()],
|
||||
['vid' => '4', 'id' => $this->entities[1]->id()],
|
||||
], ['vid' => 'vid']);
|
||||
|
||||
// View any (published-only).
|
||||
$user = $this->createUser([], ['view any entity_test_enhanced_with_owner']);
|
||||
\Drupal::currentUser()->setAccount($user);
|
||||
|
||||
$view = Views::getView('entity_test_enhanced_with_owner_revisions');
|
||||
$view->execute();
|
||||
$this->assertIdenticalResultset($view, [
|
||||
['vid' => '1', 'id' => $this->entities[0]->id()],
|
||||
['vid' => '4', 'id' => $this->entities[1]->id()],
|
||||
['vid' => '5', 'id' => $this->entities[2]->id()],
|
||||
['vid' => '6', 'id' => $this->entities[2]->id()],
|
||||
], ['vid' => 'vid']);
|
||||
|
||||
// View own unpublished.
|
||||
$user = $this->createUser([], ['view own unpublished entity_test_enhanced_with_owner']);
|
||||
\Drupal::currentUser()->setAccount($user);
|
||||
|
||||
$this->entities[0]->set('user_id', $user->id());
|
||||
$this->entities[0]->save();
|
||||
$this->entities[1]->set('user_id', $user->id());
|
||||
$this->entities[1]->save();
|
||||
|
||||
$view = Views::getView('entity_test_enhanced_with_owner_revisions');
|
||||
$view->execute();
|
||||
$this->assertIdenticalResultset($view, [
|
||||
['vid' => '2', 'id' => $this->entities[0]->id()],
|
||||
['vid' => '3', 'id' => $this->entities[1]->id()],
|
||||
], ['vid' => 'vid']);
|
||||
|
||||
// View own unpublished + view any (published-only).
|
||||
$user = $this->createUser([], [
|
||||
'view own unpublished entity_test_enhanced_with_owner',
|
||||
'view any entity_test_enhanced_with_owner',
|
||||
]);
|
||||
\Drupal::currentUser()->setAccount($user);
|
||||
|
||||
$this->entities[0]->set('user_id', $user->id());
|
||||
$this->entities[0]->save();
|
||||
|
||||
$view = Views::getView('entity_test_enhanced_with_owner_revisions');
|
||||
$view->execute();
|
||||
$this->assertIdenticalResultset($view, [
|
||||
['vid' => '1', 'id' => $this->entities[0]->id()],
|
||||
['vid' => '2', 'id' => $this->entities[0]->id()],
|
||||
['vid' => '4', 'id' => $this->entities[1]->id()],
|
||||
['vid' => '5', 'id' => $this->entities[2]->id()],
|
||||
['vid' => '6', 'id' => $this->entities[2]->id()],
|
||||
], ['vid' => 'vid']);
|
||||
|
||||
// View own $first_bundle + View any $second_bundle.
|
||||
$user = $this->createUser([], [
|
||||
'view own first entity_test_enhanced_with_owner',
|
||||
'view any second entity_test_enhanced_with_owner',
|
||||
]);
|
||||
\Drupal::currentUser()->setAccount($user);
|
||||
|
||||
$this->entities[1]->set('user_id', $user->id());
|
||||
$this->entities[1]->save();
|
||||
|
||||
$view = Views::getView('entity_test_enhanced_with_owner_revisions');
|
||||
$view->execute();
|
||||
$this->assertIdenticalResultset($view, [
|
||||
['vid' => '4', 'id' => $this->entities[1]->id()],
|
||||
['vid' => '5', 'id' => $this->entities[2]->id()],
|
||||
['vid' => '6', 'id' => $this->entities[2]->id()],
|
||||
], ['vid' => 'vid']);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,7 +3,6 @@
|
||||
namespace Drupal\Tests\entity\Kernel;
|
||||
|
||||
use Drupal\entity_module_test\Entity\EnhancedEntity;
|
||||
use Drupal\entity_module_test\Entity\EnhancedEntityBundle;
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
use Drupal\user\Entity\Role;
|
||||
use Drupal\user\Entity\User;
|
||||
@@ -30,12 +29,6 @@ class RevisionBasicUITest extends KernelTestBase {
|
||||
$this->installSchema('system', 'router');
|
||||
$this->installConfig(['system']);
|
||||
|
||||
$bundle = EnhancedEntityBundle::create([
|
||||
'id' => 'default',
|
||||
'label' => 'Default',
|
||||
]);
|
||||
$bundle->save();
|
||||
|
||||
\Drupal::service('router.builder')->rebuild();
|
||||
}
|
||||
|
||||
|
||||
+115
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\entity\Unit;
|
||||
|
||||
use Drupal\Core\Cache\Context\CacheContextsManager;
|
||||
use Drupal\Core\Config\Entity\ConfigEntityInterface;
|
||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||
use Drupal\Core\Entity\ContentEntityTypeInterface;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||
use Drupal\Core\Language\Language;
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Drupal\entity\BundleEntityAccessControlHandler;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Prophecy\Argument;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\entity\BundleEntityAccessControlHandler
|
||||
* @group entity
|
||||
*/
|
||||
class BundleEntityAccessControlHandlerTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$module_handler = $this->prophesize(ModuleHandlerInterface::class);
|
||||
$module_handler->invokeAll(Argument::any(), Argument::any())->willReturn([]);
|
||||
$cache_contexts_manager = $this->prophesize(CacheContextsManager::class);
|
||||
$cache_contexts_manager->assertValidTokens(Argument::any())->willReturn(TRUE);
|
||||
|
||||
$container = new ContainerBuilder();
|
||||
$container->set('module_handler', $module_handler->reveal());
|
||||
$container->set('cache_contexts_manager', $cache_contexts_manager->reveal());
|
||||
\Drupal::setContainer($container);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::checkAccess
|
||||
*
|
||||
* @dataProvider accessProvider
|
||||
*/
|
||||
public function testAccess(EntityInterface $entity, $operation, $account, $allowed) {
|
||||
$handler = new BundleEntityAccessControlHandler($entity->getEntityType());
|
||||
$handler->setStringTranslation($this->getStringTranslationStub());
|
||||
$result = $handler->access($entity, $operation, $account);
|
||||
$this->assertEquals($allowed, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testAccess().
|
||||
*
|
||||
* @return array
|
||||
* A list of testAccess method arguments.
|
||||
*/
|
||||
public function accessProvider() {
|
||||
$entity_type = $this->prophesize(ContentEntityTypeInterface::class);
|
||||
$entity_type->id()->willReturn('green_entity_bundle');
|
||||
$entity_type->getBundleOf()->willReturn('green_entity');
|
||||
$entity_type->getAdminPermission()->willReturn('administer green_entity');
|
||||
$entity_type = $entity_type->reveal();
|
||||
|
||||
$entity = $this->prophesize(ConfigEntityInterface::class);
|
||||
$entity->getEntityType()->willReturn($entity_type);
|
||||
$entity->getEntityTypeId()->willReturn('green_entity_bundle');
|
||||
$entity->id()->willReturn('default');
|
||||
$entity->uuid()->willReturn('fake uuid');
|
||||
$entity->language()->willReturn(new Language(['id' => LanguageInterface::LANGCODE_NOT_SPECIFIED]));
|
||||
|
||||
// User with no access.
|
||||
$user = $this->buildMockUser(1, 'access content');
|
||||
$data[] = [$entity->reveal(), 'view label', $user->reveal(), FALSE];
|
||||
|
||||
// Permissions which grant "view label" access.
|
||||
$permissions = [
|
||||
'administer green_entity',
|
||||
'view green_entity',
|
||||
'view default green_entity',
|
||||
'view own green_entity',
|
||||
'view any green_entity',
|
||||
'view own default green_entity',
|
||||
'view any default green_entity',
|
||||
];
|
||||
foreach ($permissions as $index => $permission) {
|
||||
$user = $this->buildMockUser(10 + $index, $permission);
|
||||
$data[] = [$entity->reveal(), 'view label', $user->reveal(), TRUE];
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a mock user.
|
||||
*
|
||||
* @param int $uid
|
||||
* The user ID.
|
||||
* @param string $permission
|
||||
* The permission to grant.
|
||||
*
|
||||
* @return \Prophecy\Prophecy\ObjectProphecy
|
||||
* The user mock.
|
||||
*/
|
||||
protected function buildMockUser($uid, $permission) {
|
||||
$account = $this->prophesize(AccountInterface::class);
|
||||
$account->id()->willReturn($uid);
|
||||
$account->hasPermission($permission)->willReturn(TRUE);
|
||||
$account->hasPermission(Argument::any())->willReturn(FALSE);
|
||||
|
||||
return $account;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\entity\Unit\QueryAccess;
|
||||
|
||||
use Drupal\entity\QueryAccess\Condition;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\entity\QueryAccess\Condition
|
||||
* @group entity
|
||||
*/
|
||||
class ConditionTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* ::covers __construct.
|
||||
*
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessage Unrecognized operator "INVALID".
|
||||
*/
|
||||
public function testInvalidOperator() {
|
||||
$condition = new Condition('uid', '1', 'INVALID');
|
||||
}
|
||||
|
||||
/**
|
||||
* ::covers getField
|
||||
* ::covers getValue
|
||||
* ::covers getOperator
|
||||
* ::covers __toString.
|
||||
*/
|
||||
public function testGetters() {
|
||||
$condition = new Condition('uid', '2');
|
||||
$this->assertEquals('uid', $condition->getField());
|
||||
$this->assertEquals('2', $condition->getValue());
|
||||
$this->assertEquals('=', $condition->getOperator());
|
||||
$this->assertEquals("uid = '2'", $condition->__toString());
|
||||
|
||||
$condition = new Condition('type', ['article', 'page']);
|
||||
$this->assertEquals('type', $condition->getField());
|
||||
$this->assertEquals(['article', 'page'], $condition->getValue());
|
||||
$this->assertEquals('IN', $condition->getOperator());
|
||||
$this->assertEquals("type IN ['article', 'page']", $condition->__toString());
|
||||
|
||||
$condition = new Condition('title', NULL, 'IS NULL');
|
||||
$this->assertEquals('title', $condition->getField());
|
||||
$this->assertEquals(NULL, $condition->getValue());
|
||||
$this->assertEquals('IS NULL', $condition->getOperator());
|
||||
$this->assertEquals("title IS NULL", $condition->__toString());
|
||||
}
|
||||
|
||||
}
|
||||
+4
-4
@@ -81,7 +81,7 @@ class UncacheableEntityPermissionProviderTest extends UnitTestCase {
|
||||
'create green_entity' => 'Create green entities',
|
||||
'update green_entity' => 'Update green entities',
|
||||
'delete green_entity' => 'Delete green entities',
|
||||
'view any green_entity' => 'View any green entities',
|
||||
'view green_entity' => 'View green entities',
|
||||
];
|
||||
$data[] = [$entity_type->reveal(), $expected_permissions];
|
||||
|
||||
@@ -127,9 +127,9 @@ class UncacheableEntityPermissionProviderTest extends UnitTestCase {
|
||||
'create second white_entity' => 'Second: Create white entities',
|
||||
'update second white_entity' => 'Second: Update white entities',
|
||||
'delete second white_entity' => 'Second: Delete white entities',
|
||||
'view any white_entity' => 'View any white entities',
|
||||
'view any first white_entity' => 'First: View any white entities',
|
||||
'view any second white_entity' => 'Second: View any white entities',
|
||||
'view white_entity' => 'View white entities',
|
||||
'view first white_entity' => 'First: View white entities',
|
||||
'view second white_entity' => 'Second: View white entities',
|
||||
];
|
||||
$data[] = [$entity_type->reveal(), $expected_permissions];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user