Commit 11387380 authored by xjm's avatar xjm

Issue #3139218 by mondrake, daffie: Replace usages of...

Issue #3139218 by mondrake, daffie: Replace usages of AssertLegacyTrait::assertResponse(), which is deprecated
parent d9b70a9f
......@@ -38,7 +38,7 @@ public function testActionConfiguration() {
$edit = [];
$edit['action'] = 'action_goto_action';
$this->drupalPostForm('admin/config/system/actions', $edit, t('Create'));
$this->assertResponse(200);
$this->assertSession()->statusCodeEquals(200);
// Make a POST request to the individual action configuration page.
$edit = [];
......@@ -47,7 +47,7 @@ public function testActionConfiguration() {
$edit['id'] = strtolower($action_label);
$edit['url'] = 'admin';
$this->drupalPostForm('admin/config/system/actions/add/action_goto_action', $edit, t('Save'));
$this->assertResponse(200);
$this->assertSession()->statusCodeEquals(200);
$action_id = $edit['id'];
......@@ -63,7 +63,7 @@ public function testActionConfiguration() {
$edit['label'] = $new_action_label;
$edit['url'] = 'admin';
$this->drupalPostForm(NULL, $edit, t('Save'));
$this->assertResponse(200);
$this->assertSession()->statusCodeEquals(200);
// Make sure that the action updated properly.
$this->assertText(t('The action has been successfully saved.'), "Make sure we get a confirmation that we've successfully updated the complex action.");
......@@ -77,15 +77,15 @@ public function testActionConfiguration() {
// Make sure that deletions work properly.
$this->drupalGet('admin/config/system/actions');
$this->clickLink(t('Delete'));
$this->assertResponse(200);
$this->assertSession()->statusCodeEquals(200);
$edit = [];
$this->drupalPostForm(NULL, $edit, t('Delete'));
$this->assertResponse(200);
$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]), 'Make sure that we get a delete confirmation message.');
$this->drupalGet('admin/config/system/actions');
$this->assertResponse(200);
$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.");
$action = Action::load($action_id);
......
......@@ -35,7 +35,7 @@ public function testAddFeed() {
// Check feed source.
$this->drupalGet('aggregator/sources/' . $feed->id());
$this->assertResponse(200);
$this->assertSession()->statusCodeEquals(200);
$this->assertText($feed->label(), 'Page title');
$this->assertRaw($feed->getWebsiteUrl());
......@@ -61,7 +61,7 @@ public function testFeedLabelEscaping() {
$this->checkForMetaRefresh();
$this->drupalGet('aggregator/sources/' . $feed->id());
$this->assertResponse(200);
$this->assertSession()->statusCodeEquals(200);
$this->assertEscaped('Test feed title <script>alert(123);</script>');
$this->assertNoRaw('Test feed title <script>alert(123);</script>');
......@@ -91,7 +91,7 @@ public function testAddLongFeed() {
// Check feed source.
$this->drupalGet('aggregator/sources/' . $feed->id());
$this->assertResponse(200);
$this->assertSession()->statusCodeEquals(200);
$this->assertText($feed->label(), 'Page title');
// Delete feeds.
......
......@@ -60,7 +60,7 @@ public function testSettingsPage() {
$this->container->get('module_installer')->uninstall(['aggregator_test']);
$this->resetAll();
$this->drupalGet('admin/config/services/aggregator/settings');
$this->assertResponse(200);
$this->assertSession()->statusCodeEquals(200);
}
/**
......
......@@ -127,12 +127,12 @@ public function testFeedPage() {
// Check the rss aggregator page as anonymous user.
$this->drupalLogout();
$this->drupalGet('aggregator/rss');
$this->assertResponse(403);
$this->assertSession()->statusCodeEquals(403);
// Check the rss aggregator page as admin.
$this->drupalLogin($this->adminUser);
$this->drupalGet('aggregator/rss');
$this->assertResponse(200);
$this->assertSession()->statusCodeEquals(200);
$this->assertEqual($this->drupalGetHeader('Content-type'), 'application/rss+xml; charset=utf-8');
// Check the opml aggregator page.
......
......@@ -181,11 +181,11 @@ public function getDefaultFeedItemCount() {
public function updateFeedItems(FeedInterface $feed, $expected_count = NULL) {
// First, let's ensure we can get to the rss xml.
$this->drupalGet($feed->getUrl());
$this->assertResponse(200);
$this->assertSession()->statusCodeEquals(200);
// Attempt to access the update link directly without an access token.
$this->drupalGet('admin/config/services/aggregator/update/' . $feed->id());
$this->assertResponse(403);
$this->assertSession()->statusCodeEquals(403);
// Refresh the feed (simulated link click).
$this->drupalGet('admin/config/services/aggregator');
......
......@@ -45,7 +45,7 @@ public function testDeleteFeed() {
// Check feed source.
$this->drupalGet('aggregator/sources/' . $feed1->id());
$this->assertResponse(404);
$this->assertSession()->statusCodeEquals(404);
// Check database for feed.
$result = \Drupal::entityQuery('aggregator_feed')->condition('title', $feed1->label())->condition('url', $feed1->getUrl())->count()->execute();
......
......@@ -22,7 +22,7 @@ public function testFeedUpdateFields() {
$scheduled_feed = $this->createFeed(NULL, ['refresh' => '900']);
$this->drupalGet('admin/config/services/aggregator');
$this->assertResponse(200);
$this->assertSession()->statusCodeEquals(200);
// The scheduled feed shows that it has not been updated yet and is
// scheduled.
......
......@@ -37,7 +37,7 @@ public function testRSS091Sample() {
$feed = $this->createFeed($this->getRSS091Sample());
$feed->refreshItems();
$this->drupalGet('aggregator/sources/' . $feed->id());
$this->assertResponse(200);
$this->assertSession()->statusCodeEquals(200);
$this->assertText('First example feed item title');
$this->assertLinkByHref('http://example.com/example-turns-one');
$this->assertText('First example feed item description.');
......@@ -60,7 +60,7 @@ public function testAtomSample() {
$feed = $this->createFeed($this->getAtomSample());
$feed->refreshItems();
$this->drupalGet('aggregator/sources/' . $feed->id());
$this->assertResponse(200);
$this->assertSession()->statusCodeEquals(200);
$this->assertText('Atom-Powered Robots Run Amok');
$this->assertLinkByHref('http://example.org/2003/12/13/atom03');
$this->assertText('Some text.');
......@@ -84,7 +84,7 @@ public function testHtmlEntitiesSample() {
$feed = $this->createFeed($this->getHtmlEntitiesSample());
$feed->refreshItems();
$this->drupalGet('aggregator/sources/' . $feed->id());
$this->assertResponse(200);
$this->assertSession()->statusCodeEquals(200);
$this->assertRaw("Quote&quot; Amp&amp;");
}
......
......@@ -41,7 +41,7 @@ public function testUpdateFeedItem() {
];
$this->drupalGet($edit['url[0][value]']);
$this->assertResponse(200);
$this->assertSession()->statusCodeEquals(200);
$this->drupalPostForm('aggregator/sources/add', $edit, t('Save'));
$this->assertText(t('The feed @name has been added.', ['@name' => $edit['title[0][value]']]), new FormattableMarkup('The feed @name has been added.', ['@name' => $edit['title[0][value]']]));
......@@ -75,7 +75,7 @@ public function testUpdateFeedItem() {
$this->enableTestPlugins();
$this->container->get('module_installer')->uninstall(['aggregator_test']);
$this->updateFeedItems($feed);
$this->assertResponse(200);
$this->assertSession()->statusCodeEquals(200);
}
}
......@@ -44,7 +44,7 @@ public function testUpdateFeed() {
// Check feed source.
$this->drupalGet('aggregator/sources/' . $feed->id());
$this->assertResponse(200);
$this->assertSession()->statusCodeEquals(200);
$this->assertText($edit['title[0][value]'], 'Page title');
// Set correct title so deleteFeed() will work.
......
......@@ -50,7 +50,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->assertResponse(200);
$this->assertSession()->statusCodeEquals(200);
$this->mink->resetSessions();
$this->assertNull($this->drupalGetHeader('X-Drupal-Cache'));
// Check that Cache-Control is not set to public.
......@@ -59,25 +59,25 @@ 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->assertResponse(403);
$this->assertSession()->statusCodeEquals(403);
$this->mink->resetSessions();
// Ensure that the user is prompted to authenticate if they are not yet
// authenticated and the route only allows basic auth.
$this->drupalGet($url);
$this->assertEqual($this->drupalGetHeader('WWW-Authenticate'), new FormattableMarkup('Basic realm="@realm"', ['@realm' => \Drupal::config('system.site')->get('name')]));
$this->assertResponse(401);
$this->assertSession()->statusCodeEquals(401);
// Ensure that a route without basic auth defined doesn't prompt for auth.
$this->drupalGet('admin');
$this->assertResponse(403);
$this->assertSession()->statusCodeEquals(403);
$account = $this->drupalCreateUser(['access administration pages']);
// Ensure that a route without basic auth defined doesn't allow login.
$this->basicAuthGet(Url::fromRoute('system.admin'), $account->getAccountName(), $account->pass_raw);
$this->assertNoLink('Log out', 'User is not logged in');
$this->assertResponse(403);
$this->assertSession()->statusCodeEquals(403);
$this->mink->resetSessions();
// Ensure that pages already in the page cache aren't returned from page
......@@ -113,7 +113,7 @@ public function testGlobalLoginFloodControl() {
// IP limit has reached to its limit. Even valid user credentials will fail.
$this->basicAuthGet($url, $user->getAccountName(), $user->pass_raw);
$this->assertResponse(403);
$this->assertSession()->statusCodeEquals(403);
}
/**
......@@ -137,7 +137,7 @@ public function testPerUserLoginFloodControl() {
// A successful login will reset the per-user flood control count.
$this->basicAuthGet($url, $user->getAccountName(), $user->pass_raw);
$this->assertResponse(200);
$this->assertSession()->statusCodeEquals(200);
// Try 2 failed logins for a user. They will trigger flood control.
for ($i = 0; $i < 2; $i++) {
......@@ -146,12 +146,12 @@ public function testPerUserLoginFloodControl() {
// Now the user account is blocked.
$this->basicAuthGet($url, $user->getAccountName(), $user->pass_raw);
$this->assertResponse(403);
$this->assertSession()->statusCodeEquals(403);
// Try one successful attempt for a different user, it should not trigger
// any flood control.
$this->basicAuthGet($url, $user2->getAccountName(), $user2->pass_raw);
$this->assertResponse(200);
$this->assertSession()->statusCodeEquals(200);
}
/**
......@@ -166,7 +166,7 @@ public function testLocale() {
$this->basicAuthGet($url, $account->getAccountName(), $account->pass_raw);
$this->assertText($account->getAccountName(), 'Account name is displayed.');
$this->assertResponse(200);
$this->assertSession()->statusCodeEquals(200);
}
/**
......@@ -178,24 +178,24 @@ public function testUnauthorizedErrorMessage() {
// Case when no credentials are passed.
$this->drupalGet($url);
$this->assertResponse(401);
$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.");
// Case when empty credentials are passed.
$this->basicAuthGet($url, NULL, NULL);
$this->assertResponse(403);
$this->assertSession()->statusCodeEquals(403);
$this->assertText('Access denied', "A user friendly access denied message is displayed");
// Case when wrong credentials are passed.
$this->basicAuthGet($url, $account->getAccountName(), $this->randomMachineName());
$this->assertResponse(403);
$this->assertSession()->statusCodeEquals(403);
$this->assertText('Access denied', "A user friendly access denied message is displayed");
// Case when correct credentials but hasn't access to the route.
$url = Url::fromRoute('router_test.15');
$this->basicAuthGet($url, $account->getAccountName(), $account->pass_raw);
$this->assertResponse(403);
$this->assertSession()->statusCodeEquals(403);
$this->assertText('Access denied', "A user friendly access denied message is displayed");
}
......@@ -247,19 +247,19 @@ public function testCacheabilityOf401Response() {
*/
public function testControllerNotCalledBeforeAuth() {
$this->drupalGet('/basic_auth_test/state/modify');
$this->assertResponse(401);
$this->assertSession()->statusCodeEquals(401);
$this->drupalGet('/basic_auth_test/state/read');
$this->assertResponse(200);
$this->assertSession()->statusCodeEquals(200);
$this->assertRaw('nope');
$account = $this->drupalCreateUser();
$this->basicAuthGet('/basic_auth_test/state/modify', $account->getAccountName(), $account->pass_raw);
$this->assertResponse(200);
$this->assertSession()->statusCodeEquals(200);
$this->assertRaw('Done');
$this->mink->resetSessions();
$this->drupalGet('/basic_auth_test/state/read');
$this->assertResponse(200);
$this->assertSession()->statusCodeEquals(200);
$this->assertRaw('yep');
}
......
......@@ -34,14 +34,14 @@ public function testAdminTheme() {
// Ensure that access to block admin page is denied when theme is not
// installed.
$this->drupalGet('admin/structure/block/list/bartik');
$this->assertResponse(403);
$this->assertSession()->statusCodeEquals(403);
// Install admin theme and confirm that tab is accessible.
\Drupal::service('theme_installer')->install(['bartik']);
$edit['admin_theme'] = 'bartik';
$this->drupalPostForm('admin/appearance', $edit, t('Save configuration'));
$this->drupalGet('admin/structure/block/list/bartik');
$this->assertResponse(200);
$this->assertSession()->statusCodeEquals(200);
}
/**
......
......@@ -210,10 +210,10 @@ public function testCachePerPage() {
\Drupal::state()->set('block_test.content', $current_content);
$this->drupalGet('user');
$this->assertResponse(200);
$this->assertSession()->statusCodeEquals(200);
$this->assertNoText($old_content, 'Block content cached for the test page does not show up for the user page.');
$this->drupalGet('test-page');
$this->assertResponse(200);
$this->assertSession()->statusCodeEquals(200);
$this->assertText($old_content, 'Block content cached for the test page.');
}
......
......@@ -35,7 +35,7 @@ public function testBlockDemo() {
$config = $this->container->get('config.factory')->get('system.theme');
$default_theme = $config->get('default');
$this->drupalGet('admin/structure/block/demo/' . $default_theme);
$this->assertResponse(200);
$this->assertSession()->statusCodeEquals(200);
$this->assertLinkByHref('admin/structure/block');
$this->assertNoLinkByHref('admin/structure/block/list/' . $default_theme);
......@@ -55,14 +55,14 @@ public function testBlockDemo() {
$this->container->get('theme_installer')->install([$theme]);
// Confirm access to the block demo page for the theme.
$this->drupalGet('admin/structure/block/demo/' . $theme);
$this->assertResponse(200);
$this->assertSession()->statusCodeEquals(200);
// Confirm existence of link for "Exit block region demonstration".
$this->assertLinkByHref('admin/structure/block/list/' . $theme);
}
// Confirm access to the block demo page is denied for an invalid theme.
$this->drupalGet('admin/structure/block/demo/invalid_theme');
$this->assertResponse(403);
$this->assertSession()->statusCodeEquals(403);
}
}
......@@ -42,7 +42,7 @@ public function testCachePerPage() {
// Go to "test-page" and test if the block is enabled.
$this->drupalGet('test-page');
$this->assertResponse(200);
$this->assertSession()->statusCodeEquals(200);
$this->assertText('Your .com email address.', 'form found');
// Make sure that we're currently still on /test-page after submitting the
......@@ -53,7 +53,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->assertResponse(200);
$this->assertSession()->statusCodeEquals(200);
$this->assertText('Your .com email address.', 'form found');
// Make sure that submitting the form didn't redirect us to the first page
......
......@@ -102,7 +102,7 @@ public function testBlockDemoUiPage() {
// Ensure that a hidden theme cannot use the block demo page.
\Drupal::service('theme_installer')->install(['stable']);
$this->drupalGet('admin/structure/block/demo/stable');
$this->assertResponse(404);
$this->assertSession()->statusCodeEquals(404);
}
/**
......@@ -163,7 +163,7 @@ public function testBlockAdminUiPage() {
// Ensure that a hidden theme cannot use the block demo page.
$this->drupalGet('admin/structure/block/list/stable');
$this->assertResponse(404);
$this->assertSession()->statusCodeEquals(404);
// Ensure that a hidden theme set as the admin theme can use the block demo
// page.
......@@ -173,7 +173,7 @@ public function testBlockAdminUiPage() {
$this->drupalGet('admin/structure/block');
$this->assertLink($theme_handler->getName('stable'));
$this->drupalGet('admin/structure/block/list/stable');
$this->assertResponse(200);
$this->assertSession()->statusCodeEquals(200);
}
/**
......@@ -382,9 +382,9 @@ public function testRouteProtection() {
$block = reset($this->blocks);
// Ensure that the enable and disable routes are protected.
$this->drupalGet('admin/structure/block/manage/' . $block->id() . '/disable');
$this->assertResponse(403);
$this->assertSession()->statusCodeEquals(403);
$this->drupalGet('admin/structure/block/manage/' . $block->id() . '/enable');
$this->assertResponse(403);
$this->assertSession()->statusCodeEquals(403);
}
}
......@@ -386,7 +386,7 @@ public function testBlockContextualLinks() {
$post = ['ids[0]' => $id, 'ids[1]' => $cached_id, 'tokens[0]' => $id_token, 'tokens[1]' => $cached_id_token];
$url = 'contextual/render?_format=json,destination=test-page';
$this->getSession()->getDriver()->getClient()->request('POST', $url, $post);
$this->assertResponse(200);
$this->assertSession()->statusCodeEquals(200);
$json = Json::decode($this->getSession()->getPage()->getContent());
$this->assertIdentical($json[$id], '<ul class="contextual-links"><li class="block-configure"><a href="' . base_path() . 'admin/structure/block/manage/' . $block->id() . '">Configure block</a></li><li class="entityviewedit-form"><a href="' . base_path() . 'admin/structure/views/view/test_view_block/edit/block_1">Edit view</a></li></ul>');
$this->assertIdentical($json[$cached_id], '<ul class="contextual-links"><li class="block-configure"><a href="' . base_path() . 'admin/structure/block/manage/' . $cached_block->id() . '">Configure block</a></li><li class="entityviewedit-form"><a href="' . base_path() . 'admin/structure/views/view/test_view_block/edit/block_1">Edit view</a></li></ul>');
......
......@@ -82,7 +82,7 @@ public function testBlockContentCreation() {
$this->assertRaw(new FormattableMarkup('A custom block with block description %value already exists.', [
'%value' => $edit['info[0][value]'],
]));
$this->assertResponse(200);
$this->assertSession()->statusCodeEquals(200);
}
/**
......@@ -164,7 +164,7 @@ public function testBlockContentCreationMultipleViewModes() {
$this->assertRaw(new FormattableMarkup('A custom block with block description %value already exists.', [
'%value' => $edit['info[0][value]'],
]));
$this->assertResponse(200);
$this->assertSession()->statusCodeEquals(200);
}
/**
......
......@@ -57,7 +57,7 @@ public function testListing() {
$link_text = t('Add custom block');
$this->assertLink($link_text);
$this->clickLink($link_text);
$this->assertResponse(200);
$this->assertSession()->statusCodeEquals(200);
$edit = [];
$edit['info[0][value]'] = $label;
$edit['body[0][value]'] = $this->randomMachineName(16);
......@@ -84,7 +84,7 @@ public function testListing() {
if (!empty($block)) {
$this->assertLinkByHref('block/' . $block->id());
$this->clickLink(t('Edit'));
$this->assertResponse(200);
$this->assertSession()->statusCodeEquals(200);
$this->assertTitle(strip_tags(t('Edit custom block %label', ['%label' => $label]) . ' | Drupal'));
$edit = ['info[0][value]' => $new_label];
$this->drupalPostForm(NULL, $edit, t('Save'));
......@@ -101,7 +101,7 @@ public function testListing() {
$this->assertLinkByHref('block/' . $block->id() . '/delete');
$delete_text = t('Delete');
$this->clickLink($delete_text);
$this->assertResponse(200);
$this->assertSession()->statusCodeEquals(200);
$this->assertTitle(strip_tags(t('Are you sure you want to delete the custom block %label?', ['%label' => $new_label]) . ' | Drupal'));
$this->drupalPostForm(NULL, [], $delete_text);
......
......@@ -69,7 +69,7 @@ public function testListing() {
$link_text = t('Add custom block');
$this->assertLink($link_text);
$this->clickLink($link_text);
$this->assertResponse(200);
$this->assertSession()->statusCodeEquals(200);
$edit = [];
$edit['info[0][value]'] = $label;
$edit['body[0][value]'] = $this->randomMachineName(16);
......@@ -96,7 +96,7 @@ public function testListing() {
if (!empty($block)) {
$this->assertLinkByHref('block/' . $block->id());
$this->clickLink(t('Edit'));
$this->assertResponse(200);
$this->assertSession()->statusCodeEquals(200);
$this->assertTitle(strip_tags(t('Edit custom block %label', ['%label' => $label]) . ' | Drupal'));
$edit = ['info[0][value]' => $new_label];
$this->drupalPostForm(NULL, $edit, t('Save'));
......@@ -113,7 +113,7 @@ public function testListing() {
$this->assertLinkByHref('block/' . $block->id() . '/delete');
$delete_text = t('Delete');
$this->clickLink($delete_text);
$this->assertResponse(200);
$this->assertSession()->statusCodeEquals(200);
$this->assertTitle(strip_tags(t('Are you sure you want to delete the custom block %label?', ['%label' => $new_label]) . ' | Drupal'));
$this->drupalPostForm(NULL, [], $delete_text);
......
......@@ -32,7 +32,7 @@ public function testPageEdit() {
$this->drupalGet('block-content/' . $block->id());
// Ensure user was able to view the block.
$this->assertResponse(200);
$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.'));
}
......
......@@ -60,7 +60,7 @@ public function testBlockContentTypeCreation() {
// Test the page with no block-types.
$this->drupalGet('block/add');
$this->assertResponse(200);
$this->assertSession()->statusCodeEquals(200);
$this->assertText('You have not created any block types yet');
$this->clickLink('block type creation page');
......@@ -93,7 +93,7 @@ public function testBlockContentTypeCreation() {
$this->assertInstanceOf(BlockContentType::class, $block_type);
$this->drupalGet('block/add/' . $block_type->id());
$this->assertResponse(200);
$this->assertSession()->statusCodeEquals(200);
}
/**
......