function CommentUriDeprecationTest::testCommentUriMethod

Tests the deprecation of comment_uri() method.

@group legacy

File

core/modules/comment/tests/src/Kernel/CommentUriDeprecationTest.php, line 72

Class

CommentUriDeprecationTest
Performs kernel tests on the deprecation of the comment_uri method.

Namespace

Drupal\Tests\comment\Kernel

Code

public function testCommentUriMethod() : void {
  // Create a node with a comment and make it unpublished.
  $node = $this->entityTypeManager
    ->getStorage('node')
    ->create([
    'type' => 'page',
    'title' => 'test 1',
    'promote' => 1,
    'status' => 0,
    'uid' => $this->commentUser
      ->id(),
  ]);
  $node->save();
  $comment = $this->entityTypeManager
    ->getStorage('comment')
    ->create([
    'entity_id' => $node->id(),
    'entity_type' => 'node',
    'field_name' => 'comment',
    'comment_body' => $this->randomMachineName(),
  ]);
  $comment->save();
  $comment_uri = comment_uri($comment);
  $this->expectDeprecation('comment_uri() is deprecated in drupal:11.3.0 and is removed from drupal:12.0.0. Use \\Drupal\\comment\\Entity\\Comment::permalink() instead. See https://www.drupal.org/node/3384294');
  $this->assertEquals('/comment/1#comment-1', $comment_uri->toString());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.