public function MediaRevisionTest::testImageMediaRevision in Drupal 9
Same name and namespace in other branches
- 8 core/modules/media/tests/src/Functional/MediaRevisionTest.php \Drupal\Tests\media\Functional\MediaRevisionTest::testImageMediaRevision()
Tests creating revisions of an Image media item.
File
- core/
modules/ media/ tests/ src/ Functional/ MediaRevisionTest.php, line 124
Class
- MediaRevisionTest
- Tests the revisionability of media entities.
Namespace
Drupal\Tests\media\FunctionalCode
public function testImageMediaRevision() {
$assert = $this
->assertSession();
$this
->createMediaType('image', [
'id' => 'image',
'new_revision' => TRUE,
]);
/** @var \Drupal\field\FieldConfigInterface $field */
// Disable the alt text field, because this is not a JavaScript test and
// the alt text field will therefore not appear without a full page refresh.
$field = FieldConfig::load('media.image.field_media_image');
$settings = $field
->getSettings();
$settings['alt_field'] = FALSE;
$settings['alt_field_required'] = FALSE;
$field
->set('settings', $settings);
$field
->save();
// Create a media item.
$this
->drupalGet('/media/add/image');
$page = $this
->getSession()
->getPage();
$page
->fillField('Name', 'Foobar');
$page
->attachFileToField('Image', $this->root . '/core/modules/media/tests/fixtures/example_1.jpeg');
$page
->pressButton('Save');
$assert
->addressEquals('admin/content/media');
// 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');
$assert
->checkboxChecked('Create new revision');
$page = $this
->getSession()
->getPage();
$page
->fillField('Name', 'Foobaz');
$page
->pressButton('Save');
$this
->assertRevisionCount($media, 2);
// Confirm the correct revision title appears on "view revisions" page.
$media = $this->container
->get('entity_type.manager')
->getStorage('media')
->loadUnchanged(1);
$this
->drupalGet("media/" . $media
->id() . "/revisions/" . $media
->getRevisionId() . "/view");
$assert
->pageTextContains('Foobaz');
}