80 lines
4.0 KiB
PHP
80 lines
4.0 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace Esun\LingxingErp\Test\Unit\Model\Order;
|
|
|
|
use Esun\LingxingErp\Model\Config;
|
|
use Esun\LingxingErp\Model\Order\OrderPayloadBuilder;
|
|
use Magento\Sales\Api\Data\OrderAddressInterface;
|
|
use Magento\Sales\Model\Order;
|
|
use Magento\Sales\Model\Order\Item;
|
|
use Magento\Store\Api\Data\StoreInterface;
|
|
use Magento\Store\Model\StoreManagerInterface;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class OrderPayloadBuilderTest extends TestCase
|
|
{
|
|
public function testAddsAvailableMagentoAddressDataFromExtendedCreateOrderDocument(): void
|
|
{
|
|
$config = $this->createMock(Config::class);
|
|
$config->expects(self::once())->method('assertOrderMappingReady')->with(3);
|
|
$config->method('getStockDeductionType')->willReturn(1);
|
|
$config->method('getWarehouseId')->with(3)->willReturn('');
|
|
$config->method('getPlatformCode')->with(3)->willReturn(10009);
|
|
$config->method('getLingxingStoreId')->with(3)->willReturn('STORE-US');
|
|
|
|
$store = $this->createMock(StoreInterface::class);
|
|
$store->method('getWebsiteId')->willReturn(3);
|
|
$storeManager = $this->createMock(StoreManagerInterface::class);
|
|
$storeManager->method('getStore')->with(16)->willReturn($store);
|
|
|
|
$address = $this->createMock(OrderAddressInterface::class);
|
|
$address->method('getCountryId')->willReturn('US');
|
|
$address->method('getFirstname')->willReturn('Shipping');
|
|
$address->method('getLastname')->willReturn('Customer');
|
|
$address->method('getCompany')->willReturn('Example Inc.');
|
|
$address->method('getCity')->willReturn('Austin');
|
|
$address->method('getRegion')->willReturn('Texas');
|
|
$address->method('getPostcode')->willReturn('78701');
|
|
$address->method('getStreet')->willReturn(['100 Main St', 'Suite 20', 'Reception']);
|
|
$address->method('getTelephone')->willReturn('+1 555 0100');
|
|
$address->method('getEmail')->willReturn('shipping@example.com');
|
|
|
|
$item = $this->createMock(Item::class);
|
|
$item->method('getIsVirtual')->willReturn(false);
|
|
$item->method('getSku')->willReturn('MAGENTO-SKU');
|
|
$item->method('getQtyOrdered')->willReturn(2.0);
|
|
$item->method('getPrice')->willReturn(19.99);
|
|
|
|
$order = $this->createMock(Order::class);
|
|
$order->method('getStoreId')->willReturn(16);
|
|
$order->method('getShippingAddress')->willReturn($address);
|
|
$order->method('getAllVisibleItems')->willReturn([$item]);
|
|
$order->method('getIncrementId')->willReturn('esun100001');
|
|
$order->method('getShippingAmount')->willReturn(5.0);
|
|
$order->method('getTaxAmount')->willReturn(2.0);
|
|
$order->method('getGrandTotal')->willReturn(46.98);
|
|
$order->method('getCreatedAt')->willReturn('2026-09-09 00:00:00');
|
|
$order->method('getOrderCurrencyCode')->willReturn('USD');
|
|
$order->method('getCustomerFirstname')->willReturn('Buyer');
|
|
$order->method('getCustomerMiddlename')->willReturn('M');
|
|
$order->method('getCustomerLastname')->willReturn('Name');
|
|
$order->method('getCustomerEmail')->willReturn('buyer@example.com');
|
|
$order->method('getCustomerNote')->willReturn(null);
|
|
|
|
$payload = (new OrderPayloadBuilder($config, $storeManager))->build($order);
|
|
$orderData = $payload['orders'][0];
|
|
|
|
self::assertSame('100 Main St', $orderData['address_line1']);
|
|
self::assertSame('Suite 20', $orderData['address_line2']);
|
|
self::assertSame('Reception', $orderData['address_line3']);
|
|
self::assertSame('Texas', $orderData['state_or_region']);
|
|
self::assertSame('78701', $orderData['postal_code']);
|
|
self::assertSame('+1 555 0100', $orderData['receiver_mobile']);
|
|
self::assertSame('buyer@example.com', $orderData['buyer_email']);
|
|
self::assertSame('Buyer M Name', $orderData['buyer_name']);
|
|
self::assertArrayNotHasKey('district', $orderData);
|
|
self::assertArrayNotHasKey('doorplate_no', $orderData);
|
|
}
|
|
}
|