Skip to content

Commit 7e822e1

Browse files
committed
MAGETWO-70743: Custom options are not listed in API call
- Extend test to cover all custom options types
1 parent 1b7e4fb commit 7e822e1

File tree

4 files changed

+62
-7
lines changed

4 files changed

+62
-7
lines changed

dev/tests/integration/testsuite/Magento/Catalog/_files/product_with_options.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@
3535
true
3636
)->setStockData(
3737
[
38-
'qty' => 0,
39-
'is_in_stock' => 0
38+
'qty' => 100,
39+
'is_in_stock' => 1
4040
]
41-
);
41+
)->setHasOptions(true);
4242

4343
$options = [
4444
[
@@ -204,4 +204,8 @@
204204
$customOptions[] = $customOption;
205205
}
206206

207-
$product->setOptions($customOptions)->save();
207+
$product->setOptions($customOptions);
208+
209+
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepositoryFactory */
210+
$productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
211+
$productRepository->save($product);
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Checkout\_files;
7+
8+
use Magento\Catalog\Model\Product\Option\Type\File\ValidatorFile;
9+
10+
/**
11+
* Creates mock for ValidatorFile to replace real instance in fixtures.
12+
*/
13+
class ValidatorFileMock extends \PHPUnit_Framework_TestCase
14+
{
15+
/**
16+
* Returns mock.
17+
*
18+
* @return ValidatorFile|\PHPUnit_Framework_MockObject_MockObject
19+
*/
20+
public function getInstance()
21+
{
22+
$userValue = [
23+
'type' => 'image/jpeg',
24+
'title' => "test.jpg",
25+
'quote_path' => "custom_options/quote/s/t/4624d2.jpg",
26+
'order_path' => "custom_options/order/s/t/89d25b4624d2.jpg",
27+
"fullpath" => "pub/media/custom_options/quote/s/t/e47389d25b4624d2.jpg",
28+
"size"=> "71901",
29+
"width" => 5,
30+
"height" => 5,
31+
"secret_key" => "10839ec1631b77e5e473",
32+
];
33+
$instance = $this->getMockBuilder(ValidatorFile::class)
34+
->disableOriginalConstructor()
35+
->getMock();
36+
$instance->method('SetProduct')->willReturnSelf();
37+
$instance->method('validate')->willReturn($userValue);
38+
39+
return $instance;
40+
}
41+
}

dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_items_and_custom_options_saved.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44
* See COPYING.txt for license details.
55
*/
66

7+
use Magento\Checkout\_files\ValidatorFileMock;
8+
79
require __DIR__ . '/../../Checkout/_files/quote_with_address.php';
8-
require __DIR__ . '/../../Catalog/_files/product_simple.php';
10+
require __DIR__ . '/../../Catalog/_files/product_with_options.php';
11+
require __DIR__ . '/../../Checkout/_files/ValidatorFileMock.php';
912

1013
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
1114
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
@@ -22,6 +25,9 @@
2225
case \Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_GROUP_SELECT:
2326
$value = key($option->getValues());
2427
break;
28+
case \Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_GROUP_FILE:
29+
$value = 'test.jpg';
30+
break;
2531
default:
2632
$value = 'test';
2733
break;
@@ -30,9 +36,12 @@
3036
}
3137

3238
$requestInfo = new \Magento\Framework\DataObject(['qty' => 1, 'options' => $options]);
39+
$validatorFile = (new ValidatorFileMock())->getInstance();
40+
$objectManager->addSharedInstance($validatorFile, \Magento\Catalog\Model\Product\Option\Type\File\ValidatorFile::class);
41+
3342

34-
$quote->setReservedOrderId('test_order_item_with_items_and_custom_options')
35-
->addProduct($product, $requestInfo);
43+
$quote->setReservedOrderId('test_order_item_with_items_and_custom_options');
44+
$quote->addProduct($product, $requestInfo);
3645
$quote->collectTotals();
3746
$objectManager->get(\Magento\Quote\Model\QuoteRepository::class)->save($quote);
3847

dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_items_and_custom_options_saved_rollback.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* See COPYING.txt for license details.
55
*/
66
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
7+
$objectManager->removeSharedInstance(\Magento\Catalog\Model\Product\Option\Type\File\ValidatorFile::class);
78

89
/** @var \Magento\Quote\Model\Quote $quote */
910
$quote = $objectManager->create(\Magento\Quote\Model\Quote::class);

0 commit comments

Comments
 (0)