Skip to content

Commit 62b651a

Browse files
committed
MC-30685: Admin: Mass actions on customers grid
1 parent 7962878 commit 62b651a

File tree

4 files changed

+66
-38
lines changed

4 files changed

+66
-38
lines changed

dev/tests/integration/testsuite/Magento/Customer/Controller/Adminhtml/Index/InlineEditTest.php

Lines changed: 49 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@
88
namespace Magento\Customer\Controller\Adminhtml\Index;
99

1010
use Magento\Customer\Api\CustomerMetadataInterface;
11+
use Magento\Customer\Api\CustomerRepositoryInterface;
12+
use Magento\Customer\Api\Data\CustomerInterface;
1113
use Magento\Eav\Model\AttributeRepository;
1214
use Magento\Framework\App\Request\Http as HttpRequest;
1315
use Magento\Framework\ObjectManagerInterface;
1416
use Magento\Framework\Serialize\SerializerInterface;
1517
use Magento\Store\Api\WebsiteRepositoryInterface;
1618
use Magento\TestFramework\Helper\Bootstrap;
17-
use Magento\Customer\Api\CustomerRepositoryInterface;
1819
use Magento\TestFramework\TestCase\AbstractBackendController;
1920

2021
/**
@@ -69,44 +70,69 @@ public function testInlineEditAction(): void
6970
$params = [
7071
'items' => [
7172
$firstCustomer->getId() => [
72-
'email' => 'updated_customer@example.com',
73-
'group_id' => 2,
74-
'website_id' => $defaultWebsiteId,
75-
'taxvat' => 123123,
76-
'gender' => $genderId,
73+
CustomerInterface::EMAIL => 'updated_customer@example.com',
74+
CustomerInterface::GROUP_ID => 2,
75+
CustomerInterface::WEBSITE_ID => $defaultWebsiteId,
76+
CustomerInterface::TAXVAT => 123123,
77+
CustomerInterface::GENDER => $genderId,
7778
],
7879
$secondCustomer->getId() => [
79-
'email' => 'updated_customer_two@example.com',
80-
'group_id' => 3,
81-
'website_id' => $defaultWebsiteId,
82-
'taxvat' => 456456,
83-
'gender' => $genderId,
80+
CustomerInterface::EMAIL => 'updated_customer_two@example.com',
81+
CustomerInterface::GROUP_ID => 3,
82+
CustomerInterface::WEBSITE_ID => $defaultWebsiteId,
83+
CustomerInterface::TAXVAT => 456456,
84+
CustomerInterface::GENDER => $genderId,
8485
],
8586
],
8687
'isAjax' => true,
8788
];
88-
$this->getRequest()->setParams($params)->setMethod(HttpRequest::METHOD_POST);
89-
$this->dispatch('backend/customer/index/inlineEdit');
90-
$actual = $this->json->unserialize($this->getResponse()->getBody());
91-
$this->assertEquals([], $actual['messages']);
92-
$this->assertEquals(false, $actual['error']);
89+
$actual = $this->performInlineEditRequest($params);
90+
$this->assertEmpty($actual['messages']);
91+
$this->assertFalse($actual['error']);
9392
$this->assertCustomersData($params);
9493
}
9594

9695
/**
96+
* @dataProvider inlineEditParametersDataProvider
97+
*
98+
* @param array $params
9799
* @return void
98100
*/
99-
public function testInlineEditActionNoSelection(): void
101+
public function testInlineEditWithWrongParams(array $params): void
100102
{
101-
$params = [
102-
'items' => [],
103-
'isAjax' => true,
103+
$actual = $this->performInlineEditRequest($params);
104+
$this->assertEquals([(string)__('Please correct the data sent.')], $actual['messages']);
105+
$this->assertTrue($actual['error']);
106+
}
107+
108+
/**
109+
* @return array
110+
*/
111+
public function inlineEditParametersDataProvider(): array
112+
{
113+
return [
114+
[
115+
'items' => [],
116+
'isAjax' => true,
117+
],
118+
[
119+
'items' => [],
120+
],
104121
];
122+
}
123+
124+
/**
125+
* Perform inline edit request.
126+
*
127+
* @param array $params
128+
* @return array
129+
*/
130+
private function performInlineEditRequest(array $params): array
131+
{
105132
$this->getRequest()->setParams($params)->setMethod(HttpRequest::METHOD_POST);
106133
$this->dispatch('backend/customer/index/inlineEdit');
107-
$actual = $this->json->unserialize($this->getResponse()->getBody());
108-
$this->assertEquals(['Please correct the data sent.'], $actual['messages']);
109-
$this->assertEquals(true, $actual['error']);
134+
135+
return $this->json->unserialize($this->getResponse()->getBody());
110136
}
111137

112138
/**

dev/tests/integration/testsuite/Magento/Customer/Controller/Adminhtml/Index/MassUnsubscribeTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function testMassUnsubscribeAction(): void
6565
$this->dispatch('backend/customer/index/massUnsubscribe');
6666
$this->assertRedirect($this->stringContains('backend/customer/index/index'));
6767
$this->assertSessionMessages(
68-
self::equalTo(['A total of 2 record(s) were updated.']),
68+
$this->equalTo([(string)__('A total of 2 record(s) were updated.')]),
6969
MessageInterface::TYPE_SUCCESS
7070
);
7171
$this->assertEquals(
@@ -86,13 +86,13 @@ public function testMassUnsubscribeAction(): void
8686
public function testMassSubscriberActionNoSelection(): void
8787
{
8888
$params = [
89-
'namespace' => 'customer_listing'
89+
'namespace' => 'customer_listing',
9090
];
9191
$this->getRequest()->setParams($params)->setMethod(HttpRequest::METHOD_POST);
9292
$this->dispatch('backend/customer/index/massUnsubscribe');
9393
$this->assertRedirect($this->stringContains('backend/customer/index/index'));
9494
$this->assertSessionMessages(
95-
self::equalTo(['An item needs to be selected. Select and try again.']),
95+
$this->equalTo([(string)__('An item needs to be selected. Select and try again.')]),
9696
MessageInterface::TYPE_ERROR
9797
);
9898
}

dev/tests/integration/testsuite/Magento/Customer/_files/customer_rollback.php

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,31 @@
44
* See COPYING.txt for license details.
55
*/
66

7+
use Magento\Customer\Api\CustomerRepositoryInterface;
8+
use Magento\Framework\Exception\NoSuchEntityException;
79
use Magento\Integration\Model\Oauth\Token\RequestThrottler;
10+
use Magento\TestFramework\Helper\Bootstrap;
811

12+
$objectManager = Bootstrap::getObjectManager();
13+
/** @var CustomerRepositoryInterface $customerRepository */
14+
$customerRepository = $objectManager->get(CustomerRepositoryInterface::class);
915
/** @var \Magento\Framework\Registry $registry */
10-
$registry = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Framework\Registry::class);
16+
$registry = $objectManager->get(\Magento\Framework\Registry::class);
17+
1118
$registry->unregister('isSecureArea');
1219
$registry->register('isSecureArea', true);
1320

14-
/** @var $customer \Magento\Customer\Model\Customer*/
15-
$customer = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
16-
\Magento\Customer\Model\Customer::class
17-
);
18-
$customer->load(1);
19-
if ($customer->getId()) {
20-
$customer->delete();
21+
try {
22+
$customer = $customerRepository->get('customer@example.com');
23+
$customerRepository->delete($customer);
24+
} catch (NoSuchEntityException $e) {
25+
// Customer with the specified email does not exist
2126
}
2227

2328
$registry->unregister('isSecureArea');
2429
$registry->register('isSecureArea', false);
2530

2631
/* Unlock account if it was locked for tokens retrieval */
2732
/** @var RequestThrottler $throttler */
28-
$throttler = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(RequestThrottler::class);
33+
$throttler = $objectManager->create(RequestThrottler::class);
2934
$throttler->resetAuthenticationFailuresCount('customer@example.com', RequestThrottler::USER_TYPE_CUSTOMER);

dev/tests/integration/testsuite/Magento/Newsletter/_files/two_subscribers.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,9 @@
66
declare(strict_types=1);
77

88
use Magento\Newsletter\Model\SubscriberFactory;
9-
use Magento\TestFramework\Helper\Bootstrap;
109

1110
require __DIR__ . '/../../../Magento/Customer/_files/two_customers.php';
1211

13-
$objectManager = Bootstrap::getObjectManager();
14-
/** @var SubscriberFactory $subscriberFactory */
1512
$subscriberFactory = $objectManager->get(SubscriberFactory::class);
1613

1714
$subscriberFactory->create()->subscribe('customer@example.com');

0 commit comments

Comments
 (0)