7
7
8
8
namespace Magento \Quote \Api ;
9
9
10
+ use Magento \Framework \Webapi \Rest \Request ;
11
+ use Magento \Quote \Model \Quote ;
10
12
use Magento \TestFramework \TestCase \WebapiAbstract ;
11
13
12
14
/**
13
15
* Class for testing adding and deleting items flow.
14
16
*/
15
17
class GuestCartAddingItemsTest extends WebapiAbstract
16
18
{
17
- const SERVICE_VERSION = 'V1 ' ;
18
- const SERVICE_NAME = 'quoteGuestCartManagementV1 ' ;
19
- const RESOURCE_PATH = '/V1/guest-carts/ ' ;
19
+ private const SERVICE_VERSION = 'V1 ' ;
20
+ private const SERVICE_NAME = 'quoteGuestCartManagementV1 ' ;
21
+ private const RESOURCE_PATH = '/V1/guest-carts/ ' ;
20
22
21
23
/**
22
24
* @var \Magento\TestFramework\ObjectManager
@@ -29,108 +31,91 @@ protected function setUp(): void
29
31
}
30
32
31
33
/**
32
- * Test price for cart after deleting and adding product to .
34
+ * Test add to product with custom option and test with updating custom options .
33
35
*
34
- * @magentoApiDataFixture Magento/Catalog/_files/product_without_options_with_stock_data .php
36
+ * @magentoApiDataFixture Magento/Catalog/_files/product_simple_with_custom_options .php
35
37
* @return void
36
38
*/
37
- public function testPriceForCreatingQuoteFromEmptyCart ()
39
+ public function testAddtoCartWithCustomOptionsForCreatingQuoteFromEmptyCart ()
38
40
{
41
+ $ this ->_markTestAsRestOnly ();
39
42
// Creating empty cart
40
43
$ serviceInfoForCreatingEmptyCart = [
41
44
'rest ' => [
42
45
'resourcePath ' => self ::RESOURCE_PATH ,
43
- 'httpMethod ' => \Magento \Framework \Webapi \Rest \Request::HTTP_METHOD_POST ,
44
- ],
45
- 'soap ' => [
46
- 'service ' => self ::SERVICE_NAME ,
47
- 'serviceVersion ' => self ::SERVICE_VERSION ,
48
- 'operation ' => self ::SERVICE_NAME . 'CreateEmptyCart ' ,
49
- ],
46
+ 'httpMethod ' => Request::HTTP_METHOD_POST ,
47
+ ]
50
48
];
51
49
$ quoteId = $ this ->_webApiCall ($ serviceInfoForCreatingEmptyCart );
52
50
53
51
// Adding item to the cart
54
52
$ serviceInfoForAddingProduct = [
55
53
'rest ' => [
56
54
'resourcePath ' => self ::RESOURCE_PATH . $ quoteId . '/items ' ,
57
- 'httpMethod ' => \Magento \Framework \Webapi \Rest \Request::HTTP_METHOD_POST ,
58
- ],
59
- 'soap ' => [
60
- 'service ' => GuestCartItemRepositoryTest::SERVICE_NAME ,
61
- 'serviceVersion ' => self ::SERVICE_VERSION ,
62
- 'operation ' => GuestCartItemRepositoryTest::SERVICE_NAME . 'Save ' ,
63
- ],
55
+ 'httpMethod ' => Request::HTTP_METHOD_POST ,
56
+ ]
64
57
];
65
58
$ requestData = [
66
59
'cartItem ' => [
67
60
'quote_id ' => $ quoteId ,
68
- 'sku ' => 'simple ' ,
69
- 'qty ' => 1
61
+ 'sku ' => 'simple_with_custom_options ' ,
62
+ 'qty ' => 1 ,
63
+ 'product_option ' => [
64
+ 'extension_attributes ' => [
65
+ 'custom_options ' => [
66
+ ['option_id ' => 1 , 'option_value ' => 1 ],
67
+ ['option_id ' => 2 , 'option_value ' => 1 ],
68
+ ['option_id ' => 3 , 'option_value ' => 'test ' ]
69
+ ]
70
+ ]
71
+ ]
70
72
]
71
73
];
72
74
$ item = $ this ->_webApiCall ($ serviceInfoForAddingProduct , $ requestData );
73
75
$ this ->assertNotEmpty ($ item );
74
76
75
- // Delete the item for the cart
76
- $ serviceInfoForDeleteProduct = [
77
- 'rest ' => [
78
- 'resourcePath ' => self ::RESOURCE_PATH . $ quoteId . '/items/ ' . $ item ['item_id ' ],
79
- 'httpMethod ' => \Magento \Framework \Webapi \Rest \Request::HTTP_METHOD_DELETE ,
80
- ],
81
- 'soap ' => [
82
- 'service ' => GuestCartItemRepositoryTest::SERVICE_NAME ,
83
- 'serviceVersion ' => self ::SERVICE_VERSION ,
84
- 'operation ' => GuestCartItemRepositoryTest::SERVICE_NAME . 'deleteById ' ,
85
- ],
86
- ];
87
- $ response = (TESTS_WEB_API_ADAPTER == self ::ADAPTER_SOAP ) ?
88
- $ this ->_webApiCall ($ serviceInfoForDeleteProduct , ['cartId ' => $ quoteId , 'itemId ' => $ item ['item_id ' ]])
89
- : $ this ->_webApiCall ($ serviceInfoForDeleteProduct );
90
- $ this ->assertTrue ($ response );
91
-
92
- // Add one more item and check price for this item
93
- $ serviceInfoForAddingProduct = [
94
- 'rest ' => [
95
- 'resourcePath ' => self ::RESOURCE_PATH . $ quoteId . '/items ' ,
96
- 'httpMethod ' => \Magento \Framework \Webapi \Rest \Request::HTTP_METHOD_POST ,
97
- ],
98
- 'soap ' => [
99
- 'service ' => GuestCartItemRepositoryTest::SERVICE_NAME ,
100
- 'serviceVersion ' => self ::SERVICE_VERSION ,
101
- 'operation ' => GuestCartItemRepositoryTest::SERVICE_NAME . 'Save ' ,
102
- ],
103
- ];
104
77
$ requestData = [
105
78
'cartItem ' => [
106
79
'quote_id ' => $ quoteId ,
107
- 'sku ' => 'simple ' ,
108
- 'qty ' => 1
80
+ 'sku ' => 'simple_with_custom_options ' ,
81
+ 'qty ' => 1 ,
82
+ 'product_option ' => [
83
+ 'extension_attributes ' => [
84
+ 'custom_options ' => [
85
+ ['option_id ' => 1 , 'option_value ' => 2 ],
86
+ ['option_id ' => 2 , 'option_value ' => 2 ],
87
+ ['option_id ' => 3 , 'option_value ' => 'test2 ' ]
88
+ ]
89
+ ]
90
+ ]
109
91
]
110
92
];
111
- $ item = $ this ->_webApiCall ($ serviceInfoForAddingProduct , $ requestData );
112
- $ this ->assertNotEmpty ($ item );
113
- $ this ->assertEquals ($ item ['price ' ], 10 );
114
93
115
- /** @var \Magento\Quote\Model\Quote $quote */
116
- $ quote = $ this ->objectManager ->create (\Magento \Quote \Model \Quote::class);
117
- $ quote ->load ($ quoteId );
118
- $ quote ->delete ();
94
+ // Update the item for the cart
95
+ $ serviceInfoForUpdateProduct = [
96
+ 'rest ' => [
97
+ 'resourcePath ' => self ::RESOURCE_PATH . $ quoteId . '/items/ ' . $ item ['item_id ' ],
98
+ 'httpMethod ' => Request::HTTP_METHOD_PUT ,
99
+ ]
100
+ ];
101
+
102
+ $ item = $ this ->_webApiCall ($ serviceInfoForUpdateProduct , $ requestData );
103
+ $ this ->assertNotEmpty ($ item );
119
104
}
120
105
121
106
/**
122
- * Test add to product with custom option and test with updating custom options .
107
+ * Test price for cart after deleting and adding product to .
123
108
*
124
- * @magentoApiDataFixture Magento/Catalog/_files/product_simple_with_custom_options .php
109
+ * @magentoApiDataFixture Magento/Catalog/_files/product_without_options_with_stock_data .php
125
110
* @return void
126
111
*/
127
- public function testAddtoCartWithCustomOptionsForCreatingQuoteFromEmptyCart ()
112
+ public function testPriceForCreatingQuoteFromEmptyCart ()
128
113
{
129
114
// Creating empty cart
130
115
$ serviceInfoForCreatingEmptyCart = [
131
116
'rest ' => [
132
117
'resourcePath ' => self ::RESOURCE_PATH ,
133
- 'httpMethod ' => \ Magento \ Framework \ Webapi \ Rest \ Request::HTTP_METHOD_POST ,
118
+ 'httpMethod ' => Request::HTTP_METHOD_POST ,
134
119
],
135
120
'soap ' => [
136
121
'service ' => self ::SERVICE_NAME ,
@@ -144,7 +129,7 @@ public function testAddtoCartWithCustomOptionsForCreatingQuoteFromEmptyCart()
144
129
$ serviceInfoForAddingProduct = [
145
130
'rest ' => [
146
131
'resourcePath ' => self ::RESOURCE_PATH . $ quoteId . '/items ' ,
147
- 'httpMethod ' => \ Magento \ Framework \ Webapi \ Rest \ Request::HTTP_METHOD_POST ,
132
+ 'httpMethod ' => Request::HTTP_METHOD_POST ,
148
133
],
149
134
'soap ' => [
150
135
'service ' => GuestCartItemRepositoryTest::SERVICE_NAME ,
@@ -155,57 +140,55 @@ public function testAddtoCartWithCustomOptionsForCreatingQuoteFromEmptyCart()
155
140
$ requestData = [
156
141
'cartItem ' => [
157
142
'quote_id ' => $ quoteId ,
158
- 'sku ' => 'simple_with_custom_options ' ,
159
- 'qty ' => 1 ,
160
- 'product_option ' => [
161
- 'extension_attributes ' => [
162
- 'custom_options ' => [
163
- ['option_id ' => 1 , 'option_value ' => 1 ],
164
- ['option_id ' => 2 , 'option_value ' => 1 ],
165
- ['option_id ' => 3 , 'option_value ' => 'test ' ]
166
- ]
167
- ]
168
- ]
143
+ 'sku ' => 'simple ' ,
144
+ 'qty ' => 1
169
145
]
170
146
];
171
147
$ item = $ this ->_webApiCall ($ serviceInfoForAddingProduct , $ requestData );
172
148
$ this ->assertNotEmpty ($ item );
173
149
174
- $ requestData = [
175
- 'cartItem ' => [
176
- 'quote_id ' => $ quoteId ,
177
- 'sku ' => 'simple_with_custom_options ' ,
178
- 'qty ' => 1 ,
179
- 'product_option ' => [
180
- 'extension_attributes ' => [
181
- 'custom_options ' => [
182
- ['option_id ' => 1 , 'option_value ' => 2 ],
183
- ['option_id ' => 2 , 'option_value ' => 2 ],
184
- ['option_id ' => 3 , 'option_value ' => 'test2 ' ]
185
- ]
186
- ]
187
- ]
188
- ]
150
+ // Delete the item for the cart
151
+ $ serviceInfoForDeleteProduct = [
152
+ 'rest ' => [
153
+ 'resourcePath ' => self ::RESOURCE_PATH . $ quoteId . '/items/ ' . $ item ['item_id ' ],
154
+ 'httpMethod ' => Request::HTTP_METHOD_DELETE ,
155
+ ],
156
+ 'soap ' => [
157
+ 'service ' => GuestCartItemRepositoryTest::SERVICE_NAME ,
158
+ 'serviceVersion ' => self ::SERVICE_VERSION ,
159
+ 'operation ' => GuestCartItemRepositoryTest::SERVICE_NAME . 'deleteById ' ,
160
+ ],
189
161
];
162
+ $ response = (TESTS_WEB_API_ADAPTER == self ::ADAPTER_SOAP ) ?
163
+ $ this ->_webApiCall ($ serviceInfoForDeleteProduct , ['cartId ' => $ quoteId , 'itemId ' => $ item ['item_id ' ]])
164
+ : $ this ->_webApiCall ($ serviceInfoForDeleteProduct );
165
+ $ this ->assertTrue ($ response );
190
166
191
- // Update the item for the cart
192
- $ serviceInfoForUpdateProduct = [
167
+ // Add one more item and check price for this item
168
+ $ serviceInfoForAddingProduct = [
193
169
'rest ' => [
194
- 'resourcePath ' => self ::RESOURCE_PATH . $ quoteId . '/items/ ' . $ item [ ' item_id ' ] ,
195
- 'httpMethod ' => \ Magento \ Framework \ Webapi \ Rest \ Request::HTTP_METHOD_PUT ,
170
+ 'resourcePath ' => self ::RESOURCE_PATH . $ quoteId . '/items ' ,
171
+ 'httpMethod ' => Request::HTTP_METHOD_POST ,
196
172
],
197
173
'soap ' => [
198
174
'service ' => GuestCartItemRepositoryTest::SERVICE_NAME ,
199
175
'serviceVersion ' => self ::SERVICE_VERSION ,
200
176
'operation ' => GuestCartItemRepositoryTest::SERVICE_NAME . 'Save ' ,
201
177
],
202
178
];
203
-
204
- $ item = $ this ->_webApiCall ($ serviceInfoForUpdateProduct , $ requestData );
179
+ $ requestData = [
180
+ 'cartItem ' => [
181
+ 'quote_id ' => $ quoteId ,
182
+ 'sku ' => 'simple ' ,
183
+ 'qty ' => 1
184
+ ]
185
+ ];
186
+ $ item = $ this ->_webApiCall ($ serviceInfoForAddingProduct , $ requestData );
205
187
$ this ->assertNotEmpty ($ item );
188
+ $ this ->assertEquals ($ item ['price ' ], 10 );
206
189
207
- /** @var \Magento\Quote\Model\ Quote $quote */
208
- $ quote = $ this ->objectManager ->create (\ Magento \ Quote \ Model \ Quote::class);
190
+ /** @var Quote $quote */
191
+ $ quote = $ this ->objectManager ->create (Quote::class);
209
192
$ quote ->load ($ quoteId );
210
193
$ quote ->delete ();
211
194
}
0 commit comments