Skip to content

Commit 1239118

Browse files
committed
ACP2E-2025: Refix ACP2E-1445 for multiple store views in the frontend.
- Added the test coverage.
1 parent 16f240e commit 1239118

File tree

3 files changed

+225
-0
lines changed

3 files changed

+225
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Customer\Test\Unit\ViewModel\Customer;
9+
10+
use Magento\Customer\ViewModel\Customer\Auth;
11+
use Magento\Framework\App\Http\Context;
12+
use PHPUnit\Framework\MockObject\MockObject;
13+
use PHPUnit\Framework\TestCase;
14+
15+
class AuthTest extends TestCase
16+
{
17+
/**
18+
* @var Context|MockObject
19+
*/
20+
private mixed $contextMock;
21+
22+
private Auth $model;
23+
24+
/**
25+
* @inheritdoc
26+
*/
27+
protected function setUp(): void
28+
{
29+
$this->contextMock = $this->getMockBuilder(Context::class)
30+
->disableOriginalConstructor()
31+
->getMock();
32+
33+
$this->model = new Auth(
34+
$this->contextMock
35+
);
36+
parent::setUp();
37+
}
38+
39+
/**
40+
* Test is logged in value.
41+
*
42+
* @return void
43+
*/
44+
public function testIsLoggedIn(): void
45+
{
46+
$this->contextMock->expects($this->once())
47+
->method('getValue')
48+
->willReturn(true);
49+
50+
$this->assertEquals(
51+
true,
52+
$this->model->isLoggedIn()
53+
);
54+
}
55+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Customer\Test\Unit\ViewModel\Customer;
9+
10+
use Magento\Customer\ViewModel\Customer\JsonSerializer;
11+
use Magento\Framework\Serialize\Serializer\Json as Json;
12+
use PHPUnit\Framework\MockObject\MockObject;
13+
use PHPUnit\Framework\TestCase;
14+
15+
class JsonSerializerTest extends TestCase
16+
{
17+
/**
18+
* @var Json|MockObject
19+
*/
20+
private mixed $jsonEncoderMock;
21+
22+
private JsonSerializer $model;
23+
24+
/**
25+
* @inheritdoc
26+
*/
27+
protected function setUp(): void
28+
{
29+
$this->jsonEncoderMock = $this->getMockBuilder(Json::class)
30+
->disableOriginalConstructor()
31+
->getMock();
32+
33+
$this->model = new JsonSerializer(
34+
$this->jsonEncoderMock
35+
);
36+
parent::setUp();
37+
}
38+
39+
/**
40+
* Test json encode value.
41+
*
42+
* @return void
43+
*/
44+
public function testJsonEncode(): void
45+
{
46+
$this->jsonEncoderMock->expects($this->once())
47+
->method('serialize')
48+
->willReturnCallback(
49+
function ($value) {
50+
return json_encode($value);
51+
}
52+
);
53+
54+
$this->assertEquals(
55+
json_encode(
56+
[
57+
'http://example.com/customer/section/load/'
58+
]
59+
),
60+
$this->model->jsonEncode(['http://example.com/customer/section/load/'])
61+
);
62+
}
63+
}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\PageCache\Test\Unit\Model\App\Request\Http;
9+
10+
use Magento\Framework\App\Http\Context;
11+
use Magento\Framework\App\Request\Http as HttpRequest;
12+
use Magento\Framework\Serialize\Serializer\Json;
13+
use Magento\PageCache\Model\App\Request\Http\IdentifierForSave;
14+
use PHPUnit\Framework\MockObject\MockObject;
15+
use PHPUnit\Framework\TestCase;
16+
17+
class IdentifierForSaveTest extends TestCase
18+
{
19+
/**
20+
* Test value for cache vary string
21+
*/
22+
const VARY = '123';
23+
24+
/**
25+
* @var Context|MockObject
26+
*/
27+
private mixed $contextMock;
28+
29+
/**
30+
* @var HttpRequest|MockObject
31+
*/
32+
private mixed $requestMock;
33+
34+
/**
35+
* @var IdentifierForSave
36+
*/
37+
private IdentifierForSave $model;
38+
39+
/**
40+
* @var Json|MockObject
41+
*/
42+
private mixed $serializerMock;
43+
44+
/**
45+
* @inheritdoc
46+
*/
47+
protected function setUp(): void
48+
{
49+
$this->requestMock = $this->getMockBuilder(HttpRequest::class)
50+
->disableOriginalConstructor()
51+
->getMock();
52+
$this->contextMock = $this->getMockBuilder(Context::class)
53+
->disableOriginalConstructor()
54+
->getMock();
55+
$this->serializerMock = $this->getMockBuilder(Json::class)
56+
->onlyMethods(['serialize'])
57+
->disableOriginalConstructor()
58+
->getMock();
59+
$this->serializerMock->expects($this->any())
60+
->method('serialize')
61+
->willReturnCallback(
62+
function ($value) {
63+
return json_encode($value);
64+
}
65+
);
66+
67+
$this->model = new IdentifierForSave(
68+
$this->requestMock,
69+
$this->contextMock,
70+
$this->serializerMock
71+
);
72+
parent::setUp();
73+
}
74+
75+
/**
76+
* Test get identifier for save value.
77+
*
78+
* @return void
79+
*/
80+
public function testGetValue(): void
81+
{
82+
$this->requestMock->expects($this->any())
83+
->method('isSecure')
84+
->willReturn(true);
85+
86+
$this->requestMock->expects($this->any())
87+
->method('getUriString')
88+
->willReturn('http://example.com/path1/');
89+
90+
$this->contextMock->expects($this->any())
91+
->method('getVaryString')
92+
->willReturn(self::VARY);
93+
94+
$this->assertEquals(
95+
sha1(
96+
json_encode(
97+
[
98+
true,
99+
'http://example.com/path1/',
100+
self::VARY
101+
]
102+
)
103+
),
104+
$this->model->getValue()
105+
);
106+
}
107+
}

0 commit comments

Comments
 (0)