|
| 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\Customer\Controller\Adminhtml\Index; |
| 9 | + |
| 10 | +use Magento\Framework\App\Request\Http as HttpRequest; |
| 11 | +use Magento\Framework\Data\Form\FormKey; |
| 12 | +use Magento\Framework\Message\MessageInterface; |
| 13 | +use Magento\TestFramework\TestCase\AbstractBackendController; |
| 14 | + |
| 15 | +/** |
| 16 | + * Tests for delete customer via backend/customer/index/delete controller. |
| 17 | + * |
| 18 | + * @magentoAppArea adminhtml |
| 19 | + */ |
| 20 | +class DeleteTest extends AbstractBackendController |
| 21 | +{ |
| 22 | + /** @var FormKey */ |
| 23 | + private $formKey; |
| 24 | + |
| 25 | + /** |
| 26 | + * @inheritdoc |
| 27 | + */ |
| 28 | + protected function setUp() |
| 29 | + { |
| 30 | + parent::setUp(); |
| 31 | + |
| 32 | + $this->formKey = $this->_objectManager->get(FormKey::class); |
| 33 | + } |
| 34 | + |
| 35 | + /** |
| 36 | + * Delete customer |
| 37 | + * |
| 38 | + * @dataProvider deleteCustomerProvider |
| 39 | + * @magentoDataFixture Magento/Customer/_files/customer_sample.php |
| 40 | + * |
| 41 | + * @param array $paramsData |
| 42 | + * @param string $expected |
| 43 | + * @return void |
| 44 | + */ |
| 45 | + public function testDeleteCustomer(array $paramsData, array $expected): void |
| 46 | + { |
| 47 | + $this->dispatchCustomerDelete($paramsData); |
| 48 | + |
| 49 | + $this->assertRedirect($this->stringContains('customer/index')); |
| 50 | + $this->assertSessionMessages( |
| 51 | + $this->equalTo([(string)__(...$expected['message'])]), |
| 52 | + $expected['message_type'] |
| 53 | + ); |
| 54 | + } |
| 55 | + |
| 56 | + /** |
| 57 | + * Delete customer provider |
| 58 | + * |
| 59 | + * @return array |
| 60 | + */ |
| 61 | + public function deleteCustomerProvider(): array |
| 62 | + { |
| 63 | + return [ |
| 64 | + 'delete_customer_success' => [ |
| 65 | + 'params_data' => [ |
| 66 | + 'id' => 1, |
| 67 | + ], |
| 68 | + 'expected' => [ |
| 69 | + 'message' => ['You deleted the customer.'], |
| 70 | + 'message_type' => MessageInterface::TYPE_SUCCESS, |
| 71 | + ], |
| 72 | + ], |
| 73 | + 'not_existing_customer_error' => [ |
| 74 | + 'params_data' => [ |
| 75 | + 'id' => 2, |
| 76 | + ], |
| 77 | + 'expected' => [ |
| 78 | + 'message' => [ |
| 79 | + 'No such entity with %fieldName = %fieldValue', |
| 80 | + [ |
| 81 | + 'fieldName' => 'customerId', |
| 82 | + 'fieldValue' => '2', |
| 83 | + ], |
| 84 | + ], |
| 85 | + 'message_type' => MessageInterface::TYPE_ERROR, |
| 86 | + ], |
| 87 | + ], |
| 88 | + ]; |
| 89 | + } |
| 90 | + |
| 91 | + /** |
| 92 | + * Delete customer using backend/customer/index/delete action. |
| 93 | + * |
| 94 | + * @param array $params |
| 95 | + * @return void |
| 96 | + */ |
| 97 | + private function dispatchCustomerDelete(array $params): void |
| 98 | + { |
| 99 | + $params['form_key'] = $this->formKey->getFormKey(); |
| 100 | + $this->getRequest()->setMethod(HttpRequest::METHOD_POST); |
| 101 | + $this->getRequest()->setParams($params); |
| 102 | + $this->dispatch('backend/customer/index/delete'); |
| 103 | + } |
| 104 | +} |
0 commit comments