updated core to 8.6.1 via composer
This commit is contained in:
@@ -43,7 +43,6 @@
|
||||
* @see plugin_api
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Perform alterations on Field API field types.
|
||||
*
|
||||
|
||||
@@ -324,12 +324,12 @@ function field_form_config_admin_import_form_alter(&$form, FormStateInterface $f
|
||||
foreach ($field_storages as $field) {
|
||||
$field_labels[] = $field->label();
|
||||
}
|
||||
drupal_set_message(\Drupal::translation()->formatPlural(
|
||||
\Drupal::messenger()->addWarning(\Drupal::translation()->formatPlural(
|
||||
count($field_storages),
|
||||
'This synchronization will delete data from the field %fields.',
|
||||
'This synchronization will delete data from the fields: %fields.',
|
||||
['%fields' => implode(', ', $field_labels)]
|
||||
), 'warning');
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ migration_tags:
|
||||
- Drupal 6
|
||||
- Configuration
|
||||
class: Drupal\migrate_drupal\Plugin\migrate\FieldMigration
|
||||
field_plugin_method: processField
|
||||
field_plugin_method: alterFieldMigration
|
||||
source:
|
||||
plugin: d6_field
|
||||
constants:
|
||||
|
||||
@@ -4,7 +4,7 @@ migration_tags:
|
||||
- Drupal 6
|
||||
- Configuration
|
||||
class: Drupal\migrate_drupal\Plugin\migrate\FieldMigration
|
||||
field_plugin_method: processFieldFormatter
|
||||
field_plugin_method: alterFieldFormatterMigration
|
||||
source:
|
||||
plugin: d6_field_instance_per_view_mode
|
||||
constants:
|
||||
|
||||
@@ -4,7 +4,7 @@ migration_tags:
|
||||
- Drupal 6
|
||||
- Configuration
|
||||
class: Drupal\migrate_drupal\Plugin\migrate\FieldMigration
|
||||
field_plugin_method: processFieldInstance
|
||||
field_plugin_method: alterFieldInstanceMigration
|
||||
source:
|
||||
plugin: d6_field_instance
|
||||
constants:
|
||||
|
||||
@@ -4,7 +4,7 @@ migration_tags:
|
||||
- Drupal 6
|
||||
- Configuration
|
||||
class: Drupal\migrate_drupal\Plugin\migrate\FieldMigration
|
||||
field_plugin_method: processFieldWidget
|
||||
field_plugin_method: alterFieldWidgetMigration
|
||||
source:
|
||||
plugin: d6_field_instance_per_form_display
|
||||
constants:
|
||||
@@ -57,6 +57,8 @@ process:
|
||||
optionwidgets_buttons: options_buttons
|
||||
optionwidgets_select: options_select
|
||||
nodereference_select: options_select
|
||||
nodereference_buttons: options_buttons
|
||||
nodereference_autocomplete: entity_reference_autocomplete_tags
|
||||
userreference_select: options_select
|
||||
'options/settings':
|
||||
-
|
||||
|
||||
@@ -4,7 +4,7 @@ migration_tags:
|
||||
- Drupal 7
|
||||
- Configuration
|
||||
class: Drupal\migrate_drupal\Plugin\migrate\FieldMigration
|
||||
field_plugin_method: processField
|
||||
field_plugin_method: alterFieldMigration
|
||||
source:
|
||||
plugin: d7_field
|
||||
constants:
|
||||
|
||||
@@ -4,7 +4,7 @@ migration_tags:
|
||||
- Drupal 7
|
||||
- Configuration
|
||||
class: Drupal\migrate_drupal\Plugin\migrate\FieldMigration
|
||||
field_plugin_method: processFieldFormatter
|
||||
field_plugin_method: alterFieldFormatterMigration
|
||||
source:
|
||||
plugin: d7_field_instance_per_view_mode
|
||||
constants:
|
||||
|
||||
@@ -4,7 +4,7 @@ migration_tags:
|
||||
- Drupal 7
|
||||
- Configuration
|
||||
class: Drupal\migrate_drupal\Plugin\migrate\FieldMigration
|
||||
field_plugin_method: processFieldInstance
|
||||
field_plugin_method: alterFieldInstanceMigration
|
||||
source:
|
||||
plugin: d7_field_instance
|
||||
constants:
|
||||
|
||||
@@ -4,7 +4,7 @@ migration_tags:
|
||||
- Drupal 7
|
||||
- Configuration
|
||||
class: Drupal\migrate_drupal\Plugin\migrate\FieldMigration
|
||||
field_plugin_method: processFieldWidget
|
||||
field_plugin_method: alterFieldWidgetMigration
|
||||
source:
|
||||
plugin: d7_field_instance_per_form_display
|
||||
constants:
|
||||
|
||||
@@ -15,6 +15,13 @@ use Drupal\field\FieldConfigInterface;
|
||||
* @ConfigEntityType(
|
||||
* id = "field_config",
|
||||
* label = @Translation("Field"),
|
||||
* label_collection = @Translation("Fields"),
|
||||
* label_singular = @Translation("field"),
|
||||
* label_plural = @Translation("fields"),
|
||||
* label_count = @PluralTranslation(
|
||||
* singular = "@count field",
|
||||
* plural = "@count fields",
|
||||
* ),
|
||||
* handlers = {
|
||||
* "access" = "Drupal\field\FieldConfigAccessControlHandler",
|
||||
* "storage" = "Drupal\field\FieldConfigStorage"
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace Drupal\field\Entity;
|
||||
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\Core\Config\Entity\ConfigEntityBase;
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\Core\Entity\FieldableEntityInterface;
|
||||
@@ -18,6 +17,13 @@ use Drupal\field\FieldStorageConfigInterface;
|
||||
* @ConfigEntityType(
|
||||
* id = "field_storage_config",
|
||||
* label = @Translation("Field storage"),
|
||||
* label_collection = @Translation("Field storages"),
|
||||
* label_singular = @Translation("field storage"),
|
||||
* label_plural = @Translation("field storages"),
|
||||
* label_count = @PluralTranslation(
|
||||
* singular = "@count field storage",
|
||||
* plural = "@count field storages",
|
||||
* ),
|
||||
* handlers = {
|
||||
* "access" = "Drupal\field\FieldStorageConfigAccessControlHandler",
|
||||
* "storage" = "Drupal\field\FieldStorageConfigStorage"
|
||||
@@ -310,10 +316,10 @@ class FieldStorageConfig extends ConfigEntityBase implements FieldStorageConfigI
|
||||
// Assign the ID.
|
||||
$this->id = $this->id();
|
||||
|
||||
// Field name cannot be longer than FieldStorageConfig::NAME_MAX_LENGTH characters.
|
||||
// We use Unicode::strlen() because the DB layer assumes that column widths
|
||||
// are given in characters rather than bytes.
|
||||
if (Unicode::strlen($this->getName()) > static::NAME_MAX_LENGTH) {
|
||||
// Field name cannot be longer than FieldStorageConfig::NAME_MAX_LENGTH
|
||||
// characters. We use mb_strlen() because the DB layer assumes that column
|
||||
// widths are given in characters rather than bytes.
|
||||
if (mb_strlen($this->getName()) > static::NAME_MAX_LENGTH) {
|
||||
throw new FieldException('Attempt to create a field storage with an name longer than ' . static::NAME_MAX_LENGTH . ' characters: ' . $this->getName());
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Drupal\field;
|
||||
|
||||
use Drupal\Core\Cache\MemoryCache\MemoryCacheInterface;
|
||||
use Drupal\Core\Config\Config;
|
||||
use Drupal\Core\Entity\EntityManagerInterface;
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
@@ -56,9 +57,11 @@ class FieldConfigStorage extends FieldConfigStorageBase {
|
||||
* The field type plugin manager.
|
||||
* @param \Drupal\Core\Field\DeletedFieldsRepositoryInterface $deleted_fields_repository
|
||||
* The deleted fields repository.
|
||||
* @param \Drupal\Core\Cache\MemoryCache\MemoryCacheInterface $memory_cache
|
||||
* The memory cache.
|
||||
*/
|
||||
public function __construct(EntityTypeInterface $entity_type, ConfigFactoryInterface $config_factory, UuidInterface $uuid_service, LanguageManagerInterface $language_manager, EntityManagerInterface $entity_manager, FieldTypePluginManagerInterface $field_type_manager, DeletedFieldsRepositoryInterface $deleted_fields_repository) {
|
||||
parent::__construct($entity_type, $config_factory, $uuid_service, $language_manager);
|
||||
public function __construct(EntityTypeInterface $entity_type, ConfigFactoryInterface $config_factory, UuidInterface $uuid_service, LanguageManagerInterface $language_manager, EntityManagerInterface $entity_manager, FieldTypePluginManagerInterface $field_type_manager, DeletedFieldsRepositoryInterface $deleted_fields_repository, MemoryCacheInterface $memory_cache) {
|
||||
parent::__construct($entity_type, $config_factory, $uuid_service, $language_manager, $memory_cache);
|
||||
$this->entityManager = $entity_manager;
|
||||
$this->fieldTypeManager = $field_type_manager;
|
||||
$this->deletedFieldsRepository = $deleted_fields_repository;
|
||||
@@ -75,7 +78,8 @@ class FieldConfigStorage extends FieldConfigStorageBase {
|
||||
$container->get('language_manager'),
|
||||
$container->get('entity.manager'),
|
||||
$container->get('plugin.manager.field.field_type'),
|
||||
$container->get('entity_field.deleted_fields_repository')
|
||||
$container->get('entity_field.deleted_fields_repository'),
|
||||
$container->get('entity.memory_cache')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace Drupal\field;
|
||||
|
||||
use Drupal\Component\Uuid\UuidInterface;
|
||||
use Drupal\Core\Cache\MemoryCache\MemoryCacheInterface;
|
||||
use Drupal\Core\Config\Entity\ConfigEntityStorage;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Entity\EntityManagerInterface;
|
||||
@@ -66,9 +67,11 @@ class FieldStorageConfigStorage extends ConfigEntityStorage {
|
||||
* The field type plugin manager.
|
||||
* @param \Drupal\Core\Field\DeletedFieldsRepositoryInterface $deleted_fields_repository
|
||||
* The deleted fields repository.
|
||||
* @param \Drupal\Core\Cache\MemoryCache\MemoryCacheInterface $memory_cache
|
||||
* The memory cache.
|
||||
*/
|
||||
public function __construct(EntityTypeInterface $entity_type, ConfigFactoryInterface $config_factory, UuidInterface $uuid_service, LanguageManagerInterface $language_manager, EntityManagerInterface $entity_manager, ModuleHandlerInterface $module_handler, FieldTypePluginManagerInterface $field_type_manager, DeletedFieldsRepositoryInterface $deleted_fields_repository) {
|
||||
parent::__construct($entity_type, $config_factory, $uuid_service, $language_manager);
|
||||
public function __construct(EntityTypeInterface $entity_type, ConfigFactoryInterface $config_factory, UuidInterface $uuid_service, LanguageManagerInterface $language_manager, EntityManagerInterface $entity_manager, ModuleHandlerInterface $module_handler, FieldTypePluginManagerInterface $field_type_manager, DeletedFieldsRepositoryInterface $deleted_fields_repository, MemoryCacheInterface $memory_cache) {
|
||||
parent::__construct($entity_type, $config_factory, $uuid_service, $language_manager, $memory_cache);
|
||||
$this->entityManager = $entity_manager;
|
||||
$this->moduleHandler = $module_handler;
|
||||
$this->fieldTypeManager = $field_type_manager;
|
||||
@@ -87,7 +90,8 @@ class FieldStorageConfigStorage extends ConfigEntityStorage {
|
||||
$container->get('entity.manager'),
|
||||
$container->get('module_handler'),
|
||||
$container->get('plugin.manager.field.field_type'),
|
||||
$container->get('entity_field.deleted_fields_repository')
|
||||
$container->get('entity_field.deleted_fields_repository'),
|
||||
$container->get('entity.memory_cache')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -85,7 +85,6 @@ class FieldUninstallValidator implements ModuleUninstallValidatorInterface {
|
||||
return $this->fieldStorageConfigStorage->loadByProperties(['module' => $module, 'include_deleted' => TRUE]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the label for a specified field type.
|
||||
*
|
||||
|
||||
@@ -147,7 +147,7 @@ class ProcessField extends ProcessPluginBase implements ContainerFactoryPluginIn
|
||||
$plugin_id = $field_plugin_manager->getPluginIdFromFieldType($field_type, [], $this->migration);
|
||||
$plugin_instance = $field_plugin_manager->createInstance($plugin_id, [], $this->migration);
|
||||
if (!is_callable([$plugin_instance, $method])) {
|
||||
throw new MigrateException('The specified method does not exists or is not callable.');
|
||||
throw new MigrateException('The specified method does not exist or is not callable.');
|
||||
}
|
||||
return call_user_func_array([$plugin_instance, $method], [$row]);
|
||||
}
|
||||
|
||||
@@ -28,17 +28,7 @@ class FieldInstanceDefaults extends ProcessPluginBase {
|
||||
unset($default_value[0]['email']);
|
||||
}
|
||||
|
||||
$default = [];
|
||||
|
||||
foreach ($default_value as $item) {
|
||||
switch ($widget_type) {
|
||||
// Add special processing here if needed.
|
||||
default:
|
||||
$default[] = $item;
|
||||
}
|
||||
}
|
||||
|
||||
return $default;
|
||||
return $default_value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -34,6 +34,19 @@ class Field extends DrupalSqlBase {
|
||||
->condition('fci.deleted', 0);
|
||||
$query->join('field_config_instance', 'fci', 'fc.id = fci.field_id');
|
||||
|
||||
// If the Drupal 7 Title module is enabled, we don't want to migrate the
|
||||
// fields it provides. The values of those fields will be migrated to the
|
||||
// base fields they were replacing.
|
||||
if ($this->moduleExists('title')) {
|
||||
$title_fields = [
|
||||
'title_field',
|
||||
'name_field',
|
||||
'description_field',
|
||||
'subject_field',
|
||||
];
|
||||
$query->condition('fc.field_name', $title_fields, 'NOT IN');
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ class FieldInstance extends DrupalSqlBase {
|
||||
public function query() {
|
||||
$query = $this->select('field_config_instance', 'fci')
|
||||
->fields('fci')
|
||||
->fields('fc', ['type'])
|
||||
->fields('fc', ['type', 'translatable'])
|
||||
->condition('fc.active', 1)
|
||||
->condition('fc.storage_active', 1)
|
||||
->condition('fc.deleted', 0)
|
||||
@@ -42,6 +42,19 @@ class FieldInstance extends DrupalSqlBase {
|
||||
}
|
||||
}
|
||||
|
||||
// If the Drupal 7 Title module is enabled, we don't want to migrate the
|
||||
// fields it provides. The values of those fields will be migrated to the
|
||||
// base fields they were replacing.
|
||||
if ($this->moduleExists('title')) {
|
||||
$title_fields = [
|
||||
'title_field',
|
||||
'name_field',
|
||||
'description_field',
|
||||
'subject_field',
|
||||
];
|
||||
$query->condition('fc.field_name', $title_fields, 'NOT IN');
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
@@ -102,12 +115,13 @@ class FieldInstance extends DrupalSqlBase {
|
||||
|
||||
$translatable = FALSE;
|
||||
if ($row->getSourceProperty('entity_type') == 'node') {
|
||||
$language_content_type_bundle = (int) $this->variableGet('language_content_type_' . $row->getSourceProperty('bundle'), 0);
|
||||
// language_content_type_[bundle] may be
|
||||
// - 0: no language support
|
||||
// - 1: language assignment support
|
||||
// - 2: node translation support
|
||||
// - 4: entity translation support
|
||||
if ($this->variableGet('language_content_type_' . $row->getSourceProperty('bundle'), 0) == 2) {
|
||||
if ($language_content_type_bundle === 2 || ($language_content_type_bundle === 4 && $row->getSourceProperty('translatable'))) {
|
||||
$translatable = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace Drupal\field\Tests\EntityReference;
|
||||
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\Core\Field\FieldStorageDefinitionInterface;
|
||||
use Drupal\field_ui\Tests\FieldUiTestTrait;
|
||||
@@ -294,7 +293,7 @@ class EntityReferenceAdminTest extends WebTestBase {
|
||||
|
||||
$edit = [
|
||||
'title[0][value]' => 'Example',
|
||||
'field_test_entity_ref_field[0][target_id]' => 'Test'
|
||||
'field_test_entity_ref_field[0][target_id]' => 'Test',
|
||||
];
|
||||
$this->drupalPostForm('node/add/' . $this->type, $edit, t('Save'));
|
||||
|
||||
@@ -303,7 +302,7 @@ class EntityReferenceAdminTest extends WebTestBase {
|
||||
|
||||
$edit = [
|
||||
'title[0][value]' => 'Test',
|
||||
'field_test_entity_ref_field[0][target_id]' => $node1->getTitle()
|
||||
'field_test_entity_ref_field[0][target_id]' => $node1->getTitle(),
|
||||
];
|
||||
$this->drupalPostForm('node/add/' . $this->type, $edit, t('Save'));
|
||||
|
||||
@@ -316,7 +315,7 @@ class EntityReferenceAdminTest extends WebTestBase {
|
||||
|
||||
$edit = [
|
||||
'title[0][value]' => 'Test',
|
||||
'field_test_entity_ref_field[0][target_id]' => $node1->getTitle() . ' (' . $node1->id() . ')'
|
||||
'field_test_entity_ref_field[0][target_id]' => $node1->getTitle() . ' (' . $node1->id() . ')',
|
||||
];
|
||||
$this->drupalPostForm('node/add/' . $this->type, $edit, t('Save'));
|
||||
$this->assertLink($node1->getTitle());
|
||||
@@ -424,7 +423,7 @@ class EntityReferenceAdminTest extends WebTestBase {
|
||||
/** @var \Drupal\taxonomy\Entity\Vocabulary[] $vocabularies */
|
||||
$vocabularies = [];
|
||||
for ($i = 0; $i < 2; $i++) {
|
||||
$vid = Unicode::strtolower($this->randomMachineName());
|
||||
$vid = mb_strtolower($this->randomMachineName());
|
||||
$vocabularies[$i] = Vocabulary::create([
|
||||
'name' => $this->randomString(),
|
||||
'vid' => $vid,
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace Drupal\field\Tests\Views;
|
||||
|
||||
@trigger_error(__NAMESPACE__ . '\FieldTestBase is deprecated in Drupal 8.6.0 and will be removed before Drupal 9.0.0. Instead, use \Drupal\Tests\field\Functional\Views\FieldTestBase. See https://www.drupal.org/node/2971931.', E_USER_DEPRECATED);
|
||||
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\node\Entity\NodeType;
|
||||
use Drupal\views\Tests\ViewTestBase;
|
||||
@@ -17,6 +19,11 @@ use Drupal\field\Entity\FieldStorageConfig;
|
||||
* - Use basic fields and make sure that the full wanted object is built.
|
||||
* - Use relationships between different entity types, for example node and
|
||||
* the node author(user).
|
||||
*
|
||||
* @deprecated in Drupal 8.6.0. Will be removed before Drupal 9.0.0. Use
|
||||
* \Drupal\Tests\field\Functional\Views\FieldTestBase instead.
|
||||
*
|
||||
* @see https://www.drupal.org/node/2989020
|
||||
*/
|
||||
abstract class FieldTestBase extends ViewTestBase {
|
||||
|
||||
|
||||
Vendored
+1
-1
@@ -66,7 +66,7 @@ $connection->update('key_value')
|
||||
->condition('collection', 'entity.definitions.installed')
|
||||
->condition('name', 'node.field_storage_definitions')
|
||||
->fields([
|
||||
'value' => serialize($installed)
|
||||
'value' => serialize($installed),
|
||||
])
|
||||
->execute();
|
||||
|
||||
|
||||
@@ -5,4 +5,4 @@ core: 8.x
|
||||
package: Testing
|
||||
version: VERSION
|
||||
dependencies:
|
||||
- text
|
||||
- drupal:text
|
||||
|
||||
@@ -63,6 +63,10 @@ field.widget.settings.test_field_widget_multiple_single_value:
|
||||
type: string
|
||||
label: 'Test setting'
|
||||
|
||||
field.widget.settings.test_field_widget_multilingual:
|
||||
type: field.widget.settings.test_field_widget
|
||||
label: 'Test multiple field widget settings: multilingual'
|
||||
|
||||
field.widget.third_party.color:
|
||||
type: mapping
|
||||
label: 'Field test entity display color module third party settings'
|
||||
|
||||
@@ -5,4 +5,4 @@ core: 8.x
|
||||
package: Testing
|
||||
version: VERSION
|
||||
dependencies:
|
||||
- entity_test
|
||||
- drupal:entity_test
|
||||
|
||||
@@ -104,7 +104,8 @@ function field_test_field_widget_form_alter(&$element, FormStateInterface $form_
|
||||
// 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_field_widget_form_alter(): Default form is true.');
|
||||
\Drupal::messenger()
|
||||
->addStatus('From hook_field_widget_form_alter(): Default form is true.');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,7 +130,6 @@ function field_test_field_widget_multivalue_test_field_widget_multiple_single_va
|
||||
_field_test_alter_widget("hook_field_widget_multivalue_WIDGET_TYPE_form_alter", $elements, $form_state, $context);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets up alterations for widget alter tests.
|
||||
*
|
||||
@@ -140,7 +140,7 @@ function _field_test_alter_widget($hook, array &$elements, FormStateInterface $f
|
||||
// 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.");
|
||||
\Drupal::messenger()->addStatus("From $hook(): Default form is true.");
|
||||
}
|
||||
$alter_info = \Drupal::state()->get("field_test.widget_alter_test");
|
||||
$name = $context['items']->getFieldDefinition()->getName();
|
||||
@@ -163,7 +163,6 @@ function field_test_query_efq_table_prefixing_test_alter(&$query) {
|
||||
$query->join('entity_test', 'et2', '%alias.id = entity_test.id');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implements hook_query_TAG_alter() for tag 'efq_metadata_test'.
|
||||
*
|
||||
|
||||
+2
-2
@@ -1,9 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\field\Tests;
|
||||
namespace Drupal\field_test;
|
||||
|
||||
/**
|
||||
* Helper class for \Drupal\field\Tests\FieldDefaultValueCallbackTest.
|
||||
* Helper class for \Drupal\Tests\field\Functional\FieldDefaultValueCallbackTest.
|
||||
*/
|
||||
class FieldDefaultValueCallbackProvider {
|
||||
|
||||
@@ -42,14 +42,14 @@ class NestedEntityTestForm extends FormBase {
|
||||
'#tree' => TRUE,
|
||||
'#parents' => ['entity_2'],
|
||||
'#weight' => 50,
|
||||
'#attributes' => ['class' => ['entity-2']]
|
||||
'#attributes' => ['class' => ['entity-2']],
|
||||
];
|
||||
|
||||
$form_display_2->buildForm($entity_2, $form['entity_2'], $form_state);
|
||||
|
||||
if ($entity_2 instanceof EntityChangedInterface) {
|
||||
// Changed must be sent to the client, for later overwrite error checking.
|
||||
// @see Drupal\field\Tests\NestedFormTest::testNestedEntityFormEntityLevelValidation()
|
||||
// @see \Drupal\Tests\field\Functional\NestedFormTest::testNestedEntityFormEntityLevelValidation()
|
||||
$form['entity_2']['changed'] = [
|
||||
'#type' => 'hidden',
|
||||
'#default_value' => $entity_1->getChangedTime(),
|
||||
@@ -82,7 +82,7 @@ class NestedEntityTestForm extends FormBase {
|
||||
// Extract the values of fields that are not rendered through widgets, by
|
||||
// simply copying from top-level form values. This leaves the fields that
|
||||
// are not being edited within this form untouched.
|
||||
// @see Drupal\field\Tests\NestedFormTest::testNestedEntityFormEntityLevelValidation()
|
||||
// @see \Drupal\Tests\field\Functional\NestedFormTest::testNestedEntityFormEntityLevelValidation()
|
||||
foreach ($form_state->getValues()['entity_2'] as $name => $values) {
|
||||
if ($entity_2->hasField($name) && !isset($extracted[$name])) {
|
||||
$entity_2->set($name, $values);
|
||||
@@ -92,7 +92,7 @@ class NestedEntityTestForm extends FormBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc]
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function submitForm(array &$form, FormStateInterface $form_state) {
|
||||
/** @var \Drupal\Core\Entity\EntityInterface $entity_1 */
|
||||
@@ -103,7 +103,7 @@ class NestedEntityTestForm extends FormBase {
|
||||
$entity_2 = $form_state->get('entity_2');
|
||||
$entity_2->save();
|
||||
|
||||
drupal_set_message($this->t('test_entities @id_1 and @id_2 have been updated.', ['@id_1' => $entity_1->id(), '@id_2' => $entity_2->id()]));
|
||||
$this->messenger()->addStatus($this->t('test_entities @id_1 and @id_2 have been updated.', ['@id_1' => $entity_1->id(), '@id_2' => $entity_2->id()]));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -120,7 +120,7 @@ class TestItem extends FieldItemBase {
|
||||
'TestField' => [
|
||||
'value' => -1,
|
||||
'message' => t('%name does not accept the value @value.', ['%name' => $this->getFieldDefinition()->getLabel(), '@value' => -1]),
|
||||
]
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@ class TestItemWithPreconfiguredOptions extends TestItem implements Preconfigured
|
||||
'field_storage_config' => [
|
||||
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
|
||||
'settings' => [
|
||||
'test_field_storage_setting' => 'preconfigured_storage_setting'
|
||||
'test_field_storage_setting' => 'preconfigured_storage_setting',
|
||||
],
|
||||
],
|
||||
'field_config' => [
|
||||
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\field_test\Plugin\Field\FieldWidget;
|
||||
|
||||
use Drupal\Core\Field\FieldItemListInterface;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
|
||||
/**
|
||||
* Plugin implementation of the 'test_field_widget_multilingual' widget.
|
||||
*
|
||||
* @FieldWidget(
|
||||
* id = "test_field_widget_multilingual",
|
||||
* label = @Translation("Test widget - multilingual"),
|
||||
* field_types = {
|
||||
* "test_field",
|
||||
* },
|
||||
* )
|
||||
*/
|
||||
class TestFieldWidgetMultilingual extends TestFieldWidget {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function form(FieldItemListInterface $items, array &$form, FormStateInterface $form_state, $get_delta = NULL) {
|
||||
$elements = parent::form($items, $form, $form_state, $get_delta);
|
||||
$elements['#multilingual'] = TRUE;
|
||||
return $elements;
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -5,4 +5,4 @@ core: 8.x
|
||||
package: Testing
|
||||
version: VERSION
|
||||
dependencies:
|
||||
- field
|
||||
- drupal:field
|
||||
|
||||
@@ -5,4 +5,4 @@ package: Testing
|
||||
version: VERSION
|
||||
core: 8.x
|
||||
dependencies:
|
||||
- views
|
||||
- drupal:views
|
||||
|
||||
+2
-2
@@ -5,5 +5,5 @@ core: 8.x
|
||||
package: Testing
|
||||
version: VERSION
|
||||
dependencies:
|
||||
- entity_test
|
||||
- field_test
|
||||
- drupal:entity_test
|
||||
- drupal:field_test
|
||||
|
||||
@@ -5,5 +5,5 @@ core: 8.x
|
||||
package: Testing
|
||||
version: VERSION
|
||||
dependencies:
|
||||
- entity_test
|
||||
- field
|
||||
- drupal:entity_test
|
||||
- drupal:field
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
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;
|
||||
@@ -64,7 +63,7 @@ class BooleanFieldTest extends BrowserTestBase {
|
||||
$label = $this->randomMachineName();
|
||||
|
||||
// Create a field with settings to validate.
|
||||
$field_name = Unicode::strtolower($this->randomMachineName());
|
||||
$field_name = mb_strtolower($this->randomMachineName());
|
||||
$this->fieldStorage = FieldStorageConfig::create([
|
||||
'field_name' => $field_name,
|
||||
'entity_type' => 'entity_test',
|
||||
@@ -123,7 +122,7 @@ class BooleanFieldTest extends BrowserTestBase {
|
||||
'type' => 'boolean_checkbox',
|
||||
'settings' => [
|
||||
'display_label' => FALSE,
|
||||
]
|
||||
],
|
||||
])
|
||||
->save();
|
||||
|
||||
|
||||
+14
-17
@@ -1,19 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\field\Tests\Boolean;
|
||||
namespace Drupal\Tests\field\Functional\Boolean;
|
||||
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Tests the Boolean field formatter settings.
|
||||
*
|
||||
* @group field
|
||||
*/
|
||||
class BooleanFormatterSettingsTest extends WebTestBase {
|
||||
class BooleanFormatterSettingsTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
@@ -43,14 +41,14 @@ class BooleanFormatterSettingsTest extends WebTestBase {
|
||||
parent::setUp();
|
||||
|
||||
// Create a content type. Use Node because it has Field UI pages that work.
|
||||
$type_name = Unicode::strtolower($this->randomMachineName(8)) . '_test';
|
||||
$type_name = mb_strtolower($this->randomMachineName(8)) . '_test';
|
||||
$type = $this->drupalCreateContentType(['name' => $type_name, 'type' => $type_name]);
|
||||
$this->bundle = $type->id();
|
||||
|
||||
$admin_user = $this->drupalCreateUser(['access content', 'administer content types', 'administer node fields', 'administer node display', 'bypass node access', 'administer nodes']);
|
||||
$this->drupalLogin($admin_user);
|
||||
|
||||
$this->fieldName = Unicode::strtolower($this->randomMachineName(8));
|
||||
$this->fieldName = mb_strtolower($this->randomMachineName(8));
|
||||
|
||||
$field_storage = FieldStorageConfig::create([
|
||||
'field_name' => $this->fieldName,
|
||||
@@ -90,10 +88,6 @@ class BooleanFormatterSettingsTest extends WebTestBase {
|
||||
'Custom',
|
||||
];
|
||||
|
||||
// Define what the "default" option should look like, depending on the
|
||||
// field settings.
|
||||
$default = 'Field settings (@on / @off)';
|
||||
|
||||
// For several different values of the field settings, test that the
|
||||
// options, including default, are shown correctly.
|
||||
$settings = [
|
||||
@@ -102,6 +96,7 @@ class BooleanFormatterSettingsTest extends WebTestBase {
|
||||
['TRUE', 'FALSE'],
|
||||
];
|
||||
|
||||
$assert_session = $this->assertSession();
|
||||
foreach ($settings as $values) {
|
||||
// Set up the field settings.
|
||||
$this->drupalGet('admin/structure/types/manage/' . $this->bundle . '/fields/node.' . $this->bundle . '.' . $this->fieldName);
|
||||
@@ -112,18 +107,20 @@ class BooleanFormatterSettingsTest extends WebTestBase {
|
||||
|
||||
// Open the Manage Display page and trigger the field settings form.
|
||||
$this->drupalGet('admin/structure/types/manage/' . $this->bundle . '/display');
|
||||
$this->drupalPostAjaxForm(NULL, [], $this->fieldName . '_settings_edit');
|
||||
$this->drupalPostForm(NULL, [], $this->fieldName . '_settings_edit');
|
||||
|
||||
// Test that the settings options are present in the correct format.
|
||||
foreach ($options as $string) {
|
||||
$this->assertText($string);
|
||||
$assert_session->pageTextContains($string);
|
||||
}
|
||||
$this->assertText(SafeMarkup::format($default, ['@on' => $values[0], '@off' => $values[1]]));
|
||||
}
|
||||
$assert_session->pageTextContains(t('Field settings (@on_label / @off_label)', ['@on_label' => $values[0], '@off_label' => $values[1]]));
|
||||
|
||||
foreach ($settings as $values) {
|
||||
// Test that the settings summary are present in the correct format.
|
||||
$this->drupalGet('admin/structure/types/manage/' . $this->bundle . '/display');
|
||||
$result = $this->xpath('//div[contains(@class, :class) and contains(text(), :text)]', [':class' => 'field-plugin-summary', ':text' => 'Display: TRUE / FALSE']);
|
||||
$result = $this->xpath('//div[contains(@class, :class) and contains(text(), :text)]', [
|
||||
':class' => 'field-plugin-summary',
|
||||
':text' => (string) t('Display: @true_label / @false_label', ['@true_label' => $values[0], '@false_label' => $values[1]]),
|
||||
]);
|
||||
$this->assertEqual(count($result), 1, "Boolean formatter settings summary exist.");
|
||||
}
|
||||
}
|
||||
+7
-8
@@ -1,19 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\field\Tests\Email;
|
||||
namespace Drupal\Tests\field\Functional\Email;
|
||||
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\entity_test\Entity\EntityTest;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Tests email field functionality.
|
||||
*
|
||||
* @group field
|
||||
*/
|
||||
class EmailFieldTest extends WebTestBase {
|
||||
class EmailFieldTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
@@ -51,7 +50,7 @@ class EmailFieldTest extends WebTestBase {
|
||||
*/
|
||||
public function testEmailField() {
|
||||
// Create a field with settings to validate.
|
||||
$field_name = Unicode::strtolower($this->randomMachineName());
|
||||
$field_name = mb_strtolower($this->randomMachineName());
|
||||
$this->fieldStorage = FieldStorageConfig::create([
|
||||
'field_name' => $field_name,
|
||||
'entity_type' => 'entity_test',
|
||||
@@ -91,7 +90,7 @@ class EmailFieldTest extends WebTestBase {
|
||||
"{$field_name}[0][value]" => $value,
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
preg_match('|entity_test/manage/(\d+)|', $this->url, $match);
|
||||
preg_match('|entity_test/manage/(\d+)|', $this->getUrl(), $match);
|
||||
$id = $match[1];
|
||||
$this->assertText(t('entity_test @id has been created.', ['@id' => $id]));
|
||||
$this->assertRaw($value);
|
||||
@@ -100,8 +99,8 @@ class EmailFieldTest extends WebTestBase {
|
||||
$entity = EntityTest::load($id);
|
||||
$display = entity_get_display($entity->getEntityTypeId(), $entity->bundle(), 'full');
|
||||
$content = $display->build($entity);
|
||||
$this->setRawContent(\Drupal::service('renderer')->renderRoot($content));
|
||||
$this->assertLinkByHref('mailto:test@example.com');
|
||||
$rendered_content = (string) \Drupal::service('renderer')->renderRoot($content);
|
||||
$this->assertContains('href="mailto:test@example.com"', $rendered_content);
|
||||
}
|
||||
|
||||
}
|
||||
+2
-3
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace Drupal\Tests\field\Functional\EntityReference;
|
||||
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\Core\Field\FieldStorageDefinitionInterface;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
@@ -145,7 +144,7 @@ class EntityReferenceAutoCreateTest extends BrowserTestBase {
|
||||
/** @var \Drupal\taxonomy\Entity\Vocabulary[] $vocabularies */
|
||||
$vocabularies = [];
|
||||
for ($i = 0; $i < 2; $i++) {
|
||||
$vid = Unicode::strtolower($this->randomMachineName());
|
||||
$vid = mb_strtolower($this->randomMachineName());
|
||||
$vocabularies[$i] = Vocabulary::create([
|
||||
'name' => $this->randomMachineName(),
|
||||
'vid' => $vid,
|
||||
@@ -156,7 +155,7 @@ class EntityReferenceAutoCreateTest extends BrowserTestBase {
|
||||
// Create a taxonomy term entity reference field that saves the auto-created
|
||||
// taxonomy terms in the second vocabulary from the two that were configured
|
||||
// as targets.
|
||||
$field_name = Unicode::strtolower($this->randomMachineName());
|
||||
$field_name = mb_strtolower($this->randomMachineName());
|
||||
$handler_settings = [
|
||||
'target_bundles' => [
|
||||
$vocabularies[0]->id() => $vocabularies[0]->id(),
|
||||
|
||||
+2
-3
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace Drupal\Tests\field\Functional\EntityReference;
|
||||
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\Tests\SchemaCheckTestTrait;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
@@ -51,7 +50,7 @@ class EntityReferenceFieldDefaultValueTest extends BrowserTestBase {
|
||||
// Create a node to be referenced.
|
||||
$referenced_node = $this->drupalCreateNode(['type' => 'referenced_content']);
|
||||
|
||||
$field_name = Unicode::strtolower($this->randomMachineName());
|
||||
$field_name = mb_strtolower($this->randomMachineName());
|
||||
$field_storage = FieldStorageConfig::create([
|
||||
'field_name' => $field_name,
|
||||
'entity_type' => 'node',
|
||||
@@ -114,7 +113,7 @@ class EntityReferenceFieldDefaultValueTest extends BrowserTestBase {
|
||||
$referenced_node_type = $this->drupalCreateContentType(['type' => 'referenced_config_to_delete']);
|
||||
$referenced_node_type2 = $this->drupalCreateContentType(['type' => 'referenced_config_to_preserve']);
|
||||
|
||||
$field_name = Unicode::strtolower($this->randomMachineName());
|
||||
$field_name = mb_strtolower($this->randomMachineName());
|
||||
$field_storage = FieldStorageConfig::create([
|
||||
'field_name' => $field_name,
|
||||
'entity_type' => 'node',
|
||||
|
||||
-1
@@ -302,7 +302,6 @@ class EntityReferenceFieldTranslatedReferenceViewTest extends BrowserTestBase {
|
||||
return $node;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create the referenced entity.
|
||||
*/
|
||||
|
||||
+8
-5
@@ -1,18 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\field\Tests\EntityReference;
|
||||
namespace Drupal\Tests\field\Functional\EntityReference;
|
||||
|
||||
use Drupal\Core\Field\FieldStorageDefinitionInterface;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
use Drupal\Tests\TestFileCreationTrait;
|
||||
|
||||
/**
|
||||
* Tests an autocomplete widget with file upload.
|
||||
*
|
||||
* @group entity_reference
|
||||
*/
|
||||
class EntityReferenceFileUploadTest extends WebTestBase {
|
||||
class EntityReferenceFileUploadTest extends BrowserTestBase {
|
||||
|
||||
use TestFileCreationTrait;
|
||||
|
||||
public static $modules = ['entity_reference', 'node', 'file'];
|
||||
|
||||
@@ -82,7 +85,7 @@ class EntityReferenceFileUploadTest extends WebTestBase {
|
||||
$field_storage = FieldStorageConfig::create([
|
||||
'field_name' => $file_field_name,
|
||||
'entity_type' => 'node',
|
||||
'type' => 'file'
|
||||
'type' => 'file',
|
||||
]);
|
||||
$field_storage->save();
|
||||
FieldConfig::create([
|
||||
@@ -113,7 +116,7 @@ class EntityReferenceFileUploadTest extends WebTestBase {
|
||||
$user1 = $this->drupalCreateUser(['access content', "create $this->referencingType content"]);
|
||||
$this->drupalLogin($user1);
|
||||
|
||||
$test_file = current($this->drupalGetTestFiles('text'));
|
||||
$test_file = current($this->getTestFiles('text'));
|
||||
$edit['files[file_field_0]'] = \Drupal::service('file_system')->realpath($test_file->uri);
|
||||
$this->drupalPostForm('node/add/' . $this->referencingType, $edit, 'Upload');
|
||||
$this->assertResponse(200);
|
||||
+3
-3
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Drupal\Tests\field\Functional\EntityReference;
|
||||
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
use Drupal\Component\Render\FormattableMarkup;
|
||||
use Drupal\entity_test\Entity\EntityTest;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
@@ -149,7 +149,7 @@ class EntityReferenceIntegrationTest extends BrowserTestBase {
|
||||
// Ensure the configuration has the expected dependency on the entity that
|
||||
// is being used a default value.
|
||||
$field = FieldConfig::loadByName($this->entityType, $this->bundle, $this->fieldName);
|
||||
$this->assertTrue(in_array($referenced_entities[0]->getConfigDependencyName(), $field->getDependencies()[$key]), SafeMarkup::format('Expected @type dependency @name found', ['@type' => $key, '@name' => $referenced_entities[0]->getConfigDependencyName()]));
|
||||
$this->assertTrue(in_array($referenced_entities[0]->getConfigDependencyName(), $field->getDependencies()[$key]), new FormattableMarkup('Expected @type dependency @name found', ['@type' => $key, '@name' => $referenced_entities[0]->getConfigDependencyName()]));
|
||||
// Ensure that the field can be imported without change even after the
|
||||
// default value deleted.
|
||||
$referenced_entities[0]->delete();
|
||||
@@ -163,7 +163,7 @@ class EntityReferenceIntegrationTest extends BrowserTestBase {
|
||||
$field = FieldConfig::loadByName($this->entityType, $this->bundle, $this->fieldName);
|
||||
$field->save();
|
||||
$dependencies = $field->getDependencies();
|
||||
$this->assertFalse(isset($dependencies[$key]) && in_array($referenced_entities[0]->getConfigDependencyName(), $dependencies[$key]), SafeMarkup::format('@type dependency @name does not exist.', ['@type' => $key, '@name' => $referenced_entities[0]->getConfigDependencyName()]));
|
||||
$this->assertFalse(isset($dependencies[$key]) && in_array($referenced_entities[0]->getConfigDependencyName(), $dependencies[$key]), new FormattableMarkup('@type dependency @name does not exist.', ['@type' => $key, '@name' => $referenced_entities[0]->getConfigDependencyName()]));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ class EntityReferenceXSSTest extends BrowserTestBase {
|
||||
|
||||
$edit = [
|
||||
'title[0][value]' => $this->randomString(),
|
||||
'entity_reference_test' => $referenced_node->id()
|
||||
'entity_reference_test' => $referenced_node->id(),
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, 'Save');
|
||||
$this->assertEscaped($referenced_node->getTitle());
|
||||
|
||||
@@ -127,7 +127,7 @@ class SelectionTest extends BrowserTestBase {
|
||||
'table' => 'users_field_data',
|
||||
'field' => 'uid',
|
||||
'relationship' => 'test_relationship',
|
||||
]
|
||||
],
|
||||
]);
|
||||
|
||||
// Set view to distinct so only one row per node is returned.
|
||||
|
||||
+4
-4
@@ -1,17 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\field\Tests;
|
||||
namespace Drupal\Tests\field\Functional;
|
||||
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Tests the default value callback.
|
||||
*
|
||||
* @group field
|
||||
*/
|
||||
class FieldDefaultValueCallbackTest extends WebTestBase {
|
||||
class FieldDefaultValueCallbackTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
@@ -81,7 +81,7 @@ class FieldDefaultValueCallbackTest extends WebTestBase {
|
||||
|
||||
// Set a default value callback instead, and the default field form should
|
||||
// not be visible.
|
||||
$field_config->setDefaultValueCallback('\Drupal\field\Tests\FieldDefaultValueCallbackProvider::calculateDefaultValue')->save();
|
||||
$field_config->setDefaultValueCallback('\Drupal\field_test\FieldDefaultValueCallbackProvider::calculateDefaultValue')->save();
|
||||
$this->drupalGet('/admin/structure/types/manage/article/fields/node.article.field_test');
|
||||
$this->assertNoFieldByName('default_value_input[field_test][0][value]', 'Calculated default value', 'The default field form is not visible when a callback is defined.');
|
||||
}
|
||||
@@ -14,7 +14,7 @@ class FieldHelpTest extends BrowserTestBase {
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array.
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['field', 'help'];
|
||||
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\field\Tests;
|
||||
namespace Drupal\Tests\field\Functional;
|
||||
|
||||
use Drupal\entity_test\Entity\EntityTest;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
+10
-10
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\field\Tests;
|
||||
namespace Drupal\Tests\field\Functional;
|
||||
|
||||
use Drupal\Component\Utility\Html;
|
||||
use Drupal\Core\Entity\Entity\EntityFormDisplay;
|
||||
@@ -119,7 +119,7 @@ class FormTest extends FieldTestBase {
|
||||
|
||||
// Submit with invalid value (field-level validation).
|
||||
$edit = [
|
||||
"{$field_name}[0][value]" => -1
|
||||
"{$field_name}[0][value]" => -1,
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
$this->assertRaw(t('%name does not accept the value -1.', ['%name' => $this->field['label']]), 'Field validation fails with invalid input.');
|
||||
@@ -131,7 +131,7 @@ class FormTest extends FieldTestBase {
|
||||
"{$field_name}[0][value]" => $value,
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
preg_match('|entity_test/manage/(\d+)|', $this->url, $match);
|
||||
preg_match('|entity_test/manage/(\d+)|', $this->getUrl(), $match);
|
||||
$id = $match[1];
|
||||
$this->assertText(t('entity_test @id has been created.', ['@id' => $id]), 'Entity was created');
|
||||
$entity = EntityTest::load($id);
|
||||
@@ -156,7 +156,7 @@ class FormTest extends FieldTestBase {
|
||||
// Empty the field.
|
||||
$value = '';
|
||||
$edit = [
|
||||
"{$field_name}[0][value]" => $value
|
||||
"{$field_name}[0][value]" => $value,
|
||||
];
|
||||
$this->drupalPostForm('entity_test/manage/' . $id . '/edit', $edit, t('Save'));
|
||||
$this->assertText(t('entity_test @id has been updated.', ['@id' => $id]), 'Entity was updated');
|
||||
@@ -190,7 +190,7 @@ class FormTest extends FieldTestBase {
|
||||
"{$field_name}[0][value]" => '',
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
preg_match('|entity_test/manage/(\d+)|', $this->url, $match);
|
||||
preg_match('|entity_test/manage/(\d+)|', $this->getUrl(), $match);
|
||||
$id = $match[1];
|
||||
$this->assertText(t('entity_test @id has been created.', ['@id' => $id]), 'Entity was created.');
|
||||
$entity = EntityTest::load($id);
|
||||
@@ -219,7 +219,7 @@ class FormTest extends FieldTestBase {
|
||||
"{$field_name}[0][value]" => $value,
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
preg_match('|entity_test/manage/(\d+)|', $this->url, $match);
|
||||
preg_match('|entity_test/manage/(\d+)|', $this->getUrl(), $match);
|
||||
$id = $match[1];
|
||||
$this->assertText(t('entity_test @id has been created.', ['@id' => $id]), 'Entity was created');
|
||||
$entity = EntityTest::load($id);
|
||||
@@ -300,7 +300,7 @@ class FormTest extends FieldTestBase {
|
||||
|
||||
// Submit the form and create the entity.
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
preg_match('|entity_test/manage/(\d+)|', $this->url, $match);
|
||||
preg_match('|entity_test/manage/(\d+)|', $this->getUrl(), $match);
|
||||
$id = $match[1];
|
||||
$this->assertText(t('entity_test @id has been created.', ['@id' => $id]), 'Entity was created');
|
||||
$entity = EntityTest::load($id);
|
||||
@@ -418,7 +418,7 @@ class FormTest extends FieldTestBase {
|
||||
$field_name => '1, 2, 3',
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
preg_match('|entity_test/manage/(\d+)|', $this->url, $match);
|
||||
preg_match('|entity_test/manage/(\d+)|', $this->getUrl(), $match);
|
||||
$id = $match[1];
|
||||
|
||||
// Check that the values were saved.
|
||||
@@ -498,7 +498,7 @@ class FormTest extends FieldTestBase {
|
||||
"{$field_name}[0][value]" => 1,
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
preg_match("|$entity_type/manage/(\d+)|", $this->url, $match);
|
||||
preg_match("|$entity_type/manage/(\d+)|", $this->getUrl(), $match);
|
||||
$id = $match[1];
|
||||
|
||||
// Check that the default value was saved.
|
||||
@@ -554,7 +554,7 @@ class FormTest extends FieldTestBase {
|
||||
// the field that uses the hidden widget.
|
||||
$this->assertNoField("{$field_name}[0][value]", 'The field does not appear in the form');
|
||||
$this->drupalPostForm(NULL, [], t('Save'));
|
||||
preg_match('|' . $entity_type . '/manage/(\d+)|', $this->url, $match);
|
||||
preg_match('|' . $entity_type . '/manage/(\d+)|', $this->getUrl(), $match);
|
||||
$id = $match[1];
|
||||
$this->assertText(t('entity_test_rev @id has been created.', ['@id' => $id]), 'Entity was created');
|
||||
$storage = $this->container->get('entity_type.manager')
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\field\Functional\Hal;
|
||||
|
||||
use Drupal\Tests\field\Functional\Rest\FieldConfigResourceTestBase;
|
||||
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class FieldConfigHalJsonAnonTest extends FieldConfigResourceTestBase {
|
||||
|
||||
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\field\Functional\Hal;
|
||||
|
||||
use Drupal\Tests\field\Functional\Rest\FieldConfigResourceTestBase;
|
||||
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class FieldConfigHalJsonBasicAuthTest extends FieldConfigResourceTestBase {
|
||||
|
||||
use BasicAuthResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['hal', 'basic_auth'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'hal_json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'basic_auth';
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\field\Functional\Hal;
|
||||
|
||||
use Drupal\Tests\field\Functional\Rest\FieldConfigResourceTestBase;
|
||||
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class FieldConfigHalJsonCookieTest extends FieldConfigResourceTestBase {
|
||||
|
||||
use CookieResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['hal'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'hal_json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'cookie';
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\field\Functional\Hal;
|
||||
|
||||
use Drupal\Tests\field\Functional\Rest\FieldStorageConfigResourceTestBase;
|
||||
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class FieldStorageConfigHalJsonAnonTest extends FieldStorageConfigResourceTestBase {
|
||||
|
||||
use AnonResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['hal'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'hal_json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\field\Functional\Hal;
|
||||
|
||||
use Drupal\Tests\field\Functional\Rest\FieldStorageConfigResourceTestBase;
|
||||
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class FieldStorageConfigHalJsonBasicAuthTest extends FieldStorageConfigResourceTestBase {
|
||||
|
||||
use BasicAuthResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['hal', 'basic_auth'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'hal_json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'basic_auth';
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\field\Functional\Hal;
|
||||
|
||||
use Drupal\Tests\field\Functional\Rest\FieldStorageConfigResourceTestBase;
|
||||
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class FieldStorageConfigHalJsonCookieTest extends FieldStorageConfigResourceTestBase {
|
||||
|
||||
use CookieResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['hal'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'hal_json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'cookie';
|
||||
|
||||
}
|
||||
+11
-9
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\field\Tests;
|
||||
namespace Drupal\Tests\field\Functional;
|
||||
|
||||
use Drupal\Core\Field\FieldStorageDefinitionInterface;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
@@ -139,12 +139,10 @@ class NestedFormTest extends FieldTestBase {
|
||||
$this->assertFieldValues($entity_1, 'field_unlimited', [3, 2]);
|
||||
$this->assertFieldValues($entity_2, 'field_unlimited', [13, 12]);
|
||||
|
||||
// Test the 'add more' buttons. Only Ajax submission is tested, because
|
||||
// the two 'add more' buttons present in the form have the same #value,
|
||||
// which confuses drupalPostForm().
|
||||
// Test the 'add more' buttons.
|
||||
// 'Add more' button in the first entity:
|
||||
$this->drupalGet('test-entity/nested/1/2');
|
||||
$this->drupalPostAjaxForm(NULL, [], 'field_unlimited_add_more');
|
||||
$this->drupalPostForm(NULL, [], 'field_unlimited_add_more');
|
||||
$this->assertFieldByName('field_unlimited[0][value]', 3, 'Entity 1: field_unlimited value 0 appears correctly is the form.');
|
||||
$this->assertFieldByName('field_unlimited[1][value]', 2, 'Entity 1: field_unlimited value 1 appears correctly is the form.');
|
||||
$this->assertFieldByName('field_unlimited[2][value]', '', 'Entity 1: field_unlimited value 2 appears correctly is the form.');
|
||||
@@ -155,7 +153,7 @@ class NestedFormTest extends FieldTestBase {
|
||||
'entity_2[field_unlimited][1][value]' => 14,
|
||||
'entity_2[field_unlimited][2][value]' => 15,
|
||||
];
|
||||
$this->drupalPostAjaxForm(NULL, $edit, 'entity_2_field_unlimited_add_more');
|
||||
$this->drupalPostForm(NULL, $edit, 'entity_2_field_unlimited_add_more');
|
||||
$this->assertFieldByName('entity_2[field_unlimited][0][value]', 13, 'Entity 2: field_unlimited value 0 appears correctly is the form.');
|
||||
$this->assertFieldByName('entity_2[field_unlimited][1][value]', 14, 'Entity 2: field_unlimited value 1 appears correctly is the form.');
|
||||
$this->assertFieldByName('entity_2[field_unlimited][2][value]', 15, 'Entity 2: field_unlimited value 2 appears correctly is the form.');
|
||||
@@ -180,13 +178,17 @@ class NestedFormTest extends FieldTestBase {
|
||||
$entity_2 = $storage->create();
|
||||
$entity_2->save();
|
||||
|
||||
$page = $this->getSession()->getPage();
|
||||
$assert_session = $this->assertSession();
|
||||
|
||||
// Display the 'combined form'.
|
||||
$this->drupalGet("test-entity-constraints/nested/{$entity_1->id()}/{$entity_2->id()}");
|
||||
$this->assertFieldByName('entity_2[changed]', 0, 'Entity 2: changed value appears correctly in the form.');
|
||||
$assert_session->hiddenFieldValueEquals('entity_2[changed]', REQUEST_TIME);
|
||||
|
||||
// Submit the form and check that the entities are updated accordingly.
|
||||
$edit = ['entity_2[changed]' => REQUEST_TIME - 86400];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
$assert_session->hiddenFieldExists('entity_2[changed]')
|
||||
->setValue(REQUEST_TIME - 86400);
|
||||
$page->pressButton(t('Save'));
|
||||
|
||||
$elements = $this->cssSelect('.entity-2.error');
|
||||
$this->assertEqual(1, count($elements), 'The whole nested entity form has been correctly flagged with an error class.');
|
||||
+18
-151
@@ -1,19 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\field\Tests\Number;
|
||||
namespace Drupal\Tests\field\Functional\Number;
|
||||
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\node\Entity\Node;
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Tests the creation of numeric fields.
|
||||
*
|
||||
* @group field
|
||||
*/
|
||||
class NumberFieldTest extends WebTestBase {
|
||||
class NumberFieldTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
@@ -40,7 +38,7 @@ class NumberFieldTest extends WebTestBase {
|
||||
*/
|
||||
public function testNumberDecimalField() {
|
||||
// Create a field with settings to validate.
|
||||
$field_name = Unicode::strtolower($this->randomMachineName());
|
||||
$field_name = mb_strtolower($this->randomMachineName());
|
||||
FieldStorageConfig::create([
|
||||
'field_name' => $field_name,
|
||||
'entity_type' => 'entity_test',
|
||||
@@ -57,7 +55,7 @@ class NumberFieldTest extends WebTestBase {
|
||||
->setComponent($field_name, [
|
||||
'type' => 'number',
|
||||
'settings' => [
|
||||
'placeholder' => '0.00'
|
||||
'placeholder' => '0.00',
|
||||
],
|
||||
])
|
||||
->save();
|
||||
@@ -78,7 +76,7 @@ class NumberFieldTest extends WebTestBase {
|
||||
"{$field_name}[0][value]" => $value,
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
preg_match('|entity_test/manage/(\d+)|', $this->url, $match);
|
||||
preg_match('|entity_test/manage/(\d+)|', $this->getUrl(), $match);
|
||||
$id = $match[1];
|
||||
$this->assertText(t('entity_test @id has been created.', ['@id' => $id]), 'Entity was created');
|
||||
$this->assertRaw($value, 'Value is displayed.');
|
||||
@@ -128,7 +126,7 @@ class NumberFieldTest extends WebTestBase {
|
||||
$maximum = rand(2000, 4000);
|
||||
|
||||
// Create a field with settings to validate.
|
||||
$field_name = Unicode::strtolower($this->randomMachineName());
|
||||
$field_name = mb_strtolower($this->randomMachineName());
|
||||
$storage = FieldStorageConfig::create([
|
||||
'field_name' => $field_name,
|
||||
'entity_type' => 'entity_test',
|
||||
@@ -151,7 +149,7 @@ class NumberFieldTest extends WebTestBase {
|
||||
->setComponent($field_name, [
|
||||
'type' => 'number',
|
||||
'settings' => [
|
||||
'placeholder' => '4'
|
||||
'placeholder' => '4',
|
||||
],
|
||||
])
|
||||
->save();
|
||||
@@ -170,12 +168,12 @@ class NumberFieldTest extends WebTestBase {
|
||||
'value' => [
|
||||
'type' => 'int',
|
||||
'unsigned' => '',
|
||||
'size' => 'normal'
|
||||
'size' => 'normal',
|
||||
],
|
||||
],
|
||||
'unique keys' => [],
|
||||
'indexes' => [],
|
||||
'foreign keys' => []
|
||||
'foreign keys' => [],
|
||||
];
|
||||
$this->assertEqual($storage->getSchema(), $expected);
|
||||
|
||||
@@ -190,7 +188,7 @@ class NumberFieldTest extends WebTestBase {
|
||||
"{$field_name}[0][value]" => $value,
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
preg_match('|entity_test/manage/(\d+)|', $this->url, $match);
|
||||
preg_match('|entity_test/manage/(\d+)|', $this->getUrl(), $match);
|
||||
$id = $match[1];
|
||||
$this->assertText(t('entity_test @id has been created.', ['@id' => $id]), 'Entity was created');
|
||||
|
||||
@@ -239,7 +237,7 @@ class NumberFieldTest extends WebTestBase {
|
||||
"{$field_name}[0][value]" => $valid_entry,
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
preg_match('|entity_test/manage/(\d+)|', $this->url, $match);
|
||||
preg_match('|entity_test/manage/(\d+)|', $this->getUrl(), $match);
|
||||
$id = $match[1];
|
||||
$this->assertText(t('entity_test @id has been created.', ['@id' => $id]), 'Entity was created');
|
||||
$this->assertRaw($valid_entry, 'Value is displayed.');
|
||||
@@ -261,7 +259,7 @@ class NumberFieldTest extends WebTestBase {
|
||||
"{$field_name}[0][value]" => $integer_value,
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
preg_match('|entity_test/manage/(\d+)|', $this->url, $match);
|
||||
preg_match('|entity_test/manage/(\d+)|', $this->getUrl(), $match);
|
||||
$id = $match[1];
|
||||
$this->assertText(t('entity_test @id has been created.', ['@id' => $id]), 'Entity was created');
|
||||
$this->drupalGet('entity_test/' . $id);
|
||||
@@ -273,7 +271,7 @@ class NumberFieldTest extends WebTestBase {
|
||||
*/
|
||||
public function testNumberFloatField() {
|
||||
// Create a field with settings to validate.
|
||||
$field_name = Unicode::strtolower($this->randomMachineName());
|
||||
$field_name = mb_strtolower($this->randomMachineName());
|
||||
FieldStorageConfig::create([
|
||||
'field_name' => $field_name,
|
||||
'entity_type' => 'entity_test',
|
||||
@@ -290,7 +288,7 @@ class NumberFieldTest extends WebTestBase {
|
||||
->setComponent($field_name, [
|
||||
'type' => 'number',
|
||||
'settings' => [
|
||||
'placeholder' => '0.00'
|
||||
'placeholder' => '0.00',
|
||||
],
|
||||
])
|
||||
->save();
|
||||
@@ -312,7 +310,7 @@ class NumberFieldTest extends WebTestBase {
|
||||
"{$field_name}[0][value]" => $value,
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
preg_match('|entity_test/manage/(\d+)|', $this->url, $match);
|
||||
preg_match('|entity_test/manage/(\d+)|', $this->getUrl(), $match);
|
||||
$id = $match[1];
|
||||
$this->assertText(t('entity_test @id has been created.', ['@id' => $id]), 'Entity was created');
|
||||
|
||||
@@ -358,143 +356,12 @@ class NumberFieldTest extends WebTestBase {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test default formatter behavior
|
||||
*/
|
||||
public function testNumberFormatter() {
|
||||
$type = Unicode::strtolower($this->randomMachineName());
|
||||
$float_field = Unicode::strtolower($this->randomMachineName());
|
||||
$integer_field = Unicode::strtolower($this->randomMachineName());
|
||||
$thousand_separators = ['', '.', ',', ' ', chr(8201), "'"];
|
||||
$decimal_separators = ['.', ','];
|
||||
$prefix = $this->randomMachineName();
|
||||
$suffix = $this->randomMachineName();
|
||||
$random_float = rand(0, pow(10, 6));
|
||||
$random_integer = rand(0, pow(10, 6));
|
||||
|
||||
// Create a content type containing float and integer fields.
|
||||
$this->drupalCreateContentType(['type' => $type]);
|
||||
|
||||
FieldStorageConfig::create([
|
||||
'field_name' => $float_field,
|
||||
'entity_type' => 'node',
|
||||
'type' => 'float',
|
||||
])->save();
|
||||
|
||||
FieldStorageConfig::create([
|
||||
'field_name' => $integer_field,
|
||||
'entity_type' => 'node',
|
||||
'type' => 'integer',
|
||||
])->save();
|
||||
|
||||
FieldConfig::create([
|
||||
'field_name' => $float_field,
|
||||
'entity_type' => 'node',
|
||||
'bundle' => $type,
|
||||
'settings' => [
|
||||
'prefix' => $prefix,
|
||||
'suffix' => $suffix
|
||||
],
|
||||
])->save();
|
||||
|
||||
FieldConfig::create([
|
||||
'field_name' => $integer_field,
|
||||
'entity_type' => 'node',
|
||||
'bundle' => $type,
|
||||
'settings' => [
|
||||
'prefix' => $prefix,
|
||||
'suffix' => $suffix
|
||||
],
|
||||
])->save();
|
||||
|
||||
entity_get_form_display('node', $type, 'default')
|
||||
->setComponent($float_field, [
|
||||
'type' => 'number',
|
||||
'settings' => [
|
||||
'placeholder' => '0.00'
|
||||
],
|
||||
])
|
||||
->setComponent($integer_field, [
|
||||
'type' => 'number',
|
||||
'settings' => [
|
||||
'placeholder' => '0.00'
|
||||
],
|
||||
])
|
||||
->save();
|
||||
|
||||
entity_get_display('node', $type, 'default')
|
||||
->setComponent($float_field, [
|
||||
'type' => 'number_decimal',
|
||||
])
|
||||
->setComponent($integer_field, [
|
||||
'type' => 'number_unformatted',
|
||||
])
|
||||
->save();
|
||||
|
||||
// Create a node to test formatters.
|
||||
$node = Node::create([
|
||||
'type' => $type,
|
||||
'title' => $this->randomMachineName(),
|
||||
$float_field => ['value' => $random_float],
|
||||
$integer_field => ['value' => $random_integer],
|
||||
]);
|
||||
$node->save();
|
||||
|
||||
// Go to manage display page.
|
||||
$this->drupalGet("admin/structure/types/manage/$type/display");
|
||||
|
||||
// Configure number_decimal formatter for the 'float' field type.
|
||||
$thousand_separator = $thousand_separators[array_rand($thousand_separators)];
|
||||
$decimal_separator = $decimal_separators[array_rand($decimal_separators)];
|
||||
$scale = rand(0, 10);
|
||||
|
||||
$this->drupalPostAjaxForm(NULL, [], "${float_field}_settings_edit");
|
||||
$edit = [
|
||||
"fields[${float_field}][settings_edit_form][settings][prefix_suffix]" => TRUE,
|
||||
"fields[${float_field}][settings_edit_form][settings][scale]" => $scale,
|
||||
"fields[${float_field}][settings_edit_form][settings][decimal_separator]" => $decimal_separator,
|
||||
"fields[${float_field}][settings_edit_form][settings][thousand_separator]" => $thousand_separator,
|
||||
];
|
||||
$this->drupalPostAjaxForm(NULL, $edit, "${float_field}_plugin_settings_update");
|
||||
$this->drupalPostForm(NULL, [], t('Save'));
|
||||
|
||||
// Check number_decimal and number_unformatted formatters behavior.
|
||||
$this->drupalGet('node/' . $node->id());
|
||||
$float_formatted = number_format($random_float, $scale, $decimal_separator, $thousand_separator);
|
||||
$this->assertRaw("$prefix$float_formatted$suffix", 'Prefix and suffix added');
|
||||
$this->assertRaw((string) $random_integer);
|
||||
|
||||
// Configure the number_decimal formatter.
|
||||
entity_get_display('node', $type, 'default')
|
||||
->setComponent($integer_field, [
|
||||
'type' => 'number_integer',
|
||||
])
|
||||
->save();
|
||||
$this->drupalGet("admin/structure/types/manage/$type/display");
|
||||
|
||||
$thousand_separator = $thousand_separators[array_rand($thousand_separators)];
|
||||
|
||||
$this->drupalPostAjaxForm(NULL, [], "${integer_field}_settings_edit");
|
||||
$edit = [
|
||||
"fields[${integer_field}][settings_edit_form][settings][prefix_suffix]" => FALSE,
|
||||
"fields[${integer_field}][settings_edit_form][settings][thousand_separator]" => $thousand_separator,
|
||||
];
|
||||
$this->drupalPostAjaxForm(NULL, $edit, "${integer_field}_plugin_settings_update");
|
||||
$this->drupalPostForm(NULL, [], t('Save'));
|
||||
|
||||
// Check number_integer formatter behavior.
|
||||
$this->drupalGet('node/' . $node->id());
|
||||
|
||||
$integer_formatted = number_format($random_integer, 0, '', $thousand_separator);
|
||||
$this->assertRaw($integer_formatted, 'Random integer formatted');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests setting the minimum value of a float field through the interface.
|
||||
*/
|
||||
public function testCreateNumberFloatField() {
|
||||
// Create a float field.
|
||||
$field_name = Unicode::strtolower($this->randomMachineName());
|
||||
$field_name = mb_strtolower($this->randomMachineName());
|
||||
FieldStorageConfig::create([
|
||||
'field_name' => $field_name,
|
||||
'entity_type' => 'entity_test',
|
||||
@@ -519,7 +386,7 @@ class NumberFieldTest extends WebTestBase {
|
||||
*/
|
||||
public function testCreateNumberDecimalField() {
|
||||
// Create a decimal field.
|
||||
$field_name = Unicode::strtolower($this->randomMachineName());
|
||||
$field_name = mb_strtolower($this->randomMachineName());
|
||||
FieldStorageConfig::create([
|
||||
'field_name' => $field_name,
|
||||
'entity_type' => 'entity_test',
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\field\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class FieldConfigJsonAnonTest extends FieldConfigResourceTestBase {
|
||||
|
||||
use AnonResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/json';
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\field\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class FieldConfigJsonBasicAuthTest extends FieldConfigResourceTestBase {
|
||||
|
||||
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\field\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class FieldConfigJsonCookieTest extends FieldConfigResourceTestBase {
|
||||
|
||||
use CookieResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'cookie';
|
||||
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\field\Functional\Rest;
|
||||
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\node\Entity\NodeType;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase;
|
||||
|
||||
abstract class FieldConfigResourceTestBase extends EntityResourceTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['field', 'node'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $entityTypeId = 'field_config';
|
||||
|
||||
/**
|
||||
* @var \Drupal\field\FieldConfigInterface
|
||||
*/
|
||||
protected $entity;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUpAuthorization($method) {
|
||||
$this->grantPermissionsToTestedRole(['administer node fields']);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function createEntity() {
|
||||
$camelids = NodeType::create([
|
||||
'name' => 'Camelids',
|
||||
'type' => 'camelids',
|
||||
]);
|
||||
$camelids->save();
|
||||
|
||||
$field_storage = FieldStorageConfig::create([
|
||||
'field_name' => 'field_llama',
|
||||
'entity_type' => 'node',
|
||||
'type' => 'text',
|
||||
]);
|
||||
$field_storage->save();
|
||||
|
||||
$entity = FieldConfig::create([
|
||||
'field_storage' => $field_storage,
|
||||
'bundle' => 'camelids',
|
||||
]);
|
||||
$entity->save();
|
||||
|
||||
return $entity;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getExpectedNormalizedEntity() {
|
||||
return [
|
||||
'bundle' => 'camelids',
|
||||
'default_value' => [],
|
||||
'default_value_callback' => '',
|
||||
'dependencies' => [
|
||||
'config' => [
|
||||
'field.storage.node.field_llama',
|
||||
'node.type.camelids',
|
||||
],
|
||||
'module' => [
|
||||
'text',
|
||||
],
|
||||
],
|
||||
'description' => '',
|
||||
'entity_type' => 'node',
|
||||
'field_name' => 'field_llama',
|
||||
'field_type' => 'text',
|
||||
'id' => 'node.camelids.field_llama',
|
||||
'label' => 'field_llama',
|
||||
'langcode' => 'en',
|
||||
'required' => FALSE,
|
||||
'settings' => [],
|
||||
'status' => TRUE,
|
||||
'translatable' => TRUE,
|
||||
'uuid' => $this->entity->uuid(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getNormalizedPostEntity() {
|
||||
// @todo Update in https://www.drupal.org/node/2300677.
|
||||
}
|
||||
|
||||
/**
|
||||
* {@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);
|
||||
}
|
||||
|
||||
return "The 'administer node fields' permission is required.";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\field\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class FieldConfigXmlAnonTest extends FieldConfigResourceTestBase {
|
||||
|
||||
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\field\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class FieldConfigXmlBasicAuthTest extends FieldConfigResourceTestBase {
|
||||
|
||||
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\field\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class FieldConfigXmlCookieTest extends FieldConfigResourceTestBase {
|
||||
|
||||
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\field\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class FieldStorageConfigJsonAnonTest extends FieldStorageConfigResourceTestBase {
|
||||
|
||||
use AnonResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/json';
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\field\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class FieldStorageConfigJsonBasicAuthTest extends FieldStorageConfigResourceTestBase {
|
||||
|
||||
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\field\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class FieldStorageConfigJsonCookieTest extends FieldStorageConfigResourceTestBase {
|
||||
|
||||
use CookieResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'cookie';
|
||||
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\field\Functional\Rest;
|
||||
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase;
|
||||
|
||||
abstract class FieldStorageConfigResourceTestBase extends EntityResourceTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['node'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $entityTypeId = 'field_storage_config';
|
||||
|
||||
/**
|
||||
* @var \Drupal\field\FieldConfigStorage
|
||||
*/
|
||||
protected $entity;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUpAuthorization($method) {
|
||||
$this->grantPermissionsToTestedRole(['administer node fields']);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function createEntity() {
|
||||
$field_storage = FieldStorageConfig::create([
|
||||
'field_name' => 'true_llama',
|
||||
'entity_type' => 'node',
|
||||
'type' => 'boolean',
|
||||
]);
|
||||
$field_storage->save();
|
||||
return $field_storage;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getExpectedNormalizedEntity() {
|
||||
return [
|
||||
'cardinality' => 1,
|
||||
'custom_storage' => FALSE,
|
||||
'dependencies' => [
|
||||
'module' => ['node'],
|
||||
],
|
||||
'entity_type' => 'node',
|
||||
'field_name' => 'true_llama',
|
||||
'id' => 'node.true_llama',
|
||||
'indexes' => [],
|
||||
'langcode' => 'en',
|
||||
'locked' => FALSE,
|
||||
'module' => 'core',
|
||||
'persist_with_no_fields' => FALSE,
|
||||
'settings' => [],
|
||||
'status' => TRUE,
|
||||
'translatable' => TRUE,
|
||||
'type' => 'boolean',
|
||||
'uuid' => $this->entity->uuid(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getNormalizedPostEntity() {
|
||||
// @todo Update in https://www.drupal.org/node/2300677.
|
||||
}
|
||||
|
||||
/**
|
||||
* {@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 'administer node fields' permission is required.";
|
||||
|
||||
default:
|
||||
return parent::getExpectedUnauthorizedAccessMessage($method);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getExpectedCacheContexts() {
|
||||
return [
|
||||
'user.permissions',
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\field\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class FieldStorageConfigXmlAnonTest extends FieldStorageConfigResourceTestBase {
|
||||
|
||||
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\field\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class FieldStorageConfigXmlBasicAuthTest extends FieldStorageConfigResourceTestBase {
|
||||
|
||||
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\field\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class FieldStorageConfigXmlCookieTest extends FieldStorageConfigResourceTestBase {
|
||||
|
||||
use CookieResourceTestTrait;
|
||||
use XmlEntityNormalizationQuirksTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'xml';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'text/xml; charset=UTF-8';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'cookie';
|
||||
|
||||
}
|
||||
+8
-9
@@ -1,19 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\field\Tests\String;
|
||||
namespace Drupal\Tests\field\Functional\String;
|
||||
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\entity_test\Entity\EntityTest;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Tests the creation of string fields.
|
||||
*
|
||||
* @group text
|
||||
*/
|
||||
class StringFieldTest extends WebTestBase {
|
||||
class StringFieldTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
@@ -51,11 +50,11 @@ class StringFieldTest extends WebTestBase {
|
||||
*/
|
||||
public function _testTextfieldWidgets($field_type, $widget_type) {
|
||||
// Create a field.
|
||||
$field_name = Unicode::strtolower($this->randomMachineName());
|
||||
$field_name = mb_strtolower($this->randomMachineName());
|
||||
$field_storage = FieldStorageConfig::create([
|
||||
'field_name' => $field_name,
|
||||
'entity_type' => 'entity_test',
|
||||
'type' => $field_type
|
||||
'type' => $field_type,
|
||||
]);
|
||||
$field_storage->save();
|
||||
FieldConfig::create([
|
||||
@@ -87,7 +86,7 @@ class StringFieldTest extends WebTestBase {
|
||||
"{$field_name}[0][value]" => $value,
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
preg_match('|entity_test/manage/(\d+)|', $this->url, $match);
|
||||
preg_match('|entity_test/manage/(\d+)|', $this->getUrl(), $match);
|
||||
$id = $match[1];
|
||||
$this->assertText(t('entity_test @id has been created.', ['@id' => $id]), 'Entity was created');
|
||||
|
||||
@@ -95,8 +94,8 @@ class StringFieldTest extends WebTestBase {
|
||||
$entity = EntityTest::load($id);
|
||||
$display = entity_get_display($entity->getEntityTypeId(), $entity->bundle(), 'full');
|
||||
$content = $display->build($entity);
|
||||
$this->setRawContent(\Drupal::service('renderer')->renderRoot($content));
|
||||
$this->assertText($value, 'Filtered tags are not displayed');
|
||||
$rendered_entity = \Drupal::service('renderer')->renderRoot($content);
|
||||
$this->assertContains($value, (string) $rendered_entity);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace Drupal\Tests\field\Functional;
|
||||
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
@@ -52,7 +51,7 @@ class TranslationWebTest extends FieldTestBase {
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->fieldName = Unicode::strtolower($this->randomMachineName() . '_field_name');
|
||||
$this->fieldName = mb_strtolower($this->randomMachineName() . '_field_name');
|
||||
|
||||
$field_storage = [
|
||||
'field_name' => $this->fieldName,
|
||||
|
||||
@@ -8,6 +8,7 @@ use Drupal\FunctionalTests\Update\UpdatePathTestBase;
|
||||
* Tests the update for the 'size' setting of the 'email_default' field widget.
|
||||
*
|
||||
* @group field
|
||||
* @group legacy
|
||||
*/
|
||||
class EmailWidgetSizeSettingUpdateTest extends UpdatePathTestBase {
|
||||
|
||||
|
||||
+1
@@ -8,6 +8,7 @@ use Drupal\FunctionalTests\Update\UpdatePathTestBase;
|
||||
* Tests the update for the entity reference 'handler' setting.
|
||||
*
|
||||
* @group field
|
||||
* @group legacy
|
||||
*/
|
||||
class EntityReferenceHandlerSettingUpdateTest extends UpdatePathTestBase {
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ use Drupal\Tests\Traits\Core\CronRunTrait;
|
||||
* Tests that field settings are properly updated during database updates.
|
||||
*
|
||||
* @group field
|
||||
* @group legacy
|
||||
*/
|
||||
class FieldUpdateTest extends UpdatePathTestBase {
|
||||
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\field\Functional\Views;
|
||||
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\node\Entity\NodeType;
|
||||
use Drupal\Tests\views\Functional\ViewTestBase;
|
||||
use Drupal\views\Tests\ViewTestData;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
|
||||
/**
|
||||
* Provides some helper methods for testing fieldapi integration into views.
|
||||
*
|
||||
* @todo Test on a generic entity not on a node. What has to be tested:
|
||||
* - Make sure that every wanted field is added to the according entity type.
|
||||
* - Make sure the joins are done correctly.
|
||||
* - Use basic fields and make sure that the full wanted object is built.
|
||||
* - Use relationships between different entity types, for example node and
|
||||
* the node author(user).
|
||||
*/
|
||||
abstract class FieldTestBase extends ViewTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['node', 'field_test_views'];
|
||||
|
||||
/**
|
||||
* Stores the field definitions used by the test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $fieldStorages;
|
||||
|
||||
/**
|
||||
* Stores the fields of the field storage. They have the same keys as the
|
||||
* field storages.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $fields;
|
||||
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp($import_test_views);
|
||||
|
||||
// Ensure the page node type exists.
|
||||
NodeType::create([
|
||||
'type' => 'page',
|
||||
'name' => 'page',
|
||||
])->save();
|
||||
|
||||
ViewTestData::createTestViews(get_class($this), ['field_test_views']);
|
||||
}
|
||||
|
||||
public function setUpFieldStorages($amount = 3, $type = 'string') {
|
||||
// Create three fields.
|
||||
$field_names = [];
|
||||
for ($i = 0; $i < $amount; $i++) {
|
||||
$field_names[$i] = 'field_name_' . $i;
|
||||
$this->fieldStorages[$i] = FieldStorageConfig::create([
|
||||
'field_name' => $field_names[$i],
|
||||
'entity_type' => 'node',
|
||||
'type' => $type,
|
||||
]);
|
||||
$this->fieldStorages[$i]->save();
|
||||
}
|
||||
return $field_names;
|
||||
}
|
||||
|
||||
public function setUpFields($bundle = 'page') {
|
||||
foreach ($this->fieldStorages as $key => $field_storage) {
|
||||
$this->fields[$key] = FieldConfig::create([
|
||||
'field_storage' => $field_storage,
|
||||
'bundle' => $bundle,
|
||||
]);
|
||||
$this->fields[$key]->save();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+6
-6
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\field\Tests\Views;
|
||||
namespace Drupal\Tests\field\Functional\Views;
|
||||
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
@@ -58,7 +58,7 @@ class FieldUITest extends FieldTestBase {
|
||||
// Tests the available formatter options.
|
||||
$result = $this->xpath('//select[@id=:id]/option', [':id' => 'edit-options-type']);
|
||||
$options = array_map(function ($item) {
|
||||
return (string) $item->attributes()->value[0];
|
||||
return $item->getAttribute('value');
|
||||
}, $result);
|
||||
// @todo Replace this sort by assertArray once it's in.
|
||||
sort($options, SORT_STRING);
|
||||
@@ -112,7 +112,7 @@ class FieldUITest extends FieldTestBase {
|
||||
// Tests the available formatter options.
|
||||
$result = $this->xpath('//select[@id=:id]/option', [':id' => 'edit-options-click-sort-column']);
|
||||
$options = array_map(function ($item) {
|
||||
return (string) $item->attributes()->value[0];
|
||||
return (string) $item->getAttribute('value');
|
||||
}, $result);
|
||||
sort($options, SORT_STRING);
|
||||
|
||||
@@ -143,15 +143,15 @@ class FieldUITest extends FieldTestBase {
|
||||
// Verify that using a boolean field as a filter also results in using the
|
||||
// boolean plugin.
|
||||
$option = $this->xpath('//label[@for="edit-options-value-1"]');
|
||||
$this->assertEqual(t('True'), (string) $option[0]);
|
||||
$this->assertEqual(t('True'), $option[0]->getText());
|
||||
$option = $this->xpath('//label[@for="edit-options-value-0"]');
|
||||
$this->assertEqual(t('False'), (string) $option[0]);
|
||||
$this->assertEqual(t('False'), $option[0]->getText());
|
||||
|
||||
// Expose the filter and see if the 'Any' option is added and if we can save
|
||||
// it.
|
||||
$this->drupalPostForm(NULL, [], 'Expose filter');
|
||||
$option = $this->xpath('//label[@for="edit-options-value-all"]');
|
||||
$this->assertEqual(t('- Any -'), (string) $option[0]);
|
||||
$this->assertEqual(t('- Any -'), $option[0]->getText());
|
||||
$this->drupalPostForm(NULL, ['options[value]' => 'All', 'options[expose][required]' => FALSE], 'Apply');
|
||||
$this->drupalPostForm(NULL, [], 'Save');
|
||||
$this->drupalGet('/admin/structure/views/nojs/handler/test_view_fieldapi/default/filter/field_boolean_value');
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\field\Tests\Views;
|
||||
namespace Drupal\Tests\field\Functional\Views;
|
||||
|
||||
use Drupal\Core\Field\FieldStorageDefinitionInterface;
|
||||
use Drupal\views\ViewExecutable;
|
||||
+7
-4
@@ -1,17 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\field\Tests;
|
||||
namespace Drupal\Tests\field\Functional;
|
||||
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
use Drupal\Tests\Traits\Core\CronRunTrait;
|
||||
|
||||
/**
|
||||
* Tests the behavior of a field module after being disabled and re-enabled.
|
||||
*
|
||||
* @group field
|
||||
*/
|
||||
class reEnableModuleFieldTest extends WebTestBase {
|
||||
class reEnableModuleFieldTest extends BrowserTestBase {
|
||||
|
||||
use CronRunTrait;
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
@@ -23,7 +26,7 @@ class reEnableModuleFieldTest extends WebTestBase {
|
||||
'node',
|
||||
// We use telephone module instead of test_field because test_field is
|
||||
// hidden and does not display on the admin/modules page.
|
||||
'telephone'
|
||||
'telephone',
|
||||
];
|
||||
|
||||
protected function setUp() {
|
||||
+128
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\field\FunctionalJavascript\Boolean;
|
||||
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
|
||||
|
||||
/**
|
||||
* Tests the Boolean field formatter settings.
|
||||
*
|
||||
* @group field
|
||||
*/
|
||||
class BooleanFormatterSettingsTest extends WebDriverTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['field', 'field_ui', 'text', 'node', 'user'];
|
||||
|
||||
/**
|
||||
* The name of the entity bundle that is created in the test.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $bundle;
|
||||
|
||||
/**
|
||||
* The name of the Boolean field to use for testing.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $fieldName;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Create a content type. Use Node because it has Field UI pages that work.
|
||||
$type_name = mb_strtolower($this->randomMachineName(8)) . '_test';
|
||||
$type = $this->drupalCreateContentType(['name' => $type_name, 'type' => $type_name]);
|
||||
$this->bundle = $type->id();
|
||||
|
||||
$admin_user = $this->drupalCreateUser([
|
||||
'access content',
|
||||
'administer content types',
|
||||
'administer node fields',
|
||||
'administer node display',
|
||||
'bypass node access',
|
||||
'administer nodes',
|
||||
]);
|
||||
$this->drupalLogin($admin_user);
|
||||
|
||||
$this->fieldName = mb_strtolower($this->randomMachineName(8));
|
||||
|
||||
$field_storage = FieldStorageConfig::create([
|
||||
'field_name' => $this->fieldName,
|
||||
'entity_type' => 'node',
|
||||
'type' => 'boolean',
|
||||
]);
|
||||
$field_storage->save();
|
||||
|
||||
$instance = FieldConfig::create([
|
||||
'field_storage' => $field_storage,
|
||||
'bundle' => $this->bundle,
|
||||
'label' => $this->randomMachineName(),
|
||||
]);
|
||||
$instance->save();
|
||||
|
||||
$display = entity_get_display('node', $this->bundle, 'default')
|
||||
->setComponent($this->fieldName, [
|
||||
'type' => 'boolean',
|
||||
'settings' => [],
|
||||
]);
|
||||
$display->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the formatter settings page for the Boolean formatter.
|
||||
*/
|
||||
public function testBooleanFormatterSettings() {
|
||||
// List the options we expect to see on the settings form. Omit the one
|
||||
// with the Unicode check/x characters, which does not appear to work
|
||||
// well in WebTestBase.
|
||||
$options = [
|
||||
'Yes / No',
|
||||
'True / False',
|
||||
'On / Off',
|
||||
'Enabled / Disabled',
|
||||
'1 / 0',
|
||||
'Custom',
|
||||
];
|
||||
|
||||
// For several different values of the field settings, test that the
|
||||
// options, including default, are shown correctly.
|
||||
$settings = [
|
||||
['Yes', 'No'],
|
||||
['On', 'Off'],
|
||||
['TRUE', 'FALSE'],
|
||||
];
|
||||
|
||||
$assert_session = $this->assertSession();
|
||||
foreach ($settings as $values) {
|
||||
// Set up the field settings.
|
||||
$this->drupalGet('admin/structure/types/manage/' . $this->bundle . '/fields/node.' . $this->bundle . '.' . $this->fieldName);
|
||||
$this->drupalPostForm(NULL, [
|
||||
'settings[on_label]' => $values[0],
|
||||
'settings[off_label]' => $values[1],
|
||||
], t('Save settings'));
|
||||
|
||||
// Open the Manage Display page and trigger the field settings form.
|
||||
$this->drupalGet('admin/structure/types/manage/' . $this->bundle . '/display');
|
||||
$this->getSession()->getPage()->pressButton($this->fieldName . '_settings_edit');
|
||||
$assert_session->waitForElement('css', '.ajax-new-content');
|
||||
|
||||
// Test that the settings options are present in the correct format.
|
||||
foreach ($options as $string) {
|
||||
$assert_session->pageTextContains($string);
|
||||
}
|
||||
$assert_session->pageTextContains(t('Field settings (@on_label / @off_label)', ['@on_label' => $values[0], '@off_label' => $values[1]]));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,14 +6,14 @@ use Drupal\Core\Entity\Entity\EntityFormDisplay;
|
||||
use Drupal\Core\Field\FieldStorageDefinitionInterface;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
|
||||
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
|
||||
|
||||
/**
|
||||
* Tests add more behavior for a multiple value field.
|
||||
*
|
||||
* @group field
|
||||
*/
|
||||
class FormJSAddMoreTest extends JavascriptTestBase {
|
||||
class FormJSAddMoreTest extends WebDriverTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
||||
@@ -0,0 +1,183 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\field\FunctionalJavascript\Number;
|
||||
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
|
||||
use Drupal\node\Entity\Node;
|
||||
|
||||
/**
|
||||
* Tests the numeric field widget.
|
||||
*
|
||||
* @group field
|
||||
*/
|
||||
class NumberFieldTest extends WebDriverTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $modules = ['node', 'entity_test', 'field_ui'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->drupalLogin($this->drupalCreateUser([
|
||||
'view test entity',
|
||||
'administer entity_test content',
|
||||
'administer content types',
|
||||
'administer node fields',
|
||||
'administer node display',
|
||||
'bypass node access',
|
||||
'administer entity_test fields',
|
||||
]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test default formatter behavior.
|
||||
*/
|
||||
public function testNumberFormatter() {
|
||||
$type = mb_strtolower($this->randomMachineName());
|
||||
$float_field = mb_strtolower($this->randomMachineName());
|
||||
$integer_field = mb_strtolower($this->randomMachineName());
|
||||
$thousand_separators = ['', '.', ',', ' ', chr(8201), "'"];
|
||||
$decimal_separators = ['.', ','];
|
||||
$prefix = $this->randomMachineName();
|
||||
$suffix = $this->randomMachineName();
|
||||
$random_float = rand(0, pow(10, 6));
|
||||
$random_integer = rand(0, pow(10, 6));
|
||||
$assert_session = $this->assertSession();
|
||||
|
||||
// Create a content type containing float and integer fields.
|
||||
$this->drupalCreateContentType(['type' => $type]);
|
||||
|
||||
FieldStorageConfig::create([
|
||||
'field_name' => $float_field,
|
||||
'entity_type' => 'node',
|
||||
'type' => 'float',
|
||||
])->save();
|
||||
|
||||
FieldStorageConfig::create([
|
||||
'field_name' => $integer_field,
|
||||
'entity_type' => 'node',
|
||||
'type' => 'integer',
|
||||
])->save();
|
||||
|
||||
FieldConfig::create([
|
||||
'field_name' => $float_field,
|
||||
'entity_type' => 'node',
|
||||
'bundle' => $type,
|
||||
'settings' => [
|
||||
'prefix' => $prefix,
|
||||
'suffix' => $suffix,
|
||||
],
|
||||
])->save();
|
||||
|
||||
FieldConfig::create([
|
||||
'field_name' => $integer_field,
|
||||
'entity_type' => 'node',
|
||||
'bundle' => $type,
|
||||
'settings' => [
|
||||
'prefix' => $prefix,
|
||||
'suffix' => $suffix,
|
||||
],
|
||||
])->save();
|
||||
|
||||
entity_get_form_display('node', $type, 'default')
|
||||
->setComponent($float_field, [
|
||||
'type' => 'number',
|
||||
'settings' => [
|
||||
'placeholder' => '0.00',
|
||||
],
|
||||
])
|
||||
->setComponent($integer_field, [
|
||||
'type' => 'number',
|
||||
'settings' => [
|
||||
'placeholder' => '0.00',
|
||||
],
|
||||
])
|
||||
->save();
|
||||
|
||||
entity_get_display('node', $type, 'default')
|
||||
->setComponent($float_field, [
|
||||
'type' => 'number_decimal',
|
||||
])
|
||||
->setComponent($integer_field, [
|
||||
'type' => 'number_unformatted',
|
||||
])
|
||||
->save();
|
||||
|
||||
// Create a node to test formatters.
|
||||
$node = Node::create([
|
||||
'type' => $type,
|
||||
'title' => $this->randomMachineName(),
|
||||
$float_field => ['value' => $random_float],
|
||||
$integer_field => ['value' => $random_integer],
|
||||
]);
|
||||
$node->save();
|
||||
|
||||
// Go to manage display page.
|
||||
$this->drupalGet("admin/structure/types/manage/$type/display");
|
||||
|
||||
// Configure number_decimal formatter for the 'float' field type.
|
||||
$thousand_separator = $thousand_separators[array_rand($thousand_separators)];
|
||||
$decimal_separator = $decimal_separators[array_rand($decimal_separators)];
|
||||
$scale = rand(0, 10);
|
||||
|
||||
$page = $this->getSession()->getPage();
|
||||
$page->pressButton("${float_field}_settings_edit");
|
||||
$assert_session->waitForElement('css', '.ajax-new-content');
|
||||
$edit = [
|
||||
"fields[${float_field}][settings_edit_form][settings][prefix_suffix]" => TRUE,
|
||||
"fields[${float_field}][settings_edit_form][settings][scale]" => $scale,
|
||||
"fields[${float_field}][settings_edit_form][settings][decimal_separator]" => $decimal_separator,
|
||||
"fields[${float_field}][settings_edit_form][settings][thousand_separator]" => $thousand_separator,
|
||||
];
|
||||
foreach ($edit as $name => $value) {
|
||||
$page->fillField($name, $value);
|
||||
}
|
||||
$page->pressButton("${float_field}_plugin_settings_update");
|
||||
$assert_session->waitForElement('css', '.field-plugin-summary-cell > .ajax-new-content');
|
||||
$this->drupalPostForm(NULL, [], t('Save'));
|
||||
|
||||
// Check number_decimal and number_unformatted formatters behavior.
|
||||
$this->drupalGet('node/' . $node->id());
|
||||
$float_formatted = number_format($random_float, $scale, $decimal_separator, $thousand_separator);
|
||||
$this->assertRaw("$prefix$float_formatted$suffix", 'Prefix and suffix added');
|
||||
$this->assertRaw((string) $random_integer);
|
||||
|
||||
// Configure the number_decimal formatter.
|
||||
entity_get_display('node', $type, 'default')
|
||||
->setComponent($integer_field, [
|
||||
'type' => 'number_integer',
|
||||
])
|
||||
->save();
|
||||
$this->drupalGet("admin/structure/types/manage/$type/display");
|
||||
|
||||
$thousand_separator = $thousand_separators[array_rand($thousand_separators)];
|
||||
|
||||
$page = $this->getSession()->getPage();
|
||||
$page->pressButton("${integer_field}_settings_edit");
|
||||
$assert_session->waitForElement('css', '.ajax-new-content');
|
||||
$edit = [
|
||||
"fields[${integer_field}][settings_edit_form][settings][prefix_suffix]" => FALSE,
|
||||
"fields[${integer_field}][settings_edit_form][settings][thousand_separator]" => $thousand_separator,
|
||||
];
|
||||
foreach ($edit as $name => $value) {
|
||||
$page->fillField($name, $value);
|
||||
}
|
||||
$page->pressButton("${integer_field}_plugin_settings_update");
|
||||
$assert_session->waitForElement('css', '.field-plugin-summary-cell > .ajax-new-content');
|
||||
$this->drupalPostForm(NULL, [], t('Save'));
|
||||
|
||||
// Check number_integer formatter behavior.
|
||||
$this->drupalGet('node/' . $node->id());
|
||||
|
||||
$integer_formatted = number_format($random_integer, 0, '', $thousand_separator);
|
||||
$this->assertRaw($integer_formatted, 'Random integer formatted');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace Drupal\Tests\field\Kernel\Boolean;
|
||||
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
|
||||
use Drupal\Core\Entity\FieldableEntityInterface;
|
||||
use Drupal\entity_test\Entity\EntityTest;
|
||||
@@ -55,7 +54,7 @@ class BooleanFormatterTest extends KernelTestBase {
|
||||
|
||||
$this->entityType = 'entity_test';
|
||||
$this->bundle = $this->entityType;
|
||||
$this->fieldName = Unicode::strtolower($this->randomMachineName());
|
||||
$this->fieldName = mb_strtolower($this->randomMachineName());
|
||||
|
||||
$field_storage = FieldStorageConfig::create([
|
||||
'field_name' => $this->fieldName,
|
||||
@@ -115,7 +114,7 @@ class BooleanFormatterTest extends KernelTestBase {
|
||||
$format = [
|
||||
'format' => 'custom',
|
||||
'format_custom_false' => 'FALSE',
|
||||
'format_custom_true' => 'TRUE'
|
||||
'format_custom_true' => 'TRUE',
|
||||
];
|
||||
$data[] = [0, $format, 'FALSE'];
|
||||
$data[] = [1, $format, 'TRUE'];
|
||||
|
||||
@@ -105,7 +105,7 @@ class BulkDeleteTest extends FieldKernelTestBase {
|
||||
'field_name' => 'bf_1',
|
||||
'entity_type' => $this->entityTypeId,
|
||||
'type' => 'test_field',
|
||||
'cardinality' => 1
|
||||
'cardinality' => 1,
|
||||
]);
|
||||
$field_storage->save();
|
||||
$this->fieldStorages[] = $field_storage;
|
||||
@@ -113,7 +113,7 @@ class BulkDeleteTest extends FieldKernelTestBase {
|
||||
'field_name' => 'bf_2',
|
||||
'entity_type' => $this->entityTypeId,
|
||||
'type' => 'test_field',
|
||||
'cardinality' => 4
|
||||
'cardinality' => 4,
|
||||
]);
|
||||
$field_storage->save();
|
||||
$this->fieldStorages[] = $field_storage;
|
||||
@@ -162,10 +162,11 @@ class BulkDeleteTest extends FieldKernelTestBase {
|
||||
$bundle = reset($this->bundles);
|
||||
$field_storage = reset($this->fieldStorages);
|
||||
$field_name = $field_storage->getName();
|
||||
$factory = \Drupal::service('entity.query');
|
||||
$storage = \Drupal::entityTypeManager()->getStorage('entity_test');
|
||||
|
||||
// There are 10 entities of this bundle.
|
||||
$found = $factory->get('entity_test')
|
||||
$found = $storage
|
||||
->getQuery()
|
||||
->condition('type', $bundle)
|
||||
->execute();
|
||||
$this->assertEqual(count($found), 10, 'Correct number of entities found before deleting');
|
||||
@@ -181,7 +182,6 @@ class BulkDeleteTest extends FieldKernelTestBase {
|
||||
$this->assertEqual($field->getTargetBundle(), $bundle, 'The deleted field is for the correct bundle');
|
||||
|
||||
// Check that the actual stored content did not change during delete.
|
||||
$storage = \Drupal::entityManager()->getStorage($this->entityTypeId);
|
||||
/** @var \Drupal\Core\Entity\Sql\DefaultTableMapping $table_mapping */
|
||||
$table_mapping = $storage->getTableMapping();
|
||||
$table = $table_mapping->getDedicatedDataTableName($field_storage);
|
||||
@@ -194,7 +194,8 @@ class BulkDeleteTest extends FieldKernelTestBase {
|
||||
}
|
||||
|
||||
// There are 0 entities of this bundle with non-deleted data.
|
||||
$found = $factory->get('entity_test')
|
||||
$found = $storage
|
||||
->getQuery()
|
||||
->condition('type', $bundle)
|
||||
->condition("$field_name.deleted", 0)
|
||||
->execute();
|
||||
@@ -202,7 +203,8 @@ class BulkDeleteTest extends FieldKernelTestBase {
|
||||
|
||||
// There are 10 entities of this bundle when deleted fields are allowed, and
|
||||
// their values are correct.
|
||||
$found = $factory->get('entity_test')
|
||||
$found = $storage
|
||||
->getQuery()
|
||||
->condition('type', $bundle)
|
||||
->condition("$field_name.deleted", 1)
|
||||
->sort('id')
|
||||
@@ -222,7 +224,7 @@ class BulkDeleteTest extends FieldKernelTestBase {
|
||||
'field_name' => $field_name,
|
||||
'entity_type' => $this->entityTypeId,
|
||||
'type' => 'test_field',
|
||||
'cardinality' => 1
|
||||
'cardinality' => 1,
|
||||
]);
|
||||
$deleted_field_storage->save();
|
||||
// Create the field.
|
||||
@@ -253,7 +255,7 @@ class BulkDeleteTest extends FieldKernelTestBase {
|
||||
'field_name' => $field_name,
|
||||
'entity_type' => $this->entityTypeId,
|
||||
'type' => 'test_field',
|
||||
'cardinality' => 1
|
||||
'cardinality' => 1,
|
||||
]);
|
||||
$field_storage->save();
|
||||
FieldConfig::create([
|
||||
|
||||
@@ -15,7 +15,7 @@ class ConfigFieldDefinitionTest extends FieldKernelTestBase {
|
||||
/**
|
||||
* The entity manager service.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityManagerInterface;
|
||||
* @var \Drupal\Core\Entity\EntityManagerInterface
|
||||
*/
|
||||
protected $entityManager;
|
||||
|
||||
|
||||
@@ -332,7 +332,6 @@ class EntityReferenceFormatterTest extends EntityKernelTestBase {
|
||||
$this->assertEquals($expected_occurrences, $actual_occurrences);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tests the label formatter.
|
||||
*/
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
namespace Drupal\Tests\field\Kernel\EntityReference;
|
||||
|
||||
use Drupal\comment\Entity\Comment;
|
||||
use Drupal\comment\Entity\CommentType;
|
||||
use Drupal\Component\Render\FormattableMarkup;
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\Core\Field\FieldItemListInterface;
|
||||
use Drupal\Core\Field\FieldItemInterface;
|
||||
use Drupal\Core\Field\FieldStorageDefinitionInterface;
|
||||
@@ -15,6 +15,7 @@ use Drupal\entity_test\Entity\EntityTestStringId;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait;
|
||||
use Drupal\node\Entity\NodeType;
|
||||
use Drupal\node\NodeInterface;
|
||||
use Drupal\taxonomy\TermInterface;
|
||||
use Drupal\Tests\field\Kernel\FieldKernelTestBase;
|
||||
@@ -78,7 +79,7 @@ class EntityReferenceItemTest extends FieldKernelTestBase {
|
||||
|
||||
$this->vocabulary = Vocabulary::create([
|
||||
'name' => $this->randomMachineName(),
|
||||
'vid' => Unicode::strtolower($this->randomMachineName()),
|
||||
'vid' => mb_strtolower($this->randomMachineName()),
|
||||
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
|
||||
]);
|
||||
$this->vocabulary->save();
|
||||
@@ -90,6 +91,14 @@ class EntityReferenceItemTest extends FieldKernelTestBase {
|
||||
]);
|
||||
$this->term->save();
|
||||
|
||||
NodeType::create([
|
||||
'type' => $this->randomMachineName(),
|
||||
])->save();
|
||||
CommentType::create([
|
||||
'id' => $this->randomMachineName(),
|
||||
'target_entity_type_id' => 'node',
|
||||
])->save();
|
||||
|
||||
$this->entityStringId = EntityTestStringId::create([
|
||||
'id' => $this->randomMachineName(),
|
||||
]);
|
||||
@@ -103,6 +112,7 @@ class EntityReferenceItemTest extends FieldKernelTestBase {
|
||||
$this->createEntityReferenceField('entity_test', 'entity_test', 'field_test_user', 'Test user entity reference', 'user');
|
||||
$this->createEntityReferenceField('entity_test', 'entity_test', 'field_test_comment', 'Test comment entity reference', 'comment');
|
||||
$this->createEntityReferenceField('entity_test', 'entity_test', 'field_test_file', 'Test file entity reference', 'file');
|
||||
$this->createEntityReferenceField('entity_test_string_id', 'entity_test_string_id', 'field_test_entity_test', 'Test content entity reference with string ID', 'entity_test');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -212,6 +222,19 @@ class EntityReferenceItemTest extends FieldKernelTestBase {
|
||||
$this->entityValidateAndSave($entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the ::generateSampleValue() method when it has a circular reference.
|
||||
*/
|
||||
public function testGenerateSampleValueCircularReference() {
|
||||
// Delete the existing entity.
|
||||
$this->entityStringId->delete();
|
||||
|
||||
$entity_storage = \Drupal::entityTypeManager()->getStorage('entity_test');
|
||||
$entity = $entity_storage->createWithSampleValues('entity_test');
|
||||
$this->assertInstanceOf(EntityTestStringId::class, $entity->field_test_entity_test_string_id->entity);
|
||||
$this->assertInstanceOf(EntityTest::class, $entity->field_test_entity_test_string_id->entity->field_test_entity_test->entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests referencing content entities with string IDs.
|
||||
*/
|
||||
@@ -259,7 +282,7 @@ class EntityReferenceItemTest extends FieldKernelTestBase {
|
||||
// Make sure the computed term reflects updates to the term id.
|
||||
$vocabulary2 = $vocabulary = Vocabulary::create([
|
||||
'name' => $this->randomMachineName(),
|
||||
'vid' => Unicode::strtolower($this->randomMachineName()),
|
||||
'vid' => mb_strtolower($this->randomMachineName()),
|
||||
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
|
||||
]);
|
||||
$vocabulary2->save();
|
||||
@@ -330,13 +353,13 @@ class EntityReferenceItemTest extends FieldKernelTestBase {
|
||||
* Tests that the 'handler' field setting stores the proper plugin ID.
|
||||
*/
|
||||
public function testSelectionHandlerSettings() {
|
||||
$field_name = Unicode::strtolower($this->randomMachineName());
|
||||
$field_name = mb_strtolower($this->randomMachineName());
|
||||
$field_storage = FieldStorageConfig::create([
|
||||
'field_name' => $field_name,
|
||||
'entity_type' => 'entity_test',
|
||||
'type' => 'entity_reference',
|
||||
'settings' => [
|
||||
'target_type' => 'entity_test'
|
||||
'target_type' => 'entity_test',
|
||||
],
|
||||
]);
|
||||
$field_storage->save();
|
||||
@@ -428,7 +451,7 @@ class EntityReferenceItemTest extends FieldKernelTestBase {
|
||||
$this->assertEqual($errors[0]->getPropertyPath(), 'field_test_node.0.entity');
|
||||
|
||||
// Publish the node and try again.
|
||||
$node->setPublished(TRUE);
|
||||
$node->setPublished();
|
||||
$errors = $entity->validate();
|
||||
$this->assertEqual(0, count($errors));
|
||||
|
||||
@@ -478,7 +501,7 @@ class EntityReferenceItemTest extends FieldKernelTestBase {
|
||||
$this->assertEqual($errors[1]->getPropertyPath(), 'field_test_node.1.target_id');
|
||||
|
||||
// Publish one of the nodes and try again.
|
||||
$saved_unpublished_node->setPublished(TRUE);
|
||||
$saved_unpublished_node->setPublished();
|
||||
$saved_unpublished_node->save();
|
||||
$errors = $entity->validate();
|
||||
$this->assertEqual(1, count($errors));
|
||||
@@ -486,7 +509,7 @@ class EntityReferenceItemTest extends FieldKernelTestBase {
|
||||
$this->assertEqual($errors[0]->getPropertyPath(), 'field_test_node.0.entity');
|
||||
|
||||
// Publish the last invalid node and try again.
|
||||
$unsaved_unpublished_node->setPublished(TRUE);
|
||||
$unsaved_unpublished_node->setPublished();
|
||||
$errors = $entity->validate();
|
||||
$this->assertEqual(0, count($errors));
|
||||
|
||||
@@ -510,7 +533,7 @@ class EntityReferenceItemTest extends FieldKernelTestBase {
|
||||
$this->assertEqual($errors[0]->getPropertyPath(), 'field_test_comment.0.entity');
|
||||
|
||||
// Publish the comment and try again.
|
||||
$comment->setPublished(TRUE);
|
||||
$comment->setPublished();
|
||||
$errors = $entity->validate();
|
||||
$this->assertEqual(0, count($errors));
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace Drupal\Tests\field\Kernel\EntityReference;
|
||||
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||
use Drupal\Core\Logger\RfcLogLevel;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
@@ -65,13 +64,13 @@ class EntityReferenceSettingsTest extends KernelTestBase {
|
||||
$this->installEntitySchema('entity_test');
|
||||
|
||||
$this->nodeType = NodeType::create([
|
||||
'type' => Unicode::strtolower($this->randomMachineName()),
|
||||
'type' => mb_strtolower($this->randomMachineName()),
|
||||
'name' => $this->randomString(),
|
||||
]);
|
||||
$this->nodeType->save();
|
||||
|
||||
// Create a custom bundle.
|
||||
$this->customBundle = 'test_bundle_' . Unicode::strtolower($this->randomMachineName());
|
||||
$this->customBundle = 'test_bundle_' . mb_strtolower($this->randomMachineName());
|
||||
entity_test_create_bundle($this->customBundle, NULL, 'entity_test');
|
||||
|
||||
// Prepare the logger for collecting the expected critical error.
|
||||
@@ -86,7 +85,7 @@ class EntityReferenceSettingsTest extends KernelTestBase {
|
||||
/** @var \Drupal\taxonomy\Entity\Vocabulary[] $vocabularies */
|
||||
$vocabularies = [];
|
||||
for ($i = 0; $i < 2; $i++) {
|
||||
$vid = Unicode::strtolower($this->randomMachineName());
|
||||
$vid = mb_strtolower($this->randomMachineName());
|
||||
$vocabularies[$i] = Vocabulary::create([
|
||||
'name' => $this->randomString(),
|
||||
'vid' => $vid,
|
||||
@@ -94,7 +93,7 @@ class EntityReferenceSettingsTest extends KernelTestBase {
|
||||
$vocabularies[$i]->save();
|
||||
}
|
||||
// Attach an entity reference field to $this->nodeType.
|
||||
$name = Unicode::strtolower($this->randomMachineName());
|
||||
$name = mb_strtolower($this->randomMachineName());
|
||||
$label = $this->randomString();
|
||||
$handler_settings = [
|
||||
'target_bundles' => [
|
||||
@@ -143,7 +142,7 @@ class EntityReferenceSettingsTest extends KernelTestBase {
|
||||
*/
|
||||
public function testCustomTargetBundleDeletion() {
|
||||
// Attach an entity reference field to $this->nodeType.
|
||||
$name = Unicode::strtolower($this->randomMachineName());
|
||||
$name = mb_strtolower($this->randomMachineName());
|
||||
$label = $this->randomString();
|
||||
$handler_settings = ['target_bundles' => [$this->customBundle => $this->customBundle]];
|
||||
$this->createEntityReferenceField('node', $this->nodeType->id(), $name, $label, 'entity_test', 'default', $handler_settings);
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace Drupal\Tests\field\Kernel;
|
||||
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
|
||||
@@ -292,7 +291,7 @@ class FieldAttachStorageTest extends FieldKernelTestBase {
|
||||
$cardinality = $this->fieldTestData->field_storage->getCardinality();
|
||||
|
||||
// Create a new bundle.
|
||||
$new_bundle = 'test_bundle_' . Unicode::strtolower($this->randomMachineName());
|
||||
$new_bundle = 'test_bundle_' . mb_strtolower($this->randomMachineName());
|
||||
entity_test_create_bundle($new_bundle, NULL, $entity_type);
|
||||
|
||||
// Add a field to that bundle.
|
||||
@@ -319,7 +318,7 @@ class FieldAttachStorageTest extends FieldKernelTestBase {
|
||||
$this->createFieldWithStorage('', $entity_type);
|
||||
|
||||
// Create a new bundle.
|
||||
$new_bundle = 'test_bundle_' . Unicode::strtolower($this->randomMachineName());
|
||||
$new_bundle = 'test_bundle_' . mb_strtolower($this->randomMachineName());
|
||||
entity_test_create_bundle($new_bundle, NULL, $entity_type);
|
||||
|
||||
// Add a field to that bundle.
|
||||
@@ -327,7 +326,7 @@ class FieldAttachStorageTest extends FieldKernelTestBase {
|
||||
FieldConfig::create($this->fieldTestData->field_definition)->save();
|
||||
|
||||
// Create a second field for the test bundle
|
||||
$field_name = Unicode::strtolower($this->randomMachineName() . '_field_name');
|
||||
$field_name = mb_strtolower($this->randomMachineName() . '_field_name');
|
||||
$field_storage = [
|
||||
'field_name' => $field_name,
|
||||
'entity_type' => $entity_type,
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace Drupal\Tests\field\Kernel;
|
||||
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\Core\Entity\EntityStorageException;
|
||||
use Drupal\Core\Field\FieldException;
|
||||
use Drupal\entity_test\Entity\EntityTest;
|
||||
@@ -43,7 +42,7 @@ class FieldCrudTest extends FieldKernelTestBase {
|
||||
parent::setUp();
|
||||
|
||||
$this->fieldStorageDefinition = [
|
||||
'field_name' => Unicode::strtolower($this->randomMachineName()),
|
||||
'field_name' => mb_strtolower($this->randomMachineName()),
|
||||
'entity_type' => 'entity_test',
|
||||
'type' => 'test_field',
|
||||
];
|
||||
@@ -199,7 +198,7 @@ class FieldCrudTest extends FieldKernelTestBase {
|
||||
* Test creating a field with custom storage set.
|
||||
*/
|
||||
public function testCreateFieldCustomStorage() {
|
||||
$field_name = Unicode::strtolower($this->randomMachineName());
|
||||
$field_name = mb_strtolower($this->randomMachineName());
|
||||
\Drupal::state()->set('field_test_custom_storage', $field_name);
|
||||
|
||||
$field_storage = FieldStorageConfig::create([
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\field\Kernel;
|
||||
|
||||
use Drupal\entity_test\Entity\EntityTestRev;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
use Symfony\Component\CssSelector\CssSelectorConverter;
|
||||
|
||||
/**
|
||||
* Tests Field display.
|
||||
*
|
||||
* @group field
|
||||
*/
|
||||
class FieldDisplayTest extends KernelTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = [
|
||||
'entity_test',
|
||||
'field',
|
||||
'system',
|
||||
'user',
|
||||
];
|
||||
|
||||
/**
|
||||
* Test entity type name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $entityType;
|
||||
|
||||
/**
|
||||
* Test entity bundle name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $bundle;
|
||||
|
||||
/**
|
||||
* Test field name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $fieldName;
|
||||
|
||||
/**
|
||||
* Entity view display.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface
|
||||
*/
|
||||
protected $display;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Configure the theme system.
|
||||
$this->installConfig(['system', 'field']);
|
||||
$this->installEntitySchema('entity_test_rev');
|
||||
|
||||
$this->entityType = 'entity_test_rev';
|
||||
$this->bundle = $this->entityType;
|
||||
$this->fieldName = mb_strtolower($this->randomMachineName());
|
||||
|
||||
$field_storage = FieldStorageConfig::create([
|
||||
'field_name' => $this->fieldName,
|
||||
'entity_type' => $this->entityType,
|
||||
'type' => 'string',
|
||||
]);
|
||||
$field_storage->save();
|
||||
|
||||
$instance = FieldConfig::create([
|
||||
'field_storage' => $field_storage,
|
||||
'bundle' => $this->bundle,
|
||||
'label' => $this->randomMachineName(),
|
||||
]);
|
||||
$instance->save();
|
||||
|
||||
$values = [
|
||||
'targetEntityType' => $this->entityType,
|
||||
'bundle' => $this->bundle,
|
||||
'mode' => 'default',
|
||||
'status' => TRUE,
|
||||
];
|
||||
|
||||
$this->display = \Drupal::entityTypeManager()
|
||||
->getStorage('entity_view_display')
|
||||
->create($values);
|
||||
$this->display->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that visually hidden works with core.
|
||||
*/
|
||||
public function testFieldVisualHidden() {
|
||||
$value = $this->randomMachineName();
|
||||
|
||||
// Set the formatter to link to the entity.
|
||||
$this->display->setComponent($this->fieldName, [
|
||||
'type' => 'string',
|
||||
'label' => 'visually_hidden',
|
||||
'settings' => [],
|
||||
])->save();
|
||||
|
||||
$entity = EntityTestRev::create([]);
|
||||
$entity->{$this->fieldName}->value = $value;
|
||||
$entity->save();
|
||||
|
||||
$build = $this->display->build($entity);
|
||||
$renderer = \Drupal::service('renderer');
|
||||
$content = $renderer->renderPlain($build);
|
||||
$this->setRawContent((string) $content);
|
||||
|
||||
$css_selector_converter = new CssSelectorConverter();
|
||||
$elements = $this->xpath($css_selector_converter->toXPath('.visually-hidden'));
|
||||
$this->assertCount(1, $elements, $content);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Drupal\Tests\field\Kernel;
|
||||
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
use Drupal\Component\Render\FormattableMarkup;
|
||||
use Drupal\entity_test\Entity\EntityTest;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
@@ -69,11 +69,11 @@ class FieldImportDeleteTest extends FieldKernelTestBase {
|
||||
$active = $this->container->get('config.storage');
|
||||
$sync = $this->container->get('config.storage.sync');
|
||||
$this->copyConfig($active, $sync);
|
||||
$this->assertTrue($sync->delete($field_storage_config_name), SafeMarkup::format('Deleted field storage: @field_storage', ['@field_storage' => $field_storage_config_name]));
|
||||
$this->assertTrue($sync->delete($field_storage_config_name_2), SafeMarkup::format('Deleted field storage: @field_storage', ['@field_storage' => $field_storage_config_name_2]));
|
||||
$this->assertTrue($sync->delete($field_config_name), SafeMarkup::format('Deleted field: @field', ['@field' => $field_config_name]));
|
||||
$this->assertTrue($sync->delete($field_config_name_2a), SafeMarkup::format('Deleted field: @field', ['@field' => $field_config_name_2a]));
|
||||
$this->assertTrue($sync->delete($field_config_name_2b), SafeMarkup::format('Deleted field: @field', ['@field' => $field_config_name_2b]));
|
||||
$this->assertTrue($sync->delete($field_storage_config_name), new FormattableMarkup('Deleted field storage: @field_storage', ['@field_storage' => $field_storage_config_name]));
|
||||
$this->assertTrue($sync->delete($field_storage_config_name_2), new FormattableMarkup('Deleted field storage: @field_storage', ['@field_storage' => $field_storage_config_name_2]));
|
||||
$this->assertTrue($sync->delete($field_config_name), new FormattableMarkup('Deleted field: @field', ['@field' => $field_config_name]));
|
||||
$this->assertTrue($sync->delete($field_config_name_2a), new FormattableMarkup('Deleted field: @field', ['@field' => $field_config_name_2a]));
|
||||
$this->assertTrue($sync->delete($field_config_name_2b), new FormattableMarkup('Deleted field: @field', ['@field' => $field_config_name_2b]));
|
||||
|
||||
$deletes = $this->configImporter()->getUnprocessedConfiguration('delete');
|
||||
$this->assertEqual(count($deletes), 5, 'Importing configuration will delete 3 fields and 2 field storages.');
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace Drupal\Tests\field\Kernel;
|
||||
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
@@ -87,7 +86,7 @@ abstract class FieldKernelTestBase extends KernelTestBase {
|
||||
$field = 'field' . $suffix;
|
||||
$field_definition = 'field_definition' . $suffix;
|
||||
|
||||
$this->fieldTestData->$field_name = Unicode::strtolower($this->randomMachineName() . '_field_name' . $suffix);
|
||||
$this->fieldTestData->$field_name = mb_strtolower($this->randomMachineName() . '_field_name' . $suffix);
|
||||
$this->fieldTestData->$field_storage = FieldStorageConfig::create([
|
||||
'field_name' => $this->fieldTestData->$field_name,
|
||||
'entity_type' => $entity_type,
|
||||
@@ -113,7 +112,7 @@ abstract class FieldKernelTestBase extends KernelTestBase {
|
||||
'type' => 'test_field_widget',
|
||||
'settings' => [
|
||||
'test_widget_setting' => $this->randomMachineName(),
|
||||
]
|
||||
],
|
||||
])
|
||||
->save();
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ class FieldStorageCrudTest extends FieldKernelTestBase {
|
||||
try {
|
||||
$field_storage_definition = [
|
||||
'field_name' => 'test_field',
|
||||
'type' => 'test_field'
|
||||
'type' => 'test_field',
|
||||
];
|
||||
FieldStorageConfig::create($field_storage_definition)->save();
|
||||
$this->fail('Cannot create a field without an entity type.');
|
||||
@@ -188,7 +188,7 @@ class FieldStorageCrudTest extends FieldKernelTestBase {
|
||||
*/
|
||||
public function testCreateWithExplicitSchema() {
|
||||
$schema = [
|
||||
'dummy' => 'foobar'
|
||||
'dummy' => 'foobar',
|
||||
];
|
||||
$field_storage = FieldStorageConfig::create([
|
||||
'field_name' => 'field_2',
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Drupal\Tests\field\Kernel;
|
||||
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
use Drupal\Component\Render\FormattableMarkup;
|
||||
use Drupal\Core\Extension\ExtensionDiscovery;
|
||||
use Drupal\Core\Field\BaseFieldDefinition;
|
||||
use Drupal\entity_test\Entity\EntityTest;
|
||||
@@ -48,8 +48,8 @@ class FieldTypePluginManagerTest extends FieldKernelTestBase {
|
||||
|
||||
$instance = $field_type_manager->createInstance($type, $configuration);
|
||||
|
||||
$this->assertTrue($instance instanceof $class, SafeMarkup::format('Created a @class instance', ['@class' => $class]));
|
||||
$this->assertEqual($field_name, $instance->getName(), SafeMarkup::format('Instance name is @name', ['@name' => $field_name]));
|
||||
$this->assertTrue($instance instanceof $class, new FormattableMarkup('Created a @class instance', ['@class' => $class]));
|
||||
$this->assertEqual($field_name, $instance->getName(), new FormattableMarkup('Instance name is @name', ['@name' => $field_name]));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,8 +79,8 @@ class FieldTypePluginManagerTest extends FieldKernelTestBase {
|
||||
|
||||
$instance = $field_type_manager->createInstance($type, $configuration);
|
||||
|
||||
$this->assertTrue($instance instanceof $class, SafeMarkup::format('Created a @class instance', ['@class' => $class]));
|
||||
$this->assertEqual($field_name, $instance->getName(), SafeMarkup::format('Instance name is @name', ['@name' => $field_name]));
|
||||
$this->assertTrue($instance instanceof $class, new FormattableMarkup('Created a @class instance', ['@class' => $class]));
|
||||
$this->assertEqual($field_name, $instance->getName(), new FormattableMarkup('Instance name is @name', ['@name' => $field_name]));
|
||||
$this->assertEqual($instance->getFieldDefinition()->getLabel(), 'Jenny', 'Instance label is Jenny');
|
||||
$this->assertEqual($instance->getFieldDefinition()->getDefaultValue($entity), [['value' => 8675309]], 'Instance default_value is 8675309');
|
||||
}
|
||||
@@ -112,7 +112,7 @@ class FieldTypePluginManagerTest extends FieldKernelTestBase {
|
||||
* Enable all core modules.
|
||||
*/
|
||||
protected function enableAllCoreModules() {
|
||||
$listing = new ExtensionDiscovery(\Drupal::root());
|
||||
$listing = new ExtensionDiscovery($this->root);
|
||||
$module_list = $listing->scan('module', FALSE);
|
||||
/** @var \Drupal\Core\Extension\ModuleHandlerInterface $module_handler */
|
||||
$module_handler = $this->container->get('module_handler');
|
||||
|
||||
+2
-2
@@ -130,7 +130,7 @@ class MigrateFieldFormatterSettingsTest extends MigrateDrupal6TestBase {
|
||||
$expected['weight'] = 8;
|
||||
$expected['type'] = 'file_default';
|
||||
$expected['settings'] = [
|
||||
'use_description_as_link_text' => TRUE
|
||||
'use_description_as_link_text' => TRUE,
|
||||
];
|
||||
$component = $display->getComponent('field_test_filefield');
|
||||
$this->assertIdentical($expected, $component);
|
||||
@@ -197,7 +197,7 @@ class MigrateFieldFormatterSettingsTest extends MigrateDrupal6TestBase {
|
||||
$component = $display->getComponent('field_test_datetime');
|
||||
$this->assertIdentical($expected, $component);
|
||||
// Test that our Id map has the correct data.
|
||||
$this->assertIdentical(['node', 'story', 'teaser', 'field_test'], $this->getMigration('d6_field_formatter_settings')->getIdMap()->lookupDestinationID(['story', 'teaser', 'node', 'field_test']));
|
||||
$this->assertIdentical(['node', 'story', 'teaser', 'field_test'], $this->getMigration('d6_field_formatter_settings')->getIdMap()->lookupDestinationId(['story', 'teaser', 'node', 'field_test']));
|
||||
|
||||
// Test hidden field.
|
||||
$this->assertComponentNotExists('node.test_planet.teaser', 'field_test_text_single_checkbox');
|
||||
|
||||
@@ -107,6 +107,16 @@ class MigrateFieldWidgetSettingsTest extends MigrateDrupal6TestBase {
|
||||
$this->assertInternalType('array', $component);
|
||||
$this->assertSame('options_select', $component['type']);
|
||||
|
||||
$component = entity_get_form_display('node', 'employee', 'default')
|
||||
->getComponent('field_company_2');
|
||||
$this->assertInternalType('array', $component);
|
||||
$this->assertSame('options_buttons', $component['type']);
|
||||
|
||||
$component = entity_get_form_display('node', 'employee', 'default')
|
||||
->getComponent('field_company_3');
|
||||
$this->assertInternalType('array', $component);
|
||||
$this->assertSame('entity_reference_autocomplete_tags', $component['type']);
|
||||
|
||||
$component = entity_get_form_display('node', 'employee', 'default')
|
||||
->getComponent('field_commander');
|
||||
$this->assertInternalType('array', $component);
|
||||
|
||||
@@ -283,6 +283,7 @@ class MigrateFieldFormatterSettingsTest extends MigrateDrupal7TestBase {
|
||||
$this->assertComponent('node.test_content_type.default', 'field_link', 'link', 'above', 9);
|
||||
$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_float_list', 'list_default', 'above', 19);
|
||||
$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);
|
||||
|
||||
@@ -118,19 +118,30 @@ class MigrateFieldInstanceTest extends MigrateDrupal7TestBase {
|
||||
$this->assertEntity('node.test_content_type.field_file', 'File', 'file', FALSE, FALSE);
|
||||
$this->assertEntity('node.test_content_type.field_float', 'Float', 'float', FALSE, FALSE);
|
||||
$this->assertEntity('node.test_content_type.field_images', 'Images', 'image', TRUE, FALSE);
|
||||
$this->assertEntity('node.test_content_type.field_integer', 'Integer', 'integer', TRUE, FALSE);
|
||||
$this->assertEntity('node.test_content_type.field_integer', 'Integer', 'integer', TRUE, TRUE);
|
||||
$this->assertEntity('node.test_content_type.field_link', 'Link', 'link', FALSE, FALSE);
|
||||
$this->assertEntity('node.test_content_type.field_text_list', 'Text List', 'list_string', FALSE, FALSE);
|
||||
$this->assertEntity('node.test_content_type.field_integer_list', 'Integer List', 'list_integer', FALSE, FALSE);
|
||||
$this->assertEntity('node.test_content_type.field_float_list', 'Float List', 'list_float', FALSE, FALSE);
|
||||
$this->assertEntity('node.test_content_type.field_long_text', 'Long text', 'text_with_summary', FALSE, FALSE);
|
||||
$this->assertEntity('node.test_content_type.field_term_reference', 'Term Reference', 'entity_reference', FALSE, FALSE);
|
||||
$this->assertEntity('node.test_content_type.field_text', 'Text', 'string', FALSE, FALSE);
|
||||
$this->assertEntity('comment.comment_node_test_content_type.field_integer', 'Integer', 'integer', FALSE, FALSE);
|
||||
$this->assertEntity('comment.comment_node_test_content_type.field_integer', 'Integer', 'integer', FALSE, TRUE);
|
||||
$this->assertEntity('user.user.field_file', 'File', 'file', FALSE, FALSE);
|
||||
|
||||
$this->assertLinkFields('node.test_content_type.field_link', DRUPAL_OPTIONAL);
|
||||
$this->assertLinkFields('node.article.field_link', DRUPAL_DISABLED);
|
||||
$this->assertLinkFields('node.blog.field_link', DRUPAL_REQUIRED);
|
||||
|
||||
// Tests that fields created by the Title module are not migrated.
|
||||
$title_field = FieldConfig::load('node.test_content_type.title_field');
|
||||
$this->assertNull($title_field);
|
||||
$subject_field = FieldConfig::load('comment.comment_node_article.subject_field');
|
||||
$this->assertNull($subject_field);
|
||||
$name_field = FieldConfig::load('taxonomy_term.test_vocabulary.name_field');
|
||||
$this->assertNull($name_field);
|
||||
$description_field = FieldConfig::load('taxonomy_term.test_vocabulary.description_field');
|
||||
$this->assertNull($description_field);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user