From fe1b4b19192ae64e7c83939e8f9fe89fbba593ea Mon Sep 17 00:00:00 2001 From: Pavel Bystritsky Date: Mon, 30 Oct 2017 16:20:44 +0200 Subject: [PATCH] magento/magento2#10834: Signing in after selecting checkout button, will not end up to checkout page --- app/code/Magento/Customer/etc/config.xml | 2 +- .../Customer/Controller/AccountTest.php | 100 ++++++++++++++++-- 2 files changed, 95 insertions(+), 7 deletions(-) diff --git a/app/code/Magento/Customer/etc/config.xml b/app/code/Magento/Customer/etc/config.xml index c35e9fa4b4c8a..da4b80536e631 100644 --- a/app/code/Magento/Customer/etc/config.xml +++ b/app/code/Magento/Customer/etc/config.xml @@ -56,7 +56,7 @@ - 1 + 0 {{depend prefix}}{{var prefix}} {{/depend}}{{var firstname}} {{depend middlename}}{{var middlename}} {{/depend}}{{var lastname}}{{depend suffix}} {{var suffix}}{{/depend}} diff --git a/dev/tests/integration/testsuite/Magento/Customer/Controller/AccountTest.php b/dev/tests/integration/testsuite/Magento/Customer/Controller/AccountTest.php index fd3755fa6ea5c..8cb1d896372a4 100644 --- a/dev/tests/integration/testsuite/Magento/Customer/Controller/AccountTest.php +++ b/dev/tests/integration/testsuite/Magento/Customer/Controller/AccountTest.php @@ -10,12 +10,20 @@ use Magento\Customer\Api\CustomerRepositoryInterface; use Magento\Customer\Api\Data\CustomerInterface; +use Magento\Customer\Model\Account\Redirect; +use Magento\Customer\Model\Session; use Magento\Framework\Api\FilterBuilder; use Magento\Framework\Api\SearchCriteriaBuilder; +use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Framework\App\Config\Value; +use Magento\Framework\App\Http; use Magento\Framework\Data\Form\FormKey; use Magento\Framework\Message\MessageInterface; use Magento\Store\Model\ScopeInterface; use Magento\TestFramework\Helper\Bootstrap; +use Magento\TestFramework\Request; +use Magento\TestFramework\Response; +use Zend\Stdlib\Parameters; /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) @@ -30,9 +38,9 @@ class AccountTest extends \Magento\TestFramework\TestCase\AbstractController */ protected function login($customerId) { - /** @var \Magento\Customer\Model\Session $session */ + /** @var Session $session */ $session = Bootstrap::getObjectManager() - ->get(\Magento\Customer\Model\Session::class); + ->get(Session::class); $session->loginById($customerId); } @@ -130,8 +138,8 @@ public function testCreatepasswordActionWithDirectLink() $this->assertFalse((bool)preg_match('/' . $token . '/m', $text)); $this->assertRedirect($this->stringContains('customer/account/createpassword')); - /** @var \Magento\Customer\Model\Session $customer */ - $session = Bootstrap::getObjectManager()->get(\Magento\Customer\Model\Session::class); + /** @var Session $customer */ + $session = Bootstrap::getObjectManager()->get(Session::class); $this->assertEquals($token, $session->getRpToken()); $this->assertEquals($customer->getId(), $session->getRpCustomerId()); $this->assertNotContains($token, $response->getHeader('Location')->getFieldValue()); @@ -151,8 +159,8 @@ public function testCreatepasswordActionWithSession() $customer->changeResetPasswordLinkToken($token); $customer->save(); - /** @var \Magento\Customer\Model\Session $customer */ - $session = Bootstrap::getObjectManager()->get(\Magento\Customer\Model\Session::class); + /** @var Session $customer */ + $session = Bootstrap::getObjectManager()->get(Session::class); $session->setRpToken($token); $session->setRpCustomerId($customer->getId()); @@ -652,6 +660,50 @@ public function testWrongConfirmationEditPostAction() ); } + /** + * Test redirect customer to account dashboard after logging in. + * + * @param bool|null $redirectDashboardValue + * @param string $redirectUrl + * @magentoDbIsolation enabled + * @magentoAppIsolation enabled + * @magentoDataFixture Magento/Customer/_files/customer.php + * @dataProvider loginPostRedirectDataProvider + */ + public function testLoginPostRedirect($redirectDashboardValue, string $redirectUrl) + { + if (isset($redirectDashboardValue)) { + $this->_objectManager->get(ScopeConfigInterface::class)->setValue('customer/startup/redirect_dashboard', $redirectDashboardValue); + } + + $this->_objectManager->get(Redirect::class)->setRedirectCookie('test'); + + $configValue = $this->_objectManager->create(Value::class); + $configValue->load('web/unsecure/base_url', 'path'); + $baseUrl = $configValue->getValue() ?: 'http://localhost/'; + + $request = $this->prepareRequest(); + $app = $this->_objectManager->create(Http::class, ['_request' => $request]); + $response = $app->launch(); + + $this->assertResponseRedirect($response, $baseUrl . $redirectUrl); + $this->assertTrue($this->_objectManager->get(Session::class)->isLoggedIn()); + } + + /** + * Data provider for testLoginPostRedirect. + * + * @return array + */ + public function loginPostRedirectDataProvider() + { + return [ + [null, 'index.php/'], + [0, 'index.php/'], + [1, 'index.php/customer/account/'], + ]; + } + /** * @return void */ @@ -717,4 +769,40 @@ private function getCustomerByEmail($email) return $customer; } + + /** + * Prepare request for customer login. + * + * @return Request + */ + private function prepareRequest() + { + $post = new Parameters([ + 'form_key' => $this->_objectManager->get(FormKey::class)->getFormKey(), + 'login' => [ + 'username' => 'customer@example.com', + 'password' => 'password' + ] + ]); + $request = $this->getRequest(); + $formKey = $this->_objectManager->get(FormKey::class); + $request->setParam('form_key', $formKey->getFormKey()); + $request->setMethod(Request::METHOD_POST); + $request->setRequestUri('customer/account/loginPost/'); + $request->setPost($post); + return $request; + } + + /** + * Assert response is redirect. + * + * @param Response $response + * @param string $redirectUrl + * @return void + */ + private function assertResponseRedirect(Response $response, string $redirectUrl) + { + $this->assertTrue($response->isRedirect()); + $this->assertSame($redirectUrl, $response->getHeader('Location')->getUri()); + } }