Issue #3404508 by mstrelan, smustgrave, quietone: Fix strict type errors in Functional tests: Add casts and fix types where needed

merge-requests/6427/head
Lee Rowlands 2024-02-02 07:57:36 +10:00
parent aea158c230
commit af369c3cce
No known key found for this signature in database
GPG Key ID: 2B829A3DF9204DC4
35 changed files with 140 additions and 140 deletions

View File

@ -81,19 +81,19 @@ class BigPipeTest extends BrowserTestBase {
// 1. No session (anonymous).
$this->drupalGet(Url::fromRoute('<front>'));
$this->assertSessionCookieExists(FALSE);
$this->assertBigPipeNoJsCookieExists(FALSE);
$this->assertSessionCookieExists('0');
$this->assertBigPipeNoJsCookieExists('0');
$this->assertSession()->responseNotContains('<noscript><meta http-equiv="Refresh" content="0; URL=');
$this->assertSession()->responseNotContains($no_js_to_js_markup);
// 2. Session (authenticated).
$this->drupalLogin($this->rootUser);
$this->assertSessionCookieExists(TRUE);
$this->assertBigPipeNoJsCookieExists(FALSE);
$this->assertSessionCookieExists('1');
$this->assertBigPipeNoJsCookieExists('0');
$this->assertSession()->responseContains('<noscript><meta http-equiv="Refresh" content="0; URL=' . base_path() . 'big_pipe/no-js?destination=' . UrlHelper::encodePath(base_path() . 'user/1?check_logged_in=1') . '" />' . "\n" . '</noscript>');
$this->assertSession()->responseNotContains($no_js_to_js_markup);
$this->assertBigPipeNoJsMetaRefreshRedirect();
$this->assertBigPipeNoJsCookieExists(TRUE);
$this->assertBigPipeNoJsCookieExists('1');
$this->assertSession()->responseNotContains('<noscript><meta http-equiv="Refresh" content="0; URL=');
$this->assertSession()->responseContains($no_js_to_js_markup);
$this->drupalLogout();
@ -104,12 +104,12 @@ class BigPipeTest extends BrowserTestBase {
// 3. Session (anonymous).
$this->drupalGet(Url::fromRoute('user.login', [], ['query' => ['trigger_session' => 1]]));
$this->drupalGet(Url::fromRoute('user.login'));
$this->assertSessionCookieExists(TRUE);
$this->assertBigPipeNoJsCookieExists(FALSE);
$this->assertSessionCookieExists('1');
$this->assertBigPipeNoJsCookieExists('0');
$this->assertSession()->responseContains('<noscript><meta http-equiv="Refresh" content="0; URL=' . base_path() . 'big_pipe/no-js?destination=' . base_path() . 'user/login" />' . "\n" . '</noscript>');
$this->assertSession()->responseNotContains($no_js_to_js_markup);
$this->assertBigPipeNoJsMetaRefreshRedirect();
$this->assertBigPipeNoJsCookieExists(TRUE);
$this->assertBigPipeNoJsCookieExists('1');
$this->assertSession()->responseNotContains('<noscript><meta http-equiv="Refresh" content="0; URL=');
$this->assertSession()->responseContains($no_js_to_js_markup);
@ -118,14 +118,14 @@ class BigPipeTest extends BrowserTestBase {
// Edge case: route with '_no_big_pipe' option.
$this->drupalGet(Url::fromRoute('no_big_pipe'));
$this->assertSessionCookieExists(FALSE);
$this->assertBigPipeNoJsCookieExists(FALSE);
$this->assertSessionCookieExists('0');
$this->assertBigPipeNoJsCookieExists('0');
$this->assertSession()->responseNotContains('<noscript><meta http-equiv="Refresh" content="0; URL=');
$this->assertSession()->responseNotContains($no_js_to_js_markup);
$this->drupalLogin($this->rootUser);
$this->drupalGet(Url::fromRoute('no_big_pipe'));
$this->assertSessionCookieExists(TRUE);
$this->assertBigPipeNoJsCookieExists(FALSE);
$this->assertSessionCookieExists('1');
$this->assertBigPipeNoJsCookieExists('0');
$this->assertSession()->responseNotContains('<noscript><meta http-equiv="Refresh" content="0; URL=');
$this->assertSession()->responseNotContains($no_js_to_js_markup);
}
@ -145,8 +145,8 @@ class BigPipeTest extends BrowserTestBase {
$this->config('system.logging')->set('error_level', ERROR_REPORTING_HIDE)->save();
$this->drupalLogin($this->rootUser);
$this->assertSessionCookieExists(TRUE);
$this->assertBigPipeNoJsCookieExists(FALSE);
$this->assertSessionCookieExists('1');
$this->assertBigPipeNoJsCookieExists('0');
$connection = Database::getConnection();
$log_count = $connection->select('watchdog')->countQuery()->execute()->fetchField();
@ -236,8 +236,8 @@ class BigPipeTest extends BrowserTestBase {
$this->config('system.logging')->set('error_level', ERROR_REPORTING_HIDE)->save();
$this->drupalLogin($this->rootUser);
$this->assertSessionCookieExists(TRUE);
$this->assertBigPipeNoJsCookieExists(FALSE);
$this->assertSessionCookieExists('1');
$this->assertBigPipeNoJsCookieExists('0');
// By calling performMetaRefresh() here, we simulate JavaScript being
// disabled, because as far as the BigPipe module is concerned, it is
@ -245,7 +245,7 @@ class BigPipeTest extends BrowserTestBase {
// @see setUp()
// @see performMetaRefresh()
$this->performMetaRefresh();
$this->assertBigPipeNoJsCookieExists(TRUE);
$this->assertBigPipeNoJsCookieExists('1');
$this->drupalGet(Url::fromRoute('big_pipe_test'));
$this->assertBigPipeResponseHeadersPresent();
@ -296,8 +296,8 @@ class BigPipeTest extends BrowserTestBase {
*/
public function testBigPipeMultiOccurrencePlaceholders() {
$this->drupalLogin($this->rootUser);
$this->assertSessionCookieExists(TRUE);
$this->assertBigPipeNoJsCookieExists(FALSE);
$this->assertSessionCookieExists('1');
$this->assertBigPipeNoJsCookieExists('0');
// By not calling performMetaRefresh() here, we simulate JavaScript being
// enabled, because as far as the BigPipe module is concerned, JavaScript is
@ -321,7 +321,7 @@ class BigPipeTest extends BrowserTestBase {
// @see setUp()
// @see performMetaRefresh()
$this->performMetaRefresh();
$this->assertBigPipeNoJsCookieExists(TRUE);
$this->assertBigPipeNoJsCookieExists('1');
$this->drupalGet(Url::fromRoute('big_pipe_test_multi_occurrence'));
$this->assertSession()->pageTextContains('The count is 1.');
$this->assertSession()->responseNotContains('The count is 2.');

View File

@ -117,7 +117,7 @@ class BookBreadcrumbTest extends BrowserTestBase {
static $number = 0;
$edit = [];
$edit['title[0][value]'] = str_pad($number, 2, '0', STR_PAD_LEFT) . ' - test node ' . $this->randomMachineName(10);
$edit['title[0][value]'] = str_pad((string) $number, 2, '0', STR_PAD_LEFT) . ' - test node ' . $this->randomMachineName(10);
$edit['body[0][value]'] = 'test body ' . $this->randomMachineName(32) . ' ' . $this->randomMachineName(32);
$edit['book[bid]'] = $book_nid;

View File

@ -192,7 +192,7 @@ trait BookTestTrait {
// Used to ensure that when sorted nodes stay in same order.
static $number = 0;
$edit['title[0][value]'] = str_pad($number, 2, '0', STR_PAD_LEFT) . ' - test node ' . $this->randomMachineName(10);
$edit['title[0][value]'] = str_pad((string) $number, 2, '0', STR_PAD_LEFT) . ' - test node ' . $this->randomMachineName(10);
$edit['body[0][value]'] = 'test body ' . $this->randomMachineName(32) . ' ' . $this->randomMachineName(32);
$edit['book[bid]'] = $book_nid;

View File

@ -125,14 +125,14 @@ class CommentThreadingTest extends CommentTestBase {
/**
* Asserts that the link to the specified parent comment is present.
*
* @param int $cid
* @param string $cid
* The comment ID to check.
* @param int $pid
* @param string $pid
* The expected parent comment ID.
*
* @internal
*/
protected function assertParentLink(int $cid, int $pid): void {
protected function assertParentLink(string $cid, string $pid): void {
// This pattern matches a markup structure like:
// @code
// <article id="comment-2">
@ -156,12 +156,12 @@ class CommentThreadingTest extends CommentTestBase {
/**
* Asserts that the specified comment does not have a link to a parent.
*
* @param int $cid
* @param string $cid
* The comment ID to check.
*
* @internal
*/
protected function assertNoParentLink(int $cid): void {
protected function assertNoParentLink(string $cid): void {
$pattern = "//article[@id='comment-$cid']";
// A parent link is always accompanied by the text "In reply to".
$this->assertSession()->elementTextNotContains('xpath', $pattern, 'In reply to');

View File

@ -322,7 +322,7 @@ class ConfigEntityListTest extends BrowserTestBase {
// Create 51 test entities.
for ($i = 1; $i < 52; $i++) {
$storage->create([
'id' => str_pad($i, 2, '0', STR_PAD_LEFT),
'id' => str_pad((string) $i, 2, '0', STR_PAD_LEFT),
'label' => 'Test config entity ' . $i,
'weight' => $i,
'protected_property' => $i,

View File

@ -80,7 +80,7 @@ class ConfigInstallProfileUnmetDependenciesTest extends InstallerTestBase {
mkdir($dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
}
else {
copy($item, $dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
copy((string) $item, $dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
}
}

View File

@ -339,7 +339,7 @@ class NumberFieldTest extends BrowserTestBase {
$this->assertSession()->responseContains('placeholder="0.00"');
// Submit a signed decimal value within the allowed precision and scale.
$value = '-1234.5678';
$value = -1234.5678;
$edit = [
"{$field_name}[0][value]" => $value,
];

View File

@ -108,7 +108,7 @@ class ManageDisplayTest extends BrowserTestBase {
// For this test, use a formatter setting value that is an integer unlikely
// to appear in a rendered node other than as part of the field being tested
// (for example, unlikely to be part of the "Submitted by ... on ..." line).
$value = 12345;
$value = '12345';
$settings = [
'type' => $this->type,
'field_test' => [['value' => $value]],

View File

@ -72,7 +72,7 @@ class FileOnTranslatedEntityTest extends FileFieldTestBase {
// Enable translation for "Basic page" nodes.
static::enableContentTranslation('node', 'page');
static::setFieldTranslatable('node', 'page', $this->fieldName, 1);
static::setFieldTranslatable('node', 'page', $this->fieldName, TRUE);
}
/**

View File

@ -64,7 +64,7 @@ class PrivateFileOnTranslatedEntityTest extends FileFieldTestBase {
// Enable translation for "Basic page" nodes.
static::enableContentTranslation('node', 'page');
static::setFieldTranslatable('node', 'page', $this->fieldName, 1);
static::setFieldTranslatable('node', 'page', $this->fieldName, TRUE);
}
/**

View File

@ -304,7 +304,7 @@ class ImageDimensionsTest extends BrowserTestBase {
* altered and the element is re-rendered each time.
*/
protected function getImageTag($variables) {
return str_replace("\n", '', \Drupal::service('renderer')->renderRoot($variables));
return str_replace("\n", '', (string) \Drupal::service('renderer')->renderRoot($variables));
}
}

View File

@ -116,7 +116,7 @@ class ImageFieldDisplayTest extends ImageFieldTestBase {
'#alt' => $alt,
'#attributes' => ['loading' => 'lazy'],
];
$default_output = str_replace("\n", '', $renderer->renderRoot($image));
$default_output = str_replace("\n", '', (string) $renderer->renderRoot($image));
$this->assertSession()->responseContains($default_output);
// Test the image linked to file formatter.
@ -137,7 +137,7 @@ class ImageFieldDisplayTest extends ImageFieldTestBase {
'#alt' => $alt,
'#attributes' => ['loading' => 'lazy'],
];
$default_output = '<a href="' . $file->createFileUrl() . '">' . $renderer->renderRoot($image) . '</a>';
$default_output = '<a href="' . $file->createFileUrl() . '">' . (string) $renderer->renderRoot($image) . '</a>';
$this->drupalGet('node/' . $nid);
$this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', $file->getCacheTags()[0]);
// @todo Remove in https://www.drupal.org/node/2646744.
@ -196,7 +196,7 @@ class ImageFieldDisplayTest extends ImageFieldTestBase {
'#alt' => $alt,
'#attributes' => ['loading' => 'lazy'],
];
$default_output = $renderer->renderRoot($image_style);
$default_output = (string) $renderer->renderRoot($image_style);
$this->drupalGet('node/' . $nid);
$image_style = ImageStyle::load('thumbnail');
$this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', $image_style->getCacheTags()[0]);
@ -313,7 +313,7 @@ class ImageFieldDisplayTest extends ImageFieldTestBase {
];
$this->drupalGet('node/' . $nid . '/edit');
$this->submitForm($edit, 'Save');
$default_output = str_replace("\n", '', $renderer->renderRoot($image));
$default_output = str_replace("\n", '', (string) $renderer->renderRoot($image));
$this->assertSession()->responseContains($default_output);
// Verify that alt/title longer than allowed results in a validation error.
@ -421,7 +421,7 @@ class ImageFieldDisplayTest extends ImageFieldTestBase {
'#alt' => $alt,
'#attributes' => ['loading' => 'lazy'],
];
$default_output = str_replace("\n", '', $renderer->renderRoot($image));
$default_output = str_replace("\n", '', (string) $renderer->renderRoot($image));
$this->assertSession()->responseContains($default_output);
// Test overrides of image loading attribute.
@ -446,7 +446,7 @@ class ImageFieldDisplayTest extends ImageFieldTestBase {
'#alt' => $alt,
'#attributes' => ['loading' => 'eager'],
];
$default_output = $renderer->renderRoot($image);
$default_output = (string) $renderer->renderRoot($image);
$this->drupalGet('node/' . $nid);
$this->assertSession()->responseContains($default_output);
@ -467,7 +467,7 @@ class ImageFieldDisplayTest extends ImageFieldTestBase {
'#alt' => $alt,
'#attributes' => ['loading' => 'eager'],
];
$default_output = $renderer->renderRoot($image_style);
$default_output = (string) $renderer->renderRoot($image_style);
$this->drupalGet('node/' . $nid);
$this->assertSession()->responseContains($default_output);
}
@ -521,7 +521,7 @@ class ImageFieldDisplayTest extends ImageFieldTestBase {
'#height' => 20,
'#attributes' => ['loading' => 'lazy'],
];
$default_output = str_replace("\n", '', $renderer->renderRoot($image));
$default_output = str_replace("\n", '', (string) $renderer->renderRoot($image));
$this->drupalGet('node/' . $node->id());
$this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', $file->getCacheTags()[0]);
// Verify that no image style cache tags are found.
@ -547,7 +547,7 @@ class ImageFieldDisplayTest extends ImageFieldTestBase {
'#alt' => $alt,
'#attributes' => ['loading' => 'lazy'],
];
$image_output = str_replace("\n", '', $renderer->renderRoot($image));
$image_output = str_replace("\n", '', (string) $renderer->renderRoot($image));
$this->drupalGet('node/' . $nid);
$this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', $file->getCacheTags()[0]);
// Verify that no image style cache tags are found.
@ -602,7 +602,7 @@ class ImageFieldDisplayTest extends ImageFieldTestBase {
'#height' => 20,
'#attributes' => ['loading' => 'lazy'],
];
$default_output = str_replace("\n", '', $renderer->renderRoot($image));
$default_output = str_replace("\n", '', (string) $renderer->renderRoot($image));
$this->drupalGet('node/' . $node->id());
$this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', $file->getCacheTags()[0]);
// Verify that no image style cache tags are found.

View File

@ -162,7 +162,7 @@ class BlockContentTest extends ResourceTestBase {
],
'changed' => (new \DateTime())->setTimestamp($this->entity->getChangedTime())->setTimezone(new \DateTimeZone('UTC'))->format(\DateTime::RFC3339),
'info' => 'Llama',
'revision_created' => (new \DateTime())->setTimestamp($this->entity->getRevisionCreationTime())->setTimezone(new \DateTimeZone('UTC'))->format(\DateTime::RFC3339),
'revision_created' => (new \DateTime())->setTimestamp((int) $this->entity->getRevisionCreationTime())->setTimezone(new \DateTimeZone('UTC'))->format(\DateTime::RFC3339),
'revision_translation_affected' => TRUE,
'status' => FALSE,
'langcode' => 'en',

View File

@ -109,7 +109,7 @@ class EntityTestComputedFieldTest extends ResourceTestBase {
'self' => ['href' => $self_url],
],
'attributes' => [
'created' => (new \DateTime())->setTimestamp($this->entity->get('created')->value)->setTimezone(new \DateTimeZone('UTC'))->format(\DateTime::RFC3339),
'created' => (new \DateTime())->setTimestamp((int) $this->entity->get('created')->value)->setTimezone(new \DateTimeZone('UTC'))->format(\DateTime::RFC3339),
'name' => 'Llama',
'drupal_internal__id' => 1,
'computed_string_field' => NULL,

View File

@ -110,7 +110,7 @@ class EntityTestMapFieldTest extends ResourceTestBase {
'self' => ['href' => $self_url],
],
'attributes' => [
'created' => (new \DateTime())->setTimestamp($this->entity->get('created')->value)->setTimezone(new \DateTimeZone('UTC'))->format(\DateTime::RFC3339),
'created' => (new \DateTime())->setTimestamp((int) $this->entity->get('created')->value)->setTimezone(new \DateTimeZone('UTC'))->format(\DateTime::RFC3339),
'langcode' => 'en',
'name' => 'Llama',
'data' => static::$mapValue,

View File

@ -121,7 +121,7 @@ class EntityTestTest extends ResourceTestBase {
'self' => ['href' => $self_url],
],
'attributes' => [
'created' => (new \DateTime())->setTimestamp($this->entity->get('created')->value)->setTimezone(new \DateTimeZone('UTC'))->format(\DateTime::RFC3339),
'created' => (new \DateTime())->setTimestamp((int) $this->entity->get('created')->value)->setTimezone(new \DateTimeZone('UTC'))->format(\DateTime::RFC3339),
'field_test_text' => NULL,
'langcode' => 'en',
'name' => 'Llama',

View File

@ -57,9 +57,9 @@ class JsonApiFunctionalDateFieldTest extends JsonApiFunctionalTestBase {
/** @var \Drupal\Core\Datetime\DateFormatterInterface $date_formatter */
$date_formatter = $this->container->get('date.formatter');
$timestamp_1 = '5000000';
$timestamp_2 = '6000000';
$timestamp_3 = '7000000';
$timestamp_1 = 5000000;
$timestamp_2 = 6000000;
$timestamp_3 = 7000000;
// Expected: node 1.
$timestamp_smaller_than_value = $timestamp_2;
// Expected: node 1 and node 2.

View File

@ -184,7 +184,7 @@ class MediaTest extends ResourceTestBase {
'status' => TRUE,
'created' => '1973-11-29T21:33:09+00:00',
'changed' => (new \DateTime())->setTimestamp($this->entity->getChangedTime())->setTimezone(new \DateTimeZone('UTC'))->format(\DateTime::RFC3339),
'revision_created' => (new \DateTime())->setTimestamp($this->entity->getRevisionCreationTime())->setTimezone(new \DateTimeZone('UTC'))->format(\DateTime::RFC3339),
'revision_created' => (new \DateTime())->setTimestamp((int) $this->entity->getRevisionCreationTime())->setTimezone(new \DateTimeZone('UTC'))->format(\DateTime::RFC3339),
'default_langcode' => TRUE,
'revision_log_message' => NULL,
// @todo Attempt to remove this in https://www.drupal.org/project/drupal/issues/2933518.

View File

@ -130,7 +130,7 @@ class MenuLinkContentTest extends ResourceTestBase {
'weight' => 0,
'drupal_internal__id' => 1,
'drupal_internal__revision_id' => 1,
'revision_created' => (new \DateTime())->setTimestamp($this->entity->getRevisionCreationTime())->setTimezone(new \DateTimeZone('UTC'))->format(\DateTime::RFC3339),
'revision_created' => (new \DateTime())->setTimestamp((int) $this->entity->getRevisionCreationTime())->setTimezone(new \DateTimeZone('UTC'))->format(\DateTime::RFC3339),
'revision_log_message' => NULL,
// @todo Attempt to remove this in https://www.drupal.org/project/drupal/issues/2933518.
'revision_translation_affected' => TRUE,

View File

@ -2731,7 +2731,7 @@ abstract class ResourceTestBase extends BrowserTestBase {
'all' => $relationship_field_names,
];
if (count($relationship_field_names) > 1) {
$about_half_the_fields = floor(count($relationship_field_names) / 2);
$about_half_the_fields = (int) floor(count($relationship_field_names) / 2);
$field_sets['some'] = array_slice($relationship_field_names, $about_half_the_fields);
$nested_includes = $this->getNestedIncludePaths();
@ -3324,7 +3324,7 @@ abstract class ResourceTestBase extends BrowserTestBase {
$field_names = array_keys($this->entity->toArray());
$field_sets = [
'empty' => [],
'some' => array_slice($field_names, floor(count($field_names) / 2)),
'some' => array_slice($field_names, (int) floor(count($field_names) / 2)),
'all' => $field_names,
];
if ($this->entity instanceof EntityOwnerInterface) {

View File

@ -281,7 +281,7 @@ class TermTest extends ResourceTestBase {
'drupal_internal__tid' => 1,
'status' => TRUE,
'drupal_internal__revision_id' => 1,
'revision_created' => (new \DateTime())->setTimestamp($this->entity->getRevisionCreationTime())->setTimezone(new \DateTimeZone('UTC'))->format(\DateTime::RFC3339),
'revision_created' => (new \DateTime())->setTimestamp((int) $this->entity->getRevisionCreationTime())->setTimezone(new \DateTimeZone('UTC'))->format(\DateTime::RFC3339),
// @todo Attempt to remove this in https://www.drupal.org/project/drupal/issues/2933518.
'revision_translation_affected' => TRUE,
],

View File

@ -144,7 +144,7 @@ class LocalePluralFormatTest extends BrowserTestBase {
// Assert that the we get the right translation for that. Change the
// expected index as per the logic for translation lookups.
$expected_plural_index = ($count == 1) ? 0 : $expected_plural_index;
$expected_plural_string = str_replace('@count', $count, $plural_strings[$langcode][$expected_plural_index]);
$expected_plural_string = str_replace('@count', (string) $count, $plural_strings[$langcode][$expected_plural_index]);
$this->assertSame($expected_plural_string, \Drupal::translation()->formatPlural($count, '@count hour', '@count hours', [], ['langcode' => $langcode])->render(), 'Plural translation of @count hour / @count hours for count ' . $count . ' in ' . $langcode . ' is ' . $expected_plural_string);
// DO NOT use translation to pass translated strings into
// PluralTranslatableMarkup::createFromTranslatedString() this way. It

View File

@ -213,7 +213,7 @@ class ResponsiveImageFieldDisplayTest extends ImageFieldTestBase {
'#alt' => $alt,
'#attributes' => ['loading' => 'lazy'],
];
$default_output = str_replace("\n", '', $renderer->renderRoot($image));
$default_output = str_replace("\n", '', (string) $renderer->renderRoot($image));
$this->assertSession()->responseContains($default_output);
// Test field not being configured. This should not cause a fatal error.
@ -341,7 +341,7 @@ class ResponsiveImageFieldDisplayTest extends ImageFieldTestBase {
// The image.html.twig template has a newline after the <img> tag but
// responsive-image.html.twig doesn't have one after the fallback image, so
// we remove it here.
$default_output = trim($renderer->renderRoot($fallback_image));
$default_output = trim((string) $renderer->renderRoot($fallback_image));
$this->assertSession()->responseContains($default_output);
if ($scheme == 'private') {

View File

@ -465,7 +465,7 @@ class ShortcutLinksTest extends ShortcutTestBase {
*/
protected function assertShortcutQuickLink(string $label, int $index = 0, string $message = ''): void {
$links = $this->xpath('//a[normalize-space()=:label]', [':label' => $label]);
$message = ($message ? $message : new FormattableMarkup('Shortcut quick link with label %label found.', ['%label' => $label]));
$message = ($message ? $message : (string) new FormattableMarkup('Shortcut quick link with label %label found.', ['%label' => $label]));
$this->assertArrayHasKey($index, $links, $message);
}

View File

@ -35,7 +35,7 @@ class CheckboxTest extends BrowserTestBase {
// @see \Drupal\Core\Render\Element\Checkbox::processCheckbox().
foreach (['0', '', 1, '1', 'foobar', '1foobar'] as $return_value) {
$form_array = \Drupal::formBuilder()->getForm('\Drupal\form_test\Form\FormTestCheckboxTypeJugglingForm', $default_value, $return_value);
$form = \Drupal::service('renderer')->renderRoot($form_array);
$form = (string) \Drupal::service('renderer')->renderRoot($form_array);
if ($default_value === TRUE) {
$checked = TRUE;
}

View File

@ -58,7 +58,7 @@ class SitesDirectoryHardeningTest extends BrowserTestBase {
$requirements = $this->checkSystemRequirements();
$this->assertEquals(REQUIREMENT_WARNING, $requirements['configuration_files']['severity'], 'Warning severity is properly set.');
$this->assertEquals('Protection disabled', (string) $requirements['configuration_files']['value']);
$description = strip_tags(\Drupal::service('renderer')->renderPlain($requirements['configuration_files']['description']));
$description = strip_tags((string) \Drupal::service('renderer')->renderPlain($requirements['configuration_files']['description']));
$this->assertStringContainsString('settings.php is not protected from modifications and poses a security risk.', $description);
$this->assertStringContainsString('services.yml is not protected from modifications and poses a security risk.', $description);

View File

@ -50,7 +50,7 @@ class TwigDebugMarkupTest extends BrowserTestBase {
$node = $this->drupalCreateNode();
$builder = \Drupal::entityTypeManager()->getViewBuilder('node');
$build = $builder->view($node);
$output = $renderer->renderRoot($build);
$output = (string) $renderer->renderRoot($build);
$this->assertStringContainsString('<!-- THEME DEBUG -->', $output, 'Twig debug markup found in theme output when debug is enabled.');
$this->assertStringContainsString("THEME HOOK: 'node'", $output, 'Theme call information found.');
$this->assertStringContainsString('* node--1--full' . $extension . PHP_EOL . ' x node--1' . $extension . PHP_EOL . ' * node--page--full' . $extension . PHP_EOL . ' * node--page' . $extension . PHP_EOL . ' * node--full' . $extension . PHP_EOL . ' * node' . $extension, $output, 'Suggested template files found in order and node ID specific template shown as current template.');
@ -63,7 +63,7 @@ class TwigDebugMarkupTest extends BrowserTestBase {
// debug markup are correct.
$node2 = $this->drupalCreateNode();
$build = $builder->view($node2);
$output = $renderer->renderRoot($build);
$output = (string) $renderer->renderRoot($build);
$this->assertStringContainsString('* node--2--full' . $extension . PHP_EOL . ' * node--2' . $extension . PHP_EOL . ' * node--page--full' . $extension . PHP_EOL . ' * node--page' . $extension . PHP_EOL . ' * node--full' . $extension . PHP_EOL . ' x node' . $extension, $output, 'Suggested template files found in order and base template shown as current template.');
// Create another node and make sure the template suggestions shown in the
@ -71,7 +71,7 @@ class TwigDebugMarkupTest extends BrowserTestBase {
$node3 = $this->drupalCreateNode();
$build = ['#theme' => 'node__foo__bar'];
$build += $builder->view($node3);
$output = $renderer->renderRoot($build);
$output = (string) $renderer->renderRoot($build);
$this->assertStringContainsString("THEME HOOK: 'node__foo__bar'", $output, 'Theme call information found.');
$this->assertStringContainsString('* node--foo--bar' . $extension . PHP_EOL . ' * node--foo' . $extension . PHP_EOL . ' * node--&lt;script type=&quot;text/javascript&quot;&gt;alert(&#039;yo&#039;);&lt;/script&gt;' . $extension . PHP_EOL . ' * node--3--full' . $extension . PHP_EOL . ' * node--3' . $extension . PHP_EOL . ' * node--page--full' . $extension . PHP_EOL . ' * node--page' . $extension . PHP_EOL . ' * node--full' . $extension . PHP_EOL . ' x node' . $extension, $output, 'Suggested template files found in order and base template shown as current template.');
@ -83,7 +83,7 @@ class TwigDebugMarkupTest extends BrowserTestBase {
$this->resetAll();
$build = $builder->view($node);
$output = $renderer->renderRoot($build);
$output = (string) $renderer->renderRoot($build);
$this->assertStringNotContainsString('<!-- THEME DEBUG -->', $output, 'Twig debug markup not found in theme output when debug is disabled.');
}

View File

@ -269,19 +269,19 @@ class TrackerTest extends BrowserTestBase {
// Verify that the history metadata is updated.
$this->drupalGet('activity');
$this->assertHistoryMetadata($node->id(), $node->getChangedTime(), $node->get('comment')->last_comment_timestamp);
$this->assertHistoryMetadata($node->id(), $node->getChangedTime(), (int) $node->get('comment')->last_comment_timestamp);
$this->drupalGet('activity/' . $this->user->id());
$this->assertHistoryMetadata($node->id(), $node->getChangedTime(), $node->get('comment')->last_comment_timestamp);
$this->assertHistoryMetadata($node->id(), $node->getChangedTime(), (int) $node->get('comment')->last_comment_timestamp);
$this->drupalGet('user/' . $this->user->id() . '/activity');
$this->assertHistoryMetadata($node->id(), $node->getChangedTime(), $node->get('comment')->last_comment_timestamp);
$this->assertHistoryMetadata($node->id(), $node->getChangedTime(), (int) $node->get('comment')->last_comment_timestamp);
// Log out, now verify that the metadata is still there, but the library is
// not.
$this->drupalLogout();
$this->drupalGet('activity');
$this->assertHistoryMetadata($node->id(), $node->getChangedTime(), $node->get('comment')->last_comment_timestamp, FALSE);
$this->assertHistoryMetadata($node->id(), $node->getChangedTime(), (int) $node->get('comment')->last_comment_timestamp, FALSE);
$this->drupalGet('user/' . $this->user->id() . '/activity');
$this->assertHistoryMetadata($node->id(), $node->getChangedTime(), $node->get('comment')->last_comment_timestamp, FALSE);
$this->assertHistoryMetadata($node->id(), $node->getChangedTime(), (int) $node->get('comment')->last_comment_timestamp, FALSE);
}
/**
@ -459,7 +459,7 @@ class TrackerTest extends BrowserTestBase {
* indicators, as well as the "x new" replies link to the tracker.
* We do this in JavaScript to prevent breaking the render cache.
*
* @param int $node_id
* @param string|int $node_id
* A node ID, that must exist as a data-history-node-id attribute
* @param int $node_timestamp
* A node timestamp, that must exist as a data-history-node-timestamp
@ -472,7 +472,7 @@ class TrackerTest extends BrowserTestBase {
*
* @internal
*/
public function assertHistoryMetadata(int $node_id, int $node_timestamp, int $node_last_comment_timestamp, bool $library_is_present = TRUE): void {
public function assertHistoryMetadata(string|int $node_id, int $node_timestamp, int $node_last_comment_timestamp, bool $library_is_present = TRUE): void {
$settings = $this->getDrupalSettings();
$this->assertSame($library_is_present, isset($settings['ajaxPageState']) && in_array('tracker/history', explode(',', $settings['ajaxPageState']['libraries'])), 'drupal.tracker-history library is present.');
$this->assertSession()->elementsCount('xpath', '//table/tbody/tr/td[@data-history-node-id="' . $node_id . '" and @data-history-node-timestamp="' . $node_timestamp . '"]', 1);

View File

@ -183,7 +183,7 @@ class UserLoginHttpTest extends BrowserTestBase {
$response = $this->loginRequest($name, $pass, $format);
$this->assertEquals(200, $response->getStatusCode());
$result_data = $this->serializer->decode($response->getBody(), $format);
$result_data = $this->serializer->decode((string) $response->getBody(), $format);
$this->assertEquals($name, $result_data['current_user']['name']);
$this->assertEquals($account->id(), $result_data['current_user']['uid']);
$this->assertEquals($account->getRoles(), $result_data['current_user']['roles']);
@ -192,7 +192,7 @@ class UserLoginHttpTest extends BrowserTestBase {
// Logging in while already logged in results in a 403 with helpful message.
$response = $this->loginRequest($name, $pass, $format);
$this->assertSame(403, $response->getStatusCode());
$this->assertSame(['message' => 'This route can only be accessed by anonymous users.'], $this->serializer->decode($response->getBody(), $format));
$this->assertSame(['message' => 'This route can only be accessed by anonymous users.'], $this->serializer->decode((string) $response->getBody(), $format));
$response = $client->get($login_status_url, ['cookies' => $this->cookies]);
$this->assertHttpResponse($response, 200, UserAuthenticationController::LOGGED_IN);
@ -315,7 +315,7 @@ class UserLoginHttpTest extends BrowserTestBase {
// IP limit has reached to its limit. Even valid user credentials will fail.
$response = $this->loginRequest($user->getAccountName(), $user->passRaw, $format);
$this->assertHttpResponseWithMessage($response, '403', 'Access is blocked because of IP based flood prevention.', $format);
$this->assertHttpResponseWithMessage($response, 403, 'Access is blocked because of IP based flood prevention.', $format);
$last_log = $database->select('watchdog', 'w')
->fields('w', ['message'])
->condition('type', 'user')
@ -392,7 +392,7 @@ class UserLoginHttpTest extends BrowserTestBase {
// A successful login will reset the per-user flood control count.
$response = $this->loginRequest($user1->getAccountName(), $user1->passRaw, $format);
$result_data = $this->serializer->decode($response->getBody(), $format);
$result_data = $this->serializer->decode((string) $response->getBody(), $format);
$this->logoutRequest($format, $result_data['logout_token']);
// Try 3 failed logins for user 1, they will not trigger flood control.
@ -475,7 +475,7 @@ class UserLoginHttpTest extends BrowserTestBase {
$response = $this->loginRequest($name, $pass, $format);
$this->assertEquals(200, $response->getStatusCode());
$result_data = $this->serializer->decode($response->getBody(), $format);
$result_data = $this->serializer->decode((string) $response->getBody(), $format);
$logout_token = $result_data['logout_token'];

View File

@ -44,12 +44,12 @@ class HandlerFieldUserNameTest extends UserTestBase {
$anon_name = $this->config('user.settings')->get('anonymous');
$view->result[0]->_entity->setUsername('');
$view->result[0]->_entity->uid->value = 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->assertStringContainsString($anon_name, $render, 'For user 0 it should use the default anonymous name by default.');
$render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view, $new_user) {
$render = (string) $renderer->executeInRenderContext(new RenderContext(), function () use ($view, $new_user) {
return $view->field['name']->advancedRender($view->result[$new_user->id()]);
});
$this->assertStringContainsString($new_user->getDisplayName(), $render, 'If link to user is checked the username should be part of the output.');
@ -57,7 +57,7 @@ class HandlerFieldUserNameTest extends UserTestBase {
$view->field['name']->options['link_to_user'] = FALSE;
$view->field['name']->options['type'] = 'string';
$render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view, $new_user) {
$render = (string) $renderer->executeInRenderContext(new RenderContext(), function () use ($view, $new_user) {
return $view->field['name']->advancedRender($view->result[$new_user->id()]);
});
$this->assertEquals($new_user->getDisplayName(), $render, 'If the user is not linked the username should be printed out for a normal user.');
@ -77,7 +77,7 @@ class HandlerFieldUserNameTest extends UserTestBase {
$username = $this->randomMachineName();
$view->result[0]->_entity->setUsername($username);
$view->result[0]->_entity->uid->value = 1;
$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->assertStringContainsString($username, $render, 'If link to user is checked the username should be part of the output.');

View File

@ -128,7 +128,7 @@ class AreaTest extends ViewTestBase {
// Test we have the site:name token in the output.
$output = $view->preview();
$output = $this->container->get('renderer')->renderRoot($output);
$output = (string) $this->container->get('renderer')->renderRoot($output);
$expected = \Drupal::token()->replace('[site:name]');
$this->assertStringContainsString($expected, $output);
}

View File

@ -235,7 +235,7 @@ class FieldWebTest extends ViewTestBase {
// Tests that the suffix/prefix appears on the output.
$id_field->options['alter']['prefix'] = $prefix = $this->randomMachineName();
$id_field->options['alter']['suffix'] = $suffix = $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->assertSubString($output, $prefix);
@ -243,7 +243,7 @@ class FieldWebTest extends ViewTestBase {
unset($id_field->options['alter']['prefix']);
unset($id_field->options['alter']['suffix']);
$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, $path, 'Make sure that the path is part of the output');
@ -256,28 +256,28 @@ class FieldWebTest extends ViewTestBase {
$expected_result = Url::fromRoute('entity.node.canonical', ['node' => '123'], ['absolute' => $absolute])->toString();
$alter['absolute'] = $absolute;
$result = $renderer->executeInRenderContext(new RenderContext(), function () use ($id_field, $row) {
$result = (string) $renderer->executeInRenderContext(new RenderContext(), function () use ($id_field, $row) {
return $id_field->theme($row);
});
$this->assertSubString($result, $expected_result);
$expected_result = Url::fromRoute('entity.node.canonical', ['node' => '123'], ['fragment' => 'foo', 'absolute' => $absolute])->toString();
$alter['path'] = 'node/123#foo';
$result = $renderer->executeInRenderContext(new RenderContext(), function () use ($id_field, $row) {
$result = (string) $renderer->executeInRenderContext(new RenderContext(), function () use ($id_field, $row) {
return $id_field->theme($row);
});
$this->assertSubString($result, $expected_result);
$expected_result = Url::fromRoute('entity.node.canonical', ['node' => '123'], ['query' => ['foo' => NULL], 'absolute' => $absolute])->toString();
$alter['path'] = 'node/123?foo';
$result = $renderer->executeInRenderContext(new RenderContext(), function () use ($id_field, $row) {
$result = (string) $renderer->executeInRenderContext(new RenderContext(), function () use ($id_field, $row) {
return $id_field->theme($row);
});
$this->assertSubString($result, $expected_result);
$expected_result = Url::fromRoute('entity.node.canonical', ['node' => '123'], ['query' => ['foo' => 'bar', 'bar' => 'baz'], 'absolute' => $absolute])->toString();
$alter['path'] = 'node/123?foo=bar&bar=baz';
$result = $renderer->executeInRenderContext(new RenderContext(), function () use ($id_field, $row) {
$result = (string) $renderer->executeInRenderContext(new RenderContext(), function () use ($id_field, $row) {
return $id_field->theme($row);
});
$this->assertSubString(Html::decodeEntities($result), Html::decodeEntities($expected_result));
@ -286,14 +286,14 @@ class FieldWebTest extends ViewTestBase {
// $expected_result = Url::fromRoute('entity.node.canonical', ['node' => '123'], ['query' => ['foo' => NULL], 'fragment' => 'bar', 'absolute' => $absolute])->toString();
$expected_result = Url::fromUserInput('/node/123', ['query' => ['foo' => NULL], 'fragment' => 'bar', 'absolute' => $absolute])->toString();
$alter['path'] = 'node/123?foo#bar';
$result = $renderer->executeInRenderContext(new RenderContext(), function () use ($id_field, $row) {
$result = (string) $renderer->executeInRenderContext(new RenderContext(), function () use ($id_field, $row) {
return $id_field->theme($row);
});
$this->assertSubString(Html::decodeEntities($result), Html::decodeEntities($expected_result));
$expected_result = Url::fromRoute('<front>', [], ['absolute' => $absolute])->toString();
$alter['path'] = '<front>';
$result = $renderer->executeInRenderContext(new RenderContext(), function () use ($id_field, $row) {
$result = (string) $renderer->executeInRenderContext(new RenderContext(), function () use ($id_field, $row) {
return $id_field->theme($row);
});
$this->assertSubString($result, $expected_result);
@ -302,12 +302,12 @@ class FieldWebTest extends ViewTestBase {
// Tests the replace spaces with dashes feature.
$id_field->options['alter']['replace_spaces'] = TRUE;
$id_field->options['alter']['path'] = $path = $this->randomMachineName() . ' ' . $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->assertSubString($output, str_replace(' ', '-', $path));
$id_field->options['alter']['replace_spaces'] = FALSE;
$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);
});
// The URL has a space in it, so to check we have to decode the URL output.
@ -317,7 +317,7 @@ class FieldWebTest extends ViewTestBase {
// Switch on the external flag should output an external URL as well.
$id_field->options['alter']['external'] = TRUE;
$id_field->options['alter']['path'] = $path = 'www.example.com';
$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, 'http://www.example.com');
@ -325,7 +325,7 @@ class FieldWebTest extends ViewTestBase {
// Setup a not external URL, which shouldn't lead to an external URL.
$id_field->options['alter']['external'] = FALSE;
$id_field->options['alter']['path'] = $path = 'www.example.com';
$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, 'http://www.example.com');
@ -333,19 +333,19 @@ class FieldWebTest extends ViewTestBase {
// Tests the transforming of the case setting.
$id_field->options['alter']['path'] = $path = $this->randomMachineName();
$id_field->options['alter']['path_case'] = 'none';
$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, $path);
// Switch to uppercase and lowercase.
$id_field->options['alter']['path_case'] = 'upper';
$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, strtoupper($path));
$id_field->options['alter']['path_case'] = 'lower';
$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, strtolower($path));
@ -353,13 +353,13 @@ class FieldWebTest extends ViewTestBase {
// Switch to ucfirst and ucwords.
$id_field->options['alter']['path_case'] = 'ucfirst';
$id_field->options['alter']['path'] = 'drupal has a great community';
$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, UrlHelper::encodePath('Drupal has a great community'));
$id_field->options['alter']['path_case'] = 'ucwords';
$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, UrlHelper::encodePath('Drupal Has A Great Community'));
@ -368,7 +368,7 @@ class FieldWebTest extends ViewTestBase {
// Tests the link_class setting and see whether it actually exists in the
// output.
$id_field->options['alter']['link_class'] = $class = $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);
});
$elements = $this->xpathContent($output, '//a[contains(@class, :class)]', [':class' => $class]);
@ -378,7 +378,7 @@ class FieldWebTest extends ViewTestBase {
// Tests the alt setting.
$id_field->options['alter']['alt'] = $rel = $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);
});
$elements = $this->xpathContent($output, '//a[contains(@title, :alt)]', [':alt' => $rel]);
@ -387,7 +387,7 @@ class FieldWebTest extends ViewTestBase {
// Tests the rel setting.
$id_field->options['alter']['rel'] = $rel = $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);
});
$elements = $this->xpathContent($output, '//a[contains(@rel, :rel)]', [':rel' => $rel]);
@ -396,7 +396,7 @@ class FieldWebTest extends ViewTestBase {
// Tests the target setting.
$id_field->options['alter']['target'] = $target = $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);
});
$elements = $this->xpathContent($output, '//a[contains(@target, :target)]', [':target' => $target]);
@ -420,13 +420,13 @@ class FieldWebTest extends ViewTestBase {
// Setup some kind of label by default.
$id_field->options['label'] = $this->randomMachineName();
$output = $view->preview();
$output = $renderer->renderRoot($output);
$output = (string) $renderer->renderRoot($output);
$this->assertEmpty($this->xpathContent($output, '//div[contains(@class, :class)]', [':class' => 'field-content']));
$this->assertEmpty($this->xpathContent($output, '//div[contains(@class, :class)]', [':class' => 'field__label']));
$id_field->options['element_default_classes'] = TRUE;
$output = $view->preview();
$output = $renderer->renderRoot($output);
$output = (string) $renderer->renderRoot($output);
// Per default the label and the element of the field are spans.
$this->assertNotEmpty($this->xpathContent($output, '//span[contains(@class, :class)]', [':class' => 'field-content']));
$this->assertNotEmpty($this->xpathContent($output, '//span[contains(@class, :class)]', [':class' => 'views-label']));
@ -442,13 +442,13 @@ class FieldWebTest extends ViewTestBase {
// Set a custom wrapper element css class.
$id_field->options['element_wrapper_class'] = $random_class;
$output = $view->preview();
$output = $renderer->renderRoot($output);
$output = (string) $renderer->renderRoot($output);
$this->assertNotEmpty($this->xpathContent($output, "//{$element_type}[contains(@class, :class)]", [':class' => $random_class]));
// Set no custom css class.
$id_field->options['element_wrapper_class'] = '';
$output = $view->preview();
$output = $renderer->renderRoot($output);
$output = (string) $renderer->renderRoot($output);
$this->assertEmpty($this->xpathContent($output, "//{$element_type}[contains(@class, :class)]", [':class' => $random_class]));
$this->assertNotEmpty($this->xpathContent($output, "//li[contains(@class, views-row)]/{$element_type}"));
}
@ -462,13 +462,13 @@ class FieldWebTest extends ViewTestBase {
// Set a custom label element css class.
$id_field->options['element_label_class'] = $random_class;
$output = $view->preview();
$output = $renderer->renderRoot($output);
$output = (string) $renderer->renderRoot($output);
$this->assertNotEmpty($this->xpathContent($output, "//li[contains(@class, views-row)]//{$element_type}[contains(@class, :class)]", [':class' => $random_class]));
// Set no custom css class.
$id_field->options['element_label_class'] = '';
$output = $view->preview();
$output = $renderer->renderRoot($output);
$output = (string) $renderer->renderRoot($output);
$this->assertEmpty($this->xpathContent($output, "//li[contains(@class, views-row)]//{$element_type}[contains(@class, :class)]", [':class' => $random_class]));
$this->assertNotEmpty($this->xpathContent($output, "//li[contains(@class, views-row)]//{$element_type}"));
}
@ -482,13 +482,13 @@ class FieldWebTest extends ViewTestBase {
// Set a custom label element css class.
$id_field->options['element_class'] = $random_class;
$output = $view->preview();
$output = $renderer->renderRoot($output);
$output = (string) $renderer->renderRoot($output);
$this->assertNotEmpty($this->xpathContent($output, "//li[contains(@class, views-row)]//div[contains(@class, views-field)]//{$element_type}[contains(@class, :class)]", [':class' => $random_class]));
// Set no custom css class.
$id_field->options['element_class'] = '';
$output = $view->preview();
$output = $renderer->renderRoot($output);
$output = (string) $renderer->renderRoot($output);
$this->assertEmpty($this->xpathContent($output, "//li[contains(@class, views-row)]//div[contains(@class, views-field)]//{$element_type}[contains(@class, :class)]", [':class' => $random_class]));
$this->assertNotEmpty($this->xpathContent($output, "//li[contains(@class, views-row)]//div[contains(@class, views-field)]//{$element_type}"));
}
@ -534,7 +534,7 @@ class FieldWebTest extends ViewTestBase {
$row = $view->result[0];
$name_field->options['alter']['strip_tags'] = TRUE;
$output = $renderer->executeInRenderContext(new RenderContext(), function () use ($name_field, $row) {
$output = (string) $renderer->executeInRenderContext(new RenderContext(), function () use ($name_field, $row) {
return $name_field->advancedRender($row);
});
$this->assertSubString($output, $random_text, 'Find text without html if stripping of views field output is enabled.');
@ -542,14 +542,14 @@ class FieldWebTest extends ViewTestBase {
// Tests preserving of html tags.
$name_field->options['alter']['preserve_tags'] = '<div>';
$output = $renderer->executeInRenderContext(new RenderContext(), function () use ($name_field, $row) {
$output = (string) $renderer->executeInRenderContext(new RenderContext(), function () use ($name_field, $row) {
return $name_field->advancedRender($row);
});
$this->assertSubString($output, $random_text, 'Find text without html if stripping of views field output is enabled but a div is allowed.');
$this->assertSubString($output, $html_text, 'Find text with the html if stripping of views field output is enabled but a div is allowed.');
$name_field->options['alter']['strip_tags'] = FALSE;
$output = $renderer->executeInRenderContext(new RenderContext(), function () use ($name_field, $row) {
$output = (string) $renderer->executeInRenderContext(new RenderContext(), function () use ($name_field, $row) {
return $name_field->advancedRender($row);
});
$this->assertSubString($output, $random_text, 'Find text without html if stripping of views field output is disabled.');
@ -560,7 +560,7 @@ class FieldWebTest extends ViewTestBase {
$views_test_data_name = $row->views_test_data_name;
$row->views_test_data_name = ' ' . $views_test_data_name . ' ';
$name_field->options['alter']['trim_whitespace'] = TRUE;
$output = $renderer->executeInRenderContext(new RenderContext(), function () use ($name_field, $row) {
$output = (string) $renderer->executeInRenderContext(new RenderContext(), function () use ($name_field, $row) {
return $name_field->advancedRender($row);
});
@ -568,7 +568,7 @@ class FieldWebTest extends ViewTestBase {
$this->assertNotSubString($output, $row->views_test_data_name, 'Make sure the untrimmed text can be found if trimming is enabled.');
$name_field->options['alter']['trim_whitespace'] = FALSE;
$output = $renderer->executeInRenderContext(new RenderContext(), function () use ($name_field, $row) {
$output = (string) $renderer->executeInRenderContext(new RenderContext(), function () use ($name_field, $row) {
return $name_field->advancedRender($row);
});
$this->assertSubString($output, $views_test_data_name, 'Make sure the trimmed text can be found if trimming is disabled.');
@ -583,14 +583,14 @@ class FieldWebTest extends ViewTestBase {
$name_field->options['alter']['max_length'] = 5;
$trimmed_name = mb_substr($row->views_test_data_name, 0, 5);
$output = $renderer->executeInRenderContext(new RenderContext(), function () use ($name_field, $row) {
$output = (string) $renderer->executeInRenderContext(new RenderContext(), function () use ($name_field, $row) {
return $name_field->advancedRender($row);
});
$this->assertSubString($output, $trimmed_name, "Make sure the trimmed output ($trimmed_name) appears in the rendered output ($output).");
$this->assertNotSubString($output, $row->views_test_data_name, "Make sure the untrimmed value ($row->views_test_data_name) shouldn't appear in the rendered output ($output).");
$name_field->options['alter']['max_length'] = 9;
$output = $renderer->executeInRenderContext(new RenderContext(), function () use ($name_field, $row) {
$output = (string) $renderer->executeInRenderContext(new RenderContext(), function () use ($name_field, $row) {
return $name_field->advancedRender($row);
});
$this->assertSubString($output, $trimmed_name, "Make sure the untrimmed ($trimmed_name) output appears in the rendered output ($output).");
@ -632,7 +632,7 @@ class FieldWebTest extends ViewTestBase {
foreach ($tuples as $tuple) {
$row->views_test_data_name = $tuple['value'];
$output = $renderer->executeInRenderContext(new RenderContext(), function () use ($name_field, $row) {
$output = (string) $renderer->executeInRenderContext(new RenderContext(), function () use ($name_field, $row) {
return $name_field->advancedRender($row);
});
@ -651,14 +651,14 @@ class FieldWebTest extends ViewTestBase {
$name_field->options['alter']['more_link_text'] = $more_text = $this->randomMachineName();
$name_field->options['alter']['more_link_path'] = $more_path = $this->randomMachineName();
$output = $renderer->executeInRenderContext(new RenderContext(), function () use ($name_field, $row) {
$output = (string) $renderer->executeInRenderContext(new RenderContext(), function () use ($name_field, $row) {
return $name_field->advancedRender($row);
});
$this->assertSubString($output, $more_text, 'Make sure a read more text is displayed if the output got trimmed');
$this->assertNotEmpty($this->xpathContent($output, '//a[contains(@href, :path)]', [':path' => $more_path]), 'Make sure the read more link points to the right destination.');
$name_field->options['alter']['more_link'] = FALSE;
$output = $renderer->executeInRenderContext(new RenderContext(), function () use ($name_field, $row) {
$output = (string) $renderer->executeInRenderContext(new RenderContext(), function () use ($name_field, $row) {
return $name_field->advancedRender($row);
});
$this->assertNotSubString($output, $more_text, 'Make sure no read more text appears.');
@ -667,12 +667,12 @@ class FieldWebTest extends ViewTestBase {
// Check for the ellipses.
$row->views_test_data_name = $this->randomMachineName(8);
$name_field->options['alter']['max_length'] = 5;
$output = $renderer->executeInRenderContext(new RenderContext(), function () use ($name_field, $row) {
$output = (string) $renderer->executeInRenderContext(new RenderContext(), function () use ($name_field, $row) {
return $name_field->advancedRender($row);
});
$this->assertSubString($output, '…', 'An ellipsis should appear if the output is trimmed');
$name_field->options['alter']['max_length'] = 10;
$output = $renderer->executeInRenderContext(new RenderContext(), function () use ($name_field, $row) {
$output = (string) $renderer->executeInRenderContext(new RenderContext(), function () use ($name_field, $row) {
return $name_field->advancedRender($row);
});
$this->assertNotSubString($output, '…', 'No ellipsis should appear if the output is not trimmed');

View File

@ -63,13 +63,13 @@ class DisplayPageWebTest extends ViewTestBase {
$this->assertSession()->statusCodeEquals(200);
$this->assertCacheContexts(['languages:language_interface', 'route', 'theme', 'url']);
$this->assertSession()->elementsCount('xpath', $xpath, 1);
$this->assertSession()->elementTextEquals('xpath', $xpath, 1);
$this->assertSession()->elementTextEquals('xpath', $xpath, '1');
// Ensure that just the filtered entry is returned.
$this->drupalGet('test_route_with_suffix/1/suffix');
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->elementsCount('xpath', $xpath, 1);
$this->assertSession()->elementTextEquals('xpath', $xpath, 1);
$this->assertSession()->elementTextEquals('xpath', $xpath, '1');
// Ensure that no result is returned.
$this->drupalGet('test_route_with_suffix_and_argument/1/suffix/2');
@ -80,13 +80,13 @@ class DisplayPageWebTest extends ViewTestBase {
$this->drupalGet('test_route_with_suffix_and_argument/1/suffix/1');
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->elementsCount('xpath', $xpath, 1);
$this->assertSession()->elementTextEquals('xpath', $xpath, 1);
$this->assertSession()->elementTextEquals('xpath', $xpath, '1');
// Ensure that just the filtered entry is returned.
$this->drupalGet('test_route_with_long_argument/1');
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->elementsCount('xpath', $xpath, 1);
$this->assertSession()->elementTextEquals('xpath', $xpath, 1);
$this->assertSession()->elementTextEquals('xpath', $xpath, '1');
}
/**

View File

@ -111,7 +111,7 @@ class DisplayTest extends ViewTestBase {
$view->style_plugin->setUsesRowPlugin(FALSE);
$output = $view->preview();
$output = $renderer->renderRoot($output);
$output = (string) $renderer->renderRoot($output);
$this->assertStringContainsString('<h1></h1>', $output, 'An empty value for test_option found in output.');
@ -120,7 +120,7 @@ class DisplayTest extends ViewTestBase {
$view->save();
$output = $view->preview();
$output = $renderer->renderRoot($output);
$output = (string) $renderer->renderRoot($output);
// Test we have our custom <h1> tag in the output of the view.
$this->assertStringContainsString('<h1>Test option title</h1>', $output, 'The test_option value found in display output title.');
@ -219,7 +219,7 @@ class DisplayTest extends ViewTestBase {
$view->display_handler->setOption('link_url', 'node');
$this->executeView($view);
$output = $view->preview();
$output = $renderer->renderRoot($output);
$output = (string) $renderer->renderRoot($output);
$this->assertStringContainsString('/node', $output, 'The read more link with href "/node" was found.');
// Test more link with leading slash.
@ -227,7 +227,7 @@ class DisplayTest extends ViewTestBase {
$view->display_handler->setOption('link_url', '/node');
$this->executeView($view);
$output = $view->preview();
$output = $renderer->renderRoot($output);
$output = (string) $renderer->renderRoot($output);
$this->assertStringContainsString('/node', $output, 'The read more link with href "/node" was found.');
// Test more link with absolute URL.
@ -235,7 +235,7 @@ class DisplayTest extends ViewTestBase {
$view->display_handler->setOption('link_url', 'http://example.com');
$this->executeView($view);
$output = $view->preview();
$output = $renderer->renderRoot($output);
$output = (string) $renderer->renderRoot($output);
$this->assertStringContainsString('http://example.com', $output, 'The read more link with href "http://example.com" was found.');
// Test more link with query parameters in the URL.
@ -243,7 +243,7 @@ class DisplayTest extends ViewTestBase {
$view->display_handler->setOption('link_url', 'node?page=1&foo=bar');
$this->executeView($view);
$output = $view->preview();
$output = $renderer->renderRoot($output);
$output = (string) $renderer->renderRoot($output);
$this->assertStringContainsString('/node?page=1&amp;foo=bar', $output, 'The read more link with href "/node?page=1&foo=bar" was found.');
// Test more link with fragment in the URL.
@ -251,7 +251,7 @@ class DisplayTest extends ViewTestBase {
$view->display_handler->setOption('link_url', 'node#target');
$this->executeView($view);
$output = $view->preview();
$output = $renderer->renderRoot($output);
$output = (string) $renderer->renderRoot($output);
$this->assertStringContainsString('/node#target', $output, 'The read more link with href "/node#target" was found.');
// Test more link with arguments.
@ -264,7 +264,7 @@ class DisplayTest extends ViewTestBase {
$view->setArguments([22]);
$this->executeView($view);
$output = $view->preview();
$output = $renderer->renderRoot($output);
$output = (string) $renderer->renderRoot($output);
$this->assertStringContainsString('/node?date=22&amp;foo=bar', $output, 'The read more link with href "/node?date=22&foo=bar" was found.');
// Test more link with 1 dimension array query parameters with arguments.
@ -277,7 +277,7 @@ class DisplayTest extends ViewTestBase {
$view->setArguments([22]);
$this->executeView($view);
$output = $view->preview();
$output = $renderer->renderRoot($output);
$output = (string) $renderer->renderRoot($output);
$this->assertStringContainsString('/node?f%5B0%5D=foo%3Abar&amp;f%5B1%5D=foo%3A22', $output, 'The read more link with href "/node?f[0]=foo:bar&f[1]=foo:22" was found.');
// Test more link with arguments in path.
@ -285,7 +285,7 @@ class DisplayTest extends ViewTestBase {
$view->setArguments([22]);
$this->executeView($view);
$output = $view->preview();
$output = $renderer->renderRoot($output);
$output = (string) $renderer->renderRoot($output);
$this->assertStringContainsString('/node/22?date=22&amp;foo=bar', $output, 'The read more link with href "/node/22?date=22&foo=bar" was found.');
// Test more link with arguments in fragment.
@ -293,7 +293,7 @@ class DisplayTest extends ViewTestBase {
$view->setArguments([22]);
$this->executeView($view);
$output = $view->preview();
$output = $renderer->renderRoot($output);
$output = (string) $renderer->renderRoot($output);
$this->assertStringContainsString('/node?date=22&amp;foo=bar#22', $output, 'The read more link with href "/node?date=22&foo=bar#22" was found.');
}

View File

@ -425,7 +425,7 @@ class PagerTest extends ViewTestBase {
$view->setAjaxEnabled(TRUE);
$view->pager = NULL;
$output = $view->render();
$output = \Drupal::service('renderer')->renderRoot($output);
$output = (string) \Drupal::service('renderer')->renderRoot($output);
$this->assertEquals(0, preg_match('/<ul class="pager">/', $output), 'The pager is not rendered.');
}