|
10 | 10 | use Magento\Backend\Model\Session\Quote;
|
11 | 11 | use Magento\Framework\App\Request\Http;
|
12 | 12 | use Magento\Framework\Exception\NoSuchEntityException;
|
| 13 | +use Magento\Framework\Message\MessageInterface; |
13 | 14 | use Magento\Framework\View\LayoutInterface;
|
14 | 15 | use Magento\Quote\Api\CartRepositoryInterface;
|
15 | 16 | use Magento\Quote\Api\Data\CartInterface;
|
16 | 17 | use Magento\Store\Model\StoreManagerInterface;
|
| 18 | +use Magento\TestFramework\Helper\Bootstrap; |
17 | 19 | use Magento\TestFramework\Quote\Model\GetQuoteByReservedOrderId;
|
18 | 20 | use Magento\TestFramework\TestCase\AbstractBackendController;
|
19 | 21 | use Magento\Wishlist\Model\Wishlist;
|
|
25 | 27 | *
|
26 | 28 | * @magentoAppArea adminhtml
|
27 | 29 | * @magentoDbIsolation enabled
|
| 30 | + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) |
28 | 31 | */
|
29 | 32 | class LoadBlockTest extends AbstractBackendController
|
30 | 33 | {
|
@@ -95,22 +98,31 @@ public function testAddProductToOrderFromShoppingCart(bool $asJson, bool $asJsVa
|
95 | 98 | 'json' => $asJson,
|
96 | 99 | 'as_js_varname' => $asJsVarname,
|
97 | 100 | ]);
|
| 101 | + $itemId = $oldQuote->getItemsCollection()->getFirstItem()->getId(); |
98 | 102 | $post = $this->hydratePost([
|
99 | 103 | 'sidebar' => [
|
100 | 104 | 'add_cart_item' => [
|
101 |
| - $oldQuote->getItemsCollection()->getFirstItem()->getId() => 1, |
| 105 | + $itemId => 1, |
102 | 106 | ],
|
103 | 107 | ],
|
104 | 108 | ]);
|
105 | 109 |
|
106 | 110 | $this->dispatchWitParams($params, $post);
|
107 | 111 |
|
108 | 112 | $this->checkHandles(explode(',', $params['block']), $asJson);
|
109 |
| - $this->checkQuotes($oldQuote, 'simple2'); |
110 | 113 |
|
| 114 | + $newQuote = $this->session->getQuote(); |
| 115 | + $newQuoteItemsCollection = $newQuote->getItemsCollection(false); |
| 116 | + $this->assertNotNull($newQuoteItemsCollection->getItemByColumnValue('sku', 'simple2')); |
111 | 117 | if ($asJsVarname) {
|
112 | 118 | $this->assertRedirect($this->stringContains('sales/order_create/showUpdateResult'));
|
| 119 | + $body = (string) $this->_objectManager->get(\Magento\Backend\Model\Session::class)->getUpdateResult(); |
| 120 | + } elseif ($asJson) { |
| 121 | + $body = json_decode($this->getResponse()->getBody(), true, 512, JSON_THROW_ON_ERROR)['sidebar']; |
| 122 | + } else { |
| 123 | + $body = $this->getResponse()->getBody(); |
113 | 124 | }
|
| 125 | + $this->assertStringNotContainsString("sidebar[add_cart_item][$itemId]", $body); |
114 | 126 | }
|
115 | 127 |
|
116 | 128 | /**
|
@@ -207,26 +219,31 @@ public function testMoveFromOrderToShoppingCart(): void
|
207 | 219 | *
|
208 | 220 | * @return void
|
209 | 221 | * @magentoDataFixture Magento/Wishlist/_files/wishlist_with_simple_product.php
|
| 222 | + * @magentoDbIsolation disabled |
210 | 223 | */
|
211 | 224 | public function testAddProductToOrderFromWishList(): void
|
212 | 225 | {
|
213 | 226 | /** @var Wishlist $wishlist */
|
214 | 227 | $wishlist = $this->_objectManager->create(Wishlist::class);
|
215 | 228 | $wishlistItems = $wishlist->loadByCustomerId(1)->getItemCollection();
|
216 | 229 | $this->assertCount(1, $wishlistItems);
|
| 230 | + $itemId = $wishlistItems->getFirstItem()->getId(); |
217 | 231 |
|
218 | 232 | $post = $this->hydratePost([
|
219 | 233 | 'sidebar' => [
|
220 | 234 | 'add_wishlist_item' => [
|
221 |
| - $wishlistItems->getFirstItem()->getId() => 1, |
| 235 | + $itemId => 1, |
222 | 236 | ],
|
223 | 237 | ],
|
224 | 238 | ]);
|
225 |
| - $params = $this->hydrateParams(); |
| 239 | + $params = $this->hydrateParams([ |
| 240 | + 'json' => false, |
| 241 | + 'as_js_varname' => false, |
| 242 | + ]); |
226 | 243 | $this->dispatchWitParams($params, $post);
|
227 | 244 |
|
228 |
| - $wishlistItems->clear()->load(); |
229 |
| - $this->assertEmpty($wishlistItems); |
| 245 | + $body = $this->getResponse()->getBody(); |
| 246 | + $this->assertStringNotContainsString("sidebar[add_wishlist_item][$itemId]", $body); |
230 | 247 | $quoteItems = $this->session->getQuote()->getItemsCollection();
|
231 | 248 | $this->assertCount(1, $quoteItems);
|
232 | 249 | }
|
@@ -283,6 +300,93 @@ public function testSetSpecificStoreIdIntoCurrentStore()
|
283 | 300 | $this->assertEquals('fixture_second_store', $this->storeManager->getStore()->getCode());
|
284 | 301 | }
|
285 | 302 |
|
| 303 | + /** |
| 304 | + * @magentoDataFixture Magento/Checkout/_files/quote_with_address.php |
| 305 | + */ |
| 306 | + public function testThatItemsTransferredFromShoppingCartAreDeletedAfterOrderIsCreated(): void |
| 307 | + { |
| 308 | + $oldQuote = $this->getQuoteByReservedOrderId->execute('test_order_1'); |
| 309 | + $this->assertNotEmpty($oldQuote->getItemsCollection(false)->getItems()); |
| 310 | + $itemId = $oldQuote->getItemsCollection()->getFirstItem()->getId(); |
| 311 | + $params = $this->hydrateParams(); |
| 312 | + $post = $this->hydratePost([ |
| 313 | + 'sidebar' => [ |
| 314 | + 'add_cart_item' => [ |
| 315 | + $itemId => 1, |
| 316 | + ], |
| 317 | + ], |
| 318 | + ]); |
| 319 | + |
| 320 | + $this->dispatchWitParams($params, $post); |
| 321 | + $this->assertNotEmpty($oldQuote->getItemsCollection(false)->getItems()); |
| 322 | + $this->placeOrder(); |
| 323 | + $this->assertEmpty($oldQuote->getItemsCollection(false)->getItems()); |
| 324 | + } |
| 325 | + |
| 326 | + /** |
| 327 | + * @magentoDataFixture Magento/Wishlist/_files/wishlist_with_simple_product.php |
| 328 | + * @magentoDataFixture Magento/Customer/_files/customer_address.php |
| 329 | + */ |
| 330 | + public function testThatItemsTransferredFromWishlistAreDeletedAfterOrderIsCreated(): void |
| 331 | + { |
| 332 | + /** @var Wishlist $wishlist */ |
| 333 | + $wishlist = $this->_objectManager->create(Wishlist::class); |
| 334 | + $wishlistItems = $wishlist->loadByCustomerId(1)->getItemCollection(); |
| 335 | + $this->assertCount(1, $wishlistItems); |
| 336 | + $itemId = $wishlistItems->getFirstItem()->getId(); |
| 337 | + |
| 338 | + $post = $this->hydratePost([ |
| 339 | + 'sidebar' => [ |
| 340 | + 'add_wishlist_item' => [ |
| 341 | + $itemId => 1, |
| 342 | + ], |
| 343 | + ], |
| 344 | + ]); |
| 345 | + $params = $this->hydrateParams(); |
| 346 | + $this->dispatchWitParams($params, $post); |
| 347 | + $wishlist = $this->_objectManager->create(Wishlist::class); |
| 348 | + $wishlistItems = $wishlist->loadByCustomerId(1)->getItemCollection(); |
| 349 | + $this->assertCount(1, $wishlistItems); |
| 350 | + $this->placeOrder(); |
| 351 | + $wishlist = $this->_objectManager->create(Wishlist::class); |
| 352 | + $wishlistItems = $wishlist->loadByCustomerId(1)->getItemCollection(); |
| 353 | + $this->assertCount(0, $wishlistItems); |
| 354 | + } |
| 355 | + |
| 356 | + /** |
| 357 | + * @return void |
| 358 | + * @throws \Magento\Framework\Exception\LocalizedException |
| 359 | + */ |
| 360 | + private function placeOrder(): void |
| 361 | + { |
| 362 | + $this->_request = null; |
| 363 | + $this->_response = null; |
| 364 | + Bootstrap::getInstance()->getBootstrap()->getApplication()->reinitialize(); |
| 365 | + Bootstrap::getInstance()->loadArea('adminhtml'); |
| 366 | + $this->_objectManager = Bootstrap::getObjectManager(); |
| 367 | + $this->getRequest() |
| 368 | + ->setMethod(\Magento\Framework\App\Request\Http::METHOD_POST) |
| 369 | + ->setPostValue([ |
| 370 | + 'order' => [ |
| 371 | + 'account' => [ |
| 372 | + 'email' => 'john.doe001@test.com', |
| 373 | + ], |
| 374 | + 'shipping_method' => 'flatrate_flatrate', |
| 375 | + 'payment_method' => 'checkmo', |
| 376 | + ], |
| 377 | + 'collect_shipping_rates' => true |
| 378 | + ]); |
| 379 | + $this->dispatch('backend/sales/order_create/save'); |
| 380 | + $this->assertSessionMessages( |
| 381 | + $this->isEmpty(), |
| 382 | + MessageInterface::TYPE_ERROR |
| 383 | + ); |
| 384 | + $this->assertSessionMessages( |
| 385 | + $this->equalTo([(string)__('You created the order.')]), |
| 386 | + MessageInterface::TYPE_SUCCESS |
| 387 | + ); |
| 388 | + } |
| 389 | + |
286 | 390 | /**
|
287 | 391 | * Check customer quotes
|
288 | 392 | *
|
|
0 commit comments