diff options
Diffstat (limited to 'core/modules/field')
106 files changed, 1460 insertions, 1460 deletions
diff --git a/core/modules/field/field.api.php b/core/modules/field/field.api.php index 8e11650f5cb..b0899ea02b0 100644 --- a/core/modules/field/field.api.php +++ b/core/modules/field/field.api.php @@ -85,7 +85,7 @@ function hook_field_storage_config_update_forbid(\Drupal\field\FieldStorageConfi $prior_allowed_values = $prior_field_storage->getSetting('allowed_values'); $lost_keys = array_keys(array_diff_key($prior_allowed_values, $allowed_values)); if (_options_values_in_use($field_storage->getTargetEntityTypeId(), $field_storage->getName(), $lost_keys)) { - throw new \Drupal\Core\Entity\Exception\FieldStorageDefinitionUpdateForbiddenException(t('A list field (@field_name) with existing data cannot have its keys changed.', array('@field_name' => $field_storage->getName()))); + throw new \Drupal\Core\Entity\Exception\FieldStorageDefinitionUpdateForbiddenException(t('A list field (@field_name) with existing data cannot have its keys changed.', ['@field_name' => $field_storage->getName()])); } } } @@ -257,7 +257,7 @@ function hook_field_formatter_info_alter(array &$info) { * @ingroup field_info */ function hook_field_info_max_weight($entity_type, $bundle, $context, $context_mode) { - $weights = array(); + $weights = []; foreach (my_module_entity_additions($entity_type, $bundle, $context, $context_mode) as $addition) { $weights[] = $addition['weight']; diff --git a/core/modules/field/field.module b/core/modules/field/field.module index 81330071762..8f3877d0f38 100644 --- a/core/modules/field/field.module +++ b/core/modules/field/field.module @@ -67,10 +67,10 @@ require_once __DIR__ . '/field.purge.inc'; function field_help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { case 'help.page.field': - $field_ui_url = \Drupal::moduleHandler()->moduleExists('field_ui') ? \Drupal::url('help.page', array('name' => 'field_ui')) : '#'; + $field_ui_url = \Drupal::moduleHandler()->moduleExists('field_ui') ? \Drupal::url('help.page', ['name' => 'field_ui']) : '#'; $output = ''; $output .= '<h3>' . t('About') . '</h3>'; - $output .= '<p>' . t('The Field module allows custom data fields to be defined for <em>entity</em> types (see below). The Field module takes care of storing, loading, editing, and rendering field data. Most users will not interact with the Field module directly, but will instead use the <a href=":field-ui-help">Field UI module</a> user interface. Module developers can use the Field API to make new entity types "fieldable" and thus allow fields to be attached to them. For more information, see the <a href=":field">online documentation for the Field module</a>.', array(':field-ui-help' => $field_ui_url, ':field' => 'https://www.drupal.org/documentation/modules/field')) . '</p>'; + $output .= '<p>' . t('The Field module allows custom data fields to be defined for <em>entity</em> types (see below). The Field module takes care of storing, loading, editing, and rendering field data. Most users will not interact with the Field module directly, but will instead use the <a href=":field-ui-help">Field UI module</a> user interface. Module developers can use the Field API to make new entity types "fieldable" and thus allow fields to be attached to them. For more information, see the <a href=":field">online documentation for the Field module</a>.', [':field-ui-help' => $field_ui_url, ':field' => 'https://www.drupal.org/documentation/modules/field']) . '</p>'; $output .= '<h3>' . t('Terminology') . '</h3>'; $output .= '<dl>'; $output .= '<dt>' . t('Entities and entity types') . '</dt>'; @@ -87,19 +87,19 @@ function field_help($route_name, RouteMatchInterface $route_match) { $output .= '<h3>' . t('Uses') . '</h3>'; $output .= '<dl>'; $output .= '<dt>' . t('Enabling field types, widgets, and formatters') . '</dt>'; - $output .= '<dd>' . t('The Field module provides the infrastructure for fields; the field types, formatters, and widgets are provided by Drupal core or additional modules. Some of the modules are required; the optional modules can be enabled from the <a href=":modules">Extend administration page</a>. Additional fields, formatters, and widgets may be provided by contributed modules, which you can find in the <a href=":contrib">contributed module section of Drupal.org</a>.', array(':modules' => \Drupal::url('system.modules_list'), ':contrib' => 'https://www.drupal.org/project/modules')) . '</dd>'; + $output .= '<dd>' . t('The Field module provides the infrastructure for fields; the field types, formatters, and widgets are provided by Drupal core or additional modules. Some of the modules are required; the optional modules can be enabled from the <a href=":modules">Extend administration page</a>. Additional fields, formatters, and widgets may be provided by contributed modules, which you can find in the <a href=":contrib">contributed module section of Drupal.org</a>.', [':modules' => \Drupal::url('system.modules_list'), ':contrib' => 'https://www.drupal.org/project/modules']) . '</dd>'; $output .= '<h3>' . t('Field, widget, and formatter information') . '</h3>'; // Make a list of all widget, formatter, and field modules currently // enabled, ordered by displayed module name (module names are not // translated). - $items = array(); + $items = []; $modules = \Drupal::moduleHandler()->getModuleList(); $widgets = \Drupal::service('plugin.manager.field.widget')->getDefinitions(); $field_types = \Drupal::service('plugin.manager.field.field_type')->getUiDefinitions(); $formatters = \Drupal::service('plugin.manager.field.formatter')->getDefinitions(); - $providers = array(); + $providers = []; foreach (array_merge($field_types, $widgets, $formatters) as $plugin) { $providers[] = $plugin['provider']; } @@ -111,7 +111,7 @@ function field_help($route_name, RouteMatchInterface $route_match) { if (isset($modules[$provider])) { $display = \Drupal::moduleHandler()->getName($provider); if (\Drupal::moduleHandler()->implementsHook($provider, 'help')) { - $items[] = \Drupal::l($display, new Url('help.page', array('name' => $provider))); + $items[] = \Drupal::l($display, new Url('help.page', ['name' => $provider])); } else { $items[] = $display; @@ -121,10 +121,10 @@ function field_help($route_name, RouteMatchInterface $route_match) { if ($items) { $output .= '<dt>' . t('Provided by modules') . '</dt>'; $output .= '<dd>' . t('Here is a list of the currently enabled field, formatter, and widget modules:'); - $item_list = array( + $item_list = [ '#theme' => 'item_list', '#items' => $items, - ); + ]; $output .= \Drupal::service('renderer')->renderPlain($item_list); $output .= '</dd>'; } @@ -132,10 +132,10 @@ function field_help($route_name, RouteMatchInterface $route_match) { $output .= '<dt>' . t('Provided by Drupal core') . '</dt>'; $output .= '<dd>' . t('As mentioned previously, some field types, widgets, and formatters are provided by Drupal core. Here are some notes on how to use some of these:'); $output .= '<ul>'; - $output .= '<li><p>' . t('<strong>Entity Reference</strong> fields allow you to create fields that contain links to other entities (such as content items, taxonomy terms, etc.) within the site. This allows you, for example, to include a link to a user within a content item. For more information, see <a href=":er_do">the online documentation for the Entity Reference module</a>.', array(':er_do' => 'https://drupal.org/documentation/modules/entityreference')) . '</p>'; + $output .= '<li><p>' . t('<strong>Entity Reference</strong> fields allow you to create fields that contain links to other entities (such as content items, taxonomy terms, etc.) within the site. This allows you, for example, to include a link to a user within a content item. For more information, see <a href=":er_do">the online documentation for the Entity Reference module</a>.', [':er_do' => 'https://drupal.org/documentation/modules/entityreference']) . '</p>'; $output .= '<dl>'; $output .= '<dt>' . t('Managing and displaying entity reference fields') . '</dt>'; - $output .= '<dd>' . t('The <em>settings</em> and the <em>display</em> of the entity reference field can be configured separately. See the <a href=":field_ui">Field UI help</a> for more information on how to manage fields and their display.', array(':field_ui' => $field_ui_url)) . '</dd>'; + $output .= '<dd>' . t('The <em>settings</em> and the <em>display</em> of the entity reference field can be configured separately. See the <a href=":field_ui">Field UI help</a> for more information on how to manage fields and their display.', [':field_ui' => $field_ui_url]) . '</dd>'; $output .= '<dt>' . t('Selecting reference type') . '</dt>'; $output .= '<dd>' . t('In the field settings you can select which entity type you want to create a reference to.') . '</dd>'; $output .= '<dt>' . t('Filtering and sorting reference fields') . '</dt>'; @@ -179,7 +179,7 @@ function field_entity_field_storage_info(EntityTypeInterface $entity_type) { ->execute(); // Fetch all fields and key them by field name. $field_storages = FieldStorageConfig::loadMultiple($ids); - $result = array(); + $result = []; foreach ($field_storages as $field_storage) { $result[$field_storage->getName()] = $field_storage; } @@ -200,7 +200,7 @@ function field_entity_bundle_field_info(EntityTypeInterface $entity_type, $bundl ->execute(); // Fetch all fields and key them by field name. $field_configs = FieldConfig::loadMultiple($ids); - $result = array(); + $result = []; foreach ($field_configs as $field_instance) { $result[$field_instance->getName()] = $field_instance; } @@ -283,7 +283,7 @@ function field_entity_bundle_delete($entity_type_id, $bundle) { * An entity, initialized with the provided IDs. */ function _field_create_entity_from_ids($ids) { - $id_properties = array(); + $id_properties = []; $entity_type = \Drupal::entityManager()->getDefinition($ids->entity_type); if ($id_key = $entity_type->getKey('id')) { $id_properties[$id_key] = $ids->entity_id; @@ -311,7 +311,7 @@ function field_config_import_steps_alter(&$sync_steps, ConfigImporter $config_im // Add a step to the beginning of the configuration synchronization process // to purge field data where the module that provides the field is being // uninstalled. - array_unshift($sync_steps, array('\Drupal\field\ConfigImporterFieldPurger', 'process')); + array_unshift($sync_steps, ['\Drupal\field\ConfigImporterFieldPurger', 'process']); }; } @@ -341,7 +341,7 @@ function field_form_config_admin_import_form_alter(&$form, FormStateInterface $f count($field_storages), 'This synchronization will delete data from the field %fields.', 'This synchronization will delete data from the fields: %fields.', - array('%fields' => implode(', ', $field_labels)) + ['%fields' => implode(', ', $field_labels)] ), 'warning'); } } diff --git a/core/modules/field/field.purge.inc b/core/modules/field/field.purge.inc index ae3e26694fb..519c6af2740 100644 --- a/core/modules/field/field.purge.inc +++ b/core/modules/field/field.purge.inc @@ -73,10 +73,10 @@ use Drupal\field\FieldConfigInterface; * (optional) Limit the purge to a specific field storage. */ function field_purge_batch($batch_size, $field_storage_uuid = NULL) { - $properties = array( + $properties = [ 'deleted' => TRUE, 'include_deleted' => TRUE, - ); + ]; if ($field_storage_uuid) { $properties['field_storage_uuid'] = $field_storage_uuid; } @@ -106,7 +106,7 @@ function field_purge_batch($batch_size, $field_storage_uuid = NULL) { } // Retrieve all deleted field storages. Any that have no fields can be purged. - $deleted_storages = \Drupal::state()->get('field.storage.deleted') ?: array(); + $deleted_storages = \Drupal::state()->get('field.storage.deleted') ?: []; foreach ($deleted_storages as $field_storage) { $field_storage = new FieldStorageConfig($field_storage); if ($field_storage_uuid && $field_storage->uuid() != $field_storage_uuid) { @@ -121,7 +121,7 @@ function field_purge_batch($batch_size, $field_storage_uuid = NULL) { continue; } - $fields = entity_load_multiple_by_properties('field_config', array('field_storage_uuid' => $field_storage->uuid(), 'include_deleted' => TRUE)); + $fields = entity_load_multiple_by_properties('field_config', ['field_storage_uuid' => $field_storage->uuid(), 'include_deleted' => TRUE]); if (empty($fields)) { field_purge_field_storage($field_storage); } @@ -144,7 +144,7 @@ function field_purge_field(FieldConfigInterface $field) { $state->set('field.field.deleted', $deleted_fields); // Invoke external hooks after the cache is cleared for API consistency. - \Drupal::moduleHandler()->invokeAll('field_purge_field', array($field)); + \Drupal::moduleHandler()->invokeAll('field_purge_field', [$field]); } /** @@ -159,9 +159,9 @@ function field_purge_field(FieldConfigInterface $field) { * @throws Drupal\field\FieldException */ function field_purge_field_storage(FieldStorageConfigInterface $field_storage) { - $fields = entity_load_multiple_by_properties('field_config', array('field_storage_uuid' => $field_storage->uuid(), 'include_deleted' => TRUE)); + $fields = entity_load_multiple_by_properties('field_config', ['field_storage_uuid' => $field_storage->uuid(), 'include_deleted' => TRUE]); if (count($fields) > 0) { - throw new FieldException(t('Attempt to purge a field storage @field_name that still has fields.', array('@field_name' => $field_storage->getName()))); + throw new FieldException(t('Attempt to purge a field storage @field_name that still has fields.', ['@field_name' => $field_storage->getName()])); } $state = \Drupal::state(); @@ -173,7 +173,7 @@ function field_purge_field_storage(FieldStorageConfigInterface $field_storage) { \Drupal::entityManager()->getStorage($field_storage->getTargetEntityTypeId())->finalizePurge($field_storage); // Invoke external hooks after the cache is cleared for API consistency. - \Drupal::moduleHandler()->invokeAll('field_purge_field_storage', array($field_storage)); + \Drupal::moduleHandler()->invokeAll('field_purge_field_storage', [$field_storage]); } /** diff --git a/core/modules/field/src/ConfigImporterFieldPurger.php b/core/modules/field/src/ConfigImporterFieldPurger.php index 4137294f6ff..3974511a66d 100644 --- a/core/modules/field/src/ConfigImporterFieldPurger.php +++ b/core/modules/field/src/ConfigImporterFieldPurger.php @@ -47,7 +47,7 @@ class ConfigImporterFieldPurger { } else { $context['finished'] = $context['sandbox']['field']['current_progress'] / $context['sandbox']['field']['steps_to_delete']; - $context['message'] = \Drupal::translation()->translate('Purging field @field_label', array('@field_label' => $field_storage->label())); + $context['message'] = \Drupal::translation()->translate('Purging field @field_label', ['@field_label' => $field_storage->label()]); } } @@ -111,11 +111,11 @@ class ConfigImporterFieldPurger { public static function getFieldStoragesToPurge(array $extensions, array $deletes) { $providers = array_keys($extensions['module']); $providers[] = 'core'; - $storages_to_delete = array(); + $storages_to_delete = []; // Gather fields that will be deleted during configuration synchronization // where the module that provides the field type is also being uninstalled. - $field_storage_ids = array(); + $field_storage_ids = []; foreach ($deletes as $config_name) { $field_storage_config_prefix = \Drupal::entityManager()->getDefinition('field_storage_config')->getConfigPrefix(); if (strpos($config_name, $field_storage_config_prefix . '.') === 0) { @@ -134,7 +134,7 @@ class ConfigImporterFieldPurger { // Gather deleted fields from modules that are being uninstalled. /** @var \Drupal\field\FieldStorageConfigInterface[] $field_storages */ - $field_storages = entity_load_multiple_by_properties('field_storage_config', array('deleted' => TRUE, 'include_deleted' => TRUE)); + $field_storages = entity_load_multiple_by_properties('field_storage_config', ['deleted' => TRUE, 'include_deleted' => TRUE]); foreach ($field_storages as $field_storage) { if (!in_array($field_storage->getTypeProvider(), $providers)) { $storages_to_delete[$field_storage->id()] = $field_storage; diff --git a/core/modules/field/src/Entity/FieldConfig.php b/core/modules/field/src/Entity/FieldConfig.php index f5e8ab31fe5..af2fcca738e 100644 --- a/core/modules/field/src/Entity/FieldConfig.php +++ b/core/modules/field/src/Entity/FieldConfig.php @@ -193,7 +193,7 @@ class FieldConfig extends FieldConfigBase implements FieldConfigInterface { parent::preDelete($storage, $fields); // Keep the field definitions in the state storage so we can use them // later during field_purge_batch(). - $deleted_fields = $state->get('field.field.deleted') ?: array(); + $deleted_fields = $state->get('field.field.deleted') ?: []; foreach ($fields as $field) { if (!$field->deleted) { $config = $field->toArray(); @@ -228,7 +228,7 @@ class FieldConfig extends FieldConfigBase implements FieldConfigInterface { // Delete the associated field storages if they are not used anymore and are // not persistent. - $storages_to_delete = array(); + $storages_to_delete = []; foreach ($fields as $field) { $storage_definition = $field->getFieldStorageDefinition(); if (!$field->deleted && !$field->isUninstalling() && $storage_definition->isDeletable()) { @@ -306,7 +306,7 @@ class FieldConfig extends FieldConfigBase implements FieldConfigInterface { */ public function getDisplayOptions($display_context) { // Hide configurable fields by default. - return array('region' => 'hidden'); + return ['region' => 'hidden']; } /** diff --git a/core/modules/field/src/Entity/FieldStorageConfig.php b/core/modules/field/src/Entity/FieldStorageConfig.php index 00883d61aa5..a63e54f98be 100644 --- a/core/modules/field/src/Entity/FieldStorageConfig.php +++ b/core/modules/field/src/Entity/FieldStorageConfig.php @@ -370,7 +370,7 @@ class FieldStorageConfig extends ConfigEntityBase implements FieldStorageConfigI // See if any module forbids the update by throwing an exception. This // invokes hook_field_storage_config_update_forbid(). - $module_handler->invokeAll('field_storage_config_update_forbid', array($this, $this->original)); + $module_handler->invokeAll('field_storage_config_update_forbid', [$this, $this->original]); // Notify the entity manager. A listener can reject the definition // update as invalid by raising an exception, which stops execution before @@ -407,7 +407,7 @@ class FieldStorageConfig extends ConfigEntityBase implements FieldStorageConfigI // Keep the field definitions in the state storage so we can use them later // during field_purge_batch(). - $deleted_storages = $state->get('field.storage.deleted') ?: array(); + $deleted_storages = $state->get('field.storage.deleted') ?: []; foreach ($field_storages as $field_storage) { if (!$field_storage->deleted) { $config = $field_storage->toArray(); @@ -444,12 +444,12 @@ class FieldStorageConfig extends ConfigEntityBase implements FieldStorageConfigI $class = $this->getFieldItemClass(); $schema = $class::schema($this); // Fill in default values for optional entries. - $schema += array( - 'columns' => array(), - 'unique keys' => array(), - 'indexes' => array(), - 'foreign keys' => array(), - ); + $schema += [ + 'columns' => [], + 'unique keys' => [], + 'indexes' => [], + 'foreign keys' => [], + ]; // Merge custom indexes with those specified by the field type. Custom // indexes prevail. @@ -499,7 +499,7 @@ class FieldStorageConfig extends ConfigEntityBase implements FieldStorageConfigI return $map[$this->getTargetEntityTypeId()][$this->getName()]['bundles']; } } - return array(); + return []; } /** @@ -719,7 +719,7 @@ class FieldStorageConfig extends ConfigEntityBase implements FieldStorageConfigI * {@inheritdoc} */ public function getConstraints() { - return array(); + return []; } /** diff --git a/core/modules/field/src/FieldConfigStorage.php b/core/modules/field/src/FieldConfigStorage.php index 0870cd422fc..42d96346123 100644 --- a/core/modules/field/src/FieldConfigStorage.php +++ b/core/modules/field/src/FieldConfigStorage.php @@ -95,12 +95,12 @@ class FieldConfigStorage extends FieldConfigStorageBase { /** * {@inheritdoc} */ - public function loadByProperties(array $conditions = array()) { + public function loadByProperties(array $conditions = []) { // Include deleted fields if specified in the $conditions parameters. $include_deleted = isset($conditions['include_deleted']) ? $conditions['include_deleted'] : FALSE; unset($conditions['include_deleted']); - $fields = array(); + $fields = []; // Get fields stored in configuration. If we are explicitly looking for // deleted fields only, this can be skipped, because they will be @@ -109,7 +109,7 @@ class FieldConfigStorage extends FieldConfigStorageBase { if (isset($conditions['entity_type']) && isset($conditions['bundle']) && isset($conditions['field_name'])) { // Optimize for the most frequent case where we do have a specific ID. $id = $conditions['entity_type'] . '.' . $conditions['bundle'] . '.' . $conditions['field_name']; - $fields = $this->loadMultiple(array($id)); + $fields = $this->loadMultiple([$id]); } else { // No specific ID, we need to examine all existing fields. @@ -119,8 +119,8 @@ class FieldConfigStorage extends FieldConfigStorageBase { // Merge deleted fields (stored in state) if needed. if ($include_deleted || !empty($conditions['deleted'])) { - $deleted_fields = $this->state->get('field.field.deleted') ?: array(); - $deleted_storages = $this->state->get('field.storage.deleted') ?: array(); + $deleted_fields = $this->state->get('field.field.deleted') ?: []; + $deleted_storages = $this->state->get('field.storage.deleted') ?: []; foreach ($deleted_fields as $id => $config) { // If the field storage itself is deleted, inject it directly in the field. if (isset($deleted_storages[$config['field_storage_uuid']])) { @@ -131,7 +131,7 @@ class FieldConfigStorage extends FieldConfigStorageBase { } // Collect matching fields. - $matching_fields = array(); + $matching_fields = []; foreach ($fields as $field) { // Some conditions are checked against the field storage. $field_storage = $field->getFieldStorageDefinition(); diff --git a/core/modules/field/src/FieldStorageConfigStorage.php b/core/modules/field/src/FieldStorageConfigStorage.php index cce8412c05c..7a793f6829b 100644 --- a/core/modules/field/src/FieldStorageConfigStorage.php +++ b/core/modules/field/src/FieldStorageConfigStorage.php @@ -94,13 +94,13 @@ class FieldStorageConfigStorage extends ConfigEntityStorage { /** * {@inheritdoc} */ - public function loadByProperties(array $conditions = array()) { + public function loadByProperties(array $conditions = []) { // Include deleted fields if specified in the $conditions parameters. $include_deleted = isset($conditions['include_deleted']) ? $conditions['include_deleted'] : FALSE; unset($conditions['include_deleted']); /** @var \Drupal\field\FieldStorageConfigInterface[] $storages */ - $storages = array(); + $storages = []; // Get field storages living in configuration. If we are explicitly looking // for deleted storages only, this can be skipped, because they will be @@ -109,7 +109,7 @@ class FieldStorageConfigStorage extends ConfigEntityStorage { if (isset($conditions['entity_type']) && isset($conditions['field_name'])) { // Optimize for the most frequent case where we do have a specific ID. $id = $conditions['entity_type'] . $conditions['field_name']; - $storages = $this->loadMultiple(array($id)); + $storages = $this->loadMultiple([$id]); } else { // No specific ID, we need to examine all existing storages. @@ -119,14 +119,14 @@ class FieldStorageConfigStorage extends ConfigEntityStorage { // Merge deleted field storages (living in state) if needed. if ($include_deleted || !empty($conditions['deleted'])) { - $deleted_storages = $this->state->get('field.storage.deleted') ?: array(); + $deleted_storages = $this->state->get('field.storage.deleted') ?: []; foreach ($deleted_storages as $id => $config) { $storages[$id] = $this->create($config); } } // Collect matching fields. - $matches = array(); + $matches = []; foreach ($storages as $field) { foreach ($conditions as $key => $value) { // Extract the actual value against which the condition is checked. diff --git a/core/modules/field/src/Plugin/migrate/process/d6/FieldFormatterSettingsDefaults.php b/core/modules/field/src/Plugin/migrate/process/d6/FieldFormatterSettingsDefaults.php index 034ab0b9cdf..9a8e86abb73 100644 --- a/core/modules/field/src/Plugin/migrate/process/d6/FieldFormatterSettingsDefaults.php +++ b/core/modules/field/src/Plugin/migrate/process/d6/FieldFormatterSettingsDefaults.php @@ -26,7 +26,7 @@ class FieldFormatterSettingsDefaults extends ProcessPluginBase { if (isset($value[1])) { $module = $row->getSourceProperty('module'); if ($module === 'date') { - $value = array('format_type' => 'fallback'); + $value = ['format_type' => 'fallback']; } elseif ($module === 'number') { // We have to do the lookup here in the process plugin because for @@ -35,7 +35,7 @@ class FieldFormatterSettingsDefaults extends ProcessPluginBase { return $this->numberSettings($row->getDestinationProperty('options/type'), $value[1]); } else { - $value = array(); + $value = []; } } return $value; diff --git a/core/modules/field/src/Plugin/migrate/process/d6/FieldInstanceDefaults.php b/core/modules/field/src/Plugin/migrate/process/d6/FieldInstanceDefaults.php index 3ff0d8cb6f2..748eca28962 100644 --- a/core/modules/field/src/Plugin/migrate/process/d6/FieldInstanceDefaults.php +++ b/core/modules/field/src/Plugin/migrate/process/d6/FieldInstanceDefaults.php @@ -20,7 +20,7 @@ class FieldInstanceDefaults extends ProcessPluginBase { */ public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { list($widget_type, $widget_settings) = $value; - $default = array(); + $default = []; switch ($widget_type) { case 'text_textfield': @@ -58,7 +58,7 @@ class FieldInstanceDefaults extends ProcessPluginBase { break; } if (!empty($default)) { - $default = array($default); + $default = [$default]; } return $default; } diff --git a/core/modules/field/src/Plugin/migrate/process/d6/FieldInstanceSettings.php b/core/modules/field/src/Plugin/migrate/process/d6/FieldInstanceSettings.php index 080a4d7355a..82f25b5b2d0 100644 --- a/core/modules/field/src/Plugin/migrate/process/d6/FieldInstanceSettings.php +++ b/core/modules/field/src/Plugin/migrate/process/d6/FieldInstanceSettings.php @@ -20,7 +20,7 @@ class FieldInstanceSettings extends ProcessPluginBase { */ public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { list($widget_type, $widget_settings, $field_settings) = $value; - $settings = array(); + $settings = []; switch ($widget_type) { case 'number': $settings['min'] = $field_settings['min']; @@ -33,7 +33,7 @@ class FieldInstanceSettings extends ProcessPluginBase { // $settings['url'] = $widget_settings['default_value'][0]['url']; // D6 has optional, required, value and none. D8 only has disabled (0) // optional (1) and required (2). - $map = array('disabled' => 0, 'optional' => 1, 'required' => 2); + $map = ['disabled' => 0, 'optional' => 1, 'required' => 2]; $settings['title'] = $map[$field_settings['title']]; break; diff --git a/core/modules/field/src/Plugin/migrate/process/d6/FieldInstanceWidgetSettings.php b/core/modules/field/src/Plugin/migrate/process/d6/FieldInstanceWidgetSettings.php index 1c7ede64f06..62c982963f2 100644 --- a/core/modules/field/src/Plugin/migrate/process/d6/FieldInstanceWidgetSettings.php +++ b/core/modules/field/src/Plugin/migrate/process/d6/FieldInstanceWidgetSettings.php @@ -41,41 +41,41 @@ class FieldInstanceWidgetSettings extends ProcessPluginBase { $size = isset($widget_settings['size']) ? $widget_settings['size'] : 60; $rows = isset($widget_settings['rows']) ? $widget_settings['rows'] : 5; - $settings = array( - 'text_textfield' => array( + $settings = [ + 'text_textfield' => [ 'size' => $size, 'placeholder' => '', - ), - 'text_textarea' => array( + ], + 'text_textarea' => [ 'rows' => $rows, 'placeholder' => '', - ), - 'number' => array( + ], + 'number' => [ 'placeholder' => '', - ), - 'email_textfield' => array( + ], + 'email_textfield' => [ 'placeholder' => '', - ), - 'link' => array( + ], + 'link' => [ 'placeholder_url' => '', 'placeholder_title' => '', - ), - 'filefield_widget' => array( + ], + 'filefield_widget' => [ 'progress_indicator' => $progress, - ), - 'imagefield_widget' => array( + ], + 'imagefield_widget' => [ 'progress_indicator' => $progress, 'preview_image_style' => 'thumbnail', - ), - 'optionwidgets_onoff' => array( + ], + 'optionwidgets_onoff' => [ 'display_label' => FALSE, - ), - 'phone_textfield' => array( + ], + 'phone_textfield' => [ 'placeholder' => '', - ), - ); + ], + ]; - return isset($settings[$widget_type]) ? $settings[$widget_type] : array(); + return isset($settings[$widget_type]) ? $settings[$widget_type] : []; } } diff --git a/core/modules/field/src/Plugin/migrate/process/d6/FieldSettings.php b/core/modules/field/src/Plugin/migrate/process/d6/FieldSettings.php index 018afe6151c..1bb5b77ae5c 100644 --- a/core/modules/field/src/Plugin/migrate/process/d6/FieldSettings.php +++ b/core/modules/field/src/Plugin/migrate/process/d6/FieldSettings.php @@ -59,26 +59,26 @@ class FieldSettings extends ProcessPluginBase { } } - $settings = array( - 'text' => array( + $settings = [ + 'text' => [ 'max_length' => $max_length, - ), - 'datetime' => array('datetime_type' => 'datetime'), - 'list_string' => array( + ], + 'datetime' => ['datetime_type' => 'datetime'], + 'list_string' => [ 'allowed_values' => $allowed_values, - ), - 'list_integer' => array( + ], + 'list_integer' => [ 'allowed_values' => $allowed_values, - ), - 'list_float' => array( + ], + 'list_float' => [ 'allowed_values' => $allowed_values, - ), - 'boolean' => array( + ], + 'boolean' => [ 'allowed_values' => $allowed_values, - ), - ); + ], + ]; - return isset($settings[$field_type]) ? $settings[$field_type] : array(); + return isset($settings[$field_type]) ? $settings[$field_type] : []; } } diff --git a/core/modules/field/src/Plugin/migrate/process/d7/FieldInstanceDefaults.php b/core/modules/field/src/Plugin/migrate/process/d7/FieldInstanceDefaults.php index 08501abb94e..2a463811be8 100644 --- a/core/modules/field/src/Plugin/migrate/process/d7/FieldInstanceDefaults.php +++ b/core/modules/field/src/Plugin/migrate/process/d7/FieldInstanceDefaults.php @@ -20,7 +20,7 @@ class FieldInstanceDefaults extends ProcessPluginBase { list($default_value, $widget_settings) = $value; $widget_type = $widget_settings['type']; - $default = array(); + $default = []; foreach ($default_value as $item) { switch ($widget_type) { diff --git a/core/modules/field/src/Plugin/migrate/process/d7/FieldInstanceSettings.php b/core/modules/field/src/Plugin/migrate/process/d7/FieldInstanceSettings.php index d28007986fc..70a9498c41e 100644 --- a/core/modules/field/src/Plugin/migrate/process/d7/FieldInstanceSettings.php +++ b/core/modules/field/src/Plugin/migrate/process/d7/FieldInstanceSettings.php @@ -52,13 +52,13 @@ class FieldInstanceSettings extends ProcessPluginBase { switch ($widget_type) { case 'image_image': $settings = $instance_settings; - $settings['default_image'] = array( + $settings['default_image'] = [ 'alt' => '', 'title' => '', 'width' => NULL, 'height' => NULL, 'uuid' => '', - ); + ]; break; default: diff --git a/core/modules/field/src/Plugin/migrate/process/d7/FieldSettings.php b/core/modules/field/src/Plugin/migrate/process/d7/FieldSettings.php index bec448a2c27..dc629a44828 100644 --- a/core/modules/field/src/Plugin/migrate/process/d7/FieldSettings.php +++ b/core/modules/field/src/Plugin/migrate/process/d7/FieldSettings.php @@ -22,7 +22,7 @@ class FieldSettings extends ProcessPluginBase { switch ($row->getSourceProperty('type')) { case 'image': if (!is_array($value['default_image'])) { - $value['default_image'] = array('uuid' => ''); + $value['default_image'] = ['uuid' => '']; } break; diff --git a/core/modules/field/src/Plugin/migrate/source/d6/Field.php b/core/modules/field/src/Plugin/migrate/source/d6/Field.php index cb108d700c8..7c9e620dd80 100644 --- a/core/modules/field/src/Plugin/migrate/source/d6/Field.php +++ b/core/modules/field/src/Plugin/migrate/source/d6/Field.php @@ -20,7 +20,7 @@ class Field extends DrupalSqlBase { */ public function query() { $query = $this->select('content_node_field', 'cnf') - ->fields('cnf', array( + ->fields('cnf', [ 'field_name', 'type', 'global_settings', @@ -31,7 +31,7 @@ class Field extends DrupalSqlBase { 'db_columns', 'active', 'locked', - )) + ]) ->distinct(); // Only import fields which are actually being used. $query->innerJoin('content_node_field_instance', 'cnfi', 'cnfi.field_name = cnf.field_name'); @@ -43,7 +43,7 @@ class Field extends DrupalSqlBase { * {@inheritdoc} */ public function fields() { - return array( + return [ 'field_name' => $this->t('Field name'), 'type' => $this->t('Type (text, integer, ....)'), 'widget_type' => $this->t('An instance-specific widget type'), @@ -55,7 +55,7 @@ class Field extends DrupalSqlBase { 'db_columns' => $this->t('DB Columns'), 'active' => $this->t('Active'), 'locked' => $this->t('Locked'), - ); + ]; } /** @@ -96,10 +96,10 @@ class Field extends DrupalSqlBase { * {@inheritdoc} */ public function getIds() { - $ids['field_name'] = array( + $ids['field_name'] = [ 'type' => 'string', 'alias' => 'cnf', - ); + ]; return $ids; } diff --git a/core/modules/field/src/Plugin/migrate/source/d6/FieldInstance.php b/core/modules/field/src/Plugin/migrate/source/d6/FieldInstance.php index 5436df64a3c..dbea7a8e733 100644 --- a/core/modules/field/src/Plugin/migrate/source/d6/FieldInstance.php +++ b/core/modules/field/src/Plugin/migrate/source/d6/FieldInstance.php @@ -33,7 +33,7 @@ class FieldInstance extends DrupalSqlBase { * {@inheritdoc} */ public function fields() { - return array( + return [ 'field_name' => $this->t('The machine name of field.'), 'type_name' => $this->t('Content type where this field is in use.'), 'weight' => $this->t('Weight.'), @@ -45,7 +45,7 @@ class FieldInstance extends DrupalSqlBase { 'widget_module' => $this->t('Module that implements widget.'), 'widget_active' => $this->t('Status of widget'), 'module' => $this->t('The module that provides the field.'), - ); + ]; } /** @@ -66,15 +66,15 @@ class FieldInstance extends DrupalSqlBase { * {@inheritdoc} */ public function getIds() { - $ids = array( - 'field_name' => array( + $ids = [ + 'field_name' => [ 'type' => 'string', 'alias' => 'cnfi', - ), - 'type_name' => array( + ], + 'type_name' => [ 'type' => 'string', - ), - ); + ], + ]; return $ids; } diff --git a/core/modules/field/src/Plugin/migrate/source/d6/FieldInstancePerFormDisplay.php b/core/modules/field/src/Plugin/migrate/source/d6/FieldInstancePerFormDisplay.php index 44bad618e95..21baa9ee211 100644 --- a/core/modules/field/src/Plugin/migrate/source/d6/FieldInstancePerFormDisplay.php +++ b/core/modules/field/src/Plugin/migrate/source/d6/FieldInstancePerFormDisplay.php @@ -18,7 +18,7 @@ class FieldInstancePerFormDisplay extends DrupalSqlBase { * {@inheritdoc} */ protected function initializeIterator() { - $rows = array(); + $rows = []; $result = $this->prepareQuery()->execute(); while ($field_row = $result->fetchAssoc()) { $bundle = $field_row['type_name']; @@ -44,7 +44,7 @@ class FieldInstancePerFormDisplay extends DrupalSqlBase { */ public function query() { $query = $this->select('content_node_field_instance', 'cnfi') - ->fields('cnfi', array( + ->fields('cnfi', [ 'field_name', 'type_name', 'weight', @@ -55,11 +55,11 @@ class FieldInstancePerFormDisplay extends DrupalSqlBase { 'description', 'widget_module', 'widget_active', - )) - ->fields('cnf', array( + ]) + ->fields('cnf', [ 'type', 'module', - )); + ]); $query->join('content_node_field', 'cnf', 'cnfi.field_name = cnf.field_name'); $query->orderBy('cnfi.weight'); @@ -70,7 +70,7 @@ class FieldInstancePerFormDisplay extends DrupalSqlBase { * {@inheritdoc} */ public function fields() { - return array( + return [ 'field_name' => $this->t('The machine name of field.'), 'type_name' => $this->t('Content type where this field is used.'), 'weight' => $this->t('Weight.'), @@ -81,7 +81,7 @@ class FieldInstancePerFormDisplay extends DrupalSqlBase { 'description' => $this->t('A description of field.'), 'widget_module' => $this->t('Module that implements widget.'), 'widget_active' => $this->t('Status of widget'), - ); + ]; } /** diff --git a/core/modules/field/src/Plugin/migrate/source/d6/FieldInstancePerViewMode.php b/core/modules/field/src/Plugin/migrate/source/d6/FieldInstancePerViewMode.php index 2e1832e1b0a..43d27820db0 100644 --- a/core/modules/field/src/Plugin/migrate/source/d6/FieldInstancePerViewMode.php +++ b/core/modules/field/src/Plugin/migrate/source/d6/FieldInstancePerViewMode.php @@ -18,7 +18,7 @@ class FieldInstancePerViewMode extends ViewModeBase { * {@inheritdoc} */ protected function initializeIterator() { - $rows = array(); + $rows = []; $result = $this->prepareQuery()->execute(); while ($field_row = $result->fetchAssoc()) { // These are added to every view mode row. @@ -52,18 +52,18 @@ class FieldInstancePerViewMode extends ViewModeBase { */ public function query() { $query = $this->select('content_node_field_instance', 'cnfi') - ->fields('cnfi', array( + ->fields('cnfi', [ 'field_name', 'type_name', 'weight', 'label', 'display_settings', 'widget_settings', - )) - ->fields('cnf', array( + ]) + ->fields('cnf', [ 'type', 'module', - )); + ]); $query->join('content_node_field', 'cnf', 'cnfi.field_name = cnf.field_name'); $query->orderBy('cnfi.weight'); @@ -74,7 +74,7 @@ class FieldInstancePerViewMode extends ViewModeBase { * {@inheritdoc} */ public function fields() { - return array( + return [ 'field_name' => $this->t('The machine name of field.'), 'type_name' => $this->t('Content type where this field is used.'), 'weight' => $this->t('Weight.'), @@ -85,7 +85,7 @@ class FieldInstancePerViewMode extends ViewModeBase { 'description' => $this->t('A description of field.'), 'widget_module' => $this->t('Module that implements widget.'), 'widget_active' => $this->t('Status of widget'), - ); + ]; } /** diff --git a/core/modules/field/src/Plugin/migrate/source/d7/Field.php b/core/modules/field/src/Plugin/migrate/source/d7/Field.php index 2e8f74551ca..d9aef9162a6 100644 --- a/core/modules/field/src/Plugin/migrate/source/d7/Field.php +++ b/core/modules/field/src/Plugin/migrate/source/d7/Field.php @@ -21,7 +21,7 @@ class Field extends DrupalSqlBase { $query = $this->select('field_config', 'fc') ->distinct() ->fields('fc') - ->fields('fci', array('entity_type')) + ->fields('fci', ['entity_type']) ->condition('fc.active', 1) ->condition('fc.deleted', 0) ->condition('fc.storage_active', 1); @@ -34,7 +34,7 @@ class Field extends DrupalSqlBase { * {@inheritdoc} */ public function fields() { - return array( + return [ 'field_name' => $this->t('The name of this field.'), 'type' => $this->t('The type of this field.'), 'module' => $this->t('The module that implements the field type.'), @@ -42,7 +42,7 @@ class Field extends DrupalSqlBase { 'locked' => $this->t('Locked'), 'cardinality' => $this->t('Cardinality'), 'translatable' => $this->t('Translatable'), - ); + ]; } /** @@ -59,16 +59,16 @@ class Field extends DrupalSqlBase { * {@inheritdoc} */ public function getIds() { - return array( - 'field_name' => array( + return [ + 'field_name' => [ 'type' => 'string', 'alias' => 'fc', - ), - 'entity_type' => array( + ], + 'entity_type' => [ 'type' => 'string', 'alias' => 'fci', - ), - ); + ], + ]; } } diff --git a/core/modules/field/src/Plugin/migrate/source/d7/FieldInstance.php b/core/modules/field/src/Plugin/migrate/source/d7/FieldInstance.php index 3da02b92a0c..d06336e1538 100644 --- a/core/modules/field/src/Plugin/migrate/source/d7/FieldInstance.php +++ b/core/modules/field/src/Plugin/migrate/source/d7/FieldInstance.php @@ -25,7 +25,7 @@ class FieldInstance extends DrupalSqlBase { ->condition('fc.active', 1) ->condition('fc.deleted', 0) ->condition('fc.storage_active', 1) - ->fields('fc', array('type')); + ->fields('fc', ['type']); $query->innerJoin('field_config', 'fc', 'fci.field_id = fc.id'); $query->addField('fc', 'data', 'field_data'); @@ -46,7 +46,7 @@ class FieldInstance extends DrupalSqlBase { * {@inheritdoc} */ public function fields() { - return array( + return [ 'field_name' => $this->t('The machine name of field.'), 'entity_type' => $this->t('The entity type.'), 'bundle' => $this->t('The entity bundle.'), @@ -55,7 +55,7 @@ class FieldInstance extends DrupalSqlBase { 'widget_settings' => $this->t('Widget settings.'), 'display_settings' => $this->t('Display settings.'), 'field_settings' => $this->t('Field settings.'), - ); + ]; } /** @@ -68,7 +68,7 @@ class FieldInstance extends DrupalSqlBase { $row->setSourceProperty('description', $data['description']); $row->setSourceProperty('required', $data['required']); - $default_value = !empty($data['default_value']) ? $data['default_value'] : array(); + $default_value = !empty($data['default_value']) ? $data['default_value'] : []; if ($data['widget']['type'] == 'email_textfield' && $default_value) { $default_value[0]['value'] = $default_value[0]['email']; unset($default_value[0]['email']); @@ -112,20 +112,20 @@ class FieldInstance extends DrupalSqlBase { * {@inheritdoc} */ public function getIds() { - return array( - 'entity_type' => array( + return [ + 'entity_type' => [ 'type' => 'string', 'alias' => 'fci', - ), - 'bundle' => array( + ], + 'bundle' => [ 'type' => 'string', 'alias' => 'fci', - ), - 'field_name' => array( + ], + 'field_name' => [ 'type' => 'string', 'alias' => 'fci', - ), - ); + ], + ]; } } diff --git a/core/modules/field/src/Plugin/migrate/source/d7/FieldInstancePerFormDisplay.php b/core/modules/field/src/Plugin/migrate/source/d7/FieldInstancePerFormDisplay.php index 62de5d9d6b4..ac599ec0a51 100644 --- a/core/modules/field/src/Plugin/migrate/source/d7/FieldInstancePerFormDisplay.php +++ b/core/modules/field/src/Plugin/migrate/source/d7/FieldInstancePerFormDisplay.php @@ -19,16 +19,16 @@ class FieldInstancePerFormDisplay extends DrupalSqlBase { */ public function query() { $query = $this->select('field_config_instance', 'fci') - ->fields('fci', array( + ->fields('fci', [ 'field_name', 'bundle', 'data', 'entity_type' - )) - ->fields('fc', array( + ]) + ->fields('fc', [ 'type', 'module', - )); + ]); $query->join('field_config', 'fc', 'fci.field_id = fc.id'); return $query; } @@ -47,27 +47,27 @@ class FieldInstancePerFormDisplay extends DrupalSqlBase { * {@inheritdoc} */ public function fields() { - return array( + return [ 'field_name' => $this->t('The machine name of field.'), 'bundle' => $this->t('Content type where this field is used.'), 'data' => $this->t('Field configuration data.'), 'entity_type' => $this->t('The entity type.'), - ); + ]; } /** * {@inheritdoc} */ public function getIds() { - return array( - 'bundle' => array( + return [ + 'bundle' => [ 'type' => 'string', - ), - 'field_name' => array( + ], + 'field_name' => [ 'type' => 'string', 'alias' => 'fci', - ), - ); + ], + ]; } } diff --git a/core/modules/field/src/Plugin/migrate/source/d7/FieldInstancePerViewMode.php b/core/modules/field/src/Plugin/migrate/source/d7/FieldInstancePerViewMode.php index 72a845bcaf0..7339e764a88 100644 --- a/core/modules/field/src/Plugin/migrate/source/d7/FieldInstancePerViewMode.php +++ b/core/modules/field/src/Plugin/migrate/source/d7/FieldInstancePerViewMode.php @@ -18,7 +18,7 @@ class FieldInstancePerViewMode extends DrupalSqlBase { * {@inheritdoc} */ protected function initializeIterator() { - $rows = array(); + $rows = []; $result = $this->prepareQuery()->execute(); foreach ($result as $field_instance) { $data = unserialize($field_instance['data']); @@ -53,7 +53,7 @@ class FieldInstancePerViewMode extends DrupalSqlBase { * {@inheritdoc} */ public function fields() { - return array( + return [ 'entity_type' => $this->t('The entity type ID.'), 'bundle' => $this->t('The bundle ID.'), 'field_name' => $this->t('Machine name of the field.'), @@ -64,27 +64,27 @@ class FieldInstancePerViewMode extends DrupalSqlBase { 'settings' => $this->t('Array of formatter-specific settings.'), 'module' => $this->t('The module providing the formatter.'), 'weight' => $this->t('Display weight of the field.'), - ); + ]; } /** * {@inheritdoc} */ public function getIds() { - return array( - 'entity_type' => array( + return [ + 'entity_type' => [ 'type' => 'string', - ), - 'bundle' => array( + ], + 'bundle' => [ 'type' => 'string', - ), - 'view_mode' => array( + ], + 'view_mode' => [ 'type' => 'string', - ), - 'field_name' => array( + ], + 'field_name' => [ 'type' => 'string', - ), - ); + ], + ]; } /** diff --git a/core/modules/field/src/Tests/Boolean/BooleanFieldTest.php b/core/modules/field/src/Tests/Boolean/BooleanFieldTest.php index 5fa491b20a9..17292e09d8d 100644 --- a/core/modules/field/src/Tests/Boolean/BooleanFieldTest.php +++ b/core/modules/field/src/Tests/Boolean/BooleanFieldTest.php @@ -47,12 +47,12 @@ class BooleanFieldTest extends WebTestBase { protected function setUp() { parent::setUp(); - $this->drupalLogin($this->drupalCreateUser(array( + $this->drupalLogin($this->drupalCreateUser([ 'view test entity', 'administer entity_test content', 'administer entity_test form display', 'administer entity_test fields', - ))); + ])); } /** @@ -65,36 +65,36 @@ class BooleanFieldTest extends WebTestBase { // Create a field with settings to validate. $field_name = Unicode::strtolower($this->randomMachineName()); - $this->fieldStorage = FieldStorageConfig::create(array( + $this->fieldStorage = FieldStorageConfig::create([ 'field_name' => $field_name, 'entity_type' => 'entity_test', 'type' => 'boolean', - )); + ]); $this->fieldStorage->save(); - $this->field = FieldConfig::create(array( + $this->field = FieldConfig::create([ 'field_name' => $field_name, 'entity_type' => 'entity_test', 'bundle' => 'entity_test', 'label' => $label, 'required' => TRUE, - 'settings' => array( + 'settings' => [ 'on_label' => $on, 'off_label' => $off, - ), - )); + ], + ]); $this->field->save(); // Create a form display for the default form mode. entity_get_form_display('entity_test', 'entity_test', 'default') - ->setComponent($field_name, array( + ->setComponent($field_name, [ 'type' => 'boolean_checkbox', - )) + ]) ->save(); // Create a display for the full view mode. entity_get_display('entity_test', 'entity_test', 'full') - ->setComponent($field_name, array( + ->setComponent($field_name, [ 'type' => 'boolean', - )) + ]) ->save(); // Display creation form. @@ -104,13 +104,13 @@ class BooleanFieldTest extends WebTestBase { $this->assertNoRaw($on, 'Does not use the "On" label.'); // Submit and ensure it is accepted. - $edit = array( + $edit = [ "{$field_name}[value]" => 1, - ); + ]; $this->drupalPostForm(NULL, $edit, t('Save')); preg_match('|entity_test/manage/(\d+)|', $this->url, $match); $id = $match[1]; - $this->assertText(t('entity_test @id has been created.', array('@id' => $id))); + $this->assertText(t('entity_test @id has been created.', ['@id' => $id])); // Verify that boolean value is displayed. $entity = EntityTest::load($id); @@ -121,12 +121,12 @@ class BooleanFieldTest extends WebTestBase { // Test with "On" label option. entity_get_form_display('entity_test', 'entity_test', 'default') - ->setComponent($field_name, array( + ->setComponent($field_name, [ 'type' => 'boolean_checkbox', - 'settings' => array( + 'settings' => [ 'display_label' => FALSE, - ) - )) + ] + ]) ->save(); $this->drupalGet('entity_test/add'); @@ -136,9 +136,9 @@ class BooleanFieldTest extends WebTestBase { // Test if we can change the on label. $on = $this->randomMachineName(); - $edit = array( + $edit = [ 'settings[on_label]' => $on, - ); + ]; $this->drupalPostForm('entity_test/structure/entity_test/fields/entity_test.entity_test.' . $field_name, $edit, t('Save settings')); // Check if we see the updated labels in the creation form. $this->drupalGet('entity_test/add'); @@ -150,7 +150,7 @@ class BooleanFieldTest extends WebTestBase { $this->drupalGet($fieldEditUrl); // Click on the widget settings button to open the widget settings form. - $this->drupalPostAjaxForm(NULL, array(), $field_name . "_settings_edit"); + $this->drupalPostAjaxForm(NULL, [], $field_name . "_settings_edit"); $this->assertText( 'Use field label instead of the "On label" as label', @@ -158,7 +158,7 @@ class BooleanFieldTest extends WebTestBase { ); // Enable setting. - $edit = array('fields[' . $field_name . '][settings_edit_form][settings][display_label]' => 1); + $edit = ['fields[' . $field_name . '][settings_edit_form][settings][display_label]' => 1]; $this->drupalPostAjaxForm(NULL, $edit, $field_name . "_plugin_settings_update"); $this->drupalPostForm(NULL, NULL, 'Save'); @@ -167,7 +167,7 @@ class BooleanFieldTest extends WebTestBase { $this->drupalGet($fieldEditUrl); $this->assertText('Use field label: Yes', 'Checking the display settings checkbox updated the value.'); - $this->drupalPostAjaxForm(NULL, array(), $field_name . "_settings_edit"); + $this->drupalPostAjaxForm(NULL, [], $field_name . "_settings_edit"); $this->assertText( 'Use field label instead of the "On label" as label', t('Display setting checkbox is available') diff --git a/core/modules/field/src/Tests/Boolean/BooleanFormatterSettingsTest.php b/core/modules/field/src/Tests/Boolean/BooleanFormatterSettingsTest.php index 0d0c475f30b..f45442060bc 100644 --- a/core/modules/field/src/Tests/Boolean/BooleanFormatterSettingsTest.php +++ b/core/modules/field/src/Tests/Boolean/BooleanFormatterSettingsTest.php @@ -44,10 +44,10 @@ class BooleanFormatterSettingsTest extends WebTestBase { // Create a content type. Use Node because it has Field UI pages that work. $type_name = Unicode::strtolower($this->randomMachineName(8)) . '_test'; - $type = $this->drupalCreateContentType(array('name' => $type_name, 'type' => $type_name)); + $type = $this->drupalCreateContentType(['name' => $type_name, 'type' => $type_name]); $this->bundle = $type->id(); - $admin_user = $this->drupalCreateUser(array('access content', 'administer content types', 'administer node fields', 'administer node display', 'bypass node access', 'administer nodes')); + $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)); @@ -81,14 +81,14 @@ class BooleanFormatterSettingsTest extends WebTestBase { // 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 = array( + $options = [ 'Yes / No', 'True / False', 'On / Off', 'Enabled / Disabled', '1 / 0', 'Custom', - ); + ]; // Define what the "default" option should look like, depending on the // field settings. @@ -96,29 +96,29 @@ class BooleanFormatterSettingsTest extends WebTestBase { // For several different values of the field settings, test that the // options, including default, are shown correctly. - $settings = array( - array('Yes', 'No'), - array('On', 'Off'), - array('TRUE', 'FALSE'), - ); + $settings = [ + ['Yes', 'No'], + ['On', 'Off'], + ['TRUE', 'FALSE'], + ]; 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, array( + $this->drupalPostForm(NULL, [ 'settings[on_label]' => $values[0], 'settings[off_label]' => $values[1], - ), 'Save settings'); + ], 'Save settings'); // Open the Manage Display page and trigger the field settings form. $this->drupalGet('admin/structure/types/manage/' . $this->bundle . '/display'); - $this->drupalPostAjaxForm(NULL, array(), $this->fieldName . '_settings_edit'); + $this->drupalPostAjaxForm(NULL, [], $this->fieldName . '_settings_edit'); // Test that the settings options are present in the correct format. foreach ($options as $string) { $this->assertText($string); } - $this->assertText(SafeMarkup::format($default, array('@on' => $values[0], '@off' => $values[1]))); + $this->assertText(SafeMarkup::format($default, ['@on' => $values[0], '@off' => $values[1]])); } foreach ($settings as $values) { diff --git a/core/modules/field/src/Tests/Email/EmailFieldTest.php b/core/modules/field/src/Tests/Email/EmailFieldTest.php index 7c22861e816..779870ced3d 100644 --- a/core/modules/field/src/Tests/Email/EmailFieldTest.php +++ b/core/modules/field/src/Tests/Email/EmailFieldTest.php @@ -20,7 +20,7 @@ class EmailFieldTest extends WebTestBase { * * @var array */ - public static $modules = array('node', 'entity_test', 'field_ui'); + public static $modules = ['node', 'entity_test', 'field_ui']; /** * A field storage to use in this test class. @@ -39,11 +39,11 @@ class EmailFieldTest extends WebTestBase { protected function setUp() { parent::setUp(); - $this->drupalLogin($this->drupalCreateUser(array( + $this->drupalLogin($this->drupalCreateUser([ 'view test entity', 'administer entity_test content', 'administer content types', - ))); + ])); } /** @@ -52,11 +52,11 @@ class EmailFieldTest extends WebTestBase { function testEmailField() { // Create a field with settings to validate. $field_name = Unicode::strtolower($this->randomMachineName()); - $this->fieldStorage = FieldStorageConfig::create(array( + $this->fieldStorage = FieldStorageConfig::create([ 'field_name' => $field_name, 'entity_type' => 'entity_test', 'type' => 'email', - )); + ]); $this->fieldStorage->save(); $this->field = FieldConfig::create([ 'field_storage' => $this->fieldStorage, @@ -66,18 +66,18 @@ class EmailFieldTest extends WebTestBase { // Create a form display for the default form mode. entity_get_form_display('entity_test', 'entity_test', 'default') - ->setComponent($field_name, array( + ->setComponent($field_name, [ 'type' => 'email_default', - 'settings' => array( + 'settings' => [ 'placeholder' => 'example@example.com', - ), - )) + ], + ]) ->save(); // Create a display for the full view mode. entity_get_display('entity_test', 'entity_test', 'full') - ->setComponent($field_name, array( + ->setComponent($field_name, [ 'type' => 'email_mailto', - )) + ]) ->save(); // Display creation form. @@ -87,13 +87,13 @@ class EmailFieldTest extends WebTestBase { // Submit a valid email address and ensure it is accepted. $value = 'test@example.com'; - $edit = array( + $edit = [ "{$field_name}[0][value]" => $value, - ); + ]; $this->drupalPostForm(NULL, $edit, t('Save')); preg_match('|entity_test/manage/(\d+)|', $this->url, $match); $id = $match[1]; - $this->assertText(t('entity_test @id has been created.', array('@id' => $id))); + $this->assertText(t('entity_test @id has been created.', ['@id' => $id])); $this->assertRaw($value); // Verify that a mailto link is displayed. diff --git a/core/modules/field/src/Tests/EntityReference/EntityReferenceAdminTest.php b/core/modules/field/src/Tests/EntityReference/EntityReferenceAdminTest.php index 3803029d773..fa68cb61509 100644 --- a/core/modules/field/src/Tests/EntityReference/EntityReferenceAdminTest.php +++ b/core/modules/field/src/Tests/EntityReference/EntityReferenceAdminTest.php @@ -46,18 +46,18 @@ class EntityReferenceAdminTest extends WebTestBase { // Create a content type, with underscores. $type_name = strtolower($this->randomMachineName(8)) . '_test'; - $type = $this->drupalCreateContentType(array('name' => $type_name, 'type' => $type_name)); + $type = $this->drupalCreateContentType(['name' => $type_name, 'type' => $type_name]); $this->type = $type->id(); // Create test user. - $admin_user = $this->drupalCreateUser(array( + $admin_user = $this->drupalCreateUser([ 'access content', 'administer node fields', 'administer node display', 'administer views', 'create ' . $type_name . ' content', 'edit own ' . $type_name . ' content', - )); + ]); $this->drupalLogin($admin_user); } @@ -74,11 +74,11 @@ class EntityReferenceAdminTest extends WebTestBase { $this->assertOption('edit-new-storage-type', 'field_ui:entity_reference:node'); $this->assertOption('edit-new-storage-type', 'field_ui:entity_reference:user'); - $this->drupalPostForm(NULL, array( + $this->drupalPostForm(NULL, [ 'label' => 'Test label', 'field_name' => 'test', 'new_storage_type' => 'entity_reference', - ), t('Save and continue')); + ], t('Save and continue')); // Node should be selected by default. $this->assertFieldByName('settings[target_type]', 'node'); @@ -87,7 +87,7 @@ class EntityReferenceAdminTest extends WebTestBase { $this->assertFieldSelectOptions('settings[target_type]', array_keys(\Drupal::entityManager()->getDefinitions())); // Second step: 'Field settings' form. - $this->drupalPostForm(NULL, array(), t('Save field settings')); + $this->drupalPostForm(NULL, [], t('Save field settings')); // The base handler should be selected by default. $this->assertFieldByName('settings[handler]', 'default:node'); @@ -106,7 +106,7 @@ class EntityReferenceAdminTest extends WebTestBase { $this->assertFieldByName('settings[handler_settings][sort][field]', '_none'); $this->assertNoFieldByName('settings[handler_settings][sort][direction]'); // Option 1: sort by field. - $this->drupalPostAjaxForm(NULL, array('settings[handler_settings][sort][field]' => 'nid'), 'settings[handler_settings][sort][field]'); + $this->drupalPostAjaxForm(NULL, ['settings[handler_settings][sort][field]' => 'nid'], 'settings[handler_settings][sort][field]'); $this->assertFieldByName('settings[handler_settings][sort][direction]', 'ASC'); // Test that a non-translatable base field is a sort option. @@ -117,14 +117,14 @@ class EntityReferenceAdminTest extends WebTestBase { $this->assertFieldByXPath("//select[@name='settings[handler_settings][sort][field]']/option[@value='body.value']"); // Set back to no sort. - $this->drupalPostAjaxForm(NULL, array('settings[handler_settings][sort][field]' => '_none'), 'settings[handler_settings][sort][field]'); + $this->drupalPostAjaxForm(NULL, ['settings[handler_settings][sort][field]' => '_none'], 'settings[handler_settings][sort][field]'); $this->assertNoFieldByName('settings[handler_settings][sort][direction]'); // Third step: confirm. - $this->drupalPostForm(NULL, array( + $this->drupalPostForm(NULL, [ 'required' => '1', 'settings[handler_settings][target_bundles][' . key($bundles) . ']' => key($bundles), - ), t('Save settings')); + ], t('Save settings')); // Check that the field appears in the overview form. $this->assertFieldByXPath('//table[@id="field-overview"]//tr[@id="field-test"]/td[1]', 'Test label', 'Field was created and appears in the overview page.'); @@ -133,14 +133,14 @@ class EntityReferenceAdminTest extends WebTestBase { // field is required. // The first 'Edit' link is for the Body field. $this->clickLink(t('Edit'), 1); - $this->drupalPostForm(NULL, array(), t('Save settings')); + $this->drupalPostForm(NULL, [], t('Save settings')); // Switch the target type to 'taxonomy_term' and check that the settings // specific to its selection handler are displayed. $field_name = 'node.' . $this->type . '.field_test'; - $edit = array( + $edit = [ 'settings[target_type]' => 'taxonomy_term', - ); + ]; $this->drupalPostForm($bundle_path . '/fields/' . $field_name . '/storage', $edit, t('Save field settings')); $this->drupalGet($bundle_path . '/fields/' . $field_name); $this->assertFieldByName('settings[handler_settings][auto_create]'); @@ -148,63 +148,63 @@ class EntityReferenceAdminTest extends WebTestBase { // Switch the target type to 'user' and check that the settings specific to // its selection handler are displayed. $field_name = 'node.' . $this->type . '.field_test'; - $edit = array( + $edit = [ 'settings[target_type]' => 'user', - ); + ]; $this->drupalPostForm($bundle_path . '/fields/' . $field_name . '/storage', $edit, t('Save field settings')); $this->drupalGet($bundle_path . '/fields/' . $field_name); $this->assertFieldByName('settings[handler_settings][filter][type]', '_none'); // Switch the target type to 'node'. $field_name = 'node.' . $this->type . '.field_test'; - $edit = array( + $edit = [ 'settings[target_type]' => 'node', - ); + ]; $this->drupalPostForm($bundle_path . '/fields/' . $field_name . '/storage', $edit, t('Save field settings')); // Try to select the views handler. - $edit = array( + $edit = [ 'settings[handler]' => 'views', - ); + ]; $this->drupalPostAjaxForm($bundle_path . '/fields/' . $field_name, $edit, 'settings[handler]'); - $this->assertRaw(t('No eligible views were found. <a href=":create">Create a view</a> with an <em>Entity Reference</em> display, or add such a display to an <a href=":existing">existing view</a>.', array( + $this->assertRaw(t('No eligible views were found. <a href=":create">Create a view</a> with an <em>Entity Reference</em> display, or add such a display to an <a href=":existing">existing view</a>.', [ ':create' => \Drupal::url('views_ui.add'), ':existing' => \Drupal::url('entity.view.collection'), - ))); + ])); $this->drupalPostForm(NULL, $edit, t('Save settings')); // If no eligible view is available we should see a message. $this->assertText('The views entity selection mode requires a view.'); // Enable the entity_reference_test module which creates an eligible view. - $this->container->get('module_installer')->install(array('entity_reference_test')); + $this->container->get('module_installer')->install(['entity_reference_test']); $this->resetAll(); $this->drupalGet($bundle_path . '/fields/' . $field_name); $this->drupalPostAjaxForm($bundle_path . '/fields/' . $field_name, $edit, 'settings[handler]'); - $edit = array( + $edit = [ 'settings[handler_settings][view][view_and_display]' => 'test_entity_reference:entity_reference_1', - ); + ]; $this->drupalPostForm(NULL, $edit, t('Save settings')); $this->assertResponse(200); // Switch the target type to 'entity_test'. - $edit = array( + $edit = [ 'settings[target_type]' => 'entity_test', - ); + ]; $this->drupalPostForm($bundle_path . '/fields/' . $field_name . '/storage', $edit, t('Save field settings')); $this->drupalGet($bundle_path . '/fields/' . $field_name); - $edit = array( + $edit = [ 'settings[handler]' => 'views', - ); + ]; $this->drupalPostAjaxForm($bundle_path . '/fields/' . $field_name, $edit, 'settings[handler]'); - $edit = array( + $edit = [ 'required' => FALSE, 'settings[handler_settings][view][view_and_display]' => 'test_entity_reference_entity_test:entity_reference_1', - ); + ]; $this->drupalPostForm(NULL, $edit, t('Save settings')); $this->assertResponse(200); // Create a new view and display it as a entity reference. - $edit = array( + $edit = [ 'id' => 'node_test_view', 'label' => 'Node Test View', 'show[wizard_key]' => 'node', @@ -214,13 +214,13 @@ class EntityReferenceAdminTest extends WebTestBase { 'page[path]' => 'test/node/view', 'page[style][style_plugin]' => 'default', 'page[style][row_plugin]' => 'fields', - ); + ]; $this->drupalPostForm('admin/structure/views/add', $edit, t('Save and edit')); - $this->drupalPostForm(NULL, array(), t('Duplicate as Entity Reference')); + $this->drupalPostForm(NULL, [], t('Duplicate as Entity Reference')); $this->clickLink(t('Settings')); - $edit = array( + $edit = [ 'style_options[search_fields][title]' => 'title', - ); + ]; $this->drupalPostForm(NULL, $edit, t('Apply')); // Set sort to NID ascending. @@ -230,33 +230,33 @@ class EntityReferenceAdminTest extends WebTestBase { $this->drupalPostForm('admin/structure/views/nojs/add-handler/node_test_view/entity_reference_1/sort', $edit, t('Add and configure sort criteria')); $this->drupalPostForm(NULL, NULL, t('Apply')); - $this->drupalPostForm('admin/structure/views/view/node_test_view/edit/entity_reference_1', array(), t('Save')); + $this->drupalPostForm('admin/structure/views/view/node_test_view/edit/entity_reference_1', [], t('Save')); $this->clickLink(t('Settings')); // Create a test entity reference field. $field_name = 'test_entity_ref_field'; - $edit = array( + $edit = [ 'new_storage_type' => 'field_ui:entity_reference:node', 'label' => 'Test Entity Reference Field', 'field_name' => $field_name, - ); + ]; $this->drupalPostForm($bundle_path . '/fields/add-field', $edit, t('Save and continue')); // Set to unlimited. - $edit = array( + $edit = [ 'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED, - ); + ]; $this->drupalPostForm(NULL, $edit, t('Save field settings')); // Add the view to the test field. - $edit = array( + $edit = [ 'settings[handler]' => 'views', - ); + ]; $this->drupalPostAjaxForm(NULL, $edit, 'settings[handler]'); - $edit = array( + $edit = [ 'required' => FALSE, 'settings[handler_settings][view][view_and_display]' => 'node_test_view:entity_reference_1', - ); + ]; $this->drupalPostForm(NULL, $edit, t('Save settings')); // Create nodes. @@ -275,34 +275,34 @@ class EntityReferenceAdminTest extends WebTestBase { $this->drupalGet('node/add/' . $this->type); $result = $this->xpath('//input[@name="field_test_entity_ref_field[0][target_id]" and contains(@data-autocomplete-path, "/entity_reference_autocomplete/node/views/")]'); $target_url = $this->getAbsoluteUrl($result[0]['data-autocomplete-path']); - $this->drupalGet($target_url, array('query' => array('q' => 'Foo'))); + $this->drupalGet($target_url, ['query' => ['q' => 'Foo']]); $this->assertRaw($node1->getTitle() . ' (' . $node1->id() . ')'); $this->assertRaw($node2->getTitle() . ' (' . $node2->id() . ')'); // Try to add a new node, fill the entity reference field and submit the // form. $this->drupalPostForm('node/add/' . $this->type, [], t('Add another item')); - $edit = array( + $edit = [ 'title[0][value]' => 'Example', 'field_test_entity_ref_field[0][target_id]' => 'Foo Node (' . $node1->id() . ')', 'field_test_entity_ref_field[1][target_id]' => 'Foo Node (' . $node2->id() . ')', - ); + ]; $this->drupalPostForm(NULL, $edit, t('Save')); $this->assertResponse(200); - $edit = array( + $edit = [ 'title[0][value]' => 'Example', 'field_test_entity_ref_field[0][target_id]' => 'Test' - ); + ]; $this->drupalPostForm('node/add/' . $this->type, $edit, t('Save')); // Assert that entity reference autocomplete field is validated. $this->assertText(t('There are no entities matching "@entity"', ['@entity' => 'Test'])); - $edit = array( + $edit = [ 'title[0][value]' => 'Test', 'field_test_entity_ref_field[0][target_id]' => $node1->getTitle() - ); + ]; $this->drupalPostForm('node/add/' . $this->type, $edit, t('Save')); // Assert the results multiple times to avoid sorting problem of nodes with @@ -312,15 +312,15 @@ class EntityReferenceAdminTest extends WebTestBase { $this->assertText(t("@node2", ['@node2' => $node2->getTitle() . ' (' . $node2->id() . ')'])); $this->assertText(t('Specify the one you want by appending the id in parentheses, like "@example".', ['@example' => $node2->getTitle() . ' (' . $node2->id() . ')'])); - $edit = array( + $edit = [ 'title[0][value]' => 'Test', '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()); // Tests adding default values to autocomplete widgets. - Vocabulary::create(array('vid' => 'tags', 'name' => 'tags'))->save(); + Vocabulary::create(['vid' => 'tags', 'name' => 'tags'])->save(); $taxonomy_term_field_name = $this->createEntityReferenceField('taxonomy_term', ['tags']); $field_path = 'node.' . $this->type . '.field_' . $taxonomy_term_field_name; $this->drupalGet($bundle_path . '/fields/' . $field_path . '/storage'); @@ -351,7 +351,7 @@ class EntityReferenceAdminTest extends WebTestBase { */ public function testAvailableFormatters() { // Create a new vocabulary. - Vocabulary::create(array('vid' => 'tags', 'name' => 'tags'))->save(); + Vocabulary::create(['vid' => 'tags', 'name' => 'tags'])->save(); // Create entity reference field with taxonomy term as a target. $taxonomy_term_field_name = $this->createEntityReferenceField('taxonomy_term', ['tags']); @@ -370,38 +370,38 @@ class EntityReferenceAdminTest extends WebTestBase { // Check for Taxonomy Term select box values. // Test if Taxonomy Term Entity Reference Field has the correct formatters. - $this->assertFieldSelectOptions('fields[field_' . $taxonomy_term_field_name . '][type]', array( + $this->assertFieldSelectOptions('fields[field_' . $taxonomy_term_field_name . '][type]', [ 'entity_reference_label', 'entity_reference_entity_id', 'entity_reference_rss_category', 'entity_reference_entity_view', - )); + ]); // Test if User Reference Field has the correct formatters. // Author should be available for this field. // RSS Category should not be available for this field. - $this->assertFieldSelectOptions('fields[field_' . $user_field_name . '][type]', array( + $this->assertFieldSelectOptions('fields[field_' . $user_field_name . '][type]', [ 'author', 'entity_reference_entity_id', 'entity_reference_entity_view', 'entity_reference_label', - )); + ]); // Test if Node Entity Reference Field has the correct formatters. // RSS Category should not be available for this field. - $this->assertFieldSelectOptions('fields[field_' . $node_field_name . '][type]', array( + $this->assertFieldSelectOptions('fields[field_' . $node_field_name . '][type]', [ 'entity_reference_label', 'entity_reference_entity_id', 'entity_reference_entity_view', - )); + ]); // Test if Date Format Reference Field has the correct formatters. // RSS Category & Entity View should not be available for this field. // This could be any field without a ViewBuilder. - $this->assertFieldSelectOptions('fields[field_' . $date_format_field_name . '][type]', array( + $this->assertFieldSelectOptions('fields[field_' . $date_format_field_name . '][type]', [ 'entity_reference_label', 'entity_reference_entity_id', - )); + ]); } /** @@ -483,7 +483,7 @@ class EntityReferenceAdminTest extends WebTestBase { // Generate a random field name, must be only lowercase characters. $field_name = strtolower($this->randomMachineName()); - $storage_edit = $field_edit = array(); + $storage_edit = $field_edit = []; $storage_edit['settings[target_type]'] = $target_type; foreach ($bundles as $bundle) { $field_edit['settings[handler_settings][target_bundles][' . $bundle . ']'] = TRUE; @@ -507,7 +507,7 @@ class EntityReferenceAdminTest extends WebTestBase { * TRUE if the assertion succeeded, FALSE otherwise. */ protected function assertFieldSelectOptions($name, array $expected_options) { - $xpath = $this->buildXPathQuery('//select[@name=:name]', array(':name' => $name)); + $xpath = $this->buildXPathQuery('//select[@name=:name]', [':name' => $name]); $fields = $this->xpath($xpath); if ($fields) { $field = $fields[0]; @@ -533,7 +533,7 @@ class EntityReferenceAdminTest extends WebTestBase { * An array of option values as strings. */ protected function getAllOptionsList(\SimpleXMLElement $element) { - $options = array(); + $options = []; // Add all options items. foreach ($element->option as $option) { $options[] = (string) $option['value']; diff --git a/core/modules/field/src/Tests/EntityReference/EntityReferenceFileUploadTest.php b/core/modules/field/src/Tests/EntityReference/EntityReferenceFileUploadTest.php index 6aef0f82835..19575840f29 100644 --- a/core/modules/field/src/Tests/EntityReference/EntityReferenceFileUploadTest.php +++ b/core/modules/field/src/Tests/EntityReference/EntityReferenceFileUploadTest.php @@ -14,7 +14,7 @@ use Drupal\field\Entity\FieldStorageConfig; */ class EntityReferenceFileUploadTest extends WebTestBase { - public static $modules = array('entity_reference', 'node', 'file'); + public static $modules = ['entity_reference', 'node', 'file']; /** * The name of a content type that will reference $referencedType. @@ -46,19 +46,19 @@ class EntityReferenceFileUploadTest extends WebTestBase { $referenced = $this->drupalCreateContentType(); $this->referencedType = $referenced->id(); - $this->nodeId = $this->drupalCreateNode(array('type' => $referenced->id()))->id(); + $this->nodeId = $this->drupalCreateNode(['type' => $referenced->id()])->id(); - FieldStorageConfig::create(array( + FieldStorageConfig::create([ 'field_name' => 'test_field', 'entity_type' => 'node', 'translatable' => FALSE, - 'entity_types' => array(), - 'settings' => array( + 'entity_types' => [], + 'settings' => [ 'target_type' => 'node', - ), + ], 'type' => 'entity_reference', 'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED, - ))->save(); + ])->save(); FieldConfig::create([ 'label' => 'Entity reference field', @@ -66,25 +66,25 @@ class EntityReferenceFileUploadTest extends WebTestBase { 'entity_type' => 'node', 'required' => TRUE, 'bundle' => $referencing->id(), - 'settings' => array( + 'settings' => [ 'handler' => 'default', - 'handler_settings' => array( + 'handler_settings' => [ // Reference a single vocabulary. - 'target_bundles' => array( + 'target_bundles' => [ $referenced->id(), - ), - ), - ), + ], + ], + ], ])->save(); // Create a file field. $file_field_name = 'file_field'; - $field_storage = FieldStorageConfig::create(array( + $field_storage = FieldStorageConfig::create([ 'field_name' => $file_field_name, 'entity_type' => 'node', 'type' => 'file' - )); + ]); $field_storage->save(); FieldConfig::create([ 'entity_type' => 'node', @@ -98,12 +98,12 @@ class EntityReferenceFileUploadTest extends WebTestBase { ->setComponent($file_field_name) ->save(); entity_get_form_display('node', $referencing->id(), 'default') - ->setComponent('test_field', array( + ->setComponent('test_field', [ 'type' => 'entity_reference_autocomplete', - )) - ->setComponent($file_field_name, array( + ]) + ->setComponent($file_field_name, [ 'type' => 'file_generic', - )) + ]) ->save(); } @@ -111,17 +111,17 @@ class EntityReferenceFileUploadTest extends WebTestBase { * Tests that the autocomplete input element does not cause ajax fatal. */ public function testFileUpload() { - $user1 = $this->drupalCreateUser(array('access content', "create $this->referencingType content")); + $user1 = $this->drupalCreateUser(['access content', "create $this->referencingType content"]); $this->drupalLogin($user1); $test_file = current($this->drupalGetTestFiles('text')); $edit['files[file_field_0]'] = drupal_realpath($test_file->uri); $this->drupalPostForm('node/add/' . $this->referencingType, $edit, 'Upload'); $this->assertResponse(200); - $edit = array( + $edit = [ 'title[0][value]' => $this->randomMachineName(), 'test_field[0][target_id]' => $this->nodeId, - ); + ]; $this->drupalPostForm(NULL, $edit, 'Save'); $this->assertResponse(200); } diff --git a/core/modules/field/src/Tests/EntityReference/EntityReferenceTestTrait.php b/core/modules/field/src/Tests/EntityReference/EntityReferenceTestTrait.php index 13e28da70fa..568cd4d5fcb 100644 --- a/core/modules/field/src/Tests/EntityReference/EntityReferenceTestTrait.php +++ b/core/modules/field/src/Tests/EntityReference/EntityReferenceTestTrait.php @@ -34,30 +34,30 @@ trait EntityReferenceTestTrait { * * @see \Drupal\Core\Entity\Plugin\EntityReferenceSelection\SelectionBase::buildConfigurationForm() */ - protected function createEntityReferenceField($entity_type, $bundle, $field_name, $field_label, $target_entity_type, $selection_handler = 'default', $selection_handler_settings = array(), $cardinality = 1) { + protected function createEntityReferenceField($entity_type, $bundle, $field_name, $field_label, $target_entity_type, $selection_handler = 'default', $selection_handler_settings = [], $cardinality = 1) { // Look for or add the specified field to the requested entity bundle. if (!FieldStorageConfig::loadByName($entity_type, $field_name)) { - FieldStorageConfig::create(array( + FieldStorageConfig::create([ 'field_name' => $field_name, 'type' => 'entity_reference', 'entity_type' => $entity_type, 'cardinality' => $cardinality, - 'settings' => array( + 'settings' => [ 'target_type' => $target_entity_type, - ), - ))->save(); + ], + ])->save(); } if (!FieldConfig::loadByName($entity_type, $bundle, $field_name)) { - FieldConfig::create(array( + FieldConfig::create([ 'field_name' => $field_name, 'entity_type' => $entity_type, 'bundle' => $bundle, 'label' => $field_label, - 'settings' => array( + 'settings' => [ 'handler' => $selection_handler, 'handler_settings' => $selection_handler_settings, - ), - ))->save(); + ], + ])->save(); } } diff --git a/core/modules/field/src/Tests/FieldDefaultValueCallbackTest.php b/core/modules/field/src/Tests/FieldDefaultValueCallbackTest.php index e7f5a4c5448..b6926ce7e29 100644 --- a/core/modules/field/src/Tests/FieldDefaultValueCallbackTest.php +++ b/core/modules/field/src/Tests/FieldDefaultValueCallbackTest.php @@ -18,7 +18,7 @@ class FieldDefaultValueCallbackTest extends WebTestBase { * * @var array */ - public static $modules = array('node', 'field_test', 'field_ui'); + public static $modules = ['node', 'field_test', 'field_ui']; /** * The field name. @@ -37,10 +37,10 @@ class FieldDefaultValueCallbackTest extends WebTestBase { // Create Article node types. if ($this->profile != 'standard') { - $this->drupalCreateContentType(array( + $this->drupalCreateContentType([ 'type' => 'article', 'name' => 'Article', - )); + ]); } } diff --git a/core/modules/field/src/Tests/FieldImportDeleteUninstallUiTest.php b/core/modules/field/src/Tests/FieldImportDeleteUninstallUiTest.php index e69e04f8c49..e35308603f9 100644 --- a/core/modules/field/src/Tests/FieldImportDeleteUninstallUiTest.php +++ b/core/modules/field/src/Tests/FieldImportDeleteUninstallUiTest.php @@ -22,12 +22,12 @@ class FieldImportDeleteUninstallUiTest extends FieldTestBase { * * @var array */ - public static $modules = array('entity_test', 'telephone', 'config', 'filter', 'datetime'); + public static $modules = ['entity_test', 'telephone', 'config', 'filter', 'datetime']; protected function setUp() { parent::setUp(); - $this->drupalLogin($this->drupalCreateUser(array('synchronize configuration'))); + $this->drupalLogin($this->drupalCreateUser(['synchronize configuration'])); } /** @@ -35,11 +35,11 @@ class FieldImportDeleteUninstallUiTest extends FieldTestBase { */ public function testImportDeleteUninstall() { // Create a telephone field. - $field_storage = FieldStorageConfig::create(array( + $field_storage = FieldStorageConfig::create([ 'field_name' => 'field_tel', 'entity_type' => 'entity_test', 'type' => 'telephone', - )); + ]); $field_storage->save(); FieldConfig::create([ 'field_storage' => $field_storage, @@ -47,11 +47,11 @@ class FieldImportDeleteUninstallUiTest extends FieldTestBase { ])->save(); // Create a text field. - $date_field_storage = FieldStorageConfig::create(array( + $date_field_storage = FieldStorageConfig::create([ 'field_name' => 'field_date', 'entity_type' => 'entity_test', 'type' => 'datetime', - )); + ]); $date_field_storage->save(); FieldConfig::create([ 'field_storage' => $date_field_storage, @@ -104,12 +104,12 @@ class FieldImportDeleteUninstallUiTest extends FieldTestBase { // This will purge all the data, delete the field and uninstall the // Telephone and Text modules. - $this->drupalPostForm(NULL, array(), t('Import all')); + $this->drupalPostForm(NULL, [], t('Import all')); $this->assertNoText('Field data will be deleted by this synchronization.'); $this->rebuildContainer(); $this->assertFalse(\Drupal::moduleHandler()->moduleExists('telephone')); $this->assertFalse(\Drupal::entityManager()->loadEntityByUuid('field_storage_config', $field_storage->uuid()), 'The telephone field has been deleted by the configuration synchronization'); - $deleted_storages = \Drupal::state()->get('field.storage.deleted') ?: array(); + $deleted_storages = \Drupal::state()->get('field.storage.deleted') ?: []; $this->assertFalse(isset($deleted_storages[$field_storage->uuid()]), 'Telephone field has been completed removed from the system.'); $this->assertFalse(isset($deleted_storages[$field_storage->uuid()]), 'Text field has been completed removed from the system.'); } diff --git a/core/modules/field/src/Tests/FieldTestBase.php b/core/modules/field/src/Tests/FieldTestBase.php index 30c80dfafdd..ce4161bc9b4 100644 --- a/core/modules/field/src/Tests/FieldTestBase.php +++ b/core/modules/field/src/Tests/FieldTestBase.php @@ -23,7 +23,7 @@ abstract class FieldTestBase extends WebTestBase { * An array of random values, in the format expected for field values. */ function _generateTestFieldValues($cardinality) { - $values = array(); + $values = []; for ($i = 0; $i < $cardinality; $i++) { // field_test fields treat 0 as 'empty value'. $values[$i]['value'] = mt_rand(1, 127); @@ -61,7 +61,7 @@ abstract class FieldTestBase extends WebTestBase { $values = $field->getValue(); $this->assertEqual(count($values), count($expected_values), 'Expected number of values were saved.'); foreach ($expected_values as $key => $value) { - $this->assertEqual($values[$key][$column], $value, format_string('Value @value was saved correctly.', array('@value' => $value))); + $this->assertEqual($values[$key][$column], $value, format_string('Value @value was saved correctly.', ['@value' => $value])); } } diff --git a/core/modules/field/src/Tests/FormTest.php b/core/modules/field/src/Tests/FormTest.php index 16625a9ab4f..77cc27441da 100644 --- a/core/modules/field/src/Tests/FormTest.php +++ b/core/modules/field/src/Tests/FormTest.php @@ -25,7 +25,7 @@ class FormTest extends FieldTestBase { * * @var array */ - public static $modules = array('node', 'field_test', 'options', 'entity_test', 'locale'); + public static $modules = ['node', 'field_test', 'options', 'entity_test', 'locale']; /** * An array of values defining a field single. @@ -58,37 +58,37 @@ class FormTest extends FieldTestBase { protected function setUp() { parent::setUp(); - $web_user = $this->drupalCreateUser(array('view test entity', 'administer entity_test content')); + $web_user = $this->drupalCreateUser(['view test entity', 'administer entity_test content']); $this->drupalLogin($web_user); - $this->fieldStorageSingle = array( + $this->fieldStorageSingle = [ 'field_name' => 'field_single', 'entity_type' => 'entity_test', 'type' => 'test_field', - ); - $this->fieldStorageMultiple = array( + ]; + $this->fieldStorageMultiple = [ 'field_name' => 'field_multiple', 'entity_type' => 'entity_test', 'type' => 'test_field', 'cardinality' => 4, - ); - $this->fieldStorageUnlimited = array( + ]; + $this->fieldStorageUnlimited = [ 'field_name' => 'field_unlimited', 'entity_type' => 'entity_test', 'type' => 'test_field', 'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED, - ); + ]; - $this->field = array( + $this->field = [ 'entity_type' => 'entity_test', 'bundle' => 'entity_test', 'label' => $this->randomMachineName() . '_label', 'description' => '[site:name]_description', 'weight' => mt_rand(0, 127), - 'settings' => array( + 'settings' => [ 'test_field_setting' => $this->randomMachineName(), - ), - ); + ], + ]; } function testFieldFormSingle() { @@ -115,22 +115,22 @@ class FormTest extends FieldTestBase { $this->assertNoText('From hook_field_widget_form_alter(): Default form is true.', 'Not default value form in hook_field_widget_form_alter().'); // Submit with invalid value (field-level validation). - $edit = array( + $edit = [ "{$field_name}[0][value]" => -1 - ); + ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertRaw(t('%name does not accept the value -1.', array('%name' => $this->field['label'])), 'Field validation fails with invalid input.'); + $this->assertRaw(t('%name does not accept the value -1.', ['%name' => $this->field['label']]), 'Field validation fails with invalid input.'); // TODO : check that the correct field is flagged for error. // Create an entity $value = mt_rand(1, 127); - $edit = array( + $edit = [ "{$field_name}[0][value]" => $value, - ); + ]; $this->drupalPostForm(NULL, $edit, t('Save')); preg_match('|entity_test/manage/(\d+)|', $this->url, $match); $id = $match[1]; - $this->assertText(t('entity_test @id has been created.', array('@id' => $id)), 'Entity was created'); + $this->assertText(t('entity_test @id has been created.', ['@id' => $id]), 'Entity was created'); $entity = EntityTest::load($id); $this->assertEqual($entity->{$field_name}->value, $value, 'Field value was saved'); @@ -141,23 +141,23 @@ class FormTest extends FieldTestBase { // Update the entity. $value = mt_rand(1, 127); - $edit = array( + $edit = [ "{$field_name}[0][value]" => $value, - ); + ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText(t('entity_test @id has been updated.', array('@id' => $id)), 'Entity was updated'); - $this->container->get('entity.manager')->getStorage('entity_test')->resetCache(array($id)); + $this->assertText(t('entity_test @id has been updated.', ['@id' => $id]), 'Entity was updated'); + $this->container->get('entity.manager')->getStorage('entity_test')->resetCache([$id]); $entity = EntityTest::load($id); $this->assertEqual($entity->{$field_name}->value, $value, 'Field value was updated'); // Empty the field. $value = ''; - $edit = array( + $edit = [ "{$field_name}[0][value]" => $value - ); + ]; $this->drupalPostForm('entity_test/manage/' . $id . '/edit', $edit, t('Save')); - $this->assertText(t('entity_test @id has been updated.', array('@id' => $id)), 'Entity was updated'); - $this->container->get('entity.manager')->getStorage('entity_test')->resetCache(array($id)); + $this->assertText(t('entity_test @id has been updated.', ['@id' => $id]), 'Entity was updated'); + $this->container->get('entity.manager')->getStorage('entity_test')->resetCache([$id]); $entity = EntityTest::load($id); $this->assertTrue($entity->{$field_name}->isEmpty(), 'Field was emptied'); } @@ -170,7 +170,7 @@ class FormTest extends FieldTestBase { $field_name = $field_storage['field_name']; $this->field['field_name'] = $field_name; $default = rand(1, 127); - $this->field['default_value'] = array(array('value' => $default)); + $this->field['default_value'] = [['value' => $default]]; FieldStorageConfig::create($field_storage)->save(); FieldConfig::create($this->field)->save(); entity_get_form_display($this->field['entity_type'], $this->field['bundle'], 'default') @@ -183,13 +183,13 @@ class FormTest extends FieldTestBase { $this->assertFieldByXpath("//input[@name='{$field_name}[0][value]' and @value='$default']"); // Try to submit an empty value. - $edit = array( + $edit = [ "{$field_name}[0][value]" => '', - ); + ]; $this->drupalPostForm(NULL, $edit, t('Save')); preg_match('|entity_test/manage/(\d+)|', $this->url, $match); $id = $match[1]; - $this->assertText(t('entity_test @id has been created.', array('@id' => $id)), 'Entity was created.'); + $this->assertText(t('entity_test @id has been created.', ['@id' => $id]), 'Entity was created.'); $entity = EntityTest::load($id); $this->assertTrue($entity->{$field_name}->isEmpty(), 'Field is now empty.'); } @@ -206,29 +206,29 @@ class FormTest extends FieldTestBase { ->save(); // Submit with missing required value. - $edit = array(); + $edit = []; $this->drupalPostForm('entity_test/add', $edit, t('Save')); - $this->assertRaw(t('@name field is required.', array('@name' => $this->field['label'])), 'Required field with no value fails validation'); + $this->assertRaw(t('@name field is required.', ['@name' => $this->field['label']]), 'Required field with no value fails validation'); // Create an entity $value = mt_rand(1, 127); - $edit = array( + $edit = [ "{$field_name}[0][value]" => $value, - ); + ]; $this->drupalPostForm(NULL, $edit, t('Save')); preg_match('|entity_test/manage/(\d+)|', $this->url, $match); $id = $match[1]; - $this->assertText(t('entity_test @id has been created.', array('@id' => $id)), 'Entity was created'); + $this->assertText(t('entity_test @id has been created.', ['@id' => $id]), 'Entity was created'); $entity = EntityTest::load($id); $this->assertEqual($entity->{$field_name}->value, $value, 'Field value was saved'); // Edit with missing required value. $value = ''; - $edit = array( + $edit = [ "{$field_name}[0][value]" => $value, - ); + ]; $this->drupalPostForm('entity_test/manage/' . $id . '/edit', $edit, t('Save')); - $this->assertRaw(t('@name field is required.', array('@name' => $this->field['label'])), 'Required field with no value fails validation'); + $this->assertRaw(t('@name field is required.', ['@name' => $this->field['label']]), 'Required field with no value fails validation'); } function testFieldFormUnlimited() { @@ -251,20 +251,20 @@ class FormTest extends FieldTestBase { $this->assertTrue(isset($elements[0]), t('aria-describedby attribute is properly placed on multiple value widgets.')); // Press 'add more' button -> 2 widgets. - $this->drupalPostForm(NULL, array(), t('Add another item')); + $this->drupalPostForm(NULL, [], t('Add another item')); $this->assertFieldByName("{$field_name}[0][value]", '', 'Widget 1 is displayed'); $this->assertFieldByName("{$field_name}[1][value]", '', 'New widget is displayed'); $this->assertNoField("{$field_name}[2][value]", 'No extraneous widget is displayed'); // TODO : check that non-field inputs are preserved ('title'), etc. // Yet another time so that we can play with more values -> 3 widgets. - $this->drupalPostForm(NULL, array(), t('Add another item')); + $this->drupalPostForm(NULL, [], t('Add another item')); // Prepare values and weights. $count = 3; $delta_range = $count - 1; - $values = $weights = $pattern = $expected_values = array(); - $edit = array(); + $values = $weights = $pattern = $expected_values = []; + $edit = []; for ($delta = 0; $delta <= $delta_range; $delta++) { // Assign unique random values and weights. do { @@ -299,7 +299,7 @@ class FormTest extends FieldTestBase { $this->drupalPostForm(NULL, $edit, t('Save')); preg_match('|entity_test/manage/(\d+)|', $this->url, $match); $id = $match[1]; - $this->assertText(t('entity_test @id has been created.', array('@id' => $id)), 'Entity was created'); + $this->assertText(t('entity_test @id has been created.', ['@id' => $id]), 'Entity was created'); $entity = EntityTest::load($id); ksort($field_values); $field_values = array_values($field_values); @@ -330,11 +330,11 @@ class FormTest extends FieldTestBase { // Display creation form -> 1 widget. $this->drupalGet('entity_test/add'); // Check that the Required symbol is present for the multifield label. - $element = $this->xpath('//h4[contains(@class, "label") and contains(@class, "js-form-required") and contains(text(), :value)]', array(':value' => $this->field['label'])); + $element = $this->xpath('//h4[contains(@class, "label") and contains(@class, "js-form-required") and contains(text(), :value)]', [':value' => $this->field['label']]); $this->assertTrue(isset($element[0]), 'Required symbol added field label.'); // Check that the label of the field input is visually hidden and contains // the field title and an indication of the delta for a11y. - $element = $this->xpath('//label[@for=:for and contains(@class, "visually-hidden") and contains(text(), :value)]', array(':for' => 'edit-field-unlimited-0-value', ':value' => $this->field['label'] . ' (value 1)')); + $element = $this->xpath('//label[@for=:for and contains(@class, "visually-hidden") and contains(text(), :value)]', [':for' => 'edit-field-unlimited-0-value', ':value' => $this->field['label'] . ' (value 1)']); $this->assertTrue(isset($element[0]), 'Required symbol not added for field input.'); } @@ -353,32 +353,32 @@ class FormTest extends FieldTestBase { ->save(); // Add a required radio field. - FieldStorageConfig::create(array( + FieldStorageConfig::create([ 'field_name' => 'required_radio_test', 'entity_type' => 'entity_test', 'type' => 'list_string', - 'settings' => array( - 'allowed_values' => array('yes' => 'yes', 'no' => 'no'), - ), - ))->save(); - $field = array( + 'settings' => [ + 'allowed_values' => ['yes' => 'yes', 'no' => 'no'], + ], + ])->save(); + $field = [ 'field_name' => 'required_radio_test', 'entity_type' => 'entity_test', 'bundle' => 'entity_test', 'required' => TRUE, - ); + ]; FieldConfig::create($field)->save(); entity_get_form_display($field['entity_type'], $field['bundle'], 'default') - ->setComponent($field['field_name'], array( + ->setComponent($field['field_name'], [ 'type' => 'options_buttons', - )) + ]) ->save(); // Display creation form. $this->drupalGet('entity_test/add'); // Press the 'Add more' button. - $this->drupalPostForm(NULL, array(), t('Add another item')); + $this->drupalPostForm(NULL, [], t('Add another item')); // Verify that no error is thrown by the radio element. $this->assertNoFieldByXpath('//div[contains(@class, "error")]', FALSE, 'No error message is displayed.'); @@ -405,13 +405,13 @@ class FormTest extends FieldTestBase { // Press 'add more' button a couple times -> 3 widgets. // drupalPostAjaxForm() will not work iteratively, so we add those through // non-JS submission. - $this->drupalPostForm(NULL, array(), t('Add another item')); - $this->drupalPostForm(NULL, array(), t('Add another item')); + $this->drupalPostForm(NULL, [], t('Add another item')); + $this->drupalPostForm(NULL, [], t('Add another item')); // Prepare values and weights. $count = 3; $delta_range = $count - 1; - $values = $weights = $pattern = $expected_values = $edit = array(); + $values = $weights = $pattern = $expected_values = $edit = []; for ($delta = 0; $delta <= $delta_range; $delta++) { // Assign unique random values and weights. do { @@ -457,9 +457,9 @@ class FormTest extends FieldTestBase { FieldStorageConfig::create($field_storage)->save(); FieldConfig::create($this->field)->save(); entity_get_form_display($this->field['entity_type'], $this->field['bundle'], 'default') - ->setComponent($field_name, array( + ->setComponent($field_name, [ 'type' => 'test_field_widget_multiple', - )) + ]) ->save(); // Display creation form. @@ -467,27 +467,27 @@ class FormTest extends FieldTestBase { $this->assertFieldByName($field_name, '', 'Widget is displayed.'); // Create entity with three values. - $edit = array( + $edit = [ $field_name => '1, 2, 3', - ); + ]; $this->drupalPostForm(NULL, $edit, t('Save')); preg_match('|entity_test/manage/(\d+)|', $this->url, $match); $id = $match[1]; // Check that the values were saved. $entity_init = EntityTest::load($id); - $this->assertFieldValues($entity_init, $field_name, array(1, 2, 3)); + $this->assertFieldValues($entity_init, $field_name, [1, 2, 3]); // Display the form, check that the values are correctly filled in. $this->drupalGet('entity_test/manage/' . $id . '/edit'); $this->assertFieldByName($field_name, '1, 2, 3', 'Widget is displayed.'); // Submit the form with more values than the field accepts. - $edit = array($field_name => '1, 2, 3, 4, 5'); + $edit = [$field_name => '1, 2, 3, 4, 5']; $this->drupalPostForm(NULL, $edit, t('Save')); $this->assertRaw('this field cannot hold more than 4 values', 'Form validation failed.'); // Check that the field values were not submitted. - $this->assertFieldValues($entity_init, $field_name, array(1, 2, 3)); + $this->assertFieldValues($entity_init, $field_name, [1, 2, 3]); } /** @@ -511,18 +511,18 @@ class FormTest extends FieldTestBase { // Create a field with no edit access. See // field_test_entity_field_access(). - $field_storage_no_access = array( + $field_storage_no_access = [ 'field_name' => 'field_no_edit_access', 'entity_type' => $entity_type, 'type' => 'test_field', - ); + ]; $field_name_no_access = $field_storage_no_access['field_name']; - $field_no_access = array( + $field_no_access = [ 'field_name' => $field_name_no_access, 'entity_type' => $entity_type, 'bundle' => $entity_type, - 'default_value' => array(0 => array('value' => 99)), - ); + 'default_value' => [0 => ['value' => 99]], + ]; FieldStorageConfig::create($field_storage_no_access)->save(); FieldConfig::create($field_no_access)->save(); entity_get_form_display($field_no_access['entity_type'], $field_no_access['bundle'], 'default') @@ -533,10 +533,10 @@ class FormTest extends FieldTestBase { // apart from #access. $entity = $this->container->get('entity_type.manager') ->getStorage($entity_type) - ->create(array('id' => 0, 'revision_id' => 0)); + ->create(['id' => 0, 'revision_id' => 0]); $display = entity_get_form_display($entity_type, $entity_type, 'default'); - $form = array(); + $form = []; $form_state = new FormState(); $display->buildForm($entity, $form, $form_state); @@ -547,9 +547,9 @@ class FormTest extends FieldTestBase { $this->assertNoFieldByName("{$field_name_no_access}[0][value]", '', 'Widget is not displayed if field access is denied.'); // Create entity. - $edit = array( + $edit = [ "{$field_name}[0][value]" => 1, - ); + ]; $this->drupalPostForm(NULL, $edit, t('Save')); preg_match("|$entity_type/manage/(\d+)|", $this->url, $match); $id = $match[1]; @@ -562,10 +562,10 @@ class FormTest extends FieldTestBase { $this->assertEqual($entity->$field_name->value, 1, 'Entered value vas saved for the field with edit access.'); // Create a new revision. - $edit = array( + $edit = [ "{$field_name}[0][value]" => 2, 'revision' => TRUE, - ); + ]; $this->drupalPostForm($entity_type . '/manage/' . $id . '/edit', $edit, t('Save')); // Check that the new revision has the expected values. @@ -591,7 +591,7 @@ class FormTest extends FieldTestBase { $field_storage['entity_type'] = $entity_type; $field_name = $field_storage['field_name']; $this->field['field_name'] = $field_name; - $this->field['default_value'] = array(0 => array('value' => 99)); + $this->field['default_value'] = [0 => ['value' => 99]]; $this->field['entity_type'] = $entity_type; $this->field['bundle'] = $entity_type; FieldStorageConfig::create($field_storage)->save(); @@ -606,10 +606,10 @@ class FormTest extends FieldTestBase { // Create an entity and test that the default value is assigned correctly to // the field that uses the hidden widget. $this->assertNoField("{$field_name}[0][value]", 'The field does not appear in the form'); - $this->drupalPostForm(NULL, array(), t('Save')); + $this->drupalPostForm(NULL, [], t('Save')); preg_match('|' . $entity_type . '/manage/(\d+)|', $this->url, $match); $id = $match[1]; - $this->assertText(t('entity_test_rev @id has been created.', array('@id' => $id)), 'Entity was created'); + $this->assertText(t('entity_test_rev @id has been created.', ['@id' => $id]), 'Entity was created'); $storage = $this->container->get('entity_type.manager') ->getStorage($entity_type); @@ -618,12 +618,12 @@ class FormTest extends FieldTestBase { // Update the field to remove the default value, and switch to the default // widget. - $this->field->setDefaultValue(array()); + $this->field->setDefaultValue([]); $this->field->save(); entity_get_form_display($entity_type, $this->field->getTargetBundle(), 'default') - ->setComponent($this->field->getName(), array( + ->setComponent($this->field->getName(), [ 'type' => 'test_field_widget', - )) + ]) ->save(); // Display edit form. @@ -632,9 +632,9 @@ class FormTest extends FieldTestBase { // Update the entity. $value = mt_rand(1, 127); - $edit = array("{$field_name}[0][value]" => $value); + $edit = ["{$field_name}[0][value]" => $value]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText(t('entity_test_rev @id has been updated.', array('@id' => $id)), 'Entity was updated'); + $this->assertText(t('entity_test_rev @id has been updated.', ['@id' => $id]), 'Entity was updated'); $storage->resetCache([$id]); $entity = $storage->load($id); $this->assertEqual($entity->{$field_name}->value, $value, 'Field value was updated'); @@ -645,11 +645,11 @@ class FormTest extends FieldTestBase { ->save(); // Create a new revision. - $edit = array('revision' => TRUE); + $edit = ['revision' => TRUE]; $this->drupalPostForm($entity_type . '/manage/' . $id . '/edit', $edit, t('Save')); // Check that the expected value has been carried over to the new revision. - $storage->resetCache(array($id)); + $storage->resetCache([$id]); $entity = $storage->load($id); $this->assertEqual($entity->{$field_name}->value, $value, 'New revision has the expected value for the field with the Hidden widget'); } diff --git a/core/modules/field/src/Tests/NestedFormTest.php b/core/modules/field/src/Tests/NestedFormTest.php index 8b3402d584f..530bb20f182 100644 --- a/core/modules/field/src/Tests/NestedFormTest.php +++ b/core/modules/field/src/Tests/NestedFormTest.php @@ -17,36 +17,36 @@ class NestedFormTest extends FieldTestBase { * * @var array */ - public static $modules = array('field_test', 'entity_test'); + public static $modules = ['field_test', 'entity_test']; protected function setUp() { parent::setUp(); - $web_user = $this->drupalCreateUser(array('view test entity', 'administer entity_test content')); + $web_user = $this->drupalCreateUser(['view test entity', 'administer entity_test content']); $this->drupalLogin($web_user); - $this->fieldStorageSingle = array( + $this->fieldStorageSingle = [ 'field_name' => 'field_single', 'entity_type' => 'entity_test', 'type' => 'test_field', - ); - $this->fieldStorageUnlimited = array( + ]; + $this->fieldStorageUnlimited = [ 'field_name' => 'field_unlimited', 'entity_type' => 'entity_test', 'type' => 'test_field', 'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED, - ); + ]; - $this->field = array( + $this->field = [ 'entity_type' => 'entity_test', 'bundle' => 'entity_test', 'label' => $this->randomMachineName() . '_label', 'description' => '[site:name]_description', 'weight' => mt_rand(0, 127), - 'settings' => array( + 'settings' => [ 'test_field_setting' => $this->randomMachineName(), - ), - ); + ], + ]; } /** @@ -80,7 +80,7 @@ class NestedFormTest extends FieldTestBase { $entity_1->field_unlimited->value = 1; $entity_1->save(); - $entity_2 = $storage->create(array('id' => 2)); + $entity_2 = $storage->create(['id' => 2]); $entity_2->enforceIsNew(); $entity_2->field_single->value = 10; $entity_2->field_unlimited->value = 11; @@ -94,75 +94,75 @@ class NestedFormTest extends FieldTestBase { $this->assertFieldByName('entity_2[field_unlimited][0][value]', 11, 'Entity 2: field_unlimited value 0 appears correctly is the form.'); // Submit the form and check that the entities are updated accordingly. - $edit = array( + $edit = [ 'field_single[0][value]' => 1, 'field_unlimited[0][value]' => 2, 'field_unlimited[1][value]' => 3, 'entity_2[field_single][0][value]' => 11, 'entity_2[field_unlimited][0][value]' => 12, 'entity_2[field_unlimited][1][value]' => 13, - ); + ]; $this->drupalPostForm(NULL, $edit, t('Save')); $entity_1 = $storage->load(1); $entity_2 = $storage->load(2); - $this->assertFieldValues($entity_1, 'field_single', array(1)); - $this->assertFieldValues($entity_1, 'field_unlimited', array(2, 3)); - $this->assertFieldValues($entity_2, 'field_single', array(11)); - $this->assertFieldValues($entity_2, 'field_unlimited', array(12, 13)); + $this->assertFieldValues($entity_1, 'field_single', [1]); + $this->assertFieldValues($entity_1, 'field_unlimited', [2, 3]); + $this->assertFieldValues($entity_2, 'field_single', [11]); + $this->assertFieldValues($entity_2, 'field_unlimited', [12, 13]); // Submit invalid values and check that errors are reported on the // correct widgets. - $edit = array( + $edit = [ 'field_unlimited[1][value]' => -1, - ); + ]; $this->drupalPostForm('test-entity/nested/1/2', $edit, t('Save')); - $this->assertRaw(t('%label does not accept the value -1', array('%label' => 'Unlimited field')), 'Entity 1: the field validation error was reported.'); - $error_field = $this->xpath('//input[@id=:id and contains(@class, "error")]', array(':id' => 'edit-field-unlimited-1-value')); + $this->assertRaw(t('%label does not accept the value -1', ['%label' => 'Unlimited field']), 'Entity 1: the field validation error was reported.'); + $error_field = $this->xpath('//input[@id=:id and contains(@class, "error")]', [':id' => 'edit-field-unlimited-1-value']); $this->assertTrue($error_field, 'Entity 1: the error was flagged on the correct element.'); - $edit = array( + $edit = [ 'entity_2[field_unlimited][1][value]' => -1, - ); + ]; $this->drupalPostForm('test-entity/nested/1/2', $edit, t('Save')); - $this->assertRaw(t('%label does not accept the value -1', array('%label' => 'Unlimited field')), 'Entity 2: the field validation error was reported.'); - $error_field = $this->xpath('//input[@id=:id and contains(@class, "error")]', array(':id' => 'edit-entity-2-field-unlimited-1-value')); + $this->assertRaw(t('%label does not accept the value -1', ['%label' => 'Unlimited field']), 'Entity 2: the field validation error was reported.'); + $error_field = $this->xpath('//input[@id=:id and contains(@class, "error")]', [':id' => 'edit-entity-2-field-unlimited-1-value']); $this->assertTrue($error_field, 'Entity 2: the error was flagged on the correct element.'); // Test that reordering works on both entities. - $edit = array( + $edit = [ 'field_unlimited[0][_weight]' => 0, 'field_unlimited[1][_weight]' => -1, 'entity_2[field_unlimited][0][_weight]' => 0, 'entity_2[field_unlimited][1][_weight]' => -1, - ); + ]; $this->drupalPostForm('test-entity/nested/1/2', $edit, t('Save')); - $this->assertFieldValues($entity_1, 'field_unlimited', array(3, 2)); - $this->assertFieldValues($entity_2, 'field_unlimited', array(13, 12)); + $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(). // 'Add more' button in the first entity: $this->drupalGet('test-entity/nested/1/2'); - $this->drupalPostAjaxForm(NULL, array(), 'field_unlimited_add_more'); + $this->drupalPostAjaxForm(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.'); $this->assertFieldByName('field_unlimited[3][value]', '', 'Entity 1: an empty widget was added for field_unlimited value 3.'); // 'Add more' button in the first entity (changing field values): - $edit = array( + $edit = [ 'entity_2[field_unlimited][0][value]' => 13, '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->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.'); $this->assertFieldByName('entity_2[field_unlimited][3][value]', '', 'Entity 2: an empty widget was added for field_unlimited value 3.'); // Save the form and check values are saved correctly. - $this->drupalPostForm(NULL, array(), t('Save')); - $this->assertFieldValues($entity_1, 'field_unlimited', array(3, 2)); - $this->assertFieldValues($entity_2, 'field_unlimited', array(13, 14, 15)); + $this->drupalPostForm(NULL, [], t('Save')); + $this->assertFieldValues($entity_1, 'field_unlimited', [3, 2]); + $this->assertFieldValues($entity_2, 'field_unlimited', [13, 14, 15]); } /** diff --git a/core/modules/field/src/Tests/Number/NumberFieldTest.php b/core/modules/field/src/Tests/Number/NumberFieldTest.php index 14777ec3424..3fea6166b2f 100644 --- a/core/modules/field/src/Tests/Number/NumberFieldTest.php +++ b/core/modules/field/src/Tests/Number/NumberFieldTest.php @@ -20,11 +20,11 @@ class NumberFieldTest extends WebTestBase { * * @var array */ - public static $modules = array('node', 'entity_test', 'field_ui'); + public static $modules = ['node', 'entity_test', 'field_ui']; protected function setUp() { parent::setUp(); - $this->drupalLogin($this->drupalCreateUser(array( + $this->drupalLogin($this->drupalCreateUser([ 'view test entity', 'administer entity_test content', 'administer content types', @@ -32,7 +32,7 @@ class NumberFieldTest extends WebTestBase { 'administer node display', 'bypass node access', 'administer entity_test fields', - ))); + ])); } /** @@ -41,14 +41,14 @@ class NumberFieldTest extends WebTestBase { function testNumberDecimalField() { // Create a field with settings to validate. $field_name = Unicode::strtolower($this->randomMachineName()); - FieldStorageConfig::create(array( + FieldStorageConfig::create([ 'field_name' => $field_name, 'entity_type' => 'entity_test', 'type' => 'decimal', - 'settings' => array( + 'settings' => [ 'precision' => 8, 'scale' => 4, - ) - ))->save(); + ] + ])->save(); FieldConfig::create([ 'field_name' => $field_name, 'entity_type' => 'entity_test', @@ -56,17 +56,17 @@ class NumberFieldTest extends WebTestBase { ])->save(); entity_get_form_display('entity_test', 'entity_test', 'default') - ->setComponent($field_name, array( + ->setComponent($field_name, [ 'type' => 'number', - 'settings' => array( + 'settings' => [ 'placeholder' => '0.00' - ), - )) + ], + ]) ->save(); entity_get_display('entity_test', 'entity_test', 'default') - ->setComponent($field_name, array( + ->setComponent($field_name, [ 'type' => 'number_decimal', - )) + ]) ->save(); // Display creation form. @@ -76,49 +76,49 @@ class NumberFieldTest extends WebTestBase { // Submit a signed decimal value within the allowed precision and scale. $value = '-1234.5678'; - $edit = array( + $edit = [ "{$field_name}[0][value]" => $value, - ); + ]; $this->drupalPostForm(NULL, $edit, t('Save')); preg_match('|entity_test/manage/(\d+)|', $this->url, $match); $id = $match[1]; - $this->assertText(t('entity_test @id has been created.', array('@id' => $id)), 'Entity was created'); + $this->assertText(t('entity_test @id has been created.', ['@id' => $id]), 'Entity was created'); $this->assertRaw($value, 'Value is displayed.'); // Try to create entries with more than one decimal separator; assert fail. - $wrong_entries = array( + $wrong_entries = [ '3.14.159', '0..45469', '..4589', '6.459.52', '6.3..25', - ); + ]; foreach ($wrong_entries as $wrong_entry) { $this->drupalGet('entity_test/add'); - $edit = array( + $edit = [ "{$field_name}[0][value]" => $wrong_entry, - ); + ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertRaw(t('%name must be a number.', array('%name' => $field_name)), 'Correctly failed to save decimal value with more than one decimal point.'); + $this->assertRaw(t('%name must be a number.', ['%name' => $field_name]), 'Correctly failed to save decimal value with more than one decimal point.'); } // Try to create entries with minus sign not in the first position. - $wrong_entries = array( + $wrong_entries = [ '3-3', '4-', '1.3-', '1.2-4', '-10-10', - ); + ]; foreach ($wrong_entries as $wrong_entry) { $this->drupalGet('entity_test/add'); - $edit = array( + $edit = [ "{$field_name}[0][value]" => $wrong_entry, - ); + ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertRaw(t('%name must be a number.', array('%name' => $field_name)), 'Correctly failed to save decimal value with minus sign in the wrong position.'); + $this->assertRaw(t('%name must be a number.', ['%name' => $field_name]), 'Correctly failed to save decimal value with minus sign in the wrong position.'); } } @@ -131,52 +131,52 @@ class NumberFieldTest extends WebTestBase { // Create a field with settings to validate. $field_name = Unicode::strtolower($this->randomMachineName()); - $storage = FieldStorageConfig::create(array( + $storage = FieldStorageConfig::create([ 'field_name' => $field_name, 'entity_type' => 'entity_test', 'type' => 'integer', - )); + ]); $storage->save(); FieldConfig::create([ 'field_name' => $field_name, 'entity_type' => 'entity_test', 'bundle' => 'entity_test', - 'settings' => array( + 'settings' => [ 'min' => $minimum, 'max' => $maximum, 'prefix' => 'ThePrefix', - ) + ] ])->save(); entity_get_form_display('entity_test', 'entity_test', 'default') - ->setComponent($field_name, array( + ->setComponent($field_name, [ 'type' => 'number', - 'settings' => array( + 'settings' => [ 'placeholder' => '4' - ), - )) + ], + ]) ->save(); entity_get_display('entity_test', 'entity_test', 'default') - ->setComponent($field_name, array( + ->setComponent($field_name, [ 'type' => 'number_integer', - 'settings' => array( + 'settings' => [ 'prefix_suffix' => FALSE, - ), - )) + ], + ]) ->save(); // Check the storage schema. - $expected = array( - 'columns' => array( - 'value' => array( + $expected = [ + 'columns' => [ + 'value' => [ 'type' => 'int', 'unsigned' => '', 'size' => 'normal' - ), - ), - 'unique keys' => array(), - 'indexes' => array(), - 'foreign keys' => array() - ); + ], + ], + 'unique keys' => [], + 'indexes' => [], + 'foreign keys' => [] + ]; $this->assertEqual($storage->getSchema(), $expected); // Display creation form. @@ -186,84 +186,84 @@ class NumberFieldTest extends WebTestBase { // Submit a valid integer $value = rand($minimum, $maximum); - $edit = array( + $edit = [ "{$field_name}[0][value]" => $value, - ); + ]; $this->drupalPostForm(NULL, $edit, t('Save')); preg_match('|entity_test/manage/(\d+)|', $this->url, $match); $id = $match[1]; - $this->assertText(t('entity_test @id has been created.', array('@id' => $id)), 'Entity was created'); + $this->assertText(t('entity_test @id has been created.', ['@id' => $id]), 'Entity was created'); // Try to set a value below the minimum value $this->drupalGet('entity_test/add'); - $edit = array( + $edit = [ "{$field_name}[0][value]" => $minimum - 1, - ); + ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertRaw(t('%name must be higher than or equal to %minimum.', array('%name' => $field_name, '%minimum' => $minimum)), 'Correctly failed to save integer value less than minimum allowed value.'); + $this->assertRaw(t('%name must be higher than or equal to %minimum.', ['%name' => $field_name, '%minimum' => $minimum]), 'Correctly failed to save integer value less than minimum allowed value.'); // Try to set a decimal value $this->drupalGet('entity_test/add'); - $edit = array( + $edit = [ "{$field_name}[0][value]" => 1.5, - ); + ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertRaw(t('%name is not a valid number.', array('%name' => $field_name)), 'Correctly failed to save decimal value to integer field.'); + $this->assertRaw(t('%name is not a valid number.', ['%name' => $field_name]), 'Correctly failed to save decimal value to integer field.'); // Try to set a value above the maximum value $this->drupalGet('entity_test/add'); - $edit = array( + $edit = [ "{$field_name}[0][value]" => $maximum + 1, - ); + ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertRaw(t('%name must be lower than or equal to %maximum.', array('%name' => $field_name, '%maximum' => $maximum)), 'Correctly failed to save integer value greater than maximum allowed value.'); + $this->assertRaw(t('%name must be lower than or equal to %maximum.', ['%name' => $field_name, '%maximum' => $maximum]), 'Correctly failed to save integer value greater than maximum allowed value.'); // Try to set a wrong integer value. $this->drupalGet('entity_test/add'); - $edit = array( + $edit = [ "{$field_name}[0][value]" => '20-40', - ); + ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertRaw(t('%name must be a number.', array('%name' => $field_name)), 'Correctly failed to save wrong integer value.'); + $this->assertRaw(t('%name must be a number.', ['%name' => $field_name]), 'Correctly failed to save wrong integer value.'); // Test with valid entries. - $valid_entries = array( + $valid_entries = [ '-1234', '0', '1234', - ); + ]; foreach ($valid_entries as $valid_entry) { $this->drupalGet('entity_test/add'); - $edit = array( + $edit = [ "{$field_name}[0][value]" => $valid_entry, - ); + ]; $this->drupalPostForm(NULL, $edit, t('Save')); preg_match('|entity_test/manage/(\d+)|', $this->url, $match); $id = $match[1]; - $this->assertText(t('entity_test @id has been created.', array('@id' => $id)), 'Entity was created'); + $this->assertText(t('entity_test @id has been created.', ['@id' => $id]), 'Entity was created'); $this->assertRaw($valid_entry, 'Value is displayed.'); $this->assertNoFieldByXpath('//div[@content="' . $valid_entry . '"]', NULL, 'The "content" attribute is not present since the Prefix is not being displayed'); } // Test for the content attribute when a Prefix is displayed. Presumably this also tests for the attribute when a Suffix is displayed. entity_get_display('entity_test', 'entity_test', 'default') - ->setComponent($field_name, array( + ->setComponent($field_name, [ 'type' => 'number_integer', - 'settings' => array( + 'settings' => [ 'prefix_suffix' => TRUE, - ), - )) + ], + ]) ->save(); $integer_value = '123'; $this->drupalGet('entity_test/add'); - $edit = array( + $edit = [ "{$field_name}[0][value]" => $integer_value, - ); + ]; $this->drupalPostForm(NULL, $edit, t('Save')); preg_match('|entity_test/manage/(\d+)|', $this->url, $match); $id = $match[1]; - $this->assertText(t('entity_test @id has been created.', array('@id' => $id)), 'Entity was created'); + $this->assertText(t('entity_test @id has been created.', ['@id' => $id]), 'Entity was created'); $this->drupalGet('entity_test/' . $id); $this->assertFieldByXPath('//div[@content="' . $integer_value . '"]', 'ThePrefix' . $integer_value, 'The "content" attribute has been set to the value of the field, and the prefix is being displayed.'); } @@ -274,11 +274,11 @@ class NumberFieldTest extends WebTestBase { function testNumberFloatField() { // Create a field with settings to validate. $field_name = Unicode::strtolower($this->randomMachineName()); - FieldStorageConfig::create(array( + FieldStorageConfig::create([ 'field_name' => $field_name, 'entity_type' => 'entity_test', 'type' => 'float', - ))->save(); + ])->save(); FieldConfig::create([ 'field_name' => $field_name, @@ -287,18 +287,18 @@ class NumberFieldTest extends WebTestBase { ])->save(); entity_get_form_display('entity_test', 'entity_test', 'default') - ->setComponent($field_name, array( + ->setComponent($field_name, [ 'type' => 'number', - 'settings' => array( + 'settings' => [ 'placeholder' => '0.00' - ), - )) + ], + ]) ->save(); entity_get_display('entity_test', 'entity_test', 'default') - ->setComponent($field_name, array( + ->setComponent($field_name, [ 'type' => 'number_decimal', - )) + ]) ->save(); // Display creation form. @@ -308,13 +308,13 @@ class NumberFieldTest extends WebTestBase { // Submit a signed decimal value within the allowed precision and scale. $value = '-1234.5678'; - $edit = array( + $edit = [ "{$field_name}[0][value]" => $value, - ); + ]; $this->drupalPostForm(NULL, $edit, t('Save')); preg_match('|entity_test/manage/(\d+)|', $this->url, $match); $id = $match[1]; - $this->assertText(t('entity_test @id has been created.', array('@id' => $id)), 'Entity was created'); + $this->assertText(t('entity_test @id has been created.', ['@id' => $id]), 'Entity was created'); // Ensure that the 'number_decimal' formatter displays the number with the // expected rounding. @@ -322,39 +322,39 @@ class NumberFieldTest extends WebTestBase { $this->assertRaw(round($value, 2)); // Try to create entries with more than one decimal separator; assert fail. - $wrong_entries = array( + $wrong_entries = [ '3.14.159', '0..45469', '..4589', '6.459.52', '6.3..25', - ); + ]; foreach ($wrong_entries as $wrong_entry) { $this->drupalGet('entity_test/add'); - $edit = array( + $edit = [ "{$field_name}[0][value]" => $wrong_entry, - ); + ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertRaw(t('%name must be a number.', array('%name' => $field_name)), 'Correctly failed to save float value with more than one decimal point.'); + $this->assertRaw(t('%name must be a number.', ['%name' => $field_name]), 'Correctly failed to save float value with more than one decimal point.'); } // Try to create entries with minus sign not in the first position. - $wrong_entries = array( + $wrong_entries = [ '3-3', '4-', '1.3-', '1.2-4', '-10-10', - ); + ]; foreach ($wrong_entries as $wrong_entry) { $this->drupalGet('entity_test/add'); - $edit = array( + $edit = [ "{$field_name}[0][value]" => $wrong_entry, - ); + ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertRaw(t('%name must be a number.', array('%name' => $field_name)), 'Correctly failed to save float value with minus sign in the wrong position.'); + $this->assertRaw(t('%name must be a number.', ['%name' => $field_name]), 'Correctly failed to save float value with minus sign in the wrong position.'); } } @@ -365,70 +365,70 @@ class NumberFieldTest extends WebTestBase { $type = Unicode::strtolower($this->randomMachineName()); $float_field = Unicode::strtolower($this->randomMachineName()); $integer_field = Unicode::strtolower($this->randomMachineName()); - $thousand_separators = array('', '.', ',', ' ', chr(8201), "'"); - $decimal_separators = array('.', ','); + $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(array('type' => $type)); + $this->drupalCreateContentType(['type' => $type]); - FieldStorageConfig::create(array( + FieldStorageConfig::create([ 'field_name' => $float_field, 'entity_type' => 'node', 'type' => 'float', - ))->save(); + ])->save(); - FieldStorageConfig::create(array( + FieldStorageConfig::create([ 'field_name' => $integer_field, 'entity_type' => 'node', 'type' => 'integer', - ))->save(); + ])->save(); FieldConfig::create([ 'field_name' => $float_field, 'entity_type' => 'node', 'bundle' => $type, - 'settings' => array( + 'settings' => [ 'prefix' => $prefix, 'suffix' => $suffix - ), + ], ])->save(); FieldConfig::create([ 'field_name' => $integer_field, 'entity_type' => 'node', 'bundle' => $type, - 'settings' => array( + 'settings' => [ 'prefix' => $prefix, 'suffix' => $suffix - ), + ], ])->save(); entity_get_form_display('node', $type, 'default') - ->setComponent($float_field, array( + ->setComponent($float_field, [ 'type' => 'number', - 'settings' => array( + 'settings' => [ 'placeholder' => '0.00' - ), - )) - ->setComponent($integer_field, array( + ], + ]) + ->setComponent($integer_field, [ 'type' => 'number', - 'settings' => array( + 'settings' => [ 'placeholder' => '0.00' - ), - )) + ], + ]) ->save(); entity_get_display('node', $type, 'default') - ->setComponent($float_field, array( + ->setComponent($float_field, [ 'type' => 'number_decimal', - )) - ->setComponent($integer_field, array( + ]) + ->setComponent($integer_field, [ 'type' => 'number_unformatted', - )) + ]) ->save(); // Create a node to test formatters. @@ -448,15 +448,15 @@ class NumberFieldTest extends WebTestBase { $decimal_separator = $decimal_separators[array_rand($decimal_separators)]; $scale = rand(0, 10); - $this->drupalPostAjaxForm(NULL, array(), "${float_field}_settings_edit"); - $edit = array( + $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, array(), t('Save')); + $this->drupalPostForm(NULL, [], t('Save')); // Check number_decimal and number_unformatted formatters behavior. $this->drupalGet('node/' . $node->id()); @@ -466,21 +466,21 @@ class NumberFieldTest extends WebTestBase { // Configure the number_decimal formatter. entity_get_display('node', $type, 'default') - ->setComponent($integer_field, array( + ->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, array(), "${integer_field}_settings_edit"); - $edit = array( + $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, array(), t('Save')); + $this->drupalPostForm(NULL, [], t('Save')); // Check number_integer formatter behavior. $this->drupalGet('node/' . $node->id()); @@ -495,11 +495,11 @@ class NumberFieldTest extends WebTestBase { function testCreateNumberFloatField() { // Create a float field. $field_name = Unicode::strtolower($this->randomMachineName()); - FieldStorageConfig::create(array( + FieldStorageConfig::create([ 'field_name' => $field_name, 'entity_type' => 'entity_test', 'type' => 'float', - ))->save(); + ])->save(); $field = FieldConfig::create([ 'field_name' => $field_name, @@ -520,11 +520,11 @@ class NumberFieldTest extends WebTestBase { function testCreateNumberDecimalField() { // Create a decimal field. $field_name = Unicode::strtolower($this->randomMachineName()); - FieldStorageConfig::create(array( + FieldStorageConfig::create([ 'field_name' => $field_name, 'entity_type' => 'entity_test', 'type' => 'decimal', - ))->save(); + ])->save(); $field = FieldConfig::create([ 'field_name' => $field_name, @@ -546,14 +546,14 @@ class NumberFieldTest extends WebTestBase { $field_configuration_url = 'entity_test/structure/entity_test/fields/entity_test.entity_test.' . $field->getName(); // Set the minimum value. - $edit = array( + $edit = [ 'settings[min]' => $minimum_value, - ); + ]; $this->drupalPostForm($field_configuration_url, $edit, t('Save settings')); // Check if an error message is shown. - $this->assertNoRaw(t('%name is not a valid number.', array('%name' => t('Minimum'))), 'Saved ' . gettype($minimum_value) . ' value as minimal value on a ' . $field->getType() . ' field'); + $this->assertNoRaw(t('%name is not a valid number.', ['%name' => t('Minimum')]), 'Saved ' . gettype($minimum_value) . ' value as minimal value on a ' . $field->getType() . ' field'); // Check if a success message is shown. - $this->assertRaw(t('Saved %label configuration.', array('%label' => $field->getLabel()))); + $this->assertRaw(t('Saved %label configuration.', ['%label' => $field->getLabel()])); // Check if the minimum value was actually set. $this->drupalGet($field_configuration_url); $this->assertFieldById('edit-settings-min', $minimum_value, 'Minimal ' . gettype($minimum_value) . ' value was set on a ' . $field->getType() . ' field.'); diff --git a/core/modules/field/src/Tests/String/StringFieldTest.php b/core/modules/field/src/Tests/String/StringFieldTest.php index 0ac57487759..6bd034d6130 100644 --- a/core/modules/field/src/Tests/String/StringFieldTest.php +++ b/core/modules/field/src/Tests/String/StringFieldTest.php @@ -20,7 +20,7 @@ class StringFieldTest extends WebTestBase { * * @var array */ - public static $modules = array('entity_test', 'file'); + public static $modules = ['entity_test', 'file']; /** * A user without any special permissions. @@ -32,7 +32,7 @@ class StringFieldTest extends WebTestBase { protected function setUp() { parent::setUp(); - $this->webUser = $this->drupalCreateUser(array('view test entity', 'administer entity_test content')); + $this->webUser = $this->drupalCreateUser(['view test entity', 'administer entity_test content']); $this->drupalLogin($this->webUser); } @@ -52,11 +52,11 @@ class StringFieldTest extends WebTestBase { function _testTextfieldWidgets($field_type, $widget_type) { // Create a field. $field_name = Unicode::strtolower($this->randomMachineName()); - $field_storage = FieldStorageConfig::create(array( + $field_storage = FieldStorageConfig::create([ 'field_name' => $field_name, 'entity_type' => 'entity_test', 'type' => $field_type - )); + ]); $field_storage->save(); FieldConfig::create([ 'field_storage' => $field_storage, @@ -64,12 +64,12 @@ class StringFieldTest extends WebTestBase { 'label' => $this->randomMachineName() . '_label', ])->save(); entity_get_form_display('entity_test', 'entity_test', 'default') - ->setComponent($field_name, array( + ->setComponent($field_name, [ 'type' => $widget_type, - 'settings' => array( + 'settings' => [ 'placeholder' => 'A placeholder on ' . $widget_type, - ), - )) + ], + ]) ->save(); entity_get_display('entity_test', 'entity_test', 'full') ->setComponent($field_name) @@ -79,17 +79,17 @@ class StringFieldTest extends WebTestBase { $this->drupalGet('entity_test/add'); $this->assertFieldByName("{$field_name}[0][value]", '', 'Widget is displayed'); $this->assertNoFieldByName("{$field_name}[0][format]", '1', 'Format selector is not displayed'); - $this->assertRaw(format_string('placeholder="A placeholder on @widget_type"', array('@widget_type' => $widget_type))); + $this->assertRaw(format_string('placeholder="A placeholder on @widget_type"', ['@widget_type' => $widget_type])); // Submit with some value. $value = $this->randomMachineName(); - $edit = array( + $edit = [ "{$field_name}[0][value]" => $value, - ); + ]; $this->drupalPostForm(NULL, $edit, t('Save')); preg_match('|entity_test/manage/(\d+)|', $this->url, $match); $id = $match[1]; - $this->assertText(t('entity_test @id has been created.', array('@id' => $id)), 'Entity was created'); + $this->assertText(t('entity_test @id has been created.', ['@id' => $id]), 'Entity was created'); // Display the entity. $entity = EntityTest::load($id); diff --git a/core/modules/field/src/Tests/Views/FieldTestBase.php b/core/modules/field/src/Tests/Views/FieldTestBase.php index 0f977a82c73..cd579943757 100644 --- a/core/modules/field/src/Tests/Views/FieldTestBase.php +++ b/core/modules/field/src/Tests/Views/FieldTestBase.php @@ -25,7 +25,7 @@ abstract class FieldTestBase extends ViewTestBase { * * @var array */ - public static $modules = array('node', 'field_test_views'); + public static $modules = ['node', 'field_test_views']; /** * Stores the field definitions used by the test. @@ -51,19 +51,19 @@ abstract class FieldTestBase extends ViewTestBase { 'name' => 'page', ])->save(); - ViewTestData::createTestViews(get_class($this), array('field_test_views')); + ViewTestData::createTestViews(get_class($this), ['field_test_views']); } function setUpFieldStorages($amount = 3, $type = 'string') { // Create three fields. - $field_names = array(); + $field_names = []; for ($i = 0; $i < $amount; $i++) { $field_names[$i] = 'field_name_' . $i; - $this->fieldStorages[$i] = FieldStorageConfig::create(array( + $this->fieldStorages[$i] = FieldStorageConfig::create([ 'field_name' => $field_names[$i], 'entity_type' => 'node', 'type' => $type, - )); + ]); $this->fieldStorages[$i]->save(); } return $field_names; diff --git a/core/modules/field/src/Tests/Views/FieldUITest.php b/core/modules/field/src/Tests/Views/FieldUITest.php index c47bf1962fe..ce8208ba65d 100644 --- a/core/modules/field/src/Tests/Views/FieldUITest.php +++ b/core/modules/field/src/Tests/Views/FieldUITest.php @@ -19,14 +19,14 @@ class FieldUITest extends FieldTestBase { * * @var array */ - public static $testViews = array('test_view_fieldapi'); + public static $testViews = ['test_view_fieldapi']; /** * Modules to enable. * * @var array */ - public static $modules = array('views_ui'); + public static $modules = ['views_ui']; /** * A user with the 'administer views' permission. @@ -41,7 +41,7 @@ class FieldUITest extends FieldTestBase { protected function setUp() { parent::setUp(); - $this->account = $this->drupalCreateUser(array('administer views')); + $this->account = $this->drupalCreateUser(['administer views']); $this->drupalLogin($this->account); $this->setUpFieldStorages(1, 'text'); @@ -56,26 +56,26 @@ class FieldUITest extends FieldTestBase { $this->drupalGet($url); // Tests the available formatter options. - $result = $this->xpath('//select[@id=:id]/option', array(':id' => 'edit-options-type')); + $result = $this->xpath('//select[@id=:id]/option', [':id' => 'edit-options-type']); $options = array_map(function($item) { return (string) $item->attributes()->value[0]; }, $result); // @todo Replace this sort by assertArray once it's in. sort($options, SORT_STRING); - $this->assertEqual($options, array('text_default', 'text_trimmed'), 'The text formatters for a simple text field appear as expected.'); + $this->assertEqual($options, ['text_default', 'text_trimmed'], 'The text formatters for a simple text field appear as expected.'); - $this->drupalPostForm(NULL, array('options[type]' => 'text_trimmed'), t('Apply')); + $this->drupalPostForm(NULL, ['options[type]' => 'text_trimmed'], t('Apply')); $this->drupalGet($url); $this->assertOptionSelected('edit-options-type', 'text_trimmed'); $random_number = rand(100, 400); - $this->drupalPostForm(NULL, array('options[settings][trim_length]' => $random_number), t('Apply')); + $this->drupalPostForm(NULL, ['options[settings][trim_length]' => $random_number], t('Apply')); $this->drupalGet($url); $this->assertFieldByName('options[settings][trim_length]', $random_number, 'The formatter setting got saved.'); // Save the view and test whether the settings are saved. - $this->drupalPostForm('admin/structure/views/view/test_view_fieldapi', array(), t('Save')); + $this->drupalPostForm('admin/structure/views/view/test_view_fieldapi', [], t('Save')); $view = Views::getView('test_view_fieldapi'); $view->initHandlers(); $this->assertEqual($view->field['field_name_0']->options['type'], 'text_trimmed'); @@ -101,7 +101,7 @@ class FieldUITest extends FieldTestBase { */ public function testHandlerUIAggregation() { // Enable aggregation. - $edit = array('group_by' => '1'); + $edit = ['group_by' => '1']; $this->drupalPostForm('admin/structure/views/nojs/display/test_view_fieldapi/default/group_by', $edit, t('Apply')); $url = "admin/structure/views/nojs/handler/test_view_fieldapi/default/field/field_name_0"; @@ -110,13 +110,13 @@ class FieldUITest extends FieldTestBase { // Test the click sort column options. // Tests the available formatter options. - $result = $this->xpath('//select[@id=:id]/option', array(':id' => 'edit-options-click-sort-column')); + $result = $this->xpath('//select[@id=:id]/option', [':id' => 'edit-options-click-sort-column']); $options = array_map(function($item) { return (string) $item->attributes()->value[0]; }, $result); sort($options, SORT_STRING); - $this->assertEqual($options, array('format', 'value'), 'The expected sort field options were found.'); + $this->assertEqual($options, ['format', 'value'], 'The expected sort field options were found.'); } /** @@ -138,7 +138,7 @@ class FieldUITest extends FieldTestBase { $field->save(); $url = "admin/structure/views/nojs/add-handler/test_view_fieldapi/default/filter"; - $this->drupalPostForm($url, ['name[node__' . $field_name . '.' . $field_name . '_value]' => TRUE], t('Add and configure @handler', array('@handler' => t('filter criteria')))); + $this->drupalPostForm($url, ['name[node__' . $field_name . '.' . $field_name . '_value]' => TRUE], t('Add and configure @handler', ['@handler' => t('filter criteria')])); $this->assertResponse(200); // Verify that using a boolean field as a filter also results in using the // boolean plugin. diff --git a/core/modules/field/src/Tests/Views/HandlerFieldFieldTest.php b/core/modules/field/src/Tests/Views/HandlerFieldFieldTest.php index 303eb2fd7e1..dfbb89bd209 100644 --- a/core/modules/field/src/Tests/Views/HandlerFieldFieldTest.php +++ b/core/modules/field/src/Tests/Views/HandlerFieldFieldTest.php @@ -22,14 +22,14 @@ class HandlerFieldFieldTest extends FieldTestBase { /** * {@inheritdoc} */ - public static $modules = array('node', 'field_test'); + public static $modules = ['node', 'field_test']; /** * Views used by this test. * * @var array */ - public static $testViews = array('test_view_fieldapi'); + public static $testViews = ['test_view_fieldapi']; /** * Test nodes. @@ -48,47 +48,47 @@ class HandlerFieldFieldTest extends FieldTestBase { $this->setUpFieldStorages(3); // Setup a field with cardinality > 1. - $this->fieldStorages[3] = FieldStorageConfig::create(array( + $this->fieldStorages[3] = FieldStorageConfig::create([ 'field_name' => 'field_name_3', 'entity_type' => 'node', 'type' => 'string', 'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED, - )); + ]); $this->fieldStorages[3]->save(); // Setup a field that will have no value. - $this->fieldStorages[4] = FieldStorageConfig::create(array( + $this->fieldStorages[4] = FieldStorageConfig::create([ 'field_name' => 'field_name_4', 'entity_type' => 'node', 'type' => 'string', 'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED, - )); + ]); $this->fieldStorages[4]->save(); // Setup a text field. - $this->fieldStorages[5] = FieldStorageConfig::create(array( + $this->fieldStorages[5] = FieldStorageConfig::create([ 'field_name' => 'field_name_5', 'entity_type' => 'node', 'type' => 'text', - )); + ]); $this->fieldStorages[5]->save(); // Setup a text field with access control. // @see field_test_entity_field_access() - $this->fieldStorages[6] = FieldStorageConfig::create(array( + $this->fieldStorages[6] = FieldStorageConfig::create([ 'field_name' => 'field_no_view_access', 'entity_type' => 'node', 'type' => 'text', - )); + ]); $this->fieldStorages[6]->save(); $this->setUpFields(); // Create some nodes. - $this->nodes = array(); + $this->nodes = []; for ($i = 0; $i < 3; $i++) { - $edit = array('type' => 'page'); + $edit = ['type' => 'page']; - foreach (array(0, 1, 2, 5) as $key) { + foreach ([0, 1, 2, 5] as $key) { $field_storage = $this->fieldStorages[$key]; $edit[$field_storage->getName()][0]['value'] = $this->randomMachineName(8); } @@ -98,7 +98,7 @@ class HandlerFieldFieldTest extends FieldTestBase { $edit[$this->fieldStorages[3]->getName()][$j]['value'] = $this->randomMachineName(8); } // Set this field to be empty. - $edit[$this->fieldStorages[4]->getName()] = array(array('value' => NULL)); + $edit[$this->fieldStorages[4]->getName()] = [['value' => NULL]]; $this->nodes[$i] = $this->drupalCreateNode($edit); } @@ -171,9 +171,9 @@ class HandlerFieldFieldTest extends FieldTestBase { $view = Views::getView('test_view_fieldapi'); $this->prepareView($view); $view->displayHandlers->get('default')->options['fields'][$this->fieldStorages[5]->getName()]['type'] = 'text_trimmed'; - $view->displayHandlers->get('default')->options['fields'][$this->fieldStorages[5]->getName()]['settings'] = array( + $view->displayHandlers->get('default')->options['fields'][$this->fieldStorages[5]->getName()]['settings'] = [ 'trim_length' => 3, - ); + ]; $this->executeView($view); // Make sure that the formatter works as expected. @@ -196,7 +196,7 @@ class HandlerFieldFieldTest extends FieldTestBase { for ($i = 0; $i < 3; $i++) { $rendered_field = $view->style_plugin->getField($i, $field_name); - $items = array(); + $items = []; $pure_items = $this->nodes[$i]->{$field_name}->getValue(); $pure_items = array_splice($pure_items, 0, 3); foreach ($pure_items as $j => $item) { @@ -218,7 +218,7 @@ class HandlerFieldFieldTest extends FieldTestBase { for ($i = 0; $i < 3; $i++) { $rendered_field = $view->style_plugin->getField($i, $field_name); - $items = array(); + $items = []; $pure_items = $this->nodes[$i]->{$field_name}->getValue(); $pure_items = array_splice($pure_items, 1, 3); foreach ($pure_items as $j => $item) { @@ -238,7 +238,7 @@ class HandlerFieldFieldTest extends FieldTestBase { for ($i = 0; $i < 3; $i++) { $rendered_field = $view->style_plugin->getField($i, $field_name); - $items = array(); + $items = []; $pure_items = $this->nodes[$i]->{$field_name}->getValue(); array_splice($pure_items, 0, -3); $pure_items = array_reverse($pure_items); @@ -259,7 +259,7 @@ class HandlerFieldFieldTest extends FieldTestBase { for ($i = 0; $i < 3; $i++) { $rendered_field = $view->style_plugin->getField($i, $field_name); - $items = array(); + $items = []; $pure_items = $this->nodes[$i]->{$field_name}->getValue(); $items[] = $pure_items[0]['value']; $items[] = $pure_items[4]['value']; @@ -277,7 +277,7 @@ class HandlerFieldFieldTest extends FieldTestBase { for ($i = 0; $i < 3; $i++) { $rendered_field = $view->style_plugin->getField($i, $field_name); - $items = array(); + $items = []; $pure_items = $this->nodes[$i]->{$field_name}->getValue(); $pure_items = array_splice($pure_items, 0, 3); foreach ($pure_items as $j => $item) { diff --git a/core/modules/field/src/Tests/reEnableModuleFieldTest.php b/core/modules/field/src/Tests/reEnableModuleFieldTest.php index b718e75883c..141b5e12bad 100644 --- a/core/modules/field/src/Tests/reEnableModuleFieldTest.php +++ b/core/modules/field/src/Tests/reEnableModuleFieldTest.php @@ -18,22 +18,22 @@ class reEnableModuleFieldTest extends WebTestBase { * * @var array */ - public static $modules = array( + public static $modules = [ 'field', 'node', // We use telephone module instead of test_field because test_field is // hidden and does not display on the admin/modules page. 'telephone' - ); + ]; protected function setUp() { parent::setUp(); - $this->drupalCreateContentType(array('type' => 'article')); - $this->drupalLogin($this->drupalCreateUser(array( + $this->drupalCreateContentType(['type' => 'article']); + $this->drupalLogin($this->drupalCreateUser([ 'create article content', 'edit own article content', - ))); + ])); } /** @@ -44,11 +44,11 @@ class reEnableModuleFieldTest extends WebTestBase { function testReEnabledField() { // Add a telephone field to the article content type. - $field_storage = FieldStorageConfig::create(array( + $field_storage = FieldStorageConfig::create([ 'field_name' => 'field_telephone', 'entity_type' => 'node', 'type' => 'telephone', - )); + ]); $field_storage->save(); FieldConfig::create([ 'field_storage' => $field_storage, @@ -57,19 +57,19 @@ class reEnableModuleFieldTest extends WebTestBase { ])->save(); entity_get_form_display('node', 'article', 'default') - ->setComponent('field_telephone', array( + ->setComponent('field_telephone', [ 'type' => 'telephone_default', - 'settings' => array( + 'settings' => [ 'placeholder' => '123-456-7890', - ), - )) + ], + ]) ->save(); entity_get_display('node', 'article', 'default') - ->setComponent('field_telephone', array( + ->setComponent('field_telephone', [ 'type' => 'telephone_link', 'weight' => 1, - )) + ]) ->save(); // Display the article node form and verify the telephone widget is present. @@ -78,16 +78,16 @@ class reEnableModuleFieldTest extends WebTestBase { // Submit an article node with a telephone field so data exist for the // field. - $edit = array( + $edit = [ 'title[0][value]' => $this->randomMachineName(), 'field_telephone[0][value]' => "123456789", - ); + ]; $this->drupalPostForm(NULL, $edit, t('Save')); $this->assertRaw('<a href="tel:123456789">'); // Test that the module can't be uninstalled from the UI while there is data // for it's fields. - $admin_user = $this->drupalCreateUser(array('access administration pages', 'administer modules')); + $admin_user = $this->drupalCreateUser(['access administration pages', 'administer modules']); $this->drupalLogin($admin_user); $this->drupalGet('admin/modules/uninstall'); $this->assertText("The Telephone number field type is used in the following field: node.field_telephone"); @@ -95,11 +95,11 @@ class reEnableModuleFieldTest extends WebTestBase { // Add another telephone field to a different entity type in order to test // the message for the case when multiple fields are blocking the // uninstallation of a module. - $field_storage2 = entity_create('field_storage_config', array( + $field_storage2 = entity_create('field_storage_config', [ 'field_name' => 'field_telephone_2', 'entity_type' => 'user', 'type' => 'telephone', - )); + ]); $field_storage2->save(); FieldConfig::create([ 'field_storage' => $field_storage2, diff --git a/core/modules/field/tests/modules/field_test/field_test.entity.inc b/core/modules/field/tests/modules/field_test/field_test.entity.inc index d5614acd8ea..ee831ff2b60 100644 --- a/core/modules/field/tests/modules/field_test/field_test.entity.inc +++ b/core/modules/field/tests/modules/field_test/field_test.entity.inc @@ -19,7 +19,7 @@ function field_test_entity_type_alter(array &$entity_types) { * Helper function to enable entity translations. */ function field_test_entity_info_translatable($entity_type_id = NULL, $translatable = NULL) { - $stored_value = &drupal_static(__FUNCTION__, array()); + $stored_value = &drupal_static(__FUNCTION__, []); if (isset($entity_type_id)) { $entity_manager = \Drupal::entityManager(); $original = $entity_manager->getDefinition($entity_type_id); diff --git a/core/modules/field/tests/modules/field_test/field_test.field.inc b/core/modules/field/tests/modules/field_test/field_test.field.inc index 9798fc745ac..5edd25d7636 100644 --- a/core/modules/field/tests/modules/field_test/field_test.field.inc +++ b/core/modules/field/tests/modules/field_test/field_test.field.inc @@ -34,7 +34,7 @@ function field_test_field_storage_config_update_forbid(FieldStorageConfigInterfa * Sample 'default value' callback. */ function field_test_default_value(FieldableEntityInterface $entity, FieldDefinitionInterface $definition) { - return array(array('value' => 99)); + return [['value' => 99]]; } /** diff --git a/core/modules/field/tests/modules/field_test/field_test.module b/core/modules/field/tests/modules/field_test/field_test.module index 7eda2885272..f81983637fb 100644 --- a/core/modules/field/tests/modules/field_test/field_test.module +++ b/core/modules/field/tests/modules/field_test/field_test.module @@ -66,7 +66,7 @@ function field_test_memorize($key = NULL, $value = NULL) { if (!isset($key)) { $return = $memorize; - $memorize = array(); + $memorize = []; return $return; } if (is_array($memorize)) { @@ -88,11 +88,11 @@ function field_test_field_storage_config_create(FieldStorageConfigInterface $fie function field_test_entity_display_build_alter(&$output, $context) { $display_options = $context['display']->getComponent('test_field'); if (isset($display_options['settings']['alter'])) { - $output['test_field'][] = array('#markup' => 'field_test_entity_display_build_alter'); + $output['test_field'][] = ['#markup' => 'field_test_entity_display_build_alter']; } if (isset($output['test_field'])) { - $output['test_field'][] = array('#markup' => 'entity language is ' . $context['entity']->language()->getId()); + $output['test_field'][] = ['#markup' => 'entity language is ' . $context['entity']->language()->getId()]; } } diff --git a/core/modules/field/tests/modules/field_test/src/Form/NestedEntityTestForm.php b/core/modules/field/tests/modules/field_test/src/Form/NestedEntityTestForm.php index d54c6836fdf..949ffda667d 100644 --- a/core/modules/field/tests/modules/field_test/src/Form/NestedEntityTestForm.php +++ b/core/modules/field/tests/modules/field_test/src/Form/NestedEntityTestForm.php @@ -54,11 +54,11 @@ class NestedEntityTestForm extends FormBase { ]; } - $form['save'] = array( + $form['save'] = [ '#type' => 'submit', '#value' => t('Save'), '#weight' => 100, - ); + ]; return $form; } @@ -101,7 +101,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.', array('@id_1' => $entity_1->id(), '@id_2' => $entity_2->id()))); + 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()])); } } diff --git a/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldFormatter/TestFieldApplicableFormatter.php b/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldFormatter/TestFieldApplicableFormatter.php index c2916f5d68c..418b4c6b245 100644 --- a/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldFormatter/TestFieldApplicableFormatter.php +++ b/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldFormatter/TestFieldApplicableFormatter.php @@ -34,7 +34,7 @@ class TestFieldApplicableFormatter extends FormatterBase { * {@inheritdoc} */ public function viewElements(FieldItemListInterface $items, $langcode) { - return array('#markup' => 'Nothing to see here'); + return ['#markup' => 'Nothing to see here']; } } diff --git a/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldFormatter/TestFieldDefaultFormatter.php b/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldFormatter/TestFieldDefaultFormatter.php index 5eb0354aefe..80f860bfafd 100644 --- a/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldFormatter/TestFieldDefaultFormatter.php +++ b/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldFormatter/TestFieldDefaultFormatter.php @@ -26,22 +26,22 @@ class TestFieldDefaultFormatter extends FormatterBase { * {@inheritdoc} */ public static function defaultSettings() { - return array( + return [ 'test_formatter_setting' => 'dummy test string', - ) + parent::defaultSettings(); + ] + parent::defaultSettings(); } /** * {@inheritdoc} */ public function settingsForm(array $form, FormStateInterface $form_state) { - $element['test_formatter_setting'] = array( + $element['test_formatter_setting'] = [ '#title' => t('Setting'), '#type' => 'textfield', '#size' => 20, '#default_value' => $this->getSetting('test_formatter_setting'), '#required' => TRUE, - ); + ]; return $element; } @@ -49,8 +49,8 @@ class TestFieldDefaultFormatter extends FormatterBase { * {@inheritdoc} */ public function settingsSummary() { - $summary = array(); - $summary[] = t('@setting: @value', array('@setting' => 'test_formatter_setting', '@value' => $this->getSetting('test_formatter_setting'))); + $summary = []; + $summary[] = t('@setting: @value', ['@setting' => 'test_formatter_setting', '@value' => $this->getSetting('test_formatter_setting')]); return $summary; } @@ -58,10 +58,10 @@ class TestFieldDefaultFormatter extends FormatterBase { * {@inheritdoc} */ public function viewElements(FieldItemListInterface $items, $langcode) { - $elements = array(); + $elements = []; foreach ($items as $delta => $item) { - $elements[$delta] = array('#markup' => $this->getSetting('test_formatter_setting') . '|' . $item->value); + $elements[$delta] = ['#markup' => $this->getSetting('test_formatter_setting') . '|' . $item->value]; } return $elements; diff --git a/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldFormatter/TestFieldEmptyFormatter.php b/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldFormatter/TestFieldEmptyFormatter.php index bbe0b308119..c8072177f16 100644 --- a/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldFormatter/TestFieldEmptyFormatter.php +++ b/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldFormatter/TestFieldEmptyFormatter.php @@ -23,25 +23,25 @@ class TestFieldEmptyFormatter extends FormatterBase { * {@inheritdoc} */ public static function defaultSettings() { - return array( + return [ 'test_empty_string' => '**EMPTY FIELD**', - ) + parent::defaultSettings(); + ] + parent::defaultSettings(); } /** * {@inheritdoc} */ public function viewElements(FieldItemListInterface $items, $langcode) { - $elements = array(); + $elements = []; if ($items->isEmpty()) { // For fields with no value, just add the configured "empty" value. - $elements[0] = array('#markup' => $this->getSetting('test_empty_string')); + $elements[0] = ['#markup' => $this->getSetting('test_empty_string')]; } else { foreach ($items as $delta => $item) { // This formatter only needs to output raw for testing. - $elements[$delta] = array('#markup' => $item->value); + $elements[$delta] = ['#markup' => $item->value]; } } diff --git a/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldFormatter/TestFieldEmptySettingFormatter.php b/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldFormatter/TestFieldEmptySettingFormatter.php index ca088610835..f36fea2c391 100644 --- a/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldFormatter/TestFieldEmptySettingFormatter.php +++ b/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldFormatter/TestFieldEmptySettingFormatter.php @@ -24,22 +24,22 @@ class TestFieldEmptySettingFormatter extends FormatterBase { * {@inheritdoc} */ public static function defaultSettings() { - return array( + return [ 'field_empty_setting' => '', - ) + parent::defaultSettings(); + ] + parent::defaultSettings(); } /** * {@inheritdoc} */ public function settingsForm(array $form, FormStateInterface $form_state) { - $element['field_empty_setting'] = array( + $element['field_empty_setting'] = [ '#title' => t('Setting'), '#type' => 'textfield', '#size' => 20, '#default_value' => $this->getSetting('field_empty_setting'), '#required' => TRUE, - ); + ]; return $element; } @@ -47,7 +47,7 @@ class TestFieldEmptySettingFormatter extends FormatterBase { * {@inheritdoc} */ public function settingsSummary() { - $summary = array(); + $summary = []; $setting = $this->getSetting('field_empty_setting'); if (!empty($setting)) { $summary[] = t('Default empty setting now has a value.'); @@ -59,11 +59,11 @@ class TestFieldEmptySettingFormatter extends FormatterBase { * {@inheritdoc} */ public function viewElements(FieldItemListInterface $items, $langcode) { - $elements = array(); + $elements = []; if (!empty($items)) { foreach ($items as $delta => $item) { - $elements[$delta] = array('#markup' => $this->getSetting('field_empty_setting')); + $elements[$delta] = ['#markup' => $this->getSetting('field_empty_setting')]; } } diff --git a/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldFormatter/TestFieldMultipleFormatter.php b/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldFormatter/TestFieldMultipleFormatter.php index 97bb1e63622..978e18fbac6 100644 --- a/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldFormatter/TestFieldMultipleFormatter.php +++ b/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldFormatter/TestFieldMultipleFormatter.php @@ -26,23 +26,23 @@ class TestFieldMultipleFormatter extends FormatterBase { * {@inheritdoc} */ public static function defaultSettings() { - return array( + return [ 'test_formatter_setting_multiple' => 'dummy test string', 'alter' => FALSE, - ) + parent::defaultSettings(); + ] + parent::defaultSettings(); } /** * {@inheritdoc} */ public function settingsForm(array $form, FormStateInterface $form_state) { - $element['test_formatter_setting_multiple'] = array( + $element['test_formatter_setting_multiple'] = [ '#title' => t('Setting'), '#type' => 'textfield', '#size' => 20, '#default_value' => $this->getSetting('test_formatter_setting_multiple'), '#required' => TRUE, - ); + ]; return $element; } @@ -50,8 +50,8 @@ class TestFieldMultipleFormatter extends FormatterBase { * {@inheritdoc} */ public function settingsSummary() { - $summary = array(); - $summary[] = t('@setting: @value', array('@setting' => 'test_formatter_setting_multiple', '@value' => $this->getSetting('test_formatter_setting_multiple'))); + $summary = []; + $summary[] = t('@setting: @value', ['@setting' => 'test_formatter_setting_multiple', '@value' => $this->getSetting('test_formatter_setting_multiple')]); return $summary; } @@ -59,14 +59,14 @@ class TestFieldMultipleFormatter extends FormatterBase { * {@inheritdoc} */ public function viewElements(FieldItemListInterface $items, $langcode) { - $elements = array(); + $elements = []; if (!empty($items)) { - $array = array(); + $array = []; foreach ($items as $delta => $item) { $array[] = $delta . ':' . $item->value; } - $elements[0] = array('#markup' => $this->getSetting('test_formatter_setting_multiple') . '|' . implode('|', $array)); + $elements[0] = ['#markup' => $this->getSetting('test_formatter_setting_multiple') . '|' . implode('|', $array)]; } return $elements; diff --git a/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldFormatter/TestFieldNoSettingsFormatter.php b/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldFormatter/TestFieldNoSettingsFormatter.php index 0ab66d5dd25..922207e51bd 100644 --- a/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldFormatter/TestFieldNoSettingsFormatter.php +++ b/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldFormatter/TestFieldNoSettingsFormatter.php @@ -23,11 +23,11 @@ class TestFieldNoSettingsFormatter extends FormatterBase { * {@inheritdoc} */ public function viewElements(FieldItemListInterface $items, $langcode) { - $elements = array(); + $elements = []; foreach ($items as $delta => $item) { // This formatter only needs to output raw for testing. - $elements[$delta] = array('#markup' => $item->value); + $elements[$delta] = ['#markup' => $item->value]; } return $elements; diff --git a/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldFormatter/TestFieldPrepareViewFormatter.php b/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldFormatter/TestFieldPrepareViewFormatter.php index f7df0c0c2f0..39bff8d8773 100644 --- a/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldFormatter/TestFieldPrepareViewFormatter.php +++ b/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldFormatter/TestFieldPrepareViewFormatter.php @@ -25,22 +25,22 @@ class TestFieldPrepareViewFormatter extends FormatterBase { * {@inheritdoc} */ public static function defaultSettings() { - return array( + return [ 'test_formatter_setting_additional' => 'dummy test string', - ) + parent::defaultSettings(); + ] + parent::defaultSettings(); } /** * {@inheritdoc} */ public function settingsForm(array $form, FormStateInterface $form_state) { - $element['test_formatter_setting_additional'] = array( + $element['test_formatter_setting_additional'] = [ '#title' => t('Setting'), '#type' => 'textfield', '#size' => 20, '#default_value' => $this->getSetting('test_formatter_setting_additional'), '#required' => TRUE, - ); + ]; return $element; } @@ -48,8 +48,8 @@ class TestFieldPrepareViewFormatter extends FormatterBase { * {@inheritdoc} */ public function settingsSummary() { - $summary = array(); - $summary[] = t('@setting: @value', array('@setting' => 'test_formatter_setting_additional', '@value' => $this->getSetting('test_formatter_setting_additional'))); + $summary = []; + $summary[] = t('@setting: @value', ['@setting' => 'test_formatter_setting_additional', '@value' => $this->getSetting('test_formatter_setting_additional')]); return $summary; } @@ -71,10 +71,10 @@ class TestFieldPrepareViewFormatter extends FormatterBase { * {@inheritdoc} */ public function viewElements(FieldItemListInterface $items, $langcode) { - $elements = array(); + $elements = []; foreach ($items as $delta => $item) { - $elements[$delta] = array('#markup' => $this->getSetting('test_formatter_setting_additional') . '|' . $item->value . '|' . $item->additional_formatter_value); + $elements[$delta] = ['#markup' => $this->getSetting('test_formatter_setting_additional') . '|' . $item->value . '|' . $item->additional_formatter_value]; } return $elements; diff --git a/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldType/TestItem.php b/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldType/TestItem.php index 1b8822f60f4..2f678798a2e 100644 --- a/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldType/TestItem.php +++ b/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldType/TestItem.php @@ -24,22 +24,22 @@ class TestItem extends FieldItemBase { * {@inheritdoc} */ public static function defaultStorageSettings() { - return array( + return [ 'test_field_storage_setting' => 'dummy test string', 'changeable' => 'a changeable field storage setting', 'unchangeable' => 'an unchangeable field storage setting', 'translatable_storage_setting' => 'a translatable field storage setting', - ) + parent::defaultStorageSettings(); + ] + parent::defaultStorageSettings(); } /** * {@inheritdoc} */ public static function defaultFieldSettings() { - return array( + return [ 'test_field_setting' => 'dummy test string', 'translatable_field_setting' => 'a translatable field setting', - ) + parent::defaultFieldSettings(); + ] + parent::defaultFieldSettings(); } /** @@ -57,30 +57,30 @@ class TestItem extends FieldItemBase { * {@inheritdoc} */ public static function schema(FieldStorageDefinitionInterface $field_definition) { - return array( - 'columns' => array( - 'value' => array( + return [ + 'columns' => [ + 'value' => [ 'type' => 'int', 'size' => 'medium', - ), - ), - 'indexes' => array( - 'value' => array('value'), - ), - ); + ], + ], + 'indexes' => [ + 'value' => ['value'], + ], + ]; } /** * {@inheritdoc} */ public function storageSettingsForm(array &$form, FormStateInterface $form_state, $has_data) { - $form['test_field_storage_setting'] = array( + $form['test_field_storage_setting'] = [ '#type' => 'textfield', '#title' => t('Field test field storage setting'), '#default_value' => $this->getSetting('test_field_storage_setting'), '#required' => FALSE, '#description' => t('A dummy form element to simulate field storage setting.'), - ); + ]; return $form; } @@ -89,13 +89,13 @@ class TestItem extends FieldItemBase { * {@inheritdoc} */ public function fieldSettingsForm(array $form, FormStateInterface $form_state) { - $form['test_field_setting'] = array( + $form['test_field_setting'] = [ '#type' => 'textfield', '#title' => t('Field test field setting'), '#default_value' => $this->getSetting('test_field_setting'), '#required' => FALSE, '#description' => t('A dummy form element to simulate field setting.'), - ); + ]; return $form; } @@ -105,7 +105,7 @@ class TestItem extends FieldItemBase { */ public function delete() { // Reports that delete() method is executed for testing purposes. - field_test_memorize('field_test_field_delete', array($this->getEntity())); + field_test_memorize('field_test_field_delete', [$this->getEntity()]); } /** @@ -115,14 +115,14 @@ class TestItem extends FieldItemBase { $constraint_manager = \Drupal::typedDataManager()->getValidationConstraintManager(); $constraints = parent::getConstraints(); - $constraints[] = $constraint_manager->create('ComplexData', array( - 'value' => array( - 'TestField' => array( + $constraints[] = $constraint_manager->create('ComplexData', [ + 'value' => [ + 'TestField' => [ 'value' => -1, - 'message' => t('%name does not accept the value @value.', array('%name' => $this->getFieldDefinition()->getLabel(), '@value' => -1)), - ) - ), - )); + 'message' => t('%name does not accept the value @value.', ['%name' => $this->getFieldDefinition()->getLabel(), '@value' => -1]), + ] + ], + ]); return $constraints; } diff --git a/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldWidget/TestFieldWidget.php b/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldWidget/TestFieldWidget.php index 14a5b3ccf2a..9dd3387e5aa 100644 --- a/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldWidget/TestFieldWidget.php +++ b/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldWidget/TestFieldWidget.php @@ -27,24 +27,24 @@ class TestFieldWidget extends WidgetBase { * {@inheritdoc} */ public static function defaultSettings() { - return array( + return [ 'test_widget_setting' => 'dummy test string', 'role' => 'anonymous', 'role2' => 'anonymous', - ) + parent::defaultSettings(); + ] + parent::defaultSettings(); } /** * {@inheritdoc} */ public function settingsForm(array $form, FormStateInterface $form_state) { - $element['test_widget_setting'] = array( + $element['test_widget_setting'] = [ '#type' => 'textfield', '#title' => t('Field test field widget setting'), '#description' => t('A dummy form element to simulate field widget setting.'), '#default_value' => $this->getSetting('test_widget_setting'), '#required' => FALSE, - ); + ]; return $element; } @@ -52,8 +52,8 @@ class TestFieldWidget extends WidgetBase { * {@inheritdoc} */ public function settingsSummary() { - $summary = array(); - $summary[] = t('@setting: @value', array('@setting' => 'test_widget_setting', '@value' => $this->getSetting('test_widget_setting'))); + $summary = []; + $summary[] = t('@setting: @value', ['@setting' => 'test_widget_setting', '@value' => $this->getSetting('test_widget_setting')]); return $summary; } @@ -61,11 +61,11 @@ class TestFieldWidget extends WidgetBase { * {@inheritdoc} */ public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) { - $element += array( + $element += [ '#type' => 'textfield', '#default_value' => isset($items[$delta]->value) ? $items[$delta]->value : '', - ); - return array('value' => $element); + ]; + return ['value' => $element]; } /** diff --git a/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldWidget/TestFieldWidgetMultiple.php b/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldWidget/TestFieldWidgetMultiple.php index 02f2d24cbe5..32cf6e4c5be 100644 --- a/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldWidget/TestFieldWidgetMultiple.php +++ b/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldWidget/TestFieldWidgetMultiple.php @@ -29,22 +29,22 @@ class TestFieldWidgetMultiple extends WidgetBase { * {@inheritdoc} */ public static function defaultSettings() { - return array( + return [ 'test_widget_setting_multiple' => 'dummy test string', - ) + parent::defaultSettings(); + ] + parent::defaultSettings(); } /** * {@inheritdoc} */ public function settingsForm(array $form, FormStateInterface $form_state) { - $element['test_widget_setting_multiple'] = array( + $element['test_widget_setting_multiple'] = [ '#type' => 'textfield', '#title' => t('Field test field widget setting'), '#description' => t('A dummy form element to simulate field widget setting.'), '#default_value' => $this->getSetting('test_widget_setting_multiple'), '#required' => FALSE, - ); + ]; return $element; } @@ -52,8 +52,8 @@ class TestFieldWidgetMultiple extends WidgetBase { * {@inheritdoc} */ public function settingsSummary() { - $summary = array(); - $summary[] = t('@setting: @value', array('@setting' => 'test_widget_setting_multiple', '@value' => $this->getSetting('test_widget_setting_multiple'))); + $summary = []; + $summary[] = t('@setting: @value', ['@setting' => 'test_widget_setting_multiple', '@value' => $this->getSetting('test_widget_setting_multiple')]); return $summary; } @@ -61,15 +61,15 @@ class TestFieldWidgetMultiple extends WidgetBase { * {@inheritdoc} */ public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) { - $values = array(); + $values = []; foreach ($items as $item) { $values[] = $item->value; } - $element += array( + $element += [ '#type' => 'textfield', '#default_value' => implode(', ', $values), - '#element_validate' => array(array(get_class($this), 'multipleValidate')), - ); + '#element_validate' => [[get_class($this), 'multipleValidate']], + ]; return $element; } @@ -85,9 +85,9 @@ class TestFieldWidgetMultiple extends WidgetBase { */ public static function multipleValidate($element, FormStateInterface $form_state) { $values = array_map('trim', explode(',', $element['#value'])); - $items = array(); + $items = []; foreach ($values as $value) { - $items[] = array('value' => $value); + $items[] = ['value' => $value]; } $form_state->setValueForElement($element, $items); } diff --git a/core/modules/field/tests/modules/field_test/src/Plugin/Validation/Constraint/TestFieldConstraint.php b/core/modules/field/tests/modules/field_test/src/Plugin/Validation/Constraint/TestFieldConstraint.php index 8a511ed3e58..8105a22be78 100644 --- a/core/modules/field/tests/modules/field_test/src/Plugin/Validation/Constraint/TestFieldConstraint.php +++ b/core/modules/field/tests/modules/field_test/src/Plugin/Validation/Constraint/TestFieldConstraint.php @@ -19,7 +19,7 @@ class TestFieldConstraint extends NotEqualTo { * {@inheritdoc} */ public function getRequiredOptions() { - return array('value'); + return ['value']; } /** diff --git a/core/modules/field/tests/modules/field_third_party_test/field_third_party_test.module b/core/modules/field/tests/modules/field_third_party_test/field_third_party_test.module index 9dc2b193630..d59a0c036f9 100644 --- a/core/modules/field/tests/modules/field_third_party_test/field_third_party_test.module +++ b/core/modules/field/tests/modules/field_third_party_test/field_third_party_test.module @@ -14,11 +14,11 @@ use Drupal\Core\Form\FormStateInterface; * Implements hook_field_widget_third_party_settings_form(). */ function field_third_party_test_field_widget_third_party_settings_form(WidgetInterface $plugin, FieldDefinitionInterface $field_definition, $form_mode, $form, FormStateInterface $form_state) { - $element['field_test_widget_third_party_settings_form'] = array( + $element['field_test_widget_third_party_settings_form'] = [ '#type' => 'textfield', '#title' => t('3rd party widget settings form'), '#default_value' => $plugin->getThirdPartySetting('field_third_party_test', 'field_test_widget_third_party_settings_form'), - ); + ]; return $element; } @@ -34,11 +34,11 @@ function field_third_party_test_field_widget_settings_summary_alter(&$summary, $ * Implements hook_field_formatter_third_party_settings_form(). */ function field_third_party_test_field_formatter_third_party_settings_form(FormatterInterface $plugin, FieldDefinitionInterface $field_definition, $view_mode, $form, FormStateInterface $form_state) { - $element['field_test_field_formatter_third_party_settings_form'] = array( + $element['field_test_field_formatter_third_party_settings_form'] = [ '#type' => 'textfield', '#title' => t('3rd party formatter settings form'), '#default_value' => $plugin->getThirdPartySetting('field_third_party_test', 'field_test_field_formatter_third_party_settings_form'), - ); + ]; return $element; } diff --git a/core/modules/field/tests/src/Functional/EntityReference/EntityReferenceAutoCreateTest.php b/core/modules/field/tests/src/Functional/EntityReference/EntityReferenceAutoCreateTest.php index b2a165520e3..90895b186f0 100644 --- a/core/modules/field/tests/src/Functional/EntityReference/EntityReferenceAutoCreateTest.php +++ b/core/modules/field/tests/src/Functional/EntityReference/EntityReferenceAutoCreateTest.php @@ -46,43 +46,43 @@ class EntityReferenceAutoCreateTest extends BrowserTestBase { $referenced = $this->drupalCreateContentType(); $this->referencedType = $referenced->id(); - FieldStorageConfig::create(array( + FieldStorageConfig::create([ 'field_name' => 'test_field', 'entity_type' => 'node', 'translatable' => FALSE, - 'entity_types' => array(), - 'settings' => array( + 'entity_types' => [], + 'settings' => [ 'target_type' => 'node', - ), + ], 'type' => 'entity_reference', 'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED, - ))->save(); + ])->save(); FieldConfig::create([ 'label' => 'Entity reference field', 'field_name' => 'test_field', 'entity_type' => 'node', 'bundle' => $referencing->id(), - 'settings' => array( + 'settings' => [ 'handler' => 'default', - 'handler_settings' => array( + 'handler_settings' => [ // Reference a single vocabulary. - 'target_bundles' => array( + 'target_bundles' => [ $referenced->id(), - ), + ], // Enable auto-create. 'auto_create' => TRUE, - ), - ), + ], + ], ])->save(); entity_get_display('node', $referencing->id(), 'default') ->setComponent('test_field') ->save(); entity_get_form_display('node', $referencing->id(), 'default') - ->setComponent('test_field', array( + ->setComponent('test_field', [ 'type' => 'entity_reference_autocomplete', - )) + ]) ->save(); $account = $this->drupalCreateUser(['access content', "create $this->referencingType content"]); @@ -109,10 +109,10 @@ class EntityReferenceAutoCreateTest extends BrowserTestBase { $result = $query->execute(); $this->assertFalse($result, 'Referenced node does not exist yet.'); - $edit = array( + $edit = [ 'title[0][value]' => $this->randomMachineName(), 'test_field[0][target_id]' => $new_title, - ); + ]; $this->drupalPostForm("node/add/$this->referencingType", $edit, 'Save'); // Assert referenced node was created. diff --git a/core/modules/field/tests/src/Functional/EntityReference/EntityReferenceFieldDefaultValueTest.php b/core/modules/field/tests/src/Functional/EntityReference/EntityReferenceFieldDefaultValueTest.php index 5af26f12467..2f55cd54c30 100644 --- a/core/modules/field/tests/src/Functional/EntityReference/EntityReferenceFieldDefaultValueTest.php +++ b/core/modules/field/tests/src/Functional/EntityReference/EntityReferenceFieldDefaultValueTest.php @@ -36,11 +36,11 @@ class EntityReferenceFieldDefaultValueTest extends BrowserTestBase { parent::setUp(); // Create default content type. - $this->drupalCreateContentType(array('type' => 'reference_content')); - $this->drupalCreateContentType(array('type' => 'referenced_content')); + $this->drupalCreateContentType(['type' => 'reference_content']); + $this->drupalCreateContentType(['type' => 'referenced_content']); // Create admin user. - $this->adminUser = $this->drupalCreateUser(array('access content', 'administer content types', 'administer node fields', 'administer node form display', 'bypass node access')); + $this->adminUser = $this->drupalCreateUser(['access content', 'administer content types', 'administer node fields', 'administer node form display', 'bypass node access']); $this->drupalLogin($this->adminUser); } @@ -49,33 +49,33 @@ class EntityReferenceFieldDefaultValueTest extends BrowserTestBase { */ function testEntityReferenceDefaultValue() { // Create a node to be referenced. - $referenced_node = $this->drupalCreateNode(array('type' => 'referenced_content')); + $referenced_node = $this->drupalCreateNode(['type' => 'referenced_content']); $field_name = Unicode::strtolower($this->randomMachineName()); - $field_storage = FieldStorageConfig::create(array( + $field_storage = FieldStorageConfig::create([ 'field_name' => $field_name, 'entity_type' => 'node', 'type' => 'entity_reference', - 'settings' => array('target_type' => 'node'), - )); + 'settings' => ['target_type' => 'node'], + ]); $field_storage->save(); $field = FieldConfig::create([ 'field_storage' => $field_storage, 'bundle' => 'reference_content', - 'settings' => array( + 'settings' => [ 'handler' => 'default', - 'handler_settings' => array( - 'target_bundles' => array('referenced_content'), - 'sort' => array('field' => '_none'), - ), - ), + 'handler_settings' => [ + 'target_bundles' => ['referenced_content'], + 'sort' => ['field' => '_none'], + ], + ], ]); $field->save(); // Set created node as default_value. - $field_edit = array( + $field_edit = [ 'default_value_input[' . $field_name . '][0][target_id]' => $referenced_node->getTitle() . ' (' . $referenced_node->id() . ')', - ); + ]; $this->drupalPostForm('admin/structure/types/manage/reference_content/fields/node.reference_content.' . $field_name, $field_edit, t('Save settings')); // Check that default value is selected in default value form. @@ -88,7 +88,7 @@ class EntityReferenceFieldDefaultValueTest extends BrowserTestBase { $this->assertEqual($config_entity['default_value'][0]['target_uuid'], $referenced_node->uuid(), 'Content uuid and config entity uuid are the same'); // Ensure the configuration has the expected dependency on the entity that // is being used a default value. - $this->assertEqual(array($referenced_node->getConfigDependencyName()), $config_entity['dependencies']['content']); + $this->assertEqual([$referenced_node->getConfigDependencyName()], $config_entity['dependencies']['content']); // Clear field definitions cache in order to avoid stale cache values. \Drupal::entityManager()->clearCachedFieldDefinitions(); @@ -111,35 +111,35 @@ class EntityReferenceFieldDefaultValueTest extends BrowserTestBase { */ function testEntityReferenceDefaultConfigValue() { // Create a node to be referenced. - $referenced_node_type = $this->drupalCreateContentType(array('type' => 'referenced_config_to_delete')); - $referenced_node_type2 = $this->drupalCreateContentType(array('type' => 'referenced_config_to_preserve')); + $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_storage = FieldStorageConfig::create(array( + $field_storage = FieldStorageConfig::create([ 'field_name' => $field_name, 'entity_type' => 'node', 'type' => 'entity_reference', - 'settings' => array('target_type' => 'node_type'), + 'settings' => ['target_type' => 'node_type'], 'cardinality' => FieldStorageConfig::CARDINALITY_UNLIMITED, - )); + ]); $field_storage->save(); $field = FieldConfig::create([ 'field_storage' => $field_storage, 'bundle' => 'reference_content', - 'settings' => array( + 'settings' => [ 'handler' => 'default', - 'handler_settings' => array( - 'sort' => array('field' => '_none'), - ), - ), + 'handler_settings' => [ + 'sort' => ['field' => '_none'], + ], + ], ]); $field->save(); // Set created node as default_value. - $field_edit = array( + $field_edit = [ 'default_value_input[' . $field_name . '][0][target_id]' => $referenced_node_type->label() . ' (' . $referenced_node_type->id() . ')', 'default_value_input[' . $field_name . '][1][target_id]' => $referenced_node_type2->label() . ' (' . $referenced_node_type2->id() . ')', - ); + ]; $this->drupalPostForm('admin/structure/types/manage/reference_content/fields/node.reference_content.' . $field_name, $field_edit, t('Save settings')); // Check that the field has a dependency on the default value. diff --git a/core/modules/field/tests/src/Functional/EntityReference/EntityReferenceFieldTranslatedReferenceViewTest.php b/core/modules/field/tests/src/Functional/EntityReference/EntityReferenceFieldTranslatedReferenceViewTest.php index 52dde091ddd..889bd1aca0d 100644 --- a/core/modules/field/tests/src/Functional/EntityReference/EntityReferenceFieldTranslatedReferenceViewTest.php +++ b/core/modules/field/tests/src/Functional/EntityReference/EntityReferenceFieldTranslatedReferenceViewTest.php @@ -111,11 +111,11 @@ class EntityReferenceFieldTranslatedReferenceViewTest extends BrowserTestBase { * * @var array */ - public static $modules = array( + public static $modules = [ 'language', 'content_translation', 'node', - ); + ]; protected function setUp() { parent::setUp(); @@ -203,20 +203,20 @@ class EntityReferenceFieldTranslatedReferenceViewTest extends BrowserTestBase { * Adds term reference field for the article content type. */ protected function setUpEntityReferenceField() { - FieldStorageConfig::create(array( + FieldStorageConfig::create([ 'field_name' => $this->referenceFieldName, 'entity_type' => $this->testEntityTypeName, 'type' => 'entity_reference', 'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED, 'translatable' => $this->translatable, - 'settings' => array( - 'allowed_values' => array( - array( + 'settings' => [ + 'allowed_values' => [ + [ 'target_type' => $this->testEntityTypeName, - ), - ), - ), - ))->save(); + ], + ], + ], + ])->save(); FieldConfig::create([ 'field_name' => $this->referenceFieldName, @@ -225,14 +225,14 @@ class EntityReferenceFieldTranslatedReferenceViewTest extends BrowserTestBase { ]) ->save(); entity_get_form_display($this->testEntityTypeName, $this->referrerType->id(), 'default') - ->setComponent($this->referenceFieldName, array( + ->setComponent($this->referenceFieldName, [ 'type' => 'entity_reference_autocomplete', - )) + ]) ->save(); entity_get_display($this->testEntityTypeName, $this->referrerType->id(), 'default') - ->setComponent($this->referenceFieldName, array( + ->setComponent($this->referenceFieldName, [ 'type' => 'entity_reference_label', - )) + ]) ->save(); } @@ -240,14 +240,14 @@ class EntityReferenceFieldTranslatedReferenceViewTest extends BrowserTestBase { * Create content types. */ protected function setUpContentTypes() { - $this->referrerType = $this->drupalCreateContentType(array( + $this->referrerType = $this->drupalCreateContentType([ 'type' => 'referrer', 'name' => 'Referrer', - )); - $this->referencedType = $this->drupalCreateContentType(array( + ]); + $this->referencedType = $this->drupalCreateContentType([ 'type' => 'referenced_page', 'name' => 'Referenced Page', - )); + ]); } /** @@ -255,19 +255,19 @@ class EntityReferenceFieldTranslatedReferenceViewTest extends BrowserTestBase { */ protected function createReferencedEntityWithTranslation() { /** @var \Drupal\node\Entity\Node $node */ - $node = entity_create($this->testEntityTypeName, array( + $node = entity_create($this->testEntityTypeName, [ 'title' => $this->originalLabel, 'type' => $this->referencedType->id(), - 'description' => array( + 'description' => [ 'value' => $this->randomMachineName(), 'format' => 'basic_html', - ), + ], 'langcode' => $this->baseLangcode, - )); + ]); $node->save(); - $node->addTranslation($this->translateToLangcode, array( + $node->addTranslation($this->translateToLangcode, [ 'title' => $this->translatedLabel, - )); + ]); $node->save(); return $node; @@ -279,15 +279,15 @@ class EntityReferenceFieldTranslatedReferenceViewTest extends BrowserTestBase { */ protected function createNotTranslatedReferencedEntity() { /** @var \Drupal\node\Entity\Node $node */ - $node = entity_create($this->testEntityTypeName, array( + $node = entity_create($this->testEntityTypeName, [ 'title' => $this->labelOfNotTranslatedReference, 'type' => $this->referencedType->id(), - 'description' => array( + 'description' => [ 'value' => $this->randomMachineName(), 'format' => 'basic_html', - ), + ], 'langcode' => $this->baseLangcode, - )); + ]); $node->save(); return $node; @@ -298,19 +298,19 @@ class EntityReferenceFieldTranslatedReferenceViewTest extends BrowserTestBase { */ protected function createReferrerEntity($translatable = TRUE) { /** @var \Drupal\node\Entity\Node $node */ - $node = entity_create($this->testEntityTypeName, array( + $node = entity_create($this->testEntityTypeName, [ 'title' => $this->randomMachineName(), 'type' => $this->referrerType->id(), - 'description' => array( + 'description' => [ 'value' => $this->randomMachineName(), 'format' => 'basic_html', - ), - $this->referenceFieldName => array( - array('target_id' => $this->referencedEntityWithTranslation->id()), - array('target_id' => $this->referencedEntityWithoutTranslation->id()), - ), + ], + $this->referenceFieldName => [ + ['target_id' => $this->referencedEntityWithTranslation->id()], + ['target_id' => $this->referencedEntityWithoutTranslation->id()], + ], 'langcode' => $this->baseLangcode, - )); + ]); if ($translatable) { $node->addTranslation($this->translateToLangcode, $node->toArray()); } diff --git a/core/modules/field/tests/src/Functional/EntityReference/EntityReferenceIntegrationTest.php b/core/modules/field/tests/src/Functional/EntityReference/EntityReferenceIntegrationTest.php index cb54d15545c..56484705e1b 100644 --- a/core/modules/field/tests/src/Functional/EntityReference/EntityReferenceIntegrationTest.php +++ b/core/modules/field/tests/src/Functional/EntityReference/EntityReferenceIntegrationTest.php @@ -54,7 +54,7 @@ class EntityReferenceIntegrationTest extends BrowserTestBase { parent::setUp(); // Create a test user. - $web_user = $this->drupalCreateUser(array('administer entity_test content', 'administer entity_test fields', 'view test entity')); + $web_user = $this->drupalCreateUser(['administer entity_test content', 'administer entity_test fields', 'view test entity']); $this->drupalLogin($web_user); } @@ -66,18 +66,18 @@ class EntityReferenceIntegrationTest extends BrowserTestBase { $this->fieldName = 'field_test_' . $referenced_entities[0]->getEntityTypeId(); // Create an Entity reference field. - $this->createEntityReferenceField($this->entityType, $this->bundle, $this->fieldName, $this->fieldName, $referenced_entities[0]->getEntityTypeId(), 'default', array(), 2); + $this->createEntityReferenceField($this->entityType, $this->bundle, $this->fieldName, $this->fieldName, $referenced_entities[0]->getEntityTypeId(), 'default', [], 2); // Test the default 'entity_reference_autocomplete' widget. entity_get_form_display($this->entityType, $this->bundle, 'default')->setComponent($this->fieldName)->save(); $entity_name = $this->randomMachineName(); - $edit = array( + $edit = [ 'name[0][value]' => $entity_name, $this->fieldName . '[0][target_id]' => $referenced_entities[0]->label() . ' (' . $referenced_entities[0]->id() . ')', // Test an input of the entity label without a ' (entity_id)' suffix. $this->fieldName . '[1][target_id]' => $referenced_entities[1]->label(), - ); + ]; $this->drupalPostForm($this->entityType . '/add', $edit, t('Save')); $this->assertFieldValues($entity_name, $referenced_entities); @@ -90,22 +90,22 @@ class EntityReferenceIntegrationTest extends BrowserTestBase { $this->assertFieldByName($this->fieldName . '[0][target_id]', $referenced_entities[0]->label() . ' (' . $referenced_entities[0]->id() . ')'); $this->assertFieldByName($this->fieldName . '[1][target_id]', $referenced_entities[1]->label() . ' (' . $referenced_entities[1]->id() . ')'); - $this->drupalPostForm(NULL, array(), t('Save')); + $this->drupalPostForm(NULL, [], t('Save')); $this->assertFieldValues($entity_name, $referenced_entities); // Test the 'entity_reference_autocomplete_tags' widget. - entity_get_form_display($this->entityType, $this->bundle, 'default')->setComponent($this->fieldName, array( + entity_get_form_display($this->entityType, $this->bundle, 'default')->setComponent($this->fieldName, [ 'type' => 'entity_reference_autocomplete_tags', - ))->save(); + ])->save(); $entity_name = $this->randomMachineName(); $target_id = $referenced_entities[0]->label() . ' (' . $referenced_entities[0]->id() . ')'; // Test an input of the entity label without a ' (entity_id)' suffix. $target_id .= ', ' . $referenced_entities[1]->label(); - $edit = array( + $edit = [ 'name[0][value]' => $entity_name, $this->fieldName . '[target_id]' => $target_id, - ); + ]; $this->drupalPostForm($this->entityType . '/add', $edit, t('Save')); $this->assertFieldValues($entity_name, $referenced_entities); @@ -115,23 +115,23 @@ class EntityReferenceIntegrationTest extends BrowserTestBase { $this->drupalGet($this->entityType . '/manage/' . $entity->id() . '/edit'); $this->assertFieldByName($this->fieldName . '[target_id]', $target_id . ' (' . $referenced_entities[1]->id() . ')'); - $this->drupalPostForm(NULL, array(), t('Save')); + $this->drupalPostForm(NULL, [], t('Save')); $this->assertFieldValues($entity_name, $referenced_entities); // Test all the other widgets supported by the entity reference field. // Since we don't know the form structure for these widgets, just test // that editing and saving an already created entity works. - $exclude = array('entity_reference_autocomplete', 'entity_reference_autocomplete_tags'); + $exclude = ['entity_reference_autocomplete', 'entity_reference_autocomplete_tags']; $entity = current($storage->loadByProperties(['name' => $entity_name])); $supported_widgets = \Drupal::service('plugin.manager.field.widget')->getOptions('entity_reference'); $supported_widget_types = array_diff(array_keys($supported_widgets), $exclude); foreach ($supported_widget_types as $widget_type) { - entity_get_form_display($this->entityType, $this->bundle, 'default')->setComponent($this->fieldName, array( + entity_get_form_display($this->entityType, $this->bundle, 'default')->setComponent($this->fieldName, [ 'type' => $widget_type, - ))->save(); + ])->save(); - $this->drupalPostForm($this->entityType . '/manage/' . $entity->id() . '/edit', array(), t('Save')); + $this->drupalPostForm($this->entityType . '/manage/' . $entity->id() . '/edit', [], t('Save')); $this->assertFieldValues($entity_name, $referenced_entities); } @@ -139,9 +139,9 @@ class EntityReferenceIntegrationTest extends BrowserTestBase { entity_get_form_display($this->entityType, $this->bundle, 'default')->setComponent($this->fieldName)->save(); // Set first entity as the default_value. - $field_edit = array( + $field_edit = [ 'default_value_input[' . $this->fieldName . '][0][target_id]' => $referenced_entities[0]->label() . ' (' . $referenced_entities[0]->id() . ')', - ); + ]; if ($key == 'content') { $field_edit['settings[handler_settings][target_bundles][' . $referenced_entities[0]->getEntityTypeId() . ']'] = TRUE; } @@ -179,7 +179,7 @@ class EntityReferenceIntegrationTest extends BrowserTestBase { $entity = current($this->container->get('entity_type.manager')->getStorage( $this->entityType)->loadByProperties(['name' => $entity_name])); - $this->assertTrue($entity, format_string('%entity_type: Entity found in the database.', array('%entity_type' => $this->entityType))); + $this->assertTrue($entity, format_string('%entity_type: Entity found in the database.', ['%entity_type' => $this->entityType])); $this->assertEqual($entity->{$this->fieldName}->target_id, $referenced_entities[0]->id()); $this->assertEqual($entity->{$this->fieldName}->entity->id(), $referenced_entities[0]->id()); @@ -197,26 +197,26 @@ class EntityReferenceIntegrationTest extends BrowserTestBase { * An array of entity objects. */ protected function getTestEntities() { - $config_entity_1 = entity_create('config_test', array('id' => $this->randomMachineName(), 'label' => $this->randomMachineName())); + $config_entity_1 = entity_create('config_test', ['id' => $this->randomMachineName(), 'label' => $this->randomMachineName()]); $config_entity_1->save(); - $config_entity_2 = entity_create('config_test', array('id' => $this->randomMachineName(), 'label' => $this->randomMachineName())); + $config_entity_2 = entity_create('config_test', ['id' => $this->randomMachineName(), 'label' => $this->randomMachineName()]); $config_entity_2->save(); - $content_entity_1 = EntityTest::create(array('name' => $this->randomMachineName())); + $content_entity_1 = EntityTest::create(['name' => $this->randomMachineName()]); $content_entity_1->save(); - $content_entity_2 = EntityTest::create(array('name' => $this->randomMachineName())); + $content_entity_2 = EntityTest::create(['name' => $this->randomMachineName()]); $content_entity_2->save(); - return array( - 'config' => array( + return [ + 'config' => [ $config_entity_1, $config_entity_2, - ), - 'content' => array( + ], + 'content' => [ $content_entity_1, $content_entity_2, - ), - ); + ], + ]; } } diff --git a/core/modules/field/tests/src/Functional/EntityReference/Views/SelectionTest.php b/core/modules/field/tests/src/Functional/EntityReference/Views/SelectionTest.php index 4ccf8cfcf69..cfb5ecf0845 100644 --- a/core/modules/field/tests/src/Functional/EntityReference/Views/SelectionTest.php +++ b/core/modules/field/tests/src/Functional/EntityReference/Views/SelectionTest.php @@ -21,7 +21,7 @@ class SelectionTest extends BrowserTestBase { * * @var array */ - protected $nodes = array(); + protected $nodes = []; /** * The entity reference field to test. @@ -38,39 +38,39 @@ class SelectionTest extends BrowserTestBase { // Create nodes. $type = $this->drupalCreateContentType()->id(); - $node1 = $this->drupalCreateNode(array('type' => $type)); - $node2 = $this->drupalCreateNode(array('type' => $type)); + $node1 = $this->drupalCreateNode(['type' => $type]); + $node2 = $this->drupalCreateNode(['type' => $type]); $node3 = $this->drupalCreateNode(); - foreach (array($node1, $node2, $node3) as $node) { + foreach ([$node1, $node2, $node3] as $node) { $this->nodes[$node->getType()][$node->id()] = $node->label(); } // Create a field. - $field_storage = FieldStorageConfig::create(array( + $field_storage = FieldStorageConfig::create([ 'field_name' => 'test_field', 'entity_type' => 'entity_test', 'translatable' => FALSE, - 'settings' => array( + 'settings' => [ 'target_type' => 'node', - ), + ], 'type' => 'entity_reference', 'cardinality' => '1', - )); + ]); $field_storage->save(); $field = FieldConfig::create([ 'field_storage' => $field_storage, 'bundle' => 'test_bundle', - 'settings' => array( + 'settings' => [ 'handler' => 'views', - 'handler_settings' => array( - 'view' => array( + 'handler_settings' => [ + 'view' => [ 'view_name' => 'test_entity_reference', 'display_name' => 'entity_reference_1', - 'arguments' => array(), - ), - ), - ), + 'arguments' => [], + ], + ], + ], ]); $field->save(); $this->field = $field; @@ -112,23 +112,23 @@ class SelectionTest extends BrowserTestBase { // Add a relationship to the view. $view = Views::getView('test_entity_reference'); $view->setDisplay(); - $view->displayHandlers->get('default')->setOption('relationships', array( - 'test_relationship' => array( + $view->displayHandlers->get('default')->setOption('relationships', [ + 'test_relationship' => [ 'id' => 'uid', 'table' => 'node_field_data', 'field' => 'uid', - ), - )); + ], + ]); // Add a filter depending on the relationship to the test view. - $view->displayHandlers->get('default')->setOption('filters', array( - 'uid' => array( + $view->displayHandlers->get('default')->setOption('filters', [ + 'uid' => [ 'id' => 'uid', 'table' => 'users_field_data', 'field' => 'uid', 'relationship' => 'test_relationship', - ) - )); + ] + ]); // Set view to distinct so only one row per node is returned. $query_options = $view->display_handler->getOption('query'); diff --git a/core/modules/field/tests/src/Functional/FieldAccessTest.php b/core/modules/field/tests/src/Functional/FieldAccessTest.php index a9af8366863..36f0ef97997 100644 --- a/core/modules/field/tests/src/Functional/FieldAccessTest.php +++ b/core/modules/field/tests/src/Functional/FieldAccessTest.php @@ -17,7 +17,7 @@ class FieldAccessTest extends FieldTestBase { * * @var array */ - public static $modules = array('node', 'field_test'); + public static $modules = ['node', 'field_test']; /** * Node entity to use in this test. @@ -36,28 +36,28 @@ class FieldAccessTest extends FieldTestBase { protected function setUp() { parent::setUp(); - $web_user = $this->drupalCreateUser(array('view test_view_field content')); + $web_user = $this->drupalCreateUser(['view test_view_field content']); $this->drupalLogin($web_user); // Create content type. $content_type_info = $this->drupalCreateContentType(); $content_type = $content_type_info->id(); - $field_storage = array( + $field_storage = [ 'field_name' => 'test_view_field', 'entity_type' => 'node', 'type' => 'text', - ); + ]; FieldStorageConfig::create($field_storage)->save(); - $field = array( + $field = [ 'field_name' => $field_storage['field_name'], 'entity_type' => 'node', 'bundle' => $content_type, - ); + ]; FieldConfig::create($field)->save(); // Assign display properties for the 'default' and 'teaser' view modes. - foreach (array('default', 'teaser') as $view_mode) { + foreach (['default', 'teaser'] as $view_mode) { entity_get_display('node', $content_type, $view_mode) ->setComponent($field_storage['field_name']) ->save(); @@ -65,10 +65,10 @@ class FieldAccessTest extends FieldTestBase { // Create test node. $this->testViewFieldValue = 'This is some text'; - $settings = array(); + $settings = []; $settings['type'] = $content_type; $settings['title'] = 'Field view access test'; - $settings['test_view_field'] = array(array('value' => $this->testViewFieldValue)); + $settings['test_view_field'] = [['value' => $this->testViewFieldValue]]; $this->node = $this->drupalCreateNode($settings); } diff --git a/core/modules/field/tests/src/Functional/FieldHelpTest.php b/core/modules/field/tests/src/Functional/FieldHelpTest.php index 76affaae356..9a6ff678209 100644 --- a/core/modules/field/tests/src/Functional/FieldHelpTest.php +++ b/core/modules/field/tests/src/Functional/FieldHelpTest.php @@ -16,7 +16,7 @@ class FieldHelpTest extends BrowserTestBase { * * @var array. */ - public static $modules = array('field', 'help'); + public static $modules = ['field', 'help']; // Tests field help implementation without optional core modules enabled. protected $profile = 'minimal'; @@ -30,7 +30,7 @@ class FieldHelpTest extends BrowserTestBase { parent::setUp(); // Create the admin user. - $this->adminUser = $this->drupalCreateUser(array('access administration pages', 'view the administration theme')); + $this->adminUser = $this->drupalCreateUser(['access administration pages', 'view the administration theme']); } /** @@ -44,7 +44,7 @@ class FieldHelpTest extends BrowserTestBase { $this->drupalGet('admin/help/field'); // Enable the Options, Email and Field API Test modules. - \Drupal::service('module_installer')->install(array('options', 'field_test')); + \Drupal::service('module_installer')->install(['options', 'field_test']); $this->resetAll(); \Drupal::service('plugin.manager.field.widget')->clearCachedDefinitions(); \Drupal::service('plugin.manager.field.field_type')->clearCachedDefinitions(); diff --git a/core/modules/field/tests/src/Functional/FieldTestBase.php b/core/modules/field/tests/src/Functional/FieldTestBase.php index 40cffac225c..108d5f5d7cd 100644 --- a/core/modules/field/tests/src/Functional/FieldTestBase.php +++ b/core/modules/field/tests/src/Functional/FieldTestBase.php @@ -20,7 +20,7 @@ abstract class FieldTestBase extends BrowserTestBase { * An array of random values, in the format expected for field values. */ function _generateTestFieldValues($cardinality) { - $values = array(); + $values = []; for ($i = 0; $i < $cardinality; $i++) { // field_test fields treat 0 as 'empty value'. $values[$i]['value'] = mt_rand(1, 127); @@ -58,7 +58,7 @@ abstract class FieldTestBase extends BrowserTestBase { $values = $field->getValue(); $this->assertEqual(count($values), count($expected_values), 'Expected number of values were saved.'); foreach ($expected_values as $key => $value) { - $this->assertEqual($values[$key][$column], $value, format_string('Value @value was saved correctly.', array('@value' => $value))); + $this->assertEqual($values[$key][$column], $value, format_string('Value @value was saved correctly.', ['@value' => $value])); } } diff --git a/core/modules/field/tests/src/Functional/TranslationWebTest.php b/core/modules/field/tests/src/Functional/TranslationWebTest.php index 3e0f849e312..e09e5851ba9 100644 --- a/core/modules/field/tests/src/Functional/TranslationWebTest.php +++ b/core/modules/field/tests/src/Functional/TranslationWebTest.php @@ -19,7 +19,7 @@ class TranslationWebTest extends FieldTestBase { * * @var array */ - public static $modules = array('language', 'field_test', 'entity_test'); + public static $modules = ['language', 'field_test', 'entity_test']; /** * The name of the field to use in this test. @@ -54,19 +54,19 @@ class TranslationWebTest extends FieldTestBase { $this->fieldName = Unicode::strtolower($this->randomMachineName() . '_field_name'); - $field_storage = array( + $field_storage = [ 'field_name' => $this->fieldName, 'entity_type' => $this->entityTypeId, 'type' => 'test_field', 'cardinality' => 4, - ); + ]; FieldStorageConfig::create($field_storage)->save(); $this->fieldStorage = FieldStorageConfig::load($this->entityTypeId . '.' . $this->fieldName); - $field = array( + $field = [ 'field_storage' => $this->fieldStorage, 'bundle' => $this->entityTypeId, - ); + ]; FieldConfig::create($field)->save(); $this->field = FieldConfig::load($this->entityTypeId . '.' . $field['bundle'] . '.' . $this->fieldName); @@ -75,10 +75,10 @@ class TranslationWebTest extends FieldTestBase { ->save(); for ($i = 0; $i < 3; ++$i) { - ConfigurableLanguage::create(array( + ConfigurableLanguage::create([ 'id' => 'l' . $i, 'label' => $this->randomString(), - ))->save(); + ])->save(); } } @@ -86,7 +86,7 @@ class TranslationWebTest extends FieldTestBase { * Tests field translations when creating a new revision. */ function testFieldFormTranslationRevisions() { - $web_user = $this->drupalCreateUser(array('view test entity', 'administer entity_test content')); + $web_user = $this->drupalCreateUser(['view test entity', 'administer entity_test content']); $this->drupalLogin($web_user); // Prepare the field translations. @@ -107,10 +107,10 @@ class TranslationWebTest extends FieldTestBase { $entity->save(); // Create a new revision. - $edit = array( + $edit = [ "{$field_name}[0][value]" => $entity->{$field_name}->value, 'revision' => TRUE, - ); + ]; $this->drupalPostForm($this->entityTypeId . '/manage/' . $entity->id() . '/edit', $edit, t('Save')); // Check translation revisions. @@ -129,7 +129,7 @@ class TranslationWebTest extends FieldTestBase { ->loadRevision($revision_id); foreach ($available_langcodes as $langcode => $value) { $passed = $entity->getTranslation($langcode)->{$field_name}->value == $value + 1; - $this->assertTrue($passed, format_string('The @language translation for revision @revision was correctly stored', array('@language' => $langcode, '@revision' => $entity->getRevisionId()))); + $this->assertTrue($passed, format_string('The @language translation for revision @revision was correctly stored', ['@language' => $langcode, '@revision' => $entity->getRevisionId()])); } } diff --git a/core/modules/field/tests/src/Kernel/Boolean/BooleanItemTest.php b/core/modules/field/tests/src/Kernel/Boolean/BooleanItemTest.php index cb8b501a0e0..37acab86c2d 100644 --- a/core/modules/field/tests/src/Kernel/Boolean/BooleanItemTest.php +++ b/core/modules/field/tests/src/Kernel/Boolean/BooleanItemTest.php @@ -23,11 +23,11 @@ class BooleanItemTest extends FieldKernelTestBase { parent::setUp(); // Create a boolean field and storage for validation. - FieldStorageConfig::create(array( + FieldStorageConfig::create([ 'field_name' => 'field_boolean', 'entity_type' => 'entity_test', 'type' => 'boolean', - ))->save(); + ])->save(); FieldConfig::create([ 'entity_type' => 'entity_test', 'field_name' => 'field_boolean', @@ -36,9 +36,9 @@ class BooleanItemTest extends FieldKernelTestBase { // Create a form display for the default form mode. entity_get_form_display('entity_test', 'entity_test', 'default') - ->setComponent('field_boolean', array( + ->setComponent('field_boolean', [ 'type' => 'boolean_checkbox', - )) + ]) ->save(); } diff --git a/core/modules/field/tests/src/Kernel/BulkDeleteTest.php b/core/modules/field/tests/src/Kernel/BulkDeleteTest.php index b01926ad879..f0497d64a65 100644 --- a/core/modules/field/tests/src/Kernel/BulkDeleteTest.php +++ b/core/modules/field/tests/src/Kernel/BulkDeleteTest.php @@ -90,31 +90,31 @@ class BulkDeleteTest extends FieldKernelTestBase { protected function setUp() { parent::setUp(); - $this->fieldStorages = array(); - $this->entities = array(); - $this->entitiesByBundles = array(); + $this->fieldStorages = []; + $this->entities = []; + $this->entitiesByBundles = []; // Create two bundles. - $this->bundles = array('bb_1' => 'bb_1', 'bb_2' => 'bb_2'); + $this->bundles = ['bb_1' => 'bb_1', 'bb_2' => 'bb_2']; foreach ($this->bundles as $name => $desc) { entity_test_create_bundle($name, $desc); } // Create two field storages. - $field_storage = FieldStorageConfig::create(array( + $field_storage = FieldStorageConfig::create([ 'field_name' => 'bf_1', 'entity_type' => $this->entityTypeId, 'type' => 'test_field', 'cardinality' => 1 - )); + ]); $field_storage->save(); $this->fieldStorages[] = $field_storage; - $field_storage = FieldStorageConfig::create(array( + $field_storage = FieldStorageConfig::create([ 'field_name' => 'bf_2', 'entity_type' => $this->entityTypeId, 'type' => 'test_field', 'cardinality' => 4 - )); + ]); $field_storage->save(); $this->fieldStorages[] = $field_storage; @@ -130,7 +130,7 @@ class BulkDeleteTest extends FieldKernelTestBase { for ($i = 0; $i < 10; $i++) { $entity = $this->container->get('entity_type.manager') ->getStorage($this->entityTypeId) - ->create(array('type' => $bundle)); + ->create(['type' => $bundle]); foreach ($this->fieldStorages as $field_storage) { $entity->{$field_storage->getName()}->setValue($this->_generateTestFieldValues($field_storage->getCardinality())); } @@ -175,7 +175,7 @@ class BulkDeleteTest extends FieldKernelTestBase { $field->delete(); // The field still exists, deleted. - $fields = entity_load_multiple_by_properties('field_config', array('field_storage_uuid' => $field_storage->uuid(), 'deleted' => TRUE, 'include_deleted' => TRUE)); + $fields = entity_load_multiple_by_properties('field_config', ['field_storage_uuid' => $field_storage->uuid(), 'deleted' => TRUE, 'include_deleted' => TRUE]); $this->assertEqual(count($fields), 1, 'There is one deleted field'); $field = $fields[$field->uuid()]; $this->assertEqual($field->getTargetBundle(), $bundle, 'The deleted field is for the correct bundle'); @@ -218,12 +218,12 @@ class BulkDeleteTest extends FieldKernelTestBase { $bundle = reset($this->bundles); // Create another field storage. $field_name = 'bf_3'; - $deleted_field_storage = FieldStorageConfig::create(array( + $deleted_field_storage = FieldStorageConfig::create([ 'field_name' => $field_name, 'entity_type' => $this->entityTypeId, 'type' => 'test_field', 'cardinality' => 1 - )); + ]); $deleted_field_storage->save(); // Create the field. FieldConfig::create([ @@ -234,7 +234,7 @@ class BulkDeleteTest extends FieldKernelTestBase { for ($i = 0; $i < 20; $i++) { $entity = $this->container->get('entity_type.manager') ->getStorage($this->entityTypeId) - ->create(array('type' => $bundle)); + ->create(['type' => $bundle]); $entity->{$field_name}->setValue($this->_generateTestFieldValues(1)); $entity->save(); } @@ -245,16 +245,16 @@ class BulkDeleteTest extends FieldKernelTestBase { $deleted_field_uuid = $deleted_field->uuid(); // Reload the field storage. - $field_storages = entity_load_multiple_by_properties('field_storage_config', array('uuid' => $deleted_field_storage->uuid(), 'include_deleted' => TRUE)); + $field_storages = entity_load_multiple_by_properties('field_storage_config', ['uuid' => $deleted_field_storage->uuid(), 'include_deleted' => TRUE]); $deleted_field_storage = reset($field_storages); // Create the field again. - $field_storage = FieldStorageConfig::create(array( + $field_storage = FieldStorageConfig::create([ 'field_name' => $field_name, 'entity_type' => $this->entityTypeId, 'type' => 'test_field', 'cardinality' => 1 - )); + ]); $field_storage->save(); FieldConfig::create([ 'field_storage' => $field_storage, @@ -262,14 +262,14 @@ class BulkDeleteTest extends FieldKernelTestBase { ])->save(); // The field still exists, deleted, with the same field name. - $fields = entity_load_multiple_by_properties('field_config', array('uuid' => $deleted_field_uuid, 'include_deleted' => TRUE)); + $fields = entity_load_multiple_by_properties('field_config', ['uuid' => $deleted_field_uuid, 'include_deleted' => TRUE]); $this->assertTrue(isset($fields[$deleted_field_uuid]) && $fields[$deleted_field_uuid]->isDeleted(), 'The field exists and is deleted'); $this->assertTrue(isset($fields[$deleted_field_uuid]) && $fields[$deleted_field_uuid]->getName() == $field_name); for ($i = 0; $i < 10; $i++) { $entity = $this->container->get('entity_type.manager') ->getStorage($this->entityTypeId) - ->create(array('type' => $bundle)); + ->create(['type' => $bundle]); $entity->{$field_name}->setValue($this->_generateTestFieldValues(1)); $entity->save(); } @@ -289,13 +289,13 @@ class BulkDeleteTest extends FieldKernelTestBase { $this->assertFalse(\Drupal::database()->schema()->tableExists($deleted_table_name)); // The field has been removed from the system. - $fields = entity_load_multiple_by_properties('field_config', array('field_storage_uuid' => $deleted_field_storage->uuid(), 'deleted' => TRUE, 'include_deleted' => TRUE)); + $fields = entity_load_multiple_by_properties('field_config', ['field_storage_uuid' => $deleted_field_storage->uuid(), 'deleted' => TRUE, 'include_deleted' => TRUE]); $this->assertEqual(count($fields), 0, 'The field is gone'); // Verify there are still 10 entries in the main table. $count = \Drupal::database() ->select('entity_test__' . $field_name, 'f') - ->fields('f', array('entity_id')) + ->fields('f', ['entity_id']) ->condition('bundle', $bundle) ->countQuery() ->execute() @@ -340,7 +340,7 @@ class BulkDeleteTest extends FieldKernelTestBase { // FieldItemInterface::delete() should have been called once for each entity in the // bundle. $actual_hooks = field_test_memorize(); - $hooks = array(); + $hooks = []; $entities = $this->entitiesByBundles[$bundle]; foreach ($entities as $id => $entity) { $hooks['field_test_field_delete'][] = $entity; @@ -348,19 +348,19 @@ class BulkDeleteTest extends FieldKernelTestBase { $this->checkHooksInvocations($hooks, $actual_hooks); // The field still exists, deleted. - $fields = entity_load_multiple_by_properties('field_config', array('field_storage_uuid' => $field_storage->uuid(), 'deleted' => TRUE, 'include_deleted' => TRUE)); + $fields = entity_load_multiple_by_properties('field_config', ['field_storage_uuid' => $field_storage->uuid(), 'deleted' => TRUE, 'include_deleted' => TRUE]); $this->assertEqual(count($fields), 1, 'There is one deleted field'); // Purge the field. field_purge_batch($batch_size); // The field is gone. - $fields = entity_load_multiple_by_properties('field_config', array('field_storage_uuid' => $field_storage->uuid(), 'deleted' => TRUE, 'include_deleted' => TRUE)); + $fields = entity_load_multiple_by_properties('field_config', ['field_storage_uuid' => $field_storage->uuid(), 'deleted' => TRUE, 'include_deleted' => TRUE]); $this->assertEqual(count($fields), 0, 'The field is gone'); // The field storage still exists, not deleted, because it has a second // field. - $storages = entity_load_multiple_by_properties('field_storage_config', array('uuid' => $field_storage->uuid(), 'include_deleted' => TRUE)); + $storages = entity_load_multiple_by_properties('field_storage_config', ['uuid' => $field_storage->uuid(), 'include_deleted' => TRUE]); $this->assertTrue(isset($storages[$field_storage->uuid()]), 'The field storage exists and is not deleted'); } @@ -391,7 +391,7 @@ class BulkDeleteTest extends FieldKernelTestBase { // FieldItemInterface::delete() should have been called once for each entity in the // bundle. $actual_hooks = field_test_memorize(); - $hooks = array(); + $hooks = []; $entities = $this->entitiesByBundles[$bundle]; foreach ($entities as $id => $entity) { $hooks['field_test_field_delete'][] = $entity; @@ -399,17 +399,17 @@ class BulkDeleteTest extends FieldKernelTestBase { $this->checkHooksInvocations($hooks, $actual_hooks); // The field still exists, deleted. - $fields = entity_load_multiple_by_properties('field_config', array('uuid' => $field->uuid(), 'include_deleted' => TRUE)); + $fields = entity_load_multiple_by_properties('field_config', ['uuid' => $field->uuid(), 'include_deleted' => TRUE]); $this->assertTrue(isset($fields[$field->uuid()]) && $fields[$field->uuid()]->isDeleted(), 'The field exists and is deleted'); // Purge again to purge the field. field_purge_batch(0); // The field is gone. - $fields = entity_load_multiple_by_properties('field_config', array('uuid' => $field->uuid(), 'include_deleted' => TRUE)); + $fields = entity_load_multiple_by_properties('field_config', ['uuid' => $field->uuid(), 'include_deleted' => TRUE]); $this->assertEqual(count($fields), 0, 'The field is purged.'); // The field storage still exists, not deleted. - $storages = entity_load_multiple_by_properties('field_storage_config', array('uuid' => $field_storage->uuid(), 'include_deleted' => TRUE)); + $storages = entity_load_multiple_by_properties('field_storage_config', ['uuid' => $field_storage->uuid(), 'include_deleted' => TRUE]); $this->assertTrue(isset($storages[$field_storage->uuid()]) && !$storages[$field_storage->uuid()]->isDeleted(), 'The field storage exists and is not deleted'); // Delete the second field. @@ -426,7 +426,7 @@ class BulkDeleteTest extends FieldKernelTestBase { // Check hooks invocations (same as above, for the 2nd bundle). $actual_hooks = field_test_memorize(); - $hooks = array(); + $hooks = []; $entities = $this->entitiesByBundles[$bundle]; foreach ($entities as $id => $entity) { $hooks['field_test_field_delete'][] = $entity; @@ -434,18 +434,18 @@ class BulkDeleteTest extends FieldKernelTestBase { $this->checkHooksInvocations($hooks, $actual_hooks); // The field and the storage still exist, deleted. - $fields = entity_load_multiple_by_properties('field_config', array('uuid' => $field->uuid(), 'include_deleted' => TRUE)); + $fields = entity_load_multiple_by_properties('field_config', ['uuid' => $field->uuid(), 'include_deleted' => TRUE]); $this->assertTrue(isset($fields[$field->uuid()]) && $fields[$field->uuid()]->isDeleted(), 'The field exists and is deleted'); - $storages = entity_load_multiple_by_properties('field_storage_config', array('uuid' => $field_storage->uuid(), 'include_deleted' => TRUE)); + $storages = entity_load_multiple_by_properties('field_storage_config', ['uuid' => $field_storage->uuid(), 'include_deleted' => TRUE]); $this->assertTrue(isset($storages[$field_storage->uuid()]) && $storages[$field_storage->uuid()]->isDeleted(), 'The field storage exists and is deleted'); // Purge again to purge the field and the storage. field_purge_batch(0); // The field and the storage are gone. - $fields = entity_load_multiple_by_properties('field_config', array('uuid' => $field->uuid(), 'include_deleted' => TRUE)); + $fields = entity_load_multiple_by_properties('field_config', ['uuid' => $field->uuid(), 'include_deleted' => TRUE]); $this->assertEqual(count($fields), 0, 'The field is purged.'); - $storages = entity_load_multiple_by_properties('field_storage_config', array('uuid' => $field_storage->uuid(), 'include_deleted' => TRUE)); + $storages = entity_load_multiple_by_properties('field_storage_config', ['uuid' => $field_storage->uuid(), 'include_deleted' => TRUE]); $this->assertEqual(count($storages), 0, 'The field storage is purged.'); } diff --git a/core/modules/field/tests/src/Kernel/DisplayApiTest.php b/core/modules/field/tests/src/Kernel/DisplayApiTest.php index c1218a6805c..1072de19bc0 100644 --- a/core/modules/field/tests/src/Kernel/DisplayApiTest.php +++ b/core/modules/field/tests/src/Kernel/DisplayApiTest.php @@ -69,33 +69,33 @@ class DisplayApiTest extends FieldKernelTestBase { $this->label = $this->randomMachineName(); $this->cardinality = 4; - $field_storage = array( + $field_storage = [ 'field_name' => $this->fieldName, 'entity_type' => 'entity_test', 'type' => 'test_field', 'cardinality' => $this->cardinality, - ); - $field = array( + ]; + $field = [ 'field_name' => $this->fieldName, 'entity_type' => 'entity_test', 'bundle' => 'entity_test', 'label' => $this->label, - ); + ]; - $this->displayOptions = array( - 'default' => array( + $this->displayOptions = [ + 'default' => [ 'type' => 'field_test_default', - 'settings' => array( + 'settings' => [ 'test_formatter_setting' => $this->randomMachineName(), - ), - ), - 'teaser' => array( + ], + ], + 'teaser' => [ 'type' => 'field_test_default', - 'settings' => array( + 'settings' => [ 'test_formatter_setting' => $this->randomMachineName(), - ), - ), - ); + ], + ], + ]; FieldStorageConfig::create($field_storage)->save(); FieldConfig::create($field)->save(); @@ -104,7 +104,7 @@ class DisplayApiTest extends FieldKernelTestBase { ->setComponent($this->fieldName, $this->displayOptions['default']) ->save(); // Create a display for the teaser view mode. - EntityViewMode::create(array('id' => 'entity_test.teaser', 'targetEntityType' => 'entity_test'))->save(); + EntityViewMode::create(['id' => 'entity_test.teaser', 'targetEntityType' => 'entity_test'])->save(); entity_get_display($field['entity_type'], $field['bundle'], 'teaser') ->setComponent($this->fieldName, $this->displayOptions['teaser']) ->save(); @@ -132,66 +132,66 @@ class DisplayApiTest extends FieldKernelTestBase { $setting = $settings['test_formatter_setting']; $this->assertText($this->label, 'Label was displayed.'); foreach ($this->values as $delta => $value) { - $this->assertText($setting . '|' . $value['value'], format_string('Value @delta was displayed with expected setting.', array('@delta' => $delta))); + $this->assertText($setting . '|' . $value['value'], format_string('Value @delta was displayed with expected setting.', ['@delta' => $delta])); } // Display settings: Check hidden field. - $display = array( + $display = [ 'label' => 'hidden', 'type' => 'field_test_multiple', - 'settings' => array( + 'settings' => [ 'test_formatter_setting_multiple' => $this->randomMachineName(), 'alter' => TRUE, - ), - ); + ], + ]; $build = $items->view($display); $this->render($build); $setting = $display['settings']['test_formatter_setting_multiple']; $this->assertNoText($this->label, 'Label was not displayed.'); $this->assertText('field_test_entity_display_build_alter', 'Alter fired, display passed.'); $this->assertText('entity language is en', 'Language is placed onto the context.'); - $array = array(); + $array = []; foreach ($this->values as $delta => $value) { $array[] = $delta . ':' . $value['value']; } $this->assertText($setting . '|' . implode('|', $array), 'Values were displayed with expected setting.'); // Display settings: Check visually_hidden field. - $display = array( + $display = [ 'label' => 'visually_hidden', 'type' => 'field_test_multiple', - 'settings' => array( + 'settings' => [ 'test_formatter_setting_multiple' => $this->randomMachineName(), 'alter' => TRUE, - ), - ); + ], + ]; $build = $items->view($display); $this->render($build); $setting = $display['settings']['test_formatter_setting_multiple']; $this->assertRaw('visually-hidden', 'Label was visually hidden.'); $this->assertText('field_test_entity_display_build_alter', 'Alter fired, display passed.'); $this->assertText('entity language is en', 'Language is placed onto the context.'); - $array = array(); + $array = []; foreach ($this->values as $delta => $value) { $array[] = $delta . ':' . $value['value']; } $this->assertText($setting . '|' . implode('|', $array), 'Values were displayed with expected setting.'); // Check the prepare_view steps are invoked. - $display = array( + $display = [ 'label' => 'hidden', 'type' => 'field_test_with_prepare_view', - 'settings' => array( + 'settings' => [ 'test_formatter_setting_additional' => $this->randomMachineName(), - ), - ); + ], + ]; $build = $items->view($display); $this->render($build); $setting = $display['settings']['test_formatter_setting_additional']; $this->assertNoText($this->label, 'Label was not displayed.'); $this->assertNoText('field_test_entity_display_build_alter', 'Alter not fired.'); foreach ($this->values as $delta => $value) { - $this->assertText($setting . '|' . $value['value'] . '|' . ($value['value'] + 1), format_string('Value @delta was displayed with expected setting.', array('@delta' => $delta))); + $this->assertText($setting . '|' . $value['value'] . '|' . ($value['value'] + 1), format_string('Value @delta was displayed with expected setting.', ['@delta' => $delta])); } // View mode: check that display settings specified in the display object @@ -201,7 +201,7 @@ class DisplayApiTest extends FieldKernelTestBase { $setting = $this->displayOptions['teaser']['settings']['test_formatter_setting']; $this->assertText($this->label, 'Label was displayed.'); foreach ($this->values as $delta => $value) { - $this->assertText($setting . '|' . $value['value'], format_string('Value @delta was displayed with expected setting.', array('@delta' => $delta))); + $this->assertText($setting . '|' . $value['value'], format_string('Value @delta was displayed with expected setting.', ['@delta' => $delta])); } // Unknown view mode: check that display settings for 'default' view mode @@ -211,7 +211,7 @@ class DisplayApiTest extends FieldKernelTestBase { $setting = $this->displayOptions['default']['settings']['test_formatter_setting']; $this->assertText($this->label, 'Label was displayed.'); foreach ($this->values as $delta => $value) { - $this->assertText($setting . '|' . $value['value'], format_string('Value @delta was displayed with expected setting.', array('@delta' => $delta))); + $this->assertText($setting . '|' . $value['value'], format_string('Value @delta was displayed with expected setting.', ['@delta' => $delta])); } } @@ -226,37 +226,37 @@ class DisplayApiTest extends FieldKernelTestBase { $item = $this->entity->{$this->fieldName}[$delta]; $build = $item->view(); $this->render($build); - $this->assertText($setting . '|' . $value['value'], format_string('Value @delta was displayed with expected setting.', array('@delta' => $delta))); + $this->assertText($setting . '|' . $value['value'], format_string('Value @delta was displayed with expected setting.', ['@delta' => $delta])); } // Check that explicit display settings are used. - $display = array( + $display = [ 'type' => 'field_test_multiple', - 'settings' => array( + 'settings' => [ 'test_formatter_setting_multiple' => $this->randomMachineName(), - ), - ); + ], + ]; $setting = $display['settings']['test_formatter_setting_multiple']; foreach ($this->values as $delta => $value) { $item = $this->entity->{$this->fieldName}[$delta]; $build = $item->view($display); $this->render($build); - $this->assertText($setting . '|0:' . $value['value'], format_string('Value @delta was displayed with expected setting.', array('@delta' => $delta))); + $this->assertText($setting . '|0:' . $value['value'], format_string('Value @delta was displayed with expected setting.', ['@delta' => $delta])); } // Check that prepare_view steps are invoked. - $display = array( + $display = [ 'type' => 'field_test_with_prepare_view', - 'settings' => array( + 'settings' => [ 'test_formatter_setting_additional' => $this->randomMachineName(), - ), - ); + ], + ]; $setting = $display['settings']['test_formatter_setting_additional']; foreach ($this->values as $delta => $value) { $item = $this->entity->{$this->fieldName}[$delta]; $build = $item->view($display); $this->render($build); - $this->assertText($setting . '|' . $value['value'] . '|' . ($value['value'] + 1), format_string('Value @delta was displayed with expected setting.', array('@delta' => $delta))); + $this->assertText($setting . '|' . $value['value'] . '|' . ($value['value'] + 1), format_string('Value @delta was displayed with expected setting.', ['@delta' => $delta])); } // View mode: check that display settings specified in the field are used. @@ -265,7 +265,7 @@ class DisplayApiTest extends FieldKernelTestBase { $item = $this->entity->{$this->fieldName}[$delta]; $build = $item->view('teaser'); $this->render($build); - $this->assertText($setting . '|' . $value['value'], format_string('Value @delta was displayed with expected setting.', array('@delta' => $delta))); + $this->assertText($setting . '|' . $value['value'], format_string('Value @delta was displayed with expected setting.', ['@delta' => $delta])); } // Unknown view mode: check that display settings for 'default' view mode @@ -275,7 +275,7 @@ class DisplayApiTest extends FieldKernelTestBase { $item = $this->entity->{$this->fieldName}[$delta]; $build = $item->view('unknown_view_mode'); $this->render($build); - $this->assertText($setting . '|' . $value['value'], format_string('Value @delta was displayed with expected setting.', array('@delta' => $delta))); + $this->assertText($setting . '|' . $value['value'], format_string('Value @delta was displayed with expected setting.', ['@delta' => $delta])); } } @@ -284,13 +284,13 @@ class DisplayApiTest extends FieldKernelTestBase { */ function testFieldEmpty() { // Uses \Drupal\field_test\Plugin\Field\FieldFormatter\TestFieldEmptyFormatter. - $display = array( + $display = [ 'label' => 'hidden', 'type' => 'field_empty_test', - 'settings' => array( + 'settings' => [ 'test_empty_string' => '**EMPTY FIELD**' . $this->randomMachineName(), - ), - ); + ], + ]; // $this->entity is set by the setUp() method and by default contains 4 // numeric values. We only want to test the display of this one field. $build = $this->entity->get($this->fieldName)->view($display); @@ -300,7 +300,7 @@ class DisplayApiTest extends FieldKernelTestBase { $this->assertNoText($display['settings']['test_empty_string']); // Now remove the values from the test field and retest. - $this->entity->{$this->fieldName} = array(); + $this->entity->{$this->fieldName} = []; $this->entity->save(); $build = $this->entity->get($this->fieldName)->view($display); $this->render($build); diff --git a/core/modules/field/tests/src/Kernel/Email/EmailItemTest.php b/core/modules/field/tests/src/Kernel/Email/EmailItemTest.php index cd8b7acdd1b..10b44333e07 100644 --- a/core/modules/field/tests/src/Kernel/Email/EmailItemTest.php +++ b/core/modules/field/tests/src/Kernel/Email/EmailItemTest.php @@ -20,11 +20,11 @@ class EmailItemTest extends FieldKernelTestBase { parent::setUp(); // Create an email field storage and field for validation. - FieldStorageConfig::create(array( + FieldStorageConfig::create([ 'field_name' => 'field_email', 'entity_type' => 'entity_test', 'type' => 'email', - ))->save(); + ])->save(); FieldConfig::create([ 'entity_type' => 'entity_test', 'field_name' => 'field_email', @@ -33,9 +33,9 @@ class EmailItemTest extends FieldKernelTestBase { // Create a form display for the default form mode. entity_get_form_display('entity_test', 'entity_test', 'default') - ->setComponent('field_email', array( + ->setComponent('field_email', [ 'type' => 'email_default', - )) + ]) ->save(); } diff --git a/core/modules/field/tests/src/Kernel/EntityReference/EntityReferenceFormatterTest.php b/core/modules/field/tests/src/Kernel/EntityReference/EntityReferenceFormatterTest.php index da4481aefbc..9c94aca946f 100644 --- a/core/modules/field/tests/src/Kernel/EntityReference/EntityReferenceFormatterTest.php +++ b/core/modules/field/tests/src/Kernel/EntityReference/EntityReferenceFormatterTest.php @@ -68,7 +68,7 @@ class EntityReferenceFormatterTest extends EntityKernelTestBase { $this->config('system.theme')->set('default', 'classy')->save(); $this->installEntitySchema('entity_test'); // Grant the 'view test entity' permission. - $this->installConfig(array('user')); + $this->installConfig(['user']); Role::load(RoleInterface::ANONYMOUS_ID) ->grantPermission('view test entity') ->save(); @@ -76,16 +76,16 @@ class EntityReferenceFormatterTest extends EntityKernelTestBase { // The label formatter rendering generates links, so build the router. $this->container->get('router.builder')->rebuild(); - $this->createEntityReferenceField($this->entityType, $this->bundle, $this->fieldName, 'Field test', $this->entityType, 'default', array(), FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED); + $this->createEntityReferenceField($this->entityType, $this->bundle, $this->fieldName, 'Field test', $this->entityType, 'default', [], FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED); // Set up a field, so that the entity that'll be referenced bubbles up a // cache tag when rendering it entirely. - FieldStorageConfig::create(array( + FieldStorageConfig::create([ 'field_name' => 'body', 'entity_type' => $this->entityType, 'type' => 'text', - 'settings' => array(), - ))->save(); + 'settings' => [], + ])->save(); FieldConfig::create([ 'entity_type' => $this->entityType, 'bundle' => $this->bundle, @@ -93,35 +93,35 @@ class EntityReferenceFormatterTest extends EntityKernelTestBase { 'label' => 'Body', ])->save(); entity_get_display($this->entityType, $this->bundle, 'default') - ->setComponent('body', array( + ->setComponent('body', [ 'type' => 'text_default', - 'settings' => array(), - )) + 'settings' => [], + ]) ->save(); - FilterFormat::create(array( + FilterFormat::create([ 'format' => 'full_html', 'name' => 'Full HTML', - ))->save(); + ])->save(); // Create the entity to be referenced. $this->referencedEntity = $this->container->get('entity_type.manager') ->getStorage($this->entityType) - ->create(array('name' => $this->randomMachineName())); - $this->referencedEntity->body = array( + ->create(['name' => $this->randomMachineName()]); + $this->referencedEntity->body = [ 'value' => '<p>Hello, world!</p>', 'format' => 'full_html', - ); + ]; $this->referencedEntity->save(); // Create another entity to be referenced but do not save it. $this->unsavedReferencedEntity = $this->container->get('entity_type.manager') ->getStorage($this->entityType) - ->create(array('name' => $this->randomMachineName())); - $this->unsavedReferencedEntity->body = array( + ->create(['name' => $this->randomMachineName()]); + $this->unsavedReferencedEntity->body = [ 'value' => '<p>Hello, unsaved world!</p>', 'format' => 'full_html', - ); + ]; } /** @@ -137,7 +137,7 @@ class EntityReferenceFormatterTest extends EntityKernelTestBase { $referencing_entity = $this->container->get('entity_type.manager') ->getStorage($this->entityType) - ->create(array('name' => $this->randomMachineName())); + ->create(['name' => $this->randomMachineName()]); $referencing_entity->save(); $referencing_entity->{$field_name}->entity = $this->referencedEntity; @@ -150,16 +150,16 @@ class EntityReferenceFormatterTest extends EntityKernelTestBase { foreach ($formatter_manager->getOptions('entity_reference') as $formatter => $name) { // Set formatter type for the 'full' view mode. entity_get_display($this->entityType, $this->bundle, 'default') - ->setComponent($field_name, array( + ->setComponent($field_name, [ 'type' => $formatter, - )) + ]) ->save(); // Invoke entity view. entity_view($referencing_entity, 'default'); // Verify the un-accessible item still exists. - $this->assertEqual($referencing_entity->{$field_name}->target_id, $this->referencedEntity->id(), format_string('The un-accessible item still exists after @name formatter was executed.', array('@name' => $name))); + $this->assertEqual($referencing_entity->{$field_name}->target_id, $this->referencedEntity->id(), format_string('The un-accessible item still exists after @name formatter was executed.', ['@name' => $name])); } } @@ -198,7 +198,7 @@ class EntityReferenceFormatterTest extends EntityKernelTestBase { $this->assertEqual($build[0]['#markup'], 'default | ' . $this->referencedEntity->label() . $expected_rendered_name_field_1 . $expected_rendered_body_field_1, sprintf('The markup returned by the %s formatter is correct for an item with a saved entity.', $formatter)); $expected_cache_tags = Cache::mergeTags(\Drupal::entityManager()->getViewBuilder($this->entityType)->getCacheTags(), $this->referencedEntity->getCacheTags()); $expected_cache_tags = Cache::mergeTags($expected_cache_tags, FilterFormat::load('full_html')->getCacheTags()); - $this->assertEqual($build[0]['#cache']['tags'], $expected_cache_tags, format_string('The @formatter formatter has the expected cache tags.', array('@formatter' => $formatter))); + $this->assertEqual($build[0]['#cache']['tags'], $expected_cache_tags, format_string('The @formatter formatter has the expected cache tags.', ['@formatter' => $formatter])); // Test the second field item. $expected_rendered_name_field_2 = ' @@ -338,37 +338,37 @@ class EntityReferenceFormatterTest extends EntityKernelTestBase { 'max-age' => Cache::PERMANENT, ]; $this->assertEqual($build['#cache'], $expected_field_cacheability, 'The field render array contains the entity access cacheability metadata'); - $expected_item_1 = array( + $expected_item_1 = [ '#type' => 'link', '#title' => $this->referencedEntity->label(), '#url' => $this->referencedEntity->urlInfo(), '#options' => $this->referencedEntity->urlInfo()->getOptions(), - '#cache' => array( + '#cache' => [ 'contexts' => [ 'user.permissions', ], 'tags' => $this->referencedEntity->getCacheTags(), - ), - ); + ], + ]; $this->assertEqual($renderer->renderRoot($build[0]), $renderer->renderRoot($expected_item_1), sprintf('The markup returned by the %s formatter is correct for an item with a saved entity.', $formatter)); $this->assertEqual(CacheableMetadata::createFromRenderArray($build[0]), CacheableMetadata::createFromRenderArray($expected_item_1)); // The second referenced entity is "autocreated", therefore not saved and // lacking any URL info. - $expected_item_2 = array( + $expected_item_2 = [ '#plain_text' => $this->unsavedReferencedEntity->label(), - '#cache' => array( + '#cache' => [ 'contexts' => [ 'user.permissions', ], 'tags' => $this->unsavedReferencedEntity->getCacheTags(), 'max-age' => Cache::PERMANENT, - ), - ); + ], + ]; $this->assertEqual($build[1], $expected_item_2, sprintf('The render array returned by the %s formatter is correct for an item with a unsaved entity.', $formatter)); // Test with the 'link' setting set to FALSE. - $build = $this->buildRenderArray([$this->referencedEntity, $this->unsavedReferencedEntity], $formatter, array('link' => FALSE)); + $build = $this->buildRenderArray([$this->referencedEntity, $this->unsavedReferencedEntity], $formatter, ['link' => FALSE]); $this->assertEqual($build[0]['#plain_text'], $this->referencedEntity->label(), sprintf('The markup returned by the %s formatter is correct for an item with a saved entity.', $formatter)); $this->assertEqual($build[1]['#plain_text'], $this->unsavedReferencedEntity->label(), sprintf('The markup returned by the %s formatter is correct for an item with a unsaved entity.', $formatter)); @@ -379,12 +379,12 @@ class EntityReferenceFormatterTest extends EntityKernelTestBase { $field_storage_config->setSetting('target_type', 'entity_test_label'); $field_storage_config->save(); - $referenced_entity_with_no_link_template = EntityTestLabel::create(array( + $referenced_entity_with_no_link_template = EntityTestLabel::create([ 'name' => $this->randomMachineName(), - )); + ]); $referenced_entity_with_no_link_template->save(); - $build = $this->buildRenderArray([$referenced_entity_with_no_link_template], $formatter, array('link' => TRUE)); + $build = $this->buildRenderArray([$referenced_entity_with_no_link_template], $formatter, ['link' => TRUE]); $this->assertEqual($build[0]['#plain_text'], $referenced_entity_with_no_link_template->label(), sprintf('The markup returned by the %s formatter is correct for an entity type with no valid link template.', $formatter)); } @@ -403,11 +403,11 @@ class EntityReferenceFormatterTest extends EntityKernelTestBase { * @return array * A render array. */ - protected function buildRenderArray(array $referenced_entities, $formatter, $formatter_options = array()) { + protected function buildRenderArray(array $referenced_entities, $formatter, $formatter_options = []) { // Create the entity that will have the entity reference field. $referencing_entity = $this->container->get('entity_type.manager') ->getStorage($this->entityType) - ->create(array('name' => $this->randomMachineName())); + ->create(['name' => $this->randomMachineName()]); $items = $referencing_entity->get($this->fieldName); @@ -417,7 +417,7 @@ class EntityReferenceFormatterTest extends EntityKernelTestBase { } // Build the renderable array for the field. - return $items->view(array('type' => $formatter, 'settings' => $formatter_options)); + return $items->view(['type' => $formatter, 'settings' => $formatter_options]); } } diff --git a/core/modules/field/tests/src/Kernel/EntityReference/EntityReferenceItemTest.php b/core/modules/field/tests/src/Kernel/EntityReference/EntityReferenceItemTest.php index 90d4d1f774a..ded93b85603 100644 --- a/core/modules/field/tests/src/Kernel/EntityReference/EntityReferenceItemTest.php +++ b/core/modules/field/tests/src/Kernel/EntityReference/EntityReferenceItemTest.php @@ -175,7 +175,7 @@ class EntityReferenceItemTest extends FieldKernelTestBase { // Delete terms so we have nothing to reference and try again $term->delete(); $term2->delete(); - $entity = EntityTest::create(array('name' => $this->randomMachineName())); + $entity = EntityTest::create(['name' => $this->randomMachineName()]); $entity->save(); // Test the generateSampleValue() method. @@ -244,7 +244,7 @@ class EntityReferenceItemTest extends FieldKernelTestBase { // Delete terms so we have nothing to reference and try again $this->vocabulary->delete(); $vocabulary2->delete(); - $entity = EntityTest::create(array('name' => $this->randomMachineName())); + $entity = EntityTest::create(['name' => $this->randomMachineName()]); $entity->save(); } @@ -253,11 +253,11 @@ class EntityReferenceItemTest extends FieldKernelTestBase { */ public function testEntityAutoCreate() { // The term entity is unsaved here. - $term = Term::create(array( + $term = Term::create([ 'name' => $this->randomMachineName(), 'vid' => $this->term->bundle(), 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED, - )); + ]); $entity = EntityTest::create(); // Now assign the unsaved term to the field. $entity->field_test_taxonomy_term->entity = $term; @@ -304,22 +304,22 @@ class EntityReferenceItemTest extends FieldKernelTestBase { */ public function testSelectionHandlerSettings() { $field_name = Unicode::strtolower($this->randomMachineName()); - $field_storage = FieldStorageConfig::create(array( + $field_storage = FieldStorageConfig::create([ 'field_name' => $field_name, 'entity_type' => 'entity_test', 'type' => 'entity_reference', - 'settings' => array( + 'settings' => [ 'target_type' => 'entity_test' - ), - )); + ], + ]); $field_storage->save(); // Do not specify any value for the 'handler' setting in order to verify // that the default handler with the correct derivative is used. - $field = FieldConfig::create(array( + $field = FieldConfig::create([ 'field_storage' => $field_storage, 'bundle' => 'entity_test', - )); + ]); $field->save(); $field = FieldConfig::load($field->id()); $this->assertEqual($field->getSetting('handler'), 'default:entity_test'); @@ -350,11 +350,11 @@ class EntityReferenceItemTest extends FieldKernelTestBase { */ public function testAutocreateValidation() { // The term entity is unsaved here. - $term = Term::create(array( + $term = Term::create([ 'name' => $this->randomMachineName(), 'vid' => $this->term->bundle(), 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED, - )); + ]); $entity = EntityTest::create([ 'field_test_taxonomy_term' => [ 'entity' => $term, diff --git a/core/modules/field/tests/src/Kernel/EntityReference/Views/EntityReferenceRelationshipTest.php b/core/modules/field/tests/src/Kernel/EntityReference/Views/EntityReferenceRelationshipTest.php index d18d9f30bce..2b0be855dd8 100644 --- a/core/modules/field/tests/src/Kernel/EntityReference/Views/EntityReferenceRelationshipTest.php +++ b/core/modules/field/tests/src/Kernel/EntityReference/Views/EntityReferenceRelationshipTest.php @@ -27,14 +27,14 @@ class EntityReferenceRelationshipTest extends ViewsKernelTestBase { * * @var array */ - public static $testViews = array( + public static $testViews = [ 'test_entity_reference_entity_test_view', 'test_entity_reference_entity_test_view_long', 'test_entity_reference_reverse_entity_test_view', 'test_entity_reference_entity_test_mul_view', 'test_entity_reference_reverse_entity_test_mul_view', 'test_entity_reference_group_by_empty_relationships', - ); + ]; /** * Modules to install. @@ -48,7 +48,7 @@ class EntityReferenceRelationshipTest extends ViewsKernelTestBase { * * @var array */ - protected $entities = array(); + protected $entities = []; /** * {@inheritdoc} @@ -74,9 +74,9 @@ class EntityReferenceRelationshipTest extends ViewsKernelTestBase { $this->createEntityReferenceField('entity_test_mul_changed', 'entity_test_mul_changed', 'field_test_data_with_a_long_name', 'field_test_data_with_a_long_name', 'entity_test'); // Create reference from entity_test_mul to entity_test cardinality: infinite. - $this->createEntityReferenceField('entity_test_mul', 'entity_test_mul', 'field_data_test_unlimited', 'field_data_test_unlimited', 'entity_test', 'default', array(), FieldStorageConfig::CARDINALITY_UNLIMITED); + $this->createEntityReferenceField('entity_test_mul', 'entity_test_mul', 'field_data_test_unlimited', 'field_data_test_unlimited', 'entity_test', 'default', [], FieldStorageConfig::CARDINALITY_UNLIMITED); - ViewTestData::createTestViews(get_class($this), array('entity_reference_test_views')); + ViewTestData::createTestViews(get_class($this), ['entity_reference_test_views']); } /** diff --git a/core/modules/field/tests/src/Kernel/FieldAttachOtherTest.php b/core/modules/field/tests/src/Kernel/FieldAttachOtherTest.php index ba96bc91522..c1e7ae1c51e 100644 --- a/core/modules/field/tests/src/Kernel/FieldAttachOtherTest.php +++ b/core/modules/field/tests/src/Kernel/FieldAttachOtherTest.php @@ -42,23 +42,23 @@ class FieldAttachOtherTest extends FieldKernelTestBase { $display = entity_get_display($entity_type, $entity->bundle(), 'full'); $formatter_setting = $this->randomMachineName(); - $display_options = array( + $display_options = [ 'label' => 'above', 'type' => 'field_test_default', - 'settings' => array( + 'settings' => [ 'test_formatter_setting' => $formatter_setting, - ), - ); + ], + ]; $display->setComponent($this->fieldTestData->field_name, $display_options); $formatter_setting_2 = $this->randomMachineName(); - $display_options_2 = array( + $display_options_2 = [ 'label' => 'above', 'type' => 'field_test_default', - 'settings' => array( + 'settings' => [ 'test_formatter_setting' => $formatter_setting_2, - ), - ); + ], + ]; $display->setComponent($this->fieldTestData->field_name_2, $display_options_2); // View all fields. @@ -94,13 +94,13 @@ class FieldAttachOtherTest extends FieldKernelTestBase { // Multiple formatter. $entity = clone($entity_init); $formatter_setting = $this->randomMachineName(); - $display->setComponent($this->fieldTestData->field_name, array( + $display->setComponent($this->fieldTestData->field_name, [ 'label' => 'above', 'type' => 'field_test_multiple', - 'settings' => array( + 'settings' => [ 'test_formatter_setting_multiple' => $formatter_setting, - ), - )); + ], + ]); $content = $display->build($entity); $this->render($content); $expected_output = $formatter_setting; @@ -112,13 +112,13 @@ class FieldAttachOtherTest extends FieldKernelTestBase { // Test a formatter that uses hook_field_formatter_prepare_view(). $entity = clone($entity_init); $formatter_setting = $this->randomMachineName(); - $display->setComponent($this->fieldTestData->field_name, array( + $display->setComponent($this->fieldTestData->field_name, [ 'label' => 'above', 'type' => 'field_test_with_prepare_view', - 'settings' => array( + 'settings' => [ 'test_formatter_setting_additional' => $formatter_setting, - ), - )); + ], + ]); $content = $display->build($entity); $this->render($content); foreach ($values as $delta => $value) { @@ -136,18 +136,18 @@ class FieldAttachOtherTest extends FieldKernelTestBase { function testEntityDisplayViewMultiple() { // Use a formatter that has a prepareView() step. $display = entity_get_display('entity_test', 'entity_test', 'full') - ->setComponent($this->fieldTestData->field_name, array( + ->setComponent($this->fieldTestData->field_name, [ 'type' => 'field_test_with_prepare_view', - )); + ]); // Create two entities. - $entity1 = EntityTest::create(array('id' => 1, 'type' => 'entity_test')); + $entity1 = EntityTest::create(['id' => 1, 'type' => 'entity_test']); $entity1->{$this->fieldTestData->field_name}->setValue($this->_generateTestFieldValues(1)); - $entity2 = EntityTest::create(array('id' => 2, 'type' => 'entity_test')); + $entity2 = EntityTest::create(['id' => 2, 'type' => 'entity_test']); $entity2->{$this->fieldTestData->field_name}->setValue($this->_generateTestFieldValues(1)); // Run buildMultiple(), and check that the entities come out as expected. - $display->buildMultiple(array($entity1, $entity2)); + $display->buildMultiple([$entity1, $entity2]); $item1 = $entity1->{$this->fieldTestData->field_name}[0]; $this->assertEqual($item1->additional_formatter_value, $item1->value + 1, 'Entity 1 ran through the prepareView() formatter method.'); $item2 = $entity2->{$this->fieldTestData->field_name}[0]; @@ -162,7 +162,7 @@ class FieldAttachOtherTest extends FieldKernelTestBase { */ function testEntityCache() { // Initialize random values and a test entity. - $entity_init = EntityTest::create(array('type' => $this->fieldTestData->field->getTargetBundle())); + $entity_init = EntityTest::create(['type' => $this->fieldTestData->field->getTargetBundle()]); $values = $this->_generateTestFieldValues($this->fieldTestData->field_storage->getCardinality()); // Non-cacheable entity type. @@ -185,9 +185,9 @@ class FieldAttachOtherTest extends FieldKernelTestBase { $entity_init = $this->container->get('entity_type.manager') ->getStorage($entity_type) - ->create(array( + ->create([ 'type' => $entity_type, - )); + ]); // Check that no initial cache entry is present. $cid = "values:$entity_type:" . $entity->id(); @@ -247,11 +247,11 @@ class FieldAttachOtherTest extends FieldKernelTestBase { $this->createFieldWithStorage('_2'); $entity_type = 'entity_test'; - $entity = entity_create($entity_type, array('id' => 1, 'revision_id' => 1, 'type' => $this->fieldTestData->field->getTargetBundle())); + $entity = entity_create($entity_type, ['id' => 1, 'revision_id' => 1, 'type' => $this->fieldTestData->field->getTargetBundle()]); // Test generating widgets for all fields. $display = entity_get_form_display($entity_type, $this->fieldTestData->field->getTargetBundle(), 'default'); - $form = array(); + $form = []; $form_state = new FormState(); $display->buildForm($entity, $form, $form_state); @@ -273,7 +273,7 @@ class FieldAttachOtherTest extends FieldKernelTestBase { $display->removeComponent($name); } } - $form = array(); + $form = []; $form_state = new FormState(); $display->buildForm($entity, $form, $form_state); @@ -294,18 +294,18 @@ class FieldAttachOtherTest extends FieldKernelTestBase { $entity_type = 'entity_test'; $entity_init = $this->container->get('entity_type.manager') ->getStorage($entity_type) - ->create(array('id' => 1, 'revision_id' => 1, 'type' => $this->fieldTestData->field->getTargetBundle())); + ->create(['id' => 1, 'revision_id' => 1, 'type' => $this->fieldTestData->field->getTargetBundle()]); // Build the form for all fields. $display = entity_get_form_display($entity_type, $this->fieldTestData->field->getTargetBundle(), 'default'); - $form = array(); + $form = []; $form_state = new FormState(); $display->buildForm($entity_init, $form, $form_state); // Simulate incoming values. // First field. - $values = array(); - $weights = array(); + $values = []; + $weights = []; for ($delta = 0; $delta < $this->fieldTestData->field_storage->getCardinality(); $delta++) { $values[$delta]['value'] = mt_rand(1, 127); // Assign random weight. @@ -318,8 +318,8 @@ class FieldAttachOtherTest extends FieldKernelTestBase { // Leave an empty value. 'field_test' fields are empty if empty(). $values[1]['value'] = 0; // Second field. - $values_2 = array(); - $weights_2 = array(); + $values_2 = []; + $weights_2 = []; for ($delta = 0; $delta < $this->fieldTestData->field_storage_2->getCardinality(); $delta++) { $values_2[$delta]['value'] = mt_rand(1, 127); // Assign random weight. @@ -345,17 +345,17 @@ class FieldAttachOtherTest extends FieldKernelTestBase { asort($weights); asort($weights_2); - $expected_values = array(); - $expected_values_2 = array(); + $expected_values = []; + $expected_values_2 = []; foreach ($weights as $key => $value) { if ($key != 1) { - $expected_values[] = array('value' => $values[$key]['value']); + $expected_values[] = ['value' => $values[$key]['value']]; } } $this->assertIdentical($entity->{$this->fieldTestData->field_name}->getValue(), $expected_values, 'Submit filters empty values'); foreach ($weights_2 as $key => $value) { if ($key != 1) { - $expected_values_2[] = array('value' => $values_2[$key]['value']); + $expected_values_2[] = ['value' => $values_2[$key]['value']]; } } $this->assertIdentical($entity->{$this->fieldTestData->field_name_2}->getValue(), $expected_values_2, 'Submit filters empty values'); @@ -368,10 +368,10 @@ class FieldAttachOtherTest extends FieldKernelTestBase { } $entity = clone($entity_init); $display->extractFormValues($entity, $form, $form_state); - $expected_values_2 = array(); + $expected_values_2 = []; foreach ($weights_2 as $key => $value) { if ($key != 1) { - $expected_values_2[] = array('value' => $values_2[$key]['value']); + $expected_values_2[] = ['value' => $values_2[$key]['value']]; } } $this->assertTrue($entity->{$this->fieldTestData->field_name}->isEmpty(), 'The first field is empty in the entity object'); diff --git a/core/modules/field/tests/src/Kernel/FieldAttachStorageTest.php b/core/modules/field/tests/src/Kernel/FieldAttachStorageTest.php index 8237ef4d8b9..9f0eef33d24 100644 --- a/core/modules/field/tests/src/Kernel/FieldAttachStorageTest.php +++ b/core/modules/field/tests/src/Kernel/FieldAttachStorageTest.php @@ -31,7 +31,7 @@ class FieldAttachStorageTest extends FieldKernelTestBase { // TODO : test empty values filtering and "compression" (store consecutive deltas). // Preparation: create three revisions and store them in $revision array. - $values = array(); + $values = []; $entity = $this->container->get('entity_type.manager') ->getStorage($entity_type) ->create(); @@ -54,17 +54,17 @@ class FieldAttachStorageTest extends FieldKernelTestBase { $this->assertEqual(count($entity->{$this->fieldTestData->field_name}), $cardinality, 'Current revision: expected number of values'); for ($delta = 0; $delta < $cardinality; $delta++) { // The field value loaded matches the one inserted or updated. - $this->assertEqual($entity->{$this->fieldTestData->field_name}[$delta]->value, $values[$current_revision][$delta]['value'], format_string('Current revision: expected value %delta was found.', array('%delta' => $delta))); + $this->assertEqual($entity->{$this->fieldTestData->field_name}[$delta]->value, $values[$current_revision][$delta]['value'], format_string('Current revision: expected value %delta was found.', ['%delta' => $delta])); } // Confirm each revision loads the correct data. foreach (array_keys($values) as $revision_id) { $entity = $storage->loadRevision($revision_id); // Number of values per field loaded equals the field cardinality. - $this->assertEqual(count($entity->{$this->fieldTestData->field_name}), $cardinality, format_string('Revision %revision_id: expected number of values.', array('%revision_id' => $revision_id))); + $this->assertEqual(count($entity->{$this->fieldTestData->field_name}), $cardinality, format_string('Revision %revision_id: expected number of values.', ['%revision_id' => $revision_id])); for ($delta = 0; $delta < $cardinality; $delta++) { // The field value loaded matches the one inserted or updated. - $this->assertEqual($entity->{$this->fieldTestData->field_name}[$delta]->value, $values[$revision_id][$delta]['value'], format_string('Revision %revision_id: expected value %delta was found.', array('%revision_id' => $revision_id, '%delta' => $delta))); + $this->assertEqual($entity->{$this->fieldTestData->field_name}[$delta]->value, $values[$revision_id][$delta]['value'], format_string('Revision %revision_id: expected value %delta was found.', ['%revision_id' => $revision_id, '%delta' => $delta])); } } } @@ -76,28 +76,28 @@ class FieldAttachStorageTest extends FieldKernelTestBase { $entity_type = 'entity_test_rev'; // Define 2 bundles. - $bundles = array( + $bundles = [ 1 => 'test_bundle_1', 2 => 'test_bundle_2', - ); + ]; entity_test_create_bundle($bundles[1]); entity_test_create_bundle($bundles[2]); // Define 3 fields: // - field_1 is in bundle_1 and bundle_2, // - field_2 is in bundle_1, // - field_3 is in bundle_2. - $field_bundles_map = array( - 1 => array(1, 2), - 2 => array(1), - 3 => array(2), - ); + $field_bundles_map = [ + 1 => [1, 2], + 2 => [1], + 3 => [2], + ]; for ($i = 1; $i <= 3; $i++) { $field_names[$i] = 'field_' . $i; - $field_storage = FieldStorageConfig::create(array( + $field_storage = FieldStorageConfig::create([ 'field_name' => $field_names[$i], 'entity_type' => $entity_type, 'type' => 'test_field', - )); + ]); $field_storage->save(); $field_ids[$i] = $field_storage->uuid(); foreach ($field_bundles_map[$i] as $bundle) { @@ -113,14 +113,14 @@ class FieldAttachStorageTest extends FieldKernelTestBase { foreach ($bundles as $index => $bundle) { $entities[$index] = $this->container->get('entity_type.manager') ->getStorage($entity_type) - ->create(array('id' => $index, 'revision_id' => $index, 'type' => $bundle)); + ->create(['id' => $index, 'revision_id' => $index, 'type' => $bundle]); $entity = clone($entities[$index]); foreach ($field_names as $field_name) { if (!$entity->hasField($field_name)) { continue; } $values[$index][$field_name] = mt_rand(1, 127); - $entity->$field_name->setValue(array('value' => $values[$index][$field_name])); + $entity->$field_name->setValue(['value' => $values[$index][$field_name]]); } $entity->enforceIsnew(); $entity->save(); @@ -136,7 +136,7 @@ class FieldAttachStorageTest extends FieldKernelTestBase { continue; } // The field value loaded matches the one inserted. - $this->assertEqual($entity->{$field_name}->value, $values[$index][$field_name], format_string('Entity %index: expected value was found.', array('%index' => $index))); + $this->assertEqual($entity->{$field_name}->value, $values[$index][$field_name], format_string('Entity %index: expected value was found.', ['%index' => $index])); } } } @@ -150,7 +150,7 @@ class FieldAttachStorageTest extends FieldKernelTestBase { $entity_init = $this->container->get('entity_type.manager') ->getStorage($entity_type) - ->create(array('id' => 1)); + ->create(['id' => 1]); // Insert: Field is NULL. $entity = clone $entity_init; @@ -184,7 +184,7 @@ class FieldAttachStorageTest extends FieldKernelTestBase { // Update: Field is empty array. Data should be wiped. $entity = clone($entity_init); - $entity->{$this->fieldTestData->field_name} = array(); + $entity->{$this->fieldTestData->field_name} = []; $entity = $this->entitySaveReload($entity); $this->assertTrue($entity->{$this->fieldTestData->field_name}->isEmpty(), 'Update: empty array removes existing values'); } @@ -203,7 +203,7 @@ class FieldAttachStorageTest extends FieldKernelTestBase { // Verify that fields are populated with default values. $entity_init = $this->container->get('entity_type.manager') ->getStorage($entity_type) - ->create(array('id' => 1, 'revision_id' => 1)); + ->create(['id' => 1, 'revision_id' => 1]); $default = field_test_default_value($entity_init, $this->fieldTestData->field); $this->assertEqual($entity_init->{$this->fieldTestData->field_name}->getValue(), $default, 'Default field value correctly populated.'); @@ -215,10 +215,10 @@ class FieldAttachStorageTest extends FieldKernelTestBase { $this->assertTrue($entity->{$this->fieldTestData->field_name}->isEmpty(), 'Insert: NULL field results in no value saved'); // Verify that prepopulated field values are not overwritten by defaults. - $value = array(array('value' => $default[0]['value'] - mt_rand(1, 127))); + $value = [['value' => $default[0]['value'] - mt_rand(1, 127)]]; $entity = $this->container->get('entity_type.manager') ->getStorage($entity_type) - ->create(array('type' => $entity_init->bundle(), $this->fieldTestData->field_name => $value)); + ->create(['type' => $entity_init->bundle(), $this->fieldTestData->field_name => $value]); $this->assertEqual($entity->{$this->fieldTestData->field_name}->getValue(), $value, 'Prepopulated field value correctly maintained.'); } @@ -231,8 +231,8 @@ class FieldAttachStorageTest extends FieldKernelTestBase { $cardinality = $this->fieldTestData->field_storage->getCardinality(); $entity = $this->container->get('entity_type.manager') ->getStorage($entity_type) - ->create(array('type' => $this->fieldTestData->field->getTargetBundle())); - $vids = array(); + ->create(['type' => $this->fieldTestData->field->getTargetBundle()]); + $vids = []; // Create revision 0 $values = $this->_generateTestFieldValues($cardinality); @@ -261,7 +261,7 @@ class FieldAttachStorageTest extends FieldKernelTestBase { // Delete revision 1, confirm the other two still load. $controller->deleteRevision($vids[1]); $controller->resetCache(); - foreach (array(0, 2) as $key) { + foreach ([0, 2] as $key) { $vid = $vids[$key]; $revision = $controller->loadRevision($vid); $this->assertEqual(count($revision->{$this->fieldTestData->field_name}), $cardinality, "The test entity revision $vid has $cardinality values."); @@ -275,7 +275,7 @@ class FieldAttachStorageTest extends FieldKernelTestBase { // Delete all field data, confirm nothing loads $entity->delete(); $controller->resetCache(); - foreach (array(0, 1, 2) as $vid) { + foreach ([0, 1, 2] as $vid) { $revision = $controller->loadRevision($vid); $this->assertFalse($revision); } @@ -301,7 +301,7 @@ class FieldAttachStorageTest extends FieldKernelTestBase { // Save an entity with data in the field. $entity = $this->container->get('entity_type.manager') ->getStorage($entity_type) - ->create(array('type' => $this->fieldTestData->field->getTargetBundle())); + ->create(['type' => $this->fieldTestData->field->getTargetBundle()]); $values = $this->_generateTestFieldValues($cardinality); $entity->{$this->fieldTestData->field_name} = $values; @@ -327,27 +327,27 @@ class FieldAttachStorageTest extends FieldKernelTestBase { // Create a second field for the test bundle $field_name = Unicode::strtolower($this->randomMachineName() . '_field_name'); - $field_storage = array( + $field_storage = [ 'field_name' => $field_name, 'entity_type' => $entity_type, 'type' => 'test_field', 'cardinality' => 1, - ); + ]; FieldStorageConfig::create($field_storage)->save(); - $field = array( + $field = [ 'field_name' => $field_name, 'entity_type' => $entity_type, 'bundle' => $this->fieldTestData->field->getTargetBundle(), 'label' => $this->randomMachineName() . '_label', 'description' => $this->randomMachineName() . '_description', 'weight' => mt_rand(0, 127), - ); + ]; FieldConfig::create($field)->save(); // Save an entity with data for both fields $entity = $this->container->get('entity_type.manager') ->getStorage($entity_type) - ->create(array('type' => $this->fieldTestData->field->getTargetBundle())); + ->create(['type' => $this->fieldTestData->field->getTargetBundle()]); $values = $this->_generateTestFieldValues($this->fieldTestData->field_storage->getCardinality()); $entity->{$this->fieldTestData->field_name} = $values; $entity->{$field_name} = $this->_generateTestFieldValues(1); diff --git a/core/modules/field/tests/src/Kernel/FieldCrudTest.php b/core/modules/field/tests/src/Kernel/FieldCrudTest.php index a61d64565f7..85121c96e74 100644 --- a/core/modules/field/tests/src/Kernel/FieldCrudTest.php +++ b/core/modules/field/tests/src/Kernel/FieldCrudTest.php @@ -40,18 +40,18 @@ class FieldCrudTest extends FieldKernelTestBase { function setUp() { parent::setUp(); - $this->fieldStorageDefinition = array( + $this->fieldStorageDefinition = [ 'field_name' => Unicode::strtolower($this->randomMachineName()), 'entity_type' => 'entity_test', 'type' => 'test_field', - ); + ]; $this->fieldStorage = FieldStorageConfig::create($this->fieldStorageDefinition); $this->fieldStorage->save(); - $this->fieldDefinition = array( + $this->fieldDefinition = [ 'field_name' => $this->fieldStorage->getName(), 'entity_type' => 'entity_test', 'bundle' => 'entity_test', - ); + ]; } // TODO : test creation with @@ -223,12 +223,12 @@ class FieldCrudTest extends FieldKernelTestBase { FieldConfig::create($another_field_definition)->save(); // Test that the first field is not deleted, and then delete it. - $field = current(entity_load_multiple_by_properties('field_config', array('entity_type' => 'entity_test', 'field_name' => $this->fieldDefinition['field_name'], 'bundle' => $this->fieldDefinition['bundle'], 'include_deleted' => TRUE))); + $field = current(entity_load_multiple_by_properties('field_config', ['entity_type' => 'entity_test', 'field_name' => $this->fieldDefinition['field_name'], 'bundle' => $this->fieldDefinition['bundle'], 'include_deleted' => TRUE])); $this->assertTrue(!empty($field) && empty($field->deleted), 'A new field is not marked for deletion.'); $field->delete(); // Make sure the field is marked as deleted when it is specifically loaded. - $field = current(entity_load_multiple_by_properties('field_config', array('entity_type' => 'entity_test', 'field_name' => $this->fieldDefinition['field_name'], 'bundle' => $this->fieldDefinition['bundle'], 'include_deleted' => TRUE))); + $field = current(entity_load_multiple_by_properties('field_config', ['entity_type' => 'entity_test', 'field_name' => $this->fieldDefinition['field_name'], 'bundle' => $this->fieldDefinition['bundle'], 'include_deleted' => TRUE])); $this->assertTrue($field->isDeleted(), 'A deleted field is marked for deletion.'); // Try to load the field normally and make sure it does not show up. @@ -276,7 +276,7 @@ class FieldCrudTest extends FieldKernelTestBase { $field->save(); $field_2 = FieldConfig::create($field_definition_2); $field_2->save(); - $this->container->get('entity.manager')->getStorage('field_config')->delete(array($field, $field_2)); + $this->container->get('entity.manager')->getStorage('field_config')->delete([$field, $field_2]); $this->assertFalse(FieldStorageConfig::loadByName('entity_test', $field_storage->getName())); } diff --git a/core/modules/field/tests/src/Kernel/FieldDataCountTest.php b/core/modules/field/tests/src/Kernel/FieldDataCountTest.php index e0ea6836903..2bbe24d68ca 100644 --- a/core/modules/field/tests/src/Kernel/FieldDataCountTest.php +++ b/core/modules/field/tests/src/Kernel/FieldDataCountTest.php @@ -50,12 +50,12 @@ class FieldDataCountTest extends FieldKernelTestBase { // Create a field with a cardinality of 2 to show that we are counting // entities and not rows in a table. /** @var \Drupal\field\Entity\FieldStorageConfig $field_storage */ - $field_storage = FieldStorageConfig::create(array( + $field_storage = FieldStorageConfig::create([ 'field_name' => 'field_int', 'entity_type' => 'entity_test', 'type' => 'integer', 'cardinality' => 2, - )); + ]); $field_storage->save(); FieldConfig::create([ 'field_storage' => $field_storage, @@ -112,7 +112,7 @@ class FieldDataCountTest extends FieldKernelTestBase { $entity_init = $this->container->get('entity_type.manager') ->getStorage($entity_type) - ->create(array('type' => $entity_type,)); + ->create(['type' => $entity_type,]); $cardinality = $this->fieldTestData->field_storage_2->getCardinality(); $this->assertIdentical($this->fieldTestData->field_storage_2->hasData(), FALSE, 'There are no entities with field data.'); @@ -129,7 +129,7 @@ class FieldDataCountTest extends FieldKernelTestBase { $this->assertIdentical($this->fieldTestData->field_storage_2->hasData(), TRUE, 'There are entities with field data.'); $this->assertIdentical($this->storageRev->countFieldData($this->fieldTestData->field_storage_2), 1, 'There is 1 entity with field data.'); - $entity->{$this->fieldTestData->field_name_2} = array(); + $entity->{$this->fieldTestData->field_name_2} = []; $entity->setNewRevision(); $entity->save(); @@ -137,7 +137,7 @@ class FieldDataCountTest extends FieldKernelTestBase { $storage = $this->container->get('entity.manager')->getStorage($entity_type); $entity = $storage->loadRevision($first_revision); - $this->assertEqual(count($entity->{$this->fieldTestData->field_name_2}), $cardinality, format_string('Revision %revision_id: expected number of values.', array('%revision_id' => $first_revision))); + $this->assertEqual(count($entity->{$this->fieldTestData->field_name_2}), $cardinality, format_string('Revision %revision_id: expected number of values.', ['%revision_id' => $first_revision])); } /** @@ -146,27 +146,27 @@ class FieldDataCountTest extends FieldKernelTestBase { public function testCountWithIndex0() { // Create a field that will require dedicated storage. /** @var \Drupal\field\Entity\FieldStorageConfig $field_storage */ - $field_storage = FieldStorageConfig::create(array( + $field_storage = FieldStorageConfig::create([ 'field_name' => 'field_int', 'entity_type' => 'user', 'type' => 'integer', 'cardinality' => 2, - )); + ]); $field_storage->save(); - FieldConfig::create(array( + FieldConfig::create([ 'field_storage' => $field_storage, 'bundle' => 'user', - ))->save(); + ])->save(); // Create an entry for the anonymous user, who has user ID 0. $user = $this->storageUser - ->create(array( + ->create([ 'uid' => 0, 'name' => 'anonymous', 'mail' => NULL, 'status' => FALSE, 'field_int' => 42, - )); + ]); $user->save(); // Test shared table storage. diff --git a/core/modules/field/tests/src/Kernel/FieldImportChangeTest.php b/core/modules/field/tests/src/Kernel/FieldImportChangeTest.php index 8cd029188e8..10eff6d6eca 100644 --- a/core/modules/field/tests/src/Kernel/FieldImportChangeTest.php +++ b/core/modules/field/tests/src/Kernel/FieldImportChangeTest.php @@ -20,7 +20,7 @@ class FieldImportChangeTest extends FieldKernelTestBase { * * @var array */ - public static $modules = array('field_test_config'); + public static $modules = ['field_test_config']; /** * Tests importing an updated field. diff --git a/core/modules/field/tests/src/Kernel/FieldImportCreateTest.php b/core/modules/field/tests/src/Kernel/FieldImportCreateTest.php index 3478dd3bea2..007bb0f6e01 100644 --- a/core/modules/field/tests/src/Kernel/FieldImportCreateTest.php +++ b/core/modules/field/tests/src/Kernel/FieldImportCreateTest.php @@ -37,7 +37,7 @@ class FieldImportCreateTest extends FieldKernelTestBase { // Enable field_test_config module and check that the field and storage // shipped in the module's default config were created. - \Drupal::service('module_installer')->install(array('field_test_config')); + \Drupal::service('module_installer')->install(['field_test_config']); // A field storage with one single field. $field_storage = FieldStorageConfig::load($field_storage_id); diff --git a/core/modules/field/tests/src/Kernel/FieldImportDeleteTest.php b/core/modules/field/tests/src/Kernel/FieldImportDeleteTest.php index b536fe8046a..0eef137165a 100644 --- a/core/modules/field/tests/src/Kernel/FieldImportDeleteTest.php +++ b/core/modules/field/tests/src/Kernel/FieldImportDeleteTest.php @@ -22,7 +22,7 @@ class FieldImportDeleteTest extends FieldKernelTestBase { * * @var array */ - public static $modules = array('field_test_config'); + public static $modules = ['field_test_config']; /** * Tests deleting field storages and fields as part of config import. @@ -60,11 +60,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', array('@field_storage' => $field_storage_config_name))); - $this->assertTrue($sync->delete($field_storage_config_name_2), SafeMarkup::format('Deleted field storage: @field_storage', array('@field_storage' => $field_storage_config_name_2))); - $this->assertTrue($sync->delete($field_config_name), SafeMarkup::format('Deleted field: @field', array('@field' => $field_config_name))); - $this->assertTrue($sync->delete($field_config_name_2a), SafeMarkup::format('Deleted field: @field', array('@field' => $field_config_name_2a))); - $this->assertTrue($sync->delete($field_config_name_2b), SafeMarkup::format('Deleted field: @field', array('@field' => $field_config_name_2b))); + $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])); $deletes = $this->configImporter()->getUnprocessedConfiguration('delete'); $this->assertEqual(count($deletes), 5, 'Importing configuration will delete 3 fields and 2 field storages.'); @@ -73,39 +73,39 @@ class FieldImportDeleteTest extends FieldKernelTestBase { $this->configImporter()->import(); // Check that the field storages and fields are gone. - \Drupal::entityManager()->getStorage('field_storage_config')->resetCache(array($field_storage_id)); + \Drupal::entityManager()->getStorage('field_storage_config')->resetCache([$field_storage_id]); $field_storage = FieldStorageConfig::load($field_storage_id); $this->assertFalse($field_storage, 'The field storage was deleted.'); - \Drupal::entityManager()->getStorage('field_storage_config')->resetCache(array($field_storage_id_2)); + \Drupal::entityManager()->getStorage('field_storage_config')->resetCache([$field_storage_id_2]); $field_storage_2 = FieldStorageConfig::load($field_storage_id_2); $this->assertFalse($field_storage_2, 'The second field storage was deleted.'); - \Drupal::entityManager()->getStorage('field_config')->resetCache(array($field_id)); + \Drupal::entityManager()->getStorage('field_config')->resetCache([$field_id]); $field = FieldConfig::load($field_id); $this->assertFalse($field, 'The field was deleted.'); - \Drupal::entityManager()->getStorage('field_config')->resetCache(array($field_id_2a)); + \Drupal::entityManager()->getStorage('field_config')->resetCache([$field_id_2a]); $field_2a = FieldConfig::load($field_id_2a); $this->assertFalse($field_2a, 'The second field on test bundle was deleted.'); - \Drupal::entityManager()->getStorage('field_config')->resetCache(array($field_id_2b)); + \Drupal::entityManager()->getStorage('field_config')->resetCache([$field_id_2b]); $field_2b = FieldConfig::load($field_id_2b); $this->assertFalse($field_2b, 'The second field on test bundle 2 was deleted.'); // Check that all config files are gone. $active = $this->container->get('config.storage'); - $this->assertIdentical($active->listAll($field_storage_config_name), array()); - $this->assertIdentical($active->listAll($field_storage_config_name_2), array()); - $this->assertIdentical($active->listAll($field_config_name), array()); - $this->assertIdentical($active->listAll($field_config_name_2a), array()); - $this->assertIdentical($active->listAll($field_config_name_2b), array()); + $this->assertIdentical($active->listAll($field_storage_config_name), []); + $this->assertIdentical($active->listAll($field_storage_config_name_2), []); + $this->assertIdentical($active->listAll($field_config_name), []); + $this->assertIdentical($active->listAll($field_config_name_2a), []); + $this->assertIdentical($active->listAll($field_config_name_2b), []); // Check that the storage definition is preserved in state. - $deleted_storages = \Drupal::state()->get('field.storage.deleted') ?: array(); + $deleted_storages = \Drupal::state()->get('field.storage.deleted') ?: []; $this->assertTrue(isset($deleted_storages[$field_storage_uuid])); $this->assertTrue(isset($deleted_storages[$field_storage_uuid_2])); // Purge field data, and check that the storage definition has been // completely removed once the data is purged. field_purge_batch(10); - $deleted_storages = \Drupal::state()->get('field.storage.deleted') ?: array(); + $deleted_storages = \Drupal::state()->get('field.storage.deleted') ?: []; $this->assertTrue(empty($deleted_storages), 'Fields are deleted'); } diff --git a/core/modules/field/tests/src/Kernel/FieldImportDeleteUninstallTest.php b/core/modules/field/tests/src/Kernel/FieldImportDeleteUninstallTest.php index dab6e0d53f6..c3a4d3c1d54 100644 --- a/core/modules/field/tests/src/Kernel/FieldImportDeleteUninstallTest.php +++ b/core/modules/field/tests/src/Kernel/FieldImportDeleteUninstallTest.php @@ -21,14 +21,14 @@ class FieldImportDeleteUninstallTest extends FieldKernelTestBase { * * @var array */ - public static $modules = array('telephone'); + public static $modules = ['telephone']; protected function setUp() { parent::setUp(); // Module uninstall requires users_data tables. // @see drupal_flush_all_caches() // @see user_modules_uninstalled() - $this->installSchema('user', array('users_data')); + $this->installSchema('user', ['users_data']); } /** @@ -38,11 +38,11 @@ class FieldImportDeleteUninstallTest extends FieldKernelTestBase { // Create a field to delete to prove that // \Drupal\field\ConfigImporterFieldPurger does not purge fields that are // not related to the configuration synchronization. - $unrelated_field_storage = FieldStorageConfig::create(array( + $unrelated_field_storage = FieldStorageConfig::create([ 'field_name' => 'field_int', 'entity_type' => 'entity_test', 'type' => 'integer', - )); + ]); $unrelated_field_storage->save(); FieldConfig::create([ 'field_storage' => $unrelated_field_storage, @@ -50,11 +50,11 @@ class FieldImportDeleteUninstallTest extends FieldKernelTestBase { ])->save(); // Create a telephone field for validation. - $field_storage = FieldStorageConfig::create(array( + $field_storage = FieldStorageConfig::create([ 'field_name' => 'field_test', 'entity_type' => 'entity_test', 'type' => 'telephone', - )); + ]); $field_storage->save(); FieldConfig::create([ 'field_storage' => $field_storage, @@ -93,7 +93,7 @@ class FieldImportDeleteUninstallTest extends FieldKernelTestBase { $sync->delete('field.field.entity_test.entity_test.field_test'); $steps = $this->configImporter()->initialize(); - $this->assertIdentical($steps[0], array('\Drupal\field\ConfigImporterFieldPurger', 'process'), 'The additional process configuration synchronization step has been added.'); + $this->assertIdentical($steps[0], ['\Drupal\field\ConfigImporterFieldPurger', 'process'], 'The additional process configuration synchronization step has been added.'); // This will purge all the data, delete the field and uninstall the // Telephone module. @@ -101,7 +101,7 @@ class FieldImportDeleteUninstallTest extends FieldKernelTestBase { $this->assertFalse(\Drupal::moduleHandler()->moduleExists('telephone')); $this->assertFalse(\Drupal::entityManager()->loadEntityByUuid('field_storage_config', $field_storage->uuid()), 'The test field has been deleted by the configuration synchronization'); - $deleted_storages = \Drupal::state()->get('field.storage.deleted') ?: array(); + $deleted_storages = \Drupal::state()->get('field.storage.deleted') ?: []; $this->assertFalse(isset($deleted_storages[$field_storage->uuid()]), 'Telephone field has been completed removed from the system.'); $this->assertTrue(isset($deleted_storages[$unrelated_field_storage->uuid()]), 'Unrelated field not purged by configuration synchronization.'); } @@ -112,11 +112,11 @@ class FieldImportDeleteUninstallTest extends FieldKernelTestBase { */ public function testImportAlreadyDeletedUninstall() { // Create a telephone field for validation. - $field_storage = FieldStorageConfig::create(array( + $field_storage = FieldStorageConfig::create([ 'field_name' => 'field_test', 'entity_type' => 'entity_test', 'type' => 'telephone', - )); + ]); $field_storage->save(); $field_storage_uuid = $field_storage->uuid(); FieldConfig::create([ @@ -150,18 +150,18 @@ class FieldImportDeleteUninstallTest extends FieldKernelTestBase { unset($core_extension['module']['telephone']); $sync->write('core.extension', $core_extension); - $deleted_storages = \Drupal::state()->get('field.storage.deleted') ?: array(); + $deleted_storages = \Drupal::state()->get('field.storage.deleted') ?: []; $this->assertTrue(isset($deleted_storages[$field_storage_uuid]), 'Field has been deleted and needs purging before configuration synchronization.'); $steps = $this->configImporter()->initialize(); - $this->assertIdentical($steps[0], array('\Drupal\field\ConfigImporterFieldPurger', 'process'), 'The additional process configuration synchronization step has been added.'); + $this->assertIdentical($steps[0], ['\Drupal\field\ConfigImporterFieldPurger', 'process'], 'The additional process configuration synchronization step has been added.'); // This will purge all the data, delete the field and uninstall the // Telephone module. $this->configImporter()->import(); $this->assertFalse(\Drupal::moduleHandler()->moduleExists('telephone')); - $deleted_storages = \Drupal::state()->get('field.storage.deleted') ?: array(); + $deleted_storages = \Drupal::state()->get('field.storage.deleted') ?: []; $this->assertFalse(isset($deleted_storages[$field_storage_uuid]), 'Field has been completed removed from the system.'); } diff --git a/core/modules/field/tests/src/Kernel/FieldKernelTestBase.php b/core/modules/field/tests/src/Kernel/FieldKernelTestBase.php index 4d6bd5111dc..6bc40cc3db8 100644 --- a/core/modules/field/tests/src/Kernel/FieldKernelTestBase.php +++ b/core/modules/field/tests/src/Kernel/FieldKernelTestBase.php @@ -43,24 +43,24 @@ abstract class FieldKernelTestBase extends KernelTestBase { protected function setUp() { parent::setUp(); - $this->fieldTestData = new \ArrayObject(array(), \ArrayObject::ARRAY_AS_PROPS); + $this->fieldTestData = new \ArrayObject([], \ArrayObject::ARRAY_AS_PROPS); $this->installEntitySchema('entity_test'); $this->installEntitySchema('user'); $this->installSchema('system', ['sequences', 'key_value']); // Set default storage backend and configure the theme system. - $this->installConfig(array('field', 'system')); + $this->installConfig(['field', 'system']); // Create user 1. $storage = \Drupal::entityManager()->getStorage('user'); $storage - ->create(array( + ->create([ 'uid' => 1, 'name' => 'entity-test', 'mail' => 'entity@localhost', 'status' => TRUE, - )) + ]) ->save(); } @@ -88,33 +88,33 @@ abstract class FieldKernelTestBase extends KernelTestBase { $field_definition = 'field_definition' . $suffix; $this->fieldTestData->$field_name = Unicode::strtolower($this->randomMachineName() . '_field_name' . $suffix); - $this->fieldTestData->$field_storage = FieldStorageConfig::create(array( + $this->fieldTestData->$field_storage = FieldStorageConfig::create([ 'field_name' => $this->fieldTestData->$field_name, 'entity_type' => $entity_type, 'type' => 'test_field', 'cardinality' => 4, - )); + ]); $this->fieldTestData->$field_storage->save(); $this->fieldTestData->$field_storage_uuid = $this->fieldTestData->$field_storage->uuid(); - $this->fieldTestData->$field_definition = array( + $this->fieldTestData->$field_definition = [ 'field_storage' => $this->fieldTestData->$field_storage, 'bundle' => $bundle, 'label' => $this->randomMachineName() . '_label', 'description' => $this->randomMachineName() . '_description', - 'settings' => array( + 'settings' => [ 'test_field_setting' => $this->randomMachineName(), - ), - ); + ], + ]; $this->fieldTestData->$field = FieldConfig::create($this->fieldTestData->$field_definition); $this->fieldTestData->$field->save(); entity_get_form_display($entity_type, $bundle, 'default') - ->setComponent($this->fieldTestData->$field_name, array( + ->setComponent($this->fieldTestData->$field_name, [ 'type' => 'test_field_widget', - 'settings' => array( + 'settings' => [ 'test_widget_setting' => $this->randomMachineName(), - ) - )) + ] + ]) ->save(); } @@ -159,7 +159,7 @@ abstract class FieldKernelTestBase extends KernelTestBase { * An array of random values, in the format expected for field values. */ protected function _generateTestFieldValues($cardinality) { - $values = array(); + $values = []; for ($i = 0; $i < $cardinality; $i++) { // field_test fields treat 0 as 'empty value'. $values[$i]['value'] = mt_rand(1, 127); @@ -197,7 +197,7 @@ abstract class FieldKernelTestBase extends KernelTestBase { $values = $field->getValue(); $this->assertEqual(count($values), count($expected_values), 'Expected number of values were saved.'); foreach ($expected_values as $key => $value) { - $this->assertEqual($values[$key][$column], $value, format_string('Value @value was saved correctly.', array('@value' => $value))); + $this->assertEqual($values[$key][$column], $value, format_string('Value @value was saved correctly.', ['@value' => $value])); } } diff --git a/core/modules/field/tests/src/Kernel/FieldStorageCrudTest.php b/core/modules/field/tests/src/Kernel/FieldStorageCrudTest.php index da1948c149b..13091c4dffe 100644 --- a/core/modules/field/tests/src/Kernel/FieldStorageCrudTest.php +++ b/core/modules/field/tests/src/Kernel/FieldStorageCrudTest.php @@ -21,7 +21,7 @@ class FieldStorageCrudTest extends FieldKernelTestBase { * * @var array */ - public static $modules = array(); + public static $modules = []; // TODO : test creation with // - a full fledged $field structure, check that all the values are there @@ -32,11 +32,11 @@ class FieldStorageCrudTest extends FieldKernelTestBase { * Test the creation of a field storage. */ function testCreate() { - $field_storage_definition = array( + $field_storage_definition = [ 'field_name' => 'field_2', 'entity_type' => 'entity_test', 'type' => 'test_field', - ); + ]; field_test_memorize(); $field_storage = FieldStorageConfig::create($field_storage_definition); $field_storage->save(); @@ -86,10 +86,10 @@ class FieldStorageCrudTest extends FieldKernelTestBase { // Check that field type is required. try { - $field_storage_definition = array( + $field_storage_definition = [ 'field_name' => 'field_1', 'entity_type' => 'entity_type', - ); + ]; FieldStorageConfig::create($field_storage_definition)->save(); $this->fail(t('Cannot create a field with no type.')); } @@ -99,10 +99,10 @@ class FieldStorageCrudTest extends FieldKernelTestBase { // Check that field name is required. try { - $field_storage_definition = array( + $field_storage_definition = [ 'type' => 'test_field', 'entity_type' => 'entity_test', - ); + ]; FieldStorageConfig::create($field_storage_definition)->save(); $this->fail(t('Cannot create an unnamed field.')); } @@ -111,10 +111,10 @@ class FieldStorageCrudTest extends FieldKernelTestBase { } // Check that entity type is required. try { - $field_storage_definition = array( + $field_storage_definition = [ 'field_name' => 'test_field', 'type' => 'test_field' - ); + ]; FieldStorageConfig::create($field_storage_definition)->save(); $this->fail('Cannot create a field without an entity type.'); } @@ -124,11 +124,11 @@ class FieldStorageCrudTest extends FieldKernelTestBase { // Check that field name must start with a letter or _. try { - $field_storage_definition = array( + $field_storage_definition = [ 'field_name' => '2field_2', 'entity_type' => 'entity_test', 'type' => 'test_field', - ); + ]; FieldStorageConfig::create($field_storage_definition)->save(); $this->fail(t('Cannot create a field with a name starting with a digit.')); } @@ -138,11 +138,11 @@ class FieldStorageCrudTest extends FieldKernelTestBase { // Check that field name must only contain lowercase alphanumeric or _. try { - $field_storage_definition = array( + $field_storage_definition = [ 'field_name' => 'field#_3', 'entity_type' => 'entity_test', 'type' => 'test_field', - ); + ]; FieldStorageConfig::create($field_storage_definition)->save(); $this->fail(t('Cannot create a field with a name containing an illegal character.')); } @@ -152,11 +152,11 @@ class FieldStorageCrudTest extends FieldKernelTestBase { // Check that field name cannot be longer than 32 characters long. try { - $field_storage_definition = array( + $field_storage_definition = [ 'field_name' => '_12345678901234567890123456789012', 'entity_type' => 'entity_test', 'type' => 'test_field', - ); + ]; FieldStorageConfig::create($field_storage_definition)->save(); $this->fail(t('Cannot create a field with a name longer than 32 characters.')); } @@ -167,11 +167,11 @@ class FieldStorageCrudTest extends FieldKernelTestBase { // Check that field name can not be an entity key. // "id" is known as an entity key from the "entity_test" type. try { - $field_storage_definition = array( + $field_storage_definition = [ 'type' => 'test_field', 'field_name' => 'id', 'entity_type' => 'entity_test', - ); + ]; FieldStorageConfig::create($field_storage_definition)->save(); $this->fail(t('Cannot create a field bearing the name of an entity key.')); } @@ -187,15 +187,15 @@ class FieldStorageCrudTest extends FieldKernelTestBase { * since plugin classes (and thus the field type schema) cannot be accessed. */ function testCreateWithExplicitSchema() { - $schema = array( + $schema = [ 'dummy' => 'foobar' - ); - $field_storage = FieldStorageConfig::create(array( + ]; + $field_storage = FieldStorageConfig::create([ 'field_name' => 'field_2', 'entity_type' => 'entity_test', 'type' => 'test_field', 'schema' => $schema, - )); + ]); $this->assertEqual($field_storage->getSchema(), $schema); } @@ -203,31 +203,31 @@ class FieldStorageCrudTest extends FieldKernelTestBase { * Tests reading field storage definitions. */ function testRead() { - $field_storage_definition = array( + $field_storage_definition = [ 'field_name' => 'field_1', 'entity_type' => 'entity_test', 'type' => 'test_field', - ); + ]; $field_storage = FieldStorageConfig::create($field_storage_definition); $field_storage->save(); $id = $field_storage->id(); // Check that 'single column' criteria works. - $fields = entity_load_multiple_by_properties('field_storage_config', array('field_name' => $field_storage_definition['field_name'])); + $fields = entity_load_multiple_by_properties('field_storage_config', ['field_name' => $field_storage_definition['field_name']]); $this->assertTrue(count($fields) == 1 && isset($fields[$id]), 'The field was properly read.'); // Check that 'multi column' criteria works. - $fields = entity_load_multiple_by_properties('field_storage_config', array('field_name' => $field_storage_definition['field_name'], 'type' => $field_storage_definition['type'])); + $fields = entity_load_multiple_by_properties('field_storage_config', ['field_name' => $field_storage_definition['field_name'], 'type' => $field_storage_definition['type']]); $this->assertTrue(count($fields) == 1 && isset($fields[$id]), 'The field was properly read.'); - $fields = entity_load_multiple_by_properties('field_storage_config', array('field_name' => $field_storage_definition['field_name'], 'type' => 'foo')); + $fields = entity_load_multiple_by_properties('field_storage_config', ['field_name' => $field_storage_definition['field_name'], 'type' => 'foo']); $this->assertTrue(empty($fields), 'No field was found.'); // Create a field from the field storage. - $field_definition = array( + $field_definition = [ 'field_name' => $field_storage_definition['field_name'], 'entity_type' => 'entity_test', 'bundle' => 'entity_test', - ); + ]; FieldConfig::create($field_definition)->save(); } @@ -236,48 +236,48 @@ class FieldStorageCrudTest extends FieldKernelTestBase { */ function testIndexes() { // Check that indexes specified by the field type are used by default. - $field_storage = FieldStorageConfig::create(array( + $field_storage = FieldStorageConfig::create([ 'field_name' => 'field_1', 'entity_type' => 'entity_test', 'type' => 'test_field', - )); + ]); $field_storage->save(); $field_storage = FieldStorageConfig::load($field_storage->id()); $schema = $field_storage->getSchema(); - $expected_indexes = array('value' => array('value')); + $expected_indexes = ['value' => ['value']]; $this->assertEqual($schema['indexes'], $expected_indexes, 'Field type indexes saved by default'); // Check that indexes specified by the field definition override the field // type indexes. - $field_storage = FieldStorageConfig::create(array( + $field_storage = FieldStorageConfig::create([ 'field_name' => 'field_2', 'entity_type' => 'entity_test', 'type' => 'test_field', - 'indexes' => array( - 'value' => array(), - ), - )); + 'indexes' => [ + 'value' => [], + ], + ]); $field_storage->save(); $field_storage = FieldStorageConfig::load($field_storage->id()); $schema = $field_storage->getSchema(); - $expected_indexes = array('value' => array()); + $expected_indexes = ['value' => []]; $this->assertEqual($schema['indexes'], $expected_indexes, 'Field definition indexes override field type indexes'); // Check that indexes specified by the field definition add to the field // type indexes. - $field_storage = FieldStorageConfig::create(array( + $field_storage = FieldStorageConfig::create([ 'field_name' => 'field_3', 'entity_type' => 'entity_test', 'type' => 'test_field', - 'indexes' => array( - 'value_2' => array('value'), - ), - )); + 'indexes' => [ + 'value_2' => ['value'], + ], + ]); $field_storage->save(); $id = $field_storage->id(); $field_storage = FieldStorageConfig::load($id); $schema = $field_storage->getSchema(); - $expected_indexes = array('value' => array('value'), 'value_2' => array('value')); + $expected_indexes = ['value' => ['value'], 'value_2' => ['value']]; $this->assertEqual($schema['indexes'], $expected_indexes, 'Field definition indexes are merged with field type indexes'); } @@ -288,43 +288,43 @@ class FieldStorageCrudTest extends FieldKernelTestBase { // TODO: Also test deletion of the data stored in the field ? // Create two fields (so we can test that only one is deleted). - $field_storage_definition = array( + $field_storage_definition = [ 'field_name' => 'field_1', 'type' => 'test_field', 'entity_type' => 'entity_test', - ); + ]; FieldStorageConfig::create($field_storage_definition)->save(); - $another_field_storage_definition = array( + $another_field_storage_definition = [ 'field_name' => 'field_2', 'type' => 'test_field', 'entity_type' => 'entity_test', - ); + ]; FieldStorageConfig::create($another_field_storage_definition)->save(); // Create fields for each. - $field_definition = array( + $field_definition = [ 'field_name' => $field_storage_definition['field_name'], 'entity_type' => 'entity_test', 'bundle' => 'entity_test', - ); + ]; FieldConfig::create($field_definition)->save(); $another_field_definition = $field_definition; $another_field_definition['field_name'] = $another_field_storage_definition['field_name']; FieldConfig::create($another_field_definition)->save(); // Test that the first field is not deleted, and then delete it. - $field_storage = current(entity_load_multiple_by_properties('field_storage_config', array('field_name' => $field_storage_definition['field_name'], 'include_deleted' => TRUE))); + $field_storage = current(entity_load_multiple_by_properties('field_storage_config', ['field_name' => $field_storage_definition['field_name'], 'include_deleted' => TRUE])); $this->assertTrue(!empty($field_storage) && !$field_storage->isDeleted(), 'A new storage is not marked for deletion.'); FieldStorageConfig::loadByName('entity_test', $field_storage_definition['field_name'])->delete(); // Make sure that the field is marked as deleted when it is specifically // loaded. - $field_storage = current(entity_load_multiple_by_properties('field_storage_config', array('field_name' => $field_storage_definition['field_name'], 'include_deleted' => TRUE))); + $field_storage = current(entity_load_multiple_by_properties('field_storage_config', ['field_name' => $field_storage_definition['field_name'], 'include_deleted' => TRUE])); $this->assertTrue($field_storage->isDeleted(), 'A deleted storage is marked for deletion.'); // Make sure that this field is marked as deleted when it is // specifically loaded. - $field = current(entity_load_multiple_by_properties('field_config', array('entity_type' => 'entity_test', 'field_name' => $field_definition['field_name'], 'bundle' => $field_definition['bundle'], 'include_deleted' => TRUE))); + $field = current(entity_load_multiple_by_properties('field_config', ['entity_type' => 'entity_test', 'field_name' => $field_definition['field_name'], 'bundle' => $field_definition['bundle'], 'include_deleted' => TRUE])); $this->assertTrue($field->isDeleted(), 'A field whose storage was deleted is marked for deletion.'); // Try to load the storage normally and make sure it does not show up. @@ -364,11 +364,11 @@ class FieldStorageCrudTest extends FieldKernelTestBase { } function testUpdateFieldType() { - $field_storage = FieldStorageConfig::create(array( + $field_storage = FieldStorageConfig::create([ 'field_name' => 'field_type', 'entity_type' => 'entity_test', 'type' => 'decimal', - )); + ]); $field_storage->save(); try { @@ -389,12 +389,12 @@ class FieldStorageCrudTest extends FieldKernelTestBase { // respected. Since cardinality enforcement is consistent across database // systems, it makes a good test case. $cardinality = 4; - $field_storage = FieldStorageConfig::create(array( + $field_storage = FieldStorageConfig::create([ 'field_name' => 'field_update', 'entity_type' => 'entity_test', 'type' => 'test_field', 'cardinality' => $cardinality, - )); + ]); $field_storage->save(); $field = FieldConfig::create([ 'field_storage' => $field_storage, @@ -427,14 +427,14 @@ class FieldStorageCrudTest extends FieldKernelTestBase { * Test field type modules forbidding an update. */ function testUpdateForbid() { - $field_storage = FieldStorageConfig::create(array( + $field_storage = FieldStorageConfig::create([ 'field_name' => 'forbidden', 'entity_type' => 'entity_test', 'type' => 'test_field', - 'settings' => array( + 'settings' => [ 'changeable' => 0, 'unchangeable' => 0 - ))); + ]]); $field_storage->save(); $field_storage->setSetting('changeable', $field_storage->getSetting('changeable') + 1); try { diff --git a/core/modules/field/tests/src/Kernel/FieldTypePluginManagerTest.php b/core/modules/field/tests/src/Kernel/FieldTypePluginManagerTest.php index 6d443843acf..fe46a057f9f 100644 --- a/core/modules/field/tests/src/Kernel/FieldTypePluginManagerTest.php +++ b/core/modules/field/tests/src/Kernel/FieldTypePluginManagerTest.php @@ -19,10 +19,10 @@ class FieldTypePluginManagerTest extends FieldKernelTestBase { */ function testDefaultSettings() { $field_type_manager = \Drupal::service('plugin.manager.field.field_type'); - foreach (array('test_field', 'shape', 'hidden_test_field') as $type) { + foreach (['test_field', 'shape', 'hidden_test_field'] as $type) { $definition = $field_type_manager->getDefinition($type); - $this->assertIdentical($field_type_manager->getDefaultStorageSettings($type), $definition['class']::defaultStorageSettings(), format_string("%type storage settings were returned", array('%type' => $type))); - $this->assertIdentical($field_type_manager->getDefaultFieldSettings($type), $definition['class']::defaultFieldSettings(), format_string(" %type field settings were returned", array('%type' => $type))); + $this->assertIdentical($field_type_manager->getDefaultStorageSettings($type), $definition['class']::defaultStorageSettings(), format_string("%type storage settings were returned", ['%type' => $type])); + $this->assertIdentical($field_type_manager->getDefaultFieldSettings($type), $definition['class']::defaultFieldSettings(), format_string(" %type field settings were returned", ['%type' => $type])); } } @@ -32,7 +32,7 @@ class FieldTypePluginManagerTest extends FieldKernelTestBase { public function testCreateInstance() { /** @var \Drupal\Core\Field\FieldTypePluginManagerInterface $field_type_manager */ $field_type_manager = \Drupal::service('plugin.manager.field.field_type'); - foreach (array('test_field', 'shape', 'hidden_test_field') as $type) { + foreach (['test_field', 'shape', 'hidden_test_field'] as $type) { $definition = $field_type_manager->getDefinition($type); $class = $definition['class']; @@ -40,16 +40,16 @@ class FieldTypePluginManagerTest extends FieldKernelTestBase { $field_definition = BaseFieldDefinition::create($type); - $configuration = array( + $configuration = [ 'field_definition' => $field_definition, 'name' => $field_name, 'parent' => NULL, - ); + ]; $instance = $field_type_manager->createInstance($type, $configuration); - $this->assertTrue($instance instanceof $class, SafeMarkup::format('Created a @class instance', array('@class' => $class))); - $this->assertEqual($field_name, $instance->getName(), SafeMarkup::format('Instance name is @name', array('@name' => $field_name))); + $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])); } } @@ -69,18 +69,18 @@ class FieldTypePluginManagerTest extends FieldKernelTestBase { ->setLabel('Jenny') ->setDefaultValue(8675309); - $configuration = array( + $configuration = [ 'field_definition' => $field_definition, 'name' => $field_name, 'parent' => NULL, - ); + ]; $entity = EntityTest::create(); $instance = $field_type_manager->createInstance($type, $configuration); - $this->assertTrue($instance instanceof $class, SafeMarkup::format('Created a @class instance', array('@class' => $class))); - $this->assertEqual($field_name, $instance->getName(), SafeMarkup::format('Instance name is @name', array('@name' => $field_name))); + $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->assertEqual($instance->getFieldDefinition()->getLabel(), 'Jenny', 'Instance label is Jenny'); $this->assertEqual($instance->getFieldDefinition()->getDefaultValue($entity), [['value' => 8675309]], 'Instance default_value is 8675309'); } diff --git a/core/modules/field/tests/src/Kernel/FieldValidationTest.php b/core/modules/field/tests/src/Kernel/FieldValidationTest.php index 3715832d532..5eac7734b93 100644 --- a/core/modules/field/tests/src/Kernel/FieldValidationTest.php +++ b/core/modules/field/tests/src/Kernel/FieldValidationTest.php @@ -34,9 +34,9 @@ class FieldValidationTest extends FieldKernelTestBase { $this->createFieldWithStorage('', $this->entityType, $this->bundle); // Create an 'entity_test' entity. - $this->entity = entity_create($this->entityType, array( + $this->entity = entity_create($this->entityType, [ 'type' => $this->bundle, - )); + ]); } /** @@ -47,7 +47,7 @@ class FieldValidationTest extends FieldKernelTestBase { $entity = $this->entity; for ($delta = 0; $delta < $cardinality + 1; $delta++) { - $entity->{$this->fieldTestData->field_name}[] = array('value' => 1); + $entity->{$this->fieldTestData->field_name}[] = ['value' => 1]; } // Validate the field. @@ -56,7 +56,7 @@ class FieldValidationTest extends FieldKernelTestBase { // Check that the expected constraint violations are reported. $this->assertEqual(count($violations), 1); $this->assertEqual($violations[0]->getPropertyPath(), ''); - $this->assertEqual($violations[0]->getMessage(), t('%name: this field cannot hold more than @count values.', array('%name' => $this->fieldTestData->field->getLabel(), '@count' => $cardinality))); + $this->assertEqual($violations[0]->getMessage(), t('%name: this field cannot hold more than @count values.', ['%name' => $this->fieldTestData->field->getLabel(), '@count' => $cardinality])); } /** @@ -70,7 +70,7 @@ class FieldValidationTest extends FieldKernelTestBase { $this->assertTrue($cardinality >= 2); // Set up values for the field. - $expected_violations = array(); + $expected_violations = []; for ($delta = 0; $delta < $cardinality; $delta++) { // All deltas except '1' have incorrect values. if ($delta == 1) { @@ -78,7 +78,7 @@ class FieldValidationTest extends FieldKernelTestBase { } else { $value = -1; - $expected_violations[$delta . '.value'][] = t('%name does not accept the value -1.', array('%name' => $this->fieldTestData->field->getLabel())); + $expected_violations[$delta . '.value'][] = t('%name does not accept the value -1.', ['%name' => $this->fieldTestData->field->getLabel()]); } $entity->{$this->fieldTestData->field_name}[] = $value; } @@ -87,7 +87,7 @@ class FieldValidationTest extends FieldKernelTestBase { $violations = $entity->{$this->fieldTestData->field_name}->validate(); // Check that the expected constraint violations are reported. - $violations_by_path = array(); + $violations_by_path = []; foreach ($violations as $violation) { $violations_by_path[$violation->getPropertyPath()][] = $violation->getMessage(); } diff --git a/core/modules/field/tests/src/Kernel/FormatterPluginManagerTest.php b/core/modules/field/tests/src/Kernel/FormatterPluginManagerTest.php index 4425a44eb18..0b07e3ad9b8 100644 --- a/core/modules/field/tests/src/Kernel/FormatterPluginManagerTest.php +++ b/core/modules/field/tests/src/Kernel/FormatterPluginManagerTest.php @@ -24,13 +24,13 @@ class FormatterPluginManagerTest extends FieldKernelTestBase { // Set a name that will make isApplicable() return TRUE. ->setName('field_test_field'); - $formatter_options = array( + $formatter_options = [ 'field_definition' => $base_field_definition, 'view_mode' => 'default', - 'configuration' => array( + 'configuration' => [ 'type' => 'field_test_applicable', - ), - ); + ], + ]; $instance = $formatter_plugin_manager->getInstance($formatter_options); $this->assertEqual($instance->getPluginId(), 'field_test_applicable'); diff --git a/core/modules/field/tests/src/Kernel/Migrate/d6/MigrateFieldFormatterSettingsTest.php b/core/modules/field/tests/src/Kernel/Migrate/d6/MigrateFieldFormatterSettingsTest.php index 2ee3c779bc0..edf6dc0b212 100644 --- a/core/modules/field/tests/src/Kernel/Migrate/d6/MigrateFieldFormatterSettingsTest.php +++ b/core/modules/field/tests/src/Kernel/Migrate/d6/MigrateFieldFormatterSettingsTest.php @@ -26,14 +26,14 @@ class MigrateFieldFormatterSettingsTest extends MigrateDrupal6TestBase { public function testEntityDisplaySettings() { // Run tests. $field_name = "field_test"; - $expected = array( + $expected = [ 'label' => 'above', 'weight' => 1, 'type' => 'text_trimmed', - 'settings' => array('trim_length' => 600), - 'third_party_settings' => array(), + 'settings' => ['trim_length' => 600], + 'third_party_settings' => [], 'region' => 'content', - ); + ]; // Can we load any entity display. $display = EntityViewDisplay::load('node.story.teaser'); @@ -51,7 +51,7 @@ class MigrateFieldFormatterSettingsTest extends MigrateDrupal6TestBase { // Test the default format with text_default which comes from a static map. $expected['type'] = 'text_default'; - $expected['settings'] = array(); + $expected['settings'] = []; $display = EntityViewDisplay::load('node.story.default'); $this->assertIdentical($expected, $display->getComponent($field_name)); @@ -66,40 +66,40 @@ class MigrateFieldFormatterSettingsTest extends MigrateDrupal6TestBase { // Test the number field formatter settings are correct. $expected['weight'] = 1; $expected['type'] = 'number_integer'; - $expected['settings'] = array( + $expected['settings'] = [ 'thousand_separator' => ',', 'prefix_suffix' => TRUE, - ); + ]; $component = $display->getComponent('field_test_two'); $this->assertIdentical($expected, $component); $expected['weight'] = 2; $expected['type'] = 'number_decimal'; - $expected['settings'] = array( + $expected['settings'] = [ 'scale' => 2, 'decimal_separator' => '.', 'thousand_separator' => ',', 'prefix_suffix' => TRUE, - ); + ]; $component = $display->getComponent('field_test_three'); $this->assertIdentical($expected, $component); // Test the email field formatter settings are correct. $expected['weight'] = 6; $expected['type'] = 'email_mailto'; - $expected['settings'] = array(); + $expected['settings'] = []; $component = $display->getComponent('field_test_email'); $this->assertIdentical($expected, $component); // Test the link field formatter settings. $expected['weight'] = 7; $expected['type'] = 'link'; - $expected['settings'] = array( + $expected['settings'] = [ 'trim_length' => 80, 'url_only' => TRUE, 'url_plain' => TRUE, 'rel' => '0', 'target' => '0', - ); + ]; $component = $display->getComponent('field_test_link'); $this->assertIdentical($expected, $component); $expected['settings']['url_only'] = FALSE; @@ -111,7 +111,7 @@ class MigrateFieldFormatterSettingsTest extends MigrateDrupal6TestBase { // Test the file field formatter settings. $expected['weight'] = 8; $expected['type'] = 'file_default'; - $expected['settings'] = array(); + $expected['settings'] = []; $component = $display->getComponent('field_test_filefield'); $this->assertIdentical($expected, $component); $display = EntityViewDisplay::load('node.story.default'); @@ -122,7 +122,7 @@ class MigrateFieldFormatterSettingsTest extends MigrateDrupal6TestBase { // Test the image field formatter settings. $expected['weight'] = 9; $expected['type'] = 'image'; - $expected['settings'] = array('image_style' => '', 'image_link' => ''); + $expected['settings'] = ['image_style' => '', 'image_link' => '']; $component = $display->getComponent('field_test_imagefield'); $this->assertIdentical($expected, $component); $display = EntityViewDisplay::load('node.story.teaser'); @@ -133,15 +133,15 @@ class MigrateFieldFormatterSettingsTest extends MigrateDrupal6TestBase { // Test phone field. $expected['weight'] = 13; $expected['type'] = 'basic_string'; - $expected['settings'] = array(); + $expected['settings'] = []; $component = $display->getComponent('field_test_phone'); $this->assertIdentical($expected, $component); // Test date field. - $defaults = array('format_type' => 'fallback', 'timezone_override' => '',); + $defaults = ['format_type' => 'fallback', 'timezone_override' => '',]; $expected['weight'] = 10; $expected['type'] = 'datetime_default'; - $expected['settings'] = array('format_type' => 'fallback') + $defaults; + $expected['settings'] = ['format_type' => 'fallback'] + $defaults; $component = $display->getComponent('field_test_date'); $this->assertIdentical($expected, $component); $display = EntityViewDisplay::load('node.story.default'); @@ -155,13 +155,13 @@ class MigrateFieldFormatterSettingsTest extends MigrateDrupal6TestBase { $component = $display->getComponent('field_test_datestamp'); $this->assertIdentical($expected, $component); $display = EntityViewDisplay::load('node.story.teaser'); - $expected['settings'] = array('format_type' => 'medium') + $defaults; + $expected['settings'] = ['format_type' => 'medium'] + $defaults; $component = $display->getComponent('field_test_datestamp'); $this->assertIdentical($expected, $component); // Test datetime field. $expected['weight'] = 12; - $expected['settings'] = array('format_type' => 'short') + $defaults; + $expected['settings'] = ['format_type' => 'short'] + $defaults; $component = $display->getComponent('field_test_datetime'); $this->assertIdentical($expected, $component); $display = EntityViewDisplay::load('node.story.default'); @@ -176,7 +176,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(array('node', 'story', 'teaser', 'field_test'), $this->getMigration('d6_field_formatter_settings')->getIdMap()->lookupDestinationID(array('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'])); } } diff --git a/core/modules/field/tests/src/Kernel/Migrate/d6/MigrateFieldInstanceTest.php b/core/modules/field/tests/src/Kernel/Migrate/d6/MigrateFieldInstanceTest.php index b3fac3fc585..b1eec356235 100644 --- a/core/modules/field/tests/src/Kernel/Migrate/d6/MigrateFieldInstanceTest.php +++ b/core/modules/field/tests/src/Kernel/Migrate/d6/MigrateFieldInstanceTest.php @@ -32,24 +32,24 @@ class MigrateFieldInstanceTest extends MigrateDrupal6TestBase { // Test a number field. $field = FieldConfig::load('node.story.field_test_two'); $this->assertIdentical('Integer Field', $field->label()); - $expected = array( + $expected = [ 'min' => 10, 'max' => 100, 'prefix' => 'pref', 'suffix' => 'suf', 'unsigned' => FALSE, 'size' => 'normal', - ); + ]; $this->assertIdentical($expected, $field->getSettings()); $field = FieldConfig::load('node.story.field_test_four'); $this->assertIdentical('Float Field', $field->label()); - $expected = array( + $expected = [ 'min' => 100.0, 'max' => 200.0, 'prefix' => 'id-', 'suffix' => '', - ); + ]; $this->assertIdentical($expected, $field->getSettings()); // Test email field. @@ -70,7 +70,7 @@ class MigrateFieldInstanceTest extends MigrateDrupal6TestBase { // Test a filefield. $field = FieldConfig::load('node.story.field_test_filefield'); $this->assertIdentical('File Field', $field->label()); - $expected = array( + $expected = [ 'file_extensions' => 'txt pdf doc', 'file_directory' => 'images', 'description_field' => TRUE, @@ -80,8 +80,8 @@ class MigrateFieldInstanceTest extends MigrateDrupal6TestBase { 'display_default' => FALSE, 'uri_scheme' => 'public', 'handler' => 'default:file', - 'handler_settings' => array(), - ); + 'handler_settings' => [], + ]; $field_settings = $field->getSettings(); ksort($expected); ksort($field_settings); @@ -91,7 +91,7 @@ class MigrateFieldInstanceTest extends MigrateDrupal6TestBase { // Test a link field. $field = FieldConfig::load('node.story.field_test_link'); $this->assertIdentical('Link Field', $field->label()); - $expected = array('title' => 2, 'link_type' => LinkItemInterface::LINK_GENERIC); + $expected = ['title' => 2, 'link_type' => LinkItemInterface::LINK_GENERIC]; $this->assertIdentical($expected, $field->getSettings()); $this->assertIdentical('default link title', $entity->field_test_link->title, 'Field field_test_link default title is correct.'); $this->assertIdentical('https://www.drupal.org', $entity->field_test_link->url, 'Field field_test_link default title is correct.'); diff --git a/core/modules/field/tests/src/Kernel/Migrate/d6/MigrateFieldTest.php b/core/modules/field/tests/src/Kernel/Migrate/d6/MigrateFieldTest.php index ea3fec8dd1c..690016172fe 100644 --- a/core/modules/field/tests/src/Kernel/Migrate/d6/MigrateFieldTest.php +++ b/core/modules/field/tests/src/Kernel/Migrate/d6/MigrateFieldTest.php @@ -33,38 +33,38 @@ class MigrateFieldTest extends MigrateDrupal6TestBase { // Integer field. $field_storage = FieldStorageConfig::load('node.field_test_two'); - $this->assertIdentical("integer", $field_storage->getType(), t('Field type is @fieldtype. It should be integer.', array('@fieldtype' => $field_storage->getType()))); + $this->assertIdentical("integer", $field_storage->getType(), t('Field type is @fieldtype. It should be integer.', ['@fieldtype' => $field_storage->getType()])); // Float field. $field_storage = FieldStorageConfig::load('node.field_test_three'); - $this->assertIdentical("decimal", $field_storage->getType(), t('Field type is @fieldtype. It should be decimal.', array('@fieldtype' => $field_storage->getType()))); + $this->assertIdentical("decimal", $field_storage->getType(), t('Field type is @fieldtype. It should be decimal.', ['@fieldtype' => $field_storage->getType()])); // Link field. $field_storage = FieldStorageConfig::load('node.field_test_link'); - $this->assertIdentical("link", $field_storage->getType(), t('Field type is @fieldtype. It should be link.', array('@fieldtype' => $field_storage->getType()))); + $this->assertIdentical("link", $field_storage->getType(), t('Field type is @fieldtype. It should be link.', ['@fieldtype' => $field_storage->getType()])); // File field. $field_storage = FieldStorageConfig::load('node.field_test_filefield'); - $this->assertIdentical("file", $field_storage->getType(), t('Field type is @fieldtype. It should be file.', array('@fieldtype' => $field_storage->getType()))); + $this->assertIdentical("file", $field_storage->getType(), t('Field type is @fieldtype. It should be file.', ['@fieldtype' => $field_storage->getType()])); $field_storage = FieldStorageConfig::load('node.field_test_imagefield'); - $this->assertIdentical("image", $field_storage->getType(), t('Field type is @fieldtype. It should be image.', array('@fieldtype' => $field_storage->getType()))); + $this->assertIdentical("image", $field_storage->getType(), t('Field type is @fieldtype. It should be image.', ['@fieldtype' => $field_storage->getType()])); $settings = $field_storage->getSettings(); $this->assertIdentical('file', $settings['target_type']); $this->assertIdentical('public', $settings['uri_scheme']); - $this->assertIdentical(array(), array_filter($settings['default_image'])); + $this->assertIdentical([], array_filter($settings['default_image'])); // Phone field. $field_storage = FieldStorageConfig::load('node.field_test_phone'); - $this->assertIdentical("telephone", $field_storage->getType(), t('Field type is @fieldtype. It should be telephone.', array('@fieldtype' => $field_storage->getType()))); + $this->assertIdentical("telephone", $field_storage->getType(), t('Field type is @fieldtype. It should be telephone.', ['@fieldtype' => $field_storage->getType()])); // Date field. $field_storage = FieldStorageConfig::load('node.field_test_datetime'); - $this->assertIdentical("datetime", $field_storage->getType(), t('Field type is @fieldtype. It should be datetime.', array('@fieldtype' => $field_storage->getType()))); + $this->assertIdentical("datetime", $field_storage->getType(), t('Field type is @fieldtype. It should be datetime.', ['@fieldtype' => $field_storage->getType()])); // Decimal field with radio buttons. $field_storage = FieldStorageConfig::load('node.field_test_decimal_radio_buttons'); - $this->assertIdentical("list_float", $field_storage->getType(), t('Field type is @fieldtype. It should be list_float.', array('@fieldtype' => $field_storage->getType()))); + $this->assertIdentical("list_float", $field_storage->getType(), t('Field type is @fieldtype. It should be list_float.', ['@fieldtype' => $field_storage->getType()])); $this->assertNotNull($field_storage->getSetting('allowed_values')['1.2'], t('First allowed value key is set to 1.2')); $this->assertNotNull($field_storage->getSetting('allowed_values')['2.1'], t('Second allowed value key is set to 2.1')); $this->assertIdentical('1.2', $field_storage->getSetting('allowed_values')['1.2'], t('First allowed value is set to 1.2')); @@ -72,11 +72,11 @@ class MigrateFieldTest extends MigrateDrupal6TestBase { // Float field with a single checkbox. $field_storage = FieldStorageConfig::load('node.field_test_float_single_checkbox'); - $this->assertIdentical("boolean", $field_storage->getType(), t('Field type is @fieldtype. It should be boolean.', array('@fieldtype' => $field_storage->getType()))); + $this->assertIdentical("boolean", $field_storage->getType(), t('Field type is @fieldtype. It should be boolean.', ['@fieldtype' => $field_storage->getType()])); // Integer field with a select list. $field_storage = FieldStorageConfig::load('node.field_test_integer_selectlist'); - $this->assertIdentical("list_integer", $field_storage->getType(), t('Field type is @fieldtype. It should be list_integer.', array('@fieldtype' => $field_storage->getType()))); + $this->assertIdentical("list_integer", $field_storage->getType(), t('Field type is @fieldtype. It should be list_integer.', ['@fieldtype' => $field_storage->getType()])); $this->assertNotNull($field_storage->getSetting('allowed_values')['1234'], t('First allowed value key is set to 1234')); $this->assertNotNull($field_storage->getSetting('allowed_values')['2341'], t('Second allowed value key is set to 2341')); $this->assertNotNull($field_storage->getSetting('allowed_values')['3412'], t('Third allowed value key is set to 3412')); @@ -88,7 +88,7 @@ class MigrateFieldTest extends MigrateDrupal6TestBase { // Text field with a single checkbox. $field_storage = FieldStorageConfig::load('node.field_test_text_single_checkbox'); - $this->assertIdentical("boolean", $field_storage->getType(), t('Field type is @fieldtype. It should be boolean.', array('@fieldtype' => $field_storage->getType()))); + $this->assertIdentical("boolean", $field_storage->getType(), t('Field type is @fieldtype. It should be boolean.', ['@fieldtype' => $field_storage->getType()])); // Validate that the source count and processed count match up. /** @var \Drupal\migrate\Plugin\MigrationInterface $migration */ diff --git a/core/modules/field/tests/src/Kernel/Migrate/d6/MigrateFieldWidgetSettingsTest.php b/core/modules/field/tests/src/Kernel/Migrate/d6/MigrateFieldWidgetSettingsTest.php index e7bb63621a0..2a9dd1baef2 100644 --- a/core/modules/field/tests/src/Kernel/Migrate/d6/MigrateFieldWidgetSettingsTest.php +++ b/core/modules/field/tests/src/Kernel/Migrate/d6/MigrateFieldWidgetSettingsTest.php @@ -30,9 +30,9 @@ class MigrateFieldWidgetSettingsTest extends MigrateDrupal6TestBase { // Text field. $component = $form_display->getComponent('field_test'); - $expected = array('weight' => 1, 'type' => 'text_textfield'); - $expected['settings'] = array('size' => 60, 'placeholder' => ''); - $expected['third_party_settings'] = array(); + $expected = ['weight' => 1, 'type' => 'text_textfield']; + $expected['settings'] = ['size' => 60, 'placeholder' => '']; + $expected['third_party_settings'] = []; $expected['region'] = 'content'; $this->assertIdentical($expected, $component, 'Text field settings are correct.'); @@ -40,7 +40,7 @@ class MigrateFieldWidgetSettingsTest extends MigrateDrupal6TestBase { $component = $form_display->getComponent('field_test_two'); $expected['type'] = 'number'; $expected['weight'] = 1; - $expected['settings'] = array('placeholder' => ''); + $expected['settings'] = ['placeholder' => '']; $this->assertIdentical($expected, $component); // Float field. @@ -52,7 +52,7 @@ class MigrateFieldWidgetSettingsTest extends MigrateDrupal6TestBase { $component = $form_display->getComponent('field_test_email'); $expected['type'] = 'email_default'; $expected['weight'] = 6; - $expected['settings'] = array('placeholder' => '', 'size' => 60); + $expected['settings'] = ['placeholder' => '', 'size' => 60]; $this->assertIdentical($expected, $component); // Link field. @@ -65,28 +65,28 @@ class MigrateFieldWidgetSettingsTest extends MigrateDrupal6TestBase { $component = $form_display->getComponent('field_test_filefield'); $expected['type'] = 'file_generic'; $expected['weight'] = 8; - $expected['settings'] = array('progress_indicator' => 'bar'); + $expected['settings'] = ['progress_indicator' => 'bar']; $this->assertIdentical($expected, $component); // Image field. $component = $form_display->getComponent('field_test_imagefield'); $expected['type'] = 'image_image'; $expected['weight'] = 9; - $expected['settings'] = array('progress_indicator' => 'bar', 'preview_image_style' => 'thumbnail'); + $expected['settings'] = ['progress_indicator' => 'bar', 'preview_image_style' => 'thumbnail']; $this->assertIdentical($expected, $component); // Phone field. $component = $form_display->getComponent('field_test_phone'); $expected['type'] = 'telephone_default'; $expected['weight'] = 13; - $expected['settings'] = array('placeholder' => ''); + $expected['settings'] = ['placeholder' => '']; $this->assertIdentical($expected, $component); // Date fields. $component = $form_display->getComponent('field_test_date'); $expected['type'] = 'datetime_default'; $expected['weight'] = 10; - $expected['settings'] = array(); + $expected['settings'] = []; $this->assertIdentical($expected, $component); $component = $form_display->getComponent('field_test_datestamp'); diff --git a/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldFormatterSettingsTest.php b/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldFormatterSettingsTest.php index 14f37cb4160..dd38569de14 100644 --- a/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldFormatterSettingsTest.php +++ b/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldFormatterSettingsTest.php @@ -96,40 +96,40 @@ class MigrateFieldFormatterSettingsTest extends MigrateDrupal7TestBase { // an "unsupported operand types" fatal). Database::getConnection('default', 'migrate') ->update('field_config_instance') - ->fields(array( - 'data' => serialize(array ( + ->fields([ + 'data' => serialize( [ 'label' => 'Body', 'widget' => - array ( + [ 'type' => 'text_textarea_with_summary', 'settings' => - array ( + [ 'rows' => 20, 'summary_rows' => 5, - ), + ], 'weight' => -4, 'module' => 'text', - ), + ], 'settings' => - array ( + [ 'display_summary' => TRUE, 'text_processing' => 1, 'user_register_form' => FALSE, - ), + ], 'display' => - array ( + [ 'default' => - array ( + [ 'label' => 'hidden', 'type' => 'text_default', 'settings' => - array ( - ), + [ + ], 'module' => 'text', 'weight' => 0, - ), + ], 'teaser' => - array ( + [ 'label' => 'hidden', 'type' => 'text_summary_or_trimmed', // settings is always expected to be an array. Making it NULL @@ -137,12 +137,12 @@ class MigrateFieldFormatterSettingsTest extends MigrateDrupal7TestBase { 'settings' => NULL, 'module' => 'text', 'weight' => 0, - ), - ), + ], + ], 'required' => FALSE, 'description' => '', - )), - )) + ]), + ]) ->condition('entity_type', 'node') ->condition('bundle', 'article') ->condition('field_name', 'body') diff --git a/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldInstanceTest.php b/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldInstanceTest.php index c50c3241fbb..1e3df9e4fc8 100644 --- a/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldInstanceTest.php +++ b/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldInstanceTest.php @@ -21,7 +21,7 @@ class MigrateFieldInstanceTest extends MigrateDrupal7TestBase { * * @var array */ - public static $modules = array( + public static $modules = [ 'comment', 'datetime', 'file', @@ -32,7 +32,7 @@ class MigrateFieldInstanceTest extends MigrateDrupal7TestBase { 'taxonomy', 'telephone', 'text', - ); + ]; /** * {@inheritdoc} @@ -57,16 +57,16 @@ class MigrateFieldInstanceTest extends MigrateDrupal7TestBase { * The node type ID. */ protected function createType($id) { - NodeType::create(array( + NodeType::create([ 'type' => $id, 'label' => $this->randomString(), - ))->save(); + ])->save(); - CommentType::create(array( + CommentType::create([ 'id' => 'comment_node_' . $id, 'label' => $this->randomString(), 'target_entity_type_id' => 'node', - ))->save(); + ])->save(); } /** diff --git a/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldInstanceWidgetSettingsTest.php b/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldInstanceWidgetSettingsTest.php index 7f2e0244f82..5a47e38ef72 100644 --- a/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldInstanceWidgetSettingsTest.php +++ b/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldInstanceWidgetSettingsTest.php @@ -18,7 +18,7 @@ class MigrateFieldInstanceWidgetSettingsTest extends MigrateDrupal7TestBase { * * @var array */ - public static $modules = array( + public static $modules = [ 'comment', 'datetime', 'field', @@ -29,7 +29,7 @@ class MigrateFieldInstanceWidgetSettingsTest extends MigrateDrupal7TestBase { 'taxonomy', 'telephone', 'text', - ); + ]; /** * {@inheritdoc} diff --git a/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldTest.php b/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldTest.php index 4a0f8cde569..ab2fe8e1258 100644 --- a/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldTest.php +++ b/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldTest.php @@ -18,7 +18,7 @@ class MigrateFieldTest extends MigrateDrupal7TestBase { * * @var array */ - public static $modules = array( + public static $modules = [ 'comment', 'datetime', 'file', @@ -29,7 +29,7 @@ class MigrateFieldTest extends MigrateDrupal7TestBase { 'taxonomy', 'telephone', 'text', - ); + ]; /** * {@inheritdoc} diff --git a/core/modules/field/tests/src/Kernel/Number/NumberItemTest.php b/core/modules/field/tests/src/Kernel/Number/NumberItemTest.php index 25b99bbe7df..578eeda9c63 100644 --- a/core/modules/field/tests/src/Kernel/Number/NumberItemTest.php +++ b/core/modules/field/tests/src/Kernel/Number/NumberItemTest.php @@ -21,18 +21,18 @@ class NumberItemTest extends FieldKernelTestBase { * * @var array */ - public static $modules = array(); + public static $modules = []; protected function setUp() { parent::setUp(); // Create number field storages and fields for validation. - foreach (array('integer', 'float', 'decimal') as $type) { - FieldStorageConfig::create(array( + foreach (['integer', 'float', 'decimal'] as $type) { + FieldStorageConfig::create([ 'entity_type' => 'entity_test', 'field_name' => 'field_' . $type, 'type' => $type, - ))->save(); + ])->save(); FieldConfig::create([ 'entity_type' => 'entity_test', 'field_name' => 'field_' . $type, diff --git a/core/modules/field/tests/src/Kernel/ShapeItemTest.php b/core/modules/field/tests/src/Kernel/ShapeItemTest.php index 644a15f1465..80ab04f3a9b 100644 --- a/core/modules/field/tests/src/Kernel/ShapeItemTest.php +++ b/core/modules/field/tests/src/Kernel/ShapeItemTest.php @@ -20,7 +20,7 @@ class ShapeItemTest extends FieldKernelTestBase { * * @var array */ - public static $modules = array('field_test'); + public static $modules = ['field_test']; /** * The name of the field to use in this test. @@ -33,11 +33,11 @@ class ShapeItemTest extends FieldKernelTestBase { parent::setUp(); // Create a 'shape' field and storage for validation. - FieldStorageConfig::create(array( + FieldStorageConfig::create([ 'field_name' => $this->fieldName, 'entity_type' => 'entity_test', 'type' => 'shape', - ))->save(); + ])->save(); FieldConfig::create([ 'entity_type' => 'entity_test', 'field_name' => $this->fieldName, diff --git a/core/modules/field/tests/src/Kernel/String/RawStringFormatterTest.php b/core/modules/field/tests/src/Kernel/String/RawStringFormatterTest.php index 02d72d04732..1000d640789 100644 --- a/core/modules/field/tests/src/Kernel/String/RawStringFormatterTest.php +++ b/core/modules/field/tests/src/Kernel/String/RawStringFormatterTest.php @@ -23,7 +23,7 @@ class RawStringFormatterTest extends KernelTestBase { * * @var array */ - public static $modules = array('field', 'text', 'entity_test', 'system', 'filter', 'user'); + public static $modules = ['field', 'text', 'entity_test', 'system', 'filter', 'user']; /** * @var string @@ -52,7 +52,7 @@ class RawStringFormatterTest extends KernelTestBase { parent::setUp(); // Configure the theme system. - $this->installConfig(array('system', 'field')); + $this->installConfig(['system', 'field']); \Drupal::service('router.builder')->rebuild(); $this->installEntitySchema('entity_test'); @@ -60,25 +60,25 @@ class RawStringFormatterTest extends KernelTestBase { $this->bundle = $this->entityType; $this->fieldName = Unicode::strtolower($this->randomMachineName()); - $field_storage = FieldStorageConfig::create(array( + $field_storage = FieldStorageConfig::create([ 'field_name' => $this->fieldName, 'entity_type' => $this->entityType, 'type' => 'string_long', - )); + ]); $field_storage->save(); - $instance = FieldConfig::create(array( + $instance = FieldConfig::create([ 'field_storage' => $field_storage, 'bundle' => $this->bundle, 'label' => $this->randomMachineName(), - )); + ]); $instance->save(); $this->display = entity_get_display($this->entityType, $this->bundle, 'default') - ->setComponent($this->fieldName, array( + ->setComponent($this->fieldName, [ 'type' => 'string', - 'settings' => array(), - )); + 'settings' => [], + ]); $this->display->save(); } @@ -107,7 +107,7 @@ class RawStringFormatterTest extends KernelTestBase { $value .= "\n\n<strong>" . $this->randomString() . '</strong>'; $value .= "\n\n" . $this->randomString(); - $entity = EntityTest::create(array()); + $entity = EntityTest::create([]); $entity->{$this->fieldName}->value = $value; // Verify that all HTML is escaped and newlines are retained. diff --git a/core/modules/field/tests/src/Kernel/String/StringFormatterTest.php b/core/modules/field/tests/src/Kernel/String/StringFormatterTest.php index b52a92fd28f..b09eb58c091 100644 --- a/core/modules/field/tests/src/Kernel/String/StringFormatterTest.php +++ b/core/modules/field/tests/src/Kernel/String/StringFormatterTest.php @@ -23,7 +23,7 @@ class StringFormatterTest extends KernelTestBase { * * @var array */ - public static $modules = array('field', 'text', 'entity_test', 'system', 'filter', 'user'); + public static $modules = ['field', 'text', 'entity_test', 'system', 'filter', 'user']; /** * @var string @@ -52,7 +52,7 @@ class StringFormatterTest extends KernelTestBase { parent::setUp(); // Configure the theme system. - $this->installConfig(array('system', 'field')); + $this->installConfig(['system', 'field']); \Drupal::service('router.builder')->rebuild(); $this->installEntitySchema('entity_test_rev'); @@ -60,25 +60,25 @@ class StringFormatterTest extends KernelTestBase { $this->bundle = $this->entityType; $this->fieldName = Unicode::strtolower($this->randomMachineName()); - $field_storage = FieldStorageConfig::create(array( + $field_storage = FieldStorageConfig::create([ 'field_name' => $this->fieldName, 'entity_type' => $this->entityType, 'type' => 'string', - )); + ]); $field_storage->save(); - $instance = FieldConfig::create(array( + $instance = FieldConfig::create([ 'field_storage' => $field_storage, 'bundle' => $this->bundle, 'label' => $this->randomMachineName(), - )); + ]); $instance->save(); $this->display = entity_get_display($this->entityType, $this->bundle, 'default') - ->setComponent($this->fieldName, array( + ->setComponent($this->fieldName, [ 'type' => 'string', - 'settings' => array(), - )); + 'settings' => [], + ]); $this->display->save(); } @@ -107,7 +107,7 @@ class StringFormatterTest extends KernelTestBase { $value .= "\n\n<strong>" . $this->randomString() . '</strong>'; $value .= "\n\n" . $this->randomString(); - $entity = EntityTestRev::create(array()); + $entity = EntityTestRev::create([]); $entity->{$this->fieldName}->value = $value; // Verify that all HTML is escaped and newlines are retained. diff --git a/core/modules/field/tests/src/Kernel/TestItemTest.php b/core/modules/field/tests/src/Kernel/TestItemTest.php index 6766b4099f2..73a99486b6c 100644 --- a/core/modules/field/tests/src/Kernel/TestItemTest.php +++ b/core/modules/field/tests/src/Kernel/TestItemTest.php @@ -21,7 +21,7 @@ class TestItemTest extends FieldKernelTestBase { * * @var array */ - public static $modules = array('field_test'); + public static $modules = ['field_test']; /** * The name of the field to use in this test. @@ -34,11 +34,11 @@ class TestItemTest extends FieldKernelTestBase { parent::setUp(); // Create a 'test_field' field and storage for validation. - FieldStorageConfig::create(array( + FieldStorageConfig::create([ 'field_name' => $this->fieldName, 'entity_type' => 'entity_test', 'type' => 'test_field', - ))->save(); + ])->save(); FieldConfig::create([ 'entity_type' => 'entity_test', 'field_name' => $this->fieldName, @@ -76,19 +76,19 @@ class TestItemTest extends FieldKernelTestBase { $this->assertEqual($entity->{$this->fieldName}->value, $new_value); // Test the schema for this field type. - $expected_schema = array( - 'columns' => array( - 'value' => array( + $expected_schema = [ + 'columns' => [ + 'value' => [ 'type' => 'int', 'size' => 'medium', - ), - ), - 'unique keys' => array(), - 'indexes' => array( - 'value' => array('value'), - ), - 'foreign keys' => array(), - ); + ], + ], + 'unique keys' => [], + 'indexes' => [ + 'value' => ['value'], + ], + 'foreign keys' => [], + ]; $field_schema = BaseFieldDefinition::create('test_field')->getSchema(); $this->assertEqual($field_schema, $expected_schema); } diff --git a/core/modules/field/tests/src/Kernel/TestItemWithDependenciesTest.php b/core/modules/field/tests/src/Kernel/TestItemWithDependenciesTest.php index 9766a067fba..d1a269a6a26 100644 --- a/core/modules/field/tests/src/Kernel/TestItemWithDependenciesTest.php +++ b/core/modules/field/tests/src/Kernel/TestItemWithDependenciesTest.php @@ -17,7 +17,7 @@ class TestItemWithDependenciesTest extends FieldKernelTestBase { * * @var array */ - public static $modules = array('field_test'); + public static $modules = ['field_test']; /** * The name of the field to use in this test. @@ -31,11 +31,11 @@ class TestItemWithDependenciesTest extends FieldKernelTestBase { */ public function testTestItemWithDepenencies() { // Create a 'test_field_with_dependencies' field and storage for validation. - FieldStorageConfig::create(array( + FieldStorageConfig::create([ 'field_name' => $this->fieldName, 'entity_type' => 'entity_test', 'type' => 'test_field_with_dependencies', - ))->save(); + ])->save(); $field = FieldConfig::create([ 'entity_type' => 'entity_test', 'field_name' => $this->fieldName, diff --git a/core/modules/field/tests/src/Kernel/TestObjectItemTest.php b/core/modules/field/tests/src/Kernel/TestObjectItemTest.php index 8a7875581c9..1ac87fc3b7f 100644 --- a/core/modules/field/tests/src/Kernel/TestObjectItemTest.php +++ b/core/modules/field/tests/src/Kernel/TestObjectItemTest.php @@ -18,7 +18,7 @@ class TestObjectItemTest extends FieldKernelTestBase { * * @var array */ - public static $modules = array('field_test'); + public static $modules = ['field_test']; /** * {@inheritdoc} @@ -27,11 +27,11 @@ class TestObjectItemTest extends FieldKernelTestBase { parent::setUp(); // Create a 'test_field' field and storage for validation. - FieldStorageConfig::create(array( + FieldStorageConfig::create([ 'field_name' => 'field_test', 'entity_type' => 'entity_test', 'type' => 'test_object_field', - ))->save(); + ])->save(); FieldConfig::create([ 'entity_type' => 'entity_test', 'field_name' => 'field_test', diff --git a/core/modules/field/tests/src/Kernel/Timestamp/TimestampFormatterTest.php b/core/modules/field/tests/src/Kernel/Timestamp/TimestampFormatterTest.php index ee97cabbf8e..f71be314abf 100644 --- a/core/modules/field/tests/src/Kernel/Timestamp/TimestampFormatterTest.php +++ b/core/modules/field/tests/src/Kernel/Timestamp/TimestampFormatterTest.php @@ -140,7 +140,7 @@ class TimestampFormatterTest extends KernelTestBase { public function testTimestampAgoFormatter() { $data = []; - foreach (array(1, 2, 3, 4, 5, 6) as $granularity) { + foreach ([1, 2, 3, 4, 5, 6] as $granularity) { $data[] = [ 'future_format' => '@interval hence', 'past_format' => '@interval ago', diff --git a/core/modules/field/tests/src/Kernel/TranslationTest.php b/core/modules/field/tests/src/Kernel/TranslationTest.php index 78172a38217..f1fffe60f7a 100644 --- a/core/modules/field/tests/src/Kernel/TranslationTest.php +++ b/core/modules/field/tests/src/Kernel/TranslationTest.php @@ -23,7 +23,7 @@ class TranslationTest extends FieldKernelTestBase { * * @var array */ - public static $modules = array('language', 'node'); + public static $modules = ['language', 'node']; /** * The name of the field to use in this test. @@ -73,33 +73,33 @@ class TranslationTest extends FieldKernelTestBase { protected function setUp() { parent::setUp(); - $this->installConfig(array('language')); + $this->installConfig(['language']); $this->fieldName = Unicode::strtolower($this->randomMachineName()); $this->entityType = 'entity_test'; - $this->fieldStorageDefinition = array( + $this->fieldStorageDefinition = [ 'field_name' => $this->fieldName, 'entity_type' => $this->entityType, 'type' => 'test_field', 'cardinality' => 4, - ); + ]; $this->fieldStorage = FieldStorageConfig::create($this->fieldStorageDefinition); $this->fieldStorage->save(); - $this->fieldDefinition = array( + $this->fieldDefinition = [ 'field_storage' => $this->fieldStorage, 'bundle' => 'entity_test', - ); + ]; $this->field = FieldConfig::create($this->fieldDefinition); $this->field->save(); for ($i = 0; $i < 3; ++$i) { - ConfigurableLanguage::create(array( + ConfigurableLanguage::create([ 'id' => 'l' . $i, 'label' => $this->randomString(), - ))->save(); + ])->save(); } } @@ -117,8 +117,8 @@ class TranslationTest extends FieldKernelTestBase { field_test_entity_info_translatable($entity_type_id, TRUE); $entity = $this->container->get('entity_type.manager') ->getStorage($entity_type_id) - ->create(array('type' => $this->field->getTargetBundle())); - $field_translations = array(); + ->create(['type' => $this->field->getTargetBundle()]); + $field_translations = []; $available_langcodes = array_keys($this->container->get('language_manager')->getLanguages()); $entity->langcode->value = reset($available_langcodes); foreach ($available_langcodes as $langcode) { @@ -136,7 +136,7 @@ class TranslationTest extends FieldKernelTestBase { foreach ($items as $delta => $item) { $result = $result && $item['value'] == $entity->getTranslation($langcode)->{$this->fieldName}[$delta]->value; } - $this->assertTrue($result, format_string('%language translation correctly handled.', array('%language' => $langcode))); + $this->assertTrue($result, format_string('%language translation correctly handled.', ['%language' => $langcode])); } // Test default values. @@ -148,7 +148,7 @@ class TranslationTest extends FieldKernelTestBase { $field_definition = $this->fieldDefinition; $field_definition['field_storage'] = $field_storage; - $field_definition['default_value'] = array(array('value' => rand(1, 127))); + $field_definition['default_value'] = [['value' => rand(1, 127)]]; $field = FieldConfig::create($field_definition); $field->save(); @@ -156,7 +156,7 @@ class TranslationTest extends FieldKernelTestBase { asort($translation_langcodes); $translation_langcodes = array_values($translation_langcodes); - $values = array('type' => $field->getTargetBundle(), 'langcode' => $translation_langcodes[0]); + $values = ['type' => $field->getTargetBundle(), 'langcode' => $translation_langcodes[0]]; $entity = $this->container->get('entity_type.manager') ->getStorage($entity_type_id) ->create($values); @@ -173,11 +173,11 @@ class TranslationTest extends FieldKernelTestBase { // @todo Test every translation once the Entity Translation API allows for // multilingual defaults. $langcode = $entity->language()->getId(); - $this->assertEqual($entity->getTranslation($langcode)->{$field_name_default}->getValue(), $field->getDefaultValueLiteral(), format_string('Default value correctly populated for language %language.', array('%language' => $langcode))); + $this->assertEqual($entity->getTranslation($langcode)->{$field_name_default}->getValue(), $field->getDefaultValueLiteral(), format_string('Default value correctly populated for language %language.', ['%language' => $langcode])); // Check that explicit empty values are not overridden with default values. - foreach (array(NULL, array()) as $empty_items) { - $values = array('type' => $field->getTargetBundle(), 'langcode' => $translation_langcodes[0]); + foreach ([NULL, []] as $empty_items) { + $values = ['type' => $field->getTargetBundle(), 'langcode' => $translation_langcodes[0]]; $entity = entity_create($entity_type_id, $values); foreach ($translation_langcodes as $langcode) { $values[$this->fieldName][$langcode] = $this->_generateTestFieldValues($this->fieldStorage->getCardinality()); @@ -188,7 +188,7 @@ class TranslationTest extends FieldKernelTestBase { } foreach ($entity->getTranslationLanguages() as $langcode => $language) { - $this->assertEquals([], $entity->getTranslation($langcode)->{$field_name_default}->getValue(), format_string('Empty value correctly populated for language %language.', array('%language' => $langcode))); + $this->assertEquals([], $entity->getTranslation($langcode)->{$field_name_default}->getValue(), format_string('Empty value correctly populated for language %language.', ['%language' => $langcode])); } } } diff --git a/core/modules/field/tests/src/Kernel/WidgetPluginManagerTest.php b/core/modules/field/tests/src/Kernel/WidgetPluginManagerTest.php index 3eff2ca248f..47edb9f7746 100644 --- a/core/modules/field/tests/src/Kernel/WidgetPluginManagerTest.php +++ b/core/modules/field/tests/src/Kernel/WidgetPluginManagerTest.php @@ -33,13 +33,13 @@ class WidgetPluginManagerTest extends FieldKernelTestBase { // Set a name that will make isApplicable() return TRUE. ->setName('field_multiwidgetfield'); - $widget_options = array( + $widget_options = [ 'field_definition' => $base_field_definition, 'form_mode' => 'default', - 'configuration' => array( + 'configuration' => [ 'type' => 'test_field_widget_multiple', - ), - ); + ], + ]; $instance = $widget_plugin_manager->getInstance($widget_options); $this->assertEqual($instance->getPluginId(), 'test_field_widget_multiple'); diff --git a/core/modules/field/tests/src/Unit/FieldConfigEntityUnitTest.php b/core/modules/field/tests/src/Unit/FieldConfigEntityUnitTest.php index 3f687d4b9fc..3a0c8aa75ce 100644 --- a/core/modules/field/tests/src/Unit/FieldConfigEntityUnitTest.php +++ b/core/modules/field/tests/src/Unit/FieldConfigEntityUnitTest.php @@ -100,14 +100,14 @@ class FieldConfigEntityUnitTest extends UnitTestCase { ->will($this->returnValue('field_test')); $this->fieldStorage->expects($this->any()) ->method('getSettings') - ->willReturn(array()); + ->willReturn([]); // Place the field in the mocked entity manager's field registry. $this->entityManager->expects($this->any()) ->method('getFieldStorageDefinitions') ->with('test_entity_type') - ->will($this->returnValue(array( + ->will($this->returnValue([ $this->fieldStorage->getName() => $this->fieldStorage, - ))); + ])); } /** @@ -118,7 +118,7 @@ class FieldConfigEntityUnitTest extends UnitTestCase { $target_entity_type = $this->getMock('\Drupal\Core\Entity\EntityTypeInterface'); $target_entity_type->expects($this->any()) ->method('getBundleConfigDependency') - ->will($this->returnValue(array('type' => 'config', 'name' => 'test.test_entity_type.id'))); + ->will($this->returnValue(['type' => 'config', 'name' => 'test.test_entity_type.id'])); $this->entityManager->expects($this->at(0)) ->method('getDefinition') @@ -146,12 +146,12 @@ class FieldConfigEntityUnitTest extends UnitTestCase { ->method('getConfigDependencyName') ->will($this->returnValue('field.storage.test_entity_type.test_field')); - $field = new FieldConfig(array( + $field = new FieldConfig([ 'field_name' => $this->fieldStorage->getName(), 'entity_type' => 'test_entity_type', 'bundle' => 'test_bundle', 'field_type' => 'test_field', - ), $this->entityTypeId); + ], $this->entityTypeId); $dependencies = $field->calculateDependencies()->getDependencies(); $this->assertContains('field.storage.test_entity_type.test_field', $dependencies['config']); $this->assertContains('test.test_entity_type.id', $dependencies['config']); @@ -176,10 +176,10 @@ class FieldConfigEntityUnitTest extends UnitTestCase { ->with('bundle_entity_type') ->will($this->returnValue($storage)); - $target_entity_type = new EntityType(array( + $target_entity_type = new EntityType([ 'id' => 'test_entity_type', 'bundle_entity_type' => 'bundle_entity_type', - )); + ]); $this->entityManager->expects($this->at(0)) ->method('getDefinition') @@ -203,12 +203,12 @@ class FieldConfigEntityUnitTest extends UnitTestCase { ->with('test_field') ->willReturn(['provider' => 'test_module', 'config_dependencies' => ['module' => ['test_module2']], 'class' => '\Drupal\Tests\field\Unit\DependencyFieldItem']); - $field = new FieldConfig(array( + $field = new FieldConfig([ 'field_name' => $this->fieldStorage->getName(), 'entity_type' => 'test_entity_type', 'bundle' => 'test_bundle_not_exists', 'field_type' => 'test_field', - ), $this->entityTypeId); + ], $this->entityTypeId); $field->calculateDependencies(); } @@ -245,14 +245,14 @@ class FieldConfigEntityUnitTest extends UnitTestCase { * @covers ::toArray */ public function testToArray() { - $field = new FieldConfig(array( + $field = new FieldConfig([ 'field_name' => $this->fieldStorage->getName(), 'entity_type' => 'test_entity_type', 'bundle' => 'test_bundle', 'field_type' => 'test_field', - ), $this->entityTypeId); + ], $this->entityTypeId); - $expected = array( + $expected = [ 'id' => 'test_entity_type.test_bundle.field_test', 'uuid' => NULL, 'status' => TRUE, @@ -263,12 +263,12 @@ class FieldConfigEntityUnitTest extends UnitTestCase { 'label' => '', 'description' => '', 'required' => FALSE, - 'default_value' => array(), + 'default_value' => [], 'default_value_callback' => '', - 'settings' => array(), - 'dependencies' => array(), + 'settings' => [], + 'dependencies' => [], 'field_type' => 'test_field', - ); + ]; $this->entityManager->expects($this->any()) ->method('getDefinition') ->with($this->entityTypeId) @@ -279,7 +279,7 @@ class FieldConfigEntityUnitTest extends UnitTestCase { ->will($this->returnValue('id')); $this->typedConfigManager->expects($this->once()) ->method('getDefinition') - ->will($this->returnValue(array('mapping' => array_fill_keys(array_keys($expected), '')))); + ->will($this->returnValue(['mapping' => array_fill_keys(array_keys($expected), '')])); $export = $field->toArray(); $this->assertEquals($expected, $export); @@ -296,12 +296,12 @@ class FieldConfigEntityUnitTest extends UnitTestCase { $this->fieldStorage->expects($this->never()) ->method('getType'); - $field = new FieldConfig(array( + $field = new FieldConfig([ 'field_name' => $this->fieldStorage->getName(), 'entity_type' => 'test_entity_type', 'bundle' => 'test_bundle', 'field_type' => 'test_field', - ), $this->entityTypeId); + ], $this->entityTypeId); $this->assertEquals('test_field', $field->getType()); } diff --git a/core/modules/field/tests/src/Unit/Plugin/migrate/process/d6/FieldSettingsTest.php b/core/modules/field/tests/src/Unit/Plugin/migrate/process/d6/FieldSettingsTest.php index edeef211224..df18fec0aad 100644 --- a/core/modules/field/tests/src/Unit/Plugin/migrate/process/d6/FieldSettingsTest.php +++ b/core/modules/field/tests/src/Unit/Plugin/migrate/process/d6/FieldSettingsTest.php @@ -36,32 +36,32 @@ class FieldSettingsTest extends UnitTestCase { * Provides field settings for testGetSettings(). */ public function getSettingsProvider() { - return array( - array( + return [ + [ 'list_integer', - array('allowed_values' => "1|One\n2|Two\n3"), - array( + ['allowed_values' => "1|One\n2|Two\n3"], + [ '1' => 'One', '2' => 'Two', '3' => '3', - ), - ), - array( + ], + ], + [ 'list_string', - array('allowed_values' => NULL), - array(), - ), - array( + ['allowed_values' => NULL], + [], + ], + [ 'list_float', - array('allowed_values' => ""), - array(), - ), - array( + ['allowed_values' => ""], + [], + ], + [ 'boolean', - array(), - array(), - ), - ); + [], + [], + ], + ]; } } |