Update core 8.3.0

This commit is contained in:
Rob Davies 2017-04-13 15:53:35 +01:00
parent da7a7918f8
commit cd7a898e66
6144 changed files with 132297 additions and 87747 deletions

View file

@ -15,41 +15,41 @@ function field_ui_test_form_entity_view_display_edit_form_alter(&$form, FormStat
$table = &$form['fields'];
foreach (Element::children($table) as $name) {
$table[$name]['parent_wrapper']['parent']['#options'] = array('indent' => 'Indent');
$table[$name]['parent_wrapper']['parent']['#options'] = ['indent' => 'Indent'];
$table[$name]['parent_wrapper']['parent']['#default_value'] = 'indent';
}
$table['indent'] = [
'#attributes' => array('class' => array('draggable', 'field-group'), 'id' => 'indent-id'),
'#attributes' => ['class' => ['draggable', 'field-group'], 'id' => 'indent-id'],
'#row_type' => 'group',
'#region_callback' => 'field_ui_test_region_callback',
'#js_settings' => array('rowHandler' => 'group'),
'human_name' => array(
'#js_settings' => ['rowHandler' => 'group'],
'human_name' => [
'#markup' => 'Indent',
'#prefix' => '<span class="group-label">',
'#suffix' => '</span>',
),
'weight' => array(
],
'weight' => [
'#type' => 'textfield',
'#default_value' => 0,
'#size' => 3,
'#attributes' => array('class' => array('field-weight')),
),
'parent_wrapper' => array(
'parent' => array(
'#attributes' => ['class' => ['field-weight']],
],
'parent_wrapper' => [
'parent' => [
'#type' => 'select',
'#options' => array('indent' => 'Indent'),
'#options' => ['indent' => 'Indent'],
'#empty_value' => '',
'#default_value' => '',
'#attributes' => array('class' => array('field-parent')),
'#parents' => array('fields', 'indent', 'parent'),
),
'hidden_name' => array(
'#attributes' => ['class' => ['field-parent']],
'#parents' => ['fields', 'indent', 'parent'],
],
'hidden_name' => [
'#type' => 'hidden',
'#default_value' => 'indent',
'#attributes' => array('class' => array('field-name')),
),
),
'#attributes' => ['class' => ['field-name']],
],
],
];
}

View file

@ -0,0 +1,124 @@
<?php
namespace Drupal\Tests\field_ui\Functional;
use Drupal\Tests\BrowserTestBase;
/**
* Tests the entity display modes UI.
*
* @group field_ui
*/
class EntityDisplayModeTest extends BrowserTestBase {
/**
* Modules to enable.
*
* @var string[]
*/
public static $modules = ['block', 'entity_test', 'field_ui'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->drupalPlaceBlock('local_actions_block');
$this->drupalPlaceBlock('page_title_block');
}
/**
* Tests the EntityViewMode user interface.
*/
public function testEntityViewModeUI() {
// Test the listing page.
$this->drupalGet('admin/structure/display-modes/view');
$this->assertResponse(403);
$this->drupalLogin($this->drupalCreateUser(['administer display modes']));
$this->drupalGet('admin/structure/display-modes/view');
$this->assertResponse(200);
$this->assertText(t('Add view mode'));
$this->assertLinkByHref('admin/structure/display-modes/view/add');
$this->assertLinkByHref('admin/structure/display-modes/view/add/entity_test');
$this->drupalGet('admin/structure/display-modes/view/add/entity_test_mulrev');
$this->assertResponse(404);
$this->drupalGet('admin/structure/display-modes/view/add');
$this->assertNoLink(t('Test entity - revisions and data table'), 'An entity type with no view builder cannot have view modes.');
// Test adding a view mode including dots in machine_name.
$this->clickLink(t('Test entity'));
$edit = [
'id' => strtolower($this->randomMachineName()) . '.' . strtolower($this->randomMachineName()),
'label' => $this->randomString(),
];
$this->drupalPostForm(NULL, $edit, t('Save'));
$this->assertRaw('The machine-readable name must contain only lowercase letters, numbers, and underscores.');
// Test adding a view mode.
$edit = [
'id' => strtolower($this->randomMachineName()),
'label' => $this->randomString(),
];
$this->drupalPostForm(NULL, $edit, t('Save'));
$this->assertRaw(t('Saved the %label view mode.', ['%label' => $edit['label']]));
// Test editing the view mode.
$this->drupalGet('admin/structure/display-modes/view/manage/entity_test.' . $edit['id']);
// Test deleting the view mode.
$this->clickLink(t('Delete'));
$this->assertRaw(t('Are you sure you want to delete the view mode %label?', ['%label' => $edit['label']]));
$this->drupalPostForm(NULL, NULL, t('Delete'));
$this->assertRaw(t('The view mode %label has been deleted.', ['%label' => $edit['label']]));
}
/**
* Tests the EntityFormMode user interface.
*/
public function testEntityFormModeUI() {
// Test the listing page.
$this->drupalGet('admin/structure/display-modes/form');
$this->assertResponse(403);
$this->drupalLogin($this->drupalCreateUser(['administer display modes']));
$this->drupalGet('admin/structure/display-modes/form');
$this->assertResponse(200);
$this->assertText(t('Add form mode'));
$this->assertLinkByHref('admin/structure/display-modes/form/add');
$this->drupalGet('admin/structure/display-modes/form/add/entity_test_no_label');
$this->assertResponse(404);
$this->drupalGet('admin/structure/display-modes/form/add');
$this->assertNoLink(t('Entity Test without label'), 'An entity type with no form cannot have form modes.');
// Test adding a view mode including dots in machine_name.
$this->clickLink(t('Test entity'));
$edit = [
'id' => strtolower($this->randomMachineName()) . '.' . strtolower($this->randomMachineName()),
'label' => $this->randomString(),
];
$this->drupalPostForm(NULL, $edit, t('Save'));
$this->assertRaw('The machine-readable name must contain only lowercase letters, numbers, and underscores.');
// Test adding a form mode.
$edit = [
'id' => strtolower($this->randomMachineName()),
'label' => $this->randomString(),
];
$this->drupalPostForm(NULL, $edit, t('Save'));
$this->assertRaw(t('Saved the %label form mode.', ['%label' => $edit['label']]));
// Test editing the form mode.
$this->drupalGet('admin/structure/display-modes/form/manage/entity_test.' . $edit['id']);
// Test deleting the form mode.
$this->clickLink(t('Delete'));
$this->assertRaw(t('Are you sure you want to delete the form mode %label?', ['%label' => $edit['label']]));
$this->drupalPostForm(NULL, NULL, t('Delete'));
$this->assertRaw(t('The form mode %label has been deleted.', ['%label' => $edit['label']]));
}
}

View file

@ -0,0 +1,46 @@
<?php
namespace Drupal\Tests\field_ui\Functional;
use Drupal\Tests\BrowserTestBase;
/**
* Tests the UI for entity displays.
*
* @group field_ui
*/
class EntityDisplayTest extends BrowserTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['field_ui', 'entity_test'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->drupalLogin($this->drupalCreateUser([
'administer entity_test display',
]));
}
/**
* Tests the use of regions for entity view displays.
*/
public function testEntityView() {
$this->drupalGet('entity_test/structure/entity_test/display');
$this->assertSession()->elementExists('css', '.region-content-message.region-empty');
$this->assertTrue($this->assertSession()->optionExists('fields[field_test_text][region]', 'hidden')->isSelected());
$this->getSession()->getPage()->selectFieldOption('fields[field_test_text][region]', 'content');
$this->assertTrue($this->assertSession()->optionExists('fields[field_test_text][region]', 'content')->isSelected());
$this->submitForm([], 'Save');
$this->assertSession()->pageTextContains('Your settings have been saved.');
$this->assertTrue($this->assertSession()->optionExists('fields[field_test_text][region]', 'content')->isSelected());
}
}

View file

@ -0,0 +1,41 @@
<?php
namespace Drupal\Tests\field_ui\Functional;
use Drupal\Tests\BrowserTestBase;
/**
* Tests indentation on Field UI.
*
* @group field_ui
*/
class FieldUIIndentationTest extends BrowserTestBase {
/**
* Modules to install.
*
* @var array
*/
public static $modules = ['node', 'field_ui', 'field_ui_test'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
// Create a test user.
$admin_user = $this->drupalCreateUser(['access content', 'administer content types', 'administer node display']);
$this->drupalLogin($admin_user);
// Create Basic page node type.
$this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
}
public function testIndentation() {
$this->drupalGet('admin/structure/types/manage/page/display');
$this->assertRaw('js-indentation indentation');
}
}

View file

@ -0,0 +1,120 @@
<?php
namespace Drupal\Tests\field_ui\Functional;
use Drupal\Core\Entity\Entity\EntityFormMode;
use Drupal\Core\Entity\Entity\EntityViewMode;
use Drupal\Tests\BrowserTestBase;
/**
* Tests the functionality of the Field UI route subscriber.
*
* @group field_ui
*/
class FieldUIRouteTest extends BrowserTestBase {
/**
* Modules to install.
*
* @var string[]
*/
public static $modules = ['block', 'entity_test', 'field_ui'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->drupalLogin($this->rootUser);
$this->drupalPlaceBlock('local_tasks_block');
}
/**
* Ensures that entity types with bundles do not break following entity types.
*/
public function testFieldUIRoutes() {
$this->drupalGet('entity_test_no_id/structure/entity_test/fields');
$this->assertText('No fields are present yet.');
$this->drupalGet('admin/config/people/accounts/fields');
$this->assertTitle('Manage fields | Drupal');
$this->assertLocalTasks();
// Test manage display tabs and titles.
$this->drupalGet('admin/config/people/accounts/display/compact');
$this->assertResponse(403);
$this->drupalGet('admin/config/people/accounts/display');
$this->assertTitle('Manage display | Drupal');
$this->assertLocalTasks();
$edit = ['display_modes_custom[compact]' => TRUE];
$this->drupalPostForm(NULL, $edit, t('Save'));
$this->drupalGet('admin/config/people/accounts/display/compact');
$this->assertTitle('Manage display | Drupal');
$this->assertLocalTasks();
// Test manage form display tabs and titles.
$this->drupalGet('admin/config/people/accounts/form-display/register');
$this->assertResponse(403);
$this->drupalGet('admin/config/people/accounts/form-display');
$this->assertTitle('Manage form display | Drupal');
$this->assertLocalTasks();
$edit = ['display_modes_custom[register]' => TRUE];
$this->drupalPostForm(NULL, $edit, t('Save'));
$this->assertResponse(200);
$this->drupalGet('admin/config/people/accounts/form-display/register');
$this->assertTitle('Manage form display | Drupal');
$this->assertLocalTasks();
$this->assert(count($this->xpath('//ul/li[1]/a[contains(text(), :text)]', [':text' => 'Default'])) == 1, 'Default secondary tab is in first position.');
// Create new view mode and verify it's available on the Manage Display
// screen after enabling it.
EntityViewMode::create([
'id' => 'user.test',
'label' => 'Test',
'targetEntityType' => 'user',
])->save();
$this->container->get('router.builder')->rebuildIfNeeded();
$edit = ['display_modes_custom[test]' => TRUE];
$this->drupalPostForm('admin/config/people/accounts/display', $edit, t('Save'));
$this->assertLink('Test');
// Create new form mode and verify it's available on the Manage Form
// Display screen after enabling it.
EntityFormMode::create([
'id' => 'user.test',
'label' => 'Test',
'targetEntityType' => 'user',
])->save();
$this->container->get('router.builder')->rebuildIfNeeded();
$edit = ['display_modes_custom[test]' => TRUE];
$this->drupalPostForm('admin/config/people/accounts/form-display', $edit, t('Save'));
$this->assertLink('Test');
}
/**
* Asserts that local tasks exists.
*/
public function assertLocalTasks() {
$this->assertLink('Settings');
$this->assertLink('Manage fields');
$this->assertLink('Manage display');
$this->assertLink('Manage form display');
}
/**
* Asserts that admin routes are correctly marked as such.
*/
public function testAdminRoute() {
$route = \Drupal::service('router.route_provider')->getRouteByName('entity.entity_test.field_ui_fields');
$is_admin = \Drupal::service('router.admin_context')->isAdminRoute($route);
$this->assertTrue($is_admin, 'Admin route correctly marked for "Manage fields" page.');
}
}

View file

@ -0,0 +1,106 @@
<?php
namespace Drupal\Tests\field_ui\FunctionalJavascript;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
/**
* Tests the UI for entity displays.
*
* @group field_ui
*/
class EntityDisplayTest extends JavascriptTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['field_ui', 'entity_test'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$entity = EntityTest::create([
'name' => 'The name for this entity',
'field_test_text' => [[
'value' => 'The field test text value',
]],
]);
$entity->save();
$this->drupalLogin($this->drupalCreateUser([
'access administration pages',
'view test entity',
'administer entity_test content',
'administer entity_test fields',
'administer entity_test display',
'administer entity_test form display',
'view the administration theme',
]));
}
/**
* Tests the use of regions for entity form displays.
*/
public function testEntityForm() {
$this->drupalGet('entity_test/manage/1/edit');
$this->assertSession()->fieldExists('field_test_text[0][value]');
$this->drupalGet('entity_test/structure/entity_test/form-display');
$this->assertTrue($this->assertSession()->optionExists('fields[field_test_text][region]', 'content')->isSelected());
$this->getSession()->getPage()->selectFieldOption('fields[field_test_text][region]', 'hidden');
$this->assertSession()->assertWaitOnAjaxRequest();
$this->assertTrue($this->assertSession()->optionExists('fields[field_test_text][region]', 'hidden')->isSelected());
$this->submitForm([], 'Save');
$this->assertSession()->pageTextContains('Your settings have been saved.');
$this->assertTrue($this->assertSession()->optionExists('fields[field_test_text][region]', 'hidden')->isSelected());
$this->drupalGet('entity_test/manage/1/edit');
$this->assertSession()->fieldNotExists('field_test_text[0][value]');
}
/**
* Tests the use of regions for entity view displays.
*/
public function testEntityView() {
$this->drupalGet('entity_test/1');
$this->assertSession()->elementNotExists('css', '.field--name-field-test-text');
$this->drupalGet('entity_test/structure/entity_test/display');
$this->assertSession()->elementExists('css', '.region-content-message.region-empty');
$this->assertTrue($this->assertSession()->optionExists('fields[field_test_text][region]', 'hidden')->isSelected());
$this->getSession()->getPage()->selectFieldOption('fields[field_test_text][region]', 'content');
$this->assertSession()->assertWaitOnAjaxRequest();
$this->assertTrue($this->assertSession()->optionExists('fields[field_test_text][region]', 'content')->isSelected());
$this->submitForm([], 'Save');
$this->assertSession()->pageTextContains('Your settings have been saved.');
$this->assertTrue($this->assertSession()->optionExists('fields[field_test_text][region]', 'content')->isSelected());
$this->drupalGet('entity_test/1');
$this->assertSession()->elementExists('css', '.field--name-field-test-text');
}
/**
* Tests extra fields.
*/
public function testExtraFields() {
entity_test_create_bundle('bundle_with_extra_fields');
$this->drupalGet('entity_test/structure/bundle_with_extra_fields/display');
$extra_field_row = $this->getSession()->getPage()->find('css', '#display-extra-field');
$disabled_region_row = $this->getSession()->getPage()->find('css', '.region-hidden-title');
$extra_field_row->find('css', '.handle')->dragTo($disabled_region_row);
$this->assertSession()->assertWaitOnAjaxRequest();
$this->submitForm([], 'Save');
$this->assertSession()->pageTextContains('Your settings have been saved.');
}
}

View file

@ -29,46 +29,47 @@ class EntityDisplayTest extends KernelTestBase {
*
* @var string[]
*/
public static $modules = array('field_ui', 'field', 'entity_test', 'user', 'text', 'field_test', 'node', 'system');
public static $modules = ['field_ui', 'field', 'entity_test', 'user', 'text', 'field_test', 'node', 'system'];
protected function setUp() {
parent::setUp();
$this->installEntitySchema('node');
$this->installEntitySchema('user');
$this->installConfig(array('field', 'node', 'user'));
$this->installConfig(['field', 'node', 'user']);
}
/**
* Tests basic CRUD operations on entity display objects.
*/
public function testEntityDisplayCRUD() {
$display = EntityViewDisplay::create(array(
$display = EntityViewDisplay::create([
'targetEntityType' => 'entity_test',
'bundle' => 'entity_test',
'mode' => 'default',
));
]);
$expected = array();
$expected = [];
// Check that providing no 'weight' results in the highest current weight
// being assigned. The 'name' field's formatter has weight -5, therefore
// these follow.
$expected['component_1'] = array('weight' => -4, 'settings' => array(), 'third_party_settings' => array());
$expected['component_2'] = array('weight' => -3, 'settings' => array(), 'third_party_settings' => array());
$expected['component_1'] = ['weight' => -4, 'settings' => [], 'third_party_settings' => []];
$expected['component_2'] = ['weight' => -3, 'settings' => [], 'third_party_settings' => []];
$display->setComponent('component_1');
$display->setComponent('component_2');
$this->assertEqual($display->getComponent('component_1'), $expected['component_1']);
$this->assertEqual($display->getComponent('component_2'), $expected['component_2']);
// Check that arbitrary options are correctly stored.
$expected['component_3'] = array('weight' => 10, 'third_party_settings' => array('field_test' => array('foo' => 'bar')), 'settings' => array());
$expected['component_3'] = ['weight' => 10, 'third_party_settings' => ['field_test' => ['foo' => 'bar']], 'settings' => []];
$display->setComponent('component_3', $expected['component_3']);
$this->assertEqual($display->getComponent('component_3'), $expected['component_3']);
// Check that the display can be properly saved and read back.
$display->save();
$display = EntityViewDisplay::load($display->id());
foreach (array('component_1', 'component_2', 'component_3') as $name) {
foreach (['component_1', 'component_2', 'component_3'] as $name) {
$expected[$name]['region'] = 'content';
$this->assertEqual($display->getComponent($name), $expected[$name]);
}
@ -78,15 +79,16 @@ class EntityDisplayTest extends KernelTestBase {
$this->assertEqual('bar', $display->getThirdPartySetting('entity_test', 'foo'), 'Third party settings were added to the entity view display.');
// Check that getComponents() returns options for all components.
$expected['name'] = array(
$expected['name'] = [
'label' => 'hidden',
'type' => 'string',
'weight' => -5,
'settings' => array(
'settings' => [
'link_to_entity' => FALSE,
),
'third_party_settings' => array(),
);
],
'third_party_settings' => [],
'region' => 'content'
];
$this->assertEqual($display->getComponents(), $expected);
// Check that a component can be removed.
@ -100,12 +102,12 @@ class EntityDisplayTest extends KernelTestBase {
// Check that createCopy() creates a new component that can be correctly
// saved.
EntityViewMode::create(array('id' => $display->getTargetEntityTypeId() . '.other_view_mode', 'targetEntityType' => $display->getTargetEntityTypeId()))->save();
EntityViewMode::create(['id' => $display->getTargetEntityTypeId() . '.other_view_mode', 'targetEntityType' => $display->getTargetEntityTypeId()])->save();
$new_display = $display->createCopy('other_view_mode');
$new_display->save();
$new_display = EntityViewDisplay::load($new_display->id());
$dependencies = $new_display->calculateDependencies()->getDependencies();
$this->assertEqual(array('config' => array('core.entity_view_mode.entity_test.other_view_mode'), 'module' => array('entity_test')), $dependencies);
$this->assertEqual(['config' => ['core.entity_view_mode.entity_test.other_view_mode'], 'module' => ['entity_test']], $dependencies);
$this->assertEqual($new_display->getTargetEntityTypeId(), $display->getTargetEntityTypeId());
$this->assertEqual($new_display->getTargetBundle(), $display->getTargetBundle());
$this->assertEqual($new_display->getMode(), 'other_view_mode');
@ -116,18 +118,18 @@ class EntityDisplayTest extends KernelTestBase {
* Test sorting of components by name on basic CRUD operations
*/
public function testEntityDisplayCRUDSort() {
$display = EntityViewDisplay::create(array(
$display = EntityViewDisplay::create([
'targetEntityType' => 'entity_test',
'bundle' => 'entity_test',
'mode' => 'default',
));
]);
$display->setComponent('component_3');
$display->setComponent('component_1');
$display->setComponent('component_2');
$display->save();
$components = array_keys($display->getComponents());
// The name field is not configurable so will be added automatically.
$expected = array ( 0 => 'component_1', 1 => 'component_2', 2 => 'component_3', 'name');
$expected = [ 0 => 'component_1', 1 => 'component_2', 2 => 'component_3', 'name'];
$this->assertIdentical($components, $expected);
}
@ -141,14 +143,14 @@ class EntityDisplayTest extends KernelTestBase {
$this->assertTrue($display->isNew());
// Add some components and save the display.
$display->setComponent('component_1', array('weight' => 10, 'settings' => array()))
$display->setComponent('component_1', ['weight' => 10, 'settings' => []])
->save();
// Check that entity_get_display() returns the correct object.
$display = entity_get_display('entity_test', 'entity_test', 'default');
$this->assertFalse($display->isNew());
$this->assertEqual($display->id(), 'entity_test.entity_test.default');
$this->assertEqual($display->getComponent('component_1'), array( 'weight' => 10, 'settings' => array(), 'third_party_settings' => array()));
$this->assertEqual($display->getComponent('component_1'), [ 'weight' => 10, 'settings' => [], 'third_party_settings' => [], 'region' => 'content']);
}
/**
@ -156,22 +158,51 @@ class EntityDisplayTest extends KernelTestBase {
*/
public function testExtraFieldComponent() {
entity_test_create_bundle('bundle_with_extra_fields');
$display = EntityViewDisplay::create(array(
$display = EntityViewDisplay::create([
'targetEntityType' => 'entity_test',
'bundle' => 'bundle_with_extra_fields',
'mode' => 'default',
));
]);
// Check that the default visibility taken into account for extra fields
// unknown in the display.
$this->assertEqual($display->getComponent('display_extra_field'), array('weight' => 5));
$this->assertEqual($display->getComponent('display_extra_field'), ['weight' => 5, 'region' => 'content']);
$this->assertNull($display->getComponent('display_extra_field_hidden'));
// Check that setting explicit options overrides the defaults.
$display->removeComponent('display_extra_field');
$display->setComponent('display_extra_field_hidden', array('weight' => 10));
$display->setComponent('display_extra_field_hidden', ['weight' => 10]);
$this->assertNull($display->getComponent('display_extra_field'));
$this->assertEqual($display->getComponent('display_extra_field_hidden'), array('weight' => 10, 'settings' => array(), 'third_party_settings' => array()));
$this->assertEqual($display->getComponent('display_extra_field_hidden'), ['weight' => 10, 'settings' => [], 'third_party_settings' => []]);
}
/**
* Tests the behavior of an extra field component with initial invalid values.
*/
public function testExtraFieldComponentInitialInvalidConfig() {
entity_test_create_bundle('bundle_with_extra_fields');
$display = EntityViewDisplay::create([
'targetEntityType' => 'entity_test',
'bundle' => 'bundle_with_extra_fields',
'mode' => 'default',
// Add the extra field to the initial config, without a 'type'.
'content' => [
'display_extra_field' => [
'weight' => 5,
],
],
]);
// Check that the default visibility taken into account for extra fields
// unknown in the display that were included in the initial config.
$this->assertEqual($display->getComponent('display_extra_field'), ['weight' => 5, 'region' => 'content']);
$this->assertNull($display->getComponent('display_extra_field_hidden'));
// Check that setting explicit options overrides the defaults.
$display->removeComponent('display_extra_field');
$display->setComponent('display_extra_field_hidden', ['weight' => 10]);
$this->assertNull($display->getComponent('display_extra_field'));
$this->assertEqual($display->getComponent('display_extra_field_hidden'), ['weight' => 10, 'settings' => [], 'third_party_settings' => []]);
}
/**
@ -180,36 +211,36 @@ class EntityDisplayTest extends KernelTestBase {
public function testFieldComponent() {
$field_name = 'test_field';
// Create a field storage and a field.
$field_storage = FieldStorageConfig::create(array(
$field_storage = FieldStorageConfig::create([
'field_name' => $field_name,
'entity_type' => 'entity_test',
'type' => 'test_field'
));
]);
$field_storage->save();
$field = FieldConfig::create(array(
$field = FieldConfig::create([
'field_storage' => $field_storage,
'bundle' => 'entity_test',
));
]);
$field->save();
$display = EntityViewDisplay::create(array(
$display = EntityViewDisplay::create([
'targetEntityType' => 'entity_test',
'bundle' => 'entity_test',
'mode' => 'default',
));
]);
// Check that providing no options results in default values being used.
$display->setComponent($field_name);
$field_type_info = \Drupal::service('plugin.manager.field.field_type')->getDefinition($field_storage->getType());
$default_formatter = $field_type_info['default_formatter'];
$formatter_settings = \Drupal::service('plugin.manager.field.formatter')->getDefaultSettings($default_formatter);
$expected = array(
$expected = [
'weight' => -4,
'label' => 'above',
'type' => $default_formatter,
'settings' => $formatter_settings,
'third_party_settings' => array(),
);
'third_party_settings' => [],
];
$this->assertEqual($display->getComponent($field_name), $expected);
// Check that the getFormatter() method returns the correct formatter plugin.
@ -225,9 +256,9 @@ class EntityDisplayTest extends KernelTestBase {
$this->assertEqual($formatter->randomValue, $random_value);
// Check that changing the definition creates a new formatter.
$display->setComponent($field_name, array(
$display->setComponent($field_name, [
'type' => 'field_test_multiple',
));
]);
$formatter = $display->getRenderer($field_name);
$this->assertEqual($formatter->getPluginId(), 'field_test_multiple');
$this->assertFalse(isset($formatter->randomValue));
@ -235,38 +266,40 @@ class EntityDisplayTest extends KernelTestBase {
// Check that the display has dependencies on the field and the module that
// provides the formatter.
$dependencies = $display->calculateDependencies()->getDependencies();
$this->assertEqual(array('config' => array('field.field.entity_test.entity_test.test_field'), 'module' => array('entity_test', 'field_test')), $dependencies);
$this->assertEqual(['config' => ['field.field.entity_test.entity_test.test_field'], 'module' => ['entity_test', 'field_test']], $dependencies);
}
/**
* Tests the behavior of a field component for a base field.
*/
public function testBaseFieldComponent() {
$display = EntityViewDisplay::create(array(
$display = EntityViewDisplay::create([
'targetEntityType' => 'entity_test_base_field_display',
'bundle' => 'entity_test_base_field_display',
'mode' => 'default',
));
]);
// Check that default options are correctly filled in.
$formatter_settings = \Drupal::service('plugin.manager.field.formatter')->getDefaultSettings('text_default');
$expected = array(
$expected = [
'test_no_display' => NULL,
'test_display_configurable' => array(
'test_display_configurable' => [
'label' => 'above',
'type' => 'text_default',
'settings' => $formatter_settings,
'third_party_settings' => array(),
'third_party_settings' => [],
'weight' => 10,
),
'test_display_non_configurable' => array(
'region' => 'content',
],
'test_display_non_configurable' => [
'label' => 'above',
'type' => 'text_default',
'settings' => $formatter_settings,
'third_party_settings' => array(),
'third_party_settings' => [],
'weight' => 11,
),
);
'region' => 'content',
],
];
foreach ($expected as $field_name => $options) {
$this->assertEqual($display->getComponent($field_name), $options);
}
@ -304,7 +337,7 @@ class EntityDisplayTest extends KernelTestBase {
*/
public function testDeleteBundle() {
// Create a node bundle, display and form display object.
$type = NodeType::create(array('type' => 'article'));
$type = NodeType::create(['type' => 'article']);
$type->save();
node_add_body_field($type);
entity_get_display('node', 'article', 'default')->save();
@ -324,30 +357,30 @@ class EntityDisplayTest extends KernelTestBase {
public function testDeleteField() {
$field_name = 'test_field';
// Create a field storage and a field.
$field_storage = FieldStorageConfig::create(array(
$field_storage = FieldStorageConfig::create([
'field_name' => $field_name,
'entity_type' => 'entity_test',
'type' => 'test_field'
));
]);
$field_storage->save();
$field = FieldConfig::create(array(
$field = FieldConfig::create([
'field_storage' => $field_storage,
'bundle' => 'entity_test',
));
]);
$field->save();
// Create default and teaser entity display.
EntityViewMode::create(array('id' => 'entity_test.teaser', 'targetEntityType' => 'entity_test'))->save();
EntityViewDisplay::create(array(
EntityViewMode::create(['id' => 'entity_test.teaser', 'targetEntityType' => 'entity_test'])->save();
EntityViewDisplay::create([
'targetEntityType' => 'entity_test',
'bundle' => 'entity_test',
'mode' => 'default',
))->setComponent($field_name)->save();
EntityViewDisplay::create(array(
])->setComponent($field_name)->save();
EntityViewDisplay::create([
'targetEntityType' => 'entity_test',
'bundle' => 'entity_test',
'mode' => 'teaser',
))->setComponent($field_name)->save();
])->setComponent($field_name)->save();
// Check the component exists.
$display = entity_get_display('entity_test', 'entity_test', 'default');
@ -369,27 +402,27 @@ class EntityDisplayTest extends KernelTestBase {
* Tests \Drupal\Core\Entity\EntityDisplayBase::onDependencyRemoval().
*/
public function testOnDependencyRemoval() {
$this->enableModules(array('field_plugins_test'));
$this->enableModules(['field_plugins_test']);
$field_name = 'test_field';
// Create a field.
$field_storage = FieldStorageConfig::create(array(
$field_storage = FieldStorageConfig::create([
'field_name' => $field_name,
'entity_type' => 'entity_test',
'type' => 'text'
));
]);
$field_storage->save();
$field = FieldConfig::create(array(
$field = FieldConfig::create([
'field_storage' => $field_storage,
'bundle' => 'entity_test',
));
]);
$field->save();
EntityViewDisplay::create(array(
EntityViewDisplay::create([
'targetEntityType' => 'entity_test',
'bundle' => 'entity_test',
'mode' => 'default',
))->setComponent($field_name, array('type' => 'field_plugins_test_text_formatter'))->save();
])->setComponent($field_name, ['type' => 'field_plugins_test_text_formatter'])->save();
// Check the component exists and is of the correct type.
$display = entity_get_display('entity_test', 'entity_test', 'default');
@ -427,47 +460,47 @@ class EntityDisplayTest extends KernelTestBase {
* Test getDisplayModeOptions().
*/
public function testGetDisplayModeOptions() {
NodeType::create(array('type' => 'article'))->save();
NodeType::create(['type' => 'article'])->save();
EntityViewDisplay::create(array(
EntityViewDisplay::create([
'targetEntityType' => 'node',
'bundle' => 'article',
'mode' => 'default',
))->setStatus(TRUE)->save();
])->setStatus(TRUE)->save();
$display_teaser = EntityViewDisplay::create(array(
$display_teaser = EntityViewDisplay::create([
'targetEntityType' => 'node',
'bundle' => 'article',
'mode' => 'teaser',
));
]);
$display_teaser->save();
EntityFormDisplay::create(array(
EntityFormDisplay::create([
'targetEntityType' => 'user',
'bundle' => 'user',
'mode' => 'default',
))->setStatus(TRUE)->save();
])->setStatus(TRUE)->save();
$form_display_teaser = EntityFormDisplay::create(array(
$form_display_teaser = EntityFormDisplay::create([
'targetEntityType' => 'user',
'bundle' => 'user',
'mode' => 'register',
));
]);
$form_display_teaser->save();
// Test getViewModeOptionsByBundle().
$view_modes = \Drupal::entityManager()->getViewModeOptionsByBundle('node', 'article');
$this->assertEqual($view_modes, array('default' => 'Default'));
$this->assertEqual($view_modes, ['default' => 'Default']);
$display_teaser->setStatus(TRUE)->save();
$view_modes = \Drupal::entityManager()->getViewModeOptionsByBundle('node', 'article');
$this->assertEqual($view_modes, array('default' => 'Default', 'teaser' => 'Teaser'));
$this->assertEqual($view_modes, ['default' => 'Default', 'teaser' => 'Teaser']);
// Test getFormModeOptionsByBundle().
$form_modes = \Drupal::entityManager()->getFormModeOptionsByBundle('user', 'user');
$this->assertEqual($form_modes, array('default' => 'Default'));
$this->assertEqual($form_modes, ['default' => 'Default']);
$form_display_teaser->setStatus(TRUE)->save();
$form_modes = \Drupal::entityManager()->getFormModeOptionsByBundle('user', 'user');
$this->assertEqual($form_modes, array('default' => 'Default', 'register' => 'Register'));
$this->assertEqual($form_modes, ['default' => 'Default', 'register' => 'Register']);
}
/**

View file

@ -36,14 +36,14 @@ class EntityFormDisplayTest extends KernelTestBase {
$this->assertTrue($form_display->isNew());
// Add some components and save the display.
$form_display->setComponent('component_1', array('weight' => 10))
$form_display->setComponent('component_1', ['weight' => 10])
->save();
// Check that entity_get_form_display() returns the correct object.
$form_display = entity_get_form_display('entity_test', 'entity_test', 'default');
$this->assertFalse($form_display->isNew());
$this->assertEqual($form_display->id(), 'entity_test.entity_test.default');
$this->assertEqual($form_display->getComponent('component_1'), array('weight' => 10, 'settings' => array(), 'third_party_settings' => array()));
$this->assertEqual($form_display->getComponent('component_1'), ['weight' => 10, 'settings' => [], 'third_party_settings' => [], 'region' => 'content']);
}
/**
@ -52,35 +52,35 @@ class EntityFormDisplayTest extends KernelTestBase {
public function testFieldComponent() {
// Create a field storage and a field.
$field_name = 'test_field';
$field_storage = FieldStorageConfig::create(array(
$field_storage = FieldStorageConfig::create([
'field_name' => $field_name,
'entity_type' => 'entity_test',
'type' => 'test_field'
));
]);
$field_storage->save();
$field = FieldConfig::create(array(
$field = FieldConfig::create([
'field_storage' => $field_storage,
'bundle' => 'entity_test',
));
]);
$field->save();
$form_display = EntityFormDisplay::create(array(
$form_display = EntityFormDisplay::create([
'targetEntityType' => 'entity_test',
'bundle' => 'entity_test',
'mode' => 'default',
));
]);
// Check that providing no options results in default values being used.
$form_display->setComponent($field_name);
$field_type_info = \Drupal::service('plugin.manager.field.field_type')->getDefinition($field_storage->getType());
$default_widget = $field_type_info['default_widget'];
$widget_settings = \Drupal::service('plugin.manager.field.widget')->getDefaultSettings($default_widget);
$expected = array(
$expected = [
'weight' => 3,
'type' => $default_widget,
'settings' => $widget_settings,
'third_party_settings' => array(),
);
'third_party_settings' => [],
];
$this->assertEqual($form_display->getComponent($field_name), $expected);
// Check that the getWidget() method returns the correct widget plugin.
@ -96,9 +96,9 @@ class EntityFormDisplayTest extends KernelTestBase {
$this->assertEqual($widget->randomValue, $random_value);
// Check that changing the definition creates a new widget.
$form_display->setComponent($field_name, array(
$form_display->setComponent($field_name, [
'type' => 'field_test_multiple',
));
]);
$widget = $form_display->getRenderer($field_name);
$this->assertEqual($widget->getPluginId(), 'test_field_widget');
$this->assertFalse(isset($widget->randomValue));
@ -106,9 +106,9 @@ class EntityFormDisplayTest extends KernelTestBase {
// Check that specifying an unknown widget (e.g. case of a disabled module)
// gets stored as is in the display, but results in the default widget being
// used.
$form_display->setComponent($field_name, array(
$form_display->setComponent($field_name, [
'type' => 'unknown_widget',
));
]);
$options = $form_display->getComponent($field_name);
$this->assertEqual($options['type'], 'unknown_widget');
$widget = $form_display->getRenderer($field_name);
@ -119,29 +119,31 @@ class EntityFormDisplayTest extends KernelTestBase {
* Tests the behavior of a field component for a base field.
*/
public function testBaseFieldComponent() {
$display = EntityFormDisplay::create(array(
$display = EntityFormDisplay::create([
'targetEntityType' => 'entity_test_base_field_display',
'bundle' => 'entity_test_base_field_display',
'mode' => 'default',
));
]);
// Check that default options are correctly filled in.
$formatter_settings = \Drupal::service('plugin.manager.field.widget')->getDefaultSettings('text_textfield');
$expected = array(
$expected = [
'test_no_display' => NULL,
'test_display_configurable' => array(
'test_display_configurable' => [
'type' => 'text_textfield',
'settings' => $formatter_settings,
'third_party_settings' => array(),
'third_party_settings' => [],
'weight' => 10,
),
'test_display_non_configurable' => array(
'region' => 'content',
],
'test_display_non_configurable' => [
'type' => 'text_textfield',
'settings' => $formatter_settings,
'third_party_settings' => array(),
'third_party_settings' => [],
'weight' => 11,
),
);
'region' => 'content',
],
];
foreach ($expected as $field_name => $options) {
$this->assertEqual($display->getComponent($field_name), $options);
}
@ -180,30 +182,30 @@ class EntityFormDisplayTest extends KernelTestBase {
public function testDeleteField() {
$field_name = 'test_field';
// Create a field storage and a field.
$field_storage = FieldStorageConfig::create(array(
$field_storage = FieldStorageConfig::create([
'field_name' => $field_name,
'entity_type' => 'entity_test',
'type' => 'test_field'
));
]);
$field_storage->save();
$field = FieldConfig::create(array(
$field = FieldConfig::create([
'field_storage' => $field_storage,
'bundle' => 'entity_test',
));
]);
$field->save();
// Create default and compact entity display.
EntityFormMode::create(array('id' => 'entity_test.compact', 'targetEntityType' => 'entity_test'))->save();
EntityFormDisplay::create(array(
EntityFormMode::create(['id' => 'entity_test.compact', 'targetEntityType' => 'entity_test'])->save();
EntityFormDisplay::create([
'targetEntityType' => 'entity_test',
'bundle' => 'entity_test',
'mode' => 'default',
))->setComponent($field_name)->save();
EntityFormDisplay::create(array(
])->setComponent($field_name)->save();
EntityFormDisplay::create([
'targetEntityType' => 'entity_test',
'bundle' => 'entity_test',
'mode' => 'compact',
))->setComponent($field_name)->save();
])->setComponent($field_name)->save();
// Check the component exists.
$display = entity_get_form_display('entity_test', 'entity_test', 'default');
@ -225,27 +227,27 @@ class EntityFormDisplayTest extends KernelTestBase {
* Tests \Drupal\Core\Entity\EntityDisplayBase::onDependencyRemoval().
*/
public function testOnDependencyRemoval() {
$this->enableModules(array('field_plugins_test'));
$this->enableModules(['field_plugins_test']);
$field_name = 'test_field';
// Create a field.
$field_storage = FieldStorageConfig::create(array(
$field_storage = FieldStorageConfig::create([
'field_name' => $field_name,
'entity_type' => 'entity_test',
'type' => 'text'
));
]);
$field_storage->save();
$field = FieldConfig::create(array(
$field = FieldConfig::create([
'field_storage' => $field_storage,
'bundle' => 'entity_test',
));
]);
$field->save();
EntityFormDisplay::create(array(
EntityFormDisplay::create([
'targetEntityType' => 'entity_test',
'bundle' => 'entity_test',
'mode' => 'default',
))->setComponent($field_name, array('type' => 'field_plugins_test_text_widget'))->save();
])->setComponent($field_name, ['type' => 'field_plugins_test_text_widget'])->save();
// Check the component exists and is of the correct type.
$display = entity_get_form_display('entity_test', 'entity_test', 'default');