7
7
8
8
namespace Magento \GraphQl \Quote \Customer ;
9
9
10
+ use Magento \GraphQl \Quote \GetMaskedQuoteIdByReservedOrderId ;
10
11
use Magento \Integration \Api \CustomerTokenServiceInterface ;
11
- use Magento \Quote \Model \QuoteFactory ;
12
- use Magento \Quote \Model \QuoteIdToMaskedQuoteIdInterface ;
13
- use Magento \Quote \Model \ResourceModel \Quote as QuoteResource ;
14
12
use Magento \TestFramework \Helper \Bootstrap ;
15
13
use Magento \TestFramework \TestCase \GraphQlAbstract ;
16
14
17
15
/**
18
- * Test for get billing address
16
+ * Test for get specified billing address
19
17
*/
20
- class GetBillingAddressTest extends GraphQlAbstract
18
+ class GetSpecifiedBillingAddressTest extends GraphQlAbstract
21
19
{
22
20
/**
23
21
* @var CustomerTokenServiceInterface
24
22
*/
25
23
private $ customerTokenService ;
26
24
27
25
/**
28
- * @var QuoteResource
26
+ * @var GetMaskedQuoteIdByReservedOrderId
29
27
*/
30
- private $ quoteResource ;
31
-
32
- /**
33
- * @var QuoteFactory
34
- */
35
- private $ quoteFactory ;
36
-
37
- /**
38
- * @var QuoteIdToMaskedQuoteIdInterface
39
- */
40
- private $ quoteIdToMaskedId ;
28
+ private $ getMaskedQuoteIdByReservedOrderId ;
41
29
42
30
/**
43
31
* @inheritdoc
44
32
*/
45
33
protected function setUp ()
46
34
{
47
35
$ objectManager = Bootstrap::getObjectManager ();
48
- $ this ->quoteResource = $ objectManager ->get (QuoteResource::class);
49
- $ this ->quoteFactory = $ objectManager ->get (QuoteFactory::class);
50
- $ this ->quoteIdToMaskedId = $ objectManager ->get (QuoteIdToMaskedQuoteIdInterface::class);
36
+ $ this ->getMaskedQuoteIdByReservedOrderId = $ objectManager ->get (GetMaskedQuoteIdByReservedOrderId::class);
51
37
$ this ->customerTokenService = $ objectManager ->get (CustomerTokenServiceInterface::class);
52
38
}
53
39
54
40
/**
55
41
* @magentoApiDataFixture Magento/Customer/_files/customer.php
56
- * @magentoApiDataFixture Magento/Catalog/_files/products .php
42
+ * @magentoApiDataFixture Magento/Catalog/_files/product_simple .php
57
43
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
58
44
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
59
- * @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
60
45
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_billing_address.php
61
46
*/
62
- public function testGetCartWithBillingAddress ()
47
+ public function testGeSpecifiedBillingAddress ()
63
48
{
64
- $ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId ('test_quote ' );
65
- $ query = $ this ->getGetBillingAddressQuery ($ maskedQuoteId );
49
+ $ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId ->execute ('test_quote ' );
50
+ $ query = $ this ->getQuery ($ maskedQuoteId );
51
+
66
52
$ response = $ this ->graphQlQuery ($ query , [], '' , $ this ->getHeaderMap ());
53
+ self ::assertArrayHasKey ('cart ' , $ response );
54
+ self ::assertArrayHasKey ('billing_address ' , $ response ['cart ' ]);
67
55
68
56
$ expectedBillingAddressData = [
69
57
'firstname ' => 'John ' ,
@@ -86,41 +74,23 @@ public function testGetCartWithBillingAddress()
86
74
'address_type ' => 'BILLING ' ,
87
75
'customer_notes ' => null ,
88
76
];
89
-
90
77
self ::assertEquals ($ expectedBillingAddressData , $ response ['cart ' ]['billing_address ' ]);
91
78
}
92
79
93
- /**
94
- * @magentoApiDataFixture Magento/Customer/_files/three_customers.php
95
- * @magentoApiDataFixture Magento/Catalog/_files/products.php
96
- * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
97
- * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
98
- */
99
- public function testGetBillingAddressFromAnotherCustomerCart ()
100
- {
101
- $ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId ('test_quote ' );
102
- $ this ->expectExceptionMessage (
103
- "The current user cannot perform operations on cart \"$ maskedQuoteId \""
104
- );
105
- $ this ->graphQlQuery (
106
- $ this ->getGetBillingAddressQuery ($ maskedQuoteId ),
107
- [],
108
- '' ,
109
- $ this ->getHeaderMap ('customer2@search.example.com ' )
110
- );
111
- }
112
-
113
80
/**
114
81
* @magentoApiDataFixture Magento/Customer/_files/customer.php
115
- * @magentoApiDataFixture Magento/Catalog/_files/products .php
82
+ * @magentoApiDataFixture Magento/Catalog/_files/product_simple .php
116
83
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
117
84
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
118
85
*/
119
- public function testGetBillingAddressIfBillingAddressIsNotSet ()
86
+ public function testGeSpecifiedBillingAddressIfBillingAddressIsNotSet ()
120
87
{
121
- $ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId ('test_quote ' );
122
- $ query = $ this ->getGetBillingAddressQuery ($ maskedQuoteId );
88
+ $ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId ->execute ('test_quote ' );
89
+ $ query = $ this ->getQuery ($ maskedQuoteId );
90
+
123
91
$ response = $ this ->graphQlQuery ($ query , [], '' , $ this ->getHeaderMap ());
92
+ self ::assertArrayHasKey ('cart ' , $ response );
93
+ self ::assertArrayHasKey ('billing_address ' , $ response ['cart ' ]);
124
94
125
95
$ expectedBillingAddressData = [
126
96
'firstname ' => null ,
@@ -143,7 +113,6 @@ public function testGetBillingAddressIfBillingAddressIsNotSet()
143
113
'address_type ' => 'BILLING ' ,
144
114
'customer_notes ' => null ,
145
115
];
146
-
147
116
self ::assertEquals ($ expectedBillingAddressData , $ response ['cart ' ]['billing_address ' ]);
148
117
}
149
118
@@ -152,21 +121,60 @@ public function testGetBillingAddressIfBillingAddressIsNotSet()
152
121
* @expectedException \Exception
153
122
* @expectedExceptionMessage Could not find a cart with ID "non_existent_masked_id"
154
123
*/
155
- public function testGetBillingAddressOfNonExistentCart ()
124
+ public function testGeSpecifiedBillingAddressOfNonExistentCart ()
156
125
{
157
126
$ maskedQuoteId = 'non_existent_masked_id ' ;
158
- $ query = $ this ->getGetBillingAddressQuery ($ maskedQuoteId );
127
+ $ query = $ this ->getQuery ($ maskedQuoteId );
159
128
160
129
$ this ->graphQlQuery ($ query , [], '' , $ this ->getHeaderMap ());
161
130
}
162
131
132
+ /**
133
+ * _security
134
+ * @magentoApiDataFixture Magento/Customer/_files/customer.php
135
+ * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
136
+ * @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
137
+ * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
138
+ * @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_billing_address.php
139
+ */
140
+ public function testGeSpecifiedBillingAddressFromAnotherGuestCart ()
141
+ {
142
+ $ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId ->execute ('test_quote ' );
143
+
144
+ $ this ->expectExceptionMessage (
145
+ "The current user cannot perform operations on cart \"$ maskedQuoteId \""
146
+ );
147
+ $ this ->graphQlQuery ($ this ->getQuery ($ maskedQuoteId ), [], '' , $ this ->getHeaderMap ());
148
+ }
149
+
150
+ /**
151
+ * _security
152
+ * @magentoApiDataFixture Magento/Customer/_files/three_customers.php
153
+ * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
154
+ * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
155
+ * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
156
+ * @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_billing_address.php
157
+ */
158
+ public function testGeSpecifiedBillingAddressFromAnotherCustomerCart ()
159
+ {
160
+ $ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId ->execute ('test_quote ' );
161
+
162
+ $ this ->expectExceptionMessage (
163
+ "The current user cannot perform operations on cart \"$ maskedQuoteId \""
164
+ );
165
+ $ this ->graphQlQuery ($ this ->getQuery ($ maskedQuoteId ),
166
+ [],
167
+ '' ,
168
+ $ this ->getHeaderMap ('customer2@search.example.com ' )
169
+ );
170
+ }
171
+
163
172
/**
164
173
* @param string $maskedQuoteId
165
174
* @return string
166
175
*/
167
- private function getGetBillingAddressQuery (
168
- string $ maskedQuoteId
169
- ): string {
176
+ private function getQuery (string $ maskedQuoteId ): string
177
+ {
170
178
return <<<QUERY
171
179
{
172
180
cart(cart_id: " $ maskedQuoteId") {
@@ -207,16 +215,4 @@ private function getHeaderMap(string $username = 'customer@example.com', string
207
215
$ headerMap = ['Authorization ' => 'Bearer ' . $ customerToken ];
208
216
return $ headerMap ;
209
217
}
210
-
211
- /**
212
- * @param string $reservedOrderId
213
- * @return string
214
- */
215
- private function getMaskedQuoteIdByReservedOrderId (string $ reservedOrderId ): string
216
- {
217
- $ quote = $ this ->quoteFactory ->create ();
218
- $ this ->quoteResource ->load ($ quote , $ reservedOrderId , 'reserved_order_id ' );
219
-
220
- return $ this ->quoteIdToMaskedId ->execute ((int )$ quote ->getId ());
221
- }
222
218
}
0 commit comments