|
| 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\Customer\Test\Unit\Model\Address; |
| 18 | + |
| 19 | +use Magento\Customer\Api\Data\AddressInterface; |
| 20 | +use Magento\Customer\Api\Data\CustomerInterface; |
| 21 | +use Magento\Customer\Model\Address\CustomerAddressDataFormatter; |
| 22 | +use Magento\Customer\Model\Address\CustomerAddressDataProvider; |
| 23 | +use Magento\Customer\Model\Config\Share; |
| 24 | +use Magento\Directory\Model\AllowedCountries; |
| 25 | +use PHPUnit\Framework\MockObject\MockObject; |
| 26 | +use PHPUnit\Framework\TestCase; |
| 27 | + |
| 28 | +class CustomerAddressDataProviderTest extends TestCase |
| 29 | +{ |
| 30 | + /** |
| 31 | + * @var CustomerAddressDataFormatter|MockObject |
| 32 | + */ |
| 33 | + private CustomerAddressDataFormatter $customerAddressDataFormatter; |
| 34 | + |
| 35 | + /** |
| 36 | + * @var Share|MockObject |
| 37 | + */ |
| 38 | + private Share $shareConfig; |
| 39 | + |
| 40 | + /** |
| 41 | + * @var AllowedCountries|MockObject |
| 42 | + */ |
| 43 | + private AllowedCountries $allowedCountryReader; |
| 44 | + |
| 45 | + /** |
| 46 | + * @var CustomerAddressDataProvider |
| 47 | + */ |
| 48 | + private CustomerAddressDataProvider $provider; |
| 49 | + |
| 50 | + /** |
| 51 | + * @inheritdoc |
| 52 | + */ |
| 53 | + protected function setUp(): void |
| 54 | + { |
| 55 | + $this->customerAddressDataFormatter = $this->createMock(CustomerAddressDataFormatter::class); |
| 56 | + $this->shareConfig = $this->createMock(Share::class); |
| 57 | + $this->allowedCountryReader = $this->createMock(AllowedCountries::class); |
| 58 | + |
| 59 | + $this->provider = new CustomerAddressDataProvider( |
| 60 | + $this->customerAddressDataFormatter, |
| 61 | + $this->shareConfig, |
| 62 | + $this->allowedCountryReader |
| 63 | + ); |
| 64 | + } |
| 65 | + |
| 66 | + /** |
| 67 | + * @return void |
| 68 | + * @throws \Magento\Framework\Exception\LocalizedException |
| 69 | + */ |
| 70 | + public function testGetAddressDataByCustomer(): void |
| 71 | + { |
| 72 | + $addressLimit = 1; |
| 73 | + $this->allowedCountryReader->expects($this->once())->method('getAllowedCountries')->willReturn(['1']); |
| 74 | + $this->customerAddressDataFormatter->expects($this->once()) |
| 75 | + ->method('prepareAddress') |
| 76 | + ->willreturn([1]); |
| 77 | + $this->shareConfig->expects($this->any())->method('isGlobalScope')->willReturn(false); |
| 78 | + |
| 79 | + $viableAddress = $this->getMockForAbstractClass(AddressInterface::class); |
| 80 | + $viableAddress->expects($this->once())->method('getId')->willReturn(1); |
| 81 | + $faultyAddress = $this->getMockForAbstractClass(AddressInterface::class); |
| 82 | + |
| 83 | + $customer = $this->getMockForAbstractClass(CustomerInterface::class); |
| 84 | + $customer->expects($this->once()) |
| 85 | + ->method('getAddresses') |
| 86 | + ->willReturn([$viableAddress, $faultyAddress]); |
| 87 | + |
| 88 | + $expectedResult = [ |
| 89 | + '1' => [1] |
| 90 | + ]; |
| 91 | + $this->assertSame($expectedResult, $this->provider->getAddressDataByCustomer($customer, $addressLimit)); |
| 92 | + } |
| 93 | +} |
0 commit comments