You are here

public function BlockContentRevisionsTest::testRevisions in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/block_content/src/Tests/BlockContentRevisionsTest.php \Drupal\block_content\Tests\BlockContentRevisionsTest::testRevisions()

Checks block revision related operations.

File

core/modules/block_content/src/Tests/BlockContentRevisionsTest.php, line 64
Contains \Drupal\block_content\Tests\BlockContentRevisionsTest.

Class

BlockContentRevisionsTest
Create a block with revisions.

Namespace

Drupal\block_content\Tests

Code

public function testRevisions() {
  $blocks = $this->blocks;
  $logs = $this->revisionLogs;
  foreach ($blocks as $delta => $revision_id) {

    // Confirm the correct revision text appears.
    $loaded = entity_revision_load('block_content', $revision_id);

    // Verify revision log is the same.
    $this
      ->assertEqual($loaded
      ->getRevisionLog(), $logs[$delta], format_string('Correct log message found for revision @revision', array(
      '@revision' => $loaded
        ->getRevisionId(),
    )));
  }

  // 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();
  $this
    ->drupalGet('block/' . $loaded
    ->id());
  $this
    ->assertNoText($loaded->body->value, 'Revision body text is not present on default version of block.');

  // Verify that the non-default revision id is greater than the default
  // revision id.
  $default_revision = BlockContent::load($loaded
    ->id());
  $this
    ->assertTrue($loaded
    ->getRevisionId() > $default_revision
    ->getRevisionId(), 'Revision id is greater than default revision id.');
}