@@ -47,13 +47,13 @@ class AuthorizationTest extends TestCase
47
47
protected function setUp (): void
48
48
{
49
49
$ this ->persistentSessionMock = $ this ->getMockBuilder (PersistentSession::class)
50
- ->onlyMethods (['isPersistent ' ])
51
50
->disableOriginalConstructor ()
52
51
->getMock ();
53
52
54
53
$ this ->customerSessionMock = $ this ->getMockBuilder (CustomerSession::class)
55
- ->onlyMethods (['isLoggedIn ' ])
56
54
->disableOriginalConstructor ()
55
+ ->addMethods (['getIsCustomerEmulated ' ])
56
+ ->onlyMethods (['getCustomerId ' ])
57
57
->getMock ();
58
58
59
59
$ this ->persistentCustomerAuthorization = new PersistentAuthorization (
@@ -71,19 +71,24 @@ protected function setUp(): void
71
71
*
72
72
* @dataProvider persistentLoggedInCombinations
73
73
* @param bool $isPersistent
74
- * @param bool $isLoggedIn
75
- * @param bool $isAllowedExpectation
74
+ * @param int|null $customerId
75
+ * @param bool|null $isCustomerEmulated
76
+ * @param bool $shouldBeAllowed
76
77
*/
77
78
public function testIsAuthorized (
78
79
bool $ isPersistent ,
79
- bool $ isLoggedIn ,
80
- bool $ isAllowedExpectation
81
- ): void {
82
- $ this ->persistentSessionMock ->method ('isPersistent ' )->willReturn ($ isPersistent );
83
- $ this ->customerSessionMock ->method ('isLoggedIn ' )->willReturn ($ isLoggedIn );
80
+ ?int $ customerId ,
81
+ ?bool $ isCustomerEmulated ,
82
+ bool $ shouldBeAllowed
83
+ ): void
84
+ {
85
+ $ this ->persistentSessionMock ->expects ($ this ->any ())->method ('isPersistent ' )->willReturn ($ isPersistent );
86
+ $ this ->customerSessionMock ->expects ($ this ->any ())->method ('getCustomerId ' )->willReturn ($ customerId );
87
+ $ this ->customerSessionMock ->expects ($ this ->any ())->method ('getIsCustomerEmulated ' )->willReturn ($ isCustomerEmulated );
88
+
84
89
$ isAllowedResult = $ this ->customerAuthorizationComposite ->isAllowed ('self ' );
85
90
86
- $ this ->assertEquals ($ isAllowedExpectation , $ isAllowedResult );
91
+ $ this ->assertEquals ($ shouldBeAllowed , $ isAllowedResult );
87
92
}
88
93
89
94
/**
@@ -92,21 +97,30 @@ public function testIsAuthorized(
92
97
public function persistentLoggedInCombinations (): array
93
98
{
94
99
return [
95
- [
96
- true ,
97
- false ,
98
- false
100
+ 'Emulated persistent Customer ID#1 should not be authorized ' => [
101
+ 'isPersistent ' => true ,
102
+ 'customerId ' => 1 ,
103
+ 'isCustomerEmulated ' => true ,
104
+ 'shouldBeAllowed ' => false
99
105
],
100
- [
101
- true ,
102
- true ,
103
- true
106
+ 'Logged-in persistent Customer ID#1 should be authorized ' => [
107
+ 'isPersistent ' => true ,
108
+ 'customerId ' => 1 ,
109
+ 'isCustomerEmulated ' => false ,
110
+ 'shouldBeAllowed ' => true
104
111
],
105
- [
106
- false ,
107
- false ,
108
- true
112
+ 'Logged-in Customer ID#1 without persistency should be authorized ' => [
113
+ 'isPersistent ' => false ,
114
+ 'customerId ' => 1 ,
115
+ 'isCustomerEmulated ' => false ,
116
+ 'shouldBeAllowed ' => true
109
117
],
118
+ 'Persistent Customer ID/ isCustomerEmulated = null (API Request) should be authorized ' => [
119
+ 'isPersistent ' => true ,
120
+ 'customerId ' => null ,
121
+ 'isCustomerEmulated ' => null ,
122
+ 'shouldBeAllowed ' => true
123
+ ]
110
124
];
111
125
}
112
126
}
0 commit comments