7
7
8
8
namespace Magento \GraphQl \GraphQlCache \CacheIdFactorProviders \Customer ;
9
9
10
+ use Magento \Catalog \Test \Fixture \Product as ProductFixture ;
10
11
use Magento \Customer \Api \CustomerRepositoryInterface ;
11
12
use Magento \Customer \Model \Group ;
13
+ use Magento \Customer \Test \Fixture \Customer ;
12
14
use Magento \Framework \Exception \AuthenticationException ;
13
15
use Magento \GraphQlCache \Model \CacheId \CacheIdCalculator ;
14
16
use Magento \Integration \Api \CustomerTokenServiceInterface ;
17
+ use Magento \TestFramework \Fixture \DataFixture ;
18
+ use Magento \TestFramework \Fixture \DataFixtureStorageManager ;
15
19
use Magento \TestFramework \Helper \Bootstrap ;
16
20
use Magento \TestFramework \TestCase \GraphQlAbstract ;
17
21
@@ -45,13 +49,16 @@ protected function setUp(): void
45
49
46
50
/**
47
51
* Tests that cache id header changes based on customer group and remains consistent for same customer group
48
- *
49
- * @magentoApiDataFixture Magento/Customer/_files/customer.php
50
- * @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
51
52
*/
53
+ #[
54
+ DataFixture(Customer::class, as: 'customer ' ),
55
+ DataFixture(ProductFixture::class, as: 'product ' ),
56
+ ]
52
57
public function testCacheIdHeaderWithCustomerGroup ()
53
58
{
54
- $ sku = 'simple_product ' ;
59
+ $ customer = DataFixtureStorageManager::getStorage ()->get ('customer ' );
60
+ $ product = DataFixtureStorageManager::getStorage ()->get ('product ' );
61
+ $ sku = $ product ->getSku ();
55
62
$ query = <<<QUERY
56
63
{
57
64
products(filter: {sku: {eq: " {$ sku }"}})
@@ -67,12 +74,12 @@ public function testCacheIdHeaderWithCustomerGroup()
67
74
}
68
75
}
69
76
QUERY ;
70
- $ response = $ this ->graphQlQueryWithResponseHeaders ($ query , [], '' , $ this ->getHeaderMap ());
77
+ $ response = $ this ->graphQlQueryWithResponseHeaders ($ query , [], '' , $ this ->getHeaderMap ($ customer -> getEmail () ));
71
78
$ this ->assertArrayHasKey (CacheIdCalculator::CACHE_ID_HEADER , $ response ['headers ' ]);
72
79
$ cacheId = $ response ['headers ' ][CacheIdCalculator::CACHE_ID_HEADER ];
73
80
$ this ->assertTrue ((boolean )preg_match ('/^[0-9a-f]{64}$/i ' , $ cacheId ));
74
81
$ groupCode = 'Retailer ' ;
75
- $ customer = $ this ->customerRepository ->get (' customer@example.com ' );
82
+ $ customer = $ this ->customerRepository ->get ($ customer-> getEmail () );
76
83
$ customerGroupId = $ this ->customerGroup ->load ($ groupCode , 'customer_group_code ' )->getId ();
77
84
// change the customer group of this customer from the default group
78
85
$ customer ->setGroupId ($ customerGroupId );
@@ -81,7 +88,7 @@ public function testCacheIdHeaderWithCustomerGroup()
81
88
$ query ,
82
89
[],
83
90
'' ,
84
- $ this ->getHeaderMap ()
91
+ $ this ->getHeaderMap ($ customer -> getEmail () )
85
92
);
86
93
$ this ->assertArrayHasKey (CacheIdCalculator::CACHE_ID_HEADER , $ responseAfterCustomerGroupChange ['headers ' ]);
87
94
$ cacheIdCustomerGroupChange = $ responseAfterCustomerGroupChange ['headers ' ][CacheIdCalculator::CACHE_ID_HEADER ];
@@ -96,7 +103,7 @@ public function testCacheIdHeaderWithCustomerGroup()
96
103
$ query ,
97
104
[],
98
105
'' ,
99
- $ this ->getHeaderMap ()
106
+ $ this ->getHeaderMap ($ customer -> getEmail () )
100
107
);
101
108
$ cacheIdDefaultCustomerGroup = $ responseDefaultCustomerGroup ['headers ' ][CacheIdCalculator::CACHE_ID_HEADER ];
102
109
//Verify that the cache id is same as original $cacheId
0 commit comments