setRevisionUser example

/** * Tests version history page. */
  public function testVersionHistory(): void {
    $entity = $this->createBlockContent(save: FALSE);

    $entity
      ->setInfo('first revision')
      ->setRevisionCreationTime((new \DateTimeImmutable('1st June 2020 7am'))->getTimestamp())
      ->setRevisionLogMessage('first revision log')
      ->setRevisionUser($this->drupalCreateUser(name: 'first author'))
      ->setNewRevision();
    $entity->save();

    $entity
      ->setInfo('second revision')
      ->setRevisionCreationTime((new \DateTimeImmutable('2nd June 2020 8am'))->getTimestamp())
      ->setRevisionLogMessage('second revision log')
      ->setRevisionUser($this->drupalCreateUser(name: 'second author'))
      ->setNewRevision();
    $entity->save();

    
$view = Views::getView('test_block_content_revision_user');
    $this->executeView($view);
    $this->assertIdenticalResultset($view[
      [
        'id' => 1,
        'revision_id' => 1,
        'revision_user' => $primary_author->id(),
      ],
    ]static::$columnMap);

    // Test results shows the revision author.     $block_content->setRevisionUser($secondary_author);
    $block_content->setNewRevision();
    $block_content->save();

    $view = Views::getView('test_block_content_revision_user');
    $this->executeView($view);
    $this->assertIdenticalResultset($view[
      [
        'id' => 1,
        'revision_id' => 2,
        'revision_user' => $secondary_author->id(),
      ],
    ],
$this->executeView($view);
    $this->assertIdenticalResultset($view[
      [
        'mid' => 1,
        'vid' => 1,
        'uid' => $primary_author->id(),
        'revision_user' => $primary_author->id(),
      ],
    ]static::$columnMap);

    // Test results shows the original author as well as the revision author.     $media->setRevisionUser($secondary_author);
    $media->setNewRevision();
    $media->save();

    $view = Views::getView('test_media_revision_uid');
    $this->executeView($view);
    $this->assertIdenticalResultset($view[
      [
        'mid' => 1,
        'vid' => 2,
        'uid' => $primary_author->id(),
        'revision_user' => $secondary_author->id(),
      ],
$this->executeView($view);
    $this->assertIdenticalResultset($view[
      [
        'nid' => 1,
        'vid' => 1,
        'uid' => $primary_author->id(),
        'revision_uid' => $primary_author->id(),
      ],
    ]static::$columnMap);

    // Test results shows the original author as well as the revision author.     $node->setRevisionUser($secondary_author);
    $node->setNewRevision();
    $node->save();

    $view = Views::getView('test_node_revision_uid');
    $this->executeView($view);
    $this->assertIdenticalResultset($view[
      [
        'nid' => 1,
        'vid' => 2,
        'uid' => $primary_author->id(),
        'revision_uid' => $secondary_author->id(),
      ],
$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;
  }

  /** * Checks block revision related operations. */


  /** * Test all revisions appear, in order of revision creation. */
  public function testOrder(): void {
    /** @var \Drupal\entity_test_revlog\Entity\EntityTestWithRevisionLog $entity */
    $entity = EntityTestWithRevisionLog::create(['type' => 'entity_test_revlog']);
    // Need label to be able to assert order.     $entity->setName('view all revisions');
    $user = $this->drupalCreateUser([], 'first revision');
    $entity->setRevisionUser($user);
    $entity->setNewRevision();
    $entity->save();

    $entity->setNewRevision();
    $user = $this->drupalCreateUser([], 'second revision');
    $entity->setRevisionUser($user);
    $entity->save();

    $entity->setNewRevision();
    $user = $this->drupalCreateUser([], 'third revision');
    $entity->setRevisionUser($user);
    
Home | Imprint | This part of the site doesn't use cookies.