Skip to content
Snippets Groups Projects
Commit 590371ca authored by catch's avatar catch
Browse files

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

(cherry picked from commit 2ba2f9f3)
parent a2d4afd1
No related branches found
No related tags found
14 merge requests!11515Issue #3480419 by mondrake, smustgrave, catch: Method...,!11380Issue #3490698 by catch, spokje: Bump MINIMUM_STABILITY back to 'stable' when...,!11281Use Drupal Core Leadership terminology in MAINTAINERS.txt,!11239Issue #3507548: Allow workspace changes listing to show all items, without a pager,!11238Fix issue #3051797,!11213Issue #3506743 by tomislav.matokovic: Increasing the color contrast for the navigation block title against the background of the navigation sidebar to at least 4.5:1,!11147Draft: Try to avoid manually setting required cache contexts,!11108Issue #3490298 by nicxvan: Profiles can be missed in OOP hooks,!11093Drupal on MongoDB 11.1.x,!11017Issue #3502540: Add date filter for moderated content.,!11009Issue #3486972 migrate feed icon,!10999Cleaning up Taxonomy hooks and updating baseline.,!10977Issue #3501457: Fix path used in a A11y Test Admin,!10881Issue #3489329 by mfb, casey: symfony/http-foundation commit 32310ff breaks PathValidator
Pipeline #391927 canceled
Pipeline: drupal

#391928

    ......@@ -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());
    ......
    ......@@ -7,16 +7,12 @@
    use Drupal\Component\Render\FormattableMarkup;
    use Drupal\Core\Hook\Attribute\Hook;
    use Drupal\Core\Session\AccountInterface;
    use Drupal\Core\State\StateInterface;
    /**
    * Contains hook implementations.
    */
    class UserHooksTest {
    public function __construct(protected StateInterface $state) {
    }
    /**
    * Alters the username.
    *
    ......@@ -29,8 +25,8 @@ public function __construct(protected StateInterface $state) {
    */
    #[Hook('user_format_name_alter')]
    public function userFormatNameAlter(&$name, AccountInterface $account): void {
    if ($this->state->get('user_hooks_test_user_format_name_alter', FALSE)) {
    if ($this->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 {
    ......
    ......@@ -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');
    ......
    ......@@ -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([]);
    ......@@ -173,8 +173,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]);
    ......
    ......@@ -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());
    ......
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment