BlockContentRevisionsTest.php in Zircon Profile 8
File
core/modules/block_content/src/Tests/BlockContentRevisionsTest.php
View source
<?php
namespace Drupal\block_content\Tests;
use Drupal\block_content\Entity\BlockContent;
class BlockContentRevisionsTest extends BlockContentTestBase {
protected $blocks;
protected $revisionLogs;
protected function setUp() {
parent::setUp();
$block = $this
->createBlockContent('initial');
$blocks = array();
$logs = array();
$blocks[] = $block
->getRevisionId();
$logs[] = '';
$revision_count = 3;
for ($i = 0; $i < $revision_count; $i++) {
$block
->setNewRevision(TRUE);
$block
->setRevisionLog($this
->randomMachineName(32));
$logs[] = $block
->getRevisionLog();
$block
->save();
$blocks[] = $block
->getRevisionId();
}
$this->blocks = $blocks;
$this->revisionLogs = $logs;
}
public function testRevisions() {
$blocks = $this->blocks;
$logs = $this->revisionLogs;
foreach ($blocks as $delta => $revision_id) {
$loaded = entity_revision_load('block_content', $revision_id);
$this
->assertEqual($loaded
->getRevisionLog(), $logs[$delta], format_string('Correct log message found for revision @revision', array(
'@revision' => $loaded
->getRevisionId(),
)));
}
$this
->assertTrue($loaded
->isDefaultRevision(), 'Third block revision is the default one.');
$loaded
->setNewRevision();
$loaded
->isDefaultRevision(FALSE);
$loaded->body = $this
->randomMachineName(8);
$loaded
->save();
$this
->drupalGet('block/' . $loaded
->id());
$this
->assertNoText($loaded->body->value, 'Revision body text is not present on default version of block.');
$default_revision = BlockContent::load($loaded
->id());
$this
->assertTrue($loaded
->getRevisionId() > $default_revision
->getRevisionId(), 'Revision id is greater than default revision id.');
}
}