@@ -31,6 +31,11 @@ class AddSimpleProductWithCustomOptionsToCartTest extends GraphQlAbstract
31
31
*/
32
32
private $ getCustomOptionsValuesForQueryBySku ;
33
33
34
+ /**
35
+ * @var GetEmptyOptionsValuesForQueryBySku
36
+ */
37
+ private $ getEmptyOptionsValuesForQueryBySku ;
38
+
34
39
/**
35
40
* @inheritdoc
36
41
*/
@@ -40,6 +45,7 @@ protected function setUp()
40
45
$ this ->getMaskedQuoteIdByReservedOrderId = $ objectManager ->get (GetMaskedQuoteIdByReservedOrderId::class);
41
46
$ this ->productCustomOptionsRepository = $ objectManager ->get (ProductCustomOptionRepositoryInterface::class);
42
47
$ this ->getCustomOptionsValuesForQueryBySku = $ objectManager ->get (GetCustomOptionsValuesForQueryBySku::class);
48
+ $ this ->getEmptyOptionsValuesForQueryBySku = $ objectManager ->get (GetEmptyOptionsValuesForQueryBySku::class);
43
49
}
44
50
45
51
/**
@@ -99,6 +105,58 @@ public function testAddSimpleProductWithMissedRequiredOptionsSet()
99
105
$ this ->graphQlMutation ($ query );
100
106
}
101
107
108
+ /**
109
+ * Test adding a simple product to the shopping cart with Date customizable option assigned
110
+ *
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
+ $ customizableOptionOutput = $ response ['addSimpleProductsToCart ' ]['cart ' ]['items ' ][0 ]['customizable_options ' ][0 ]['values ' ][0 ]['value ' ];
131
+ $ expectedValue = date ("M d, Y " , strtotime ($ customOptionsValues [0 ]['value_string ' ]));
132
+
133
+ self ::assertEquals ($ expectedValue , $ customizableOptionOutput );
134
+ }
135
+
136
+ /**
137
+ * Test adding a simple product with empty values for date option
138
+ *
139
+ * @magentoApiDataFixture Magento/Catalog/_files/product_simple_with_option_date.php
140
+ * @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
141
+ */
142
+ public function testAddSimpleProductWithMissedDateOptionsSet ()
143
+ {
144
+ $ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId ->execute ('test_order_1 ' );
145
+ $ sku = 'simple-product-1 ' ;
146
+ $ quantity = 1 ;
147
+
148
+ $ customOptionsValues = $ this ->getEmptyOptionsValuesForQueryBySku ->execute ($ sku );
149
+ $ queryCustomizableOptionValues = preg_replace ('/"([^"]+)"\s*:\s*/ ' , '$1: ' , json_encode ($ customOptionsValues ));
150
+ $ customizableOptions = "customizable_options: {$ queryCustomizableOptionValues }" ;
151
+ $ query = $ this ->getQuery ($ maskedQuoteId , $ sku , $ quantity , $ customizableOptions );
152
+
153
+ self ::expectExceptionMessage (
154
+ 'Invalid format provided. Please use \'Y-m-d H:i:s \' format. '
155
+ );
156
+
157
+ $ this ->graphQlMutation ($ query );
158
+ }
159
+
102
160
/**
103
161
* @param string $maskedQuoteId
104
162
* @param string $sku
0 commit comments