reverted: --- b/core/modules/media/media.info.yml +++ a/core/modules/media/media.info.yml @@ -5,5 +5,6 @@ version: VERSION core: 8.x dependencies: + - file - image - user only in patch2: unchanged: --- /dev/null +++ b/core/modules/media/tests/src/Functional/MediaRevisionTest.php @@ -0,0 +1,73 @@ +createMediaType([ + 'new_revision' => TRUE, + ]); + entity_get_form_display('media', $media_type->id(), 'default') + ->setComponent('field_media_test', [ + 'type' => 'string_textfield', + 'region' => 'content', + ]) + ->save(); + + // Create a media item. + $this->drupalGet('/media/add/' . $media_type->id()); + $page = $this->getSession()->getPage(); + $page->fillField('Name', 'Foobar'); + $page->fillField('Test source', $this->randomString()); + $page->pressButton('Save and publish'); + + // The media item was just created, so it should only have one revision. + $media = $this->container + ->get('entity_type.manager') + ->getStorage('media') + ->load(1); + $this->assertRevisionCount($media, 1); + + // If we edit the item, we should get a new revision. + $this->drupalGet('/media/1/edit'); + $this->assertSession()->checkboxChecked('Create new revision'); + $page = $this->getSession()->getPage(); + $page->fillField('Name', 'Foobaz'); + $page->pressButton('Save and keep published'); + $this->assertRevisionCount($media, 2); + } + + /** + * Asserts that an entity has a certain number of revisions. + * + * @param \Drupal\Core\Entity\EntityInterface $entity + * The entity in question. + * @param int $expected_revisions + * The expected number of revisions. + */ + protected function assertRevisionCount(EntityInterface $entity, $expected_revisions) { + $entity_type = $entity->getEntityType(); + + $count = $this->container + ->get('entity.query') + ->get($entity_type->id()) + ->count() + ->allRevisions() + ->condition($entity_type->getKey('id'), $entity->id()) + ->execute(); + + $this->assertSame($expected_revisions, (int) $count); + } + +}