Commit 18ab5c0a authored by catch's avatar catch
Browse files

Issue #3170396 by mondrake, ankithashetty, longwave, catch: [backport] Remove...

Issue #3170396 by mondrake, ankithashetty, longwave, catch: [backport] Remove uses of t() and switch to pageTextContains() in assert(No)Raw() calls
parent cef0c900
......@@ -89,7 +89,7 @@ public function testActionConfiguration() {
$this->assertSession()->statusCodeEquals(200);
// Make sure that the action was actually deleted.
$this->assertRaw(t('The action %action has been deleted.', ['%action' => $new_action_label]));
$this->assertSession()->pageTextContains("The action $new_action_label has been deleted.");
$this->drupalGet('admin/config/system/actions');
$this->assertSession()->statusCodeEquals(200);
// The action label does not appear on the overview page.
......
......@@ -48,8 +48,8 @@ public function testAddFeed() {
];
$this->drupalGet('aggregator/sources/add');
$this->submitForm($edit, 'Save');
$this->assertRaw(t('A feed named %feed already exists. Enter a unique title.', ['%feed' => $feed->label()]));
$this->assertRaw(t('A feed with this URL %url already exists. Enter a unique URL.', ['%url' => $feed->getUrl()]));
$this->assertSession()->pageTextContains('A feed named ' . $feed->label() . ' already exists. Enter a unique title.');
$this->assertSession()->pageTextContains('A feed with this URL ' . $feed->getUrl() . ' already exists. Enter a unique URL.');
// Delete feed.
$this->deleteFeed($feed);
......
......@@ -99,7 +99,7 @@ public function createFeed($feed_url = NULL, array $edit = []) {
public function deleteFeed(FeedInterface $feed) {
$this->drupalGet('aggregator/sources/' . $feed->id() . '/delete');
$this->submitForm([], 'Delete');
$this->assertRaw(t('The feed %title has been deleted.', ['%title' => $feed->label()]));
$this->assertSession()->pageTextContains('The feed ' . $feed->label() . ' has been deleted.');
}
/**
......@@ -222,7 +222,7 @@ public function updateFeedItems(FeedInterface $feed, $expected_count = NULL) {
public function deleteFeedItems(FeedInterface $feed) {
$this->drupalGet('admin/config/services/aggregator/delete/' . $feed->id());
$this->submitForm([], 'Delete items');
$this->assertRaw(t('The news items from %title have been deleted.', ['%title' => $feed->label()]));
$this->assertSession()->pageTextContains('The news items from ' . $feed->label() . ' have been deleted.');
}
/**
......
......@@ -119,7 +119,7 @@ public function testInvalidFeed() {
// Update the feed. Use the UI to be able to check the message easily.
$this->drupalGet('admin/config/services/aggregator');
$this->clickLink('Update items');
$this->assertRaw(t('The feed from %title seems to be broken because of error', ['%title' => $feed->label()]));
$this->assertSession()->pageTextContains('The feed from ' . $feed->label() . ' seems to be broken because of error');
}
}
......@@ -63,7 +63,7 @@ public function validateImportFormFields() {
$edit = [];
$this->drupalGet('admin/config/services/aggregator/add/opml');
$this->submitForm($edit, 'Import');
$this->assertRaw(t('<em>Either</em> upload a file or enter a URL.'));
$this->assertSession()->pageTextContains('Either upload a file or enter a URL.');
$path = $this->getEmptyOpml();
$edit = [
......@@ -72,7 +72,7 @@ public function validateImportFormFields() {
];
$this->drupalGet('admin/config/services/aggregator/add/opml');
$this->submitForm($edit, 'Import');
$this->assertRaw(t('<em>Either</em> upload a file or enter a URL.'));
$this->assertSession()->pageTextContains('Either upload a file or enter a URL.');
// Error if the URL is invalid.
$edit = ['remote' => 'invalidUrl://empty'];
......@@ -120,9 +120,9 @@ protected function submitImportForm() {
$this->drupalGet('admin/config/services/aggregator/add/opml');
$this->submitForm($edit, 'Import');
// Verify that a duplicate URL was identified.
$this->assertRaw(t('A feed with the URL %url already exists.', ['%url' => $feeds[0]['url[0][value]']]));
$this->assertSession()->pageTextContains('A feed with the URL ' . $feeds[0]['url[0][value]'] . ' already exists.');
// Verify that a duplicate title was identified.
$this->assertRaw(t('A feed named %title already exists.', ['%title' => $feeds[1]['title[0][value]']]));
$this->assertSession()->pageTextContains('A feed named ' . $feeds[1]['title[0][value]'] . ' already exists.');
$after = $count_query->execute();
$this->assertEquals(2, $after, 'Verifying that two distinct feeds were added.');
......
......@@ -42,7 +42,7 @@ public function testIPAddressValidation() {
$this->submitForm($edit, 'Add');
$ip = $connection->select('ban_ip', 'bi')->fields('bi', ['iid'])->condition('ip', $edit['ip'])->execute()->fetchField();
$this->assertNotEmpty($ip, 'IP address found in database.');
$this->assertRaw(t('The IP address %ip has been banned.', ['%ip' => $edit['ip']]));
$this->assertSession()->pageTextContains('The IP address 1.2.3.3 has been banned.');
// Try to block an IP address that's already blocked.
$edit = [];
......@@ -78,7 +78,7 @@ public function testIPAddressValidation() {
$this->submitForm([], 'Add');
$ip = $connection->select('ban_ip', 'bi')->fields('bi', ['iid'])->condition('ip', $submit_ip)->execute()->fetchField();
$this->assertNotEmpty($ip, 'IP address found in database');
$this->assertRaw(t('The IP address %ip has been banned.', ['%ip' => $submit_ip]));
$this->assertSession()->pageTextContains("The IP address $submit_ip has been banned.");
// Submit your own IP address. This fails, although it works when testing
// manually.
......
......@@ -45,17 +45,17 @@ public function testBlockInInvalidRegion() {
\Drupal::configFactory()->getEditable('block.block.' . $block->id())->set('region', 'invalid_region')->save();
$block = Block::load($block->id());
$warning_message = t('The block %info was assigned to the invalid region %region and has been disabled.', ['%info' => $block->id(), '%region' => 'invalid_region']);
$warning_message = 'The block ' . $block->id() . ' was assigned to the invalid region invalid_region and has been disabled.';
// Clearing the cache should disable the test block placed in the invalid region.
$this->drupalGet('admin/config/development/performance');
$this->submitForm([], 'Clear all caches');
$this->assertRaw($warning_message);
$this->assertSession()->pageTextContains($warning_message);
// Clear the cache to check if the warning message is not triggered.
$this->drupalGet('admin/config/development/performance');
$this->submitForm([], 'Clear all caches');
$this->assertNoRaw($warning_message);
$this->assertSession()->pageTextNotContains($warning_message);
// Place disabled test block in the invalid region of the default theme.
\Drupal::configFactory()->getEditable('block.block.' . $block->id())->set('region', 'invalid_region')->save();
......@@ -64,7 +64,7 @@ public function testBlockInInvalidRegion() {
// Clear the cache to check if the warning message is not triggered.
$this->drupalGet('admin/config/development/performance');
$this->submitForm([], 'Clear all caches');
$this->assertNoRaw($warning_message);
$this->assertSession()->pageTextNotContains($warning_message);
}
}
......@@ -244,17 +244,17 @@ public function testBlock() {
// Test deleting the block from the edit form.
$this->drupalGet('admin/structure/block/manage/' . $block['id']);
$this->clickLink('Remove block');
$this->assertRaw(t('Are you sure you want to remove the block @name?', ['@name' => $block['settings[label]']]));
$this->assertSession()->pageTextContains('Are you sure you want to remove the block ' . $block['settings[label]'] . '?');
$this->submitForm([], 'Remove');
$this->assertRaw(t('The block %name has been removed.', ['%name' => $block['settings[label]']]));
$this->assertSession()->pageTextContains('The block ' . $block['settings[label]'] . ' has been removed.');
// Test deleting a block via "Configure block" link.
$block = $this->drupalPlaceBlock('system_powered_by_block');
$this->drupalGet('admin/structure/block/manage/' . $block->id(), ['query' => ['destination' => 'admin']]);
$this->clickLink('Remove block');
$this->assertRaw(t('Are you sure you want to remove the block @name?', ['@name' => $block->label()]));
$this->assertSession()->pageTextContains('Are you sure you want to remove the block ' . $block->label() . '?');
$this->submitForm([], 'Remove');
$this->assertRaw(t('The block %name has been removed.', ['%name' => $block->label()]));
$this->assertSession()->pageTextContains('The block ' . $block->label() . ' has been removed.');
$this->assertSession()->addressEquals('admin');
$this->assertSession()->responseNotContains($block->id());
}
......
......@@ -2,7 +2,6 @@
namespace Drupal\Tests\block_content\Functional;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\block_content\Entity\BlockContent;
use Drupal\Core\Database\Database;
......@@ -60,10 +59,7 @@ public function testBlockContentCreation() {
$this->submitForm($edit, 'Save');
// Check that the Basic block has been created.
$this->assertRaw(new FormattableMarkup('@block %name has been created.', [
'@block' => 'basic',
'%name' => $edit['info[0][value]'],
]));
$this->assertSession()->pageTextContains('basic ' . $edit['info[0][value]'] . ' has been created.');
// Check that the view mode setting is hidden because only one exists.
$this->assertSession()->fieldNotExists('settings[view_mode]');
......@@ -81,9 +77,7 @@ public function testBlockContentCreation() {
$this->submitForm($edit, 'Save');
// Check that the Basic block has been created.
$this->assertRaw(new FormattableMarkup('A custom block with block description %value already exists.', [
'%value' => $edit['info[0][value]'],
]));
$this->assertSession()->pageTextContains('A custom block with block description ' . $edit['info[0][value]'] . ' already exists.');
$this->assertSession()->statusCodeEquals(200);
}
......@@ -99,7 +93,7 @@ public function testBlockContentCreationMultipleViewModes() {
'label' => 'Test View Mode',
];
$this->submitForm($edit, 'Save');
$this->assertRaw(t('Saved the %label view mode.', ['%label' => $edit['label']]));
$this->assertSession()->pageTextContains('Saved the ' . $edit['label'] . ' view mode.');
$this->drupalLogin($this->adminUser);
......@@ -111,10 +105,7 @@ public function testBlockContentCreationMultipleViewModes() {
$this->submitForm($edit, 'Save');
// Check that the Basic block has been created.
$this->assertRaw(new FormattableMarkup('@block %name has been created.', [
'@block' => 'basic',
'%name' => $edit['info[0][value]'],
]));
$this->assertSession()->pageTextContains('basic ' . $edit['info[0][value]'] . ' has been created.');
// Save our block permanently
$this->submitForm(['region' => 'content'], 'Save block');
......@@ -167,9 +158,7 @@ public function testBlockContentCreationMultipleViewModes() {
$this->submitForm($edit, 'Save');
// Check that the Basic block has been created.
$this->assertRaw(new FormattableMarkup('A custom block with block description %value already exists.', [
'%value' => $edit['info[0][value]'],
]));
$this->assertSession()->pageTextContains('A custom block with block description ' . $edit['info[0][value]'] . ' already exists.');
$this->assertSession()->statusCodeEquals(200);
}
......@@ -188,10 +177,7 @@ public function testDefaultBlockContentCreation() {
$this->submitForm($edit, 'Save');
// Check that the block has been created and that it is a basic block.
$this->assertRaw(new FormattableMarkup('@block %name has been created.', [
'@block' => 'basic',
'%name' => $edit['info[0][value]'],
]));
$this->assertSession()->pageTextContains('basic ' . $edit['info[0][value]'] . ' has been created.');
// Check that the block exists in the database.
$blocks = \Drupal::entityTypeManager()
......@@ -262,7 +248,7 @@ public function testBlockDelete() {
$this->assertSession()->pageTextContains('This will also remove 1 placed block instance.');
$this->submitForm([], 'Delete');
$this->assertRaw(t('The custom block %name has been deleted.', ['%name' => $edit['info[0][value]']]));
$this->assertSession()->pageTextContains('The custom block ' . $edit['info[0][value]'] . ' has been deleted.');
// Create another block and force the plugin cache to flush.
$edit2 = [];
......
......@@ -34,7 +34,7 @@ public function testPageEdit() {
// Ensure user was able to view the block.
$this->assertSession()->statusCodeEquals(200);
$this->drupalGet('<front>');
$this->assertRaw(t('This block is broken or missing. You may be missing content or you might need to enable the original module.'));
$this->assertSession()->pageTextContains('This block is broken or missing. You may be missing content or you might need to enable the original module.');
}
}
......@@ -145,13 +145,7 @@ protected function doTestTranslationEdit() {
$options = ['language' => $languages[$langcode]];
$url = $entity->toUrl('edit-form', $options);
$this->drupalGet($url);
$title = t('<em>Edit @type</em> @title [%language translation]', [
'@type' => $entity->bundle(),
'@title' => $entity->getTranslation($langcode)->label(),
'%language' => $languages[$langcode]->getName(),
]);
$this->assertRaw($title);
$this->assertSession()->pageTextContains("Edit {$entity->bundle()} {$entity->getTranslation($langcode)->label()} [{$languages[$langcode]->getName()} translation]");
}
}
}
......
......@@ -175,18 +175,14 @@ public function testBlockContentTypeDeletion() {
$block = $this->createBlockContent(FALSE, 'foo');
// Attempt to delete the block type, which should not be allowed.
$this->drupalGet('admin/structure/block/block-content/manage/' . $type->id() . '/delete');
$this->assertRaw(
t('%label is used by 1 custom block on your site. You can not remove this block type until you have removed all of the %label blocks.', ['%label' => $type->label()])
);
$this->assertSession()->pageTextContains($type->label() . ' is used by 1 custom block on your site. You can not remove this block type until you have removed all of the ' . $type->label() . ' blocks.');
$this->assertSession()->pageTextNotContains('This action cannot be undone.');
// Delete the block.
$block->delete();
// Attempt to delete the block type, which should now be allowed.
$this->drupalGet('admin/structure/block/block-content/manage/' . $type->id() . '/delete');
$this->assertRaw(
t('Are you sure you want to delete the custom block type %type?', ['%type' => $type->id()])
);
$this->assertSession()->pageTextContains('Are you sure you want to delete the custom block type ' . $type->id() . '?');
$this->assertSession()->pageTextContains('This action cannot be undone.');
}
......
......@@ -459,7 +459,7 @@ public function testBookDelete() {
$nodes = $this->createBook();
$this->drupalLogin($this->adminUser);
$this->drupalGet($this->book->toUrl('delete-form'));
$this->assertRaw(t('%title is part of a book outline, and has associated child pages. If you proceed with deletion, the child pages will be relocated automatically.', ['%title' => $this->book->label()]));
$this->assertSession()->pageTextContains($this->book->label() . ' is part of a book outline, and has associated child pages. If you proceed with deletion, the child pages will be relocated automatically.');
// Delete parent, and visit a child page.
$this->drupalGet($this->book->toUrl('delete-form'));
$this->submitForm([], 'Delete');
......@@ -489,7 +489,7 @@ public function testBookOutline() {
$this->drupalLogin($this->adminUser);
$this->drupalGet('node/' . $empty_book->id() . '/outline');
$this->assertRaw(t('Book outline'));
$this->assertSession()->pageTextContains('Book outline');
// Verify that the node does not belong to a book.
$this->assertTrue($this->assertSession()->optionExists('edit-book-bid', 0)->isSelected());
$this->assertSession()->linkNotExists('Remove from book outline');
......@@ -512,9 +512,9 @@ public function testBookOutline() {
$this->drupalLogin($this->adminUser);
$this->drupalGet('node/' . $book->id() . '/outline');
$this->assertRaw(t('Book outline'));
$this->assertSession()->pageTextContains('Book outline');
$this->clickLink('Remove from book outline');
$this->assertRaw(t('Are you sure you want to remove %title from the book hierarchy?', ['%title' => $book->label()]));
$this->assertSession()->pageTextContains('Are you sure you want to remove ' . $book->label() . ' from the book hierarchy?');
// Create a new node and set the book after the node was created.
$node = $this->drupalCreateNode(['type' => 'book']);
......
......@@ -77,7 +77,7 @@ public function testExistingFormat() {
'editor[editor]' => 'ckeditor',
];
$this->submitForm($edit, 'Save configuration');
$this->assertRaw(t('You must configure the selected text editor.'));
$this->assertSession()->pageTextContains('You must configure the selected text editor.');
// Ensure the CKEditor editor returns the expected default settings.
$expected_default_settings = [
......
......@@ -95,7 +95,7 @@ public function testExistingFormat() {
'editor[settings][plugins][stylescombo][styles]' => "h1.title|Title\np.callout|Title\n\n",
];
$this->submitForm($edit, 'Save configuration');
$this->assertRaw(t('Each style must have a unique label.'));
$this->assertSession()->pageTextContains('Each style must have a unique label.');
$editor = Editor::load($this->format);
$this->assertEquals($expected_settings, $editor->getSettings(), 'The Editor config entity has the correct settings.');
}
......
......@@ -80,9 +80,7 @@ public function testAnonymous() {
];
$this->drupalGet('comment/reply/node/' . $this->node->id() . '/comment');
$this->submitForm($edit, 'Save');
$this->assertRaw(t('The name you used (%name) belongs to a registered user.', [
'%name' => $this->adminUser->getAccountName(),
]));
$this->assertSession()->pageTextContains('The name you used (' . $this->adminUser->getAccountName() . ') belongs to a registered user.');
// Allow contact info.
$this->drupalLogin($this->adminUser);
......@@ -114,9 +112,7 @@ public function testAnonymous() {
];
$this->drupalGet('comment/reply/node/' . $this->node->id() . '/comment');
$this->submitForm($edit, 'Save');
$this->assertRaw(t('The name you used (%name) belongs to a registered user.', [
'%name' => $this->adminUser->getAccountName(),
]));
$this->assertSession()->pageTextContains('The name you used (' . $this->adminUser->getAccountName() . ') belongs to a registered user.');
// Require contact info.
$this->drupalLogin($this->adminUser);
......
......@@ -239,7 +239,7 @@ public function performCommentOperation($comment, $operation, $approval = FALSE)
if ($operation == 'delete') {
$this->submitForm([], 'Delete');
$this->assertRaw(\Drupal::translation()->formatPlural(1, 'Deleted 1 comment.', 'Deleted @count comments.'));
$this->assertSession()->pageTextContains('Deleted 1 comment.');
}
else {
$this->assertSession()->pageTextContains('The update has been performed.');
......
......@@ -45,7 +45,7 @@ public function testCommentPaging() {
// Check the first page of the node, and confirm the correct comments are
// shown.
$this->drupalGet('node/' . $node->id());
$this->assertRaw(t('next'));
$this->assertSession()->pageTextContains('next');
$this->assertTrue($this->commentExists($comments[0]), 'Comment 1 appears on page 1.');
$this->assertFalse($this->commentExists($comments[1]), 'Comment 2 does not appear on page 1.');
$this->assertFalse($this->commentExists($comments[2]), 'Comment 3 does not appear on page 1.');
......@@ -382,7 +382,7 @@ public function testTwoPagers() {
// Check the first page of the node, and confirm the correct comments are
// shown.
$this->drupalGet('node/' . $node->id());
$this->assertRaw(t('next'));
$this->assertSession()->pageTextContains('next');
$this->assertRaw('Comment 1 on field comment');
$this->assertRaw('Comment 1 on field comment_2');
// Navigate to next page of field 1.
......
......@@ -367,7 +367,7 @@ public function performCommentOperation(CommentInterface $comment, $operation, $
if ($operation == 'delete') {
$this->submitForm([], 'Delete');
$this->assertRaw(\Drupal::translation()->formatPlural(1, 'Deleted 1 comment.', 'Deleted @count comments.'));
$this->assertSession()->pageTextContains('Deleted 1 comment.');
}
else {
$this->assertSession()->pageTextContains('The update has been performed.');
......
......@@ -229,13 +229,7 @@ protected function doTestTranslationEdit() {
$options = ['language' => $languages[$langcode]];
$url = $entity->toUrl('edit-form', $options);
$this->drupalGet($url);
$title = t('Edit @type @title [%language translation]', [
'@type' => $this->entityTypeId,
'@title' => $entity->getTranslation($langcode)->label(),
'%language' => $languages[$langcode]->getName(),
]);
$this->assertRaw($title);
$this->assertSession()->pageTextContains("Edit {$this->entityTypeId} {$entity->getTranslation($langcode)->label()} [{$languages[$langcode]->getName()} translation]");
}
}
}
......
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