Browse Source

Fix tests

ADmad 5 years ago
parent
commit
229c234343

+ 2 - 0
src/Http/ResponseEmitter.php

@@ -248,6 +248,8 @@ class ResponseEmitter implements EmitterInterface
             if (is_string($data['expires'])) {
                 $data['expires'] = strtotime($data['expires']);
             }
+            unset($data['']);
+
             $this->setcookie($name, $value, $data);
         }
     }

+ 13 - 3
tests/TestCase/Controller/Component/CookieComponentTest.php

@@ -322,7 +322,9 @@ class CookieComponentTest extends TestCase
             'path' => '/',
             'domain' => '',
             'secure' => false,
-            'httpOnly' => false];
+            'httpOnly' => false,
+            'samesite' => null,
+        ];
         $result = $this->Controller->response->getCookie('Testing');
 
         $this->assertEquals($future->format('U'), $result['expire'], '', 3);
@@ -350,7 +352,9 @@ class CookieComponentTest extends TestCase
             'path' => '/',
             'domain' => '',
             'secure' => false,
-            'httpOnly' => true];
+            'httpOnly' => true,
+            'samesite' => null,
+        ];
         $result = $this->Controller->response->getCookie('Testing');
         $this->assertEquals($expected, $result);
     }
@@ -375,6 +379,7 @@ class CookieComponentTest extends TestCase
             'domain' => '',
             'secure' => false,
             'httpOnly' => false,
+            'samesite' => null,
         ];
         $result = $this->Controller->response->getCookie('Open');
         unset($result['expire']);
@@ -442,7 +447,9 @@ class CookieComponentTest extends TestCase
             'path' => '/',
             'domain' => '',
             'secure' => false,
-            'httpOnly' => true];
+            'httpOnly' => true,
+            'samesite' => null,
+        ];
         $result = $this->Controller->response->getCookie('Testing');
         $this->assertEquals($expected, $result);
     }
@@ -462,6 +469,7 @@ class CookieComponentTest extends TestCase
             'domain' => '',
             'secure' => false,
             'httpOnly' => false,
+            'samesite' => null,
         ];
         $result = $this->Controller->response->getCookie('Testing');
 
@@ -487,6 +495,7 @@ class CookieComponentTest extends TestCase
             'domain' => '',
             'secure' => false,
             'httpOnly' => false,
+            'samesite' => null,
         ];
         $result = $this->Controller->response->getCookie('User');
         unset($result['expire']);
@@ -502,6 +511,7 @@ class CookieComponentTest extends TestCase
             'domain' => '',
             'secure' => false,
             'httpOnly' => false,
+            'samesite' => null,
         ];
         $result = $this->Controller->response->getCookie('User');
         unset($result['expire']);

+ 9 - 2
tests/TestCase/Http/ResponseEmitterTest.php

@@ -161,6 +161,9 @@ class ResponseEmitterTest extends TestCase
         if (PHP_VERSION_ID < 70300) {
             $expected[1]['path'] = '/; SameSite=Lax';
             unset($expected[1]['samesite']);
+        } else {
+            $expected[0]['samesite'] = null;
+            $expected[2]['samesite'] = null;
         }
 
         $this->assertEquals($expected, $GLOBALS['mockedCookies']);
@@ -247,13 +250,17 @@ class ResponseEmitterTest extends TestCase
                 'domain' => '',
                 'secure' => false,
                 'httponly' => false,
-                'samesite' => 'None',
             ],
         ];
 
         if (PHP_VERSION_ID < 70300) {
             $expected[5]['path'] = '/; SameSite=None';
-            unset($expected[5]['samesite']);
+        } else {
+            foreach ($expected as &$val) {
+                $val['samesite'] = null;
+            }
+
+            $expected[5]['samesite'] = 'None';
         }
 
         $this->assertEquals($expected, $GLOBALS['mockedCookies']);