diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBundleBase.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBundleBase.php index d95ddc689364b8531a46016a19eef026dab7d6f5..915b19d9583b01cc7857b125faa7ea570edeedae 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBundleBase.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBundleBase.php @@ -26,9 +26,9 @@ protected function renameDisplays() { // Rename entity displays. if ($this->getOriginalId() !== $this->id()) { foreach ($this->loadDisplays('entity_view_display') as $display) { - $new_id = $this->getEntityType()->getBundleOf() . '.' . $this->id() . '.' . $display->mode; + $new_id = $this->getEntityType()->getBundleOf() . '.' . $this->id() . '.' . $display->getMode(); $display->set('id', $new_id); - $display->bundle = $this->id(); + $display->setTargetBundle($this->id()); $display->save(); } } @@ -36,9 +36,9 @@ protected function renameDisplays() { // Rename entity form displays. if ($this->getOriginalId() !== $this->id()) { foreach ($this->loadDisplays('entity_form_display') as $form_display) { - $new_id = $this->getEntityType()->getBundleOf() . '.' . $this->id() . '.' . $form_display->mode; + $new_id = $this->getEntityType()->getBundleOf() . '.' . $this->id() . '.' . $form_display->getMode(); $form_display->set('id', $new_id); - $form_display->bundle = $this->id(); + $form_display->setTargetBundle($this->id()); $form_display->save(); } } diff --git a/core/lib/Drupal/Core/Entity/Display/EntityDisplayInterface.php b/core/lib/Drupal/Core/Entity/Display/EntityDisplayInterface.php index dbc4741c0f1d73952f326d0b71bcaea2f87fc9db..fd25c290e6685937d2fe2aa1417faecf053c90ae 100644 --- a/core/lib/Drupal/Core/Entity/Display/EntityDisplayInterface.php +++ b/core/lib/Drupal/Core/Entity/Display/EntityDisplayInterface.php @@ -22,10 +22,11 @@ interface EntityDisplayInterface extends ConfigEntityInterface, EntityWithPlugin * The new object necessarily has the same $targetEntityType and $bundle * properties than the original one. * - * @param $view_mode + * @param string $view_mode * The view mode for the new object. * * @return static + * A duplicate of this object with the given view mode. */ public function createCopy($view_mode); @@ -91,4 +92,46 @@ public function getHighestWeight(); */ public function getRenderer($field_name); + /** + * Returns the entity type for which this display is used. + * + * @return string + * The entity type id. + */ + public function getTargetEntityTypeId(); + + /** + * Returns the view or form mode to be displayed. + * + * @return string + * The mode to be displayed. + */ + public function getMode(); + + /** + * Returns the original view or form mode that was requested. + * + * @return string + * The original mode that was requested. + */ + public function getOriginalMode(); + + /** + * Returns the bundle to be displayed. + * + * @return string + * The bundle to be displayed. + */ + public function getTargetBundle(); + + /** + * Sets the bundle to be displayed. + * + * @param string $bundle + * The bundle to be displayed. + * + * @return $this + */ + public function setTargetBundle($bundle); + } diff --git a/core/lib/Drupal/Core/Entity/EntityDisplayBase.php b/core/lib/Drupal/Core/Entity/EntityDisplayBase.php index aba35e27544d0bc4bee6c8a8e864503a9145c34d..a1c8e84e5347bd84c98b3e233dc922611aba61f0 100644 --- a/core/lib/Drupal/Core/Entity/EntityDisplayBase.php +++ b/core/lib/Drupal/Core/Entity/EntityDisplayBase.php @@ -36,21 +36,21 @@ abstract class EntityDisplayBase extends ConfigEntityBase implements EntityDispl * * @var string */ - public $id; + protected $id; /** * Entity type to be displayed. * * @var string */ - public $targetEntityType; + protected $targetEntityType; /** * Bundle to be displayed. * * @var string */ - public $bundle; + protected $bundle; /** * A list of field definitions eligible for configuration in this display. @@ -64,7 +64,7 @@ abstract class EntityDisplayBase extends ConfigEntityBase implements EntityDispl * * @var string */ - public $mode = self::CUSTOM_MODE; + protected $mode = self::CUSTOM_MODE; /** * Whether this display is enabled or not. If the entity (form) display @@ -94,7 +94,7 @@ abstract class EntityDisplayBase extends ConfigEntityBase implements EntityDispl * * @var string */ - public $originalMode; + protected $originalMode; /** * The plugin objects used for this display, keyed by field name. @@ -144,6 +144,91 @@ public function __construct(array $values, $entity_type) { $this->init(); } + /** + * Initializes the display. + * + * This fills in default options for components: + * - that are not explicitly known as either "visible" or "hidden" in the + * display, + * - or that are not supposed to be configurable. + */ + protected function init() { + // Only populate defaults for "official" view modes and form modes. + if ($this->mode !== static::CUSTOM_MODE) { + // Fill in defaults for extra fields. + $context = $this->displayContext == 'view' ? 'display' : $this->displayContext; + $extra_fields = \Drupal::entityManager()->getExtraFields($this->targetEntityType, $this->bundle); + $extra_fields = isset($extra_fields[$context]) ? $extra_fields[$context] : array(); + foreach ($extra_fields as $name => $definition) { + if (!isset($this->content[$name]) && !isset($this->hidden[$name])) { + // Extra fields are visible by default unless they explicitly say so. + if (!isset($definition['visible']) || $definition['visible'] == TRUE) { + $this->content[$name] = array( + 'weight' => $definition['weight'] + ); + } + else { + $this->hidden[$name] = TRUE; + } + } + } + + // Fill in defaults for fields. + $fields = $this->getFieldDefinitions(); + foreach ($fields as $name => $definition) { + if (!$definition->isDisplayConfigurable($this->displayContext) || (!isset($this->content[$name]) && !isset($this->hidden[$name]))) { + $options = $definition->getDisplayOptions($this->displayContext); + + if (!empty($options['type']) && $options['type'] == 'hidden') { + $this->hidden[$name] = TRUE; + } + elseif ($options) { + $this->content[$name] = $this->pluginManager->prepareConfiguration($definition->getType(), $options); + } + // Note: (base) fields that do not specify display options are not + // tracked in the display at all, in order to avoid cluttering the + // configuration that gets saved back. + } + } + } + } + + /** + * {@inheritdoc} + */ + public function getTargetEntityTypeId() { + return $this->targetEntityType; + } + + /** + * {@inheritdoc} + */ + public function getMode() { + return $this->get('mode'); + } + + /** + * {@inheritdoc} + */ + public function getOriginalMode() { + return $this->get('originalMode'); + } + + /** + * {@inheritdoc} + */ + public function getTargetBundle() { + return $this->bundle; + } + + /** + * {@inheritdoc} + */ + public function setTargetBundle($bundle) { + $this->set('bundle', $bundle); + return $this; + } + /** * {@inheritdoc} */ @@ -213,55 +298,6 @@ public function toArray() { return $properties; } - /** - * Initializes the display. - * - * This fills in default options for components: - * - that are not explicitly known as either "visible" or "hidden" in the - * display, - * - or that are not supposed to be configurable. - */ - protected function init() { - // Only populate defaults for "official" view modes and form modes. - if ($this->mode !== static::CUSTOM_MODE) { - // Fill in defaults for extra fields. - $context = $this->displayContext == 'view' ? 'display' : $this->displayContext; - $extra_fields = \Drupal::entityManager()->getExtraFields($this->targetEntityType, $this->bundle); - $extra_fields = isset($extra_fields[$context]) ? $extra_fields[$context] : array(); - foreach ($extra_fields as $name => $definition) { - if (!isset($this->content[$name]) && !isset($this->hidden[$name])) { - // Extra fields are visible by default unless they explicitly say so. - if (!isset($definition['visible']) || $definition['visible'] == TRUE) { - $this->content[$name] = array( - 'weight' => $definition['weight'] - ); - } - else { - $this->hidden[$name] = TRUE; - } - } - } - - // Fill in defaults for fields. - $fields = $this->getFieldDefinitions(); - foreach ($fields as $name => $definition) { - if (!$definition->isDisplayConfigurable($this->displayContext) || (!isset($this->content[$name]) && !isset($this->hidden[$name]))) { - $options = $definition->getDisplayOptions($this->displayContext); - - if (!empty($options['type']) && $options['type'] == 'hidden') { - $this->hidden[$name] = TRUE; - } - elseif ($options) { - $this->content[$name] = $this->pluginManager->prepareConfiguration($definition->getType(), $options); - } - // Note: (base) fields that do not specify display options are not - // tracked in the display at all, in order to avoid cluttering the - // configuration that gets saved back. - } - } - } - } - /** * {@inheritdoc} */ diff --git a/core/modules/field_ui/src/Form/EntityDisplayFormBase.php b/core/modules/field_ui/src/Form/EntityDisplayFormBase.php index 67052743b1c74b4c15e615d7c3d9ea87cfb0845b..f4e336521c6c4be905aa5af1201f2c8ac735d3a7 100644 --- a/core/modules/field_ui/src/Form/EntityDisplayFormBase.php +++ b/core/modules/field_ui/src/Form/EntityDisplayFormBase.php @@ -149,7 +149,7 @@ public function getRegionOptions() { */ protected function getFieldDefinitions() { $context = $this->displayContext; - return array_filter($this->entityManager->getFieldDefinitions($this->entity->targetEntityType, $this->entity->bundle), function(FieldDefinitionInterface $field_definition) use ($context) { + return array_filter($this->entityManager->getFieldDefinitions($this->entity->getTargetEntityTypeId(), $this->entity->getTargetBundle()), function(FieldDefinitionInterface $field_definition) use ($context) { return $field_definition->isDisplayConfigurable($context); }); } @@ -164,13 +164,13 @@ public function form(array $form, FormStateInterface $form_state) { $extra_fields = $this->getExtraFields(); $form += array( - '#entity_type' => $this->entity->targetEntityType, - '#bundle' => $this->entity->bundle, + '#entity_type' => $this->entity->getTargetEntityTypeId(), + '#bundle' => $this->entity->getTargetBundle(), '#fields' => array_keys($field_definitions), '#extra' => array_keys($extra_fields), ); - if (empty($field_definitions) && empty($extra_fields) && $route_info = FieldUI::getOverviewRouteInfo($this->entity->targetEntityType, $this->entity->bundle)) { + if (empty($field_definitions) && empty($extra_fields) && $route_info = FieldUI::getOverviewRouteInfo($this->entity->getTargetEntityTypeId(), $this->entity->getTargetBundle())) { drupal_set_message($this->t('There are no fields yet added. You can add new fields on the Manage fields page.', array('@link' => $route_info->toString())), 'warning'); return $form; } @@ -217,7 +217,7 @@ public function form(array $form, FormStateInterface $form_state) { $form['fields'] = $table; // Custom display settings. - if ($this->entity->mode == 'default') { + if ($this->entity->getMode() == 'default') { // Only show the settings if there is at least one custom display mode. if ($display_modes = $this->getDisplayModes()) { $form['modes'] = array( @@ -538,7 +538,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { $form_values = $form_state->getValues(); // Handle the 'display modes' checkboxes if present. - if ($this->entity->mode == 'default' && !empty($form_values['display_modes_custom'])) { + if ($this->entity->getMode() == 'default' && !empty($form_values['display_modes_custom'])) { $display_modes = $this->getDisplayModes(); $current_statuses = $this->getDisplayStatuses(); @@ -548,8 +548,8 @@ public function submitForm(array &$form, FormStateInterface $form_state) { // If no display exists for the newly enabled view mode, initialize // it with those from the 'default' view mode, which were used so // far. - if (!$this->entityManager->getStorage($this->entity->getEntityTypeId())->load($this->entity->targetEntityType . '.' . $this->entity->bundle . '.' . $mode)) { - $display = $this->getEntityDisplay($this->entity->targetEntityType, $this->entity->bundle, 'default')->createCopy($mode); + if (!$this->entityManager->getStorage($this->entity->getEntityTypeId())->load($this->entity->getTargetEntityTypeId() . '.' . $this->entity->getTargetBundle() . '.' . $mode)) { + $display = $this->getEntityDisplay($this->entity->getTargetEntityTypeId(), $this->entity->getTargetBundle(), 'default')->createCopy($mode); $display->save(); } @@ -854,7 +854,7 @@ public function reduceOrder($array, $a) { */ protected function getExtraFields() { $context = $this->displayContext == 'view' ? 'display' : $this->displayContext; - $extra_fields = $this->entityManager->getExtraFields($this->entity->targetEntityType, $this->entity->bundle); + $extra_fields = $this->entityManager->getExtraFields($this->entity->getTargetEntityTypeId(), $this->entity->getTargetBundle()); return isset($extra_fields[$context]) ? $extra_fields[$context] : array(); } @@ -967,7 +967,7 @@ protected function getDisplays() { $display_entity_type = $this->entity->getEntityTypeId(); $entity_type = $this->entityManager->getDefinition($display_entity_type); $config_prefix = $entity_type->getConfigPrefix(); - $ids = $this->configFactory()->listAll($config_prefix . '.' . $this->entity->targetEntityType . '.' . $this->entity->bundle . '.'); + $ids = $this->configFactory()->listAll($config_prefix . '.' . $this->entity->getTargetEntityTypeId() . '.' . $this->entity->getTargetBundle() . '.'); foreach ($ids as $id) { $config_id = str_replace($config_prefix . '.', '', $id); list(,, $display_mode) = explode('.', $config_id); diff --git a/core/modules/field_ui/src/Form/EntityFormDisplayEditForm.php b/core/modules/field_ui/src/Form/EntityFormDisplayEditForm.php index 0120cd5d19997edac7b999cf095063fdbc15c43d..81e97fda98a14617e5df82508f8afff2a7f78b21 100644 --- a/core/modules/field_ui/src/Form/EntityFormDisplayEditForm.php +++ b/core/modules/field_ui/src/Form/EntityFormDisplayEditForm.php @@ -67,7 +67,7 @@ protected function getPlugin(FieldDefinitionInterface $field_definition, $config if ($configuration && $configuration['type'] != 'hidden') { $plugin = $this->pluginManager->getInstance(array( 'field_definition' => $field_definition, - 'form_mode' => $this->entity->mode, + 'form_mode' => $this->entity->getMode(), 'configuration' => $configuration )); } @@ -86,7 +86,7 @@ protected function getDefaultPlugin($field_type) { * {@inheritdoc} */ protected function getDisplayModes() { - return $this->entityManager->getFormModes($this->entity->targetEntityType); + return $this->entityManager->getFormModes($this->entity->getTargetEntityTypeId()); } /** @@ -105,10 +105,10 @@ protected function getTableHeader() { * {@inheritdoc} */ protected function getOverviewUrl($mode) { - $entity_type = $this->entityManager->getDefinition($this->entity->targetEntityType); + $entity_type = $this->entityManager->getDefinition($this->entity->getTargetEntityTypeId()); $field_entity_type = $entity_type->getBundleEntityType() != 'bundle'? $entity_type->getBundleEntityType() : $entity_type->id(); return Url::fromRoute('entity.entity_form_display.' . $field_entity_type . '.form_mode', [ - $this->bundleEntityTypeId => $this->entity->bundle, + $this->bundleEntityTypeId => $this->entity->getTargetBundle(), 'form_mode_name' => $mode, ]); } @@ -124,7 +124,7 @@ protected function thirdPartySettingsForm(PluginSettingsInterface $plugin, Field $settings_form[$module] = $this->moduleHandler->invoke($module, 'field_widget_third_party_settings_form', array( $plugin, $field_definition, - $this->entity->mode, + $this->entity->getMode(), $form, $form_state, )); @@ -139,7 +139,7 @@ protected function alterSettingsSummary(array &$summary, PluginSettingsInterface $context = array( 'widget' => $plugin, 'field_definition' => $field_definition, - 'form_mode' => $this->entity->mode, + 'form_mode' => $this->entity->getMode(), ); $this->moduleHandler->alter('field_widget_settings_summary', $summary, $context); } diff --git a/core/modules/field_ui/src/Form/EntityViewDisplayEditForm.php b/core/modules/field_ui/src/Form/EntityViewDisplayEditForm.php index 55abe97888bc9cf42521697c79de2d68d167807e..03c08110ff17918efa66776e1dd960e043bfa294 100644 --- a/core/modules/field_ui/src/Form/EntityViewDisplayEditForm.php +++ b/core/modules/field_ui/src/Form/EntityViewDisplayEditForm.php @@ -100,7 +100,7 @@ protected function getPlugin(FieldDefinitionInterface $field_definition, $config if ($configuration && $configuration['type'] != 'hidden') { $plugin = $this->pluginManager->getInstance(array( 'field_definition' => $field_definition, - 'view_mode' => $this->entity->mode, + 'view_mode' => $this->entity->getMode(), 'configuration' => $configuration )); } @@ -119,7 +119,7 @@ protected function getDefaultPlugin($field_type) { * {@inheritdoc} */ protected function getDisplayModes() { - return $this->entityManager->getViewModes($this->entity->targetEntityType); + return $this->entityManager->getViewModes($this->entity->getTargetEntityTypeId()); } /** @@ -139,10 +139,10 @@ protected function getTableHeader() { * {@inheritdoc} */ protected function getOverviewUrl($mode) { - $entity_type = $this->entityManager->getDefinition($this->entity->targetEntityType); + $entity_type = $this->entityManager->getDefinition($this->entity->getTargetEntityTypeId()); $field_entity_type = $entity_type->getBundleEntityType() != 'bundle'? $entity_type->getBundleEntityType() : $entity_type->id(); return Url::fromRoute('entity.entity_view_display.' . $field_entity_type . '.view_mode', [ - $this->bundleEntityTypeId => $this->entity->bundle, + $this->bundleEntityTypeId => $this->entity->getTargetBundle(), 'view_mode_name' => $mode, ]); } @@ -173,7 +173,7 @@ protected function thirdPartySettingsForm(PluginSettingsInterface $plugin, Field $settings_form[$module] = $this->moduleHandler->invoke($module, 'field_formatter_third_party_settings_form', array( $plugin, $field_definition, - $this->entity->mode, + $this->entity->getMode(), $form, $form_state, )); @@ -188,7 +188,7 @@ protected function alterSettingsSummary(array &$summary, PluginSettingsInterface $context = array( 'formatter' => $plugin, 'field_definition' => $field_definition, - 'view_mode' => $this->entity->mode, + 'view_mode' => $this->entity->getMode(), ); $this->moduleHandler->alter('field_formatter_settings_summary', $summary, $context); } diff --git a/core/modules/field_ui/src/Tests/EntityDisplayTest.php b/core/modules/field_ui/src/Tests/EntityDisplayTest.php index 5bdc3e686e3ec881d92b1af0e4182c0ba581b73e..09887da7568aca54b63d3e1f511d787c4bd2145f 100644 --- a/core/modules/field_ui/src/Tests/EntityDisplayTest.php +++ b/core/modules/field_ui/src/Tests/EntityDisplayTest.php @@ -87,15 +87,15 @@ public function testEntityDisplayCRUD() { // Check that CreateCopy() creates a new component that can be correclty // saved. - EntityViewMode::create(array('id' => $display->targetEntityType . '.other_view_mode', 'targetEntityType' => $display->targetEntityType))->save(); + EntityViewMode::create(array('id' => $display->getTargetEntityTypeId() . '.other_view_mode', 'targetEntityType' => $display->getTargetEntityTypeId()))->save(); $new_display = $display->createCopy('other_view_mode'); $new_display->save(); $new_display = entity_load('entity_view_display', $new_display->id()); $dependencies = $new_display->calculateDependencies(); $this->assertEqual(array('config' => array('core.entity_view_mode.entity_test.other_view_mode'), 'module' => array('entity_test')), $dependencies); - $this->assertEqual($new_display->targetEntityType, $display->targetEntityType); - $this->assertEqual($new_display->bundle, $display->bundle); - $this->assertEqual($new_display->mode, 'other_view_mode'); + $this->assertEqual($new_display->getTargetEntityTypeId(), $display->getTargetEntityTypeId()); + $this->assertEqual($new_display->getTargetBundle(), $display->getTargetBundle()); + $this->assertEqual($new_display->getMode(), 'other_view_mode'); $this->assertEqual($new_display->getComponents(), $display->getComponents()); } @@ -115,7 +115,7 @@ public function testEntityGetDisplay() { // 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->id(), 'entity_test.entity_test.default'); $this->assertEqual($display->getComponent('component_1'), array( 'weight' => 10, 'settings' => array(), 'third_party_settings' => array())); } @@ -287,11 +287,11 @@ public function testRenameDeleteBundle() { $old_form_display = entity_load('entity_form_display', 'node.article.default'); $this->assertFalse((bool) $old_form_display); $new_display = entity_load('entity_view_display', 'node.article_rename.default'); - $this->assertEqual('article_rename', $new_display->bundle); - $this->assertEqual('node.article_rename.default', $new_display->id); + $this->assertEqual('article_rename', $new_display->getTargetBundle()); + $this->assertEqual('node.article_rename.default', $new_display->id()); $new_form_display = entity_load('entity_form_display', 'node.article_rename.default'); - $this->assertEqual('article_rename', $new_form_display->bundle); - $this->assertEqual('node.article_rename.default', $new_form_display->id); + $this->assertEqual('article_rename', $new_form_display->getTargetBundle()); + $this->assertEqual('node.article_rename.default', $new_form_display->id()); $expected_view_dependencies = array( 'config' => array('field.field.node.article_rename.body', 'node.type.article_rename'), diff --git a/core/modules/field_ui/src/Tests/EntityFormDisplayTest.php b/core/modules/field_ui/src/Tests/EntityFormDisplayTest.php index a6529423c26e860af1666a9982be2148a943a4cc..fccc525f342bd25931cf672a953703535c710f65 100644 --- a/core/modules/field_ui/src/Tests/EntityFormDisplayTest.php +++ b/core/modules/field_ui/src/Tests/EntityFormDisplayTest.php @@ -39,7 +39,7 @@ public function testEntityGetFromDisplay() { // 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->id(), 'entity_test.entity_test.default'); $this->assertEqual($form_display->getComponent('component_1'), array('weight' => 10, 'settings' => array(), 'third_party_settings' => array())); } diff --git a/core/modules/history/history.module b/core/modules/history/history.module index 61395dec70fbde61645a110b91285eeaf8bf3b02..57439bba633f3f642be710569b6b5679e87b13a7 100644 --- a/core/modules/history/history.module +++ b/core/modules/history/history.module @@ -134,7 +134,7 @@ function history_cron() { */ function history_node_view_alter(array &$build, EntityInterface $node, EntityViewDisplayInterface $display) { // Update the history table, stating that this user viewed this node. - if (($display->originalMode === 'full') && \Drupal::currentUser()->isAuthenticated()) { + if (($display->getOriginalMode() === 'full') && \Drupal::currentUser()->isAuthenticated()) { // When the window's "load" event is triggered, mark the node as read. // This still allows for Drupal behaviors (which are triggered on the // "DOMContentReady" event) to add "new" and "updated" indicators. diff --git a/core/tests/Drupal/Tests/Core/Config/Entity/EntityDisplayBaseTest.php b/core/tests/Drupal/Tests/Core/Config/Entity/EntityDisplayBaseTest.php new file mode 100644 index 0000000000000000000000000000000000000000..0ceeb6167bd7e0fc282d44c8d2079c7e4761268a --- /dev/null +++ b/core/tests/Drupal/Tests/Core/Config/Entity/EntityDisplayBaseTest.php @@ -0,0 +1,74 @@ +getMockForAbstractClass('\Drupal\Core\Entity\EntityDisplayBase', [], '', FALSE); + $reflection = new \ReflectionProperty($mock, 'targetEntityType'); + $reflection->setAccessible(TRUE); + $reflection->setValue($mock, 'test'); + $this->assertEquals('test', $mock->getTargetEntityTypeId()); + } + + /** + * @covers ::getMode() + */ + public function testGetMode() { + $mock = $this->getMockForAbstractClass('\Drupal\Core\Entity\EntityDisplayBase', [], '', FALSE); + $reflection = new \ReflectionProperty($mock, 'mode'); + $reflection->setAccessible(TRUE); + $reflection->setValue($mock, 'test'); + $this->assertEquals('test', $mock->getMode()); + } + + /** + * @covers ::getOriginalMode() + */ + public function testGetOriginalMode() { + $mock = $this->getMockForAbstractClass('\Drupal\Core\Entity\EntityDisplayBase', [], '', FALSE); + $reflection = new \ReflectionProperty($mock, 'originalMode'); + $reflection->setAccessible(TRUE); + $reflection->setValue($mock, 'test'); + $this->assertEquals('test', $mock->getOriginalMode()); + } + + /** + * @covers ::getDisplayBundle() + */ + public function testGetDisplayBundle() { + $mock = $this->getMockForAbstractClass('\Drupal\Core\Entity\EntityDisplayBase', [], '', FALSE); + $reflection = new \ReflectionProperty($mock, 'bundle'); + $reflection->setAccessible(TRUE); + $reflection->setValue($mock, 'test'); + $this->assertEquals('test', $mock->getTargetBundle()); + } + + /** + * @covers ::setDisplayBundle() + */ + public function testSetDisplayBundle() { + $mock = $this->getMockForAbstractClass('\Drupal\Core\Entity\EntityDisplayBase', [], '', FALSE); + $reflection = new \ReflectionProperty($mock, 'bundle'); + $reflection->setAccessible(TRUE); + $mock->setTargetBundle('test'); + $this->assertEquals('test', $reflection->getValue($mock)); + } + +}