Skip to content

Commit

Permalink
⏫ Forwardport of #11876 to 2.3-develop branch
Browse files Browse the repository at this point in the history
  • Loading branch information
p-bystritsky committed Jan 24, 2018
1 parent 8e77e2f commit 41cd961
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 1 deletion.
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 @@ -8,12 +8,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 Down Expand Up @@ -660,6 +668,47 @@ 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/'],
];
}

/**
* @param string $email
* @return void
Expand Down Expand Up @@ -727,4 +776,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());
}
}

0 comments on commit 41cd961

Please sign in to comment.