Skip to content

Commit f45d97f

Browse files
committed
31075-added type to CustomizableDateValue for detect from one of three types
1 parent f6c4e1c commit f45d97f

File tree

2 files changed

+135
-0
lines changed

2 files changed

+135
-0
lines changed

app/code/Magento/CatalogGraphQl/etc/schema.graphqls

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ type CustomizableDateOption implements CustomizableOptionInterface @doc(descript
153153
type CustomizableDateValue @doc(description: "CustomizableDateValue defines the price and sku of a product whose page contains a customized date picker.") {
154154
price: Float @doc(description: "The price assigned to this option.")
155155
price_type: PriceTypeEnum @doc(description: "FIXED, PERCENT, or DYNAMIC.")
156+
type: String @doc(description: "date, date_time or time")
156157
sku: String @doc(description: "The Stock Keeping Unit for this option.")
157158
uid: ID! @doc(description: "A string that encodes option details.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\CustomizableEnteredOptionValueUid") # A Base64 string that encodes option details.
158159
}
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\GraphQl\Catalog\Options\Uid;
9+
10+
use Exception;
11+
use Magento\TestFramework\Helper\Bootstrap;
12+
use Magento\TestFramework\Helper\CompareArraysRecursively;
13+
use Magento\TestFramework\TestCase\GraphQlAbstract;
14+
15+
/**
16+
* Test for customizable product options.
17+
*/
18+
class CustomizableOptionsTest extends GraphQlAbstract
19+
{
20+
/**
21+
* @var CompareArraysRecursively
22+
*/
23+
private $compareArraysRecursively;
24+
25+
/**
26+
* @inheritDoc
27+
*/
28+
protected function setUp(): void
29+
{
30+
$objectManager = Bootstrap::getObjectManager();
31+
$this->compareArraysRecursively = $objectManager->create(CompareArraysRecursively::class);
32+
}
33+
34+
/**
35+
* @magentoApiDataFixture Magento/Catalog/_files/product_with_options.php
36+
*
37+
* @param array $optionDataProvider
38+
*
39+
* @dataProvider getProductCustomizableOptionsProvider
40+
* @throws Exception
41+
*/
42+
public function testQueryCustomizableOptions(array $optionDataProvider): void
43+
{
44+
$productSku = 'simple';
45+
$query = $this->getQuery($productSku);
46+
$response = $this->graphQlQuery($query);
47+
$responseProduct = reset($response['products']['items']);
48+
self::assertNotEmpty($responseProduct['options']);
49+
50+
foreach ($optionDataProvider as $key => $data) {
51+
$this->compareArraysRecursively->execute($data, $responseProduct[$key]);
52+
}
53+
}
54+
55+
/**
56+
* Get query.
57+
*
58+
* @param string $sku
59+
*
60+
* @return string
61+
*/
62+
private function getQuery(string $sku): string
63+
{
64+
return <<<QUERY
65+
query {
66+
products(filter: { sku: { eq: "$sku" } }) {
67+
items {
68+
... on CustomizableProductInterface {
69+
options {
70+
option_id
71+
title
72+
... on CustomizableDateOption {
73+
value {
74+
type
75+
}
76+
}
77+
}
78+
}
79+
}
80+
}
81+
}
82+
QUERY;
83+
}
84+
85+
/**
86+
* Get product customizable options provider.
87+
*
88+
* @return array
89+
*/
90+
public function getProductCustomizableOptionsProvider(): array
91+
{
92+
return [
93+
'products' => [
94+
'items' => [
95+
'options' => [
96+
[
97+
'title' => 'test_option_code_1'
98+
],
99+
[
100+
'title' => 'area option'
101+
],
102+
[
103+
'title' => 'file option'
104+
],
105+
[
106+
'title' => 'radio option'
107+
],
108+
[
109+
'title' => 'multiple option'
110+
],
111+
[
112+
'title' => 'date option',
113+
'values' => [
114+
'type' => 'date'
115+
]
116+
],
117+
[
118+
'title' => 'date_time option',
119+
'values' => [
120+
'type' => 'date_time'
121+
]
122+
],
123+
[
124+
'title' => 'time option',
125+
'values' => [
126+
'type' => 'time'
127+
]
128+
]
129+
]
130+
]
131+
]
132+
];
133+
}
134+
}

0 commit comments

Comments
 (0)