16
16
17
17
namespace Magento \GraphQl \PageCache ;
18
18
19
- use Magento \TestFramework \TestCase \GraphQlAbstract ;
20
- use Magento \TestFramework \Fixture \Config ;
21
19
use Magento \Framework \App \PageCache \Version ;
20
+ use Magento \TestFramework \Fixture \Config ;
21
+ use Magento \TestFramework \TestCase \GraphQlAbstract ;
22
22
23
23
/**
24
24
* Test absence/presence of private_content_version cookie in GraphQl POST HTTP responses
25
25
*/
26
26
class DisableSessionTest extends GraphQlAbstract
27
27
{
28
+ private const PHPSESSID_COOKIE_NAME = 'PHPSESSID ' ;
29
+
28
30
#[
29
31
Config('graphql/session/disable ' , '1 ' )
30
32
]
@@ -33,10 +35,14 @@ public function testPrivateSessionContentCookieNotPresentWhenSessionDisabled()
33
35
$ result = $ this ->graphQlMutationWithResponseHeaders ($ this ->getMutation ());
34
36
$ this ->assertArrayHasKey ('headers ' , $ result );
35
37
if (!empty ($ result ['headers ' ]['Set-Cookie ' ])) {
36
- $ this ->assertStringNotContainsString (
37
- Version::COOKIE_NAME ,
38
- $ result ['headers ' ]['Set-Cookie ' ],
39
- Version::COOKIE_NAME . ' should not be present in Set-Cookie header '
38
+ $ this ->assertFalse (
39
+ $ this ->isCookieSet ($ result ['headers ' ]['Set-Cookie ' ], self ::PHPSESSID_COOKIE_NAME ),
40
+ self ::PHPSESSID_COOKIE_NAME . ' should not be present in HTTP response '
41
+ );
42
+
43
+ $ this ->assertFalse (
44
+ $ this ->isCookieSet ($ result ['headers ' ]['Set-Cookie ' ], Version::COOKIE_NAME ),
45
+ Version::COOKIE_NAME . ' should not be present in HTTP response '
40
46
);
41
47
}
42
48
}
@@ -49,11 +55,30 @@ public function testPrivateSessionContentCookiePresentWhenSessionEnabled()
49
55
$ result = $ this ->graphQlMutationWithResponseHeaders ($ this ->getMutation ());
50
56
$ this ->assertArrayHasKey ('headers ' , $ result );
51
57
$ this ->assertArrayHasKey ('Set-Cookie ' , $ result ['headers ' ], 'Set-Cookie HTTP response header should be present ' );
52
- $ this -> assertStringContainsString (
53
- Version:: COOKIE_NAME ,
54
- $ result ['headers ' ]['Set-Cookie ' ],
55
- Version:: COOKIE_NAME . ' should be set by the server '
58
+
59
+ $ this -> assertTrue (
60
+ $ this -> isCookieSet ( $ result ['headers ' ]['Set-Cookie ' ], self :: PHPSESSID_COOKIE_NAME ) ,
61
+ self :: PHPSESSID_COOKIE_NAME . ' should be present in HTTP response '
56
62
);
63
+
64
+ $ this ->assertTrue (
65
+ $ this ->isCookieSet ($ result ['headers ' ]['Set-Cookie ' ], Version::COOKIE_NAME ),
66
+ Version::COOKIE_NAME . ' should be present in HTTP response '
67
+ );
68
+ }
69
+
70
+ /**
71
+ * Checks if $cookieName was set by server in any of Set-Cookie header(s)
72
+ *
73
+ * @param array $setCookieHeader
74
+ * @param string $cookieName
75
+ * @return bool
76
+ */
77
+ private function isCookieSet (array $ setCookieHeader , string $ cookieName ): bool
78
+ {
79
+ return count (array_filter ($ setCookieHeader , function ($ cookie ) use ($ cookieName ) {
80
+ return str_starts_with ($ cookie , $ cookieName );
81
+ })) > 0 ;
57
82
}
58
83
59
84
/**
0 commit comments