|
12 | 12 | use Magento\Framework\Api\AttributeValueFactory; |
13 | 13 | use \Magento\Framework\Api\SearchCriteriaInterface; |
14 | 14 | use Magento\Framework\App\Cache\Type\Reflection; |
| 15 | +use Magento\Framework\Exception\InputException; |
15 | 16 | use Magento\Framework\Exception\InvalidArgumentException; |
16 | 17 | use Magento\Framework\ObjectManagerInterface; |
17 | 18 | use Magento\Framework\Reflection\FieldNamer; |
|
20 | 21 | use Magento\Framework\Reflection\TypeProcessor; |
21 | 22 | use Magento\Framework\Serialize\SerializerInterface; |
22 | 23 | use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; |
| 24 | +use Magento\Framework\Webapi\Exception; |
23 | 25 | use Magento\Framework\Webapi\Validator\IOLimit\DefaultPageSizeSetter; |
24 | 26 | use Magento\Framework\Webapi\ServiceInputProcessor; |
25 | 27 | use Magento\Framework\Webapi\Validator\IOLimit\IOLimitConfigProvider; |
|
40 | 42 | use PHPUnit\Framework\MockObject\MockObject; |
41 | 43 | use PHPUnit\Framework\TestCase; |
42 | 44 | use Magento\Framework\Webapi\Validator\EntityArrayValidator\InputArraySizeLimitValue; |
| 45 | +use Magento\Quote\Api\ShipmentEstimationInterface; |
| 46 | +use Magento\Quote\Api\Data\AddressInterface; |
43 | 47 |
|
44 | 48 | /** |
45 | 49 | * @SuppressWarnings(PHPMD.CouplingBetweenObjects) |
@@ -84,16 +88,23 @@ class ServiceInputProcessorTest extends TestCase |
84 | 88 | */ |
85 | 89 | private $defaultPageSizeSetter; |
86 | 90 |
|
| 91 | + /** |
| 92 | + * @var AddressInterface|MockObject |
| 93 | + */ |
| 94 | + protected $addressMock; |
| 95 | + |
87 | 96 | /** |
88 | 97 | * @SuppressWarnings(PHPMD.ExcessiveMethodLength) |
89 | 98 | */ |
90 | 99 | protected function setUp(): void |
91 | 100 | { |
92 | 101 | $this->searchCriteria = self::getMockBuilder(SearchCriteriaInterface::class) |
93 | 102 | ->getMock(); |
94 | | - |
| 103 | + $this->addressMock = self::getMockBuilder(AddressInterface::class) |
| 104 | + ->getMock(); |
95 | 105 | $objectManagerStatic = [ |
96 | | - SearchCriteriaInterface::class => $this->searchCriteria |
| 106 | + SearchCriteriaInterface::class => $this->searchCriteria, |
| 107 | + AddressInterface::class => $this->addressMock |
97 | 108 | ]; |
98 | 109 | $objectManager = new ObjectManager($this); |
99 | 110 | $this->objectManagerMock = $this->getMockBuilder(ObjectManagerInterface::class) |
@@ -701,4 +712,60 @@ public function invalidCustomAttributesDataProvider() |
701 | 712 | ] |
702 | 713 | ]; |
703 | 714 | } |
| 715 | + |
| 716 | + /** |
| 717 | + * @return array |
| 718 | + */ |
| 719 | + public function payloadDataProvider(): array |
| 720 | + { |
| 721 | + return [ |
| 722 | + [ |
| 723 | + [ |
| 724 | + 'address' => [ |
| 725 | + "street" => [ |
| 726 | + "서울 강북구 한천로166길 2 (-서울 강북구 수유동 269-36)" |
| 727 | + ], |
| 728 | + "city." => "pune", |
| 729 | + ], |
| 730 | + 'cartId' => "30" |
| 731 | + ], |
| 732 | + 1 |
| 733 | + ], |
| 734 | + [ |
| 735 | + [ |
| 736 | + 'address' => [ |
| 737 | + "street" => [ |
| 738 | + "서울 강북구 한천로166길 2 (-서울 강북구 수유동 269-36)" |
| 739 | + ], |
| 740 | + "city" => "pune", |
| 741 | + ], |
| 742 | + 'cartId' => "30" |
| 743 | + ], |
| 744 | + 0 |
| 745 | + ] |
| 746 | + ]; |
| 747 | + } |
| 748 | + |
| 749 | + /** |
| 750 | + * Validate if payload has correct attributes |
| 751 | + * |
| 752 | + * @param array $payload |
| 753 | + * @param int $exception |
| 754 | + * @return void |
| 755 | + * @throws Exception |
| 756 | + * @dataProvider payloadDataProvider |
| 757 | + */ |
| 758 | + public function testValidateApiPayload(array $payload, int $exception): void |
| 759 | + { |
| 760 | + if ($exception) { |
| 761 | + $this->expectException(InputException::class); |
| 762 | + $this->expectExceptionMessage('"City." is required. Enter and try again.'); |
| 763 | + } |
| 764 | + $result = $this->serviceInputProcessor->process( |
| 765 | + ShipmentEstimationInterface::class, |
| 766 | + 'estimateByExtendedAddress', |
| 767 | + $payload |
| 768 | + ); |
| 769 | + $this->assertNotEmpty($result); |
| 770 | + } |
704 | 771 | } |
0 commit comments