Skip to content

Commit f1593ac

Browse files
committed
MC-30685: Admin: Mass actions on customers grid
1 parent 5ae20ac commit f1593ac

File tree

6 files changed

+47
-61
lines changed

6 files changed

+47
-61
lines changed

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,10 @@ private function performInlineEditRequest(array $params): array
144144
private function assertCustomersData(array $data): void
145145
{
146146
foreach ($data['items'] as $customerId => $expectedData) {
147-
$customer = $this->customerRepository->getById($customerId);
148-
$this->assertEquals($expectedData['email'], $customer->getEmail());
149-
$this->assertEquals($expectedData['group_id'], $customer->getGroupId());
150-
$this->assertEquals($expectedData['website_id'], $customer->getWebsiteId());
151-
$this->assertEquals($expectedData['taxvat'], $customer->getTaxvat());
152-
$this->assertEquals($expectedData['gender'], $customer->getGender());
147+
$customerData = $this->customerRepository->getById($customerId)->__toArray();
148+
foreach ($expectedData as $key => $value) {
149+
$this->assertEquals($value, $customerData[$key]);
150+
}
153151
}
154152
}
155153
}

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

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
use Magento\Framework\App\Request\Http as HttpRequest;
1111
use Magento\Framework\Message\MessageInterface;
1212
use Magento\Framework\ObjectManagerInterface;
13+
use Magento\Newsletter\Model\ResourceModel\Subscriber\CollectionFactory;
1314
use Magento\Newsletter\Model\Subscriber;
14-
use Magento\Newsletter\Model\SubscriberFactory;
1515
use Magento\TestFramework\Helper\Bootstrap;
1616
use Magento\Customer\Api\CustomerRepositoryInterface;
1717
use Magento\TestFramework\TestCase\AbstractBackendController;
@@ -27,12 +27,12 @@ class MassUnsubscribeTest extends AbstractBackendController
2727
/** @var ObjectManagerInterface */
2828
private $objectManager;
2929

30-
/** @var SubscriberFactory */
31-
private $subscriberFactory;
32-
3330
/** @var CustomerRepositoryInterface */
3431
private $customerRepository;
3532

33+
/** @var CollectionFactory */
34+
private $subscriberCollectionFactory;
35+
3636
/**
3737
* @inheritdoc
3838
*/
@@ -41,43 +41,35 @@ protected function setUp()
4141
parent::setUp();
4242

4343
$this->objectManager = Bootstrap::getObjectManager();
44-
$this->subscriberFactory = $this->objectManager->get(SubscriberFactory::class);
44+
$this->subscriberCollectionFactory = $this->objectManager->get(CollectionFactory::class);
4545
$this->customerRepository = $this->objectManager->get(CustomerRepositoryInterface::class);
4646
}
4747

4848
/**
49-
* @magentoDataFixture Magento/Newsletter/_files/two_subscribers.php
49+
* @magentoDataFixture Magento/Newsletter/_files/three_subscribers.php
5050
*
5151
* @return void
5252
*/
5353
public function testMassUnsubscribeAction(): void
5454
{
55-
$firstCustomer = $this->customerRepository->get('customer@example.com');
56-
$secondCustomer = $this->customerRepository->get('customer_two@example.com');
5755
$params = [
58-
'selected' => [
59-
$firstCustomer->getId(),
60-
$secondCustomer->getId(),
61-
],
56+
'selected' => [1, 2, 3],
6257
'namespace' => 'customer_listing',
6358
];
6459
$this->getRequest()->setParams($params)->setMethod(HttpRequest::METHOD_POST);
6560
$this->dispatch('backend/customer/index/massUnsubscribe');
6661
$this->assertRedirect($this->stringContains('backend/customer/index/index'));
6762
$this->assertSessionMessages(
68-
$this->equalTo([(string)__('A total of 2 record(s) were updated.')]),
63+
$this->equalTo([(string)__('A total of 3 record(s) were updated.')]),
6964
MessageInterface::TYPE_SUCCESS
7065
);
71-
$this->assertEquals(
72-
Subscriber::STATUS_UNSUBSCRIBED,
73-
$this->subscriberFactory->create()
74-
->loadByEmail('customer@example.com')->getSubscriberStatus()
75-
);
76-
$this->assertEquals(
77-
Subscriber::STATUS_UNSUBSCRIBED,
78-
$this->subscriberFactory->create()
79-
->loadByEmail('customer_two@example.com')->getSubscriberStatus()
80-
);
66+
$emails = ['customer@search.example.com', 'customer2@search.example.com', 'customer3@search.example.com'];
67+
$collection = $this->subscriberCollectionFactory->create()->addFieldToFilter('subscriber_email', $emails)
68+
->addFieldToSelect('subscriber_status');
69+
$this->assertCount(3, $collection);
70+
foreach ($collection as $subscriber) {
71+
$this->assertEquals(Subscriber::STATUS_UNSUBSCRIBED, $subscriber->getData('subscriber_status'));
72+
}
8173
}
8274

8375
/**

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

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

7-
use Magento\Customer\Api\CustomerRepositoryInterface;
8-
use Magento\Customer\Model\CustomerRegistry;
9-
use Magento\Framework\Exception\NoSuchEntityException;
107
use Magento\Integration\Model\Oauth\Token\RequestThrottler;
11-
use Magento\TestFramework\Helper\Bootstrap;
128

13-
$objectManager = Bootstrap::getObjectManager();
14-
$objectManager->removeSharedInstance(CustomerRegistry::class);
15-
/** @var CustomerRepositoryInterface $customerRepository */
16-
$customerRepository = $objectManager->create(CustomerRepositoryInterface::class);
179
/** @var \Magento\Framework\Registry $registry */
18-
$registry = $objectManager->get(\Magento\Framework\Registry::class);
19-
10+
$registry = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Framework\Registry::class);
2011
$registry->unregister('isSecureArea');
2112
$registry->register('isSecureArea', true);
2213

23-
try {
24-
$customer = $customerRepository->get('customer@example.com');
25-
$customerRepository->delete($customer);
26-
} catch (NoSuchEntityException $e) {
27-
// Customer with the specified email does not exist
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();
2821
}
2922

3023
$registry->unregister('isSecureArea');
3124
$registry->register('isSecureArea', false);
3225

3326
/* Unlock account if it was locked for tokens retrieval */
3427
/** @var RequestThrottler $throttler */
35-
$throttler = $objectManager->create(RequestThrottler::class);
28+
$throttler = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(RequestThrottler::class);
3629
$throttler->resetAuthenticationFailuresCount('customer@example.com', RequestThrottler::USER_TYPE_CUSTOMER);
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
use Magento\Newsletter\Model\SubscriberFactory;
9+
use Magento\TestFramework\Helper\Bootstrap;
10+
11+
require __DIR__ . '/../../../Magento/Customer/_files/three_customers.php';
12+
13+
$objectManager = Bootstrap::getObjectManager();
14+
$subscriberFactory = $objectManager->get(SubscriberFactory::class);
15+
16+
$subscriberFactory->create()->subscribe('customer@search.example.com');
17+
$subscriberFactory->create()->subscribe('customer2@search.example.com');
18+
$subscriberFactory->create()->subscribe('customer3@search.example.com');

dev/tests/integration/testsuite/Magento/Newsletter/_files/two_subscribers_rollback.php renamed to dev/tests/integration/testsuite/Magento/Newsletter/_files/three_subscribers_rollback.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
*/
66
declare(strict_types=1);
77

8-
require __DIR__ . '/../../../Magento/Customer/_files/two_customers_rollback.php';
8+
require __DIR__ . '/../../../Magento/Customer/_files/three_customers_rollback.php';

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

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)