Issue #3402713 by mstrelan, smustgrave, dww: Fix strict type errors: miscellaneous fixes in core Kernel tests

(cherry picked from commit f60bcea7d7)
merge-requests/7420/head
Alex Pott 2024-04-09 23:19:05 +01:00
parent c3630f3e45
commit cb25ccbb4a
No known key found for this signature in database
GPG Key ID: BDA67E7EE836E5CE
7 changed files with 11 additions and 8 deletions

View File

@ -96,7 +96,7 @@ class LinkItemSerializationTest extends FieldKernelTestBase {
->set('query', $parsed_url['query']);
$json = json_decode($this->serializer->serialize($entity, 'json'), TRUE);
$json['field_test'][0]['options'] = 'string data';
$serialized = json_encode($json, TRUE);
$serialized = json_encode($json);
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('The generic FieldItemNormalizer cannot denormalize string values for "options" properties of the "field_test" field (field item class: Drupal\link\Plugin\Field\FieldType\LinkItem).');
$this->serializer->deserialize($serialized, EntityTest::class, 'json');

View File

@ -23,7 +23,7 @@ class TemporaryQueryTest extends TemporaryQueryTestBase {
// Assert that the table is indeed a temporary one.
$temporary_table_info = $connection->query("SHOW CREATE TABLE {" . $table_name_test . "}")->fetchAssoc();
$this->stringContains($temporary_table_info["Create Table"], "CREATE TEMPORARY TABLE");
$this->assertStringContainsString('CREATE TEMPORARY TABLE', $temporary_table_info['Create Table']);
// Assert that both have the same field names.
$normal_table_fields = $connection->query("SELECT * FROM {test}")->fetch();

View File

@ -86,7 +86,7 @@ class PathPluginTest extends ViewsKernelTestBase {
// Test with view_mode full.
$output = $view->preview();
$output = $renderer->renderRoot($output);
$output = (string) $renderer->renderRoot($output);
foreach ($this->nodes as $node) {
$this->assertStringContainsString('This is <strong>not escaped</strong> and this is ' . $node->toLink('the link')->toString(), $output, 'Make sure path field rewriting is not escaped.');
}

View File

@ -98,7 +98,7 @@ class RowPluginTest extends ViewsKernelTestBase {
// Test with view_mode full.
$output = $view->preview();
$output = $renderer->renderRoot($output);
$output = (string) $renderer->renderRoot($output);
foreach ($this->nodes as $node) {
$this->assertStringNotContainsString($node->body->summary, $output, 'Make sure the teaser appears in the output of the view.');
$this->assertStringContainsString($node->body->value, $output, 'Make sure the full text appears in the output of the view.');
@ -107,7 +107,7 @@ class RowPluginTest extends ViewsKernelTestBase {
// Test with teasers.
$view->rowPlugin->options['view_mode'] = 'teaser';
$output = $view->preview();
$output = $renderer->renderRoot($output);
$output = (string) $renderer->renderRoot($output);
foreach ($this->nodes as $node) {
$this->assertStringContainsString($node->body->summary, $output, 'Make sure the teaser appears in the output of the view.');
$this->assertStringNotContainsString($node->body->value, $output);

View File

@ -115,7 +115,8 @@ class WhoIsOnlineBlockTest extends KernelTestBase {
$this->assertText($user2->getAccountName(), 'Active user 2 found in online list.');
$this->assertNoText($user3->getAccountName(), 'Inactive user not found in online list.');
// Verify that online users are ordered correctly.
$this->assertGreaterThan(strpos($this->getRawContent(), $user2->getAccountName()), strpos($this->getRawContent(), $user1->getAccountName()));
$raw_content = (string) $this->getRawContent();
$this->assertGreaterThan(strpos($raw_content, $user2->getAccountName()), strpos($raw_content, $user1->getAccountName()));
}
}

View File

@ -62,8 +62,10 @@ class PathValidatorTest extends KernelTestBase {
}
$this->container->set('router.request_context', new RequestContext());
}
else {
$requestContext->setMethod($method);
}
$requestContext->setMethod($method);
/** @var \Drupal\Core\Url $url */
$url = $pathValidator->getUrlIfValidWithoutAccessCheck($entity->toUrl()->toString(TRUE)->getGeneratedUrl());
$this->assertEquals($method, $requestContext->getMethod());

View File

@ -64,7 +64,7 @@ class ClaroTableTest extends KernelTestBase {
],
];
$renderedTable = \Drupal::service('renderer')->renderRoot($table);
$renderedTable = (string) \Drupal::service('renderer')->renderRoot($table);
// Confirm that table is rendered.
$this->assertStringContainsString('class="class"', $renderedTable);