Browse Source

Merge pull request #12794 from jeremyharris/assert-cookie-not-set

Fixed regression in assertCookieNotSet
Mark Story 7 years ago
parent
commit
53d09343f2

+ 2 - 2
src/TestSuite/Constraint/Response/CookieSet.php

@@ -29,9 +29,9 @@ class CookieSet extends ResponseBase
      */
     public function matches($other)
     {
-        $value = $this->response->getCookie($other);
+        $cookie = $this->response->getCookie($other);
 
-        return $value !== null;
+        return $cookie !== null && $cookie['value'] !== '';
     }
 
     /**

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

@@ -704,6 +704,18 @@ class IntegrationTestTraitTest extends IntegrationTestCase
     }
 
     /**
+     * Tests assertCookieNotSet assertion
+     *
+     * @return void
+     */
+    public function testAssertCookieNotSet()
+    {
+        $this->cookie('test', 'value');
+        $this->get('/cookie_component_test/remove_cookie/test');
+        $this->assertCookieNotSet('test');
+    }
+
+    /**
      * Tests the failure message for assertCookieNotSet
      *
      * @return void

+ 5 - 0
tests/test_app/TestApp/Controller/CookieComponentTestController.php

@@ -57,4 +57,9 @@ class CookieComponentTestController extends Controller
         }
         $this->Cookie->write('NameOfCookie', 'abc');
     }
+
+    public function remove_cookie($key)
+    {
+        $this->Cookie->delete($key);
+    }
 }