77
88namespace Magento \GraphQl \GraphQlCache \CacheIdFactorProviders \Customer ;
99
10+ use Magento \Catalog \Test \Fixture \Product as ProductFixture ;
1011use Magento \Customer \Api \CustomerRepositoryInterface ;
1112use Magento \Customer \Model \Group ;
13+ use Magento \Customer \Test \Fixture \Customer ;
1214use Magento \Framework \Exception \AuthenticationException ;
1315use Magento \GraphQlCache \Model \CacheId \CacheIdCalculator ;
1416use Magento \Integration \Api \CustomerTokenServiceInterface ;
17+ use Magento \TestFramework \Fixture \DataFixture ;
18+ use Magento \TestFramework \Fixture \DataFixtureStorageManager ;
1519use Magento \TestFramework \Helper \Bootstrap ;
1620use Magento \TestFramework \TestCase \GraphQlAbstract ;
1721
@@ -45,13 +49,16 @@ protected function setUp(): void
4549
4650 /**
4751 * 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
5152 */
53+ #[
54+ DataFixture(Customer::class, as: 'customer ' ),
55+ DataFixture(ProductFixture::class, as: 'product ' ),
56+ ]
5257 public function testCacheIdHeaderWithCustomerGroup ()
5358 {
54- $ sku = 'simple_product ' ;
59+ $ customer = DataFixtureStorageManager::getStorage ()->get ('customer ' );
60+ $ product = DataFixtureStorageManager::getStorage ()->get ('product ' );
61+ $ sku = $ product ->getSku ();
5562 $ query = <<<QUERY
5663 {
5764 products(filter: {sku: {eq: " {$ sku }"}})
@@ -67,12 +74,12 @@ public function testCacheIdHeaderWithCustomerGroup()
6774 }
6875 }
6976QUERY ;
70- $ response = $ this ->graphQlQueryWithResponseHeaders ($ query , [], '' , $ this ->getHeaderMap ());
77+ $ response = $ this ->graphQlQueryWithResponseHeaders ($ query , [], '' , $ this ->getHeaderMap ($ customer -> getEmail () ));
7178 $ this ->assertArrayHasKey (CacheIdCalculator::CACHE_ID_HEADER , $ response ['headers ' ]);
7279 $ cacheId = $ response ['headers ' ][CacheIdCalculator::CACHE_ID_HEADER ];
7380 $ this ->assertTrue ((boolean )preg_match ('/^[0-9a-f]{64}$/i ' , $ cacheId ));
7481 $ groupCode = 'Retailer ' ;
75- $ customer = $ this ->customerRepository ->get (' customer@example.com ' );
82+ $ customer = $ this ->customerRepository ->get ($ customer-> getEmail () );
7683 $ customerGroupId = $ this ->customerGroup ->load ($ groupCode , 'customer_group_code ' )->getId ();
7784 // change the customer group of this customer from the default group
7885 $ customer ->setGroupId ($ customerGroupId );
@@ -81,7 +88,7 @@ public function testCacheIdHeaderWithCustomerGroup()
8188 $ query ,
8289 [],
8390 '' ,
84- $ this ->getHeaderMap ()
91+ $ this ->getHeaderMap ($ customer -> getEmail () )
8592 );
8693 $ this ->assertArrayHasKey (CacheIdCalculator::CACHE_ID_HEADER , $ responseAfterCustomerGroupChange ['headers ' ]);
8794 $ cacheIdCustomerGroupChange = $ responseAfterCustomerGroupChange ['headers ' ][CacheIdCalculator::CACHE_ID_HEADER ];
@@ -96,7 +103,7 @@ public function testCacheIdHeaderWithCustomerGroup()
96103 $ query ,
97104 [],
98105 '' ,
99- $ this ->getHeaderMap ()
106+ $ this ->getHeaderMap ($ customer -> getEmail () )
100107 );
101108 $ cacheIdDefaultCustomerGroup = $ responseDefaultCustomerGroup ['headers ' ][CacheIdCalculator::CACHE_ID_HEADER ];
102109 //Verify that the cache id is same as original $cacheId
0 commit comments