6
6
7
7
namespace Magento \GraphQl \Customer ;
8
8
9
+ use Magento \Customer \Api \AddressRepositoryInterface ;
9
10
use Magento \Customer \Api \CustomerRepositoryInterface ;
11
+ use Magento \Customer \Api \Data \AddressInterface ;
10
12
use Magento \Customer \Api \Data \CustomerInterface ;
11
13
use Magento \TestFramework \ObjectManager ;
12
14
use Magento \TestFramework \TestCase \GraphQlAbstract ;
@@ -18,6 +20,7 @@ class CustomerAuthenticationTest extends GraphQlAbstract
18
20
* Verify customers with valid credentials with a customer bearer token
19
21
*
20
22
* @magentoApiDataFixture Magento/Customer/_files/customer.php
23
+ * @magentoApiDataFixture Magento/Customer/_files/customer_two_addresses.php
21
24
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
22
25
*/
23
26
@@ -28,12 +31,28 @@ public function testRegisteredCustomerWithValidCredentials()
28
31
{
29
32
customer
30
33
{
31
- id
32
- website_id
33
- store_id
34
+ created_at
35
+ group_id
36
+ prefix
37
+ firstname
38
+ middlename
34
39
lastname
40
+ suffix
41
+ email
35
42
default_billing
36
- default_shipping
43
+ default_shipping
44
+ id
45
+ addresses{
46
+ id
47
+ customer_id
48
+ region_id
49
+ country_id
50
+ telephone
51
+ postcode
52
+ city
53
+ firstname
54
+ lastname
55
+ }
37
56
}
38
57
}
39
58
QUERY ;
@@ -49,9 +68,16 @@ public function testRegisteredCustomerWithValidCredentials()
49
68
/** @var CustomerRepositoryInterface $customerRepository */
50
69
$ customerRepository = ObjectManager::getInstance ()->get (CustomerRepositoryInterface::class);
51
70
$ customer =
$ customerRepository->
get (
'[email protected] ' );
71
+
52
72
$ response = $ this ->graphQlQuery ($ query );
53
73
$ this ->assertArrayHasKey ('customer ' , $ response );
74
+ $ this ->assertArrayHasKey ('addresses ' , $ response ['customer ' ]);
75
+ $ this ->assertTrue (
76
+ is_array ([$ response ['customer ' ]['addresses ' ]]),
77
+ " Addresses field must be of an array type. "
78
+ );
54
79
$ this ->assertCustomerFields ($ customer , $ response ['customer ' ]);
80
+ $ this ->assertCustomerAddressesFields ($ customer , $ response );
55
81
}
56
82
57
83
/**
@@ -87,12 +113,17 @@ public function testCustomerWithValidCredentialsWithoutToken()
87
113
{
88
114
customer
89
115
{
90
- id
91
- website_id
92
- store_id
116
+ created_at
117
+ group_id
118
+ prefix
119
+ firstname
120
+ middlename
93
121
lastname
122
+ suffix
123
+ email
94
124
default_billing
95
- default_shipping
125
+ default_shipping
126
+ id
96
127
}
97
128
}
98
129
QUERY ;
@@ -115,16 +146,54 @@ public function assertCustomerFields($customer, $actualResponse)
115
146
*/
116
147
$ assertionMap = [
117
148
['response_field ' => 'id ' , 'expected_value ' => $ customer ->getId ()],
118
- ['response_field ' => 'website_id ' , 'expected_value ' => $ customer ->getWebsiteId ()],
119
- ['response_field ' => 'store_id ' , 'expected_value ' => $ customer ->getStoreId ()],
149
+ ['response_field ' => 'created_at ' , 'expected_value ' => $ customer ->getCreatedAt ()],
150
+ ['response_field ' => 'group_id ' , 'expected_value ' => $ customer ->getGroupId ()],
151
+ ['response_field ' => 'prefix ' , 'expected_value ' => $ customer ->getPrefix ()],
152
+ ['response_field ' => 'firstname ' , 'expected_value ' => $ customer ->getFirstname ()],
153
+ ['response_field ' => 'middlename ' , 'expected_value ' => $ customer ->getMiddlename ()],
120
154
['response_field ' => 'lastname ' , 'expected_value ' => $ customer ->getLastname ()],
121
- ['response_field ' => 'default_shipping ' , 'expected_value ' => $ customer ->getDefaultShipping ()],
122
- ['response_field ' => 'default_billing ' , 'expected_value ' => $ customer ->getDefaultBilling ()]
155
+ ['response_field ' => 'suffix ' , 'expected_value ' => $ customer ->getSuffix ()],
156
+ ['response_field ' => 'email ' , 'expected_value ' => $ customer ->getEmail ()],
157
+ ['response_field ' => 'default_shipping ' , 'expected_value ' => (bool )$ customer ->getDefaultShipping ()],
158
+ ['response_field ' => 'default_billing ' , 'expected_value ' => (bool )$ customer ->getDefaultBilling ()],
159
+ ['response_field ' => 'id ' , 'expected_value ' => $ customer ->getId ()]
123
160
];
124
161
125
162
$ this ->assertResponseFields ($ actualResponse , $ assertionMap );
126
163
}
127
164
165
+ /**
166
+ * @param CustomerInterface $customer
167
+ * @param array $actualResponse
168
+ */
169
+
170
+ public function assertCustomerAddressesFields ($ customer , $ actualResponse )
171
+ {
172
+ /** @var AddressInterface $addresses */
173
+ $ addresses = $ customer ->getAddresses ();
174
+
175
+ foreach ( $ addresses as $ addressKey => $ addressValue ) {
176
+ $ this ->assertNotEmpty ($ addressValue );
177
+ $ assertionMap = [
178
+ ['response_field ' => 'id ' , 'expected_value ' => $ addresses [$ addressKey ]->getId ()],
179
+ ['response_field ' => 'customer_id ' , 'expected_value ' => $ addresses [$ addressKey ]->getCustomerId ()],
180
+ ['response_field ' => 'region_id ' , 'expected_value ' => $ addresses [$ addressKey ]->getRegionId ()],
181
+ ['response_field ' => 'country_id ' , 'expected_value ' => $ addresses [$ addressKey ]->getCountryId ()],
182
+ ['response_field ' => 'telephone ' , 'expected_value ' => $ addresses [$ addressKey ]->getTelephone ()],
183
+ ['response_field ' => 'postcode ' , 'expected_value ' => $ addresses [$ addressKey ]->getPostcode ()],
184
+ ['response_field ' => 'city ' , 'expected_value ' => $ addresses [$ addressKey ]->getCity ()],
185
+ ['response_field ' => 'firstname ' , 'expected_value ' => $ addresses [$ addressKey ]->getFirstname ()],
186
+ ['response_field ' => 'lastname ' , 'expected_value ' => $ addresses [$ addressKey ]->getLastname ()]
187
+ ];
188
+ $ this ->assertResponseFields ($ actualResponse ['customer ' ]['addresses ' ][$ addressKey ], $ assertionMap );
189
+ }
190
+
191
+ // $addressId = $actualResponse['customer']['addresses']['id'][0];
192
+ // $addressRepository = ObjectManager::getInstance()->get(\Magento\Customer\Api\AddressRepositoryInterface::class);
193
+ // $customerAddress = $addressRepository->getById(1);
194
+ }
195
+
196
+
128
197
/**
129
198
* @param array $actualResponse
130
199
* @param array $assertionMap ['response_field_name' => 'response_field_value', ...]
0 commit comments