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
@@ -25,40 +23,32 @@ class GetAvailableShippingMethodsTest extends GraphQlAbstract
25
23
private $ customerTokenService ;
26
24
27
25
/**
28
- * @var QuoteIdToMaskedQuoteIdInterface
26
+ * @var GetMaskedQuoteIdByReservedOrderId
29
27
*/
30
- private $ quoteIdToMaskedId ;
31
-
32
- /**
33
- * @var QuoteFactory
34
- */
35
- private $ quoteFactory ;
36
-
37
- /**
38
- * @var QuoteResource
39
- */
40
- private $ quoteResource ;
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 ->quoteFactory = $ objectManager ->get (QuoteFactory::class);
49
- $ this ->quoteResource = $ objectManager ->get (QuoteResource::class);
36
+ $ this ->getMaskedQuoteIdByReservedOrderId = $ objectManager ->get (GetMaskedQuoteIdByReservedOrderId::class);
50
37
$ this ->customerTokenService = $ objectManager ->get (CustomerTokenServiceInterface::class);
51
- $ this ->quoteIdToMaskedId = $ objectManager ->get (QuoteIdToMaskedQuoteIdInterface::class);
52
38
}
53
39
54
40
/**
55
41
* Test case: get available shipping methods from current customer quote
56
42
*
57
- * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php
43
+ * @magentoApiDataFixture Magento/Customer/_files/customer.php
44
+ * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
45
+ * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
46
+ * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
47
+ * @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
58
48
*/
59
49
public function testGetAvailableShippingMethods ()
60
50
{
61
- $ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId ( ' test_order_1 ' );
51
+ $ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId -> execute ( ' test_quote ' );
62
52
$ response = $ this ->graphQlQuery ($ this ->getQuery ($ maskedQuoteId ), [], '' , $ this ->getHeaderMap ());
63
53
64
54
self ::assertArrayHasKey ('cart ' , $ response );
@@ -84,40 +74,62 @@ public function testGetAvailableShippingMethods()
84
74
);
85
75
}
86
76
77
+ /**
78
+ * _security
79
+ * @magentoApiDataFixture Magento/Customer/_files/customer.php
80
+ * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
81
+ * @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
82
+ * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
83
+ * @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
84
+ */
85
+ public function testGetAvailableShippingMethodsFromGuestCart ()
86
+ {
87
+ $ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId ->execute ('test_quote ' );
88
+ $ query = $ this ->getQuery ($ maskedQuoteId );
89
+
90
+ $ this ->expectExceptionMessage (
91
+ "The current user cannot perform operations on cart \"$ maskedQuoteId \""
92
+ );
93
+ $ this ->graphQlQuery ($ query , [], '' , $ this ->getHeaderMap ());
94
+ }
95
+
87
96
/**
88
97
* Test case: get available shipping methods from quote of another customer
89
98
*
99
+ * _security
90
100
* @magentoApiDataFixture Magento/Customer/_files/three_customers.php
91
- * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php
101
+ * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
102
+ * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
103
+ * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
104
+ * @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
92
105
*/
93
106
public function testGetAvailableShippingMethodsFromAnotherCustomerCart ()
94
107
{
95
- $ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId ('test_order_1 ' );
108
+ $ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId ->execute ('test_quote ' );
109
+ $ query = $ this ->getQuery ($ maskedQuoteId );
96
110
97
111
$ this ->expectExceptionMessage (
98
112
"The current user cannot perform operations on cart \"$ maskedQuoteId \""
99
113
);
100
-
101
- $ this ->graphQlQuery (
102
- $ this ->getQuery ($ maskedQuoteId ),
103
- [],
104
- '' ,
105
- $ this ->getHeaderMap ('customer2@search.example.com ' )
106
- );
114
+ $ this ->graphQlQuery ($ query , [], '' , $ this ->getHeaderMap ('customer3@search.example.com ' ));
107
115
}
108
116
109
117
/**
110
118
* Test case: get available shipping methods when all shipping methods are disabled
111
119
*
112
- * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php
113
- * @magentoApiDataFixture Magento/OfflineShipping/_files/disable_offline_shipping_methods.php
120
+ * @magentoApiDataFixture Magento/Customer/_files/customer.php
121
+ * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
122
+ * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
123
+ * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
124
+ * @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
125
+ * @magentoApiDataFixture Magento/GraphQl/Quote/_files/disable_offline_shipping_methods.php
114
126
*/
115
- public function testGetAvailableShippingMethodsIfAllShippingsAreDisabled ()
127
+ public function testGetAvailableShippingMethodsIfShippingMethodsAreNotPresent ()
116
128
{
117
- $ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId ( ' test_order_1 ' );
129
+ $ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId -> execute ( ' test_quote ' );
118
130
$ response = $ this ->graphQlQuery ($ this ->getQuery ($ maskedQuoteId ), [], '' , $ this ->getHeaderMap ());
119
131
120
- self ::assertEquals ( 0 , count ( $ response ['cart ' ]['shipping_addresses ' ][0 ]['available_shipping_methods ' ]) );
132
+ self ::assertEmpty ( $ response ['cart ' ]['shipping_addresses ' ][0 ]['available_shipping_methods ' ]);
121
133
}
122
134
123
135
/**
@@ -173,16 +185,4 @@ private function getHeaderMap(string $username = 'customer@example.com', string
173
185
$ headerMap = ['Authorization ' => 'Bearer ' . $ customerToken ];
174
186
return $ headerMap ;
175
187
}
176
-
177
- /**
178
- * @param string $reservedOrderId
179
- * @return string
180
- */
181
- private function getMaskedQuoteIdByReservedOrderId (string $ reservedOrderId ): string
182
- {
183
- $ quote = $ this ->quoteFactory ->create ();
184
- $ this ->quoteResource ->load ($ quote , $ reservedOrderId , 'reserved_order_id ' );
185
-
186
- return $ this ->quoteIdToMaskedId ->execute ((int )$ quote ->getId ());
187
- }
188
188
}
0 commit comments