Issue #2555145 by TR, kostyashupenko, Mile23, oriol_e9g, geertvd: Remove t() from pass/fail assertions in tests

merge-requests/1119/head
Alex Pott 2019-06-06 20:00:56 +01:00
parent 45f97bcf50
commit b644848b2d
No known key found for this signature in database
GPG Key ID: 31905460D4A69276
10 changed files with 45 additions and 44 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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