I have a Drupal 8 module for banning users based on country.

In it, I have the following test.

public function setUp() {

public function testCompleteBan() {
  // node/1.
  $this->addBanNode("Read only page");
  // node/2.
  $this->addBanNode("Complete ban page");
  $edit = [
    // Set the United States to Read Only
    // 0 = no action / 1 = Read Only / 2 = Complete Ban.
    'ip_ban_US' => 2,
    // Set the test IP address to a known Google US address.
    'ip_ban_test_ip' => '',
    // Configure the paths for read-only and complete ban.
    'ip_ban_readonly_path' => '/node/1',
    'ip_ban_completeban_path' => '/node/2',
  $this->drupalPostForm(IP_BAN_ADMIN_FORM_PATH, $edit, t('Save configuration'));
  $this->assertOptionSelected('edit-ip-ban-us', 2, 'Complete ban set correctly in country list table.');
  // Should be redirected to complete ban page after logout.

However, I get an error on the last line (assertURL()): "Expected 'http://d8.dev/node/2' matches current URL (http://d8.dev/). Value 'http://d8.dev/' is equal to value 'http://d8.dev/node/2'."

It seems as if the page is not redirected on logout the way it is when manually testing with an extremely minimal installation and using the exact same settings (including permissions)/workflow as the tests.

Note all the form-based tests are working as well.

Any idea why this is not working in D8? (It works fine in D7.)

  • It's possible WebTestBase doesn't handle the symfony redirect in the same way. maybe try assertResponse(302).
    – mradcliffe
    Oct 29, 2016 at 20:20
  • Okay I changed my event subscriber to middleware because of another problem I was having, and that seemed to solve the issue of the redirect not working, but now I'm getting a different error: "GET /node/2 returned 0 (0 bytes)" for the line $this->drupalGet('user/logout');, and "Expected 'd8.dev/node/2' matches current URL (/node/2). Value '/node/2' is equal to value 'd8.dev/node/2'" for the last line. Something's still amiss.
    – Webdrips
    Oct 31, 2016 at 11:11
  • I remember running into this because either my VM did not have a hosts entry for the DNS i was using and/or the http_request_fails option or whatever needed to be set to FALSE.
    – mradcliffe
    Oct 31, 2016 at 20:16
  • I have a valid VM (and have added the trusted_hosts_patterns just in case), and that didn't help. I grepped the code base for http_request_fails, and came up empty.
    – Webdrips
    Nov 1, 2016 at 10:17
  • Not trusted hosts pattern - /etc/hosts
    – mradcliffe
    Nov 1, 2016 at 11:59

1 Answer 1


The assertion failure looks as though the testing framework isn't following the double redirect (from /user/logout to <front> and thence to /node/2). Maybe explicitly request the front page after logging out?



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.