Verified Commit 955418c2 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3402294 by mstrelan, quietone, dww, smustgrave: Fix strict type errors:...

Issue #3402294 by mstrelan, quietone, dww, smustgrave: Fix strict type errors: Convert FormattableMarkup to strings (complex replacement) in core Kernel tests
parent 2e08112e
Loading
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -2,7 +2,6 @@

namespace Drupal\Tests\field_ui\Kernel;

use Drupal\Component\Render\FormattableMarkup;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Database\Database;
use Drupal\Core\Entity\Display\EntityDisplayInterface;
@@ -703,8 +702,8 @@ protected function assertDependencyHelper(bool $assertion, string $type, string
    $dependencies = !empty($all_dependencies[$type]) ? $all_dependencies[$type] : [];
    $context = $display instanceof EntityViewDisplayInterface ? 'View' : 'Form';
    $value = $assertion ? in_array($key, $dependencies) : !in_array($key, $dependencies);
    $args = ['@context' => $context, '@id' => $display->id(), '@type' => $type, '@key' => $key];
    $message = $assertion ? new FormattableMarkup("@context display '@id' depends on @type '@key'.", $args) : new FormattableMarkup("@context display '@id' do not depend on @type '@key'.", $args);
    $display_id = $display->id();
    $message = $assertion ? "$context display '$display_id' depends on $type '$key'." : "$context display '$display_id' do not depend on $type '$key'.";
    $this->assertTrue($value, $message);
  }

+3 −3
Original line number Diff line number Diff line
@@ -57,16 +57,16 @@ public function assertFileHooksCalled($expected) {
    // Determine if there were any expected that were not called.
    $uncalled = array_diff($expected, $actual);
    if (count($uncalled)) {
      $this->assertTrue(FALSE, new FormattableMarkup('Expected hooks %expected to be called but %uncalled was not called.', ['%expected' => implode(', ', $expected), '%uncalled' => implode(', ', $uncalled)]));
      $this->assertTrue(FALSE, sprintf('Expected hooks %s to be called but %s was not called.', implode(', ', $expected), implode(', ', $uncalled)));
    }
    else {
      $this->assertTrue(TRUE, new FormattableMarkup('All the expected hooks were called: %expected', ['%expected' => empty($expected) ? '(none)' : implode(', ', $expected)]));
      $this->assertTrue(TRUE, sprintf('All the expected hooks were called: %s', empty($expected) ? '(none)' : implode(', ', $expected)));
    }

    // Determine if there were any unexpected calls.
    $unexpected = array_diff($actual, $expected);
    if (count($unexpected)) {
      $this->assertTrue(FALSE, new FormattableMarkup('Unexpected hooks were called: %unexpected.', ['%unexpected' => empty($unexpected) ? '(none)' : implode(', ', $unexpected)]));
      $this->assertTrue(FALSE, sprintf('Unexpected hooks were called: %s.', empty($unexpected) ? '(none)' : implode(', ', $unexpected)));
    }
    else {
      $this->assertTrue(TRUE, 'No unexpected hooks were called.');
+1 −2
Original line number Diff line number Diff line
@@ -2,7 +2,6 @@

namespace Drupal\Tests\file\Kernel;

use Drupal\Component\Render\FormattableMarkup;
use Drupal\Core\Entity\EntityStorageException;
use Drupal\Core\Entity\EntityTypeManager;
use Drupal\Core\File\Exception\FileExistsException;
@@ -57,7 +56,7 @@ public function testNormal() {
    $this->assertFileHooksCalled(['move', 'load', 'update']);

    // Make sure we got the same file back.
    $this->assertEquals($source->id(), $result->id(), new FormattableMarkup("Source file id's' %fid is unchanged after move.", ['%fid' => $source->id()]));
    $this->assertEquals($source->id(), $result->id(), "Source file ID {$source->id()} should be unchanged after move.");

    // Reload the file from the database and check that the changes were
    // actually saved.
+16 −17
Original line number Diff line number Diff line
@@ -2,7 +2,6 @@

namespace Drupal\Tests\filter\Kernel;

use Drupal\Component\Render\FormattableMarkup;
use Drupal\Component\Utility\Html;
use Drupal\Core\Language\Language;
use Drupal\Core\Render\RenderContext;
@@ -992,18 +991,18 @@ public function assertFilteredString(FilterInterface $filter, array $tests): voi
      $result = $filter->process($source, $filter)->getProcessedText();
      foreach ($tasks as $value => $is_expected) {
        if ($is_expected) {
          $this->assertStringContainsString($value, $result, new FormattableMarkup('@source: @value found. Filtered result: @result.', [
            '@source' => var_export($source, TRUE),
            '@value' => var_export($value, TRUE),
            '@result' => var_export($result, TRUE),
          ]));
          $this->assertStringContainsString($value, $result, sprintf('%s: %s found. Filtered result: %s.',
            var_export($source, TRUE),
            var_export($value, TRUE),
            var_export($result, TRUE),
          ));
        }
        else {
          $this->assertStringNotContainsString($value, $result, new FormattableMarkup('@source: @value not found. Filtered result: @result.', [
            '@source' => var_export($source, TRUE),
            '@value' => var_export($value, TRUE),
            '@result' => var_export($result, TRUE),
          ]));
          $this->assertStringNotContainsString($value, $result, sprintf('%s: %s not found. Filtered result: %s.',
            var_export($source, TRUE),
            var_export($value, TRUE),
            var_export($result, TRUE),
          ));
        }
      }
    }
@@ -1176,7 +1175,7 @@ public function testHtmlCorrectorFilter() {
body {color:red}
/*]]>*/
</style></p>';
    $this->assertEquals($html, Html::normalize($html), new FormattableMarkup('HTML corrector -- Existing cdata section @pattern_name properly escaped', ['@pattern_name' => '/*<![CDATA[*/']));
    $this->assertEquals($html, Html::normalize($html), 'HTML corrector -- Existing cdata section /*<![CDATA[*/ properly escaped');

    $html = '<p><style>
/*<![CDATA[*/
@@ -1184,28 +1183,28 @@ public function testHtmlCorrectorFilter() {
  body {color:red}
/*]]>*/
</style></p>';
    $this->assertEquals($html, Html::normalize($html), new FormattableMarkup('HTML corrector -- Existing cdata section @pattern_name properly escaped', ['@pattern_name' => '<!--/*--><![CDATA[/* ><!--*/']));
    $this->assertEquals($html, Html::normalize($html), 'HTML corrector -- Existing cdata section <!--/*--><![CDATA[/* ><!--*/ properly escaped');

    $html = '<p><script>
//<![CDATA[
  alert("test");
//]]>
</script></p>';
    $this->assertEquals($html, Html::normalize($html), new FormattableMarkup('HTML corrector -- Existing cdata section @pattern_name properly escaped', ['@pattern_name' => '<!--//--><![CDATA[// ><!--']));
    $this->assertEquals($html, Html::normalize($html), 'HTML corrector -- Existing cdata section <!--//--><![CDATA[// ><!-- properly escaped');

    $html = '<p><script>
// <![CDATA[
  alert("test");
//]]>
</script></p>';
    $this->assertEquals($html, Html::normalize($html), new FormattableMarkup('HTML corrector -- Existing cdata section @pattern_name properly escaped', ['@pattern_name' => '// <![CDATA[']));
    $this->assertEquals($html, Html::normalize($html), 'HTML corrector -- Existing cdata section // <![CDATA[ properly escaped');

    $html = '<p><script>
// <![CDATA[![CDATA[![CDATA[
  alert("test");
//]]]]]]>
</script></p>';
    $this->assertEquals($html, Html::normalize($html), new FormattableMarkup('HTML corrector -- Existing cdata section @pattern_name properly escaped', ['@pattern_name' => '// <![CDATA[![CDATA[![CDATA[']));
    $this->assertEquals($html, Html::normalize($html), 'HTML corrector -- Existing cdata section // <![CDATA[![CDATA[![CDATA[ properly escaped');

    // Test calling Html::normalize() twice.
    $html = '<p><script>
@@ -1213,7 +1212,7 @@ public function testHtmlCorrectorFilter() {
  alert("test");
//]]]]]]>
</script></p>';
    $this->assertEquals($html, Html::normalize(Html::normalize($html)), new FormattableMarkup('HTML corrector -- Existing cdata section @pattern_name properly escaped', ['@pattern_name' => '// <![CDATA[![CDATA[![CDATA[']));
    $this->assertEquals($html, Html::normalize(Html::normalize($html)), 'HTML corrector -- Existing cdata section // <![CDATA[![CDATA[![CDATA[ properly escaped');
  }

  /**
+2 −2
Original line number Diff line number Diff line
@@ -2,7 +2,6 @@

namespace Drupal\Tests\menu_link_content\Kernel;

use Drupal\Component\Render\FormattableMarkup;
use Drupal\Core\Menu\MenuTreeParameters;
use Drupal\entity_test\Entity\EntityTestExternal;
use Drupal\KernelTests\KernelTestBase;
@@ -129,7 +128,8 @@ public function assertMenuLinkParents(array $links, array $expected_hierarchy):
      $menu_link_plugin = $this->menuLinkManager->createInstance($links[$id]);
      $expected_parent = $links[$parent] ?? '';

      $this->assertEquals($expected_parent, $menu_link_plugin->getParent(), new FormattableMarkup('Menu link %id has parent of %parent, expected %expected_parent.', ['%id' => $id, '%parent' => $menu_link_plugin->getParent(), '%expected_parent' => $expected_parent]));
      $link_parent = $menu_link_plugin->getParent();
      $this->assertEquals($expected_parent, $link_parent, "Menu link $id has parent of $link_parent, expected $expected_parent.");
    }
  }

Loading