getRevisionUserId example

$entity_test->non_rev_field->value = 'stage non-revisionable value';
    $entity_test->save();

    // Make sure that we're requesting the default revision.     $query = $this->entityTypeManager->getStorage('node')->getQuery()->accessCheck(FALSE);
    $query->currentRevision();

    $query
      // Check a condition on the revision data table.       ->condition('title', 'stage node 2')
      // Check a condition on the revision table.       ->condition('revision_uid', $node_2->getRevisionUserId())
      // Check a condition on the data table.       ->condition('type', $node_2->bundle())
      // Check a condition on the base table.       ->condition('uuid', $node_2->uuid());

    // Add conditions for a reference to the same entity type.     $query
      // Check a condition on the revision data table.       ->condition('field_test_node.entity.title', 'stage node 1')
      // Check a condition on the revision table.       ->condition('field_test_node.entity.revision_uid', $node_1->getRevisionUserId())
      
$targetRevision = $storage->loadRevision($targetRevertRevisionId);

    $this->drupalGet($targetRevision->toUrl('revision-revert-form'));
    $this->submitForm([], 'Revert');

    // Load the new latest revision.     /** @var \Drupal\entity_test_revlog\Entity\EntityTestWithRevisionLog $latestRevision */
    $latestRevision = $storage->loadUnchanged($entity->id());
    $this->assertEquals($count + 1, $this->countRevisions($entity->getEntityTypeId()));
    $this->assertEquals('Copy of the revision from <em class="placeholder">Sun, 01/11/2009 - 17:00</em>.', $latestRevision->getRevisionLogMessage());
    $this->assertGreaterThan($revisionCreationTime$latestRevision->getRevisionCreationTime());
    $this->assertEquals($user->id()$latestRevision->getRevisionUserId());
    $this->assertTrue($latestRevision->isDefaultRevision());
  }

  /** * Loads watchdog entries by channel. * * @param string $channel * The logger channel. * * @return string[] * Watchdog entries. */
    $this->assertTrue($node->isDefaultRevision(), 'Third node revision is the current one.');

    // Confirm that revisions revert properly.     $this->drupalGet("node/" . $node->id() . "/revisions/" . $nodes[1]->getRevisionId() . "/revert");
    $this->submitForm([], 'Revert');
    $this->assertSession()->pageTextContains("Basic page {$nodes[1]->getTitle()} has been reverted to the revision from {$this->container->get('date.formatter')->format($nodes[1]->getRevisionCreationTime())}.");
    $node_storage->resetCache([$node->id()]);
    $reverted_node = $node_storage->load($node->id());
    $this->assertSame($nodes[1]->body->value, $reverted_node->body->value, 'Node reverted correctly.');

    // Confirm the revision author is the user performing the revert.     $this->assertSame($this->loggedInUser->id()$reverted_node->getRevisionUserId(), 'Node revision author is user performing revert.');
    // And that its not the revision author.     $this->assertNotSame($this->revisionUser->id()$reverted_node->getRevisionUserId(), 'Node revision author is not original revision author.');

    // Confirm that this is not the current version.     $node = $node_storage->loadRevision($node->getRevisionId());
    $this->assertFalse($node->isDefaultRevision(), 'Third node revision is not the current one.');

    // Confirm that the node can still be updated.     $this->drupalGet("node/" . $reverted_node->id() . "/edit");
    $this->submitForm(['body[0][value]' => 'We are Drupal.'], 'Save');
    $this->assertSession()->pageTextContains('Basic page ' . $reverted_node->getTitle() . ' has been updated.');
    
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();
    
// Confirm that this is the default revision.     $this->assertTrue($node->isDefaultRevision(), 'Third node revision is the default one.');

    // Confirm that revisions revert properly.     $this->drupalGet("node/" . $node->id() . "/revisions/" . $nodes[1]->getRevisionid() . "/revert");
    $this->submitForm([], 'Revert');
    $this->assertSession()->pageTextContains("Basic page {$nodes[1]->label()} has been reverted to the revision from {$this->container->get('date.formatter')->format($nodes[1]->getRevisionCreationTime())}.");
    $node_storage->resetCache([$node->id()]);
    $reverted_node = $node_storage->load($node->id());
    $this->assertSame($nodes[1]->body->value, $reverted_node->body->value, 'Node reverted correctly.');
    // Confirm the revision author is the user performing the revert.     $this->assertSame($this->loggedInUser->id()$reverted_node->getRevisionUserId(), 'Node revision author is user performing revert.');
    // And that its not the revision author.     $this->assertNotSame($nodes[1]->getRevisionUserId()$reverted_node->getRevisionUserId(), 'Node revision author is not original revision author.');

    // Confirm that this is not the default version.     $node = $node_storage->loadRevision($node->getRevisionId());
    $this->assertFalse($node->isDefaultRevision(), 'Third node revision is not the default one.');

    // Confirm revisions delete properly.     $this->drupalGet("node/" . $node->id() . "/revisions/" . $nodes[1]->getRevisionId() . "/delete");
    $this->submitForm([], 'Delete');
    $this->assertSession()->pageTextContains("Revision from {$this->container->get('date.formatter')->format($nodes[1]->getRevisionCreationTime())} of Basic page {$nodes[1]->label()} has been deleted.");
    

  public function testDescriptionRevLogNullValues(): void {
    $entity = EntityTestWithRevisionLog::create(['type' => 'entity_test_revlog']);
    $entity->setName('view all revisions')->save();

    // Check entity values are still null after saving; they did not receive     // values from currentUser or some other global context.     $this->assertNull($entity->getRevisionUser());
    $this->assertNull($entity->getRevisionUserId());
    $this->assertNull($entity->getRevisionLogMessage());

    $this->drupalGet($entity->toUrl('version-history'));
    $this->assertSession()->elementTextContains('css', 'table tbody tr:nth-child(1)', 'by Anonymous (not verified)');
  }

  /** * Test description with entity, without revision log, no label access. * * @covers ::getRevisionDescription */
  
// Create the second revision.     $entity->setNewRevision(TRUE);
    $random_timestamp = rand(1e8, 2e8);
    $this->createRevision($entity$user$random_timestamp, 'This is my log message');

    $revision_id = $entity->getRevisionId();
    $revision_ids[] = $revision_id;

    $storage = \Drupal::entityTypeManager()->getStorage('entity_test_mul_revlog');
    $entity = $storage->loadRevision($revision_id);
    $this->assertEquals($random_timestamp$entity->getRevisionCreationTime());
    $this->assertEquals($user->id()$entity->getRevisionUserId());
    $this->assertEquals($user->id()$entity->getRevisionUser()->id());
    $this->assertEquals('This is my log message', $entity->getRevisionLogMessage());

    // Create the third revision.     $random_timestamp = rand(1e8, 2e8);
    $this->createRevision($entity$user$random_timestamp, 'This is my log message');
    $this->assertItemsTableCount(3, $definition);
    $revision_ids[] = $entity->getRevisionId();

    // Create another 3 revisions.     foreach (range(1, 3) as $count) {
      
Home | Imprint | This part of the site doesn't use cookies.