Skip to content

Commit 41cd961

Browse files
committed
⏫ Forwardport of #11876 to 2.3-develop branch
1 parent 8e77e2f commit 41cd961

File tree

3 files changed

+88
-1
lines changed

3 files changed

+88
-1
lines changed

app/code/Magento/Customer/etc/config.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
<fax_show/>
5757
</address>
5858
<startup>
59-
<redirect_dashboard>1</redirect_dashboard>
59+
<redirect_dashboard>0</redirect_dashboard>
6060
</startup>
6161
<address_templates>
6262
<text>{{depend prefix}}{{var prefix}} {{/depend}}{{var firstname}} {{depend middlename}}{{var middlename}} {{/depend}}{{var lastname}}{{depend suffix}} {{var suffix}}{{/depend}}

dev/tests/functional/tests/app/Magento/Customer/Test/TestStep/LoginCustomerOnFrontendStep.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ public function run()
7575
$this->cmsIndex->getCmsPageBlock()->waitPageInit();
7676
$this->customerAccountLogin->getLoginBlock()->login($this->customer);
7777
$this->cmsIndex->getCmsPageBlock()->waitPageInit();
78+
$this->cmsIndex->getLinksBlock()->openLink('My Account');
79+
$this->cmsIndex->getCmsPageBlock()->waitPageInit();
7880
}
7981

8082
/**

dev/tests/integration/testsuite/Magento/Customer/Controller/AccountTest.php

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,20 @@
88

99
use Magento\Customer\Api\CustomerRepositoryInterface;
1010
use Magento\Customer\Api\Data\CustomerInterface;
11+
use Magento\Customer\Model\Account\Redirect;
12+
use Magento\Customer\Model\Session;
1113
use Magento\Framework\Api\FilterBuilder;
1214
use Magento\Framework\Api\SearchCriteriaBuilder;
15+
use Magento\Framework\App\Config\ScopeConfigInterface;
16+
use Magento\Framework\App\Config\Value;
17+
use Magento\Framework\App\Http;
1318
use Magento\Framework\Data\Form\FormKey;
1419
use Magento\Framework\Message\MessageInterface;
1520
use Magento\Store\Model\ScopeInterface;
1621
use Magento\TestFramework\Helper\Bootstrap;
22+
use Magento\TestFramework\Request;
23+
use Magento\TestFramework\Response;
24+
use Zend\Stdlib\Parameters;
1725

1826
/**
1927
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -660,6 +668,47 @@ public function testWrongConfirmationEditPostAction()
660668
);
661669
}
662670

671+
/**
672+
* Test redirect customer to account dashboard after logging in.
673+
*
674+
* @param bool|null $redirectDashboard
675+
* @param string $redirectUrl
676+
* @magentoDbIsolation enabled
677+
* @magentoAppIsolation enabled
678+
* @magentoDataFixture Magento/Customer/_files/customer.php
679+
* @dataProvider loginPostRedirectDataProvider
680+
*/
681+
public function testLoginPostRedirect($redirectDashboard, string $redirectUrl)
682+
{
683+
if (isset($redirectDashboard)) {
684+
$this->_objectManager->get(ScopeConfigInterface::class)->setValue('customer/startup/redirect_dashboard',
685+
$redirectDashboard);
686+
}
687+
$this->_objectManager->get(Redirect::class)->setRedirectCookie('test');
688+
$configValue = $this->_objectManager->create(Value::class);
689+
$configValue->load('web/unsecure/base_url', 'path');
690+
$baseUrl = $configValue->getValue() ?: 'http://localhost/';
691+
$request = $this->prepareRequest();
692+
$app = $this->_objectManager->create(Http::class, ['_request' => $request]);
693+
$response = $app->launch();
694+
$this->assertResponseRedirect($response, $baseUrl . $redirectUrl);
695+
$this->assertTrue($this->_objectManager->get(Session::class)->isLoggedIn());
696+
}
697+
698+
/**
699+
* Data provider for testLoginPostRedirect.
700+
*
701+
* @return array
702+
*/
703+
public function loginPostRedirectDataProvider()
704+
{
705+
return [
706+
[null, 'index.php/'],
707+
[0, 'index.php/'],
708+
[1, 'index.php/customer/account/'],
709+
];
710+
}
711+
663712
/**
664713
* @param string $email
665714
* @return void
@@ -727,4 +776,40 @@ private function getCustomerByEmail($email)
727776

728777
return $customer;
729778
}
779+
780+
/**
781+
* Prepare request for customer login.
782+
*
783+
* @return Request
784+
*/
785+
private function prepareRequest()
786+
{
787+
$post = new Parameters([
788+
'form_key' => $this->_objectManager->get(FormKey::class)->getFormKey(),
789+
'login' => [
790+
'username' => '[email protected]',
791+
'password' => 'password'
792+
]
793+
]);
794+
$request = $this->getRequest();
795+
$formKey = $this->_objectManager->get(FormKey::class);
796+
$request->setParam('form_key', $formKey->getFormKey());
797+
$request->setMethod(Request::METHOD_POST);
798+
$request->setRequestUri('customer/account/loginPost/');
799+
$request->setPost($post);
800+
return $request;
801+
}
802+
803+
/**
804+
* Assert response is redirect.
805+
*
806+
* @param Response $response
807+
* @param string $redirectUrl
808+
* @return void
809+
*/
810+
private function assertResponseRedirect(Response $response, string $redirectUrl)
811+
{
812+
$this->assertTrue($response->isRedirect());
813+
$this->assertSame($redirectUrl, $response->getHeader('Location')->getUri());
814+
}
730815
}

0 commit comments

Comments
 (0)