@@ -31,11 +31,6 @@ class AddSimpleProductWithCustomOptionsToCartTest extends GraphQlAbstract
31
31
*/
32
32
private $ getCustomOptionsValuesForQueryBySku ;
33
33
34
- /**
35
- * @var GetEmptyOptionsValuesForQueryBySku
36
- */
37
- private $ getEmptyOptionsValuesForQueryBySku ;
38
-
39
34
/**
40
35
* @inheritdoc
41
36
*/
@@ -45,7 +40,6 @@ protected function setUp()
45
40
$ this ->getMaskedQuoteIdByReservedOrderId = $ objectManager ->get (GetMaskedQuoteIdByReservedOrderId::class);
46
41
$ this ->productCustomOptionsRepository = $ objectManager ->get (ProductCustomOptionRepositoryInterface::class);
47
42
$ this ->getCustomOptionsValuesForQueryBySku = $ objectManager ->get (GetCustomOptionsValuesForQueryBySku::class);
48
- $ this ->getEmptyOptionsValuesForQueryBySku = $ objectManager ->get (GetEmptyOptionsValuesForQueryBySku::class);
49
43
}
50
44
51
45
/**
@@ -63,7 +57,7 @@ public function testAddSimpleProductWithOptions()
63
57
64
58
$ customOptionsValues = $ this ->getCustomOptionsValuesForQueryBySku ->execute ($ sku );
65
59
/* Generate customizable options fragment for GraphQl request */
66
- $ queryCustomizableOptionValues = preg_replace ('/"([^"]+)"\s*:\s*/ ' , '$1: ' , json_encode ($ customOptionsValues ));
60
+ $ queryCustomizableOptionValues = preg_replace ('/"([^"]+)"\s*:\s*/ ' , '$1: ' , json_encode (array_values ( $ customOptionsValues) ));
67
61
68
62
$ customizableOptions = "customizable_options: {$ queryCustomizableOptionValues }" ;
69
63
$ query = $ this ->getQuery ($ maskedQuoteId , $ sku , $ quantity , $ customizableOptions );
@@ -74,13 +68,14 @@ public function testAddSimpleProductWithOptions()
74
68
self ::assertCount (1 , $ response ['addSimpleProductsToCart ' ]['cart ' ]);
75
69
76
70
$ customizableOptionsOutput = $ response ['addSimpleProductsToCart ' ]['cart ' ]['items ' ][0 ]['customizable_options ' ];
77
- $ assignedOptionsCount = count ( $ customOptionsValues ) ;
78
- for ($ counter = 0 ; $ counter < $ assignedOptionsCount ; $ counter ++ ) {
79
- $ expectedValues = $ this ->buildExpectedValuesArray ($ customOptionsValues [ $ counter ][ 'value_string ' ]);
71
+ $ count = 0 ;
72
+ foreach ($ customOptionsValues as $ type => $ value ) {
73
+ $ expectedValues = $ this ->buildExpectedValuesArray ($ value [ 'value_string ' ], $ type );
80
74
self ::assertEquals (
81
75
$ expectedValues ,
82
- $ customizableOptionsOutput [$ counter ]['values ' ]
76
+ $ customizableOptionsOutput [$ count ]['values ' ]
83
77
);
78
+ $ count ++;
84
79
}
85
80
}
86
81
@@ -106,54 +101,24 @@ public function testAddSimpleProductWithMissedRequiredOptionsSet()
106
101
}
107
102
108
103
/**
109
- * Test adding a simple product to the shopping cart with Date customizable option assigned
104
+ * Test adding a simple product with wrong format value for date option
110
105
*
111
- * @magentoApiDataFixture Magento/Catalog/_files/product_simple_with_option_date.php
112
- * @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
113
- */
114
- public function testAddSimpleProductWithDateOption ()
115
- {
116
- $ sku = 'simple-product-1 ' ;
117
- $ quantity = 1 ;
118
- $ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId ->execute ('test_order_1 ' );
119
-
120
- $ customOptionsValues = $ this ->getCustomOptionsValuesForQueryBySku ->execute ($ sku );
121
- $ queryCustomizableOptionValues = preg_replace ('/"([^"]+)"\s*:\s*/ ' , '$1: ' , json_encode ($ customOptionsValues ));
122
- $ customizableOptions = "customizable_options: {$ queryCustomizableOptionValues }" ;
123
- $ query = $ this ->getQuery ($ maskedQuoteId , $ sku , $ quantity , $ customizableOptions );
124
-
125
- $ response = $ this ->graphQlMutation ($ query );
126
-
127
- self ::assertArrayHasKey ('items ' , $ response ['addSimpleProductsToCart ' ]['cart ' ]);
128
- self ::assertCount (1 , $ response ['addSimpleProductsToCart ' ]['cart ' ]);
129
-
130
- $ cartItem = $ response ['addSimpleProductsToCart ' ]['cart ' ]['items ' ][0 ];
131
- $ customizableOptionOutput = $ cartItem ['customizable_options ' ][0 ]['values ' ][0 ]['value ' ];
132
- $ expectedValue = date ("M d, Y " , strtotime ($ customOptionsValues [0 ]['value_string ' ]));
133
-
134
- self ::assertEquals ($ expectedValue , $ customizableOptionOutput );
135
- }
136
-
137
- /**
138
- * Test adding a simple product with empty values for date option
139
- *
140
- * @magentoApiDataFixture Magento/Catalog/_files/product_simple_with_option_date.php
106
+ * @magentoApiDataFixture Magento/Catalog/_files/product_simple_with_options.php
141
107
* @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
142
108
*/
143
- public function testAddSimpleProductWithMissedDateOptionsSet ()
109
+ public function testAddSimpleProductWithWrongDateOptionFormat ()
144
110
{
145
111
$ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId ->execute ('test_order_1 ' );
146
- $ sku = 'simple-product-1 ' ;
112
+ $ sku = 'simple ' ;
147
113
$ quantity = 1 ;
148
114
149
- $ customOptionsValues = $ this ->getEmptyOptionsValuesForQueryBySku ->execute ($ sku );
150
- $ queryCustomizableOptionValues = preg_replace ('/"([^"]+)"\s*:\s*/ ' , '$1: ' , json_encode ($ customOptionsValues ));
115
+ $ customOptionsValues = $ this ->getCustomOptionsValuesForQueryBySku ->execute ($ sku );
116
+ $ customOptionsValues ['date ' ]['value_string ' ] = '12-12-12 ' ;
117
+ $ queryCustomizableOptionValues = preg_replace ('/"([^"]+)"\s*:\s*/ ' , '$1: ' , json_encode (array_values ($ customOptionsValues )));
151
118
$ customizableOptions = "customizable_options: {$ queryCustomizableOptionValues }" ;
152
119
$ query = $ this ->getQuery ($ maskedQuoteId , $ sku , $ quantity , $ customizableOptions );
153
120
154
- self ::expectExceptionMessage (
155
- 'Invalid format provided. Please use \'Y-m-d H:i:s \' format. '
156
- );
121
+ $ this ->expectExceptionMessage ('Invalid format provided. Please use \'Y-m-d H:i:s \' format. ' );
157
122
158
123
$ this ->graphQlMutation ($ query );
159
124
}
@@ -204,10 +169,14 @@ private function getQuery(string $maskedQuoteId, string $sku, float $quantity, s
204
169
* Build the part of expected response.
205
170
*
206
171
* @param string $assignedValue
172
+ * @param string $type option type
207
173
* @return array
208
174
*/
209
- private function buildExpectedValuesArray (string $ assignedValue ) : array
175
+ private function buildExpectedValuesArray (string $ assignedValue, string $ type ) : array
210
176
{
177
+ if ($ type === 'date ' ){
178
+ return [['value ' => date ('M d, Y ' , strtotime ($ assignedValue ))]];
179
+ }
211
180
$ assignedOptionsArray = explode (', ' , trim ($ assignedValue , '[] ' ));
212
181
$ expectedArray = [];
213
182
foreach ($ assignedOptionsArray as $ assignedOption ) {
0 commit comments