Browse Source

Add assertion for testing exactly the specified redirect, not 'full'

gregs 6 years ago
parent
commit
991d442d60
1 changed files with 20 additions and 1 deletions
  1. 20 1
      src/TestSuite/IntegrationTestTrait.php

+ 20 - 1
src/TestSuite/IntegrationTestTrait.php

@@ -858,7 +858,7 @@ trait IntegrationTestTrait
     }
 
     /**
-     * Asserts that the Location header is correct.
+     * Asserts that the Location header is correct. Comparison is made against a full URL.
      *
      * @param string|array|null $url The URL you expected the client to go to. This
      *   can either be a string URL or an array compatible with Router::url(). Use null to
@@ -877,6 +877,25 @@ trait IntegrationTestTrait
     }
 
     /**
+     * Asserts that the Location header is correct. Comparison is made against exactly the URL provided.
+     *
+     * @param string|array|null $url The URL you expected the client to go to. This
+     *   can either be a string URL or an array compatible with Router::url(). Use null to
+     *   simply check for the existence of this header.
+     * @param string $message The failure message that will be appended to the generated message.
+     * @return void
+     */
+    public function assertRedirectEquals($url = null, $message = '')
+    {
+        $verboseMessage = $this->extractVerboseMessage($message);
+        $this->assertThat(null, new HeaderSet($this->_response, 'Location'), $verboseMessage);
+
+        if ($url) {
+            $this->assertThat(Router::url($url), new HeaderEquals($this->_response, 'Location'), $verboseMessage);
+        }
+    }
+
+    /**
      * Asserts that the Location header contains a substring
      *
      * @param string $url The URL you expected the client to go to.