7
7
8
8
namespace Magento \Framework \App \Test \Unit \Http ;
9
9
10
+ use Magento \Framework \App \DeploymentConfig ;
10
11
use Magento \Framework \App \Http \Context ;
12
+ use Magento \Framework \Config \ConfigOptionsListConstants ;
13
+ use Magento \Framework \ObjectManagerInterface ;
11
14
use Magento \Framework \Serialize \Serializer \Json ;
12
15
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
13
16
use PHPUnit \Framework \MockObject \MockObject ;
@@ -25,13 +28,29 @@ class ContextTest extends TestCase
25
28
*/
26
29
protected $ object ;
27
30
31
+ /**
32
+ * @var DeploymentConfig|MockObject
33
+ */
34
+ private $ deploymentConfig ;
35
+
36
+ /**
37
+ * @var ObjectManagerInterface|MockObject
38
+ */
39
+ private $ objectManagerMock ;
40
+
28
41
/**
29
42
* @var Json|MockObject
30
43
*/
31
44
private $ serializerMock ;
32
45
33
46
protected function setUp (): void
34
47
{
48
+ $ this ->objectManagerMock = $ this ->getMockBuilder (ObjectManagerInterface::class)
49
+ ->disableOriginalConstructor ()
50
+ ->onlyMethods (['create ' ])
51
+ ->getMockForAbstractClass ();
52
+ \Magento \Framework \App \ObjectManager::setInstance ($ this ->objectManagerMock );
53
+
35
54
$ this ->objectManager = new ObjectManager ($ this );
36
55
$ this ->serializerMock = $ this ->getMockBuilder (Json::class)
37
56
->setMethods (['serialize ' ])
@@ -50,6 +69,10 @@ function ($value) {
50
69
'serializer ' => $ this ->serializerMock
51
70
]
52
71
);
72
+ $ this ->deploymentConfig = $ this ->createPartialMock (
73
+ DeploymentConfig::class,
74
+ ['get ' ]
75
+ );
53
76
}
54
77
55
78
public function testGetValue ()
@@ -81,14 +104,28 @@ public function testGetData()
81
104
82
105
public function testGetVaryString ()
83
106
{
107
+ $ this ->objectManagerMock ->expects ($ this ->any ())
108
+ ->method ('get ' )
109
+ ->with (DeploymentConfig::class)
110
+ ->willReturn ($ this ->deploymentConfig );
111
+
112
+ $ this ->deploymentConfig ->expects ($ this ->any ())
113
+ ->method ('get ' )
114
+ ->with (ConfigOptionsListConstants::CONFIG_PATH_CRYPT_KEY )
115
+ ->willReturn ('448198e08af35844a42d3c93c1ef4e03 ' );
116
+
84
117
$ this ->object ->setValue ('key2 ' , 'value2 ' , 'default2 ' );
85
118
$ this ->object ->setValue ('key1 ' , 'value1 ' , 'default1 ' );
86
119
$ data = [
87
120
'key2 ' => 'value2 ' ,
88
121
'key1 ' => 'value1 '
89
122
];
90
123
ksort ($ data );
91
- $ this ->assertEquals (sha1 (json_encode ($ data )), $ this ->object ->getVaryString ());
124
+
125
+ $ salt = $ this ->deploymentConfig ->get (ConfigOptionsListConstants::CONFIG_PATH_CRYPT_KEY );
126
+ $ cacheKey = hash ('sha256 ' , $ this ->serializerMock ->serialize ($ data ) . '| ' . $ salt );
127
+
128
+ $ this ->assertEquals ($ cacheKey , $ this ->object ->getVaryString ());
92
129
}
93
130
94
131
public function testToArray ()
0 commit comments