@@ -54,11 +54,59 @@ protected function setUp()
54
54
/**
55
55
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_items_saved.php
56
56
*/
57
- public function testGetCartWithPaymentMethods ()
57
+ public function testGetPaymentMethodsFromCustomerCart ()
58
58
{
59
- $ maskedQuoteId = $ this ->getMaskedQuoteIdByReversedQuoteId ('test_order_item_with_items ' );
59
+ $ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId ('test_order_item_with_items ' );
60
+ $ query = $ this ->getCartAvailablePaymentMethodsQuery ($ maskedQuoteId );
61
+ $ response = $ this ->graphQlQuery ($ query , [], '' , $ this ->getHeaderMap ());
60
62
61
- $ query = <<<QUERY
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
+ }
72
+
73
+ /**
74
+ * @magentoApiDataFixture Magento/Customer/_files/three_customers.php
75
+ * @magentoApiDataFixture Magento/Checkout/_files/quote_with_items_saved.php
76
+ */
77
+ public function testGetPaymentMethodsFromAnotherCustomerCart ()
78
+ {
79
+ $ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId ('test_order_item_with_items ' );
80
+ $ query = $ this ->getCartAvailablePaymentMethodsQuery ($ maskedQuoteId );
81
+
82
+ $ this ->expectExceptionMessage (
83
+ "The current user cannot perform operations on cart \"$ maskedQuoteId \""
84
+ );
85
+ $ this ->
graphQlQuery (
$ query, [],
'' ,
$ this ->
getHeaderMap (
'[email protected] ' ));
86
+ }
87
+
88
+
89
+ /**
90
+ * @magentoApiDataFixture Magento/Customer/_files/customer.php
91
+ * @expectedException \Exception
92
+ * @expectedExceptionMessage Could not find a cart with ID "non_existent_masked_id"
93
+ */
94
+ public function testGetPaymentMethodsOfNonExistentCart ()
95
+ {
96
+ $ maskedQuoteId = 'non_existent_masked_id ' ;
97
+ $ query = $ this ->getCartAvailablePaymentMethodsQuery ($ maskedQuoteId );
98
+
99
+ $ this ->graphQlQuery ($ query , [], '' , $ this ->getHeaderMap ());
100
+ }
101
+
102
+ /**
103
+ * @param string $maskedQuoteId
104
+ * @return string
105
+ */
106
+ private function getCartAvailablePaymentMethodsQuery (
107
+ string $ maskedQuoteId
108
+ ) : string {
109
+ return <<<QUERY
62
110
{
63
111
cart(cart_id: " $ maskedQuoteId") {
64
112
available_payment_methods {
@@ -68,11 +116,6 @@ public function testGetCartWithPaymentMethods()
68
116
}
69
117
}
70
118
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
119
}
77
120
78
121
/**
@@ -88,13 +131,13 @@ private function getHeaderMap(string $username = '
[email protected] ', string
88
131
}
89
132
90
133
/**
91
- * @param string $reversedQuoteId
134
+ * @param string $reservedOrderId
92
135
* @return string
93
136
*/
94
- private function getMaskedQuoteIdByReversedQuoteId (string $ reversedQuoteId ): string
137
+ private function getMaskedQuoteIdByReservedOrderId (string $ reservedOrderId ): string
95
138
{
96
139
$ quote = $ this ->quoteFactory ->create ();
97
- $ this ->quoteResource ->load ($ quote , $ reversedQuoteId , 'reserved_order_id ' );
140
+ $ this ->quoteResource ->load ($ quote , $ reservedOrderId , 'reserved_order_id ' );
98
141
99
142
return $ this ->quoteIdToMaskedId ->execute ((int )$ quote ->getId ());
100
143
}
0 commit comments