updated core
This commit is contained in:
@@ -138,7 +138,8 @@ function hook_field_widget_info_alter(array &$info) {
|
||||
* Alter forms for field widgets provided by other modules.
|
||||
*
|
||||
* @param $element
|
||||
* The field widget form element as constructed by hook_field_widget_form().
|
||||
* The field widget form element as constructed by
|
||||
* \Drupal\Core\Field\WidgetBaseInterface::form().
|
||||
* @param $form_state
|
||||
* The current state of the form.
|
||||
* @param $context
|
||||
@@ -152,6 +153,7 @@ function hook_field_widget_info_alter(array &$info) {
|
||||
* - default: A boolean indicating whether the form is being shown as a dummy
|
||||
* form to set default values.
|
||||
*
|
||||
* @see \Drupal\Core\Field\WidgetBaseInterface::form()
|
||||
* @see \Drupal\Core\Field\WidgetBase::formSingleElement()
|
||||
* @see hook_field_widget_WIDGET_TYPE_form_alter()
|
||||
*/
|
||||
@@ -172,13 +174,15 @@ function hook_field_widget_form_alter(&$element, \Drupal\Core\Form\FormStateInte
|
||||
* checking the widget type.
|
||||
*
|
||||
* @param $element
|
||||
* The field widget form element as constructed by hook_field_widget_form().
|
||||
* The field widget form element as constructed by
|
||||
* \Drupal\Core\Field\WidgetBaseInterface::form().
|
||||
* @param $form_state
|
||||
* The current state of the form.
|
||||
* @param $context
|
||||
* An associative array. See hook_field_widget_form_alter() for the structure
|
||||
* and content of the array.
|
||||
*
|
||||
* @see \Drupal\Core\Field\WidgetBaseInterface::form()
|
||||
* @see \Drupal\Core\Field\WidgetBase::formSingleElement()
|
||||
* @see hook_field_widget_form_alter()
|
||||
*/
|
||||
|
||||
@@ -5,8 +5,8 @@ package: Core
|
||||
# version: VERSION
|
||||
# core: 8.x
|
||||
|
||||
# Information added by Drupal.org packaging script on 2017-11-03
|
||||
version: '8.4.2'
|
||||
# Information added by Drupal.org packaging script on 2018-01-03
|
||||
version: '8.4.4'
|
||||
core: '8.x'
|
||||
project: 'drupal'
|
||||
datestamp: 1509719929
|
||||
datestamp: 1515021228
|
||||
|
||||
@@ -250,19 +250,6 @@ function field_entity_bundle_delete($entity_type_id, $bundle) {
|
||||
unset($handler_settings['target_bundles'][$bundle]);
|
||||
$field_config->setSetting('handler_settings', $handler_settings);
|
||||
$field_config->save();
|
||||
|
||||
// In case we deleted the only target bundle allowed by the field we
|
||||
// have to log a critical message because the field will not function
|
||||
// correctly anymore.
|
||||
if ($handler_settings['target_bundles'] === []) {
|
||||
\Drupal::logger('entity_reference')->critical('The %target_bundle bundle (entity type: %target_entity_type) was deleted. As a result, the %field_name entity reference field (entity_type: %entity_type, bundle: %bundle) no longer has any valid bundle it can reference. The field is not working correctly anymore and has to be adjusted.', [
|
||||
'%target_bundle' => $bundle,
|
||||
'%target_entity_type' => $entity_type_id,
|
||||
'%field_name' => $field_config->getName(),
|
||||
'%entity_type' => $field_config->getTargetEntityTypeId(),
|
||||
'%bundle' => $field_config->getTargetBundle()
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -407,4 +394,17 @@ function field_field_config_presave(FieldConfigInterface $field) {
|
||||
$selection_manager = \Drupal::service('plugin.manager.entity_reference_selection');
|
||||
list($current_handler) = explode(':', $field->getSetting('handler'), 2);
|
||||
$field->setSetting('handler', $selection_manager->getPluginId($target_type, $current_handler));
|
||||
|
||||
// In case we removed all the target bundles allowed by the field in
|
||||
// EntityReferenceItem::onDependencyRemoval() or field_entity_bundle_delete()
|
||||
// we have to log a critical message because the field will not function
|
||||
// correctly anymore.
|
||||
$handler_settings = $field->getSetting('handler_settings');
|
||||
if (isset($handler_settings['target_bundles']) && $handler_settings['target_bundles'] === []) {
|
||||
\Drupal::logger('entity_reference')->critical('The %field_name entity reference field (entity_type: %entity_type, bundle: %bundle) no longer has any valid bundle it can reference. The field is not working correctly anymore and has to be adjusted.', [
|
||||
'%field_name' => $field->getName(),
|
||||
'%entity_type' => $field->getTargetEntityTypeId(),
|
||||
'%bundle' => $field->getTargetBundle(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,16 @@ class FieldSettings extends ProcessPluginBase {
|
||||
}
|
||||
break;
|
||||
|
||||
case 'date':
|
||||
case 'datetime':
|
||||
case 'datestamp':
|
||||
if ($value['granularity']['hour'] === 0
|
||||
&& $value['granularity']['minute'] === 0
|
||||
&& $value['granularity']['second'] === 0) {
|
||||
$value['datetime_type'] = 'date';
|
||||
}
|
||||
break;
|
||||
|
||||
case 'taxonomy_term_reference':
|
||||
$value['target_type'] = 'taxonomy_term';
|
||||
break;
|
||||
|
||||
@@ -145,7 +145,7 @@ class FieldInstance extends DrupalSqlBase {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function count() {
|
||||
public function count($refresh = FALSE) {
|
||||
return $this->initializeIterator()->count();
|
||||
}
|
||||
|
||||
|
||||
@@ -330,6 +330,12 @@ class EntityReferenceAdminTest extends WebTestBase {
|
||||
$this->drupalPostForm(NULL, $edit, t('Save field settings'));
|
||||
$this->drupalGet($bundle_path . '/fields/' . $field_path);
|
||||
$term_name = $this->randomString();
|
||||
$result = \Drupal::entityQuery('taxonomy_term')
|
||||
->condition('name', $term_name)
|
||||
->condition('vid', 'tags')
|
||||
->accessCheck(FALSE)
|
||||
->execute();
|
||||
$this->assertIdentical(0, count($result), "No taxonomy terms exist with the name '$term_name'.");
|
||||
$edit = [
|
||||
// This must be set before new entities will be auto-created.
|
||||
'settings[handler_settings][auto_create]' => 1,
|
||||
@@ -342,8 +348,12 @@ class EntityReferenceAdminTest extends WebTestBase {
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save settings'));
|
||||
// The term should now exist.
|
||||
$term = taxonomy_term_load_multiple_by_name($term_name, 'tags')[1];
|
||||
$this->assertIdentical(1, count($term), 'Taxonomy term was auto created when set as field default.');
|
||||
$result = \Drupal::entityQuery('taxonomy_term')
|
||||
->condition('name', $term_name)
|
||||
->condition('vid', 'tags')
|
||||
->accessCheck(FALSE)
|
||||
->execute();
|
||||
$this->assertIdentical(1, count($result), 'Taxonomy term was auto created when set as field default.');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,228 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\field\Tests\EntityReference;
|
||||
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\Core\Field\FieldStorageDefinitionInterface;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
use Drupal\taxonomy\Entity\Vocabulary;
|
||||
use Drupal\node\Entity\Node;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
|
||||
/**
|
||||
* Tests creating new entity (e.g. taxonomy-term) from an autocomplete widget.
|
||||
*
|
||||
* @group entity_reference
|
||||
*/
|
||||
class EntityReferenceAutoCreateTest extends WebTestBase {
|
||||
|
||||
use EntityReferenceTestTrait;
|
||||
|
||||
public static $modules = ['node', 'taxonomy'];
|
||||
|
||||
/**
|
||||
* The name of a content type that will reference $referencedType.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $referencingType;
|
||||
|
||||
/**
|
||||
* The name of a content type that will be referenced by $referencingType.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $referencedType;
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Create "referencing" and "referenced" node types.
|
||||
$referencing = $this->drupalCreateContentType();
|
||||
$this->referencingType = $referencing->id();
|
||||
|
||||
$referenced = $this->drupalCreateContentType();
|
||||
$this->referencedType = $referenced->id();
|
||||
|
||||
FieldStorageConfig::create(array(
|
||||
'field_name' => 'test_field',
|
||||
'entity_type' => 'node',
|
||||
'translatable' => FALSE,
|
||||
'entity_types' => array(),
|
||||
'settings' => array(
|
||||
'target_type' => 'node',
|
||||
),
|
||||
'type' => 'entity_reference',
|
||||
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
|
||||
))->save();
|
||||
|
||||
FieldConfig::create([
|
||||
'label' => 'Entity reference field',
|
||||
'field_name' => 'test_field',
|
||||
'entity_type' => 'node',
|
||||
'bundle' => $referencing->id(),
|
||||
'settings' => array(
|
||||
'handler' => 'default',
|
||||
'handler_settings' => array(
|
||||
// Reference a single vocabulary.
|
||||
'target_bundles' => array(
|
||||
$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(
|
||||
'type' => 'entity_reference_autocomplete',
|
||||
))
|
||||
->save();
|
||||
|
||||
$account = $this->drupalCreateUser(['access content', "create $this->referencingType content"]);
|
||||
$this->drupalLogin($account);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the autocomplete input element appears and the creation of a new
|
||||
* entity.
|
||||
*/
|
||||
public function testAutoCreate() {
|
||||
$this->drupalGet('node/add/' . $this->referencingType);
|
||||
$this->assertFieldByXPath('//input[@id="edit-test-field-0-target-id" and contains(@class, "form-autocomplete")]', NULL, 'The autocomplete input element appears.');
|
||||
|
||||
$new_title = $this->randomMachineName();
|
||||
|
||||
// Assert referenced node does not exist.
|
||||
$base_query = \Drupal::entityQuery('node');
|
||||
$base_query
|
||||
->condition('type', $this->referencedType)
|
||||
->condition('title', $new_title);
|
||||
|
||||
$query = clone $base_query;
|
||||
$result = $query->execute();
|
||||
$this->assertFalse($result, 'Referenced node does not exist yet.');
|
||||
|
||||
$edit = array(
|
||||
'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.
|
||||
$query = clone $base_query;
|
||||
$result = $query->execute();
|
||||
$this->assertTrue($result, 'Referenced node was created.');
|
||||
$referenced_nid = key($result);
|
||||
$referenced_node = Node::load($referenced_nid);
|
||||
|
||||
// Assert the referenced node is associated with referencing node.
|
||||
$result = \Drupal::entityQuery('node')
|
||||
->condition('type', $this->referencingType)
|
||||
->execute();
|
||||
|
||||
$referencing_nid = key($result);
|
||||
$referencing_node = Node::load($referencing_nid);
|
||||
$this->assertEqual($referenced_nid, $referencing_node->test_field->target_id, 'Newly created node is referenced from the referencing node.');
|
||||
|
||||
// Now try to view the node and check that the referenced node is shown.
|
||||
$this->drupalGet('node/' . $referencing_node->id());
|
||||
$this->assertText($referencing_node->label(), 'Referencing node label found.');
|
||||
$this->assertText($referenced_node->label(), 'Referenced node label found.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if an entity reference field having multiple target bundles is
|
||||
* storing the auto-created entity in the right destination.
|
||||
*/
|
||||
public function testMultipleTargetBundles() {
|
||||
/** @var \Drupal\taxonomy\Entity\Vocabulary[] $vocabularies */
|
||||
$vocabularies = [];
|
||||
for ($i = 0; $i < 2; $i++) {
|
||||
$vid = Unicode::strtolower($this->randomMachineName());
|
||||
$vocabularies[$i] = Vocabulary::create([
|
||||
'name' => $this->randomMachineName(),
|
||||
'vid' => $vid,
|
||||
]);
|
||||
$vocabularies[$i]->save();
|
||||
}
|
||||
|
||||
// Create a taxonomy term entity reference field that saves the auto-created
|
||||
// taxonomy terms in the second vocabulary from the two that were configured
|
||||
// as targets.
|
||||
$field_name = Unicode::strtolower($this->randomMachineName());
|
||||
$handler_settings = [
|
||||
'target_bundles' => [
|
||||
$vocabularies[0]->id() => $vocabularies[0]->id(),
|
||||
$vocabularies[1]->id() => $vocabularies[1]->id(),
|
||||
],
|
||||
'auto_create' => TRUE,
|
||||
'auto_create_bundle' => $vocabularies[1]->id(),
|
||||
];
|
||||
$this->createEntityReferenceField('node', $this->referencingType, $field_name, $this->randomString(), 'taxonomy_term', 'default', $handler_settings);
|
||||
/** @var \Drupal\Core\Entity\Display\EntityFormDisplayInterface $fd */
|
||||
entity_get_form_display('node', $this->referencingType, 'default')
|
||||
->setComponent($field_name, ['type' => 'entity_reference_autocomplete'])
|
||||
->save();
|
||||
|
||||
$term_name = $this->randomString();
|
||||
$edit = [
|
||||
$field_name . '[0][target_id]' => $term_name,
|
||||
'title[0][value]' => $this->randomString(),
|
||||
];
|
||||
|
||||
$this->drupalPostForm('node/add/' . $this->referencingType, $edit, 'Save');
|
||||
/** @var \Drupal\taxonomy\Entity\Term $term */
|
||||
$term = taxonomy_term_load_multiple_by_name($term_name);
|
||||
$term = reset($term);
|
||||
|
||||
// The new term is expected to be stored in the second vocabulary.
|
||||
$this->assertEqual($vocabularies[1]->id(), $term->bundle());
|
||||
|
||||
/** @var \Drupal\field\Entity\FieldConfig $field_config */
|
||||
$field_config = FieldConfig::loadByName('node', $this->referencingType, $field_name);
|
||||
$handler_settings = $field_config->getSetting('handler_settings');
|
||||
|
||||
// Change the field setting to store the auto-created terms in the first
|
||||
// vocabulary and test again.
|
||||
$handler_settings['auto_create_bundle'] = $vocabularies[0]->id();
|
||||
$field_config->setSetting('handler_settings', $handler_settings);
|
||||
$field_config->save();
|
||||
|
||||
$term_name = $this->randomString();
|
||||
$edit = [
|
||||
$field_name . '[0][target_id]' => $term_name,
|
||||
'title[0][value]' => $this->randomString(),
|
||||
];
|
||||
|
||||
$this->drupalPostForm('node/add/' . $this->referencingType, $edit, 'Save');
|
||||
/** @var \Drupal\taxonomy\Entity\Term $term */
|
||||
$term = taxonomy_term_load_multiple_by_name($term_name);
|
||||
$term = reset($term);
|
||||
|
||||
// The second term is expected to be stored in the first vocabulary.
|
||||
$this->assertEqual($vocabularies[0]->id(), $term->bundle());
|
||||
|
||||
// @todo Re-enable this test when WebTestBase::curlHeaderCallback() provides
|
||||
// a way to catch and assert user-triggered errors.
|
||||
|
||||
// Test the case when the field config settings are inconsistent.
|
||||
//unset($handler_settings['auto_create_bundle']);
|
||||
//$field_config->setSetting('handler_settings', $handler_settings);
|
||||
//$field_config->save();
|
||||
//
|
||||
//$this->drupalGet('node/add/' . $this->referencingType);
|
||||
//$error_message = sprintf(
|
||||
// "Create referenced entities if they don't already exist option is enabled but a specific destination bundle is not set. You should re-visit and fix the settings of the '%s' (%s) field.",
|
||||
// $field_config->getLabel(),
|
||||
// $field_config->getName()
|
||||
//);
|
||||
//$this->assertErrorLogged($error_message);
|
||||
}
|
||||
|
||||
}
|
||||
-158
@@ -1,158 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\field\Tests\EntityReference;
|
||||
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\config\Tests\SchemaCheckTestTrait;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\node\Entity\Node;
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
|
||||
/**
|
||||
* Tests entity reference field default values storage in CMI.
|
||||
*
|
||||
* @group entity_reference
|
||||
*/
|
||||
class EntityReferenceFieldDefaultValueTest extends WebTestBase {
|
||||
|
||||
use SchemaCheckTestTrait;
|
||||
|
||||
/**
|
||||
* Modules to install.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['field_ui', 'node'];
|
||||
|
||||
/**
|
||||
* A user with permission to administer content types, node fields, etc.
|
||||
*
|
||||
* @var \Drupal\user\UserInterface
|
||||
*/
|
||||
protected $adminUser;
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Create default content type.
|
||||
$this->drupalCreateContentType(array('type' => 'reference_content'));
|
||||
$this->drupalCreateContentType(array('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->drupalLogin($this->adminUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that default values are correctly translated to UUIDs in config.
|
||||
*/
|
||||
function testEntityReferenceDefaultValue() {
|
||||
// Create a node to be referenced.
|
||||
$referenced_node = $this->drupalCreateNode(array('type' => 'referenced_content'));
|
||||
|
||||
$field_name = Unicode::strtolower($this->randomMachineName());
|
||||
$field_storage = FieldStorageConfig::create(array(
|
||||
'field_name' => $field_name,
|
||||
'entity_type' => 'node',
|
||||
'type' => 'entity_reference',
|
||||
'settings' => array('target_type' => 'node'),
|
||||
));
|
||||
$field_storage->save();
|
||||
$field = FieldConfig::create([
|
||||
'field_storage' => $field_storage,
|
||||
'bundle' => 'reference_content',
|
||||
'settings' => array(
|
||||
'handler' => 'default',
|
||||
'handler_settings' => array(
|
||||
'target_bundles' => array('referenced_content'),
|
||||
'sort' => array('field' => '_none'),
|
||||
),
|
||||
),
|
||||
]);
|
||||
$field->save();
|
||||
|
||||
// Set created node as default_value.
|
||||
$field_edit = array(
|
||||
'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.
|
||||
$this->drupalGet('admin/structure/types/manage/reference_content/fields/node.reference_content.' . $field_name);
|
||||
$this->assertRaw('name="default_value_input[' . $field_name . '][0][target_id]" value="' . $referenced_node->getTitle() . ' (' . $referenced_node->id() . ')', 'The default value is selected in instance settings page');
|
||||
|
||||
// Check if the ID has been converted to UUID in config entity.
|
||||
$config_entity = $this->config('field.field.node.reference_content.' . $field_name)->get();
|
||||
$this->assertTrue(isset($config_entity['default_value'][0]['target_uuid']), 'Default value contains target_uuid property');
|
||||
$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']);
|
||||
|
||||
// Clear field definitions cache in order to avoid stale cache values.
|
||||
\Drupal::entityManager()->clearCachedFieldDefinitions();
|
||||
|
||||
// Create a new node to check that UUID has been converted to numeric ID.
|
||||
$new_node = Node::create(['type' => 'reference_content']);
|
||||
$this->assertEqual($new_node->get($field_name)->offsetGet(0)->target_id, $referenced_node->id());
|
||||
|
||||
// Ensure that the entity reference config schemas are correct.
|
||||
$field_config = $this->config('field.field.node.reference_content.' . $field_name);
|
||||
$this->assertConfigSchema(\Drupal::service('config.typed'), $field_config->getName(), $field_config->get());
|
||||
$field_storage_config = $this->config('field.storage.node.' . $field_name);
|
||||
$this->assertConfigSchema(\Drupal::service('config.typed'), $field_storage_config->getName(), $field_storage_config->get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that dependencies due to default values can be removed.
|
||||
*
|
||||
* @see \Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem::onDependencyRemoval()
|
||||
*/
|
||||
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'));
|
||||
|
||||
$field_name = Unicode::strtolower($this->randomMachineName());
|
||||
$field_storage = FieldStorageConfig::create(array(
|
||||
'field_name' => $field_name,
|
||||
'entity_type' => 'node',
|
||||
'type' => 'entity_reference',
|
||||
'settings' => array('target_type' => 'node_type'),
|
||||
'cardinality' => FieldStorageConfig::CARDINALITY_UNLIMITED,
|
||||
));
|
||||
$field_storage->save();
|
||||
$field = FieldConfig::create([
|
||||
'field_storage' => $field_storage,
|
||||
'bundle' => 'reference_content',
|
||||
'settings' => array(
|
||||
'handler' => 'default',
|
||||
'handler_settings' => array(
|
||||
'sort' => array('field' => '_none'),
|
||||
),
|
||||
),
|
||||
]);
|
||||
$field->save();
|
||||
|
||||
// Set created node as default_value.
|
||||
$field_edit = array(
|
||||
'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.
|
||||
$config_entity = $this->config('field.field.node.reference_content.' . $field_name)->get();
|
||||
$this->assertTrue(in_array($referenced_node_type->getConfigDependencyName(), $config_entity['dependencies']['config'], TRUE), 'The node type referenced_config_to_delete is a dependency of the field.');
|
||||
$this->assertTrue(in_array($referenced_node_type2->getConfigDependencyName(), $config_entity['dependencies']['config'], TRUE), 'The node type referenced_config_to_preserve is a dependency of the field.');
|
||||
|
||||
// Check that the field does not have a dependency on the default value
|
||||
// after deleting the node type.
|
||||
$referenced_node_type->delete();
|
||||
$config_entity = $this->config('field.field.node.reference_content.' . $field_name)->get();
|
||||
$this->assertFalse(in_array($referenced_node_type->getConfigDependencyName(), $config_entity['dependencies']['config'], TRUE), 'The node type referenced_config_to_delete not a dependency of the field.');
|
||||
$this->assertTrue(in_array($referenced_node_type2->getConfigDependencyName(), $config_entity['dependencies']['config'], TRUE), 'The node type referenced_config_to_preserve is a dependency of the field.');
|
||||
}
|
||||
|
||||
}
|
||||
-322
@@ -1,322 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\field\Tests\EntityReference;
|
||||
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\Core\Field\FieldStorageDefinitionInterface;
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
|
||||
/**
|
||||
* Tests the translation of entity reference field display on nodes.
|
||||
*
|
||||
* @group entity_reference
|
||||
*/
|
||||
class EntityReferenceFieldTranslatedReferenceViewTest extends WebTestBase {
|
||||
|
||||
/**
|
||||
* Flag indicating whether the field is translatable.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $translatable = TRUE;
|
||||
|
||||
/**
|
||||
* The langcode of the source language.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $baseLangcode = 'en';
|
||||
|
||||
/**
|
||||
* Target langcode for translation.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $translateToLangcode = 'hu';
|
||||
|
||||
/**
|
||||
* The test entity type name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $testEntityTypeName = 'node';
|
||||
|
||||
/**
|
||||
* Entity type which have the entity reference field.
|
||||
*
|
||||
* @var \Drupal\node\Entity\NodeType
|
||||
*/
|
||||
protected $referrerType;
|
||||
|
||||
/**
|
||||
* Entity type which can be referenced.
|
||||
*
|
||||
* @var \Drupal\node\Entity\NodeType
|
||||
*/
|
||||
protected $referencedType;
|
||||
|
||||
/**
|
||||
* The referrer entity.
|
||||
*
|
||||
* @var \Drupal\node\Entity\Node
|
||||
*/
|
||||
protected $referrerEntity;
|
||||
|
||||
/**
|
||||
* The entity to refer.
|
||||
*
|
||||
* @var \Drupal\node\Entity\Node
|
||||
*/
|
||||
protected $referencedEntityWithoutTranslation;
|
||||
|
||||
/**
|
||||
* The entity to refer.
|
||||
*
|
||||
* @var \Drupal\node\Entity\Node
|
||||
*/
|
||||
protected $referencedEntityWithTranslation;
|
||||
|
||||
/**
|
||||
* The machine name of the entity reference field.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $referenceFieldName = 'test_reference_field';
|
||||
|
||||
/**
|
||||
* The label of the untranslated referenced entity, used in assertions.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $labelOfNotTranslatedReference;
|
||||
|
||||
/**
|
||||
* The original label of the referenced entity, used in assertions.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $originalLabel;
|
||||
|
||||
/**
|
||||
* The translated label of the referenced entity, used in assertions.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $translatedLabel;
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array(
|
||||
'language',
|
||||
'content_translation',
|
||||
'node',
|
||||
);
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->labelOfNotTranslatedReference = $this->randomMachineName();
|
||||
$this->originalLabel = $this->randomMachineName();
|
||||
$this->translatedLabel = $this->randomMachineName();
|
||||
|
||||
$this->setUpLanguages();
|
||||
|
||||
// We setup languages, so we need to ensure that the language manager
|
||||
// and language path processor is updated.
|
||||
$this->rebuildContainer();
|
||||
|
||||
$this->setUpContentTypes();
|
||||
$this->enableTranslation();
|
||||
$this->setUpEntityReferenceField();
|
||||
$this->createContent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if the entity is displayed in an entity reference field.
|
||||
*/
|
||||
public function testEntityReferenceDisplay() {
|
||||
// Create a translated referrer entity.
|
||||
$this->referrerEntity = $this->createReferrerEntity();
|
||||
$this->assertEntityReferenceDisplay();
|
||||
|
||||
// Disable translation for referrer content type.
|
||||
$this->drupalLogin($this->rootUser);
|
||||
$this->drupalPostForm('admin/config/regional/content-language', ['settings[node][referrer][translatable]' => FALSE], t('Save configuration'));
|
||||
|
||||
// Create a referrer entity without translation.
|
||||
$this->referrerEntity = $this->createReferrerEntity(FALSE);
|
||||
$this->assertEntityReferenceDisplay();
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert entity reference display.
|
||||
*/
|
||||
protected function assertEntityReferenceDisplay() {
|
||||
$url = $this->referrerEntity->urlInfo();
|
||||
$translation_url = $this->referrerEntity->urlInfo('canonical', ['language' => ConfigurableLanguage::load($this->translateToLangcode)]);
|
||||
|
||||
$this->drupalGet($url);
|
||||
$this->assertText($this->labelOfNotTranslatedReference, 'The label of not translated reference is displayed.');
|
||||
$this->assertText($this->originalLabel, 'The default label of translated reference is displayed.');
|
||||
$this->assertNoText($this->translatedLabel, 'The translated label of translated reference is not displayed.');
|
||||
$this->drupalGet($translation_url);
|
||||
$this->assertText($this->labelOfNotTranslatedReference, 'The label of not translated reference is displayed.');
|
||||
$this->assertNoText($this->originalLabel, 'The default label of translated reference is not displayed.');
|
||||
$this->assertText($this->translatedLabel, 'The translated label of translated reference is displayed.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds additional languages.
|
||||
*/
|
||||
protected function setUpLanguages() {
|
||||
ConfigurableLanguage::createFromLangcode($this->translateToLangcode)->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a test subject contents, with translation.
|
||||
*/
|
||||
protected function createContent() {
|
||||
$this->referencedEntityWithTranslation = $this->createReferencedEntityWithTranslation();
|
||||
$this->referencedEntityWithoutTranslation = $this->createNotTranslatedReferencedEntity();
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables translations where it needed.
|
||||
*/
|
||||
protected function enableTranslation() {
|
||||
// Enable translation for the entity types and ensure the change is picked
|
||||
// up.
|
||||
\Drupal::service('content_translation.manager')->setEnabled($this->testEntityTypeName, $this->referrerType->id(), TRUE);
|
||||
\Drupal::service('content_translation.manager')->setEnabled($this->testEntityTypeName, $this->referencedType->id(), TRUE);
|
||||
drupal_static_reset();
|
||||
\Drupal::entityManager()->clearCachedDefinitions();
|
||||
\Drupal::service('router.builder')->rebuild();
|
||||
\Drupal::service('entity.definition_update_manager')->applyUpdates();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds term reference field for the article content type.
|
||||
*/
|
||||
protected function setUpEntityReferenceField() {
|
||||
FieldStorageConfig::create(array(
|
||||
'field_name' => $this->referenceFieldName,
|
||||
'entity_type' => $this->testEntityTypeName,
|
||||
'type' => 'entity_reference',
|
||||
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
|
||||
'translatable' => $this->translatable,
|
||||
'settings' => array(
|
||||
'allowed_values' => array(
|
||||
array(
|
||||
'target_type' => $this->testEntityTypeName,
|
||||
),
|
||||
),
|
||||
),
|
||||
))->save();
|
||||
|
||||
FieldConfig::create([
|
||||
'field_name' => $this->referenceFieldName,
|
||||
'bundle' => $this->referrerType->id(),
|
||||
'entity_type' => $this->testEntityTypeName,
|
||||
])
|
||||
->save();
|
||||
entity_get_form_display($this->testEntityTypeName, $this->referrerType->id(), 'default')
|
||||
->setComponent($this->referenceFieldName, array(
|
||||
'type' => 'entity_reference_autocomplete',
|
||||
))
|
||||
->save();
|
||||
entity_get_display($this->testEntityTypeName, $this->referrerType->id(), 'default')
|
||||
->setComponent($this->referenceFieldName, array(
|
||||
'type' => 'entity_reference_label',
|
||||
))
|
||||
->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create content types.
|
||||
*/
|
||||
protected function setUpContentTypes() {
|
||||
$this->referrerType = $this->drupalCreateContentType(array(
|
||||
'type' => 'referrer',
|
||||
'name' => 'Referrer',
|
||||
));
|
||||
$this->referencedType = $this->drupalCreateContentType(array(
|
||||
'type' => 'referenced_page',
|
||||
'name' => 'Referenced Page',
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a referenced entity with a translation.
|
||||
*/
|
||||
protected function createReferencedEntityWithTranslation() {
|
||||
/** @var \Drupal\node\Entity\Node $node */
|
||||
$node = entity_create($this->testEntityTypeName, array(
|
||||
'title' => $this->originalLabel,
|
||||
'type' => $this->referencedType->id(),
|
||||
'description' => array(
|
||||
'value' => $this->randomMachineName(),
|
||||
'format' => 'basic_html',
|
||||
),
|
||||
'langcode' => $this->baseLangcode,
|
||||
));
|
||||
$node->save();
|
||||
$node->addTranslation($this->translateToLangcode, array(
|
||||
'title' => $this->translatedLabel,
|
||||
));
|
||||
$node->save();
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create the referenced entity.
|
||||
*/
|
||||
protected function createNotTranslatedReferencedEntity() {
|
||||
/** @var \Drupal\node\Entity\Node $node */
|
||||
$node = entity_create($this->testEntityTypeName, array(
|
||||
'title' => $this->labelOfNotTranslatedReference,
|
||||
'type' => $this->referencedType->id(),
|
||||
'description' => array(
|
||||
'value' => $this->randomMachineName(),
|
||||
'format' => 'basic_html',
|
||||
),
|
||||
'langcode' => $this->baseLangcode,
|
||||
));
|
||||
$node->save();
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the referrer entity.
|
||||
*/
|
||||
protected function createReferrerEntity($translatable = TRUE) {
|
||||
/** @var \Drupal\node\Entity\Node $node */
|
||||
$node = entity_create($this->testEntityTypeName, array(
|
||||
'title' => $this->randomMachineName(),
|
||||
'type' => $this->referrerType->id(),
|
||||
'description' => array(
|
||||
'value' => $this->randomMachineName(),
|
||||
'format' => 'basic_html',
|
||||
),
|
||||
$this->referenceFieldName => array(
|
||||
array('target_id' => $this->referencedEntityWithTranslation->id()),
|
||||
array('target_id' => $this->referencedEntityWithoutTranslation->id()),
|
||||
),
|
||||
'langcode' => $this->baseLangcode,
|
||||
));
|
||||
if ($translatable) {
|
||||
$node->addTranslation($this->translateToLangcode, $node->toArray());
|
||||
}
|
||||
$node->save();
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -77,7 +77,6 @@ class EntityReferenceFileUploadTest extends WebTestBase {
|
||||
],
|
||||
])->save();
|
||||
|
||||
|
||||
// Create a file field.
|
||||
$file_field_name = 'file_field';
|
||||
$field_storage = FieldStorageConfig::create([
|
||||
|
||||
@@ -1,218 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\field\Tests\EntityReference;
|
||||
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
use Drupal\config\Tests\AssertConfigEntityImportTrait;
|
||||
use Drupal\entity_test\Entity\EntityTest;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
|
||||
/**
|
||||
* Tests various Entity reference UI components.
|
||||
*
|
||||
* @group entity_reference
|
||||
*/
|
||||
class EntityReferenceIntegrationTest extends WebTestBase {
|
||||
|
||||
use AssertConfigEntityImportTrait;
|
||||
use EntityReferenceTestTrait;
|
||||
|
||||
/**
|
||||
* The entity type used in this test.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $entityType = 'entity_test';
|
||||
|
||||
/**
|
||||
* The bundle used in this test.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $bundle = 'entity_test';
|
||||
|
||||
/**
|
||||
* The name of the field used in this test.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $fieldName;
|
||||
|
||||
/**
|
||||
* Modules to install.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['config_test', 'entity_test', 'field_ui'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Create a test user.
|
||||
$web_user = $this->drupalCreateUser(array('administer entity_test content', 'administer entity_test fields', 'view test entity'));
|
||||
$this->drupalLogin($web_user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the entity reference field with all its supported field widgets.
|
||||
*/
|
||||
public function testSupportedEntityTypesAndWidgets() {
|
||||
foreach ($this->getTestEntities() as $key => $referenced_entities) {
|
||||
$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);
|
||||
|
||||
// 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(
|
||||
'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);
|
||||
|
||||
// Try to post the form again with no modification and check if the field
|
||||
// values remain the same.
|
||||
$entity = current(entity_load_multiple_by_properties($this->entityType, array('name' => $entity_name)));
|
||||
$this->drupalGet($this->entityType . '/manage/' . $entity->id() . '/edit');
|
||||
$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->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(
|
||||
'type' => 'entity_reference_autocomplete_tags',
|
||||
))->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(
|
||||
'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);
|
||||
|
||||
// Try to post the form again with no modification and check if the field
|
||||
// values remain the same.
|
||||
$entity = current(entity_load_multiple_by_properties($this->entityType, array('name' => $entity_name)));
|
||||
$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->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');
|
||||
$entity = current(entity_load_multiple_by_properties($this->entityType, array('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(
|
||||
'type' => $widget_type,
|
||||
))->save();
|
||||
|
||||
$this->drupalPostForm($this->entityType . '/manage/' . $entity->id() . '/edit', array(), t('Save'));
|
||||
$this->assertFieldValues($entity_name, $referenced_entities);
|
||||
}
|
||||
|
||||
// Reset to the default 'entity_reference_autocomplete' widget.
|
||||
entity_get_form_display($this->entityType, $this->bundle, 'default')->setComponent($this->fieldName)->save();
|
||||
|
||||
// Set first entity as the default_value.
|
||||
$field_edit = array(
|
||||
'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;
|
||||
}
|
||||
$this->drupalPostForm($this->entityType . '/structure/' . $this->bundle . '/fields/' . $this->entityType . '.' . $this->bundle . '.' . $this->fieldName, $field_edit, t('Save settings'));
|
||||
// Ensure the configuration has the expected dependency on the entity that
|
||||
// is being used a default value.
|
||||
$field = FieldConfig::loadByName($this->entityType, $this->bundle, $this->fieldName);
|
||||
$this->assertTrue(in_array($referenced_entities[0]->getConfigDependencyName(), $field->getDependencies()[$key]), SafeMarkup::format('Expected @type dependency @name found', ['@type' => $key, '@name' => $referenced_entities[0]->getConfigDependencyName()]));
|
||||
// Ensure that the field can be imported without change even after the
|
||||
// default value deleted.
|
||||
$referenced_entities[0]->delete();
|
||||
// Reload the field since deleting the default value can change the field.
|
||||
\Drupal::entityManager()->getStorage($field->getEntityTypeId())->resetCache([$field->id()]);
|
||||
$field = FieldConfig::loadByName($this->entityType, $this->bundle, $this->fieldName);
|
||||
$this->assertConfigEntityImport($field);
|
||||
|
||||
// Once the default value has been removed after saving the dependency
|
||||
// should be removed.
|
||||
$field = FieldConfig::loadByName($this->entityType, $this->bundle, $this->fieldName);
|
||||
$field->save();
|
||||
$dependencies = $field->getDependencies();
|
||||
$this->assertFalse(isset($dependencies[$key]) && in_array($referenced_entities[0]->getConfigDependencyName(), $dependencies[$key]), SafeMarkup::format('@type dependency @name does not exist.', ['@type' => $key, '@name' => $referenced_entities[0]->getConfigDependencyName()]));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the reference field values are correct.
|
||||
*
|
||||
* @param string $entity_name
|
||||
* The name of the test entity.
|
||||
* @param \Drupal\Core\Entity\EntityInterface[] $referenced_entities
|
||||
* An array of referenced entities.
|
||||
*/
|
||||
protected function assertFieldValues($entity_name, $referenced_entities) {
|
||||
$entity = current(entity_load_multiple_by_properties($this->entityType, array('name' => $entity_name)));
|
||||
|
||||
$this->assertTrue($entity, format_string('%entity_type: Entity found in the database.', array('%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());
|
||||
$this->assertEqual($entity->{$this->fieldName}->entity->label(), $referenced_entities[0]->label());
|
||||
|
||||
$this->assertEqual($entity->{$this->fieldName}[1]->target_id, $referenced_entities[1]->id());
|
||||
$this->assertEqual($entity->{$this->fieldName}[1]->entity->id(), $referenced_entities[1]->id());
|
||||
$this->assertEqual($entity->{$this->fieldName}[1]->entity->label(), $referenced_entities[1]->label());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates two content and two config test entities.
|
||||
*
|
||||
* @return array
|
||||
* 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->save();
|
||||
$config_entity_2 = entity_create('config_test', array('id' => $this->randomMachineName(), 'label' => $this->randomMachineName()));
|
||||
$config_entity_2->save();
|
||||
|
||||
$content_entity_1 = EntityTest::create(array('name' => $this->randomMachineName()));
|
||||
$content_entity_1->save();
|
||||
$content_entity_2 = EntityTest::create(array('name' => $this->randomMachineName()));
|
||||
$content_entity_2->save();
|
||||
|
||||
return array(
|
||||
'config' => array(
|
||||
$config_entity_1,
|
||||
$config_entity_2,
|
||||
),
|
||||
'content' => array(
|
||||
$content_entity_1,
|
||||
$content_entity_2,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\field\Tests\EntityReference;
|
||||
|
||||
use Drupal\Core\Entity\Entity\EntityFormDisplay;
|
||||
use Drupal\Core\Entity\Entity\EntityViewDisplay;
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
|
||||
/**
|
||||
* Tests possible XSS security issues in entity references.
|
||||
*
|
||||
* @group entity_reference
|
||||
*/
|
||||
class EntityReferenceXSSTest extends WebTestBase {
|
||||
|
||||
use EntityReferenceTestTrait;
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $modules = ['node'];
|
||||
|
||||
/**
|
||||
* Tests markup is escaped in the entity reference select and label formatter.
|
||||
*/
|
||||
public function testEntityReferenceXSS() {
|
||||
$this->drupalCreateContentType(['type' => 'article']);
|
||||
|
||||
// Create a node with markup in the title.
|
||||
$node_type_one = $this->drupalCreateContentType();
|
||||
$node = [
|
||||
'type' => $node_type_one->id(),
|
||||
'title' => '<em>I am kitten</em>',
|
||||
];
|
||||
$referenced_node = $this->drupalCreateNode($node);
|
||||
|
||||
$node_type_two = $this->drupalCreateContentType(['name' => '<em>bundle with markup</em>']);
|
||||
$this->drupalCreateNode([
|
||||
'type' => $node_type_two->id(),
|
||||
'title' => 'My bundle has markup',
|
||||
]);
|
||||
|
||||
$this->createEntityReferenceField('node', 'article', 'entity_reference_test', 'Entity Reference test', 'node', 'default', ['target_bundles' => [$node_type_one->id(), $node_type_two->id()]]);
|
||||
|
||||
EntityFormDisplay::load('node.article.default')
|
||||
->setComponent('entity_reference_test', ['type' => 'options_select'])
|
||||
->save();
|
||||
EntityViewDisplay::load('node.article.default')
|
||||
->setComponent('entity_reference_test', ['type' => 'entity_reference_label'])
|
||||
->save();
|
||||
|
||||
// Create a node and reference the node with markup in the title.
|
||||
$this->drupalLogin($this->rootUser);
|
||||
$this->drupalGet('node/add/article');
|
||||
$this->assertEscaped($referenced_node->getTitle());
|
||||
$this->assertEscaped($node_type_two->label());
|
||||
|
||||
$edit = [
|
||||
'title[0][value]' => $this->randomString(),
|
||||
'entity_reference_test' => $referenced_node->id()
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, 'Save and publish');
|
||||
$this->assertEscaped($referenced_node->getTitle());
|
||||
|
||||
// Test the options_buttons type.
|
||||
EntityFormDisplay::load('node.article.default')
|
||||
->setComponent('entity_reference_test', ['type' => 'options_buttons'])
|
||||
->save();
|
||||
$this->drupalGet('node/add/article');
|
||||
$this->assertEscaped($referenced_node->getTitle());
|
||||
// options_buttons does not support optgroups.
|
||||
$this->assertNoText('bundle with markup');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,145 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\field\Tests\EntityReference\Views;
|
||||
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
use Drupal\views\Views;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
|
||||
/**
|
||||
* Tests entity reference selection handler.
|
||||
*
|
||||
* @group entity_reference
|
||||
*/
|
||||
class SelectionTest extends WebTestBase {
|
||||
|
||||
public static $modules = ['node', 'views', 'entity_reference_test', 'entity_test'];
|
||||
|
||||
/**
|
||||
* Nodes for testing.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $nodes = array();
|
||||
|
||||
/**
|
||||
* The entity reference field to test.
|
||||
*
|
||||
* @var \Drupal\Core\Field\FieldDefinitionInterface
|
||||
*/
|
||||
protected $field;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Create nodes.
|
||||
$type = $this->drupalCreateContentType()->id();
|
||||
$node1 = $this->drupalCreateNode(array('type' => $type));
|
||||
$node2 = $this->drupalCreateNode(array('type' => $type));
|
||||
$node3 = $this->drupalCreateNode();
|
||||
|
||||
foreach (array($node1, $node2, $node3) as $node) {
|
||||
$this->nodes[$node->getType()][$node->id()] = $node->label();
|
||||
}
|
||||
|
||||
// Create a field.
|
||||
$field_storage = FieldStorageConfig::create(array(
|
||||
'field_name' => 'test_field',
|
||||
'entity_type' => 'entity_test',
|
||||
'translatable' => FALSE,
|
||||
'settings' => array(
|
||||
'target_type' => 'node',
|
||||
),
|
||||
'type' => 'entity_reference',
|
||||
'cardinality' => '1',
|
||||
));
|
||||
$field_storage->save();
|
||||
$field = FieldConfig::create([
|
||||
'field_storage' => $field_storage,
|
||||
'bundle' => 'test_bundle',
|
||||
'settings' => array(
|
||||
'handler' => 'views',
|
||||
'handler_settings' => array(
|
||||
'view' => array(
|
||||
'view_name' => 'test_entity_reference',
|
||||
'display_name' => 'entity_reference_1',
|
||||
'arguments' => array(),
|
||||
),
|
||||
),
|
||||
),
|
||||
]);
|
||||
$field->save();
|
||||
$this->field = $field;
|
||||
}
|
||||
|
||||
/**
|
||||
* Confirm the expected results are returned.
|
||||
*
|
||||
* @param array $result
|
||||
* Query results keyed by node type and nid.
|
||||
*/
|
||||
protected function assertResults(array $result) {
|
||||
$success = FALSE;
|
||||
foreach ($result as $node_type => $values) {
|
||||
foreach ($values as $nid => $label) {
|
||||
if (!$success = $this->nodes[$node_type][$nid] == trim(strip_tags($label))) {
|
||||
// There was some error, so break.
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->assertTrue($success, 'Views selection handler returned expected values.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the selection handler.
|
||||
*/
|
||||
public function testSelectionHandler() {
|
||||
// Get values from selection handler.
|
||||
$handler = $this->container->get('plugin.manager.entity_reference_selection')->getSelectionHandler($this->field);
|
||||
$result = $handler->getReferenceableEntities();
|
||||
$this->assertResults($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the selection handler with a relationship.
|
||||
*/
|
||||
public function testSelectionHandlerRelationship() {
|
||||
// Add a relationship to the view.
|
||||
$view = Views::getView('test_entity_reference');
|
||||
$view->setDisplay();
|
||||
$view->displayHandlers->get('default')->setOption('relationships', array(
|
||||
'test_relationship' => array(
|
||||
'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(
|
||||
'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');
|
||||
$query_options['options']['distinct'] = TRUE;
|
||||
$view->display_handler->setOption('query', $query_options);
|
||||
$view->save();
|
||||
|
||||
// Get values from the selection handler.
|
||||
$handler = $this->container->get('plugin.manager.entity_reference_selection')->getSelectionHandler($this->field);
|
||||
$result = $handler->getReferenceableEntities();
|
||||
$this->assertResults($result);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,92 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\field\Tests;
|
||||
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
|
||||
/**
|
||||
* Tests Field access.
|
||||
*
|
||||
* @group field
|
||||
*/
|
||||
class FieldAccessTest extends FieldTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('node', 'field_test');
|
||||
|
||||
/**
|
||||
* Node entity to use in this test.
|
||||
*
|
||||
* @var \Drupal\node\Entity\Node
|
||||
*/
|
||||
protected $node;
|
||||
|
||||
/**
|
||||
* Field value to test display on nodes.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $testViewFieldValue;
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$web_user = $this->drupalCreateUser(array('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_name' => 'test_view_field',
|
||||
'entity_type' => 'node',
|
||||
'type' => 'text',
|
||||
);
|
||||
FieldStorageConfig::create($field_storage)->save();
|
||||
$field = array(
|
||||
'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) {
|
||||
entity_get_display('node', $content_type, $view_mode)
|
||||
->setComponent($field_storage['field_name'])
|
||||
->save();
|
||||
}
|
||||
|
||||
// Create test node.
|
||||
$this->testViewFieldValue = 'This is some text';
|
||||
$settings = array();
|
||||
$settings['type'] = $content_type;
|
||||
$settings['title'] = 'Field view access test';
|
||||
$settings['test_view_field'] = array(array('value' => $this->testViewFieldValue));
|
||||
$this->node = $this->drupalCreateNode($settings);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that hook_entity_field_access() is called.
|
||||
*/
|
||||
function testFieldAccess() {
|
||||
|
||||
// Assert the text is visible.
|
||||
$this->drupalGet('node/' . $this->node->id());
|
||||
$this->assertText($this->testViewFieldValue);
|
||||
|
||||
// Assert the text is not visible for anonymous users.
|
||||
// The field_test module implements hook_entity_field_access() which will
|
||||
// specifically target the 'test_view_field' field.
|
||||
$this->drupalLogout();
|
||||
$this->drupalGet('node/' . $this->node->id());
|
||||
$this->assertNoText($this->testViewFieldValue);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\field\Tests;
|
||||
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
|
||||
/**
|
||||
* Tests help display for the Field module.
|
||||
*
|
||||
* @group field
|
||||
*/
|
||||
class FieldHelpTest extends WebTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array.
|
||||
*/
|
||||
public static $modules = array('field', 'help');
|
||||
|
||||
// Tests field help implementation without optional core modules enabled.
|
||||
protected $profile = 'minimal';
|
||||
|
||||
/**
|
||||
* The admin user that will be created.
|
||||
*/
|
||||
protected $adminUser;
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Create the admin user.
|
||||
$this->adminUser = $this->drupalCreateUser(array('access administration pages', 'view the administration theme'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the Field module's help page.
|
||||
*/
|
||||
public function testFieldHelp() {
|
||||
// Log in the admin user.
|
||||
$this->drupalLogin($this->adminUser);
|
||||
|
||||
// Visit the Help page and make sure no warnings or notices are thrown.
|
||||
$this->drupalGet('admin/help/field');
|
||||
|
||||
// Enable the Options, Email and Field API Test modules.
|
||||
\Drupal::service('module_installer')->install(array('options', 'field_test'));
|
||||
$this->resetAll();
|
||||
\Drupal::service('plugin.manager.field.widget')->clearCachedDefinitions();
|
||||
\Drupal::service('plugin.manager.field.field_type')->clearCachedDefinitions();
|
||||
|
||||
$this->drupalGet('admin/help/field');
|
||||
$this->assertLink('Options', 0, 'Options module is listed on the Field help page.');
|
||||
$this->assertText('Field API Test', 'Modules with field types that do not implement hook_help are listed.');
|
||||
$this->assertNoLink('Field API Test', 'Modules with field types that do not implement hook_help are not linked.');
|
||||
$this->assertNoLink('Link', 'Modules that have not been installed, are not listed.');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -36,7 +36,7 @@ abstract class FieldTestBase extends WebTestBase {
|
||||
*
|
||||
* This function only checks a single column in the field values.
|
||||
*
|
||||
* @param EntityInterface $entity
|
||||
* @param \Drupal\Core\Entity\EntityInterface $entity
|
||||
* The entity to test.
|
||||
* @param $field_name
|
||||
* The name of the field to test
|
||||
|
||||
@@ -1,204 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\field\Tests;
|
||||
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\simpletest\KernelTestBase;
|
||||
|
||||
/**
|
||||
* Parent class for Field API unit tests.
|
||||
*
|
||||
* @deprecated in Drupal 8.1.x, will be removed before Drupal 8.2.x. Use
|
||||
* \Drupal\Tests\field\Kernel\FieldKernelTestBase instead.
|
||||
*/
|
||||
abstract class FieldUnitTestBase extends KernelTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['user', 'system', 'field', 'text', 'entity_test', 'field_test'];
|
||||
|
||||
/**
|
||||
* Bag of created field storages and fields.
|
||||
*
|
||||
* Allows easy access to test field storage/field names/IDs/objects via:
|
||||
* - $this->fieldTestData->field_name[suffix]
|
||||
* - $this->fieldTestData->field_storage[suffix]
|
||||
* - $this->fieldTestData->field_storage_uuid[suffix]
|
||||
* - $this->fieldTestData->field[suffix]
|
||||
* - $this->fieldTestData->field_definition[suffix]
|
||||
*
|
||||
* @see \Drupal\field\Tests\FieldUnitTestBase::createFieldWithStorage()
|
||||
*
|
||||
* @var \ArrayObject
|
||||
*/
|
||||
protected $fieldTestData;
|
||||
|
||||
/**
|
||||
* Set the default field storage backend for fields created during tests.
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->fieldTestData = new \ArrayObject(array(), \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'));
|
||||
|
||||
// Create user 1.
|
||||
$storage = \Drupal::entityManager()->getStorage('user');
|
||||
$storage
|
||||
->create(array(
|
||||
'uid' => 1,
|
||||
'name' => 'entity-test',
|
||||
'mail' => 'entity@localhost',
|
||||
'status' => TRUE,
|
||||
))
|
||||
->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a field and an associated field storage.
|
||||
*
|
||||
* @param string $suffix
|
||||
* (optional) A string that should only contain characters that are valid in
|
||||
* PHP variable names as well.
|
||||
* @param string $entity_type
|
||||
* (optional) The entity type on which the field should be created.
|
||||
* Defaults to "entity_test".
|
||||
* @param string $bundle
|
||||
* (optional) The entity type on which the field should be created.
|
||||
* Defaults to the default bundle of the entity type.
|
||||
*/
|
||||
protected function createFieldWithStorage($suffix = '', $entity_type = 'entity_test', $bundle = NULL) {
|
||||
if (empty($bundle)) {
|
||||
$bundle = $entity_type;
|
||||
}
|
||||
$field_name = 'field_name' . $suffix;
|
||||
$field_storage = 'field_storage' . $suffix;
|
||||
$field_storage_uuid = 'field_storage_uuid' . $suffix;
|
||||
$field = 'field' . $suffix;
|
||||
$field_definition = 'field_definition' . $suffix;
|
||||
|
||||
$this->fieldTestData->$field_name = Unicode::strtolower($this->randomMachineName() . '_field_name' . $suffix);
|
||||
$this->fieldTestData->$field_storage = FieldStorageConfig::create(array(
|
||||
'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(
|
||||
'field_storage' => $this->fieldTestData->$field_storage,
|
||||
'bundle' => $bundle,
|
||||
'label' => $this->randomMachineName() . '_label',
|
||||
'description' => $this->randomMachineName() . '_description',
|
||||
'settings' => array(
|
||||
'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(
|
||||
'type' => 'test_field_widget',
|
||||
'settings' => array(
|
||||
'test_widget_setting' => $this->randomMachineName(),
|
||||
)
|
||||
))
|
||||
->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves and reloads an entity.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\EntityInterface $entity
|
||||
* The entity to save.
|
||||
*
|
||||
* @return \Drupal\Core\Entity\EntityInterface
|
||||
* The entity, freshly reloaded from storage.
|
||||
*/
|
||||
protected function entitySaveReload(EntityInterface $entity) {
|
||||
$entity->save();
|
||||
$controller = $this->container->get('entity.manager')->getStorage($entity->getEntityTypeId());
|
||||
$controller->resetCache();
|
||||
return $controller->load($entity->id());
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate and save entity. Fail if violations are found.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\EntityInterface $entity
|
||||
* The entity to save.
|
||||
*/
|
||||
protected function entityValidateAndSave(EntityInterface $entity) {
|
||||
$violations = $entity->validate();
|
||||
if ($violations->count()) {
|
||||
$this->fail($violations);
|
||||
}
|
||||
else {
|
||||
$entity->save();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate random values for a field_test field.
|
||||
*
|
||||
* @param $cardinality
|
||||
* Number of values to generate.
|
||||
* @return
|
||||
* An array of random values, in the format expected for field values.
|
||||
*/
|
||||
protected function _generateTestFieldValues($cardinality) {
|
||||
$values = array();
|
||||
for ($i = 0; $i < $cardinality; $i++) {
|
||||
// field_test fields treat 0 as 'empty value'.
|
||||
$values[$i]['value'] = mt_rand(1, 127);
|
||||
}
|
||||
return $values;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that a field has the expected values in an entity.
|
||||
*
|
||||
* This function only checks a single column in the field values.
|
||||
*
|
||||
* @param EntityInterface $entity
|
||||
* The entity to test.
|
||||
* @param $field_name
|
||||
* The name of the field to test
|
||||
* @param $expected_values
|
||||
* The array of expected values.
|
||||
* @param $langcode
|
||||
* (Optional) The language code for the values. Defaults to
|
||||
* \Drupal\Core\Language\LanguageInterface::LANGCODE_NOT_SPECIFIED.
|
||||
* @param $column
|
||||
* (Optional) The name of the column to check. Defaults to 'value'.
|
||||
*/
|
||||
protected function assertFieldValues(EntityInterface $entity, $field_name, $expected_values, $langcode = LanguageInterface::LANGCODE_NOT_SPECIFIED, $column = 'value') {
|
||||
// Re-load the entity to make sure we have the latest changes.
|
||||
\Drupal::entityManager()->getStorage($entity->getEntityTypeId())->resetCache(array($entity->id()));
|
||||
$e = entity_load($entity->getEntityTypeId(), $entity->id());
|
||||
$field = $values = $e->getTranslation($langcode)->$field_name;
|
||||
// Filter out empty values so that they don't mess with the assertions.
|
||||
$field->filterEmptyItems();
|
||||
$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)));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,134 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\field\Tests;
|
||||
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
|
||||
/**
|
||||
* Tests multilanguage fields logic that require a full environment.
|
||||
*
|
||||
* @group field
|
||||
*/
|
||||
class TranslationWebTest extends FieldTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('language', 'field_test', 'entity_test');
|
||||
|
||||
/**
|
||||
* The name of the field to use in this test.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $fieldName;
|
||||
|
||||
/**
|
||||
* The name of the entity type to use in this test.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $entityTypeId = 'entity_test_mulrev';
|
||||
|
||||
/**
|
||||
* The field storage to use in this test.
|
||||
*
|
||||
* @var \Drupal\field\Entity\FieldStorageConfig
|
||||
*/
|
||||
protected $fieldStorage;
|
||||
|
||||
/**
|
||||
* The field to use in this test.
|
||||
*
|
||||
* @var \Drupal\field\Entity\FieldConfig
|
||||
*/
|
||||
protected $field;
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->fieldName = Unicode::strtolower($this->randomMachineName() . '_field_name');
|
||||
|
||||
$field_storage = array(
|
||||
'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_storage' => $this->fieldStorage,
|
||||
'bundle' => $this->entityTypeId,
|
||||
);
|
||||
FieldConfig::create($field)->save();
|
||||
$this->field = FieldConfig::load($this->entityTypeId . '.' . $field['bundle'] . '.' . $this->fieldName);
|
||||
|
||||
entity_get_form_display($this->entityTypeId, $this->entityTypeId, 'default')
|
||||
->setComponent($this->fieldName)
|
||||
->save();
|
||||
|
||||
for ($i = 0; $i < 3; ++$i) {
|
||||
ConfigurableLanguage::create(array(
|
||||
'id' => 'l' . $i,
|
||||
'label' => $this->randomString(),
|
||||
))->save();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests field translations when creating a new revision.
|
||||
*/
|
||||
function testFieldFormTranslationRevisions() {
|
||||
$web_user = $this->drupalCreateUser(array('view test entity', 'administer entity_test content'));
|
||||
$this->drupalLogin($web_user);
|
||||
|
||||
// Prepare the field translations.
|
||||
field_test_entity_info_translatable($this->entityTypeId, TRUE);
|
||||
$entity = $this->container->get('entity_type.manager')
|
||||
->getStorage($this->entityTypeId)
|
||||
->create();
|
||||
$available_langcodes = array_flip(array_keys($this->container->get('language_manager')->getLanguages()));
|
||||
$field_name = $this->fieldStorage->getName();
|
||||
|
||||
// Store the field translations.
|
||||
ksort($available_langcodes);
|
||||
$entity->langcode->value = key($available_langcodes);
|
||||
foreach ($available_langcodes as $langcode => $value) {
|
||||
$translation = $entity->hasTranslation($langcode) ? $entity->getTranslation($langcode) : $entity->addTranslation($langcode);
|
||||
$translation->{$field_name}->value = $value + 1;
|
||||
}
|
||||
$entity->save();
|
||||
|
||||
// Create a new revision.
|
||||
$edit = array(
|
||||
"{$field_name}[0][value]" => $entity->{$field_name}->value,
|
||||
'revision' => TRUE,
|
||||
);
|
||||
$this->drupalPostForm($this->entityTypeId . '/manage/' . $entity->id() . '/edit', $edit, t('Save'));
|
||||
|
||||
// Check translation revisions.
|
||||
$this->checkTranslationRevisions($entity->id(), $entity->getRevisionId(), $available_langcodes);
|
||||
$this->checkTranslationRevisions($entity->id(), $entity->getRevisionId() + 1, $available_langcodes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the field translation attached to the entity revision identified
|
||||
* by the passed arguments were correctly stored.
|
||||
*/
|
||||
private function checkTranslationRevisions($id, $revision_id, $available_langcodes) {
|
||||
$field_name = $this->fieldStorage->getName();
|
||||
$entity = entity_revision_load($this->entityTypeId, $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())));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\field\Tests\Update;
|
||||
|
||||
use Drupal\system\Tests\Update\UpdatePathTestBase;
|
||||
|
||||
/**
|
||||
* Tests the update for the 'size' setting of the 'email_default' field widget.
|
||||
*
|
||||
* @group field
|
||||
*/
|
||||
class EmailWidgetSizeSettingUpdateTest extends UpdatePathTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setDatabaseDumpFiles() {
|
||||
$this->databaseDumpFiles = [
|
||||
__DIR__ . '/../../../../system/tests/fixtures/update/drupal-8.bare.standard.php.gz',
|
||||
__DIR__ . '/../../../tests/fixtures/update/drupal-8.email_widget_size_setting-2578741.php',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests field_post_update_email_widget_size_setting().
|
||||
*
|
||||
* @see field_post_update_email_widget_size_setting()
|
||||
*/
|
||||
public function testFieldPostUpdateEmailWidgetSizeSetting() {
|
||||
$configFactory = $this->container->get('config.factory');
|
||||
|
||||
// Load the 'node.article.default' entity form display and check that the
|
||||
// widget for 'field_email_2578741' does not have a 'size' setting.
|
||||
/** @var \Drupal\Core\Config\Config $config */
|
||||
$config = $configFactory->get('core.entity_form_display.node.article.default');
|
||||
$settings = $config->get('content.field_email_2578741.settings');
|
||||
$this->assertTrue(!isset($settings['size']), 'The size setting does not exist prior to running the update functions.');
|
||||
|
||||
// Run updates.
|
||||
$this->runUpdates();
|
||||
|
||||
// Reload the config and check that the 'size' setting has been populated.
|
||||
$config = $configFactory->get('core.entity_form_display.node.article.default');
|
||||
$settings = $config->get('content.field_email_2578741.settings');
|
||||
$this->assertEqual($settings['size'], 60, 'The size setting exists and it has the correct default value.');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\field\Tests\Update;
|
||||
|
||||
use Drupal\system\Tests\Update\UpdatePathTestBase;
|
||||
|
||||
/**
|
||||
* Tests the update for the entity reference 'handler' setting.
|
||||
*
|
||||
* @group field
|
||||
*/
|
||||
class EntityReferenceHandlerSettingUpdateTest extends UpdatePathTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setDatabaseDumpFiles() {
|
||||
$this->databaseDumpFiles = [
|
||||
__DIR__ . '/../../../../system/tests/fixtures/update/drupal-8.bare.standard.php.gz',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests field_post_update_entity_reference_handler_setting().
|
||||
*
|
||||
* @see field_post_update_entity_reference_handler_setting()
|
||||
*/
|
||||
public function testFieldPostUpdateERHandlerSetting() {
|
||||
$configFactory = $this->container->get('config.factory');
|
||||
|
||||
// Load the 'node.article.field_image' field config, and check that its
|
||||
// 'handler' setting is wrong.
|
||||
/** @var \Drupal\Core\Config\Config */
|
||||
$config = $configFactory->get('field.field.node.article.field_image');
|
||||
$settings = $config->get('settings');
|
||||
$this->assertEqual($settings['handler'], 'default:node');
|
||||
|
||||
// Run updates.
|
||||
$this->runUpdates();
|
||||
|
||||
// Reload the config, and check that the 'handler' setting has been fixed.
|
||||
$config = $configFactory->get('field.field.node.article.field_image');
|
||||
$settings = $config->get('settings');
|
||||
$this->assertEqual($settings['handler'], 'default:file');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,144 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\field\Tests\Update;
|
||||
|
||||
use Drupal\Core\Config\Config;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\node\Entity\Node;
|
||||
use Drupal\system\Tests\Update\UpdatePathTestBase;
|
||||
|
||||
/**
|
||||
* Tests that field settings are properly updated during database updates.
|
||||
*
|
||||
* @group field
|
||||
*/
|
||||
class FieldUpdateTest extends UpdatePathTestBase {
|
||||
|
||||
/**
|
||||
* The config factory service.
|
||||
*
|
||||
* @var \Drupal\Core\Config\ConfigFactoryInterface
|
||||
*/
|
||||
protected $configFactory;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->configFactory = $this->container->get('config.factory');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setDatabaseDumpFiles() {
|
||||
$this->databaseDumpFiles = [
|
||||
__DIR__ . '/../../../../system/tests/fixtures/update/drupal-8.bare.standard.php.gz',
|
||||
__DIR__ . '/../../../tests/fixtures/update/drupal-8.views_entity_reference_plugins-2429191.php',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests field_update_8001().
|
||||
*
|
||||
* @see field_update_8001()
|
||||
*/
|
||||
public function testFieldUpdate8001() {
|
||||
// Load the 'node.field_image' field storage config, and check that is has
|
||||
// a 'target_bundle' setting.
|
||||
$config = $this->configFactory->get('field.storage.node.field_image');
|
||||
$settings = $config->get('settings');
|
||||
$this->assertTrue(array_key_exists('target_bundle', $settings));
|
||||
|
||||
// Run updates.
|
||||
$this->runUpdates();
|
||||
|
||||
// Reload the config, and check that the 'target_bundle' setting has been
|
||||
// removed.
|
||||
$config = $this->configFactory->get('field.storage.node.field_image');
|
||||
$settings = $config->get('settings');
|
||||
$this->assertFalse(array_key_exists('target_bundle', $settings));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests field_update_8002().
|
||||
*
|
||||
* @see field_update_8002()
|
||||
*/
|
||||
public function testFieldUpdate8002() {
|
||||
// Check that 'entity_reference' is the provider and a dependency of the
|
||||
// test field storage .
|
||||
$field_storage = $this->configFactory->get('field.storage.node.field_ref_views_select_2429191');
|
||||
$this->assertIdentical($field_storage->get('module'), 'entity_reference');
|
||||
$this->assertEntityRefDependency($field_storage, TRUE);
|
||||
|
||||
// Check that 'entity_reference' is a dependency of the test field.
|
||||
$field = $this->configFactory->get('field.field.node.article.field_ref_views_select_2429191');
|
||||
$this->assertEntityRefDependency($field, TRUE);
|
||||
|
||||
// Check that 'entity_reference' is a dependency of the test view.
|
||||
$view = $this->configFactory->get('views.view.entity_reference_plugins_2429191');
|
||||
$this->assertEntityRefDependency($view, TRUE);
|
||||
|
||||
// Run updates.
|
||||
$this->runUpdates();
|
||||
|
||||
// Check that 'entity_reference' is no longer a dependency of the test field
|
||||
// and view.
|
||||
$field_storage = $this->configFactory->get('field.storage.node.field_ref_views_select_2429191');
|
||||
$this->assertIdentical($field_storage->get('module'), 'core');
|
||||
$this->assertEntityRefDependency($field_storage, FALSE);
|
||||
$field = $this->configFactory->get('field.field.node.article.field_ref_views_select_2429191');
|
||||
$this->assertEntityRefDependency($field, FALSE);
|
||||
$view = $this->configFactory->get('views.view.entity_reference_plugins_2429191');
|
||||
$this->assertEntityRefDependency($view, FALSE);
|
||||
|
||||
// Check that field selection, based on the view, still works. It only
|
||||
// selects nodes whose title contains 'foo'.
|
||||
$node_1 = Node::create(['type' => 'article', 'title' => 'foobar']);
|
||||
$node_1->save();
|
||||
$node_2 = Node::create(['type' => 'article', 'title' => 'barbaz']);
|
||||
$node_2->save();
|
||||
$field = FieldConfig::load('node.article.field_ref_views_select_2429191');
|
||||
$selection = \Drupal::service('plugin.manager.entity_reference_selection')->getSelectionHandler($field);
|
||||
$referencable = $selection->getReferenceableEntities();
|
||||
$this->assertEqual(array_keys($referencable['article']), [$node_1->id()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests field_update_8003().
|
||||
*
|
||||
* @see field_update_8003()
|
||||
*/
|
||||
public function testFieldUpdate8003() {
|
||||
// Run updates.
|
||||
$this->runUpdates();
|
||||
|
||||
// Check that the new 'auto_create_bundle' setting is populated correctly.
|
||||
$field = $this->configFactory->get('field.field.node.article.field_ref_autocreate_2412569');
|
||||
$handler_settings = $field->get('settings.handler_settings');
|
||||
|
||||
$expected_target_bundles = ['tags' => 'tags', 'test' => 'test'];
|
||||
$this->assertEqual($handler_settings['target_bundles'], $expected_target_bundles);
|
||||
|
||||
$this->assertTrue($handler_settings['auto_create']);
|
||||
$this->assertEqual($handler_settings['auto_create_bundle'], 'tags');
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that a config depends on 'entity_reference' or not
|
||||
*
|
||||
* @param \Drupal\Core\Config\Config $config
|
||||
* The config to test.
|
||||
* @param bool $present
|
||||
* TRUE to test that entity_reference is present, FALSE to test that it is
|
||||
* absent.
|
||||
*/
|
||||
protected function assertEntityRefDependency(Config $config, $present) {
|
||||
$dependencies = $config->get('dependencies');
|
||||
$dependencies += ['module' => []];
|
||||
$this->assertEqual(in_array('entity_reference', $dependencies['module']), $present);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,8 +7,8 @@ package: Testing
|
||||
dependencies:
|
||||
- text
|
||||
|
||||
# Information added by Drupal.org packaging script on 2017-11-03
|
||||
version: '8.4.2'
|
||||
# Information added by Drupal.org packaging script on 2018-01-03
|
||||
version: '8.4.4'
|
||||
core: '8.x'
|
||||
project: 'drupal'
|
||||
datestamp: 1509719929
|
||||
datestamp: 1515021228
|
||||
|
||||
@@ -7,8 +7,8 @@ package: Testing
|
||||
dependencies:
|
||||
- entity_test
|
||||
|
||||
# Information added by Drupal.org packaging script on 2017-11-03
|
||||
version: '8.4.2'
|
||||
# Information added by Drupal.org packaging script on 2018-01-03
|
||||
version: '8.4.4'
|
||||
core: '8.x'
|
||||
project: 'drupal'
|
||||
datestamp: 1509719929
|
||||
datestamp: 1515021228
|
||||
|
||||
+3
-3
@@ -7,8 +7,8 @@ package: Testing
|
||||
dependencies:
|
||||
- field
|
||||
|
||||
# Information added by Drupal.org packaging script on 2017-11-03
|
||||
version: '8.4.2'
|
||||
# Information added by Drupal.org packaging script on 2018-01-03
|
||||
version: '8.4.4'
|
||||
core: '8.x'
|
||||
project: 'drupal'
|
||||
datestamp: 1509719929
|
||||
datestamp: 1515021228
|
||||
|
||||
@@ -5,8 +5,8 @@ description: 'Support module for the Field API configuration tests.'
|
||||
package: Testing
|
||||
# version: VERSION
|
||||
|
||||
# Information added by Drupal.org packaging script on 2017-11-03
|
||||
version: '8.4.2'
|
||||
# Information added by Drupal.org packaging script on 2018-01-03
|
||||
version: '8.4.4'
|
||||
core: '8.x'
|
||||
project: 'drupal'
|
||||
datestamp: 1509719929
|
||||
datestamp: 1515021228
|
||||
|
||||
@@ -7,8 +7,8 @@ package: Testing
|
||||
dependencies:
|
||||
- views
|
||||
|
||||
# Information added by Drupal.org packaging script on 2017-11-03
|
||||
version: '8.4.2'
|
||||
# Information added by Drupal.org packaging script on 2018-01-03
|
||||
version: '8.4.4'
|
||||
core: '8.x'
|
||||
project: 'drupal'
|
||||
datestamp: 1509719929
|
||||
datestamp: 1515021228
|
||||
|
||||
+3
-3
@@ -8,8 +8,8 @@ dependencies:
|
||||
- entity_test
|
||||
- field_test
|
||||
|
||||
# Information added by Drupal.org packaging script on 2017-11-03
|
||||
version: '8.4.2'
|
||||
# Information added by Drupal.org packaging script on 2018-01-03
|
||||
version: '8.4.4'
|
||||
core: '8.x'
|
||||
project: 'drupal'
|
||||
datestamp: 1509719929
|
||||
datestamp: 1515021228
|
||||
|
||||
+3
-2
@@ -197,9 +197,10 @@ class EntityReferenceIntegrationTest extends BrowserTestBase {
|
||||
* An array of entity objects.
|
||||
*/
|
||||
protected function getTestEntities() {
|
||||
$config_entity_1 = entity_create('config_test', ['id' => $this->randomMachineName(), 'label' => $this->randomMachineName()]);
|
||||
$storage = \Drupal::entityTypeManager()->getStorage('config_test');
|
||||
$config_entity_1 = $storage->create(['id' => $this->randomMachineName(), 'label' => $this->randomMachineName()]);
|
||||
$config_entity_1->save();
|
||||
$config_entity_2 = entity_create('config_test', ['id' => $this->randomMachineName(), 'label' => $this->randomMachineName()]);
|
||||
$config_entity_2 = $storage->create(['id' => $this->randomMachineName(), 'label' => $this->randomMachineName()]);
|
||||
$config_entity_2->save();
|
||||
|
||||
$content_entity_1 = EntityTest::create(['name' => $this->randomMachineName()]);
|
||||
|
||||
@@ -33,7 +33,7 @@ abstract class FieldTestBase extends BrowserTestBase {
|
||||
*
|
||||
* This function only checks a single column in the field values.
|
||||
*
|
||||
* @param EntityInterface $entity
|
||||
* @param \Drupal\Core\Entity\EntityInterface $entity
|
||||
* The entity to test.
|
||||
* @param $field_name
|
||||
* The name of the field to test
|
||||
|
||||
+70
-10
@@ -3,11 +3,14 @@
|
||||
namespace Drupal\Tests\field\Kernel\EntityReference;
|
||||
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||
use Drupal\Core\Logger\RfcLogLevel;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait;
|
||||
use Drupal\node\Entity\NodeType;
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
use Drupal\taxonomy\Entity\Vocabulary;
|
||||
use Symfony\Component\Debug\BufferingLogger;
|
||||
|
||||
/**
|
||||
* Tests entity reference field settings.
|
||||
@@ -44,6 +47,13 @@ class EntityReferenceSettingsTest extends KernelTestBase {
|
||||
*/
|
||||
protected $customBundle;
|
||||
|
||||
/**
|
||||
* The service name for a logger implementation that collects anything logged.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $testLogServiceName = 'entity_reference_settings_test.logger';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@@ -60,26 +70,38 @@ class EntityReferenceSettingsTest extends KernelTestBase {
|
||||
]);
|
||||
$this->nodeType->save();
|
||||
|
||||
$this->vocabulary = Vocabulary::create([
|
||||
'vid' => Unicode::strtolower($this->randomMachineName()),
|
||||
'name' => $this->randomString(),
|
||||
]);
|
||||
$this->vocabulary->save();
|
||||
|
||||
// Create a custom bundle.
|
||||
$this->customBundle = 'test_bundle_' . Unicode::strtolower($this->randomMachineName());
|
||||
entity_test_create_bundle($this->customBundle, NULL, 'entity_test');
|
||||
|
||||
// Prepare the logger for collecting the expected critical error.
|
||||
$this->container->get($this->testLogServiceName)->cleanLogs();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that config bundle deletions are mirrored in field config settings.
|
||||
*/
|
||||
public function testConfigTargetBundleDeletion() {
|
||||
// Create two vocabularies.
|
||||
/** @var \Drupal\taxonomy\Entity\Vocabulary[] $vocabularies */
|
||||
$vocabularies = [];
|
||||
for ($i = 0; $i < 2; $i++) {
|
||||
$vid = Unicode::strtolower($this->randomMachineName());
|
||||
$vocabularies[$i] = Vocabulary::create([
|
||||
'name' => $this->randomString(),
|
||||
'vid' => $vid,
|
||||
]);
|
||||
$vocabularies[$i]->save();
|
||||
}
|
||||
// Attach an entity reference field to $this->nodeType.
|
||||
$name = Unicode::strtolower($this->randomMachineName());
|
||||
$label = $this->randomString();
|
||||
$vid = $this->vocabulary->id();
|
||||
$handler_settings = ['target_bundles' => [$vid => $vid]];
|
||||
$handler_settings = [
|
||||
'target_bundles' => [
|
||||
$vocabularies[0]->id() => $vocabularies[0]->id(),
|
||||
$vocabularies[1]->id() => $vocabularies[1]->id(),
|
||||
],
|
||||
];
|
||||
$this->createEntityReferenceField('node', $this->nodeType->id(), $name, $label, 'taxonomy_term', 'default', $handler_settings);
|
||||
|
||||
// Check that the 'target_bundle' setting contains the vocabulary.
|
||||
@@ -88,13 +110,32 @@ class EntityReferenceSettingsTest extends KernelTestBase {
|
||||
$this->assertEqual($handler_settings, $actual_handler_settings);
|
||||
|
||||
// Delete the vocabulary.
|
||||
$this->vocabulary->delete();
|
||||
$vocabularies[0]->delete();
|
||||
// Ensure that noting is logged.
|
||||
$this->assertEmpty($this->container->get($this->testLogServiceName)->cleanLogs());
|
||||
|
||||
// Check that the deleted vocabulary is no longer present in the
|
||||
// 'target_bundles' field setting.
|
||||
$field_config = FieldConfig::loadByName('node', $this->nodeType->id(), $name);
|
||||
$handler_settings = $field_config->getSetting('handler_settings');
|
||||
$this->assertTrue(empty($handler_settings['target_bundles']));
|
||||
$this->assertEquals([$vocabularies[1]->id() => $vocabularies[1]->id()], $handler_settings['target_bundles']);
|
||||
|
||||
// Delete the other vocabulary.
|
||||
$vocabularies[1]->delete();
|
||||
// Ensure that field_field_config_presave() logs the expected critical
|
||||
// error.
|
||||
$log_message = $this->container->get($this->testLogServiceName)->cleanLogs()[0];
|
||||
$this->assertEquals(RfcLogLevel::CRITICAL, $log_message[0]);
|
||||
$this->assertEquals('The %field_name entity reference field (entity_type: %entity_type, bundle: %bundle) no longer has any valid bundle it can reference. The field is not working correctly anymore and has to be adjusted.', $log_message[1]);
|
||||
$this->assertEquals($field_config->getName(), $log_message[2]['%field_name']);
|
||||
$this->assertEquals('node', $log_message[2]['%entity_type']);
|
||||
$this->assertEquals($this->nodeType->id(), $log_message[2]['%bundle']);
|
||||
|
||||
// Check that the deleted bundle is no longer present in the
|
||||
// 'target_bundles' field setting.
|
||||
$field_config = FieldConfig::loadByName('node', $this->nodeType->id(), $name);
|
||||
$handler_settings = $field_config->getSetting('handler_settings');
|
||||
$this->assertEquals([], $handler_settings['target_bundles']);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -115,6 +156,15 @@ class EntityReferenceSettingsTest extends KernelTestBase {
|
||||
// Delete the custom bundle.
|
||||
entity_test_delete_bundle($this->customBundle, 'entity_test');
|
||||
|
||||
// Ensure that field_field_config_presave() logs the expected critical
|
||||
// error.
|
||||
$log_message = $this->container->get($this->testLogServiceName)->cleanLogs()[0];
|
||||
$this->assertEquals(RfcLogLevel::CRITICAL, $log_message[0]);
|
||||
$this->assertEquals('The %field_name entity reference field (entity_type: %entity_type, bundle: %bundle) no longer has any valid bundle it can reference. The field is not working correctly anymore and has to be adjusted.', $log_message[1]);
|
||||
$this->assertEquals($field_config->getName(), $log_message[2]['%field_name']);
|
||||
$this->assertEquals('node', $log_message[2]['%entity_type']);
|
||||
$this->assertEquals($this->nodeType->id(), $log_message[2]['%bundle']);
|
||||
|
||||
// Check that the deleted bundle is no longer present in the
|
||||
// 'target_bundles' field setting.
|
||||
$field_config = FieldConfig::loadByName('node', $this->nodeType->id(), $name);
|
||||
@@ -122,4 +172,14 @@ class EntityReferenceSettingsTest extends KernelTestBase {
|
||||
$this->assertTrue(empty($handler_settings['target_bundles']));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function register(ContainerBuilder $container) {
|
||||
parent::register($container);
|
||||
$container
|
||||
->register($this->testLogServiceName, BufferingLogger::class)
|
||||
->addTag('logger');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,7 +2,13 @@
|
||||
|
||||
namespace Drupal\Tests\field\Kernel;
|
||||
|
||||
use Drupal\Component\Plugin\Discovery\DiscoveryInterface;
|
||||
use Drupal\Component\Plugin\Exception\PluginNotFoundException;
|
||||
use Drupal\Component\Utility\NestedArray;
|
||||
use Drupal\Core\Entity\ContentEntityTypeInterface;
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\Core\Extension\Extension;
|
||||
use Drupal\Core\Field\BaseFieldDefinition;
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
|
||||
/**
|
||||
@@ -21,22 +27,13 @@ class FieldDefinitionIntegrityTest extends KernelTestBase {
|
||||
* Tests the integrity of field plugin definitions.
|
||||
*/
|
||||
public function testFieldPluginDefinitionIntegrity() {
|
||||
|
||||
// Enable all core modules that provide field plugins.
|
||||
$modules = system_rebuild_module_data();
|
||||
$modules = array_filter($modules, function (Extension $module) {
|
||||
// Filter contrib, hidden, already enabled modules and modules in the
|
||||
// Testing package.
|
||||
if ($module->origin === 'core'
|
||||
&& empty($module->info['hidden'])
|
||||
&& $module->status == FALSE
|
||||
&& $module->info['package'] !== 'Testing'
|
||||
&& is_readable($module->getPath() . '/src/Plugin/Field')) {
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
});
|
||||
$this->enableModules(array_keys($modules));
|
||||
// Enable all core modules that provide field plugins, and their
|
||||
// dependencies.
|
||||
$this->enableModules(
|
||||
$this->modulesWithSubdirectory(
|
||||
'src' . DIRECTORY_SEPARATOR . 'Plugin' . DIRECTORY_SEPARATOR . 'Field'
|
||||
)
|
||||
);
|
||||
|
||||
/** @var \Drupal\Component\Plugin\Discovery\DiscoveryInterface $field_type_manager */
|
||||
$field_type_manager = \Drupal::service('plugin.manager.field.field_type');
|
||||
@@ -108,7 +105,114 @@ class FieldDefinitionIntegrityTest extends KernelTestBase {
|
||||
else {
|
||||
$this->pass(sprintf('Field formatter %s integrates with existing field types.', $definition['id']));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests to load field plugin definitions used in core's existing entities.
|
||||
*/
|
||||
public function testFieldPluginDefinitionAvailability() {
|
||||
$this->enableModules(
|
||||
$this->modulesWithSubdirectory('src' . DIRECTORY_SEPARATOR . 'Entity')
|
||||
);
|
||||
|
||||
/** @var \Drupal\Component\Plugin\Discovery\DiscoveryInterface $field_type_manager */
|
||||
$field_formatter_manager = $this->container->get('plugin.manager.field.formatter');
|
||||
|
||||
/** @var \Drupal\Component\Plugin\Discovery\DiscoveryInterface $field_type_manager */
|
||||
$field_widget_manager = $this->container->get('plugin.manager.field.widget');
|
||||
|
||||
/** @var \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager */
|
||||
$entity_field_manager = $this->container->get('entity_field.manager');
|
||||
|
||||
/** @var \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager */
|
||||
$entity_type_manager = $this->container->get('entity_type.manager');
|
||||
|
||||
/** @var \Drupal\Core\Field\BaseFieldDefinition[][] $field_definitions */
|
||||
$field_definitions = [];
|
||||
|
||||
/** @var \Drupal\Core\Entity\EntityTypeInterface[] $content_entity_types */
|
||||
$content_entity_types = array_filter($entity_type_manager->getDefinitions(), function (EntityTypeInterface $entity_type) {
|
||||
return $entity_type instanceof ContentEntityTypeInterface;
|
||||
});
|
||||
|
||||
foreach ($content_entity_types as $entity_type_id => $entity_type_definition) {
|
||||
$field_definitions[$entity_type_id] = $entity_field_manager->getBaseFieldDefinitions($entity_type_id);
|
||||
}
|
||||
|
||||
foreach ($field_definitions as $entity_type_id => $definitions) {
|
||||
foreach ($definitions as $field_id => $field_definition) {
|
||||
$this->checkDisplayOption($entity_type_id, $field_id, $field_definition, $field_formatter_manager, 'view');
|
||||
$this->checkDisplayOption($entity_type_id, $field_id, $field_definition, $field_widget_manager, 'form');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method that tries to load plugin definitions.
|
||||
*
|
||||
* @param string $entity_type_id
|
||||
* Id of entity type. Required by message.
|
||||
* @param string $field_id
|
||||
* Id of field. Required by message.
|
||||
* @param \Drupal\Core\Field\BaseFieldDefinition $field_definition
|
||||
* Field definition that provide display options.
|
||||
* @param \Drupal\Component\Plugin\Discovery\DiscoveryInterface $plugin_manager
|
||||
* Plugin manager that will try to provide plugin definition.
|
||||
* @param string $display_context
|
||||
* Defines which display options should be loaded.
|
||||
*/
|
||||
protected function checkDisplayOption($entity_type_id, $field_id, BaseFieldDefinition $field_definition, DiscoveryInterface $plugin_manager, $display_context) {
|
||||
$display_options = $field_definition->getDisplayOptions($display_context);
|
||||
if (!empty($display_options['type'])) {
|
||||
try {
|
||||
$plugin_manager->getDefinition($display_options['type']);
|
||||
}
|
||||
catch (PluginNotFoundException $e) {
|
||||
$this->fail(sprintf(
|
||||
'PluginNotFoundException here for "%s" field %s display options of "%s" entity type. Original message: %s',
|
||||
$field_id,
|
||||
$display_context,
|
||||
$entity_type_id,
|
||||
$e->getMessage()
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Find modules with a specified subdirectory.
|
||||
*
|
||||
* @param string $subdirectory
|
||||
* The required path, relative to the module directory.
|
||||
*
|
||||
* @return string[]
|
||||
* A list of module names satisfying these criteria:
|
||||
* - provided by core
|
||||
* - not hidden
|
||||
* - not already enabled
|
||||
* - not in the Testing package
|
||||
* - containing the required $subdirectory
|
||||
* and all modules required by any of these modules.
|
||||
*/
|
||||
protected function modulesWithSubdirectory($subdirectory) {
|
||||
$modules = system_rebuild_module_data();
|
||||
$modules = array_filter($modules, function (Extension $module) use ($subdirectory) {
|
||||
// Filter contrib, hidden, already enabled modules and modules in the
|
||||
// Testing package.
|
||||
return ($module->origin === 'core'
|
||||
&& empty($module->info['hidden'])
|
||||
&& $module->status == FALSE
|
||||
&& $module->info['package'] !== 'Testing'
|
||||
&& is_readable($module->getPath() . DIRECTORY_SEPARATOR . $subdirectory));
|
||||
});
|
||||
// Gather the dependencies of the modules.
|
||||
$dependencies = NestedArray::mergeDeepArray(array_map(function (Extension $module) {
|
||||
return array_keys($module->requires);
|
||||
}, $modules));
|
||||
|
||||
return array_unique(NestedArray::mergeDeep(array_keys($modules), $dependencies));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -172,7 +172,7 @@ abstract class FieldKernelTestBase extends KernelTestBase {
|
||||
*
|
||||
* This function only checks a single column in the field values.
|
||||
*
|
||||
* @param EntityInterface $entity
|
||||
* @param \Drupal\Core\Entity\EntityInterface $entity
|
||||
* The entity to test.
|
||||
* @param $field_name
|
||||
* The name of the field to test
|
||||
|
||||
@@ -128,7 +128,6 @@ class MigrateFieldInstanceTest extends MigrateDrupal7TestBase {
|
||||
$this->assertEntity('comment.comment_node_test_content_type.field_integer', 'Integer', 'integer', FALSE, FALSE);
|
||||
$this->assertEntity('user.user.field_file', 'File', 'file', FALSE, FALSE);
|
||||
|
||||
|
||||
$this->assertLinkFields('node.test_content_type.field_link', DRUPAL_OPTIONAL);
|
||||
$this->assertLinkFields('node.article.field_link', DRUPAL_DISABLED);
|
||||
$this->assertLinkFields('node.blog.field_link', DRUPAL_REQUIRED);
|
||||
|
||||
@@ -101,6 +101,8 @@ class MigrateFieldTest extends MigrateDrupal7TestBase {
|
||||
$this->assertEntity('node.field_node_entityreference', 'entity_reference', TRUE, -1);
|
||||
$this->assertEntity('node.field_user_entityreference', 'entity_reference', TRUE, 1);
|
||||
$this->assertEntity('node.field_term_entityreference', 'entity_reference', TRUE, -1);
|
||||
$this->assertEntity('node.field_date_without_time', 'datetime', TRUE, 1);
|
||||
$this->assertEntity('node.field_datetime_without_time', 'datetime', TRUE, 1);
|
||||
|
||||
// Assert that the taxonomy term reference fields are referencing the
|
||||
// correct entity type.
|
||||
@@ -117,6 +119,18 @@ class MigrateFieldTest extends MigrateDrupal7TestBase {
|
||||
$this->assertEquals('user', $field->getSetting('target_type'));
|
||||
$field = FieldStorageConfig::load('node.field_term_entityreference');
|
||||
$this->assertEquals('taxonomy_term', $field->getSetting('target_type'));
|
||||
|
||||
// Make sure that datetime fields get the right datetime_type setting
|
||||
$field = FieldStorageConfig::load('node.field_date');
|
||||
$this->assertEquals('datetime', $field->getSetting('datetime_type'));
|
||||
$field = FieldStorageConfig::load('node.field_date_without_time');
|
||||
$this->assertEquals('date', $field->getSetting('datetime_type'));
|
||||
$field = FieldStorageConfig::load('node.field_datetime_without_time');
|
||||
$this->assertEquals('date', $field->getSetting('datetime_type'));
|
||||
// Except for field_date_with_end_time which is a timestamp and so does not
|
||||
// have a datetime_type setting.
|
||||
$field = FieldStorageConfig::load('node.field_date_with_end_time');
|
||||
$this->assertNull($field->getSetting('datetime_type'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
-75
@@ -1,75 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\field\Unit\Plugin\migrate\source\d6;
|
||||
|
||||
use Drupal\field\Plugin\migrate\source\d6\FieldInstancePerFormDisplay;
|
||||
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
|
||||
|
||||
/**
|
||||
* Tests d6_field_instance_per_form_display source plugin.
|
||||
*
|
||||
* @group field
|
||||
*/
|
||||
class FieldInstancePerFormDisplayTest extends MigrateSqlSourceTestCase {
|
||||
|
||||
const PLUGIN_CLASS = FieldInstancePerFormDisplay::class;
|
||||
|
||||
protected $migrationConfiguration = array(
|
||||
'id' => 'view_mode_test',
|
||||
'source' => array(
|
||||
'plugin' => 'd6_field_instance_per_form_display',
|
||||
),
|
||||
);
|
||||
|
||||
protected $expectedResults = array(
|
||||
array(
|
||||
'display_settings' => array(),
|
||||
'widget_settings' => array(),
|
||||
'type_name' => 'story',
|
||||
'widget_active' => TRUE,
|
||||
'field_name' => 'field_test_filefield',
|
||||
'type' => 'filefield',
|
||||
'module' => 'filefield',
|
||||
'weight' => '8',
|
||||
'widget_type' => 'filefield_widget',
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
$empty_array = serialize([]);
|
||||
|
||||
$this->databaseContents['content_node_field'] = array(
|
||||
array(
|
||||
'field_name' => 'field_test_filefield',
|
||||
'type' => 'filefield',
|
||||
'global_settings' => $empty_array,
|
||||
'required' => '0',
|
||||
'multiple' => '0',
|
||||
'db_storage' => '1',
|
||||
'module' => 'filefield',
|
||||
'db_columns' => $empty_array,
|
||||
'active' => '1',
|
||||
'locked' => '0',
|
||||
)
|
||||
);
|
||||
$this->databaseContents['content_node_field_instance'] = array(
|
||||
array(
|
||||
'field_name' => 'field_test_filefield',
|
||||
'type_name' => 'story',
|
||||
'weight' => '8',
|
||||
'label' => 'File Field',
|
||||
'widget_type' => 'filefield_widget',
|
||||
'widget_settings' => $empty_array,
|
||||
'display_settings' => $empty_array,
|
||||
'description' => 'An example image field.',
|
||||
'widget_module' => 'filefield',
|
||||
'widget_active' => '1',
|
||||
),
|
||||
);
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
}
|
||||
-96
@@ -1,96 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\field\Unit\Plugin\migrate\source\d6;
|
||||
|
||||
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
|
||||
|
||||
/**
|
||||
* Tests D6 fields per view mode source plugin.
|
||||
*
|
||||
* @group field
|
||||
*/
|
||||
class FieldInstancePerViewModeTest extends MigrateSqlSourceTestCase {
|
||||
|
||||
const PLUGIN_CLASS = 'Drupal\field\Plugin\migrate\source\d6\FieldInstancePerViewMode';
|
||||
|
||||
protected $migrationConfiguration = array(
|
||||
'id' => 'view_mode_test',
|
||||
'source' => array(
|
||||
'plugin' => 'd6_field_instance_per_view_mode',
|
||||
),
|
||||
);
|
||||
|
||||
protected $expectedResults = array(
|
||||
array(
|
||||
'entity_type' => 'node',
|
||||
'view_mode' => 4,
|
||||
'type_name' => 'article',
|
||||
'field_name' => 'field_test',
|
||||
'type' => 'text',
|
||||
'module' => 'text',
|
||||
'weight' => 1,
|
||||
'label' => 'above',
|
||||
'display_settings' => array(
|
||||
'weight' => 1,
|
||||
'parent' => '',
|
||||
'label' => array(
|
||||
'format' => 'above',
|
||||
),
|
||||
4 => array(
|
||||
'format' => 'trimmed',
|
||||
'exclude' => 0,
|
||||
),
|
||||
),
|
||||
'widget_settings' => array(),
|
||||
),
|
||||
array(
|
||||
'entity_type' => 'node',
|
||||
'view_mode' => 'teaser',
|
||||
'type_name' => 'story',
|
||||
'field_name' => 'field_test',
|
||||
'type' => 'text',
|
||||
'module' => 'text',
|
||||
'weight' => 2,
|
||||
'label' => 'above',
|
||||
'display_settings' => array(
|
||||
'weight' => 1,
|
||||
'parent' => '',
|
||||
'label' => array(
|
||||
'format' => 'above',
|
||||
),
|
||||
'teaser' => array(
|
||||
'format' => 'trimmed',
|
||||
'exclude' => 0,
|
||||
),
|
||||
),
|
||||
'widget_settings' => array(),
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
foreach ($this->expectedResults as $k => $field_view_mode) {
|
||||
// These are stored as serialized strings.
|
||||
$field_view_mode['display_settings'] = serialize($field_view_mode['display_settings']);
|
||||
$field_view_mode['widget_settings'] = serialize($field_view_mode['widget_settings']);
|
||||
|
||||
$this->databaseContents['content_node_field'][] = array(
|
||||
'field_name' => $field_view_mode['field_name'],
|
||||
'type' => $field_view_mode['type'],
|
||||
'module' => $field_view_mode['module'],
|
||||
);
|
||||
unset($field_view_mode['type']);
|
||||
unset($field_view_mode['module']);
|
||||
|
||||
$this->databaseContents['content_node_field_instance'][] = $field_view_mode;
|
||||
|
||||
// Update the expected display settings.
|
||||
$this->expectedResults[$k]['display_settings'] = $this->expectedResults[$k]['display_settings'][$field_view_mode['view_mode']];
|
||||
|
||||
}
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,91 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\field\Unit\Plugin\migrate\source\d6;
|
||||
|
||||
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
|
||||
|
||||
/**
|
||||
* Tests D6 field instance source plugin.
|
||||
*
|
||||
* @group field
|
||||
*/
|
||||
class FieldInstanceTest extends MigrateSqlSourceTestCase {
|
||||
|
||||
// The plugin system is not working during unit testing so the source plugin
|
||||
// class needs to be manually specified.
|
||||
const PLUGIN_CLASS = 'Drupal\field\Plugin\migrate\source\d6\FieldInstance';
|
||||
|
||||
// The fake Migration configuration entity.
|
||||
protected $migrationConfiguration = [
|
||||
// The id of the entity, can be any string.
|
||||
'id' => 'test_fieldinstance',
|
||||
'source' => [
|
||||
'plugin' => 'd6_field_instance',
|
||||
],
|
||||
];
|
||||
|
||||
// We need to set up the database contents; it's easier to do that below.
|
||||
// These are sample result queries.
|
||||
protected $expectedResults = [
|
||||
[
|
||||
'field_name' => 'field_body',
|
||||
'type_name' => 'page',
|
||||
'weight' => 1,
|
||||
'label' => 'body',
|
||||
'widget_type' => 'text_textarea',
|
||||
'widget_settings' => '',
|
||||
'display_settings' => '',
|
||||
'description' => '',
|
||||
'widget_module' => 'text',
|
||||
'widget_active' => 1,
|
||||
'required' => 1,
|
||||
'active' => 1,
|
||||
'global_settings' => [],
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* Prepopulate contents with results.
|
||||
*/
|
||||
protected function setUp() {
|
||||
$this->expectedResults[0]['widget_settings'] = [
|
||||
'rows' => 5,
|
||||
'size' => 60,
|
||||
'default_value' => [
|
||||
[
|
||||
'value' => '',
|
||||
'_error_element' => 'default_value_widget][field_body][0][value',
|
||||
'default_value_php' => '',
|
||||
],
|
||||
],
|
||||
];
|
||||
$this->expectedResults[0]['display_settings'] = [
|
||||
'label' => [
|
||||
'format' => 'above',
|
||||
'exclude' => 0,
|
||||
],
|
||||
'teaser' => [
|
||||
'format' => 'default',
|
||||
'exclude' => 0,
|
||||
],
|
||||
'full' => [
|
||||
'format' => 'default',
|
||||
'exclude' => 0,
|
||||
],
|
||||
];
|
||||
$this->databaseContents['content_node_field_instance'] = $this->expectedResults;
|
||||
$this->databaseContents['content_node_field_instance'][0]['widget_settings'] = serialize($this->expectedResults[0]['widget_settings']);
|
||||
$this->databaseContents['content_node_field_instance'][0]['display_settings'] = serialize($this->expectedResults[0]['display_settings']);
|
||||
$this->databaseContents['content_node_field_instance'][0]['global_settings'] = 'a:0:{}';
|
||||
|
||||
$this->databaseContents['content_node_field'][0] = [
|
||||
'field_name' => 'field_body',
|
||||
'required' => 1,
|
||||
'type' => 'text',
|
||||
'active' => 1,
|
||||
'global_settings' => serialize([]),
|
||||
];
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\field\Unit\Plugin\migrate\source\d6;
|
||||
|
||||
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
|
||||
|
||||
/**
|
||||
* Tests D6 field source plugin.
|
||||
*
|
||||
* @group field
|
||||
*/
|
||||
class FieldTest extends MigrateSqlSourceTestCase {
|
||||
|
||||
// The plugin system is not working during unit testing so the source plugin
|
||||
// class needs to be manually specified.
|
||||
const PLUGIN_CLASS = 'Drupal\field\Plugin\migrate\source\d6\Field';
|
||||
|
||||
// The fake Migration configuration entity.
|
||||
protected $migrationConfiguration = array(
|
||||
// The id of the entity, can be any string.
|
||||
'id' => 'test_field',
|
||||
'source' => array(
|
||||
'plugin' => 'd6_field',
|
||||
),
|
||||
);
|
||||
|
||||
// We need to set up the database contents; it's easier to do that below.
|
||||
// These are sample result queries.
|
||||
protected $expectedResults = array(
|
||||
array(
|
||||
'field_name' => 'field_body',
|
||||
'type' => 'text',
|
||||
'global_settings' => '',
|
||||
'required' => 0,
|
||||
'multiple' => 0,
|
||||
'db_storage' => 1,
|
||||
'module' => 'text',
|
||||
'db_columns' => '',
|
||||
'active' => 1,
|
||||
'locked' => 0,
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Prepopulate contents with results.
|
||||
*/
|
||||
protected function setUp() {
|
||||
$this->expectedResults[0]['global_settings'] = array(
|
||||
'text_processing' => 0,
|
||||
'max_length' => '',
|
||||
'allowed_values' => '',
|
||||
'allowed_values_php' => '',
|
||||
);
|
||||
$this->expectedResults[0]['db_columns'] = array(
|
||||
'value' => array(
|
||||
'type' => 'text',
|
||||
'size' => 'big',
|
||||
'not null' => '',
|
||||
'sortable' => 1,
|
||||
'views' => 1,
|
||||
),
|
||||
);
|
||||
$this->databaseContents['content_node_field'] = $this->expectedResults;
|
||||
$this->databaseContents['content_node_field'][0]['global_settings'] = serialize($this->databaseContents['content_node_field'][0]['global_settings']);
|
||||
$this->databaseContents['content_node_field'][0]['db_columns'] = serialize($this->databaseContents['content_node_field'][0]['db_columns']);
|
||||
|
||||
$this->databaseContents['content_node_field_instance'][0]['widget_type'] = 'text_textarea';
|
||||
$this->databaseContents['content_node_field_instance'][0]['field_name'] = 'field_body';
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
}
|
||||
-184
@@ -1,184 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\field\Unit\Plugin\migrate\source\d7;
|
||||
|
||||
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
|
||||
|
||||
/**
|
||||
* Tests D7 field instance per form display source plugin.
|
||||
*
|
||||
* @group field
|
||||
*/
|
||||
class FieldInstancePerFormDisplayTest extends MigrateSqlSourceTestCase {
|
||||
|
||||
const PLUGIN_CLASS = 'Drupal\field\Plugin\migrate\source\d7\FieldInstancePerFormDisplay';
|
||||
|
||||
protected $migrationConfiguration = array(
|
||||
'id' => 'test_fieldinstance',
|
||||
'source' => array(
|
||||
'plugin' => 'd7_field_instance_per_form_display',
|
||||
),
|
||||
);
|
||||
|
||||
// We need to set up the database contents; it's easier to do that below.
|
||||
// These are sample result queries.
|
||||
protected $expectedResults = array(
|
||||
array(
|
||||
'field_name' => 'body',
|
||||
'entity_type' => 'node',
|
||||
'bundle' => 'page',
|
||||
'widget_settings' => array(
|
||||
),
|
||||
'display_settings' => array(
|
||||
),
|
||||
'description' => '',
|
||||
'required' => FALSE,
|
||||
'global_settings' => array(),
|
||||
),
|
||||
array(
|
||||
'field_name' => 'field_file',
|
||||
'entity_type' => 'user',
|
||||
'bundle' => 'user',
|
||||
'widget_settings' => array(
|
||||
),
|
||||
'display_settings' => array(
|
||||
),
|
||||
'description' => '',
|
||||
'required' => FALSE,
|
||||
'global_settings' => array(),
|
||||
),
|
||||
array(
|
||||
'field_name' => 'field_integer',
|
||||
'entity_type' => 'comment',
|
||||
'bundle' => 'comment_node_test_content_type',
|
||||
'widget_settings' => array(
|
||||
),
|
||||
'display_settings' => array(
|
||||
),
|
||||
'description' => '',
|
||||
'required' => FALSE,
|
||||
'global_settings' => array(),
|
||||
),
|
||||
array(
|
||||
'field_name' => 'field_link',
|
||||
'entity_type' => 'taxonomy_term',
|
||||
'bundle' => 'test_vocabulary',
|
||||
'widget_settings' => array(
|
||||
),
|
||||
'display_settings' => array(
|
||||
),
|
||||
'description' => '',
|
||||
'required' => FALSE,
|
||||
'global_settings' => array(),
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Prepopulate contents with results.
|
||||
*/
|
||||
protected function setUp() {
|
||||
$this->databaseContents['field_config_instance'] = array(
|
||||
array(
|
||||
'id' => '2',
|
||||
'field_id' => '2',
|
||||
'field_name' => 'body',
|
||||
'entity_type' => 'node',
|
||||
'bundle' => 'page',
|
||||
'data' => 'a:6:{s:5:"label";s:4:"Body";s:6:"widget";a:4:{s:4:"type";s:26:"text_textarea_with_summary";s:8:"settings";a:2:{s:4:"rows";i:20;s:12:"summary_rows";i:5;}s:6:"weight";i:-4;s:6:"module";s:4:"text";}s:8:"settings";a:3:{s:15:"display_summary";b:1;s:15:"text_processing";i:1;s:18:"user_register_form";b:0;}s:7:"display";a:2:{s:7:"default";a:5:{s:5:"label";s:6:"hidden";s:4:"type";s:12:"text_default";s:8:"settings";a:0:{}s:6:"module";s:4:"text";s:6:"weight";i:0;}s:6:"teaser";a:5:{s:5:"label";s:6:"hidden";s:4:"type";s:23:"text_summary_or_trimmed";s:8:"settings";a:1:{s:11:"trim_length";i:600;}s:6:"module";s:4:"text";s:6:"weight";i:0;}}s:8:"required";b:0;s:11:"description";s:0:"";}',
|
||||
'deleted' => '0',
|
||||
),
|
||||
array(
|
||||
'id' => '33',
|
||||
'field_id' => '11',
|
||||
'field_name' => 'field_file',
|
||||
'entity_type' => 'user',
|
||||
'bundle' => 'user',
|
||||
'data' => 'a:6:{s:5:"label";s:4:"File";s:6:"widget";a:5:{s:6:"weight";s:1:"8";s:4:"type";s:12:"file_generic";s:6:"module";s:4:"file";s:6:"active";i:1;s:8:"settings";a:1:{s:18:"progress_indicator";s:8:"throbber";}}s:8:"settings";a:5:{s:14:"file_directory";s:0:"";s:15:"file_extensions";s:3:"txt";s:12:"max_filesize";s:0:"";s:17:"description_field";i:0;s:18:"user_register_form";i:0;}s:7:"display";a:1:{s:7:"default";a:5:{s:5:"label";s:5:"above";s:4:"type";s:12:"file_default";s:8:"settings";a:0:{}s:6:"module";s:4:"file";s:6:"weight";i:0;}}s:8:"required";i:0;s:11:"description";s:0:"";}',
|
||||
'deleted' => '0',
|
||||
),
|
||||
array(
|
||||
'id' => '32',
|
||||
'field_id' => '14',
|
||||
'field_name' => 'field_integer',
|
||||
'entity_type' => 'comment',
|
||||
'bundle' => 'comment_node_test_content_type',
|
||||
'data' => 'a:7:{s:5:"label";s:7:"Integer";s:6:"widget";a:5:{s:6:"weight";s:1:"2";s:4:"type";s:6:"number";s:6:"module";s:6:"number";s:6:"active";i:0;s:8:"settings";a:0:{}}s:8:"settings";a:5:{s:3:"min";s:0:"";s:3:"max";s:0:"";s:6:"prefix";s:0:"";s:6:"suffix";s:0:"";s:18:"user_register_form";b:0;}s:7:"display";a:1:{s:7:"default";a:5:{s:5:"label";s:5:"above";s:4:"type";s:14:"number_integer";s:8:"settings";a:4:{s:18:"thousand_separator";s:1:" ";s:17:"decimal_separator";s:1:".";s:5:"scale";i:0;s:13:"prefix_suffix";b:1;}s:6:"module";s:6:"number";s:6:"weight";i:1;}}s:8:"required";i:0;s:11:"description";s:0:"";s:13:"default_value";N;}',
|
||||
'deleted' => '0',
|
||||
),
|
||||
array(
|
||||
'id' => '25',
|
||||
'field_id' => '15',
|
||||
'field_name' => 'field_link',
|
||||
'entity_type' => 'taxonomy_term',
|
||||
'bundle' => 'test_vocabulary',
|
||||
'data' => 'a:7:{s:5:"label";s:4:"Link";s:6:"widget";a:5:{s:6:"weight";s:2:"10";s:4:"type";s:10:"link_field";s:6:"module";s:4:"link";s:6:"active";i:0;s:8:"settings";a:0:{}}s:8:"settings";a:12:{s:12:"absolute_url";i:1;s:12:"validate_url";i:1;s:3:"url";i:0;s:5:"title";s:8:"optional";s:11:"title_value";s:19:"Unused Static Title";s:27:"title_label_use_field_label";i:0;s:15:"title_maxlength";s:3:"128";s:7:"display";a:1:{s:10:"url_cutoff";s:2:"81";}s:10:"attributes";a:6:{s:6:"target";s:6:"_blank";s:3:"rel";s:8:"nofollow";s:18:"configurable_class";i:0;s:5:"class";s:7:"classes";s:18:"configurable_title";i:1;s:5:"title";s:0:"";}s:10:"rel_remove";s:19:"rel_remove_external";s:13:"enable_tokens";i:1;s:18:"user_register_form";b:0;}s:7:"display";a:1:{s:7:"default";a:5:{s:5:"label";s:5:"above";s:4:"type";s:12:"link_default";s:6:"weight";s:1:"9";s:8:"settings";a:0:{}s:6:"module";s:4:"link";}}s:8:"required";i:0;s:11:"description";s:0:"";s:13:"default_value";N;}',
|
||||
'deleted' => '0',
|
||||
),
|
||||
);
|
||||
$this->databaseContents['field_config'] = array(
|
||||
array(
|
||||
'id' => '2',
|
||||
'field_name' => 'body',
|
||||
'type' => 'text_with_summary',
|
||||
'module' => 'text',
|
||||
'active' => '1',
|
||||
'storage_type' => 'field_sql_storage',
|
||||
'storage_module' => 'field_sql_storage',
|
||||
'storage_active' => '1',
|
||||
'locked' => '0',
|
||||
'data' => 'a:6:{s:12:"entity_types";a:1:{i:0;s:4:"node";}s:12:"translatable";b:0;s:8:"settings";a:0:{}s:7:"storage";a:4:{s:4:"type";s:17:"field_sql_storage";s:8:"settings";a:0:{}s:6:"module";s:17:"field_sql_storage";s:6:"active";i:1;}s:12:"foreign keys";a:1:{s:6:"format";a:2:{s:5:"table";s:13:"filter_format";s:7:"columns";a:1:{s:6:"format";s:6:"format";}}}s:7:"indexes";a:1:{s:6:"format";a:1:{i:0;s:6:"format";}}}',
|
||||
'cardinality' => '1',
|
||||
'translatable' => '0',
|
||||
'deleted' => '0',
|
||||
),
|
||||
array(
|
||||
'id' => '11',
|
||||
'field_name' => 'field_file',
|
||||
'type' => 'file',
|
||||
'module' => 'file',
|
||||
'active' => '1',
|
||||
'storage_type' => 'field_sql_storage',
|
||||
'storage_module' => 'field_sql_storage',
|
||||
'storage_active' => '1',
|
||||
'locked' => '0',
|
||||
'data' => 'a:7:{s:12:"translatable";s:1:"0";s:12:"entity_types";a:0:{}s:8:"settings";a:3:{s:13:"display_field";i:0;s:15:"display_default";i:0;s:10:"uri_scheme";s:6:"public";}s:7:"storage";a:5:{s:4:"type";s:17:"field_sql_storage";s:8:"settings";a:0:{}s:6:"module";s:17:"field_sql_storage";s:6:"active";s:1:"1";s:7:"details";a:1:{s:3:"sql";a:2:{s:18:"FIELD_LOAD_CURRENT";a:1:{s:21:"field_data_field_file";a:3:{s:3:"fid";s:14:"field_file_fid";s:7:"display";s:18:"field_file_display";s:11:"description";s:22:"field_file_description";}}s:19:"FIELD_LOAD_REVISION";a:1:{s:25:"field_revision_field_file";a:3:{s:3:"fid";s:14:"field_file_fid";s:7:"display";s:18:"field_file_display";s:11:"description";s:22:"field_file_description";}}}}}s:12:"foreign keys";a:1:{s:3:"fid";a:2:{s:5:"table";s:12:"file_managed";s:7:"columns";a:1:{s:3:"fid";s:3:"fid";}}}s:7:"indexes";a:1:{s:3:"fid";a:1:{i:0;s:3:"fid";}}s:2:"id";s:2:"11";}',
|
||||
'cardinality' => '1',
|
||||
'translatable' => '0',
|
||||
'deleted' => '0',
|
||||
),
|
||||
array(
|
||||
'id' => '14',
|
||||
'field_name' => 'field_integer',
|
||||
'type' => 'number_integer',
|
||||
'module' => 'number',
|
||||
'active' => '1',
|
||||
'storage_type' => 'field_sql_storage',
|
||||
'storage_module' => 'field_sql_storage',
|
||||
'storage_active' => '1',
|
||||
'locked' => '0',
|
||||
'data' => 'a:7:{s:12:"translatable";s:1:"0";s:12:"entity_types";a:0:{}s:8:"settings";a:0:{}s:7:"storage";a:5:{s:4:"type";s:17:"field_sql_storage";s:8:"settings";a:0:{}s:6:"module";s:17:"field_sql_storage";s:6:"active";s:1:"1";s:7:"details";a:1:{s:3:"sql";a:2:{s:18:"FIELD_LOAD_CURRENT";a:1:{s:24:"field_data_field_integer";a:1:{s:5:"value";s:19:"field_integer_value";}}s:19:"FIELD_LOAD_REVISION";a:1:{s:28:"field_revision_field_integer";a:1:{s:5:"value";s:19:"field_integer_value";}}}}}s:12:"foreign keys";a:0:{}s:7:"indexes";a:0:{}s:2:"id";s:2:"14";}',
|
||||
'cardinality' => '1',
|
||||
'translatable' => '0',
|
||||
'deleted' => '0',
|
||||
),
|
||||
array(
|
||||
'id' => '15',
|
||||
'field_name' => 'field_link',
|
||||
'type' => 'link_field',
|
||||
'module' => 'link',
|
||||
'active' => '1',
|
||||
'storage_type' => 'field_sql_storage',
|
||||
'storage_module' => 'field_sql_storage',
|
||||
'storage_active' => '1',
|
||||
'locked' => '0',
|
||||
'data' => 'a:7:{s:12:"translatable";s:1:"0";s:12:"entity_types";a:0:{}s:8:"settings";a:7:{s:10:"attributes";a:3:{s:6:"target";s:7:"default";s:5:"class";s:0:"";s:3:"rel";s:0:"";}s:3:"url";i:0;s:5:"title";s:8:"optional";s:11:"title_value";s:0:"";s:15:"title_maxlength";i:128;s:13:"enable_tokens";i:1;s:7:"display";a:1:{s:10:"url_cutoff";i:80;}}s:7:"storage";a:5:{s:4:"type";s:17:"field_sql_storage";s:8:"settings";a:0:{}s:6:"module";s:17:"field_sql_storage";s:6:"active";s:1:"1";s:7:"details";a:1:{s:3:"sql";a:2:{s:18:"FIELD_LOAD_CURRENT";a:1:{s:21:"field_data_field_link";a:3:{s:3:"url";s:14:"field_link_url";s:5:"title";s:16:"field_link_title";s:10:"attributes";s:21:"field_link_attributes";}}s:19:"FIELD_LOAD_REVISION";a:1:{s:25:"field_revision_field_link";a:3:{s:3:"url";s:14:"field_link_url";s:5:"title";s:16:"field_link_title";s:10:"attributes";s:21:"field_link_attributes";}}}}}s:12:"foreign keys";a:0:{}s:7:"indexes";a:0:{}s:2:"id";s:2:"15";}',
|
||||
'cardinality' => '1',
|
||||
'translatable' => '0',
|
||||
'deleted' => '0',
|
||||
),
|
||||
);
|
||||
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
}
|
||||
-68
@@ -1,68 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\field\Unit\Plugin\migrate\source\d7;
|
||||
|
||||
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
|
||||
|
||||
/**
|
||||
* Tests D7 field instance per view mode source plugin.
|
||||
*
|
||||
* @group field
|
||||
*/
|
||||
class FieldInstancePerViewModeTest extends MigrateSqlSourceTestCase {
|
||||
|
||||
const PLUGIN_CLASS = 'Drupal\field\Plugin\migrate\source\d7\FieldInstancePerViewMode';
|
||||
|
||||
protected $migrationConfiguration = array(
|
||||
'id' => 'test',
|
||||
'source' => array(
|
||||
'plugin' => 'd7_field_instance_per_view_mode',
|
||||
),
|
||||
);
|
||||
|
||||
protected $expectedResults = array(
|
||||
array(
|
||||
'entity_type' => 'node',
|
||||
'bundle' => 'page',
|
||||
'field_name' => 'body',
|
||||
'label' => 'hidden',
|
||||
'type' => 'text_default',
|
||||
'settings' => array(),
|
||||
'module' => 'text',
|
||||
'weight' => 0,
|
||||
'view_mode' => 'default',
|
||||
),
|
||||
array(
|
||||
'entity_type' => 'node',
|
||||
'bundle' => 'page',
|
||||
'field_name' => 'body',
|
||||
'label' => 'hidden',
|
||||
'type' => 'text_summary_or_trimmed',
|
||||
'settings' => array(
|
||||
'trim_length' => 600,
|
||||
),
|
||||
'module' => 'text',
|
||||
'weight' => 0,
|
||||
'view_mode' => 'teaser',
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Prepopulate contents with results.
|
||||
*/
|
||||
protected function setUp() {
|
||||
$this->databaseContents['field_config_instance'] = array(
|
||||
array(
|
||||
'id' => '2',
|
||||
'field_id' => '2',
|
||||
'field_name' => 'body',
|
||||
'entity_type' => 'node',
|
||||
'bundle' => 'page',
|
||||
'data' => 'a:6:{s:5:"label";s:4:"Body";s:6:"widget";a:4:{s:4:"type";s:26:"text_textarea_with_summary";s:8:"settings";a:2:{s:4:"rows";i:20;s:12:"summary_rows";i:5;}s:6:"weight";i:-4;s:6:"module";s:4:"text";}s:8:"settings";a:3:{s:15:"display_summary";b:1;s:15:"text_processing";i:1;s:18:"user_register_form";b:0;}s:7:"display";a:2:{s:7:"default";a:5:{s:5:"label";s:6:"hidden";s:4:"type";s:12:"text_default";s:8:"settings";a:0:{}s:6:"module";s:4:"text";s:6:"weight";i:0;}s:6:"teaser";a:5:{s:5:"label";s:6:"hidden";s:4:"type";s:23:"text_summary_or_trimmed";s:8:"settings";a:1:{s:11:"trim_length";i:600;}s:6:"module";s:4:"text";s:6:"weight";i:0;}}s:8:"required";b:0;s:11:"description";s:0:"";}',
|
||||
'deleted' => '0',
|
||||
),
|
||||
);
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,82 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\field\Unit\Plugin\migrate\source\d7;
|
||||
|
||||
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
|
||||
|
||||
/**
|
||||
* Tests D7 field instance source plugin.
|
||||
*
|
||||
* @group field
|
||||
*/
|
||||
class FieldInstanceTest extends MigrateSqlSourceTestCase {
|
||||
|
||||
const PLUGIN_CLASS = 'Drupal\field\Plugin\migrate\source\d7\FieldInstance';
|
||||
|
||||
protected $migrationConfiguration = array(
|
||||
'id' => 'test_fieldinstance',
|
||||
'source' => array(
|
||||
'plugin' => 'd7_field_instance',
|
||||
),
|
||||
);
|
||||
|
||||
protected $expectedResults = array(
|
||||
array(
|
||||
'field_name' => 'body',
|
||||
'entity_type' => 'node',
|
||||
'bundle' => 'page',
|
||||
'label' => 'Body',
|
||||
'widget_settings' => array(
|
||||
'module' => 'text',
|
||||
'settings' => array(
|
||||
'rows' => 20,
|
||||
'summary_rows' => 5,
|
||||
),
|
||||
'type' => 'text_textarea_with_summary',
|
||||
'weight' => -4,
|
||||
),
|
||||
'display_settings' => array(
|
||||
),
|
||||
'description' => '',
|
||||
'required' => FALSE,
|
||||
'global_settings' => array(),
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Prepopulate contents with results.
|
||||
*/
|
||||
protected function setUp() {
|
||||
$this->databaseContents['field_config_instance'] = array(
|
||||
array(
|
||||
'id' => '2',
|
||||
'field_id' => '2',
|
||||
'field_name' => 'body',
|
||||
'entity_type' => 'node',
|
||||
'bundle' => 'page',
|
||||
'data' => 'a:6:{s:5:"label";s:4:"Body";s:6:"widget";a:4:{s:4:"type";s:26:"text_textarea_with_summary";s:8:"settings";a:2:{s:4:"rows";i:20;s:12:"summary_rows";i:5;}s:6:"weight";i:-4;s:6:"module";s:4:"text";}s:8:"settings";a:3:{s:15:"display_summary";b:1;s:15:"text_processing";i:1;s:18:"user_register_form";b:0;}s:7:"display";a:2:{s:7:"default";a:5:{s:5:"label";s:6:"hidden";s:4:"type";s:12:"text_default";s:8:"settings";a:0:{}s:6:"module";s:4:"text";s:6:"weight";i:0;}s:6:"teaser";a:5:{s:5:"label";s:6:"hidden";s:4:"type";s:23:"text_summary_or_trimmed";s:8:"settings";a:1:{s:11:"trim_length";i:600;}s:6:"module";s:4:"text";s:6:"weight";i:0;}}s:8:"required";b:0;s:11:"description";s:0:"";}',
|
||||
'deleted' => '0',
|
||||
),
|
||||
);
|
||||
$this->databaseContents['field_config'] = array(
|
||||
array(
|
||||
'id' => '2',
|
||||
'field_name' => 'body',
|
||||
'type' => 'text_with_summary',
|
||||
'module' => 'text',
|
||||
'active' => '1',
|
||||
'storage_type' => 'field_sql_storage',
|
||||
'storage_module' => 'field_sql_storage',
|
||||
'storage_active' => '1',
|
||||
'locked' => '0',
|
||||
'data' => 'a:6:{s:12:"entity_types";a:1:{i:0;s:4:"node";}s:12:"translatable";b:0;s:8:"settings";a:0:{}s:7:"storage";a:4:{s:4:"type";s:17:"field_sql_storage";s:8:"settings";a:0:{}s:6:"module";s:17:"field_sql_storage";s:6:"active";i:1;}s:12:"foreign keys";a:1:{s:6:"format";a:2:{s:5:"table";s:13:"filter_format";s:7:"columns";a:1:{s:6:"format";s:6:"format";}}}s:7:"indexes";a:1:{s:6:"format";a:1:{i:0;s:6:"format";}}}',
|
||||
'cardinality' => '1',
|
||||
'translatable' => '0',
|
||||
'deleted' => '0',
|
||||
),
|
||||
);
|
||||
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,136 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\field\Unit\Plugin\migrate\source\d7;
|
||||
|
||||
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
|
||||
|
||||
/**
|
||||
* Tests D7 field source plugin.
|
||||
*
|
||||
* @group field
|
||||
*/
|
||||
class FieldTest extends MigrateSqlSourceTestCase {
|
||||
|
||||
const PLUGIN_CLASS = 'Drupal\field\Plugin\migrate\source\d7\Field';
|
||||
|
||||
protected $migrationConfiguration = array(
|
||||
'id' => 'test_field',
|
||||
'source' => array(
|
||||
'plugin' => 'd7_field',
|
||||
),
|
||||
);
|
||||
|
||||
protected $expectedResults = array(
|
||||
array(
|
||||
'field_name' => 'field_file',
|
||||
'type' => 'file',
|
||||
'global_settings' => '',
|
||||
'storage' => array(
|
||||
'active' => 1,
|
||||
'details' => array(
|
||||
'sql' => array(
|
||||
'FIELD_LOAD_CURRENT' => array(
|
||||
'field_data_field_file' => array(
|
||||
'description' => 'field_file_description',
|
||||
'display' => 'field_file_display',
|
||||
'fid' => 'field_file_fid',
|
||||
),
|
||||
),
|
||||
'FIELD_LOAD_REVISION' => array(
|
||||
'field_revision_field_file' => array(
|
||||
'description' => 'field_file_description',
|
||||
'display' => 'field_file_display',
|
||||
'fid' => 'field_file_fid',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
'module' => 'field_sql_storage',
|
||||
'settings' => array(),
|
||||
'type' => 'field_sql_storage',
|
||||
),
|
||||
'module' => 'file',
|
||||
'db_columns' => '',
|
||||
'locked' => 0,
|
||||
'entity_type' => 'node',
|
||||
),
|
||||
array(
|
||||
'field_name' => 'field_file',
|
||||
'type' => 'file',
|
||||
'global_settings' => '',
|
||||
'storage' => array(
|
||||
'active' => 1,
|
||||
'details' => array(
|
||||
'sql' => array(
|
||||
'FIELD_LOAD_CURRENT' => array(
|
||||
'field_data_field_file' => array(
|
||||
'description' => 'field_file_description',
|
||||
'display' => 'field_file_display',
|
||||
'fid' => 'field_file_fid',
|
||||
),
|
||||
),
|
||||
'FIELD_LOAD_REVISION' => array(
|
||||
'field_revision_field_file' => array(
|
||||
'description' => 'field_file_description',
|
||||
'display' => 'field_file_display',
|
||||
'fid' => 'field_file_fid',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
'module' => 'field_sql_storage',
|
||||
'settings' => array(),
|
||||
'type' => 'field_sql_storage',
|
||||
),
|
||||
'module' => 'file',
|
||||
'db_columns' => '',
|
||||
'locked' => 0,
|
||||
'entity_type' => 'user',
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Prepopulate contents with results.
|
||||
*/
|
||||
protected function setUp() {
|
||||
$this->databaseContents['field_config'] = array(
|
||||
array(
|
||||
'id' => '11',
|
||||
'field_name' => 'field_file',
|
||||
'type' => 'file',
|
||||
'module' => 'file',
|
||||
'active' => '1',
|
||||
'storage_type' => 'field_sql_storage',
|
||||
'storage_module' => 'field_sql_storage',
|
||||
'storage_active' => '1',
|
||||
'locked' => '0',
|
||||
'data' => 'a:7:{s:12:"translatable";s:1:"0";s:12:"entity_types";a:0:{}s:8:"settings";a:3:{s:13:"display_field";i:0;s:15:"display_default";i:0;s:10:"uri_scheme";s:6:"public";}s:7:"storage";a:5:{s:4:"type";s:17:"field_sql_storage";s:8:"settings";a:0:{}s:6:"module";s:17:"field_sql_storage";s:6:"active";s:1:"1";s:7:"details";a:1:{s:3:"sql";a:2:{s:18:"FIELD_LOAD_CURRENT";a:1:{s:21:"field_data_field_file";a:3:{s:3:"fid";s:14:"field_file_fid";s:7:"display";s:18:"field_file_display";s:11:"description";s:22:"field_file_description";}}s:19:"FIELD_LOAD_REVISION";a:1:{s:25:"field_revision_field_file";a:3:{s:3:"fid";s:14:"field_file_fid";s:7:"display";s:18:"field_file_display";s:11:"description";s:22:"field_file_description";}}}}}s:12:"foreign keys";a:1:{s:3:"fid";a:2:{s:5:"table";s:12:"file_managed";s:7:"columns";a:1:{s:3:"fid";s:3:"fid";}}}s:7:"indexes";a:1:{s:3:"fid";a:1:{i:0;s:3:"fid";}}s:2:"id";s:2:"11";}',
|
||||
'cardinality' => '1',
|
||||
'translatable' => '0',
|
||||
'deleted' => '0',
|
||||
),
|
||||
);
|
||||
$this->databaseContents['field_config_instance'] = array(
|
||||
array(
|
||||
'id' => '33',
|
||||
'field_id' => '11',
|
||||
'field_name' => 'field_file',
|
||||
'entity_type' => 'user',
|
||||
'bundle' => 'user',
|
||||
'data' => 'a:6:{s:5:"label";s:4:"File";s:6:"widget";a:5:{s:6:"weight";s:1:"8";s:4:"type";s:12:"file_generic";s:6:"module";s:4:"file";s:6:"active";i:1;s:8:"settings";a:1:{s:18:"progress_indicator";s:8:"throbber";}}s:8:"settings";a:5:{s:14:"file_directory";s:0:"";s:15:"file_extensions";s:3:"txt";s:12:"max_filesize";s:0:"";s:17:"description_field";i:0;s:18:"user_register_form";i:0;}s:7:"display";a:1:{s:7:"default";a:5:{s:5:"label";s:5:"above";s:4:"type";s:12:"file_default";s:8:"settings";a:0:{}s:6:"module";s:4:"file";s:6:"weight";i:0;}}s:8:"required";i:0;s:11:"description";s:0:"";}',
|
||||
'deleted' => '0',
|
||||
),
|
||||
array(
|
||||
'id' => '21',
|
||||
'field_id' => '11',
|
||||
'field_name' => 'field_file',
|
||||
'entity_type' => 'node',
|
||||
'bundle' => 'test_content_type',
|
||||
'data' => 'a:6:{s:5:"label";s:4:"File";s:6:"widget";a:5:{s:6:"weight";s:1:"5";s:4:"type";s:12:"file_generic";s:6:"module";s:4:"file";s:6:"active";i:1;s:8:"settings";a:1:{s:18:"progress_indicator";s:8:"throbber";}}s:8:"settings";a:5:{s:14:"file_directory";s:0:"";s:15:"file_extensions";s:15:"txt pdf ods odf";s:12:"max_filesize";s:5:"10 MB";s:17:"description_field";i:1;s:18:"user_register_form";b:0;}s:7:"display";a:1:{s:7:"default";a:5:{s:5:"label";s:5:"above";s:4:"type";s:12:"file_default";s:6:"weight";s:1:"5";s:8:"settings";a:0:{}s:6:"module";s:4:"file";}}s:8:"required";i:0;s:11:"description";s:0:"";}',
|
||||
'deleted' => '0',
|
||||
),
|
||||
);
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,82 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\field\Unit\Plugin\migrate\source\d7;
|
||||
|
||||
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
|
||||
|
||||
/**
|
||||
* Tests D7 view mode source plugin.
|
||||
*
|
||||
* @group field
|
||||
*/
|
||||
class ViewModeTest extends MigrateSqlSourceTestCase {
|
||||
|
||||
const PLUGIN_CLASS = 'Drupal\field\Plugin\migrate\source\d7\ViewMode';
|
||||
|
||||
protected $migrationConfiguration = array(
|
||||
'id' => 'test',
|
||||
'source' => array(
|
||||
'plugin' => 'd7_view_mode',
|
||||
),
|
||||
);
|
||||
|
||||
protected $expectedResults = array(
|
||||
array(
|
||||
'entity_type' => 'node',
|
||||
'view_mode' => 'default',
|
||||
),
|
||||
array(
|
||||
'entity_type' => 'node',
|
||||
'view_mode' => 'teaser',
|
||||
),
|
||||
array(
|
||||
'entity_type' => 'node',
|
||||
'view_mode' => 'custom',
|
||||
),
|
||||
array(
|
||||
'entity_type' => 'user',
|
||||
'view_mode' => 'default',
|
||||
),
|
||||
array(
|
||||
'entity_type' => 'comment',
|
||||
'view_mode' => 'default',
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Prepopulate contents with results.
|
||||
*/
|
||||
protected function setUp() {
|
||||
$this->databaseContents['field_config_instance'] = array(
|
||||
array(
|
||||
'id' => '13',
|
||||
'field_id' => '2',
|
||||
'field_name' => 'body',
|
||||
'entity_type' => 'node',
|
||||
'bundle' => 'forum',
|
||||
'data' => 'a:6:{s:5:"label";s:4:"Body";s:6:"widget";a:4:{s:4:"type";s:26:"text_textarea_with_summary";s:8:"settings";a:2:{s:4:"rows";i:20;s:12:"summary_rows";i:5;}s:6:"weight";i:1;s:6:"module";s:4:"text";}s:8:"settings";a:3:{s:15:"display_summary";b:1;s:15:"text_processing";i:1;s:18:"user_register_form";b:0;}s:7:"display";a:3:{s:7:"default";a:5:{s:5:"label";s:6:"hidden";s:4:"type";s:12:"text_default";s:8:"settings";a:0:{}s:6:"module";s:4:"text";s:6:"weight";i:11;}s:6:"teaser";a:5:{s:5:"label";s:6:"hidden";s:4:"type";s:23:"text_summary_or_trimmed";s:8:"settings";a:1:{s:11:"trim_length";i:600;}s:6:"module";s:4:"text";s:6:"weight";i:11;}s:6:"custom";a:5:{s:5:"label";s:6:"hidden";s:4:"type";s:23:"text_summary_or_trimmed";s:8:"settings";a:0:{}s:6:"module";s:4:"text";s:6:"weight";i:11;}}s:8:"required";b:0;s:11:"description";s:0:"";}',
|
||||
'deleted' => '0',
|
||||
),
|
||||
array(
|
||||
'id' => '33',
|
||||
'field_id' => '11',
|
||||
'field_name' => 'field_file',
|
||||
'entity_type' => 'user',
|
||||
'bundle' => 'user',
|
||||
'data' => 'a:6:{s:5:"label";s:4:"File";s:6:"widget";a:5:{s:6:"weight";s:1:"8";s:4:"type";s:12:"file_generic";s:6:"module";s:4:"file";s:6:"active";i:1;s:8:"settings";a:1:{s:18:"progress_indicator";s:8:"throbber";}}s:8:"settings";a:5:{s:14:"file_directory";s:0:"";s:15:"file_extensions";s:3:"txt";s:12:"max_filesize";s:0:"";s:17:"description_field";i:0;s:18:"user_register_form";i:0;}s:7:"display";a:1:{s:7:"default";a:5:{s:5:"label";s:5:"above";s:4:"type";s:12:"file_default";s:8:"settings";a:0:{}s:6:"module";s:4:"file";s:6:"weight";i:0;}}s:8:"required";i:0;s:11:"description";s:0:"";}',
|
||||
'deleted' => '0',
|
||||
),
|
||||
array(
|
||||
'id' => '12',
|
||||
'field_id' => '1',
|
||||
'field_name' => 'comment_body',
|
||||
'entity_type' => 'comment',
|
||||
'bundle' => 'comment_node_forum',
|
||||
'data' => 'a:6:{s:5:"label";s:7:"Comment";s:8:"settings";a:2:{s:15:"text_processing";i:1;s:18:"user_register_form";b:0;}s:8:"required";b:1;s:7:"display";a:1:{s:7:"default";a:5:{s:5:"label";s:6:"hidden";s:4:"type";s:12:"text_default";s:6:"weight";i:0;s:8:"settings";a:0:{}s:6:"module";s:4:"text";}}s:6:"widget";a:4:{s:4:"type";s:13:"text_textarea";s:8:"settings";a:1:{s:4:"rows";i:5;}s:6:"weight";i:0;s:6:"module";s:4:"text";}s:11:"description";s:0:"";}',
|
||||
'deleted' => '0',
|
||||
),
|
||||
);
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user