11
11
class BookTest extends \PHPUnit \Framework \TestCase
12
12
{
13
13
/**
14
- * @var \Magento\Customer\Block\Address\Book
14
+ * @var \Magento\Framework\View\LayoutInterface
15
15
*/
16
- protected $ _block ;
16
+ private $ layout ;
17
17
18
18
/**
19
19
* @var \Magento\Customer\Helper\Session\CurrentCustomer
@@ -32,15 +32,8 @@ protected function setUp()
32
32
33
33
$ this ->currentCustomer = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()
34
34
->get (\Magento \Customer \Helper \Session \CurrentCustomer::class);
35
- /** @var \Magento\Framework\View\LayoutInterface $layout */
36
- $ layout = Bootstrap::getObjectManager ()->get (\Magento \Framework \View \LayoutInterface::class);
37
- $ layout ->setBlock ('head ' , $ blockMock );
38
- $ this ->_block = $ layout
39
- ->createBlock (
40
- \Magento \Customer \Block \Address \Book::class,
41
- '' ,
42
- ['currentCustomer ' => $ this ->currentCustomer ]
43
- );
35
+ $ this ->layout = Bootstrap::getObjectManager ()->get (\Magento \Framework \View \LayoutInterface::class);
36
+ $ this ->layout ->setBlock ('head ' , $ blockMock );
44
37
}
45
38
46
39
protected function tearDown ()
@@ -52,11 +45,17 @@ protected function tearDown()
52
45
$ customerRegistry ->remove (1 );
53
46
}
54
47
48
+ /**
49
+ * @magentoDataFixture Magento/Customer/_files/customer.php
50
+ * @magentoAppIsolation enabled
51
+ */
55
52
public function testGetAddressEditUrl ()
56
53
{
54
+ $ bookBlock = $ this ->createBlockForCustomer (1 );
55
+
57
56
$ this ->assertEquals (
58
57
'http://localhost/index.php/customer/address/edit/id/1/ ' ,
59
- $ this -> _block ->getAddressEditUrl (1 )
58
+ $ bookBlock ->getAddressEditUrl (1 )
60
59
);
61
60
}
62
61
@@ -65,137 +64,159 @@ public function testGetAddressEditUrl()
65
64
* @magentoDataFixture Magento/Customer/_files/customer_two_addresses.php
66
65
* @magentoDataFixture Magento/Customer/_files/customer_no_address.php
67
66
* @dataProvider hasPrimaryAddressDataProvider
67
+ * @param int $customerId
68
+ * @param bool $expected
69
+ * @magentoAppIsolation enabled
68
70
*/
69
71
public function testHasPrimaryAddress ($ customerId , $ expected )
70
72
{
71
- if (!empty ($ customerId )) {
72
- $ this ->currentCustomer ->setCustomerId ($ customerId );
73
- }
74
- $ this ->assertEquals ($ expected , $ this ->_block ->hasPrimaryAddress ());
73
+ $ bookBlock = $ this ->createBlockForCustomer ($ customerId );
74
+ $ this ->assertEquals ($ expected , $ bookBlock ->hasPrimaryAddress ());
75
75
}
76
76
77
77
public function hasPrimaryAddressDataProvider ()
78
78
{
79
- return ['0 ' => [ 0 , false ], ' 1 ' => [1 , true ], '5 ' => [5 , false ]];
79
+ return ['1 ' => [1 , true ], '5 ' => [5 , false ]];
80
80
}
81
81
82
82
/**
83
83
* @magentoDataFixture Magento/Customer/_files/customer.php
84
84
* @magentoDataFixture Magento/Customer/_files/customer_two_addresses.php
85
+ * @magentoAppIsolation enabled
85
86
*/
86
87
public function testGetAdditionalAddresses ()
87
88
{
88
- $ this ->currentCustomer -> setCustomerId (1 );
89
- $ this ->assertNotNull ($ this -> _block ->getAdditionalAddresses ());
90
- $ this ->assertCount (1 , $ this -> _block ->getAdditionalAddresses ());
89
+ $ bookBlock = $ this ->createBlockForCustomer (1 );
90
+ $ this ->assertNotNull ($ bookBlock ->getAdditionalAddresses ());
91
+ $ this ->assertCount (1 , $ bookBlock ->getAdditionalAddresses ());
91
92
$ this ->assertInstanceOf (
92
93
\Magento \Customer \Api \Data \AddressInterface::class,
93
- $ this -> _block ->getAdditionalAddresses ()[0 ]
94
+ $ bookBlock ->getAdditionalAddresses ()[0 ]
94
95
);
95
- $ this ->assertEquals (2 , $ this -> _block ->getAdditionalAddresses ()[0 ]->getId ());
96
+ $ this ->assertEquals (2 , $ bookBlock ->getAdditionalAddresses ()[0 ]->getId ());
96
97
}
97
98
98
99
/**
99
100
* @magentoDataFixture Magento/Customer/_files/customer_no_address.php
100
101
* @dataProvider getAdditionalAddressesDataProvider
102
+ * @magentoAppIsolation enabled
101
103
*/
102
104
public function testGetAdditionalAddressesNegative ($ customerId , $ expected )
103
105
{
104
- if (!empty ($ customerId )) {
105
- $ this ->currentCustomer ->setCustomerId ($ customerId );
106
- }
107
- $ this ->assertEquals ($ expected , $ this ->_block ->getAdditionalAddresses ());
106
+ $ bookBlock = $ this ->createBlockForCustomer ($ customerId );
107
+ $ this ->currentCustomer ->setCustomerId ($ customerId );
108
+ $ this ->assertEquals ($ expected , $ bookBlock ->getAdditionalAddresses ());
108
109
}
109
110
110
111
public function getAdditionalAddressesDataProvider ()
111
112
{
112
- return ['0 ' => [ 0 , false ], ' 5 ' => [5 , false ]];
113
+ return ['5 ' => [5 , false ]];
113
114
}
114
115
115
116
/**
116
117
* @magentoDataFixture Magento/Customer/_files/customer.php
117
118
* @magentoDataFixture Magento/Customer/_files/customer_address.php
119
+ * @magentoAppIsolation enabled
118
120
*/
119
121
public function testGetAddressHtml ()
120
122
{
123
+ $ bookBlock = $ this ->createBlockForCustomer (1 );
121
124
$ expected = "John Smith<br /> \nCompanyName<br /> \nGreen str, 67<br /> \n\n\n\nCityM, Alabama, 75477<br /> " .
122
125
"\nUnited States<br /> \nT: <a href= \"tel:3468676 \">3468676</a> \n\n" ;
123
126
$ address = Bootstrap::getObjectManager ()->get (
124
127
\Magento \Customer \Api \AddressRepositoryInterface::class
125
128
)->getById (1 );
126
- $ html = $ this -> _block ->getAddressHtml ($ address );
129
+ $ html = $ bookBlock ->getAddressHtml ($ address );
127
130
$ this ->assertEquals ($ expected , $ html );
128
131
}
129
132
133
+ /**
134
+ * @magentoDataFixture Magento/Customer/_files/customer_no_address.php
135
+ * @magentoAppIsolation enabled
136
+ */
130
137
public function testGetAddressHtmlWithoutAddress ()
131
138
{
132
- $ this ->assertEquals ('' , $ this ->_block ->getAddressHtml (null ));
139
+ $ bookBlock = $ this ->createBlockForCustomer (5 );
140
+ $ this ->assertEquals ('' , $ bookBlock ->getAddressHtml (null ));
133
141
}
134
142
135
143
/**
136
144
* @magentoDataFixture Magento/Customer/_files/customer.php
145
+ * @magentoAppIsolation enabled
137
146
*/
138
147
public function testGetCustomer ()
139
148
{
149
+ $ bookBlock = $ this ->createBlockForCustomer (1 );
140
150
/** @var CustomerRepositoryInterface $customerRepository */
141
151
$ customerRepository = Bootstrap::getObjectManager ()->get (
142
152
\Magento \Customer \Api \CustomerRepositoryInterface::class
143
153
);
144
154
$ customer = $ customerRepository ->getById (1 );
145
-
146
- $ this ->currentCustomer ->setCustomerId (1 );
147
- $ object = $ this ->_block ->getCustomer ();
155
+ $ object = $ bookBlock ->getCustomer ();
148
156
$ this ->assertEquals ($ customer , $ object );
149
157
}
150
158
151
- public function testGetCustomerMissingCustomer ()
152
- {
153
- $ this ->assertNull ($ this ->_block ->getCustomer ());
154
- }
155
-
156
159
/**
157
160
* @magentoDataFixture Magento/Customer/_files/customer.php
158
161
* @magentoDataFixture Magento/Customer/_files/customer_two_addresses.php
159
162
* @magentoDataFixture Magento/Customer/_files/customer_no_address.php
160
163
* @dataProvider getDefaultBillingDataProvider
164
+ * @magentoAppIsolation enabled
161
165
*/
162
166
public function testGetDefaultBilling ($ customerId , $ expected )
163
167
{
164
- $ this ->currentCustomer -> setCustomerId ($ customerId );
165
- $ this ->assertEquals ($ expected , $ this -> _block ->getDefaultBilling ());
168
+ $ bookBlock = $ this ->createBlockForCustomer ($ customerId );
169
+ $ this ->assertEquals ($ expected , $ bookBlock ->getDefaultBilling ());
166
170
}
167
171
168
172
public function getDefaultBillingDataProvider ()
169
173
{
170
- return ['0 ' => [ 0 , null ], ' 1 ' => [1 , 1 ], '5 ' => [5 , null ]];
174
+ return ['1 ' => [1 , 1 ], '5 ' => [5 , null ]];
171
175
}
172
176
173
177
/**
174
178
* @magentoDataFixture Magento/Customer/_files/customer.php
175
179
* @magentoDataFixture Magento/Customer/_files/customer_two_addresses.php
176
180
* @magentoDataFixture Magento/Customer/_files/customer_no_address.php
177
181
* @dataProvider getDefaultShippingDataProvider
182
+ * @magentoAppIsolation enabled
178
183
*/
179
184
public function testGetDefaultShipping ($ customerId , $ expected )
180
185
{
181
- if (!empty ($ customerId )) {
182
- $ this ->currentCustomer ->setCustomerId ($ customerId );
183
- }
184
- $ this ->assertEquals ($ expected , $ this ->_block ->getDefaultShipping ());
186
+ $ bookBlock = $ this ->createBlockForCustomer ($ customerId );
187
+ $ this ->currentCustomer ->setCustomerId ($ customerId );
188
+ $ this ->assertEquals ($ expected , $ bookBlock ->getDefaultShipping ());
185
189
}
186
190
187
191
public function getDefaultShippingDataProvider ()
188
192
{
189
- return ['0 ' => [ 0 , null ], ' 1 ' => [1 , 1 ], '5 ' => [5 , null ]];
193
+ return ['1 ' => [1 , 1 ], '5 ' => [5 , null ]];
190
194
}
191
195
192
196
/**
193
197
* @magentoDataFixture Magento/Customer/_files/customer.php
194
198
* @magentoDataFixture Magento/Customer/_files/customer_two_addresses.php
199
+ * @magentoAppIsolation enabled
195
200
*/
196
201
public function testGetAddressById ()
197
202
{
198
- $ this ->assertInstanceOf (\Magento \Customer \Api \Data \AddressInterface::class, $ this ->_block ->getAddressById (1 ));
199
- $ this ->assertNull ($ this ->_block ->getAddressById (5 ));
203
+ $ bookBlock = $ this ->createBlockForCustomer (1 );
204
+ $ this ->assertInstanceOf (\Magento \Customer \Api \Data \AddressInterface::class, $ bookBlock ->getAddressById (1 ));
205
+ }
206
+
207
+ /**
208
+ * Create address book block for customer
209
+ *
210
+ * @param int $customerId
211
+ * @return \Magento\Framework\View\Element\BlockInterface
212
+ */
213
+ private function createBlockForCustomer ($ customerId )
214
+ {
215
+ $ this ->currentCustomer ->setCustomerId ($ customerId );
216
+ return $ this ->layout ->createBlock (
217
+ \Magento \Customer \Block \Address \Book::class,
218
+ '' ,
219
+ ['currentCustomer ' => $ this ->currentCustomer ]
220
+ );
200
221
}
201
222
}
0 commit comments