Skip to content

Commit b335359

Browse files
author
Stanislav Idolov
authored
🔃 [EngCom] Public Pull Requests - 2.3-develop
Accepted Public Pull Requests: - #13630: [Forwardport] magento/magento2#:11155 Refactor ConfigGenerator to replace/set crypt key instead of append (by @nmalevanec) - #13618: [Forwardport] magento/magento2#:13040 Customer Login/Logout Issue (by @nmalevanec) Fixed GitHub Issues: - #11089: setup:config:set --key append instead of replace (reported by @ju5t) has been fixed in #13630 by @nmalevanec in 2.3-develop branch Related commits: 1. 88a90f8
2 parents 0f61d2d + 5282516 commit b335359

File tree

9 files changed

+418
-139
lines changed

9 files changed

+418
-139
lines changed

app/code/Magento/Customer/Model/Account/Redirect.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ class Redirect
7474
*/
7575
private $hostChecker;
7676

77+
/**
78+
* @var Session
79+
*/
80+
private $session;
81+
7782
/**
7883
* @param RequestInterface $request
7984
* @param Session $customerSession
@@ -206,6 +211,10 @@ protected function processLoggedCustomer()
206211
$referer = $this->request->getParam(CustomerUrl::REFERER_QUERY_PARAM_NAME);
207212
if ($referer) {
208213
$referer = $this->urlDecoder->decode($referer);
214+
preg_match('/logoutSuccess\//', $referer, $matches, PREG_OFFSET_CAPTURE);
215+
if (!empty($matches)) {
216+
$referer = str_replace('logoutSuccess/', '', $referer);
217+
}
209218
if ($this->hostChecker->isOwnOrigin($referer)) {
210219
$this->applyRedirect($referer);
211220
}

app/code/Magento/Customer/Test/Unit/Model/Account/RedirectTest.php

Lines changed: 44 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
use Magento\Customer\Model\Account\Redirect;
1212
use Magento\Customer\Model\Url as CustomerUrl;
1313
use Magento\Framework\Controller\ResultFactory;
14+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1415
use Magento\Framework\Url\HostChecker;
1516
use Magento\Store\Model\ScopeInterface;
16-
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1717

1818
/**
1919
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -147,15 +147,15 @@ protected function setUp()
147147
$this->model = $objectManager->getObject(
148148
\Magento\Customer\Model\Account\Redirect::class,
149149
[
150-
'request' => $this->request,
151-
'customerSession' => $this->customerSession,
152-
'scopeConfig' => $this->scopeConfig,
153-
'storeManager' => $this->storeManager,
154-
'url' => $this->url,
155-
'urlDecoder' => $this->urlDecoder,
156-
'customerUrl' => $this->customerUrl,
157-
'resultFactory' => $this->resultFactory,
158-
'hostChecker' => $this->hostChecker
150+
'request' => $this->request,
151+
'customerSession' => $this->customerSession,
152+
'scopeConfig' => $this->scopeConfig,
153+
'storeManager' => $this->storeManager,
154+
'url' => $this->url,
155+
'urlDecoder' => $this->urlDecoder,
156+
'customerUrl' => $this->customerUrl,
157+
'resultFactory' => $this->resultFactory,
158+
'hostChecker' => $this->hostChecker,
159159
]
160160
);
161161
}
@@ -191,57 +191,31 @@ public function testGetRedirect(
191191
$redirectToDashboard
192192
) {
193193
// Preparations for method updateLastCustomerId()
194-
$this->customerSession->expects($this->once())
195-
->method('getLastCustomerId')
196-
->willReturn($customerId);
197-
$this->customerSession->expects($this->any())
198-
->method('isLoggedIn')
199-
->willReturn($customerLoggedIn);
200-
$this->customerSession->expects($this->any())
201-
->method('getId')
202-
->willReturn($lastCustomerId);
203-
$this->customerSession->expects($this->any())
204-
->method('unsBeforeAuthUrl')
205-
->willReturnSelf();
194+
$this->customerSession->expects($this->once())->method('getLastCustomerId')->willReturn($customerId);
195+
$this->customerSession->expects($this->any())->method('isLoggedIn')->willReturn($customerLoggedIn);
196+
$this->customerSession->expects($this->any())->method('getId')->willReturn($lastCustomerId);
197+
$this->customerSession->expects($this->any())->method('unsBeforeAuthUrl')->willReturnSelf();
206198
$this->customerSession->expects($this->any())
207199
->method('setLastCustomerId')
208200
->with($lastCustomerId)
209201
->willReturnSelf();
210202

211203
// Preparations for method prepareRedirectUrl()
212-
$this->store->expects($this->once())
213-
->method('getBaseUrl')
214-
->willReturn($baseUrl);
204+
$this->store->expects($this->once())->method('getBaseUrl')->willReturn($baseUrl);
215205

216-
$this->customerSession->expects($this->any())
217-
->method('getBeforeAuthUrl')
218-
->willReturn($beforeAuthUrl);
219-
$this->customerSession->expects($this->any())
220-
->method('setBeforeAuthUrl')
221-
->willReturnSelf();
222-
$this->customerSession->expects($this->any())
223-
->method('getAfterAuthUrl')
224-
->willReturn($afterAuthUrl);
206+
$this->customerSession->expects($this->any())->method('getBeforeAuthUrl')->willReturn($beforeAuthUrl);
207+
$this->customerSession->expects($this->any())->method('setBeforeAuthUrl')->willReturnSelf();
208+
$this->customerSession->expects($this->any())->method('getAfterAuthUrl')->willReturn($afterAuthUrl);
225209
$this->customerSession->expects($this->any())
226210
->method('setAfterAuthUrl')
227211
->with($beforeAuthUrl)
228212
->willReturnSelf();
229-
$this->customerSession->expects($this->any())
230-
->method('getBeforeRequestParams')
231-
->willReturn(false);
232-
233-
$this->customerUrl->expects($this->any())
234-
->method('getAccountUrl')
235-
->willReturn($accountUrl);
236-
$this->customerUrl->expects($this->any())
237-
->method('getLoginUrl')
238-
->willReturn($loginUrl);
239-
$this->customerUrl->expects($this->any())
240-
->method('getLogoutUrl')
241-
->willReturn($logoutUrl);
242-
$this->customerUrl->expects($this->any())
243-
->method('getDashboardUrl')
244-
->willReturn($dashboardUrl);
213+
$this->customerSession->expects($this->any())->method('getBeforeRequestParams')->willReturn(false);
214+
215+
$this->customerUrl->expects($this->any())->method('getAccountUrl')->willReturn($accountUrl);
216+
$this->customerUrl->expects($this->any())->method('getLoginUrl')->willReturn($loginUrl);
217+
$this->customerUrl->expects($this->any())->method('getLogoutUrl')->willReturn($logoutUrl);
218+
$this->customerUrl->expects($this->any())->method('getDashboardUrl')->willReturn($dashboardUrl);
245219

246220
$this->scopeConfig->expects($this->any())
247221
->method('isSetFlag')
@@ -253,25 +227,19 @@ public function testGetRedirect(
253227
->with(CustomerUrl::REFERER_QUERY_PARAM_NAME)
254228
->willReturn($referer);
255229

256-
$this->urlDecoder->expects($this->any())
257-
->method('decode')
258-
->with($referer)
259-
->willReturn($referer);
230+
$this->urlDecoder->expects($this->any())->method('decode')->with($referer)->willReturn($referer);
260231

261-
$this->url->expects($this->any())
262-
->method('isOwnOriginUrl')
263-
->willReturn(true);
232+
$this->url->expects($this->any())->method('isOwnOriginUrl')->willReturn(true);
264233

265-
$this->resultRedirect->expects($this->once())
266-
->method('setUrl')
267-
->with($beforeAuthUrl)
268-
->willReturnSelf();
234+
$this->resultRedirect->expects($this->once())->method('setUrl')->with($beforeAuthUrl)->willReturnSelf();
269235

270236
$this->resultFactory->expects($this->once())
271237
->method('create')
272238
->with(ResultFactory::TYPE_REDIRECT)
273239
->willReturn($this->resultRedirect);
274240

241+
$this->hostChecker->expects($this->any())->method('isOwnOrigin')->willReturn(true);
242+
275243
$this->model->getRedirect();
276244
}
277245

@@ -306,6 +274,21 @@ public function getRedirectDataProvider()
306274
[1, 2, 'referer', 'base', 'logout', '', 'account', 'login', 'logout', 'dashboard', false, true],
307275
// Default redirect
308276
[1, 2, 'referer', 'base', 'defined', '', 'account', 'login', 'logout', 'dashboard', true, true],
277+
// Logout, Without Redirect to Dashboard
278+
[
279+
'customer_id' => 1,
280+
'last_customer_id' => 2,
281+
'referer' => 'http://base.com/customer/account/logoutSuccess/',
282+
'base_url' => 'http://base.com/',
283+
'before_auth_url' => 'http://base.com/',
284+
'after_auth_url' => 'http://base.com/customer/account/',
285+
'account_url' => 'account',
286+
'login_url' => 'login',
287+
'logout_url' => 'logout',
288+
'dashboard_url' => 'dashboard',
289+
'is_customer_logged_id_flag' => true,
290+
'redirect_to_dashboard_flag' => false,
291+
],
309292
];
310293
}
311294

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Framework\Config\Data;
8+
9+
use Magento\Framework\App\ObjectManager;
10+
use Magento\Framework\ObjectManagerInterface;
11+
12+
/**
13+
* Factory for ConfigData.
14+
*/
15+
class ConfigDataFactory
16+
{
17+
/**
18+
* @var ObjectManager
19+
*/
20+
private $objectManager;
21+
22+
/**
23+
* Factory constructor.
24+
*
25+
* @param ObjectManagerInterface $objectManager
26+
*/
27+
public function __construct(ObjectManagerInterface $objectManager)
28+
{
29+
$this->objectManager = $objectManager;
30+
}
31+
32+
/**
33+
* Returns a new instance of ConfigData on every call.
34+
*
35+
* @param string $fileKey
36+
* @return ConfigData
37+
*/
38+
public function create($fileKey)
39+
{
40+
return $this->objectManager->create(ConfigData::class, ['fileKey' => $fileKey]);
41+
}
42+
}

0 commit comments

Comments
 (0)