@@ -105,18 +105,26 @@ protected function setUp(): void
105
105
],
106
106
as: 'customer '
107
107
),
108
- DataFixture(CustomerCart::class, ['customer_id ' => '$customer.id$ ' , 'store_id ' => '$store2.id$ ' ], as: 'quote ' ),
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 ' )
108
+ DataFixture(CustomerCart::class, ['customer_id ' => '$customer.id$ ' , 'store_id ' => '$store2.id$ ' ], as: 'quote1 ' ),
109
+ DataFixture(AddProductToCart::class, ['cart_id ' => '$quote1.id$ ' , 'product_id ' => '$product.id$ ' , 'qty ' => 1 ]),
110
+ DataFixture(SetBillingAddress::class, ['cart_id ' => '$quote1.id$ ' ]),
111
+ DataFixture(SetShippingAddress::class, ['cart_id ' => '$quote1.id$ ' ]),
112
+ DataFixture(SetDeliveryMethodFixture::class, ['cart_id ' => '$quote1.id$ ' ]),
113
+ DataFixture(SetPaymentMethodFixture::class, ['cart_id ' => '$quote1.id$ ' ]),
114
+ DataFixture(PlaceOrderFixture::class, ['cart_id ' => '$quote1.id$ ' ], 'order1 ' ),
115
+ DataFixture(CustomerCart::class, ['customer_id ' => '$customer.id$ ' , 'store_id ' => '$store3.id$ ' ], as: 'quote2 ' ),
116
+ DataFixture(AddProductToCart::class, ['cart_id ' => '$quote2.id$ ' , 'product_id ' => '$product.id$ ' , 'qty ' => 1 ]),
117
+ DataFixture(SetBillingAddress::class, ['cart_id ' => '$quote2.id$ ' ]),
118
+ DataFixture(SetShippingAddress::class, ['cart_id ' => '$quote2.id$ ' ]),
119
+ DataFixture(SetDeliveryMethodFixture::class, ['cart_id ' => '$quote2.id$ ' ]),
120
+ DataFixture(SetPaymentMethodFixture::class, ['cart_id ' => '$quote2.id$ ' ]),
121
+ DataFixture(PlaceOrderFixture::class, ['cart_id ' => '$quote2.id$ ' ], 'order2 ' )
115
122
]
116
123
public function testGetCustomerOrders ()
117
124
{
118
125
$ fixtures = DataFixtureStorageManager::getStorage ();
119
126
$ store2 = $ fixtures ->get ('store2 ' );
127
+ $ store3 = $ fixtures ->get ('store3 ' );
120
128
$ customer = $ fixtures ->get ('customer ' );
121
129
$ currentEmail = $ customer ->getEmail ();
122
130
$ currentPassword = 'password ' ;
@@ -130,12 +138,60 @@ public function testGetCustomerOrders()
130
138
);
131
139
$ customerToken = $ tokenResponse ['body ' ]['generateCustomerToken ' ]['token ' ];
132
140
141
+ $ query = $ this ->getCustomerOrdersQuery ('STORE ' );
142
+ $ response = $ this ->graphQlQuery (
143
+ $ query ,
144
+ [],
145
+ '' ,
146
+ $ this ->getCustomerHeaders ($ customerToken , $ store2 ->getCode ())
147
+ );
148
+
149
+ $ this ->assertNotNull ($ response ['customer ' ]['orders ' ]);
150
+
151
+ $ response = $ this ->graphQlQuery (
152
+ $ query ,
153
+ [],
154
+ '' ,
155
+ $ this ->getCustomerHeaders ($ customerToken , $ store3 ->getCode ())
156
+ );
157
+
158
+ $ this ->assertNotNull ($ response ['customer ' ]['orders ' ]);
159
+
160
+ $ query = $ this ->getCustomerOrdersQuery ();
161
+ $ response = $ this ->graphQlQuery (
162
+ $ query ,
163
+ [],
164
+ '' ,
165
+ $ this ->getCustomerHeaders ($ customerToken , null )
166
+ );
167
+
168
+ $ this ->assertNotNull ($ response ['customer ' ]['orders ' ]);
169
+ }
170
+
171
+ /**
172
+ * @param string $token
173
+ * @param string|null $storeCode
174
+ *
175
+ * @return array
176
+ */
177
+ private function getCustomerHeaders (string $ token , ?string $ storeCode ): array
178
+ {
179
+ return ['Authorization ' => 'Bearer ' . $ token , 'Store ' => $ storeCode ?? 'default ' ];
180
+ }
181
+
182
+ /**
183
+ * @param string|null $scope
184
+ *
185
+ * @return array|string
186
+ */
187
+ private function getCustomerOrdersQuery (?string $ scope = null ): array |string
188
+ {
133
189
$ query = <<<QUERY
134
190
query {
135
191
customer {
136
192
orders(
137
193
pageSize: 20,
138
- scope: STORE
194
+ {{ scope}}
139
195
) {
140
196
items {
141
197
id
@@ -150,28 +206,8 @@ public function testGetCustomerOrders()
150
206
}
151
207
}
152
208
QUERY ;
153
- $ response = $ this ->graphQlQuery (
154
- $ query ,
155
- [],
156
- '' ,
157
- $ this ->getCustomerHeaders ($ customerToken , $ store2 ->getCode ())
158
- );
159
-
160
- $ this ->assertNotNull ($ response ['customer ' ]['orders ' ]);
161
- $ this ->assertEquals ('John ' , $ response ['customer ' ]['firstname ' ]);
162
- $ this ->assertEquals ('Smith ' , $ response ['customer ' ]['lastname ' ]);
163
- $ this ->assertEquals ($ currentEmail , $ response ['customer ' ]['email ' ]);
164
- }
165
-
166
- /**
167
- * @param string $token
168
- * @param string $storeCode
169
- *
170
- * @return array
171
- */
172
- private function getCustomerHeaders (string $ token , string $ storeCode ): array
173
- {
174
- return ['Authorization ' => 'Bearer ' . $ token , 'Store ' => $ storeCode ];
209
+ $ query = str_replace ("{{scope}} " , isset ($ scope ) ? "scope: $ scope " : '' , $ query );
210
+ return $ query ;
175
211
}
176
212
177
213
/**
0 commit comments