Browse Source

Use new method in responses when getting cookie values.

Refs #11208
Mark Story 8 years ago
parent
commit
6cf84bcb47
2 changed files with 28 additions and 1 deletions
  1. 1 1
      src/Http/Response.php
  2. 27 0
      tests/TestCase/Http/ResponseTest.php

+ 1 - 1
src/Http/Response.php

@@ -2146,7 +2146,7 @@ class Response implements ResponseInterface
     {
         return [
             'name' => $cookie->getName(),
-            'value' => $cookie->getValue(),
+            'value' => $cookie->getStringValue(),
             'path' => $cookie->getPath(),
             'domain' => $cookie->getDomain(),
             'secure' => $cookie->isSecure(),

+ 27 - 0
tests/TestCase/Http/ResponseTest.php

@@ -1578,6 +1578,33 @@ class ResponseTest extends TestCase
     }
 
     /**
+     * Test getCookies() and array data.
+     *
+     * @return void
+     */
+    public function testGetCookiesArrayValue()
+    {
+        $response = new Response();
+        $cookie = (new Cookie('urmc'))
+            ->withValue(['user_id' => 1, 'token' => 'abc123'])
+            ->withHttpOnly(true);
+
+        $new = $response->withCookie($cookie);
+        $expected = [
+            'urmc' => [
+                'name' => 'urmc',
+                'value' => '{"user_id":1,"token":"abc123"}',
+                'expire' => null,
+                'path' => '',
+                'domain' => '',
+                'secure' => false,
+                'httpOnly' => true
+            ],
+        ];
+        $this->assertEquals($expected, $new->getCookies());
+    }
+
+    /**
      * Test getCookieCollection() as array data
      *
      * @return void