9
9
10
10
use Magento \Catalog \Helper \Data ;
11
11
use Magento \Catalog \Test \Fixture \Product as ProductFixture ;
12
+ use Magento \Checkout \Test \Fixture \PlaceOrder as PlaceOrderFixture ;
13
+ use Magento \Checkout \Test \Fixture \SetBillingAddress ;
14
+ use Magento \Checkout \Test \Fixture \SetDeliveryMethod as SetDeliveryMethodFixture ;
15
+ use Magento \Checkout \Test \Fixture \SetPaymentMethod as SetPaymentMethodFixture ;
16
+ use Magento \Checkout \Test \Fixture \SetShippingAddress ;
12
17
use Magento \Customer \Api \CustomerRepositoryInterface ;
13
18
use Magento \Customer \Model \CustomerAuthUpdate ;
14
19
use Magento \Customer \Model \CustomerRegistry ;
15
20
use Magento \Customer \Test \Fixture \Customer ;
16
- use Magento \Framework \Exception \AuthenticationException ;
17
21
use Magento \Framework \ObjectManagerInterface ;
18
22
use Magento \Integration \Api \CustomerTokenServiceInterface ;
19
23
use Magento \Quote \Test \Fixture \AddProductToCart ;
@@ -102,13 +106,30 @@ protected function setUp(): void
102
106
as: 'customer '
103
107
),
104
108
DataFixture(CustomerCart::class, ['customer_id ' => '$customer.id$ ' , 'store_id ' => '$store2.id$ ' ], as: 'quote ' ),
105
- DataFixture(AddProductToCart::class, ['cart_id ' => '$quote.id$ ' , 'product_id ' => '$product.id$ ' , 'qty ' => 1 ])
109
+ DataFixture(AddProductToCart::class, ['cart_id ' => '$quote.id$ ' , 'product_id ' => '$product.id$ ' , 'qty ' => 1 ]),
110
+ DataFixture(SetBillingAddress::class, ['cart_id ' => '$quote.id$ ' ]),
111
+ DataFixture(SetShippingAddress::class, ['cart_id ' => '$quote.id$ ' ]),
112
+ DataFixture(SetDeliveryMethodFixture::class, ['cart_id ' => '$quote.id$ ' ]),
113
+ DataFixture(SetPaymentMethodFixture::class, ['cart_id ' => '$quote.id$ ' ]),
114
+ DataFixture(PlaceOrderFixture::class, ['cart_id ' => '$quote.id$ ' ], 'order ' )
106
115
]
107
116
public function testGetCustomerOrders ()
108
117
{
109
- $ currentEmail =
'[email protected] ' ;
118
+ $ fixtures = DataFixtureStorageManager::getStorage ();
119
+ $ store2 = $ fixtures ->get ('store2 ' );
120
+ $ customer = $ fixtures ->get ('customer ' );
121
+ $ currentEmail = $ customer ->getEmail ();
110
122
$ currentPassword = 'password ' ;
111
123
124
+ $ generateToken = $ this ->generateCustomerToken ($ currentEmail , $ currentPassword );
125
+ $ tokenResponse = $ this ->graphQlMutationWithResponseHeaders (
126
+ $ generateToken ,
127
+ [],
128
+ '' ,
129
+ ['Store ' => $ store2 ->getCode ()]
130
+ );
131
+ $ customerToken = $ tokenResponse ['body ' ]['generateCustomerToken ' ]['token ' ];
132
+
112
133
$ query = <<<QUERY
113
134
query {
114
135
customer {
@@ -127,13 +148,13 @@ public function testGetCustomerOrders()
127
148
}
128
149
}
129
150
}
130
- }
151
+ }
131
152
QUERY ;
132
153
$ response = $ this ->graphQlQuery (
133
154
$ query ,
134
155
[],
135
156
'' ,
136
- $ this ->getCustomerAuthHeaders ($ currentEmail , $ currentPassword )
157
+ $ this ->getCustomerAuthHeaders ($ customerToken )
137
158
);
138
159
139
160
$ this ->assertNull ($ response ['customer ' ]['id ' ]);
@@ -142,15 +163,32 @@ public function testGetCustomerOrders()
142
163
$ this ->assertEquals ($ currentEmail , $ response ['customer ' ]['email ' ]);
143
164
}
144
165
166
+ /**
167
+ * @param string $token
168
+ *
169
+ * @return array
170
+ */
171
+ private function getCustomerAuthHeaders (string $ token ): array
172
+ {
173
+ return ['Authorization ' => 'Bearer ' . $ token ];
174
+ }
175
+
145
176
/**
146
177
* @param string $email
147
178
* @param string $password
148
- * @return array
149
- * @throws AuthenticationException
179
+ * @return string
150
180
*/
151
- private function getCustomerAuthHeaders (string $ email , string $ password ): array
181
+ private function generateCustomerToken (string $ email , string $ password ) : string
152
182
{
153
- $ customerToken = $ this ->customerTokenService ->createCustomerAccessToken ($ email , $ password );
154
- return ['Authorization ' => 'Bearer ' . $ customerToken ];
183
+ return <<<MUTATION
184
+ mutation {
185
+ generateCustomerToken(
186
+ email: " {$ email }"
187
+ password: " {$ password }"
188
+ ) {
189
+ token
190
+ }
191
+ }
192
+ MUTATION ;
155
193
}
156
194
}
0 commit comments