ltsecurityinc安防产品在线商城代码
This commit is contained in:
+32
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Bundle\Controller\Adminhtml\Bundle\Product\Edit;
|
||||
|
||||
use Magento\Catalog\Controller\Adminhtml\Product\MassDeleteTest as CatalogMassDeleteTest;
|
||||
|
||||
/**
|
||||
* Test for mass bundle product deleting.
|
||||
*
|
||||
* @see \Magento\Bundle\Controller\Adminhtml\Bundle\Product\Edit\MassDelete
|
||||
* @magentoAppArea adminhtml
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
class MassDeleteTest extends CatalogMassDeleteTest
|
||||
{
|
||||
/**
|
||||
* @magentoDataFixture Magento/Bundle/_files/bundle_product_checkbox_required_option.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDeleteBundleProductViaMassAction(): void
|
||||
{
|
||||
$product = $this->productRepository->get('bundle-product-checkbox-required-option');
|
||||
$this->dispatchMassDeleteAction([$product->getId()]);
|
||||
$this->assertSuccessfulDeleteProducts(1);
|
||||
}
|
||||
}
|
||||
+252
@@ -0,0 +1,252 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Bundle\Controller\Adminhtml\Product;
|
||||
|
||||
use Magento\Bundle\Model\Product\Type;
|
||||
use Magento\Bundle\Model\ResourceModel\Option\Collection as OptionCollection;
|
||||
use Magento\Bundle\Model\ResourceModel\Selection\Collection as SelectionCollection;
|
||||
use Magento\Catalog\Api\Data\ProductAttributeInterface;
|
||||
use Magento\Catalog\Api\Data\ProductInterface;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Catalog\Model\ResourceModel\Product as ProductResource;
|
||||
use Magento\Eav\Model\Config;
|
||||
use Magento\Framework\App\Request\Http as HttpRequest;
|
||||
use Magento\TestFramework\TestCase\AbstractBackendController;
|
||||
|
||||
/**
|
||||
* Class determine basic logic for bundle product save tests
|
||||
*/
|
||||
abstract class AbstractBundleProductSaveTest extends AbstractBackendController
|
||||
{
|
||||
/** @var string */
|
||||
protected $productToDelete;
|
||||
|
||||
/** @var ProductRepositoryInterface */
|
||||
protected $productRepository;
|
||||
|
||||
/** @var Config */
|
||||
private $eavConfig;
|
||||
|
||||
/** @var ProductResource */
|
||||
private $productResource;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->productRepository = $this->_objectManager->get(ProductRepositoryInterface::class);
|
||||
$this->eavConfig = $this->_objectManager->get(Config::class);
|
||||
$this->productResource = $this->_objectManager->get(ProductResource::class);
|
||||
$this->productToDelete = $this->getStaticProductData()['sku'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
if ($this->productToDelete) {
|
||||
$this->productRepository->deleteById($this->productToDelete);
|
||||
}
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve default product attribute set id.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
protected function getDefaultAttributeSetId(): int
|
||||
{
|
||||
return (int)$this->eavConfig->getEntityType(ProductAttributeInterface::ENTITY_TYPE_CODE)
|
||||
->getDefaultAttributeSetId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare request
|
||||
*
|
||||
* @param array $post
|
||||
* @param int|null $id
|
||||
* @return array
|
||||
*/
|
||||
protected function prepareRequestData(array $post, ?int $id = null): array
|
||||
{
|
||||
$post = $this->preparePostParams($post);
|
||||
$this->setRequestparams($post, $id);
|
||||
|
||||
return $post;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare and assert bundle options
|
||||
*
|
||||
* @param array $bundleOptions
|
||||
* @return void
|
||||
*/
|
||||
protected function assertBundleOptions(array $bundleOptions): void
|
||||
{
|
||||
$mainProduct = $this->productRepository->get($this->getStaticProductData()['sku'], false, null, true);
|
||||
$optionsCollection = $mainProduct->getTypeInstance()->getOptionsCollection($mainProduct);
|
||||
$selectionCollection = $mainProduct->getTypeInstance()
|
||||
->getSelectionsCollection($optionsCollection->getAllIds(), $mainProduct);
|
||||
$this->assertOptionsData($bundleOptions, $optionsCollection, $selectionCollection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare post params before dispatch
|
||||
*
|
||||
* @param array $post
|
||||
* @return array
|
||||
*/
|
||||
private function preparePostParams(array $post): array
|
||||
{
|
||||
$post['product'] = $this->getStaticProductData();
|
||||
foreach ($post['bundle_options']['bundle_options'] as &$bundleOption) {
|
||||
$bundleOption = $this->prepareOptionByType($bundleOption['type'], $bundleOption);
|
||||
$productIdsBySkus = $this->productResource->getProductsIdsBySkus(
|
||||
array_column($bundleOption['bundle_selections'], 'sku')
|
||||
);
|
||||
foreach ($bundleOption['bundle_selections'] as &$bundleSelection) {
|
||||
$bundleSelection = $this->prepareSelection($productIdsBySkus, $bundleSelection);
|
||||
}
|
||||
}
|
||||
|
||||
return $post;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare option params
|
||||
*
|
||||
* @param string $type
|
||||
* @param array $option
|
||||
* @return array
|
||||
*/
|
||||
private function prepareOptionByType(string $type, array $option): array
|
||||
{
|
||||
$option['required'] = '1';
|
||||
$option['delete'] = '';
|
||||
$option['title'] = $option['title'] ?? $type . ' Option Title';
|
||||
|
||||
return $option;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare selection params
|
||||
*
|
||||
* @param array $productIdsBySkus
|
||||
* @param array $selection
|
||||
* @return array
|
||||
*/
|
||||
private function prepareSelection(array $productIdsBySkus, array $selection): array
|
||||
{
|
||||
$staticData = [
|
||||
'price' => '10.000000',
|
||||
'selection_qty' => '5.0000',
|
||||
'selection_can_change_qty' => '0'
|
||||
];
|
||||
$selection['product_id'] = $productIdsBySkus[$selection['sku']];
|
||||
$selection = array_merge($selection, $staticData);
|
||||
|
||||
return $selection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert bundle options data
|
||||
*
|
||||
* @param array $expectedOptions
|
||||
* @param OptionCollection $actualOptions
|
||||
* @param SelectionCollection $selectionCollection
|
||||
* @return void
|
||||
*/
|
||||
private function assertOptionsData(
|
||||
array $expectedOptions,
|
||||
OptionCollection $actualOptions,
|
||||
SelectionCollection $selectionCollection
|
||||
): void {
|
||||
$this->assertCount(count($expectedOptions['bundle_options']), $actualOptions);
|
||||
foreach ($expectedOptions['bundle_options'] as $expectedOption) {
|
||||
$optionToCheck = $actualOptions->getItemByColumnValue('title', $expectedOption['title']);
|
||||
$this->assertNotNull($optionToCheck->getId());
|
||||
$selectionToCheck = $selectionCollection->getItemsByColumnValue('option_id', $optionToCheck->getId());
|
||||
$this->assertCount(count($expectedOption['bundle_selections']), $selectionToCheck);
|
||||
$this->assertSelections($expectedOption['bundle_selections'], $selectionToCheck);
|
||||
unset($expectedOption['delete'], $expectedOption['bundle_selections']);
|
||||
foreach ($expectedOption as $key => $value) {
|
||||
$this->assertEquals($value, $optionToCheck->getData($key));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert selections data
|
||||
*
|
||||
* @param array $expectedSelections
|
||||
* @param array $actualSelections
|
||||
* @return void
|
||||
*/
|
||||
private function assertSelections(array $expectedSelections, array $actualSelections): void
|
||||
{
|
||||
foreach ($expectedSelections as $expectedSelection) {
|
||||
$actualSelectionToCheck = $this->getSelectionByProductSku($expectedSelection['sku'], $actualSelections);
|
||||
$this->assertNotNull($actualSelectionToCheck);
|
||||
foreach ($expectedSelection as $key => $value) {
|
||||
$this->assertEquals($value, $actualSelectionToCheck->getData($key));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get selection by product sku
|
||||
*
|
||||
* @param string $sku
|
||||
* @param array $actualSelections
|
||||
* @return ProductInterface
|
||||
*/
|
||||
private function getSelectionByProductSku(string $sku, array $actualSelections): ProductInterface
|
||||
{
|
||||
$item = null;
|
||||
foreach ($actualSelections as $selection) {
|
||||
if ($selection->getSku() === $sku) {
|
||||
$item = $selection;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set request parameters
|
||||
*
|
||||
* @param array $post
|
||||
* @param int|null $id
|
||||
* @return void
|
||||
*/
|
||||
private function setRequestParams(array $post, ?int $id): void
|
||||
{
|
||||
$this->getRequest()->setMethod(HttpRequest::METHOD_POST);
|
||||
$params = ['type' => Type::TYPE_CODE, 'set' => $this->getDefaultAttributeSetId()];
|
||||
if ($id) {
|
||||
$params['id'] = $id;
|
||||
}
|
||||
$this->getRequest()->setParams($params);
|
||||
$this->getRequest()->setPostValue('product', $post['product']);
|
||||
$this->getRequest()->setPostValue('bundle_options', $post['bundle_options']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get main product data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
abstract protected function getStaticProductData(): array;
|
||||
}
|
||||
+269
@@ -0,0 +1,269 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Bundle\Controller\Adminhtml\Product;
|
||||
|
||||
use Magento\Bundle\Model\Product\Price;
|
||||
use Magento\Catalog\Model\Product\Type\AbstractType;
|
||||
|
||||
/**
|
||||
* Class checks dynamic bundle product save behavior
|
||||
*
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class DynamicBundleProductTest extends AbstractBundleProductSaveTest
|
||||
{
|
||||
/**
|
||||
* @magentoDataFixture Magento/Catalog/_files/second_product_simple.php
|
||||
*
|
||||
* @dataProvider bundleProductDataProvider
|
||||
*
|
||||
* @param array $post
|
||||
* @return void
|
||||
*/
|
||||
public function testBundleProductSave(array $post): void
|
||||
{
|
||||
$post = $this->prepareRequestData($post);
|
||||
$this->dispatch('backend/catalog/product/save');
|
||||
$this->assertBundleOptions($post['bundle_options']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function bundleProductDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'with_dropdown_option' => [
|
||||
'post' => [
|
||||
'bundle_options' => [
|
||||
'bundle_options' => [
|
||||
[
|
||||
'type' => 'select',
|
||||
'bundle_selections' => [
|
||||
[
|
||||
'name' => 'Simple Product2',
|
||||
'sku' => 'simple2',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
'with_radio_buttons_option' => [
|
||||
'post' => [
|
||||
'bundle_options' => [
|
||||
'bundle_options' => [
|
||||
[
|
||||
'type' => 'radio',
|
||||
'bundle_selections' => [
|
||||
[
|
||||
'name' => 'Simple Product2',
|
||||
'sku' => 'simple2',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
'with_checkbox_option' => [
|
||||
'post' => [
|
||||
'bundle_options' => [
|
||||
'bundle_options' => [
|
||||
[
|
||||
'type' => 'checkbox',
|
||||
'bundle_selections' => [
|
||||
[
|
||||
'name' => 'Simple Product2',
|
||||
'sku' => 'simple2',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
'with_multiselect_option' => [
|
||||
'post' => [
|
||||
'bundle_options' => [
|
||||
'bundle_options' => [
|
||||
[
|
||||
'type' => 'multi',
|
||||
'bundle_selections' => [
|
||||
[
|
||||
'name' => 'Simple Product2',
|
||||
'sku' => 'simple2',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Catalog/_files/second_product_simple.php
|
||||
* @magentoDataFixture Magento/Catalog/_files/product_simple_duplicated.php
|
||||
*
|
||||
* @dataProvider multiOptionsDataProvider
|
||||
*
|
||||
* @param array $post
|
||||
* @return void
|
||||
*/
|
||||
public function testBundleProductSaveMultiOptions(array $post): void
|
||||
{
|
||||
$post = $this->prepareRequestData($post);
|
||||
$this->dispatch('backend/catalog/product/save');
|
||||
$this->assertBundleOptions($post['bundle_options']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function multiOptionsDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'with_two_options_few_selections' => [
|
||||
'post' => [
|
||||
'bundle_options' => [
|
||||
'bundle_options' => [
|
||||
[
|
||||
'type' => 'select',
|
||||
'bundle_selections' => [
|
||||
[
|
||||
'name' => 'Simple Product2',
|
||||
'sku' => 'simple2',
|
||||
],
|
||||
[
|
||||
'name' => 'Simple Product',
|
||||
'sku' => 'simple-1',
|
||||
],
|
||||
],
|
||||
],
|
||||
[
|
||||
'type' => 'checkbox',
|
||||
'bundle_selections' => [
|
||||
[
|
||||
'name' => 'Simple Product',
|
||||
'sku' => 'simple-1',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Catalog/_files/second_product_simple.php
|
||||
*
|
||||
* @dataProvider emptyOptionTitleDataProvider
|
||||
*
|
||||
* @param array $post
|
||||
* @return void
|
||||
*/
|
||||
public function testProductSaveMissedOptionTitle(array $post): void
|
||||
{
|
||||
$this->productToDelete = null;
|
||||
$post = $this->prepareRequestData($post);
|
||||
$this->dispatch('backend/catalog/product/save');
|
||||
$this->assertSessionMessages($this->equalTo(["The option couldn't be saved."]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function emptyOptionTitleDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'empty_option_title' => [
|
||||
'post' => [
|
||||
'bundle_options' => [
|
||||
'bundle_options' => [
|
||||
[
|
||||
'title' => '',
|
||||
'type' => 'multi',
|
||||
'bundle_selections' => [
|
||||
[
|
||||
'name' => 'Simple Product2',
|
||||
'sku' => 'simple2',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Bundle/_files/bundle_product_checkbox_options.php
|
||||
* @magentoDataFixture Magento/Catalog/_files/second_product_simple.php
|
||||
*
|
||||
* @dataProvider updateProductDataProvider
|
||||
*
|
||||
* @param array $post
|
||||
* @return void
|
||||
*/
|
||||
public function testUpdateProduct(array $post): void
|
||||
{
|
||||
$id = $this->productRepository->get('bundle-product-checkbox-options')->getId();
|
||||
$post = $this->prepareRequestData($post, (int)$id);
|
||||
$this->dispatch('backend/catalog/product/save');
|
||||
$this->assertBundleOptions($post['bundle_options']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function updateProductDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'update_existing_product' => [
|
||||
'post' => [
|
||||
'bundle_options' => [
|
||||
'bundle_options' => [
|
||||
[
|
||||
'type' => 'multi',
|
||||
'bundle_selections' => [
|
||||
[
|
||||
'name' => 'Simple Product2',
|
||||
'sku' => 'simple2',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function getStaticProductData(): array
|
||||
{
|
||||
return [
|
||||
'sku' => 'bundle-test-product',
|
||||
'name' => 'test-bundle',
|
||||
'price' => '',
|
||||
'sku_type' => '0',
|
||||
'price_type' => Price::PRICE_TYPE_DYNAMIC,
|
||||
'weight_type' => '0',
|
||||
'shipment_type' => AbstractType::SHIPMENT_TOGETHER,
|
||||
'attribute_set_id' => $this->getDefaultAttributeSetId(),
|
||||
];
|
||||
}
|
||||
}
|
||||
+226
@@ -0,0 +1,226 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Bundle\Controller\Adminhtml\Product;
|
||||
|
||||
use Magento\Bundle\Model\Product\Price;
|
||||
use Magento\Catalog\Model\Product\Type\AbstractType;
|
||||
|
||||
/**
|
||||
* Class checks fixed bundle product save behavior
|
||||
*
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class FixedBundleProductTest extends AbstractBundleProductSaveTest
|
||||
{
|
||||
/**
|
||||
* @magentoDataFixture Magento/Catalog/_files/second_product_simple.php
|
||||
*
|
||||
* @dataProvider fixedBundleProductDataProvider
|
||||
*
|
||||
* @param array $post
|
||||
* @return void
|
||||
*/
|
||||
public function testBundleProductSave(array $post): void
|
||||
{
|
||||
$post = $this->prepareRequestData($post);
|
||||
$this->dispatch('backend/catalog/product/save');
|
||||
$this->assertBundleOptions($post['bundle_options']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function fixedBundleProductDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'with_dropdown_option' => [
|
||||
'post' => [
|
||||
'bundle_options' => [
|
||||
'bundle_options' => [
|
||||
[
|
||||
'type' => 'select',
|
||||
'bundle_selections' => [
|
||||
[
|
||||
'name' => 'Simple Product2',
|
||||
'sku' => 'simple2',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
'with_radio_buttons_option' => [
|
||||
'post' => [
|
||||
'bundle_options' => [
|
||||
'bundle_options' => [
|
||||
[
|
||||
'type' => 'radio',
|
||||
'bundle_selections' => [
|
||||
[
|
||||
'name' => 'Simple Product2',
|
||||
'sku' => 'simple2',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
'with_checkbox_option' => [
|
||||
'post' => [
|
||||
'bundle_options' => [
|
||||
'bundle_options' => [
|
||||
[
|
||||
'type' => 'checkbox',
|
||||
'bundle_selections' => [
|
||||
[
|
||||
'name' => 'Simple Product2',
|
||||
'sku' => 'simple2',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
'with_multiselect_option' => [
|
||||
'post' => [
|
||||
'bundle_options' => [
|
||||
'bundle_options' => [
|
||||
[
|
||||
'type' => 'multi',
|
||||
'bundle_selections' => [
|
||||
[
|
||||
'name' => 'Simple Product2',
|
||||
'sku' => 'simple2',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Catalog/_files/second_product_simple.php
|
||||
* @magentoDataFixture Magento/Catalog/_files/product_simple_duplicated.php
|
||||
*
|
||||
* @dataProvider multiOptionsDataProvider
|
||||
*
|
||||
* @param array $post
|
||||
* @return void
|
||||
*/
|
||||
public function testBundleProductSaveMultiOptions(array $post): void
|
||||
{
|
||||
$post = $this->prepareRequestData($post);
|
||||
$this->dispatch('backend/catalog/product/save');
|
||||
$this->assertBundleOptions($post['bundle_options']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function multiOptionsDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'with_two_options_few_selections' => [
|
||||
'post' => [
|
||||
'bundle_options' => [
|
||||
'bundle_options' => [
|
||||
[
|
||||
'type' => 'select',
|
||||
'bundle_selections' => [
|
||||
[
|
||||
'name' => 'Simple Product2',
|
||||
'sku' => 'simple2',
|
||||
],
|
||||
[
|
||||
'name' => 'Simple Product',
|
||||
'sku' => 'simple-1',
|
||||
],
|
||||
],
|
||||
],
|
||||
[
|
||||
'type' => 'checkbox',
|
||||
'bundle_selections' => [
|
||||
[
|
||||
'name' => 'Simple Product',
|
||||
'sku' => 'simple-1',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Bundle/_files/bundle_product_checkbox_options.php
|
||||
* @magentoDataFixture Magento/Catalog/_files/second_product_simple.php
|
||||
*
|
||||
* @dataProvider updateProductDataProvider
|
||||
*
|
||||
* @param array $post
|
||||
* @return void
|
||||
*/
|
||||
public function testUpdateProduct(array $post): void
|
||||
{
|
||||
$id = $this->productRepository->get('bundle-product-checkbox-options')->getId();
|
||||
$post = $this->prepareRequestData($post, (int)$id);
|
||||
$this->dispatch('backend/catalog/product/save');
|
||||
$this->assertBundleOptions($post['bundle_options']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function updateProductDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'update_existing_product' => [
|
||||
'post' => [
|
||||
'bundle_options' => [
|
||||
'bundle_options' => [
|
||||
[
|
||||
'type' => 'multi',
|
||||
'bundle_selections' => [
|
||||
[
|
||||
'name' => 'Simple Product2',
|
||||
'sku' => 'simple2',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function getStaticProductData(): array
|
||||
{
|
||||
return [
|
||||
'sku' => 'bundle-test-product',
|
||||
'name' => 'test-bundle',
|
||||
'price' => '150',
|
||||
'sku_type' => '1',
|
||||
'price_type' => Price::PRICE_TYPE_FIXED,
|
||||
'weight_type' => '1',
|
||||
'shipment_type' => AbstractType::SHIPMENT_TOGETHER,
|
||||
'attribute_set_id' => $this->getDefaultAttributeSetId(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,238 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Bundle\Controller\Adminhtml;
|
||||
|
||||
use Magento\Bundle\Api\Data\OptionInterface;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Catalog\Model\Product;
|
||||
use Magento\Catalog\Model\Product\Type;
|
||||
use Magento\Framework\App\Request\Http as HttpRequest;
|
||||
use Magento\Framework\Data\Form\FormKey;
|
||||
use Magento\Framework\Message\MessageInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\TestCase\AbstractBackendController;
|
||||
|
||||
/**
|
||||
* Provide tests for product admin controllers.
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class ProductTest extends AbstractBackendController
|
||||
{
|
||||
/**
|
||||
* Test bundle product duplicate won't remove bundle options from original product.
|
||||
*
|
||||
* @magentoDataFixture Magento/Catalog/_files/products_new.php
|
||||
* @return void
|
||||
*/
|
||||
public function testDuplicateProduct()
|
||||
{
|
||||
$params = $this->getRequestParamsForDuplicate();
|
||||
$this->getRequest()->setMethod(HttpRequest::METHOD_POST);
|
||||
$this->getRequest()->setParams(['type' => Type::TYPE_BUNDLE]);
|
||||
$this->getRequest()->setPostValue($params);
|
||||
$this->dispatch('backend/catalog/product/save');
|
||||
$this->assertSessionMessages(
|
||||
$this->equalTo(
|
||||
[
|
||||
'You saved the product.',
|
||||
'You duplicated the product.',
|
||||
]
|
||||
),
|
||||
MessageInterface::TYPE_SUCCESS
|
||||
);
|
||||
$this->assertOptions();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get necessary request post params for creating and duplicating bundle product.
|
||||
*
|
||||
* @return array
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
*/
|
||||
private function getRequestParamsForDuplicate()
|
||||
{
|
||||
$product = Bootstrap::getObjectManager()->get(ProductRepositoryInterface::class)->get('simple');
|
||||
return [
|
||||
'product' =>
|
||||
[
|
||||
'attribute_set_id' => '4',
|
||||
'gift_message_available' => '0',
|
||||
'use_config_gift_message_available' => '1',
|
||||
'stock_data' =>
|
||||
[
|
||||
'min_qty_allowed_in_shopping_cart' =>
|
||||
[
|
||||
[
|
||||
'record_id' => '0',
|
||||
'customer_group_id' => '32000',
|
||||
'min_sale_qty' => '',
|
||||
],
|
||||
],
|
||||
'min_qty' => '0',
|
||||
'max_sale_qty' => '10000',
|
||||
'notify_stock_qty' => '1',
|
||||
'min_sale_qty' => '1',
|
||||
'qty_increments' => '1',
|
||||
'use_config_manage_stock' => '1',
|
||||
'manage_stock' => '1',
|
||||
'use_config_min_qty' => '1',
|
||||
'use_config_max_sale_qty' => '1',
|
||||
'use_config_backorders' => '1',
|
||||
'backorders' => '0',
|
||||
'use_config_notify_stock_qty' => '1',
|
||||
'use_config_enable_qty_inc' => '1',
|
||||
'enable_qty_increments' => '0',
|
||||
'use_config_qty_increments' => '1',
|
||||
'use_config_min_sale_qty' => '1',
|
||||
'is_qty_decimal' => '0',
|
||||
'is_decimal_divided' => '0',
|
||||
],
|
||||
'status' => '1',
|
||||
'affect_product_custom_options' => '1',
|
||||
'name' => 'b1',
|
||||
'price' => '',
|
||||
'weight' => '',
|
||||
'url_key' => '',
|
||||
'special_price' => '',
|
||||
'quantity_and_stock_status' =>
|
||||
[
|
||||
'qty' => '',
|
||||
'is_in_stock' => '1',
|
||||
],
|
||||
'sku_type' => '0',
|
||||
'price_type' => '0',
|
||||
'weight_type' => '0',
|
||||
'website_ids' =>
|
||||
[
|
||||
1 => '1',
|
||||
],
|
||||
'sku' => 'b1',
|
||||
'meta_title' => 'b1',
|
||||
'meta_keyword' => 'b1',
|
||||
'meta_description' => 'b1 ',
|
||||
'tax_class_id' => '2',
|
||||
'product_has_weight' => '1',
|
||||
'visibility' => '4',
|
||||
'country_of_manufacture' => '',
|
||||
'page_layout' => '',
|
||||
'options_container' => 'container2',
|
||||
'custom_design' => '',
|
||||
'custom_layout' => '',
|
||||
'price_view' => '0',
|
||||
'shipment_type' => '0',
|
||||
'news_from_date' => '',
|
||||
'news_to_date' => '',
|
||||
'custom_design_from' => '',
|
||||
'custom_design_to' => '',
|
||||
'special_from_date' => '',
|
||||
'special_to_date' => '',
|
||||
'description' => '',
|
||||
'short_description' => '',
|
||||
'custom_layout_update' => '',
|
||||
'image' => '',
|
||||
'small_image' => '',
|
||||
'thumbnail' => '',
|
||||
],
|
||||
'bundle_options' =>
|
||||
[
|
||||
'bundle_options' =>
|
||||
[
|
||||
[
|
||||
'record_id' => '0',
|
||||
'type' => 'select',
|
||||
'required' => '1',
|
||||
'title' => 'test option title',
|
||||
'position' => '1',
|
||||
'option_id' => '',
|
||||
'delete' => '',
|
||||
'bundle_selections' =>
|
||||
[
|
||||
[
|
||||
'product_id' => $product->getId(),
|
||||
'name' => $product->getName(),
|
||||
'sku' => $product->getSku(),
|
||||
'price' => $product->getPrice(),
|
||||
'delete' => '',
|
||||
'selection_can_change_qty' => '',
|
||||
'selection_id' => '',
|
||||
'selection_price_type' => '0',
|
||||
'selection_price_value' => '',
|
||||
'selection_qty' => '1',
|
||||
'position' => '1',
|
||||
'option_id' => '',
|
||||
'record_id' => '1',
|
||||
'is_default' => '0',
|
||||
],
|
||||
],
|
||||
'bundle_button_proxy' =>
|
||||
[
|
||||
[
|
||||
'entity_id' => '1',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
'affect_bundle_product_selections' => '1',
|
||||
'back' => 'duplicate',
|
||||
'form_key' => Bootstrap::getObjectManager()->get(FormKey::class)->getFormKey(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Check options in created and duplicated products.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function assertOptions()
|
||||
{
|
||||
$createdOptions = $this->getProductOptions('b1');
|
||||
$createdOption = array_shift($createdOptions);
|
||||
$duplicatedOptions = $this->getProductOptions('b1-1');
|
||||
$duplicatedOption = array_shift($duplicatedOptions);
|
||||
$this->assertNotEmpty($createdOption);
|
||||
$this->assertNotEmpty($duplicatedOption);
|
||||
$optionFields = ['type', 'title', 'position', 'required', 'default_title'];
|
||||
foreach ($optionFields as $field) {
|
||||
$this->assertSame($createdOption->getData($field), $duplicatedOption->getData($field));
|
||||
}
|
||||
$createdLinks = $createdOption->getProductLinks();
|
||||
$createdLink = array_shift($createdLinks);
|
||||
$duplicatedLinks = $duplicatedOption->getProductLinks();
|
||||
$duplicatedLink = array_shift($duplicatedLinks);
|
||||
$this->assertNotEmpty($createdLink);
|
||||
$this->assertNotEmpty($duplicatedLink);
|
||||
$linkFields = [
|
||||
'entity_id',
|
||||
'sku',
|
||||
'position',
|
||||
'is_default',
|
||||
'price',
|
||||
'qty',
|
||||
'selection_can_change_quantity',
|
||||
'price_type',
|
||||
];
|
||||
foreach ($linkFields as $field) {
|
||||
$this->assertSame($createdLink->getData($field), $duplicatedLink->getData($field));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get options for given product.
|
||||
*
|
||||
* @param string $sku
|
||||
* @return OptionInterface[]
|
||||
*/
|
||||
private function getProductOptions(string $sku)
|
||||
{
|
||||
$product = Bootstrap::getObjectManager()->create(Product::class);
|
||||
$productId = $product->getResource()->getIdBySku($sku);
|
||||
$product->load($productId);
|
||||
|
||||
return $product->getExtensionAttributes()->getBundleProductOptions();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test class for \Magento\Catalog\Controller\Product (bundle product type)
|
||||
*/
|
||||
namespace Magento\Bundle\Controller;
|
||||
|
||||
class ProductTest extends \Magento\TestFramework\TestCase\AbstractController
|
||||
{
|
||||
/**
|
||||
* @magentoDataFixture Magento/Bundle/_files/product.php
|
||||
* @magentoDbIsolation disabled
|
||||
*/
|
||||
public function testViewAction()
|
||||
{
|
||||
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $this->_objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
|
||||
$product = $productRepository->get('bundle-product');
|
||||
$this->dispatch('catalog/product/view/id/' . $product->getEntityId());
|
||||
$responseBody = $this->getResponse()->getBody();
|
||||
$this->assertStringContainsString('Bundle Product', $responseBody);
|
||||
$this->assertStringContainsString(
|
||||
'In stock',
|
||||
$responseBody,
|
||||
'Bundle Product Detailed Page does not contain In Stock field'
|
||||
);
|
||||
$addToCartCount = substr_count($responseBody, '<span>Add to Cart</span>');
|
||||
$this->assertEquals(1, $addToCartCount, '"Add to Cart" button should appear on the page exactly once.');
|
||||
$actualLinkCount = substr_count($responseBody, '>Bundle Product Items<');
|
||||
$this->assertEquals(1, $actualLinkCount, 'Bundle product options should appear on the page exactly once.');
|
||||
$this->assertStringNotContainsString('class="options-container-big"', $responseBody);
|
||||
$this->assertEquals(
|
||||
1,
|
||||
\Magento\TestFramework\Helper\Xpath::getElementsCountForXpath(
|
||||
'//*[@id="product-options-wrapper"]',
|
||||
$responseBody
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user