@@ -127,7 +127,16 @@ public function testAddProductToOrderFromShoppingCart(bool $asJson, bool $asJsVa
127127 $ this ->assertNotNull ($ newQuoteItemsCollection ->getItemByColumnValue ('sku ' , 'simple2 ' ));
128128 if ($ asJsVarname ) {
129129 $ this ->assertRedirect ($ this ->stringContains ('sales/order_create/showUpdateResult ' ));
130- $ body = (string ) $ this ->_objectManager ->get (\Magento \Backend \Model \Session::class)->getUpdateResult ();
130+ $ sessionData = $ this ->_objectManager ->get (\Magento \Backend \Model \Session::class)->getUpdateResult ();
131+ // Handle compressed data for JSON responses
132+ if (is_array ($ sessionData ) && isset ($ sessionData ['compressed ' ]) && $ sessionData ['compressed ' ]) {
133+ $ body = gzdecode ($ sessionData ['data ' ]);
134+ } else {
135+ $ body = (string ) $ sessionData ;
136+ }
137+ if ($ asJson ) {
138+ $ body = json_decode ($ body , true , 512 , JSON_THROW_ON_ERROR )['sidebar ' ];
139+ }
131140 } elseif ($ asJson ) {
132141 $ body = json_decode ($ this ->getResponse ()->getBody (), true , 512 , JSON_THROW_ON_ERROR )['sidebar ' ];
133142 } else {
@@ -154,7 +163,7 @@ public static function responseFlagsProvider(): array
154163 }
155164
156165 /**
157- * Test that JSON response with as_js_varname does not store result in session
166+ * Test that JSON response with as_js_varname stores compressed data to prevent session bloat
158167 *
159168 * @return void
160169 */
@@ -164,7 +173,7 @@ public static function responseFlagsProvider(): array
164173 DataFixture(CustomerCart::class, ['customer_id ' => '$customer.id$ ' , 'is_active ' => 1 ], as: 'quote ' ),
165174 DataFixture(AddProductToCart::class, ['cart_id ' => '$quote.id$ ' , 'product_id ' => '$product.id$ ' , 'qty ' => 1 ])
166175 ]
167- public function testJsonResponseWithJsVarnameDoesNotStoreInSession (): void
176+ public function testJsonResponseWithJsVarnameUsesCompressionToPreventSessionBloat (): void
168177 {
169178 /** @var CartInterface $quote */
170179 $ quote = $ this ->fixtures ->get ('quote ' );
@@ -198,23 +207,37 @@ public function testJsonResponseWithJsVarnameDoesNotStoreInSession(): void
198207 $ newQuoteItemsCollection = $ newQuote ->getItemsCollection (false );
199208 $ this ->assertNotNull ($ newQuoteItemsCollection ->getItemByColumnValue ('sku ' , $ product ->getSku ()));
200209
201- // Session should NOT contain updateResult (prevents session bloat)
202- $ backendSession = $ this ->_objectManager ->get (\Magento \Backend \Model \Session::class);
203- $ this ->assertFalse (
204- $ backendSession ->hasUpdateResult (),
205- 'Session should not store updateResult for JSON responses to prevent session bloat '
206- );
207-
208- // Verify response is returned directly (not a redirect)
210+ // Verify redirect happens (maintains 2-request pattern for PAT compatibility)
209211 $ response = $ this ->getResponse ();
210- $ this ->assertFalse (
212+ $ this ->assertTrue (
211213 $ response ->isRedirect (),
212- 'Response should not be a redirect when json=true with as_js_varname '
214+ 'Response should redirect to ShowUpdateResult '
213215 );
216+ $ this ->assertRedirect ($ this ->stringContains ('sales/order_create/showUpdateResult ' ));
214217
215- // Verify response body is valid JSON with expected content
216- $ responseBody = $ response ->getBody ();
217- $ this ->assertNotEmpty ($ responseBody , 'Response body should not be empty ' );
218+ // Verify session stores compressed data to prevent bloat
219+ $ backendSession = $ this ->_objectManager ->get (\Magento \Backend \Model \Session::class);
220+ $ this ->assertTrue (
221+ $ backendSession ->hasUpdateResult (),
222+ 'Session should contain compressed updateResult '
223+ );
224+
225+ $ sessionData = $ backendSession ->getUpdateResult ();
226+ $ this ->assertIsArray ($ sessionData , 'Session data should be array for compressed format ' );
227+ $ this ->assertTrue ($ sessionData ['compressed ' ], 'Data should be marked as compressed ' );
228+ $ this ->assertArrayHasKey ('data ' , $ sessionData , 'Compressed data should exist ' );
229+
230+ // Verify compression actually reduces size
231+ $ decompressed = gzdecode ($ sessionData ['data ' ]);
232+ $ this ->assertNotEmpty ($ decompressed , 'Decompressed data should not be empty ' );
233+
234+ $ originalSize = strlen ($ decompressed );
235+ $ compressedSize = strlen ($ sessionData ['data ' ]);
236+ $ this ->assertLessThan (
237+ $ originalSize ,
238+ $ compressedSize ,
239+ 'Compressed size should be smaller than original '
240+ );
218241 }
219242
220243 /**
0 commit comments