77
88namespace Swag \PayPal \Test \Storefront \Framework \Cookie ;
99
10+ use PHPUnit \Framework \Attributes \DataProvider ;
11+ use PHPUnit \Framework \MockObject \MockObject ;
1012use PHPUnit \Framework \TestCase ;
13+ use Shopware \Core \Framework \Context ;
14+ use Shopware \Core \Framework \DataAbstractionLayer \EntityRepository ;
15+ use Shopware \Core \Framework \DataAbstractionLayer \Search \Criteria ;
16+ use Shopware \Core \Framework \DataAbstractionLayer \Search \IdSearchResult ;
1117use Shopware \Core \Framework \Log \Package ;
18+ use Shopware \Core \Framework \Uuid \Uuid ;
1219use Shopware \Storefront \Framework \Cookie \CookieProviderInterface ;
1320use Swag \PayPal \Storefront \Framework \Cookie \PayPalCookieProvider ;
21+ use Symfony \Component \HttpFoundation \Request ;
22+ use Symfony \Component \HttpFoundation \RequestStack ;
1423
1524/**
1625 * @internal
1726 */
1827#[Package('checkout ' )]
1928class PayPalCookieProviderTest extends TestCase
2029{
30+ private EntityRepository &MockObject $ paymentMethodRepository ;
31+
32+ private RequestStack $ requestStack ;
33+
34+ protected function setUp (): void
35+ {
36+ $ request = new Request ();
37+ $ request ->attributes ->set ('sw-sales-channel-id ' , Uuid::randomHex ());
38+
39+ $ this ->paymentMethodRepository = $ this ->createMock (EntityRepository::class);
40+ $ this ->requestStack = new RequestStack ();
41+ $ this ->requestStack ->push ($ request );
42+ }
43+
2144 public function testGetCookieGroupsWithEmptyOriginalCookiesReturnsOriginalCookies (): void
2245 {
2346 $ cookieProviderMock = $ this ->getMockBuilder (CookieProviderInterface::class)->getMock ();
@@ -26,7 +49,7 @@ public function testGetCookieGroupsWithEmptyOriginalCookiesReturnsOriginalCookie
2649 ->method ('getCookieGroups ' )
2750 ->willReturn ($ cookies );
2851
29- $ result = (new PayPalCookieProvider ($ cookieProviderMock ))->getCookieGroups ();
52+ $ result = (new PayPalCookieProvider ($ cookieProviderMock, $ this -> paymentMethodRepository , $ this -> requestStack ))->getCookieGroups ();
3053 static ::assertSame ($ cookies , $ result );
3154 }
3255
@@ -41,7 +64,7 @@ public function testGetCookieGroupsWithOriginalCookiesNotInSubArraysReturnsOrigi
4164 ->method ('getCookieGroups ' )
4265 ->willReturn ($ cookies );
4366
44- $ result = (new PayPalCookieProvider ($ cookieProviderMock ))->getCookieGroups ();
67+ $ result = (new PayPalCookieProvider ($ cookieProviderMock, $ this -> paymentMethodRepository , $ this -> requestStack ))->getCookieGroups ();
4568 static ::assertSame ($ cookies , $ result );
4669 }
4770
@@ -55,7 +78,17 @@ public function testGetCookieGroupsWithRequiredCookieGroup(array $cookies, bool
5578 ->method ('getCookieGroups ' )
5679 ->willReturn ($ cookies );
5780
58- $ result = (new PayPalCookieProvider ($ cookieProviderMock ))->getCookieGroups ();
81+ $ searchResult = new IdSearchResult (0 , [Uuid::randomHex () => ['primaryKey ' => 'test-id ' , 'data ' => []]], new Criteria (), Context::createDefaultContext ());
82+
83+ $ this ->paymentMethodRepository ->expects ($ payPalCookieAdded ? static ::once () : static ::never ())
84+ ->method ('searchIds ' )
85+ ->willReturnCallback (static function (Criteria $ criteria ) use ($ searchResult ) {
86+ static ::assertCount (3 , $ criteria ->getFilters ());
87+
88+ return $ searchResult ;
89+ });
90+
91+ $ result = (new PayPalCookieProvider ($ cookieProviderMock , $ this ->paymentMethodRepository , $ this ->requestStack ))->getCookieGroups ();
5992 if (!$ payPalCookieAdded ) {
6093 static ::assertSame ($ cookies , $ result );
6194
@@ -74,7 +107,7 @@ public function testGetCookieGroupsWithRequiredCookieGroup(array $cookies, bool
74107 static ::assertSame ('paypal-cookie-key ' , $ payPalCookie ['cookie ' ]);
75108 }
76109
77- public function dataTestGetCookieGroupsWithRequiredCookieGroup (): array
110+ public static function dataTestGetCookieGroupsWithRequiredCookieGroup (): array
78111 {
79112 return [
80113 // Matching snippet name, missing is required flag
0 commit comments