|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +namespace Magento\Sales\Service\V1; |
| 7 | + |
| 8 | +use Magento\Checkout\Test\Fixture\PlaceOrder as PlaceOrderFixture; |
| 9 | +use Magento\Checkout\Test\Fixture\SetBillingAddress as SetBillingAddressFixture; |
| 10 | +use Magento\Checkout\Test\Fixture\SetDeliveryMethod as SetDeliveryMethodFixture; |
| 11 | +use Magento\Checkout\Test\Fixture\SetGuestEmail as SetGuestEmailFixture; |
| 12 | +use Magento\Checkout\Test\Fixture\SetPaymentMethod as SetPaymentMethodFixture; |
| 13 | +use Magento\Checkout\Test\Fixture\SetShippingAddress as SetShippingAddressFixture; |
| 14 | +use Magento\Framework\Exception\NoSuchEntityException; |
| 15 | +use Magento\Framework\Webapi\Rest\Request; |
| 16 | +use Magento\Sales\Api\Data\OrderInterface; |
| 17 | +use Magento\Sales\Test\Fixture\Invoice as InvoiceFixture; |
| 18 | +use Magento\TestFramework\Fixture\DataFixture; |
| 19 | +use Magento\TestFramework\TestCase\WebapiAbstract; |
| 20 | +use Magento\Framework\ObjectManagerInterface; |
| 21 | +use Magento\TestFramework\Fixture\DataFixtureStorage; |
| 22 | +use Magento\TestFramework\Fixture\DataFixtureStorageManager; |
| 23 | +use Magento\TestFramework\Helper\Bootstrap; |
| 24 | +use Magento\Catalog\Test\Fixture\Product as ProductFixture; |
| 25 | +use Magento\ConfigurableProduct\Test\Fixture\Attribute as AttributeFixture; |
| 26 | +use Magento\ConfigurableProduct\Test\Fixture\Product as ConfigurableProductFixture; |
| 27 | +use Magento\Quote\Test\Fixture\GuestCart as GuestCartFixture; |
| 28 | +use Magento\ConfigurableProduct\Test\Fixture\AddProductToCart as AddConfigurableProductToCartFixture; |
| 29 | + |
| 30 | +/** |
| 31 | + * Class CreditMemoGenerateIfConfigurableProductWithDecimalQuantityTest |
| 32 | + */ |
| 33 | +class CreditMemoGenerateIfConfigurableProductWithDecimalQuantityTest extends WebapiAbstract |
| 34 | +{ |
| 35 | + private const SERVICE_REFUND_ORDER_NAME = 'salesRefundOrderV1'; |
| 36 | + |
| 37 | + /** |
| 38 | + * @var ObjectManagerInterface |
| 39 | + */ |
| 40 | + private $objectManager; |
| 41 | + |
| 42 | + /** |
| 43 | + * @var DataFixtureStorage |
| 44 | + */ |
| 45 | + private $fixtures; |
| 46 | + |
| 47 | + protected function setUp(): void |
| 48 | + { |
| 49 | + $this->objectManager = Bootstrap::getObjectManager(); |
| 50 | + $this->fixtures = $this->objectManager->get(DataFixtureStorageManager::class)->getStorage(); |
| 51 | + } |
| 52 | + |
| 53 | + #[ |
| 54 | + DataFixture(ProductFixture::class, ['stock_item' => ['is_qty_decimal' => true]], as: 'p1'), |
| 55 | + DataFixture(ProductFixture::class, as: 'p2'), |
| 56 | + DataFixture(AttributeFixture::class, as: 'attr'), |
| 57 | + DataFixture( |
| 58 | + ConfigurableProductFixture::class, |
| 59 | + ['_options' => ['$attr$'], '_links' => ['$p1$', '$p2$']], |
| 60 | + 'cp1' |
| 61 | + ), |
| 62 | + DataFixture(GuestCartFixture::class, as: 'cart'), |
| 63 | + DataFixture( |
| 64 | + AddConfigurableProductToCartFixture::class, |
| 65 | + ['cart_id' => '$cart.id$', 'product_id' => '$cp1.id$', 'child_product_id' => '$p1.id$', 'qty' => 2.6], |
| 66 | + ), |
| 67 | + DataFixture(SetBillingAddressFixture::class, ['cart_id' => '$cart.id$']), |
| 68 | + DataFixture(SetShippingAddressFixture::class, ['cart_id' => '$cart.id$']), |
| 69 | + DataFixture(SetGuestEmailFixture::class, ['cart_id' => '$cart.id$']), |
| 70 | + DataFixture(SetDeliveryMethodFixture::class, ['cart_id' => '$cart.id$']), |
| 71 | + DataFixture(SetPaymentMethodFixture::class, ['cart_id' => '$cart.id$']), |
| 72 | + DataFixture(PlaceOrderFixture::class, ['cart_id' => '$cart.id$'], 'order'), |
| 73 | + DataFixture(InvoiceFixture::class, ['order_id' => '$order.id$']), |
| 74 | + ] |
| 75 | + public function testCreditMemoGenerationWithConfigurableProductDecimalQuantity(): void |
| 76 | + { |
| 77 | + $order = $this->fixtures->get('order'); |
| 78 | + try { |
| 79 | + $creditMemoResult = $this->_webApiCall( |
| 80 | + $this->getServiceData($order), |
| 81 | + [ |
| 82 | + 'orderId' => $order->getEntityId() |
| 83 | + ] |
| 84 | + ); |
| 85 | + $this->assertGreaterThan(0 , $creditMemoResult); |
| 86 | + } catch (NoSuchEntityException $e) { |
| 87 | + $this->fail('Failed asserting that Creditmemo was not created'); |
| 88 | + } |
| 89 | + } |
| 90 | + |
| 91 | + /** |
| 92 | + * Prepares and returns info for API service. |
| 93 | + * |
| 94 | + * @param OrderInterface $order |
| 95 | + * |
| 96 | + * @return array |
| 97 | + */ |
| 98 | + private function getServiceData(OrderInterface $order) |
| 99 | + { |
| 100 | + return [ |
| 101 | + 'rest' => [ |
| 102 | + 'resourcePath' => '/V1/order/' . $order->getEntityId() . '/refund', |
| 103 | + 'httpMethod' => Request::HTTP_METHOD_POST, |
| 104 | + ], |
| 105 | + 'soap' => [ |
| 106 | + 'service' => self::SERVICE_REFUND_ORDER_NAME, |
| 107 | + 'serviceVersion' => 'V1', |
| 108 | + 'operation' => self::SERVICE_REFUND_ORDER_NAME . 'execute', |
| 109 | + ] |
| 110 | + ]; |
| 111 | + } |
| 112 | +} |
0 commit comments