@@ -57,7 +57,11 @@ public function testAddSimpleProductWithOptions()
57
57
58
58
$ customOptionsValues = $ this ->getCustomOptionsValuesForQueryBySku ->execute ($ sku );
59
59
/* Generate customizable options fragment for GraphQl request */
60
- $ queryCustomizableOptionValues = preg_replace ('/"([^"]+)"\s*:\s*/ ' , '$1: ' , json_encode ($ customOptionsValues ));
60
+ $ queryCustomizableOptionValues = preg_replace (
61
+ '/"([^"]+)"\s*:\s*/ ' ,
62
+ '$1: ' ,
63
+ json_encode (array_values ($ customOptionsValues ))
64
+ );
61
65
62
66
$ customizableOptions = "customizable_options: {$ queryCustomizableOptionValues }" ;
63
67
$ query = $ this ->getQuery ($ maskedQuoteId , $ sku , $ quantity , $ customizableOptions );
@@ -68,13 +72,14 @@ public function testAddSimpleProductWithOptions()
68
72
self ::assertCount (1 , $ response ['addSimpleProductsToCart ' ]['cart ' ]);
69
73
70
74
$ customizableOptionsOutput = $ response ['addSimpleProductsToCart ' ]['cart ' ]['items ' ][0 ]['customizable_options ' ];
71
- $ assignedOptionsCount = count ( $ customOptionsValues ) ;
72
- for ($ counter = 0 ; $ counter < $ assignedOptionsCount ; $ counter ++ ) {
73
- $ expectedValues = $ this ->buildExpectedValuesArray ($ customOptionsValues [ $ counter ][ 'value_string ' ]);
75
+ $ count = 0 ;
76
+ foreach ($ customOptionsValues as $ type => $ value ) {
77
+ $ expectedValues = $ this ->buildExpectedValuesArray ($ value [ 'value_string ' ], $ type );
74
78
self ::assertEquals (
75
79
$ expectedValues ,
76
- $ customizableOptionsOutput [$ counter ]['values ' ]
80
+ $ customizableOptionsOutput [$ count ]['values ' ]
77
81
);
82
+ $ count ++;
78
83
}
79
84
}
80
85
@@ -99,6 +104,33 @@ public function testAddSimpleProductWithMissedRequiredOptionsSet()
99
104
$ this ->graphQlMutation ($ query );
100
105
}
101
106
107
+ /**
108
+ * Test adding a simple product with wrong format value for date option
109
+ *
110
+ * @magentoApiDataFixture Magento/Catalog/_files/product_simple_with_options.php
111
+ * @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
112
+ */
113
+ public function testAddSimpleProductWithWrongDateOptionFormat ()
114
+ {
115
+ $ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId ->execute ('test_order_1 ' );
116
+ $ sku = 'simple ' ;
117
+ $ quantity = 1 ;
118
+
119
+ $ customOptionsValues = $ this ->getCustomOptionsValuesForQueryBySku ->execute ($ sku );
120
+ $ customOptionsValues ['date ' ]['value_string ' ] = '12-12-12 ' ;
121
+ $ queryCustomizableOptionValues = preg_replace (
122
+ '/"([^"]+)"\s*:\s*/ ' ,
123
+ '$1: ' ,
124
+ json_encode (array_values ($ customOptionsValues ))
125
+ );
126
+ $ customizableOptions = "customizable_options: {$ queryCustomizableOptionValues }" ;
127
+ $ query = $ this ->getQuery ($ maskedQuoteId , $ sku , $ quantity , $ customizableOptions );
128
+
129
+ $ this ->expectExceptionMessage ('Invalid format provided. Please use \'Y-m-d H:i:s \' format. ' );
130
+
131
+ $ this ->graphQlMutation ($ query );
132
+ }
133
+
102
134
/**
103
135
* @param string $maskedQuoteId
104
136
* @param string $sku
@@ -145,10 +177,14 @@ private function getQuery(string $maskedQuoteId, string $sku, float $quantity, s
145
177
* Build the part of expected response.
146
178
*
147
179
* @param string $assignedValue
180
+ * @param string $type option type
148
181
* @return array
149
182
*/
150
- private function buildExpectedValuesArray (string $ assignedValue ) : array
183
+ private function buildExpectedValuesArray (string $ assignedValue, string $ type ) : array
151
184
{
185
+ if ($ type === 'date ' ) {
186
+ return [['value ' => date ('M d, Y ' , strtotime ($ assignedValue ))]];
187
+ }
152
188
$ assignedOptionsArray = explode (', ' , trim ($ assignedValue , '[] ' ));
153
189
$ expectedArray = [];
154
190
foreach ($ assignedOptionsArray as $ assignedOption ) {
0 commit comments