diff --git a/core/modules/user/src/Tests/UserUsernameTest.php b/core/modules/user/src/Tests/UserUsernameTest.php index 3ba2608..e6573a3 100644 --- a/core/modules/user/src/Tests/UserUsernameTest.php +++ b/core/modules/user/src/Tests/UserUsernameTest.php @@ -7,6 +7,8 @@ namespace Drupal\user\Tests; +use Drupal\Component\Utility\String; +use Drupal\Component\Utility\Unicode; use Drupal\simpletest\WebTestBase; /** @@ -24,7 +26,7 @@ class UserUsernameTest extends WebTestBase { public static $modules = array( 'node', 'block', - 'comment_test', + 'comment', 'user_test_views', ); @@ -49,6 +51,7 @@ public function setUp() { parent::setUp(); $this->drupalCreateContentType(array('type' => 'article')); + $this->container->get('comment.manager')->addDefaultField('node', 'article'); // Create user with short username. $this->userShortName = $this->drupalCreateUser( @@ -59,7 +62,7 @@ public function setUp() { 'skip comment approval', 'create article content', ), - $this->randomName(30) + $this->randomString(30) ); // Create user with long username. @@ -71,7 +74,7 @@ public function setUp() { 'skip comment approval', 'create article content', ), - $this->randomName(31) + $this->randomString(31) ); } @@ -84,15 +87,15 @@ public function testTruncatedNodeAuthorName() { $node = $this->drupalCreateNode(array('type' => 'article')); $this->drupalGet('node/' . $node->id()); - $this->assertText($this->userShortName->getUsername(), 'Untruncated username found.'); + $this->assertText(String::checkPlain($this->userShortName->getUsername()), 'Untruncated username found.'); // Test truncated username. $this->drupalLogin($this->userLongName); $node = $this->drupalCreateNode(array('type' => 'article')); $this->drupalGet('node/' . $node->id()); - $this->assertNoText($this->userLongName->getUsername(), 'Untruncated username not found.'); - $this->assertText(drupal_substr($this->userLongName->getUsername(), 0, 29) . '…', 'Truncated username found.'); + $this->assertNoText(String::checkPlain($this->userLongName->getUsername()), 'Untruncated username not found.'); + $this->assertText(String::checkPlain(Unicode::truncate($this->userLongName->getUsername(), 29, FALSE, TRUE)), 'Truncated username found.'); } /** @@ -102,18 +105,20 @@ public function testTruncatedCommentAuthorName() { $node = $this->drupalCreateNode(array('type' => 'article')); $this->drupalLogin($this->userShortName); - $edit = array( - 'comment_body[0][value]' => $this->randomString(), + $comment = array( + 'subject[0][value]' => $this->randomMachineName(), + 'comment_body[0][value]' => $this->randomMachineName(20), ); - $this->drupalPostForm('comment/reply/node/' . $node->id() . '/comment', $edit, t('Save')); - $this->assertText($this->userShortName->getUsername(), 'Untruncated username found.'); + $this->drupalPostForm('comment/reply/node/' . $node->id() . '/comment', $comment, t('Save')); + $this->assertText(String::checkPlain($this->userShortName->getUsername()), 'Untruncated username found.'); $this->drupalLogin($this->userLongName); - $edit = array( - 'comment_body[0][value]' => $this->randomString(), + $comment = array( + 'subject[0][value]' => $this->randomMachineName(), + 'comment_body[0][value]' => $this->randomMachineName(20), ); - $this->drupalPostForm('comment/reply/node/' . $node->id() . '/comment', $edit, t('Save')); - $this->assertNoText($this->userLongName->getUsername(), 'Untruncated username not found.'); - $this->assertText(drupal_substr($this->userLongName->getUsername(), 0, 29) . '…', 'Truncated username found.'); + $this->drupalPostForm('comment/reply/node/' . $node->id() . '/comment', $comment, t('Save')); + $this->assertNoText(String::checkPlain($this->userLongName->getUsername()), 'Untruncated username not found.'); + $this->assertText(String::checkPlain(Unicode::truncate($this->userLongName->getUsername(), 29, FALSE, TRUE)), 'Truncated username found.'); } @@ -126,9 +131,16 @@ public function testTruncatedWhosNewName() { $this->drupalGet(''); - $this->assertText($this->userShortName->getUsername(), 'Untruncated username found.'); - $this->assertNoText($this->userLongName->getUsername(), 'Untruncated username not found.'); - $this->assertText(drupal_substr($this->userLongName->getUsername(), 0, 29) . '…', 'Truncated username found.'); + // 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->assertText(String::checkPlain($this->userShortName->getUsername()), 'Untruncated username found.'); + $this->assertNoText(String::checkPlain($this->userLongName->getUsername()), 'Untruncated username not found.'); + $this->assertText(String::checkPlain(Unicode::truncate($this->userLongName->getUsername(), 29, FALSE, TRUE)), 'Truncated username found.'); } }