Skip to content

Commit ba8797a

Browse files
committed
MC-33493: Test render fields in composite configure block for simple and configurable product
1 parent 2dea62c commit ba8797a

File tree

8 files changed

+51
-31
lines changed

8 files changed

+51
-31
lines changed

dev/tests/integration/testsuite/Magento/Catalog/Block/Adminhtml/Product/Composite/Fieldset/OptionsTest.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Magento\Catalog\Model\Product\Option;
1616
use Magento\Catalog\Model\Product\Option\Value;
1717
use Magento\Framework\DataObject;
18+
use Magento\Framework\DataObjectFactory;
1819
use Magento\TestFramework\Helper\Xpath;
1920

2021
/**
@@ -27,6 +28,9 @@ class OptionsTest extends AbstractRenderCustomOptionsTest
2728
/** @var HelperProduct */
2829
private $helperProduct;
2930

31+
/** @var DataObjectFactory */
32+
private $dataObjectFactory;
33+
3034
/**
3135
* @inheritdoc
3236
*/
@@ -35,22 +39,21 @@ protected function setUp(): void
3539
parent::setUp();
3640

3741
$this->helperProduct = $this->objectManager->get(HelperProduct::class);
42+
$this->dataObjectFactory = $this->objectManager->get(DataObjectFactory::class);
3843
}
3944

4045
/**
4146
* @magentoDataFixture Magento/Catalog/_files/product_without_options_with_stock_data.php
42-
* @throws \Magento\Framework\Exception\NoSuchEntityException
4347
* @return void
4448
*/
4549
public function testRenderCustomOptionsWithoutOptions(): void
4650
{
4751
$product = $this->productRepository->get('simple');
48-
$optionHtml = $this->getOptionHtml($product);
4952
$this->assertEquals(
5053
0,
5154
Xpath::getElementsCountForXpath(
5255
"//fieldset[@id='product_composite_configure_fields_options']",
53-
$optionHtml
56+
$this->getOptionHtml($product)
5457
),
5558
'The option block is expected to be empty!'
5659
);
@@ -508,7 +511,7 @@ protected function addOptionToProduct(
508511
: $optionValueObject->getOptionTypeId();
509512
}
510513
/** @var DataObject $request */
511-
$buyRequest = $this->objectManager->create(DataObject::class);
514+
$buyRequest = $this->dataObjectFactory->create();
512515
$buyRequest->setData([
513516
'qty' => 1,
514517
'options' => [$option->getId() => $optionValue],
@@ -546,7 +549,7 @@ protected function additionalTypeTextAsserts(
546549

547550
if (isset($checkArray['equals_xpath'])) {
548551
foreach ($checkArray['equals_xpath'] as $key => $value) {
549-
$value['args'] = $key == 'control_price_attribute' ? [(float)$option->getPrice()] : [];
552+
$value['args'] = $key === 'control_price_attribute' ? [(float)$option->getPrice()] : [];
550553
$this->assertEqualsXpath($option, $optionHtml, $value);
551554
}
552555
}
@@ -572,12 +575,12 @@ protected function additionalTypeSelectAsserts(
572575
/**
573576
* @inheritdoc
574577
*/
575-
protected function getHandlesList(ProductInterface $product): array
578+
protected function getHandlesList(): array
576579
{
577580
return [
578581
'default',
579582
'CATALOG_PRODUCT_COMPOSITE_CONFIGURE',
580-
'catalog_product_view_type_' . $product->getTypeId(),
583+
'catalog_product_view_type_simple',
581584
];
582585
}
583586

dev/tests/integration/testsuite/Magento/Catalog/Block/Adminhtml/Product/Composite/Fieldset/QtyTest.php

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Catalog\Api\ProductRepositoryInterface;
1212
use Magento\Catalog\Helper\Product as HelperProduct;
1313
use Magento\Framework\DataObject;
14+
use Magento\Framework\DataObjectFactory;
1415
use Magento\Framework\ObjectManagerInterface;
1516
use Magento\Framework\Registry;
1617
use Magento\Framework\View\LayoutInterface;
@@ -40,17 +41,23 @@ class QtyTest extends TestCase
4041
/** @var HelperProduct */
4142
private $helperProduct;
4243

44+
/** @var DataObjectFactory */
45+
private $dataObjectFactory;
46+
4347
/**
4448
* @inheritdoc
4549
*/
4650
protected function setUp(): void
4751
{
52+
parent::setUp();
53+
4854
$this->objectManager = Bootstrap::getObjectManager();
4955
$this->block = $this->objectManager->get(LayoutInterface::class)->createBlock(Qty::class);
5056
$this->registry = $this->objectManager->get(Registry::class);
5157
$this->productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
5258
$this->productRepository->cleanCache();
5359
$this->helperProduct = $this->objectManager->get(HelperProduct::class);
60+
$this->dataObjectFactory = $this->objectManager->get(DataObjectFactory::class);
5461
}
5562

5663
/**
@@ -60,6 +67,8 @@ protected function tearDown(): void
6067
{
6168
$this->registry->unregister('current_product');
6269
$this->registry->unregister('product');
70+
71+
parent::tearDown();
6372
}
6473

6574
/**
@@ -70,7 +79,11 @@ public function testGetProduct(): void
7079
{
7180
$product = $this->productRepository->get('simple-1');
7281
$this->registerProduct($product);
73-
$this->assertSame($product, $this->block->getProduct());
82+
$this->assertEquals(
83+
$product->getId(),
84+
$this->block->getProduct()->getId(),
85+
'The expected product is missing in the Qty block!'
86+
);
7487
}
7588

7689
/**
@@ -80,12 +93,12 @@ public function testGetProduct(): void
8093
* @param int $qty
8194
* @return void
8295
*/
83-
public function testGetQtyValue(bool $isQty, int $qty): void
96+
public function testGetQtyValue(bool $isQty = false, int $qty = 1): void
8497
{
8598
$product = $this->productRepository->get('simple-1');
8699
if ($isQty) {
87100
/** @var DataObject $request */
88-
$buyRequest = $this->objectManager->create(DataObject::class);
101+
$buyRequest = $this->dataObjectFactory->create();
89102
$buyRequest->setData(['qty' => $qty]);
90103
$this->helperProduct->prepareProductOptions($product, $buyRequest);
91104
}
@@ -105,10 +118,7 @@ public function getQtyValueProvider(): array
105118
'is_qty' => true,
106119
'qty' => 5,
107120
],
108-
'without_qty' => [
109-
'is_qty' => false,
110-
'qty' => 1,
111-
],
121+
'without_qty' => [],
112122
];
113123
}
114124

dev/tests/integration/testsuite/Magento/Catalog/Block/Adminhtml/Product/Composite/FieldsetTest.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,10 @@ public function testRenderHtml(): void
7373
{
7474
$product = $this->productRepository->get('simple');
7575
$this->registerProduct($product);
76-
$this->preparePage($product->getTypeId());
77-
$html = $this->page->getLayout()->getBlock('product.composite.fieldset')->toHtml();
76+
$this->preparePage();
77+
$fieldsetBlock = $this->page->getLayout()->getBlock('product.composite.fieldset');
78+
$this->assertNotFalse($fieldsetBlock, 'Expected fieldset block is missing!');
79+
$html = $fieldsetBlock->toHtml();
7880

7981
$this->assertEquals(
8082
1,
@@ -91,15 +93,14 @@ public function testRenderHtml(): void
9193
/**
9294
* Prepare page layout
9395
*
94-
* @param string $productType
9596
* @return void
9697
*/
97-
private function preparePage(string $productType): void
98+
private function preparePage(): void
9899
{
99100
$this->page->addHandle([
100101
'default',
101102
'CATALOG_PRODUCT_COMPOSITE_CONFIGURE',
102-
'catalog_product_view_type_' . $productType,
103+
'catalog_product_view_type_simple',
103104
]);
104105
$this->page->getLayout()->generateXml();
105106
}

dev/tests/integration/testsuite/Magento/Catalog/Block/Product/View/Options/AbstractRenderCustomOptionsTest.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ protected function setUp(): void
5858
{
5959
$this->objectManager = Bootstrap::getObjectManager();
6060
$this->productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
61+
$this->productRepository->cleanCache();
6162
$this->productCustomOptionFactory = $this->objectManager->get(ProductCustomOptionInterfaceFactory::class);
6263
$this->productCustomOptionValuesFactory = $this->objectManager->get(
6364
ProductCustomOptionValuesInterfaceFactory::class
@@ -376,6 +377,7 @@ protected function getOptionHtml(ProductInterface $product): string
376377
$this->page->getLayout()->generateXml();
377378
/** @var Options $optionsBlock */
378379
$optionsBlock = $this->page->getLayout()->getBlock($this->getOptionsBlockName());
380+
$this->assertNotFalse($optionsBlock);
379381
$optionsBlock->setProduct($product);
380382

381383
return $optionsBlock->toHtml();
@@ -426,21 +428,16 @@ protected function findOptionValueByTitle(
426428
/**
427429
* Return all need handles for load.
428430
*
429-
* @param ProductInterface $product
430431
* @return array
431432
*/
432-
abstract protected function getHandlesList(ProductInterface $product): array;
433+
abstract protected function getHandlesList(): array;
433434

434435
/**
435-
*
436-
*
437436
* @return string
438437
*/
439438
abstract protected function getMaxCharactersCssClass(): string;
440439

441440
/**
442-
*
443-
*
444441
* @return string
445442
*/
446443
abstract protected function getOptionsBlockName(): string;

dev/tests/integration/testsuite/Magento/Catalog/Block/Product/View/Options/RenderOptionsTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
namespace Magento\Catalog\Block\Product\View\Options;
99

10-
use Magento\Catalog\Api\Data\ProductInterface;
11-
1210
/**
1311
* Test cases related to check that simple product custom option renders as expected.
1412
*
@@ -83,7 +81,7 @@ public function testRenderCustomOptionsFromDateGroup(array $optionData, array $c
8381
/**
8482
* @inheritdoc
8583
*/
86-
protected function getHandlesList(ProductInterface $product): array
84+
protected function getHandlesList(): array
8785
{
8886
return [
8987
'default',

dev/tests/integration/testsuite/Magento/ConfigurableProduct/Block/Adminhtml/Product/Composite/Fieldset/ConfigurableTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ protected function setUp(): void
5959
protected function tearDown(): void
6060
{
6161
$this->registry->unregister('product');
62+
63+
parent::tearDown();
6264
}
6365

6466
/**
@@ -71,6 +73,11 @@ public function testGetProduct(): void
7173
$this->registerProduct($product);
7274
$blockProduct = $this->block->getProduct();
7375
$this->assertSame($product, $blockProduct);
76+
$this->assertEquals(
77+
$product->getId(),
78+
$blockProduct->getId(),
79+
'The expected product is missing in the Configurable block!'
80+
);
7481
$this->assertNotNull($blockProduct->getTypeInstance()->getStoreFilter($blockProduct));
7582
}
7683

dev/tests/integration/testsuite/Magento/ConfigurableProduct/Block/Product/View/CustomOptions/RenderOptionsTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
namespace Magento\ConfigurableProduct\Block\Product\View\CustomOptions;
99

10-
use Magento\Catalog\Api\Data\ProductInterface;
1110
use Magento\Catalog\Block\Product\View\Options\AbstractRenderCustomOptionsTest;
1211

1312
/**
@@ -85,7 +84,7 @@ public function testRenderCustomOptionsFromDateGroup(array $optionData, array $c
8584
/**
8685
* @inheritdoc
8786
*/
88-
protected function getHandlesList(ProductInterface $product): array
87+
protected function getHandlesList(): array
8988
{
9089
return [
9190
'default',

dev/tests/integration/testsuite/Magento/ConfigurableProduct/Block/Product/View/Type/ConfigurableTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Attribute\Collection;
1616
use Magento\Framework\Api\SearchCriteriaBuilder;
1717
use Magento\Framework\DataObject;
18+
use Magento\Framework\DataObjectFactory;
1819
use Magento\Framework\ObjectManagerInterface;
1920
use Magento\Framework\Serialize\SerializerInterface;
2021
use Magento\Framework\View\LayoutInterface;
@@ -73,6 +74,9 @@ class ConfigurableTest extends TestCase
7374
*/
7475
private $helperProduct;
7576

77+
/** @var DataObjectFactory */
78+
private $dataObjectFactory;
79+
7680
/**
7781
* @inheritdoc
7882
*/
@@ -89,6 +93,7 @@ protected function setUp(): void
8993
$this->block = $this->objectManager->get(LayoutInterface::class)->createBlock(Configurable::class);
9094
$this->block->setProduct($this->product);
9195
$this->helperProduct = $this->objectManager->get(HelperProduct::class);
96+
$this->dataObjectFactory = $this->objectManager->get(DataObjectFactory::class);
9297
}
9398

9499
/**
@@ -149,7 +154,7 @@ public function testGetJsonConfigWithPreconfiguredValues(): void
149154
$attribute->getAttributeId() => $attribute->getOptions()[0]['value_index'],
150155
];
151156
/** @var DataObject $request */
152-
$buyRequest = $this->objectManager->create(DataObject::class);
157+
$buyRequest = $this->dataObjectFactory->create();
153158
$buyRequest->setData([
154159
'qty' => 1,
155160
'super_attribute' => $expectedAttributeValue,

0 commit comments

Comments
 (0)