diff -u b/core/modules/system/src/Tests/Entity/EntityChangedConstraintValidatorTest.php b/core/modules/system/src/Tests/Entity/EntityChangedConstraintValidatorTest.php --- b/core/modules/system/src/Tests/Entity/EntityChangedConstraintValidatorTest.php +++ b/core/modules/system/src/Tests/Entity/EntityChangedConstraintValidatorTest.php @@ -2,7 +2,7 @@ /** * @file - * Contains Drupal\system\Tests\Entity\EntityChangedConstraintValidatorTest. + * Contains \Drupal\system\Tests\Entity\EntityChangedConstraintValidatorTest. */ namespace Drupal\system\Tests\Entity; @@ -14,6 +14,8 @@ /** * Tests validation constraints for EntityChangedConstraintValidator. + * + * @group Validation */ class EntityChangedConstraintValidatorTest extends EntityUnitTestBase { @@ -24,18 +26,8 @@ */ protected $typedData; - public static function getInfo() { - return array( - 'name' => 'Entity changed constraint', - 'description' => 'Tests validation constraints for EntityChangedConstraintValidator.', - 'group' => 'Validation', - ); - } - public function setUp() { parent::setUp(); - - $this->installEntitySchema('entity_test_changed'); $this->typedData = $this->container->get('typed_data_manager'); } @@ -44,12 +36,17 @@ */ public function testValidation() { // Test the validation. - $user1 = $this->createUser(); - $entity_test = entity_create('entity_test_changed', array('user_id' => $user1->id())); + $account = $this->createUser(); + $entity_test = entity_create('entity_test', array('user_id' => $account->id())); $entity_test->save(); $violations = $entity_test->changed->validate(); $this->assertEqual($violations->count(), 0, 'Validation passed for correct value.'); + // Set a changed date in the future. + $entity_test->set('changed', REQUEST_TIME + 100000); + // Run validation on the changed field. + $violations = $entity_test->changed->validate(); + $this->assertEqual($violations->count(), 0, 'Validation passed for correct value.'); // Test the validation when an invalid value is passed. // Set a changed date in the past. reverted: --- b/core/modules/system/tests/modules/entity_test/entity_test.install +++ a/core/modules/system/tests/modules/entity_test/entity_test.install @@ -14,7 +14,6 @@ 'entity_test_rev', 'entity_test_mul', 'entity_test_mulrev', - 'entity_test_changed', ); foreach ($entity_types as $entity_type) { // Auto-create fields for testing. reverted: --- b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestChanged.php +++ /dev/null @@ -1,66 +0,0 @@ -setLabel(t('Changed')) - ->setDescription(t('The time that the entity was last edited.')) - ->setRevisionable(TRUE) - ->setTranslatable(TRUE); - return $fields; - } - - /** - * {@inheritdoc} - */ - public function getChangedTime() { - return $this->get('changed')->value; - } -} only in patch2: unchanged: --- a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTest.php +++ b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTest.php @@ -13,6 +13,7 @@ use Drupal\Core\Entity\EntityStorageInterface; use Drupal\user\EntityOwnerInterface; use Drupal\user\UserInterface; +use Drupal\Core\Entity\EntityChangedInterface; /** * Defines the test entity class. @@ -48,7 +49,7 @@ * field_ui_base_route = "entity.entity_test.admin_form", * ) */ -class EntityTest extends ContentEntityBase implements EntityOwnerInterface { +class EntityTest extends ContentEntityBase implements EntityOwnerInterface, EntityChangedInterface { /** * {@inheritdoc} @@ -120,6 +121,11 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { ), )); + $fields['changed'] = BaseFieldDefinition::create('changed') + ->setLabel(t('Changed')) + ->setDescription(t('The time that the entity was last edited.')) + ->setRevisionable(TRUE) + ->setTranslatable(TRUE); return $fields; } @@ -175,4 +181,10 @@ public function getName() { return $this->get('name')->value; } + /** + * {@inheritdoc} + */ + public function getChangedTime() { + return $this->get('changed')->value; + } }