Skip to content

Commit 0c0e64d

Browse files
authored
ENGCOM-4638: Tests data rollback for`\Magento\GraphQl\Customer\CreateCustomerTest::testCreateCustomerAccountWithPassword #473
2 parents 0fd138c + c6c0de1 commit 0c0e64d

File tree

1 file changed

+32
-12
lines changed

1 file changed

+32
-12
lines changed

dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/CreateCustomerTest.php

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,19 @@
88
namespace Magento\GraphQl\Customer;
99

1010
use Magento\Customer\Api\CustomerRepositoryInterface;
11-
use Magento\Customer\Model\CustomerRegistry;
11+
use Magento\Framework\Registry;
1212
use Magento\TestFramework\Helper\Bootstrap;
1313
use Magento\TestFramework\TestCase\GraphQlAbstract;
1414

15+
/**
16+
* Test for create customer functionallity
17+
*/
1518
class CreateCustomerTest extends GraphQlAbstract
1619
{
1720
/**
18-
* @var CustomerRegistry
21+
* @var Registry
1922
*/
20-
private $customerRegistry;
23+
private $registry;
2124

2225
/**
2326
* @var CustomerRepositoryInterface
@@ -28,7 +31,7 @@ protected function setUp()
2831
{
2932
parent::setUp();
3033

31-
$this->customerRegistry = Bootstrap::getObjectManager()->get(CustomerRegistry::class);
34+
$this->registry = Bootstrap::getObjectManager()->get(Registry::class);
3235
$this->customerRepository = Bootstrap::getObjectManager()->get(CustomerRepositoryInterface::class);
3336
}
3437

@@ -40,7 +43,7 @@ public function testCreateCustomerAccountWithPassword()
4043
$newFirstname = 'Richard';
4144
$newLastname = 'Rowe';
4245
$currentPassword = 'test123#';
43-
$newEmail = 'customer_created' . rand(1, 2000000) . '@example.com';
46+
$newEmail = 'new_customer@example.com';
4447

4548
$query = <<<QUERY
4649
mutation {
@@ -50,7 +53,7 @@ public function testCreateCustomerAccountWithPassword()
5053
lastname: "{$newLastname}"
5154
email: "{$newEmail}"
5255
password: "{$currentPassword}"
53-
is_subscribed: true
56+
is_subscribed: true
5457
}
5558
) {
5659
customer {
@@ -78,7 +81,7 @@ public function testCreateCustomerAccountWithoutPassword()
7881
{
7982
$newFirstname = 'Richard';
8083
$newLastname = 'Rowe';
81-
$newEmail = 'customer_created' . rand(1, 2000000) . '@example.com';
84+
$newEmail = 'new_customer@example.com';
8285

8386
$query = <<<QUERY
8487
mutation {
@@ -87,7 +90,7 @@ public function testCreateCustomerAccountWithoutPassword()
8790
firstname: "{$newFirstname}"
8891
lastname: "{$newLastname}"
8992
email: "{$newEmail}"
90-
is_subscribed: true
93+
is_subscribed: true
9194
}
9295
) {
9396
customer {
@@ -151,7 +154,7 @@ public function testCreateCustomerIfEmailMissed()
151154
firstname: "{$newFirstname}"
152155
lastname: "{$newLastname}"
153156
password: "{$currentPassword}"
154-
is_subscribed: true
157+
is_subscribed: true
155158
}
156159
) {
157160
customer {
@@ -186,7 +189,7 @@ public function testCreateCustomerIfEmailIsNotValid()
186189
lastname: "{$newLastname}"
187190
email: "{$newEmail}"
188191
password: "{$currentPassword}"
189-
is_subscribed: true
192+
is_subscribed: true
190193
}
191194
) {
192195
customer {
@@ -211,7 +214,7 @@ public function testCreateCustomerIfPassedAttributeDosNotExistsInCustomerInput()
211214
$newFirstname = 'Richard';
212215
$newLastname = 'Rowe';
213216
$currentPassword = 'test123#';
214-
$newEmail = 'customer_created' . rand(1, 2000000) . '@example.com';
217+
$newEmail = 'new_customer@example.com';
215218

216219
$query = <<<QUERY
217220
mutation {
@@ -222,7 +225,7 @@ public function testCreateCustomerIfPassedAttributeDosNotExistsInCustomerInput()
222225
test123: "123test123"
223226
email: "{$newEmail}"
224227
password: "{$currentPassword}"
225-
is_subscribed: true
228+
is_subscribed: true
226229
}
227230
) {
228231
customer {
@@ -237,4 +240,21 @@ public function testCreateCustomerIfPassedAttributeDosNotExistsInCustomerInput()
237240
QUERY;
238241
$this->graphQlQuery($query);
239242
}
243+
244+
public function tearDown()
245+
{
246+
$newEmail = 'new_customer@example.com';
247+
try {
248+
$customer = $this->customerRepository->get($newEmail);
249+
} catch (\Exception $exception) {
250+
return;
251+
}
252+
253+
$this->registry->unregister('isSecureArea');
254+
$this->registry->register('isSecureArea', true);
255+
$this->customerRepository->delete($customer);
256+
$this->registry->unregister('isSecureArea');
257+
$this->registry->register('isSecureArea', false);
258+
parent::tearDown();
259+
}
240260
}

0 commit comments

Comments
 (0)