|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright 2023 Adobe |
| 4 | + * All Rights Reserved. |
| 5 | + * |
| 6 | + * NOTICE: All information contained herein is, and remains |
| 7 | + * the property of Adobe and its suppliers, if any. The intellectual |
| 8 | + * and technical concepts contained herein are proprietary to Adobe |
| 9 | + * and its suppliers and are protected by all applicable intellectual |
| 10 | + * property laws, including trade secret and copyright laws. |
| 11 | + * Dissemination of this information or reproduction of this material |
| 12 | + * is strictly forbidden unless prior written permission is obtained |
| 13 | + * from Adobe. |
| 14 | + */ |
| 15 | +declare(strict_types=1); |
| 16 | + |
| 17 | +namespace Magento\Sales\Model\ResourceModel\Order; |
| 18 | + |
| 19 | +use Magento\Catalog\Test\Fixture\Product as ProductFixture; |
| 20 | +use Magento\Checkout\Test\Fixture\PlaceOrder as PlaceOrderFixture; |
| 21 | +use Magento\Checkout\Test\Fixture\SetBillingAddress; |
| 22 | +use Magento\Checkout\Test\Fixture\SetDeliveryMethod as SetDeliveryMethodFixture; |
| 23 | +use Magento\Checkout\Test\Fixture\SetPaymentMethod as SetPaymentMethodFixture; |
| 24 | +use Magento\Checkout\Test\Fixture\SetShippingAddress; |
| 25 | +use Magento\Customer\Test\Fixture\Customer; |
| 26 | +use Magento\Framework\Exception\LocalizedException; |
| 27 | +use Magento\Quote\Test\Fixture\AddProductToCart; |
| 28 | +use Magento\Quote\Test\Fixture\CustomerCart; |
| 29 | +use Magento\Sales\Api\OrderAddressRepositoryInterface; |
| 30 | +use Magento\Sales\Api\OrderRepositoryInterface; |
| 31 | +use Magento\TestFramework\Fixture\DataFixture; |
| 32 | +use Magento\TestFramework\Fixture\DataFixtureStorage; |
| 33 | +use Magento\TestFramework\Fixture\DataFixtureStorageManager; |
| 34 | +use Magento\TestFramework\Fixture\DbIsolation; |
| 35 | +use Magento\TestFramework\Helper\Bootstrap; |
| 36 | +use Magento\TestFramework\ObjectManager; |
| 37 | +use PHPUnit\Framework\TestCase; |
| 38 | + |
| 39 | +/** |
| 40 | + * Test for order address |
| 41 | + * |
| 42 | + * @magentoAppArea adminhtml |
| 43 | + */ |
| 44 | +class AddressTest extends TestCase |
| 45 | +{ |
| 46 | + /** |
| 47 | + * @var ObjectManager |
| 48 | + */ |
| 49 | + private $objectManager; |
| 50 | + |
| 51 | + /** |
| 52 | + * @var DataFixtureStorage |
| 53 | + */ |
| 54 | + private $fixtures; |
| 55 | + |
| 56 | + /** |
| 57 | + * @var OrderAddressRepositoryInterface |
| 58 | + */ |
| 59 | + private $orderAddressRepository; |
| 60 | + |
| 61 | + /** |
| 62 | + * @var OrderRepositoryInterface |
| 63 | + */ |
| 64 | + private $orderRepository; |
| 65 | + |
| 66 | + protected function setUp(): void |
| 67 | + { |
| 68 | + $this->objectManager = Bootstrap::getObjectManager(); |
| 69 | + $this->fixtures = $this->objectManager->get(DataFixtureStorageManager::class)->getStorage(); |
| 70 | + $this->orderAddressRepository = $this->objectManager->get(OrderAddressRepositoryInterface::class); |
| 71 | + $this->orderRepository = $this->objectManager->get(OrderRepositoryInterface::class); |
| 72 | + } |
| 73 | + |
| 74 | + /** |
| 75 | + * Check to see if leading zeros have been added to the number strings |
| 76 | + * in the order address's phone field. |
| 77 | + * |
| 78 | + * @return void |
| 79 | + * @throws LocalizedException |
| 80 | + */ |
| 81 | + #[ |
| 82 | + DataFixture(ProductFixture::class, as: 'product'), |
| 83 | + DataFixture(Customer::class, as: 'customer'), |
| 84 | + DataFixture(CustomerCart::class, ['customer_id' => '$customer.id$'], as: 'quote'), |
| 85 | + DataFixture(AddProductToCart::class, ['cart_id' => '$quote.id$', 'product_id' => '$product.id$', 'qty' => 1]), |
| 86 | + DataFixture(SetBillingAddress::class, [ |
| 87 | + 'cart_id' => '$quote.id$', |
| 88 | + 'address' => [ |
| 89 | + 'customer_id' => '$customer.id$', |
| 90 | + 'telephone' => '009999999999' |
| 91 | + ] |
| 92 | + ]), |
| 93 | + DataFixture(SetShippingAddress::class, ['cart_id' => '$quote.id$']), |
| 94 | + DataFixture(SetDeliveryMethodFixture::class, ['cart_id' => '$quote.id$']), |
| 95 | + DataFixture(SetPaymentMethodFixture::class, ['cart_id' => '$quote.id$']), |
| 96 | + DataFixture(PlaceOrderFixture::class, ['cart_id' => '$quote.id$'], 'order') |
| 97 | + ] |
| 98 | + public function testOrderAddressUpdateWithTelephone(): void |
| 99 | + { |
| 100 | + $telephoneValue = '9999999999'; |
| 101 | + $order = $this->fixtures->get('order'); |
| 102 | + $address = $this->orderAddressRepository->get($order->getBillingAddressId()); |
| 103 | + $address->setTelephone($telephoneValue); |
| 104 | + $this->orderAddressRepository->save($address); |
| 105 | + $updatedOrder = $this->orderRepository->get($order->getId()); |
| 106 | + $billingAddress = $updatedOrder->getBillingAddress(); |
| 107 | + $updatedTelephoneValue = $billingAddress->getTelephone(); |
| 108 | + $this->assertEquals($telephoneValue, $updatedTelephoneValue); |
| 109 | + } |
| 110 | +} |
0 commit comments