1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Customer\Model\Metadata;
use Magento\TestFramework\Helper\Bootstrap;
class FormTest extends \PHPUnit\Framework\TestCase
{
/**
* @var Form
*/
protected $_form;
/** @var array */
protected $_attributes;
/** @var \Magento\Framework\App\RequestInterface */
protected $_request;
/** @var array */
protected $_expected;
/** @var array */
protected $_requestData = [];
public function setUp()
{
$objectManager = Bootstrap::getObjectManager();
/** @var FormFactory $formFactory */
$formFactory = $objectManager->create(\Magento\Customer\Model\Metadata\FormFactory::class);
$this->_form = $formFactory->create('customer_address', 'customer_address_edit');
$this->_attributes = [
'id' => 14,
'default_shipping' => 1,
'default_billing' => 0,
'company' => 'Company Name',
'middlename' => 'Mid',
'prefix' => 'Mr.',
'suffix' => 'Esq.',
'vat_id' => '',
'firstname' => 'Jane',
'lastname' => 'Doe',
'street' => ['2211 North First Street'],
'city' => 'San Jose',
'country_id' => 'US',
'postcode' => '95131',
'telephone' => '5125125125',
'region_id' => 12,
'region' => 'California',
];
$requestData = [
'company' => 'Company Name',
'middlename' => 'Mid',
'prefix' => 'Mr.',
'suffix' => 'Esq.',
'vat_id' => '',
'firstname' => 'New Name',
'lastname' => 'Doe',
'street' => ['2211 New Street'],
'city' => 'San Jose',
'country_id' => 'US',
'postcode' => '95131',
'telephone' => '5125125125',
'region_id' => 12,
'region' => 'California',
];
$this->_request = $objectManager->get(\Magento\Framework\App\RequestInterface::class);
$this->_request->setParams($requestData);
$this->_expected = array_merge($this->_attributes, $requestData);
unset($this->_expected['id']);
unset($this->_expected['default_shipping']);
unset($this->_expected['default_billing']);
unset($this->_expected['middlename']);
unset($this->_expected['prefix']);
unset($this->_expected['suffix']);
}
/**
* @magentoAppIsolation enabled
*/
public function testCompactData()
{
$attributeValues = $this->_form->compactData($this->_form->extractData($this->_request));
$this->assertEquals($this->_expected, $attributeValues);
}
/**
* @magentoAppIsolation enabled
*/
public function testGetAttributes()
{
$expectedAttributes = [
'prefix',
'firstname',
'middlename',
'lastname',
'suffix',
'company',
'street',
'city',
'country_id',
'region',
'region_id',
'postcode',
'telephone',
'fax',
'vat_id',
];
$this->assertEquals($expectedAttributes, array_keys($this->_form->getAttributes()));
}
/**
* @magentoAppIsolation enabled
*/
public function testGetSystemAttributes()
{
$this->assertCount(15, $this->_form->getSystemAttributes());
}
/**
* @magentoAppIsolation enabled
* @magentoDataFixture Magento/Customer/_files/attribute_user_defined_address.php
*/
public function testGetUserAttributes()
{
$expectedAttributes = ['address_user_attribute'];
$this->assertEquals($expectedAttributes, array_keys($this->_form->getUserAttributes()));
}
/**
* @magentoAppIsolation enabled
*/
public function testRestoreData()
{
$attributeValues = $this->_form->restoreData($this->_form->extractData($this->_request));
$this->assertEquals($this->_expected, $attributeValues);
}
}