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,75 +23,71 @@ class GetAvailablePaymentMethodsTest extends GraphQlAbstract
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
- * @magentoApiDataFixture Magento/Checkout/_files/quote_with_items_saved.php
41
+ * @magentoApiDataFixture Magento/Customer/_files/customer.php
42
+ * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
43
+ * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
44
+ * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
45
+ * @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
56
46
*/
57
- public function testGetCartWithPaymentMethods ()
47
+ public function testGetAvailablePaymentMethods ()
58
48
{
59
- $ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId ( ' test_order_item_with_items ' );
49
+ $ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId -> execute ( ' test_quote ' );
60
50
$ query = $ this ->getQuery ($ maskedQuoteId );
61
51
$ response = $ this ->graphQlQuery ($ query , [], '' , $ this ->getHeaderMap ());
62
52
63
53
self ::assertArrayHasKey ('cart ' , $ response );
54
+ self ::assertArrayHasKey ('available_payment_methods ' , $ response ['cart ' ]);
55
+ self ::assertCount (1 , $ response ['cart ' ]['available_payment_methods ' ]);
56
+
64
57
self ::assertEquals ('checkmo ' , $ response ['cart ' ]['available_payment_methods ' ][0 ]['code ' ]);
65
58
self ::assertEquals ('Check / Money order ' , $ response ['cart ' ]['available_payment_methods ' ][0 ]['title ' ]);
66
- self ::assertGreaterThan (
67
- 0 ,
68
- count ($ response ['cart ' ]['available_payment_methods ' ]),
69
- 'There are no available payment methods for customer cart! '
70
- );
71
59
}
72
60
73
61
/**
62
+ * @security
74
63
* @magentoApiDataFixture Magento/Customer/_files/customer.php
75
- * @magentoApiDataFixture Magento/Checkout/_files/quote_with_virtual_product_saved.php
64
+ * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
65
+ * @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
66
+ * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
67
+ * @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
76
68
*/
77
- public function testGetPaymentMethodsFromGuestCart ()
69
+ public function testGetAvailablePaymentMethodsFromGuestCart ()
78
70
{
79
- $ guestQuoteMaskedId = $ this ->getMaskedQuoteIdByReservedOrderId (
80
- 'test_order_with_virtual_product_without_address '
81
- );
82
- $ query = $ this ->getQuery ($ guestQuoteMaskedId );
71
+ $ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId ->execute ('test_quote ' );
72
+ $ query = $ this ->getQuery ($ maskedQuoteId );
83
73
84
74
$ this ->expectExceptionMessage (
85
- "The current user cannot perform operations on cart \"$ guestQuoteMaskedId \""
75
+ "The current user cannot perform operations on cart \"$ maskedQuoteId \""
86
76
);
87
77
$ this ->graphQlQuery ($ query , [], '' , $ this ->getHeaderMap ());
88
78
}
89
79
90
80
/**
81
+ * @security
91
82
* @magentoApiDataFixture Magento/Customer/_files/three_customers.php
92
- * @magentoApiDataFixture Magento/Checkout/_files/quote_with_items_saved.php
83
+ * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
84
+ * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
85
+ * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
86
+ * @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
93
87
*/
94
- public function testGetPaymentMethodsFromAnotherCustomerCart ()
88
+ public function testGetAvailablePaymentMethodsFromAnotherCustomerCart ()
95
89
{
96
- $ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId ( ' test_order_item_with_items ' );
90
+ $ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId -> execute ( ' test_quote ' );
97
91
$ query = $ this ->getQuery ($ maskedQuoteId );
98
92
99
93
$ this ->expectExceptionMessage (
@@ -103,24 +97,31 @@ public function testGetPaymentMethodsFromAnotherCustomerCart()
103
97
}
104
98
105
99
/**
106
- * @magentoApiDataFixture Magento/Checkout/_files/quote_with_items_saved.php
107
- * @magentoApiDataFixture Magento/Payment/_files/disable_all_active_payment_methods.php
100
+ * @magentoApiDataFixture Magento/Customer/_files/customer.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
105
+ * @magentoApiDataFixture Magento/GraphQl/Quote/_files/disable_all_active_payment_methods.php
108
106
*/
109
- public function testGetPaymentMethodsIfPaymentsAreNotSet ()
107
+ public function testGetAvailablePaymentMethodsIfPaymentsAreNotPresent ()
110
108
{
111
- $ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId ( ' test_order_item_with_items ' );
109
+ $ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId -> execute ( ' test_quote ' );
112
110
$ query = $ this ->getQuery ($ maskedQuoteId );
113
111
$ response = $ this ->graphQlQuery ($ query , [], '' , $ this ->getHeaderMap ());
114
112
115
- self ::assertEquals (0 , count ($ response ['cart ' ]['available_payment_methods ' ]));
113
+ self ::assertArrayHasKey ('cart ' , $ response );
114
+ self ::assertArrayHasKey ('available_payment_methods ' , $ response ['cart ' ]);
115
+ self ::assertEmpty ($ response ['cart ' ]['available_payment_methods ' ]);
116
116
}
117
117
118
118
/**
119
119
* @magentoApiDataFixture Magento/Customer/_files/customer.php
120
+ *
120
121
* @expectedException \Exception
121
122
* @expectedExceptionMessage Could not find a cart with ID "non_existent_masked_id"
122
123
*/
123
- public function testGetPaymentMethodsOfNonExistentCart ()
124
+ public function testGetAvailablePaymentMethodsOfNonExistentCart ()
124
125
{
125
126
$ maskedQuoteId = 'non_existent_masked_id ' ;
126
127
$ query = $ this ->getQuery ($ maskedQuoteId );
@@ -132,9 +133,8 @@ public function testGetPaymentMethodsOfNonExistentCart()
132
133
* @param string $maskedQuoteId
133
134
* @return string
134
135
*/
135
- private function getQuery (
136
- string $ maskedQuoteId
137
- ): string {
136
+ private function getQuery (string $ maskedQuoteId ): string
137
+ {
138
138
return <<<QUERY
139
139
{
140
140
cart(cart_id: " $ maskedQuoteId") {
@@ -158,16 +158,4 @@ private function getHeaderMap(string $username = '
[email protected] ', string
158
158
$ headerMap = ['Authorization ' => 'Bearer ' . $ customerToken ];
159
159
return $ headerMap ;
160
160
}
161
-
162
- /**
163
- * @param string $reservedOrderId
164
- * @return string
165
- */
166
- private function getMaskedQuoteIdByReservedOrderId (string $ reservedOrderId ): string
167
- {
168
- $ quote = $ this ->quoteFactory ->create ();
169
- $ this ->quoteResource ->load ($ quote , $ reservedOrderId , 'reserved_order_id ' );
170
-
171
- return $ this ->quoteIdToMaskedId ->execute ((int )$ quote ->getId ());
172
- }
173
161
}
0 commit comments