Unverified Commit 7aa26830 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3496319 by spokje, catch: [random test failure] CommentPreviewTest::testCommentPreview

parent f6a31492
Loading
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -45,7 +45,7 @@ public function testCommentPreview(): void {

    // Test escaping of the username on the preview form.
    \Drupal::service('module_installer')->install(['user_hooks_test']);
    \Drupal::state()->set('user_hooks_test_user_format_name_alter', TRUE);
    \Drupal::keyValue('user_hooks_test')->set('user_format_name_alter', TRUE);
    $edit = [];
    $edit['subject[0][value]'] = $this->randomMachineName(8);
    $edit['comment_body[0][value]'] = $this->randomMachineName(16);
@@ -53,7 +53,7 @@ public function testCommentPreview(): void {
    $this->submitForm($edit, 'Preview');
    $this->assertSession()->assertEscaped('<em>' . $this->webUser->id() . '</em>');

    \Drupal::state()->set('user_hooks_test_user_format_name_alter_safe', TRUE);
    \Drupal::keyValue('user_hooks_test')->set('user_format_name_alter_safe', TRUE);
    $this->drupalGet('node/' . $this->node->id());
    $this->submitForm($edit, 'Preview');
    $this->assertInstanceOf(MarkupInterface::class, $this->webUser->getDisplayName());
+2 −2
Original line number Diff line number Diff line
@@ -12,8 +12,8 @@
 * Implements hook_user_format_name_alter().
 */
function user_hooks_test_user_format_name_alter(&$name, AccountInterface $account) {
  if (\Drupal::state()->get('user_hooks_test_user_format_name_alter', FALSE)) {
    if (\Drupal::state()->get('user_hooks_test_user_format_name_alter_safe', FALSE)) {
  if (\Drupal::keyValue('user_hooks_test')->get('user_format_name_alter', FALSE)) {
    if (\Drupal::keyValue('user_hooks_test')->get('user_format_name_alter_safe', FALSE)) {
      $name = new FormattableMarkup('<em>@uid</em>', ['@uid' => $account->id()]);
    }
    else {
+1 −1
Original line number Diff line number Diff line
@@ -36,7 +36,7 @@ public function testUserEdit(): void {

    // Check that the default value in user name field
    // is the raw value and not a formatted one.
    \Drupal::state()->set('user_hooks_test_user_format_name_alter', TRUE);
    \Drupal::keyValue('user_hooks_test')->set('user_format_name_alter', TRUE);
    \Drupal::service('module_installer')->install(['user_hooks_test']);
    Cache::invalidateTags(['rendered']);
    $this->drupalGet('user/' . $user1->id() . '/edit');
+3 −3
Original line number Diff line number Diff line
@@ -51,8 +51,8 @@ public function testUserTokenReplacement(): void {
      'language' => $language_interface,
    ];

    \Drupal::state()->set('user_hooks_test_user_format_name_alter', TRUE);
    \Drupal::state()->set('user_hooks_test_user_format_name_alter_safe', TRUE);
    \Drupal::keyValue('user_hooks_test')->set('user_format_name_alter', TRUE);
    \Drupal::keyValue('user_hooks_test')->set('user_format_name_alter_safe', TRUE);

    // Create two users and log them in one after another.
    $user1 = $this->drupalCreateUser([]);
@@ -170,7 +170,7 @@ public function testUserTokenReplacement(): void {

    // Generate user display name tokens when safe markup is returned.
    // @see user_hooks_test_user_format_name_alter()
    \Drupal::state()->set('user_hooks_test_user_format_name_alter_safe', TRUE);
    \Drupal::keyValue('user_hooks_test')->set('user_format_name_alter_safe', TRUE);
    $input = '[user:display-name] [current-user:display-name]';
    $expected = "<em>{$user1->id()}</em> <em>{$user2->id()}</em>";
    $output = $token_service->replace($input, ['user' => $user1]);
+1 −1
Original line number Diff line number Diff line
@@ -46,7 +46,7 @@ public function testLabelCallback(): void {
    $this->assertEmpty($anonymous->getAccountName());

    // Set to test the altered username.
    \Drupal::state()->set('user_hooks_test_user_format_name_alter', TRUE);
    \Drupal::keyValue('user_hooks_test')->set('user_format_name_alter', TRUE);

    // The user display name should be altered.
    $this->assertEquals('<em>' . $account->id() . '</em>', $account->getDisplayName());