function MediaRevisionTest::testFileMediaRevision
Same name in other branches
- 9 core/modules/media/tests/src/Functional/MediaRevisionTest.php \Drupal\Tests\media\Functional\MediaRevisionTest::testFileMediaRevision()
- 8.9.x core/modules/media/tests/src/Functional/MediaRevisionTest.php \Drupal\Tests\media\Functional\MediaRevisionTest::testFileMediaRevision()
- 10 core/modules/media/tests/src/Functional/MediaRevisionTest.php \Drupal\Tests\media\Functional\MediaRevisionTest::testFileMediaRevision()
Tests creating revisions of a File media item.
File
-
core/
modules/ media/ tests/ src/ Functional/ MediaRevisionTest.php, line 107
Class
- MediaRevisionTest
- Tests the revisions of media entities.
Namespace
Drupal\Tests\media\FunctionalCode
public function testFileMediaRevision() : void {
$assert = $this->assertSession();
$uri = 'temporary://foo.txt';
file_put_contents($uri, $this->randomString(128));
$this->createMediaType('file', [
'id' => 'document',
'new_revision' => TRUE,
]);
// Create a media item.
$this->drupalGet('/media/add/document');
$page = $this->getSession()
->getPage();
$page->fillField('Name', 'Foobar');
$page->attachFileToField('File', $this->container
->get('file_system')
->realpath($uri));
$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', 'Foo');
$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('Foo');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.