Update to Drupal 8.2.4. For more information, see https://www.drupal.org/project/drupal/releases/8.2.4
This commit is contained in:
parent
0a95b8440e
commit
8544b60b39
284 changed files with 12980 additions and 3199 deletions
|
@ -123,4 +123,4 @@ process:
|
|||
- '@type'
|
||||
- global_settings
|
||||
destination:
|
||||
plugin: md_entity:field_storage_config
|
||||
plugin: entity:field_storage_config
|
||||
|
|
|
@ -22,6 +22,7 @@ process:
|
|||
datestamp: datetime
|
||||
datetime: datetime
|
||||
email: email
|
||||
entityreference: entity_reference
|
||||
file: file
|
||||
image: image
|
||||
link_field: link
|
||||
|
|
|
@ -51,7 +51,7 @@ process:
|
|||
-
|
||||
plugin: static_map
|
||||
bypass: true
|
||||
source: type
|
||||
source: formatter_type
|
||||
map:
|
||||
date_default: datetime_default
|
||||
email_default: email_mailto
|
||||
|
@ -61,6 +61,9 @@ process:
|
|||
link_default: link
|
||||
phone: basic_string
|
||||
taxonomy_term_reference_link: entity_reference_label
|
||||
entityreference_label: entity_reference_label
|
||||
entityreference_entity_id: entity_reference_entity_id
|
||||
entityreference_entity_view: entity_reference_entity_view
|
||||
-
|
||||
plugin: skip_on_empty
|
||||
method: row
|
||||
|
|
|
@ -21,6 +21,7 @@ process:
|
|||
source:
|
||||
- instance_settings
|
||||
- widget_settings
|
||||
- field_settings
|
||||
default_value_function: ''
|
||||
default_value:
|
||||
plugin: d7_field_instance_defaults
|
||||
|
|
|
@ -46,6 +46,7 @@ process:
|
|||
phone_textfield: telephone_default
|
||||
options_onoff: boolean_checkbox
|
||||
entityreference_autocomplete: entity_reference_autocomplete
|
||||
entityreference_autocomplete_tags: entity_reference_autocomplete_tags
|
||||
taxonomy_autocomplete: entity_reference_autocomplete
|
||||
'options/settings':
|
||||
plugin: field_instance_widget_settings
|
||||
|
|
|
@ -17,9 +17,38 @@ class FieldInstanceSettings extends ProcessPluginBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
|
||||
list($instance_settings, $widget_settings) = $value;
|
||||
list($instance_settings, $widget_settings, $field_settings) = $value;
|
||||
$widget_type = $widget_settings['type'];
|
||||
|
||||
// Get entityreference handler settings from source field configuration.
|
||||
if ($row->getSourceProperty('type') == "entityreference") {
|
||||
$instance_settings['handler'] = 'default:' . $field_settings['target_type'];
|
||||
// Transform the sort settings to D8 structure.
|
||||
$sort = [
|
||||
'field' => '_none',
|
||||
'direction' => 'ASC',
|
||||
];
|
||||
if (!empty(array_filter($field_settings['handler_settings']['sort']))) {
|
||||
if ($field_settings['handler_settings']['sort']['type'] == "property") {
|
||||
$sort = [
|
||||
'field' => $field_settings['handler_settings']['sort']['property'],
|
||||
'direction' => $field_settings['handler_settings']['sort']['direction'],
|
||||
];
|
||||
}
|
||||
elseif ($field_settings['handler_settings']['sort']['type'] == "field") {
|
||||
$sort = [
|
||||
'field' => $field_settings['handler_settings']['sort']['field'],
|
||||
'direction' => $field_settings['handler_settings']['sort']['direction'],
|
||||
];
|
||||
}
|
||||
}
|
||||
if (empty($field_settings['handler_settings']['target_bundles'])) {
|
||||
$field_settings['handler_settings']['target_bundles'] = NULL;
|
||||
}
|
||||
$field_settings['handler_settings']['sort'] = $sort;
|
||||
$instance_settings['handler_settings'] = $field_settings['handler_settings'];
|
||||
}
|
||||
|
||||
switch ($widget_type) {
|
||||
case 'image_image':
|
||||
$settings = $instance_settings;
|
||||
|
|
|
@ -28,6 +28,7 @@ class FieldInstance extends DrupalSqlBase {
|
|||
->fields('fc', array('type'));
|
||||
|
||||
$query->innerJoin('field_config', 'fc', 'fci.field_id = fc.id');
|
||||
$query->addField('fc', 'data', 'field_data');
|
||||
|
||||
// Optionally filter by entity type and bundle.
|
||||
if (isset($this->configuration['entity_type'])) {
|
||||
|
@ -53,6 +54,7 @@ class FieldInstance extends DrupalSqlBase {
|
|||
'instance_settings' => $this->t('Field instance settings.'),
|
||||
'widget_settings' => $this->t('Widget settings.'),
|
||||
'display_settings' => $this->t('Display settings.'),
|
||||
'field_settings' => $this->t('Field settings.'),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -81,6 +83,9 @@ class FieldInstance extends DrupalSqlBase {
|
|||
// This is for parity with the d6_field_instance plugin.
|
||||
$row->setSourceProperty('widget_type', $data['widget']['type']);
|
||||
|
||||
$field_data = unserialize($row->getSourceProperty('field_data'));
|
||||
$row->setSourceProperty('field_settings', $field_data['settings']);
|
||||
|
||||
return parent::prepareRow($row);
|
||||
}
|
||||
|
||||
|
|
|
@ -24,8 +24,15 @@ class FieldInstancePerViewMode extends DrupalSqlBase {
|
|||
$data = unserialize($field_instance['data']);
|
||||
// We don't need to include the serialized data in the returned rows.
|
||||
unset($field_instance['data']);
|
||||
|
||||
foreach ($data['display'] as $view_mode => $info) {
|
||||
$rows[] = array_merge($field_instance, $info, array('view_mode' => $view_mode));
|
||||
// Rename type to formatter_type in the info array.
|
||||
$info['formatter_type'] = $info['type'];
|
||||
unset($info['type']);
|
||||
|
||||
$rows[] = array_merge($field_instance, $info, [
|
||||
'view_mode' => $view_mode,
|
||||
]);
|
||||
}
|
||||
}
|
||||
return new \ArrayIterator($rows);
|
||||
|
@ -35,8 +42,11 @@ class FieldInstancePerViewMode extends DrupalSqlBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function query() {
|
||||
return $this->select('field_config_instance', 'fci')
|
||||
->fields('fci', array('entity_type', 'bundle', 'field_name', 'data'));
|
||||
$query = $this->select('field_config_instance', 'fci')
|
||||
->fields('fci', ['entity_type', 'bundle', 'field_name', 'data'])
|
||||
->fields('fc', ['type']);
|
||||
$query->join('field_config', 'fc', 'fc.field_name = fci.field_name');
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -49,7 +59,8 @@ class FieldInstancePerViewMode extends DrupalSqlBase {
|
|||
'field_name' => $this->t('Machine name of the field.'),
|
||||
'view_mode' => $this->t('The original machine name of the view mode.'),
|
||||
'label' => $this->t('The display label of the field.'),
|
||||
'type' => $this->t('The formatter ID.'),
|
||||
'type' => $this->t('The field ID.'),
|
||||
'formatter_type' => $this->t('The formatter ID.'),
|
||||
'settings' => $this->t('Array of formatter-specific settings.'),
|
||||
'module' => $this->t('The module providing the formatter.'),
|
||||
'weight' => $this->t('Display weight of the field.'),
|
||||
|
|
|
@ -20,7 +20,12 @@ class BooleanFieldTest extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('entity_test', 'field_ui', 'options');
|
||||
public static $modules = [
|
||||
'entity_test',
|
||||
'field_ui',
|
||||
'options',
|
||||
'field_test_boolean_access_denied',
|
||||
];
|
||||
|
||||
/**
|
||||
* A field to use in this test class.
|
||||
|
@ -179,4 +184,66 @@ class BooleanFieldTest extends WebTestBase {
|
|||
$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->url, $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->url, $match);
|
||||
$id = $match[1];
|
||||
$this->assertText(t('entity_test @id has been created.', ['@id' => $id]));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\field_test\Plugin\Field\FieldType;
|
||||
|
||||
use Drupal\Core\Field\FieldStorageDefinitionInterface;
|
||||
use Drupal\Core\TypedData\DataDefinition;
|
||||
use Drupal\Core\Field\FieldItemBase;
|
||||
|
||||
/**
|
||||
* Defines the 'test_object_field' entity field item.
|
||||
*
|
||||
* @FieldType(
|
||||
* id = "test_object_field",
|
||||
* label = @Translation("Test object field"),
|
||||
* description = @Translation("Test field type that has an object to test serialization"),
|
||||
* default_widget = "test_object_field_widget",
|
||||
* default_formatter = "object_field_test_default"
|
||||
* )
|
||||
*/
|
||||
class TestObjectItem extends FieldItemBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
|
||||
$properties['value'] = DataDefinition::create('any')
|
||||
->setLabel(t('Value'))
|
||||
->setRequired(TRUE);
|
||||
|
||||
return $properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function schema(FieldStorageDefinitionInterface $field_definition) {
|
||||
return [
|
||||
'columns' => [
|
||||
'value' => [
|
||||
'description' => 'The object item value.',
|
||||
'type' => 'blob',
|
||||
'not null' => TRUE,
|
||||
'serialize' => TRUE,
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setValue($values, $notify = TRUE) {
|
||||
if (isset($values['value'])) {
|
||||
// @todo Remove this in https://www.drupal.org/node/2788637.
|
||||
if (is_string($values['value'])) {
|
||||
$values['value'] = unserialize($values['value']);
|
||||
}
|
||||
}
|
||||
parent::setValue($values, $notify);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
name: 'Boolean field Test'
|
||||
type: module
|
||||
description: 'Support module for the field and entity display tests.'
|
||||
core: 8.x
|
||||
package: Testing
|
||||
version: VERSION
|
||||
dependencies:
|
||||
- field
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Module for testing denying access to boolean fields.
|
||||
*/
|
||||
|
||||
use Drupal\Core\Access\AccessResult;
|
||||
use Drupal\Core\Field\FieldDefinitionInterface;
|
||||
use Drupal\Core\Field\FieldItemListInterface;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
|
||||
/**
|
||||
* Implements hook_entity_field_access().
|
||||
*/
|
||||
function field_test_boolean_access_denied_entity_field_access($operation, FieldDefinitionInterface $field_definition, AccountInterface $account, FieldItemListInterface $items = NULL) {
|
||||
return AccessResult::forbiddenIf($field_definition->getName() === \Drupal::state()->get('field.test_boolean_field_access_field'));
|
||||
}
|
|
@ -277,6 +277,49 @@ class EntityReferenceFormatterTest extends EntityKernelTestBase {
|
|||
$this->assertEqual($actual_occurrences, $expected_occurrences);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the same entity referenced from different places.
|
||||
*/
|
||||
public function testEntityReferenceRecursiveProtectionWithManyRenderedEntities() {
|
||||
$formatter = 'entity_reference_entity_view';
|
||||
$view_builder = $this->entityManager->getViewBuilder($this->entityType);
|
||||
|
||||
// Set the default view mode to use the 'entity_reference_entity_view'
|
||||
// formatter.
|
||||
entity_get_display($this->entityType, $this->bundle, 'default')
|
||||
->setComponent($this->fieldName, [
|
||||
'type' => $formatter,
|
||||
])
|
||||
->save();
|
||||
|
||||
$storage = $this->entityManager->getStorage($this->entityType);
|
||||
/** @var \Drupal\Core\Entity\ContentEntityInterface $referenced_entity */
|
||||
$referenced_entity = $storage->create(['name' => $this->randomMachineName()]);
|
||||
|
||||
$range = range(0, 30);
|
||||
$referencing_entities = array_map(function () use ($storage, $referenced_entity) {
|
||||
$referencing_entity = $storage->create([
|
||||
'name' => $this->randomMachineName(),
|
||||
$this->fieldName => $referenced_entity,
|
||||
]);
|
||||
$referencing_entity->save();
|
||||
return $referencing_entity;
|
||||
}, $range);
|
||||
|
||||
$build = $view_builder->viewMultiple($referencing_entities, 'default');
|
||||
$output = $this->render($build);
|
||||
|
||||
// The title of entity_test entities is printed twice by default, so we have
|
||||
// to multiply the formatter's recursive rendering protection limit by 2.
|
||||
// Additionally, we have to take into account 2 additional occurrences of
|
||||
// the entity title because we're rendering the full entity, not just the
|
||||
// reference field.
|
||||
$expected_occurrences = 30 * 2 + 2;
|
||||
$actual_occurrences = substr_count($output, $referenced_entity->get('name')->value);
|
||||
$this->assertEquals($expected_occurrences, $actual_occurrences);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tests the label formatter.
|
||||
*/
|
||||
|
|
|
@ -276,6 +276,9 @@ class MigrateFieldFormatterSettingsTest extends MigrateDrupal7TestBase {
|
|||
$this->assertComponent('node.test_content_type.default', 'field_text_list', 'list_default', 'above', 10);
|
||||
$this->assertComponent('node.test_content_type.default', 'field_integer_list', 'list_default', 'above', 11);
|
||||
$this->assertComponent('node.test_content_type.default', 'field_long_text', 'text_default', 'above', 12);
|
||||
$this->assertComponent('node.test_content_type.default', 'field_node_entityreference', 'entity_reference_label', 'above', 15);
|
||||
$this->assertComponent('node.test_content_type.default', 'field_user_entityreference', 'entity_reference_label', 'above', 16);
|
||||
$this->assertComponent('node.test_content_type.default', 'field_term_entityreference', 'entity_reference_label', 'above', 17);
|
||||
$this->assertComponentNotExists('node.test_content_type.default', 'field_term_reference');
|
||||
$this->assertComponentNotExists('node.test_content_type.default', 'field_text');
|
||||
|
||||
|
|
|
@ -141,6 +141,9 @@ class MigrateFieldInstanceTest extends MigrateDrupal7TestBase {
|
|||
$this->assertEntity('node.test_content_type.field_integer_list', 'Integer List', 'list_integer', FALSE);
|
||||
$this->assertEntity('node.test_content_type.field_long_text', 'Long text', 'text_with_summary', FALSE);
|
||||
$this->assertEntity('node.test_content_type.field_term_reference', 'Term Reference', 'entity_reference', FALSE);
|
||||
$this->assertEntity('node.test_content_type.field_node_entityreference', 'Node Entity Reference', 'entity_reference', FALSE);
|
||||
$this->assertEntity('node.test_content_type.field_user_entityreference', 'User Entity Reference', 'entity_reference', FALSE);
|
||||
$this->assertEntity('node.test_content_type.field_term_entityreference', 'Term Entity Reference', 'entity_reference', FALSE);
|
||||
$this->assertEntity('node.test_content_type.field_text', 'Text', 'text', FALSE);
|
||||
$this->assertEntity('comment.comment_node_test_content_type.field_integer', 'Integer', 'integer', FALSE);
|
||||
$this->assertEntity('user.user.field_file', 'File', 'file', FALSE);
|
||||
|
|
|
@ -125,6 +125,9 @@ class MigrateFieldInstanceWidgetSettingsTest extends MigrateDrupal7TestBase {
|
|||
$this->assertComponent('node.test_content_type.default', 'field_long_text', 'text_textarea_with_summary', 13);
|
||||
$this->assertComponent('node.test_content_type.default', 'field_phone', 'telephone_default', 6);
|
||||
$this->assertComponent('node.test_content_type.default', 'field_term_reference', 'entity_reference_autocomplete', 14);
|
||||
$this->assertComponent('node.test_content_type.default', 'field_node_entityreference', 'entity_reference_autocomplete', 16);
|
||||
$this->assertComponent('node.test_content_type.default', 'field_user_entityreference', 'options_buttons', 17);
|
||||
$this->assertComponent('node.test_content_type.default', 'field_term_entityreference', 'entity_reference_autocomplete_tags', 18);
|
||||
$this->assertComponent('node.test_content_type.default', 'field_text', 'text_textfield', 15);
|
||||
$this->assertComponent('node.test_content_type.default', 'field_text_list', 'options_select', 11);
|
||||
|
||||
|
|
|
@ -100,6 +100,9 @@ class MigrateFieldTest extends MigrateDrupal7TestBase {
|
|||
$this->assertEntity('node.field_phone', 'telephone', FALSE, 1);
|
||||
$this->assertEntity('node.field_date', 'datetime', FALSE, 1);
|
||||
$this->assertEntity('node.field_date_with_end_time', 'datetime', FALSE, 1);
|
||||
$this->assertEntity('node.field_node_entityreference', 'entity_reference', FALSE, -1);
|
||||
$this->assertEntity('node.field_user_entityreference', 'entity_reference', FALSE, 1);
|
||||
$this->assertEntity('node.field_term_entityreference', 'entity_reference', FALSE, -1);
|
||||
|
||||
// Assert that the taxonomy term reference fields are referencing the
|
||||
// correct entity type.
|
||||
|
@ -108,6 +111,15 @@ class MigrateFieldTest extends MigrateDrupal7TestBase {
|
|||
$field = FieldStorageConfig::load('node.taxonomy_forums');
|
||||
$this->assertIdentical('taxonomy_term', $field->getSetting('target_type'));
|
||||
|
||||
// Assert that the entityreference fields are referencing the correct
|
||||
// entity type.
|
||||
$field = FieldStorageConfig::load('node.field_node_entityreference');
|
||||
$this->assertIdentical('node', $field->getSetting('target_type'));
|
||||
$field = FieldStorageConfig::load('node.field_user_entityreference');
|
||||
$this->assertIdentical('user', $field->getSetting('target_type'));
|
||||
$field = FieldStorageConfig::load('node.field_term_entityreference');
|
||||
$this->assertIdentical('taxonomy_term', $field->getSetting('target_type'));
|
||||
|
||||
// Validate that the source count and processed count match up.
|
||||
/** @var \Drupal\migrate\Plugin\MigrationInterface $migration */
|
||||
$migration = $this->getMigration('d7_field');
|
||||
|
|
|
@ -41,6 +41,24 @@ class FieldInstancePerViewModeTest extends MigrateSqlSourceTestBase {
|
|||
],
|
||||
];
|
||||
|
||||
$tests[0]['source_data']['field_config'] = [
|
||||
[
|
||||
'id' => '2',
|
||||
'field_name' => 'body',
|
||||
'type' => 'text_with_summary',
|
||||
'module' => 'text',
|
||||
'active' => '1',
|
||||
'storage_type' => 'field_sql_storage',
|
||||
'storage_module' => 'field_sql_storage',
|
||||
'storage_active' => '1',
|
||||
'locked' => '0',
|
||||
'data' => 'a:7:{s:12:"entity_types";a:1:{i:0;s:4:"node";}s:7:"indexes";a:1:{s:6:"format";a:1:{i:0;s:6:"format";}}s:8:"settings";a:0:{}s:12:"translatable";i:0;s:12:"foreign keys";a:1:{s:6:"format";a:2:{s:5:"table";s:13:"filter_format";s:7:"columns";a:1:{s:6:"format";s:6:"format";}}}s:7:"storage";a:4:{s:4:"type";s:17:"field_sql_storage";s:8:"settings";a:0:{}s:6:"module";s:17:"field_sql_storage";s:6:"active";s:1:"1";}s:2:"id";s:2:"25";}',
|
||||
'cardinality' => '1',
|
||||
'translatable' => '0',
|
||||
'deleted' => '0',
|
||||
],
|
||||
];
|
||||
|
||||
// The expected results.
|
||||
$tests[0]['expected_data'] = [
|
||||
[
|
||||
|
@ -48,7 +66,8 @@ class FieldInstancePerViewModeTest extends MigrateSqlSourceTestBase {
|
|||
'bundle' => 'page',
|
||||
'field_name' => 'body',
|
||||
'label' => 'hidden',
|
||||
'type' => 'text_default',
|
||||
'type' => 'text_with_summary',
|
||||
'formatter_type' => 'text_default',
|
||||
'settings' => [],
|
||||
'module' => 'text',
|
||||
'weight' => 0,
|
||||
|
@ -59,7 +78,8 @@ class FieldInstancePerViewModeTest extends MigrateSqlSourceTestBase {
|
|||
'bundle' => 'page',
|
||||
'field_name' => 'body',
|
||||
'label' => 'hidden',
|
||||
'type' => 'text_summary_or_trimmed',
|
||||
'type' => 'text_with_summary',
|
||||
'formatter_type' => 'text_summary_or_trimmed',
|
||||
'settings' => [
|
||||
'trim_length' => 600,
|
||||
],
|
||||
|
|
30
core/modules/field/tests/src/Kernel/String/UuidItemTest.php
Normal file
30
core/modules/field/tests/src/Kernel/String/UuidItemTest.php
Normal file
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\field\Kernel\String;
|
||||
|
||||
use Drupal\entity_test\Entity\EntityTest;
|
||||
use Drupal\Tests\field\Kernel\FieldKernelTestBase;
|
||||
use Drupal\Component\Uuid\Uuid;
|
||||
|
||||
/**
|
||||
* Tests the UUID field.
|
||||
*
|
||||
* @group field
|
||||
*/
|
||||
class UuidItemTest extends FieldKernelTestBase {
|
||||
|
||||
/**
|
||||
* Tests 'uuid' random values.
|
||||
*/
|
||||
public function testSampleValue() {
|
||||
$entity = EntityTest::create([]);
|
||||
$entity->save();
|
||||
|
||||
$uuid_field = $entity->get('uuid');
|
||||
|
||||
// Test the generateSampleValue() method.
|
||||
$uuid_field->generateSampleItems();
|
||||
$this->assertTrue(Uuid::isValid($uuid_field->value));
|
||||
}
|
||||
|
||||
}
|
59
core/modules/field/tests/src/Kernel/TestObjectItemTest.php
Normal file
59
core/modules/field/tests/src/Kernel/TestObjectItemTest.php
Normal file
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\field\Kernel;
|
||||
|
||||
use Drupal\entity_test\Entity\EntityTest;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
|
||||
/**
|
||||
* Tests the serialization of an object.
|
||||
*
|
||||
* @group field
|
||||
*/
|
||||
class TestObjectItemTest extends FieldKernelTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('field_test');
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Create a 'test_field' field and storage for validation.
|
||||
FieldStorageConfig::create(array(
|
||||
'field_name' => 'field_test',
|
||||
'entity_type' => 'entity_test',
|
||||
'type' => 'test_object_field',
|
||||
))->save();
|
||||
FieldConfig::create([
|
||||
'entity_type' => 'entity_test',
|
||||
'field_name' => 'field_test',
|
||||
'bundle' => 'entity_test',
|
||||
])->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the serialization of a field type that has an object.
|
||||
*/
|
||||
public function testTestObjectItem() {
|
||||
$object = new \stdClass();
|
||||
$object->foo = 'bar';
|
||||
$entity = EntityTest::create();
|
||||
$entity->field_test->value = $object;
|
||||
$entity->save();
|
||||
|
||||
// Verify that the entity has been created properly.
|
||||
$id = $entity->id();
|
||||
$entity = EntityTest::load($id);
|
||||
$this->assertTrue($entity->field_test->value instanceof \stdClass);
|
||||
$this->assertEquals($object, $entity->field_test->value);
|
||||
}
|
||||
|
||||
}
|
|
@ -28,7 +28,7 @@ class FieldInstanceSettingsTest extends MigrateTestCase {
|
|||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$value = $plugin->transform([[], ['type' => 'image_image']], $executable, $row, 'foo');
|
||||
$value = $plugin->transform([[], ['type' => 'image_image'], []], $executable, $row, 'foo');
|
||||
$this->assertInternalType('array', $value['default_image']);
|
||||
$this->assertSame('', $value['default_image']['alt']);
|
||||
$this->assertSame('', $value['default_image']['title']);
|
||||
|
|
Reference in a new issue