8
8
namespace Magento \Quote \Test \Unit \Model \QuoteRepository \Plugin ;
9
9
10
10
use Magento \Authorization \Model \UserContextInterface ;
11
+ use Magento \Framework \Exception \StateException ;
11
12
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
12
13
use Magento \Quote \Model \ChangeQuoteControl ;
13
14
use Magento \Quote \Model \Quote ;
@@ -52,7 +53,7 @@ protected function setUp(): void
52
53
53
54
$ this ->quoteMock = $ this ->getMockBuilder (Quote::class)
54
55
->disableOriginalConstructor ()
55
- ->setMethods (['getCustomerId ' ])
56
+ ->addMethods (['getCustomerId ' ])
56
57
->getMock ();
57
58
58
59
$ this ->quoteRepositoryMock = $ this ->getMockBuilder (QuoteRepository::class)
@@ -63,17 +64,10 @@ protected function setUp(): void
63
64
->disableOriginalConstructor ()
64
65
->getMock ();
65
66
66
- $ objectManagerHelper = new ObjectManager ($ this );
67
- $ this ->accessChangeQuoteControl = $ objectManagerHelper ->getObject (
68
- AccessChangeQuoteControl::class,
69
- ['changeQuoteControl ' => $ this ->changeQuoteControlMock ]
70
- );
67
+ $ this ->accessChangeQuoteControl = new AccessChangeQuoteControl ($ this ->changeQuoteControlMock );
71
68
}
72
69
73
- /**
74
- * User with role Customer and customer_id matches context user_id.
75
- */
76
- public function testBeforeSaveForCustomer ()
70
+ public function testBeforeSaveForCustomerWithCustomerIdMatchinQuoteUserIdIsAllowed ()
77
71
{
78
72
$ this ->quoteMock ->method ('getCustomerId ' )
79
73
->willReturn (1 );
@@ -84,17 +78,12 @@ public function testBeforeSaveForCustomer()
84
78
$ this ->changeQuoteControlMock ->method ('isAllowed ' )
85
79
->willReturn (true );
86
80
87
- $ result = $ this ->accessChangeQuoteControl ->beforeSave ($ this ->quoteRepositoryMock , $ this ->quoteMock );
88
-
89
- $ this ->assertNull ($ result );
81
+ $ this ->accessChangeQuoteControl ->beforeSave ($ this ->quoteRepositoryMock , $ this ->quoteMock );
90
82
}
91
83
92
- /**
93
- * The user_id and customer_id from the quote are different.
94
- */
95
- public function testBeforeSaveException ()
84
+ public function testBeforeSaveThrowsExceptionForCustomerWithCustomerIdNotMatchingQuoteUserId ()
96
85
{
97
- $ this ->expectException (' Magento\Framework\Exception\ StateException' );
86
+ $ this ->expectException (StateException::class );
98
87
$ this ->expectExceptionMessage ('Invalid state change requested ' );
99
88
$ this ->quoteMock ->method ('getCustomerId ' )
100
89
->willReturn (2 );
@@ -108,10 +97,7 @@ public function testBeforeSaveException()
108
97
$ this ->accessChangeQuoteControl ->beforeSave ($ this ->quoteRepositoryMock , $ this ->quoteMock );
109
98
}
110
99
111
- /**
112
- * User with role Admin and customer_id not much with user_id.
113
- */
114
- public function testBeforeSaveForAdmin ()
100
+ public function testBeforeSaveForAdminUserRoleIsAllowed ()
115
101
{
116
102
$ this ->quoteMock ->method ('getCustomerId ' )
117
103
->willReturn (2 );
@@ -122,15 +108,10 @@ public function testBeforeSaveForAdmin()
122
108
$ this ->changeQuoteControlMock ->method ('isAllowed ' )
123
109
->willReturn (true );
124
110
125
- $ result = $ this ->accessChangeQuoteControl ->beforeSave ($ this ->quoteRepositoryMock , $ this ->quoteMock );
126
-
127
- $ this ->assertNull ($ result );
111
+ $ this ->accessChangeQuoteControl ->beforeSave ($ this ->quoteRepositoryMock , $ this ->quoteMock );
128
112
}
129
113
130
- /**
131
- * User with role Guest and customer_id === null.
132
- */
133
- public function testBeforeSaveForGuest ()
114
+ public function testBeforeSaveForGuestIsAllowed ()
134
115
{
135
116
$ this ->quoteMock ->method ('getCustomerId ' )
136
117
->willReturn (null );
@@ -141,17 +122,12 @@ public function testBeforeSaveForGuest()
141
122
$ this ->changeQuoteControlMock ->method ('isAllowed ' )
142
123
->willReturn (true );
143
124
144
- $ result = $ this ->accessChangeQuoteControl ->beforeSave ($ this ->quoteRepositoryMock , $ this ->quoteMock );
145
-
146
- $ this ->assertNull ($ result );
125
+ $ this ->accessChangeQuoteControl ->beforeSave ($ this ->quoteRepositoryMock , $ this ->quoteMock );
147
126
}
148
127
149
- /**
150
- * User with role Guest and customer_id !== null.
151
- */
152
- public function testBeforeSaveForGuestException ()
128
+ public function testBeforeSaveThrowsExceptionForGuestDoesNotEquals ()
153
129
{
154
- $ this ->expectException (' Magento\Framework\Exception\ StateException' );
130
+ $ this ->expectException (StateException::class );
155
131
$ this ->expectExceptionMessage ('Invalid state change requested ' );
156
132
$ this ->quoteMock ->method ('getCustomerId ' )
157
133
->willReturn (1 );
@@ -165,12 +141,9 @@ public function testBeforeSaveForGuestException()
165
141
$ this ->accessChangeQuoteControl ->beforeSave ($ this ->quoteRepositoryMock , $ this ->quoteMock );
166
142
}
167
143
168
- /**
169
- * User with unknown role.
170
- */
171
- public function testBeforeSaveForUnknownUserTypeException ()
144
+ public function testBeforeSaveThrowsExceptionForUnknownUserType ()
172
145
{
173
- $ this ->expectException (' Magento\Framework\Exception\ StateException' );
146
+ $ this ->expectException (StateException::class );
174
147
$ this ->expectExceptionMessage ('Invalid state change requested ' );
175
148
$ this ->quoteMock ->method ('getCustomerId ' )
176
149
->willReturn (2 );
0 commit comments