Issue #3402295 by mstrelan, dww, smustgrave: Fix strict type errors in kernel tests: Add casts and fix types where needed

(cherry picked from commit 5b8514adec)
merge-requests/6064/head
Lee Rowlands 2024-01-08 07:55:19 +10:00
parent a5369ac460
commit ee348449d0
No known key found for this signature in database
GPG Key ID: 2B829A3DF9204DC4
43 changed files with 166 additions and 166 deletions

View File

@ -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);
}

View File

@ -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);

View File

@ -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"

View File

@ -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;

View File

@ -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);

View File

@ -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()));
}
}
}

View File

@ -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'));

View File

@ -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();

View File

@ -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)));
}
}

View File

@ -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);
}
/**

View File

@ -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);
}

View File

@ -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']);
}
/**

View File

@ -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);

View File

@ -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);

View File

@ -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 &lt;&gt;&amp;&quot;&#039;', trim(strip_tags($text)), 'feed_icon template escapes reserved HTML characters.');
}

View File

@ -31,12 +31,12 @@ class UrlTest extends KernelTestBase {
$path = "<SCRIPT>alert('XSS')</SCRIPT>";
$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");
}

View File

@ -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);
}
}

View File

@ -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.');
}

View File

@ -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,

View File

@ -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');

View File

@ -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;

View File

@ -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 = [];

View File

@ -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);
}

View File

@ -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();

View File

@ -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.");
}
}

View File

@ -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'))));
}
/**

View File

@ -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'] = '<p>{{ id }}</p>';
$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, '<p>1</p>');
@ -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'] = '<p>{{ id }} <script>alert("Script removed")</script></p>';
$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, '<p>1 alert("Script removed")</p>');
@ -204,7 +204,7 @@ class FieldKernelTest extends ViewsKernelTestBase {
$id_field->options['alter']['text'] = '<p>{{ id }}</p>';
$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, '<p>1</p>');
@ -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'] = '<p>{{ id }} <script>alert("Script removed")</script></p>';
$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, '<p>1 alert("Script removed")</p>');
@ -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'] = '<h1>{{ job }}</h1>';
$random_text = $this->randomMachineName();
$job_field->setTestValue('<span>' . $random_text . '</span>');
$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('<h1>&lt;span&gt;' . $random_text . '&lt;/span&gt;</h1>', (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, '<script>', 'Ensure a script tag in the rewrite template is removed.');
@ -349,7 +349,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->assertEquals($random_text, $output, new FormattableMarkup('Make sure a script tag in the template (@template) is removed, leaving only the replaced token in the output (@output)', ['@output' => $output, '@template' => $rewrite_template]));
@ -367,7 +367,7 @@ class FieldKernelTest extends ViewsKernelTestBase {
$view->field['name']->options['exclude'] = TRUE;
$output = $view->preview();
$output = $renderer->renderRoot($output);
$output = (string) $renderer->renderRoot($output);
foreach ($this->dataSet() as $entry) {
$this->assertNotSubString($output, $entry['name']);
}
@ -376,7 +376,7 @@ class FieldKernelTest extends ViewsKernelTestBase {
$view->field['name']->options['exclude'] = FALSE;
$output = $view->preview();
$output = $renderer->renderRoot($output);
$output = (string) $renderer->renderRoot($output);
foreach ($this->dataSet() as $entry) {
$this->assertSubString($output, $entry['name']);
}
@ -416,28 +416,28 @@ class FieldKernelTest extends ViewsKernelTestBase {
// Test a valid string.
$view->result[0]->{$column_map_reversed['name']} = $random_name;
$render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
$render = (string) $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
return $view->field['name']->advancedRender($view->result[0]);
});
$this->assertSame($random_name, (string) $render, 'By default, a string should not be treated as empty.');
// Test an empty string.
$view->result[0]->{$column_map_reversed['name']} = "";
$render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
$render = (string) $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
return $view->field['name']->advancedRender($view->result[0]);
});
$this->assertSame("", $render, 'By default, "" should not be treated as empty.');
// Test zero as an integer.
$view->result[0]->{$column_map_reversed['name']} = 0;
$render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
$render = (string) $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
return $view->field['name']->advancedRender($view->result[0]);
});
$this->assertSame('0', (string) $render, 'By default, 0 should not be treated as empty.');
// Test zero as a string.
$view->result[0]->{$column_map_reversed['name']} = "0";
$render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
$render = (string) $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
return $view->field['name']->advancedRender($view->result[0]);
});
$this->assertSame("0", (string) $render, 'By default, "0" should not be treated as empty.');
@ -449,28 +449,28 @@ class FieldKernelTest extends ViewsKernelTestBase {
// Test a valid string.
$view->result[0]->{$column_map_reversed['name']} = $random_name;
$render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
$render = (string) $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
return $view->field['name']->advancedRender($view->result[0]);
});
$this->assertSame($random_name, (string) $render, 'If hide_empty is checked, a string should not be treated as empty.');
// Test an empty string.
$view->result[0]->{$column_map_reversed['name']} = "";
$render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
$render = (string) $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
return $view->field['name']->advancedRender($view->result[0]);
});
$this->assertSame("", $render, 'If hide_empty is checked, "" should be treated as empty.');
// Test zero as an integer.
$view->result[0]->{$column_map_reversed['name']} = 0;
$render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
$render = (string) $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
return $view->field['name']->advancedRender($view->result[0]);
});
$this->assertSame('0', (string) $render, 'If hide_empty is checked, but not empty_zero, 0 should not be treated as empty.');
// Test zero as a string.
$view->result[0]->{$column_map_reversed['name']} = "0";
$render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
$render = (string) $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
return $view->field['name']->advancedRender($view->result[0]);
});
$this->assertSame("0", (string) $render, 'If hide_empty is checked, but not empty_zero, "0" should not be treated as empty.');
@ -482,14 +482,14 @@ class FieldKernelTest extends ViewsKernelTestBase {
// Test zero as an integer.
$view->result[0]->{$column_map_reversed['name']} = 0;
$render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
$render = (string) $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
return $view->field['name']->advancedRender($view->result[0]);
});
$this->assertSame("", $render, 'If hide_empty and empty_zero are checked, 0 should be treated as empty.');
// Test zero as a string.
$view->result[0]->{$column_map_reversed['name']} = "0";
$render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
$render = (string) $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
return $view->field['name']->advancedRender($view->result[0]);
});
$this->assertSame("", $render, 'If hide_empty and empty_zero are checked, "0" should be treated as empty.');
@ -504,28 +504,28 @@ class FieldKernelTest extends ViewsKernelTestBase {
// Test a valid string.
$view->result[0]->{$column_map_reversed['name']} = $random_value;
$render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
$render = (string) $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
return $view->field['name']->advancedRender($view->result[0]);
});
$this->assertSame($random_name, (string) $render, 'If the rewritten string is not empty, it should not be treated as empty.');
// Test an empty string.
$view->result[0]->{$column_map_reversed['name']} = "";
$render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
$render = (string) $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
return $view->field['name']->advancedRender($view->result[0]);
});
$this->assertSame($random_name, (string) $render, 'If the rewritten string is not empty, "" should not be treated as empty.');
// Test zero as an integer.
$view->result[0]->{$column_map_reversed['name']} = 0;
$render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
$render = (string) $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
return $view->field['name']->advancedRender($view->result[0]);
});
$this->assertSame($random_name, (string) $render, 'If the rewritten string is not empty, 0 should not be treated as empty.');
// Test zero as a string.
$view->result[0]->{$column_map_reversed['name']} = "0";
$render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
$render = (string) $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
return $view->field['name']->advancedRender($view->result[0]);
});
$this->assertSame($random_name, (string) $render, 'If the rewritten string is not empty, "0" should not be treated as empty.');
@ -539,28 +539,28 @@ class FieldKernelTest extends ViewsKernelTestBase {
// Test a valid string.
$view->result[0]->{$column_map_reversed['name']} = $random_name;
$render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
$render = (string) $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
return $view->field['name']->advancedRender($view->result[0]);
});
$this->assertSame($random_name, (string) $render, 'If the rewritten string is empty, it should not be treated as empty.');
// Test an empty string.
$view->result[0]->{$column_map_reversed['name']} = "";
$render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
$render = (string) $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
return $view->field['name']->advancedRender($view->result[0]);
});
$this->assertSame("", $render, 'If the rewritten string is empty, "" should be treated as empty.');
// Test zero as an integer.
$view->result[0]->{$column_map_reversed['name']} = 0;
$render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
$render = (string) $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
return $view->field['name']->advancedRender($view->result[0]);
});
$this->assertSame('0', (string) $render, 'If the rewritten string is empty, 0 should not be treated as empty.');
// Test zero as a string.
$view->result[0]->{$column_map_reversed['name']} = "0";
$render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
$render = (string) $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
return $view->field['name']->advancedRender($view->result[0]);
});
$this->assertSame("0", (string) $render, 'If the rewritten string is empty, "0" should not be treated as empty.');
@ -575,28 +575,28 @@ class FieldKernelTest extends ViewsKernelTestBase {
// Test a valid string.
$view->result[0]->{$column_map_reversed['name']} = $random_name;
$render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
$render = (string) $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
return $view->field['name']->advancedRender($view->result[0]);
});
$this->assertSame("0", (string) $render, 'If the rewritten string is zero and empty_zero is not checked, the string rewritten as 0 should not be treated as empty.');
// Test an empty string.
$view->result[0]->{$column_map_reversed['name']} = "";
$render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
$render = (string) $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
return $view->field['name']->advancedRender($view->result[0]);
});
$this->assertSame("0", (string) $render, 'If the rewritten string is zero and empty_zero is not checked, "" rewritten as 0 should not be treated as empty.');
// Test zero as an integer.
$view->result[0]->{$column_map_reversed['name']} = 0;
$render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
$render = (string) $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
return $view->field['name']->advancedRender($view->result[0]);
});
$this->assertSame("0", (string) $render, 'If the rewritten string is zero and empty_zero is not checked, 0 should not be treated as empty.');
// Test zero as a string.
$view->result[0]->{$column_map_reversed['name']} = "0";
$render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
$render = (string) $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
return $view->field['name']->advancedRender($view->result[0]);
});
$this->assertSame("0", (string) $render, 'If the rewritten string is zero and empty_zero is not checked, "0" should not be treated as empty.');
@ -611,28 +611,28 @@ class FieldKernelTest extends ViewsKernelTestBase {
// Test a valid string.
$view->result[0]->{$column_map_reversed['name']} = $random_name;
$render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
$render = (string) $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
return $view->field['name']->advancedRender($view->result[0]);
});
$this->assertSame($random_value, (string) $render, 'If the original and rewritten strings are valid, it should not be treated as empty.');
// Test an empty string.
$view->result[0]->{$column_map_reversed['name']} = "";
$render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
$render = (string) $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
return $view->field['name']->advancedRender($view->result[0]);
});
$this->assertSame("", $render, 'If either the original or rewritten string is invalid, "" should be treated as empty.');
// Test zero as an integer.
$view->result[0]->{$column_map_reversed['name']} = 0;
$render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
$render = (string) $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
return $view->field['name']->advancedRender($view->result[0]);
});
$this->assertSame($random_value, (string) $render, 'If the original and rewritten strings are valid, 0 should not be treated as empty.');
// Test zero as a string.
$view->result[0]->{$column_map_reversed['name']} = "0";
$render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
$render = (string) $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
return $view->field['name']->advancedRender($view->result[0]);
});
$this->assertSame($random_value, (string) $render, 'If the original and rewritten strings are valid, "0" should not be treated as empty.');
@ -647,28 +647,28 @@ class FieldKernelTest extends ViewsKernelTestBase {
// Test a valid string.
$view->result[0]->{$column_map_reversed['name']} = $random_name;
$render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
$render = (string) $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
return $view->field['name']->advancedRender($view->result[0]);
});
$this->assertSame("", (string) $render, 'If the rewritten string is zero, it should be treated as empty.');
// Test an empty string.
$view->result[0]->{$column_map_reversed['name']} = "";
$render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
$render = (string) $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
return $view->field['name']->advancedRender($view->result[0]);
});
$this->assertSame("", $render, 'If the rewritten string is zero, "" should be treated as empty.');
// Test zero as an integer.
$view->result[0]->{$column_map_reversed['name']} = 0;
$render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
$render = (string) $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
return $view->field['name']->advancedRender($view->result[0]);
});
$this->assertSame("", $render, 'If the rewritten string is zero, 0 should not be treated as empty.');
// Test zero as a string.
$view->result[0]->{$column_map_reversed['name']} = "0";
$render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
$render = (string) $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
return $view->field['name']->advancedRender($view->result[0]);
});
$this->assertSame("", $render, 'If the rewritten string is zero, "0" should not be treated as empty.');

View File

@ -128,7 +128,7 @@ class FieldRenderedEntityTest extends ViewsKernelTestBase {
$renderer = \Drupal::service('renderer');
$renderer->renderPlain($build);
for ($i = 1; $i <= 3; $i++) {
$view_field = $view->style_plugin->getField($i - 1, 'rendered_entity');
$view_field = (string) $view->style_plugin->getField($i - 1, 'rendered_entity');
$search_result = str_contains($view_field, "Test $i");
$this->assertFalse($search_result, "The text 'Test $i' not found in the view.");
}
@ -201,7 +201,7 @@ class FieldRenderedEntityTest extends ViewsKernelTestBase {
$renderer = \Drupal::service('renderer');
$renderer->renderPlain($build);
for ($i = 1; $i <= 3; $i++) {
$view_field = $view->style_plugin->getField($i - 1, 'rendered_entity');
$view_field = (string) $view->style_plugin->getField($i - 1, 'rendered_entity');
$search_result = str_contains($view_field, "Test $i");
$this->assertTrue($search_result, "The text 'Test $i' found in the view.");
}

View File

@ -193,7 +193,7 @@ class FilterCombineTest extends ViewsKernelTestBase {
// Confirm that the query with multiple filters used the "CONCAT_WS"
// operator.
$this->assertStringContainsString('CONCAT_WS(', $view->query->query());
$this->assertStringContainsString('CONCAT_WS(', (string) $view->query->query());
}
/**
@ -279,7 +279,7 @@ class FilterCombineTest extends ViewsKernelTestBase {
// Confirm that the query with single filter does not use the "CONCAT_WS"
// operator.
$this->assertStringNotContainsString('CONCAT_WS(', $view->query->query());
$this->assertStringNotContainsString('CONCAT_WS(', (string) $view->query->query());
}
/**

View File

@ -177,7 +177,7 @@ class DisplayPageTest extends ViewsKernelTestBase {
$this->setRawContent($output);
$result = $this->xpath('//div[@class=:class]/a', [':class' => 'more-link']);
$this->assertEquals(Url::fromRoute('view.test_display_more.page_1')->toString(), $result[0]->attributes()->href, 'The right more link is shown.');
$this->assertEquals($expected_more_text, trim($result[0][0]), 'The right link text is shown.');
$this->assertEquals($expected_more_text, trim((string) $result[0][0]), 'The right link text is shown.');
// Test the renderMoreLink method directly. This could be directly unit
// tested.
@ -186,7 +186,7 @@ class DisplayPageTest extends ViewsKernelTestBase {
$this->setRawContent($more_link);
$result = $this->xpath('//div[@class=:class]/a', [':class' => 'more-link']);
$this->assertEquals(Url::fromRoute('view.test_display_more.page_1')->toString(), $result[0]->attributes()->href, 'The right more link is shown.');
$this->assertEquals($expected_more_text, trim($result[0][0]), 'The right link text is shown.');
$this->assertEquals($expected_more_text, trim((string) $result[0][0]), 'The right link text is shown.');
// Test the useMoreText method directly. This could be directly unit
// tested.

View File

@ -26,7 +26,7 @@ class StyleHtmlListTest extends ViewsKernelTestBase {
public function testDefaultRowClasses() {
$view = Views::getView('test_style_html_list');
$output = $view->preview();
$output = \Drupal::service('renderer')->renderRoot($output);
$output = (string) \Drupal::service('renderer')->renderRoot($output);
// Check that an empty class attribute is not added if the wrapper class is
// not set.
@ -41,7 +41,7 @@ class StyleHtmlListTest extends ViewsKernelTestBase {
$view->style_plugin->options['wrapper_class'] = 'wrapper-class';
$output = $view->preview();
$output = \Drupal::service('renderer')->renderRoot($output);
$output = (string) \Drupal::service('renderer')->renderRoot($output);
// Check that class attribute is present if the wrapper class is set.
$this->assertStringContainsString('<div class="wrapper-class">', $output, 'Class is added to DIV');

View File

@ -26,7 +26,7 @@ class StyleMappingTest extends StyleTestBase {
*/
public function testMappedOutput() {
$view = Views::getView('test_style_mapping');
$output = $this->mappedOutputHelper($view);
$output = (string) $this->mappedOutputHelper($view);
$this->assertStringNotContainsString('job', $output, 'The job field is added to the view but not in the mapping.');
$view->destroy();
@ -47,7 +47,7 @@ class StyleMappingTest extends StyleTestBase {
*/
protected function mappedOutputHelper(ViewExecutable $view) {
$output = $view->preview();
$rendered_output = \Drupal::service('renderer')->renderRoot($output);
$rendered_output = (string) \Drupal::service('renderer')->renderRoot($output);
$this->storeViewPreview($rendered_output);
$rows = $this->elements->body->div->div;
$data_set = $this->dataSet();

View File

@ -118,7 +118,7 @@ class StyleTableUnitTest extends PluginKernelTestBase {
$this->prepareView($view);
$view->field['name']->options['exclude'] = TRUE;
$output = $view->preview();
$output = \Drupal::service('renderer')->renderRoot($output);
$output = (string) \Drupal::service('renderer')->renderRoot($output);
$this->assertStringNotContainsString('views-field-name', $output, "Excluded field's wrapper was not rendered.");
$view->destroy();
@ -126,7 +126,7 @@ class StyleTableUnitTest extends PluginKernelTestBase {
// rendered.
$this->executeView($view);
$output = $view->preview();
$output = \Drupal::service('renderer')->renderRoot($output);
$output = (string) \Drupal::service('renderer')->renderRoot($output);
$this->assertStringNotContainsString('custom text', $output, 'Empty handler was not rendered on a non empty table.');
@ -135,7 +135,7 @@ class StyleTableUnitTest extends PluginKernelTestBase {
$view->executed = TRUE;
$view->result = [];
$output = $view->preview();
$output = \Drupal::service('renderer')->renderRoot($output);
$output = (string) \Drupal::service('renderer')->renderRoot($output);
$this->assertStringContainsString('custom text', $output, 'Empty handler got rendered on an empty table.');
}

View File

@ -286,7 +286,7 @@ class StyleTest extends ViewsKernelTestBase {
$view->style_plugin->options['row_class'] = $random_name . " test-token-{{ name }}";
$output = $view->preview();
$html_dom = $this->getHtmlDom($this->container->get('renderer')->renderRoot($output));
$html_dom = $this->getHtmlDom((string) $this->container->get('renderer')->renderRoot($output));
$rows = $html_dom->body->div->div;
$count = 0;

View File

@ -445,7 +445,7 @@ class ViewExecutableTest extends ViewsKernelTestBase {
$count = 0;
foreach ($view->displayHandlers as $id => $display) {
$match = function ($value) use ($display) {
return str_contains($value, $display->display['display_title']);
return str_contains((string) $value, $display->display['display_title']);
};
$this->assertNotEmpty(array_filter($validate[$id], $match), "Error message found for $id display");
$count++;

View File

@ -93,8 +93,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);
$query_string = $this->container->get('asset.query_string')->get();
$this->assertStringContainsString('<link rel="stylesheet" media="all" href="' . $this->fileUrlGenerator->generateString('core/modules/system/tests/modules/common_test/bar.css') . '?' . $query_string . '" />', $rendered_css, 'Rendering an external CSS file.');
$this->assertStringContainsString('<script src="' . $this->fileUrlGenerator->generateString('core/modules/system/tests/modules/common_test/foo.js') . '?' . $query_string . '"></script>', $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('<link rel="stylesheet" media="all" href="http://example.com/stylesheet.css" />', $rendered_css, 'Rendering an external CSS file.');
$this->assertStringContainsString('<script src="http://example.com/script.js"></script>', $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 = '<script src="http://example.com/deferred-external.js" foo="bar" defer></script>';
$expected_2 = '<script src="' . $this->fileUrlGenerator->generateString('core/modules/system/tests/modules/common_test/deferred-internal.js') . '?v=1" defer bar="foo"></script>';
$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 = '<script src="http://example.com/deferred-external.js" foo="bar" defer></script>';
$expected_2 = '<script src="' . $this->fileUrlGenerator->generateString('core/modules/system/tests/modules/common_test/deferred-internal.js') . '?v=1" defer bar="foo"></script>';
$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('<script src="' . $this->fileUrlGenerator->generateString('core/modules/system/tests/modules/common_test/header.js') . '?' . $query_string . '"></script>', $rendered_js, 'The JS asset in common_test/js-header appears in the header.');
$this->assertStringContainsString('<script src="' . $this->fileUrlGenerator->generateString('core/misc/drupal.js'), $rendered_js, 'The JS asset of the direct dependency (core/drupal) of common_test/js-header appears in the header.');
@ -266,7 +266,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);
$this->assertStringContainsString('core/assets/vendor/once/once.min.js?v=1.0.1', $rendered_js, 'JavaScript version identifiers correctly appended to URLs');
}
@ -295,7 +295,7 @@ class AttachedAssetsTest extends KernelTestBase {
// Retrieve the rendered JavaScript and test against the regex.
$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);
$matches = [];
if (preg_match_all('/weight_([-0-9]+_[0-9]+)/', $rendered_js, $matches)) {
$result = $matches[1];
@ -337,7 +337,7 @@ class AttachedAssetsTest extends KernelTestBase {
// Retrieve the rendered CSS and test against the regex.
$css = $this->assetResolver->getCssAssets($assets, FALSE, \Drupal::languageManager()->getCurrentLanguage());
$css_render_array = \Drupal::service('asset.css.collection_renderer')->render($css);
$rendered_css = $this->renderer->renderPlain($css_render_array);
$rendered_css = (string) $this->renderer->renderPlain($css_render_array);
$matches = [];
if (preg_match_all('/([a-z]+)_weight_([-0-9]+_[0-9]+)/', $rendered_css, $matches)) {
$result = $matches[0];
@ -360,7 +360,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);
// Verify that lighter CSS assets are rendered first.
$this->assertLessThan(strpos($rendered_js, 'first.js'), strpos($rendered_js, 'lighter.css'));
// Verify that lighter JavaScript assets are rendered first.
@ -385,7 +385,7 @@ class AttachedAssetsTest extends KernelTestBase {
// takes place.
$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);
// Verify that JavaScript weight is correctly altered by the alter hook.
$this->assertLessThan(strpos($rendered_js, 'core/misc/tableselect.js'), strpos($rendered_js, 'alter.js'));
}
@ -407,7 +407,7 @@ class AttachedAssetsTest extends KernelTestBase {
$assets = AttachedAssets::createFromRenderArray($build);
$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);
$this->assertStringContainsString('core/assets/vendor/jquery-form/jquery.form.min.js', (string) $rendered_js, 'Altered library dependencies are added to the page.');
}
@ -456,9 +456,9 @@ class AttachedAssetsTest extends KernelTestBase {
$this->assertArrayHasKey('core/modules/system/tests/modules/common_test/querystring.js?arg1=value1&arg2=value2', $js);
$css_render_array = \Drupal::service('asset.css.collection_renderer')->render($css);
$rendered_css = $this->renderer->renderPlain($css_render_array);
$rendered_css = (string) $this->renderer->renderPlain($css_render_array);
$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('<link rel="stylesheet" media="all" href="' . str_replace('&', '&amp;', $this->fileUrlGenerator->generateString('core/modules/system/tests/modules/common_test/querystring.css?arg1=value1&arg2=value2')) . '&amp;' . $query_string . '" />', $rendered_css, 'CSS file with query string gets version query string correctly appended..');
$this->assertStringContainsString('<script src="' . str_replace('&', '&amp;', $this->fileUrlGenerator->generateString('core/modules/system/tests/modules/common_test/querystring.js?arg1=value1&arg2=value2')) . '&amp;' . $query_string . '"></script>', $rendered_js, 'JavaScript file with query string gets version query string correctly appended.');

View File

@ -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);
}
}

View File

@ -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;
}
/**

View File

@ -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.');
}

View File

@ -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();
}

View File

@ -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.');

View File

@ -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');

View File

@ -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.');
}