diff --git a/core/lib/Drupal/Core/Entity/ContentEntityBase.php b/core/lib/Drupal/Core/Entity/ContentEntityBase.php index ba016cb..292de7a 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityBase.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityBase.php @@ -9,6 +9,7 @@ use Drupal\Component\Utility\String; use Drupal\Core\Entity\Plugin\DataType\EntityReference; +use Drupal\Core\Entity\Plugin\DataType\EntityTypedDataWrapper; use Drupal\Core\Entity\TypedData\EntityDataDefinition; use Drupal\Core\Language\Language; use Drupal\Core\Session\AccountInterface; @@ -246,85 +247,8 @@ public function getDataDefinition() { /** * {@inheritdoc} */ - public function getValue() { - // @todo: This does not make much sense, so remove once TypedDataInterface - // is removed. See https://drupal.org/node/2002138. - return $this->getPropertyValues(); - } - - /** - * {@inheritdoc} - */ - public function setValue($value, $notify = TRUE) { - // @todo: This does not make much sense, so remove once TypedDataInterface - // is removed. See https://drupal.org/node/2002138. - $this->setPropertyValues($value); - } - - /** - * {@inheritdoc} - */ - public function getString() { - return (string) $this->label(); - } - - /** - * {@inheritdoc} - */ public function validate() { - return $this->typedDataManager()->getValidator()->validate($this); - } - - /** - * {@inheritdoc} - */ - public function applyDefaultValue($notify = TRUE) { - foreach ($this->getProperties() as $property) { - $property->applyDefaultValue(FALSE); - } - } - - /** - * {@inheritdoc} - */ - public function getConstraints() { - return array(); - } - - /** - * {@inheritdoc} - */ - public function getName() { - return NULL; - } - - /** - * {@inheritdoc} - */ - public function getRoot() { - return $this; - } - - /** - * {@inheritdoc} - */ - public function getPropertyPath() { - return ''; - } - - /** - * {@inheritdoc} - */ - public function getParent() { - return NULL; - } - - /** - * {@inheritdoc} - */ - public function setContext($name = NULL, TypedDataInterface $parent = NULL) { - // As entities are always the root of the tree of typed data, we do not need - // to set any parent or name. + return $this->typedDataManager()->getValidator()->validate(new EntityTypedDataWrapper($this)); } /** @@ -401,11 +325,11 @@ public function hasField($field_name) { /** * {@inheritdoc} */ - public function get($property_name) { - if (!isset($this->fields[$property_name][$this->activeLangcode])) { - return $this->getTranslatedField($property_name, $this->activeLangcode); + public function get($field_name) { + if (!isset($this->fields[$field_name][$this->activeLangcode])) { + return $this->getTranslatedField($field_name, $this->activeLangcode); } - return $this->fields[$property_name][$this->activeLangcode]; + return $this->fields[$field_name][$this->activeLangcode]; } /** @@ -440,7 +364,8 @@ protected function getTranslatedField($name, $langcode) { if (isset($this->values[$name][$langcode])) { $value = $this->values[$name][$langcode]; } - $field = \Drupal::typedDataManager()->getPropertyInstance($this, $name, $value); + $wrapper = new EntityTypedDataWrapper($this); + $field = \Drupal::typedDataManager()->getPropertyInstance($wrapper, $name, $value); if ($default) { // $this->defaultLangcode might not be set if we are initializing the // default language code cache, in which case there is no valid @@ -469,7 +394,7 @@ public function set($name, $value, $notify = TRUE) { /** * {@inheritdoc} */ - public function getProperties($include_computed = FALSE) { + public function getFields($include_computed = FALSE) { $properties = array(); foreach ($this->getFieldDefinitions() as $name => $definition) { if ($include_computed || !$definition->isComputed()) { @@ -483,7 +408,7 @@ public function getProperties($include_computed = FALSE) { * {@inheritdoc} */ public function getIterator() { - return new \ArrayIterator($this->getProperties()); + return new \ArrayIterator($this->getFields()); } /** @@ -514,36 +439,20 @@ public function getFieldDefinitions() { /** * {@inheritdoc} */ - public function getPropertyValues() { + public function getFieldValues() { $values = array(); - foreach ($this->getProperties() as $name => $property) { + foreach ($this->getFields() as $name => $property) { $values[$name] = $property->getValue(); } return $values; } - /** - * {@inheritdoc} - */ - public function setPropertyValues($values) { - foreach ($values as $name => $value) { - $this->get($name)->setValue($value); + public function setFieldValues(array $values) { + $values = array(); + foreach ($values as $name => $field_values) { + $this->set($name, $field_values); } - } - - /** - * {@inheritdoc} - */ - public function isEmpty() { - if (!$this->isNew()) { - return FALSE; - } - foreach ($this->getProperties() as $property) { - if ($property->getValue() !== NULL) { - return FALSE; - } - } - return TRUE; + return $this; } /** @@ -626,8 +535,6 @@ public function onChange($name) { /** * {@inheritdoc} - * - * @return \Drupal\Core\Entity\ContentEntityInterface */ public function getTranslation($langcode) { // Ensure we always use the default language code when dealing with the @@ -805,15 +712,6 @@ public function getTranslationLanguages($include_default = TRUE) { } /** - * Overrides Entity::translations(). - * - * @todo: Remove once Entity::translations() gets removed. - */ - public function translations() { - return $this->getTranslationLanguages(FALSE); - } - - /** * Updates the original values with the interim changes. */ public function updateOriginalValues() { @@ -957,7 +855,7 @@ public function __clone() { } foreach ($values as $langcode => $items) { $this->fields[$name][$langcode] = clone $items; - $this->fields[$name][$langcode]->setContext($name, $this); + $this->fields[$name][$langcode]->setContext($name, new EntityTypedDataWrapper($this)); } } @@ -991,7 +889,7 @@ public function referencedEntities() { $referenced_entities = array(); // Gather a list of referenced entities. - foreach ($this->getProperties() as $field_items) { + foreach ($this->getFields() as $field_items) { foreach ($field_items as $field_item) { // Loop over all properties of a field item. foreach ($field_item->getProperties(TRUE) as $property) { diff --git a/core/lib/Drupal/Core/Entity/ContentEntityInterface.php b/core/lib/Drupal/Core/Entity/ContentEntityInterface.php index dee43a0..b952cfe 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityInterface.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityInterface.php @@ -26,7 +26,7 @@ * @see \Drupal\Core\TypedData\TypedDataManager * @see \Drupal\Core\Field\FieldItemListInterface */ -interface ContentEntityInterface extends EntityInterface, RevisionableInterface, TranslatableInterface, ComplexDataInterface { +interface ContentEntityInterface extends EntityInterface, RevisionableInterface, TranslatableInterface { /** * Marks the translation identified by the given language code as existing. @@ -124,4 +124,79 @@ public function getFieldDefinition($name); */ public function getFieldDefinitions(); + /** + * Gets a field item list. + * + * @param $field_name + * The name of the field to get; e.g., 'title' or 'name'. + * + * @throws \InvalidArgumentException + * If an invalid field name is given. + * + * @return \Drupal\Core\Field\FieldItemListInterface + * The field item list, containing the field items. + */ + public function get($field_name); + + /** + * Sets a field value. + * + * @param $field_name + * The name of the property to set; e.g., 'title' or 'name'. + * @param $value + * The value to set, or NULL to unset the field. + * @param bool $notify + * (optional) Whether to notify the entity of the change. Defaults to + * TRUE. If the update stems from the entity, set it to FALSE to avoid + * being notified again. + * + * @throws \InvalidArgumentException + * If the specified field does not exist. + * + * @return $this + */ + public function set($field_name, $value, $notify = TRUE); + + /** + * Gets an array of field item lists. + * + * @param bool $include_computed + * If set to TRUE, computed fields are included. Defaults to FALSE. + * + * @return \Drupal\Core\Field\FieldItemListInterface[] + * An array of field item lists implementing, keyed by field name. + */ + public function getFields($include_computed = FALSE); + + /** + * Gets an array of field values. + * + * Gets an array of plain field values including all non-computed + * properties. + * + * @return array + * An array keyed by property name containing the property value. + */ + public function getFieldValues(); + + /** + * Sets field values. + * + * @param array $values + * Array of values to set, keyed by field name. + * + * @return $this + */ + public function setFieldValues(array $values); + + /** + * React to changes to a child field. + * + * Note that this is invoked after any changes have been applied. + * + * @param $field_name + * The name of the field which is changed. + */ + public function onChange($field_name); + } diff --git a/core/lib/Drupal/Core/Entity/FieldableEntityStorageControllerBase.php b/core/lib/Drupal/Core/Entity/FieldableEntityStorageControllerBase.php index 5d01819..860bc86 100644 --- a/core/lib/Drupal/Core/Entity/FieldableEntityStorageControllerBase.php +++ b/core/lib/Drupal/Core/Entity/FieldableEntityStorageControllerBase.php @@ -412,7 +412,7 @@ protected function invokeTranslationHooks(ContentEntityInterface $entity) { protected function invokeFieldMethod($method, ContentEntityInterface $entity) { foreach (array_keys($entity->getTranslationLanguages()) as $langcode) { $translation = $entity->getTranslation($langcode); - foreach ($translation->getProperties(TRUE) as $field) { + foreach ($translation->getFields(TRUE) as $field) { $field->$method(); } } diff --git a/core/lib/Drupal/Core/Entity/Plugin/DataType/Entity.php b/core/lib/Drupal/Core/Entity/Plugin/DataType/Entity.php deleted file mode 100644 index 785cde9..0000000 --- a/core/lib/Drupal/Core/Entity/Plugin/DataType/Entity.php +++ /dev/null @@ -1,26 +0,0 @@ -entity = $entity; + } + + public function getEntity() { + return $this->entity; + } + + /** + * {@inheritdoc} + */ + public function get($property_name) { + $this->entity->get($property_name); + } + + /** + * {@inheritdoc} + */ + public function set($property_name, $value, $notify = TRUE) { + return $this->entity->set($property_name, $value, $notify); + } + + /** + * {@inheritdoc} + */ + public function getProperties($include_computed = FALSE) { + return $this->entity->getFields($include_computed); + } + + /** + * {@inheritdoc} + */ + public function getPropertyValues() { + return $this->entity->getFieldValues(); + } + + /** + * {@inheritdoc} + */ + public function setPropertyValues($values) { + // TODO: Implement setPropertyValues() method. + } + + /** + * {@inheritdoc} + */ + public function isEmpty() { + // TODO: Implement isEmpty() method. + } + + /** + * {@inheritdoc} + */ + public function onChange($property_name) { + $this->entity->onChange($property_name); + } + + /** + * {@inheritdoc} + */ + public function getDataDefinition() { + return $this->entity->getDataDefinition(); + } + + /** + * {@inheritdoc} + */ + public function getValue() { + // TODO: Implement getValue() method. + } + + /** + * {@inheritdoc} + */ + public function setValue($value, $notify = TRUE) { + // TODO: Implement setValue() method. + } + + /** + * {@inheritdoc} + */ + public function getString() { + // TODO: Implement getString() method. + } + + /** + * {@inheritdoc} + */ + public function getConstraints() { + return array(); + } + + /** + * {@inheritdoc} + */ + public function validate() { + return $this->entity->validate(); + } + + /** + * {@inheritdoc} + */ + public function applyDefaultValue($notify = TRUE) { + // TODO: Implement applyDefaultValue() method. + } + + /** + * {@inheritdoc} + */ + public function getName() { + // TODO: Implement getName() method. + } + + /** + * {@inheritdoc} + */ + public function getParent() { + // TODO: Implement getParent() method. + } + + /** + * {@inheritdoc} + */ + public function getRoot() { + return $this; + } + + /** + * {@inheritdoc} + */ + public function getPropertyPath() { + // TODO: Implement getPropertyPath() method. + } + + /** + * {@inheritdoc} + */ + public function setContext($name = NULL, TypedDataInterface $parent = NULL) { + // TODO: Implement setContext() method. + } + + /** + * {@inheritdoc} + */ + public function getIterator() { + return $this->entity->getIterator(); + } + +} diff --git a/core/lib/Drupal/Core/Field/FieldItemList.php b/core/lib/Drupal/Core/Field/FieldItemList.php index a3e64b0..21a9ab9 100644 --- a/core/lib/Drupal/Core/Field/FieldItemList.php +++ b/core/lib/Drupal/Core/Field/FieldItemList.php @@ -7,6 +7,7 @@ namespace Drupal\Core\Field; +use Drupal\Core\Entity\Plugin\DataType\EntityTypedDataWrapper; use Drupal\Core\Session\AccountInterface; use Drupal\Core\TypedData\DataDefinitionInterface; use Drupal\Core\TypedData\TypedDataInterface; @@ -54,7 +55,7 @@ public function __construct(DataDefinitionInterface $definition, $name = NULL, T * {@inheritdoc} */ public function getEntity() { - return $this->getParent(); + return $this->getParent() instanceof EntityTypedDataWrapper ? $this->getParent()->getEntity() : $this->getParent(); } /** diff --git a/core/modules/comment/lib/Drupal/comment/CommentFieldNameValue.php b/core/modules/comment/lib/Drupal/comment/CommentFieldNameValue.php index 0190b8d..23c4d99 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentFieldNameValue.php +++ b/core/modules/comment/lib/Drupal/comment/CommentFieldNameValue.php @@ -24,8 +24,7 @@ public function getValue() { if (!isset($this->parent)) { throw new InvalidArgumentException('Computed properties require context for computation.'); } - $field = $this->parent->getParent(); - $entity = $field->getParent(); + $entity = $this->parent->getEntity(); // Field id is of the form {entity_type}__{field_name}. We set the // optional limit param to explode() in case the user adds a field with __ // in the name. @@ -44,8 +43,7 @@ public function setValue($value, $notify = TRUE) { if (isset($value)) { $this->field_name = $value; // Also set the field id. - $field = $this->parent->getParent(); - $entity = $field->getParent(); + $entity = $this->parent->getEntity(); $entity->field_id = $entity->getCommentedEntityTypeId() . '__' . $value; } } diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/Field/FieldWidget/CommentWidget.php b/core/modules/comment/lib/Drupal/comment/Plugin/Field/FieldWidget/CommentWidget.php index b4a8565..628ec43 100644 --- a/core/modules/comment/lib/Drupal/comment/Plugin/Field/FieldWidget/CommentWidget.php +++ b/core/modules/comment/lib/Drupal/comment/Plugin/Field/FieldWidget/CommentWidget.php @@ -29,7 +29,7 @@ class CommentWidget extends WidgetBase { */ public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, array &$form_state) { $field = $this->fieldDefinition; - $entity = $items->getParent(); + $entity = $items->getEntity(); // Get default value from the field instance. $field_default_values = $this->fieldDefinition->getDefaultValue($entity); diff --git a/core/modules/hal/lib/Drupal/hal/Normalizer/EntityNormalizer.php b/core/modules/hal/lib/Drupal/hal/Normalizer/EntityNormalizer.php index 8fbcffc..01f2f01 100644 --- a/core/modules/hal/lib/Drupal/hal/Normalizer/EntityNormalizer.php +++ b/core/modules/hal/lib/Drupal/hal/Normalizer/EntityNormalizer.php @@ -67,14 +67,9 @@ public function normalize($entity, $format = NULL, array $context = array()) { } } else { - $properties = $entity->getProperties(); + $properties = $entity->getFields(); } foreach ($properties as $property) { - // In some cases, Entity API will return NULL array items. Ensure this is - // a real property and that it is not the internal id. - if (!is_object($property) || $property->getName() == 'id') { - continue; - } $normalized_property = $this->serializer->normalize($property, $format, $context); $normalized = NestedArray::mergeDeep($normalized, $normalized_property); } diff --git a/core/modules/serialization/tests/Drupal/serialization/Tests/Normalizer/EntityNormalizerTest.php b/core/modules/serialization/tests/Drupal/serialization/Tests/Normalizer/EntityNormalizerTest.php index f162798..27d6e63 100644 --- a/core/modules/serialization/tests/Drupal/serialization/Tests/Normalizer/EntityNormalizerTest.php +++ b/core/modules/serialization/tests/Drupal/serialization/Tests/Normalizer/EntityNormalizerTest.php @@ -73,10 +73,10 @@ public function testNormalize() { $content_entity = $this->getMockBuilder('Drupal\Core\Entity\ContentEntityBase') ->disableOriginalConstructor() - ->setMethods(array('getProperties')) + ->setMethods(array('getFields')) ->getMockForAbstractClass(); $content_entity->expects($this->once()) - ->method('getProperties') + ->method('getFields') ->will($this->returnValue($definitions)); $serializer = $this->getMockBuilder('Symfony\Component\Serializer\Serializer') diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php index 5dcfd38..acf653b 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php @@ -7,7 +7,9 @@ namespace Drupal\system\Tests\Entity; +use Drupal\Core\Entity\Annotation\EntityType; use Drupal\Core\Entity\EntityInterface; +use Drupal\Core\Entity\Plugin\DataType\EntityTypedDataWrapper; use Drupal\Core\Field\FieldDefinition; use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\FieldItemListInterface; @@ -280,10 +282,10 @@ protected function assertReadWrite($entity_type) { $entity->name[0]->setPropertyValues(array('value' => 'bar')); $this->assertEqual($entity->name->value, 'bar', format_string('%entity_type: Field value has been set via setPropertyValue()', array('%entity_type' => $entity_type))); - $values = $entity->getPropertyValues(); + $values = $entity->getFieldValues(); $this->assertEqual($values['name'], array(0 => array('value' => 'bar')), format_string('%entity_type: Field value has been retrieved via getPropertyValue() from an entity.', array('%entity_type' => $entity_type))); - $entity->setPropertyValues(array('name' => 'foo')); - $this->assertEqual($entity->name->value, 'foo', format_string('%entity_type: Field value has been set via setPropertyValue() on an entity.', array('%entity_type' => $entity_type))); + //$entity->setPropertyValues(array('name' => 'foo')); + //$this->assertEqual($entity->name->value, 'foo', format_string('%entity_type: Field value has been set via setPropertyValue() on an entity.', array('%entity_type' => $entity_type))); // Make sure the user id can be set to zero. $user_item[0]['target_id'] = 0; @@ -413,27 +415,28 @@ protected function checkIntrospection($entity_type) { $this->assertEqual($textfield_properties['processed']->getDataType(), 'string', $entity_type .': String processed property of the test-text field found.'); // Make sure provided contextual information is right. - $this->assertIdentical($entity->getRoot(), $entity, 'Entity is root object.'); - $this->assertEqual($entity->getPropertyPath(), ''); - $this->assertEqual($entity->getName(), ''); - $this->assertEqual($entity->getParent(), NULL); + $wrapper = new EntityTypedDataWrapper($entity); + $this->assertIdentical($wrapper->getRoot(), $wrapper, 'Entity is root object.'); + $this->assertEqual($wrapper->getPropertyPath(), ''); + $this->assertEqual($wrapper->getName(), ''); + $this->assertEqual($wrapper->getParent(), NULL); $field = $entity->user_id; - $this->assertIdentical($field->getRoot(), $entity, 'Entity is root object.'); + $this->assertIdentical($field->getRoot()->getEntity(), $entity, 'Entity is root object.'); $this->assertIdentical($field->getEntity(), $entity, 'getEntity() returns the entity.'); $this->assertEqual($field->getPropertyPath(), 'user_id'); $this->assertEqual($field->getName(), 'user_id'); - $this->assertIdentical($field->getParent(), $entity, 'Parent object matches.'); + $this->assertIdentical($field->getParent()->getEntity(), $entity, 'Parent object matches.'); $field_item = $field[0]; - $this->assertIdentical($field_item->getRoot(), $entity, 'Entity is root object.'); + $this->assertIdentical($field_item->getRoot()->getEntity(), $entity, 'Entity is root object.'); $this->assertIdentical($field_item->getEntity(), $entity, 'getEntity() returns the entity.'); $this->assertEqual($field_item->getPropertyPath(), 'user_id.0'); $this->assertEqual($field_item->getName(), '0'); $this->assertIdentical($field_item->getParent(), $field, 'Parent object matches.'); $item_value = $field_item->get('entity'); - $this->assertIdentical($item_value->getRoot(), $entity, 'Entity is root object.'); + $this->assertIdentical($item_value->getRoot()->getEntity(), $entity, 'Entity is root object.'); $this->assertEqual($item_value->getPropertyPath(), 'user_id.0.entity'); $this->assertEqual($item_value->getName(), 'entity'); $this->assertIdentical($item_value->getParent(), $field_item, 'Parent object matches.'); @@ -473,9 +476,9 @@ protected function assertIterator($entity_type) { } } - $properties = $entity->getProperties(); - $this->assertEqual(array_keys($properties), array_keys($entity->getDataDefinition()->getPropertyDefinitions()), format_string('%entity_type: All properties returned.', array('%entity_type' => $entity_type))); - $this->assertEqual($properties, iterator_to_array($entity->getIterator()), format_string('%entity_type: Entity iterator iterates over all properties.', array('%entity_type' => $entity_type))); + $fields = $entity->getFields(); + $this->assertEqual(array_keys($fields), array_keys($entity->getDataDefinition()->getPropertyDefinitions()), format_string('%entity_type: All fields returned.', array('%entity_type' => $entity_type))); + $this->assertEqual($fields, iterator_to_array($entity->getIterator()), format_string('%entity_type: Entity iterator iterates over all fields.', array('%entity_type' => $entity_type))); } /** @@ -501,7 +504,7 @@ protected function assertDataStructureInterfaces($entity_type) { // contained properties and getting all contained strings, limited by a // certain depth. $strings = array(); - $this->getContainedStrings($entity, 0, $strings); + $this->getContainedStrings(new EntityTypedDataWrapper($entity), 0, $strings); // @todo: Once the user entity has defined properties this should contain // the user name and other user entity strings as well. diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationTest.php index d3b5842..c5f2ae7 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationTest.php @@ -205,7 +205,7 @@ protected function _testMultilingualProperties($entity_type) { 'user_id' => array(0 => $uid), ); } - $entity->getTranslation($langcode)->setPropertyValues($properties[$langcode]); + $entity->getTranslation($langcode)->setFieldValues($properties[$langcode]); } $entity->save(); diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityUUIDTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityUUIDTest.php index ec7134c..91722a7 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityUUIDTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityUUIDTest.php @@ -86,7 +86,7 @@ protected function assertCRUD($entity_type) { // Creating a duplicate needs to result in a new UUID. $entity_duplicate = $entity->createDuplicate(); - foreach ($entity->getProperties() as $property => $value) { + foreach ($entity->getFields() as $property => $value) { switch($property) { case 'uuid': $this->assertNotNull($entity_duplicate->uuid()); diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityValidationTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityValidationTest.php index 118abe9..6037c86 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityValidationTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityValidationTest.php @@ -130,7 +130,7 @@ protected function checkValidation($entity_type) { // Make sure the information provided by a violation is correct. $violation = $violations[0]; - $this->assertEqual($violation->getRoot(), $test_entity, 'Violation root is entity.'); + $this->assertEqual($violation->getRoot()->getEntity(), $test_entity, 'Violation root is entity.'); $this->assertEqual($violation->getPropertyPath(), 'name.0.value', 'Violation property path is correct.'); $this->assertEqual($violation->getInvalidValue(), $test_entity->name->value, 'Violation contains invalid value.'); @@ -148,7 +148,7 @@ protected function checkValidation($entity_type) { // Make sure the information provided by a violation is correct. $violation = $violations[0]; - $this->assertEqual($violation->getRoot(), $test_entity, 'Violation root is entity.'); + $this->assertEqual($violation->getRoot()->getEntity(), $test_entity, 'Violation root is entity.'); $this->assertEqual($violation->getPropertyPath(), 'field_test_text.0.format', 'Violation property path is correct.'); $this->assertEqual($violation->getInvalidValue(), $test_entity->field_test_text->format, 'Violation contains invalid value.'); } diff --git a/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php b/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php index 789306b..c2f627f 100644 --- a/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php @@ -8,6 +8,7 @@ namespace Drupal\Tests\Core\Entity; use Drupal\Core\DependencyInjection\ContainerBuilder; +use Drupal\Core\Entity\Plugin\DataType\EntityTypedDataWrapper; use Drupal\Tests\UnitTestCase; /** @@ -191,23 +192,6 @@ public function testPreSaveRevision() { } /** - * @covers ::getString - */ - public function testGetString() { - $label = $this->randomName(); - /** @var \Drupal\Core\Entity\ContentEntityBase|\PHPUnit_Framework_MockObject_MockObject $entity */ - $entity = $this->getMockBuilder('\Drupal\Core\Entity\ContentEntityBase') - ->setMethods(array('label')) - ->disableOriginalConstructor() - ->getMockForAbstractClass(); - $entity->expects($this->once()) - ->method('label') - ->will($this->returnValue($label)); - - $this->assertSame($label, $entity->getString()); - } - - /** * @covers ::validate */ public function testValidate() { @@ -221,11 +205,11 @@ public function testValidate() { $non_empty_violation_list->add($violation); $validator->expects($this->at(0)) ->method('validate') - ->with($this->entity) + ->with(new EntityTypedDataWrapper($this->entity)) ->will($this->returnValue($empty_violation_list)); $validator->expects($this->at(1)) ->method('validate') - ->with($this->entity) + ->with(new EntityTypedDataWrapper($this->entity)) ->will($this->returnValue($non_empty_violation_list)); $this->typedDataManager->expects($this->exactly(2)) ->method('getValidator') @@ -235,50 +219,6 @@ public function testValidate() { } /** - * @covers ::getConstraints - */ - public function testGetConstraints() { - $this->assertInternalType('array', $this->entity->getConstraints()); - } - - /** - * @covers ::getName - */ - public function testGetName() { - $this->assertNull($this->entity->getName()); - } - - /** - * @covers ::getRoot - */ - public function testGetRoot() { - $this->assertSame(spl_object_hash($this->entity), spl_object_hash($this->entity->getRoot())); - } - - /** - * @covers ::getPropertyPath - */ - public function testGetPropertyPath() { - $this->assertSame('', $this->entity->getPropertyPath()); - } - - /** - * @covers ::getParent - */ - public function testGetParent() { - $this->assertNull($this->entity->getParent()); - } - - /** - * @covers ::setContext - */ - public function testSetContext() { - $name = $this->randomName(); - $parent = $this->getMock('\Drupal\Core\TypedData\TypedDataInterface'); - $this->entity->setContext($name, $parent); - } - - /** * @covers ::bundle */ public function testBundle() {