Commit 9ac7689b authored by catch's avatar catch

Issue #3159788 by mondrake, ravi.shankar, narendra.rajwar27, longwave,...

Issue #3159788 by mondrake, ravi.shankar, narendra.rajwar27, longwave, Hardik_Patel_12, ankithashetty, sarvjeetsingh, kishor_kolekar: AssertLegacyTrait::assert(No)Text() in functional tests still have a message passed in
parent 00b0a6ed
......@@ -52,8 +52,9 @@ public function testActionConfiguration() {
$action_id = $edit['id'];
// Make sure that the new complex action was saved properly.
$this->assertText('The action has been successfully saved.', "Make sure we get a confirmation that we've successfully saved the complex action.");
$this->assertText($action_label, "Make sure the action label appears on the configuration page after we've saved the complex action.");
$this->assertText('The action has been successfully saved.');
// The action label appears on the configuration page.
$this->assertText($action_label);
// Make another POST request to the action edit page.
$this->clickLink(t('Configure'));
......@@ -66,9 +67,12 @@ public function testActionConfiguration() {
$this->assertSession()->statusCodeEquals(200);
// Make sure that the action updated properly.
$this->assertText('The action has been successfully saved.', "Make sure we get a confirmation that we've successfully updated the complex action.");
$this->assertNoText($action_label, "Make sure the old action label does NOT appear on the configuration page after we've updated the complex action.");
$this->assertText($new_action_label, "Make sure the action label appears on the configuration page after we've updated the complex action.");
$this->assertText('The action has been successfully saved.');
// The old action label does NOT appear on the configuration page.
$this->assertNoText($action_label);
// The action label appears on the configuration page after we've updated
// the complex action.
$this->assertText($new_action_label);
$this->clickLink(t('Configure'));
$element = $this->xpath('//input[@type="text" and @value="admin"]');
......@@ -86,7 +90,8 @@ public function testActionConfiguration() {
$this->assertRaw(t('The action %action has been deleted.', ['%action' => $new_action_label]));
$this->drupalGet('admin/config/system/actions');
$this->assertSession()->statusCodeEquals(200);
$this->assertNoText($new_action_label, "Make sure the action label does not appear on the overview page after we've deleted the action.");
// The action label does not appear on the overview page.
$this->assertNoText($new_action_label);
$action = Action::load($action_id);
$this->assertNull($action, 'Make sure the action is gone after being deleted.');
......
......@@ -36,7 +36,8 @@ public function testAddFeed() {
// Check feed source.
$this->drupalGet('aggregator/sources/' . $feed->id());
$this->assertSession()->statusCodeEquals(200);
$this->assertText($feed->label(), 'Page title');
// Verify that the feed label is present in the page title.
$this->assertText($feed->label());
$this->assertRaw($feed->getWebsiteUrl());
// Try to add a duplicate.
......@@ -92,7 +93,8 @@ public function testAddLongFeed() {
// Check feed source.
$this->drupalGet('aggregator/sources/' . $feed->id());
$this->assertSession()->statusCodeEquals(200);
$this->assertText($feed->label(), 'Page title');
// Verify that the feed label is present in the page title.
$this->assertText($feed->label());
// Delete feeds.
$this->deleteFeed($feed);
......
......@@ -56,7 +56,7 @@ public function testBlockLinks() {
// Confirm that the block is now being displayed on pages.
$this->drupalGet('test-page');
$this->assertText($block->label(), 'Feed block is displayed on the page.');
$this->assertText($block->label());
// Confirm items appear as links.
$items = $this->container->get('entity_type.manager')->getStorage('aggregator_item')->loadByFeed($feed->id(), 1);
......@@ -80,7 +80,7 @@ public function testBlockLinks() {
$block->save();
// Check that the block is no longer displayed.
$this->drupalGet('test-page');
$this->assertNoText($block->label(), 'Feed block is not displayed on the page when number of items is set to 0.');
$this->assertNoText($block->label());
}
/**
......
......@@ -75,7 +75,7 @@ protected function setUp() {
public function createFeed($feed_url = NULL, array $edit = []) {
$edit = $this->getFeedEditArray($feed_url, $edit);
$this->drupalPostForm('aggregator/sources/add', $edit, 'Save');
$this->assertText('The feed ' . Html::escape($edit['title[0][value]']) . ' has been added.', new FormattableMarkup('The feed @name has been added.', ['@name' => $edit['title[0][value]']]));
$this->assertText('The feed ' . Html::escape($edit['title[0][value]']) . ' has been added.');
// Verify that the creation message contains a link to a feed.
$this->assertSession()->elementExists('xpath', '//div[@data-drupal-messages]//a[contains(@href, "aggregator/sources/")]');
......
......@@ -26,20 +26,20 @@ public function testFeedUpdateFields() {
// The scheduled feed shows that it has not been updated yet and is
// scheduled.
$this->assertText('never', 'The scheduled feed has not been updated yet. Last update shows "never".');
$this->assertText('imminently', 'The scheduled feed has not been updated yet. Next update shows "imminently".');
$this->assertNoText('ago', 'The scheduled feed has not been updated yet. Last update does not show "x x ago".');
$this->assertNoText('left', 'The scheduled feed has not been updated yet. Next update does not show "x x left".');
$this->assertText('never');
$this->assertText('imminently');
$this->assertNoText('ago');
$this->assertNoText('left');
$this->updateFeedItems($scheduled_feed);
$this->drupalGet('admin/config/services/aggregator');
// After the update, an interval should be displayed on both last updated
// and next update.
$this->assertNoText('never', 'The scheduled feed has been updated. Last updated changed.');
$this->assertNoText('imminently', 'The scheduled feed has been updated. Next update changed.');
$this->assertText('ago', 'The scheduled feed been updated. Last update shows "x x ago".');
$this->assertText('left', 'The scheduled feed has been updated. Next update shows "x x left".');
$this->assertNoText('never');
$this->assertNoText('imminently');
$this->assertText('ago');
$this->assertText('left');
// Delete scheduled feed.
$this->deleteFeed($scheduled_feed);
......@@ -49,20 +49,20 @@ public function testFeedUpdateFields() {
$this->drupalGet('admin/config/services/aggregator');
// The non scheduled feed shows that it has not been updated yet.
$this->assertText('never', 'The non scheduled feed has not been updated yet. Last update shows "never".');
$this->assertNoText('imminently', 'The non scheduled feed does not show "imminently" as next update.');
$this->assertNoText('ago', 'The non scheduled feed has not been updated. It does not show "x x ago" as last update.');
$this->assertNoText('left', 'The feed is not scheduled. It does not show a timeframe "x x left" for next update.');
$this->assertText('never');
$this->assertNoText('imminently');
$this->assertNoText('ago');
$this->assertNoText('left');
$this->updateFeedItems($non_scheduled_feed);
$this->drupalGet('admin/config/services/aggregator');
// After the feed update, we still need to see "never" as next update label.
// Last update will show an interval.
$this->assertNoText('imminently', 'The updated non scheduled feed does not show "imminently" as next update.');
$this->assertText('never', 'The updated non scheduled feed still shows "never" as next update.');
$this->assertText('ago', 'The non scheduled feed has been updated. It shows "x x ago" as last update.');
$this->assertNoText('left', 'The feed is not scheduled. It does not show a timeframe "x x left" for next update.');
$this->assertText('never');
$this->assertNoText('imminently');
$this->assertText('ago');
$this->assertNoText('left');
}
/**
......
......@@ -46,7 +46,7 @@ public function openImportForm() {
$this->drupalPlaceBlock('help_block', ['region' => 'help']);
$this->drupalGet('admin/config/services/aggregator/add/opml');
$this->assertText('A single OPML document may contain many feeds.', 'Found OPML help text.');
$this->assertText('A single OPML document may contain many feeds.');
// Ensure that the file upload, remote URL, and refresh fields exist.
$this->assertSession()->fieldExists('files[upload]');
$this->assertSession()->fieldExists('remote');
......@@ -72,9 +72,10 @@ public function validateImportFormFields() {
$this->drupalPostForm('admin/config/services/aggregator/add/opml', $edit, 'Import');
$this->assertRaw(t('<em>Either</em> upload a file or enter a URL.'));
// Error if the URL is invalid.
$edit = ['remote' => 'invalidUrl://empty'];
$this->drupalPostForm('admin/config/services/aggregator/add/opml', $edit, 'Import');
$this->assertText('The URL invalidUrl://empty is not valid.', 'Error if the URL is invalid.');
$this->assertText('The URL invalidUrl://empty is not valid.');
$after = $count_query->execute();
$this->assertEqual($before, $after, 'No feeds were added during the three last form submissions.');
......@@ -87,13 +88,15 @@ protected function submitImportForm() {
$count_query = \Drupal::entityQuery('aggregator_feed')->count();
$before = $count_query->execute();
// Attempting to upload invalid XML.
$form['files[upload]'] = $this->getInvalidOpml();
$this->drupalPostForm('admin/config/services/aggregator/add/opml', $form, 'Import');
$this->assertText('No new feed has been added.', 'Attempting to upload invalid XML.');
$this->assertText('No new feed has been added.');
// Attempting to load empty OPML from remote URL
$edit = ['remote' => file_create_url($this->getEmptyOpml())];
$this->drupalPostForm('admin/config/services/aggregator/add/opml', $edit, 'Import');
$this->assertText('No new feed has been added.', 'Attempting to load empty OPML from remote URL.');
$this->assertText('No new feed has been added.');
$after = $count_query->execute();
$this->assertEqual($before, $after, 'No feeds were added during the two last form submissions.');
......
......@@ -44,7 +44,7 @@ public function testUpdateFeedItem() {
$this->assertSession()->statusCodeEquals(200);
$this->drupalPostForm('aggregator/sources/add', $edit, 'Save');
$this->assertText('The feed ' . $edit['title[0][value]'] . ' has been added.', new FormattableMarkup('The feed @name has been added.', ['@name' => $edit['title[0][value]']]));
$this->assertText('The feed ' . $edit['title[0][value]'] . ' has been added.');
// Verify that the creation message contains a link to a feed.
$this->assertSession()->elementExists('xpath', '//div[@data-drupal-messages]//a[contains(@href, "aggregator/sources/")]');
......
......@@ -2,8 +2,6 @@
namespace Drupal\Tests\aggregator\Functional;
use Drupal\Component\Render\FormattableMarkup;
/**
* Update feed test.
*
......@@ -32,7 +30,7 @@ public function testUpdateFeed() {
$edit[$same_field] = $feed->{$same_field}->value;
}
$this->drupalPostForm('aggregator/sources/' . $feed->id() . '/configure', $edit, 'Save');
$this->assertText('The feed ' . $edit['title[0][value]'] . ' has been updated.', new FormattableMarkup('The feed %name has been updated.', ['%name' => $edit['title[0][value]']]));
$this->assertText('The feed ' . $edit['title[0][value]'] . ' has been updated.');
// Verify that the creation message contains a link to a feed.
$this->assertSession()->elementExists('xpath', '//div[@data-drupal-messages]//a[contains(@href, "aggregator/sources/")]');
......@@ -41,10 +39,10 @@ public function testUpdateFeed() {
$this->assertSession()->addressEquals($feed->toUrl('canonical'));
$this->assertTrue($this->uniqueFeed($edit['title[0][value]'], $edit['url[0][value]']), 'The feed is unique.');
// Check feed source.
// Check feed source, the title should be on the page.
$this->drupalGet('aggregator/sources/' . $feed->id());
$this->assertSession()->statusCodeEquals(200);
$this->assertText($edit['title[0][value]'], 'Page title');
$this->assertText($edit['title[0][value]']);
// Set correct title so deleteFeed() will work.
$feed->title = $edit['title[0][value]'];
......
......@@ -48,7 +48,7 @@ public function testBasicAuth() {
// Ensure we can log in with valid authentication details.
$this->basicAuthGet($url, $account->getAccountName(), $account->pass_raw);
$this->assertText($account->getAccountName(), 'Account name is displayed.');
$this->assertText($account->getAccountName());
$this->assertSession()->statusCodeEquals(200);
$this->mink->resetSessions();
$this->assertSession()->responseHeaderDoesNotExist('X-Drupal-Cache');
......@@ -57,7 +57,7 @@ public function testBasicAuth() {
// Ensure that invalid authentication details give access denied.
$this->basicAuthGet($url, $account->getAccountName(), $this->randomMachineName());
$this->assertNoText($account->getAccountName(), 'Bad basic auth credentials do not authenticate the user.');
$this->assertNoText($account->getAccountName());
$this->assertSession()->statusCodeEquals(403);
$this->mink->resetSessions();
......@@ -164,7 +164,7 @@ public function testLocale() {
$url = Url::fromRoute('router_test.11');
$this->basicAuthGet($url, $account->getAccountName(), $account->pass_raw);
$this->assertText($account->getAccountName(), 'Account name is displayed.');
$this->assertText($account->getAccountName());
$this->assertSession()->statusCodeEquals(200);
}
......@@ -175,27 +175,31 @@ public function testUnauthorizedErrorMessage() {
$account = $this->drupalCreateUser();
$url = Url::fromRoute('router_test.11');
// Case when no credentials are passed.
// Case when no credentials are passed, a user friendly access
// unauthorized message is displayed.
$this->drupalGet($url);
$this->assertSession()->statusCodeEquals(401);
$this->assertNoText('Exception', "No raw exception is displayed on the page.");
$this->assertText('Please log in to access this page.', "A user friendly access unauthorized message is displayed.");
$this->assertNoText('Exception');
$this->assertText('Please log in to access this page.');
// Case when empty credentials are passed.
// Case when empty credentials are passed, a user friendly access denied
// message is displayed.
$this->basicAuthGet($url, NULL, NULL);
$this->assertSession()->statusCodeEquals(403);
$this->assertText('Access denied', "A user friendly access denied message is displayed");
$this->assertText('Access denied');
// Case when wrong credentials are passed.
// Case when wrong credentials are passed, a user friendly access denied
// message is displayed.
$this->basicAuthGet($url, $account->getAccountName(), $this->randomMachineName());
$this->assertSession()->statusCodeEquals(403);
$this->assertText('Access denied', "A user friendly access denied message is displayed");
$this->assertText('Access denied');
// Case when correct credentials but hasn't access to the route.
// Case when correct credentials but hasn't access to the route, an user
// friendly access denied message is displayed.
$url = Url::fromRoute('router_test.15');
$this->basicAuthGet($url, $account->getAccountName(), $account->pass_raw);
$this->assertSession()->statusCodeEquals(403);
$this->assertText('Access denied', "A user friendly access denied message is displayed");
$this->assertText('Access denied');
}
/**
......
......@@ -85,20 +85,21 @@ public function testCachePerRole() {
\Drupal::state()->set('block_test.content', $current_content);
$this->drupalLogin($this->normalUser);
$this->drupalGet('');
$this->assertText($current_content, 'Block content displays.');
$this->assertText($current_content);
// Change the content, but the cached copy should still be served.
$old_content = $current_content;
$current_content = $this->randomMachineName();
\Drupal::state()->set('block_test.content', $current_content);
$this->drupalGet('');
$this->assertText($old_content, 'Block is served from the cache.');
$this->assertText($old_content);
// Clear the cache and verify that the stale data is no longer there.
Cache::invalidateTags(['block_view']);
$this->drupalGet('');
$this->assertNoText($old_content, 'Block cache clear removes stale cache data.');
$this->assertText($current_content, 'Fresh block content is displayed after clearing the cache.');
$this->assertNoText($old_content);
// Fresh block content is displayed after clearing the cache.
$this->assertText($current_content);
// Test whether the cached data is served for the correct users.
$old_content = $current_content;
......@@ -106,19 +107,23 @@ public function testCachePerRole() {
\Drupal::state()->set('block_test.content', $current_content);
$this->drupalLogout();
$this->drupalGet('');
$this->assertNoText($old_content, 'Anonymous user does not see content cached per-role for normal user.');
// Anonymous user does not see content cached per-role for normal user.
$this->assertNoText($old_content);
// User with the same roles sees per-role cached content.
$this->drupalLogin($this->normalUserAlt);
$this->drupalGet('');
$this->assertText($old_content, 'User with the same roles sees per-role cached content.');
$this->assertText($old_content);
// Admin user does not see content cached per-role for normal user.
$this->drupalLogin($this->adminUser);
$this->drupalGet('');
$this->assertNoText($old_content, 'Admin user does not see content cached per-role for normal user.');
$this->assertNoText($old_content);
// Block is served from the per-role cache.
$this->drupalLogin($this->normalUser);
$this->drupalGet('');
$this->assertText($old_content, 'Block is served from the per-role cache.');
$this->assertText($old_content);
}
/**
......@@ -133,18 +138,20 @@ public function testCachePermissions() {
\Drupal::state()->set('block_test.content', $current_content);
$this->drupalGet('');
$this->assertText($current_content, 'Block content displays.');
$this->assertText($current_content);
$old_content = $current_content;
$current_content = $this->randomMachineName();
\Drupal::state()->set('block_test.content', $current_content);
// Block content served from cache.
$this->drupalGet('user');
$this->assertText($old_content, 'Block content served from cache.');
$this->assertText($old_content);
// Block content not served from cache.
$this->drupalLogout();
$this->drupalGet('user');
$this->assertText($current_content, 'Block content not served from cache.');
$this->assertText($current_content);
}
/**
......@@ -158,13 +165,14 @@ public function testNoCache() {
// If max_age = 0 has no effect, the next request would be cached.
$this->drupalGet('');
$this->assertText($current_content, 'Block content displays.');
$this->assertText($current_content);
// A cached copy should not be served.
$current_content = $this->randomMachineName();
\Drupal::state()->set('block_test.content', $current_content);
$this->drupalGet('');
$this->assertText($current_content, 'Maximum age of zero prevents blocks from being cached.');
// Maximum age of zero prevents blocks from being cached.
$this->assertText($current_content);
}
/**
......@@ -178,22 +186,25 @@ public function testCachePerUser() {
$this->drupalLogin($this->normalUser);
$this->drupalGet('');
$this->assertText($current_content, 'Block content displays.');
$this->assertText($current_content);
$old_content = $current_content;
$current_content = $this->randomMachineName();
\Drupal::state()->set('block_test.content', $current_content);
// Block is served from per-user cache.
$this->drupalGet('');
$this->assertText($old_content, 'Block is served from per-user cache.');
$this->assertText($old_content);
// Per-user block cache is not served for other users.
$this->drupalLogin($this->normalUserAlt);
$this->drupalGet('');
$this->assertText($current_content, 'Per-user block cache is not served for other users.');
$this->assertText($current_content);
// Per-user block cache is persistent.
$this->drupalLogin($this->normalUser);
$this->drupalGet('');
$this->assertText($old_content, 'Per-user block cache is persistent.');
$this->assertText($old_content);
}
/**
......@@ -206,7 +217,7 @@ public function testCachePerPage() {
\Drupal::state()->set('block_test.content', $current_content);
$this->drupalGet('test-page');
$this->assertText($current_content, 'Block content displays on the test page.');
$this->assertText($current_content);
$old_content = $current_content;
$current_content = $this->randomMachineName();
......@@ -214,10 +225,13 @@ public function testCachePerPage() {
$this->drupalGet('user');
$this->assertSession()->statusCodeEquals(200);
$this->assertNoText($old_content, 'Block content cached for the test page does not show up for the user page.');
// Verify that block content cached for the test page does not show up
// for the user page.
$this->assertNoText($old_content);
$this->drupalGet('test-page');
$this->assertSession()->statusCodeEquals(200);
$this->assertText($old_content, 'Block content cached for the test page.');
// Verify that the block content is cached for the test page.
$this->assertText($old_content);
}
}
......@@ -43,7 +43,7 @@ public function testCachePerPage() {
// Go to "test-page" and test if the block is enabled.
$this->drupalGet('test-page');
$this->assertSession()->statusCodeEquals(200);
$this->assertText('Your .com email address.', 'form found');
$this->assertText('Your .com email address.');
// Make sure that we're currently still on /test-page after submitting the
// form.
......@@ -54,7 +54,7 @@ public function testCachePerPage() {
// Go to a different page and see if the block is enabled there as well.
$this->drupalGet('test-render-title');
$this->assertSession()->statusCodeEquals(200);
$this->assertText('Your .com email address.', 'form found');
$this->assertText('Your .com email address.');
// Make sure that submitting the form didn't redirect us to the first page
// we submitted the form from after submitting the form from
......@@ -71,7 +71,7 @@ public function testPlaceholders() {
$this->drupalGet('test-multiple-forms');
$placeholder = 'form_action_' . Crypt::hashBase64('Drupal\Core\Form\FormBuilder::prepareForm');
$this->assertText('Form action: ' . $placeholder, 'placeholder found.');
$this->assertText('Form action: ' . $placeholder);
}
}
......@@ -52,7 +52,7 @@ public function testBlockNotInHiddenRegion() {
// Ensure that the search form block is displayed.
$this->drupalGet('');
$this->assertText('Search', 'Block was displayed on the front page.');
$this->assertText('Search');
// Install "block_test_theme" and set it as the default theme.
$theme = 'block_test_theme';
......@@ -72,7 +72,7 @@ public function testBlockNotInHiddenRegion() {
// Ensure that the search form block is displayed.
$this->drupalGet('');
$this->assertText('Search', 'Block was displayed on the front page.');
$this->assertText('Search');
}
}
......@@ -44,7 +44,9 @@ protected function setUp(): void {
'predefined_langcode' => 'fr',
];
$this->drupalPostForm('admin/config/regional/language/add', $edit, 'Add language');
$this->assertText('French', 'Language added successfully.');
// Verify that language was added successfully.
$this->assertText('French');
}
/**
......@@ -75,11 +77,11 @@ public function testLanguageBlockVisibility() {
// Check that a page has a block.
$this->drupalGet('en');
$this->assertText('Powered by Drupal', 'The body of the custom block appears on the page.');
$this->assertText('Powered by Drupal');
// Check that a page doesn't has a block for the current language anymore.
$this->drupalGet('fr');
$this->assertNoText('Powered by Drupal', 'The body of the custom block does not appear on the page.');
$this->assertNoText('Powered by Drupal');
}
/**
......@@ -154,9 +156,9 @@ public function testMultipleLanguageTypes() {
// Interface negotiation depends on request arguments.
$this->drupalGet('node', ['query' => ['language' => 'en']]);
$this->assertNoText('Powered by Drupal', 'The body of the block does not appear on the page.');
$this->assertNoText('Powered by Drupal');
$this->drupalGet('node', ['query' => ['language' => 'fr']]);
$this->assertText('Powered by Drupal', 'The body of the block appears on the page.');
$this->assertText('Powered by Drupal');
// Log in again in order to clear the interface language stored in the
// session.
......@@ -166,9 +168,9 @@ public function testMultipleLanguageTypes() {
// Content language does not depend on session/request arguments.