transportBuilderMock = $this->_objectManager->get(TransportBuilderMock::class); } /** * Login the user * * @param string $customerId Customer to mark as logged in for the session * @return void */ protected function login($customerId) { /** @var Session $session */ $session = Bootstrap::getObjectManager()->get(Session::class); $session->loginById($customerId); } /** * @magentoDataFixture Magento/Customer/_files/customer.php * @magentoDataFixture Magento/Customer/_files/customer_address.php */ public function testIndexAction() { $this->login(1); $this->dispatch('customer/account/index'); $body = $this->getResponse()->getBody(); $this->assertStringContainsString('Green str, 67', $body); } /** * Test sign up form displaying. */ public function testCreateAction() { $this->dispatch('customer/account/create'); $body = $this->getResponse()->getBody(); $this->assertMatchesRegularExpression('~]*id="firstname"~', $body); $this->assertMatchesRegularExpression('~]*id="lastname"~', $body); $this->assertMatchesRegularExpression('~]*id="is_subscribed"~', $body); $this->assertMatchesRegularExpression('~]*id="email_address"~', $body); $this->assertMatchesRegularExpression('~]*id="password"~', $body); $this->assertMatchesRegularExpression('~]*id="password-confirmation"~', $body); } /** * @magentoDataFixture Magento/Customer/_files/customer.php */ public function testLogoutAction() { $this->login(1); $this->dispatch('customer/account/logout'); $this->assertRedirect($this->stringContains('customer/account/logoutSuccess')); } /** * @magentoDataFixture Magento/Customer/_files/customer.php */ public function testCreatepasswordActionWithDirectLink() { /** @var \Magento\Customer\Model\Customer $customer */ $customer = Bootstrap::getObjectManager() ->create(\Magento\Customer\Model\Customer::class)->load(1); $token = Bootstrap::getObjectManager()->get(\Magento\Framework\Math\Random::class) ->getUniqueHash(); $customer->changeResetPasswordLinkToken($token); $customer->setData('confirmation', 'confirmation'); $customer->save(); $this->getRequest()->setParam('token', $token); $this->getRequest()->setParam('id', 1); $this->dispatch('customer/account/createPassword'); $response = $this->getResponse(); $this->assertEquals(302, $response->getHttpResponseCode()); $text = $response->getBody(); $this->assertFalse((bool)preg_match('/' . $token . '/m', $text)); $this->assertRedirect( $this->stringContains('customer/account/createpassword') ); /** @var Session $customer */ $session = Bootstrap::getObjectManager()->get(Session::class); $this->assertEquals($token, $session->getRpToken()); $this->assertStringNotContainsString($token, $response->getHeader('Location')->getFieldValue()); $this->assertCustomerConfirmationEquals(1, null); } /** * @magentoDataFixture Magento/Customer/_files/customer.php */ public function testCreatepasswordActionWithSession() { /** @var \Magento\Customer\Model\Customer $customer */ $customer = Bootstrap::getObjectManager() ->create(\Magento\Customer\Model\Customer::class)->load(1); $token = Bootstrap::getObjectManager()->get(\Magento\Framework\Math\Random::class) ->getUniqueHash(); $customer->changeResetPasswordLinkToken($token); $customer->setData('confirmation', 'confirmation'); $customer->save(); /** @var Session $customer */ $session = Bootstrap::getObjectManager()->get(Session::class); $session->setRpToken($token); $session->setRpCustomerId($customer->getId()); $this->dispatch('customer/account/createPassword'); $response = $this->getResponse(); $text = $response->getBody(); $this->assertTrue((bool)preg_match('/' . $token . '/m', $text)); $this->assertCustomerConfirmationEquals(1, null); } /** * @magentoDataFixture Magento/Customer/_files/customer.php */ public function testCreatepasswordActionInvalidToken() { /** @var \Magento\Customer\Model\Customer $customer */ $customer = Bootstrap::getObjectManager() ->create(\Magento\Customer\Model\Customer::class)->load(1); $token = Bootstrap::getObjectManager()->get(\Magento\Framework\Math\Random::class) ->getUniqueHash(); $customer->changeResetPasswordLinkToken($token); $customer->setData('confirmation', 'confirmation'); $customer->save(); $this->getRequest()->setParam('token', 'INVALIDTOKEN'); $this->getRequest()->setParam('id', $customer->getId()); $this->dispatch('customer/account/createPassword'); // should be redirected to forgotpassword page $response = $this->getResponse(); $this->assertEquals(302, $response->getHttpResponseCode()); $this->assertStringContainsString( 'customer/account/forgotpassword', $response->getHeader('Location')->getFieldValue() ); $this->assertCustomerConfirmationEquals(1, 'confirmation'); } /** * @param int $customerId * @param string|null $confirmation */ private function assertCustomerConfirmationEquals(int $customerId, string $confirmation = null) { /** @var \Magento\Customer\Model\Customer $customer */ $customer = Bootstrap::getObjectManager() ->create(\Magento\Customer\Model\Customer::class)->load($customerId); $this->assertEquals($confirmation, $customer->getConfirmation()); } /** * @magentoDataFixture Magento/Customer/_files/customer.php */ public function testConfirmActionAlreadyActive() { /** @var \Magento\Customer\Model\Customer $customer */ $customer = Bootstrap::getObjectManager() ->create(\Magento\Customer\Model\Customer::class)->load(1); $this->getRequest()->setParam('key', 'abc'); $this->getRequest()->setParam('id', $customer->getId()); $this->dispatch('customer/account/confirm'); $this->getResponse()->getBody(); } /** * @magentoDataFixture Magento/Customer/_files/inactive_customer.php */ public function testInactiveUserConfirmationAction() { $this->getRequest() ->setMethod('POST') ->setPostValue( [ 'email' => 'customer@needAconfirmation.com', ] ); $this->dispatch('customer/account/confirmation'); $this->assertRedirect($this->stringContains('customer/account/index')); $this->assertSessionMessages( $this->equalTo(['Please check your email for confirmation key.']), MessageInterface::TYPE_SUCCESS ); } /** * @magentoDataFixture Magento/Customer/_files/customer.php */ public function testActiveUserConfirmationAction() { $this->getRequest() ->setMethod('POST') ->setPostValue( [ 'email' => 'customer@example.com', ] ); $this->dispatch('customer/account/confirmation'); $this->assertRedirect($this->stringContains('customer/account/index')); $this->assertSessionMessages( $this->equalTo( [ 'This email does not require confirmation.', ] ), MessageInterface::TYPE_SUCCESS ); } /** * @magentoDataFixture Magento/Customer/_files/customer.php */ public function testResetPasswordPostNoEmail() { $this->getRequest() ->setParam('id', 1) ->setParam('token', '8ed8677e6c79e68b94e61658bd756ea5') ->setMethod('POST') ->setPostValue( [ 'password' => 'new-password', 'password_confirmation' => 'new-password', ] ); $this->dispatch('customer/account/resetPasswordPost'); $this->assertRedirect($this->stringContains('customer/account/')); $this->assertSessionMessages( $this->equalTo(['"email" is required. Enter and try again.']), MessageInterface::TYPE_ERROR ); } /** * @magentoDataFixture Magento/Customer/_files/customer_rp_token.php * @magentoConfigFixture customer/password/reset_link_expiration_period 10 */ public function testResetPasswordPostAction() { $this->getRequest() ->setQueryValue('id', 1) ->setQueryValue('token', '8ed8677e6c79e68b94e61658bd756ea5') ->setMethod('POST') ->setPostValue( [ 'password' => 'new-Password1', 'password_confirmation' => 'new-Password1', ] ); $this->dispatch('customer/account/resetPasswordPost'); $this->assertRedirect($this->stringContains('customer/account/login')); $this->assertSessionMessages( $this->equalTo(['You updated your password.']), MessageInterface::TYPE_SUCCESS ); } /** * @magentoDataFixture Magento/Customer/_files/customer.php */ public function testEditAction() { $this->login(1); $this->dispatch('customer/account/edit'); $body = $this->getResponse()->getBody(); $this->assertEquals(200, $this->getResponse()->getHttpResponseCode(), $body); $this->assertStringContainsString('