Update to Drupal 8.0.0-beta15. For more information, see: https://www.drupal.org/node/2563023

This commit is contained in:
Pantheon Automation 2015-09-04 13:20:09 -07:00 committed by Greg Anderson
parent 2720a9ec4b
commit f3791f1da3
1898 changed files with 54300 additions and 11481 deletions

View file

@ -115,7 +115,7 @@ class BooleanFieldTest extends WebTestBase {
$display = entity_get_display($entity->getEntityTypeId(), $entity->bundle(), 'full');
$content = $display->build($entity);
$this->setRawContent(\Drupal::service('renderer')->renderRoot($content));
$this->assertRaw('<div class="field-item">' . $on . '</div>');
$this->assertRaw('<div class="field__item">' . $on . '</div>');
// Test if we can change the on label.
$on = $this->randomMachineName();

View file

@ -119,6 +119,9 @@ class DisplayApiTest extends FieldUnitTestBase {
function testFieldItemListView() {
$items = $this->entity->get($this->fieldName);
\Drupal::service('theme_handler')->install(['classy']);
$this->config('system.theme')->set('default', 'classy')->save();
// No display settings: check that default display settings are used.
$build = $items->view();
$this->render($build);

View file

@ -0,0 +1,104 @@
<?php
/**
* @file
* Contains \Drupal\field\Tests\Entity\Update\SqlContentEntityStorageSchemaColumnTest.
*/
namespace Drupal\field\Tests\Entity\Update;
use Drupal\Core\Entity\Exception\FieldStorageDefinitionUpdateForbiddenException;
use Drupal\entity_test\Entity\EntityTestRev;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\simpletest\KernelTestBase;
/**
* Tests that schema changes in fields with data are detected during updates.
*
* @group Entity
*/
class SqlContentEntityStorageSchemaColumnTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['entity_test', 'field', 'text', 'user'];
/**
* The created entity.
*
* @var \Drupal\Core\Entity\Entity
*/
protected $entity;
/**
* The field.
*
* @var \Drupal\field\FieldConfigInterface
*/
protected $field;
/**
* The field storage.
*
* @var \Drupal\field\FieldStorageConfigInterface
*/
protected $fieldStorage;
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
$this->installEntitySchema('entity_test_rev');
$this->installEntitySchema('user');
$field_name = 'test';
$this->fieldStorage = FieldStorageConfig::create([
'field_name' => $field_name,
'entity_type' => 'entity_test_rev',
'type' => 'string',
'cardinality' => 1,
]);
$this->fieldStorage->save();
$this->field = FieldConfig::create([
'field_name' => $field_name,
'entity_type' => 'entity_test_rev',
'bundle' => 'entity_test_rev',
'required' => TRUE,
]);
$this->field->save();
// Create an entity with field data.
$this->entity = EntityTestRev::create([
'user_id' => mt_rand(1, 10),
'name' => $this->randomMachineName(),
$field_name => $this->randomString(),
]);
$this->entity->save();
}
/**
* Tests that column-level schema changes are detected for fields with data.
*/
public function testColumnUpdate() {
// Change the field type in the stored schema.
$schema = \Drupal::keyValue('entity.storage_schema.sql')->get('entity_test_rev.field_schema_data.test');
$schema['entity_test_rev__test']['fields']['test_value']['type'] = 'varchar_ascii';
\Drupal::keyValue('entity.storage_schema.sql')->set('entity_test_rev.field_schema_data.test', $schema);
// Now attempt to run automatic updates. An exception should be thrown
// since there is data in the table.
try {
\Drupal::service('entity.definition_update_manager')->applyUpdates();
$this->fail('Failed to detect a schema change in a field with data.');
}
catch (FieldStorageDefinitionUpdateForbiddenException $e) {
$this->pass('Detected a schema change in a field with data.');
}
}
}

View file

@ -72,6 +72,10 @@ class EntityReferenceFormatterTest extends EntityUnitTestBase {
protected function setUp() {
parent::setUp();
// Use Classy theme for testing markup output.
\Drupal::service('theme_handler')->install(['classy']);
$this->config('system.theme')->set('default', 'classy')->save();
// Grant the 'view test entity' permission.
$this->installConfig(array('user'));
Role::load(RoleInterface::ANONYMOUS_ID)
@ -170,7 +174,7 @@ class EntityReferenceFormatterTest extends EntityUnitTestBase {
$formatter = 'entity_reference_entity_id';
$build = $this->buildRenderArray([$this->referencedEntity, $this->unsavedReferencedEntity], $formatter);
$this->assertEqual($build[0]['#markup'], $this->referencedEntity->id(), sprintf('The markup returned by the %s formatter is correct for an item with a saved entity.', $formatter));
$this->assertEqual($build[0]['#plain_text'], $this->referencedEntity->id(), sprintf('The markup returned by the %s formatter is correct for an item with a saved entity.', $formatter));
$this->assertEqual($build[0]['#cache']['tags'], $this->referencedEntity->getCacheTags(), sprintf('The %s formatter has the expected cache tags.', $formatter));
$this->assertTrue(!isset($build[1]), sprintf('The markup returned by the %s formatter is correct for an item with a unsaved entity.', $formatter));
}
@ -185,18 +189,14 @@ class EntityReferenceFormatterTest extends EntityUnitTestBase {
$build = $this->buildRenderArray([$this->referencedEntity, $this->unsavedReferencedEntity], $formatter);
// Test the first field item.
$expected_rendered_name_field_1 = '<div class="field field-entity-test--name field-name-name field-type-string field-label-hidden">
<div class="field-items">
<div class="field-item">' . $this->referencedEntity->label() . '</div>
</div>
</div>
';
$expected_rendered_body_field_1 = '<div class="field field-entity-test--body field-name-body field-type-text field-label-above">
<div class="field-label">Body</div>
<div class="field-items">
<div class="field-item"><p>Hello, world!</p></div>
</div>
</div>
$expected_rendered_name_field_1 = '
<div class="field field--name-name field--type-string field--label-hidden field__item">' . $this->referencedEntity->label() . '</div>
';
$expected_rendered_body_field_1 = '
<div class="clearfix text-formatted field field--name-body field--type-text field--label-above">
<div class="field__label">Body</div>
<div class="field__item"><p>Hello, world!</p></div>
</div>
';
$renderer->renderRoot($build[0]);
$this->assertEqual($build[0]['#markup'], 'default | ' . $this->referencedEntity->label() . $expected_rendered_name_field_1 . $expected_rendered_body_field_1, sprintf('The markup returned by the %s formatter is correct for an item with a saved entity.', $formatter));
@ -244,7 +244,7 @@ class EntityReferenceFormatterTest extends EntityUnitTestBase {
// The second referenced entity is "autocreated", therefore not saved and
// lacking any URL info.
$expected_item_2 = array(
'#markup' => $this->unsavedReferencedEntity->label(),
'#plain_text' => $this->unsavedReferencedEntity->label(),
'#cache' => array(
'contexts' => [
'user.permissions',
@ -257,8 +257,8 @@ class EntityReferenceFormatterTest extends EntityUnitTestBase {
// Test with the 'link' setting set to FALSE.
$build = $this->buildRenderArray([$this->referencedEntity, $this->unsavedReferencedEntity], $formatter, array('link' => FALSE));
$this->assertEqual($build[0]['#markup'], $this->referencedEntity->label(), sprintf('The markup returned by the %s formatter is correct for an item with a saved entity.', $formatter));
$this->assertEqual($build[1]['#markup'], $this->unsavedReferencedEntity->label(), sprintf('The markup returned by the %s formatter is correct for an item with a unsaved entity.', $formatter));
$this->assertEqual($build[0]['#plain_text'], $this->referencedEntity->label(), sprintf('The markup returned by the %s formatter is correct for an item with a saved entity.', $formatter));
$this->assertEqual($build[1]['#plain_text'], $this->unsavedReferencedEntity->label(), sprintf('The markup returned by the %s formatter is correct for an item with a unsaved entity.', $formatter));
// Test an entity type that doesn't have any link templates, which means
// \Drupal\Core\Entity\EntityInterface::urlInfo() will throw an exception
@ -273,7 +273,7 @@ class EntityReferenceFormatterTest extends EntityUnitTestBase {
$referenced_entity_with_no_link_template->save();
$build = $this->buildRenderArray([$referenced_entity_with_no_link_template], $formatter, array('link' => TRUE));
$this->assertEqual($build[0]['#markup'], $referenced_entity_with_no_link_template->label(), sprintf('The markup returned by the %s formatter is correct for an entity type with no valid link template.', $formatter));
$this->assertEqual($build[0]['#plain_text'], $referenced_entity_with_no_link_template->label(), sprintf('The markup returned by the %s formatter is correct for an entity type with no valid link template.', $formatter));
}
/**

View file

@ -10,6 +10,7 @@ namespace Drupal\field\Tests\EntityReference;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FieldItemInterface;
use Drupal\Core\StringTranslation\TranslationWrapper;
use Drupal\Core\Language\LanguageInterface;
use Drupal\entity_reference\Tests\EntityReferenceTestTrait;
use Drupal\entity_test\Entity\EntityTest;
@ -111,6 +112,10 @@ class EntityReferenceItemTest extends FieldUnitTestBase {
$this->assertEqual($entity->field_test_taxonomy_term->entity->getName(), $this->term->getName());
$this->assertEqual($entity->field_test_taxonomy_term->entity->id(), $tid);
$this->assertEqual($entity->field_test_taxonomy_term->entity->uuid(), $this->term->uuid());
// Verify that the label for the target ID property definition is correct.
$label = $entity->field_test_taxonomy_term->getFieldDefinition()->getFieldStorageDefinition()->getPropertyDefinition('target_id')->getLabel();
$this->assertTrue($label instanceof TranslationWrapper);
$this->assertEqual($label->render(), 'Taxonomy term ID');
// Change the name of the term via the reference.
$new_name = $this->randomMachineName();
@ -178,6 +183,10 @@ class EntityReferenceItemTest extends FieldUnitTestBase {
$storage = \Drupal::entityManager()->getStorage('entity_test');
$storage->resetCache();
$this->assertEqual($this->entityStringId->id(), $storage->load($entity->id())->field_test_entity_test_string_id->target_id);
// Verify that the label for the target ID property definition is correct.
$label = $entity->field_test_taxonomy_term->getFieldDefinition()->getFieldStorageDefinition()->getPropertyDefinition('target_id')->getLabel();
$this->assertTrue($label instanceof TranslationWrapper);
$this->assertEqual($label->render(), 'Taxonomy term ID');
}
/**

View file

@ -8,6 +8,8 @@
namespace Drupal\field\Tests;
use Drupal\Core\Entity\Sql\SqlContentEntityStorage;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
/**
* Tests counting field data records and the hasData() method on
@ -146,6 +148,20 @@ class FieldDataCountTest extends FieldUnitTestBase {
* Verify that we can count a table that contains an entry with index 0.
*/
public function testCountWithIndex0() {
// Create a field that will require dedicated storage.
/** @var \Drupal\field\Entity\FieldStorageConfig $field_storage */
$field_storage = FieldStorageConfig::create(array(
'field_name' => 'field_int',
'entity_type' => 'user',
'type' => 'integer',
'cardinality' => 2,
));
$field_storage->save();
FieldConfig::create(array(
'field_storage' => $field_storage,
'bundle' => 'user',
))->save();
// Create an entry for the anonymous user, who has user ID 0.
$user = $this->storageUser
->create(array(
@ -153,11 +169,17 @@ class FieldDataCountTest extends FieldUnitTestBase {
'name' => 'anonymous',
'mail' => NULL,
'status' => FALSE,
'field_int' => 42,
));
$user->save();
// Test shared table storage.
$storage = $user->getFieldDefinition('name')->getFieldStorageDefinition();
$this->assertIdentical(TRUE, $this->storageUser->countFieldData($storage, TRUE));
// Test dedicated table storage.
$storage = $user->getFieldDefinition('field_int')->getFieldStorageDefinition();
$this->assertIdentical(TRUE, $this->storageUser->countFieldData($storage, TRUE));
}
}

View file

@ -7,7 +7,7 @@
namespace Drupal\field\Tests;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Component\Utility\Html;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Form\FormState;
use Drupal\field\Entity\FieldConfig;
@ -105,7 +105,7 @@ class FormTest extends FieldTestBase {
$this->drupalGet('entity_test/add');
// Create token value expected for description.
$token_description = SafeMarkup::checkPlain($this->config('system.site')->get('name')) . '_description';
$token_description = Html::escape($this->config('system.site')->get('name')) . '_description';
$this->assertText($token_description, 'Token replacement for description is displayed');
$this->assertFieldByName("{$field_name}[0][value]", '', 'Widget is displayed');
$this->assertNoField("{$field_name}[1][value]", 'No extraneous widget is displayed');
@ -334,12 +334,12 @@ class FormTest extends FieldTestBase {
// Display creation form -> 1 widget.
$this->drupalGet('entity_test/add');
// Check that the Required symbol is present for the multifield label.
$this->assertRaw(SafeMarkup::format('<h4 class="label form-required">@label</h4>', array('@label' => $this->field['label'])),
'Required symbol added field label.');
$element = $this->xpath('//h4[contains(@class, "label") and contains(@class, "js-form-required") and contains(text(), :value)]', array(':value' => $this->field['label']));
$this->assertTrue(isset($element[0]), 'Required symbol added field label.');
// Check that the label of the field input is visually hidden and contains
// the field title and an indication of the delta for a11y.
$this->assertRaw(SafeMarkup::format('<label for="edit-field-unlimited-0-value" class="visually-hidden form-required">@label (value 1)</label>', array('@label' => $this->field['label'])),
'Required symbol not added for field input.');
$element = $this->xpath('//label[@for=:for and contains(@class, "js-form-required") and contains(text(), :value)]', array(':for' => 'edit-field-unlimited-0-value', ':value' => $this->field['label'] . ' (value 1)'));
$this->assertTrue(isset($element[0]), 'Required symbol not added for field input.');
}
/**

View file

@ -0,0 +1,228 @@
<?php
/**
* @file
* Contains \Drupal\field\Tests\Migrate\d6\MigrateFieldFormatterSettingsTest.
*/
namespace Drupal\field\Tests\Migrate\d6;
use Drupal\Core\Entity\Entity\EntityViewMode;
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
/**
* Upgrade field formatter settings to entity.display.*.*.yml.
*
* @group migrate_drupal_6
*/
class MigrateFieldFormatterSettingsTest extends MigrateDrupal6TestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('node', 'field', 'datetime', 'image', 'text', 'link', 'file', 'telephone');
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installConfig(['node']);
entity_create('node_type', array('type' => 'test_page'))->save();
entity_create('node_type', array('type' => 'story'))->save();
// Create the node preview view mode.
EntityViewMode::create(array('id' => 'node.preview', 'targetEntityType' => 'node'))->save();
// Add some id mappings for the dependant migrations.
$id_mappings = array(
'd6_view_modes' => array(
array(array(1), array('node', 'preview')),
array(array(4), array('node', 'rss')),
array(array('teaser'), array('node', 'teaser')),
array(array('full'), array('node', 'full')),
),
'd6_field_instance' => array(
array(array('fieldname', 'page'), array('node', 'fieldname', 'page')),
),
'd6_field' => array(
array(array('field_test'), array('node', 'field_test')),
array(array('field_test_two'), array('node', 'field_test_two')),
array(array('field_test_three'), array('node', 'field_test_three')),
array(array('field_test_email'), array('node', 'field_test_email')),
array(array('field_test_link'), array('node', 'field_test_link')),
array(array('field_test_filefield'), array('node', 'field_test_filefield')),
array(array('field_test_imagefield'), array('node', 'field_test_imagefield')),
array(array('field_test_phone'), array('node', 'field_test_phone')),
array(array('field_test_date'), array('node', 'field_test_date')),
array(array('field_test_datestamp'), array('node', 'field_test_datestamp')),
array(array('field_test_datetime'), array('node', 'field_test_datetime')),
array(array('field_test_exclude_unset'), array('node', 'field_test_exclude_unset')),
),
);
$this->prepareMigrations($id_mappings);
$this->executeMigration('d6_field_formatter_settings');
}
/**
* Test that migrated entity display settings can be loaded using D8 API's.
*/
public function testEntityDisplaySettings() {
// Run tests.
$field_name = "field_test";
$expected = array(
'label' => 'above',
'weight' => 1,
'type' => 'text_trimmed',
'settings' => array('trim_length' => 600),
'third_party_settings' => array(),
);
// Can we load any entity display.
$display = entity_load('entity_view_display', 'node.story.teaser');
$this->assertIdentical($expected, $display->getComponent($field_name));
// Test migrate worked with multiple bundles.
$display = entity_load('entity_view_display', 'node.test_page.teaser');
$expected['weight'] = 35;
$this->assertIdentical($expected, $display->getComponent($field_name));
// Test RSS because that has been converted from 4 to rss.
$display = entity_load('entity_view_display', 'node.story.rss');
$expected['weight'] = 1;
$this->assertIdentical($expected, $display->getComponent($field_name));
// Test the default format with text_default which comes from a static map.
$expected['type'] = 'text_default';
$expected['settings'] = array();
$display = entity_load('entity_view_display', 'node.story.default');
$this->assertIdentical($expected, $display->getComponent($field_name));
// Check that we can migrate multiple fields.
$content = $display->get('content');
$this->assertTrue(isset($content['field_test']), 'Settings for field_test exist.');
$this->assertTrue(isset($content['field_test_two']), "Settings for field_test_two exist.");
// Check that we can migrate a field where exclude is not set.
$this->assertTrue(isset($content['field_test_exclude_unset']), "Settings for field_test_exclude_unset exist.");
// Test the number field formatter settings are correct.
$expected['weight'] = 1;
$expected['type'] = 'number_integer';
$expected['settings'] = array(
'thousand_separator' => ',',
'prefix_suffix' => TRUE,
);
$component = $display->getComponent('field_test_two');
$this->assertIdentical($expected, $component);
$expected['weight'] = 2;
$expected['type'] = 'number_decimal';
$expected['settings'] = array(
'scale' => 2,
'decimal_separator' => '.',
'thousand_separator' => ',',
'prefix_suffix' => TRUE,
);
$component = $display->getComponent('field_test_three');
$this->assertIdentical($expected, $component);
// Test the email field formatter settings are correct.
$expected['weight'] = 6;
$expected['type'] = 'email_mailto';
$expected['settings'] = array();
$component = $display->getComponent('field_test_email');
$this->assertIdentical($expected, $component);
// Test the link field formatter settings.
$expected['weight'] = 7;
$expected['type'] = 'link';
$expected['settings'] = array(
'trim_length' => 80,
'url_only' => TRUE,
'url_plain' => TRUE,
'rel' => '0',
'target' => '0',
);
$component = $display->getComponent('field_test_link');
$this->assertIdentical($expected, $component);
$expected['settings']['url_only'] = FALSE;
$expected['settings']['url_plain'] = FALSE;
$display = entity_load('entity_view_display', 'node.story.teaser');
$component = $display->getComponent('field_test_link');
$this->assertIdentical($expected, $component);
// Test the file field formatter settings.
$expected['weight'] = 8;
$expected['type'] = 'file_default';
$expected['settings'] = array();
$component = $display->getComponent('field_test_filefield');
$this->assertIdentical($expected, $component);
$display = entity_load('entity_view_display', 'node.story.default');
$expected['type'] = 'file_url_plain';
$component = $display->getComponent('field_test_filefield');
$this->assertIdentical($expected, $component);
// Test the image field formatter settings.
$expected['weight'] = 9;
$expected['type'] = 'image';
$expected['settings'] = array('image_style' => '', 'image_link' => '');
$component = $display->getComponent('field_test_imagefield');
$this->assertIdentical($expected, $component);
$display = entity_load('entity_view_display', 'node.story.teaser');
$expected['settings']['image_link'] = 'file';
$component = $display->getComponent('field_test_imagefield');
$this->assertIdentical($expected, $component);
// Test phone field.
$expected['weight'] = 13;
$expected['type'] = 'basic_string';
$expected['settings'] = array();
$component = $display->getComponent('field_test_phone');
$this->assertIdentical($expected, $component);
// Test date field.
$defaults = array('format_type' => 'fallback', 'timezone_override' => '',);
$expected['weight'] = 10;
$expected['type'] = 'datetime_default';
$expected['settings'] = array('format_type' => 'fallback') + $defaults;
$component = $display->getComponent('field_test_date');
$this->assertIdentical($expected, $component);
$display = entity_load('entity_view_display', 'node.story.default');
$expected['settings']['format_type'] = 'long';
$component = $display->getComponent('field_test_date');
$this->assertIdentical($expected, $component);
// Test date stamp field.
$expected['weight'] = 11;
$expected['settings']['format_type'] = 'fallback';
$component = $display->getComponent('field_test_datestamp');
$this->assertIdentical($expected, $component);
$display = entity_load('entity_view_display', 'node.story.teaser');
$expected['settings'] = array('format_type' => 'medium') + $defaults;
$component = $display->getComponent('field_test_datestamp');
$this->assertIdentical($expected, $component);
// Test datetime field.
$expected['weight'] = 12;
$expected['settings'] = array('format_type' => 'short') + $defaults;
$component = $display->getComponent('field_test_datetime');
$this->assertIdentical($expected, $component);
$display = entity_load('entity_view_display', 'node.story.default');
$expected['settings']['format_type'] = 'fallback';
$component = $display->getComponent('field_test_datetime');
$this->assertIdentical($expected, $component);
// Test a date field with a random format which should be mapped
// to datetime_default.
$display = entity_load('entity_view_display', 'node.story.rss');
$expected['settings']['format_type'] = 'fallback';
$component = $display->getComponent('field_test_datetime');
$this->assertIdentical($expected, $component);
// Test that our Id map has the correct data.
$this->assertIdentical(array('node', 'story', 'teaser', 'field_test'), entity_load('migration', 'd6_field_formatter_settings')->getIdMap()->lookupDestinationID(array('story', 'teaser', 'node', 'field_test')));
}
}

View file

@ -0,0 +1,175 @@
<?php
/**
* @file
* Contains \Drupal\field\Tests\Migrate\d6\MigrateFieldInstanceTest.
*/
namespace Drupal\field\Tests\Migrate\d6;
use Drupal\field\Entity\FieldConfig;
use Drupal\link\LinkItemInterface;
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
/**
* Migrate field instances.
*
* @group migrate_drupal_6
*/
class MigrateFieldInstanceTest extends MigrateDrupal6TestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array(
'telephone',
'link',
'file',
'image',
'datetime',
'node',
'field',
'text',
);
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
// Add some id mappings for the dependant migrations.
$id_mappings = array(
'd6_field' => array(
array(array('field_test'), array('node', 'field_test')),
array(array('field_test_two'), array('node', 'field_test_two')),
array(array('field_test_three'), array('node', 'field_test_three')),
array(array('field_test_four'), array('node', 'field_test_four')),
array(array('field_test_email'), array('node', 'field_test_email')),
array(array('field_test_link'), array('node', 'field_test_link')),
array(array('field_test_filefield'), array('node', 'field_test_filefield')),
array(array('field_test_imagefield'), array('node', 'field_test_imagefield')),
array(array('field_test_phone'), array('node', 'field_test_phone')),
array(array('field_test_date'), array('node', 'field_test_date')),
array(array('field_test_datestamp'), array('node', 'field_test_datestamp')),
array(array('field_test_datetime'), array('node', 'field_test_datetime')),
),
'd6_node_type' => array(
array(array('page'), array('page')),
array(array('story'), array('story')),
array(array('test_page'), array('test_page')),
),
);
$this->prepareMigrations($id_mappings);
entity_create('node_type', array('type' => 'page'))->save();
entity_create('node_type', array('type' => 'story'))->save();
entity_create('node_type', array('type' => 'test_page'))->save();
$this->createFields();
$this->executeMigration('d6_field_instance');
}
/**
* Tests migration of file variables to file.settings.yml.
*/
public function testFieldInstanceSettings() {
$entity = entity_create('node', array('type' => 'story'));
// Test a text field.
$field = FieldConfig::load('node.story.field_test');
$this->assertIdentical('Text Field', $field->label());
$expected = array('max_length' => 255);
$this->assertIdentical($expected, $field->getSettings());
$this->assertIdentical('text for default value', $entity->field_test->value);
// Test a number field.
$field = FieldConfig::load('node.story.field_test_two');
$this->assertIdentical('Integer Field', $field->label());
$expected = array(
'min' => 10,
'max' => 100,
'prefix' => 'pref',
'suffix' => 'suf',
'unsigned' => FALSE,
'size' => 'normal',
);
$this->assertIdentical($expected, $field->getSettings());
$field = FieldConfig::load('node.story.field_test_four');
$this->assertIdentical('Float Field', $field->label());
$expected = array(
'min' => 100.0,
'max' => 200.0,
'prefix' => 'id-',
'suffix' => '',
);
$this->assertIdentical($expected, $field->getSettings());
// Test email field.
$field = FieldConfig::load('node.story.field_test_email');
$this->assertIdentical('Email Field', $field->label());
$this->assertIdentical('benjy@example.com', $entity->field_test_email->value);
// Test a filefield.
$field = FieldConfig::load('node.story.field_test_filefield');
$this->assertIdentical('File Field', $field->label());
$expected = array(
'file_extensions' => 'txt pdf doc',
'file_directory' => 'images',
'description_field' => TRUE,
'max_filesize' => '200KB',
'target_type' => 'file',
'display_field' => FALSE,
'display_default' => FALSE,
'uri_scheme' => 'public',
// This value should be 'default:file' but the test does not migrate field
// storages so we end up with the default value for this setting.
'handler' => 'default:node',
'handler_settings' => array(),
'target_bundle' => NULL,
);
$field_settings = $field->getSettings();
ksort($expected);
ksort($field_settings);
// This is the only way to compare arrays.
$this->assertIdentical($expected, $field_settings);
// Test a link field.
$field = FieldConfig::load('node.story.field_test_link');
$this->assertIdentical('Link Field', $field->label());
$expected = array('title' => 2, 'link_type' => LinkItemInterface::LINK_GENERIC);
$this->assertIdentical($expected, $field->getSettings());
$this->assertIdentical('default link title', $entity->field_test_link->title, 'Field field_test_link default title is correct.');
$this->assertIdentical('https://www.drupal.org', $entity->field_test_link->url, 'Field field_test_link default title is correct.');
$this->assertIdentical([], $entity->field_test_link->options['attributes']);
}
/**
* Helper to create fields.
*/
protected function createFields() {
$fields = array(
'field_test' => 'text',
'field_test_two' => 'integer',
'field_test_three' => 'decimal',
'field_test_four' => 'float',
'field_test_email' => 'email',
'field_test_link' => 'link',
'field_test_filefield' => 'file',
'field_test_imagefield' => 'image',
'field_test_phone' => 'telephone',
'field_test_date' => 'datetime',
'field_test_datestamp' => 'datetime',
'field_test_datetime' => 'datetime',
);
foreach ($fields as $name => $type) {
entity_create('field_storage_config', array(
'field_name' => $name,
'entity_type' => 'node',
'type' => $type,
))->save();
}
}
}

View file

@ -0,0 +1,107 @@
<?php
/**
* @file
* Contains \Drupal\field\Tests\Migrate\d6\MigrateFieldTest.
*/
namespace Drupal\field\Tests\Migrate\d6;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
/**
* Migrate fields.
*
* @group migrate_drupal_6
*/
class MigrateFieldTest extends MigrateDrupal6TestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('field', 'telephone', 'link', 'file', 'image', 'datetime', 'node', 'options', 'text');
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->executeMigration('d6_field');
}
/**
* Tests the Drupal 6 field to Drupal 8 migration.
*/
public function testFields() {
// Text field.
/** @var \Drupal\field\Entity\FieldStorageConfig $field_storage */
$field_storage = FieldStorageConfig::load('node.field_test');
$expected = array('max_length' => 255);
$this->assertIdentical("text", $field_storage->getType(), t('Field type is @fieldtype. It should be text.', array('@fieldtype' => $field_storage->getType())));
$this->assertIdentical($expected, $field_storage->getSettings(), "Field type text settings are correct");
// Integer field.
$field_storage = FieldStorageConfig::load('node.field_test_two');
$this->assertIdentical("integer", $field_storage->getType(), t('Field type is @fieldtype. It should be integer.', array('@fieldtype' => $field_storage->getType())));
// Float field.
$field_storage = FieldStorageConfig::load('node.field_test_three');
$this->assertIdentical("decimal", $field_storage->getType(), t('Field type is @fieldtype. It should be decimal.', array('@fieldtype' => $field_storage->getType())));
// Link field.
$field_storage = FieldStorageConfig::load('node.field_test_link');
$this->assertIdentical("link", $field_storage->getType(), t('Field type is @fieldtype. It should be link.', array('@fieldtype' => $field_storage->getType())));
// File field.
$field_storage = FieldStorageConfig::load('node.field_test_filefield');
$this->assertIdentical("file", $field_storage->getType(), t('Field type is @fieldtype. It should be file.', array('@fieldtype' => $field_storage->getType())));
$field_storage = FieldStorageConfig::load('node.field_test_imagefield');
$this->assertIdentical("image", $field_storage->getType(), t('Field type is @fieldtype. It should be image.', array('@fieldtype' => $field_storage->getType())));
$settings = $field_storage->getSettings();
$this->assertIdentical('file', $settings['target_type']);
$this->assertIdentical('public', $settings['uri_scheme']);
$this->assertIdentical(array(), array_filter($settings['default_image']));
// Phone field.
$field_storage = FieldStorageConfig::load('node.field_test_phone');
$this->assertIdentical("telephone", $field_storage->getType(), t('Field type is @fieldtype. It should be telephone.', array('@fieldtype' => $field_storage->getType())));
// Date field.
$field_storage = FieldStorageConfig::load('node.field_test_datetime');
$this->assertIdentical("datetime", $field_storage->getType(), t('Field type is @fieldtype. It should be datetime.', array('@fieldtype' => $field_storage->getType())));
// Decimal field with radio buttons.
$field_storage = FieldStorageConfig::load('node.field_test_decimal_radio_buttons');
$this->assertIdentical("list_float", $field_storage->getType(), t('Field type is @fieldtype. It should be list_float.', array('@fieldtype' => $field_storage->getType())));
$this->assertNotNull($field_storage->getSetting('allowed_values')['1.2'], t('First allowed value key is set to 1.2'));
$this->assertNotNull($field_storage->getSetting('allowed_values')['2.1'], t('Second allowed value key is set to 2.1'));
$this->assertIdentical('1.2', $field_storage->getSetting('allowed_values')['1.2'], t('First allowed value is set to 1.2'));
$this->assertIdentical('2.1', $field_storage->getSetting('allowed_values')['2.1'], t('Second allowed value is set to 1.2'));
// Float field with a single checkbox.
$field_storage = FieldStorageConfig::load('node.field_test_float_single_checkbox');
$this->assertIdentical("boolean", $field_storage->getType(), t('Field type is @fieldtype. It should be boolean.', array('@fieldtype' => $field_storage->getType())));
// Integer field with a select list.
$field_storage = FieldStorageConfig::load('node.field_test_integer_selectlist');
$this->assertIdentical("list_integer", $field_storage->getType(), t('Field type is @fieldtype. It should be list_integer.', array('@fieldtype' => $field_storage->getType())));
$this->assertNotNull($field_storage->getSetting('allowed_values')['1234'], t('First allowed value key is set to 1234'));
$this->assertNotNull($field_storage->getSetting('allowed_values')['2341'], t('Second allowed value key is set to 2341'));
$this->assertNotNull($field_storage->getSetting('allowed_values')['3412'], t('Third allowed value key is set to 3412'));
$this->assertNotNull($field_storage->getSetting('allowed_values')['4123'], t('Fourth allowed value key is set to 4123'));
$this->assertIdentical('1234', $field_storage->getSetting('allowed_values')['1234'], t('First allowed value is set to 1234'));
$this->assertIdentical('2341', $field_storage->getSetting('allowed_values')['2341'], t('Second allowed value is set to 2341'));
$this->assertIdentical('3412', $field_storage->getSetting('allowed_values')['3412'], t('Third allowed value is set to 3412'));
$this->assertIdentical('4123', $field_storage->getSetting('allowed_values')['4123'], t('Fourth allowed value is set to 4123'));
// Text field with a single checkbox.
$field_storage = FieldStorageConfig::load('node.field_test_text_single_checkbox');
$this->assertIdentical("boolean", $field_storage->getType(), t('Field type is @fieldtype. It should be boolean.', array('@fieldtype' => $field_storage->getType())));
}
}

View file

@ -0,0 +1,144 @@
<?php
/**
* @file
* Contains \Drupal\field\Tests\Migrate\d6\MigrateFieldWidgetSettingsTest.
*/
namespace Drupal\field\Tests\Migrate\d6;
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
/**
* Migrate field widget settings.
*
* @group migrate_drupal_6
*/
class MigrateFieldWidgetSettingsTest extends MigrateDrupal6TestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array(
'field',
'telephone',
'link',
'file',
'image',
'datetime',
'node',
'text',
);
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
entity_create('node_type', array('type' => 'test_page'))->save();
entity_create('node_type', array('type' => 'story'))->save();
// Add some id mappings for the dependant migrations.
$id_mappings = array(
'd6_field_instance' => array(
array(array('fieldname', 'page'), array('node', 'fieldname', 'page')),
),
'd6_field' => array(
array(array('field_test'), array('node', 'field_test')),
array(array('field_test_two'), array('node', 'field_test_two')),
array(array('field_test_three'), array('node', 'field_test_three')),
array(array('field_test_email'), array('node', 'field_test_email')),
array(array('field_test_link'), array('node', 'field_test_link')),
array(array('field_test_filefield'), array('node', 'field_test_filefield')),
array(array('field_test_imagefield'), array('node', 'field_test_imagefield')),
array(array('field_test_phone'), array('node', 'field_test_phone')),
array(array('field_test_date'), array('node', 'field_test_date')),
array(array('field_test_datestamp'), array('node', 'field_test_datestamp')),
array(array('field_test_datetime'), array('node', 'field_test_datetime')),
),
);
$this->prepareMigrations($id_mappings);
$this->executeMigration('d6_field_instance_widget_settings');
}
/**
* Test that migrated view modes can be loaded using D8 API's.
*/
public function testWidgetSettings() {
// Test the config can be loaded.
$form_display = entity_load('entity_form_display', 'node.story.default');
$this->assertIdentical(FALSE, is_null($form_display), "Form display node.story.default loaded with config.");
// Text field.
$component = $form_display->getComponent('field_test');
$expected = array('weight' => 1, 'type' => 'text_textfield');
$expected['settings'] = array('size' => 60, 'placeholder' => '');
$expected['third_party_settings'] = array();
$this->assertIdentical($expected, $component, 'Text field settings are correct.');
// Integer field.
$component = $form_display->getComponent('field_test_two');
$expected['type'] = 'number';
$expected['weight'] = 1;
$expected['settings'] = array('placeholder' => '');
$this->assertIdentical($expected, $component);
// Float field.
$component = $form_display->getComponent('field_test_three');
$expected['weight'] = 2;
$this->assertIdentical($expected, $component);
// Email field.
$component = $form_display->getComponent('field_test_email');
$expected['type'] = 'email_default';
$expected['weight'] = 6;
$this->assertIdentical($expected, $component);
// Link field.
$component = $form_display->getComponent('field_test_link');
$this->assertIdentical('link_default', $component['type']);
$this->assertIdentical(7, $component['weight']);
$this->assertFalse(array_filter($component['settings']));
// File field.
$component = $form_display->getComponent('field_test_filefield');
$expected['type'] = 'file_generic';
$expected['weight'] = 8;
$expected['settings'] = array('progress_indicator' => 'bar');
$this->assertIdentical($expected, $component);
// Image field.
$component = $form_display->getComponent('field_test_imagefield');
$expected['type'] = 'image_image';
$expected['weight'] = 9;
$expected['settings'] = array('progress_indicator' => 'bar', 'preview_image_style' => 'thumbnail');
$this->assertIdentical($expected, $component);
// Phone field.
$component = $form_display->getComponent('field_test_phone');
$expected['type'] = 'telephone_default';
$expected['weight'] = 13;
$expected['settings'] = array('placeholder' => '');
$this->assertIdentical($expected, $component);
// Date fields.
$component = $form_display->getComponent('field_test_date');
$expected['type'] = 'datetime_default';
$expected['weight'] = 10;
$expected['settings'] = array();
$this->assertIdentical($expected, $component);
$component = $form_display->getComponent('field_test_datestamp');
$expected['weight'] = 11;
$this->assertIdentical($expected, $component);
$component = $form_display->getComponent('field_test_datetime');
$expected['weight'] = 12;
$this->assertIdentical($expected, $component);
}
}

View file

@ -0,0 +1,283 @@
<?php
/**
* @file
* Contains \Drupal\field\Tests\Migrate\d7\MigrateFieldFormatterSettingsTest.
*/
namespace Drupal\field\Tests\Migrate\d7;
use Drupal\comment\Entity\CommentType;
use Drupal\Core\Database\Database;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase;
use Drupal\node\Entity\NodeType;
/**
* Tests migration of D7 field formatter settings.
*
* @group field
*/
class MigrateFieldFormatterSettingsTest extends MigrateDrupal7TestBase {
public static $modules = [
'comment',
'datetime',
'entity_reference',
'file',
'image',
'link',
'node',
'telephone',
'text',
];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installEntitySchema('comment');
CommentType::create([
'id' => 'comment_node_page',
'label' => $this->randomMachineName(),
])->save();
CommentType::create([
'id' => 'comment_node_article',
'label' => $this->randomMachineName(),
])->save();
CommentType::create([
'id' => 'comment_node_blog',
'label' => $this->randomMachineName(),
])->save();
CommentType::create([
'id' => 'comment_node_book',
'label' => $this->randomMachineName(),
])->save();
CommentType::create([
'id' => 'comment_node_forum',
'label' => $this->randomMachineName(),
])->save();
CommentType::create([
'id' => 'comment_node_test_content_type',
'label' => $this->randomMachineName(),
])->save();
$this->installEntitySchema('node');
NodeType::create([
'type' => 'page',
'label' => $this->randomMachineName(),
])->save();
NodeType::create([
'type' => 'article',
'label' => $this->randomMachineName(),
])->save();
NodeType::create([
'type' => 'blog',
'label' => $this->randomMachineName(),
])->save();
NodeType::create([
'type' => 'book',
'label' => $this->randomMachineName(),
])->save();
NodeType::create([
'type' => 'forum',
'label' => $this->randomMachineName(),
])->save();
NodeType::create([
'type' => 'test_content_type',
'label' => $this->randomMachineName(),
])->save();
// Give one unfortunate field instance invalid display settings to ensure
// that the migration provides an empty array as a default (thus avoiding
// an "unsupported operand types" fatal).
Database::getConnection('default', 'migrate')
->update('field_config_instance')
->fields(array(
'data' => serialize(array (
'label' => 'Body',
'widget' =>
array (
'type' => 'text_textarea_with_summary',
'settings' =>
array (
'rows' => 20,
'summary_rows' => 5,
),
'weight' => -4,
'module' => 'text',
),
'settings' =>
array (
'display_summary' => true,
'text_processing' => 1,
'user_register_form' => false,
),
'display' =>
array (
'default' =>
array (
'label' => 'hidden',
'type' => 'text_default',
'settings' =>
array (
),
'module' => 'text',
'weight' => 0,
),
'teaser' =>
array (
'label' => 'hidden',
'type' => 'text_summary_or_trimmed',
// settings is always expected to be an array. Making it NULL
// causes a fatal.
'settings' => NULL,
'module' => 'text',
'weight' => 0,
),
),
'required' => false,
'description' => '',
)),
))
->condition('entity_type', 'node')
->condition('bundle', 'article')
->condition('field_name', 'body')
->execute();
$this->executeMigration('d7_field');
$this->executeMigration('d7_field_instance');
$this->executeMigration('d7_view_modes');
$this->executeMigration('d7_field_formatter_settings');
}
/**
* Asserts various aspects of a view display.
*
* @param string $id
* The view display ID.
*/
protected function assertEntity($id) {
$display = EntityViewDisplay::load($id);
$this->assertTrue($display instanceof EntityViewDisplayInterface);
}
/**
* Asserts various aspects of a particular component of a view display.
*
* @param string $display_id
* The view display ID.
* @param string $component_id
* The component ID.
* @param string $type
* The expected component type (formatter plugin ID).
* @param string $label
* The expected label of the component.
* @param int $weight
* The expected weight of the component.
*/
protected function assertComponent($display_id, $component_id, $type, $label, $weight) {
$component = EntityViewDisplay::load($display_id)->getComponent($component_id);
$this->assertTrue(is_array($component));
$this->assertIdentical($type, $component['type']);
$this->assertIdentical($label, $component['label']);
$this->assertIdentical($weight, $component['weight']);
}
/**
* Asserts that a particular component is NOT included in a display.
*
* @param string $display_id
* The display ID.
* @param string $component_id
* The component ID.
*/
protected function assertComponentNotExists($display_id, $component_id) {
$component = EntityViewDisplay::load($display_id)->getComponent($component_id);
$this->assertTrue(is_null($component));
}
/**
* Tests migration of D7 field formatter settings.
*/
public function testMigration() {
$this->assertEntity('comment.comment_node_article.default');
$this->assertComponent('comment.comment_node_article.default', 'comment_body', 'text_default', 'hidden', 0);
$this->assertEntity('comment.comment_node_blog.default');
$this->assertComponent('comment.comment_node_blog.default', 'comment_body', 'text_default', 'hidden', 0);
$this->assertEntity('comment.comment_node_book.default');
$this->assertComponent('comment.comment_node_book.default', 'comment_body', 'text_default', 'hidden', 0);
$this->assertEntity('comment.comment_node_forum.default');
$this->assertComponent('comment.comment_node_forum.default', 'comment_body', 'text_default', 'hidden', 0);
$this->assertEntity('comment.comment_node_page.default');
$this->assertComponent('comment.comment_node_page.default', 'comment_body', 'text_default', 'hidden', 0);
$this->assertEntity('comment.comment_node_test_content_type.default');
$this->assertComponent('comment.comment_node_test_content_type.default', 'comment_body', 'text_default', 'hidden', 0);
$this->assertComponent('comment.comment_node_test_content_type.default', 'field_integer', 'number_integer', 'above', 1);
$this->assertEntity('node.article.default');
$this->assertComponent('node.article.default', 'body', 'text_default', 'hidden', 0);
$this->assertComponent('node.article.default', 'field_tags', 'entity_reference_label', 'above', 10);
$this->assertComponent('node.article.default', 'field_image', 'image', 'hidden', -1);
$this->assertEntity('node.article.teaser');
$this->assertComponent('node.article.teaser', 'body', 'text_summary_or_trimmed', 'hidden', 0);
$this->assertComponent('node.article.teaser', 'field_tags', 'entity_reference_label', 'above', 10);
$this->assertComponent('node.article.teaser', 'field_image', 'image', 'hidden', -1);
$this->assertEntity('node.blog.default');
$this->assertComponent('node.blog.default', 'body', 'text_default', 'hidden', 0);
$this->assertEntity('node.blog.teaser');
$this->assertComponent('node.blog.teaser', 'body', 'text_summary_or_trimmed', 'hidden', 0);
$this->assertEntity('node.book.default');
$this->assertComponent('node.book.default', 'body', 'text_default', 'hidden', 0);
$this->assertEntity('node.book.teaser');
$this->assertComponent('node.book.teaser', 'body', 'text_summary_or_trimmed', 'hidden', 0);
$this->assertEntity('node.forum.default');
$this->assertComponent('node.forum.default', 'body', 'text_default', 'hidden', 11);
$this->assertComponent('node.forum.default', 'taxonomy_forums', 'entity_reference_label', 'above', 10);
$this->assertEntity('node.forum.teaser');
$this->assertComponent('node.forum.teaser', 'body', 'text_summary_or_trimmed', 'hidden', 11);
$this->assertComponent('node.forum.teaser', 'taxonomy_forums', 'entity_reference_label', 'above', 10);
$this->assertEntity('node.page.default');
$this->assertComponent('node.page.default', 'body', 'text_default', 'hidden', 0);
$this->assertEntity('node.page.teaser');
$this->assertComponent('node.page.teaser', 'body', 'text_summary_or_trimmed', 'hidden', 0);
$this->assertEntity('node.test_content_type.default');
$this->assertComponent('node.test_content_type.default', 'field_boolean', 'list_default', 'above', 0);
$this->assertComponent('node.test_content_type.default', 'field_email', 'email_mailto', 'above', 1);
// Phone formatters are not mapped and should default to basic_string.
$this->assertComponent('node.test_content_type.default', 'field_phone', 'basic_string', 'above', 2);
$this->assertComponent('node.test_content_type.default', 'field_date', 'datetime_default', 'above', 3);
$this->assertComponent('node.test_content_type.default', 'field_date_with_end_time', 'datetime_default', 'above', 4);
$this->assertComponent('node.test_content_type.default', 'field_file', 'file_default', 'above', 5);
$this->assertComponent('node.test_content_type.default', 'field_float', 'number_decimal', 'above', 6);
$this->assertComponent('node.test_content_type.default', 'field_images', 'image', 'above', 7);
$this->assertComponent('node.test_content_type.default', 'field_integer', 'number_integer', 'above', 8);
$this->assertComponent('node.test_content_type.default', 'field_link', 'link', 'above', 9);
$this->assertComponent('node.test_content_type.default', 'field_text_list', 'list_default', 'above', 10);
$this->assertComponent('node.test_content_type.default', 'field_integer_list', 'list_default', 'above', 11);
$this->assertComponent('node.test_content_type.default', 'field_long_text', 'text_default', 'above', 12);
$this->assertComponentNotExists('node.test_content_type.default', 'field_term_reference');
$this->assertComponentNotExists('node.test_content_type.default', 'field_text');
$this->assertEntity('user.user.default');
$this->assertComponent('user.user.default', 'field_file', 'file_default', 'above', 0);
}
}

View file

@ -0,0 +1,141 @@
<?php
/**
* @file
* Contains \Drupal\field\Tests\Migrate\d7\MigrateFieldInstanceTest.
*/
namespace Drupal\field\Tests\Migrate\d7;
use Drupal\comment\Entity\CommentType;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\FieldConfigInterface;
use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase;
use Drupal\node\Entity\NodeType;
/**
* Migrates Drupal 7 field instances.
*
* @group field
*/
class MigrateFieldInstanceTest extends MigrateDrupal7TestBase {
/**
* The modules to be enabled during the test.
*
* @var array
*/
static $modules = array(
'comment',
'datetime',
'entity_reference',
'file',
'image',
'link',
'node',
'system',
'taxonomy',
'telephone',
'text',
);
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installConfig(static::$modules);
$this->createType('page');
$this->createType('article');
$this->createType('blog');
$this->createType('book');
$this->createType('forum');
$this->createType('test_content_type');
$this->executeMigration('d7_field');
$this->executeMigration('d7_field_instance');
}
/**
* Creates a node type with a corresponding comment type.
*
* @param string $id
* The node type ID.
*/
protected function createType($id) {
NodeType::create(array(
'type' => $id,
'label' => $this->randomString(),
))->save();
CommentType::create(array(
'id' => 'comment_node_' . $id,
'label' => $this->randomString(),
'target_entity_type_id' => 'node',
))->save();
}
/**
* Asserts various aspects of a field config entity.
*
* @param string $id
* The entity ID in the form ENTITY_TYPE.BUNDLE.FIELD_NAME.
* @param string $expected_label
* The expected field label.
* @param string $expected_field_type
* The expected field type.
* @param boolean $is_required
* Whether or not the field is required.
*/
protected function assertEntity($id, $expected_label, $expected_field_type, $is_required) {
list ($expected_entity_type, $expected_bundle, $expected_name) = explode('.', $id);
/** @var \Drupal\field\FieldConfigInterface $field */
$field = FieldConfig::load($id);
$this->assertTrue($field instanceof FieldConfigInterface);
$this->assertIdentical($expected_label, $field->label());
$this->assertIdentical($expected_field_type, $field->getType());
$this->assertIdentical($expected_entity_type, $field->getTargetEntityTypeId());
$this->assertIdentical($expected_bundle, $field->getTargetBundle());
$this->assertIdentical($expected_name, $field->getName());
$this->assertEqual($is_required, $field->isRequired());
$this->assertIdentical($expected_entity_type . '.' . $expected_name, $field->getFieldStorageDefinition()->id());
}
/**
* Tests migrating D7 field instances to field_config entities.
*/
public function testFieldInstances() {
$this->assertEntity('comment.comment_node_page.comment_body', 'Comment', 'text_long', TRUE);
$this->assertEntity('node.page.body', 'Body', 'text_with_summary', FALSE);
$this->assertEntity('comment.comment_node_article.comment_body', 'Comment', 'text_long', TRUE);
$this->assertEntity('node.article.body', 'Body', 'text_with_summary', FALSE);
$this->assertEntity('node.article.field_tags', 'Tags', 'entity_reference', FALSE);
$this->assertEntity('node.article.field_image', 'Image', 'image', FALSE);
$this->assertEntity('comment.comment_node_blog.comment_body', 'Comment', 'text_long', TRUE);
$this->assertEntity('node.blog.body', 'Body', 'text_with_summary', FALSE);
$this->assertEntity('comment.comment_node_book.comment_body', 'Comment', 'text_long', TRUE);
$this->assertEntity('node.book.body', 'Body', 'text_with_summary', FALSE);
$this->assertEntity('node.forum.taxonomy_forums', 'Forums', 'entity_reference', TRUE);
$this->assertEntity('comment.comment_node_forum.comment_body', 'Comment', 'text_long', TRUE);
$this->assertEntity('node.forum.body', 'Body', 'text_with_summary', FALSE);
$this->assertEntity('comment.comment_node_test_content_type.comment_body', 'Comment', 'text_long', TRUE);
$this->assertEntity('node.test_content_type.field_boolean', 'Boolean', 'boolean', FALSE);
$this->assertEntity('node.test_content_type.field_email', 'Email', 'email', FALSE);
$this->assertEntity('node.test_content_type.field_phone', 'Phone', 'telephone', TRUE);
$this->assertEntity('node.test_content_type.field_date', 'Date', 'datetime', FALSE);
$this->assertEntity('node.test_content_type.field_date_with_end_time', 'Date With End Time', 'datetime', FALSE);
$this->assertEntity('node.test_content_type.field_file', 'File', 'file', FALSE);
$this->assertEntity('node.test_content_type.field_float', 'Float', 'float', FALSE);
$this->assertEntity('node.test_content_type.field_images', 'Images', 'image', TRUE);
$this->assertEntity('node.test_content_type.field_integer', 'Integer', 'integer', TRUE);
$this->assertEntity('node.test_content_type.field_link', 'Link', 'link', FALSE);
$this->assertEntity('node.test_content_type.field_text_list', 'Text List', 'list_string', FALSE);
$this->assertEntity('node.test_content_type.field_integer_list', 'Integer List', 'list_integer', FALSE);
$this->assertEntity('node.test_content_type.field_long_text', 'Long text', 'text_with_summary', FALSE);
$this->assertEntity('node.test_content_type.field_term_reference', 'Term Reference', 'entity_reference', FALSE);
$this->assertEntity('node.test_content_type.field_text', 'Text', 'text', FALSE);
$this->assertEntity('comment.comment_node_test_content_type.field_integer', 'Integer', 'integer', FALSE);
$this->assertEntity('user.user.field_file', 'File', 'file', FALSE);
}
}

View file

@ -0,0 +1,177 @@
<?php
/**
* @file
* Contains \Drupal\field\Tests\Migrate\d7\MigrateFieldInstanceWidgetSettingsTest.
*/
namespace Drupal\field\Tests\Migrate\d7;
use Drupal\Core\Entity\Display\EntityFormDisplayInterface;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase;
use Drupal\node\Entity\NodeType;
/**
* Migrate field widget settings.
*
* @group field
*/
class MigrateFieldInstanceWidgetSettingsTest extends MigrateDrupal7TestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array(
'field',
'telephone',
'link',
'file',
'image',
'datetime',
'node',
'text',
);
/**
* Creates a node type.
*
* @param string $id
* The node type ID.
*/
protected function createNodeType($id) {
NodeType::create(array(
'type' => $id,
'label' => $this->randomString(),
))->save();
}
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installEntitySchema('node');
$this->createNodeType('page');
$this->createNodeType('article');
$this->createNodeType('blog');
$this->createNodeType('book');
$this->createNodeType('forum');
$this->createNodeType('test_content_type');
// Add some id mappings for the dependent migrations.
$id_mappings = [
'd7_field' => [
[['comment', 'comment_body'], ['comment', 'comment_body']],
[['node', 'body'], ['node', 'body']],
[['node', 'field_tags'], ['node', 'field_tags']],
[['node', 'field_image'], ['node', 'field_image']],
[['node', 'taxonomy_forums'], ['node', 'taxonomy_forums']],
[['node', 'field_boolean'], ['node', 'field_boolean']],
[['node', 'field_email'], ['node', 'field_email']],
[['node', 'field_phone'], ['node', 'field_phone']],
[['node', 'field_date'], ['node', 'field_date']],
[['node', 'field_date_with_end_time'], ['node', 'field_date_with_end_time']],
[['node', 'field_file'], ['node', 'field_file']],
[['node', 'field_float'], ['node', 'field_float']],
[['node', 'field_images'], ['node', 'field_images']],
[['node', 'field_integer'], ['node', 'field_integer']],
[['node', 'field_link'], ['node', 'field_link']],
[['node', 'field_text_list'], ['node', 'field_text_list']],
[['node', 'field_integer_list'], ['node', 'field_integer_list']],
[['node', 'field_long_text'], ['node', 'field_long_text']],
[['node', 'field_term_reference'], ['node', 'field_term_reference']],
[['node', 'field_text'], ['node', 'field_text']],
[['node', 'field_integer'], ['node', 'field_integer']],
[['user', 'field_file'], ['user', 'field_file']],
],
// We don't actually need any ID lookups from the d7_field_instance
// migration -- it's merely a sensible dependency.
'd7_field_instance' => [],
];
$this->prepareMigrations($id_mappings);
$this->executeMigration('d7_field_instance_widget_settings');
}
/**
* Asserts various aspects of a form display entity.
*
* @param string $id
* The entity ID.
* @param string $expected_entity_type
* The expected entity type to which the display settings are attached.
* @param string $expected_bundle
* The expected bundle to which the display settings are attached.
*/
protected function assertEntity($id, $expected_entity_type, $expected_bundle) {
/** @var \Drupal\Core\Entity\Display\EntityFormDisplayInterface $entity */
$entity = EntityFormDisplay::load($id);
$this->assertTrue($entity instanceof EntityFormDisplayInterface);
$this->assertIdentical($expected_entity_type, $entity->getTargetEntityTypeId());
$this->assertIdentical($expected_bundle, $entity->getTargetBundle());
}
/**
* Asserts various aspects of a particular component of a form display.
*
* @param string $display_id
* The form display ID.
* @param string $component_id
* The component ID.
* @param string $widget_type
* The expected widget type.
* @param string $weight
* The expected weight of the component.
*/
protected function assertComponent($display_id, $component_id, $widget_type, $weight) {
$component = EntityFormDisplay::load($display_id)->getComponent($component_id);
$this->assertTrue(is_array($component));
$this->assertIdentical($widget_type, $component['type']);
$this->assertIdentical($weight, $component['weight']);
}
/**
* Test that migrated view modes can be loaded using D8 APIs.
*/
public function testWidgetSettings() {
$this->assertEntity('node.page.default', 'node', 'page');
$this->assertComponent('node.page.default', 'body', 'text_textarea_with_summary', -4);
$this->assertEntity('node.article.default', 'node', 'article');
$this->assertComponent('node.article.default', 'body', 'text_textarea_with_summary', -4);
$this->assertComponent('node.article.default', 'field_tags', 'taxonomy_autocomplete', -4);
$this->assertComponent('node.article.default', 'field_image', 'image_image', -1);
$this->assertEntity('node.blog.default', 'node', 'blog');
$this->assertComponent('node.blog.default', 'body', 'text_textarea_with_summary', -4);
$this->assertEntity('node.book.default', 'node', 'book');
$this->assertComponent('node.book.default', 'body', 'text_textarea_with_summary', -4);
$this->assertEntity('node.forum.default', 'node', 'forum');
$this->assertComponent('node.forum.default', 'body', 'text_textarea_with_summary', 1);
$this->assertComponent('node.forum.default', 'taxonomy_forums', 'options_select', 0);
$this->assertEntity('node.test_content_type.default', 'node', 'test_content_type');
$this->assertComponent('node.test_content_type.default', 'field_boolean', 'boolean_checkbox', 1);
$this->assertComponent('node.test_content_type.default', 'field_date', 'datetime_default', 2);
$this->assertComponent('node.test_content_type.default', 'field_date_with_end_time', 'datetime_default', 3);
$this->assertComponent('node.test_content_type.default', 'field_email', 'email_default', 4);
$this->assertComponent('node.test_content_type.default', 'field_file', 'file_generic', 5);
$this->assertComponent('node.test_content_type.default', 'field_float', 'number', 7);
$this->assertComponent('node.test_content_type.default', 'field_images', 'image_image', 8);
$this->assertComponent('node.test_content_type.default', 'field_integer', 'number', 9);
$this->assertComponent('node.test_content_type.default', 'field_link', 'link_default', 10);
$this->assertComponent('node.test_content_type.default', 'field_integer_list', 'options_buttons', 12);
$this->assertComponent('node.test_content_type.default', 'field_long_text', 'text_textarea_with_summary', 13);
$this->assertComponent('node.test_content_type.default', 'field_phone', 'telephone_default', 6);
$this->assertComponent('node.test_content_type.default', 'field_term_reference', 'taxonomy_autocomplete', 14);
$this->assertComponent('node.test_content_type.default', 'field_text', 'text_textfield', 15);
$this->assertComponent('node.test_content_type.default', 'field_text_list', 'options_select', 11);
}
}

View file

@ -0,0 +1,111 @@
<?php
/**
* @file
* Contains \Drupal\field\Tests\Migrate\d7\MigrateFieldTest.
*/
namespace Drupal\field\Tests\Migrate\d7;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field\FieldStorageConfigInterface;
use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase;
/**
* Migrates Drupal 7 fields.
*
* @group field
*/
class MigrateFieldTest extends MigrateDrupal7TestBase {
/**
* The modules to be enabled during the test.
*
* @var array
*/
static $modules = array(
'comment',
'datetime',
'entity_reference',
'file',
'image',
'link',
'node',
'system',
'taxonomy',
'telephone',
'text',
);
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installConfig(static::$modules);
$this->executeMigration('d7_field');
}
/**
* Asserts various aspects of a field_storage_config entity.
*
* @param string $id
* The entity ID in the form ENTITY_TYPE.FIELD_NAME.
* @param string $expected_type
* The expected field type.
* @param boolean $expected_translatable
* Whether or not the field is expected to be translatable.
* @param integer $expected_cardinality
* The expected cardinality of the field.
*/
protected function assertEntity($id, $expected_type, $expected_translatable, $expected_cardinality) {
list ($expected_entity_type, $expected_name) = explode('.', $id);
/** @var \Drupal\field\FieldStorageConfigInterface $field */
$field = FieldStorageConfig::load($id);
$this->assertTrue($field instanceof FieldStorageConfigInterface);
$this->assertIdentical($expected_name, $field->getName());
$this->assertIdentical($expected_type, $field->getType());
// FieldStorageConfig::$translatable is TRUE by default, so it is useful
// to test for FALSE here.
$this->assertEqual($expected_translatable, $field->isTranslatable());
$this->assertIdentical($expected_entity_type, $field->getTargetEntityTypeId());
if ($expected_cardinality === 1) {
$this->assertFalse($field->isMultiple());
}
else {
$this->assertTrue($field->isMultiple());
}
$this->assertIdentical($expected_cardinality, $field->getCardinality());
}
/**
* Tests migrating D7 fields to field_storage_config entities.
*/
public function testFields() {
$this->assertEntity('node.body', 'text_with_summary', FALSE, 1);
$this->assertEntity('node.field_long_text', 'text_with_summary', FALSE, 1);
$this->assertEntity('comment.comment_body', 'text_long', FALSE, 1);
$this->assertEntity('node.field_file', 'file', FALSE, 1);
$this->assertEntity('user.field_file', 'file', FALSE, 1);
$this->assertEntity('node.field_float', 'float', FALSE, 1);
$this->assertEntity('node.field_image', 'image', FALSE, 1);
$this->assertEntity('node.field_images', 'image', FALSE, 1);
$this->assertEntity('node.field_integer', 'integer', FALSE, 1);
$this->assertEntity('comment.field_integer', 'integer', FALSE, 1);
$this->assertEntity('node.field_integer_list', 'list_integer', FALSE, 1);
$this->assertEntity('node.field_link', 'link', FALSE, 1);
$this->assertEntity('node.field_tags', 'entity_reference', FALSE, -1);
$this->assertEntity('node.field_term_reference', 'entity_reference', FALSE, 1);
$this->assertEntity('node.taxonomy_forums', 'entity_reference', FALSE, 1);
$this->assertEntity('node.field_text', 'text', FALSE, 1);
$this->assertEntity('node.field_text_list', 'list_string', FALSE, 3);
$this->assertEntity('node.field_boolean', 'boolean', FALSE, 1);
$this->assertEntity('node.field_email', 'email', FALSE, -1);
$this->assertEntity('node.field_phone', 'telephone', FALSE, 1);
$this->assertEntity('node.field_date', 'datetime', FALSE, 1);
$this->assertEntity('node.field_date_with_end_time', 'datetime', FALSE, 1);
}
}

View file

@ -0,0 +1,63 @@
<?php
/**
* @file
* Contains \Drupal\field\Tests\Migrate\d7\MigrateViewModesTest.
*/
namespace Drupal\field\Tests\Migrate\d7;
use Drupal\Core\Entity\Entity\EntityViewMode;
use Drupal\Core\Entity\EntityViewModeInterface;
use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase;
/**
* Tests migration of D7 view modes.
*
* @group field
*/
class MigrateViewModesTest extends MigrateDrupal7TestBase {
public static $modules = ['comment', 'node'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installEntitySchema('comment');
$this->installEntitySchema('node');
$this->executeMigration('d7_view_modes');
}
/**
* Asserts various aspects of a view mode entity.
*
* @param string $id
* The entity ID.
* @param string $label
* The expected label of the view mode.
* @param string $entity_type
* The expected entity type ID which owns the view mode.
* @param bool $status
* The expected status of the view mode.
*/
protected function assertEntity($id, $label, $entity_type) {
/** @var \Drupal\Core\Entity\EntityViewModeInterface $view_mode */
$view_mode = EntityViewMode::load($id);
$this->assertTrue($view_mode instanceof EntityViewModeInterface);
$this->assertIdentical($label, $view_mode->label());
$this->assertIdentical($entity_type, $view_mode->getTargetType());
}
/**
* Tests migration of D7 view mode variables to D8 config entities.
*/
public function testMigration() {
$this->assertEntity('comment.full', 'Full', 'comment');
$this->assertEntity('node.teaser', 'Teaser', 'node');
$this->assertEntity('node.full', 'Full', 'node');
$this->assertEntity('user.full', 'Full', 'user');
}
}

View file

@ -284,7 +284,11 @@ class NumberFieldTest extends WebTestBase {
preg_match('|entity_test/manage/(\d+)|', $this->url, $match);
$id = $match[1];
$this->assertText(t('entity_test @id has been created.', array('@id' => $id)), 'Entity was created');
$this->assertRaw(round($value, 2), 'Value is displayed.');
// Ensure that the 'number_decimal' formatter displays the number with the
// expected rounding.
$this->drupalGet('entity_test/' . $id);
$this->assertRaw(round($value, 2));
// Try to create entries with more than one decimal separator; assert fail.
$wrong_entries = array(

View file

@ -7,7 +7,7 @@
namespace Drupal\field\Tests\String;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Component\Utility\Html;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Entity\FieldableEntityInterface;
@ -119,11 +119,11 @@ class RawStringFormatterTest extends KernelTestBase {
// Verify that all HTML is escaped and newlines are retained.
$this->renderEntityFields($entity, $this->display);
$this->assertNoRaw($value);
$this->assertRaw(nl2br(SafeMarkup::checkPlain($value)));
$this->assertRaw(nl2br(Html::escape($value)));
// Verify the cache tags.
$build = $entity->{$this->fieldName}->view();
$this->assertTrue(!isset($build[0]['#cache']), format_string('The string formatter has no cache tags.'));
$this->assertTrue(!isset($build[0]['#cache']), 'The string formatter has no cache tags.');
}
}

View file

@ -7,7 +7,7 @@
namespace Drupal\field\Tests\String;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Component\Utility\Html;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Entity\FieldableEntityInterface;
@ -119,11 +119,11 @@ class StringFormatterTest extends KernelTestBase {
// Verify that all HTML is escaped and newlines are retained.
$this->renderEntityFields($entity, $this->display);
$this->assertNoRaw($value);
$this->assertRaw(nl2br(SafeMarkup::checkPlain($value)));
$this->assertRaw(nl2br(Html::escape($value)));
// Verify the cache tags.
$build = $entity->{$this->fieldName}->view();
$this->assertTrue(!isset($build[0]['#cache']), format_string('The string formatter has no cache tags.'));
$this->assertTrue(!isset($build[0]['#cache']), 'The string formatter has no cache tags.');
$value = $this->randomMachineName();
$entity->{$this->fieldName}->value = $value;

View file

@ -51,7 +51,7 @@ class UuidFormatterTest extends KernelTestBase {
$render_array = $uuid_field->view(['settings' => ['link_to_entity' => TRUE]]);
$this->assertIdentical($render_array[0]['#type'], 'link');
$this->assertIdentical($render_array[0]['#title'], $entity->uuid());
$this->assertIdentical($render_array[0]['#title']['#markup'], $entity->uuid());
$this->assertIdentical($render_array[0]['#url']->toString(), $entity->url());
}

View file

@ -50,7 +50,7 @@ class TestItemWithDependenciesTest extends FieldUnitTestBase {
$this->assertEqual([
'content' => ['node:article:uuid'],
'config' => ['field.storage.entity_test.field_test'],
'module' => ['field_test', 'test_module']
'module' => ['entity_test', 'field_test', 'test_module']
], $field->getDependencies());
}

View file

@ -0,0 +1,73 @@
<?php
/**
* @file
* Contains \Drupal\field\Tests\Uri\UriItemTest.
*/
namespace Drupal\field\Tests\Uri;
use Drupal\Component\Utility\Unicode;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field\Tests\FieldUnitTestBase;
/**
* Tests URI field functionality.
*
* @see \Drupal\Core\Field\Plugin\Field\FieldType\UriItem
*
* @group field
*/
class UriItemTest extends FieldUnitTestBase {
/**
* A field to use in this test class.
*
* @var \Drupal\field\Entity\FieldStorageConfig
*/
protected $fieldStorage;
/**
* The field used in this test class.
*
* @var \Drupal\field\Entity\FieldConfig
*/
protected $field;
/**
* Tests URI field.
*/
public function testUriField() {
$label = $this->randomMachineName();
// Create a field with settings to validate.
$field_name = Unicode::strtolower($this->randomMachineName());
$this->fieldStorage = FieldStorageConfig::create([
'field_name' => $field_name,
'entity_type' => 'entity_test',
'type' => 'uri',
]);
$this->fieldStorage->save();
$this->field = FieldConfig::create([
'field_name' => $field_name,
'entity_type' => 'entity_test',
'bundle' => 'entity_test',
'label' => $label,
'required' => TRUE,
'settings' => [
'size' => 123,
'placeholder' => '',
],
]);
$this->field->save();
// Create a form display for the default form mode.
entity_get_form_display('entity_test', 'entity_test', 'default')
->setComponent($field_name, [
'type' => 'uri',
])
->save();
}
}