updated core from 8.4 to 8.5 : bug with login_destination
This commit is contained in:
Vendored
+203
@@ -0,0 +1,203 @@
|
||||
<?php
|
||||
// @codingStandardsIgnoreFile
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains SQL necessary to add a deleted field to the node entity type.
|
||||
*/
|
||||
|
||||
use Drupal\Core\Database\Database;
|
||||
|
||||
$connection = Database::getConnection();
|
||||
|
||||
// Add the field schema data and the deleted field definitions.
|
||||
$connection->insert('key_value')
|
||||
->fields([
|
||||
'collection',
|
||||
'name',
|
||||
'value',
|
||||
])
|
||||
->values([
|
||||
'collection' => 'entity.storage_schema.sql',
|
||||
'name' => 'node.field_schema_data.field_test',
|
||||
'value' => 'a:2:{s:16:"node__field_test";a:4:{s:11:"description";s:39:"Data storage for node field field_test.";s:6:"fields";a:7:{s:6:"bundle";a:5:{s:4:"type";s:13:"varchar_ascii";s:6:"length";i:128;s:8:"not null";b:1;s:7:"default";s:0:"";s:11:"description";s:88:"The field instance bundle to which this row belongs, used when deleting a field instance";}s:7:"deleted";a:5:{s:4:"type";s:3:"int";s:4:"size";s:4:"tiny";s:8:"not null";b:1;s:7:"default";i:0;s:11:"description";s:60:"A boolean indicating whether this data item has been deleted";}s:9:"entity_id";a:4:{s:4:"type";s:3:"int";s:8:"unsigned";b:1;s:8:"not null";b:1;s:11:"description";s:38:"The entity id this data is attached to";}s:11:"revision_id";a:4:{s:4:"type";s:3:"int";s:8:"unsigned";b:1;s:8:"not null";b:1;s:11:"description";s:47:"The entity revision id this data is attached to";}s:8:"langcode";a:5:{s:4:"type";s:13:"varchar_ascii";s:6:"length";i:32;s:8:"not null";b:1;s:7:"default";s:0:"";s:11:"description";s:37:"The language code for this data item.";}s:5:"delta";a:4:{s:4:"type";s:3:"int";s:8:"unsigned";b:1;s:8:"not null";b:1;s:11:"description";s:67:"The sequence number for this data item, used for multi-value fields";}s:16:"field_test_value";a:3:{s:4:"type";s:7:"varchar";s:6:"length";i:254;s:8:"not null";b:1;}}s:11:"primary key";a:4:{i:0;s:9:"entity_id";i:1;s:7:"deleted";i:2;s:5:"delta";i:3;s:8:"langcode";}s:7:"indexes";a:2:{s:6:"bundle";a:1:{i:0;s:6:"bundle";}s:11:"revision_id";a:1:{i:0;s:11:"revision_id";}}}s:25:"node_revision__field_test";a:4:{s:11:"description";s:51:"Revision archive storage for node field field_test.";s:6:"fields";a:7:{s:6:"bundle";a:5:{s:4:"type";s:13:"varchar_ascii";s:6:"length";i:128;s:8:"not null";b:1;s:7:"default";s:0:"";s:11:"description";s:88:"The field instance bundle to which this row belongs, used when deleting a field instance";}s:7:"deleted";a:5:{s:4:"type";s:3:"int";s:4:"size";s:4:"tiny";s:8:"not null";b:1;s:7:"default";i:0;s:11:"description";s:60:"A boolean indicating whether this data item has been deleted";}s:9:"entity_id";a:4:{s:4:"type";s:3:"int";s:8:"unsigned";b:1;s:8:"not null";b:1;s:11:"description";s:38:"The entity id this data is attached to";}s:11:"revision_id";a:4:{s:4:"type";s:3:"int";s:8:"unsigned";b:1;s:8:"not null";b:1;s:11:"description";s:47:"The entity revision id this data is attached to";}s:8:"langcode";a:5:{s:4:"type";s:13:"varchar_ascii";s:6:"length";i:32;s:8:"not null";b:1;s:7:"default";s:0:"";s:11:"description";s:37:"The language code for this data item.";}s:5:"delta";a:4:{s:4:"type";s:3:"int";s:8:"unsigned";b:1;s:8:"not null";b:1;s:11:"description";s:67:"The sequence number for this data item, used for multi-value fields";}s:16:"field_test_value";a:3:{s:4:"type";s:7:"varchar";s:6:"length";i:254;s:8:"not null";b:1;}}s:11:"primary key";a:5:{i:0;s:9:"entity_id";i:1;s:11:"revision_id";i:2;s:7:"deleted";i:3;s:5:"delta";i:4;s:8:"langcode";}s:7:"indexes";a:2:{s:6:"bundle";a:1:{i:0;s:6:"bundle";}s:11:"revision_id";a:1:{i:0;s:11:"revision_id";}}}}',
|
||||
])
|
||||
->values([
|
||||
'collection' => 'state',
|
||||
'name' => 'field.field.deleted',
|
||||
'value' => 'a:1:{s:36:"5d0d9870-560b-46c4-b838-0dcded0502dd";a:18:{s:4:"uuid";s:36:"5d0d9870-560b-46c4-b838-0dcded0502dd";s:8:"langcode";s:2:"en";s:6:"status";b:1;s:12:"dependencies";a:1:{s:6:"config";a:2:{i:0;s:29:"field.storage.node.field_test";i:1;s:17:"node.type.article";}}s:2:"id";s:23:"node.article.field_test";s:10:"field_name";s:10:"field_test";s:11:"entity_type";s:4:"node";s:6:"bundle";s:7:"article";s:5:"label";s:4:"Test";s:11:"description";s:0:"";s:8:"required";b:0;s:12:"translatable";b:0;s:13:"default_value";a:0:{}s:22:"default_value_callback";s:0:"";s:8:"settings";a:0:{}s:10:"field_type";s:5:"email";s:7:"deleted";b:1;s:18:"field_storage_uuid";s:36:"ce93d7c2-1da7-4a2c-9e6d-b4925e3b129f";}}',
|
||||
])
|
||||
->values([
|
||||
'collection' => 'state',
|
||||
'name' => 'field.storage.deleted',
|
||||
'value' => 'a:1:{s:36:"ce93d7c2-1da7-4a2c-9e6d-b4925e3b129f";a:18:{s:4:"uuid";s:36:"ce93d7c2-1da7-4a2c-9e6d-b4925e3b129f";s:8:"langcode";s:2:"en";s:6:"status";b:1;s:12:"dependencies";a:1:{s:6:"module";a:1:{i:0;s:4:"node";}}s:2:"id";s:15:"node.field_test";s:10:"field_name";s:10:"field_test";s:11:"entity_type";s:4:"node";s:4:"type";s:5:"email";s:8:"settings";a:0:{}s:6:"module";s:4:"core";s:6:"locked";b:0;s:11:"cardinality";i:1;s:12:"translatable";b:1;s:7:"indexes";a:0:{}s:22:"persist_with_no_fields";b:0;s:14:"custom_storage";b:0;s:7:"deleted";b:1;s:7:"bundles";a:0:{}}}',
|
||||
])
|
||||
->execute();
|
||||
|
||||
// Create and populate the deleted field tables.
|
||||
// @see \Drupal\Core\Entity\Sql\DefaultTableMapping::getDedicatedDataTableName()
|
||||
$deleted_field_data_table_name = "field_deleted_data_" . substr(hash('sha256', 'ce93d7c2-1da7-4a2c-9e6d-b4925e3b129f'), 0, 10);
|
||||
$connection->schema()->createTable($deleted_field_data_table_name, array(
|
||||
'fields' => array(
|
||||
'bundle' => array(
|
||||
'type' => 'varchar_ascii',
|
||||
'not null' => TRUE,
|
||||
'length' => '128',
|
||||
'default' => '',
|
||||
),
|
||||
'deleted' => array(
|
||||
'type' => 'int',
|
||||
'not null' => TRUE,
|
||||
'size' => 'tiny',
|
||||
'default' => '0',
|
||||
),
|
||||
'entity_id' => array(
|
||||
'type' => 'int',
|
||||
'not null' => TRUE,
|
||||
'size' => 'normal',
|
||||
'unsigned' => TRUE,
|
||||
),
|
||||
'revision_id' => array(
|
||||
'type' => 'int',
|
||||
'not null' => TRUE,
|
||||
'size' => 'normal',
|
||||
'unsigned' => TRUE,
|
||||
),
|
||||
'langcode' => array(
|
||||
'type' => 'varchar_ascii',
|
||||
'not null' => TRUE,
|
||||
'length' => '32',
|
||||
'default' => '',
|
||||
),
|
||||
'delta' => array(
|
||||
'type' => 'int',
|
||||
'not null' => TRUE,
|
||||
'size' => 'normal',
|
||||
'unsigned' => TRUE,
|
||||
),
|
||||
'field_test_value' => array(
|
||||
'type' => 'varchar',
|
||||
'not null' => TRUE,
|
||||
'length' => '254',
|
||||
),
|
||||
),
|
||||
'primary key' => array(
|
||||
'entity_id',
|
||||
'deleted',
|
||||
'delta',
|
||||
'langcode',
|
||||
),
|
||||
'indexes' => array(
|
||||
'bundle' => array(
|
||||
'bundle',
|
||||
),
|
||||
'revision_id' => array(
|
||||
'revision_id',
|
||||
),
|
||||
),
|
||||
));
|
||||
|
||||
$connection->insert($deleted_field_data_table_name)
|
||||
->fields(array(
|
||||
'bundle',
|
||||
'deleted',
|
||||
'entity_id',
|
||||
'revision_id',
|
||||
'langcode',
|
||||
'delta',
|
||||
'field_test_value',
|
||||
))
|
||||
->values(array(
|
||||
'bundle' => 'article',
|
||||
'deleted' => '1',
|
||||
'entity_id' => '1',
|
||||
'revision_id' => '1',
|
||||
'langcode' => 'en',
|
||||
'delta' => '0',
|
||||
'field_test_value' => 'test@test.com',
|
||||
))
|
||||
->execute();
|
||||
|
||||
// @see \Drupal\Core\Entity\Sql\DefaultTableMapping::getDedicatedDataTableName()
|
||||
$deleted_field_revision_table_name = "field_deleted_revision_" . substr(hash('sha256', 'ce93d7c2-1da7-4a2c-9e6d-b4925e3b129f'), 0, 10);
|
||||
$connection->schema()->createTable($deleted_field_revision_table_name, array(
|
||||
'fields' => array(
|
||||
'bundle' => array(
|
||||
'type' => 'varchar_ascii',
|
||||
'not null' => TRUE,
|
||||
'length' => '128',
|
||||
'default' => '',
|
||||
),
|
||||
'deleted' => array(
|
||||
'type' => 'int',
|
||||
'not null' => TRUE,
|
||||
'size' => 'tiny',
|
||||
'default' => '0',
|
||||
),
|
||||
'entity_id' => array(
|
||||
'type' => 'int',
|
||||
'not null' => TRUE,
|
||||
'size' => 'normal',
|
||||
'unsigned' => TRUE,
|
||||
),
|
||||
'revision_id' => array(
|
||||
'type' => 'int',
|
||||
'not null' => TRUE,
|
||||
'size' => 'normal',
|
||||
'unsigned' => TRUE,
|
||||
),
|
||||
'langcode' => array(
|
||||
'type' => 'varchar_ascii',
|
||||
'not null' => TRUE,
|
||||
'length' => '32',
|
||||
'default' => '',
|
||||
),
|
||||
'delta' => array(
|
||||
'type' => 'int',
|
||||
'not null' => TRUE,
|
||||
'size' => 'normal',
|
||||
'unsigned' => TRUE,
|
||||
),
|
||||
'field_test_value' => array(
|
||||
'type' => 'varchar',
|
||||
'not null' => TRUE,
|
||||
'length' => '254',
|
||||
),
|
||||
),
|
||||
'primary key' => array(
|
||||
'entity_id',
|
||||
'revision_id',
|
||||
'deleted',
|
||||
'delta',
|
||||
'langcode',
|
||||
),
|
||||
'indexes' => array(
|
||||
'bundle' => array(
|
||||
'bundle',
|
||||
),
|
||||
'revision_id' => array(
|
||||
'revision_id',
|
||||
),
|
||||
),
|
||||
));
|
||||
|
||||
$connection->insert($deleted_field_revision_table_name)
|
||||
->fields(array(
|
||||
'bundle',
|
||||
'deleted',
|
||||
'entity_id',
|
||||
'revision_id',
|
||||
'langcode',
|
||||
'delta',
|
||||
'field_test_value',
|
||||
))
|
||||
->values(array(
|
||||
'bundle' => 'article',
|
||||
'deleted' => '1',
|
||||
'entity_id' => '1',
|
||||
'revision_id' => '1',
|
||||
'langcode' => 'en',
|
||||
'delta' => '0',
|
||||
'field_test_value' => 'test@test.com',
|
||||
))
|
||||
->execute();
|
||||
@@ -7,8 +7,8 @@ package: Testing
|
||||
dependencies:
|
||||
- text
|
||||
|
||||
# Information added by Drupal.org packaging script on 2018-01-03
|
||||
version: '8.4.4'
|
||||
# Information added by Drupal.org packaging script on 2018-03-07
|
||||
version: '8.5.0'
|
||||
core: '8.x'
|
||||
project: 'drupal'
|
||||
datestamp: 1515021228
|
||||
datestamp: 1520457825
|
||||
|
||||
@@ -55,6 +55,14 @@ field.widget.settings.test_field_widget_multiple:
|
||||
type: string
|
||||
label: 'Test setting'
|
||||
|
||||
field.widget.settings.test_field_widget_multiple_single_value:
|
||||
type: mapping
|
||||
label: 'Test multiple field widget settings: single values'
|
||||
mapping:
|
||||
test_widget_setting_multiple:
|
||||
type: string
|
||||
label: 'Test setting'
|
||||
|
||||
field.widget.third_party.color:
|
||||
type: mapping
|
||||
label: 'Field test entity display color module third party settings'
|
||||
|
||||
@@ -19,6 +19,13 @@ use Drupal\field\FieldStorageConfigInterface;
|
||||
function field_test_field_widget_info_alter(&$info) {
|
||||
$info['test_field_widget_multiple']['field_types'][] = 'test_field';
|
||||
$info['test_field_widget_multiple']['field_types'][] = 'test_field_with_preconfigured_options';
|
||||
// Add extra widget when needed for tests.
|
||||
// @see \Drupal\field\Tests\FormTest::widgetAlterTest().
|
||||
if ($alter_info = \Drupal::state()->get("field_test.widget_alter_test")) {
|
||||
if ($alter_info['widget'] === 'test_field_widget_multiple_single_value') {
|
||||
$info['test_field_widget_multiple_single_value']['field_types'][] = 'test_field';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -7,8 +7,8 @@ package: Testing
|
||||
dependencies:
|
||||
- entity_test
|
||||
|
||||
# Information added by Drupal.org packaging script on 2018-01-03
|
||||
version: '8.4.4'
|
||||
# Information added by Drupal.org packaging script on 2018-03-07
|
||||
version: '8.5.0'
|
||||
core: '8.x'
|
||||
project: 'drupal'
|
||||
datestamp: 1515021228
|
||||
datestamp: 1520457825
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Render\Element;
|
||||
use Drupal\field\FieldStorageConfigInterface;
|
||||
|
||||
require_once __DIR__ . '/field_test.entity.inc';
|
||||
@@ -100,16 +101,6 @@ function field_test_entity_display_build_alter(&$output, $context) {
|
||||
* Implements hook_field_widget_form_alter().
|
||||
*/
|
||||
function field_test_field_widget_form_alter(&$element, FormStateInterface $form_state, $context) {
|
||||
$field_definition = $context['items']->getFieldDefinition();
|
||||
switch ($field_definition->getName()) {
|
||||
case 'alter_test_text':
|
||||
drupal_set_message('Field size: ' . $context['widget']->getSetting('size'));
|
||||
break;
|
||||
|
||||
case 'alter_test_options':
|
||||
drupal_set_message('Widget type: ' . $context['widget']->getPluginId());
|
||||
break;
|
||||
}
|
||||
// Set a message if this is for the form displayed to set default value for
|
||||
// the field.
|
||||
if ($context['default']) {
|
||||
@@ -117,6 +108,50 @@ function field_test_field_widget_form_alter(&$element, FormStateInterface $form_
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_widget_multivalue_form_alter().
|
||||
*/
|
||||
function field_test_field_widget_multivalue_form_alter(array &$elements, FormStateInterface $form_state, array $context) {
|
||||
_field_test_alter_widget("hook_field_widget_multivalue_form_alter", $elements, $form_state, $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_widget_multivalue_WIDGET_TYPE_form_alter().
|
||||
*/
|
||||
function field_test_field_widget_multivalue_test_field_widget_multiple_form_alter(array &$elements, FormStateInterface $form_state, array $context) {
|
||||
_field_test_alter_widget("hook_field_widget_multivalue_WIDGET_TYPE_form_alter", $elements, $form_state, $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_widget_multivalue_WIDGET_TYPE_form_alter().
|
||||
*/
|
||||
function field_test_field_widget_multivalue_test_field_widget_multiple_single_value_form_alter(array &$elements, FormStateInterface $form_state, array $context) {
|
||||
_field_test_alter_widget("hook_field_widget_multivalue_WIDGET_TYPE_form_alter", $elements, $form_state, $context);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets up alterations for widget alter tests.
|
||||
*
|
||||
* @see \Drupal\field\Tests\FormTest::widgetAlterTest()
|
||||
*/
|
||||
function _field_test_alter_widget($hook, array &$elements, FormStateInterface $form_state, array $context) {
|
||||
|
||||
// Set a message if this is for the form displayed to set default value for
|
||||
// the field.
|
||||
if ($context['default']) {
|
||||
drupal_set_message("From $hook(): Default form is true.");
|
||||
}
|
||||
$alter_info = \Drupal::state()->get("field_test.widget_alter_test");
|
||||
$name = $context['items']->getFieldDefinition()->getName();
|
||||
if (!empty($alter_info) && $hook === $alter_info['hook'] && $name === $alter_info['field_name']) {
|
||||
$elements['#prefix'] = "From $hook(): prefix on $name parent element.";
|
||||
foreach (Element::children($elements) as $delta => $element) {
|
||||
$elements[$delta]['#suffix'] = "From $hook(): suffix on $name child element.";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_query_TAG_alter() for tag 'efq_table_prefixing_test'.
|
||||
*
|
||||
@@ -171,3 +206,14 @@ function field_test_entity_bundle_field_info_alter(&$fields, EntityTypeInterface
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_ui_preconfigured_options_alter().
|
||||
*/
|
||||
function field_test_field_ui_preconfigured_options_alter(array &$options, $field_type) {
|
||||
if ($field_type === 'test_field_with_preconfigured_options') {
|
||||
$options['custom_options']['entity_view_display']['settings'] = [
|
||||
'test_formatter_setting_multiple' => 'altered dummy test string',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@ use Drupal\Core\Entity\Entity\EntityFormDisplay;
|
||||
|
||||
/**
|
||||
* Provides a form for field_test routes.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class NestedEntityTestForm extends FormBase {
|
||||
|
||||
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\field_test\Plugin\Field\FieldWidget;
|
||||
|
||||
/**
|
||||
* Plugin implementation of the 'test_field_widget_multiple' widget.
|
||||
*
|
||||
* The 'field_types' entry is left empty, and is populated through
|
||||
* hook_field_widget_info_alter().
|
||||
*
|
||||
* @see field_test_field_widget_info_alter()
|
||||
*
|
||||
* @FieldWidget(
|
||||
* id = "test_field_widget_multiple_single_value",
|
||||
* label = @Translation("Test widget - multiple - single value"),
|
||||
* multiple_values = FALSE,
|
||||
* weight = 10
|
||||
* )
|
||||
*/
|
||||
class TestFieldWidgetMultipleSingleValues extends TestFieldWidgetMultiple {
|
||||
|
||||
}
|
||||
+3
-3
@@ -7,8 +7,8 @@ package: Testing
|
||||
dependencies:
|
||||
- field
|
||||
|
||||
# Information added by Drupal.org packaging script on 2018-01-03
|
||||
version: '8.4.4'
|
||||
# Information added by Drupal.org packaging script on 2018-03-07
|
||||
version: '8.5.0'
|
||||
core: '8.x'
|
||||
project: 'drupal'
|
||||
datestamp: 1515021228
|
||||
datestamp: 1520457825
|
||||
|
||||
@@ -5,8 +5,8 @@ description: 'Support module for the Field API configuration tests.'
|
||||
package: Testing
|
||||
# version: VERSION
|
||||
|
||||
# Information added by Drupal.org packaging script on 2018-01-03
|
||||
version: '8.4.4'
|
||||
# Information added by Drupal.org packaging script on 2018-03-07
|
||||
version: '8.5.0'
|
||||
core: '8.x'
|
||||
project: 'drupal'
|
||||
datestamp: 1515021228
|
||||
datestamp: 1520457825
|
||||
|
||||
@@ -7,8 +7,8 @@ package: Testing
|
||||
dependencies:
|
||||
- views
|
||||
|
||||
# Information added by Drupal.org packaging script on 2018-01-03
|
||||
version: '8.4.4'
|
||||
# Information added by Drupal.org packaging script on 2018-03-07
|
||||
version: '8.5.0'
|
||||
core: '8.x'
|
||||
project: 'drupal'
|
||||
datestamp: 1515021228
|
||||
datestamp: 1520457825
|
||||
|
||||
+3
-3
@@ -8,8 +8,8 @@ dependencies:
|
||||
- entity_test
|
||||
- field_test
|
||||
|
||||
# Information added by Drupal.org packaging script on 2018-01-03
|
||||
version: '8.4.4'
|
||||
# Information added by Drupal.org packaging script on 2018-03-07
|
||||
version: '8.5.0'
|
||||
core: '8.x'
|
||||
project: 'drupal'
|
||||
datestamp: 1515021228
|
||||
datestamp: 1520457825
|
||||
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
config:
|
||||
- field.storage.entity_test.timestamp
|
||||
id: entity_test.entity_test.timestamp
|
||||
field_name: timestamp
|
||||
entity_type: entity_test
|
||||
bundle: entity_test
|
||||
label: 'Time stamp'
|
||||
description: ''
|
||||
required: false
|
||||
translatable: false
|
||||
default_value:
|
||||
-
|
||||
value: 1514847537
|
||||
default_value_callback: ''
|
||||
settings: { }
|
||||
field_type: timestamp
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
module:
|
||||
- entity_test
|
||||
id: node.timestamp
|
||||
field_name: timestamp
|
||||
entity_type: entity_test
|
||||
type: timestamp
|
||||
settings: { }
|
||||
module: core
|
||||
locked: false
|
||||
cardinality: 1
|
||||
translatable: true
|
||||
indexes: { }
|
||||
persist_with_no_fields: false
|
||||
custom_storage: false
|
||||
@@ -0,0 +1,15 @@
|
||||
name: 'Field Timestamp Test'
|
||||
type: module
|
||||
description: 'Support module for the Timestamp field item test.'
|
||||
# core: 8.x
|
||||
package: Testing
|
||||
# version: VERSION
|
||||
dependencies:
|
||||
- entity_test
|
||||
- field
|
||||
|
||||
# Information added by Drupal.org packaging script on 2018-03-07
|
||||
version: '8.5.0'
|
||||
core: '8.x'
|
||||
project: 'drupal'
|
||||
datestamp: 1520457825
|
||||
@@ -0,0 +1,243 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\field\Functional\Boolean;
|
||||
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\entity_test\Entity\EntityTest;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Tests boolean field functionality.
|
||||
*
|
||||
* @group field
|
||||
*/
|
||||
class BooleanFieldTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = [
|
||||
'entity_test',
|
||||
'field_ui',
|
||||
'options',
|
||||
'field_test_boolean_access_denied',
|
||||
];
|
||||
|
||||
/**
|
||||
* A field to use in this test class.
|
||||
*
|
||||
* @var \Drupal\field\Entity\FieldStorageConfig
|
||||
*/
|
||||
protected $fieldStorage;
|
||||
|
||||
/**
|
||||
* The field used in this test class.
|
||||
*
|
||||
* @var \Drupal\field\Entity\FieldConfig
|
||||
*/
|
||||
protected $field;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->drupalLogin($this->drupalCreateUser([
|
||||
'view test entity',
|
||||
'administer entity_test content',
|
||||
'administer entity_test form display',
|
||||
'administer entity_test fields',
|
||||
]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests boolean field.
|
||||
*/
|
||||
public function testBooleanField() {
|
||||
$on = $this->randomMachineName();
|
||||
$off = $this->randomMachineName();
|
||||
$label = $this->randomMachineName();
|
||||
|
||||
// Create a field with settings to validate.
|
||||
$field_name = Unicode::strtolower($this->randomMachineName());
|
||||
$this->fieldStorage = FieldStorageConfig::create([
|
||||
'field_name' => $field_name,
|
||||
'entity_type' => 'entity_test',
|
||||
'type' => 'boolean',
|
||||
]);
|
||||
$this->fieldStorage->save();
|
||||
$this->field = FieldConfig::create([
|
||||
'field_name' => $field_name,
|
||||
'entity_type' => 'entity_test',
|
||||
'bundle' => 'entity_test',
|
||||
'label' => $label,
|
||||
'required' => TRUE,
|
||||
'settings' => [
|
||||
'on_label' => $on,
|
||||
'off_label' => $off,
|
||||
],
|
||||
]);
|
||||
$this->field->save();
|
||||
|
||||
// Create a form display for the default form mode.
|
||||
entity_get_form_display('entity_test', 'entity_test', 'default')
|
||||
->setComponent($field_name, [
|
||||
'type' => 'boolean_checkbox',
|
||||
])
|
||||
->save();
|
||||
// Create a display for the full view mode.
|
||||
entity_get_display('entity_test', 'entity_test', 'full')
|
||||
->setComponent($field_name, [
|
||||
'type' => 'boolean',
|
||||
])
|
||||
->save();
|
||||
|
||||
// Display creation form.
|
||||
$this->drupalGet('entity_test/add');
|
||||
$this->assertFieldByName("{$field_name}[value]", '', 'Widget found.');
|
||||
$this->assertText($this->field->label(), 'Uses field label by default.');
|
||||
$this->assertNoRaw($on, 'Does not use the "On" label.');
|
||||
|
||||
// Submit and ensure it is accepted.
|
||||
$edit = [
|
||||
"{$field_name}[value]" => 1,
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
preg_match('|entity_test/manage/(\d+)|', $this->getUrl(), $match);
|
||||
$id = $match[1];
|
||||
$this->assertText(t('entity_test @id has been created.', ['@id' => $id]));
|
||||
|
||||
// Verify that boolean value is displayed.
|
||||
$entity = EntityTest::load($id);
|
||||
$this->drupalGet($entity->toUrl());
|
||||
$this->assertRaw('<div class="field__item">' . $on . '</div>');
|
||||
|
||||
// Test with "On" label option.
|
||||
entity_get_form_display('entity_test', 'entity_test', 'default')
|
||||
->setComponent($field_name, [
|
||||
'type' => 'boolean_checkbox',
|
||||
'settings' => [
|
||||
'display_label' => FALSE,
|
||||
]
|
||||
])
|
||||
->save();
|
||||
|
||||
$this->drupalGet('entity_test/add');
|
||||
$this->assertFieldByName("{$field_name}[value]", '', 'Widget found.');
|
||||
$this->assertRaw($on);
|
||||
$this->assertNoText($this->field->label());
|
||||
|
||||
// Test if we can change the on label.
|
||||
$on = $this->randomMachineName();
|
||||
$edit = [
|
||||
'settings[on_label]' => $on,
|
||||
];
|
||||
$this->drupalPostForm('entity_test/structure/entity_test/fields/entity_test.entity_test.' . $field_name, $edit, t('Save settings'));
|
||||
// Check if we see the updated labels in the creation form.
|
||||
$this->drupalGet('entity_test/add');
|
||||
$this->assertRaw($on);
|
||||
|
||||
// Go to the form display page and check if the default settings works as
|
||||
// expected.
|
||||
$fieldEditUrl = 'entity_test/structure/entity_test/form-display';
|
||||
$this->drupalGet($fieldEditUrl);
|
||||
|
||||
// Click on the widget settings button to open the widget settings form.
|
||||
$this->drupalPostForm(NULL, [], $field_name . "_settings_edit");
|
||||
|
||||
$this->assertText(
|
||||
'Use field label instead of the "On" label as the label.',
|
||||
t('Display setting checkbox available.')
|
||||
);
|
||||
|
||||
// Enable setting.
|
||||
$edit = ['fields[' . $field_name . '][settings_edit_form][settings][display_label]' => 1];
|
||||
$this->drupalPostForm(NULL, $edit, $field_name . "_plugin_settings_update");
|
||||
$this->drupalPostForm(NULL, NULL, 'Save');
|
||||
|
||||
// Go again to the form display page and check if the setting
|
||||
// is stored and has the expected effect.
|
||||
$this->drupalGet($fieldEditUrl);
|
||||
$this->assertText('Use field label: Yes', 'Checking the display settings checkbox updated the value.');
|
||||
|
||||
$this->drupalPostForm(NULL, [], $field_name . "_settings_edit");
|
||||
$this->assertText(
|
||||
'Use field label instead of the "On" label as the label.',
|
||||
t('Display setting checkbox is available')
|
||||
);
|
||||
$this->getSession()->getPage()->hasCheckedField('fields[' . $field_name . '][settings_edit_form][settings][display_label]');
|
||||
|
||||
// Test the boolean field settings.
|
||||
$this->drupalGet('entity_test/structure/entity_test/fields/entity_test.entity_test.' . $field_name);
|
||||
$this->assertFieldById('edit-settings-on-label', $on);
|
||||
$this->assertFieldById('edit-settings-off-label', $off);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test field access.
|
||||
*/
|
||||
public function testFormAccess() {
|
||||
$on = 'boolean_on';
|
||||
$off = 'boolean_off';
|
||||
$label = 'boolean_label';
|
||||
$field_name = 'boolean_name';
|
||||
$this->fieldStorage = FieldStorageConfig::create([
|
||||
'field_name' => $field_name,
|
||||
'entity_type' => 'entity_test',
|
||||
'type' => 'boolean',
|
||||
]);
|
||||
$this->fieldStorage->save();
|
||||
$this->field = FieldConfig::create([
|
||||
'field_name' => $field_name,
|
||||
'entity_type' => 'entity_test',
|
||||
'bundle' => 'entity_test',
|
||||
'label' => $label,
|
||||
'settings' => [
|
||||
'on_label' => $on,
|
||||
'off_label' => $off,
|
||||
],
|
||||
]);
|
||||
$this->field->save();
|
||||
|
||||
// Create a form display for the default form mode.
|
||||
entity_get_form_display('entity_test', 'entity_test', 'default')
|
||||
->setComponent($field_name, [
|
||||
'type' => 'boolean_checkbox',
|
||||
])
|
||||
->save();
|
||||
|
||||
// Create a display for the full view mode.
|
||||
entity_get_display('entity_test', 'entity_test', 'full')
|
||||
->setComponent($field_name, [
|
||||
'type' => 'boolean',
|
||||
])
|
||||
->save();
|
||||
|
||||
// Display creation form.
|
||||
$this->drupalGet('entity_test/add');
|
||||
$this->assertFieldByName("{$field_name}[value]");
|
||||
|
||||
// Should be posted OK.
|
||||
$this->drupalPostForm(NULL, [], t('Save'));
|
||||
preg_match('|entity_test/manage/(\d+)|', $this->getUrl(), $match);
|
||||
$id = $match[1];
|
||||
$this->assertText(t('entity_test @id has been created.', ['@id' => $id]));
|
||||
|
||||
// Tell the test module to disable access to the field.
|
||||
\Drupal::state()->set('field.test_boolean_field_access_field', $field_name);
|
||||
$this->drupalGet('entity_test/add');
|
||||
// Field should not be there anymore.
|
||||
$this->assertNoFieldByName("{$field_name}[value]");
|
||||
// Should still be able to post the form.
|
||||
$this->drupalPostForm(NULL, [], t('Save'));
|
||||
preg_match('|entity_test/manage/(\d+)|', $this->getUrl(), $match);
|
||||
$id = $match[1];
|
||||
$this->assertText(t('entity_test @id has been created.', ['@id' => $id]));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,9 +3,12 @@
|
||||
namespace Drupal\Tests\field\Functional\Update;
|
||||
|
||||
use Drupal\Core\Config\Config;
|
||||
use Drupal\Core\Field\FieldDefinitionInterface;
|
||||
use Drupal\Core\Field\FieldStorageDefinitionInterface;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\FunctionalTests\Update\UpdatePathTestBase;
|
||||
use Drupal\node\Entity\Node;
|
||||
use Drupal\Tests\Traits\Core\CronRunTrait;
|
||||
|
||||
/**
|
||||
* Tests that field settings are properly updated during database updates.
|
||||
@@ -14,6 +17,8 @@ use Drupal\node\Entity\Node;
|
||||
*/
|
||||
class FieldUpdateTest extends UpdatePathTestBase {
|
||||
|
||||
use CronRunTrait;
|
||||
|
||||
/**
|
||||
* The config factory service.
|
||||
*
|
||||
@@ -21,12 +26,45 @@ class FieldUpdateTest extends UpdatePathTestBase {
|
||||
*/
|
||||
protected $configFactory;
|
||||
|
||||
/**
|
||||
* The database connection.
|
||||
*
|
||||
* @var \Drupal\Core\Database\Connection
|
||||
*/
|
||||
protected $database;
|
||||
|
||||
/**
|
||||
* The key-value collection for tracking installed storage schema.
|
||||
*
|
||||
* @var \Drupal\Core\KeyValueStore\KeyValueStoreInterface
|
||||
*/
|
||||
protected $installedStorageSchema;
|
||||
|
||||
/**
|
||||
* The state service.
|
||||
*
|
||||
* @var \Drupal\Core\State\StateInterface
|
||||
*/
|
||||
protected $state;
|
||||
|
||||
/**
|
||||
* The deleted fields repository.
|
||||
*
|
||||
* @var \Drupal\Core\Field\DeletedFieldsRepositoryInterface
|
||||
*/
|
||||
protected $deletedFieldsRepository;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->configFactory = $this->container->get('config.factory');
|
||||
$this->database = $this->container->get('database');
|
||||
$this->installedStorageSchema = $this->container->get('keyvalue')->get('entity.storage_schema.sql');
|
||||
$this->state = $this->container->get('state');
|
||||
$this->deletedFieldsRepository = $this->container->get('entity_field.deleted_fields_repository');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -37,6 +75,7 @@ class FieldUpdateTest extends UpdatePathTestBase {
|
||||
__DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.bare.standard.php.gz',
|
||||
__DIR__ . '/../../../fixtures/update/drupal-8.views_entity_reference_plugins-2429191.php',
|
||||
__DIR__ . '/../../../fixtures/update/drupal-8.remove_handler_submit_setting-2715589.php',
|
||||
__DIR__ . '/../../../fixtures/update/drupal-8.update_deleted_field_definitions-2931436.php',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -127,6 +166,76 @@ class FieldUpdateTest extends UpdatePathTestBase {
|
||||
$this->assertEqual($handler_settings['auto_create_bundle'], 'tags');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests field_update_8500().
|
||||
*
|
||||
* @see field_update_8500()
|
||||
*/
|
||||
public function testFieldUpdate8500() {
|
||||
$field_name = 'field_test';
|
||||
$field_uuid = '5d0d9870-560b-46c4-b838-0dcded0502dd';
|
||||
$field_storage_uuid = 'ce93d7c2-1da7-4a2c-9e6d-b4925e3b129f';
|
||||
|
||||
// Check that we have pre-existing entries for 'field.field.deleted' and
|
||||
// 'field.storage.deleted'.
|
||||
$deleted_fields = $this->state->get('field.field.deleted');
|
||||
$this->assertCount(1, $deleted_fields);
|
||||
$this->assertArrayHasKey($field_uuid, $deleted_fields);
|
||||
|
||||
$deleted_field_storages = $this->state->get('field.storage.deleted');
|
||||
$this->assertCount(1, $deleted_field_storages);
|
||||
$this->assertArrayHasKey($field_storage_uuid, $deleted_field_storages);
|
||||
|
||||
// Ensure that cron does not run automatically after running the updates.
|
||||
$this->state->set('system.cron_last', REQUEST_TIME + 100);
|
||||
|
||||
// Run updates.
|
||||
$this->runUpdates();
|
||||
|
||||
// Now that we can use the API, check that the "delete fields" state entries
|
||||
// have been converted to proper field definition objects.
|
||||
$deleted_fields = $this->deletedFieldsRepository->getFieldDefinitions();
|
||||
|
||||
$this->assertCount(1, $deleted_fields);
|
||||
$this->assertArrayHasKey($field_uuid, $deleted_fields);
|
||||
$this->assertTrue($deleted_fields[$field_uuid] instanceof FieldDefinitionInterface);
|
||||
$this->assertEquals($field_name, $deleted_fields[$field_uuid]->getName());
|
||||
|
||||
$deleted_field_storages = $this->deletedFieldsRepository->getFieldStorageDefinitions();
|
||||
$this->assertCount(1, $deleted_field_storages);
|
||||
$this->assertArrayHasKey($field_storage_uuid, $deleted_field_storages);
|
||||
$this->assertTrue($deleted_field_storages[$field_storage_uuid] instanceof FieldStorageDefinitionInterface);
|
||||
$this->assertEquals($field_name, $deleted_field_storages[$field_storage_uuid]->getName());
|
||||
|
||||
// Check that the installed storage schema still exists.
|
||||
$this->assertNotNull($this->installedStorageSchema->get("node.field_schema_data.$field_name"));
|
||||
|
||||
// Check that the deleted field tables exist.
|
||||
/** @var \Drupal\Core\Entity\Sql\DefaultTableMapping $table_mapping */
|
||||
$table_mapping = \Drupal::entityTypeManager()->getStorage('node')->getTableMapping();
|
||||
|
||||
$deleted_field_data_table_name = $table_mapping->getDedicatedDataTableName($deleted_field_storages[$field_storage_uuid], TRUE);
|
||||
$this->assertTrue($this->database->schema()->tableExists($deleted_field_data_table_name));
|
||||
$deleted_field_revision_table_name = $table_mapping->getDedicatedRevisionTableName($deleted_field_storages[$field_storage_uuid], TRUE);
|
||||
$this->assertTrue($this->database->schema()->tableExists($deleted_field_revision_table_name));
|
||||
|
||||
// Run cron and repeat the checks above.
|
||||
$this->cronRun();
|
||||
|
||||
$deleted_fields = $this->deletedFieldsRepository->getFieldDefinitions();
|
||||
$this->assertCount(0, $deleted_fields);
|
||||
|
||||
$deleted_field_storages = $this->deletedFieldsRepository->getFieldStorageDefinitions();
|
||||
$this->assertCount(0, $deleted_field_storages);
|
||||
|
||||
// Check that the installed storage schema has been deleted.
|
||||
$this->assertNull($this->installedStorageSchema->get("node.field_schema_data.$field_name"));
|
||||
|
||||
// Check that the deleted field tables have been deleted.
|
||||
$this->assertFalse($this->database->schema()->tableExists($deleted_field_data_table_name));
|
||||
$this->assertFalse($this->database->schema()->tableExists($deleted_field_revision_table_name));
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that a config depends on 'entity_reference' or not
|
||||
*
|
||||
|
||||
@@ -16,6 +16,7 @@ use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait;
|
||||
use Drupal\node\NodeInterface;
|
||||
use Drupal\taxonomy\TermInterface;
|
||||
use Drupal\Tests\field\Kernel\FieldKernelTestBase;
|
||||
use Drupal\file\Entity\File;
|
||||
use Drupal\node\Entity\Node;
|
||||
@@ -193,6 +194,24 @@ class EntityReferenceItemTest extends FieldKernelTestBase {
|
||||
$entity = EntityTest::create(['user_id' => ['target_id' => (int) $user->id(), 'entity' => $user]]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the ::generateSampleValue() method.
|
||||
*/
|
||||
public function testGenerateSampleValue() {
|
||||
$entity = EntityTest::create();
|
||||
|
||||
// Test while a term exists.
|
||||
$entity->field_test_taxonomy_term->generateSampleItems();
|
||||
$this->assertInstanceOf(TermInterface::class, $entity->field_test_taxonomy_term->entity);
|
||||
$this->entityValidateAndSave($entity);
|
||||
|
||||
// Delete the term and test again.
|
||||
$this->term->delete();
|
||||
$entity->field_test_taxonomy_term->generateSampleItems();
|
||||
$this->assertInstanceOf(TermInterface::class, $entity->field_test_taxonomy_term->entity);
|
||||
$this->entityValidateAndSave($entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests referencing content entities with string IDs.
|
||||
*/
|
||||
|
||||
+1
-1
@@ -67,7 +67,7 @@ class EntityReferenceRelationshipTest extends ViewsKernelTestBase {
|
||||
// Create reference from entity_test_mul to entity_test.
|
||||
$this->createEntityReferenceField('entity_test_mul', 'entity_test_mul', 'field_data_test', 'field_data_test', 'entity_test');
|
||||
|
||||
// Create another field for testing with a long name. So it's storage name
|
||||
// Create another field for testing with a long name. So its storage name
|
||||
// will become hashed. Use entity_test_mul_changed, so the resulting field
|
||||
// tables created will be greater than 48 chars long.
|
||||
// @see \Drupal\Core\Entity\Sql\DefaultTableMapping::generateFieldTableName()
|
||||
|
||||
+4
-1
@@ -129,11 +129,14 @@ class MigrateFieldFormatterSettingsTest extends MigrateDrupal6TestBase {
|
||||
// Test the file field formatter settings.
|
||||
$expected['weight'] = 8;
|
||||
$expected['type'] = 'file_default';
|
||||
$expected['settings'] = [];
|
||||
$expected['settings'] = [
|
||||
'use_description_as_link_text' => TRUE
|
||||
];
|
||||
$component = $display->getComponent('field_test_filefield');
|
||||
$this->assertIdentical($expected, $component);
|
||||
$display = EntityViewDisplay::load('node.story.default');
|
||||
$expected['type'] = 'file_url_plain';
|
||||
$expected['settings'] = [];
|
||||
$component = $display->getComponent('field_test_filefield');
|
||||
$this->assertIdentical($expected, $component);
|
||||
|
||||
|
||||
@@ -21,9 +21,9 @@ class FieldConfigAccessControlHandlerTest extends FieldStorageConfigAccessContro
|
||||
parent::setUp();
|
||||
|
||||
$this->entity = new FieldConfig([
|
||||
'field_name' => $this->fieldStorage->getName(),
|
||||
'field_name' => $this->entity->getName(),
|
||||
'entity_type' => 'node',
|
||||
'fieldStorage' => $this->fieldStorage,
|
||||
'fieldStorage' => $this->entity,
|
||||
'bundle' => 'test_bundle',
|
||||
'field_type' => 'test_field',
|
||||
], 'node');
|
||||
|
||||
@@ -10,6 +10,9 @@ namespace Drupal\Tests\field\Unit;
|
||||
use Drupal\Core\Entity\EntityType;
|
||||
use Drupal\Core\Field\FieldDefinitionInterface;
|
||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||
use Drupal\Core\Entity\EntityFieldManagerInterface;
|
||||
use Drupal\Core\Entity\EntityManager;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
||||
@@ -33,6 +36,20 @@ class FieldConfigEntityUnitTest extends UnitTestCase {
|
||||
*/
|
||||
protected $entityManager;
|
||||
|
||||
/**
|
||||
* The entity type manager used for testing.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityTypeManagerInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $entityTypeManager;
|
||||
|
||||
/**
|
||||
* The entity field manager used for testing.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityFieldManagerInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $entityFieldManager;
|
||||
|
||||
/**
|
||||
* The ID of the type of the entity under test.
|
||||
*
|
||||
@@ -75,7 +92,9 @@ class FieldConfigEntityUnitTest extends UnitTestCase {
|
||||
$this->entityTypeId = $this->randomMachineName();
|
||||
$this->entityType = $this->getMock('\Drupal\Core\Config\Entity\ConfigEntityTypeInterface');
|
||||
|
||||
$this->entityManager = $this->getMock('\Drupal\Core\Entity\EntityManagerInterface');
|
||||
$this->entityManager = new EntityManager();
|
||||
$this->entityTypeManager = $this->getMock(EntityTypeManagerInterface::class);
|
||||
$this->entityFieldManager = $this->getMock(EntityFieldManagerInterface::class);
|
||||
|
||||
$this->uuid = $this->getMock('\Drupal\Component\Uuid\UuidInterface');
|
||||
|
||||
@@ -85,9 +104,14 @@ class FieldConfigEntityUnitTest extends UnitTestCase {
|
||||
|
||||
$container = new ContainerBuilder();
|
||||
$container->set('entity.manager', $this->entityManager);
|
||||
$container->set('entity_field.manager', $this->entityFieldManager);
|
||||
$container->set('entity_type.manager', $this->entityTypeManager);
|
||||
$container->set('uuid', $this->uuid);
|
||||
$container->set('config.typed', $this->typedConfigManager);
|
||||
$container->set('plugin.manager.field.field_type', $this->fieldTypePluginManager);
|
||||
// Inject the container into entity.manager so it can defer to
|
||||
// entity_type.manager, etc.
|
||||
$this->entityManager->setContainer($container);
|
||||
\Drupal::setContainer($container);
|
||||
|
||||
// Create a mock FieldStorageConfig object.
|
||||
@@ -102,7 +126,7 @@ class FieldConfigEntityUnitTest extends UnitTestCase {
|
||||
->method('getSettings')
|
||||
->willReturn([]);
|
||||
// Place the field in the mocked entity manager's field registry.
|
||||
$this->entityManager->expects($this->any())
|
||||
$this->entityFieldManager->expects($this->any())
|
||||
->method('getFieldStorageDefinitions')
|
||||
->with('test_entity_type')
|
||||
->will($this->returnValue([
|
||||
@@ -120,19 +144,19 @@ class FieldConfigEntityUnitTest extends UnitTestCase {
|
||||
->method('getBundleConfigDependency')
|
||||
->will($this->returnValue(['type' => 'config', 'name' => 'test.test_entity_type.id']));
|
||||
|
||||
$this->entityManager->expects($this->at(0))
|
||||
$this->entityTypeManager->expects($this->at(0))
|
||||
->method('getDefinition')
|
||||
->with($this->entityTypeId)
|
||||
->willReturn($this->entityType);
|
||||
$this->entityManager->expects($this->at(1))
|
||||
$this->entityTypeManager->expects($this->at(1))
|
||||
->method('getDefinition')
|
||||
->with($this->entityTypeId)
|
||||
->willReturn($this->entityType);
|
||||
$this->entityManager->expects($this->at(2))
|
||||
$this->entityTypeManager->expects($this->at(2))
|
||||
->method('getDefinition')
|
||||
->with($this->entityTypeId)
|
||||
->willReturn($this->entityType);
|
||||
$this->entityManager->expects($this->at(3))
|
||||
$this->entityTypeManager->expects($this->at(3))
|
||||
->method('getDefinition')
|
||||
->with('test_entity_type')
|
||||
->willReturn($target_entity_type);
|
||||
@@ -168,7 +192,7 @@ class FieldConfigEntityUnitTest extends UnitTestCase {
|
||||
->with('test_bundle_not_exists')
|
||||
->will($this->returnValue(NULL));
|
||||
|
||||
$this->entityManager->expects($this->any())
|
||||
$this->entityTypeManager->expects($this->any())
|
||||
->method('getStorage')
|
||||
->with('bundle_entity_type')
|
||||
->will($this->returnValue($storage));
|
||||
@@ -178,19 +202,19 @@ class FieldConfigEntityUnitTest extends UnitTestCase {
|
||||
'bundle_entity_type' => 'bundle_entity_type',
|
||||
]);
|
||||
|
||||
$this->entityManager->expects($this->at(0))
|
||||
$this->entityTypeManager->expects($this->at(0))
|
||||
->method('getDefinition')
|
||||
->with($this->entityTypeId)
|
||||
->willReturn($this->entityType);
|
||||
$this->entityManager->expects($this->at(1))
|
||||
$this->entityTypeManager->expects($this->at(1))
|
||||
->method('getDefinition')
|
||||
->with($this->entityTypeId)
|
||||
->willReturn($this->entityType);
|
||||
$this->entityManager->expects($this->at(2))
|
||||
$this->entityTypeManager->expects($this->at(2))
|
||||
->method('getDefinition')
|
||||
->with($this->entityTypeId)
|
||||
->willReturn($this->entityType);
|
||||
$this->entityManager->expects($this->at(3))
|
||||
$this->entityTypeManager->expects($this->at(3))
|
||||
->method('getDefinition')
|
||||
->with('test_entity_type')
|
||||
->willReturn($target_entity_type);
|
||||
@@ -267,7 +291,7 @@ class FieldConfigEntityUnitTest extends UnitTestCase {
|
||||
'dependencies' => [],
|
||||
'field_type' => 'test_field',
|
||||
];
|
||||
$this->entityManager->expects($this->any())
|
||||
$this->entityTypeManager->expects($this->any())
|
||||
->method('getDefinition')
|
||||
->with($this->entityTypeId)
|
||||
->will($this->returnValue($this->entityType));
|
||||
@@ -289,7 +313,7 @@ class FieldConfigEntityUnitTest extends UnitTestCase {
|
||||
public function testGetType() {
|
||||
// Ensure that FieldConfig::getType() is not delegated to
|
||||
// FieldStorage.
|
||||
$this->entityManager->expects($this->never())
|
||||
$this->entityFieldManager->expects($this->never())
|
||||
->method('getFieldStorageDefinitions');
|
||||
$this->fieldStorage->expects($this->never())
|
||||
->method('getType');
|
||||
|
||||
@@ -6,8 +6,9 @@ use Drupal\Component\Uuid\UuidInterface;
|
||||
use Drupal\Core\Cache\Context\CacheContextsManager;
|
||||
use Drupal\Core\Config\Entity\ConfigEntityTypeInterface;
|
||||
use Drupal\Core\DependencyInjection\Container;
|
||||
use Drupal\Core\Entity\EntityManagerInterface;
|
||||
use Drupal\Core\Entity\EntityManager;
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
@@ -52,17 +53,10 @@ class FieldStorageConfigAccessControlHandlerTest extends UnitTestCase {
|
||||
protected $member;
|
||||
|
||||
/**
|
||||
* The mocked test field storage config.
|
||||
* The FieldStorageConfig entity used for testing.
|
||||
*
|
||||
* @var \Drupal\field\FieldStorageConfigInterface
|
||||
*/
|
||||
protected $fieldStorage;
|
||||
|
||||
/**
|
||||
* The main entity used for testing.
|
||||
*
|
||||
* @var \Drupal\Core\Config\Entity\ConfigEntityInterface
|
||||
*/
|
||||
protected $entity;
|
||||
|
||||
/**
|
||||
@@ -126,34 +120,40 @@ class FieldStorageConfigAccessControlHandlerTest extends UnitTestCase {
|
||||
$storage_access_control_handler = new FieldStorageConfigAccessControlHandler($storageType);
|
||||
$storage_access_control_handler->setModuleHandler($this->moduleHandler);
|
||||
|
||||
$entityManager = $this->getMock(EntityManagerInterface::class);
|
||||
$entityManager
|
||||
$entity_type_manager = $this->getMock(EntityTypeManagerInterface::class);
|
||||
$entity_type_manager
|
||||
->expects($this->any())
|
||||
->method('getDefinition')
|
||||
->willReturnMap([
|
||||
['field_storage_config', TRUE, $storageType],
|
||||
['node', TRUE, $entityType],
|
||||
]);
|
||||
$entityManager
|
||||
$entity_type_manager
|
||||
->expects($this->any())
|
||||
->method('getStorage')
|
||||
->willReturnMap([
|
||||
['field_storage_config', $this->getMock(EntityStorageInterface::class)],
|
||||
]);
|
||||
$entityManager
|
||||
$entity_type_manager
|
||||
->expects($this->any())
|
||||
->method('getAccessControlHandler')
|
||||
->willReturnMap([
|
||||
['field_storage_config', $storage_access_control_handler],
|
||||
]);
|
||||
|
||||
$entity_manager = new EntityManager();
|
||||
|
||||
$container = new Container();
|
||||
$container->set('entity.manager', $entityManager);
|
||||
$container->set('entity.manager', $entity_manager);
|
||||
$container->set('entity_type.manager', $entity_type_manager);
|
||||
$container->set('uuid', $this->getMock(UuidInterface::class));
|
||||
$container->set('cache_contexts_manager', $this->prophesize(CacheContextsManager::class));
|
||||
// Inject the container into entity.manager so it can defer to
|
||||
// entity_type.manager.
|
||||
$entity_manager->setContainer($container);
|
||||
\Drupal::setContainer($container);
|
||||
|
||||
$this->fieldStorage = new FieldStorageConfig([
|
||||
$this->entity = new FieldStorageConfig([
|
||||
'field_name' => 'test_field',
|
||||
'entity_type' => 'node',
|
||||
'type' => 'boolean',
|
||||
@@ -161,7 +161,6 @@ class FieldStorageConfigAccessControlHandlerTest extends UnitTestCase {
|
||||
'uuid' => '6f2f259a-f3c7-42ea-bdd5-111ad1f85ed1',
|
||||
]);
|
||||
|
||||
$this->entity = $this->fieldStorage;
|
||||
$this->accessControlHandler = $storage_access_control_handler;
|
||||
}
|
||||
|
||||
@@ -188,7 +187,7 @@ class FieldStorageConfigAccessControlHandlerTest extends UnitTestCase {
|
||||
$this->assertAllowOperations([], $this->anon);
|
||||
$this->assertAllowOperations(['view', 'update', 'delete'], $this->member);
|
||||
|
||||
$this->fieldStorage->setLocked(TRUE)->save();
|
||||
$this->entity->setLocked(TRUE)->save();
|
||||
// Unfortunately, EntityAccessControlHandler has a static cache, which we
|
||||
// therefore must reset manually.
|
||||
$this->accessControlHandler->resetCache();
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
namespace Drupal\Tests\field\Unit;
|
||||
|
||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||
use Drupal\Core\Entity\EntityManager;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\Core\Field\FieldException;
|
||||
use Drupal\Core\Field\FieldStorageDefinitionInterface;
|
||||
use Drupal\Core\Field\FieldTypePluginManagerInterface;
|
||||
@@ -22,11 +24,11 @@ use Drupal\Tests\UnitTestCase;
|
||||
class FieldStorageConfigEntityUnitTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* The entity manager used for testing.
|
||||
* The entity type manager used for testing.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityManagerInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
* @var \Drupal\Core\Entity\EntityTypeManagerInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $entityManager;
|
||||
protected $entityTypeManager;
|
||||
|
||||
/**
|
||||
* The ID of the type of the entity under test.
|
||||
@@ -53,14 +55,19 @@ class FieldStorageConfigEntityUnitTest extends UnitTestCase {
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
$this->entityManager = $this->getMock('\Drupal\Core\Entity\EntityManagerInterface');
|
||||
$entity_manager = new EntityManager();
|
||||
$this->entityTypeManager = $this->getMock(EntityTypeManagerInterface::class);
|
||||
$this->uuid = $this->getMock('\Drupal\Component\Uuid\UuidInterface');
|
||||
$this->fieldTypeManager = $this->getMock(FieldTypePluginManagerInterface::class);
|
||||
|
||||
$container = new ContainerBuilder();
|
||||
$container->set('entity.manager', $this->entityManager);
|
||||
$container->set('entity.manager', $entity_manager);
|
||||
$container->set('entity_type.manager', $this->entityTypeManager);
|
||||
$container->set('uuid', $this->uuid);
|
||||
$container->set('plugin.manager.field.field_type', $this->fieldTypeManager);
|
||||
// Inject the container into entity.manager so it can defer to
|
||||
// entity_type.manager.
|
||||
$entity_manager->setContainer($container);
|
||||
\Drupal::setContainer($container);
|
||||
}
|
||||
|
||||
@@ -85,7 +92,7 @@ class FieldStorageConfigEntityUnitTest extends UnitTestCase {
|
||||
// ConfigEntityBase::addDependency() to get the provider of the field config
|
||||
// entity type and once in FieldStorageConfig::calculateDependencies() to
|
||||
// get the provider of the entity type that field is attached to.
|
||||
$this->entityManager->expects($this->any())
|
||||
$this->entityTypeManager->expects($this->any())
|
||||
->method('getDefinition')
|
||||
->willReturnMap([
|
||||
['field_storage_config', TRUE, $fieldStorageConfigentityType],
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\field\Unit\Plugin\migrate\process;
|
||||
|
||||
use Drupal\field\Plugin\migrate\process\FieldTypeDefaults;
|
||||
use Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase;
|
||||
|
||||
/**
|
||||
* Tests the deprecation of the field_type_defaults process plugin.
|
||||
*
|
||||
* @coversDefaultClass \Drupal\field\Plugin\migrate\process\FieldTypeDefaults
|
||||
* @group field
|
||||
* @group legacy
|
||||
*/
|
||||
class FieldTypeDefaultsTest extends MigrateProcessTestCase {
|
||||
|
||||
/**
|
||||
* Tests that the field_type_defaults plugin triggers a deprecation error.
|
||||
*
|
||||
* @expectedDeprecation The field_type_defaults process plugin is deprecated in Drupal 8.6.0 and will be removed before Drupal 9.0.0. Use d6_field_type_defaults or d7_field_type_defaults instead. See https://www.drupal.org/node/2944589.
|
||||
*/
|
||||
public function testDeprecatedError() {
|
||||
$this->plugin = new FieldTypeDefaults([], 'field_type_defaults', []);
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -19,7 +19,7 @@ class FieldTypeDefaultsTest extends MigrateProcessTestCase {
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->plugin = new FieldTypeDefaults([], 'field_type_defaults', []);
|
||||
$this->plugin = new FieldTypeDefaults([], 'd6_field_type_defaults', []);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\field\Unit\Plugin\migrate\process\d7;
|
||||
|
||||
use Drupal\field\Plugin\migrate\process\d7\FieldTypeDefaults;
|
||||
use Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase;
|
||||
|
||||
/**
|
||||
* Tests D7 field formatter defaults.
|
||||
*
|
||||
* @coversDefaultClass \Drupal\field\Plugin\migrate\process\d7\FieldTypeDefaults
|
||||
* @group field
|
||||
*/
|
||||
class FieldTypeDefaultsTest extends MigrateProcessTestCase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->plugin = new FieldTypeDefaults([], 'd7_field_type_defaults', []);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests various default cases.
|
||||
*
|
||||
* @covers ::transform
|
||||
*/
|
||||
public function testDefaults() {
|
||||
// Assert common values are passed through without modification.
|
||||
$this->assertNull($this->plugin->transform(NULL, $this->migrateExecutable, $this->row, 'property'));
|
||||
$this->assertEquals('string', $this->plugin->transform('string', $this->migrateExecutable, $this->row, 'property'));
|
||||
$this->assertEquals(1234, $this->plugin->transform(1234, $this->migrateExecutable, $this->row, 'property'));
|
||||
// Assert that an array will return the second item, which is the source
|
||||
// formatter type.
|
||||
$this->assertEquals('datetime_default', $this->plugin->transform(['datetime', 'datetime_default'], $this->migrateExecutable, $this->row, 'property'));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user