9
9
10
10
use Magento \GraphQl \Quote \GetMaskedQuoteIdByReservedOrderId ;
11
11
use Magento \Integration \Api \CustomerTokenServiceInterface ;
12
- use Magento \Quote \Model \QuoteFactory ;
13
- use Magento \Quote \Model \QuoteIdToMaskedQuoteIdInterface ;
14
- use Magento \Quote \Model \ResourceModel \Quote as QuoteResource ;
15
12
use Magento \TestFramework \Helper \Bootstrap ;
16
13
use Magento \TestFramework \TestCase \GraphQlAbstract ;
17
14
@@ -25,21 +22,6 @@ class GetCartTest extends GraphQlAbstract
25
22
*/
26
23
private $ getMaskedQuoteIdByReservedOrderId ;
27
24
28
- /**
29
- * @var QuoteResource
30
- */
31
- private $ quoteResource ;
32
-
33
- /**
34
- * @var QuoteFactory
35
- */
36
- private $ quoteFactory ;
37
-
38
- /**
39
- * @var QuoteIdToMaskedQuoteIdInterface
40
- */
41
- private $ quoteIdToMaskedId ;
42
-
43
25
/**
44
26
* @var CustomerTokenServiceInterface
45
27
*/
@@ -49,19 +31,21 @@ protected function setUp()
49
31
{
50
32
$ objectManager = Bootstrap::getObjectManager ();
51
33
$ this ->getMaskedQuoteIdByReservedOrderId = $ objectManager ->get (GetMaskedQuoteIdByReservedOrderId::class);
52
- $ this ->quoteResource = $ objectManager ->get (QuoteResource::class);
53
- $ this ->quoteFactory = $ objectManager ->get (QuoteFactory::class);
54
- $ this ->quoteIdToMaskedId = $ objectManager ->get (QuoteIdToMaskedQuoteIdInterface::class);
55
34
$ this ->customerTokenService = $ objectManager ->get (CustomerTokenServiceInterface::class);
56
35
}
57
36
58
37
/**
59
- * @magentoApiDataFixture Magento/Checkout/_files/quote_with_items_saved.php
38
+ * @magentoApiDataFixture Magento/Customer/_files/customer.php
39
+ * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
40
+ * @magentoApiDataFixture Magento/Catalog/_files/product_virtual.php
41
+ * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
42
+ * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
43
+ * @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_virtual_product.php
60
44
*/
61
45
public function testGetCart ()
62
46
{
63
- $ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId ->execute ('test_order_item_with_items ' );
64
- $ query = $ this ->getCartQuery ($ maskedQuoteId );
47
+ $ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId ->execute ('test_quote ' );
48
+ $ query = $ this ->getQuery ($ maskedQuoteId );
65
49
66
50
$ response = $ this ->graphQlQuery ($ query , [], '' , $ this ->getHeaderMap ());
67
51
@@ -70,24 +54,23 @@ public function testGetCart()
70
54
self ::assertCount (2 , $ response ['cart ' ]['items ' ]);
71
55
72
56
self ::assertNotEmpty ($ response ['cart ' ]['items ' ][0 ]['id ' ]);
73
- self ::assertEquals ($ response ['cart ' ]['items ' ][0 ]['qty ' ], 2 );
74
- self ::assertEquals ($ response ['cart ' ]['items ' ][0 ]['product ' ]['sku ' ], ' simple ' );
57
+ self ::assertEquals (2 , $ response ['cart ' ]['items ' ][0 ]['qty ' ]);
58
+ self ::assertEquals (' simple ' , $ response ['cart ' ]['items ' ][0 ]['product ' ]['sku ' ]);
75
59
76
60
self ::assertNotEmpty ($ response ['cart ' ]['items ' ][1 ]['id ' ]);
77
- self ::assertEquals ($ response ['cart ' ]['items ' ][1 ]['qty ' ], 1 );
78
- self ::assertEquals ($ response ['cart ' ]['items ' ][1 ]['product ' ]['sku ' ], ' simple_one ' );
61
+ self ::assertEquals (2 , $ response ['cart ' ]['items ' ][1 ]['qty ' ]);
62
+ self ::assertEquals (' virtual-product ' , $ response ['cart ' ]['items ' ][1 ]['product ' ]['sku ' ]);
79
63
}
80
64
81
65
/**
66
+ * @security
82
67
* @magentoApiDataFixture Magento/Customer/_files/customer.php
83
- * @magentoApiDataFixture Magento/Checkout/ _files/quote_with_simple_product_saved .php
68
+ * @magentoApiDataFixture Magento/GraphQl/Quote/ _files/guest/create_empty_cart .php
84
69
*/
85
70
public function testGetGuestCart ()
86
71
{
87
- $ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId ->execute (
88
- 'test_order_with_simple_product_without_address '
89
- );
90
- $ query = $ this ->getCartQuery ($ maskedQuoteId );
72
+ $ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId ->execute ('test_quote ' );
73
+ $ query = $ this ->getQuery ($ maskedQuoteId );
91
74
92
75
$ this ->expectExceptionMessage (
93
76
"The current user cannot perform operations on cart \"{$ maskedQuoteId }\""
@@ -96,13 +79,14 @@ public function testGetGuestCart()
96
79
}
97
80
98
81
/**
82
+ * @security
99
83
* @magentoApiDataFixture Magento/Customer/_files/three_customers.php
100
- * @magentoApiDataFixture Magento/Checkout/ _files/quote_with_items_saved .php
84
+ * @magentoApiDataFixture Magento/GraphQl/Quote/ _files/customer/create_empty_cart .php
101
85
*/
102
86
public function testGetAnotherCustomerCart ()
103
87
{
104
- $ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId ->execute ('test_order_item_with_items ' );
105
- $ query = $ this ->getCartQuery ($ maskedQuoteId );
88
+ $ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId ->execute ('test_quote ' );
89
+ $ query = $ this ->getQuery ($ maskedQuoteId );
106
90
107
91
$ this ->expectExceptionMessage (
108
92
"The current user cannot perform operations on cart \"{$ maskedQuoteId }\""
@@ -112,33 +96,30 @@ public function testGetAnotherCustomerCart()
112
96
113
97
/**
114
98
* @magentoApiDataFixture Magento/Customer/_files/customer.php
99
+ *
115
100
* @expectedException \Exception
116
101
* @expectedExceptionMessage Could not find a cart with ID "non_existent_masked_id"
117
102
*/
118
103
public function testGetNonExistentCart ()
119
104
{
120
105
$ maskedQuoteId = 'non_existent_masked_id ' ;
121
- $ query = $ this ->getCartQuery ($ maskedQuoteId );
106
+ $ query = $ this ->getQuery ($ maskedQuoteId );
122
107
123
108
$ this ->graphQlQuery ($ query , [], '' , $ this ->getHeaderMap ());
124
109
}
125
110
126
111
/**
127
- * @magentoApiDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
128
112
* @magentoApiDataFixture Magento/Customer/_files/customer.php
113
+ * @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
114
+ * @magentoApiDataFixture Magento/GraphQl/Quote/_files/make_cart_inactive.php
115
+ *
129
116
* @expectedException \Exception
130
117
* @expectedExceptionMessage Current user does not have an active cart.
131
118
*/
132
119
public function testGetInactiveCart ()
133
120
{
134
- $ quote = $ this ->quoteFactory ->create ();
135
- $ this ->quoteResource ->load ($ quote , 'test_order_with_simple_product_without_address ' , 'reserved_order_id ' );
136
- $ quote ->setCustomerId (1 );
137
- $ quote ->setIsActive (false );
138
- $ this ->quoteResource ->save ($ quote );
139
- $ maskedQuoteId = $ this ->quoteIdToMaskedId ->execute ((int )$ quote ->getId ());
140
-
141
- $ query = $ this ->getCartQuery ($ maskedQuoteId );
121
+ $ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId ->execute ('test_quote ' );
122
+ $ query = $ this ->getQuery ($ maskedQuoteId );
142
123
143
124
$ this ->graphQlQuery ($ query , [], '' , $ this ->getHeaderMap ());
144
125
}
@@ -147,12 +128,11 @@ public function testGetInactiveCart()
147
128
* @param string $maskedQuoteId
148
129
* @return string
149
130
*/
150
- private function getCartQuery (
151
- string $ maskedQuoteId
152
- ) : string {
131
+ private function getQuery (string $ maskedQuoteId ): string
132
+ {
153
133
return <<<QUERY
154
134
{
155
- cart(cart_id: " $ maskedQuoteId") {
135
+ cart(cart_id: " { $ maskedQuoteId} ") {
156
136
items {
157
137
id
158
138
qty
0 commit comments