|
| 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 | +} |
0 commit comments