diff --git a/core/modules/dblog/tests/src/Kernel/DbLogTest.php b/core/modules/dblog/tests/src/Kernel/DbLogTest.php index 08d4c3717349a3d86afe9d9af638f4b417ca152c..59283e795f3f6cb4c2eb1b3fce34d7e64feeadac 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 @@ public function testDbLogCron() { $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 @@ function (callable $hook, string $module) use (&$implementation_count) { ); $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 8cc81031cbe5c7bcba05fe55f7fcf950841f69e8..804f5ab97eceb65ba7f6118afa91e849fae692f5 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 @@ public function testAccess() { ->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 @@ public function testEntityFormatter() { $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 844a33c173c8353376bbda97e5e459f2cf88ddc9..16c43b86281518b541dd47550739d81544d4a933 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 @@ public function testFieldAttachSaveLoad() { $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 @@ public function testFieldAttachLoadMultiple() { 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 dc99bf4a5c13e7d2cebea65594fdab51fecf8c9d..837b0b36332d26252decd6d4aee14122373131d6 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 @@ public function testEntityCountAndHasData() { /** @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 10a972abc5ce71ec4ee46edaff6412100dee282b..fa756f535e9a468213e633dd7239e2d415b53f8a 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 @@ public function testImportDelete() { $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 f905cd750eea448977f6735af22f4aa3146909ae..73b769836b285021984542d7ff9e8ec6c002d09e 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 @@ public function testDefaultSettings() { $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 @@ public function testCreateInstance() { $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 @@ public function testCreateInstanceWithConfig() { $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 8e9dc31bb2808bed0d3f6accc43f53e34391d0bc..f6308cc0a7a2be4edfa00afcbd3a69223287fc7f 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 @@ public function testTranslatableFieldSaveLoad() { 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 @@ public function testTranslatableFieldSaveLoad() { // @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 @@ public function testTranslatableFieldSaveLoad() { } 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 97cc287d7b842bc9fc7d437e091fa1eb44b45857..09a237e441f1bb0991d430f991a0a3eaff054cc6 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 @@ public function assertFilterFormatViolation(ConstraintViolationListInterface $vi 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 72df6bd4d2513c8551751bbcae1464d627c34468..5c1d3b54b779c3099736a1ae2cbd8629f5a77ece 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 @@ public function testDisableFallbackFormat() { * 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 c14863b476a5d893ef05998d5d26caa5ba0954a4..91596d3de21de5e5dfbc45ac432be1489f4f0659 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 @@ public function testTranslatableFieldSaveLoad() { 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 148c9bee294cec565662b8d59a7c25a211eedffb..0682fda9dcf763bb582ca1527641939f6d1c205c 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 @@ public function testLabelExist() { /** @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 308d48137280a300ed4de557aa9419b5e664144e..2ff0f6a6a645a78f1a3fecdc0f7ab63ad532f6bf 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 @@ public function testScriptLoad() { // 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 957140229580a7f310fff2e63320619556e10f90..6c7d2004755d75b6568ed84e66b58c918d21deeb 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 @@ public function testNodeAccessRecords() { $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 83db6a13d2bc68455f115f47edec37ee95808433..050716a9933cd05bd028b09a07273c853501b645 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 @@ public function testAccessToAdministrativeFields() { // 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 e826329232183afd620a3b727e21301e9f1e6091..b7ee917d4822a74de40b8bc3f800c74e3b4c2ab8 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 @@ public function testNodeTokenReplacement() { 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 cb7d1f0438b2b3f14c7fb8da2593657de825adc0..a335d9648a563ac724b3c196418ddd86814747ab 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 @@ public function testConfigLevelDepth() { 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 @@ public function testConfigLevelDepth() { 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 a9512b5b3173bf929bbb632cbe8884c8ae5eaeee..9457ca8a81596242d0ddb6d916a59733fb776537 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 @@ public function testLinkXSS() { $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 @@ public function testLinkAttributes() { $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 @@ public function testLinkAttributes() { ], ]; $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 a6290498d0efe02a7ac07ddf950ed7724950da39..d9b213f45a722c88c9c6757c049b4e334151822a 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 @@ public function testModuleList() { 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 1d8824bdbb5fad18ee4c6c31c7acf89cdbcdab84..c8c5d856feaa6853086a9c4ca63ef0793fcb4539 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 @@ public function testDrupalPreRenderLinks() { // thing. We expect a single <ul> with appropriate links contained within // it. $render_array = $base_array; - $html = \Drupal::service('renderer')->renderRoot($render_array); + $html = (string) \Drupal::service('renderer')->renderRoot($render_array); $dom = Html::load($html); $this->assertEquals(1, $dom->getElementsByTagName('ul')->length, 'One "ul" tag found in the rendered HTML.'); $list_elements = $dom->getElementsByTagName('li'); @@ -494,8 +494,8 @@ public function testDrupalPreRenderLinks() { // sure we get two separate <ul>'s with the appropriate links contained // within each. $render_array = $base_array; - $child_html = \Drupal::service('renderer')->renderRoot($render_array['first_child']); - $parent_html = \Drupal::service('renderer')->renderRoot($render_array); + $child_html = (string) \Drupal::service('renderer')->renderRoot($render_array['first_child']); + $parent_html = (string) \Drupal::service('renderer')->renderRoot($render_array); // First check the child HTML. $dom = Html::load($child_html); $this->assertEquals(1, $dom->getElementsByTagName('ul')->length, 'One "ul" tag found in the rendered child HTML.'); diff --git a/core/modules/system/tests/src/Kernel/Theme/ThemeTest.php b/core/modules/system/tests/src/Kernel/Theme/ThemeTest.php index 5ba25601084363be7183ac05c167e860fba6a944..7885ff709a37cc8a40fe29059d07258c66009447 100644 --- a/core/modules/system/tests/src/Kernel/Theme/ThemeTest.php +++ b/core/modules/system/tests/src/Kernel/Theme/ThemeTest.php @@ -2,7 +2,6 @@ namespace Drupal\Tests\system\Kernel\Theme; -use Drupal\Component\Render\FormattableMarkup; use Drupal\KernelTests\KernelTestBase; use Drupal\Component\Render\MarkupInterface; @@ -58,7 +57,7 @@ public function testThemeDataTypes() { $types = ['null' => NULL, 'false' => FALSE, 'integer' => 1, 'string' => 'foo', 'empty_string' => '']; foreach ($types as $type => $example) { $output = \Drupal::theme()->render('theme_test_foo', ['foo' => $example]); - $this->assertTrue($output instanceof MarkupInterface || is_string($output), new FormattableMarkup('\Drupal::theme() returns an object that implements MarkupInterface or a string for data type @type.', ['@type' => $type])); + $this->assertTrue($output instanceof MarkupInterface || is_string($output), "\Drupal::theme() returns an object that implements MarkupInterface or a string for data type $type."); if ($output instanceof MarkupInterface) { $this->assertSame((string) $example, $output->__toString()); } diff --git a/core/modules/system/tests/src/Kernel/Token/TokenReplaceKernelTest.php b/core/modules/system/tests/src/Kernel/Token/TokenReplaceKernelTest.php index 2ecff8dcbe6a28bbf971bc92bfcf5ace0dcaf4dd..516e3bd40c3806109a3c06a1569b4d946ecc0b1f 100644 --- a/core/modules/system/tests/src/Kernel/Token/TokenReplaceKernelTest.php +++ b/core/modules/system/tests/src/Kernel/Token/TokenReplaceKernelTest.php @@ -3,7 +3,6 @@ namespace Drupal\Tests\system\Kernel\Token; use Drupal\Core\Url; -use Drupal\Component\Render\FormattableMarkup; use Drupal\Component\Utility\Html; use Drupal\Component\Utility\Xss; use Drupal\Core\Render\BubbleableMetadata; @@ -48,7 +47,7 @@ public function testSystemTokenRecognition() { $input = $test['prefix'] . '[site:name]' . $test['suffix']; $expected = $test['prefix'] . 'Drupal' . $test['suffix']; $output = $this->tokenService->replace($input, [], ['langcode' => $this->interfaceLanguage->getId()]); - $this->assertSame($expected, $output, new FormattableMarkup('Token recognized in string %string', ['%string' => $input])); + $this->assertSame($expected, $output, "Token recognized in string $input"); } // Test token replacement when the string contains no tokens. @@ -125,7 +124,7 @@ public function testSystemSiteTokenReplacement() { foreach ($tests as $input => $expected) { $bubbleable_metadata = new BubbleableMetadata(); $output = $this->tokenService->replace($input, [], ['langcode' => $this->interfaceLanguage->getId()], $bubbleable_metadata); - $this->assertEquals($expected, $output, new FormattableMarkup('System site information token %token replaced.', ['%token' => $input])); + $this->assertEquals($expected, $output, "System site information token $input replaced."); $this->assertEquals($metadata_tests[$input], $bubbleable_metadata); } @@ -171,7 +170,7 @@ public function testSystemDateTokenReplacement() { foreach ($tests as $input => $expected) { $output = $this->tokenService->replace($input, ['date' => $date], ['langcode' => $this->interfaceLanguage->getId()]); - $this->assertEquals($expected, $output, new FormattableMarkup('Date token %token replaced.', ['%token' => $input])); + $this->assertEquals($expected, $output, "Date token $input replaced."); } } diff --git a/core/modules/taxonomy/tests/src/Kernel/LoadMultipleTest.php b/core/modules/taxonomy/tests/src/Kernel/LoadMultipleTest.php index e4b75f14cd517674420c5bb5796c3830e753131f..08cfa4bf376cca561a2548eda5f42127111bf4a5 100644 --- a/core/modules/taxonomy/tests/src/Kernel/LoadMultipleTest.php +++ b/core/modules/taxonomy/tests/src/Kernel/LoadMultipleTest.php @@ -2,7 +2,6 @@ namespace Drupal\Tests\taxonomy\Kernel; -use Drupal\Component\Render\FormattableMarkup; use Drupal\KernelTests\KernelTestBase; use Drupal\taxonomy\Entity\Term; use Drupal\Tests\taxonomy\Traits\TaxonomyTestTrait; @@ -53,7 +52,7 @@ public function testTaxonomyTermMultipleLoad() { $term_storage = \Drupal::entityTypeManager()->getStorage('taxonomy_term'); $terms = $term_storage->loadByProperties(['vid' => $vocabulary->id()]); $count = count($terms); - $this->assertEquals(5, $count, new FormattableMarkup('Correct number of terms were loaded. @count terms.', ['@count' => $count])); + $this->assertEquals(5, $count, "Correct number of terms were loaded. $count terms."); // Load the same terms again by tid. $terms2 = Term::loadMultiple(array_keys($terms)); diff --git a/core/modules/text/tests/src/Kernel/TextFormatterTest.php b/core/modules/text/tests/src/Kernel/TextFormatterTest.php index d2baebafcea3c7914ee4450efb8df34becf36e65..10a7247b0ac5fd9e6560b80e519c4c8869388c8b 100644 --- a/core/modules/text/tests/src/Kernel/TextFormatterTest.php +++ b/core/modules/text/tests/src/Kernel/TextFormatterTest.php @@ -2,7 +2,6 @@ namespace Drupal\Tests\text\Kernel; -use Drupal\Component\Render\FormattableMarkup; use Drupal\field\Entity\FieldConfig; use Drupal\filter\Entity\FilterFormat; use Drupal\KernelTests\Core\Entity\EntityKernelTestBase; @@ -92,7 +91,7 @@ public function testFormatters() { $build = $entity->get('formatted_text')->view(['type' => $formatter]); \Drupal::service('renderer')->renderRoot($build[0]); $this->assertSame("<p>Hello, world!</p>\n", (string) $build[0]['#markup']); - $this->assertEquals(FilterFormat::load('my_text_format')->getCacheTags(), $build[0]['#cache']['tags'], new FormattableMarkup('The @formatter formatter has the expected cache tags when formatting a formatted text field.', ['@formatter' => $formatter])); + $this->assertEquals(FilterFormat::load('my_text_format')->getCacheTags(), $build[0]['#cache']['tags'], "The $formatter formatter has the expected cache tags when formatting a formatted text field."); } } diff --git a/core/modules/text/tests/src/Kernel/TextSummaryTest.php b/core/modules/text/tests/src/Kernel/TextSummaryTest.php index c377c2e388889d7f2022ab06e937ae73f150da88..2a3cc32713b7c1e9c46ea1d188be62a44cb85d22 100644 --- a/core/modules/text/tests/src/Kernel/TextSummaryTest.php +++ b/core/modules/text/tests/src/Kernel/TextSummaryTest.php @@ -2,7 +2,6 @@ namespace Drupal\Tests\text\Kernel; -use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Entity\Entity\EntityFormDisplay; use Drupal\entity_test\Entity\EntityTest; use Drupal\field\Entity\FieldConfig; @@ -245,7 +244,7 @@ public function testInvalidFilterFormat() { */ public function assertTextSummary(string $text, string $expected, ?string $format = NULL, int $size = NULL): void { $summary = text_summary($text, $format, $size); - $this->assertSame($expected, $summary, new FormattableMarkup('<pre style="white-space: pre-wrap">@actual</pre> is identical to <pre style="white-space: pre-wrap">@expected</pre>', ['@actual' => $summary, '@expected' => $expected])); + $this->assertSame($expected, $summary, '<pre style="white-space: pre-wrap">' . $summary . '</pre> is identical to <pre style="white-space: pre-wrap">' . $expected . '</pre>'); } /** diff --git a/core/modules/views/tests/src/Kernel/Handler/AreaEntityTest.php b/core/modules/views/tests/src/Kernel/Handler/AreaEntityTest.php index ba181188b1864c5157e253f460b94058a42fe26e..46304a776b657e1f22147c8b8a349244624cdd23 100644 --- a/core/modules/views/tests/src/Kernel/Handler/AreaEntityTest.php +++ b/core/modules/views/tests/src/Kernel/Handler/AreaEntityTest.php @@ -2,7 +2,6 @@ namespace Drupal\Tests\views\Kernel\Handler; -use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Form\FormState; use Drupal\Tests\block\Traits\BlockCreationTrait; @@ -73,7 +72,7 @@ public function testEntityAreaData() { foreach (array_keys($expected_entities) as $entity) { $this->assertNotEmpty($data['entity_' . $entity], "Views entity '$entity' should have a data area."); // Test that entity_type is set correctly in the area data. - $this->assertEquals($data['entity_' . $entity]['area']['entity_type'], $entity, new FormattableMarkup('Correct entity_type set for @entity', ['@entity' => $entity])); + $this->assertEquals($data['entity_' . $entity]['area']['entity_type'], $entity, "Correct entity_type set for $entity"); } $expected_entities = array_filter($entity_types, function (EntityTypeInterface $type) { diff --git a/core/modules/views/tests/src/Kernel/Handler/FieldCounterTest.php b/core/modules/views/tests/src/Kernel/Handler/FieldCounterTest.php index b7ee77a4b974e9cd17e208dbfdb6ca086ff3b8eb..8bfa3c2d77eaa0e3fce2405f1fd113b990fab363 100644 --- a/core/modules/views/tests/src/Kernel/Handler/FieldCounterTest.php +++ b/core/modules/views/tests/src/Kernel/Handler/FieldCounterTest.php @@ -2,7 +2,6 @@ namespace Drupal\Tests\views\Kernel\Handler; -use Drupal\Component\Render\FormattableMarkup; use Drupal\Tests\views\Kernel\ViewsKernelTestBase; use Drupal\views\Views; @@ -47,11 +46,11 @@ public function testSimple() { $view->preview(); $counter = $view->style_plugin->getField(0, 'counter'); - $this->assertEquals('1', $counter, new FormattableMarkup('Make sure the expected number (@expected) patches with the rendered number (@counter)', ['@expected' => 1, '@counter' => $counter])); + $this->assertEquals('1', $counter, "Make sure the expected number (1) patches with the rendered number ($counter)"); $counter = $view->style_plugin->getField(1, 'counter'); - $this->assertEquals('2', $counter, new FormattableMarkup('Make sure the expected number (@expected) patches with the rendered number (@counter)', ['@expected' => 2, '@counter' => $counter])); + $this->assertEquals('2', $counter, "Make sure the expected number (2) patches with the rendered number ($counter)"); $counter = $view->style_plugin->getField(2, 'counter'); - $this->assertEquals('3', $counter, new FormattableMarkup('Make sure the expected number (@expected) patches with the rendered number (@counter)', ['@expected' => 3, '@counter' => $counter])); + $this->assertEquals('3', $counter, "Make sure the expected number (3) patches with the rendered number ($counter)"); $view->destroy(); $view->storage->invalidateCaches(); @@ -76,13 +75,13 @@ public function testSimple() { $counter = $view->style_plugin->getField(0, 'counter'); $expected_number = 0 + $rand_start; - $this->assertEquals((string) $expected_number, $counter, new FormattableMarkup('Make sure the expected number (@expected) patches with the rendered number (@counter)', ['@expected' => $expected_number, '@counter' => $counter])); + $this->assertEquals((string) $expected_number, $counter, "Make sure the expected number ($expected_number) patches with the rendered number ($counter)"); $counter = $view->style_plugin->getField(1, 'counter'); $expected_number = 1 + $rand_start; - $this->assertEquals((string) $expected_number, $counter, new FormattableMarkup('Make sure the expected number (@expected) patches with the rendered number (@counter)', ['@expected' => $expected_number, '@counter' => $counter])); + $this->assertEquals((string) $expected_number, $counter, "Make sure the expected number ($expected_number) patches with the rendered number ($counter)"); $counter = $view->style_plugin->getField(2, 'counter'); $expected_number = 2 + $rand_start; - $this->assertEquals((string) $expected_number, $counter, new FormattableMarkup('Make sure the expected number (@expected) patches with the rendered number (@counter)', ['@expected' => $expected_number, '@counter' => $counter])); + $this->assertEquals((string) $expected_number, $counter, "Make sure the expected number ($expected_number) patches with the rendered number ($counter)"); } /** diff --git a/core/modules/views/tests/src/Kernel/ModuleTest.php b/core/modules/views/tests/src/Kernel/ModuleTest.php index 8113f573d061d65e264f86eab8022b4f22ca4e18..b47c57eda3089a9023a3e4632ebacab8cfce230c 100644 --- a/core/modules/views/tests/src/Kernel/ModuleTest.php +++ b/core/modules/views/tests/src/Kernel/ModuleTest.php @@ -233,7 +233,7 @@ public function testViewsPluginList() { [$plugin_type, $plugin_id] = explode(':', $key); $plugin_def = $this->container->get("plugin.manager.views.$plugin_type")->getDefinition($plugin_id); - $this->assertTrue(isset($plugin_list[$key]), new FormattableMarkup('The expected @key plugin list key was found.', ['@key' => $key])); + $this->assertTrue(isset($plugin_list[$key]), "The expected $key plugin list key was found."); $plugin_details = $plugin_list[$key]; $this->assertEquals($plugin_type, $plugin_details['type'], 'The expected plugin type was found.'); diff --git a/core/modules/views/tests/src/Kernel/Plugin/DisplayExtenderTest.php b/core/modules/views/tests/src/Kernel/Plugin/DisplayExtenderTest.php index 32bb1095808f4a6f1d50b5b908de16ab8d7ed4ae..00fcfe90d58553d267c3191e556b4c470a399fbd 100644 --- a/core/modules/views/tests/src/Kernel/Plugin/DisplayExtenderTest.php +++ b/core/modules/views/tests/src/Kernel/Plugin/DisplayExtenderTest.php @@ -2,7 +2,6 @@ namespace Drupal\Tests\views\Kernel\Plugin; -use Drupal\Component\Render\FormattableMarkup; use Drupal\Tests\views\Kernel\ViewsKernelTestBase; use Drupal\views_test_data\Plugin\views\display_extender\DisplayExtenderTest as DisplayExtenderTestData; use Drupal\views\Views; @@ -54,7 +53,7 @@ public function testDisplayExtendersValidate() { foreach ($view->displayHandlers as $id => $display) { $this->assertArrayHasKey($id, $errors); - $this->assertContains('Display extender test error.', $errors[$id], new FormattableMarkup('Error message found for @id display', ['@id' => $id])); + $this->assertContains('Display extender test error.', $errors[$id], "Error message found for $id display"); } } diff --git a/core/modules/views/tests/src/Kernel/Plugin/StyleMappingTest.php b/core/modules/views/tests/src/Kernel/Plugin/StyleMappingTest.php index 5e09b3157a00d19d4af0795662cbcbdf449cde70..2ffadd2bc11793f726d616315941695c5e1fdfb9 100644 --- a/core/modules/views/tests/src/Kernel/Plugin/StyleMappingTest.php +++ b/core/modules/views/tests/src/Kernel/Plugin/StyleMappingTest.php @@ -2,7 +2,6 @@ namespace Drupal\Tests\views\Kernel\Plugin; -use Drupal\Component\Render\FormattableMarkup; use Drupal\views\Views; use Drupal\views\ViewExecutable; @@ -70,7 +69,7 @@ protected function mappedOutputHelper(ViewExecutable $view) { // separated by ':'. $expected_result = $name . ':' . $data_set[$count][$field_id]; $actual_result = (string) $field; - $this->assertSame($expected_result, $actual_result, new FormattableMarkup('The fields were mapped successfully: %name => %field_id', ['%name' => $name, '%field_id' => $field_id])); + $this->assertSame($expected_result, $actual_result, "The fields were mapped successfully: $name => $field_id"); } $count++; diff --git a/core/modules/views/tests/src/Kernel/QueryGroupByTest.php b/core/modules/views/tests/src/Kernel/QueryGroupByTest.php index 522ff701ca66122237114d6dfaff3052b070ccfc..63a3c17d283bfc462ccc32160b220ebbb1174075 100644 --- a/core/modules/views/tests/src/Kernel/QueryGroupByTest.php +++ b/core/modules/views/tests/src/Kernel/QueryGroupByTest.php @@ -2,7 +2,6 @@ namespace Drupal\Tests\views\Kernel; -use Drupal\Component\Render\FormattableMarkup; use Drupal\entity_test\Entity\EntityTestMul; use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldStorageConfig; @@ -132,8 +131,9 @@ public function groupByTestHelper($aggregation_function, $values) { foreach ($view->result as $item) { $results[$item->entity_test_name] = $item->id; } - $this->assertEquals($values[0], $results['name1'], new FormattableMarkup('Aggregation with @aggregation_function and groupby name: name1 returned the expected amount of results', ['@aggregation_function' => $aggregation_function ?? 'NULL'])); - $this->assertEquals($values[1], $results['name2'], new FormattableMarkup('Aggregation with @aggregation_function and groupby name: name2 returned the expected amount of results', ['@aggregation_function' => $aggregation_function ?? 'NULL'])); + $aggregation_function ??= 'NULL'; + $this->assertEquals($values[0], $results['name1'], "Aggregation with $aggregation_function and groupby name: name1 returned the expected amount of results"); + $this->assertEquals($values[1], $results['name2'], "Aggregation with $aggregation_function and groupby name: name2 returned the expected amount of results"); } /** diff --git a/core/modules/views/tests/src/Kernel/TokenReplaceTest.php b/core/modules/views/tests/src/Kernel/TokenReplaceTest.php index 0c46533b58a11a54e11b8b3793f1df3b834a5e08..9c3c9b4bf195888ad3eb68c687fdab60ecc50618 100644 --- a/core/modules/views/tests/src/Kernel/TokenReplaceTest.php +++ b/core/modules/views/tests/src/Kernel/TokenReplaceTest.php @@ -2,7 +2,6 @@ namespace Drupal\Tests\views\Kernel; -use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Render\BubbleableMetadata; use Drupal\views\Tests\ViewTestData; use Drupal\views\Views; @@ -65,7 +64,7 @@ public function testTokenReplacement() { foreach ($expected as $token => $expected_output) { $bubbleable_metadata = new BubbleableMetadata(); $output = $token_handler->replace($token, ['view' => $view], [], $bubbleable_metadata); - $this->assertSame($expected_output, $output, new FormattableMarkup('Token %token replaced correctly.', ['%token' => $token])); + $this->assertSame($expected_output, $output, "Token $token replaced correctly."); $this->assertEquals($metadata_tests[$token], $bubbleable_metadata); } } @@ -156,7 +155,7 @@ public function testTokenReplacementNoResults() { foreach ($expected as $token => $expected_output) { $output = $token_handler->replace($token, ['view' => $view]); - $this->assertSame($expected_output, $output, new FormattableMarkup('Token %token replaced correctly.', ['%token' => $token])); + $this->assertSame($expected_output, $output, "Token $token replaced correctly."); } } @@ -175,7 +174,7 @@ public function testTokenReplacementNoPath() { foreach ($expected as $token => $expected_output) { $output = $token_handler->replace($token, ['view' => $view]); - $this->assertSame($expected_output, $output, new FormattableMarkup('Token %token replaced correctly.', ['%token' => $token])); + $this->assertSame($expected_output, $output, "Token $token replaced correctly."); } } diff --git a/core/modules/views/tests/src/Kernel/ViewExecutableTest.php b/core/modules/views/tests/src/Kernel/ViewExecutableTest.php index 4e6d651b1877b616f37c4756383212ce4d9f4f64..77a8d4a5de8c90123d54042c2e74d8c9c130bf76 100644 --- a/core/modules/views/tests/src/Kernel/ViewExecutableTest.php +++ b/core/modules/views/tests/src/Kernel/ViewExecutableTest.php @@ -2,7 +2,6 @@ namespace Drupal\Tests\views\Kernel; -use Drupal\Component\Render\FormattableMarkup; use Drupal\comment\Tests\CommentTestTrait; use Drupal\Component\Utility\Xss; use Drupal\node\Entity\NodeType; @@ -134,7 +133,7 @@ public function testInitMethods() { if ($type == 'relationship') { continue; } - $this->assertGreaterThan(0, count($view->$type), new FormattableMarkup('Make sure a %type instance got instantiated.', ['%type' => $type])); + $this->assertGreaterThan(0, count($view->$type), "Make sure a $type instance got instantiated."); } // initHandlers() should create display handlers automatically as well. @@ -448,7 +447,7 @@ public function testValidate() { $match = function ($value) use ($display) { return str_contains($value, $display->display['display_title']); }; - $this->assertNotEmpty(array_filter($validate[$id], $match), new FormattableMarkup('Error message found for @id display', ['@id' => $id])); + $this->assertNotEmpty(array_filter($validate[$id], $match), "Error message found for $id display"); $count++; } diff --git a/core/modules/views/tests/src/Kernel/ViewStorageTest.php b/core/modules/views/tests/src/Kernel/ViewStorageTest.php index ce2726a60d2d23a2050781ee42a2cadc16b86ec3..1ae06efafb723088faba787974fa1ec901b80e12 100644 --- a/core/modules/views/tests/src/Kernel/ViewStorageTest.php +++ b/core/modules/views/tests/src/Kernel/ViewStorageTest.php @@ -2,7 +2,6 @@ namespace Drupal\Tests\views\Kernel; -use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\views\Entity\View; use Drupal\views\Plugin\views\display\Page; @@ -85,7 +84,7 @@ protected function loadTests() { // expected properties. $this->assertInstanceOf(View::class, $view); foreach ($this->configProperties as $property) { - $this->assertNotNull($view->get($property), new FormattableMarkup('Property: @property loaded onto View.', ['@property' => $property])); + $this->assertNotNull($view->get($property), "Property: $property loaded onto View."); } // Check the displays have been loaded correctly from config display data. @@ -101,7 +100,7 @@ protected function loadTests() { // exists. $original_options = $data['display'][$key]; foreach ($original_options as $orig_key => $value) { - $this->assertSame($display[$orig_key], $value, new FormattableMarkup('@key is identical to saved data', ['@key' => $key])); + $this->assertSame($display[$orig_key], $value, "$key is identical to saved data"); } } @@ -120,7 +119,7 @@ protected function createTests() { $this->assertInstanceOf(View::class, $created); // Check that the View contains all of the properties. foreach ($this->configProperties as $property) { - $this->assertTrue(property_exists($created, $property), new FormattableMarkup('Property: @property created on View.', ['@property' => $property])); + $this->assertTrue(property_exists($created, $property), "Property: $property created on View."); } // Create a new View instance with config values. @@ -137,8 +136,8 @@ protected function createTests() { // Test all properties except displays. foreach ($properties as $property) { - $this->assertNotNull($created->get($property), new FormattableMarkup('Property: @property created on View.', ['@property' => $property])); - $this->assertSame($values[$property], $created->get($property), new FormattableMarkup('Property value: @property matches configuration value.', ['@property' => $property])); + $this->assertNotNull($created->get($property), "Property: $property created on View."); + $this->assertSame($values[$property], $created->get($property), "Property value: $property matches configuration value."); } // Check the UUID of the loaded View. @@ -209,14 +208,14 @@ protected function displayMethodTests() { $random_title = $this->randomMachineName(); $id = $view->addDisplay('page', $random_title); - $this->assertEquals('page_1', $id, new FormattableMarkup('Make sure the first display (%id_new) has the expected ID (%id)', ['%id_new' => $id, '%id' => 'page_1'])); + $this->assertEquals('page_1', $id, "Make sure the first display ($id) has the expected ID (page_1)"); $display = $view->get('display'); $this->assertEquals($random_title, $display[$id]['display_title']); $random_title = $this->randomMachineName(); $id = $view->addDisplay('page', $random_title); $display = $view->get('display'); - $this->assertEquals('page_2', $id, new FormattableMarkup('Make sure the second display (%id_new) has the expected ID (%id)', ['%id_new' => $id, '%id' => 'page_2'])); + $this->assertEquals('page_2', $id, "Make sure the second display ($id) has the expected ID (page_2)"); $this->assertEquals($random_title, $display[$id]['display_title']); $id = $view->addDisplay('page'); @@ -325,14 +324,14 @@ public function testCreateDuplicate() { ]; foreach ($config_properties as $property) { - $this->assertSame($view->storage->get($property), $copy->get($property), new FormattableMarkup('@property property is identical.', ['@property' => $property])); + $this->assertSame($view->storage->get($property), $copy->get($property), "$property property is identical."); } // Check the displays are the same. $copy_display = $copy->get('display'); foreach ($view->storage->get('display') as $id => $display) { // assertIdentical will not work here. - $this->assertEquals($copy_display[$id], $display, new FormattableMarkup('The @display display has been copied correctly.', ['@display' => $id])); + $this->assertEquals($copy_display[$id], $display, "The $id display has been copied correctly."); } } diff --git a/core/modules/views/tests/src/Kernel/ViewsHooksTest.php b/core/modules/views/tests/src/Kernel/ViewsHooksTest.php index 0fcf159dbe9b5838cb92894c0fbab0cdd730146b..3314012a0ed20834fb8a1da7c15154809975c0e5 100644 --- a/core/modules/views/tests/src/Kernel/ViewsHooksTest.php +++ b/core/modules/views/tests/src/Kernel/ViewsHooksTest.php @@ -2,7 +2,6 @@ namespace Drupal\Tests\views\Kernel; -use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Render\RenderContext; use Drupal\views\Form\ViewsFormMainForm; use Drupal\views\Views; @@ -78,7 +77,7 @@ public function testHooks() { // Test each hook is found in the implementations array and is invoked. foreach (static::$hooks as $hook => $type) { - $this->assertTrue($this->moduleHandler->hasImplementations($hook, 'views_test_data'), new FormattableMarkup('The hook @hook was registered.', ['@hook' => $hook])); + $this->assertTrue($this->moduleHandler->hasImplementations($hook, 'views_test_data'), "The hook $hook was registered."); if ($hook == 'views_post_render') { $this->moduleHandler->invoke('views_test_data', $hook, [$view, &$view->display_handler->output, $view->display_handler->getPlugin('cache')]); @@ -99,7 +98,7 @@ public function testHooks() { $this->moduleHandler->invoke('views_test_data', $hook); } - $this->assertTrue($this->container->get('state')->get('views_hook_test_' . $hook), new FormattableMarkup('The %hook hook was invoked.', ['%hook' => $hook])); + $this->assertTrue($this->container->get('state')->get('views_hook_test_' . $hook), "The $hook hook was invoked."); // Reset the module implementations cache, so we ensure that the // .views.inc file is loaded actively. $this->moduleHandler->resetImplementations();