From ee348449d056ee562537814d01c3ec06b229b495 Mon Sep 17 00:00:00 2001 From: Lee Rowlands Date: Mon, 8 Jan 2024 07:55:19 +1000 Subject: [PATCH] Issue #3402295 by mstrelan, dww, smustgrave: Fix strict type errors in kernel tests: Add casts and fix types where needed (cherry picked from commit 5b8514adec9b33570cb7c33bc79c41d93d7b2bf1) --- .../tests/src/Kernel/BookMultilingualTest.php | 8 +- .../src/Kernel/DefaultRevisionStateTest.php | 4 +- .../WorkspacesContentModerationStateTest.php | 2 +- ...ontentTranslationFieldSyncRevisionTest.php | 2 +- .../EntityReferenceFormatterTest.php | 6 +- .../EntityReference/Views/SelectionTest.php | 2 +- .../tests/src/Kernel/FieldDisplayTest.php | 4 +- .../tests/src/Kernel/FieldKernelTestBase.php | 2 +- .../Kernel/Views/HandlerFieldFieldTest.php | 2 +- .../src/Kernel/FileManagedUnitTestBase.php | 2 +- .../Formatter/FileEntityFormatterTest.php | 2 +- .../tests/src/Kernel/ImageFormatterTest.php | 12 +-- .../src/Kernel/Migrate/d7/MigrateNodeTest.php | 2 +- .../tests/src/Kernel/SearchExcerptTest.php | 2 +- .../tests/src/Kernel/Common/AddFeedTest.php | 2 +- .../tests/src/Kernel/Common/UrlTest.php | 12 +-- .../src/Kernel/Entity/EntityLabelTest.php | 4 +- .../tests/src/Kernel/TermKernelTest.php | 2 +- .../src/Kernel/Migrate/d7/MigrateUserTest.php | 8 +- .../Views/HandlerFilterPermissionTest.php | 2 +- .../Kernel/Entity/RowEntityRenderersTest.php | 2 +- .../src/Kernel/Handler/AreaEntityTest.php | 2 +- .../tests/src/Kernel/Handler/AreaTest.php | 6 +- .../tests/src/Kernel/Handler/AreaViewTest.php | 4 +- .../src/Kernel/Handler/FieldDateTest.php | 4 +- .../src/Kernel/Handler/FieldFieldTest.php | 30 +++--- .../src/Kernel/Handler/FieldKernelTest.php | 98 +++++++++---------- .../Handler/FieldRenderedEntityTest.php | 4 +- .../src/Kernel/Handler/FilterCombineTest.php | 4 +- .../src/Kernel/Plugin/DisplayPageTest.php | 4 +- .../src/Kernel/Plugin/StyleHtmlListTest.php | 4 +- .../src/Kernel/Plugin/StyleMappingTest.php | 4 +- .../src/Kernel/Plugin/StyleTableUnitTest.php | 6 +- .../tests/src/Kernel/Plugin/StyleTest.php | 2 +- .../tests/src/Kernel/ViewExecutableTest.php | 2 +- .../Core/Asset/AttachedAssetsTest.php | 30 +++--- .../Entity/EntityAccessControlHandlerTest.php | 2 +- ...ntityDecoupledTranslationRevisionsTest.php | 2 +- .../Entity/EntityDefinitionUpdateTest.php | 22 ++--- .../RevisionableContentEntityBaseTest.php | 6 +- .../Core/File/StreamWrapperTest.php | 4 +- .../Core/Menu/MenuTreeStorageTest.php | 2 +- .../Render/Element/RenderElementTypesTest.php | 6 +- 43 files changed, 166 insertions(+), 166 deletions(-) diff --git a/core/modules/book/tests/src/Kernel/BookMultilingualTest.php b/core/modules/book/tests/src/Kernel/BookMultilingualTest.php index fbdfc3d8499a..73625a5a7068 100644 --- a/core/modules/book/tests/src/Kernel/BookMultilingualTest.php +++ b/core/modules/book/tests/src/Kernel/BookMultilingualTest.php @@ -174,7 +174,7 @@ class BookMultilingualTest extends KernelTestBase { $books = $bm->getAllBooks(); $this->assertNotEmpty($books); foreach ($books as $book) { - $bid = $book['bid']; + $bid = (int) $book['bid']; $build = $bm->bookTreeOutput($bm->bookTreeAllData($bid)); $items = $build['#items']; $this->assertBookItemIsCorrectlyTranslated($items[$bid], $langcode); @@ -217,7 +217,7 @@ class BookMultilingualTest extends KernelTestBase { $bbb = $this->container->get('book.breadcrumb'); $links = $bbb->build($route_match)->getLinks(); $link = array_shift($links); - $rendered_link = Link::fromTextAndUrl($link->getText(), $link->getUrl())->toString(); + $rendered_link = (string) Link::fromTextAndUrl($link->getText(), $link->getUrl())->toString(); $this->assertStringContainsString("http://$langcode.book.test.domain/", $rendered_link); $link = array_shift($links); $this->assertNodeLinkIsCorrectlyTranslated(1, $link->getText(), $link->getUrl(), $langcode); @@ -292,7 +292,7 @@ class BookMultilingualTest extends KernelTestBase { * @internal */ protected function assertBookItemIsCorrectlyTranslated(array $item, string $langcode): void { - $this->assertNodeLinkIsCorrectlyTranslated($item['original_link']['nid'], $item['title'], $item['url'], $langcode); + $this->assertNodeLinkIsCorrectlyTranslated((int) $item['original_link']['nid'], $item['title'], $item['url'], $langcode); } /** @@ -312,7 +312,7 @@ class BookMultilingualTest extends KernelTestBase { protected function assertNodeLinkIsCorrectlyTranslated(int $nid, string $title, Url $url, string $langcode): void { $node = Node::load($nid); $this->assertSame($node->getTranslation($langcode)->label(), $title); - $rendered_link = Link::fromTextAndUrl($title, $url)->toString(); + $rendered_link = (string) Link::fromTextAndUrl($title, $url)->toString(); $this->assertStringContainsString("http://$langcode.book.test.domain/node/$nid", $rendered_link); } diff --git a/core/modules/content_moderation/tests/src/Kernel/DefaultRevisionStateTest.php b/core/modules/content_moderation/tests/src/Kernel/DefaultRevisionStateTest.php index 9bb05d02d0b6..9ced54c900db 100644 --- a/core/modules/content_moderation/tests/src/Kernel/DefaultRevisionStateTest.php +++ b/core/modules/content_moderation/tests/src/Kernel/DefaultRevisionStateTest.php @@ -116,7 +116,7 @@ class DefaultRevisionStateTest extends KernelTestBase { /** * Verifies the expected moderation state revision exists. * - * @param int $revision_id + * @param string $revision_id * The revision ID of the host entity. * @param string $langcode * The language code of the host entity to check. @@ -127,7 +127,7 @@ class DefaultRevisionStateTest extends KernelTestBase { * * @internal */ - protected function assertModerationState(int $revision_id, string $langcode, string $expected_state, string $expected_workflow = 'editorial'): void { + protected function assertModerationState(string $revision_id, string $langcode, string $expected_state, string $expected_workflow = 'editorial'): void { $moderation_state_storage = $this->entityTypeManager->getStorage('content_moderation_state'); $query = $moderation_state_storage->getQuery()->accessCheck(FALSE); diff --git a/core/modules/content_moderation/tests/src/Kernel/WorkspacesContentModerationStateTest.php b/core/modules/content_moderation/tests/src/Kernel/WorkspacesContentModerationStateTest.php index 6589ec00f199..9f9776682e5d 100644 --- a/core/modules/content_moderation/tests/src/Kernel/WorkspacesContentModerationStateTest.php +++ b/core/modules/content_moderation/tests/src/Kernel/WorkspacesContentModerationStateTest.php @@ -256,7 +256,7 @@ class WorkspacesContentModerationStateTest extends ContentModerationStateTest { // In the context of a workspace, the default revision ID is always the // latest workspace-specific revision, so we need to adjust the expectation // of the parent assertion. - $revision_id = $this->entityTypeManager->getStorage($entity->getEntityTypeId())->load($entity->id())->getRevisionId(); + $revision_id = (int) $this->entityTypeManager->getStorage($entity->getEntityTypeId())->load($entity->id())->getRevisionId(); // Additionally, the publishing status of the default revision is not // relevant in a workspace, because getting an entity to a "published" diff --git a/core/modules/content_translation/tests/src/Kernel/ContentTranslationFieldSyncRevisionTest.php b/core/modules/content_translation/tests/src/Kernel/ContentTranslationFieldSyncRevisionTest.php index a689935c413f..288f91eedfed 100644 --- a/core/modules/content_translation/tests/src/Kernel/ContentTranslationFieldSyncRevisionTest.php +++ b/core/modules/content_translation/tests/src/Kernel/ContentTranslationFieldSyncRevisionTest.php @@ -483,7 +483,7 @@ class ContentTranslationFieldSyncRevisionTest extends EntityKernelTestBase { * * @internal */ - protected function assertLatestRevisionFieldValues(int $entity_id, array $expected_values): void { + protected function assertLatestRevisionFieldValues(string $entity_id, array $expected_values): void { /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */ $entity = $this->storage->loadRevision($this->storage->getLatestRevisionId($entity_id)); @[$revision_id, $target_id_en, $target_id_it, $alt_en, $alt_it] = $expected_values; diff --git a/core/modules/field/tests/src/Kernel/EntityReference/EntityReferenceFormatterTest.php b/core/modules/field/tests/src/Kernel/EntityReference/EntityReferenceFormatterTest.php index 804f5ab97ece..14456f6aee1f 100644 --- a/core/modules/field/tests/src/Kernel/EntityReference/EntityReferenceFormatterTest.php +++ b/core/modules/field/tests/src/Kernel/EntityReference/EntityReferenceFormatterTest.php @@ -260,7 +260,7 @@ class EntityReferenceFormatterTest extends EntityKernelTestBase { // Check that the recursive rendering stops after it reaches the specified // limit. $build = $view_builder->view($referencing_entity_1, 'default'); - $output = $renderer->renderRoot($build); + $output = (string) $renderer->renderRoot($build); // The title of entity_test entities is printed twice by default, so we have // to multiply the formatter's recursive rendering protection limit by 2. @@ -279,14 +279,14 @@ class EntityReferenceFormatterTest extends EntityKernelTestBase { $referencing_entity_2->save(); $build = $view_builder->view($referencing_entity_2, 'default'); - $output = $renderer->renderRoot($build); + $output = (string) $renderer->renderRoot($build); $actual_occurrences = substr_count($output, $referencing_entity_2->label()); $this->assertEquals($expected_occurrences, $actual_occurrences); // Now render both entities at the same time and check again. $build = $view_builder->viewMultiple([$referencing_entity_1, $referencing_entity_2], 'default'); - $output = $renderer->renderRoot($build); + $output = (string) $renderer->renderRoot($build); $actual_occurrences = substr_count($output, $referencing_entity_1->label()); $this->assertEquals($expected_occurrences, $actual_occurrences); diff --git a/core/modules/field/tests/src/Kernel/EntityReference/Views/SelectionTest.php b/core/modules/field/tests/src/Kernel/EntityReference/Views/SelectionTest.php index d9adda0c5690..8110e0c525ee 100644 --- a/core/modules/field/tests/src/Kernel/EntityReference/Views/SelectionTest.php +++ b/core/modules/field/tests/src/Kernel/EntityReference/Views/SelectionTest.php @@ -161,7 +161,7 @@ class SelectionTest extends KernelTestBase { foreach ($result as $node_type => $values) { foreach ($values as $nid => $label) { $this->assertSame($node_type, $this->nodes[$nid]->bundle()); - $this->assertSame(trim(strip_tags($label)), Html::escape($this->nodes[$nid]->label())); + $this->assertSame(trim(strip_tags((string) $label)), Html::escape($this->nodes[$nid]->label())); } } } diff --git a/core/modules/field/tests/src/Kernel/FieldDisplayTest.php b/core/modules/field/tests/src/Kernel/FieldDisplayTest.php index 09801aea26b2..14d568f4fed9 100644 --- a/core/modules/field/tests/src/Kernel/FieldDisplayTest.php +++ b/core/modules/field/tests/src/Kernel/FieldDisplayTest.php @@ -115,8 +115,8 @@ class FieldDisplayTest extends KernelTestBase { $build = $this->display->build($entity); $renderer = \Drupal::service('renderer'); - $content = $renderer->renderPlain($build); - $this->setRawContent((string) $content); + $content = (string) $renderer->renderPlain($build); + $this->setRawContent($content); $css_selector_converter = new CssSelectorConverter(); $elements = $this->xpath($css_selector_converter->toXPath('.visually-hidden')); diff --git a/core/modules/field/tests/src/Kernel/FieldKernelTestBase.php b/core/modules/field/tests/src/Kernel/FieldKernelTestBase.php index a6dd4bae1cf5..f630209c7c76 100644 --- a/core/modules/field/tests/src/Kernel/FieldKernelTestBase.php +++ b/core/modules/field/tests/src/Kernel/FieldKernelTestBase.php @@ -155,7 +155,7 @@ abstract class FieldKernelTestBase extends KernelTestBase { protected function entityValidateAndSave(EntityInterface $entity) { $violations = $entity->validate(); if ($violations->count()) { - $this->fail($violations); + $this->fail((string) $violations); } else { $entity->save(); diff --git a/core/modules/field/tests/src/Kernel/Views/HandlerFieldFieldTest.php b/core/modules/field/tests/src/Kernel/Views/HandlerFieldFieldTest.php index 3e6f9d20fe7c..ce88f094663d 100644 --- a/core/modules/field/tests/src/Kernel/Views/HandlerFieldFieldTest.php +++ b/core/modules/field/tests/src/Kernel/Views/HandlerFieldFieldTest.php @@ -162,7 +162,7 @@ class HandlerFieldFieldTest extends KernelTestBase { // @see https://www.drupal.org/project/drupal/issues/3046722 for ($i = 0; $i < 2; $i++) { $field_name = $this->fieldStorages[5]->getName(); - $rendered_field = $view->style_plugin->getField($i, $field_name); + $rendered_field = (string) $view->style_plugin->getField($i, $field_name); $this->assertEquals(3, strlen(html_entity_decode($rendered_field))); } } diff --git a/core/modules/file/tests/src/Kernel/FileManagedUnitTestBase.php b/core/modules/file/tests/src/Kernel/FileManagedUnitTestBase.php index 990b5ef658cc..19ca6f584a01 100644 --- a/core/modules/file/tests/src/Kernel/FileManagedUnitTestBase.php +++ b/core/modules/file/tests/src/Kernel/FileManagedUnitTestBase.php @@ -97,7 +97,7 @@ abstract class FileManagedUnitTestBase extends KernelTestBase { $message = new FormattableMarkup('hook_file_@name was expected to be called %expected times but was called %actual times.', ['@name' => $hook, '%expected' => $expected_count, '%actual' => $actual_count]); } } - $this->assertEquals($expected_count, $actual_count, $message); + $this->assertEquals($expected_count, $actual_count, (string) $message); } /** diff --git a/core/modules/file/tests/src/Kernel/Formatter/FileEntityFormatterTest.php b/core/modules/file/tests/src/Kernel/Formatter/FileEntityFormatterTest.php index a32838bd650f..26c506dc9959 100644 --- a/core/modules/file/tests/src/Kernel/Formatter/FileEntityFormatterTest.php +++ b/core/modules/file/tests/src/Kernel/Formatter/FileEntityFormatterTest.php @@ -185,7 +185,7 @@ class FileEntityFormatterTest extends KernelTestBase { '#file' => $file, ]; - $output = \Drupal::service('renderer')->renderRoot($file_link); + $output = (string) \Drupal::service('renderer')->renderRoot($file_link); $this->assertStringContainsString($this->fileUrlGenerator->generate('dummy-external-readonly://file-query-string?foo=bar')->toUriString(), $output); } diff --git a/core/modules/image/tests/src/Kernel/ImageFormatterTest.php b/core/modules/image/tests/src/Kernel/ImageFormatterTest.php index b2f67d1c4b29..0f7ee9404cb7 100644 --- a/core/modules/image/tests/src/Kernel/ImageFormatterTest.php +++ b/core/modules/image/tests/src/Kernel/ImageFormatterTest.php @@ -154,9 +154,9 @@ class ImageFormatterTest extends FieldKernelTestBase { $this->assertEquals('medium', $build[$this->fieldName][0]['#image_style']); // We check that the image URL contains the expected style directory // structure. - $this->assertStringContainsString('styles/medium/public/test-image.png', $build[$this->fieldName][0]['#markup']); - $this->assertStringContainsString('width="220"', $build[$this->fieldName][0]['#markup']); - $this->assertStringContainsString('height="220"', $build[$this->fieldName][0]['#markup']); + $this->assertStringContainsString('styles/medium/public/test-image.png', (string) $build[$this->fieldName][0]['#markup']); + $this->assertStringContainsString('width="220"', (string) $build[$this->fieldName][0]['#markup']); + $this->assertStringContainsString('height="220"', (string) $build[$this->fieldName][0]['#markup']); // The second image is an SVG, which is not supported by the GD toolkit. // The image style should still be applied with its cache tags, but image @@ -167,11 +167,11 @@ class ImageFormatterTest extends FieldKernelTestBase { $this->assertEquals('medium', $build[$this->fieldName][1]['#image_style']); // We check that the image URL does not contain the style directory // structure. - $this->assertStringNotContainsString('styles/medium/public/test-image.svg', $build[$this->fieldName][1]['#markup']); + $this->assertStringNotContainsString('styles/medium/public/test-image.svg', (string) $build[$this->fieldName][1]['#markup']); // Since we did not store original image dimensions, width and height // HTML attributes will not be present. - $this->assertStringNotContainsString('width', $build[$this->fieldName][1]['#markup']); - $this->assertStringNotContainsString('height', $build[$this->fieldName][1]['#markup']); + $this->assertStringNotContainsString('width', (string) $build[$this->fieldName][1]['#markup']); + $this->assertStringNotContainsString('height', (string) $build[$this->fieldName][1]['#markup']); } /** diff --git a/core/modules/node/tests/src/Kernel/Migrate/d7/MigrateNodeTest.php b/core/modules/node/tests/src/Kernel/Migrate/d7/MigrateNodeTest.php index 55035a7419b7..ff1814d7fd0b 100644 --- a/core/modules/node/tests/src/Kernel/Migrate/d7/MigrateNodeTest.php +++ b/core/modules/node/tests/src/Kernel/Migrate/d7/MigrateNodeTest.php @@ -106,7 +106,7 @@ class MigrateNodeTest extends MigrateDrupal7TestBase { * * @internal */ - protected function assertEntity(string $id, string $type, string $langcode, string $title, int $uid, bool $status, int $created, int $changed, bool $promoted, bool $sticky): void { + protected function assertEntity(int $id, string $type, string $langcode, string $title, int $uid, bool $status, int $created, int $changed, bool $promoted, bool $sticky): void { /** @var \Drupal\node\NodeInterface $node */ $node = Node::load($id); $this->assertInstanceOf(NodeInterface::class, $node); diff --git a/core/modules/search/tests/src/Kernel/SearchExcerptTest.php b/core/modules/search/tests/src/Kernel/SearchExcerptTest.php index 3d740bb586d2..2c2bc79001ea 100644 --- a/core/modules/search/tests/src/Kernel/SearchExcerptTest.php +++ b/core/modules/search/tests/src/Kernel/SearchExcerptTest.php @@ -191,7 +191,7 @@ class SearchExcerptTest extends KernelTestBase { */ protected function doSearchExcerpt($keys, $render_array, $langcode = NULL) { $render_array = search_excerpt($keys, $render_array, $langcode); - $text = \Drupal::service('renderer')->renderPlain($render_array); + $text = (string) \Drupal::service('renderer')->renderPlain($render_array); // The search_excerpt() function adds some extra spaces -- not // important for HTML formatting or this test. Remove these for comparison. return preg_replace('| +|', ' ', $text); diff --git a/core/modules/system/tests/src/Kernel/Common/AddFeedTest.php b/core/modules/system/tests/src/Kernel/Common/AddFeedTest.php index 8c9d8350ac04..eacb206d3e97 100644 --- a/core/modules/system/tests/src/Kernel/Common/AddFeedTest.php +++ b/core/modules/system/tests/src/Kernel/Common/AddFeedTest.php @@ -93,7 +93,7 @@ class AddFeedTest extends KernelTestBase { '#url' => 'node', '#title' => '<>&"\'', ]; - $text = \Drupal::service('renderer')->renderRoot($variables); + $text = (string) \Drupal::service('renderer')->renderRoot($variables); $this->assertEquals('Subscribe to <>&"'', trim(strip_tags($text)), 'feed_icon template escapes reserved HTML characters.'); } diff --git a/core/modules/system/tests/src/Kernel/Common/UrlTest.php b/core/modules/system/tests/src/Kernel/Common/UrlTest.php index 9457ca8a8159..97e2dff93461 100644 --- a/core/modules/system/tests/src/Kernel/Common/UrlTest.php +++ b/core/modules/system/tests/src/Kernel/Common/UrlTest.php @@ -31,12 +31,12 @@ class UrlTest extends KernelTestBase { $path = ""; $encoded_path = "%3CSCRIPT%3Ealert%28%27XSS%27%29%3C/SCRIPT%3E"; - $link = Link::fromTextAndUrl($text, Url::fromUserInput('/' . $path))->toString(); + $link = (string) Link::fromTextAndUrl($text, Url::fromUserInput('/' . $path))->toString(); $this->assertStringContainsString($encoded_path, $link, "XSS attack $path was filtered by \\Drupal\\Core\\Utility\\LinkGeneratorInterface::generate()."); $this->assertStringNotContainsString($path, $link, "XSS attack $path was filtered by \\Drupal\\Core\\Utility\\LinkGeneratorInterface::generate()."); // Test \Drupal\Core\Url. - $link = Url::fromUri('base:' . $path)->toString(); + $link = (string) Url::fromUri('base:' . $path)->toString(); $this->assertStringContainsString($encoded_path, $link, "XSS attack $path was filtered by #theme"); $this->assertStringNotContainsString($path, $link, "XSS attack $path was filtered by #theme"); } @@ -95,17 +95,17 @@ class UrlTest extends KernelTestBase { $hreflang_override_link = $hreflang_link; $hreflang_override_link['#options']['attributes']['hreflang'] = 'foo'; - $rendered = $renderer->renderRoot($hreflang_link); + $rendered = (string) $renderer->renderRoot($hreflang_link); $this->assertTrue($this->hasAttribute('hreflang', $rendered, $langcode), "hreflang attribute with value $langcode is present on a rendered link when langcode is provided in the render array."); - $rendered = $renderer->renderRoot($hreflang_override_link); + $rendered = (string) $renderer->renderRoot($hreflang_override_link); $this->assertTrue($this->hasAttribute('hreflang', $rendered, 'foo'), 'hreflang attribute with value foo is present on a rendered link when @hreflang is provided in the render array.'); // Test adding a custom class in links produced by // \Drupal\Core\Utility\LinkGeneratorInterface::generate() and #type 'link'. // Test the link generator. $class_l = $this->randomMachineName(); - $link_l = Link::fromTextAndUrl($this->randomMachineName(), Url::fromRoute('common_test.destination', [], ['attributes' => ['class' => [$class_l]]]))->toString(); + $link_l = (string) Link::fromTextAndUrl($this->randomMachineName(), Url::fromRoute('common_test.destination', [], ['attributes' => ['class' => [$class_l]]]))->toString(); $this->assertTrue($this->hasAttribute('class', $link_l, $class_l), "Custom class $class_l is present on link when requested by Link::toString()"); // Test #type. @@ -120,7 +120,7 @@ class UrlTest extends KernelTestBase { ], ], ]; - $link_theme = $renderer->renderRoot($type_link); + $link_theme = (string) $renderer->renderRoot($type_link); $this->assertTrue($this->hasAttribute('class', $link_theme, $class_theme), "Custom class $class_theme is present on link when requested by #type"); } diff --git a/core/modules/system/tests/src/Kernel/Entity/EntityLabelTest.php b/core/modules/system/tests/src/Kernel/Entity/EntityLabelTest.php index a29d454355ae..380b5fb1570d 100644 --- a/core/modules/system/tests/src/Kernel/Entity/EntityLabelTest.php +++ b/core/modules/system/tests/src/Kernel/Entity/EntityLabelTest.php @@ -41,11 +41,11 @@ class EntityLabelTest extends KernelTestBase { // string. Special cases may need to be added to this test in the future // if an acronym is in a different position in the label. $first_word = strtok($label_string, " "); - $remaining_string = strtolower(strstr($label_string, " ")); + $remaining_string = strtolower((string) strstr($label_string, " ")); $this->assertEquals($first_word . $remaining_string, $label_string); $first_word = strtok($collection_label_string, " "); - $remaining_string = strtolower(strstr($collection_label_string, " ")); + $remaining_string = strtolower((string) strstr($collection_label_string, " ")); $this->assertEquals($first_word . $remaining_string, $collection_label_string); } } diff --git a/core/modules/taxonomy/tests/src/Kernel/TermKernelTest.php b/core/modules/taxonomy/tests/src/Kernel/TermKernelTest.php index 8166e9a3f732..b0b4d4f5dc14 100644 --- a/core/modules/taxonomy/tests/src/Kernel/TermKernelTest.php +++ b/core/modules/taxonomy/tests/src/Kernel/TermKernelTest.php @@ -167,7 +167,7 @@ class TermKernelTest extends KernelTestBase { $this->assertNotEmpty($render_array, 'Term view builder is built.'); // Confirm we can render said view. - $rendered = \Drupal::service('renderer')->renderPlain($render_array); + $rendered = (string) \Drupal::service('renderer')->renderPlain($render_array); $this->assertNotEmpty(trim($rendered), 'Term is able to be rendered.'); } diff --git a/core/modules/user/tests/src/Kernel/Migrate/d7/MigrateUserTest.php b/core/modules/user/tests/src/Kernel/Migrate/d7/MigrateUserTest.php index 571c8c08bafc..1f4ff49057c6 100644 --- a/core/modules/user/tests/src/Kernel/Migrate/d7/MigrateUserTest.php +++ b/core/modules/user/tests/src/Kernel/Migrate/d7/MigrateUserTest.php @@ -194,10 +194,10 @@ class MigrateUserTest extends MigrateDrupal7TestBase { $source->name, $source->mail, $source->pass, - $source->created, - $source->access, - $source->login, - $source->status, + (int) $source->created, + (int) $source->access, + (int) $source->login, + (bool) $source->status, $entity_language, $source->language, $source->timezone, diff --git a/core/modules/user/tests/src/Kernel/Views/HandlerFilterPermissionTest.php b/core/modules/user/tests/src/Kernel/Views/HandlerFilterPermissionTest.php index f2c403cd593c..8c7bd1274f38 100644 --- a/core/modules/user/tests/src/Kernel/Views/HandlerFilterPermissionTest.php +++ b/core/modules/user/tests/src/Kernel/Views/HandlerFilterPermissionTest.php @@ -105,7 +105,7 @@ class HandlerFilterPermissionTest extends UserKernelTestBase { } foreach (['system' => 'System', 'user' => 'User'] as $module => $title) { $expected = array_map(function ($permission) { - return Html::escape(strip_tags($permission['title'])); + return Html::escape(strip_tags((string) $permission['title'])); }, $permission_by_module[$module]); $this->assertEquals($expected, $value_options[$title], 'Ensure the all permissions are available'); diff --git a/core/modules/views/tests/src/Kernel/Entity/RowEntityRenderersTest.php b/core/modules/views/tests/src/Kernel/Entity/RowEntityRenderersTest.php index 12cfc35988e5..82516bc672c7 100644 --- a/core/modules/views/tests/src/Kernel/Entity/RowEntityRenderersTest.php +++ b/core/modules/views/tests/src/Kernel/Entity/RowEntityRenderersTest.php @@ -386,7 +386,7 @@ class RowEntityRenderersTest extends ViewsKernelTestBase { foreach ($expected as $index => $expected_output) { if (!empty($view->result[$index])) { $build = $view->rowPlugin->render($view->result[$index]); - $output = \Drupal::service('renderer')->renderRoot($build); + $output = (string) \Drupal::service('renderer')->renderRoot($build); $result = str_contains($output, $expected_output); if (!$result) { break; diff --git a/core/modules/views/tests/src/Kernel/Handler/AreaEntityTest.php b/core/modules/views/tests/src/Kernel/Handler/AreaEntityTest.php index 46304a776b65..c83022efa25d 100644 --- a/core/modules/views/tests/src/Kernel/Handler/AreaEntityTest.php +++ b/core/modules/views/tests/src/Kernel/Handler/AreaEntityTest.php @@ -172,7 +172,7 @@ class AreaEntityTest extends ViewsKernelTestBase { $this->setRawContent($renderer->renderRoot($preview)); $view_class = 'js-view-dom-id-' . $view->dom_id; $result = $this->xpath('//div[@class = "' . $view_class . '"]/footer[1]'); - $this->assertStringNotContainsString($entities[2]->label(), $result[0], 'The rendered entity does not appear in the footer of the view.'); + $this->assertStringNotContainsString($entities[2]->label(), (string) $result[0], 'The rendered entity does not appear in the footer of the view.'); // Test the available view mode options. $form = []; diff --git a/core/modules/views/tests/src/Kernel/Handler/AreaTest.php b/core/modules/views/tests/src/Kernel/Handler/AreaTest.php index 8e0dab1404ea..4d0e4f94d441 100644 --- a/core/modules/views/tests/src/Kernel/Handler/AreaTest.php +++ b/core/modules/views/tests/src/Kernel/Handler/AreaTest.php @@ -75,7 +75,7 @@ class AreaTest extends ViewsKernelTestBase { // Check whether the strings exist in the output and are sanitized. $output = $view->preview(); - $output = $this->container->get('renderer')->renderRoot($output); + $output = (string) $this->container->get('renderer')->renderRoot($output); $this->assertStringContainsString(Xss::filterAdmin($header_string), $output, 'Views header exists in the output and is sanitized'); $this->assertStringContainsString(Xss::filterAdmin($footer_string), $output, 'Views footer exists in the output and is sanitized'); $this->assertStringContainsString(Xss::filterAdmin($empty_string), $output, 'Views empty exists in the output and is sanitized'); @@ -94,7 +94,7 @@ class AreaTest extends ViewsKernelTestBase { $this->assertCount(0, $handlers); $output = $view->preview(); - $output = \Drupal::service('renderer')->renderRoot($output); + $output = (string) \Drupal::service('renderer')->renderRoot($output); // The area output should not be present since access was denied. $this->assertStringNotContainsString('a custom string', $output); $view->destroy(); @@ -116,7 +116,7 @@ class AreaTest extends ViewsKernelTestBase { $handlers = $view->display_handler->getHandlers('empty'); $output = $view->preview(); - $output = \Drupal::service('renderer')->renderRoot($output); + $output = (string) \Drupal::service('renderer')->renderRoot($output); $this->assertStringContainsString('a custom string', $output); $this->assertCount(1, $handlers); } diff --git a/core/modules/views/tests/src/Kernel/Handler/AreaViewTest.php b/core/modules/views/tests/src/Kernel/Handler/AreaViewTest.php index 5f566e7fd6d9..f33371a51574 100644 --- a/core/modules/views/tests/src/Kernel/Handler/AreaViewTest.php +++ b/core/modules/views/tests/src/Kernel/Handler/AreaViewTest.php @@ -40,14 +40,14 @@ class AreaViewTest extends ViewsKernelTestBase { $this->executeView($view); $output = $view->render(); - $output = $renderer->renderRoot($output); + $output = (string) $renderer->renderRoot($output); $this->assertStringContainsString('js-view-dom-id-' . $view->dom_id, $output, 'The test view is correctly embedded.'); $view->destroy(); $view->setArguments([27]); $this->executeView($view); $output = $view->render(); - $output = $renderer->renderRoot($output); + $output = (string) $renderer->renderRoot($output); $this->assertStringNotContainsString('John', $output, 'The test view is correctly embedded with inherited arguments.'); $this->assertStringContainsString('George', $output, 'The test view is correctly embedded with inherited arguments.'); $view->destroy(); diff --git a/core/modules/views/tests/src/Kernel/Handler/FieldDateTest.php b/core/modules/views/tests/src/Kernel/Handler/FieldDateTest.php index f97a507ffbc0..69c237f26a37 100644 --- a/core/modules/views/tests/src/Kernel/Handler/FieldDateTest.php +++ b/core/modules/views/tests/src/Kernel/Handler/FieldDateTest.php @@ -163,7 +163,7 @@ class FieldDateTest extends ViewsKernelTestBase { else { $message = "$date_format format matches."; } - $actual_result = $view->field['created']->advancedRender($view->result[0]); + $actual_result = (string) $view->field['created']->advancedRender($view->result[0]); $this->assertEquals($expected_result, strip_tags($actual_result), $message); } } @@ -181,7 +181,7 @@ class FieldDateTest extends ViewsKernelTestBase { protected function assertRenderedFutureDatesEqual(ViewExecutable $view, array $map): void { foreach ($map as $format => $result) { $view->field['destroyed']->options['date_format'] = $format; - $view_result = $view->field['destroyed']->advancedRender($view->result[0]); + $view_result = (string) $view->field['destroyed']->advancedRender($view->result[0]); $this->assertEquals($result, strip_tags($view_result), "$format format matches."); } } diff --git a/core/modules/views/tests/src/Kernel/Handler/FieldFieldTest.php b/core/modules/views/tests/src/Kernel/Handler/FieldFieldTest.php index 458cab3e06f2..995b9af0b3d2 100644 --- a/core/modules/views/tests/src/Kernel/Handler/FieldFieldTest.php +++ b/core/modules/views/tests/src/Kernel/Handler/FieldFieldTest.php @@ -405,41 +405,41 @@ class FieldFieldTest extends ViewsKernelTestBase { $this->assertEquals("1, 3", $executable->getStyle()->getField(0, 'field_test_multiple')); $this->assertEquals("1", $executable->getStyle()->getField(0, 'field_test_multiple_1')); $this->assertEquals("3", $executable->getStyle()->getField(0, 'field_test_multiple_2')); - $this->assertEquals($date_formatter->format($this->testUsers[0]->getCreatedTime(), 'custom', 'Y'), trim(strip_tags($executable->getStyle()->getField(0, 'created')))); - $this->assertEquals($date_formatter->format($this->testUsers[0]->getCreatedTime(), 'custom', 'H:i:s'), trim(strip_tags($executable->getStyle()->getField(0, 'created_1')))); - $this->assertEquals($date_formatter->format($this->testUsers[0]->getCreatedTime(), 'fallback'), trim(strip_tags($executable->getStyle()->getField(0, 'created_2')))); + $this->assertEquals($date_formatter->format($this->testUsers[0]->getCreatedTime(), 'custom', 'Y'), trim(strip_tags((string) $executable->getStyle()->getField(0, 'created')))); + $this->assertEquals($date_formatter->format($this->testUsers[0]->getCreatedTime(), 'custom', 'H:i:s'), trim(strip_tags((string) $executable->getStyle()->getField(0, 'created_1')))); + $this->assertEquals($date_formatter->format($this->testUsers[0]->getCreatedTime(), 'fallback'), trim(strip_tags((string) $executable->getStyle()->getField(0, 'created_2')))); $this->assertEquals($this->testUsers[1]->getTimeZone(), $executable->getStyle()->getField(1, 'timezone')); $this->assertEquals("7, 0", $executable->getStyle()->getField(1, 'field_test_multiple')); $this->assertEquals("7", $executable->getStyle()->getField(1, 'field_test_multiple_1')); $this->assertEquals("0", $executable->getStyle()->getField(1, 'field_test_multiple_2')); - $this->assertEquals($date_formatter->format($this->testUsers[1]->getCreatedTime(), 'custom', 'Y'), trim(strip_tags($executable->getStyle()->getField(1, 'created')))); - $this->assertEquals($date_formatter->format($this->testUsers[1]->getCreatedTime(), 'custom', 'H:i:s'), trim(strip_tags($executable->getStyle()->getField(1, 'created_1')))); - $this->assertEquals($date_formatter->format($this->testUsers[1]->getCreatedTime(), 'fallback'), trim(strip_tags($executable->getStyle()->getField(1, 'created_2')))); + $this->assertEquals($date_formatter->format($this->testUsers[1]->getCreatedTime(), 'custom', 'Y'), trim(strip_tags((string) $executable->getStyle()->getField(1, 'created')))); + $this->assertEquals($date_formatter->format($this->testUsers[1]->getCreatedTime(), 'custom', 'H:i:s'), trim(strip_tags((string) $executable->getStyle()->getField(1, 'created_1')))); + $this->assertEquals($date_formatter->format($this->testUsers[1]->getCreatedTime(), 'fallback'), trim(strip_tags((string) $executable->getStyle()->getField(1, 'created_2')))); $this->assertEquals($this->testUsers[2]->getTimeZone(), $executable->getStyle()->getField(2, 'timezone')); $this->assertEquals("3, 5", $executable->getStyle()->getField(2, 'field_test_multiple')); $this->assertEquals("3", $executable->getStyle()->getField(2, 'field_test_multiple_1')); $this->assertEquals("5", $executable->getStyle()->getField(2, 'field_test_multiple_2')); - $this->assertEquals($date_formatter->format($this->testUsers[2]->getCreatedTime(), 'custom', 'Y'), trim(strip_tags($executable->getStyle()->getField(2, 'created')))); - $this->assertEquals($date_formatter->format($this->testUsers[2]->getCreatedTime(), 'custom', 'H:i:s'), trim(strip_tags($executable->getStyle()->getField(2, 'created_1')))); - $this->assertEquals($date_formatter->format($this->testUsers[2]->getCreatedTime(), 'fallback'), trim(strip_tags($executable->getStyle()->getField(2, 'created_2')))); + $this->assertEquals($date_formatter->format($this->testUsers[2]->getCreatedTime(), 'custom', 'Y'), trim(strip_tags((string) $executable->getStyle()->getField(2, 'created')))); + $this->assertEquals($date_formatter->format($this->testUsers[2]->getCreatedTime(), 'custom', 'H:i:s'), trim(strip_tags((string) $executable->getStyle()->getField(2, 'created_1')))); + $this->assertEquals($date_formatter->format($this->testUsers[2]->getCreatedTime(), 'fallback'), trim(strip_tags((string) $executable->getStyle()->getField(2, 'created_2')))); $this->assertEquals($this->testUsers[3]->getTimeZone(), $executable->getStyle()->getField(3, 'timezone')); $this->assertEquals("9, 9", $executable->getStyle()->getField(3, 'field_test_multiple')); $this->assertEquals("9", $executable->getStyle()->getField(3, 'field_test_multiple_1')); $this->assertEquals("9", $executable->getStyle()->getField(3, 'field_test_multiple_2')); - $this->assertEquals($date_formatter->format($this->testUsers[3]->getCreatedTime(), 'custom', 'Y'), trim(strip_tags($executable->getStyle()->getField(3, 'created')))); - $this->assertEquals($date_formatter->format($this->testUsers[3]->getCreatedTime(), 'custom', 'H:i:s'), trim(strip_tags($executable->getStyle()->getField(3, 'created_1')))); - $this->assertEquals($date_formatter->format($this->testUsers[3]->getCreatedTime(), 'fallback'), trim(strip_tags($executable->getStyle()->getField(3, 'created_2')))); + $this->assertEquals($date_formatter->format($this->testUsers[3]->getCreatedTime(), 'custom', 'Y'), trim(strip_tags((string) $executable->getStyle()->getField(3, 'created')))); + $this->assertEquals($date_formatter->format($this->testUsers[3]->getCreatedTime(), 'custom', 'H:i:s'), trim(strip_tags((string) $executable->getStyle()->getField(3, 'created_1')))); + $this->assertEquals($date_formatter->format($this->testUsers[3]->getCreatedTime(), 'fallback'), trim(strip_tags((string) $executable->getStyle()->getField(3, 'created_2')))); $this->assertEquals($this->testUsers[4]->getTimeZone(), $executable->getStyle()->getField(4, 'timezone')); $this->assertEquals("9, 0", $executable->getStyle()->getField(4, 'field_test_multiple')); $this->assertEquals("9", $executable->getStyle()->getField(4, 'field_test_multiple_1')); $this->assertEquals("0", $executable->getStyle()->getField(4, 'field_test_multiple_2')); - $this->assertEquals($date_formatter->format($this->testUsers[4]->getCreatedTime(), 'custom', 'Y'), trim(strip_tags($executable->getStyle()->getField(4, 'created')))); - $this->assertEquals($date_formatter->format($this->testUsers[4]->getCreatedTime(), 'custom', 'H:i:s'), trim(strip_tags($executable->getStyle()->getField(4, 'created_1')))); - $this->assertEquals($date_formatter->format($this->testUsers[4]->getCreatedTime(), 'fallback'), trim(strip_tags($executable->getStyle()->getField(4, 'created_2')))); + $this->assertEquals($date_formatter->format($this->testUsers[4]->getCreatedTime(), 'custom', 'Y'), trim(strip_tags((string) $executable->getStyle()->getField(4, 'created')))); + $this->assertEquals($date_formatter->format($this->testUsers[4]->getCreatedTime(), 'custom', 'H:i:s'), trim(strip_tags((string) $executable->getStyle()->getField(4, 'created_1')))); + $this->assertEquals($date_formatter->format($this->testUsers[4]->getCreatedTime(), 'fallback'), trim(strip_tags((string) $executable->getStyle()->getField(4, 'created_2')))); } /** diff --git a/core/modules/views/tests/src/Kernel/Handler/FieldKernelTest.php b/core/modules/views/tests/src/Kernel/Handler/FieldKernelTest.php index 7dda16f0aca2..45c98c3d8f67 100644 --- a/core/modules/views/tests/src/Kernel/Handler/FieldKernelTest.php +++ b/core/modules/views/tests/src/Kernel/Handler/FieldKernelTest.php @@ -57,7 +57,7 @@ class FieldKernelTest extends ViewsKernelTestBase { $random_text = $this->randomMachineName(); $view->field['job']->setTestValue($random_text); - $output = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) { + $output = (string) $renderer->executeInRenderContext(new RenderContext(), function () use ($view) { return $view->field['job']->theme($view->result[0]); }); $this->assertEquals($random_text, $output, 'Make sure the render method rendered the manual set value.'); @@ -145,13 +145,13 @@ class FieldKernelTest extends ViewsKernelTestBase { // Don't check the rewrite checkbox, so the text shouldn't appear. $id_field->options['alter']['text'] = $random_text = $this->randomMachineName(); - $output = $renderer->executeInRenderContext(new RenderContext(), function () use ($id_field, $row) { + $output = (string) $renderer->executeInRenderContext(new RenderContext(), function () use ($id_field, $row) { return $id_field->theme($row); }); $this->assertNotSubString($output, $random_text); $id_field->options['alter']['alter_text'] = TRUE; - $output = $renderer->executeInRenderContext(new RenderContext(), function () use ($id_field, $row) { + $output = (string) $renderer->executeInRenderContext(new RenderContext(), function () use ($id_field, $row) { return $id_field->theme($row); }); $this->assertSubString($output, $random_text); @@ -172,7 +172,7 @@ class FieldKernelTest extends ViewsKernelTestBase { $id_field->options['alter']['text'] = '

{{ id }}

'; $id_field->options['alter']['alter_text'] = TRUE; - $output = $renderer->executeInRenderContext(new RenderContext(), function () use ($id_field, $row) { + $output = (string) $renderer->executeInRenderContext(new RenderContext(), function () use ($id_field, $row) { return $id_field->theme($row); }); $this->assertSubString($output, '

1

'); @@ -180,7 +180,7 @@ class FieldKernelTest extends ViewsKernelTestBase { // Add a non-safe HTML tag and make sure this gets removed. $id_field->options['alter']['text'] = '

{{ id }}

'; $id_field->options['alter']['alter_text'] = TRUE; - $output = $renderer->executeInRenderContext(new RenderContext(), function () use ($id_field, $row) { + $output = (string) $renderer->executeInRenderContext(new RenderContext(), function () use ($id_field, $row) { return $id_field->theme($row); }); $this->assertSubString($output, '

1 alert("Script removed")

'); @@ -204,7 +204,7 @@ class FieldKernelTest extends ViewsKernelTestBase { $id_field->options['alter']['text'] = '

{{ id }}

'; $id_field->options['alter']['alter_text'] = TRUE; - $output = $renderer->executeInRenderContext(new RenderContext(), function () use ($id_field, $row) { + $output = (string) $renderer->executeInRenderContext(new RenderContext(), function () use ($id_field, $row) { return $id_field->theme($row); }); $this->assertSubString($output, '

1

'); @@ -212,7 +212,7 @@ class FieldKernelTest extends ViewsKernelTestBase { // Add a non-safe HTML tag and make sure this gets removed. $id_field->options['alter']['text'] = '

{{ id }}

'; $id_field->options['alter']['alter_text'] = TRUE; - $output = $renderer->executeInRenderContext(new RenderContext(), function () use ($id_field, $row) { + $output = (string) $renderer->executeInRenderContext(new RenderContext(), function () use ($id_field, $row) { return $id_field->theme($row); }); $this->assertSubString($output, '

1 alert("Script removed")

'); @@ -235,7 +235,7 @@ class FieldKernelTest extends ViewsKernelTestBase { $name_field_0->options['alter']['text'] = '%1 !1'; $row = $view->result[0]; - $output = $renderer->executeInRenderContext(new RenderContext(), function () use ($name_field_0, $row) { + $output = (string) $renderer->executeInRenderContext(new RenderContext(), function () use ($name_field_0, $row) { return $name_field_0->advancedRender($row); }); @@ -248,7 +248,7 @@ class FieldKernelTest extends ViewsKernelTestBase { $name_field_0->options['alter']['text'] = '{{ arguments.null }} {{ raw_arguments.null }}'; $row = $view->result[0]; - $output = $renderer->executeInRenderContext(new RenderContext(), function () use ($name_field_0, $row) { + $output = (string) $renderer->executeInRenderContext(new RenderContext(), function () use ($name_field_0, $row) { return $name_field_0->advancedRender($row); }); @@ -284,17 +284,17 @@ class FieldKernelTest extends ViewsKernelTestBase { $expected_output_1 = "$row->views_test_data_name $row->views_test_data_name"; $expected_output_2 = "$row->views_test_data_name $row->views_test_data_name $row->views_test_data_name"; - $output = $renderer->executeInRenderContext(new RenderContext(), function () use ($name_field_0, $row) { + $output = (string) $renderer->executeInRenderContext(new RenderContext(), function () use ($name_field_0, $row) { return $name_field_0->advancedRender($row); }); $this->assertEquals($expected_output_0, $output, new FormattableMarkup('Test token replacement: "@token" gave "@output"', ['@token' => $name_field_0->options['alter']['text'], '@output' => $output])); - $output = $renderer->executeInRenderContext(new RenderContext(), function () use ($name_field_1, $row) { + $output = (string) $renderer->executeInRenderContext(new RenderContext(), function () use ($name_field_1, $row) { return $name_field_1->advancedRender($row); }); $this->assertEquals($expected_output_1, $output, new FormattableMarkup('Test token replacement: "@token" gave "@output"', ['@token' => $name_field_1->options['alter']['text'], '@output' => $output])); - $output = $renderer->executeInRenderContext(new RenderContext(), function () use ($name_field_2, $row) { + $output = (string) $renderer->executeInRenderContext(new RenderContext(), function () use ($name_field_2, $row) { return $name_field_2->advancedRender($row); }); $this->assertEquals($expected_output_2, $output, new FormattableMarkup('Test token replacement: "@token" gave "@output"', ['@token' => $name_field_2->options['alter']['text'], '@output' => $output])); @@ -306,7 +306,7 @@ class FieldKernelTest extends ViewsKernelTestBase { $random_text = $this->randomMachineName(); $job_field->setTestValue($random_text); - $output = $renderer->executeInRenderContext(new RenderContext(), function () use ($job_field, $row) { + $output = (string) $renderer->executeInRenderContext(new RenderContext(), function () use ($job_field, $row) { return $job_field->advancedRender($row); }); $this->assertSubString($output, $random_text, new FormattableMarkup('Make sure the self token (@token => @value) appears in the output (@output)', [ @@ -320,7 +320,7 @@ class FieldKernelTest extends ViewsKernelTestBase { $job_field->options['alter']['text'] = $old_token; $random_text = $this->randomMachineName(); $job_field->setTestValue($random_text); - $output = $renderer->executeInRenderContext(new RenderContext(), function () use ($job_field, $row) { + $output = (string) $renderer->executeInRenderContext(new RenderContext(), function () use ($job_field, $row) { return $job_field->advancedRender($row); }); $this->assertEquals($old_token, $output, new FormattableMarkup('Make sure the old token style (@token => @value) is not changed in the output (@output)', ['@value' => $random_text, '@output' => $output, '@token' => $job_field->options['alter']['text']])); @@ -330,7 +330,7 @@ class FieldKernelTest extends ViewsKernelTestBase { $job_field->options['alter']['text'] = '

{{ job }}

'; $random_text = $this->randomMachineName(); $job_field->setTestValue('' . $random_text . ''); - $output = $renderer->executeInRenderContext(new RenderContext(), function () use ($job_field, $row) { + $output = (string) $renderer->executeInRenderContext(new RenderContext(), function () use ($job_field, $row) { return $job_field->advancedRender($row); }); $this->assertSame('

<span>' . $random_text . '</span>

', (string) $output, 'Valid tags are allowed in rewrite templates and token replacements.'); @@ -340,7 +340,7 @@ class FieldKernelTest extends ViewsKernelTestBase { $job_field->options['alter']['text'] = $rewrite_template; $random_text = $this->randomMachineName(); $job_field->setTestValue($random_text); - $output = $renderer->executeInRenderContext(new RenderContext(), function () use ($job_field, $row) { + $output = (string) $renderer->executeInRenderContext(new RenderContext(), function () use ($job_field, $row) { return $job_field->advancedRender($row); }); $this->assertNotSubString($output, '', $rendered_js, 'Rendering an external JavaScript file.'); @@ -133,8 +133,8 @@ class AttachedAssetsTest extends KernelTestBase { $css_render_array = \Drupal::service('asset.css.collection_renderer')->render($css); $js_render_array = \Drupal::service('asset.js.collection_renderer')->render($js); - $rendered_css = $this->renderer->renderPlain($css_render_array); - $rendered_js = $this->renderer->renderPlain($js_render_array); + $rendered_css = (string) $this->renderer->renderPlain($css_render_array); + $rendered_js = (string) $this->renderer->renderPlain($js_render_array); $this->assertStringContainsString('', $rendered_css, 'Rendering an external CSS file.'); $this->assertStringContainsString('', $rendered_js, 'Rendering an external JavaScript file.'); } @@ -148,7 +148,7 @@ class AttachedAssetsTest extends KernelTestBase { $js = $this->assetResolver->getJsAssets($assets, FALSE, \Drupal::languageManager()->getCurrentLanguage())[1]; $js_render_array = \Drupal::service('asset.js.collection_renderer')->render($js); - $rendered_js = $this->renderer->renderPlain($js_render_array); + $rendered_js = (string) $this->renderer->renderPlain($js_render_array); $expected_1 = ''; $expected_2 = ''; $this->assertStringContainsString($expected_1, $rendered_js, 'Rendered external JavaScript with correct defer and random attributes.'); @@ -164,7 +164,7 @@ class AttachedAssetsTest extends KernelTestBase { $js = $this->assetResolver->getJsAssets($assets, TRUE, \Drupal::languageManager()->getCurrentLanguage())[1]; $js_render_array = \Drupal::service('asset.js.collection_renderer')->render($js); - $rendered_js = $this->renderer->renderPlain($js_render_array); + $rendered_js = (string) $this->renderer->renderPlain($js_render_array); $expected_1 = ''; $expected_2 = ''; $this->assertStringContainsString($expected_1, $rendered_js, 'Rendered external JavaScript with correct defer and random attributes.'); @@ -238,7 +238,7 @@ class AttachedAssetsTest extends KernelTestBase { $js = $this->assetResolver->getJsAssets($assets, FALSE, \Drupal::languageManager()->getCurrentLanguage())[0]; $js_render_array = \Drupal::service('asset.js.collection_renderer')->render($js); - $rendered_js = $this->renderer->renderPlain($js_render_array); + $rendered_js = (string) $this->renderer->renderPlain($js_render_array); $query_string = $this->container->get('asset.query_string')->get(); $this->assertStringContainsString('', $rendered_js, 'The JS asset in common_test/js-header appears in the header.'); $this->assertStringContainsString('', $rendered_js, 'JavaScript file with query string gets version query string correctly appended.'); diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityAccessControlHandlerTest.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityAccessControlHandlerTest.php index ccbc1ef101bf..3a34d85990d1 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/EntityAccessControlHandlerTest.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityAccessControlHandlerTest.php @@ -48,7 +48,7 @@ class EntityAccessControlHandlerTest extends EntityLanguageTestBase { '@op' => $op, ]); - $this->assertEquals($object->access($op, $account), $result, $message); + $this->assertEquals($object->access($op, $account), $result, (string) $message); } } diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityDecoupledTranslationRevisionsTest.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityDecoupledTranslationRevisionsTest.php index 5541ec27c411..bcd9955e6cae 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/EntityDecoupledTranslationRevisionsTest.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityDecoupledTranslationRevisionsTest.php @@ -294,7 +294,7 @@ class EntityDecoupledTranslationRevisionsTest extends EntityKernelTestBase { $this->stepIndex = $index; $revision_id = call_user_func_array([$this, 'doEditStep'], $step); } - return $revision_id; + return (int) $revision_id; } /** diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityDefinitionUpdateTest.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityDefinitionUpdateTest.php index a293e1a2399b..48b33b75512e 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/EntityDefinitionUpdateTest.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityDefinitionUpdateTest.php @@ -278,7 +278,7 @@ class EntityDefinitionUpdateTest extends EntityKernelTestBase { $this->assertTrue($this->entityDefinitionUpdateManager->needsUpdates(), 'EntityDefinitionUpdateManager reports that updates are needed.'); $changes = $this->entityDefinitionUpdateManager->getChangeSummary(); $this->assertCount(1, $changes['entity_test_update']); - $this->assertEquals('The A new base field field needs to be installed.', strip_tags($changes['entity_test_update'][0])); + $this->assertEquals('The A new base field field needs to be installed.', strip_tags((string) $changes['entity_test_update'][0])); $this->applyEntityUpdates(); $this->assertTrue($this->database->schema()->fieldExists('entity_test_update', 'new_base_field'), 'Column created in shared table for new_base_field.'); @@ -288,7 +288,7 @@ class EntityDefinitionUpdateTest extends EntityKernelTestBase { $this->assertTrue($this->entityDefinitionUpdateManager->needsUpdates(), 'EntityDefinitionUpdateManager reports that updates are needed.'); $changes = $this->entityDefinitionUpdateManager->getChangeSummary(); $this->assertCount(1, $changes['entity_test_update']); - $this->assertEquals('The A new base field field needs to be updated.', strip_tags($changes['entity_test_update'][0])); + $this->assertEquals('The A new base field field needs to be updated.', strip_tags((string) $changes['entity_test_update'][0])); $this->applyEntityUpdates(); $this->assertTrue($this->database->schema()->indexExists('entity_test_update', 'entity_test_update_field__new_base_field'), 'Index created.'); @@ -298,7 +298,7 @@ class EntityDefinitionUpdateTest extends EntityKernelTestBase { $this->assertTrue($this->entityDefinitionUpdateManager->needsUpdates(), 'EntityDefinitionUpdateManager reports that updates are needed.'); $changes = $this->entityDefinitionUpdateManager->getChangeSummary(); $this->assertCount(1, $changes['entity_test_update']); - $this->assertEquals('The A new base field field needs to be updated.', strip_tags($changes['entity_test_update'][0])); + $this->assertEquals('The A new base field field needs to be updated.', strip_tags((string) $changes['entity_test_update'][0])); $this->applyEntityUpdates(); $this->assertFalse($this->database->schema()->indexExists('entity_test_update', 'entity_test_update_field__new_base_field'), 'Index deleted.'); @@ -309,7 +309,7 @@ class EntityDefinitionUpdateTest extends EntityKernelTestBase { $this->assertTrue($this->entityDefinitionUpdateManager->needsUpdates(), 'EntityDefinitionUpdateManager reports that updates are needed.'); $changes = $this->entityDefinitionUpdateManager->getChangeSummary(); $this->assertCount(1, $changes['entity_test_update']); - $this->assertEquals('The A new base field field needs to be updated.', strip_tags($changes['entity_test_update'][0])); + $this->assertEquals('The A new base field field needs to be updated.', strip_tags((string) $changes['entity_test_update'][0])); $this->applyEntityUpdates(); $this->assertFalse($this->database->schema()->fieldExists('entity_test_update', 'new_base_field'), 'Original column deleted in shared table for new_base_field.'); $this->assertTrue($this->database->schema()->fieldExists('entity_test_update', 'new_base_field__value'), 'Value column created in shared table for new_base_field.'); @@ -321,7 +321,7 @@ class EntityDefinitionUpdateTest extends EntityKernelTestBase { $this->assertTrue($this->entityDefinitionUpdateManager->needsUpdates(), 'EntityDefinitionUpdateManager reports that updates are needed.'); $changes = $this->entityDefinitionUpdateManager->getChangeSummary(); $this->assertCount(1, $changes['entity_test_update']); - $this->assertEquals('The A new base field field needs to be uninstalled.', strip_tags($changes['entity_test_update'][0])); + $this->assertEquals('The A new base field field needs to be uninstalled.', strip_tags((string) $changes['entity_test_update'][0])); $this->applyEntityUpdates(); $this->assertFalse($this->database->schema()->fieldExists('entity_test_update', 'new_base_field_value'), 'Value column deleted from shared table for new_base_field.'); $this->assertFalse($this->database->schema()->fieldExists('entity_test_update', 'new_base_field_format'), 'Format column deleted from shared table for new_base_field.'); @@ -338,7 +338,7 @@ class EntityDefinitionUpdateTest extends EntityKernelTestBase { $this->addBaseField('string', 'entity_test_update', FALSE, FALSE); $changes = $this->entityDefinitionUpdateManager->getChangeSummary(); $this->assertCount(1, $changes['entity_test_update']); - $this->assertEquals('The new_base_field field needs to be installed.', strip_tags($changes['entity_test_update'][0])); + $this->assertEquals('The new_base_field field needs to be installed.', strip_tags((string) $changes['entity_test_update'][0])); $this->applyEntityUpdates(); // Add an index on the base field, ensure the update manager reports it with @@ -346,7 +346,7 @@ class EntityDefinitionUpdateTest extends EntityKernelTestBase { $this->addBaseFieldIndex(); $changes = $this->entityDefinitionUpdateManager->getChangeSummary(); $this->assertCount(1, $changes['entity_test_update']); - $this->assertEquals('The new_base_field field needs to be updated.', strip_tags($changes['entity_test_update'][0])); + $this->assertEquals('The new_base_field field needs to be updated.', strip_tags((string) $changes['entity_test_update'][0])); $this->applyEntityUpdates(); // Remove the base field, ensure the update manager reports it with the @@ -354,7 +354,7 @@ class EntityDefinitionUpdateTest extends EntityKernelTestBase { $this->removeBaseField(); $changes = $this->entityDefinitionUpdateManager->getChangeSummary(); $this->assertCount(1, $changes['entity_test_update']); - $this->assertEquals('The new_base_field field needs to be uninstalled.', strip_tags($changes['entity_test_update'][0])); + $this->assertEquals('The new_base_field field needs to be uninstalled.', strip_tags((string) $changes['entity_test_update'][0])); } /** @@ -367,7 +367,7 @@ class EntityDefinitionUpdateTest extends EntityKernelTestBase { $this->assertTrue($this->entityDefinitionUpdateManager->needsUpdates(), 'EntityDefinitionUpdateManager reports that updates are needed.'); $changes = $this->entityDefinitionUpdateManager->getChangeSummary(); $this->assertCount(1, $changes['entity_test_update']); - $this->assertEquals('The A new bundle field field needs to be installed.', strip_tags($changes['entity_test_update'][0])); + $this->assertEquals('The A new bundle field field needs to be installed.', strip_tags((string) $changes['entity_test_update'][0])); $this->applyEntityUpdates(); $this->assertTrue($this->database->schema()->tableExists('entity_test_update__new_bundle_field'), 'Dedicated table created for new_bundle_field.'); @@ -378,7 +378,7 @@ class EntityDefinitionUpdateTest extends EntityKernelTestBase { $this->assertTrue($this->entityDefinitionUpdateManager->needsUpdates(), 'EntityDefinitionUpdateManager reports that updates are needed.'); $changes = $this->entityDefinitionUpdateManager->getChangeSummary(); $this->assertCount(1, $changes['entity_test_update']); - $this->assertEquals('The A new bundle field field needs to be updated.', strip_tags($changes['entity_test_update'][0])); + $this->assertEquals('The A new bundle field field needs to be updated.', strip_tags((string) $changes['entity_test_update'][0])); $this->applyEntityUpdates(); $this->assertTrue($this->database->schema()->fieldExists('entity_test_update__new_bundle_field', 'new_bundle_field_format'), 'Format column created in dedicated table for new_base_field.'); @@ -388,7 +388,7 @@ class EntityDefinitionUpdateTest extends EntityKernelTestBase { $this->assertTrue($this->entityDefinitionUpdateManager->needsUpdates(), 'EntityDefinitionUpdateManager reports that updates are needed.'); $changes = $this->entityDefinitionUpdateManager->getChangeSummary(); $this->assertCount(1, $changes['entity_test_update']); - $this->assertEquals('The A new bundle field field needs to be uninstalled.', strip_tags($changes['entity_test_update'][0])); + $this->assertEquals('The A new bundle field field needs to be uninstalled.', strip_tags((string) $changes['entity_test_update'][0])); $this->applyEntityUpdates(); $this->assertFalse($this->database->schema()->tableExists('entity_test_update__new_bundle_field'), 'Dedicated table deleted for new_bundle_field.'); } diff --git a/core/tests/Drupal/KernelTests/Core/Entity/RevisionableContentEntityBaseTest.php b/core/tests/Drupal/KernelTests/Core/Entity/RevisionableContentEntityBaseTest.php index b0ce3373d0b0..dee4b5cbc3ec 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/RevisionableContentEntityBaseTest.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/RevisionableContentEntityBaseTest.php @@ -53,7 +53,7 @@ class RevisionableContentEntityBaseTest extends EntityKernelTestBase { // Create the second revision. $entity->setNewRevision(TRUE); - $random_timestamp = rand(1e8, 2e8); + $random_timestamp = rand(100_000_000, 200_000_000); $this->createRevision($entity, $user, $random_timestamp, 'This is my log message'); $revision_id = $entity->getRevisionId(); @@ -68,14 +68,14 @@ class RevisionableContentEntityBaseTest extends EntityKernelTestBase { $this->assertEquals('This is my log message', $entity->getRevisionLogMessage()); // Create the third revision. - $random_timestamp = rand(1e8, 2e8); + $random_timestamp = rand(100_000_000, 200_000_000); $this->createRevision($entity, $user, $random_timestamp, 'This is my log message'); $this->assertItemsTableCount(3, $definition); $revision_ids[] = $entity->getRevisionId(); // Create another 3 revisions. foreach (range(1, 3) as $count) { - $timestamp = rand(1e8, 2e8); + $timestamp = rand(100_000_000, 200_000_000); $this->createRevision($entity, $user, $timestamp, 'This is my log message number: ' . $count); $revision_ids[] = $entity->getRevisionId(); } diff --git a/core/tests/Drupal/KernelTests/Core/File/StreamWrapperTest.php b/core/tests/Drupal/KernelTests/Core/File/StreamWrapperTest.php index 5a3a59290bb9..d0a88403a6f2 100644 --- a/core/tests/Drupal/KernelTests/Core/File/StreamWrapperTest.php +++ b/core/tests/Drupal/KernelTests/Core/File/StreamWrapperTest.php @@ -120,8 +120,8 @@ class StreamWrapperTest extends FileTestBase { $this->assertNotFalse($handle, 'Able to open a file for appending, reading and writing.'); // Attempt to change options on the file stream: should all fail. - $this->assertFalse(@stream_set_blocking($handle, 0), 'Unable to set to non blocking using a local stream wrapper.'); - $this->assertFalse(@stream_set_blocking($handle, 1), 'Unable to set to blocking using a local stream wrapper.'); + $this->assertFalse(@stream_set_blocking($handle, FALSE), 'Unable to set to non blocking using a local stream wrapper.'); + $this->assertFalse(@stream_set_blocking($handle, TRUE), 'Unable to set to blocking using a local stream wrapper.'); $this->assertFalse(@stream_set_timeout($handle, 1), 'Unable to set read time out using a local stream wrapper.'); $this->assertEquals(-1 /*EOF*/, @stream_set_write_buffer($handle, 512), 'Unable to set write buffer using a local stream wrapper.'); diff --git a/core/tests/Drupal/KernelTests/Core/Menu/MenuTreeStorageTest.php b/core/tests/Drupal/KernelTests/Core/Menu/MenuTreeStorageTest.php index 0704cec75d24..b06eacfe638f 100644 --- a/core/tests/Drupal/KernelTests/Core/Menu/MenuTreeStorageTest.php +++ b/core/tests/Drupal/KernelTests/Core/Menu/MenuTreeStorageTest.php @@ -435,7 +435,7 @@ class MenuTreeStorageTest extends KernelTestBase { $found_parents = $query->execute()->fetchAllKeyed(0, 1); $this->assertSameSize($parents, $found_parents, 'Found expected number of parents'); - $this->assertCount($raw['depth'], $found_parents, 'Number of parents is the same as the depth'); + $this->assertCount((int) $raw['depth'], $found_parents, 'Number of parents is the same as the depth'); $materialized_path = $this->treeStorage->getRootPathIds($id); $this->assertEquals(array_values($parents), array_values($materialized_path), 'Parents match the materialized path'); diff --git a/core/tests/Drupal/KernelTests/Core/Render/Element/RenderElementTypesTest.php b/core/tests/Drupal/KernelTests/Core/Render/Element/RenderElementTypesTest.php index d2f36d7b733d..6eb81c3a7f9b 100644 --- a/core/tests/Drupal/KernelTests/Core/Render/Element/RenderElementTypesTest.php +++ b/core/tests/Drupal/KernelTests/Core/Render/Element/RenderElementTypesTest.php @@ -185,7 +185,7 @@ class RenderElementTypesTest extends KernelTestBase { ]; foreach ($elements as $element) { - $xml = new \SimpleXMLElement(\Drupal::service('renderer')->renderRoot($element['value'])); + $xml = new \SimpleXMLElement((string) \Drupal::service('renderer')->renderRoot($element['value'])); $result = $xml->xpath($element['expected']); $this->assertNotEmpty($result, '"' . $element['name'] . '" input rendered correctly.'); } @@ -216,7 +216,7 @@ class RenderElementTypesTest extends KernelTestBase { ]; foreach ($elements as $element) { - $xml = new \SimpleXMLElement(\Drupal::service('renderer')->renderRoot($element['value'])); + $xml = new \SimpleXMLElement((string) \Drupal::service('renderer')->renderRoot($element['value'])); $result = $xml->xpath($element['expected']); $this->assertNotEmpty($result, '"' . $element['name'] . '" is rendered correctly.'); } @@ -232,7 +232,7 @@ class RenderElementTypesTest extends KernelTestBase { 'expected' => '//div[@class="compact-link"]/a[contains(@href, "admin/compact?") and text()="Show descriptions"]', ]; - $xml = new \SimpleXMLElement(\Drupal::service('renderer')->renderRoot($element['value'])); + $xml = new \SimpleXMLElement((string) \Drupal::service('renderer')->renderRoot($element['value'])); $result = $xml->xpath($element['expected']); $this->assertNotEmpty($result, '"' . $element['name'] . '" is rendered correctly.'); }