From b644848b2da90d5074e9cdd2846f12a618fa2565 Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Thu, 6 Jun 2019 20:00:56 +0100 Subject: [PATCH] Issue #2555145 by TR, kostyashupenko, Mile23, oriol_e9g, geertvd: Remove t() from pass/fail assertions in tests --- .../field/tests/src/Kernel/FieldCrudTest.php | 8 ++-- .../tests/src/Kernel/FieldStorageCrudTest.php | 40 +++++++++---------- .../tests/src/Functional/NodeCreationTest.php | 4 +- .../src/Functional/NodeQueryAlterTest.php | 10 ++--- .../tests/src/Kernel/OptionsFieldTest.php | 4 +- .../simpletest/src/Tests/SimpleTestTest.php | 4 +- .../Kernel/Extension/ModuleHandlerTest.php | 4 +- .../Core/Database/TransactionTest.php | 5 ++- .../Core/Entity/FieldSqlStorageTest.php | 8 ++-- .../Core/Routing/MatcherDumperTest.php | 2 +- 10 files changed, 45 insertions(+), 44 deletions(-) diff --git a/core/modules/field/tests/src/Kernel/FieldCrudTest.php b/core/modules/field/tests/src/Kernel/FieldCrudTest.php index 33c94e29d03e..ad8e7c72e9fd 100644 --- a/core/modules/field/tests/src/Kernel/FieldCrudTest.php +++ b/core/modules/field/tests/src/Kernel/FieldCrudTest.php @@ -100,20 +100,20 @@ class FieldCrudTest extends FieldKernelTestBase { // Guarantee that the field/bundle combination is unique. try { FieldConfig::create($this->fieldDefinition)->save(); - $this->fail(t('Cannot create two fields with the same field / bundle combination.')); + $this->fail('Cannot create two fields with the same field / bundle combination.'); } catch (EntityStorageException $e) { - $this->pass(t('Cannot create two fields with the same field / bundle combination.')); + $this->pass('Cannot create two fields with the same field / bundle combination.'); } // Check that the specified field exists. try { $this->fieldDefinition['field_name'] = $this->randomMachineName(); FieldConfig::create($this->fieldDefinition)->save(); - $this->fail(t('Cannot create a field with a non-existing storage.')); + $this->fail('Cannot create a field with a non-existing storage.'); } catch (FieldException $e) { - $this->pass(t('Cannot create a field with a non-existing storage.')); + $this->pass('Cannot create a field with a non-existing storage.'); } // TODO: test other failures. diff --git a/core/modules/field/tests/src/Kernel/FieldStorageCrudTest.php b/core/modules/field/tests/src/Kernel/FieldStorageCrudTest.php index b4d7f56ddfea..82eae161d010 100644 --- a/core/modules/field/tests/src/Kernel/FieldStorageCrudTest.php +++ b/core/modules/field/tests/src/Kernel/FieldStorageCrudTest.php @@ -78,10 +78,10 @@ class FieldStorageCrudTest extends FieldKernelTestBase { // Guarantee that the name is unique. try { FieldStorageConfig::create($field_storage_definition)->save(); - $this->fail(t('Cannot create two fields with the same name.')); + $this->fail('Cannot create two fields with the same name.'); } catch (EntityStorageException $e) { - $this->pass(t('Cannot create two fields with the same name.')); + $this->pass('Cannot create two fields with the same name.'); } // Check that field type is required. @@ -91,10 +91,10 @@ class FieldStorageCrudTest extends FieldKernelTestBase { 'entity_type' => 'entity_type', ]; FieldStorageConfig::create($field_storage_definition)->save(); - $this->fail(t('Cannot create a field with no type.')); + $this->fail('Cannot create a field with no type.'); } catch (FieldException $e) { - $this->pass(t('Cannot create a field with no type.')); + $this->pass('Cannot create a field with no type.'); } // Check that field name is required. @@ -104,10 +104,10 @@ class FieldStorageCrudTest extends FieldKernelTestBase { 'entity_type' => 'entity_test', ]; FieldStorageConfig::create($field_storage_definition)->save(); - $this->fail(t('Cannot create an unnamed field.')); + $this->fail('Cannot create an unnamed field.'); } catch (FieldException $e) { - $this->pass(t('Cannot create an unnamed field.')); + $this->pass('Cannot create an unnamed field.'); } // Check that entity type is required. try { @@ -130,10 +130,10 @@ class FieldStorageCrudTest extends FieldKernelTestBase { 'type' => 'test_field', ]; FieldStorageConfig::create($field_storage_definition)->save(); - $this->fail(t('Cannot create a field with a name starting with a digit.')); + $this->fail('Cannot create a field with a name starting with a digit.'); } catch (FieldException $e) { - $this->pass(t('Cannot create a field with a name starting with a digit.')); + $this->pass('Cannot create a field with a name starting with a digit.'); } // Check that field name must only contain lowercase alphanumeric or _. @@ -144,10 +144,10 @@ class FieldStorageCrudTest extends FieldKernelTestBase { 'type' => 'test_field', ]; FieldStorageConfig::create($field_storage_definition)->save(); - $this->fail(t('Cannot create a field with a name containing an illegal character.')); + $this->fail('Cannot create a field with a name containing an illegal character.'); } catch (FieldException $e) { - $this->pass(t('Cannot create a field with a name containing an illegal character.')); + $this->pass('Cannot create a field with a name containing an illegal character.'); } // Check that field name cannot be longer than 32 characters long. @@ -158,10 +158,10 @@ class FieldStorageCrudTest extends FieldKernelTestBase { 'type' => 'test_field', ]; FieldStorageConfig::create($field_storage_definition)->save(); - $this->fail(t('Cannot create a field with a name longer than 32 characters.')); + $this->fail('Cannot create a field with a name longer than 32 characters.'); } catch (FieldException $e) { - $this->pass(t('Cannot create a field with a name longer than 32 characters.')); + $this->pass('Cannot create a field with a name longer than 32 characters.'); } // Check that field name can not be an entity key. @@ -173,10 +173,10 @@ class FieldStorageCrudTest extends FieldKernelTestBase { 'entity_type' => 'entity_test', ]; FieldStorageConfig::create($field_storage_definition)->save(); - $this->fail(t('Cannot create a field bearing the name of an entity key.')); + $this->fail('Cannot create a field bearing the name of an entity key.'); } catch (FieldException $e) { - $this->pass(t('Cannot create a field bearing the name of an entity key.')); + $this->pass('Cannot create a field bearing the name of an entity key.'); } } @@ -376,10 +376,10 @@ class FieldStorageCrudTest extends FieldKernelTestBase { try { $field_storage->set('type', 'integer'); $field_storage->save(); - $this->fail(t('Cannot update a field to a different type.')); + $this->fail('Cannot update a field to a different type.'); } catch (FieldException $e) { - $this->pass(t('Cannot update a field to a different type.')); + $this->pass('Cannot update a field to a different type.'); } } @@ -442,18 +442,18 @@ class FieldStorageCrudTest extends FieldKernelTestBase { $field_storage->setSetting('changeable', $field_storage->getSetting('changeable') + 1); try { $field_storage->save(); - $this->pass(t("A changeable setting can be updated.")); + $this->pass('A changeable setting can be updated.'); } catch (FieldStorageDefinitionUpdateForbiddenException $e) { - $this->fail(t("An unchangeable setting cannot be updated.")); + $this->fail('An unchangeable setting cannot be updated.'); } $field_storage->setSetting('unchangeable', $field_storage->getSetting('unchangeable') + 1); try { $field_storage->save(); - $this->fail(t("An unchangeable setting can be updated.")); + $this->fail('An unchangeable setting can be updated.'); } catch (FieldStorageDefinitionUpdateForbiddenException $e) { - $this->pass(t("An unchangeable setting cannot be updated.")); + $this->pass('An unchangeable setting cannot be updated.'); } } diff --git a/core/modules/node/tests/src/Functional/NodeCreationTest.php b/core/modules/node/tests/src/Functional/NodeCreationTest.php index a4c0f23a03fc..b574e58925fb 100644 --- a/core/modules/node/tests/src/Functional/NodeCreationTest.php +++ b/core/modules/node/tests/src/Functional/NodeCreationTest.php @@ -97,10 +97,10 @@ class NodeCreationTest extends NodeTestBase { // An exception is generated by node_test_exception_node_insert() if the // title is 'testing_transaction_exception'. Node::create($edit)->save(); - $this->fail(t('Expected exception has not been thrown.')); + $this->fail('Expected exception has not been thrown.'); } catch (\Exception $e) { - $this->pass(t('Expected exception has been thrown.')); + $this->pass('Expected exception has been thrown.'); } if (Database::getConnection()->supportsTransactions()) { diff --git a/core/modules/node/tests/src/Functional/NodeQueryAlterTest.php b/core/modules/node/tests/src/Functional/NodeQueryAlterTest.php index 6b9306703cf1..787def2767d8 100644 --- a/core/modules/node/tests/src/Functional/NodeQueryAlterTest.php +++ b/core/modules/node/tests/src/Functional/NodeQueryAlterTest.php @@ -65,7 +65,7 @@ class NodeQueryAlterTest extends NodeTestBase { $this->assertEqual(count($result), 4, 'User with access can see correct nodes'); } catch (\Exception $e) { - $this->fail(t('Altered query is malformed')); + $this->fail('Altered query is malformed'); } } @@ -106,7 +106,7 @@ class NodeQueryAlterTest extends NodeTestBase { $this->assertEqual(count($result), 0, 'User with no access cannot see nodes'); } catch (\Exception $e) { - $this->fail(t('Altered query is malformed')); + $this->fail('Altered query is malformed'); } } @@ -131,7 +131,7 @@ class NodeQueryAlterTest extends NodeTestBase { catch (\Exception $e) { $this->fail($e->getMessage()); $this->fail((string) $query); - $this->fail(t('Altered query is malformed')); + $this->fail('Altered query is malformed'); } } @@ -170,7 +170,7 @@ class NodeQueryAlterTest extends NodeTestBase { $this->assertEqual(count($result), 0, 'User view privileges are not overridden'); } catch (\Exception $e) { - $this->fail(t('Altered query is malformed')); + $this->fail('Altered query is malformed'); } // Have node_test_node_grants return a node_access_all privilege, @@ -192,7 +192,7 @@ class NodeQueryAlterTest extends NodeTestBase { $this->assertEqual(count($result), 4, 'User view privileges are overridden'); } catch (\Exception $e) { - $this->fail(t('Altered query is malformed')); + $this->fail('Altered query is malformed'); } \Drupal::state()->delete('node_access_test.no_access_uid'); } diff --git a/core/modules/options/tests/src/Kernel/OptionsFieldTest.php b/core/modules/options/tests/src/Kernel/OptionsFieldTest.php index a0aa6f72f8b6..6ed2fda2cb9e 100644 --- a/core/modules/options/tests/src/Kernel/OptionsFieldTest.php +++ b/core/modules/options/tests/src/Kernel/OptionsFieldTest.php @@ -40,10 +40,10 @@ class OptionsFieldTest extends OptionsFieldUnitTestBase { $this->fieldStorage->setSetting('allowed_values', [2 => 'Two']); try { $this->fieldStorage->save(); - $this->fail(t('Cannot update a list field storage to not include keys with existing data.')); + $this->fail('Cannot update a list field storage to not include keys with existing data.'); } catch (FieldStorageDefinitionUpdateForbiddenException $e) { - $this->pass(t('Cannot update a list field storage to not include keys with existing data.')); + $this->pass('Cannot update a list field storage to not include keys with existing data.'); } // Empty the value, so that we can actually remove the option. unset($entity->{$this->fieldName}); diff --git a/core/modules/simpletest/src/Tests/SimpleTestTest.php b/core/modules/simpletest/src/Tests/SimpleTestTest.php index 942902c9888a..392bbb921dde 100644 --- a/core/modules/simpletest/src/Tests/SimpleTestTest.php +++ b/core/modules/simpletest/src/Tests/SimpleTestTest.php @@ -205,7 +205,7 @@ EOD; // This causes the eleventh of the sixteen passes asserted in // confirmStubResults(). - $this->pass(t('Test ID is @id.', ['@id' => $this->testId])); + $this->pass('Test ID is ' . $this->testId . '.'); // These cause the twelfth to fifteenth of the sixteen passes asserted in // confirmStubResults(). @@ -234,7 +234,7 @@ EOD; * Assert nothing. */ public function assertNothing() { - $this->pass("This is nothing."); + $this->pass('This is nothing.'); } /** diff --git a/core/modules/system/tests/src/Kernel/Extension/ModuleHandlerTest.php b/core/modules/system/tests/src/Kernel/Extension/ModuleHandlerTest.php index bc6a580ea54c..e68d0939fc32 100644 --- a/core/modules/system/tests/src/Kernel/Extension/ModuleHandlerTest.php +++ b/core/modules/system/tests/src/Kernel/Extension/ModuleHandlerTest.php @@ -92,10 +92,10 @@ class ModuleHandlerTest extends KernelTestBase { try { $result = $this->moduleInstaller()->install(['color']); - $this->fail(t('ModuleInstaller::install() throws an exception if dependencies are missing.')); + $this->fail('ModuleInstaller::install() throws an exception if dependencies are missing.'); } catch (MissingDependencyException $e) { - $this->pass(t('ModuleInstaller::install() throws an exception if dependencies are missing.')); + $this->pass('ModuleInstaller::install() throws an exception if dependencies are missing.'); } $this->assertFalse($this->moduleHandler()->moduleExists('color'), 'ModuleInstaller::install() aborts if dependencies are missing.'); diff --git a/core/tests/Drupal/KernelTests/Core/Database/TransactionTest.php b/core/tests/Drupal/KernelTests/Core/Database/TransactionTest.php index 7de79248bcf8..f3607547cf8f 100644 --- a/core/tests/Drupal/KernelTests/Core/Database/TransactionTest.php +++ b/core/tests/Drupal/KernelTests/Core/Database/TransactionTest.php @@ -293,9 +293,10 @@ class TransactionTest extends DatabaseTestBase { try { $transaction->rollBack(); unset($transaction); - // @TODO: an exception should be triggered here, but is not, because + // @todo An exception should be triggered here, but is not because // "ROLLBACK" fails silently in MySQL if there is no transaction active. - // $this->fail(t('Rolling back a transaction containing DDL should fail.')); + // @see https://www.drupal.org/project/drupal/issues/2736777 + // $this->fail('Rolling back a transaction containing DDL should fail.'); } catch (TransactionNoActiveException $e) { $this->pass('Rolling back a transaction containing DDL should fail.'); diff --git a/core/tests/Drupal/KernelTests/Core/Entity/FieldSqlStorageTest.php b/core/tests/Drupal/KernelTests/Core/Entity/FieldSqlStorageTest.php index 7e9300c7aaec..2a8faf90e3f5 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/FieldSqlStorageTest.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/FieldSqlStorageTest.php @@ -341,10 +341,10 @@ class FieldSqlStorageTest extends EntityKernelTestBase { $field_storage->setSetting('scale', 3); try { $field_storage->save(); - $this->fail(t('Cannot update field schema with data.')); + $this->fail('Cannot update field schema with data.'); } catch (FieldStorageDefinitionUpdateForbiddenException $e) { - $this->pass(t('Cannot update field schema with data.')); + $this->pass('Cannot update field schema with data.'); } } @@ -370,10 +370,10 @@ class FieldSqlStorageTest extends EntityKernelTestBase { $field_storage->setSetting('max_length', '-1)'); try { $field_storage->save(); - $this->fail(t('Update succeeded.')); + $this->fail('Update succeeded.'); } catch (\Exception $e) { - $this->pass(t('Update properly failed.')); + $this->pass('Update properly failed.'); } // Ensure that the field tables are still there. diff --git a/core/tests/Drupal/KernelTests/Core/Routing/MatcherDumperTest.php b/core/tests/Drupal/KernelTests/Core/Routing/MatcherDumperTest.php index bf3ca96a163a..e5b1e1184d1e 100644 --- a/core/tests/Drupal/KernelTests/Core/Routing/MatcherDumperTest.php +++ b/core/tests/Drupal/KernelTests/Core/Routing/MatcherDumperTest.php @@ -99,7 +99,7 @@ class MatcherDumperTest extends KernelTestBase { foreach ($collection_routes as $name => $route) { if (empty($dumper_routes[$name])) { $success = FALSE; - $this->fail(t('Not all routes found in the dumper.')); + $this->fail('Not all routes found in the dumper.'); } }