reverted: --- b/core/modules/user/src/Tests/UserUsernameTest.php +++ /dev/null @@ -1,158 +0,0 @@ -drupalCreateContentType(['type' => 'article', 'name' => 'Article']); - $this->addDefaultCommentField('node', 'article'); - - // Create user with short username. - $this->userShortName = $this->drupalCreateUser( - [ - 'access content', - 'access comments', - 'post comments', - 'skip comment approval', - 'create article content', - ], - $this->randomString(30) - ); - - // Create user with long username. - $this->userLongName = $this->drupalCreateUser( - [ - 'access content', - 'access comments', - 'post comments', - 'skip comment approval', - 'create article content', - ], - $this->randomString(31) - ); - } - - /** - * Tests author name display on nodes. - */ - public function testTruncatedNodeAuthorName() { - // Test untruncated username. - $this->drupalLogin($this->userShortName); - - $node = $this->drupalCreateNode(['type' => 'article']); - $this->drupalGet('node/' . $node->id()); - $this->assertText(Html::escape($this->userShortName->getUsername())); - - // Test truncated username. - $this->drupalLogin($this->userLongName); - - $node = $this->drupalCreateNode(['type' => 'article']); - $this->drupalGet('node/' . $node->id()); - - // Tests if the username is trimmed to USERNAME_TRIM_LENGTH value. - // @see template_preprocess_username() - $this->assertNoText(Html::escape($this->userLongName->getUsername())); - $this->assertText(Html::escape(Unicode::truncate($this->userLongName->getUsername(), USERNAME_TRIM_LENGTH - 1, FALSE, TRUE))); - } - - /** - * Tests author name display on comments. - */ - public function testTruncatedCommentAuthorName() { - $node = $this->drupalCreateNode(['type' => 'article']); - - $this->drupalLogin($this->userShortName); - $comment = [ - 'subject[0][value]' => $this->randomMachineName(), - 'comment_body[0][value]' => $this->randomMachineName(20), - ]; - $this->drupalPostForm('comment/reply/node/' . $node->id() . '/comment', $comment, t('Save')); - $this->assertText(Html::escape($this->userShortName->getUsername())); - $this->drupalLogin($this->userLongName); - $comment = [ - 'subject[0][value]' => $this->randomMachineName(), - 'comment_body[0][value]' => $this->randomMachineName(20), - ]; - - // Tests if the username is trimmed to USERNAME_TRIM_LENGTH value. - // @see template_preprocess_username() - $this->drupalPostForm('comment/reply/node/' . $node->id() . '/comment', $comment, t('Save')); - $this->assertNoText(Html::escape($this->userLongName->getUsername())); - $this->assertText(Html::escape(Unicode::truncate($this->userLongName->getUsername(), USERNAME_TRIM_LENGTH - 1, FALSE, TRUE))); - } - - - /** - * Tests username display in Who's New block. - */ - public function testTruncatedWhosNewName() { - // Enable Who's New block. - $this->drupalPlaceBlock('views_block:who_s_new-block_1', ['label' => 'user_view_block-block_1:1', 'views_label' => 'Who\'s new']); - - // The Who's new block requires a last access to be set. - // Log the users in for them to show up. - $this->drupalLogin($this->userShortName); - $this->drupalLogin($this->userLongName); - - // Log user out to prevent a false negative. - $this->drupalLogout(); - - $this->drupalGet(''); - - // Tests if the username is trimmed to USERNAME_TRIM_LENGTH value. - // @see template_preprocess_username() - $this->assertText(Html::escape($this->userShortName->getUsername())); - $this->assertNoText(Html::escape($this->userLongName->getUsername())); - $this->assertText(Html::escape(Unicode::truncate($this->userLongName->getUsername(), USERNAME_TRIM_LENGTH - 1, FALSE, TRUE))); - } - -} only in patch2: unchanged: --- /dev/null +++ b/core/modules/user/tests/src/Functional/UserUsernameTest.php @@ -0,0 +1,153 @@ +drupalCreateContentType(['type' => 'article', 'name' => 'Article']); + $this->addDefaultCommentField('node', 'article'); + + // Create user with short username. + $this->userShortName = $this->drupalCreateUser( + [ + 'access content', + 'access comments', + 'post comments', + 'skip comment approval', + 'create article content', + ], + $this->randomString(30) + ); + + // Create user with long username. + $this->userLongName = $this->drupalCreateUser( + [ + 'access content', + 'access comments', + 'post comments', + 'skip comment approval', + 'create article content', + ], + $this->randomString(31) + ); + } + + /** + * Tests author name display on nodes. + */ + public function testTruncatedNodeAuthorName() { + // Test untruncated username. + $this->drupalLogin($this->userShortName); + + $node = $this->drupalCreateNode(['type' => 'article']); + $this->drupalGet('node/' . $node->id()); + $this->assertSession()->pageTextContains(Html::escape($this->userShortName->getUsername())); + + // Test truncated username. + $this->drupalLogin($this->userLongName); + + $node = $this->drupalCreateNode(['type' => 'article']); + $this->drupalGet('node/' . $node->id()); + + // Tests if the username is trimmed to USERNAME_TRIM_LENGTH value. + // @see template_preprocess_username() + $this->assertSession()->responseNotContains(Html::escape($this->userLongName->getUsername())); + $this->assertSession()->pageTextContains(Html::escape(Unicode::truncate($this->userLongName->getUsername(), USERNAME_TRIM_LENGTH - 1, FALSE, TRUE))); + } + + /** + * Tests author name display on comments. + */ + public function testTruncatedCommentAuthorName() { + $node = $this->drupalCreateNode(['type' => 'article']); + + $this->drupalLogin($this->userShortName); + $comment = [ + 'subject[0][value]' => $this->randomMachineName(), + 'comment_body[0][value]' => $this->randomMachineName(20), + ]; + $this->drupalPostForm('comment/reply/node/' . $node->id() . '/comment', $comment, t('Save')); + $this->assertSession()->pageTextContains(Html::escape($this->userShortName->getUsername())); + $this->drupalLogin($this->userLongName); + $comment = [ + 'subject[0][value]' => $this->randomMachineName(), + 'comment_body[0][value]' => $this->randomMachineName(20), + ]; + + // Tests if the username is trimmed to USERNAME_TRIM_LENGTH value. + // @see template_preprocess_username() + $this->drupalPostForm('comment/reply/node/' . $node->id() . '/comment', $comment, t('Save')); + $this->assertSession()->responseNotContains(Html::escape($this->userLongName->getUsername())); + $this->assertSession()->pageTextContains(Html::escape(Unicode::truncate($this->userLongName->getUsername(), USERNAME_TRIM_LENGTH - 1, FALSE, TRUE))); + } + + + /** + * Tests username display in Who's New block. + */ + public function testTruncatedWhosNewName() { + // Enable Who's New block. + $this->drupalPlaceBlock('views_block:who_s_new-block_1', ['label' => 'user_view_block-block_1:1', 'views_label' => 'Who\'s new']); + + // The Who's new block requires a last access to be set. + // Log the users in for them to show up. + $this->drupalLogin($this->userShortName); + $this->drupalLogin($this->userLongName); + + // Log user out to prevent a false negative. + $this->drupalLogout(); + + $this->drupalGet(''); + + // Tests if the username is trimmed to USERNAME_TRIM_LENGTH value. + // @see template_preprocess_username() + $this->assertSession()->pageTextContains(Html::escape($this->userShortName->getUsername())); + $this->assertSession()->responseNotContains(Html::escape($this->userLongName->getUsername())); + $this->assertSession()->pageTextContains(Html::escape(Unicode::truncate($this->userLongName->getUsername(), USERNAME_TRIM_LENGTH - 1, FALSE, TRUE))); + } + +}