Skip to content

Commit 7028b31

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-91411' into mpi-PR-1806
2 parents 6600fdf + 70cbd3c commit 7028b31

File tree

7 files changed

+323
-77
lines changed

7 files changed

+323
-77
lines changed

app/code/Magento/Catalog/Controller/Adminhtml/Product/MassDelete.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,12 @@ public function execute()
6464
$this->productRepository->delete($product);
6565
$productDeleted++;
6666
}
67-
$this->messageManager->addSuccess(
68-
__('A total of %1 record(s) have been deleted.', $productDeleted)
69-
);
67+
68+
if ($productDeleted) {
69+
$this->messageManager->addSuccess(
70+
__('A total of %1 record(s) have been deleted.', $productDeleted)
71+
);
72+
}
7073

7174
return $this->resultFactory->create(ResultFactory::TYPE_REDIRECT)->setPath('catalog/*/index');
7275
}

app/code/Magento/Ui/Component/MassAction/Filter.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,12 @@ public function getCollection(AbstractDb $collection)
9898
throw new LocalizedException(__('Please select item(s).'));
9999
}
100100
}
101-
/** @var \Magento\Customer\Model\ResourceModel\Customer\Collection $collection */
102-
$idsArray = $this->getFilterIds();
103-
if (!empty($idsArray)) {
104-
$collection->addFieldToFilter(
105-
$collection->getIdFieldName(),
106-
['in' => $idsArray]
107-
);
108-
}
101+
102+
$collection->addFieldToFilter(
103+
$collection->getIdFieldName(),
104+
['in' => $this->getFilterIds()]
105+
);
106+
109107
return $collection;
110108
}
111109

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

Lines changed: 56 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,21 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Customer\Controller\Adminhtml\Index;
79

8-
use Magento\TestFramework\Helper\Bootstrap;
10+
use Magento\Backend\Model\Session;
911
use Magento\Customer\Api\CustomerRepositoryInterface;
12+
use Magento\Customer\Api\Data\CustomerInterface;
13+
use Magento\Framework\Message\MessageInterface;
14+
use Magento\TestFramework\Helper\Bootstrap;
15+
use Magento\TestFramework\TestCase\AbstractBackendController;
1016

1117
/**
1218
* @magentoAppArea adminhtml
1319
*/
14-
class MassAssignGroupTest extends \Magento\TestFramework\TestCase\AbstractBackendController
20+
class MassAssignGroupTest extends AbstractBackendController
1521
{
1622
/**
1723
* Base controller URL
@@ -28,85 +34,105 @@ class MassAssignGroupTest extends \Magento\TestFramework\TestCase\AbstractBacken
2834
protected function setUp()
2935
{
3036
parent::setUp();
31-
$this->customerRepository = Bootstrap::getObjectManager()->get(
32-
\Magento\Customer\Api\CustomerRepositoryInterface::class
33-
);
37+
$this->customerRepository = Bootstrap::getObjectManager()->get(CustomerRepositoryInterface::class);
3438
}
3539

3640
protected function tearDown()
3741
{
3842
/**
3943
* Unset customer data
4044
*/
41-
Bootstrap::getObjectManager()->get(\Magento\Backend\Model\Session::class)->setCustomerData(null);
45+
Bootstrap::getObjectManager()->get(Session::class)->setCustomerData(null);
4246

4347
/**
4448
* Unset messages
4549
*/
46-
Bootstrap::getObjectManager()->get(\Magento\Backend\Model\Session::class)->getMessages(true);
50+
Bootstrap::getObjectManager()->get(Session::class)->getMessages(true);
4751
}
4852

4953
/**
50-
* @magentoDataFixture Magento/Customer/_files/customer.php
54+
* Tests os update a single customer record.
55+
*
56+
* @magentoDataFixture Magento/Customer/_files/five_repository_customers.php
57+
* @magentoDbIsolation disabled
5158
*/
5259
public function testMassAssignGroupAction()
5360
{
54-
$customer = $this->customerRepository->getById(1);
61+
$customerEmail = 'customer1@example.com';
62+
/** @var CustomerInterface $customer */
63+
$customer = $this->customerRepository->get($customerEmail);
5564
$this->assertEquals(1, $customer->getGroupId());
5665

57-
$this->getRequest()
58-
->setParam('group', 0)
59-
->setPostValue('namespace', 'customer_listing')
60-
->setPostValue('selected', [1]);
66+
$params = [
67+
'group' => 0,
68+
'namespace' => 'customer_listing',
69+
'selected' => [$customer->getId()]
70+
];
71+
72+
$this->getRequest()->setParams($params);
6173
$this->dispatch('backend/customer/index/massAssignGroup');
6274
$this->assertSessionMessages(
63-
$this->equalTo(['A total of 1 record(s) were updated.']),
64-
\Magento\Framework\Message\MessageInterface::TYPE_SUCCESS
75+
self::equalTo(['A total of 1 record(s) were updated.']),
76+
MessageInterface::TYPE_SUCCESS
6577
);
6678
$this->assertRedirect($this->stringStartsWith($this->baseControllerUrl));
6779

68-
$customer = $this->customerRepository->getById(1);
80+
$customer = $this->customerRepository->get($customerEmail);
6981
$this->assertEquals(0, $customer->getGroupId());
7082
}
7183

7284
/**
73-
* @magentoDataFixture Magento/Customer/_files/twenty_one_customers.php
85+
* Tests os update a multiple customer records.
86+
*
87+
* @magentoDataFixture Magento/Customer/_files/five_repository_customers.php
88+
* @magentoDbIsolation disabled
7489
*/
7590
public function testLargeGroupMassAssignGroupAction()
7691
{
77-
78-
for ($i = 1; $i < 22; $i++) {
79-
$customer = $this->customerRepository->getById($i);
92+
$ids = [];
93+
for ($i = 1; $i <= 5; $i++) {
94+
/** @var CustomerInterface $customer */
95+
$customer = $this->customerRepository->get('customer' . $i . '@example.com');
8096
$this->assertEquals(1, $customer->getGroupId());
97+
$ids[] = $customer->getId();
8198
}
8299

83-
$this->getRequest()
84-
->setParam('group', 0)
85-
->setPostValue('namespace', 'customer_listing')
86-
->setPostValue('selected', [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21]);
100+
$params = [
101+
'group' => 0,
102+
'namespace' => 'customer_listing',
103+
'selected' => $ids,
104+
];
105+
106+
$this->getRequest()->setParams($params);
87107
$this->dispatch('backend/customer/index/massAssignGroup');
88108
$this->assertSessionMessages(
89-
$this->equalTo(['A total of 21 record(s) were updated.']),
90-
\Magento\Framework\Message\MessageInterface::TYPE_SUCCESS
109+
self::equalTo(['A total of 5 record(s) were updated.']),
110+
MessageInterface::TYPE_SUCCESS
91111
);
92112
$this->assertRedirect($this->stringStartsWith($this->baseControllerUrl));
93-
for ($i = 1; $i < 22; $i++) {
94-
$customer = $this->customerRepository->getById($i);
113+
for ($i = 1; $i < 5; $i++) {
114+
/** @var CustomerInterface $customer */
115+
$customer = $this->customerRepository->get('customer' . $i . '@example.com');
95116
$this->assertEquals(0, $customer->getGroupId());
96117
}
97118
}
98119

99120
/**
100121
* Valid group Id but no customer Ids specified
122+
*
101123
* @magentoDbIsolation enabled
102124
*/
103125
public function testMassAssignGroupActionNoCustomerIds()
104126
{
105-
$this->getRequest()->setParam('group', 0)->setPostValue('namespace', 'customer_listing');
127+
$params = [
128+
'group' => 0,
129+
'namespace' => 'customer_listing',
130+
];
131+
$this->getRequest()->setParams($params);
106132
$this->dispatch('backend/customer/index/massAssignGroup');
107133
$this->assertSessionMessages(
108134
$this->equalTo(['Please select item(s).']),
109-
\Magento\Framework\Message\MessageInterface::TYPE_ERROR
135+
MessageInterface::TYPE_ERROR
110136
);
111137
}
112138
}

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

Lines changed: 120 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,60 +3,162 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Customer\Controller\Adminhtml\Index;
79

10+
use Magento\Backend\Model\Session;
11+
use Magento\Customer\Api\CustomerRepositoryInterface;
12+
use Magento\Customer\Api\Data\CustomerInterface;
13+
use PHPUnit\Framework\Constraint\Constraint;
14+
use Magento\Framework\Message\MessageInterface;
815
use Magento\TestFramework\Helper\Bootstrap;
16+
use Magento\TestFramework\TestCase\AbstractBackendController;
917

1018
/**
1119
* @magentoAppArea adminhtml
1220
*/
13-
class MassDeleteTest extends \Magento\TestFramework\TestCase\AbstractBackendController
21+
class MassDeleteTest extends AbstractBackendController
1422
{
23+
/**
24+
* @var CustomerRepositoryInterface
25+
*/
26+
private $customerRepository;
27+
1528
/**
1629
* Base controller URL
1730
*
1831
* @var string
1932
*/
20-
protected $baseControllerUrl = 'http://localhost/index.php/backend/customer/index/index';
33+
private $baseControllerUrl = 'http://localhost/index.php/backend/customer/index/index';
34+
35+
protected function setUp()
36+
{
37+
parent::setUp();
38+
$this->customerRepository = Bootstrap::getObjectManager()->get(CustomerRepositoryInterface::class);
39+
}
2140

2241
protected function tearDown()
2342
{
2443
/**
2544
* Unset customer data
2645
*/
27-
Bootstrap::getObjectManager()->get(\Magento\Backend\Model\Session::class)->setCustomerData(null);
46+
Bootstrap::getObjectManager()->get(Session::class)->setCustomerData(null);
2847

2948
/**
3049
* Unset messages
3150
*/
32-
Bootstrap::getObjectManager()->get(\Magento\Backend\Model\Session::class)->getMessages(true);
51+
Bootstrap::getObjectManager()->get(Session::class)->getMessages(true);
3352
}
3453

3554
/**
36-
* @magentoDataFixture Magento/Customer/_files/customer.php
55+
* Validates failure attempts to delete customers from grid.
56+
*
57+
* @param array|null $ids
58+
* @param Constraint $constraint
59+
* @param string|null $messageType
60+
* @magentoDataFixture Magento/Customer/_files/five_repository_customers.php
61+
* @magentoDbIsolation disabled
62+
* @dataProvider failedRequestDataProvider
3763
*/
38-
public function testMassDeleteAction()
64+
public function testFailedMassDeleteAction($ids, Constraint $constraint, $messageType)
3965
{
40-
$this->getRequest()->setPostValue('selected', [1])->setPostValue('namespace', 'customer_listing');
41-
$this->dispatch('backend/customer/index/massDelete');
42-
$this->assertSessionMessages(
43-
$this->equalTo(['A total of 1 record(s) were deleted.']),
44-
\Magento\Framework\Message\MessageInterface::TYPE_SUCCESS
66+
$this->massDeleteAssertions($ids, $constraint, $messageType);
67+
}
68+
69+
/**
70+
* Validates success attempt to delete customer from grid.
71+
*
72+
* @param array $emails
73+
* @param Constraint $constraint
74+
* @param string $messageType
75+
* @magentoDataFixture Magento/Customer/_files/five_repository_customers.php
76+
* @magentoDbIsolation disabled
77+
* @dataProvider successRequestDataProvider
78+
*/
79+
public function testSuccessMassDeleteAction(array $emails, Constraint $constraint, string $messageType)
80+
{
81+
$ids = [];
82+
foreach ($emails as $email) {
83+
/** @var CustomerInterface $customer */
84+
$customer = $this->customerRepository->get($email);
85+
$ids[] = $customer->getId();
86+
}
87+
88+
$this->massDeleteAssertions(
89+
$ids,
90+
$constraint,
91+
$messageType
4592
);
46-
$this->assertRedirect($this->stringStartsWith($this->baseControllerUrl));
4793
}
4894

4995
/**
50-
* Valid group Id but no customer Ids specified
51-
* @magentoDbIsolation enabled
96+
* Performs required request and assertions.
97+
*
98+
* @param array|null $ids
99+
* @param Constraint $constraint
100+
* @param string|null $messageType
52101
*/
53-
public function testMassDeleteActionNoCustomerIds()
102+
private function massDeleteAssertions($ids, Constraint $constraint, $messageType)
54103
{
55-
$this->getRequest()->setPostValue('namespace', 'customer_listing');
104+
$requestData = [
105+
'selected' => $ids,
106+
'namespace' => 'customer_listing',
107+
];
108+
109+
$this->getRequest()->setParams($requestData);
56110
$this->dispatch('backend/customer/index/massDelete');
57111
$this->assertSessionMessages(
58-
$this->equalTo(['Please select item(s).']),
59-
\Magento\Framework\Message\MessageInterface::TYPE_ERROR
112+
$constraint,
113+
$messageType
60114
);
115+
$this->assertRedirect($this->stringStartsWith($this->baseControllerUrl));
116+
}
117+
118+
/**
119+
* Provides sets of data for unsuccessful attempts.
120+
*
121+
* @return array
122+
*/
123+
public function failedRequestDataProvider(): array
124+
{
125+
return [
126+
[
127+
'ids' => [],
128+
'constraint' => self::equalTo(['Please select item(s).']),
129+
'messageType' => MessageInterface::TYPE_ERROR,
130+
],
131+
[
132+
'ids' => [111],
133+
'constraint' => self::isEmpty(),
134+
'messageType' => null,
135+
],
136+
[
137+
'ids' => null,
138+
'constraint' => self::equalTo(['Please select item(s).']),
139+
'messageType' => MessageInterface::TYPE_ERROR,
140+
]
141+
];
142+
}
143+
144+
/**
145+
* Provides sets of data for successful attempts.
146+
*
147+
* @return array
148+
*/
149+
public function successRequestDataProvider(): array
150+
{
151+
return [
152+
[
153+
'customerEmails' => ['customer1@example.com'],
154+
'constraint' => self::equalTo(['A total of 1 record(s) were deleted.']),
155+
'messageType' => MessageInterface::TYPE_SUCCESS,
156+
],
157+
[
158+
'customerEmails' => ['customer2@example.com', 'customer3@example.com'],
159+
'constraint' => self::equalTo(['A total of 2 record(s) were deleted.']),
160+
'messageType' => MessageInterface::TYPE_SUCCESS,
161+
],
162+
];
61163
}
62164
}

0 commit comments

Comments
 (0)