Henrik Gemal 7 years ago
parent
commit
3de38795b5

+ 19 - 0
src/TestSuite/IntegrationTestTrait.php

@@ -856,6 +856,25 @@ trait IntegrationTestTrait
     }
 
     /**
+     * Asserts that the Location header does not contain a substring
+     *
+     * @param string $url The URL you expected the client to go to.
+     * @param string $message The failure message that will be appended to the generated message.
+     * @return void
+     */
+    public function assertRedirectNotContains($url, $message = '')
+    {
+        if (!$this->_response) {
+            $this->fail('No response set, cannot assert location header. ' . $message);
+        }
+        $result = $this->_response->header();
+        if (empty($result['Location'])) {
+            $this->fail('No location header set. ' . $message);
+        }
+        $this->assertNotContains($url, $result['Location'], $message);
+    }
+
+    /**
      * Asserts that the Location header is not set.
      *
      * @param string $message The failure message that will be appended to the generated message.

+ 12 - 0
tests/TestCase/TestSuite/IntegrationTestTraitTest.php

@@ -942,6 +942,18 @@ class IntegrationTestTraitTest extends IntegrationTestCase
     }
 
     /**
+     * Test the location header assertion string not contains
+     *
+     * @return void
+     */
+    public function testAssertRedirectNotContains()
+    {
+        $this->_response = new Response();
+        $this->_response->header('Location', 'http://localhost/tasks/index');
+        $this->assertRedirectNotContains('test');
+    }
+
+    /**
      * Test the location header assertion.
      *
      * @return void