88namespace Magento \PageCache \Test \Unit \Model \App \Request \Http ;
99
1010use Magento \Framework \App \Http \Context ;
11+ use Magento \Framework \App \ObjectManager ;
12+ use Magento \Framework \App \PageCache \Identifier ;
1113use Magento \Framework \App \Request \Http as HttpRequest ;
14+ use Magento \Framework \ObjectManagerInterface ;
1215use Magento \Framework \Serialize \Serializer \Json ;
1316use Magento \PageCache \Model \App \Request \Http \IdentifierForSave ;
1417use Magento \PageCache \Model \App \Request \Http \IdentifierStoreReader ;
@@ -46,6 +49,11 @@ class IdentifierForSaveTest extends TestCase
4649 */
4750 private $ identifierStoreReader ;
4851
52+ /**
53+ * @var Identifier
54+ */
55+ private $ identifierMock ;
56+
4957 /**
5058 * @inheritdoc
5159 */
@@ -74,6 +82,16 @@ function ($value) {
7482 ->disableOriginalConstructor ()
7583 ->getMock ();
7684
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+
7795 $ this ->model = new IdentifierForSave (
7896 $ this ->requestMock ,
7997 $ this ->contextMock ,
@@ -90,6 +108,10 @@ function ($value) {
90108 */
91109 public function testGetValue (): void
92110 {
111+ $ this ->identifierMock ->expects ($ this ->once ())
112+ ->method ('getMarketingParameterPatterns ' )
113+ ->willReturn ($ this ->getpattern ());
114+
93115 $ this ->requestMock ->expects ($ this ->any ())
94116 ->method ('isSecure ' )
95117 ->willReturn (true );
@@ -129,6 +151,10 @@ function ($value) {
129151 */
130152 public function testGetValueWithMarketingParameters (): void
131153 {
154+ $ this ->identifierMock ->expects ($ this ->any ())
155+ ->method ('getMarketingParameterPatterns ' )
156+ ->willReturn ($ this ->getPattern ());
157+
132158 $ this ->requestMock ->expects ($ this ->any ())
133159 ->method ('isSecure ' )
134160 ->willReturn (true );
@@ -160,4 +186,33 @@ function ($value) {
160186 $ this ->model ->getValue ()
161187 );
162188 }
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+ }
163218}
0 commit comments