-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
⏫ Forwardport of #11876 to 2.3-develop branch
- Loading branch information
1 parent
8e77e2f
commit 41cd961
Showing
3 changed files
with
88 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
|
@@ -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 | ||
|
@@ -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()); | ||
} | ||
} |