Commit 59d64824 authored by catch's avatar catch
Browse files

Issue #3522811 by quietone: Remove uses of FormattableMarkup in tests not testing that API

parent 87883408
Loading
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -5,7 +5,6 @@
namespace Drupal\Tests\comment\Functional;

use Drupal\comment\CommentInterface;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Component\Utility\Html;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\user\RoleInterface;
@@ -281,8 +280,8 @@ public function testCommentedTranslationDeletion(): void {
    ];
    $this->drupalGet('admin/content/comment');
    $this->submitForm($edit, 'Update');
    $this->assertSession()->responseContains(new FormattableMarkup('@label (Original translation) - <em>The following comment translations will be deleted:</em>', ['@label' => $comment1->label()]));
    $this->assertSession()->responseContains(new FormattableMarkup('@label (Original translation) - <em>The following comment translations will be deleted:</em>', ['@label' => $comment2->label()]));
    $this->assertSession()->responseContains($comment1->label() . " (Original translation) - <em>The following comment translations will be deleted:</em>");
    $this->assertSession()->responseContains($comment2->label() . " (Original translation) - <em>The following comment translations will be deleted:</em>");
    $this->assertSession()->pageTextContains('English');
    $this->assertSession()->pageTextContains('Urdu');
    $this->submitForm([], 'Delete');
+1 −2
Original line number Diff line number Diff line
@@ -5,7 +5,6 @@
namespace Drupal\Tests\comment\Functional;

use Drupal\comment\CommentManagerInterface;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\node\Entity\Node;

/**
@@ -446,7 +445,7 @@ protected function clickLinkWithXPath($xpath, $arguments = [], $index = 0) {
      $url_target = $this->getAbsoluteUrl($urls[$index]->getAttribute('href'));
      return $this->drupalGet($url_target);
    }
    $this->fail(new FormattableMarkup('Link %label does not exist on @url_before', ['%label' => $xpath, '@url_before' => $url_before]));
    $this->fail("Link $xpath does not exist on $url_before");
    return FALSE;
  }

+3 −5
Original line number Diff line number Diff line
@@ -4,7 +4,6 @@

namespace Drupal\Tests\config\Functional;

use Drupal\Component\Render\FormattableMarkup;
use Drupal\Component\Uuid\Uuid;
use Drupal\Core\Entity\EntityMalformedException;
use Drupal\Core\Entity\EntityStorageException;
@@ -172,10 +171,9 @@ public function testCRUD(): void {
    ]);
    try {
      $status = $id_length_config_test->save();
      $this->fail(new FormattableMarkup("config_test entity with ID length @length exceeding the maximum allowed length of @max saved successfully", [
        '@length' => strlen($id_length_config_test->id()),
        '@max' => static::MAX_ID_LENGTH,
      ]));
      $length = strlen($id_length_config_test->id());
      $max = static::MAX_ID_LENGTH;
      $this->fail("config_test entity with ID length $length exceeding the maximum allowed length of $max saved successfully");
    }
    catch (ConfigEntityIdLengthException) {
      // Expected exception; just continue testing.
+1 −7
Original line number Diff line number Diff line
@@ -4,7 +4,6 @@

namespace Drupal\Tests\contact\Functional;

use Drupal\Component\Render\FormattableMarkup;
use Drupal\Component\Utility\Html;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Test\AssertMailTrait;
@@ -106,12 +105,7 @@ public function testSendPersonalContactMessage(): void {
    $this->drupalLogin($this->adminUser);
    // Verify that the correct watchdog message has been logged.
    $this->drupalGet('/admin/reports/dblog');
    $placeholders = [
      '@sender_name' => $this->webUser->getAccountName(),
      '@sender_email' => $this->webUser->getEmail(),
      '@recipient_name' => $this->contactUser->getAccountName(),
    ];
    $this->assertSession()->responseContains(new FormattableMarkup('@sender_name (@sender_email) sent @recipient_name an email.', $placeholders));
    $this->assertSession()->responseContains($this->webUser->getAccountName() . " (" . HTML::escape($this->webUser->getEmail()) . ") sent " . $this->contactUser->getAccountName() . " an email.");
    // Ensure an unescaped version of the email does not exist anywhere.
    $this->assertSession()->responseNotContains($this->webUser->getEmail());

+34 −19
Original line number Diff line number Diff line
@@ -4,7 +4,6 @@

namespace Drupal\Tests\datetime\Functional;

use Drupal\Component\Render\FormattableMarkup;
use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\Core\Datetime\Entity\DateFormat;
use Drupal\datetime\Plugin\Field\FieldType\DateTimeItemInterface;
@@ -190,11 +189,15 @@ public function testDateField(): void {
      $display_repository->getViewDisplay($this->field->getTargetEntityTypeId(), $this->field->getTargetBundle(), 'full')
        ->setComponent($field_name, $this->displayOptions)
        ->save();
      $expected = new FormattableMarkup($this->displayOptions['settings']['past_format'], [
        '@interval' => $this->dateFormatter->formatTimeDiffSince($timestamp, ['granularity' => $this->displayOptions['settings']['granularity']]),
      ]);
      $expected = str_replace(
        '@interval',
        $this->dateFormatter->formatTimeDiffSince(
          $timestamp,
          ['granularity' => $this->displayOptions['settings']['granularity']]),
        $this->displayOptions['settings']['past_format']
      );
      $output = $this->renderTestEntity($id);
      $this->assertStringContainsString((string) $expected, $output, "Formatted date field using datetime_time_ago format displayed as $expected in $timezone.");
      $this->assertStringContainsString($expected, $output, "Formatted date field using datetime_time_ago format displayed as $expected in $timezone.");

      // Verify that the 'datetime_time_ago' formatter works for intervals in
      // the future.  First update the test entity so that the date difference
@@ -211,11 +214,15 @@ public function testDateField(): void {
      $display_repository->getViewDisplay($this->field->getTargetEntityTypeId(), $this->field->getTargetBundle(), 'full')
        ->setComponent($field_name, $this->displayOptions)
        ->save();
      $expected = new FormattableMarkup($this->displayOptions['settings']['future_format'], [
        '@interval' => $this->dateFormatter->formatTimeDiffUntil($timestamp, ['granularity' => $this->displayOptions['settings']['granularity']]),
      ]);
      $expected = str_replace(
        '@interval',
        $this->dateFormatter->formatTimeDiffUntil(
          $timestamp,
          ['granularity' => $this->displayOptions['settings']['granularity']]),
        $this->displayOptions['settings']['future_format']
      );
      $output = $this->renderTestEntity($id);
      $this->assertStringContainsString((string) $expected, $output, "Formatted date field using datetime_time_ago format displayed as $expected in $timezone.");
      $this->assertStringContainsString($expected, $output, "Formatted date field using datetime_time_ago format displayed as $expected in $timezone.");
    }
  }

@@ -341,11 +348,15 @@ public function testDatetimeField(): void {
    $display_repository->getViewDisplay($this->field->getTargetEntityTypeId(), $this->field->getTargetBundle(), 'full')
      ->setComponent($field_name, $this->displayOptions)
      ->save();
    $expected = new FormattableMarkup($this->displayOptions['settings']['past_format'], [
      '@interval' => $this->dateFormatter->formatTimeDiffSince($timestamp, ['granularity' => $this->displayOptions['settings']['granularity']]),
    ]);
    $expected = str_replace(
      '@interval',
      $this->dateFormatter->formatTimeDiffSince(
        $timestamp,
        ['granularity' => $this->displayOptions['settings']['granularity']]),
      $this->displayOptions['settings']['past_format']
    );
    $output = $this->renderTestEntity($id);
    $this->assertStringContainsString((string) $expected, $output, "Formatted date field using datetime_time_ago format displayed as $expected.");
    $this->assertStringContainsString($expected, $output, "Formatted date field using datetime_time_ago format displayed as $expected.");

    // Verify that the 'datetime_time_ago' formatter works for intervals in the
    // future.  First update the test entity so that the date difference always
@@ -363,11 +374,15 @@ public function testDatetimeField(): void {
      ->getViewDisplay($this->field->getTargetEntityTypeId(), $this->field->getTargetBundle(), 'full')
      ->setComponent($field_name, $this->displayOptions)
      ->save();
    $expected = new FormattableMarkup($this->displayOptions['settings']['future_format'], [
      '@interval' => $this->dateFormatter->formatTimeDiffUntil($timestamp, ['granularity' => $this->displayOptions['settings']['granularity']]),
    ]);
    $expected = str_replace(
      '@interval',
      $this->dateFormatter->formatTimeDiffUntil(
        $timestamp,
        ['granularity' => $this->displayOptions['settings']['granularity']]),
      $this->displayOptions['settings']['future_format']
    );
    $output = $this->renderTestEntity($id);
    $this->assertStringContainsString((string) $expected, $output, "Formatted date field using datetime_time_ago format displayed as $expected.");
    $this->assertStringContainsString($expected, $output, "Formatted date field using datetime_time_ago format displayed as $expected.");

    // Test the required field validation error message.
    $entity = EntityTest::create(['name' => 'test datetime required message']);
@@ -375,9 +390,9 @@ public function testDatetimeField(): void {
    $form_state = new FormState();
    \Drupal::formBuilder()->submitForm($form, $form_state);
    $errors = $form_state->getErrors();
    $expected_error_message = new FormattableMarkup('The %field date is required.', ['%field' => $field_label]);
    $expected_error_message = "The <em class=\"placeholder\">$field_label</em> date is required.";
    $actual_error_message = $errors["{$field_name}][0][value"]->__toString();
    $this->assertEquals($expected_error_message->__toString(), $actual_error_message);
    $this->assertEquals($expected_error_message, $actual_error_message);
  }

  /**
Loading