Unverified Commit 347dbb0e authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3069033 by mikelutz, Berdir: Properly deprecate...

Issue #3069033 by mikelutz, Berdir: Properly deprecate Node::setRevisionAuthorId and Node::getRevisionAuthor
parent fa4c5174
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -257,6 +257,7 @@ public function setSticky($sticky) {
   * {@inheritdoc}
   */
  public function getRevisionAuthor() {
    @trigger_error(__NAMESPACE__ . '\Node::getRevisionAuthor is deprecated in drupal:8.2.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Entity\RevisionLogInterface::getRevisionUser() instead. See https://www.drupal.org/node/3069750', E_USER_DEPRECATED);
    return $this->getRevisionUser();
  }

@@ -264,8 +265,8 @@ public function getRevisionAuthor() {
   * {@inheritdoc}
   */
  public function setRevisionAuthorId($uid) {
    $this->setRevisionUserId($uid);
    return $this;
    @trigger_error(__NAMESPACE__ . '\Node::setRevisionAuthorId is deprecated in drupal:8.2.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Entity\RevisionLogInterface::setRevisionUserId() instead. See https://www.drupal.org/node/3069750', E_USER_DEPRECATED);
    return $this->setRevisionUserId($uid);
  }

  /**
+6 −2
Original line number Diff line number Diff line
@@ -152,8 +152,10 @@ public function setRevisionCreationTime($timestamp);
   * @return \Drupal\user\UserInterface
   *   The user entity for the revision author.
   *
   * @deprecated in Drupal 8.2.0, will be removed before Drupal 9.0.0. Use
   * @deprecated in drupal:8.2.0 and is removed from drupal:9.0.0. Use
   *   \Drupal\Core\Entity\RevisionLogInterface::getRevisionUser() instead.
   *
   * @see https://www.drupal.org/node/3069750
   */
  public function getRevisionAuthor();

@@ -166,8 +168,10 @@ public function getRevisionAuthor();
   * @return \Drupal\node\NodeInterface
   *   The called node entity.
   *
   * @deprecated in Drupal 8.2.0, will be removed before Drupal 9.0.0. Use
   * @deprecated in drupal:8.2.0 and is removed from drupal:9.0.0. Use
   *   \Drupal\Core\Entity\RevisionLogInterface::setRevisionUserId() instead.
   *
   * @see https://www.drupal.org/node/3069750
   */
  public function setRevisionAuthorId($uid);

+28 −0
Original line number Diff line number Diff line
@@ -87,4 +87,32 @@ public function testNodeTypeIsNewRevision() {
    $this->assertSame($type->shouldCreateNewRevision(), $type->isNewRevision());
  }

  /**
   * Tests that Node::setRevisionAuthorId() triggers a deprecation error.
   *
   * @expectedDeprecation Drupal\node\Entity\Node::setRevisionAuthorId is deprecated in drupal:8.2.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Entity\RevisionLogInterface::setRevisionUserId() instead. See https://www.drupal.org/node/3069750
   */
  public function testNodeSetRevisionAuthorId() {
    $user = $this->createUser(['uid' => 2, 'name' => 'Test']);
    $entity = Node::create([
      'type' => 'page',
    ]);
    $entity->setRevisionAuthorId($user->id());
    $this->assertSame($user->id(), $entity->getRevisionUser()->id());
  }

  /**
   * Tests that Node::getRevisionAuthor() triggers a deprecation error.
   *
   * @expectedDeprecation Drupal\node\Entity\Node::getRevisionAuthor is deprecated in drupal:8.2.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Entity\RevisionLogInterface::getRevisionUser() instead. See https://www.drupal.org/node/3069750
   */
  public function testNodeGetRevisionAuthor() {
    $user = $this->createUser(['uid' => 2, 'name' => 'Test']);
    $entity = Node::create([
      'type' => 'page',
    ]);
    $entity->setRevisionUser($user);
    $this->assertSame($user->id(), $entity->getRevisionAuthor()->id());
  }

}
+2 −2
Original line number Diff line number Diff line
@@ -64,13 +64,13 @@ public function testArgument() {
      'type' => 'default',
      'title' => $this->randomMachineName(),
    ]);
    $node2->setRevisionAuthorId($no_author->id());
    $node2->setRevisionUserId($no_author->id());
    $node2->save();
    $expected_result[] = ['nid' => $node2->id()];

    // Force to add a new revision.
    $node2->setNewRevision(TRUE);
    $node2->setRevisionAuthorId($author->id());
    $node2->setRevisionUserId($author->id());
    $node2->save();

    // Create one  node on which the author has neither authorship of revisions