diff --git a/core/modules/update/tests/src/Kernel/UpdateReportTest.php b/core/modules/update/tests/src/Kernel/UpdateReportTest.php index 16468e62c5b03ea6c50149b83cedee427404242e..cee75a38b1556689c7ccf718558ca6509834c6da 100644 --- a/core/modules/update/tests/src/Kernel/UpdateReportTest.php +++ b/core/modules/update/tests/src/Kernel/UpdateReportTest.php @@ -117,7 +117,7 @@ public function testTemplatePreprocessUpdateFetchErrorMessageWithDblog(): void { $this->render($build); $this->assertRaw('Failed to fetch available update data:<ul><li>See <a href="https://www.drupal.org/node/3170647">PHP OpenSSL requirements</a> in the Drupal.org handbook for possible reasons this could happen and what you can do to resolve them.</li><li>Check'); $dblog_url = Url::fromRoute('dblog.overview', [], ['query' => ['type' => ['update']]]); - $this->assertRaw(Link::fromTextAndUrl('your local system logs', $dblog_url)->toString()); + $this->assertRaw((string) Link::fromTextAndUrl('your local system logs', $dblog_url)->toString()); $this->assertRaw(' for additional error messages.</li></ul>'); $variables = []; diff --git a/core/phpcs.xml.dist b/core/phpcs.xml.dist index 0c4784aac89d4f769c89685a0c64afc0de3105ae..54bdfe45052a961b005fb839f569bccf92fa0d66 100644 --- a/core/phpcs.xml.dist +++ b/core/phpcs.xml.dist @@ -277,8 +277,6 @@ <include-pattern>./modules/system/src/Tests/Routing/*</include-pattern> <exclude-pattern>./tests/Drupal/Tests/*/Fixture/*</exclude-pattern> <exclude-pattern>./tests/Drupal/Tests/*/fixtures/*</exclude-pattern> - <!-- @todo remove this in https://www.drupal.org/project/drupal/issues/3402707 --> - <exclude-pattern>./tests/Drupal/KernelTests/AssertContentTrait.php</exclude-pattern> </rule> <rule ref="SlevomatCodingStandard.TypeHints.NullableTypeForNullDefaultValue"/> diff --git a/core/tests/Drupal/KernelTests/AssertContentTrait.php b/core/tests/Drupal/KernelTests/AssertContentTrait.php index fa9ce3faced1b3db5d74306587b6e492f8de14aa..8d16f053f53b3b8f4d6d81313e35d201c8d42202 100644 --- a/core/tests/Drupal/KernelTests/AssertContentTrait.php +++ b/core/tests/Drupal/KernelTests/AssertContentTrait.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + namespace Drupal\KernelTests; use Drupal\Component\Serialization\Json; @@ -58,11 +60,11 @@ protected function getRawContent() { * The raw content to set. */ protected function setRawContent($content) { - $this->content = $content; + $this->content = (string) $content; $this->plainTextContent = NULL; $this->elements = NULL; $this->drupalSettings = []; - if (preg_match('@<script type="application/json" data-drupal-selector="drupal-settings-json">([^<]*)</script>@', $content, $matches)) { + if (preg_match('@<script type="application/json" data-drupal-selector="drupal-settings-json">([^<]*)</script>@', (string) $content, $matches)) { $this->drupalSettings = Json::decode($matches[1]); } } @@ -305,7 +307,7 @@ protected function assertNoLink($label, $message = ''): bool { // Cast MarkupInterface objects to string. $label = (string) $label; $links = $this->xpath('//a[normalize-space(text())=:label]', [':label' => $label]); - $message = ($message ? $message : new FormattableMarkup('Link with label %label not found.', ['%label' => $label])); + $message = $message ?: "Link with label $label not found."; $this->assertEmpty($links, $message); return TRUE; } @@ -328,8 +330,8 @@ protected function assertNoLink($label, $message = ''): bool { */ protected function assertLinkByHref($href, $index = 0, $message = ''): bool { $links = $this->xpath('//a[contains(@href, :href)]', [':href' => $href]); - $message = ($message ? $message : new FormattableMarkup('Link containing href %href found.', ['%href' => $href])); - $this->assertArrayHasKey($index, $links, $message); + $message = $message ?: "Link containing href $href found."; + $this->assertArrayHasKey($index, $links, (string) $message); return TRUE; } @@ -390,7 +392,7 @@ protected function assertNoLinkByHrefInMainRegion($href, $message = ''): bool { */ protected function assertRaw($raw, $message = ''): void { if (!$message) { - $message = 'Raw "' . Html::escape($raw) . '" found'; + $message = 'Raw "' . Html::escape((string) $raw) . '" found'; } $this->assertStringContainsString((string) $raw, $this->getRawContent(), $message); } @@ -410,7 +412,7 @@ protected function assertRaw($raw, $message = ''): void { */ protected function assertNoRaw($raw, $message = ''): void { if (!$message) { - $message = 'Raw "' . Html::escape($raw) . '" not found'; + $message = 'Raw "' . Html::escape((string) $raw) . '" not found'; } $this->assertStringNotContainsString((string) $raw, $this->getRawContent(), $message); } @@ -430,9 +432,9 @@ protected function assertNoRaw($raw, $message = ''): void { */ protected function assertEscaped($raw, $message = ''): void { if (!$message) { - $message = 'Escaped "' . Html::escape($raw) . '" found'; + $message = 'Escaped "' . Html::escape((string) $raw) . '" found'; } - $this->assertStringContainsString(Html::escape($raw), $this->getRawContent(), $message); + $this->assertStringContainsString(Html::escape((string) $raw), $this->getRawContent(), $message); } /** @@ -450,9 +452,9 @@ protected function assertEscaped($raw, $message = ''): void { */ protected function assertNoEscaped($raw, $message = ''): void { if (!$message) { - $message = 'Escaped "' . Html::escape($raw) . '" not found'; + $message = 'Escaped "' . Html::escape((string) $raw) . '" not found'; } - $this->assertStringNotContainsString(Html::escape($raw), $this->getRawContent(), $message); + $this->assertStringNotContainsString(Html::escape((string) $raw), $this->getRawContent(), $message); } /** @@ -518,10 +520,10 @@ protected function assertTextHelper($text, $message = '', $group = NULL, $not_ex $message = !$not_exists ? new FormattableMarkup('"@text" found', ['@text' => $text]) : new FormattableMarkup('"@text" not found', ['@text' => $text]); } if ($not_exists) { - $this->assertStringNotContainsString((string) $text, $this->getTextContent(), $message); + $this->assertStringNotContainsString((string) $text, $this->getTextContent(), (string) $message); } else { - $this->assertStringContainsString((string) $text, $this->getTextContent(), $message); + $this->assertStringContainsString((string) $text, $this->getTextContent(), (string) $message); } } @@ -624,7 +626,7 @@ protected function assertPattern($pattern, $message = ''): bool { if (!$message) { $message = new FormattableMarkup('Pattern "@pattern" found', ['@pattern' => $pattern]); } - $this->assertMatchesRegularExpression($pattern, $this->getRawContent(), $message); + $this->assertMatchesRegularExpression($pattern, $this->getRawContent(), (string) $message); return TRUE; } @@ -691,7 +693,7 @@ protected function assertTitle($title, $message = '') { '@expected' => var_export($title, TRUE), ]); } - $this->assertEquals($title, $actual, $message); + $this->assertEquals($title, $actual, (string) $message); } else { $this->fail('No title element found on the page.'); @@ -749,7 +751,7 @@ protected function assertThemeOutput($callback, array $variables = [], $expected $message = '%callback rendered correctly.'; } $message = new FormattableMarkup($message, ['%callback' => 'theme_' . $callback . '()']); - $this->assertSame($expected, $output, $message); + $this->assertSame($expected, $output, (string) $message); } /** @@ -802,7 +804,7 @@ protected function assertFieldsByValue($fields, $value = NULL, $message = ''): b } } $this->assertNotEmpty($fields); - $this->assertTrue($found, $message); + $this->assertTrue($found, (string) $message); return TRUE; } @@ -886,7 +888,7 @@ protected function assertNoFieldByXPath($xpath, $value = NULL, $message = ''): b } } $this->assertNotEmpty($fields); - $this->assertTrue($found, $message); + $this->assertTrue($found, (string) $message); return TRUE; }