Verified Commit e934b62e authored by Lee Rowlands's avatar Lee Rowlands
Browse files

Issue #1929420 by quietone, krlucas, kay_v, seiplax, floydm, alexpott, mlncn,...

Issue #1929420 by quietone, krlucas, kay_v, seiplax, floydm, alexpott, mlncn, nlisgo, gulab.bisht, scor, larowlan, longwave, pameeela: [backport] $account->getDisplayName() should be used when outputing username in RDF module
parent b348229a
Loading
Loading
Loading
Loading
+14 −6
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@
use Drupal\comment\CommentManagerInterface;
use Drupal\Tests\comment\Functional\CommentTestBase;
use Drupal\Tests\rdf\Traits\RdfParsingTrait;
use Drupal\user\Entity\User;
use Drupal\user\RoleInterface;
use Drupal\comment\Entity\Comment;

@@ -24,7 +25,7 @@ class CommentAttributesTest extends CommentTestBase {
   *
   * @var array
   */
  public static $modules = ['views', 'node', 'comment', 'rdf'];
  public static $modules = ['views', 'node', 'comment', 'rdf', 'user_hooks_test'];

  /**
   * {@inheritdoc}
@@ -148,6 +149,9 @@ public function testNumberOfCommentsRdfaMarkup() {
   * Tests comment author link markup has not been broken by RDF.
   */
  public function testCommentRdfAuthorMarkup() {
    // Set to test the altered display name.
    \Drupal::state()->set('user_hooks_test_user_format_name_alter', TRUE);

    // Post a comment as a registered user.
    $this->saveComment($this->node->id(), $this->webUser->id());

@@ -158,7 +162,7 @@ public function testCommentRdfAuthorMarkup() {
    // Ensure that the author link still works properly after the author output
    // is modified by the RDF module.
    $this->drupalGet('node/' . $this->node->id());
    $this->assertSession()->linkExists($this->webUser->getAccountName());
    $this->assertSession()->linkExistsExact($this->webUser->getDisplayName());
    $this->assertLinkByHref('user/' . $this->webUser->id());
  }

@@ -169,6 +173,9 @@ public function testCommentRdfAuthorMarkup() {
   * on comments from registered and anonymous users.
   */
  public function testCommentRdfaMarkup() {
    // Set to test the altered display name.
    \Drupal::state()->set('user_hooks_test_user_format_name_alter', TRUE);

    // Posts comment #1 on behalf of registered user.
    $comment1 = $this->saveComment($this->node->id(), $this->webUser->id());

@@ -187,12 +194,13 @@ public function testCommentRdfaMarkup() {
    $anonymous_user['homepage'] = 'http://example.org/';
    $comment2 = $this->saveComment($this->node->id(), 0, $anonymous_user);

    $anonymous = User::load(0);
    // Tests comment #2 as anonymous user.
    $this->_testBasicCommentRdfaMarkup($comment2, $anonymous_user);
    $this->_testBasicCommentRdfaMarkup($comment2, $anonymous);

    // Tests comment #2 as logged in user.
    $this->drupalLogin($this->webUser);
    $this->_testBasicCommentRdfaMarkup($comment2, $anonymous_user);
    $this->_testBasicCommentRdfaMarkup($comment2, $anonymous);
  }

  /**
@@ -240,7 +248,7 @@ public function testCommentReplyOfRdfaMarkup() {
   * @param $account
   *   An array containing information about an anonymous user.
   */
  public function _testBasicCommentRdfaMarkup(CommentInterface $comment, $account = []) {
  public function _testBasicCommentRdfaMarkup(CommentInterface $comment, $account = NULL) {
    $this->drupalGet($this->node->toUrl());
    $comment_uri = $comment->toUrl('canonical', ['absolute' => TRUE])->toString();

@@ -303,7 +311,7 @@ public function _testBasicCommentRdfaMarkup(CommentInterface $comment, $account
    }

    // Author name.
    $name = empty($account["name"]) ? $this->webUser->getAccountName() : $account["name"] . " (not verified)";
    $name = $account ? $account->getDisplayName() . " (not verified)" : $this->webUser->getDisplayName();
    $expected_value = [
      'type' => 'literal',
      'value' => $name,
+6 −3
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@ class UserAttributesTest extends BrowserTestBase {
   *
   * @var array
   */
  public static $modules = ['rdf', 'node'];
  public static $modules = ['rdf', 'node', 'user_hooks_test'];

  /**
   * {@inheritdoc}
@@ -47,6 +47,9 @@ protected function setUp() {

    // Prepares commonly used URIs.
    $this->baseUri = Url::fromRoute('<front>', [], ['absolute' => TRUE])->toString();

    // Set to test the altered display name.
    \Drupal::state()->set('user_hooks_test_user_format_name_alter', TRUE);
  }

  /**
@@ -87,7 +90,7 @@ public function testUserAttributesInMarkup() {
      // User name.
      $expected_value = [
        'type' => 'literal',
        'value' => $author->getAccountName(),
        'value' => $author->getDisplayName(),
      ];
      $this->assertTrue($this->hasRdfProperty($this->getSession()->getPage()->getContent(), $this->baseUri, $account_uri, 'http://xmlns.com/foaf/0.1/name', $expected_value), 'User name found in RDF output (foaf:name).');

@@ -108,7 +111,7 @@ public function testUserAttributesInMarkup() {
      // User name.
      $expected_value = [
        'type' => 'literal',
        'value' => $author->getAccountName(),
        'value' => $author->getDisplayName(),
      ];
      $this->assertTrue($this->hasRdfProperty($this->getSession()->getPage()->getContent(), $this->baseUri, $account_uri, 'http://xmlns.com/foaf/0.1/name', $expected_value), 'User name found in RDF output (foaf:name).');
    }