From df70716e5a60b82a846e0d557ee2d72eb5af41f7 Mon Sep 17 00:00:00 2001 From: Dave Long Date: Sat, 25 Nov 2023 11:41:15 +0000 Subject: [PATCH] Issue #3402293 by dww, mstrelan, smustgrave: Fix strict type errors: Convert FormattableMarkup to strings (simple replacement) in core/modules/*/tests/src/Kernel/* --- .../dblog/tests/src/Kernel/DbLogTest.php | 8 ++++---- .../EntityReferenceFormatterTest.php | 5 ++--- .../src/Kernel/FieldAttachStorageTest.php | 9 ++++----- .../tests/src/Kernel/FieldDataCountTest.php | 3 +-- .../src/Kernel/FieldImportDeleteTest.php | 11 +++++------ .../src/Kernel/FieldTypePluginManagerTest.php | 9 ++++----- .../tests/src/Kernel/TranslationTest.php | 7 +++---- .../filter/tests/src/Kernel/FilterAPITest.php | 3 +-- .../tests/src/Kernel/FilterCrudTest.php | 11 +++++------ .../tests/src/Kernel/MediaTranslationTest.php | 11 +++++------ .../src/Kernel/MigrationLabelExistTest.php | 3 +-- .../tests/src/Kernel/mysql/DbDumpTest.php | 7 +++---- .../src/Kernel/NodeAccessRecordsTest.php | 3 +-- .../tests/src/Kernel/NodeFieldAccessTest.php | 19 +++++++++---------- .../tests/src/Kernel/NodeTokenReplaceTest.php | 3 +-- .../src/Kernel/Block/SystemMenuBlockTest.php | 5 ++--- .../tests/src/Kernel/Common/UrlTest.php | 17 ++++++++--------- .../Kernel/Extension/ModuleHandlerTest.php | 3 +-- .../tests/src/Kernel/Theme/FunctionsTest.php | 6 +++--- .../tests/src/Kernel/Theme/ThemeTest.php | 3 +-- .../Kernel/Token/TokenReplaceKernelTest.php | 7 +++---- .../tests/src/Kernel/LoadMultipleTest.php | 3 +-- .../tests/src/Kernel/TextFormatterTest.php | 3 +-- .../text/tests/src/Kernel/TextSummaryTest.php | 3 +-- .../src/Kernel/Handler/AreaEntityTest.php | 3 +-- .../src/Kernel/Handler/FieldCounterTest.php | 13 ++++++------- .../views/tests/src/Kernel/ModuleTest.php | 2 +- .../src/Kernel/Plugin/DisplayExtenderTest.php | 3 +-- .../src/Kernel/Plugin/StyleMappingTest.php | 3 +-- .../tests/src/Kernel/QueryGroupByTest.php | 6 +++--- .../tests/src/Kernel/TokenReplaceTest.php | 7 +++---- .../tests/src/Kernel/ViewExecutableTest.php | 5 ++--- .../tests/src/Kernel/ViewStorageTest.php | 19 +++++++++---------- .../views/tests/src/Kernel/ViewsHooksTest.php | 5 ++--- 34 files changed, 99 insertions(+), 129 deletions(-) diff --git a/core/modules/dblog/tests/src/Kernel/DbLogTest.php b/core/modules/dblog/tests/src/Kernel/DbLogTest.php index 08d4c371734..59283e795f3 100644 --- a/core/modules/dblog/tests/src/Kernel/DbLogTest.php +++ b/core/modules/dblog/tests/src/Kernel/DbLogTest.php @@ -2,7 +2,6 @@ namespace Drupal\Tests\dblog\Kernel; -use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Database\Database; use Drupal\KernelTests\KernelTestBase; use Drupal\Tests\dblog\Functional\FakeLogEntries; @@ -40,7 +39,7 @@ class DbLogTest extends KernelTestBase { $this->generateLogEntries($row_limit + 10); // Verify that the database log row count exceeds the row limit. $count = Database::getConnection()->select('watchdog')->countQuery()->execute()->fetchField(); - $this->assertGreaterThan($row_limit, $count, new FormattableMarkup('Dblog row count of @count exceeds row limit of @limit', ['@count' => $count, '@limit' => $row_limit])); + $this->assertGreaterThan($row_limit, $count, "Dblog row count of $count exceeds row limit of $row_limit"); // Get the number of enabled modules. Cron adds a log entry for each module. $implementation_count = 0; @@ -52,12 +51,13 @@ class DbLogTest extends KernelTestBase { ); $cron_detailed_count = $this->runCron(); - $this->assertEquals($implementation_count + 2, $cron_detailed_count, new FormattableMarkup('Cron added @count of @expected new log entries', ['@count' => $cron_detailed_count, '@expected' => $implementation_count + 2])); + $expected_count = $implementation_count + 2; + $this->assertEquals($expected_count, $cron_detailed_count, "Cron added $cron_detailed_count of $expected_count new log entries"); // Test disabling of detailed cron logging. $this->config('system.cron')->set('logging', 0)->save(); $cron_count = $this->runCron(); - $this->assertEquals(1, $cron_count, new FormattableMarkup('Cron added @count of @expected new log entries', ['@count' => $cron_count, '@expected' => 1])); + $this->assertEquals(1, $cron_count, "Cron added $cron_count of 1 new log entries"); } /** diff --git a/core/modules/field/tests/src/Kernel/EntityReference/EntityReferenceFormatterTest.php b/core/modules/field/tests/src/Kernel/EntityReference/EntityReferenceFormatterTest.php index 8cc81031cbe..804f5ab97ec 100644 --- a/core/modules/field/tests/src/Kernel/EntityReference/EntityReferenceFormatterTest.php +++ b/core/modules/field/tests/src/Kernel/EntityReference/EntityReferenceFormatterTest.php @@ -2,7 +2,6 @@ namespace Drupal\Tests\field\Kernel\EntityReference; -use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Cache\Cache; use Drupal\Core\Cache\CacheableMetadata; use Drupal\Core\Field\FieldStorageDefinitionInterface; @@ -163,7 +162,7 @@ class EntityReferenceFormatterTest extends EntityKernelTestBase { ->view($referencing_entity, 'default'); // Verify the un-accessible item still exists. - $this->assertEquals($this->referencedEntity->id(), $referencing_entity->{$field_name}->target_id, new FormattableMarkup('The un-accessible item still exists after @name formatter was executed.', ['@name' => $name])); + $this->assertEquals($this->referencedEntity->id(), $referencing_entity->{$field_name}->target_id, "The un-accessible item still exists after $name formatter was executed."); } } @@ -215,7 +214,7 @@ class EntityReferenceFormatterTest extends EntityKernelTestBase { $this->assertSame('default | ' . $this->referencedEntity->label() . $expected_rendered_name_field_1 . $expected_rendered_body_field_1, (string) $build[0]['#markup'], sprintf('The markup returned by the %s formatter is correct for an item with a saved entity.', $formatter)); $expected_cache_tags = Cache::mergeTags(\Drupal::entityTypeManager()->getViewBuilder($this->entityType)->getCacheTags(), $this->referencedEntity->getCacheTags()); $expected_cache_tags = Cache::mergeTags($expected_cache_tags, FilterFormat::load('full_html')->getCacheTags()); - $this->assertEquals($expected_cache_tags, $build[0]['#cache']['tags'], new FormattableMarkup('The @formatter formatter has the expected cache tags.', ['@formatter' => $formatter])); + $this->assertEquals($expected_cache_tags, $build[0]['#cache']['tags'], "The $formatter formatter has the expected cache tags."); // Test the second field item. $expected_rendered_name_field_2 = ' diff --git a/core/modules/field/tests/src/Kernel/FieldAttachStorageTest.php b/core/modules/field/tests/src/Kernel/FieldAttachStorageTest.php index 844a33c173c..16c43b86281 100644 --- a/core/modules/field/tests/src/Kernel/FieldAttachStorageTest.php +++ b/core/modules/field/tests/src/Kernel/FieldAttachStorageTest.php @@ -2,7 +2,6 @@ namespace Drupal\Tests\field\Kernel; -use Drupal\Component\Render\FormattableMarkup; use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldStorageConfig; @@ -59,17 +58,17 @@ class FieldAttachStorageTest extends FieldKernelTestBase { $this->assertCount($cardinality, $entity->{$this->fieldTestData->field_name}, 'Current revision: expected number of values'); for ($delta = 0; $delta < $cardinality; $delta++) { // The field value loaded matches the one inserted or updated. - $this->assertEquals($values[$current_revision][$delta]['value'], $entity->{$this->fieldTestData->field_name}[$delta]->value, new FormattableMarkup('Current revision: expected value %delta was found.', ['%delta' => $delta])); + $this->assertEquals($values[$current_revision][$delta]['value'], $entity->{$this->fieldTestData->field_name}[$delta]->value, "Current revision: expected value $delta was found."); } // Confirm each revision loads the correct data. foreach (array_keys($values) as $revision_id) { $entity = $storage->loadRevision($revision_id); // Number of values per field loaded equals the field cardinality. - $this->assertCount($cardinality, $entity->{$this->fieldTestData->field_name}, new FormattableMarkup('Revision %revision_id: expected number of values.', ['%revision_id' => $revision_id])); + $this->assertCount($cardinality, $entity->{$this->fieldTestData->field_name}, "Revision $revision_id: expected number of values."); for ($delta = 0; $delta < $cardinality; $delta++) { // The field value loaded matches the one inserted or updated. - $this->assertEquals($values[$revision_id][$delta]['value'], $entity->{$this->fieldTestData->field_name}[$delta]->value, new FormattableMarkup('Revision %revision_id: expected value %delta was found.', ['%revision_id' => $revision_id, '%delta' => $delta])); + $this->assertEquals($values[$revision_id][$delta]['value'], $entity->{$this->fieldTestData->field_name}[$delta]->value, "Revision $revision_id: expected value $delta was found."); } } } @@ -140,7 +139,7 @@ class FieldAttachStorageTest extends FieldKernelTestBase { continue; } // The field value loaded matches the one inserted. - $this->assertEquals($values[$index][$field_name], $entity->{$field_name}->value, new FormattableMarkup('Entity %index: expected value was found.', ['%index' => $index])); + $this->assertEquals($values[$index][$field_name], $entity->{$field_name}->value, "Entity $index: expected value was found."); } } } diff --git a/core/modules/field/tests/src/Kernel/FieldDataCountTest.php b/core/modules/field/tests/src/Kernel/FieldDataCountTest.php index dc99bf4a5c1..837b0b36332 100644 --- a/core/modules/field/tests/src/Kernel/FieldDataCountTest.php +++ b/core/modules/field/tests/src/Kernel/FieldDataCountTest.php @@ -2,7 +2,6 @@ namespace Drupal\Tests\field\Kernel; -use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Database\Database; use Drupal\Core\Entity\Sql\SqlContentEntityStorage; use Drupal\entity_test\Entity\EntityTest; @@ -139,7 +138,7 @@ class FieldDataCountTest extends FieldKernelTestBase { /** @var \Drupal\Core\Entity\RevisionableStorageInterface $storage */ $storage = $this->container->get('entity_type.manager')->getStorage($entity_type); $entity = $storage->loadRevision($first_revision); - $this->assertCount($cardinality, $entity->{$this->fieldTestData->field_name_2}, new FormattableMarkup('Revision %revision_id: expected number of values.', ['%revision_id' => $first_revision])); + $this->assertCount($cardinality, $entity->{$this->fieldTestData->field_name_2}, "Revision $first_revision: expected number of values."); } /** diff --git a/core/modules/field/tests/src/Kernel/FieldImportDeleteTest.php b/core/modules/field/tests/src/Kernel/FieldImportDeleteTest.php index 10a972abc5c..fa756f535e9 100644 --- a/core/modules/field/tests/src/Kernel/FieldImportDeleteTest.php +++ b/core/modules/field/tests/src/Kernel/FieldImportDeleteTest.php @@ -2,7 +2,6 @@ namespace Drupal\Tests\field\Kernel; -use Drupal\Component\Render\FormattableMarkup; use Drupal\entity_test\Entity\EntityTest; use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldStorageConfig; @@ -69,11 +68,11 @@ class FieldImportDeleteTest extends FieldKernelTestBase { $active = $this->container->get('config.storage'); $sync = $this->container->get('config.storage.sync'); $this->copyConfig($active, $sync); - $this->assertTrue($sync->delete($field_storage_config_name), new FormattableMarkup('Deleted field storage: @field_storage', ['@field_storage' => $field_storage_config_name])); - $this->assertTrue($sync->delete($field_storage_config_name_2), new FormattableMarkup('Deleted field storage: @field_storage', ['@field_storage' => $field_storage_config_name_2])); - $this->assertTrue($sync->delete($field_config_name), new FormattableMarkup('Deleted field: @field', ['@field' => $field_config_name])); - $this->assertTrue($sync->delete($field_config_name_2a), new FormattableMarkup('Deleted field: @field', ['@field' => $field_config_name_2a])); - $this->assertTrue($sync->delete($field_config_name_2b), new FormattableMarkup('Deleted field: @field', ['@field' => $field_config_name_2b])); + $this->assertTrue($sync->delete($field_storage_config_name), "Deleted field storage: $field_storage_config_name"); + $this->assertTrue($sync->delete($field_storage_config_name_2), "Deleted field storage: $field_storage_config_name_2"); + $this->assertTrue($sync->delete($field_config_name), "Deleted field: $field_config_name"); + $this->assertTrue($sync->delete($field_config_name_2a), "Deleted field: $field_config_name_2a"); + $this->assertTrue($sync->delete($field_config_name_2b), "Deleted field: $field_config_name_2b"); $deletes = $this->configImporter()->getUnprocessedConfiguration('delete'); $this->assertCount(5, $deletes, 'Importing configuration will delete 3 fields and 2 field storages.'); diff --git a/core/modules/field/tests/src/Kernel/FieldTypePluginManagerTest.php b/core/modules/field/tests/src/Kernel/FieldTypePluginManagerTest.php index f905cd750ee..73b769836b2 100644 --- a/core/modules/field/tests/src/Kernel/FieldTypePluginManagerTest.php +++ b/core/modules/field/tests/src/Kernel/FieldTypePluginManagerTest.php @@ -2,7 +2,6 @@ namespace Drupal\Tests\field\Kernel; -use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Extension\ExtensionDiscovery; use Drupal\Core\Field\BaseFieldDefinition; use Drupal\entity_test\Entity\EntityTest; @@ -21,8 +20,8 @@ class FieldTypePluginManagerTest extends FieldKernelTestBase { $field_type_manager = \Drupal::service('plugin.manager.field.field_type'); foreach (['test_field', 'shape', 'hidden_test_field'] as $type) { $definition = $field_type_manager->getDefinition($type); - $this->assertSame($field_type_manager->getDefaultStorageSettings($type), $definition['class']::defaultStorageSettings(), new FormattableMarkup("%type storage settings were returned", ['%type' => $type])); - $this->assertSame($field_type_manager->getDefaultFieldSettings($type), $definition['class']::defaultFieldSettings(), new FormattableMarkup(" %type field settings were returned", ['%type' => $type])); + $this->assertSame($field_type_manager->getDefaultStorageSettings($type), $definition['class']::defaultStorageSettings(), "$type storage settings were returned"); + $this->assertSame($field_type_manager->getDefaultFieldSettings($type), $definition['class']::defaultFieldSettings(), "$type field settings were returned"); } } @@ -49,7 +48,7 @@ class FieldTypePluginManagerTest extends FieldKernelTestBase { $instance = $field_type_manager->createInstance($type, $configuration); $this->assertInstanceOf($class, $instance); - $this->assertEquals($field_name, $instance->getName(), new FormattableMarkup('Instance name is @name', ['@name' => $field_name])); + $this->assertEquals($field_name, $instance->getName(), "Instance name is $field_name"); } } @@ -80,7 +79,7 @@ class FieldTypePluginManagerTest extends FieldKernelTestBase { $instance = $field_type_manager->createInstance($type, $configuration); $this->assertInstanceOf($class, $instance); - $this->assertEquals($field_name, $instance->getName(), new FormattableMarkup('Instance name is @name', ['@name' => $field_name])); + $this->assertEquals($field_name, $instance->getName(), "Instance name is $field_name"); $this->assertEquals('Jenny', $instance->getFieldDefinition()->getLabel(), 'Instance label is Jenny'); $this->assertEquals([['value' => 8675309]], $instance->getFieldDefinition()->getDefaultValue($entity), 'Instance default_value is 8675309'); } diff --git a/core/modules/field/tests/src/Kernel/TranslationTest.php b/core/modules/field/tests/src/Kernel/TranslationTest.php index 8e9dc31bb28..f6308cc0a7a 100644 --- a/core/modules/field/tests/src/Kernel/TranslationTest.php +++ b/core/modules/field/tests/src/Kernel/TranslationTest.php @@ -2,7 +2,6 @@ namespace Drupal\Tests\field\Kernel; -use Drupal\Component\Render\FormattableMarkup; use Drupal\field\Entity\FieldConfig; use Drupal\language\Entity\ConfigurableLanguage; use Drupal\field\Entity\FieldStorageConfig; @@ -137,7 +136,7 @@ class TranslationTest extends FieldKernelTestBase { foreach ($items as $delta => $item) { $result = $result && $item['value'] == $entity->getTranslation($langcode)->{$this->fieldName}[$delta]->value; } - $this->assertTrue($result, new FormattableMarkup('%language translation correctly handled.', ['%language' => $langcode])); + $this->assertTrue($result, "$langcode translation correctly handled."); } // Test default values. @@ -174,7 +173,7 @@ class TranslationTest extends FieldKernelTestBase { // @todo Test every translation once the Entity Translation API allows for // multilingual defaults. $langcode = $entity->language()->getId(); - $this->assertEquals($field->getDefaultValueLiteral(), $entity->getTranslation($langcode)->{$field_name_default}->getValue(), new FormattableMarkup('Default value correctly populated for language %language.', ['%language' => $langcode])); + $this->assertEquals($field->getDefaultValueLiteral(), $entity->getTranslation($langcode)->{$field_name_default}->getValue(), "Default value correctly populated for language $langcode."); $storage = \Drupal::entityTypeManager()->getStorage($entity_type_id); // Check that explicit empty values are not overridden with default values. @@ -190,7 +189,7 @@ class TranslationTest extends FieldKernelTestBase { } foreach ($entity->getTranslationLanguages() as $langcode => $language) { - $this->assertEquals([], $entity->getTranslation($langcode)->{$field_name_default}->getValue(), new FormattableMarkup('Empty value correctly populated for language %language.', ['%language' => $langcode])); + $this->assertEquals([], $entity->getTranslation($langcode)->{$field_name_default}->getValue(), "Empty value correctly populated for language $langcode."); } } } diff --git a/core/modules/filter/tests/src/Kernel/FilterAPITest.php b/core/modules/filter/tests/src/Kernel/FilterAPITest.php index 97cc287d7b8..09a237e441f 100644 --- a/core/modules/filter/tests/src/Kernel/FilterAPITest.php +++ b/core/modules/filter/tests/src/Kernel/FilterAPITest.php @@ -2,7 +2,6 @@ namespace Drupal\Tests\filter\Kernel; -use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Session\AnonymousUserSession; use Drupal\Core\TypedData\OptionsProviderInterface; @@ -454,7 +453,7 @@ class FilterAPITest extends EntityKernelTestBase { break; } } - $this->assertTrue($filter_format_violation_found, new FormattableMarkup('Validation violation for invalid value "%invalid_value" found', ['%invalid_value' => $invalid_value])); + $this->assertTrue($filter_format_violation_found, 'Validation violation for invalid value "' . $invalid_value . '" found'); } /** diff --git a/core/modules/filter/tests/src/Kernel/FilterCrudTest.php b/core/modules/filter/tests/src/Kernel/FilterCrudTest.php index 72df6bd4d25..5c1d3b54b77 100644 --- a/core/modules/filter/tests/src/Kernel/FilterCrudTest.php +++ b/core/modules/filter/tests/src/Kernel/FilterCrudTest.php @@ -2,7 +2,6 @@ namespace Drupal\Tests\filter\Kernel; -use Drupal\Component\Render\FormattableMarkup; use Drupal\filter\Entity\FilterFormat; use Drupal\KernelTests\KernelTestBase; @@ -90,16 +89,16 @@ class FilterCrudTest extends KernelTestBase { * Verifies that a text format is properly stored. */ public function verifyTextFormat($format) { - $t_args = ['%format' => $format->label()]; $default_langcode = \Drupal::languageManager()->getDefaultLanguage()->getId(); // Verify the loaded filter has all properties. $filter_format = FilterFormat::load($format->id()); - $this->assertEquals($format->id(), $filter_format->id(), new FormattableMarkup('filter_format_load: Proper format id for text format %format.', $t_args)); - $this->assertEquals($format->label(), $filter_format->label(), new FormattableMarkup('filter_format_load: Proper title for text format %format.', $t_args)); - $this->assertEquals($format->get('weight'), $filter_format->get('weight'), new FormattableMarkup('filter_format_load: Proper weight for text format %format.', $t_args)); + $format_label = $format->label(); + $this->assertEquals($format->id(), $filter_format->id(), "filter_format_load: Proper format id for text format $format_label."); + $this->assertEquals($format->label(), $filter_format->label(), "filter_format_load: Proper title for text format $format_label."); + $this->assertEquals($format->get('weight'), $filter_format->get('weight'), "filter_format_load: Proper weight for text format $format_label."); // Check that the filter was created in site default language. - $this->assertEquals($default_langcode, $format->language()->getId(), new FormattableMarkup('filter_format_load: Proper language code for text format %format.', $t_args)); + $this->assertEquals($default_langcode, $format->language()->getId(), "filter_format_load: Proper language code for text format $format_label."); // Verify the permission exists and has the correct dependencies. $permissions = \Drupal::service('user.permissions')->getPermissions(); diff --git a/core/modules/media/tests/src/Kernel/MediaTranslationTest.php b/core/modules/media/tests/src/Kernel/MediaTranslationTest.php index c14863b476a..91596d3de21 100644 --- a/core/modules/media/tests/src/Kernel/MediaTranslationTest.php +++ b/core/modules/media/tests/src/Kernel/MediaTranslationTest.php @@ -2,7 +2,6 @@ namespace Drupal\Tests\media\Kernel; -use Drupal\Component\Render\FormattableMarkup; use Drupal\language\Entity\ConfigurableLanguage; use Drupal\content_translation\ContentTranslationHandler; @@ -97,11 +96,11 @@ class MediaTranslationTest extends MediaKernelTestBase { foreach ($items as $delta => $item) { $result = $result && $item['value'] == $media_translation->{$source_field_definition->getName()}[$delta]->value; } - $this->assertTrue($result, new FormattableMarkup('%language translation field value not correct.', ['%language' => $langcode])); - $this->assertSame('public://' . $langcode . '.png', $media_translation->getSource()->getMetadata($media_translation, 'thumbnail_uri'), new FormattableMarkup('%language translation thumbnail metadata attribute is not correct.', ['%language' => $langcode])); - $this->assertSame('public://' . $langcode . '.png', $media_translation->get('thumbnail')->entity->getFileUri(), new FormattableMarkup('%language translation thumbnail value is not correct.', ['%language' => $langcode])); - $this->assertEquals('Test Thumbnail ' . $langcode, $media_translation->getSource()->getMetadata($media_translation, 'test_thumbnail_alt'), new FormattableMarkup('%language translation thumbnail alt metadata attribute is not correct.', ['%language' => $langcode])); - $this->assertSame('Test Thumbnail ' . $langcode, $media_translation->get('thumbnail')->alt, new FormattableMarkup('%language translation thumbnail alt value is not correct.', ['%language' => $langcode])); + $this->assertTrue($result, "$langcode translation field value not correct."); + $this->assertSame('public://' . $langcode . '.png', $media_translation->getSource()->getMetadata($media_translation, 'thumbnail_uri'), "$langcode translation thumbnail metadata attribute is not correct."); + $this->assertSame('public://' . $langcode . '.png', $media_translation->get('thumbnail')->entity->getFileUri(), "$langcode translation thumbnail value is not correct."); + $this->assertEquals('Test Thumbnail ' . $langcode, $media_translation->getSource()->getMetadata($media_translation, 'test_thumbnail_alt'), "$langcode translation thumbnail alt metadata attribute is not correct."); + $this->assertSame('Test Thumbnail ' . $langcode, $media_translation->get('thumbnail')->alt, "$langcode translation thumbnail alt value is not correct."); } } diff --git a/core/modules/migrate_drupal_ui/tests/src/Kernel/MigrationLabelExistTest.php b/core/modules/migrate_drupal_ui/tests/src/Kernel/MigrationLabelExistTest.php index 148c9bee294..0682fda9dcf 100644 --- a/core/modules/migrate_drupal_ui/tests/src/Kernel/MigrationLabelExistTest.php +++ b/core/modules/migrate_drupal_ui/tests/src/Kernel/MigrationLabelExistTest.php @@ -2,7 +2,6 @@ namespace Drupal\Tests\migrate_drupal_ui\Kernel; -use Drupal\Component\Render\FormattableMarkup; use Drupal\KernelTests\FileSystemModuleDiscoveryDataProviderTrait; use Drupal\Tests\migrate_drupal\Kernel\MigrateDrupalTestBase; @@ -33,7 +32,7 @@ class MigrationLabelExistTest extends MigrateDrupalTestBase { /** @var \Drupal\migrate\Plugin\Migration $migration */ foreach ($migrations as $migration) { $migration_id = $migration->getPluginId(); - $this->assertNotEmpty($migration->label(), new FormattableMarkup('Label found for @migration_id.', ['@migration_id' => $migration_id])); + $this->assertNotEmpty($migration->label(), "Label found for $migration_id."); } } diff --git a/core/modules/mysql/tests/src/Kernel/mysql/DbDumpTest.php b/core/modules/mysql/tests/src/Kernel/mysql/DbDumpTest.php index 308d4813728..2ff0f6a6a64 100644 --- a/core/modules/mysql/tests/src/Kernel/mysql/DbDumpTest.php +++ b/core/modules/mysql/tests/src/Kernel/mysql/DbDumpTest.php @@ -2,7 +2,6 @@ namespace Drupal\Tests\mysql\Kernel\mysql; -use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Command\DbDumpApplication; use Drupal\Core\Config\DatabaseStorage; use Drupal\Core\Database\Database; @@ -196,9 +195,9 @@ class DbDumpTest extends DriverSpecificKernelTestBase { // The tables should now exist and the schemas should match the originals. foreach ($this->tables as $table) { $this->assertTrue($schema - ->tableExists($table), new FormattableMarkup('Table @table created by the database script.', ['@table' => $table])); - $this->assertSame($this->originalTableSchemas[$table], $this->getTableSchema($table), new FormattableMarkup('The schema for @table was properly restored.', ['@table' => $table])); - $this->assertSame($this->originalTableIndexes[$table], $this->getTableIndexes($table), new FormattableMarkup('The indexes for @table were properly restored.', ['@table' => $table])); + ->tableExists($table), "Table $table created by the database script."); + $this->assertSame($this->originalTableSchemas[$table], $this->getTableSchema($table), "The schema for $table was properly restored."); + $this->assertSame($this->originalTableIndexes[$table], $this->getTableIndexes($table), "The indexes for $table were properly restored."); } // Ensure the test config has been replaced. diff --git a/core/modules/node/tests/src/Kernel/NodeAccessRecordsTest.php b/core/modules/node/tests/src/Kernel/NodeAccessRecordsTest.php index 95714022958..6c7d2004755 100644 --- a/core/modules/node/tests/src/Kernel/NodeAccessRecordsTest.php +++ b/core/modules/node/tests/src/Kernel/NodeAccessRecordsTest.php @@ -2,7 +2,6 @@ namespace Drupal\Tests\node\Kernel; -use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Database\Database; use Drupal\node\Entity\Node; @@ -90,7 +89,7 @@ class NodeAccessRecordsTest extends NodeAccessTestBase { $grants = node_test_node_grants($web_user, $op); $altered_grants = $grants; \Drupal::moduleHandler()->alter('node_grants', $altered_grants, $web_user, $op); - $this->assertNotEquals($grants, $altered_grants, new FormattableMarkup('Altered the %op grant for a user.', ['%op' => $op])); + $this->assertNotEquals($grants, $altered_grants, "Altered the $op grant for a user."); } // Check that core does not grant access to an unpublished node when an diff --git a/core/modules/node/tests/src/Kernel/NodeFieldAccessTest.php b/core/modules/node/tests/src/Kernel/NodeFieldAccessTest.php index 83db6a13d2b..050716a9933 100644 --- a/core/modules/node/tests/src/Kernel/NodeFieldAccessTest.php +++ b/core/modules/node/tests/src/Kernel/NodeFieldAccessTest.php @@ -2,7 +2,6 @@ namespace Drupal\Tests\node\Kernel; -use Drupal\Component\Render\FormattableMarkup; use Drupal\KernelTests\Core\Entity\EntityKernelTestBase; use Drupal\node\Entity\Node; use Drupal\node\Entity\NodeType; @@ -119,35 +118,35 @@ class NodeFieldAccessTest extends EntityKernelTestBase { // Checks on view operations. foreach ($test_users as $account) { $may_view = $node1->{$field}->access('view', $account); - $this->assertTrue($may_view, new FormattableMarkup('Any user may view the field @name.', ['@name' => $field])); + $this->assertTrue($may_view, "Any user may view the field $field."); } // Checks on edit operations. $may_update = $node1->{$field}->access('edit', $page_creator_user); - $this->assertFalse($may_update, new FormattableMarkup('Users with permission "edit own page content" is not allowed to the field @name.', ['@name' => $field])); + $this->assertFalse($may_update, 'Users with permission "edit own page content" is not allowed to the field ' . $field . '.'); $may_update = $node2->{$field}->access('edit', $page_creator_user); - $this->assertFalse($may_update, new FormattableMarkup('Users with permission "edit own page content" is not allowed to the field @name.', ['@name' => $field])); + $this->assertFalse($may_update, 'Users with permission "edit own page content" is not allowed to the field ' . $field . '.'); $may_update = $node2->{$field}->access('edit', $page_manager_user); - $this->assertFalse($may_update, new FormattableMarkup('Users with permission "edit any page content" is not allowed to the field @name.', ['@name' => $field])); + $this->assertFalse($may_update, 'Users with permission "edit any page content" is not allowed to the field ' . $field . '.'); $may_update = $node1->{$field}->access('edit', $page_manager_user); - $this->assertFalse($may_update, new FormattableMarkup('Users with permission "edit any page content" is not allowed to the field @name.', ['@name' => $field])); + $this->assertFalse($may_update, 'Users with permission "edit any page content" is not allowed to the field ' . $field . '.'); $may_update = $node2->{$field}->access('edit', $page_unrelated_user); - $this->assertFalse($may_update, new FormattableMarkup('Users not having permission "edit any page content" is not allowed to the field @name.', ['@name' => $field])); + $this->assertFalse($may_update, 'Users not having permission "edit any page content" is not allowed to the field ' . $field . '.'); $may_update = $node1->{$field}->access('edit', $content_admin_user) && $node3->status->access('edit', $content_admin_user); - $this->assertTrue($may_update, new FormattableMarkup('Users with permission "administer nodes" may edit @name fields on all nodes.', ['@name' => $field])); + $this->assertTrue($may_update, 'Users with permission "administer nodes" may edit ' . $field . ' fields on all nodes.'); } foreach ($this->readOnlyFields as $field) { // Check view operation. foreach ($test_users as $account) { $may_view = $node1->{$field}->access('view', $account); - $this->assertTrue($may_view, new FormattableMarkup('Any user may view the field @name.', ['@name' => $field])); + $this->assertTrue($may_view, "Any user may view the field $field."); } // Check edit operation. foreach ($test_users as $account) { $may_view = $node1->{$field}->access('edit', $account); - $this->assertFalse($may_view, new FormattableMarkup('No user is not allowed to edit the field @name.', ['@name' => $field])); + $this->assertFalse($may_view, "No user is not allowed to edit the field $field."); } } diff --git a/core/modules/node/tests/src/Kernel/NodeTokenReplaceTest.php b/core/modules/node/tests/src/Kernel/NodeTokenReplaceTest.php index e8263292321..b7ee917d482 100644 --- a/core/modules/node/tests/src/Kernel/NodeTokenReplaceTest.php +++ b/core/modules/node/tests/src/Kernel/NodeTokenReplaceTest.php @@ -3,7 +3,6 @@ namespace Drupal\Tests\node\Kernel; use Drupal\Component\Utility\Html; -use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Render\BubbleableMetadata; use Drupal\node\Entity\Node; use Drupal\node\Entity\NodeType; @@ -126,7 +125,7 @@ class NodeTokenReplaceTest extends TokenReplaceKernelTestBase { foreach ($tests as $input => $expected) { $output = $this->tokenService->replace($input, ['node' => $node], ['language' => $this->interfaceLanguage]); - $this->assertEquals($output, $expected, new FormattableMarkup('Node token %token replaced for unpublished node.', ['%token' => $input])); + $this->assertEquals($output, $expected, "Node token $input replaced for unpublished node."); } // Repeat for a node without a summary. diff --git a/core/modules/system/tests/src/Kernel/Block/SystemMenuBlockTest.php b/core/modules/system/tests/src/Kernel/Block/SystemMenuBlockTest.php index cb7d1f0438b..a335d9648a5 100644 --- a/core/modules/system/tests/src/Kernel/Block/SystemMenuBlockTest.php +++ b/core/modules/system/tests/src/Kernel/Block/SystemMenuBlockTest.php @@ -2,7 +2,6 @@ namespace Drupal\Tests\system\Kernel\Block; -use Drupal\Component\Render\FormattableMarkup; use Drupal\KernelTests\KernelTestBase; use Drupal\system\Entity\Menu; use Drupal\block\Entity\Block; @@ -226,7 +225,7 @@ class SystemMenuBlockTest extends KernelTestBase { foreach ($blocks as $id => $block) { $block_build = $block->build(); $items = $block_build['#items'] ?? []; - $this->assertSame($no_active_trail_expectations[$id], $this->convertBuiltMenuToIdTree($items), new FormattableMarkup('Menu block %id with no active trail renders the expected tree.', ['%id' => $id])); + $this->assertSame($no_active_trail_expectations[$id], $this->convertBuiltMenuToIdTree($items), "Menu block $id with no active trail renders the expected tree."); } // Scenario 2: test all block instances when there's an active trail. @@ -278,7 +277,7 @@ class SystemMenuBlockTest extends KernelTestBase { foreach ($blocks as $id => $block) { $block_build = $block->build(); $items = $block_build['#items'] ?? []; - $this->assertSame($active_trail_expectations[$id], $this->convertBuiltMenuToIdTree($items), new FormattableMarkup('Menu block %id with an active trail renders the expected tree.', ['%id' => $id])); + $this->assertSame($active_trail_expectations[$id], $this->convertBuiltMenuToIdTree($items), "Menu block $id with an active trail renders the expected tree."); } } diff --git a/core/modules/system/tests/src/Kernel/Common/UrlTest.php b/core/modules/system/tests/src/Kernel/Common/UrlTest.php index a9512b5b317..9457ca8a815 100644 --- a/core/modules/system/tests/src/Kernel/Common/UrlTest.php +++ b/core/modules/system/tests/src/Kernel/Common/UrlTest.php @@ -2,7 +2,6 @@ namespace Drupal\Tests\system\Kernel\Common; -use Drupal\Component\Render\FormattableMarkup; use Drupal\Component\Utility\UrlHelper; use Drupal\Core\Cache\Cache; use Drupal\Core\Language\Language; @@ -33,13 +32,13 @@ class UrlTest extends KernelTestBase { $encoded_path = "%3CSCRIPT%3Ealert%28%27XSS%27%29%3C/SCRIPT%3E"; $link = Link::fromTextAndUrl($text, Url::fromUserInput('/' . $path))->toString(); - $this->assertStringContainsString($encoded_path, $link, new FormattableMarkup('XSS attack @path was filtered by \Drupal\Core\Utility\LinkGeneratorInterface::generate().', ['@path' => $path])); - $this->assertStringNotContainsString($path, $link, new FormattableMarkup('XSS attack @path was filtered by \Drupal\Core\Utility\LinkGeneratorInterface::generate().', ['@path' => $path])); + $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(); - $this->assertStringContainsString($encoded_path, $link, new FormattableMarkup('XSS attack @path was filtered by #theme', ['@path' => $path])); - $this->assertStringNotContainsString($path, $link, new FormattableMarkup('XSS attack @path was filtered by #theme', ['@path' => $path])); + $this->assertStringContainsString($encoded_path, $link, "XSS attack $path was filtered by #theme"); + $this->assertStringNotContainsString($path, $link, "XSS attack $path was filtered by #theme"); } /** @@ -97,17 +96,17 @@ class UrlTest extends KernelTestBase { $hreflang_override_link['#options']['attributes']['hreflang'] = 'foo'; $rendered = $renderer->renderRoot($hreflang_link); - $this->assertTrue($this->hasAttribute('hreflang', $rendered, $langcode), new FormattableMarkup('hreflang attribute with value @langcode is present on a rendered link when langcode is provided in the render array.', ['@langcode' => $langcode])); + $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); - $this->assertTrue($this->hasAttribute('hreflang', $rendered, 'foo'), new FormattableMarkup('hreflang attribute with value @hreflang is present on a rendered link when @hreflang is provided in the render array.', ['@hreflang' => 'foo'])); + $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(); - $this->assertTrue($this->hasAttribute('class', $link_l, $class_l), new FormattableMarkup('Custom class @class is present on link when requested by Link::toString()', ['@class' => $class_l])); + $this->assertTrue($this->hasAttribute('class', $link_l, $class_l), "Custom class $class_l is present on link when requested by Link::toString()"); // Test #type. $class_theme = $this->randomMachineName(); @@ -122,7 +121,7 @@ class UrlTest extends KernelTestBase { ], ]; $link_theme = $renderer->renderRoot($type_link); - $this->assertTrue($this->hasAttribute('class', $link_theme, $class_theme), new FormattableMarkup('Custom class @class is present on link when requested by #type', ['@class' => $class_theme])); + $this->assertTrue($this->hasAttribute('class', $link_theme, $class_theme), "Custom class $class_theme is present on link when requested by #type"); } /** diff --git a/core/modules/system/tests/src/Kernel/Extension/ModuleHandlerTest.php b/core/modules/system/tests/src/Kernel/Extension/ModuleHandlerTest.php index a6290498d0e..d9b213f45a7 100644 --- a/core/modules/system/tests/src/Kernel/Extension/ModuleHandlerTest.php +++ b/core/modules/system/tests/src/Kernel/Extension/ModuleHandlerTest.php @@ -2,7 +2,6 @@ namespace Drupal\Tests\system\Kernel\Extension; -use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Entity\ContentEntityTypeInterface; use Drupal\Core\Extension\MissingDependencyException; use Drupal\Core\Extension\ModuleUninstallValidatorException; @@ -71,7 +70,7 @@ class ModuleHandlerTest extends KernelTestBase { protected function assertModuleList(array $expected_values, string $condition): void { $expected_values = array_values(array_unique($expected_values)); $enabled_modules = array_keys($this->container->get('module_handler')->getModuleList()); - $this->assertEquals($expected_values, $enabled_modules, new FormattableMarkup('@condition: extension handler returns correct results', ['@condition' => $condition])); + $this->assertEquals($expected_values, $enabled_modules, "$condition: extension handler returns correct results"); } /** diff --git a/core/modules/system/tests/src/Kernel/Theme/FunctionsTest.php b/core/modules/system/tests/src/Kernel/Theme/FunctionsTest.php index 1d8824bdbb5..c8c5d856fea 100644 --- a/core/modules/system/tests/src/Kernel/Theme/FunctionsTest.php +++ b/core/modules/system/tests/src/Kernel/Theme/FunctionsTest.php @@ -479,7 +479,7 @@ class FunctionsTest extends KernelTestBase { // thing. We expect a single