Skip to content

Commit 7df64bd

Browse files
ashishkumarpundeerashishkumarpundeer
authored andcommitted
AC-9340::Error occurs during Region id Processing while multi-shipping checkout
1 parent 7e5a145 commit 7df64bd

File tree

1 file changed

+204
-0
lines changed

1 file changed

+204
-0
lines changed
Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Catalog\Test\Unit\Controller\Adminhtml\Product\Attribute;
9+
10+
use Magento\Catalog\Test\Unit\Controller\Adminhtml\Product\AttributeTest;
11+
use Magento\Customer\Api\AddressMetadataInterface;
12+
use Magento\Customer\Api\Data\AddressInterfaceFactory;
13+
use Magento\Customer\Api\Data\RegionInterfaceFactory;
14+
use Magento\Customer\Model\Address\AbstractAddress;
15+
use Magento\Customer\Model\Address\CompositeValidator;
16+
use Magento\Framework\ObjectManagerInterface;
17+
use PHPUnit\Framework\MockObject\MockObject;
18+
use Magento\Framework\Model\Context;
19+
use Magento\Framework\Registry;
20+
use Magento\Framework\Api\ExtensionAttributesFactory;
21+
use Magento\Framework\Api\AttributeValueFactory;
22+
use Magento\Directory\Helper\Data;
23+
use Magento\Eav\Model\Config;
24+
use Magento\Directory\Model\RegionFactory;
25+
use Magento\Directory\Model\CountryFactory;
26+
use Magento\Framework\Api\DataObjectHelper;
27+
use Magento\Framework\Model\ResourceModel\AbstractResource;
28+
use Magento\Framework\Data\Collection\AbstractDb;
29+
use Magento\Customer\Model\Address\Config as AddressConfig;
30+
use Magento\Framework\App\ObjectManager;
31+
use Magento\Framework\Model\AbstractExtensibleModel;
32+
use Magento\Directory\Model\Region;
33+
34+
/**
35+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
36+
*/
37+
class GetRegionIdTest extends AttributeTest
38+
{
39+
40+
/**
41+
* @var Context|MockObject
42+
*/
43+
private Context $context;
44+
45+
/**
46+
* @var Registry|MockObject
47+
*/
48+
private Registry $registry;
49+
50+
/**
51+
* @var ExtensionAttributesFactory|MockObject
52+
*/
53+
private ExtensionAttributesFactory $extensionFactory;
54+
55+
/**
56+
* @var AttributeValueFactory|MockObject
57+
*/
58+
private AttributeValueFactory $customAttributeFactory;
59+
60+
/**
61+
* @var Data|MockObject
62+
*/
63+
private Data $directoryData;
64+
65+
/**
66+
* @var Config|MockObject
67+
*/
68+
private Config $eavConfig;
69+
70+
/**
71+
* @var \Magento\Customer\Model\Address\Config
72+
*/
73+
protected $_addressConfig;
74+
75+
/**
76+
* @var RegionFactory|MockObject
77+
*/
78+
private RegionFactory $regionFactory;
79+
80+
/**
81+
* @var CountryFactory|MockObject
82+
*/
83+
private CountryFactory $countryFactory;
84+
85+
/**
86+
* @var AddressMetadataInterface
87+
*/
88+
protected $metadataService;
89+
90+
/**
91+
* @var AddressInterfaceFactory
92+
*/
93+
protected $addressDataFactory;
94+
95+
/**
96+
* @var RegionInterfaceFactory
97+
*/
98+
protected $regionDataFactory;
99+
100+
/**
101+
* @var DataObjectHelper|MockObject
102+
*/
103+
private DataObjectHelper $dataObjectHelper;
104+
105+
/**
106+
* @var AbstractResource|MockObject
107+
*/
108+
private AbstractResource $resource;
109+
110+
/**
111+
* @var AbstractDb|MockObject
112+
*/
113+
private AbstractDb $resourceCollection;
114+
115+
/** @var CompositeValidator */
116+
private $compositeValidator;
117+
118+
/**
119+
* @var ObjectManagerInterface|MockObject
120+
*/
121+
protected $objectManagerMock;
122+
123+
/**
124+
* @var AbstractExtensibleModel|MockObject
125+
*/
126+
protected $abstractExtensibleModel;
127+
128+
/**
129+
* @var Region|MockObject
130+
*/
131+
protected $region;
132+
133+
134+
/**
135+
* @var AbstractAddress|MockObject
136+
*/
137+
protected $abstractAddress;
138+
139+
protected function setUp(): void
140+
{
141+
$this->context = $this->createMock(Context::class);
142+
$this->registry = $this->createMock(Registry::class);
143+
$this->extensionFactory = $this->createMock(ExtensionAttributesFactory::class);
144+
$this->customAttributeFactory = $this->createMock(AttributeValueFactory::class);
145+
$this->directoryData = $this->createMock(Data::class);
146+
$this->eavConfig = $this->createMock(Config::class);
147+
$this->_addressConfig = $this->createMock(AddressConfig::class);
148+
$this->countryFactory = $this->createMock(CountryFactory::class);
149+
$this->metadataService = $this->createMock(AddressMetadataInterface::class);
150+
$this->addressDataFactory = $this->createMock(AddressInterfaceFactory::class);
151+
$this->regionDataFactory = $this->createMock(RegionInterfaceFactory::class);
152+
$this->dataObjectHelper = $this->createMock(DataObjectHelper::class);
153+
$this->resource = $this->createMock(AbstractResource::class);
154+
$this->resourceCollection = $this->createMock(AbstractDb::class);
155+
$this->objectManagerMock = $this->getMockBuilder(ObjectManagerInterface::class)
156+
->getMockForAbstractClass();
157+
$compositeValidator = $this->createMock(CompositeValidator::class);
158+
$this->compositeValidator = $compositeValidator ?: ObjectManager::getInstance();
159+
$this->abstractExtensibleModel = $this->createMock(AbstractExtensibleModel::class);
160+
$this->region = $this->createMock(Region::class);
161+
}
162+
163+
public function testExecute()
164+
{
165+
$address = $this->getMockBuilder(AbstractAddress::class)
166+
->disableOriginalConstructor()
167+
->setMethods(['getRegionCode', 'getCountryId'])
168+
->getMock();
169+
//loadByCode
170+
$regionFactory = $this->getMockBuilder(RegionFactory::class)
171+
->disableOriginalConstructor()
172+
->setMethods(['create'])
173+
->getMock();
174+
$region = $this->getMockBuilder(Region::class)
175+
->disableOriginalConstructor()
176+
->setMethods(['getRegionIdByCode'])
177+
->getMock();
178+
$regionFactory->expects($this->once())
179+
->method('create')
180+
->willReturn($region);
181+
$abstractAddress = new AbstractAddress(
182+
$this->context,
183+
$this->registry,
184+
$this->extensionFactory,
185+
$this->customAttributeFactory,
186+
$this->directoryData,
187+
$this->eavConfig,
188+
$this->_addressConfig,
189+
$regionFactory, // Use the mocked RegionFactory
190+
$this->countryFactory,
191+
$this->metadataService,
192+
$this->addressDataFactory,
193+
$this->regionDataFactory,
194+
$this->dataObjectHelper,
195+
$this->resource,
196+
$this->resourceCollection,
197+
[],
198+
$this->compositeValidator
199+
);
200+
$regionId = $abstractAddress->getRegionId();
201+
// Assert the result
202+
$this->assertEquals(null, $regionId);
203+
}
204+
}

0 commit comments

Comments
 (0)