Skip to content

Commit 0ee1c6c

Browse files
[Magento Community Engineering] Community Contributions - 2.4-develop
- merged latest code from mainline branch
2 parents 21ac7c7 + 72f253e commit 0ee1c6c

File tree

60 files changed

+5095
-482
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+5095
-482
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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\TestFramework\Core\Version;
9+
10+
/**
11+
* Class for magento version flag.
12+
*/
13+
class View
14+
{
15+
/**
16+
* Returns flag that checks that magento version is clean community version.
17+
*
18+
* @return bool
19+
*/
20+
public function isVersionUpdated(): bool
21+
{
22+
return false;
23+
}
24+
}

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

Lines changed: 621 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
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\Catalog\Block\Adminhtml\Product\Composite\Fieldset;
9+
10+
use Magento\Catalog\Api\Data\ProductInterface;
11+
use Magento\Catalog\Api\ProductRepositoryInterface;
12+
use Magento\Catalog\Helper\Product as HelperProduct;
13+
use Magento\Framework\DataObject;
14+
use Magento\Framework\DataObjectFactory;
15+
use Magento\Framework\ObjectManagerInterface;
16+
use Magento\Framework\Registry;
17+
use Magento\Framework\View\LayoutInterface;
18+
use Magento\TestFramework\Helper\Bootstrap;
19+
use PHPUnit\Framework\TestCase;
20+
21+
/**
22+
* Test Qty block in composite product configuration layout
23+
*
24+
* @see \Magento\Catalog\Block\Adminhtml\Product\Composite\Fieldset\Qty
25+
* @magentoAppArea adminhtml
26+
*/
27+
class QtyTest extends TestCase
28+
{
29+
/** @var ObjectManagerInterface */
30+
private $objectManager;
31+
32+
/** @var Qty */
33+
private $block;
34+
35+
/** @var ProductRepositoryInterface */
36+
private $productRepository;
37+
38+
/** @var Registry */
39+
private $registry;
40+
41+
/** @var HelperProduct */
42+
private $helperProduct;
43+
44+
/** @var DataObjectFactory */
45+
private $dataObjectFactory;
46+
47+
/**
48+
* @inheritdoc
49+
*/
50+
protected function setUp(): void
51+
{
52+
parent::setUp();
53+
54+
$this->objectManager = Bootstrap::getObjectManager();
55+
$this->block = $this->objectManager->get(LayoutInterface::class)->createBlock(Qty::class);
56+
$this->registry = $this->objectManager->get(Registry::class);
57+
$this->productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
58+
$this->productRepository->cleanCache();
59+
$this->helperProduct = $this->objectManager->get(HelperProduct::class);
60+
$this->dataObjectFactory = $this->objectManager->get(DataObjectFactory::class);
61+
}
62+
63+
/**
64+
* @inheritdoc
65+
*/
66+
protected function tearDown(): void
67+
{
68+
$this->registry->unregister('current_product');
69+
$this->registry->unregister('product');
70+
71+
parent::tearDown();
72+
}
73+
74+
/**
75+
* @magentoDataFixture Magento/Catalog/_files/product_simple_duplicated.php
76+
* @return void
77+
*/
78+
public function testGetProduct(): void
79+
{
80+
$product = $this->productRepository->get('simple-1');
81+
$this->registerProduct($product);
82+
$this->assertEquals(
83+
$product->getId(),
84+
$this->block->getProduct()->getId(),
85+
'The expected product is missing in the Qty block!'
86+
);
87+
}
88+
89+
/**
90+
* @magentoDataFixture Magento/Catalog/_files/product_simple_duplicated.php
91+
* @dataProvider getQtyValueProvider
92+
* @param bool $isQty
93+
* @param int $qty
94+
* @return void
95+
*/
96+
public function testGetQtyValue(bool $isQty = false, int $qty = 1): void
97+
{
98+
$product = $this->productRepository->get('simple-1');
99+
if ($isQty) {
100+
/** @var DataObject $request */
101+
$buyRequest = $this->dataObjectFactory->create();
102+
$buyRequest->setData(['qty' => $qty]);
103+
$this->helperProduct->prepareProductOptions($product, $buyRequest);
104+
}
105+
$this->registerProduct($product);
106+
$this->assertEquals($qty, $this->block->getQtyValue(), 'Expected block qty value is incorrect!');
107+
}
108+
109+
/**
110+
* Provides test data to verify block qty value.
111+
*
112+
* @return array
113+
*/
114+
public function getQtyValueProvider(): array
115+
{
116+
return [
117+
'with_qty' => [
118+
'is_qty' => true,
119+
'qty' => 5,
120+
],
121+
'without_qty' => [],
122+
];
123+
}
124+
125+
/**
126+
* Register the product
127+
*
128+
* @param ProductInterface $product
129+
* @return void
130+
*/
131+
private function registerProduct(ProductInterface $product): void
132+
{
133+
$this->registry->unregister('current_product');
134+
$this->registry->unregister('product');
135+
$this->registry->register('current_product', $product);
136+
$this->registry->register('product', $product);
137+
}
138+
}
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
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\Catalog\Block\Adminhtml\Product\Composite;
9+
10+
use Magento\Backend\Model\View\Result\Page;
11+
use Magento\Catalog\Api\Data\ProductInterface;
12+
use Magento\Catalog\Api\ProductRepositoryInterface;
13+
use Magento\Framework\ObjectManagerInterface;
14+
use Magento\Framework\Registry;
15+
use Magento\Framework\View\Result\PageFactory;
16+
use Magento\TestFramework\Helper\Bootstrap;
17+
use Magento\TestFramework\Helper\Xpath;
18+
use PHPUnit\Framework\TestCase;
19+
20+
/**
21+
* Test Fieldset block in composite product configuration layout
22+
*
23+
* @see \Magento\Catalog\Block\Adminhtml\Product\Composite\Fieldset
24+
* @magentoAppArea adminhtml
25+
*/
26+
class FieldsetTest extends TestCase
27+
{
28+
/** @var ObjectManagerInterface */
29+
private $objectManager;
30+
31+
/** @var Page */
32+
private $page;
33+
34+
/** @var Registry */
35+
private $registry;
36+
37+
/** @var ProductRepositoryInterface */
38+
private $productRepository;
39+
40+
/** @var string */
41+
private $fieldsetXpath = "//fieldset[@id='product_composite_configure_fields_%s']";
42+
43+
/**
44+
* @inheritdoc
45+
*/
46+
protected function setUp(): void
47+
{
48+
parent::setUp();
49+
50+
$this->objectManager = Bootstrap::getObjectManager();
51+
$this->page = $this->objectManager->get(PageFactory::class)->create();
52+
$this->registry = $this->objectManager->get(Registry::class);
53+
$this->productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
54+
$this->productRepository->cleanCache();
55+
}
56+
57+
/**
58+
* @inheritdoc
59+
*/
60+
protected function tearDown(): void
61+
{
62+
$this->registry->unregister('current_product');
63+
$this->registry->unregister('product');
64+
65+
parent::tearDown();
66+
}
67+
68+
/**
69+
* @magentoDataFixture Magento/Catalog/_files/product_simple_with_options.php
70+
* @return void
71+
*/
72+
public function testRenderHtml(): void
73+
{
74+
$product = $this->productRepository->get('simple');
75+
$this->registerProduct($product);
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();
80+
81+
$this->assertEquals(
82+
1,
83+
Xpath::getElementsCountForXpath(sprintf($this->fieldsetXpath, 'options'), $html),
84+
'Expected options block is missing!'
85+
);
86+
$this->assertEquals(
87+
1,
88+
Xpath::getElementsCountForXpath(sprintf($this->fieldsetXpath, 'qty'), $html),
89+
'Expected qty block is missing!'
90+
);
91+
}
92+
93+
/**
94+
* Prepare page layout
95+
*
96+
* @return void
97+
*/
98+
private function preparePage(): void
99+
{
100+
$this->page->addHandle([
101+
'default',
102+
'CATALOG_PRODUCT_COMPOSITE_CONFIGURE',
103+
'catalog_product_view_type_simple',
104+
]);
105+
$this->page->getLayout()->generateXml();
106+
}
107+
108+
/**
109+
* Register the product
110+
*
111+
* @param ProductInterface $product
112+
* @return void
113+
*/
114+
private function registerProduct(ProductInterface $product): void
115+
{
116+
$this->registry->unregister('current_product');
117+
$this->registry->unregister('product');
118+
$this->registry->register('current_product', $product);
119+
$this->registry->register('product', $product);
120+
}
121+
}

0 commit comments

Comments
 (0)