Skip to content

Commit 70cbd3c

Browse files
committed
MAGETWO-91411: Delete action in grid could be sent multiple times
- test refactoring
1 parent a892d87 commit 70cbd3c

File tree

5 files changed

+60
-79
lines changed

5 files changed

+60
-79
lines changed

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

Lines changed: 26 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
namespace Magento\Customer\Controller\Adminhtml\Index;
99

10+
use Magento\Backend\Model\Session;
1011
use Magento\Customer\Api\CustomerRepositoryInterface;
1112
use Magento\Customer\Api\Data\CustomerInterface;
12-
use Magento\Framework\Exception\LocalizedException;
1313
use Magento\Framework\Message\MessageInterface;
1414
use Magento\TestFramework\Helper\Bootstrap;
1515
use Magento\TestFramework\TestCase\AbstractBackendController;
@@ -42,12 +42,12 @@ protected function tearDown()
4242
/**
4343
* Unset customer data
4444
*/
45-
Bootstrap::getObjectManager()->get(\Magento\Backend\Model\Session::class)->setCustomerData(null);
45+
Bootstrap::getObjectManager()->get(Session::class)->setCustomerData(null);
4646

4747
/**
4848
* Unset messages
4949
*/
50-
Bootstrap::getObjectManager()->get(\Magento\Backend\Model\Session::class)->getMessages(true);
50+
Bootstrap::getObjectManager()->get(Session::class)->getMessages(true);
5151
}
5252

5353
/**
@@ -59,30 +59,26 @@ protected function tearDown()
5959
public function testMassAssignGroupAction()
6060
{
6161
$customerEmail = 'customer1@example.com';
62-
try {
63-
/** @var CustomerInterface $customer */
64-
$customer = $this->customerRepository->get($customerEmail);
65-
$this->assertEquals(1, $customer->getGroupId());
62+
/** @var CustomerInterface $customer */
63+
$customer = $this->customerRepository->get($customerEmail);
64+
$this->assertEquals(1, $customer->getGroupId());
6665

67-
$params = [
68-
'group' => 0,
69-
'namespace' => 'customer_listing',
70-
'selected' => [$customer->getId()]
71-
];
66+
$params = [
67+
'group' => 0,
68+
'namespace' => 'customer_listing',
69+
'selected' => [$customer->getId()]
70+
];
7271

73-
$this->getRequest()->setParams($params);
74-
$this->dispatch('backend/customer/index/massAssignGroup');
75-
$this->assertSessionMessages(
76-
self::equalTo(['A total of 1 record(s) were updated.']),
77-
MessageInterface::TYPE_SUCCESS
78-
);
79-
$this->assertRedirect($this->stringStartsWith($this->baseControllerUrl));
72+
$this->getRequest()->setParams($params);
73+
$this->dispatch('backend/customer/index/massAssignGroup');
74+
$this->assertSessionMessages(
75+
self::equalTo(['A total of 1 record(s) were updated.']),
76+
MessageInterface::TYPE_SUCCESS
77+
);
78+
$this->assertRedirect($this->stringStartsWith($this->baseControllerUrl));
8079

81-
$customer = $this->customerRepository->get($customerEmail);
82-
$this->assertEquals(0, $customer->getGroupId());
83-
} catch (LocalizedException $e) {
84-
self::fail($e->getMessage());
85-
}
80+
$customer = $this->customerRepository->get($customerEmail);
81+
$this->assertEquals(0, $customer->getGroupId());
8682
}
8783

8884
/**
@@ -96,13 +92,9 @@ public function testLargeGroupMassAssignGroupAction()
9692
$ids = [];
9793
for ($i = 1; $i <= 5; $i++) {
9894
/** @var CustomerInterface $customer */
99-
try {
100-
$customer = $this->customerRepository->get('customer'.$i.'@example.com');
101-
$this->assertEquals(1, $customer->getGroupId());
102-
$ids[] = $customer->getId();
103-
} catch (\Exception $e) {
104-
self::fail($e->getMessage());
105-
}
95+
$customer = $this->customerRepository->get('customer' . $i . '@example.com');
96+
$this->assertEquals(1, $customer->getGroupId());
97+
$ids[] = $customer->getId();
10698
}
10799

108100
$params = [
@@ -119,13 +111,9 @@ public function testLargeGroupMassAssignGroupAction()
119111
);
120112
$this->assertRedirect($this->stringStartsWith($this->baseControllerUrl));
121113
for ($i = 1; $i < 5; $i++) {
122-
try {
123-
/** @var CustomerInterface $customer */
124-
$customer = $this->customerRepository->get('customer'.$i.'@example.com');
125-
$this->assertEquals(0, $customer->getGroupId());
126-
} catch (\Exception $e) {
127-
self::fail($e->getMessage());
128-
}
114+
/** @var CustomerInterface $customer */
115+
$customer = $this->customerRepository->get('customer' . $i . '@example.com');
116+
$this->assertEquals(0, $customer->getGroupId());
129117
}
130118
}
131119

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

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
namespace Magento\Customer\Controller\Adminhtml\Index;
99

10+
use Magento\Backend\Model\Session;
1011
use Magento\Customer\Api\CustomerRepositoryInterface;
1112
use Magento\Customer\Api\Data\CustomerInterface;
12-
use Magento\Framework\Exception\LocalizedException;
1313
use PHPUnit\Framework\Constraint\Constraint;
1414
use Magento\Framework\Message\MessageInterface;
1515
use Magento\TestFramework\Helper\Bootstrap;
@@ -38,6 +38,19 @@ protected function setUp()
3838
$this->customerRepository = Bootstrap::getObjectManager()->get(CustomerRepositoryInterface::class);
3939
}
4040

41+
protected function tearDown()
42+
{
43+
/**
44+
* Unset customer data
45+
*/
46+
Bootstrap::getObjectManager()->get(Session::class)->setCustomerData(null);
47+
48+
/**
49+
* Unset messages
50+
*/
51+
Bootstrap::getObjectManager()->get(Session::class)->getMessages(true);
52+
}
53+
4154
/**
4255
* Validates failure attempts to delete customers from grid.
4356
*
@@ -65,22 +78,18 @@ public function testFailedMassDeleteAction($ids, Constraint $constraint, $messag
6578
*/
6679
public function testSuccessMassDeleteAction(array $emails, Constraint $constraint, string $messageType)
6780
{
68-
try {
69-
$ids = [];
70-
foreach ($emails as $email) {
71-
/** @var CustomerInterface $customer */
72-
$customer = $this->customerRepository->get($email);
73-
$ids[] = $customer->getId();
74-
}
75-
76-
$this->massDeleteAssertions(
77-
$ids,
78-
$constraint,
79-
$messageType
80-
);
81-
} catch (LocalizedException $e) {
82-
self::fail($e->getMessage());
81+
$ids = [];
82+
foreach ($emails as $email) {
83+
/** @var CustomerInterface $customer */
84+
$customer = $this->customerRepository->get($email);
85+
$ids[] = $customer->getId();
8386
}
87+
88+
$this->massDeleteAssertions(
89+
$ids,
90+
$constraint,
91+
$messageType
92+
);
8493
}
8594

8695
/**
@@ -152,17 +161,4 @@ public function successRequestDataProvider(): array
152161
],
153162
];
154163
}
155-
156-
protected function tearDown()
157-
{
158-
/**
159-
* Unset customer data
160-
*/
161-
Bootstrap::getObjectManager()->get(\Magento\Backend\Model\Session::class)->setCustomerData(null);
162-
163-
/**
164-
* Unset messages
165-
*/
166-
Bootstrap::getObjectManager()->get(\Magento\Backend\Model\Session::class)->getMessages(true);
167-
}
168164
}

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

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Magento\Customer\Controller\Adminhtml\Index;
99

10+
use Magento\Backend\Model\Session;
1011
use Magento\Framework\Message\MessageInterface;
1112
use Magento\Newsletter\Model\Subscriber;
1213
use Magento\Newsletter\Model\SubscriberFactory;
@@ -31,12 +32,12 @@ protected function tearDown()
3132
/**
3233
* Unset customer data
3334
*/
34-
Bootstrap::getObjectManager()->get(\Magento\Backend\Model\Session::class)->setCustomerData(null);
35+
Bootstrap::getObjectManager()->get(Session::class)->setCustomerData(null);
3536

3637
/**
3738
* Unset messages
3839
*/
39-
Bootstrap::getObjectManager()->get(\Magento\Backend\Model\Session::class)->getMessages(true);
40+
Bootstrap::getObjectManager()->get(Session::class)->getMessages(true);
4041
}
4142

4243
/**
@@ -62,14 +63,10 @@ public function testMassSubscriberAction()
6263
->getSubscriberStatus()
6364
);
6465

65-
try {
66-
/** @var CustomerInterface $customer1 */
67-
$customer1 = $customerRepository->get('customer1@example.com');
68-
/** @var CustomerInterface $customer2 */
69-
$customer2 = $customerRepository->get('customer2@example.com');
70-
} catch (\Exception $e) {
71-
self::fail($e->getMessage());
72-
}
66+
/** @var CustomerInterface $customer1 */
67+
$customer1 = $customerRepository->get('customer1@example.com');
68+
/** @var CustomerInterface $customer2 */
69+
$customer2 = $customerRepository->get('customer2@example.com');
7370

7471
$params = [
7572
'selected' => [

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
/** @var CustomerInterfaceFactory $customerFactory */
2222
$customerFactory = $objectManager->get(CustomerInterfaceFactory::class);
2323

24-
for ($i=1; $i<=5; $i++) {
24+
for ($i = 1; $i <= 5; $i++) {
2525
/** @var CustomerInterface $customer */
2626
$customer = $customerFactory->create();
2727
$customer->setFirstname('John')

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
/** @var CustomerRepositoryInterface $repository */
1616
$customerRepository = $objectManager->create(CustomerRepositoryInterface::class);
1717

18-
for ($i=1; $i<=5; $i++) {
18+
for ($i = 1; $i <= 5; $i++) {
1919
try {
2020
/** @var CustomerInterface $customer */
2121
$customer = $customerRepository->get('customer'.$i.'@example.com');

0 commit comments

Comments
 (0)