public function BlockContentRevisionsTest::testRevisions in Drupal 9
Same name and namespace in other branches
- 8 core/modules/block_content/tests/src/Functional/BlockContentRevisionsTest.php \Drupal\Tests\block_content\Functional\BlockContentRevisionsTest::testRevisions()
Checks block revision related operations.
File
- core/
modules/ block_content/ tests/ src/ Functional/ BlockContentRevisionsTest.php, line 68
Class
- BlockContentRevisionsTest
- Create a block with revisions.
Namespace
Drupal\Tests\block_content\FunctionalCode
public function testRevisions() {
$blocks = $this->blocks;
$logs = $this->revisionLogs;
foreach ($blocks as $delta => $revision_id) {
// Confirm the correct revision text appears.
/** @var \Drupal\block_content\BlockContentInterface $loaded */
$loaded = $this->container
->get('entity_type.manager')
->getStorage('block_content')
->loadRevision($revision_id);
// Verify revision log is the same.
$this
->assertEquals($logs[$delta], $loaded
->getRevisionLogMessage(), new FormattableMarkup('Correct log message found for revision @revision', [
'@revision' => $loaded
->getRevisionId(),
]));
if ($delta > 0) {
$this
->assertInstanceOf(UserInterface::class, $loaded
->getRevisionUser());
$this
->assertIsNumeric($loaded
->getRevisionUserId());
$this
->assertIsNumeric($loaded
->getRevisionCreationTime());
}
}
// Confirm that this is the default revision.
$this
->assertTrue($loaded
->isDefaultRevision(), 'Third block revision is the default one.');
// Make a new revision and set it to not be default.
// This will create a new revision that is not "front facing".
// Save this as a non-default revision.
$loaded
->setNewRevision();
$loaded
->isDefaultRevision(FALSE);
$loaded->body = $this
->randomMachineName(8);
$loaded
->save();
// Confirm that revision body text is not present on default version of
// block.
$this
->drupalGet('block/' . $loaded
->id());
$this
->assertSession()
->pageTextNotContains($loaded->body->value);
// Verify that the non-default revision id is greater than the default
// revision id.
$default_revision = BlockContent::load($loaded
->id());
// Verify that the revision ID is greater than the default revision ID.
$this
->assertGreaterThan($default_revision
->getRevisionId(), $loaded
->getRevisionId());
}