Skip to content

Commit

Permalink
#10834: Signing in after selecting checkout button, will not end up t…
Browse files Browse the repository at this point in the history
…o checkout page
  • Loading branch information
p-bystritsky committed Oct 30, 2017
1 parent 08f0056 commit fe1b4b1
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 7 deletions.
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 @@ -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 $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
*/
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' => '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());
}
}

0 comments on commit fe1b4b1

Please sign in to comment.