-
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.
Merge pull request #8341 from magento-l3/JUN062023_PR_sarmistha
[L3 Kings] Bugfix delivery
- Loading branch information
Showing
28 changed files
with
1,015 additions
and
104 deletions.
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
58 changes: 58 additions & 0 deletions
58
app/code/Magento/Customer/Test/Unit/ViewModel/Customer/AuthTest.php
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\Customer\Test\Unit\ViewModel\Customer; | ||
|
||
use Magento\Customer\ViewModel\Customer\Auth; | ||
use Magento\Framework\App\Http\Context; | ||
use PHPUnit\Framework\MockObject\MockObject; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class AuthTest extends TestCase | ||
{ | ||
/** | ||
* @var Context|MockObject | ||
*/ | ||
private mixed $contextMock; | ||
|
||
/** | ||
* @var Auth | ||
*/ | ||
private Auth $model; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function setUp(): void | ||
{ | ||
$this->contextMock = $this->getMockBuilder(Context::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$this->model = new Auth( | ||
$this->contextMock | ||
); | ||
parent::setUp(); | ||
} | ||
|
||
/** | ||
* Test is logged in value. | ||
* | ||
* @return void | ||
*/ | ||
public function testIsLoggedIn(): void | ||
{ | ||
$this->contextMock->expects($this->once()) | ||
->method('getValue') | ||
->willReturn(true); | ||
|
||
$this->assertEquals( | ||
true, | ||
$this->model->isLoggedIn() | ||
); | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
app/code/Magento/Customer/Test/Unit/ViewModel/Customer/JsonSerializerTest.php
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 |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\Customer\Test\Unit\ViewModel\Customer; | ||
|
||
use Magento\Customer\ViewModel\Customer\JsonSerializer; | ||
use Magento\Framework\Serialize\Serializer\Json as Json; | ||
use PHPUnit\Framework\MockObject\MockObject; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class JsonSerializerTest extends TestCase | ||
{ | ||
/** | ||
* @var Json|MockObject | ||
*/ | ||
private mixed $jsonEncoderMock; | ||
|
||
/** | ||
* @var JsonSerializer | ||
*/ | ||
private JsonSerializer $model; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function setUp(): void | ||
{ | ||
$this->jsonEncoderMock = $this->getMockBuilder(Json::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$this->model = new JsonSerializer( | ||
$this->jsonEncoderMock | ||
); | ||
parent::setUp(); | ||
} | ||
|
||
/** | ||
* Test serialize value. | ||
* | ||
* @return void | ||
*/ | ||
public function testSerialize(): void | ||
{ | ||
$this->jsonEncoderMock->expects($this->once()) | ||
->method('serialize') | ||
->willReturnCallback( | ||
function ($value) { | ||
return json_encode($value); | ||
} | ||
); | ||
|
||
$this->assertEquals( | ||
json_encode( | ||
[ | ||
'http://example.com/customer/section/load/' | ||
] | ||
), | ||
$this->model->serialize(['http://example.com/customer/section/load/']) | ||
); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\Customer\ViewModel\Customer; | ||
|
||
use Magento\Customer\Model\Context; | ||
use Magento\Framework\App\Http\Context as HttpContext; | ||
use Magento\Framework\View\Element\Block\ArgumentInterface; | ||
|
||
/** | ||
* Customer's auth view model | ||
*/ | ||
class Auth implements ArgumentInterface | ||
{ | ||
/** | ||
* @param HttpContext $httpContext | ||
*/ | ||
public function __construct( | ||
private HttpContext $httpContext | ||
) { | ||
} | ||
|
||
/** | ||
* Check is user login | ||
* | ||
* @return bool | ||
*/ | ||
public function isLoggedIn(): bool | ||
{ | ||
return $this->httpContext->getValue(Context::CONTEXT_AUTH) ?? false; | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
app/code/Magento/Customer/ViewModel/Customer/JsonSerializer.php
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\Customer\ViewModel\Customer; | ||
|
||
use Magento\Framework\Serialize\Serializer\Json as Json; | ||
use Magento\Framework\View\Element\Block\ArgumentInterface; | ||
|
||
/** | ||
* Customer's json serializer view model | ||
*/ | ||
class JsonSerializer implements ArgumentInterface | ||
{ | ||
/** | ||
* @param Json $jsonEncoder | ||
*/ | ||
public function __construct( | ||
private Json $jsonEncoder | ||
) { | ||
} | ||
|
||
/** | ||
* Encode the mixed $value into the JSON format | ||
* | ||
* @param mixed $value | ||
* @return string | ||
*/ | ||
public function serialize(mixed $value): string | ||
{ | ||
return $this->jsonEncoder->serialize($value); | ||
} | ||
} |
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
47 changes: 47 additions & 0 deletions
47
app/code/Magento/PageCache/Model/App/Request/Http/IdentifierForSave.php
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\PageCache\Model\App\Request\Http; | ||
|
||
use Magento\Framework\App\Http\Context; | ||
use Magento\Framework\App\Request\Http; | ||
use Magento\Framework\Serialize\Serializer\Json; | ||
use Magento\Framework\App\PageCache\IdentifierInterface; | ||
|
||
/** | ||
* Page unique identifier | ||
*/ | ||
class IdentifierForSave implements IdentifierInterface | ||
{ | ||
/** | ||
* @param Http $request | ||
* @param Context $context | ||
* @param Json $serializer | ||
*/ | ||
public function __construct( | ||
private Http $request, | ||
private Context $context, | ||
private Json $serializer | ||
) { | ||
} | ||
|
||
/** | ||
* Return unique page identifier | ||
* | ||
* @return string | ||
*/ | ||
public function getValue() | ||
{ | ||
$data = [ | ||
$this->request->isSecure(), | ||
$this->request->getUriString(), | ||
$this->context->getVaryString() | ||
]; | ||
|
||
return sha1($this->serializer->serialize($data)); | ||
} | ||
} |
Oops, something went wrong.