@@ -56,9 +56,86 @@ protected function setUp()
56
56
*/
57
57
public function testGetCartWithPaymentMethods ()
58
58
{
59
- $ maskedQuoteId = $ this ->getMaskedQuoteIdByReversedQuoteId ('test_order_item_with_items ' );
59
+ $ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId ('test_order_item_with_items ' );
60
+ $ query = $ this ->getQuery ($ maskedQuoteId );
61
+ $ response = $ this ->graphQlQuery ($ query , [], '' , $ this ->getHeaderMap ());
62
+
63
+ self ::assertArrayHasKey ('cart ' , $ response );
64
+ self ::assertEquals ('checkmo ' , $ response ['cart ' ]['available_payment_methods ' ][0 ]['code ' ]);
65
+ 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
+ }
60
72
61
- $ query = <<<QUERY
73
+ /**
74
+ * @magentoApiDataFixture Magento/Customer/_files/customer.php
75
+ * @magentoApiDataFixture Magento/Checkout/_files/quote_with_virtual_product_saved.php
76
+ */
77
+ public function testGetPaymentMethodsFromGuestCart ()
78
+ {
79
+ $ guestQuoteMaskedId = $ this ->getMaskedQuoteIdByReservedOrderId (
80
+ 'test_order_with_virtual_product_without_address '
81
+ );
82
+ $ query = $ this ->getQuery ($ guestQuoteMaskedId );
83
+
84
+ $ this ->expectExceptionMessage (
85
+ "The current user cannot perform operations on cart \"$ guestQuoteMaskedId \""
86
+ );
87
+ $ this ->graphQlQuery ($ query , [], '' , $ this ->getHeaderMap ());
88
+ }
89
+
90
+ /**
91
+ * @magentoApiDataFixture Magento/Customer/_files/three_customers.php
92
+ * @magentoApiDataFixture Magento/Checkout/_files/quote_with_items_saved.php
93
+ */
94
+ public function testGetPaymentMethodsFromAnotherCustomerCart ()
95
+ {
96
+ $ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId ('test_order_item_with_items ' );
97
+ $ query = $ this ->getQuery ($ maskedQuoteId );
98
+
99
+ $ this ->expectExceptionMessage (
100
+ "The current user cannot perform operations on cart \"$ maskedQuoteId \""
101
+ );
102
+ $ this ->graphQlQuery ($ query , [], '' , $ this ->getHeaderMap ('customer3@search.example.com ' ));
103
+ }
104
+
105
+ /**
106
+ * @magentoApiDataFixture Magento/Checkout/_files/quote_with_items_saved.php
107
+ * @magentoApiDataFixture Magento/Payment/_files/disable_all_active_payment_methods.php
108
+ */
109
+ public function testGetPaymentMethodsIfPaymentsAreNotSet ()
110
+ {
111
+ $ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId ('test_order_item_with_items ' );
112
+ $ query = $ this ->getQuery ($ maskedQuoteId );
113
+ $ response = $ this ->graphQlQuery ($ query , [], '' , $ this ->getHeaderMap ());
114
+
115
+ self ::assertEquals (0 , count ($ response ['cart ' ]['available_payment_methods ' ]));
116
+ }
117
+
118
+ /**
119
+ * @magentoApiDataFixture Magento/Customer/_files/customer.php
120
+ * @expectedException \Exception
121
+ * @expectedExceptionMessage Could not find a cart with ID "non_existent_masked_id"
122
+ */
123
+ public function testGetPaymentMethodsOfNonExistentCart ()
124
+ {
125
+ $ maskedQuoteId = 'non_existent_masked_id ' ;
126
+ $ query = $ this ->getQuery ($ maskedQuoteId );
127
+
128
+ $ this ->graphQlQuery ($ query , [], '' , $ this ->getHeaderMap ());
129
+ }
130
+
131
+ /**
132
+ * @param string $maskedQuoteId
133
+ * @return string
134
+ */
135
+ private function getQuery (
136
+ string $ maskedQuoteId
137
+ ): string {
138
+ return <<<QUERY
62
139
{
63
140
cart(cart_id: " $ maskedQuoteId") {
64
141
available_payment_methods {
@@ -68,11 +145,6 @@ public function testGetCartWithPaymentMethods()
68
145
}
69
146
}
70
147
QUERY ;
71
- $ response = $ this ->graphQlQuery ($ query , [], '' , $ this ->getHeaderMap ());
72
-
73
- self ::assertArrayHasKey ('cart ' , $ response );
74
- self ::assertEquals ('checkmo ' , $ response ['cart ' ]['available_payment_methods ' ][0 ]['code ' ]);
75
- self ::assertEquals ('Check / Money order ' , $ response ['cart ' ]['available_payment_methods ' ][0 ]['title ' ]);
76
148
}
77
149
78
150
/**
@@ -88,13 +160,13 @@ private function getHeaderMap(string $username = 'customer@example.com', string
88
160
}
89
161
90
162
/**
91
- * @param string $reversedQuoteId
163
+ * @param string $reservedOrderId
92
164
* @return string
93
165
*/
94
- private function getMaskedQuoteIdByReversedQuoteId (string $ reversedQuoteId ): string
166
+ private function getMaskedQuoteIdByReservedOrderId (string $ reservedOrderId ): string
95
167
{
96
168
$ quote = $ this ->quoteFactory ->create ();
97
- $ this ->quoteResource ->load ($ quote , $ reversedQuoteId , 'reserved_order_id ' );
169
+ $ this ->quoteResource ->load ($ quote , $ reservedOrderId , 'reserved_order_id ' );
98
170
99
171
return $ this ->quoteIdToMaskedId ->execute ((int )$ quote ->getId ());
100
172
}
0 commit comments