Skip to content

Commit 5831fe7

Browse files
author
Spandana Chittimala
committed
Merge remote-tracking branch 'tango/MAGETWO-99647' into PR-05-29-2019
2 parents addca69 + e0992e9 commit 5831fe7

File tree

4 files changed

+280
-5
lines changed
  • app/code/Magento/Sales
  • dev/tests/integration/testsuite/Magento/Sales/Block/Adminhtml/Order/Create/Form

4 files changed

+280
-5
lines changed

app/code/Magento/Sales/Block/Adminhtml/Order/Create/Form/Address.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
use Magento\Framework\App\ObjectManager;
1010
use Magento\Framework\Data\Form\Element\AbstractElement;
1111
use Magento\Framework\Pricing\PriceCurrencyInterface;
12+
use Magento\Customer\Api\Data\AddressInterface;
13+
use Magento\Eav\Model\AttributeDataFactory;
1214

1315
/**
1416
* Order create address form
@@ -191,17 +193,19 @@ public function getAddressCollectionJson()
191193
$emptyAddressForm = $this->_customerFormFactory->create(
192194
'customer_address',
193195
'adminhtml_customer_address',
194-
[\Magento\Customer\Api\Data\AddressInterface::COUNTRY_ID => $defaultCountryId]
196+
[AddressInterface::COUNTRY_ID => $defaultCountryId]
195197
);
196-
$data = [0 => $emptyAddressForm->outputData(\Magento\Eav\Model\AttributeDataFactory::OUTPUT_FORMAT_JSON)];
198+
$data = [0 => $emptyAddressForm->outputData(AttributeDataFactory::OUTPUT_FORMAT_JSON)];
197199
foreach ($this->getAddressCollection() as $address) {
198200
$addressForm = $this->_customerFormFactory->create(
199201
'customer_address',
200202
'adminhtml_customer_address',
201-
$this->addressMapper->toFlatArray($address)
203+
$this->addressMapper->toFlatArray($address),
204+
false,
205+
false
202206
);
203207
$data[$address->getId()] = $addressForm->outputData(
204-
\Magento\Eav\Model\AttributeDataFactory::OUTPUT_FORMAT_JSON
208+
AttributeDataFactory::OUTPUT_FORMAT_JSON
205209
);
206210
}
207211

Lines changed: 263 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,263 @@
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\Sales\Test\Unit\Block\Adminhtml\Order\Create\Form;
9+
10+
use Magento\Backend\Model\Session\Quote as QuoteSession;
11+
use Magento\Store\Model\Store;
12+
use Magento\Directory\Helper\Data as DirectoryHelper;
13+
use Magento\Eav\Model\AttributeDataFactory;
14+
use Magento\Sales\Block\Adminhtml\Order\Create\Form\Address;
15+
use Magento\Customer\Api\AddressRepositoryInterface;
16+
use Magento\Customer\Api\Data\AddressSearchResultsInterface;
17+
use Magento\Customer\Api\Data\AddressInterface;
18+
use Magento\Customer\Model\Metadata\Form;
19+
use Magento\Customer\Model\Metadata\FormFactory;
20+
use Magento\Customer\Model\Address\Mapper;
21+
use Magento\Framework\Api\FilterBuilder;
22+
use Magento\Framework\Api\Filter;
23+
use Magento\Framework\Api\SearchCriteriaBuilder;
24+
use Magento\Framework\Api\SearchCriteria;
25+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
26+
use PHPUnit\Framework\TestCase;
27+
use PHPUnit_Framework_MockObject_MockObject as MockObject;
28+
29+
/**
30+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
31+
*/
32+
class AddressTest extends TestCase
33+
{
34+
/**
35+
* @var QuoteSession|MockObject
36+
*/
37+
private $quoteSession;
38+
39+
/**
40+
* @var Store|MockObject
41+
*/
42+
private $store;
43+
44+
/**
45+
* @var DirectoryHelper|MockObject
46+
*/
47+
private $directoryHelper;
48+
49+
/**
50+
* @var int
51+
*/
52+
private $defaultCountryId;
53+
54+
/**
55+
* @var int
56+
*/
57+
private $customerId;
58+
59+
/**
60+
* @var int
61+
*/
62+
private $addressId;
63+
64+
/**
65+
* @var FormFactory|MockObject
66+
*/
67+
private $formFactory;
68+
69+
/**
70+
* @var FilterBuilder|MockObject
71+
*/
72+
private $filterBuilder;
73+
74+
/**
75+
* @var SearchCriteriaBuilder|MockObject
76+
*/
77+
private $criteriaBuilder;
78+
79+
/**
80+
* @var AddressInterface|MockObject
81+
*/
82+
private $addressItem;
83+
84+
/**
85+
* @var AddressRepositoryInterface|MockObject
86+
*/
87+
private $addressService;
88+
89+
/**
90+
* @var Mapper|MockObject
91+
*/
92+
private $addressMapper;
93+
94+
/**
95+
* @var Address
96+
*/
97+
private $address;
98+
99+
/**
100+
* @var ObjectManager
101+
*/
102+
private $objectManager;
103+
104+
/**
105+
* @inheritdoc
106+
*/
107+
protected function setUp()
108+
{
109+
$this->objectManager = new ObjectManager($this);
110+
111+
$this->defaultCountryId = 1;
112+
$this->customerId = 10;
113+
$this->addressId = 100;
114+
115+
$this->quoteSession = $this->getMockBuilder(QuoteSession::class)
116+
->disableOriginalConstructor()
117+
->setMethods(['getStore', 'getCustomerId'])
118+
->getMock();
119+
$this->store = $this->getMockBuilder(Store::class)
120+
->disableOriginalConstructor()
121+
->getMock();
122+
$this->quoteSession->expects($this->any())
123+
->method('getStore')
124+
->willReturn($this->store);
125+
$this->quoteSession->expects($this->any())
126+
->method('getCustomerId')
127+
->willReturn($this->customerId);
128+
$this->directoryHelper = $this->getMockBuilder(DirectoryHelper::class)
129+
->disableOriginalConstructor()
130+
->setMethods(['getDefaultCountry'])
131+
->getMock();
132+
$this->directoryHelper->expects($this->any())
133+
->method('getDefaultCountry')
134+
->willReturn($this->defaultCountryId);
135+
$this->formFactory = $this->getMockBuilder(FormFactory::class)
136+
->disableOriginalConstructor()
137+
->setMethods(['create'])
138+
->getMock();
139+
$this->filterBuilder = $this->getMockBuilder(FilterBuilder::class)
140+
->disableOriginalConstructor()
141+
->setMethods(['setField', 'setValue', 'setConditionType', 'create'])
142+
->getMock();
143+
$this->criteriaBuilder = $this->getMockBuilder(SearchCriteriaBuilder::class)
144+
->disableOriginalConstructor()
145+
->setMethods(['create', 'addFilters'])
146+
->getMock();
147+
$this->addressService = $this->getMockBuilder(AddressRepositoryInterface::class)
148+
->setMethods(['getList'])
149+
->getMockForAbstractClass();
150+
$this->addressItem = $this->getMockBuilder(AddressInterface::class)
151+
->setMethods(['getId'])
152+
->getMockForAbstractClass();
153+
$this->addressItem->expects($this->any())
154+
->method('getId')
155+
->willReturn($this->addressId);
156+
$this->addressMapper = $this->getMockBuilder(Mapper::class)
157+
->disableOriginalConstructor()
158+
->setMethods(['toFlatArray'])
159+
->getMock();
160+
161+
$this->address = $this->objectManager->getObject(
162+
Address::class,
163+
[
164+
'directoryHelper' => $this->directoryHelper,
165+
'sessionQuote' => $this->quoteSession,
166+
'customerFormFactory' => $this->formFactory,
167+
'filterBuilder' => $this->filterBuilder,
168+
'criteriaBuilder' => $this->criteriaBuilder,
169+
'addressService' => $this->addressService,
170+
'addressMapper' => $this->addressMapper
171+
]
172+
);
173+
}
174+
175+
public function testGetAddressCollectionJson()
176+
{
177+
/** @var Form|MockObject $emptyForm */
178+
$emptyForm = $this->getMockBuilder(Form::class)
179+
->disableOriginalConstructor()
180+
->setMethods(['outputData'])
181+
->getMock();
182+
$emptyForm->expects($this->once())
183+
->method('outputData')
184+
->with(AttributeDataFactory::OUTPUT_FORMAT_JSON)
185+
->willReturn('emptyFormData');
186+
187+
/** @var Filter|MockObject $filter */
188+
$filter = $this->getMockBuilder(Filter::class)
189+
->disableOriginalConstructor()
190+
->getMock();
191+
$this->filterBuilder->expects($this->once())
192+
->method('setField')
193+
->with('parent_id')
194+
->willReturnSelf();
195+
$this->filterBuilder->expects($this->once())
196+
->method('setValue')
197+
->with($this->customerId)
198+
->willReturnSelf();
199+
$this->filterBuilder->expects($this->once())
200+
->method('setConditionType')
201+
->with('eq')
202+
->willReturnSelf();
203+
$this->filterBuilder->expects($this->once())
204+
->method('create')
205+
->willReturn($filter);
206+
207+
/** @var SearchCriteria|MockObject $searchCriteria */
208+
$searchCriteria = $this->getMockBuilder(SearchCriteria::class)
209+
->disableOriginalConstructor()
210+
->getMock();
211+
$this->criteriaBuilder->expects($this->once())
212+
->method('create')
213+
->willReturn($searchCriteria);
214+
$this->criteriaBuilder->expects($this->once())
215+
->method('addFilters')
216+
->with([$filter]);
217+
218+
/** @var AddressSearchResultsInterface|MockObject $result */
219+
$result = $this->getMockBuilder(AddressSearchResultsInterface::class)
220+
->setMethods(['getList'])
221+
->getMockForAbstractClass();
222+
$result->expects($this->once())
223+
->method('getItems')
224+
->willReturn([$this->addressItem]);
225+
$this->addressService->expects($this->once())
226+
->method('getList')
227+
->with($searchCriteria)
228+
->willReturn($result);
229+
230+
/** @var Form|MockObject $emptyForm */
231+
$addressForm = $this->getMockBuilder(Form::class)
232+
->disableOriginalConstructor()
233+
->setMethods(['outputData'])
234+
->getMock();
235+
$addressForm->expects($this->once())
236+
->method('outputData')
237+
->with(AttributeDataFactory::OUTPUT_FORMAT_JSON)
238+
->willReturn('addressFormData');
239+
$this->addressMapper->expects($this->once())
240+
->method('toFlatArray')
241+
->with($this->addressItem)
242+
->willReturn([]);
243+
244+
$this->directoryHelper->expects($this->once())
245+
->method('getDefaultCountry')
246+
->with($this->store)
247+
->willReturn($this->defaultCountryId);
248+
$this->formFactory->expects($this->at(0))
249+
->method('create')
250+
->with(
251+
'customer_address',
252+
'adminhtml_customer_address',
253+
[AddressInterface::COUNTRY_ID => $this->defaultCountryId]
254+
)
255+
->willReturn($emptyForm);
256+
$this->formFactory->expects($this->at(1))
257+
->method('create')
258+
->with('customer_address', 'adminhtml_customer_address', [], false, false)
259+
->willReturn($addressForm);
260+
261+
$this->address->getAddressCollectionJson();
262+
}
263+
}

app/code/Magento/Sales/view/adminhtml/templates/order/create/form/address.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ if ($block->getIsShipping()):
3232
require(["Magento_Sales/order/create/form"], function(){
3333

3434
order.shippingAddressContainer = '<?= /* @escapeNotVerified */ $_fieldsContainerId ?>';
35-
order.setAddresses(<?= /* @escapeVerfied */ $block->getAddressCollectionJson() ?>);
35+
order.setAddresses(<?= /* @noEscape */ $block->getAddressCollectionJson() ?>);
3636

3737
});
3838
</script>

dev/tests/integration/testsuite/Magento/Sales/Block/Adminhtml/Order/Create/Form/AddressTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ public function testGetAddressCollectionJson()
122122
'postcode' => '90230',
123123
'telephone' => '3468676',
124124
'vat_id' => false,
125+
'prefix' => false,
126+
'middlename' => false,
127+
'suffix' => false,
128+
'fax' => false
125129
],
126130
$addresses[1]->getId() => [
127131
'telephone' => '845454465',
@@ -135,6 +139,10 @@ public function testGetAddressCollectionJson()
135139
'region' => false,
136140
'region_id' => 0,
137141
'vat_id' => false,
142+
'prefix' => false,
143+
'middlename' => false,
144+
'suffix' => false,
145+
'fax' => false
138146
]
139147
];
140148

0 commit comments

Comments
 (0)