Commit c4d78579 authored by catch's avatar catch
Browse files

Issue #3226008 by longwave, mondrake: Remove simple uses of t() in assertEquals() calls

parent 18ab5c0a
......@@ -109,7 +109,7 @@ public function testValidation() {
$violations = $comment->validate();
$this->assertCount(1, $violations, 'Violation found when email is invalid');
$this->assertEquals('mail.0.value', $violations[0]->getPropertyPath());
$this->assertEquals(t('This value is not a valid email address.'), $violations[0]->getMessage());
$this->assertEquals('This value is not a valid email address.', $violations[0]->getMessage());
$comment->set('mail', NULL);
$comment->set('homepage', 'http://example.com/' . $this->randomMachineName(237));
......@@ -122,7 +122,7 @@ public function testValidation() {
// @todo This message should be improved in
// https://www.drupal.org/node/2012690.
$this->assertEquals(t('This value should be of the correct primitive type.'), $violations[0]->getMessage());
$this->assertEquals('This value should be of the correct primitive type.', $violations[0]->getMessage());
$comment->set('homepage', NULL);
$comment->set('hostname', $this->randomString(129));
......@@ -152,7 +152,7 @@ public function testValidation() {
$violations = $comment->validate();
$this->assertCount(1, $violations, 'Violation found when name is required, but empty and UID is anonymous.');
$this->assertEquals('name', $violations[0]->getPropertyPath());
$this->assertEquals(t('You have to specify a valid author.'), $violations[0]->getMessage());
$this->assertEquals('You have to specify a valid author.', $violations[0]->getMessage());
// Test creating a default comment with a given user id works.
$comment = $this->entityTypeManager->getStorage('comment')->create([
......@@ -177,7 +177,7 @@ public function testValidation() {
$violations = $comment->validate();
$this->assertCount(1, $violations, 'Violation found when author name and comment author do not match.');
$this->assertEquals('name', $violations[0]->getPropertyPath());
$this->assertEquals(t('The specified author name does not match the comment author.'), $violations[0]->getMessage());
$this->assertEquals('The specified author name does not match the comment author.', $violations[0]->getMessage());
}
/**
......
......@@ -398,7 +398,7 @@ public function testSiteWideContact() {
// Message is now by default displayed twice, once for the form element and
// once for the viewed message.
$page_text = $this->getSession()->getPage()->getText();
$this->assertGreaterThan(1, substr_count($page_text, t('Message')));
$this->assertGreaterThan(1, substr_count($page_text, 'Message'));
$this->assertSession()->responseContains('class="field field--name-message field--type-string-long field--label-above');
$this->assertSession()->pageTextContains($edit['message[0][value]']);
......@@ -413,7 +413,7 @@ public function testSiteWideContact() {
$this->submitForm($edit, 'Preview');
// Message should only be displayed once now.
$page_text = $this->getSession()->getPage()->getText();
$this->assertEquals(1, substr_count($page_text, t('Message')));
$this->assertEquals(1, substr_count($page_text, 'Message'));
$this->assertSession()->responseContains('class="field field--name-message field--type-string-long field--label-hidden field__item">');
$this->assertSession()->pageTextContains($edit['message[0][value]']);
......
......@@ -41,8 +41,7 @@ public function testEnable() {
// No pending updates should be available.
$this->drupalGet('admin/reports/status');
$requirement_value = $this->cssSelect("details.system-status-report__entry summary:contains('Entity/field definitions') + div");
$this->assertEquals(t('Up to date'), trim($requirement_value[0]->getText()));
$this->assertSession()->elementTextEquals('css', "details.system-status-report__entry summary:contains('Entity/field definitions') + div", 'Up to date');
$this->drupalGet('admin/config/regional/content-language');
// The node entity type should not be an option because it has no bundles.
......@@ -59,8 +58,7 @@ public function testEnable() {
// No pending updates should be available.
$this->drupalGet('admin/reports/status');
$requirement_value = $this->cssSelect("details.system-status-report__entry summary:contains('Entity/field definitions') + div");
$this->assertEquals(t('Up to date'), trim($requirement_value[0]->getText()));
$this->assertSession()->elementTextEquals('css', "details.system-status-report__entry summary:contains('Entity/field definitions') + div", 'Up to date');
// Create a node type and check the content translation settings are now
// available for nodes.
......
......@@ -139,7 +139,7 @@ public function testFileCreateUrl() {
$this->checkUrl('public', '', $basename, $base_path . '/' . $public_directory_path . '/' . $basename_encoded);
$this->checkUrl('private', '', $basename, $base_path . '/' . $script_path . 'system/files/' . $basename_encoded);
}
$this->assertEquals('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==', file_create_url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=='), t('Generated URL matches expected URL.'));
$this->assertEquals('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==', file_create_url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=='));
}
/**
......
......@@ -95,13 +95,13 @@ public function assertFileHookCalled($hook, $expected_count = 1, $message = NULL
* File object to compare.
*/
public function assertFileUnchanged(FileInterface $before, FileInterface $after) {
$this->assertEquals($before->id(), $after->id(), t('File id is the same: %file1 == %file2.', ['%file1' => $before->id(), '%file2' => $after->id()]), 'File unchanged');
$this->assertEquals($before->getOwner()->id(), $after->getOwner()->id(), t('File owner is the same: %file1 == %file2.', ['%file1' => $before->getOwner()->id(), '%file2' => $after->getOwner()->id()]), 'File unchanged');
$this->assertEquals($before->getFilename(), $after->getFilename(), t('File name is the same: %file1 == %file2.', ['%file1' => $before->getFilename(), '%file2' => $after->getFilename()]), 'File unchanged');
$this->assertEquals($before->getFileUri(), $after->getFileUri(), t('File path is the same: %file1 == %file2.', ['%file1' => $before->getFileUri(), '%file2' => $after->getFileUri()]), 'File unchanged');
$this->assertEquals($before->getMimeType(), $after->getMimeType(), t('File MIME type is the same: %file1 == %file2.', ['%file1' => $before->getMimeType(), '%file2' => $after->getMimeType()]), 'File unchanged');
$this->assertEquals($before->getSize(), $after->getSize(), t('File size is the same: %file1 == %file2.', ['%file1' => $before->getSize(), '%file2' => $after->getSize()]), 'File unchanged');
$this->assertEquals($before->isPermanent(), $after->isPermanent(), t('File status is the same: %file1 == %file2.', ['%file1' => $before->isPermanent(), '%file2' => $after->isPermanent()]), 'File unchanged');
$this->assertEquals($before->id(), $after->id());
$this->assertEquals($before->getOwner()->id(), $after->getOwner()->id());
$this->assertEquals($before->getFilename(), $after->getFilename());
$this->assertEquals($before->getFileUri(), $after->getFileUri());
$this->assertEquals($before->getMimeType(), $after->getMimeType());
$this->assertEquals($before->getSize(), $after->getSize());
$this->assertEquals($before->isPermanent(), $after->isPermanent());
}
/**
......@@ -113,8 +113,8 @@ public function assertFileUnchanged(FileInterface $before, FileInterface $after)
* File object to compare.
*/
public function assertDifferentFile(FileInterface $file1, FileInterface $file2) {
$this->assertNotEquals($file1->id(), $file2->id(), t('Files have different ids: %file1 != %file2.', ['%file1' => $file1->id(), '%file2' => $file2->id()]));
$this->assertNotEquals($file1->getFileUri(), $file2->getFileUri(), t('Files have different paths: %file1 != %file2.', ['%file1' => $file1->getFileUri(), '%file2' => $file2->getFileUri()]));
$this->assertNotEquals($file1->id(), $file2->id());
$this->assertNotEquals($file1->getFileUri(), $file2->getFileUri());
}
/**
......@@ -126,8 +126,8 @@ public function assertDifferentFile(FileInterface $file1, FileInterface $file2)
* File object to compare.
*/
public function assertSameFile(FileInterface $file1, FileInterface $file2) {
$this->assertEquals($file1->id(), $file2->id(), t('Files have the same ids: %file1 == %file2.', ['%file1' => $file1->id(), '%file2-fid' => $file2->id()]), 'Same file');
$this->assertEquals($file1->getFileUri(), $file2->getFileUri(), t('Files have the same path: %file1 == %file2.', ['%file1' => $file1->getFileUri(), '%file2' => $file2->getFileUri()]), 'Same file');
$this->assertEquals($file1->id(), $file2->id());
$this->assertEquals($file1->getFileUri(), $file2->getFileUri());
}
/**
......
......@@ -2,7 +2,6 @@
namespace Drupal\Tests\search\Functional;
use Drupal\Component\Utility\Html;
use Drupal\Component\Utility\Unicode;
use Drupal\Tests\BrowserTestBase;
......@@ -82,7 +81,6 @@ public function testSearchText() {
$this->submitForm($edit, 'Search');
$this->assertSession()->pageTextContains('search yielded no results');
$this->assertSession()->pageTextContains('Search');
$title_source = 'Search for @keywords | Drupal';
$this->assertSession()->titleEquals('Search for ' . Unicode::truncate($search_terms, 60, TRUE, TRUE) . ' | Drupal');
$this->assertSession()->pageTextNotContains('Node');
$this->assertSession()->pageTextNotContains('Node');
......@@ -105,8 +103,7 @@ public function testSearchText() {
$edit['keys'] = $search_terms;
$this->drupalGet('search/node');
$this->submitForm($edit, 'Search');
$actual_title = $this->xpath('//title')[0]->getText();
$this->assertEquals(Html::decodeEntities(t($title_source, ['@keywords' => Unicode::truncate($search_terms, 60, TRUE, TRUE)])), $actual_title, 'Search page title is correct');
$this->assertSession()->titleEquals('Search for ' . Unicode::truncate($search_terms, 60, TRUE, TRUE) . ' | Drupal');
$edit['keys'] = $this->searchingUser->getAccountName();
$this->drupalGet('search/user');
......
......@@ -79,7 +79,7 @@ public function testTaxonomyRelationships() {
// Check the parent relationship data.
$this->assertEquals('taxonomy_term_field_data', $views_data['parent_target_id']['relationship']['base']);
$this->assertEquals('tid', $views_data['parent_target_id']['relationship']['base field']);
$this->assertEquals(t('Parent'), $views_data['parent_target_id']['relationship']['label']);
$this->assertEquals('Parent', $views_data['parent_target_id']['relationship']['label']);
$this->assertEquals('standard', $views_data['parent_target_id']['relationship']['id']);
// Check the parent filter and argument data.
$this->assertEquals('numeric', $views_data['parent_target_id']['filter']['id']);
......
......@@ -53,7 +53,7 @@ public function testValidation() {
$violations = $term->validate();
$this->assertCount(1, $violations, 'Violation found when name is NULL.');
$this->assertEquals('name', $violations[0]->getPropertyPath());
$this->assertEquals(t('This value should not be null.'), $violations[0]->getMessage());
$this->assertEquals('This value should not be null.', $violations[0]->getMessage());
$term->set('name', 'test');
$term->set('parent', 9999);
......
......@@ -91,7 +91,7 @@ public function testUserListing() {
$this->assertEmpty(array_keys(array_diff_key($result_accounts, $accounts)), 'Ensure all accounts are listed.');
foreach ($result_accounts as $name => $values) {
$this->assertEquals($accounts[$name]->status->value, $values['status'] == t('active'), 'Ensure the status is displayed properly.');
$this->assertEquals($accounts[$name]->status->value, $values['status'] == 'active');
}
$expected_roles = ['custom_role_1', 'custom_role_2'];
......
......@@ -135,9 +135,9 @@ public function testRegistrationWithUserFields() {
->getStorage('user')
->loadByProperties(['name' => $name, 'mail' => $name . '@example.com']);
$new_user = reset($accounts);
$this->assertEquals($value, $new_user->test_user_field[0]->value, t('The field value was correctly saved.'));
$this->assertEquals($value . '1', $new_user->test_user_field[1]->value, t('The field value was correctly saved.'));
$this->assertEquals($value . '2', $new_user->test_user_field[2]->value, t('The field value was correctly saved.'));
$this->assertEquals($value, $new_user->test_user_field[0]->value);
$this->assertEquals($value . '1', $new_user->test_user_field[1]->value);
$this->assertEquals($value . '2', $new_user->test_user_field[2]->value);
}
}
......@@ -114,7 +114,7 @@ public function testValidation() {
$violations = $user->validate();
$this->assertCount(1, $violations, 'Violation found when email is invalid');
$this->assertEquals('mail.0.value', $violations[0]->getPropertyPath());
$this->assertEquals(t('This value is not a valid email address.'), $violations[0]->getMessage());
$this->assertEquals('This value is not a valid email address.', $violations[0]->getMessage());
$mail = $this->randomMachineName(Email::EMAIL_MAX_LENGTH - 11) . '@example.com';
$user->set('mail', $mail);
......@@ -127,7 +127,7 @@ public function testValidation() {
$this->assertEquals('mail.0.value', $violations[0]->getPropertyPath());
$this->assertEquals(t('%name: the email address can not be longer than @max characters.', ['%name' => $user->get('mail')->getFieldDefinition()->getLabel(), '@max' => Email::EMAIL_MAX_LENGTH]), $violations[0]->getMessage());
$this->assertEquals('mail.0.value', $violations[1]->getPropertyPath());
$this->assertEquals(t('This value is not a valid email address.'), $violations[1]->getMessage());
$this->assertEquals('This value is not a valid email address.', $violations[1]->getMessage());
// Provoke an email collision with an existing user.
$user->set('mail', 'existing@example.com');
......@@ -219,7 +219,7 @@ protected function assertAllowedValuesViolation(EntityInterface $entity, $field_
$violations = $entity->validate();
$this->assertCount(1, $violations, "Allowed values violation for $field_name found.");
$this->assertEquals($field_name === 'langcode' ? "{$field_name}.0" : "{$field_name}.0.value", $violations[0]->getPropertyPath());
$this->assertEquals(t('The value you selected is not a valid choice.'), $violations[0]->getMessage());
$this->assertEquals('The value you selected is not a valid choice.', $violations[0]->getMessage());
}
}
......@@ -49,20 +49,20 @@ public function testFieldBoolean() {
$this->executeView($view);
// This is john, which has no age, there are no custom formats defined, yet.
$this->assertEquals(t('No'), $view->field['age']->advancedRender($view->result[0]));
$this->assertEquals(t('Yes'), $view->field['age']->advancedRender($view->result[1]));
$this->assertEquals('No', $view->field['age']->advancedRender($view->result[0]));
$this->assertEquals('Yes', $view->field['age']->advancedRender($view->result[1]));
// Reverse the output.
$view->field['age']->options['not'] = TRUE;
$this->assertEquals(t('Yes'), $view->field['age']->advancedRender($view->result[0]));
$this->assertEquals(t('No'), $view->field['age']->advancedRender($view->result[1]));
$this->assertEquals('Yes', $view->field['age']->advancedRender($view->result[0]));
$this->assertEquals('No', $view->field['age']->advancedRender($view->result[1]));
unset($view->field['age']->options['not']);
// Use another output format.
$view->field['age']->options['type'] = 'true-false';
$this->assertEquals(t('False'), $view->field['age']->advancedRender($view->result[0]));
$this->assertEquals(t('True'), $view->field['age']->advancedRender($view->result[1]));
$this->assertEquals('False', $view->field['age']->advancedRender($view->result[0]));
$this->assertEquals('True', $view->field['age']->advancedRender($view->result[1]));
// test awesome unicode.
$view->field['age']->options['type'] = 'unicode-yes-no';
......@@ -72,8 +72,8 @@ public function testFieldBoolean() {
// Set a custom output format.
$view->field['age']->formats['test'] = [t('Test-True'), t('Test-False')];
$view->field['age']->options['type'] = 'test';
$this->assertEquals(t('Test-False'), $view->field['age']->advancedRender($view->result[0]));
$this->assertEquals(t('Test-True'), $view->field['age']->advancedRender($view->result[1]));
$this->assertEquals('Test-False', $view->field['age']->advancedRender($view->result[0]));
$this->assertEquals('Test-True', $view->field['age']->advancedRender($view->result[1]));
}
}
......@@ -137,7 +137,8 @@ public function testSubSelectUpdate() {
$after_age = $this->connection->query('SELECT [age] FROM {test} WHERE [name] = :name', [':name' => 'Ringo'])->fetchField();
$expected_age = $select->execute()->fetchField();
$this->assertEquals($expected_age, $after_age);
$this->assertEquals(1, $num_updated, t('Expected 1 row to be updated in subselect update query.'));
// Expect 1 row to be updated.
$this->assertEquals(1, $num_updated);
}
}
......@@ -67,7 +67,7 @@ public function testConstraintValidation() {
$entity->changed->value = REQUEST_TIME - 86400;
$violations = $entity->validate();
$this->assertEquals(1, $violations->count(), 'Validation failed.');
$this->assertEquals(t('The content has either been modified by another user, or you have already submitted modifications. As a result, your changes cannot be saved.'), $violations[0]->getMessage());
$this->assertEquals('The content has either been modified by another user, or you have already submitted modifications. As a result, your changes cannot be saved.', $violations[0]->getMessage());
}
}
......@@ -150,13 +150,13 @@ protected function checkValidation($entity_type) {
// This should fail on AllowedValues and Length constraints.
$this->assertEquals(2, $violations->count(), 'Validation failed.');
$this->assertEquals(t('This value is too long. It should have %limit characters or less.', ['%limit' => '12']), $violations[0]->getMessage());
$this->assertEquals(t('The value you selected is not a valid choice.'), $violations[1]->getMessage());
$this->assertEquals('The value you selected is not a valid choice.', $violations[1]->getMessage());
$test_entity = clone $entity;
$test_entity->type->value = NULL;
$violations = $test_entity->validate();
$this->assertEquals(1, $violations->count(), 'Validation failed.');
$this->assertEquals(t('This value should not be null.'), $violations[0]->getMessage());
$this->assertEquals('This value should not be null.', $violations[0]->getMessage());
$test_entity = clone $entity;
$test_entity->name->value = $this->randomString(33);
......@@ -180,7 +180,7 @@ protected function checkValidation($entity_type) {
$test_entity->field_test_text->format = $this->randomString(33);
$violations = $test_entity->validate();
$this->assertEquals(1, $violations->count(), 'Validation failed.');
$this->assertEquals(t('The value you selected is not a valid choice.'), $violations[0]->getMessage());
$this->assertEquals('The value you selected is not a valid choice.', $violations[0]->getMessage());
// Make sure the information provided by a violation is correct.
$violation = $violations[0];
......
......@@ -437,7 +437,7 @@ public function testFieldUpdateIndexesWithData() {
// Verify that the tables were not dropped in the process.
$entity = $this->container->get('entity_type.manager')->getStorage($entity_type)->load(1);
$this->assertEquals('field data', $entity->{$field_name}->value, t("Index changes performed without dropping the tables"));
$this->assertEquals('field data', $entity->{$field_name}->value);
}
/**
......
......@@ -83,7 +83,7 @@ public function testUriFunctions() {
// Test file_uri_target().
$this->assertEquals('foo/bar.txt', $stream_wrapper_manager::getTarget('public://foo/bar.txt'), 'Got a valid stream target from public://foo/bar.txt.');
$this->assertEquals('image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==', $stream_wrapper_manager::getTarget('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=='), t('Got a valid stream target from a data URI.'));
$this->assertEquals('image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==', $stream_wrapper_manager::getTarget('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=='));
$this->assertFalse($stream_wrapper_manager::getTarget('foo/bar.txt'), 'foo/bar.txt is not a valid stream.');
$this->assertSame($stream_wrapper_manager::getTarget('public://'), '');
$this->assertSame($stream_wrapper_manager::getTarget('data:'), '');
......
......@@ -47,7 +47,7 @@ public function testValidation() {
// Make sure the information provided by a violation is correct.
$violation = $violations[0];
$this->assertEquals(t('The value you selected is not a valid choice.'), $violation->getMessage(), 'The message for invalid value is correct.');
$this->assertEquals('The value you selected is not a valid choice.', $violation->getMessage(), 'The message for invalid value is correct.');
$this->assertEquals($typed_data, $violation->getRoot(), 'Violation root is correct.');
$this->assertEquals(4, $violation->getInvalidValue(), 'The invalid value is set correctly in the violation.');
......
......@@ -53,7 +53,7 @@ public function testValidation() {
// Make sure the information provided by a violation is correct.
$violation = $violations[0];
$this->assertEquals(t('The value you selected is not a valid choice.'), $violation->getMessage(), 'The message for invalid value is correct.');
$this->assertEquals('The value you selected is not a valid choice.', $violation->getMessage(), 'The message for invalid value is correct.');
$this->assertEquals($typed_data, $violation->getRoot(), 'Violation root is correct.');
$this->assertEquals(4, $violation->getInvalidValue(), 'The invalid value is set correctly in the violation.');
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment