updated core to 8.6.1 via composer

This commit is contained in:
2018-09-12 13:58:26 +02:00
parent a9a219f2ed
commit ea56b9fba3
4443 changed files with 112098 additions and 40708 deletions
@@ -47,7 +47,7 @@ $existing_blocks = unserialize($existing_blocks);
$connection->update('key_value')
->fields([
'value' => serialize(array_merge($existing_blocks, ['block.block.testfor2354889', 'block.block.secondtestfor2354889', 'block.block.thirdtestfor2354889']))
'value' => serialize(array_merge($existing_blocks, ['block.block.testfor2354889', 'block.block.secondtestfor2354889', 'block.block.thirdtestfor2354889'])),
])
->condition('collection', 'config.entity.key_store.block')
->condition('name', 'theme:bartik')
@@ -40,7 +40,7 @@ $existing_blocks = unserialize($existing_blocks);
$connection->update('key_value')
->fields([
'value' => serialize(array_merge($existing_blocks, ['block.block.seven_local_actions']))
'value' => serialize(array_merge($existing_blocks, ['block.block.seven_local_actions'])),
])
->condition('collection', 'config.entity.key_store.block')
->condition('name', 'theme:seven')
@@ -55,7 +55,7 @@ $extensions = $connection->select('config')
$extensions = unserialize($extensions);
$connection->update('config')
->fields([
'data' => serialize(array_merge_recursive($extensions, ['theme' => ['test_theme' => 0]]))
'data' => serialize(array_merge_recursive($extensions, ['theme' => ['test_theme' => 0]])),
])
->condition('name', 'core.extension')
->execute();
@@ -40,7 +40,7 @@ $existing_blocks = unserialize($existing_blocks);
$connection->update('key_value')
->fields([
'value' => serialize(array_merge($existing_blocks, ['block.block.bartik_page_title']))
'value' => serialize(array_merge($existing_blocks, ['block.block.bartik_page_title'])),
])
->condition('collection', 'config.entity.key_store.block')
->condition('name', 'theme:bartik')
@@ -55,7 +55,7 @@ $extensions = $connection->select('config')
$extensions = unserialize($extensions);
$connection->update('config')
->fields([
'data' => serialize(array_merge_recursive($extensions, ['theme' => ['test_theme' => 0]]))
'data' => serialize(array_merge_recursive($extensions, ['theme' => ['test_theme' => 0]])),
])
->condition('name', 'core.extension')
->execute();
@@ -40,7 +40,7 @@ $existing_blocks = unserialize($existing_blocks);
$connection->update('key_value')
->fields([
'value' => serialize(array_merge($existing_blocks, ['block.block.seven_secondary_local_tasks']))
'value' => serialize(array_merge($existing_blocks, ['block.block.seven_secondary_local_tasks'])),
])
->condition('collection', 'config.entity.key_store.block')
->condition('name', 'theme:seven')
@@ -40,7 +40,7 @@ $existing_blocks = unserialize($existing_blocks);
$connection->update('key_value')
->fields([
'value' => serialize(array_merge($existing_blocks, ['block.block.bartik_branding']))
'value' => serialize(array_merge($existing_blocks, ['block.block.bartik_branding'])),
])
->condition('collection', 'config.entity.key_store.block')
->condition('name', 'theme:bartik')
@@ -55,7 +55,7 @@ $extensions = $connection->select('config')
$extensions = unserialize($extensions);
$connection->update('config')
->fields([
'data' => serialize(array_merge_recursive($extensions, ['theme' => ['test_theme' => 0]]))
'data' => serialize(array_merge_recursive($extensions, ['theme' => ['test_theme' => 0]])),
])
->condition('name', 'core.extension')
->execute();
@@ -19,7 +19,7 @@ $extensions = $connection->select('config')
$extensions = unserialize($extensions);
$connection->update('config')
->fields([
'data' => serialize(array_merge_recursive($extensions, ['theme' => ['test_stable' => 0]]))
'data' => serialize(array_merge_recursive($extensions, ['theme' => ['test_stable' => 0]])),
])
->condition('name', 'core.extension')
->execute();
@@ -43,7 +43,7 @@ $existing_blocks = unserialize($existing_blocks);
$connection->update('key_value')
->fields([
'value' => serialize(array_merge($existing_blocks, ['block.block.testfor2513534', 'block.block.secondtestfor2513534']))
'value' => serialize(array_merge($existing_blocks, ['block.block.testfor2513534', 'block.block.secondtestfor2513534'])),
])
->condition('collection', 'config.entity.key_store.block')
->condition('name', 'theme:bartik')
@@ -0,0 +1,63 @@
<?php
/**
* @file
* Contains database additions to drupal-8.bare.standard.php.gz for testing the
* upgrade path of https://www.drupal.org/node/2455125.
*/
use Drupal\Component\Uuid\Php;
use Drupal\Core\Database\Database;
use Drupal\Core\Serialization\Yaml;
$connection = Database::getConnection();
$view_file = __DIR__ . '/drupal-8.views-taxonomy-parent-2543726.yml';
$view_config = Yaml::decode(file_get_contents($view_file));
$connection->insert('config')
->fields(['collection', 'name', 'data'])
->values([
'collection' => '',
'name' => "views.view.test_taxonomy_parent",
'data' => serialize($view_config),
])
->execute();
$uuid = new Php();
// The root tid.
$tids = [0];
for ($i = 0; $i < 4; $i++) {
$name = $this->randomString();
$tid = $connection->insert('taxonomy_term_data')
->fields(['vid', 'uuid', 'langcode'])
->values(['vid' => 'tags', 'uuid' => $uuid->generate(), 'langcode' => 'en'])
->execute();
$connection->insert('taxonomy_term_field_data')
->fields(['tid', 'vid', 'langcode', 'name', 'weight', 'changed', 'default_langcode'])
->values(['tid' => $tid, 'vid' => 'tags', 'langcode' => 'en', 'name' => $name, 'weight' => 0, 'changed' => REQUEST_TIME, 'default_langcode' => 1])
->execute();
$tids[] = $tid;
}
$hierarchy = [
// Term with tid 1 has terms with tids 2 and 3 as parents.
1 => [2, 3],
2 => [3, 0],
3 => [0],
];
$query = $connection->insert('taxonomy_term_hierarchy')->fields(['tid', 'parent']);
foreach ($hierarchy as $tid => $parents) {
foreach ($parents as $parent) {
$query->values(['tid' => $tids[$tid], 'parent' => $tids[$parent]]);
}
}
$query->execute();
@@ -0,0 +1,222 @@
langcode: en
status: true
dependencies:
module:
- taxonomy
- user
id: test_taxonomy_parent
label: test_taxonomy_parent
module: views
description: ''
tag: ''
base_table: taxonomy_term_data
base_field: tid
core: 8.x
display:
default:
display_plugin: default
id: default
display_title: Master
position: 0
display_options:
access:
type: perm
options:
perm: 'access content'
cache:
type: 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: full
options:
items_per_page: 10
offset: 0
id: 0
total_pages: null
expose:
items_per_page: false
items_per_page_label: 'Items per page'
items_per_page_options: '5, 10, 25, 50'
items_per_page_options_all: false
items_per_page_options_all_label: '- All -'
offset: false
offset_label: Offset
tags:
previous: ' Previous'
next: 'Next '
first: '« First'
last: 'Last »'
quantity: 9
style:
type: default
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:
id: name
table: taxonomy_term_data
field: name
label: ''
alter:
alter_text: false
make_link: false
absolute: false
trim: false
word_boundary: false
ellipsis: false
strip_tags: false
html: false
hide_empty: false
empty_zero: false
relationship: none
group_type: group
admin_label: ''
exclude: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: true
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_alter_empty: true
plugin_id: field
type: string
settings:
link_to_entity: true
entity_type: taxonomy_term
entity_field: name
filters:
parent:
id: parent
table: taxonomy_term_hierarchy
field: parent
relationship: field_tags
group_type: group
admin_label: ''
operator: '='
value:
min: ''
max: ''
value: ''
group: 1
exposed: true
expose:
operator_id: parent_op
label: 'Parent term'
description: ''
use_operator: false
operator: parent_op
identifier: parent
required: false
remember: false
multiple: false
remember_roles:
authenticated: authenticated
anonymous: '0'
administrator: '0'
placeholder: ''
min_placeholder: ''
max_placeholder: ''
is_grouped: false
group_info:
label: ''
description: ''
identifier: ''
optional: true
widget: select
multiple: false
remember: false
default_group: All
default_group_multiple: { }
group_items: { }
plugin_id: numeric
parent_1:
id: parent_1
table: taxonomy_term_hierarchy
field: parent
relationship: field_tags
group_type: group
admin_label: ''
operator: '='
value:
min: ''
max: ''
value: ''
group: 1
exposed: true
expose:
operator_id: parent_1_op
label: 'Parent term'
description: ''
use_operator: false
operator: parent_1_op
identifier: parent_1
required: false
remember: false
multiple: false
remember_roles:
authenticated: authenticated
anonymous: '0'
administrator: '0'
placeholder: ''
min_placeholder: ''
max_placeholder: ''
is_grouped: false
group_info:
label: ''
description: ''
identifier: ''
optional: true
widget: select
multiple: false
remember: false
default_group: All
default_group_multiple: { }
group_items: { }
plugin_id: numeric
sorts: { }
header: { }
footer: { }
empty: { }
relationships:
parent:
id: parent
table: taxonomy_term__parent
field: parent_target_id
relationship: none
group_type: group
admin_label: Parent
required: true
plugin_id: standard
arguments: { }
@@ -180,8 +180,8 @@ function ajax_forms_test_advanced_commands_add_css_callback($form, FormStateInte
* Ajax form callback: Selects the 'drivertext' element of the validation form.
*/
function ajax_forms_test_validation_form_callback($form, FormStateInterface $form_state) {
drupal_set_message("ajax_forms_test_validation_form_callback invoked");
drupal_set_message(t("Callback: drivertext=%drivertext, spare_required_field=%spare_required_field", ['%drivertext' => $form_state->getValue('drivertext'), '%spare_required_field' => $form_state->getValue('spare_required_field')]));
\Drupal::messenger()->addStatus("ajax_forms_test_validation_form_callback invoked");
\Drupal::messenger()->addStatus(t("Callback: drivertext=%drivertext, spare_required_field=%spare_required_field", ['%drivertext' => $form_state->getValue('drivertext'), '%spare_required_field' => $form_state->getValue('spare_required_field')]));
return ['#markup' => '<div id="message_area">ajax_forms_test_validation_form_callback at ' . date('c') . '</div>'];
}
@@ -189,8 +189,8 @@ function ajax_forms_test_validation_form_callback($form, FormStateInterface $for
* Ajax form callback: Selects the 'drivernumber' element of the validation form.
*/
function ajax_forms_test_validation_number_form_callback($form, FormStateInterface $form_state) {
drupal_set_message("ajax_forms_test_validation_number_form_callback invoked");
drupal_set_message(t("Callback: drivernumber=%drivernumber, spare_required_field=%spare_required_field", ['%drivernumber' => $form_state->getValue('drivernumber'), '%spare_required_field' => $form_state->getValue('spare_required_field')]));
\Drupal::messenger()->addStatus("ajax_forms_test_validation_number_form_callback invoked");
\Drupal::messenger()->addStatus(t("Callback: drivernumber=%drivernumber, spare_required_field=%spare_required_field", ['%drivernumber' => $form_state->getValue('drivernumber'), '%spare_required_field' => $form_state->getValue('spare_required_field')]));
return ['#markup' => '<div id="message_area_number">ajax_forms_test_validation_number_form_callback at ' . date('c') . '</div>'];
}
@@ -45,4 +45,3 @@ ajax_forms_test.ajax_element_form:
_form: '\Drupal\ajax_forms_test\Form\AjaxFormsTestAjaxElementsForm'
requirements:
_access: 'TRUE'
@@ -27,7 +27,8 @@ class Callbacks {
*/
public function dateCallback($form, FormStateInterface $form_state) {
$response = new AjaxResponse();
$response->addCommand(new HtmlCommand('#ajax_date_value', $form_state->getValue('date')));
$date = $form_state->getValue('date');
$response->addCommand(new HtmlCommand('#ajax_date_value', sprintf('<div>%s</div>', $date)));
$response->addCommand(new DataCommand('#ajax_date_value', 'form_state_value_date', $form_state->getValue('date')));
return $response;
}
@@ -39,7 +40,7 @@ class Callbacks {
$datetime = $form_state->getValue('datetime')['date'] . ' ' . $form_state->getValue('datetime')['time'];
$response = new AjaxResponse();
$response->addCommand(new HtmlCommand('#ajax_datetime_value', $datetime));
$response->addCommand(new HtmlCommand('#ajax_datetime_value', sprintf('<div>%s</div>', $datetime)));
$response->addCommand(new DataCommand('#ajax_datetime_value', 'form_state_value_datetime', $datetime));
return $response;
}
@@ -67,7 +67,7 @@ class AjaxFormsTestValidationForm extends FormBase {
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
drupal_set_message($this->t("Validation form submitted"));
$this->messenger()->addStatus($this->t("Validation form submitted"));
}
}
@@ -6,6 +6,7 @@ use Drupal\Core\Block\BlockBase;
use Drupal\Core\Form\FormBuilderInterface;
use Drupal\Core\Form\FormInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Messenger\MessengerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
@@ -27,6 +28,13 @@ class AjaxFormBlock extends BlockBase implements FormInterface, ContainerFactory
*/
protected $formBuilder;
/**
* The messenger.
*
* @var \Drupal\Core\Messenger\MessengerInterface
*/
protected $messenger;
/**
* Constructs a new AjaxFormBlock.
*
@@ -38,10 +46,13 @@ class AjaxFormBlock extends BlockBase implements FormInterface, ContainerFactory
* The plugin implementation definition.
* @param \Drupal\Core\Form\FormBuilderInterface $form_builder
* The form builder.
* @param \Drupal\Core\Messenger\MessengerInterface $messenger
* The messenger.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, FormBuilderInterface $form_builder) {
public function __construct(array $configuration, $plugin_id, $plugin_definition, FormBuilderInterface $form_builder, MessengerInterface $messenger) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->formBuilder = $form_builder;
$this->messenger = $messenger;
}
/**
@@ -52,7 +63,8 @@ class AjaxFormBlock extends BlockBase implements FormInterface, ContainerFactory
$configuration,
$plugin_id,
$plugin_definition,
$container->get('form_builder')
$container->get('form_builder'),
$container->get('messenger')
);
}
@@ -129,7 +141,7 @@ class AjaxFormBlock extends BlockBase implements FormInterface, ContainerFactory
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
drupal_set_message('Submission successful.');
$this->messenger->addStatus('Submission successful.');
}
}
@@ -5,4 +5,4 @@ package: Testing
version: VERSION
core: 8.x
dependencies:
- contact
- drupal:contact
@@ -1,3 +1,8 @@
ajax_insert:
js:
js/insert-ajax.js: {}
dependencies:
- core/drupal.ajax
order:
drupalSettings:
ajax: test
@@ -6,6 +6,14 @@ ajax_test.dialog_contents:
requirements:
_access: 'TRUE'
ajax_test.ajax_render_types:
path: '/ajax-test/dialog-contents-types/{type}'
defaults:
_title: 'AJAX Dialog contents routing'
_controller: '\Drupal\ajax_test\Controller\AjaxTestController::renderTypes'
requirements:
_access: 'TRUE'
ajax_test.dialog_form:
path: '/ajax-test/dialog-form'
defaults:
@@ -21,6 +29,20 @@ ajax_test.dialog:
requirements:
_access: 'TRUE'
ajax_test.insert_links_block_wrapper:
path: '/ajax-test/insert-block-wrapper'
defaults:
_controller: '\Drupal\ajax_test\Controller\AjaxTestController::insertLinksBlockWrapper'
requirements:
_access: 'TRUE'
ajax_test.insert_links_inline_wrapper:
path: '/ajax-test/insert-inline-wrapper'
defaults:
_controller: '\Drupal\ajax_test\Controller\AjaxTestController::insertLinksInlineWrapper'
requirements:
_access: 'TRUE'
ajax_test.dialog_close:
path: '/ajax-test/dialog-close'
defaults:
@@ -0,0 +1,45 @@
/**
* @file
* Drupal behavior to attach click event handlers to ajax-insert and
* ajax-insert-inline links for testing ajax requests.
*/
(function($, window, Drupal) {
Drupal.behaviors.insertTest = {
attach(context) {
$('.ajax-insert')
.once('ajax-insert')
.on('click', event => {
event.preventDefault();
const ajaxSettings = {
url: event.currentTarget.getAttribute('href'),
wrapper: 'ajax-target',
base: false,
element: false,
method: event.currentTarget.getAttribute('data-method'),
effect: event.currentTarget.getAttribute('data-effect'),
};
const myAjaxObject = Drupal.ajax(ajaxSettings);
myAjaxObject.execute();
});
$('.ajax-insert-inline')
.once('ajax-insert')
.on('click', event => {
event.preventDefault();
const ajaxSettings = {
url: event.currentTarget.getAttribute('href'),
wrapper: 'ajax-target-inline',
base: false,
element: false,
method: event.currentTarget.getAttribute('data-method'),
effect: event.currentTarget.getAttribute('data-effect'),
};
const myAjaxObject = Drupal.ajax(ajaxSettings);
myAjaxObject.execute();
});
$(context).addClass('processed');
},
};
})(jQuery, window, Drupal);
@@ -0,0 +1,42 @@
/**
* DO NOT EDIT THIS FILE.
* See the following change record for more information,
* https://www.drupal.org/node/2815083
* @preserve
**/
(function ($, window, Drupal) {
Drupal.behaviors.insertTest = {
attach: function attach(context) {
$('.ajax-insert').once('ajax-insert').on('click', function (event) {
event.preventDefault();
var ajaxSettings = {
url: event.currentTarget.getAttribute('href'),
wrapper: 'ajax-target',
base: false,
element: false,
method: event.currentTarget.getAttribute('data-method'),
effect: event.currentTarget.getAttribute('data-effect')
};
var myAjaxObject = Drupal.ajax(ajaxSettings);
myAjaxObject.execute();
});
$('.ajax-insert-inline').once('ajax-insert').on('click', function (event) {
event.preventDefault();
var ajaxSettings = {
url: event.currentTarget.getAttribute('href'),
wrapper: 'ajax-target-inline',
base: false,
element: false,
method: event.currentTarget.getAttribute('data-method'),
effect: event.currentTarget.getAttribute('data-effect')
};
var myAjaxObject = Drupal.ajax(ajaxSettings);
myAjaxObject.execute();
});
$(context).addClass('processed');
}
};
})(jQuery, window, Drupal);
@@ -42,6 +42,101 @@ class AjaxTestController {
return $content;
}
/**
* Example content for testing the wrapper of the response.
*
* @param string $type
* Type of response.
*
* @return array
* Renderable array of AJAX response contents.
*/
public function renderTypes($type) {
return [
'#title' => '<em>AJAX Dialog & contents</em>',
'content' => [
'#type' => 'inline_template',
'#template' => $this->getRenderTypes()[$type]['render'],
],
];
}
/**
* Returns a render array of links that directly Drupal.ajax().
*
* @return array
* Renderable array of AJAX response contents.
*/
public function insertLinksBlockWrapper() {
$methods = [
'html',
'replaceWith',
];
$build['links'] = [
'ajax_target' => [
'#markup' => '<div class="ajax-target-wrapper"><div id="ajax-target">Target</div></div>',
],
'links' => [
'#theme' => 'links',
'#attached' => ['library' => ['ajax_test/ajax_insert']],
],
];
foreach ($methods as $method) {
foreach ($this->getRenderTypes() as $type => $item) {
$class = 'ajax-insert';
$build['links']['links']['#links']["$method-$type"] = [
'title' => "Link $method $type",
'url' => Url::fromRoute('ajax_test.ajax_render_types', ['type' => $type]),
'attributes' => [
'class' => [$class],
'data-method' => $method,
'data-effect' => $item['effect'],
],
];
}
}
return $build;
}
/**
* Returns a render array of links that directly Drupal.ajax().
*
* @return array
* Renderable array of AJAX response contents.
*/
public function insertLinksInlineWrapper() {
$methods = [
'html',
'replaceWith',
];
$build['links'] = [
'ajax_target' => [
'#markup' => '<div class="ajax-target-wrapper"><span id="ajax-target-inline">Target inline</span></div>',
],
'links' => [
'#theme' => 'links',
'#attached' => ['library' => ['ajax_test/ajax_insert']],
],
];
foreach ($methods as $method) {
foreach ($this->getRenderTypes() as $type => $item) {
$class = 'ajax-insert-inline';
$build['links']['links']['#links']["$method-$type"] = [
'title' => "Link $method $type",
'url' => Url::fromRoute('ajax_test.ajax_render_types', ['type' => $type]),
'attributes' => [
'class' => [$class],
'data-method' => $method,
'data-effect' => $item['effect'],
],
];
}
}
return $build;
}
/**
* Returns a render array that will be rendered by AjaxRenderer.
*
@@ -139,7 +234,7 @@ class AjaxTestController {
'data-dialog-type' => 'modal',
'data-dialog-options' => json_encode([
'width' => 400,
])
]),
],
],
'link3' => [
@@ -151,7 +246,7 @@ class AjaxTestController {
'data-dialog-options' => json_encode([
'target' => 'ajax-test-dialog-wrapper-1',
'width' => 800,
])
]),
],
],
'link4' => [
@@ -179,7 +274,7 @@ class AjaxTestController {
'data-dialog-options' => json_encode([
'width' => 800,
'height' => 500,
])
]),
],
],
'link7' => [
@@ -190,7 +285,7 @@ class AjaxTestController {
'data-dialog-type' => 'dialog',
'data-dialog-options' => json_encode([
'width' => 800,
])
]),
],
],
'link8' => [
@@ -222,4 +317,41 @@ class AjaxTestController {
return $response;
}
/**
* Render types.
*
* @return array
* Render types.
*/
protected function getRenderTypes() {
$render_single_root = [
'pre-wrapped-div' => '<div class="pre-wrapped">pre-wrapped<script> var test;</script></div>',
'pre-wrapped-span' => '<span class="pre-wrapped">pre-wrapped<script> var test;</script></span>',
'pre-wrapped-whitespace' => ' <div class="pre-wrapped-whitespace">pre-wrapped-whitespace</div>' . "\r\n",
'not-wrapped' => 'not-wrapped',
'comment-string-not-wrapped' => '<!-- COMMENT -->comment-string-not-wrapped',
'comment-not-wrapped' => '<!-- COMMENT --><div class="comment-not-wrapped">comment-not-wrapped</div>',
'svg' => '<svg xmlns="http://www.w3.org/2000/svg" width="10" height="10"><rect x="0" y="0" height="10" width="10" fill="green"/></svg>',
'empty' => '',
];
$render_multiple_root = [
'mixed' => ' foo <!-- COMMENT --> foo bar<div class="a class"><p>some string</p></div> additional not wrapped strings, <!-- ANOTHER COMMENT --> <p>final string</p>',
'top-level-only' => '<div>element #1</div><div>element #2</div>',
'top-level-only-pre-whitespace' => ' <div>element #1</div><div>element #2</div> ',
'top-level-only-middle-whitespace-span' => '<span>element #1</span> <span>element #2</span>',
'top-level-only-middle-whitespace-div' => '<div>element #1</div> <div>element #2</div>',
];
$render_info = [];
foreach ($render_single_root as $key => $render) {
$render_info[$key] = ['render' => $render, 'effect' => 'fade'];
}
foreach ($render_multiple_root as $key => $render) {
$render_info[$key] = ['render' => $render, 'effect' => 'none'];
$render_info["$key--effect"] = ['render' => $render, 'effect' => 'fade'];
}
return $render_info;
}
}
@@ -31,7 +31,7 @@ class AjaxTestDialogForm extends FormBase {
// to have a dummy field we can set in WebTestBase::drupalPostForm() else it won't
// submit anything.
$form['textfield'] = [
'#type' => 'hidden'
'#type' => 'hidden',
];
$form['button1'] = [
'#type' => 'submit',
@@ -67,7 +67,6 @@ class AjaxTestDialogForm extends FormBase {
$form_state->setRedirect('ajax_test.dialog_contents');
}
/**
* AJAX callback handler for AjaxTestDialogForm.
*/
@@ -82,7 +81,6 @@ class AjaxTestDialogForm extends FormBase {
return $this->dialog(FALSE);
}
/**
* Util to render dialog in ajax callback.
*
@@ -116,7 +116,7 @@ function _batch_test_finished_helper($batch_id, $success, $results, $operations)
],
];
drupal_set_message(\Drupal::service('renderer')->renderPlain($error_message));
\Drupal::messenger()->addStatus(\Drupal::service('renderer')->renderPlain($error_message));
}
/**
@@ -19,7 +19,7 @@ class BatchTestController {
return [
'success' => [
'#markup' => 'Redirection successful.',
]
],
];
}
@@ -103,7 +103,7 @@ class BatchTestController {
return [
'success' => [
'#markup' => 'Got out of a programmatic batched form.',
]
],
];
}
@@ -8,8 +8,8 @@
/**
* Implements hook_cron().
*
* common_test_cron() throws an exception, but the execution should reach this
* function as well.
* Function common_test_cron() throws an exception, but the execution should
* reach this function as well.
*
* @see common_test_cron()
*/
@@ -60,13 +60,13 @@ class FormController implements FormInterface {
$this->condition->submitConfigurationForm($form, $form_state);
$config = $this->condition->getConfig();
foreach ($config['bundles'] as $bundle) {
drupal_set_message('Bundle: ' . $bundle);
\Drupal::messenger()->addStatus('Bundle: ' . $bundle);
}
$article = Node::load(1);
$this->condition->setContextValue('node', $article);
if ($this->condition->execute()) {
drupal_set_message(t('Executed successfully.'));
\Drupal::messenger()->addStatus(t('Executed successfully.'));
}
}
@@ -47,7 +47,7 @@ function database_test_schema() {
],
'primary key' => ['id'],
'unique keys' => [
'name' => ['name']
'name' => ['name'],
],
'indexes' => [
'ages' => ['age'],
@@ -148,7 +148,7 @@ function database_test_schema() {
],
'blob2' => [
'description' => 'A second BLOB field.',
'type' => 'blob'
'type' => 'blob',
],
],
'primary key' => ['id'],
@@ -212,7 +212,7 @@ function database_test_schema() {
],
'primary key' => ['id'],
'unique keys' => [
'name' => ['name']
'name' => ['name'],
],
'indexes' => [
'ages' => ['age'],
@@ -242,7 +242,7 @@ function database_test_schema() {
],
'primary key' => ['id'],
'unique keys' => [
'name' => ['name']
'name' => ['name'],
],
];
@@ -287,6 +287,10 @@ function database_test_schema() {
'description' => 'A column with preserved name.',
'type' => 'text',
],
'function' => [
'description' => 'A column with reserved name in MySQL 8.',
'type' => 'text',
],
],
'primary key' => ['id'],
];
@@ -38,7 +38,6 @@ function database_test_query_alter(AlterableInterface $query) {
}
}
/**
* Implements hook_query_TAG_alter().
*
@@ -0,0 +1,6 @@
name: 'Default format test'
type: module
description: 'Support module for testing default route format.'
package: Testing
version: VERSION
core: 8.x
@@ -0,0 +1,28 @@
default_format_test.machine:
path: '/default_format_test/machine'
defaults:
# Same controller + method!
_controller: '\Drupal\default_format_test\DefaultFormatTestController::content'
requirements:
_access: 'TRUE'
_format: 'json'
default_format_test.human:
path: '/default_format_test/human'
defaults:
# Same controller + method!
_controller: '\Drupal\default_format_test\DefaultFormatTestController::content'
requirements:
_access: 'TRUE'
_format: 'html'
# Route definition identical to default_format_test.machine, only different name.
# @see \Drupal\FunctionalTests\Routing\DefaultFormatTest::testMultiple
default_format_test.machine.alias:
path: '/default_format_test/machine'
defaults:
# Same controller + method!
_controller: '\Drupal\default_format_test\DefaultFormatTestController::content'
requirements:
_access: 'TRUE'
_format: 'json'
@@ -0,0 +1,15 @@
<?php
namespace Drupal\default_format_test;
use Drupal\Core\Cache\CacheableResponse;
use Symfony\Component\HttpFoundation\Request;
class DefaultFormatTestController {
public function content(Request $request) {
$format = $request->getRequestFormat();
return new CacheableResponse('format:' . $format, 200, ['Content-Type' => $request->getMimeType($format)]);
}
}
@@ -38,7 +38,6 @@ class WideModalRenderer extends ModalRenderer {
$this->mode = $mode;
}
/**
* {@inheritdoc}
*/
@@ -62,7 +62,7 @@ class EarlyRenderingTestController extends ControllerBase {
'#pre_render' => [function () {
$elements = $this->earlyRenderContent();
return $elements;
}
},
],
];
}
@@ -5,7 +5,7 @@ core: 8.x
package: Testing
version: VERSION
dependencies:
- node
- user
- views
- entity_test
- drupal:node
- drupal:user
- drupal:views
- drupal:entity_test
@@ -5,4 +5,4 @@ package: Testing
version: VERSION
core: 8.x
dependencies:
- views
- drupal:views
@@ -5,4 +5,4 @@ package: Testing
version: VERSION
core: 8.x
dependencies:
- entity_test
- drupal:entity_test
@@ -5,5 +5,5 @@ package: Testing
version: VERSION
core: 8.x
dependencies:
- field
- text
- drupal:field
- drupal:text
@@ -101,6 +101,9 @@ function entity_test_entity_type_alter(array &$entity_types) {
if (!$state->get('entity_test_new')) {
unset($entity_types['entity_test_new']);
}
$entity_test_definition = $entity_types['entity_test'];
$entity_test_definition->set('entity_keys', $state->get('entity_test.entity_keys', []) + $entity_test_definition->getKeys());
}
/**
@@ -303,7 +306,7 @@ function entity_test_entity_extra_field_info() {
'description' => t('An extra field on the display side, hidden by default.'),
'visible' => FALSE,
],
]
],
];
return $extra;
@@ -677,6 +680,23 @@ function entity_test_entity_test_mul_langcode_key_translation_delete(EntityInter
_entity_test_record_hooks('entity_test_mul_langcode_key_translation_delete', $translation->language()->getId());
}
/**
* Implements hook_entity_revision_create().
*/
function entity_test_entity_revision_create(EntityInterface $new_revision, EntityInterface $entity, $keep_untranslatable_fields) {
_entity_test_record_hooks('entity_revision_create', ['new_revision' => $new_revision, 'entity' => $entity, 'keep_untranslatable_fields' => $keep_untranslatable_fields]);
}
/**
* Implements hook_ENTITY_TYPE_revision_create() for 'entity_test_mulrev'.
*/
function entity_test_entity_test_mulrev_revision_create(EntityInterface $new_revision, EntityInterface $entity, $keep_untranslatable_fields) {
if ($new_revision->get('name')->value == 'revision_create_test_it') {
$new_revision->set('name', 'revision_create_test_it_altered');
}
_entity_test_record_hooks('entity_test_mulrev_revision_create', ['new_revision' => $new_revision, 'entity' => $entity, 'keep_untranslatable_fields' => $keep_untranslatable_fields]);
}
/**
* Field default value callback.
*
@@ -95,7 +95,6 @@ class EntityTestController extends ControllerBase {
];
}
/**
* Empty list of entities of the given entity type.
*
@@ -109,7 +109,7 @@ class EntityTest extends ContentEntityBase implements EntityOwnerInterface {
],
]);
return $fields;
return $fields + \Drupal::state()->get($entity_type->id() . '.additional_base_field_definitions', []);
}
/**
@@ -164,4 +164,15 @@ class EntityTest extends ContentEntityBase implements EntityOwnerInterface {
return $this->get('name')->value;
}
/**
* {@inheritdoc}
*/
public function getEntityKey($key) {
// Typically this protected method is used internally by entity classes and
// exposed publicly through more specific getter methods. So that test cases
// are able to set and access entity keys dynamically, update the visibility
// of this method to public.
return parent::getEntityKey($key);
}
}
@@ -4,6 +4,7 @@ namespace Drupal\entity_test\Entity;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\entity_test\Plugin\Field\ComputedReferenceTestFieldItemList;
use Drupal\entity_test\Plugin\Field\ComputedTestFieldItemList;
/**
@@ -39,6 +40,12 @@ class EntityTestComputedField extends EntityTest {
->setComputed(TRUE)
->setClass(ComputedTestFieldItemList::class);
$fields['computed_reference_field'] = BaseFieldDefinition::create('entity_reference')
->setLabel('Computed Reference Field Test')
->setComputed(TRUE)
->setSetting('target_type', 'entity_test')
->setClass(ComputedReferenceTestFieldItemList::class);
return $fields;
}
@@ -0,0 +1,39 @@
<?php
namespace Drupal\entity_test\Entity;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\BaseFieldDefinition;
/**
* An entity used for testing map base field values.
*
* @ContentEntityType(
* id = "entity_test_map_field",
* label = @Translation("Entity Test map field"),
* base_table = "entity_test_map_field",
* entity_keys = {
* "uuid" = "uuid",
* "id" = "id",
* "label" = "name",
* "langcode" = "langcode",
* },
* admin_permission = "administer entity_test content",
* )
*/
class EntityTestMapField extends EntityTest {
/**
* {@inheritdoc}
*/
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields = parent::baseFieldDefinitions($entity_type);
$fields['data'] = BaseFieldDefinition::create('map')
->setLabel(t('Data'))
->setDescription(t('A serialized array of additional data.'));
return $fields;
}
}
@@ -50,7 +50,7 @@ class EntityTestMul extends EntityTest {
* {@inheritdoc}
*/
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
return parent::baseFieldDefinitions($entity_type) + \Drupal::state()->get($entity_type->id() . '.additional_base_field_definitions', []);
return parent::baseFieldDefinitions($entity_type);
}
}
@@ -54,7 +54,7 @@ class EntityTestMulRev extends EntityTestRev {
* {@inheritdoc}
*/
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields = parent::baseFieldDefinitions($entity_type) + \Drupal::state()->get($entity_type->id() . '.additional_base_field_definitions', []);
$fields = parent::baseFieldDefinitions($entity_type);
$fields['non_mul_field'] = BaseFieldDefinition::create('string')
->setLabel(t('Non translatable'))
@@ -17,7 +17,8 @@ use Drupal\Core\Entity\EntityTypeInterface;
* "access" = "Drupal\entity_test\EntityTestAccessControlHandler",
* "form" = {
* "default" = "Drupal\entity_test\EntityTestForm",
* "delete" = "Drupal\entity_test\EntityTestDeleteForm"
* "delete" = "Drupal\entity_test\EntityTestDeleteForm",
* "delete-multiple-confirm" = "Drupal\Core\Entity\Form\DeleteMultipleForm"
* },
* "translation" = "Drupal\content_translation\ContentTranslationHandler",
* "views_data" = "Drupal\views\EntityViewsData",
@@ -45,6 +46,7 @@ use Drupal\Core\Entity\EntityTypeInterface;
* "add-form" = "/entity_test_mulrevpub/add",
* "canonical" = "/entity_test_mulrevpub/manage/{entity_test_mulrevpub}",
* "delete-form" = "/entity_test/delete/entity_test_mulrevpub/{entity_test_mulrevpub}",
* "delete-multiple-form" = "/entity_test/delete",
* "edit-form" = "/entity_test_mulrevpub/manage/{entity_test_mulrevpub}/edit",
* "revision" = "/entity_test_mulrevpub/{entity_test_mulrevpub}/revision/{entity_test_mulrevpub_revision}/view",
* }
@@ -16,7 +16,8 @@ use Drupal\Core\Field\BaseFieldDefinition;
* "view_builder" = "Drupal\entity_test\EntityTestViewBuilder",
* "form" = {
* "default" = "Drupal\entity_test\EntityTestForm",
* "delete" = "Drupal\entity_test\EntityTestDeleteForm"
* "delete" = "Drupal\entity_test\EntityTestDeleteForm",
* "delete-multiple-confirm" = "Drupal\Core\Entity\Form\DeleteMultipleForm"
* },
* "view_builder" = "Drupal\entity_test\EntityTestViewBuilder",
* "translation" = "Drupal\content_translation\ContentTranslationHandler",
@@ -41,6 +42,7 @@ use Drupal\Core\Field\BaseFieldDefinition;
* "add-form" = "/entity_test_rev/add",
* "canonical" = "/entity_test_rev/manage/{entity_test_rev}",
* "delete-form" = "/entity_test/delete/entity_test_rev/{entity_test_rev}",
* "delete-multiple-form" = "/entity_test_rev/delete_multiple",
* "edit-form" = "/entity_test_rev/manage/{entity_test_rev}/edit",
* "revision" = "/entity_test_rev/{entity_test_rev}/revision/{entity_test_rev_revision}/view",
* }
@@ -65,7 +67,7 @@ class EntityTestRev extends EntityTest {
->setCardinality(1)
->setReadOnly(TRUE);
return $fields + \Drupal::state()->get($entity_type->id() . '.additional_base_field_definitions', []);
return $fields;
}
}
@@ -65,7 +65,7 @@ class EntityTestForm extends ContentEntityForm {
else {
$message = t('%entity_type @id has been updated.', ['@id' => $entity->id(), '%entity_type' => $entity->getEntityTypeId()]);
}
drupal_set_message($message);
$this->messenger()->addStatus($message);
if ($entity->id()) {
$entity_type = $entity->getEntityTypeId();
@@ -76,7 +76,7 @@ class EntityTestForm extends ContentEntityForm {
}
else {
// Error on save.
drupal_set_message(t('The entity could not be saved.'), 'error');
$this->messenger()->addError($this->t('The entity could not be saved.'));
$form_state->setRebuild();
}
}
@@ -0,0 +1,24 @@
<?php
namespace Drupal\entity_test\Plugin\Field;
use Drupal\Core\Field\EntityReferenceFieldItemList;
use Drupal\Core\TypedData\ComputedItemListTrait;
/**
* A computed entity reference field item list.
*/
class ComputedReferenceTestFieldItemList extends EntityReferenceFieldItemList {
use ComputedItemListTrait;
/**
* Compute the list property from state.
*/
protected function computeValue() {
foreach (\Drupal::state()->get('entity_test_reference_computed_target_ids', []) as $delta => $id) {
$this->list[$delta] = $this->createItem($delta, $id);
}
}
}
@@ -25,7 +25,7 @@ class ShapeOnlyColorEditableWidget extends WidgetBase {
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
$element['shape'] = [
'#type' => 'hidden',
'#value' => $items[$delta]->shape
'#value' => $items[$delta]->shape,
];
$element['color'] = [
@@ -0,0 +1,32 @@
<?php
namespace Drupal\Tests\entity_test\Functional\Hal;
use Drupal\Tests\entity_test\Functional\Rest\EntityTestBundleResourceTestBase;
use Drupal\Tests\hal\Functional\EntityResource\HalEntityNormalizationTrait;
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
/**
* @group hal
*/
class EntityTestBundleHalJsonAnonTest extends EntityTestBundleResourceTestBase {
use HalEntityNormalizationTrait;
use AnonResourceTestTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['hal'];
/**
* {@inheritdoc}
*/
protected static $format = 'hal_json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/hal+json';
}
@@ -0,0 +1,35 @@
<?php
namespace Drupal\Tests\entity_test\Functional\Hal;
use Drupal\Tests\entity_test\Functional\Rest\EntityTestBundleResourceTestBase;
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
/**
* @group hal
*/
class EntityTestBundleHalJsonBasicAuthTest extends EntityTestBundleResourceTestBase {
use BasicAuthResourceTestTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['hal', 'basic_auth'];
/**
* {@inheritdoc}
*/
protected static $auth = 'basic_auth';
/**
* {@inheritdoc}
*/
protected static $format = 'hal_json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/hal+json';
}
@@ -0,0 +1,35 @@
<?php
namespace Drupal\Tests\entity_test\Functional\Hal;
use Drupal\Tests\entity_test\Functional\Rest\EntityTestBundleResourceTestBase;
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
/**
* @group hal
*/
class EntityTestBundleHalJsonCookieTest extends EntityTestBundleResourceTestBase {
use CookieResourceTestTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['hal'];
/**
* {@inheritdoc}
*/
protected static $auth = 'cookie';
/**
* {@inheritdoc}
*/
protected static $format = 'hal_json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/hal+json';
}
@@ -0,0 +1,93 @@
<?php
namespace Drupal\Tests\entity_test\Functional\Hal;
use Drupal\Tests\entity_test\Functional\Rest\EntityTestResourceTestBase;
use Drupal\Tests\hal\Functional\EntityResource\HalEntityNormalizationTrait;
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\FormatSpecificGetBcRouteTestTrait;
use Drupal\user\Entity\User;
/**
* @group hal
*/
class EntityTestHalJsonAnonTest extends EntityTestResourceTestBase {
use HalEntityNormalizationTrait;
use AnonResourceTestTrait;
use FormatSpecificGetBcRouteTestTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['hal'];
/**
* {@inheritdoc}
*/
protected static $format = 'hal_json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/hal+json';
/**
* {@inheritdoc}
*/
protected function getExpectedNormalizedEntity() {
$default_normalization = parent::getExpectedNormalizedEntity();
$normalization = $this->applyHalFieldNormalization($default_normalization);
$author = User::load(0);
return $normalization + [
'_links' => [
'self' => [
'href' => $this->baseUrl . '/entity_test/1?_format=hal_json',
],
'type' => [
'href' => $this->baseUrl . '/rest/type/entity_test/entity_test',
],
$this->baseUrl . '/rest/relation/entity_test/entity_test/user_id' => [
[
'href' => $this->baseUrl . '/user/0?_format=hal_json',
'lang' => 'en',
],
],
],
'_embedded' => [
$this->baseUrl . '/rest/relation/entity_test/entity_test/user_id' => [
[
'_links' => [
'self' => [
'href' => $this->baseUrl . '/user/0?_format=hal_json',
],
'type' => [
'href' => $this->baseUrl . '/rest/type/user/user',
],
],
'uuid' => [
['value' => $author->uuid()],
],
'lang' => 'en',
],
],
],
];
}
/**
* {@inheritdoc}
*/
protected function getNormalizedPostEntity() {
return parent::getNormalizedPostEntity() + [
'_links' => [
'type' => [
'href' => $this->baseUrl . '/rest/type/entity_test/entity_test',
],
],
];
}
}
@@ -0,0 +1,24 @@
<?php
namespace Drupal\Tests\entity_test\Functional\Hal;
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
/**
* @group hal
*/
class EntityTestHalJsonBasicAuthTest extends EntityTestHalJsonAnonTest {
use BasicAuthResourceTestTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['basic_auth'];
/**
* {@inheritdoc}
*/
protected static $auth = 'basic_auth';
}
@@ -0,0 +1,19 @@
<?php
namespace Drupal\Tests\entity_test\Functional\Hal;
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
/**
* @group hal
*/
class EntityTestHalJsonCookieTest extends EntityTestHalJsonAnonTest {
use CookieResourceTestTrait;
/**
* {@inheritdoc}
*/
protected static $auth = 'cookie';
}
@@ -0,0 +1,100 @@
<?php
namespace Drupal\Tests\entity_test\Functional\Hal;
use Drupal\Core\Cache\Cache;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\Tests\hal\Functional\EntityResource\HalEntityNormalizationTrait;
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
/**
* Test that internal properties are not exposed in the 'hal_json' format.
*
* @group hal
*/
class EntityTestHalJsonInternalPropertyNormalizerTest extends EntityTestHalJsonAnonTest {
use AnonResourceTestTrait, HalEntityNormalizationTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['hal'];
/**
* {@inheritdoc}
*/
protected function getExpectedNormalizedEntity() {
$default_normalization = parent::getExpectedNormalizedEntity();
$normalization = $this->applyHalFieldNormalization($default_normalization);
// The 'internal_value' property in test field type will not be returned in
// normalization because setInternal(FALSE) was not called for this
// property.
// @see \Drupal\entity_test\Plugin\Field\FieldType\InternalPropertyTestFieldItem::propertyDefinitions
$normalization['field_test_internal'] = [
[
'value' => 'This value shall not be internal!',
'non_internal_value' => 'Computed! This value shall not be internal!',
],
];
return $normalization;
}
/**
* {@inheritdoc}
*/
protected function createEntity() {
if (!FieldStorageConfig::loadByName('entity_test', 'field_test_internal')) {
FieldStorageConfig::create([
'entity_type' => 'entity_test',
'field_name' => 'field_test_internal',
'type' => 'internal_property_test',
'cardinality' => 1,
'translatable' => FALSE,
])->save();
FieldConfig::create([
'entity_type' => 'entity_test',
'field_name' => 'field_test_internal',
'bundle' => 'entity_test',
'label' => 'Test field with internal and non-internal properties',
])->save();
}
$entity = parent::createEntity();
$entity->field_test_internal = [
'value' => 'This value shall not be internal!',
];
$entity->save();
return $entity;
}
/**
* {@inheritdoc}
*/
protected function getNormalizedPostEntity() {
return parent::getNormalizedPostEntity() + [
'field_test_internal' => [
[
'value' => 'This value shall not be internal!',
],
],
];
}
/**
* {@inheritdoc}
*/
protected function getExpectedCacheContexts() {
return Cache::mergeContexts(parent::getExpectedCacheContexts(), ['request_format']);
}
/**
* {@inheritdoc}
*/
protected function getExpectedCacheTags() {
return Cache::mergeTags(parent::getExpectedCacheTags(), ['you_are_it', 'no_tag_backs']);
}
}
@@ -0,0 +1,103 @@
<?php
namespace Drupal\Tests\entity_test\Functional\Hal;
use Drupal\Tests\entity_test\Functional\Rest\EntityTestLabelResourceTestBase;
use Drupal\Tests\hal\Functional\EntityResource\HalEntityNormalizationTrait;
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
use Drupal\user\Entity\User;
/**
* @group hal
*/
class EntityTestLabelHalJsonAnonTest extends EntityTestLabelResourceTestBase {
use HalEntityNormalizationTrait;
use AnonResourceTestTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['hal'];
/**
* {@inheritdoc}
*/
protected static $format = 'hal_json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/hal+json';
/**
* {@inheritdoc}
*/
protected function getExpectedNormalizedEntity() {
$default_normalization = parent::getExpectedNormalizedEntity();
$normalization = $this->applyHalFieldNormalization($default_normalization);
$author = User::load(0);
return $normalization + [
'_links' => [
'self' => [
'href' => '',
],
'type' => [
'href' => $this->baseUrl . '/rest/type/entity_test_label/entity_test_label',
],
$this->baseUrl . '/rest/relation/entity_test_label/entity_test_label/user_id' => [
[
'href' => $this->baseUrl . '/user/0?_format=hal_json',
'lang' => 'en',
],
],
],
'_embedded' => [
$this->baseUrl . '/rest/relation/entity_test_label/entity_test_label/user_id' => [
[
'_links' => [
'self' => [
'href' => $this->baseUrl . '/user/0?_format=hal_json',
],
'type' => [
'href' => $this->baseUrl . '/rest/type/user/user',
],
],
'uuid' => [
[
'value' => $author->uuid(),
],
],
'lang' => 'en',
],
],
],
];
}
/**
* {@inheritdoc}
*/
protected function getNormalizedPostEntity() {
return parent::getNormalizedPostEntity() + [
'_links' => [
'type' => [
'href' => $this->baseUrl . '/rest/type/entity_test_label/entity_test_label',
],
],
];
}
/**
* {@inheritdoc}
*/
protected function getExpectedCacheContexts() {
return [
'url.site',
'user.permissions',
];
}
}
@@ -0,0 +1,24 @@
<?php
namespace Drupal\Tests\entity_test\Functional\Hal;
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
/**
* @group hal
*/
class EntityTestLabelHalJsonBasicAuthTest extends EntityTestLabelHalJsonAnonTest {
use BasicAuthResourceTestTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['basic_auth'];
/**
* {@inheritdoc}
*/
protected static $auth = 'basic_auth';
}
@@ -0,0 +1,19 @@
<?php
namespace Drupal\Tests\entity_test\Functional\Hal;
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
/**
* @group hal
*/
class EntityTestLabelHalJsonCookieTest extends EntityTestLabelHalJsonAnonTest {
use CookieResourceTestTrait;
/**
* {@inheritdoc}
*/
protected static $auth = 'cookie';
}
@@ -0,0 +1,103 @@
<?php
namespace Drupal\Tests\entity_test\Functional\Hal;
use Drupal\Tests\entity_test\Functional\Rest\EntityTestMapFieldResourceTestBase;
use Drupal\Tests\hal\Functional\EntityResource\HalEntityNormalizationTrait;
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
use Drupal\user\Entity\User;
/**
* @group hal
*/
class EntityTestMapFieldHalJsonAnonTest extends EntityTestMapFieldResourceTestBase {
use HalEntityNormalizationTrait;
use AnonResourceTestTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['hal'];
/**
* {@inheritdoc}
*/
protected static $format = 'hal_json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/hal+json';
/**
* {@inheritdoc}
*/
protected function getExpectedNormalizedEntity() {
$default_normalization = parent::getExpectedNormalizedEntity();
$normalization = $this->applyHalFieldNormalization($default_normalization);
$author = User::load(0);
return $normalization + [
'_links' => [
'self' => [
'href' => '',
],
'type' => [
'href' => $this->baseUrl . '/rest/type/entity_test_map_field/entity_test_map_field',
],
$this->baseUrl . '/rest/relation/entity_test_map_field/entity_test_map_field/user_id' => [
[
'href' => $this->baseUrl . '/user/0?_format=hal_json',
'lang' => 'en',
],
],
],
'_embedded' => [
$this->baseUrl . '/rest/relation/entity_test_map_field/entity_test_map_field/user_id' => [
[
'_links' => [
'self' => [
'href' => $this->baseUrl . '/user/0?_format=hal_json',
],
'type' => [
'href' => $this->baseUrl . '/rest/type/user/user',
],
],
'uuid' => [
[
'value' => $author->uuid(),
],
],
'lang' => 'en',
],
],
],
];
}
/**
* {@inheritdoc}
*/
protected function getNormalizedPostEntity() {
return parent::getNormalizedPostEntity() + [
'_links' => [
'type' => [
'href' => $this->baseUrl . '/rest/type/entity_test_map_field/entity_test_map_field',
],
],
];
}
/**
* {@inheritdoc}
*/
protected function getExpectedCacheContexts() {
return [
'url.site',
'user.permissions',
];
}
}
@@ -0,0 +1,24 @@
<?php
namespace Drupal\Tests\entity_test\Functional\Rest;
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
/**
* @group rest
*/
class EntityTestBundleJsonAnonTest extends EntityTestBundleResourceTestBase {
use AnonResourceTestTrait;
/**
* {@inheritdoc}
*/
protected static $format = 'json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/json';
}
@@ -0,0 +1,34 @@
<?php
namespace Drupal\Tests\entity_test\Functional\Rest;
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
/**
* @group rest
*/
class EntityTestBundleJsonBasicAuthTest extends EntityTestBundleResourceTestBase {
use BasicAuthResourceTestTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['basic_auth'];
/**
* {@inheritdoc}
*/
protected static $format = 'json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/json';
/**
* {@inheritdoc}
*/
protected static $auth = 'basic_auth';
}
@@ -0,0 +1,29 @@
<?php
namespace Drupal\Tests\entity_test\Functional\Rest;
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
/**
* @group rest
*/
class EntityTestBundleJsonCookieTest extends EntityTestBundleResourceTestBase {
use CookieResourceTestTrait;
/**
* {@inheritdoc}
*/
protected static $format = 'json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/json';
/**
* {@inheritdoc}
*/
protected static $auth = 'cookie';
}
@@ -0,0 +1,76 @@
<?php
namespace Drupal\Tests\entity_test\Functional\Rest;
use Drupal\entity_test\Entity\EntityTestBundle;
use Drupal\Tests\rest\Functional\BcTimestampNormalizerUnixTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase;
abstract class EntityTestBundleResourceTestBase extends EntityResourceTestBase {
use BcTimestampNormalizerUnixTestTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['entity_test'];
/**
* {@inheritdoc}
*/
protected static $entityTypeId = 'entity_test_bundle';
/**
* {@inheritdoc}
*/
protected static $patchProtectedFieldNames = [];
/**
* @var \Drupal\entity_test\Entity\EntityTestBundle
*/
protected $entity;
/**
* {@inheritdoc}
*/
protected function setUpAuthorization($method) {
$this->grantPermissionsToTestedRole(['administer entity_test_bundle content']);
}
/**
* {@inheritdoc}
*/
protected function createEntity() {
$entity_test_bundle = EntityTestBundle::create([
'id' => 'camelids',
'label' => 'Camelids',
'description' => 'Camelids are large, strictly herbivorous animals with slender necks and long legs.',
]);
$entity_test_bundle->save();
return $entity_test_bundle;
}
/**
* {@inheritdoc}
*/
protected function getExpectedNormalizedEntity() {
return [
'dependencies' => [],
'description' => 'Camelids are large, strictly herbivorous animals with slender necks and long legs.',
'id' => 'camelids',
'label' => 'Camelids',
'langcode' => 'en',
'status' => TRUE,
'uuid' => $this->entity->uuid(),
];
}
/**
* {@inheritdoc}
*/
protected function getNormalizedPostEntity() {
// @todo Update in https://www.drupal.org/node/2300677.
}
}
@@ -0,0 +1,26 @@
<?php
namespace Drupal\Tests\entity_test\Functional\Rest;
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
/**
* @group rest
*/
class EntityTestBundleXmlAnonTest extends EntityTestBundleResourceTestBase {
use AnonResourceTestTrait;
use XmlEntityNormalizationQuirksTrait;
/**
* {@inheritdoc}
*/
protected static $format = 'xml';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'text/xml; charset=UTF-8';
}
@@ -0,0 +1,36 @@
<?php
namespace Drupal\Tests\entity_test\Functional\Rest;
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
/**
* @group rest
*/
class EntityTestBundleXmlBasicAuthTest extends EntityTestBundleResourceTestBase {
use BasicAuthResourceTestTrait;
use XmlEntityNormalizationQuirksTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['basic_auth'];
/**
* {@inheritdoc}
*/
protected static $format = 'xml';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'text/xml; charset=UTF-8';
/**
* {@inheritdoc}
*/
protected static $auth = 'basic_auth';
}
@@ -0,0 +1,31 @@
<?php
namespace Drupal\Tests\entity_test\Functional\Rest;
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
/**
* @group rest
*/
class EntityTestBundleXmlCookieTest extends EntityTestBundleResourceTestBase {
use CookieResourceTestTrait;
use XmlEntityNormalizationQuirksTrait;
/**
* {@inheritdoc}
*/
protected static $format = 'xml';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'text/xml; charset=UTF-8';
/**
* {@inheritdoc}
*/
protected static $auth = 'cookie';
}
@@ -0,0 +1,26 @@
<?php
namespace Drupal\Tests\entity_test\Functional\Rest;
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\FormatSpecificGetBcRouteTestTrait;
/**
* @group rest
*/
class EntityTestJsonAnonTest extends EntityTestResourceTestBase {
use AnonResourceTestTrait;
use FormatSpecificGetBcRouteTestTrait;
/**
* {@inheritdoc}
*/
protected static $format = 'json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/json';
}
@@ -0,0 +1,34 @@
<?php
namespace Drupal\Tests\entity_test\Functional\Rest;
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
/**
* @group rest
*/
class EntityTestJsonBasicAuthTest extends EntityTestResourceTestBase {
use BasicAuthResourceTestTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['basic_auth'];
/**
* {@inheritdoc}
*/
protected static $format = 'json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/json';
/**
* {@inheritdoc}
*/
protected static $auth = 'basic_auth';
}
@@ -0,0 +1,29 @@
<?php
namespace Drupal\Tests\entity_test\Functional\Rest;
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
/**
* @group rest
*/
class EntityTestJsonCookieTest extends EntityTestResourceTestBase {
use CookieResourceTestTrait;
/**
* {@inheritdoc}
*/
protected static $format = 'json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/json';
/**
* {@inheritdoc}
*/
protected static $auth = 'cookie';
}
@@ -0,0 +1,102 @@
<?php
namespace Drupal\Tests\entity_test\Functional\Rest;
use Drupal\Core\Cache\Cache;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
/**
* Test that internal properties are not exposed in the 'json' format.
*
* @group rest
*/
class EntityTestJsonInternalPropertyNormalizerTest extends EntityTestResourceTestBase {
use AnonResourceTestTrait;
/**
* {@inheritdoc}
*/
protected static $format = 'json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/json';
/**
* {@inheritdoc}
*/
protected function getExpectedNormalizedEntity() {
$expected = parent::getExpectedNormalizedEntity();
// The 'internal_value' property in test field type is not exposed in the
// normalization because setInternal(FALSE) was not called for this
// property.
// @see \Drupal\entity_test\Plugin\Field\FieldType\InternalPropertyTestFieldItem::propertyDefinitions
$expected['field_test_internal'] = [
[
'value' => 'This value shall not be internal!',
'non_internal_value' => 'Computed! This value shall not be internal!',
],
];
return $expected;
}
/**
* {@inheritdoc}
*/
protected function createEntity() {
if (!FieldStorageConfig::loadByName('entity_test', 'field_test_internal')) {
FieldStorageConfig::create([
'entity_type' => 'entity_test',
'field_name' => 'field_test_internal',
'type' => 'internal_property_test',
'cardinality' => 1,
'translatable' => FALSE,
])->save();
FieldConfig::create([
'entity_type' => 'entity_test',
'field_name' => 'field_test_internal',
'bundle' => 'entity_test',
'label' => 'Test field with internal and non-internal properties',
])->save();
}
$entity = parent::createEntity();
$entity->field_test_internal = [
'value' => 'This value shall not be internal!',
];
$entity->save();
return $entity;
}
/**
* {@inheritdoc}
*/
protected function getNormalizedPostEntity() {
return parent::getNormalizedPostEntity() + [
'field_test_internal' => [
[
'value' => 'This value shall not be internal!',
],
],
];
}
/**
* {@inheritdoc}
*/
protected function getExpectedCacheContexts() {
return Cache::mergeContexts(parent::getExpectedCacheContexts(), ['request_format']);
}
/**
* {@inheritdoc}
*/
protected function getExpectedCacheTags() {
return Cache::mergeTags(parent::getExpectedCacheTags(), ['you_are_it', 'no_tag_backs']);
}
}
@@ -0,0 +1,24 @@
<?php
namespace Drupal\Tests\entity_test\Functional\Rest;
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
/**
* @group rest
*/
class EntityTestLabelJsonAnonTest extends EntityTestLabelResourceTestBase {
use AnonResourceTestTrait;
/**
* {@inheritdoc}
*/
protected static $format = 'json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/json';
}
@@ -0,0 +1,34 @@
<?php
namespace Drupal\Tests\entity_test\Functional\Rest;
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
/**
* @group rest
*/
class EntityTestLabelJsonBasicAuthTest extends EntityTestLabelResourceTestBase {
use BasicAuthResourceTestTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['basic_auth'];
/**
* {@inheritdoc}
*/
protected static $format = 'json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/json';
/**
* {@inheritdoc}
*/
protected static $auth = 'basic_auth';
}
@@ -0,0 +1,29 @@
<?php
namespace Drupal\Tests\entity_test\Functional\Rest;
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
/**
* @group rest
*/
class EntityTestLabelJsonCookieTest extends EntityTestLabelResourceTestBase {
use CookieResourceTestTrait;
/**
* {@inheritdoc}
*/
protected static $format = 'json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/json';
/**
* {@inheritdoc}
*/
protected static $auth = 'cookie';
}
@@ -0,0 +1,161 @@
<?php
namespace Drupal\Tests\entity_test\Functional\Rest;
use Drupal\entity_test\Entity\EntityTestLabel;
use Drupal\Tests\rest\Functional\BcTimestampNormalizerUnixTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase;
use Drupal\user\Entity\User;
abstract class EntityTestLabelResourceTestBase extends EntityResourceTestBase {
use BcTimestampNormalizerUnixTestTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['entity_test'];
/**
* {@inheritdoc}
*/
protected static $entityTypeId = 'entity_test_label';
/**
* {@inheritdoc}
*/
protected static $patchProtectedFieldNames = [];
/**
* @var \Drupal\entity_test\Entity\EntityTestLabel
*/
protected $entity;
/**
* {@inheritdoc}
*/
protected function setUpAuthorization($method) {
switch ($method) {
case 'GET':
$this->grantPermissionsToTestedRole(['view test entity']);
break;
case 'POST':
$this->grantPermissionsToTestedRole([
'administer entity_test content',
'administer entity_test_with_bundle content',
'create entity_test entity_test_with_bundle entities',
]);
break;
case 'PATCH':
case 'DELETE':
$this->grantPermissionsToTestedRole(['administer entity_test content']);
break;
}
}
/**
* {@inheritdoc}
*/
protected function createEntity() {
$entity_test_label = EntityTestLabel::create([
'name' => 'label_llama',
]);
$entity_test_label->setOwnerId(0);
$entity_test_label->save();
return $entity_test_label;
}
/**
* {@inheritdoc}
*/
protected function getExpectedNormalizedEntity() {
$author = User::load(0);
$normalization = [
'uuid' => [
[
'value' => $this->entity->uuid(),
],
],
'id' => [
[
'value' => (int) $this->entity->id(),
],
],
'langcode' => [
[
'value' => 'en',
],
],
'type' => [
[
'value' => 'entity_test_label',
],
],
'name' => [
[
'value' => 'label_llama',
],
],
'created' => [
$this->formatExpectedTimestampItemValues((int) $this->entity->get('created')->value),
],
'user_id' => [
[
'target_id' => (int) $author->id(),
'target_type' => 'user',
'target_uuid' => $author->uuid(),
'url' => $author->toUrl()->toString(),
],
],
];
return $normalization;
}
/**
* {@inheritdoc}
*/
protected function getNormalizedPostEntity() {
return [
'type' => [
[
'value' => 'entity_test_label',
],
],
'name' => [
[
'value' => 'label_llama',
],
],
];
}
/**
* {@inheritdoc}
*/
protected function getExpectedCacheContexts() {
return ['user.permissions'];
}
/**
* {@inheritdoc}
*/
protected function getExpectedUnauthorizedAccessMessage($method) {
if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) {
return parent::getExpectedUnauthorizedAccessMessage($method);
}
switch ($method) {
case 'GET':
return "The 'view test entity' permission is required.";
case 'POST':
return "The following permissions are required: 'administer entity_test content' OR 'administer entity_test_with_bundle content' OR 'create entity_test_label entity_test_with_bundle entities'.";
case 'PATCH':
case 'DELETE':
return "The 'administer entity_test content' permission is required.";
default:
return parent::getExpectedUnauthorizedAccessMessage($method);
}
}
}
@@ -0,0 +1,26 @@
<?php
namespace Drupal\Tests\entity_test\Functional\Rest;
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
/**
* @group rest
*/
class EntityTestLabelXmlAnonTest extends EntityTestLabelResourceTestBase {
use AnonResourceTestTrait;
use XmlEntityNormalizationQuirksTrait;
/**
* {@inheritdoc}
*/
protected static $format = 'xml';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'text/xml; charset=UTF-8';
}
@@ -0,0 +1,36 @@
<?php
namespace Drupal\Tests\entity_test\Functional\Rest;
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
/**
* @group rest
*/
class EntityTestLabelXmlBasicAuthTest extends EntityTestLabelResourceTestBase {
use BasicAuthResourceTestTrait;
use XmlEntityNormalizationQuirksTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['basic_auth'];
/**
* {@inheritdoc}
*/
protected static $format = 'xml';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'text/xml; charset=UTF-8';
/**
* {@inheritdoc}
*/
protected static $auth = 'basic_auth';
}
@@ -0,0 +1,31 @@
<?php
namespace Drupal\Tests\entity_test\Functional\Rest;
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
/**
* @group rest
*/
class EntityTestLabelXmlCookieTest extends EntityTestLabelResourceTestBase {
use CookieResourceTestTrait;
use XmlEntityNormalizationQuirksTrait;
/**
* {@inheritdoc}
*/
protected static $format = 'xml';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'text/xml; charset=UTF-8';
/**
* {@inheritdoc}
*/
protected static $auth = 'cookie';
}
@@ -0,0 +1,24 @@
<?php
namespace Drupal\Tests\entity_test\Functional\Rest;
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
/**
* @group rest
*/
class EntityTestMapFieldJsonAnonTest extends EntityTestMapFieldResourceTestBase {
use AnonResourceTestTrait;
/**
* {@inheritdoc}
*/
protected static $format = 'json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/json';
}
@@ -0,0 +1,152 @@
<?php
namespace Drupal\Tests\entity_test\Functional\Rest;
use Drupal\entity_test\Entity\EntityTestMapField;
use Drupal\Tests\rest\Functional\BcTimestampNormalizerUnixTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase;
use Drupal\Tests\Traits\ExpectDeprecationTrait;
use Drupal\user\Entity\User;
abstract class EntityTestMapFieldResourceTestBase extends EntityResourceTestBase {
use BcTimestampNormalizerUnixTestTrait;
use ExpectDeprecationTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['entity_test'];
/**
* {@inheritdoc}
*/
protected static $entityTypeId = 'entity_test_map_field';
/**
* {@inheritdoc}
*/
protected static $patchProtectedFieldNames = [];
/**
* @var \Drupal\entity_test\Entity\EntityTestMapField
*/
protected $entity;
/**
* The complex nested value to assign to a @FieldType=map field.
*
* @var array
*/
protected static $mapValue = [
'key1' => 'value',
'key2' => 'no, val you',
'π' => 3.14159,
TRUE => 42,
'nested' => [
'bird' => 'robin',
'doll' => 'Russian',
],
];
/**
* {@inheritdoc}
*/
protected function setUpAuthorization($method) {
$this->grantPermissionsToTestedRole(['administer entity_test content']);
}
/**
* {@inheritdoc}
*/
protected function createEntity() {
$entity = EntityTestMapField::create([
'name' => 'Llama',
'type' => 'entity_test_map_field',
'data' => [
static::$mapValue,
],
]);
$entity->setOwnerId(0);
$entity->save();
return $entity;
}
/**
* {@inheritdoc}
*/
protected function getExpectedNormalizedEntity() {
$author = User::load(0);
return [
'uuid' => [
[
'value' => $this->entity->uuid(),
],
],
'id' => [
[
'value' => 1,
],
],
'name' => [
[
'value' => 'Llama',
],
],
'langcode' => [
[
'value' => 'en',
],
],
'created' => [
$this->formatExpectedTimestampItemValues((int) $this->entity->get('created')->value),
],
'user_id' => [
[
'target_id' => (int) $author->id(),
'target_type' => 'user',
'target_uuid' => $author->uuid(),
'url' => $author->toUrl()->toString(),
],
],
'data' => [
static::$mapValue,
],
];
}
/**
* {@inheritdoc}
*/
protected function getNormalizedPostEntity() {
return [
'name' => [
[
'value' => 'Dramallama',
],
],
'data' => [
0 => static::$mapValue,
],
];
}
/**
* {@inheritdoc}
*/
protected function getExpectedUnauthorizedAccessMessage($method) {
if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) {
return parent::getExpectedUnauthorizedAccessMessage($method);
}
return "The 'administer entity_test content' permission is required.";
}
/**
* {@inheritdoc}
*/
protected function getExpectedCacheContexts() {
return ['user.permissions'];
}
}
@@ -0,0 +1,163 @@
<?php
namespace Drupal\Tests\entity_test\Functional\Rest;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\Tests\rest\Functional\BcTimestampNormalizerUnixTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase;
use Drupal\Tests\Traits\ExpectDeprecationTrait;
use Drupal\user\Entity\User;
abstract class EntityTestResourceTestBase extends EntityResourceTestBase {
use BcTimestampNormalizerUnixTestTrait;
use ExpectDeprecationTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['entity_test'];
/**
* {@inheritdoc}
*/
protected static $entityTypeId = 'entity_test';
/**
* {@inheritdoc}
*/
protected static $patchProtectedFieldNames = [];
/**
* @var \Drupal\entity_test\Entity\EntityTest
*/
protected $entity;
/**
* {@inheritdoc}
*/
protected function setUpAuthorization($method) {
switch ($method) {
case 'GET':
$this->grantPermissionsToTestedRole(['view test entity']);
break;
case 'POST':
$this->grantPermissionsToTestedRole(['create entity_test entity_test_with_bundle entities']);
break;
case 'PATCH':
case 'DELETE':
$this->grantPermissionsToTestedRole(['administer entity_test content']);
break;
}
}
/**
* {@inheritdoc}
*/
protected function createEntity() {
// Set flag so that internal field 'internal_string_field' is created.
// @see entity_test_entity_base_field_info()
$this->container->get('state')->set('entity_test.internal_field', TRUE);
\Drupal::entityDefinitionUpdateManager()->applyUpdates();
$entity_test = EntityTest::create([
'name' => 'Llama',
'type' => 'entity_test',
// Set a value for the internal field to confirm that it will not be
// returned in normalization.
// @see entity_test_entity_base_field_info().
'internal_string_field' => [
'value' => 'This value shall not be internal!',
],
]);
$entity_test->setOwnerId(0);
$entity_test->save();
return $entity_test;
}
/**
* {@inheritdoc}
*/
protected function getExpectedNormalizedEntity() {
$author = User::load(0);
$normalization = [
'uuid' => [
[
'value' => $this->entity->uuid(),
],
],
'id' => [
[
'value' => 1,
],
],
'langcode' => [
[
'value' => 'en',
],
],
'type' => [
[
'value' => 'entity_test',
],
],
'name' => [
[
'value' => 'Llama',
],
],
'created' => [
$this->formatExpectedTimestampItemValues((int) $this->entity->get('created')->value),
],
'user_id' => [
[
'target_id' => (int) $author->id(),
'target_type' => 'user',
'target_uuid' => $author->uuid(),
'url' => $author->toUrl()->toString(),
],
],
'field_test_text' => [],
];
return $normalization;
}
/**
* {@inheritdoc}
*/
protected function getNormalizedPostEntity() {
return [
'type' => [
[
'value' => 'entity_test',
],
],
'name' => [
[
'value' => 'Dramallama',
],
],
];
}
/**
* {@inheritdoc}
*/
protected function getExpectedUnauthorizedAccessMessage($method) {
if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) {
return parent::getExpectedUnauthorizedAccessMessage($method);
}
switch ($method) {
case 'GET':
return "The 'view test entity' permission is required.";
case 'POST':
return "The following permissions are required: 'administer entity_test content' OR 'administer entity_test_with_bundle content' OR 'create entity_test entity_test_with_bundle entities'.";
default:
return parent::getExpectedUnauthorizedAccessMessage($method);
}
}
}
@@ -0,0 +1,195 @@
<?php
namespace Drupal\Tests\entity_test\Functional\Rest;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Language\LanguageInterface;
use Drupal\filter\Entity\FilterFormat;
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
/**
* @group rest
*/
class EntityTestTextItemNormalizerTest extends EntityTestResourceTestBase {
use AnonResourceTestTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['filter_test'];
/**
* {@inheritdoc}
*/
protected static $format = 'json';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'application/json';
/**
* {@inheritdoc}
*/
protected function setUpAuthorization($method) {
parent::setUpAuthorization($method);
if (in_array($method, ['POST', 'PATCH'], TRUE)) {
$this->grantPermissionsToTestedRole(['use text format my_text_format']);
}
}
/**
* {@inheritdoc}
*/
protected function getExpectedNormalizedEntity() {
$expected = parent::getExpectedNormalizedEntity();
$expected['field_test_text'] = [
[
'value' => 'Cádiz is the oldest continuously inhabited city in Spain and a nice place to spend a Sunday with friends.',
'format' => 'my_text_format',
'processed' => '<p>Cádiz is the oldest continuously inhabited city in Spain and a nice place to spend a Sunday with friends.</p>' . "\n" . '<p>This is a dynamic llama.</p>',
],
];
return $expected;
}
/**
* {@inheritdoc}
*/
protected function createEntity() {
$entity = parent::createEntity();
if (!FilterFormat::load('my_text_format')) {
FilterFormat::create([
'format' => 'my_text_format',
'name' => 'My Text Format',
'filters' => [
'filter_test_assets' => [
'weight' => -1,
'status' => TRUE,
],
'filter_test_cache_tags' => [
'weight' => 0,
'status' => TRUE,
],
'filter_test_cache_contexts' => [
'weight' => 0,
'status' => TRUE,
],
'filter_test_cache_merge' => [
'weight' => 0,
'status' => TRUE,
],
'filter_test_placeholders' => [
'weight' => 1,
'status' => TRUE,
],
'filter_autop' => [
'status' => TRUE,
],
],
])->save();
}
$entity->field_test_text = [
'value' => 'Cádiz is the oldest continuously inhabited city in Spain and a nice place to spend a Sunday with friends.',
'format' => 'my_text_format',
];
$entity->save();
return $entity;
}
/**
* {@inheritdoc}
*/
protected function getNormalizedPostEntity() {
$post_entity = parent::getNormalizedPostEntity();
$post_entity['field_test_text'] = [
[
'value' => 'Llamas are awesome.',
'format' => 'my_text_format',
],
];
return $post_entity;
}
/**
* {@inheritdoc}
*/
protected function getExpectedCacheTags() {
return Cache::mergeTags([
// The cache tag set by the processed_text element itself.
'config:filter.format.my_text_format',
// The cache tags set by the filter_test_cache_tags filter.
'foo:bar',
'foo:baz',
// The cache tags set by the filter_test_cache_merge filter.
'merge:tag',
], parent::getExpectedCacheTags());
}
/**
* {@inheritdoc}
*/
protected function getExpectedCacheContexts() {
return Cache::mergeContexts([
// The cache context set by the filter_test_cache_contexts filter.
'languages:' . LanguageInterface::TYPE_CONTENT,
// The default cache contexts for Renderer.
'languages:' . LanguageInterface::TYPE_INTERFACE,
'theme',
// The cache tags set by the filter_test_cache_merge filter.
'user.permissions',
], parent::getExpectedCacheContexts());
}
/**
* Tests GETting an entity with the test text field set to a specific format.
*
* @dataProvider providerTestGetWithFormat
*/
public function testGetWithFormat($text_format_id, array $expected_cache_tags) {
FilterFormat::create([
'name' => 'Pablo Piccasso',
'format' => 'pablo',
'langcode' => 'es',
'filters' => [],
])->save();
// Set TextItemBase field's value for testing, using the given text format.
$value = [
'value' => $this->randomString(),
];
if ($text_format_id !== FALSE) {
$value['format'] = $text_format_id;
}
$this->entity->set('field_test_text', $value)->save();
$this->initAuthentication();
$url = $this->getEntityResourceUrl();
$url->setOption('query', ['_format' => static::$format]);
$request_options = $this->getAuthenticationRequestOptions('GET');
$this->provisionEntityResource();
$this->setUpAuthorization('GET');
$response = $this->request('GET', $url, $request_options);
$expected_cache_tags = Cache::mergeTags($expected_cache_tags, parent::getExpectedCacheTags());
$this->assertSame($expected_cache_tags, explode(' ', $response->getHeader('X-Drupal-Cache-Tags')[0]));
}
public function providerTestGetWithFormat() {
return [
'format specified (different from fallback format)' => [
'pablo',
['config:filter.format.pablo'],
],
'format specified (happens to be the same as fallback format)' => [
'plain_text',
['config:filter.format.plain_text'],
],
'no format specified: fallback format used automatically' => [
FALSE,
['config:filter.format.plain_text', 'config:filter.settings'],
],
];
}
}
@@ -0,0 +1,28 @@
<?php
namespace Drupal\Tests\entity_test\Functional\Rest;
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\FormatSpecificGetBcRouteTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
/**
* @group rest
*/
class EntityTestXmlAnonTest extends EntityTestResourceTestBase {
use AnonResourceTestTrait;
use FormatSpecificGetBcRouteTestTrait;
use XmlEntityNormalizationQuirksTrait;
/**
* {@inheritdoc}
*/
protected static $format = 'xml';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'text/xml; charset=UTF-8';
}
@@ -0,0 +1,36 @@
<?php
namespace Drupal\Tests\entity_test\Functional\Rest;
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
/**
* @group rest
*/
class EntityTestXmlBasicAuthTest extends EntityTestResourceTestBase {
use BasicAuthResourceTestTrait;
use XmlEntityNormalizationQuirksTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['basic_auth'];
/**
* {@inheritdoc}
*/
protected static $format = 'xml';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'text/xml; charset=UTF-8';
/**
* {@inheritdoc}
*/
protected static $auth = 'basic_auth';
}
@@ -0,0 +1,31 @@
<?php
namespace Drupal\Tests\entity_test\Functional\Rest;
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
/**
* @group rest
*/
class EntityTestXmlCookieTest extends EntityTestResourceTestBase {
use CookieResourceTestTrait;
use XmlEntityNormalizationQuirksTrait;
/**
* {@inheritdoc}
*/
protected static $format = 'xml';
/**
* {@inheritdoc}
*/
protected static $mimeType = 'text/xml; charset=UTF-8';
/**
* {@inheritdoc}
*/
protected static $auth = 'cookie';
}
@@ -5,4 +5,4 @@ package: Testing
version: VERSION
core: 8.x
dependencies:
- entity_test
- drupal:entity_test
@@ -5,4 +5,4 @@ package: Testing
version: VERSION
core: 8.x
dependencies:
- entity_test
- drupal:entity_test
@@ -5,4 +5,4 @@ package: Testing
version: VERSION
core: 8.x
dependencies:
- entity_test_update
- drupal:entity_test_update
@@ -5,4 +5,4 @@ package: Testing
version: VERSION
core: 8.x
dependencies:
- entity_test
- drupal:entity_test
@@ -99,7 +99,7 @@ function entity_test_update_entity_presave(EntityInterface $entity) {
*/
function _entity_test_update_create_test_entities($start = 1, $end = 50, $add_translation = FALSE) {
for ($i = $start; $i <= $end; $i++) {
$entity = EntityTestUpdate::create([
$entity = EntityTestUpdate::create([
'id' => $i,
'name' => $i,
'test_single_property' => $i . ' - test single property',
@@ -13,7 +13,8 @@ use Drupal\Core\StringTranslation\TranslatableMarkup;
*
* This entity type starts out non-revisionable and non-translatable, but during
* an update test it can be made revisionable and translatable using the helper
* methods from \Drupal\system\Tests\Entity\EntityDefinitionTestTrait.
* methods from
* \Drupal\Tests\system\Functional\Entity\Traits\EntityDefinitionTestTrait.
*
* @ContentEntityType(
* id = "entity_test_update",
@@ -18,7 +18,7 @@ class EntityTestUpdateStorageSchema extends SqlContentEntityStorageSchema {
$schema = parent::getEntitySchema($entity_type, $reset);
if ($entity_type->id() == 'entity_test_update') {
$schema[$entity_type->getBaseTable()]['indexes'] += \Drupal::state()->get('entity_test_update.additional_entity_indexes', []);
$schema[$this->storage->getBaseTable()]['indexes'] += \Drupal::state()->get('entity_test_update.additional_entity_indexes', []);
}
return $schema;
}
@@ -8,41 +8,17 @@
use Drupal\Core\Field\BaseFieldDefinition;
/**
* Implements hook_update_dependencies().
*/
function entity_test_update_update_dependencies() {
// The update function that adds the status field must run after
// content_translation_update_8400() which fixes NULL values for the
// 'content_translation_status' field.
$dependencies['entity_test_update'][8400] = [
'content_translation' => 8400,
];
return $dependencies;
}
/**
* Add the 'published' and revisionable metadata fields to entity_test_update.
* Add the 'published' entity key to entity_test_update.
*/
function entity_test_update_update_8400() {
$definition_update_manager = \Drupal::entityDefinitionUpdateManager();
// Add the published entity key and revisionable metadata fields to the
// entity_test_update entity type.
// Add the published entity key to the entity_test_update entity type.
$entity_type = $definition_update_manager->getEntityType('entity_test_update');
$entity_keys = $entity_type->getKeys();
$entity_keys['published'] = 'status';
$entity_type->set('entity_keys', $entity_keys);
$revision_metadata_keys = [
'revision_user' => 'revision_user',
'revision_created' => 'revision_created',
'revision_log_message' => 'revision_log_message',
'revision_default' => 'revision_default',
];
$entity_type->set('revision_metadata_keys', $revision_metadata_keys);
$definition_update_manager->updateEntityType($entity_type);
// Add the status field.
@@ -55,41 +31,13 @@ function entity_test_update_update_8400() {
$has_content_translation_status_field = \Drupal::moduleHandler()->moduleExists('content_translation') && $definition_update_manager->getFieldStorageDefinition('content_translation_status', 'entity_test_update');
if ($has_content_translation_status_field) {
$status->setInitialValueFromField('content_translation_status');
$status->setInitialValueFromField('content_translation_status', TRUE);
}
else {
$status->setInitialValue(TRUE);
}
$definition_update_manager->installFieldStorageDefinition('status', 'entity_test_update', 'entity_test_update', $status);
// Add the revision metadata fields.
$revision_created = BaseFieldDefinition::create('created')
->setLabel(t('Revision create time'))
->setDescription(t('The time that the current revision was created.'))
->setRevisionable(TRUE);
$definition_update_manager->installFieldStorageDefinition('revision_created', 'entity_test_update', 'entity_test_update', $revision_created);
$revision_user = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Revision user'))
->setDescription(t('The user ID of the author of the current revision.'))
->setSetting('target_type', 'user')
->setRevisionable(TRUE);
$definition_update_manager->installFieldStorageDefinition('revision_user', 'entity_test_update', 'entity_test_update', $revision_user);
$revision_log_message = BaseFieldDefinition::create('string_long')
->setLabel(t('Revision log message'))
->setDescription(t('Briefly describe the changes you have made.'))
->setRevisionable(TRUE)
->setDefaultValue('')
->setDisplayOptions('form', [
'type' => 'string_textarea',
'weight' => 25,
'settings' => [
'rows' => 4,
],
]);
$definition_update_manager->installFieldStorageDefinition('revision_log_message', 'entity_test_update', 'entity_test_update', $revision_log_message);
// Uninstall the 'content_translation_status' field if needed.
$database = \Drupal::database();
if ($has_content_translation_status_field) {
@@ -14,7 +14,7 @@ class ErrorTestController extends ControllerBase {
/**
* The database connection.
*
* @var \Drupal\Core\Database\Connection;
* @var \Drupal\Core\Database\Connection
*/
protected $database;
@@ -88,7 +88,7 @@ class ErrorTestController extends ControllerBase {
'#post_render' => [
function () {
throw new \Exception('This is an exception that occurs during rendering');
}
},
],
];
}
@@ -3,6 +3,6 @@ type: module
description: 'Module with a dependency in the experimental package.'
package: Testing
dependencies:
- experimental_module_test
- drupal:experimental_module_test
version: VERSION
core: 8.x
@@ -4,3 +4,6 @@ description: 'Support module for Form API tests.'
package: Testing
version: VERSION
core: 8.x
dependencies:
- file
- filter
@@ -11,7 +11,7 @@ use Drupal\Core\Form\FormStateInterface;
* Implements hook_form_FORM_ID_alter() on behalf of block.module.
*/
function block_form_form_test_alter_form_alter(&$form, FormStateInterface $form_state) {
drupal_set_message('block_form_form_test_alter_form_alter() executed.');
\Drupal::messenger()->addStatus('block_form_form_test_alter_form_alter() executed.');
}
/**
@@ -19,7 +19,7 @@ function block_form_form_test_alter_form_alter(&$form, FormStateInterface $form_
*/
function form_test_form_alter(&$form, FormStateInterface $form_state, $form_id) {
if ($form_id == 'form_test_alter_form') {
drupal_set_message('form_test_form_alter() executed.');
\Drupal::messenger()->addStatus('form_test_form_alter() executed.');
}
}
@@ -27,14 +27,14 @@ function form_test_form_alter(&$form, FormStateInterface $form_state, $form_id)
* Implements hook_form_FORM_ID_alter().
*/
function form_test_form_form_test_alter_form_alter(&$form, FormStateInterface $form_state) {
drupal_set_message('form_test_form_form_test_alter_form_alter() executed.');
\Drupal::messenger()->addStatus('form_test_form_form_test_alter_form_alter() executed.');
}
/**
* Implements hook_form_FORM_ID_alter() on behalf of system.module.
*/
function system_form_form_test_alter_form_alter(&$form, FormStateInterface $form_state) {
drupal_set_message('system_form_form_test_alter_form_alter() executed.');
\Drupal::messenger()->addStatus('system_form_form_test_alter_form_alter() executed.');
}
/**
@@ -90,7 +90,7 @@ function form_test_form_user_register_form_alter(&$form, FormStateInterface $for
* Submit callback that just lets the form rebuild.
*/
function form_test_user_register_form_rebuild($form, FormStateInterface $form_state) {
drupal_set_message('Form rebuilt.');
\Drupal::messenger()->addStatus('Form rebuilt.');
$form_state->setRebuild();
}
@@ -498,6 +498,14 @@ form_test.get_form:
requirements:
_access: 'TRUE'
form_test.machine_name_validation:
path: '/form-test/form-test-machine-name-validation'
defaults:
_form: '\Drupal\form_test\Form\FormTestMachineNameValidationForm'
_title: 'Form machine name validation test'
requirements:
_access: 'TRUE'
form_test.optional_container:
path: '/form-test/optional-container'
defaults:
@@ -38,7 +38,7 @@ class Callbacks {
if ($triggered) {
// Output the element's value from $form_state.
drupal_set_message(t('@label value: @value', ['@label' => $element['#title'], '@value' => $form_state->getValue('name')]));
\Drupal::messenger()->addStatus(t('@label value: @value', ['@label' => $element['#title'], '@value' => $form_state->getValue('name')]));
// Trigger a form validation error to see our changes.
$form_state->setErrorByName('');
@@ -68,7 +68,7 @@ class ConfirmFormTestForm extends ConfirmFormBase {
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
drupal_set_message($this->t('The ConfirmFormTestForm::submitForm() method was used for this form.'));
$this->messenger()->addStatus($this->t('The ConfirmFormTestForm::submitForm() method was used for this form.'));
$form_state->setRedirect('<front>');
}

Some files were not shown because too many files have changed in this diff Show More