@@ -49,18 +49,8 @@ protected function setUp()
49
49
*/
50
50
public function testGetCartWithPaymentMethods ()
51
51
{
52
- $ maskedQuoteId = $ this ->getMaskedQuoteIdByReversedQuoteId ('test_order_with_simple_product_without_address ' );
53
-
54
- $ query = <<<QUERY
55
- {
56
- cart(cart_id: " $ maskedQuoteId") {
57
- available_payment_methods {
58
- code
59
- title
60
- }
61
- }
62
- }
63
- QUERY ;
52
+ $ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId ('test_order_with_simple_product_without_address ' );
53
+ $ query = $ this ->getQuery ($ maskedQuoteId );
64
54
$ response = $ this ->graphQlQuery ($ query );
65
55
66
56
self ::assertArrayHasKey ('cart ' , $ response );
@@ -73,16 +63,78 @@ public function testGetCartWithPaymentMethods()
73
63
'No Payment Information Required ' ,
74
64
$ response ['cart ' ]['available_payment_methods ' ][1 ]['title ' ]
75
65
);
66
+ self ::assertGreaterThan (
67
+ 0 ,
68
+ count ($ response ['cart ' ]['available_payment_methods ' ]),
69
+ 'There are no available payment methods for guest cart! '
70
+ );
71
+ }
72
+
73
+ /**
74
+ * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php
75
+ */
76
+ public function testGetPaymentMethodsFromCustomerCart ()
77
+ {
78
+ $ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId ('test_order_1 ' );
79
+ $ query = $ this ->getQuery ($ maskedQuoteId );
80
+
81
+ $ this ->expectExceptionMessage (
82
+ "The current user cannot perform operations on cart \"$ maskedQuoteId \""
83
+ );
84
+ $ this ->graphQlQuery ($ query );
85
+ }
86
+
87
+ /**
88
+ * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
89
+ * @magentoApiDataFixture Magento/Payment/_files/disable_all_active_payment_methods.php
90
+ */
91
+ public function testGetPaymentMethodsIfPaymentsAreNotSet ()
92
+ {
93
+ $ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId ('test_order_with_simple_product_without_address ' );
94
+ $ query = $ this ->getQuery ($ maskedQuoteId );
95
+ $ response = $ this ->graphQlQuery ($ query );
96
+
97
+ self ::assertEquals (0 , count ($ response ['cart ' ]['available_payment_methods ' ]));
98
+ }
99
+
100
+ /**
101
+ * @expectedException \Exception
102
+ * @expectedExceptionMessage Could not find a cart with ID "non_existent_masked_id"
103
+ */
104
+ public function testGetPaymentMethodsOfNonExistentCart ()
105
+ {
106
+ $ maskedQuoteId = 'non_existent_masked_id ' ;
107
+ $ query = $ this ->getQuery ($ maskedQuoteId );
108
+ $ this ->graphQlQuery ($ query );
109
+ }
110
+
111
+ /**
112
+ * @param string $maskedQuoteId
113
+ * @return string
114
+ */
115
+ private function getQuery (
116
+ string $ maskedQuoteId
117
+ ): string {
118
+ return <<<QUERY
119
+ {
120
+ cart(cart_id: " $ maskedQuoteId") {
121
+ available_payment_methods {
122
+ code
123
+ title
124
+ }
125
+ }
126
+ }
127
+ QUERY ;
76
128
}
77
129
78
130
/**
79
- * @param string $reversedQuoteId
131
+ * @param string $reservedOrderId
80
132
* @return string
81
133
*/
82
- private function getMaskedQuoteIdByReversedQuoteId (string $ reversedQuoteId ): string
134
+ private function getMaskedQuoteIdByReservedOrderId (string $ reservedOrderId ): string
83
135
{
84
136
$ quote = $ this ->quoteFactory ->create ();
85
- $ this ->quoteResource ->load ($ quote , $ reversedQuoteId , 'reserved_order_id ' );
137
+ $ this ->quoteResource ->load ($ quote , $ reservedOrderId , 'reserved_order_id ' );
86
138
87
139
return $ this ->quoteIdToMaskedId ->execute ((int )$ quote ->getId ());
88
140
}
0 commit comments