Skip to content

After logging in customer is now not redirecting to Customer Dashboard by default #11876

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/code/Magento/Customer/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
<fax_show/>
</address>
<startup>
<redirect_dashboard>1</redirect_dashboard>
<redirect_dashboard>0</redirect_dashboard>
</startup>
<address_templates>
<text>{{depend prefix}}{{var prefix}} {{/depend}}{{var firstname}} {{depend middlename}}{{var middlename}} {{/depend}}{{var lastname}}{{depend suffix}} {{var suffix}}{{/depend}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ public function run()
$this->cmsIndex->getCmsPageBlock()->waitPageInit();
$this->customerAccountLogin->getLoginBlock()->login($this->customer);
$this->cmsIndex->getCmsPageBlock()->waitPageInit();
$this->cmsIndex->getLinksBlock()->openLink('My Account');
$this->cmsIndex->getCmsPageBlock()->waitPageInit();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
}

Expand Down Expand Up @@ -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());
Expand All @@ -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());

Expand Down Expand Up @@ -652,6 +660,50 @@ public function testWrongConfirmationEditPostAction()
);
}

/**
* Test redirect customer to account dashboard after logging in.
*
* @param bool|null $redirectDashboard
* @param string $redirectUrl
* @magentoDbIsolation enabled
* @magentoAppIsolation enabled
* @magentoDataFixture Magento/Customer/_files/customer.php
* @dataProvider loginPostRedirectDataProvider
*/
public function testLoginPostRedirect($redirectDashboard, string $redirectUrl)
{
if (isset($redirectDashboard)) {
$this->_objectManager->get(ScopeConfigInterface::class)->setValue('customer/startup/redirect_dashboard', $redirectDashboard);
}

$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
*/
Expand Down Expand Up @@ -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' => '[email protected]',
'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());
}
}