8
8
namespace Magento \PageCache \Test \Unit \Model \App \Request \Http ;
9
9
10
10
use Magento \Framework \App \Http \Context ;
11
+ use Magento \Framework \App \ObjectManager ;
12
+ use Magento \Framework \App \PageCache \Identifier ;
11
13
use Magento \Framework \App \Request \Http as HttpRequest ;
14
+ use Magento \Framework \ObjectManagerInterface ;
12
15
use Magento \Framework \Serialize \Serializer \Json ;
13
16
use Magento \PageCache \Model \App \Request \Http \IdentifierForSave ;
14
17
use Magento \PageCache \Model \App \Request \Http \IdentifierStoreReader ;
@@ -46,6 +49,11 @@ class IdentifierForSaveTest extends TestCase
46
49
*/
47
50
private $ identifierStoreReader ;
48
51
52
+ /**
53
+ * @var Identifier
54
+ */
55
+ private $ identifierMock ;
56
+
49
57
/**
50
58
* @inheritdoc
51
59
*/
@@ -74,6 +82,16 @@ function ($value) {
74
82
->disableOriginalConstructor ()
75
83
->getMock ();
76
84
85
+ $ this ->identifierMock = $ this ->getMockBuilder (Identifier::class)
86
+ ->disableOriginalConstructor ()
87
+ ->getMock ();
88
+
89
+ $ objectManagerMock = $ this ->getMockForAbstractClass (ObjectManagerInterface::class);
90
+ $ objectManagerMock ->expects ($ this ->once ())
91
+ ->method ('get ' )
92
+ ->willReturn ($ this ->identifierMock );
93
+ ObjectManager::setInstance ($ objectManagerMock );
94
+
77
95
$ this ->model = new IdentifierForSave (
78
96
$ this ->requestMock ,
79
97
$ this ->contextMock ,
@@ -90,6 +108,10 @@ function ($value) {
90
108
*/
91
109
public function testGetValue (): void
92
110
{
111
+ $ this ->identifierMock ->expects ($ this ->once ())
112
+ ->method ('getMarketingParameterPatterns ' )
113
+ ->willReturn ($ this ->getpattern ());
114
+
93
115
$ this ->requestMock ->expects ($ this ->any ())
94
116
->method ('isSecure ' )
95
117
->willReturn (true );
@@ -129,6 +151,10 @@ function ($value) {
129
151
*/
130
152
public function testGetValueWithMarketingParameters (): void
131
153
{
154
+ $ this ->identifierMock ->expects ($ this ->any ())
155
+ ->method ('getMarketingParameterPatterns ' )
156
+ ->willReturn ($ this ->getPattern ());
157
+
132
158
$ this ->requestMock ->expects ($ this ->any ())
133
159
->method ('isSecure ' )
134
160
->willReturn (true );
@@ -160,4 +186,33 @@ function ($value) {
160
186
$ this ->model ->getValue ()
161
187
);
162
188
}
189
+
190
+ /**
191
+ * @return string[]
192
+ */
193
+ public function getPattern (): array
194
+ {
195
+ return [
196
+ '/&?gad_source\=[^&]+/ ' ,
197
+ '/&?gbraid\=[^&]+/ ' ,
198
+ '/&?wbraid\=[^&]+/ ' ,
199
+ '/&?_gl\=[^&]+/ ' ,
200
+ '/&?dclid\=[^&]+/ ' ,
201
+ '/&?gclsrc\=[^&]+/ ' ,
202
+ '/&?srsltid\=[^&]+/ ' ,
203
+ '/&?msclkid\=[^&]+/ ' ,
204
+ '/&?_kx\=[^&]+/ ' ,
205
+ '/&?gclid\=[^&]+/ ' ,
206
+ '/&?cx\=[^&]+/ ' ,
207
+ '/&?ie\=[^&]+/ ' ,
208
+ '/&?cof\=[^&]+/ ' ,
209
+ '/&?siteurl\=[^&]+/ ' ,
210
+ '/&?zanpid\=[^&]+/ ' ,
211
+ '/&?origin\=[^&]+/ ' ,
212
+ '/&?fbclid\=[^&]+/ ' ,
213
+ '/&?mc_(.*?)\=[^&]+/ ' ,
214
+ '/&?utm_(.*?)\=[^&]+/ ' ,
215
+ '/&?_bta_(.*?)\=[^&]+/ ' ,
216
+ ];
217
+ }
163
218
}
0 commit comments