Skip to content

Commit d222581

Browse files
merge magento/2.4-develop into magento-tsg/2.4-develop-com-api-func-improve
2 parents 2f65736 + 082e3cc commit d222581

File tree

52 files changed

+4237
-375
lines changed

Some content is hidden

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

52 files changed

+4237
-375
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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\Customer\Model;
9+
10+
use Magento\Customer\Api\CustomerRepositoryInterface;
11+
use Magento\Framework\Exception\NoSuchEntityException;
12+
use Magento\Framework\Registry;
13+
14+
/**
15+
* Delete customer by email or id
16+
*/
17+
class DeleteCustomer
18+
{
19+
/** @var CustomerRepositoryInterface */
20+
private $customerRepository;
21+
22+
/** @var Registry */
23+
private $registry;
24+
25+
/**
26+
* @param CustomerRepositoryInterface $customerRepository
27+
* @param Registry $registry
28+
*/
29+
public function __construct(CustomerRepositoryInterface $customerRepository, Registry $registry)
30+
{
31+
$this->customerRepository = $customerRepository;
32+
$this->registry = $registry;
33+
}
34+
35+
/**
36+
* Delete customer by id or email
37+
*
38+
* @param int|string $id
39+
* @return void
40+
*/
41+
public function execute($id): void
42+
{
43+
$isSecure = $this->registry->registry('isSecureArea');
44+
45+
$this->registry->unregister('isSecureArea');
46+
$this->registry->register('isSecureArea', true);
47+
48+
try {
49+
$customer = is_numeric($id) ? $this->customerRepository->getById($id) : $this->customerRepository->get($id);
50+
$this->customerRepository->delete($customer);
51+
} catch (NoSuchEntityException $e) {
52+
//customer already deleted
53+
}
54+
55+
$this->registry->unregister('isSecureArea');
56+
$this->registry->register('isSecureArea', $isSecure);
57+
}
58+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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\Bundle\Controller\Adminhtml\Bundle\Product\Edit;
9+
10+
use Magento\Catalog\Controller\Adminhtml\Product\MassDeleteTest as CatalogMassDeleteTest;
11+
12+
/**
13+
* Test for mass bundle product deleting.
14+
*
15+
* @see \Magento\Bundle\Controller\Adminhtml\Bundle\Product\Edit\MassDelete
16+
* @magentoAppArea adminhtml
17+
* @magentoDbIsolation enabled
18+
*/
19+
class MassDeleteTest extends CatalogMassDeleteTest
20+
{
21+
/**
22+
* @magentoDataFixture Magento/Bundle/_files/bundle_product_checkbox_required_option.php
23+
*
24+
* @return void
25+
*/
26+
public function testDeleteBundleProductViaMassAction(): void
27+
{
28+
$product = $this->productRepository->get('bundle-product-checkbox-required-option');
29+
$this->dispatchMassDeleteAction([$product->getId()]);
30+
$this->assertSuccessfulDeleteProducts(1);
31+
}
32+
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
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\Controller\Adminhtml\Product;
9+
10+
use Magento\Catalog\Api\ProductRepositoryInterface;
11+
use Magento\Framework\App\Request\Http as HttpRequest;
12+
use Magento\Framework\Message\MessageInterface;
13+
use Magento\TestFramework\TestCase\AbstractBackendController;
14+
15+
/**
16+
* Test for mass product deleting.
17+
*
18+
* @see \Magento\Catalog\Controller\Adminhtml\Product\MassDelete
19+
* @magentoAppArea adminhtml
20+
* @magentoDbIsolation enabled
21+
*/
22+
class MassDeleteTest extends AbstractBackendController
23+
{
24+
/** @var ProductRepositoryInterface */
25+
protected $productRepository;
26+
27+
/**
28+
* @inheritdoc
29+
*/
30+
protected function setUp(): void
31+
{
32+
parent::setUp();
33+
34+
$this->productRepository = $this->_objectManager->get(ProductRepositoryInterface::class);
35+
$this->productRepository->cleanCache();
36+
}
37+
38+
/**
39+
* @magentoDataFixture Magento/Catalog/_files/multiple_products.php
40+
*
41+
* @return void
42+
*/
43+
public function testDeleteSimpleProductViaMassAction(): void
44+
{
45+
$productIds = [10, 11, 12];
46+
$this->dispatchMassDeleteAction($productIds);
47+
$this->assertSuccessfulDeleteProducts(count($productIds));
48+
}
49+
50+
/**
51+
* @return void
52+
*/
53+
public function testDeleteNotExistingProductViaMassAction(): void
54+
{
55+
$this->dispatchMassDeleteAction([989]);
56+
$this->assertSessionMessages($this->isEmpty(), MessageInterface::TYPE_ERROR);
57+
$this->assertRedirect($this->stringContains('backend/catalog/product/index'));
58+
}
59+
60+
/**
61+
* @return void
62+
*/
63+
public function testMassDeleteWithoutProductIds(): void
64+
{
65+
$this->markTestSkipped('Test is blocked by issue MC-34495');
66+
$this->dispatchMassDeleteAction();
67+
$this->assertSessionMessages(
68+
$this->equalTo('An item needs to be selected. Select and try again.'),
69+
MessageInterface::TYPE_ERROR
70+
);
71+
$this->assertRedirect($this->stringContains('backend/catalog/product/index'));
72+
}
73+
74+
/**
75+
* Assert successful delete products.
76+
*
77+
* @param int $productCount
78+
* @return void
79+
*/
80+
protected function assertSuccessfulDeleteProducts(int $productCount): void
81+
{
82+
$this->assertSessionMessages(
83+
$this->equalTo([(string)__('A total of %1 record(s) have been deleted.', $productCount)]),
84+
MessageInterface::TYPE_SUCCESS
85+
);
86+
$this->assertRedirect($this->stringContains('backend/catalog/product/index'));
87+
}
88+
89+
/**
90+
* Dispatch mass delete action.
91+
*
92+
* @param array $productIds
93+
* @return void
94+
*/
95+
protected function dispatchMassDeleteAction(array $productIds = []): void
96+
{
97+
$this->getRequest()->setMethod(HttpRequest::METHOD_POST);
98+
$this->getRequest()->setParams(['selected' => $productIds, 'namespace' => 'product_listing']);
99+
$this->dispatch('backend/catalog/product/massDelete/');
100+
}
101+
}

dev/tests/integration/testsuite/Magento/Catalog/Helper/Product/CompositeTest.php

Lines changed: 95 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,51 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

78
namespace Magento\Catalog\Helper\Product;
89

10+
use Magento\Catalog\Api\ProductRepositoryInterface;
11+
use Magento\Catalog\Model\Product;
912
use Magento\Customer\Controller\RegistryConstants;
13+
use Magento\Framework\DataObject;
14+
use Magento\Framework\ObjectManagerInterface;
1015
use Magento\Framework\Registry;
1116
use Magento\TestFramework\Helper\Bootstrap;
17+
use PHPUnit\Framework\TestCase;
1218

1319
/**
1420
* Test Composite
1521
*/
16-
class CompositeTest extends \PHPUnit\Framework\TestCase
22+
class CompositeTest extends TestCase
1723
{
18-
/**
19-
* @var Composite
20-
*/
21-
protected $helper;
24+
/** @var ObjectManagerInterface */
25+
private $objectManager;
26+
27+
/** @var Composite */
28+
private $helper;
29+
30+
/** @var Registry */
31+
private $registry;
32+
33+
/** @var ProductRepositoryInterface */
34+
private $productRepository;
2235

2336
/**
24-
* @var Registry
37+
* @inheritdoc
2538
*/
26-
protected $registry;
27-
2839
protected function setUp(): void
2940
{
30-
$this->helper = Bootstrap::getObjectManager()->get(\Magento\Catalog\Helper\Product\Composite::class);
31-
$this->registry = Bootstrap::getObjectManager()->get(\Magento\Framework\Registry::class);
41+
$this->objectManager = Bootstrap::getObjectManager();
42+
$this->helper = $this->objectManager->get(Composite::class);
43+
$this->registry = $this->objectManager->get(Registry::class);
44+
$this->productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
45+
$this->productRepository->cleanCache();
3246
}
3347

48+
/**
49+
* @inheritdoc
50+
*/
3451
protected function tearDown(): void
3552
{
3653
$this->registry->unregister('composite_configure_result_error_message');
@@ -42,40 +59,85 @@ protected function tearDown(): void
4259
/**
4360
* @magentoDataFixture Magento/Catalog/_files/product_simple.php
4461
* @magentoDataFixture Magento/Customer/_files/customer.php
62+
* @return void
4563
*/
46-
public function testRenderConfigureResult()
64+
public function testRenderConfigureResult(): void
4765
{
48-
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
49-
$productRepository = Bootstrap::getObjectManager()->create(
50-
\Magento\Catalog\Api\ProductRepositoryInterface::class
51-
);
52-
/** @var $product \Magento\Catalog\Model\Product */
53-
$product = $productRepository->get('simple');
54-
55-
$configureResult = new \Magento\Framework\DataObject();
66+
$product = $this->productRepository->get('simple');
67+
/** @var DataObject $buyRequest */
68+
$buyRequest = $this->objectManager->create(DataObject::class);
69+
$buyRequest->setData(['qty' => 1]);
70+
/** @var DataObject $configureResult */
71+
$configureResult = $this->objectManager->create(DataObject::class);
5672
$configureResult->setOk(true)
5773
->setProductId($product->getId())
74+
->setBuyRequest($buyRequest)
5875
->setCurrentCustomerId(1);
5976

60-
$this->helper->renderConfigureResult($configureResult);
77+
$resultLayout = $this->helper->renderConfigureResult($configureResult);
6178

62-
$customerId = $this->registry->registry(RegistryConstants::CURRENT_CUSTOMER_ID);
63-
$this->assertEquals(1, $customerId);
64-
$errorMessage = $this->registry->registry('composite_configure_result_error_message');
65-
$this->assertNull($errorMessage);
79+
/** @var Product $preparedProduct */
80+
$preparedProduct = $this->registry->registry('product');
81+
$preparedCurrentProduct = $this->registry->registry('current_product');
82+
$this->assertTrue($preparedProduct && $preparedCurrentProduct);
83+
$this->assertEquals(1, $this->registry->registry(RegistryConstants::CURRENT_CUSTOMER_ID));
84+
$this->assertNotNull($preparedProduct->getPreconfiguredValues());
85+
$this->assertContains(
86+
'CATALOG_PRODUCT_COMPOSITE_CONFIGURE',
87+
$resultLayout->getLayout()->getUpdate()->getHandles()
88+
);
89+
$this->assertContains(
90+
'catalog_product_view_type_' . $product->getTypeId(),
91+
$resultLayout->getLayout()->getUpdate()->getHandles()
92+
);
6693
}
6794

68-
public function testRenderConfigureResultNotOK()
95+
/**
96+
* @dataProvider renderConfigureResultExceptionProvider
97+
* @param array $data
98+
* @param string $expectedErrorMessage
99+
* @return void
100+
*/
101+
public function testRenderConfigureResultException(array $data, string $expectedErrorMessage): void
69102
{
70-
$configureResult = new \Magento\Framework\DataObject();
71-
$configureResult->setError(true)
72-
->setMessage('Test Message');
103+
/** @var DataObject $configureResult */
104+
$configureResult = $this->objectManager->create(DataObject::class);
105+
$configureResult->setData($data);
73106

74-
$this->helper->renderConfigureResult($configureResult);
107+
$resultLayout = $this->helper->renderConfigureResult($configureResult);
108+
109+
$this->assertEquals(
110+
$expectedErrorMessage,
111+
$this->registry->registry('composite_configure_result_error_message')
112+
);
113+
$this->assertContains(
114+
'CATALOG_PRODUCT_COMPOSITE_CONFIGURE_ERROR',
115+
$resultLayout->getLayout()->getUpdate()->getHandles()
116+
);
117+
}
75118

76-
$customerId = $this->registry->registry(RegistryConstants::CURRENT_CUSTOMER_ID);
77-
$this->assertNull($customerId);
78-
$errorMessage = $this->registry->registry('composite_configure_result_error_message');
79-
$this->assertEquals('Test Message', $errorMessage);
119+
/**
120+
* Create render configure result exception provider
121+
*
122+
* @return array
123+
*/
124+
public function renderConfigureResultExceptionProvider(): array
125+
{
126+
return [
127+
'error_true' => [
128+
'data' => [
129+
'error' => true,
130+
'message' => 'Test Message'
131+
],
132+
'expected_error_message' => 'Test Message',
133+
],
134+
'without_product' => [
135+
'data' => [
136+
'ok' => true,
137+
],
138+
'expected_error_message' => 'The product that was requested doesn\'t exist.'
139+
. ' Verify the product and try again.',
140+
],
141+
];
80142
}
81143
}

0 commit comments

Comments
 (0)