This commit is contained in:
2026-09-15 10:26:34 +08:00
commit ecf36afa56
10493 changed files with 1404888 additions and 0 deletions
@@ -0,0 +1,37 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Bundle\Block\Adminhtml\Catalog\Product\Edit\Tab\Bundle\Option\Search;
class GridTest extends \PHPUnit\Framework\TestCase
{
/**
* @magentoAppIsolation enabled
*/
public function testToHtmlHasOnClick()
{
\Magento\TestFramework\Helper\Bootstrap::getInstance()
->loadArea(\Magento\Backend\App\Area\FrontNameResolver::AREA_CODE);
/** @var $layout \Magento\Framework\View\LayoutInterface */
$layout = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
\Magento\Framework\View\Layout::class,
['area' => \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE]
);
$block = $layout->createBlock(
\Magento\Bundle\Block\Adminhtml\Catalog\Product\Edit\Tab\Bundle\Option\Search\Grid::class,
'block'
);
$block->setId('temp_id');
$html = $block->toHtml();
$regexpTemplate = '/\<script.*?\>.*?temp_id[^"]*\\.%s/is';
$jsFuncs = ['doFilter', 'resetFilter'];
foreach ($jsFuncs as $func) {
$regexp = sprintf($regexpTemplate, $func);
$this->assertMatchesRegularExpression($regexp, $html);
}
}
}
@@ -0,0 +1,31 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Bundle\Block\Adminhtml\Catalog\Product\Edit\Tab\Bundle\Option;
class SearchTest extends \PHPUnit\Framework\TestCase
{
/**
* @magentoAppIsolation enabled
* @magentoAppArea adminhtml
*/
public function testToHtmlHasIndex()
{
/** @var $layout \Magento\Framework\View\LayoutInterface */
$layout = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
\Magento\Framework\View\Layout::class
);
$block = $layout->createBlock(
\Magento\Bundle\Block\Adminhtml\Catalog\Product\Edit\Tab\Bundle\Option\Search::class,
'block2'
);
$indexValue = 'magento_index_set_to_test';
$block->setIndex($indexValue);
$html = $block->toHtml();
$this->assertStringContainsString($indexValue, $html);
}
}
@@ -0,0 +1,194 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Bundle\Block\Catalog\Product\View\Type;
use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Catalog\Model\ResourceModel\Product as ProductResource;
use Magento\Framework\ObjectManagerInterface;
use Magento\Framework\Registry;
use Magento\Framework\Serialize\SerializerInterface;
use Magento\Framework\View\Result\PageFactory;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\Helper\Xpath;
use PHPUnit\Framework\TestCase;
/**
* Class consist of basic logic for bundle options view
*/
abstract class AbstractBundleOptionsViewTest extends TestCase
{
/** @var ObjectManagerInterface */
private $objectManager;
/** @var ProductRepositoryInterface */
private $productRepository;
/** @var SerializerInterface */
private $serializer;
/** @var Registry */
private $registry;
/** @var PageFactory */
private $pageFactory;
/** @var ProductResource */
private $productResource;
/** @var string */
private $selectLabelXpath = "//fieldset[contains(@class, 'fieldset-bundle-options')]"
. "//label/span[normalize-space(text()) = '%s']";
/** @var string */
private $backToProductDetailButtonXpath = "//button[contains(@class, 'back customization')]";
/** @var string */
private $titleXpath = "//fieldset[contains(@class, 'bundle-options')]//span[contains(text(), 'Customize %s')]";
/** @var string */
private $singleOptionXpath = "//input[contains(@class, 'bundle-option') and contains(@type, 'hidden')]";
/**
* @inheritdoc
*/
protected function setUp(): void
{
parent::setUp();
$this->objectManager = Bootstrap::getObjectManager();
$this->productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
$this->productRepository->cleanCache();
$this->serializer = $this->objectManager->get(SerializerInterface::class);
$this->registry = $this->objectManager->get(Registry::class);
$this->pageFactory = $this->objectManager->get(PageFactory::class);
$this->productResource = $this->objectManager->get(ProductResource::class);
}
/**
* @inheritdoc
*/
protected function tearDown(): void
{
$this->registry->unregister('product');
$this->registry->unregister('current_product');
parent::tearDown();
}
/**
* Process bundle options view with few selections
*
* @param string $sku
* @param string $optionsSelectLabel
* @param array $expectedSelectionsNames
* @param bool $requiredOption
* @return void
*/
protected function processMultiSelectionsView(
string $sku,
string $optionsSelectLabel,
array $expectedSelectionsNames,
bool $requiredOption = false
): void {
$product = $this->productRepository->get($sku);
$result = $this->renderProductOptionsBlock($product);
$this->assertEquals(
1,
Xpath::getElementsCountForXpath($this->backToProductDetailButtonXpath, $result),
"'Back to product details' button doesn't exist on the page"
);
$this->assertEquals(
1,
Xpath::getElementsCountForXpath(sprintf($this->selectLabelXpath, $optionsSelectLabel), $result),
'Options select label does not exist on the page'
);
$this->assertEquals(
1,
Xpath::getElementsCountForXpath(sprintf($this->titleXpath, $product->getName()), $result),
sprintf('Customize %s label does not exist on the page', $product->getName())
);
$selectPath = $requiredOption ? $this->getRequiredSelectXpath() : $this->getNotRequiredSelectXpath();
foreach ($expectedSelectionsNames as $selection) {
$this->assertEquals(
1,
Xpath::getElementsCountForXpath(sprintf($selectPath, $selection), $result),
sprintf('Option for product named %s does not exist on the page', $selection)
);
}
}
/**
* Process bundle options view with single selection
*
* @param string $sku
* @param string $optionsSelectLabel
* @return void
*/
protected function processSingleSelectionView(string $sku, string $optionsSelectLabel): void
{
$product = $this->productRepository->get($sku);
$result = $this->renderProductOptionsBlock($product);
$this->assertEquals(1, Xpath::getElementsCountForXpath($this->backToProductDetailButtonXpath, $result));
$this->assertEquals(
1,
Xpath::getElementsCountForXpath(sprintf($this->selectLabelXpath, $optionsSelectLabel), $result),
'Options select label does not exist on the page'
);
$this->assertEquals(
1,
Xpath::getElementsCountForXpath($this->singleOptionXpath, $result),
'Bundle product options select with single option does not display correctly'
);
}
/**
* Register product
*
* @param ProductInterface $product
* @return void
*/
private function registerProduct(ProductInterface $product): void
{
$this->registry->unregister('product');
$this->registry->unregister('current_product');
$this->registry->register('product', $product);
$this->registry->register('current_product', $product);
}
/**
* Render bundle product options block
*
* @param ProductInterface $product
* @return string
*/
private function renderProductOptionsBlock(ProductInterface $product): string
{
$this->registerProduct($product);
$page = $this->pageFactory->create();
$page->addHandle(['default', 'catalog_product_view', 'catalog_product_view_type_bundle']);
$page->getLayout()->generateXml();
$block = $page->getLayout()->getBlock('product.info.bundle.options');
return $block->toHtml();
}
/**
* Get required select Xpath
*
* @return string
*/
abstract protected function getRequiredSelectXpath(): string;
/**
* Get not required select Xpath
*
* @return string
*/
abstract protected function getNotRequiredSelectXpath(): string;
}
@@ -0,0 +1,172 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Bundle\Block\Catalog\Product\View\Type;
use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Framework\ObjectManagerInterface;
use Magento\Framework\Registry;
use Magento\Framework\Serialize\SerializerInterface;
use Magento\Framework\View\LayoutInterface;
use Magento\TestFramework\Helper\Bootstrap;
use PHPUnit\Framework\TestCase;
/**
* Check bundle product prices.
*
* @magentoDbIsolation enabled
* @magentoAppIsolation disabled
* @magentoAppArea frontend
*/
class BundleProductPriceTest extends TestCase
{
/** @var ObjectManagerInterface */
private $objectManager;
/** @var Registry */
private $registry;
/** @var ProductRepositoryInterface */
private $productRepository;
/** @var SerializerInterface */
private $json;
/** @var Bundle */
private $block;
/**
* @inheritdoc
*/
protected function setUp(): void
{
parent::setUp();
$this->objectManager = Bootstrap::getObjectManager();
$this->productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
$this->productRepository->cleanCache();
$this->block = $this->objectManager->get(LayoutInterface::class)->createBlock(Bundle::class);
$this->registry = $this->objectManager->get(Registry::class);
$this->json = $this->objectManager->get(SerializerInterface::class);
}
/**
* @inheritdoc
*/
protected function tearDown(): void
{
$this->registry->unregister('product');
parent::tearDown();
}
/**
* @magentoDataFixture Magento/Bundle/_files/dynamic_bundle_product_multiselect_option.php
*
* @return void
*/
public function testDynamicBundleOptionPrices(): void
{
$expectedData = [
'options_prices' => [
[
'oldPrice' => ['amount' => 10],
'basePrice' => ['amount' => 10],
'finalPrice' => ['amount' => 10],
],
[
'oldPrice' => ['amount' => 20],
'basePrice' => ['amount' => 20],
'finalPrice' => ['amount' => 20],
],
[
'oldPrice' => ['amount' => 30],
'basePrice' => ['amount' => 30],
'finalPrice' => ['amount' => 30],
],
],
'bundle_prices' => [
'oldPrice' => ['amount' => 0],
'basePrice' => ['amount' => 0],
'finalPrice' => ['amount' => 0],
]
];
$this->processBundlePriceView('bundle_product', $expectedData);
}
/**
* @magentoDataFixture Magento/Bundle/_files/product_with_multiple_options_1.php
*
* @return void
*/
public function testFixedBundleOptionPrices(): void
{
$expectedData = [
'options_prices' => [
[
'oldPrice' => ['amount' => 2.75],
'basePrice' => ['amount' => 2.75],
'finalPrice' => ['amount' => 2.75],
],
[
'oldPrice' => ['amount' => 6.75],
'basePrice' => ['amount' => 6.75],
'finalPrice' => ['amount' => 6.75],
],
],
'bundle_prices' => [
'oldPrice' => ['amount' => 12.75],
'basePrice' => ['amount' => 10],
'finalPrice' => ['amount' => 10],
]
];
$this->processBundlePriceView('bundle-product', $expectedData);
}
/**
* @param string $productSku
* @param array $expectedData
* @return void
*/
private function processBundlePriceView(string $productSku, array $expectedData): void
{
$this->registerProduct($productSku);
$jsonConfig = $this->json->unserialize($this->block->getJsonConfig());
$this->assertEquals($expectedData['bundle_prices'], $jsonConfig['prices']);
$this->assertOptionsConfig($expectedData['options_prices'], $jsonConfig);
}
/**
* Assert options prices.
*
* @param array $expectedData
* @param array $actualData
* @return void
*/
private function assertOptionsConfig(array $expectedData, array $actualData): void
{
$optionConfig = $actualData['options'] ?? null;
$this->assertNotNull($optionConfig);
$optionConfig = reset($optionConfig);
foreach (array_values($optionConfig['selections']) as $key => $selection) {
$this->assertEquals($expectedData[$key], $selection['prices']);
}
}
/**
* Register the product.
*
* @param string $productSku
* @return void
*/
private function registerProduct(string $productSku): void
{
$product = $this->productRepository->get($productSku);
$this->registry->unregister('product');
$this->registry->register('product', $product);
}
}
@@ -0,0 +1,211 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Bundle\Block\Catalog\Product\View\Type;
use Magento\Bundle\Model\Product\Price;
use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Framework\ObjectManagerInterface;
use Magento\Framework\Registry;
use Magento\Framework\Serialize\SerializerInterface;
use Magento\Framework\View\LayoutInterface;
use Magento\TestFramework\Helper\Bootstrap;
use PHPUnit\Framework\TestCase;
/**
* Class checks bundle product view behaviour
*
* @magentoDataFixture Magento/Bundle/_files/product.php
* @magentoDbIsolation enabled
* @magentoAppArea frontend
* @see \Magento\Bundle\Block\Catalog\Product\View\Type\Bundle
*/
class BundleTest extends TestCase
{
/** @var Bundle */
private $block;
/** @var ObjectManagerInterface */
private $objectManager;
/** @var ProductRepositoryInterface */
private $productRepository;
/** @var LayoutInterface */
private $layout;
/** @var SerializerInterface */
private $json;
/** @var Registry */
private $registry;
/**
* @inheritdoc
*/
protected function setUp(): void
{
$this->objectManager = Bootstrap::getObjectManager();
$this->productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
$this->productRepository->cleanCache();
$this->layout = $this->objectManager->get(LayoutInterface::class);
$this->block = $this->layout->createBlock(Bundle::class);
$this->json = $this->objectManager->get(SerializerInterface::class);
$this->registry = $this->objectManager->get(Registry::class);
}
/**
* @inheritdoc
*/
protected function tearDown(): void
{
$this->registry->unregister('product');
parent::tearDown();
}
/**
* Test for method \Magento\Bundle\Block\Catalog\Product\View\Type\Bundle::getJsonConfig
*
* @return void
*/
public function testGetJsonConfig(): void
{
$product = $this->updateProduct('bundle-product', ['price_type' => Price::PRICE_TYPE_DYNAMIC]);
$this->registerProduct($product);
$this->updateProduct('simple', ['special_price' => 5]);
$config = $this->json->unserialize($this->block->getJsonConfig());
$options = current($config['options']);
$selection = current($options['selections']);
$this->assertEquals(10, $selection['prices']['oldPrice']['amount']);
$this->assertEquals(5, $selection['prices']['basePrice']['amount']);
$this->assertEquals(5, $selection['prices']['finalPrice']['amount']);
}
/**
* @dataProvider isSalableForStockStatusProvider
*
* @param bool $isSalable
* @param string $expectedValue
* @return void
*/
public function testStockStatusView(bool $isSalable, string $expectedValue): void
{
$product = $this->productRepository->get('bundle-product');
$product->setIsSalable($isSalable);
$this->block->setTemplate('Magento_Bundle::catalog/product/view/type/bundle.phtml');
$result = $this->renderBlockHtml($product);
$this->assertEquals($expectedValue, trim(strip_tags($result)));
}
/**
* @return array
*/
public function isSalableForStockStatusProvider(): array
{
return [
'is_salable' => [
'is_salable' => true,
'expected_value' => 'In stock',
],
'is_not_salable' => [
'is_salable' => false,
'expected_value' => 'Out of stock',
],
];
}
/**
* @dataProvider isSalableForCustomizeButtonProvider
*
* @param bool $isSalable
* @param string $expectedValue
* @return void
*/
public function testCustomizeButton(bool $isSalable, string $expectedValue): void
{
$product = $this->productRepository->get('bundle-product');
$product->setSalable($isSalable);
$this->block->setTemplate('Magento_Bundle::catalog/product/view/customize.phtml');
$result = $this->renderBlockHtml($product);
$this->assertEquals($expectedValue, trim(strip_tags($result)));
}
/**
* @return array
*/
public function isSalableForCustomizeButtonProvider(): array
{
return [
'is_salable' => [
'is_salable' => true,
'expected_value' => 'Customize and Add to Cart',
],
'is_not_salable' => [
'is_salable' => false,
'expected_value' => '',
],
];
}
/**
* @magentoDataFixture Magento/Bundle/_files/empty_bundle_product.php
*
* @param bool $isSalable
* @param string $expectedValue
* @return void
*/
public function testCustomizeButtonProductWithoutOptions(): void
{
$product = $this->productRepository->get('bundle-product');
$product->setSalable(true);
$this->block->setTemplate('Magento_Bundle::catalog/product/view/customize.phtml');
$result = $this->renderBlockHtml($product);
$this->assertEmpty(trim(strip_tags($result)));
}
/**
* Update product
*
* @param ProductInterface|string $productSku
* @param array $data
* @return ProductInterface
*/
private function updateProduct(string $productSku, array $data): ProductInterface
{
$product = $this->productRepository->get($productSku);
$product->addData($data);
return $this->productRepository->save($product);
}
/**
* Register product
*
* @param ProductInterface $product
* @return void
*/
private function registerProduct(ProductInterface $product): void
{
$this->registry->unregister('product');
$this->registry->register('product', $product);
}
/**
* Render block output
*
* @param ProductInterface $product
* @return string
*/
private function renderBlockHtml(ProductInterface $product): string
{
$this->registerProduct($product);
return $this->block->toHtml();
}
}
@@ -0,0 +1,77 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Bundle\Block\Catalog\Product\View\Type;
/**
* Class checks checkbox bundle options appearance
*
* @magentoAppArea frontend
* @magentoAppIsolation enabled
* @magentoDbIsolation enabled
*/
class CheckboxOptionViewTest extends AbstractBundleOptionsViewTest
{
/**
* @magentoDataFixture Magento/Bundle/_files/bundle_product_checkbox_options.php
*
* @return void
*/
public function testNotRequiredSelectMultiSelectionsView(): void
{
$expectedSelectionsNames = ['Simple Product', 'Simple Product2'];
$this->processMultiSelectionsView(
'bundle-product-checkbox-options',
'Checkbox Options',
$expectedSelectionsNames
);
}
/**
* @magentoDataFixture Magento/Bundle/_files/bundle_product_checkbox_required_options.php
*
* @return void
*/
public function testRequiredSelectMultiSelectionsView(): void
{
$expectedSelectionsNames = ['Simple Product', 'Simple Product2'];
$this->processMultiSelectionsView(
'bundle-product-checkbox-required-options',
'Checkbox Options',
$expectedSelectionsNames,
true
);
}
/**
* @magentoDataFixture Magento/Bundle/_files/bundle_product_checkbox_required_option.php
*
* @return void
*/
public function testShowSingle(): void
{
$this->processSingleSelectionView('bundle-product-checkbox-required-option', 'Checkbox Options');
}
/**
* @inheritdoc
*/
protected function getRequiredSelectXpath(): string
{
return "//input[@type='checkbox' and contains(@data-validate, 'validate-one-required-by-name')"
. "and contains(@class, 'bundle-option')]/../label//span[normalize-space(text()) = '1 x %s']";
}
/**
* @inheritdoc
*/
protected function getNotRequiredSelectXpath(): string
{
return "//input[@type='checkbox' and not(contains(@data-validate, 'validate-one-required-by-name'))"
. "and contains(@class, 'bundle-option')]/../label//span[normalize-space(text()) = '1 x %s']";
}
}
@@ -0,0 +1,77 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Bundle\Block\Catalog\Product\View\Type;
/**
* Class checks dropdown bundle options appearance
*
* @magentoAppArea frontend
* @magentoAppIsolation enabled
* @magentoDbIsolation enabled
*/
class DropDownOptionViewTest extends AbstractBundleOptionsViewTest
{
/**
* @magentoDataFixture Magento/Bundle/_files/bundle_product_dropdown_options.php
*
* @return void
*/
public function testNotRequiredSelectMultiSelectionsView(): void
{
$expectedSelectionsNames = ['Simple Product', 'Simple Product2'];
$this->processMultiSelectionsView(
'bundle-product-dropdown-options',
'Dropdown Options',
$expectedSelectionsNames
);
}
/**
* @magentoDataFixture Magento/Bundle/_files/bundle_product_dropdown_required_options.php
*
* @return void
*/
public function testRequiredSelectMultiSelectionsView(): void
{
$expectedSelectionsNames = ['Simple Product', 'Simple Product2'];
$this->processMultiSelectionsView(
'bundle-product-dropdown-required-options',
'Dropdown Options',
$expectedSelectionsNames,
true
);
}
/**
* @magentoDataFixture Magento/Bundle/_files/product.php
*
* @return void
*/
public function testShowSingle(): void
{
$this->processSingleSelectionView('bundle-product', 'Bundle Product Items');
}
/**
* @inheritdoc
*/
protected function getRequiredSelectXpath(): string
{
return "//select[contains(@id, 'bundle-option') and contains(@data-validate, 'required:true')]"
. "/option/span[normalize-space(text()) = '%s']";
}
/**
* @inheritdoc
*/
protected function getNotRequiredSelectXpath(): string
{
return "//select[contains(@id, 'bundle-option') and not(contains(@data-validate, 'required:true'))]"
. "/option/span[normalize-space(text()) = '%s']";
}
}
@@ -0,0 +1,77 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Bundle\Block\Catalog\Product\View\Type;
/**
* Class checks multiselect bundle options appearance
*
* @magentoAppArea frontend
* @magentoAppIsolation enabled
* @magentoDbIsolation enabled
*/
class MultiselectOptionViewTest extends AbstractBundleOptionsViewTest
{
/**
* @magentoDataFixture Magento/Bundle/_files/bundle_product_multiselect_options.php
*
* @return void
*/
public function testNotRequiredSelectMultiSelectionsView(): void
{
$expectedSelectionsNames = ['Simple Product', 'Simple Product2'];
$this->processMultiSelectionsView(
'bundle-product-multiselect-options',
'Multiselect Options',
$expectedSelectionsNames
);
}
/**
* @magentoDataFixture Magento/Bundle/_files/bundle_product_multiselect_required_options.php
*
* @return void
*/
public function testRequiredSelectMultiSelectionsView(): void
{
$expectedSelectionsNames = ['Simple Product', 'Simple Product2'];
$this->processMultiSelectionsView(
'bundle-product-multiselect-required-options',
'Multiselect Options',
$expectedSelectionsNames,
true
);
}
/**
* @magentoDataFixture Magento/Bundle/_files/bundle_product_multiselect_required_option.php
*
* @return void
*/
public function testShowSingle(): void
{
$this->processSingleSelectionView('bundle-product-multiselect-required-option', 'Multiselect Options');
}
/**
* @inheridoc
*/
protected function getRequiredSelectXpath(): string
{
return "//select[contains(@id, 'bundle-option') and @multiple='multiple' "
. "and contains(@data-validate, 'required:true')]/option/span[normalize-space(text()) = '1 x %s']";
}
/**
* @inheridoc
*/
protected function getNotRequiredSelectXpath(): string
{
return "//select[contains(@id, 'bundle-option') and @multiple='multiple'"
. "and not(contains(@data-validate, 'required:true'))]/option/span[normalize-space(text()) = '1 x %s']";
}
}
@@ -0,0 +1,73 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Bundle\Block\Catalog\Product\View\Type;
/**
* Class checks radio buttons bundle options appearance
*
* @magentoAppArea frontend
* @magentoAppIsolation enabled
* @magentoDbIsolation enabled
*/
class RadioOptionViewTest extends AbstractBundleOptionsViewTest
{
/**
* @magentoDataFixture Magento/Bundle/_files/bundle_product_radio_options.php
*
* @return void
*/
public function testNotRequiredSelectMultiSelectionsView(): void
{
$expectedSelectionsNames = ['Simple Product', 'Simple Product2'];
$this->processMultiSelectionsView('bundle-product-radio-options', 'Radio Options', $expectedSelectionsNames);
}
/**
* @magentoDataFixture Magento/Bundle/_files/bundle_product_radio_required_options.php
*
* @return void
*/
public function testRequiredSelectMultiSelectionsView(): void
{
$expectedSelectionsNames = ['Simple Product', 'Simple Product2'];
$this->processMultiSelectionsView(
'bundle-product-radio-required-options',
'Radio Options',
$expectedSelectionsNames,
true
);
}
/**
* @magentoDataFixture Magento/Bundle/_files/bundle_product_radio_required_option.php
*
* @return void
*/
public function testShowSingle(): void
{
$this->processSingleSelectionView('bundle-product-radio-required-option', 'Radio Options');
}
/**
* @inheritdoc
*/
protected function getRequiredSelectXpath(): string
{
return "//input[@type='radio' and contains(@data-validate, 'validate-one-required-by-name')"
. "and contains(@class, 'bundle option')]/../label//span[normalize-space(text()) = '%s']";
}
/**
* @inheritdoc
*/
protected function getNotRequiredSelectXpath(): string
{
return "//input[@type='radio' and not(contains(@data-validate, 'validate-one-required-by-name'))"
. "and contains(@class, 'bundle option')]/../label//span[normalize-space(text()) = '%s']";
}
}
@@ -0,0 +1,209 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Bundle\Block\Sales\Order\Items;
use Magento\Bundle\Test\Fixture\Option as BundleOptionFixture;
use Magento\Bundle\Test\Fixture\OrderItem as OrderItemFixture;
use Magento\Bundle\Test\Fixture\Product as BundleProductFixture;
use Magento\Catalog\Test\Fixture\Product as ProductFixture;
use Magento\Config\Model\ResourceModel\Config as CoreConfig;
use Magento\Customer\Api\AccountManagementInterface;
use Magento\Customer\Model\Session;
use Magento\Customer\Test\Fixture\Customer;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\ObjectManagerInterface;
use Magento\Framework\View\LayoutInterface;
use Magento\Sales\Model\Order;
use Magento\Sales\Model\Order\Email\Sender\OrderSender;
use Magento\Sales\Model\Order\Address as OrderAddress;
use Magento\Store\Model\StoreManagerInterface;
use Magento\TestFramework\Fixture\Config;
use Magento\TestFramework\Fixture\DataFixture;
use Magento\TestFramework\Fixture\DataFixtureStorage;
use Magento\TestFramework\Fixture\DataFixtureStorageManager;
use Magento\TestFramework\Fixture\DbIsolation;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\Mail\Template\TransportBuilderMock;
use PHPUnit\Framework\TestCase;
/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class RendererTest extends TestCase
{
/**
* @var ObjectManagerInterface
*/
private $objectManager;
/**
* @var DataFixtureStorage
*/
private $fixtures;
/**
* @var Session
*/
protected $session;
/** @var Renderer */
private $block;
/**
* @var CoreConfig
*/
protected $resourceConfig;
/**
* @var AccountManagementInterface
*/
private $accountManagement;
/**
* @var OrderSender
*/
private $orderSender;
/**
* @defaultDoc
*/
protected function setUp(): void
{
$this->objectManager = Bootstrap::getObjectManager();
$layout = $this->objectManager->get(LayoutInterface::class);
$this->block = $layout->createBlock(Renderer::class);
$this->fixtures = Bootstrap::getObjectManager()->get(DataFixtureStorageManager::class)->getStorage();
$this->resourceConfig = $this->objectManager->get(CoreConfig::class);
$this->accountManagement = $this->objectManager->get(AccountManagementInterface::class);
$this->orderSender = $this->objectManager->get(OrderSender::class);
}
#[
DbIsolation(false),
Config('default/currency/options/base', 'USD', 'store', 'default'),
Config('currency/options/default', 'EUR', 'store', 'default'),
Config('currency/options/allow', 'USD, EUR', 'store', 'default'),
DataFixture(ProductFixture::class, ['price' => 10], 'p1'),
DataFixture(ProductFixture::class, ['price' => 20], 'p2'),
DataFixture(BundleOptionFixture::class, ['product_links' => ['$p1$', '$p2$']], 'opt1'),
DataFixture(BundleProductFixture::class, ['_options' => ['$opt1$']], 'bundle1'),
DataFixture(OrderItemFixture::class, ['items' => [['sku' => '$bundle1.sku$']]], 'order'),
]
public function testOrderEmailContent(): void
{
$order = $this->objectManager->create(Order::class);
$incrementId = $this->fixtures->get('order')->getIncrementId();
$order->loadByIncrementId($incrementId);
$storeManager = $this->objectManager->get(StoreManagerInterface::class);
$currencyCode = $storeManager->getWebsite()->getDefaultStore()->getDefaultCurrency()->getCode();
$storeId = $this->objectManager->get(StoreManagerInterface::class)->getStore()->getId();
$order->setStoreId($storeId);
$order->setOrderCurrencyCode($currencyCode);
$order->save();
$priceBlockHtml = [];
$items = $order->getAllItems();
foreach ($items as $item) {
$item->setProductOptions([
'bundle_options' => [
[
'value' => [
['title' => '']
],
],
],
'bundle_selection_attributes' => '{"qty":5 ,"price":99}'
]);
$this->block->setItem($item);
$priceBlockHtml[] = $this->block->getValueHtml($item);
}
$this->assertStringContainsString("€99", $priceBlockHtml[0]);
}
/**
* @return void
* @throws \Magento\Framework\Exception\LocalizedException
*/
#[
DbIsolation(true),
DataFixture(ProductFixture::class, ['price' => 10], 'p1'),
DataFixture(ProductFixture::class, ['price' => 20], 'p2'),
DataFixture(ProductFixture::class, ['price' => 30], 'p3'),
DataFixture(BundleOptionFixture::class, ['product_links' => ['$p1$', '$p2$', '$p3$']], 'opt1'),
DataFixture(BundleProductFixture::class, ['_options' => ['$opt1$']], 'bundle1'),
DataFixture(OrderItemFixture::class, ['items' => [['sku' => '$bundle1.sku$']]], 'order'),
DataFixture(Customer::class, ['email' => 'customer@example.com'], as: 'customer'),
]
public function testPlaceOrderWithOtherThanDefaultCurrencyValidateEmailHasSameCurrency(): void
{
$this->resourceConfig->saveConfig(
'currency/options/default',
'EUR',
ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
0
);
$this->resourceConfig->saveConfig(
'currency/options/allow',
'EUR',
ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
0
);
$this->resourceConfig->saveConfig(
'currency/options/base',
'USD',
ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
0
);
// Load customer data
$customer = $this->fixtures->get('customer');
$customerEmail = $customer->getEmail();
// Login to customer
$this->accountManagement->authenticate($customerEmail, 'password');
// Including address data file
$addressData = include __DIR__ . '/../../../../../Sales/_files/address_data.php';
// Setting the billing address
$billingAddress = $this->objectManager->create(OrderAddress::class, ['data' => $addressData]);
$billingAddress->setAddressType('billing');
// Setting the shipping address
$shippingAddress = clone $billingAddress;
$shippingAddress->setId(null)->setAddressType('shipping');
// Place the order
$order = $this->objectManager->create(Order::class);
$incrementId = $this->fixtures->get('order')->getIncrementId();
$order->loadByIncrementId($incrementId);
$storeManager = $this->objectManager->get(StoreManagerInterface::class);
$currencyCodeSymbol = $storeManager->getWebsite()->getDefaultStore()->getDefaultCurrency()->getCurrencySymbol();
$storeId = $this->objectManager->get(StoreManagerInterface::class)->getStore()->getId();
$order->setStoreId($storeId);
$order->setCustomerEmail($customerEmail);
$order->setBillingAddress($billingAddress);
$order->setShippingAddress($shippingAddress);
$order->save();
$this->orderSender->send($order);
$this->assertTrue($order->getSendEmail());
/** @var TransportBuilderMock $transportBuilderMock */
$transportBuilderMock = Bootstrap::getObjectManager()
->get(TransportBuilderMock::class);
$sentMessage = $transportBuilderMock->getSentMessage();
$this->assertNotNull($sentMessage);
$this->assertStringContainsString($currencyCodeSymbol, $sentMessage->getBodyText());
}
}