registry = Bootstrap::getObjectManager()->get(Registry::class); $this->customerRepository = Bootstrap::getObjectManager()->get(CustomerRepositoryInterface::class); } /** * @throws \Exception */ public function testCreateCustomerAccountWithPassword() { $newFirstname = 'Richard'; $newLastname = 'Rowe'; $currentPassword = 'test123#'; $newEmail = 'new_customer@example.com'; $query = <<graphQlMutation($query); $this->assertNull($response['createCustomer']['customer']['id']); $this->assertEquals($newFirstname, $response['createCustomer']['customer']['firstname']); $this->assertEquals($newLastname, $response['createCustomer']['customer']['lastname']); $this->assertEquals($newEmail, $response['createCustomer']['customer']['email']); $this->assertTrue($response['createCustomer']['customer']['is_subscribed']); } /** * @throws \Exception */ public function testCreateCustomerAccountWithoutPassword() { $newFirstname = 'Richard'; $newLastname = 'Rowe'; $newEmail = 'new_customer@example.com'; $query = <<graphQlMutation($query); $this->assertEquals($newFirstname, $response['createCustomer']['customer']['firstname']); $this->assertEquals($newLastname, $response['createCustomer']['customer']['lastname']); $this->assertEquals($newEmail, $response['createCustomer']['customer']['email']); $this->assertTrue($response['createCustomer']['customer']['is_subscribed']); } /** */ public function testCreateCustomerIfInputDataIsEmpty() { $this->expectException(\Exception::class); $this->expectExceptionMessage('"input" value should be specified'); $query = <<graphQlMutation($query); } /** */ public function testCreateCustomerIfEmailMissed() { $this->expectException(\Exception::class); $this->expectExceptionMessage('Required parameters are missing: Email'); $newFirstname = 'Richard'; $newLastname = 'Rowe'; $currentPassword = 'test123#'; $query = <<graphQlMutation($query); } /** * @dataProvider invalidEmailAddressDataProvider * * @param string $email * @throws \Exception */ public function testCreateCustomerIfEmailIsNotValid(string $email) { $firstname = 'Richard'; $lastname = 'Rowe'; $password = 'test123#'; $query = <<expectExceptionMessage('"' . $email . '" is not a valid email address.'); $this->graphQlMutation($query); } /** * @return array */ public function invalidEmailAddressDataProvider(): array { return [ ['plainaddress'], ['jØrgen@somedomain.com'], ['#@%^%#$@#$@#.com'], ['@example.com'], ['Joe Smith '], ['email.example.com'], ['email@example@example.com'], ['email@example.com (Joe Smith)'], ['email@example'], ['“email”@example.com'], ]; } /** */ public function testCreateCustomerIfPassedAttributeDosNotExistsInCustomerInput() { $this->expectException(\Exception::class); $this->expectExceptionMessage('Field "test123" is not defined by type "CustomerInput".'); $newFirstname = 'Richard'; $newLastname = 'Rowe'; $currentPassword = 'test123#'; $newEmail = 'new_customer@example.com'; $query = <<graphQlMutation($query); } /** */ public function testCreateCustomerIfNameEmpty() { $this->expectException(\Exception::class); $this->expectExceptionMessage('Required parameters are missing: First Name'); $newEmail = 'customer_created' . rand(1, 2000000) . '@example.com'; $newFirstname = ''; $newLastname = 'Rowe'; $currentPassword = 'test123#'; $query = <<graphQlMutation($query); } /** * @magentoConfigFixture default_store newsletter/general/active 0 */ public function testCreateCustomerSubscribed() { $newFirstname = 'Richard'; $newLastname = 'Rowe'; $newEmail = 'new_customer@example.com'; $query = <<graphQlMutation($query); $this->assertFalse($response['createCustomer']['customer']['is_subscribed']); } /** * @magentoApiDataFixture Magento/Customer/_files/customer.php */ public function testCreateCustomerIfCustomerWithProvidedEmailAlreadyExists() { $this->expectException(\Exception::class); $this->expectExceptionMessage( 'A customer with the same email address already exists in an associated website.' ); $existedEmail = 'customer@example.com'; $password = 'test123#'; $firstname = 'John'; $lastname = 'Smith'; $query = <<graphQlMutation($query); } protected function tearDown(): void { $newEmail = 'new_customer@example.com'; try { $customer = $this->customerRepository->get($newEmail); } catch (\Exception $exception) { return; } $this->registry->unregister('isSecureArea'); $this->registry->register('isSecureArea', true); $this->customerRepository->delete($customer); $this->registry->unregister('isSecureArea'); $this->registry->register('isSecureArea', false); parent::tearDown(); } }