You are here

protected function BlockContentRevisionsTest::setUp in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/block_content/tests/src/Functional/BlockContentRevisionsTest.php \Drupal\Tests\block_content\Functional\BlockContentRevisionsTest::setUp()

Sets the test up.

Overrides BlockContentTestBase::setUp

File

core/modules/block_content/tests/src/Functional/BlockContentRevisionsTest.php, line 37

Class

BlockContentRevisionsTest
Create a block with revisions.

Namespace

Drupal\Tests\block_content\Functional

Code

protected function setUp() {
  parent::setUp();

  /** @var \Drupal\user\Entity\UserInterface $user */
  $user = User::load(1);

  // Create initial block.
  $block = $this
    ->createBlockContent('initial');
  $blocks = [];
  $logs = [];

  // Get original block.
  $blocks[] = $block
    ->getRevisionId();
  $logs[] = '';

  // Create three revisions.
  $revision_count = 3;
  for ($i = 0; $i < $revision_count; $i++) {
    $block
      ->setNewRevision(TRUE);
    $block
      ->setRevisionLogMessage($this
      ->randomMachineName(32));
    $block
      ->setRevisionUser($this->adminUser);
    $block
      ->setRevisionCreationTime(REQUEST_TIME);
    $logs[] = $block
      ->getRevisionLogMessage();
    $block
      ->save();
    $blocks[] = $block
      ->getRevisionId();
  }
  $this->blocks = $blocks;
  $this->revisionLogs = $logs;
}