88namespace Magento \Quote \Test \Unit \Model \QuoteRepository \Plugin ;
99
1010use Magento \Authorization \Model \UserContextInterface ;
11+ use Magento \Framework \Exception \StateException ;
1112use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
1213use Magento \Quote \Model \ChangeQuoteControl ;
1314use Magento \Quote \Model \Quote ;
@@ -52,7 +53,7 @@ protected function setUp(): void
5253
5354 $ this ->quoteMock = $ this ->getMockBuilder (Quote::class)
5455 ->disableOriginalConstructor ()
55- ->setMethods (['getCustomerId ' ])
56+ ->addMethods (['getCustomerId ' ])
5657 ->getMock ();
5758
5859 $ this ->quoteRepositoryMock = $ this ->getMockBuilder (QuoteRepository::class)
@@ -63,17 +64,10 @@ protected function setUp(): void
6364 ->disableOriginalConstructor ()
6465 ->getMock ();
6566
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 );
7168 }
7269
73- /**
74- * User with role Customer and customer_id matches context user_id.
75- */
76- public function testBeforeSaveForCustomer ()
70+ public function testBeforeSaveForCustomerWithCustomerIdMatchinQuoteUserIdIsAllowed ()
7771 {
7872 $ this ->quoteMock ->method ('getCustomerId ' )
7973 ->willReturn (1 );
@@ -84,17 +78,12 @@ public function testBeforeSaveForCustomer()
8478 $ this ->changeQuoteControlMock ->method ('isAllowed ' )
8579 ->willReturn (true );
8680
87- $ result = $ this ->accessChangeQuoteControl ->beforeSave ($ this ->quoteRepositoryMock , $ this ->quoteMock );
88-
89- $ this ->assertNull ($ result );
81+ $ this ->accessChangeQuoteControl ->beforeSave ($ this ->quoteRepositoryMock , $ this ->quoteMock );
9082 }
9183
92- /**
93- * The user_id and customer_id from the quote are different.
94- */
95- public function testBeforeSaveException ()
84+ public function testBeforeSaveThrowsExceptionForCustomerWithCustomerIdNotMatchingQuoteUserId ()
9685 {
97- $ this ->expectException (' Magento\Framework\Exception\ StateException' );
86+ $ this ->expectException (StateException::class );
9887 $ this ->expectExceptionMessage ('Invalid state change requested ' );
9988 $ this ->quoteMock ->method ('getCustomerId ' )
10089 ->willReturn (2 );
@@ -108,10 +97,7 @@ public function testBeforeSaveException()
10897 $ this ->accessChangeQuoteControl ->beforeSave ($ this ->quoteRepositoryMock , $ this ->quoteMock );
10998 }
11099
111- /**
112- * User with role Admin and customer_id not much with user_id.
113- */
114- public function testBeforeSaveForAdmin ()
100+ public function testBeforeSaveForAdminUserRoleIsAllowed ()
115101 {
116102 $ this ->quoteMock ->method ('getCustomerId ' )
117103 ->willReturn (2 );
@@ -122,15 +108,10 @@ public function testBeforeSaveForAdmin()
122108 $ this ->changeQuoteControlMock ->method ('isAllowed ' )
123109 ->willReturn (true );
124110
125- $ result = $ this ->accessChangeQuoteControl ->beforeSave ($ this ->quoteRepositoryMock , $ this ->quoteMock );
126-
127- $ this ->assertNull ($ result );
111+ $ this ->accessChangeQuoteControl ->beforeSave ($ this ->quoteRepositoryMock , $ this ->quoteMock );
128112 }
129113
130- /**
131- * User with role Guest and customer_id === null.
132- */
133- public function testBeforeSaveForGuest ()
114+ public function testBeforeSaveForGuestIsAllowed ()
134115 {
135116 $ this ->quoteMock ->method ('getCustomerId ' )
136117 ->willReturn (null );
@@ -141,17 +122,12 @@ public function testBeforeSaveForGuest()
141122 $ this ->changeQuoteControlMock ->method ('isAllowed ' )
142123 ->willReturn (true );
143124
144- $ result = $ this ->accessChangeQuoteControl ->beforeSave ($ this ->quoteRepositoryMock , $ this ->quoteMock );
145-
146- $ this ->assertNull ($ result );
125+ $ this ->accessChangeQuoteControl ->beforeSave ($ this ->quoteRepositoryMock , $ this ->quoteMock );
147126 }
148127
149- /**
150- * User with role Guest and customer_id !== null.
151- */
152- public function testBeforeSaveForGuestException ()
128+ public function testBeforeSaveThrowsExceptionForGuestDoesNotEquals ()
153129 {
154- $ this ->expectException (' Magento\Framework\Exception\ StateException' );
130+ $ this ->expectException (StateException::class );
155131 $ this ->expectExceptionMessage ('Invalid state change requested ' );
156132 $ this ->quoteMock ->method ('getCustomerId ' )
157133 ->willReturn (1 );
@@ -165,12 +141,9 @@ public function testBeforeSaveForGuestException()
165141 $ this ->accessChangeQuoteControl ->beforeSave ($ this ->quoteRepositoryMock , $ this ->quoteMock );
166142 }
167143
168- /**
169- * User with unknown role.
170- */
171- public function testBeforeSaveForUnknownUserTypeException ()
144+ public function testBeforeSaveThrowsExceptionForUnknownUserType ()
172145 {
173- $ this ->expectException (' Magento\Framework\Exception\ StateException' );
146+ $ this ->expectException (StateException::class );
174147 $ this ->expectExceptionMessage ('Invalid state change requested ' );
175148 $ this ->quoteMock ->method ('getCustomerId ' )
176149 ->willReturn (2 );
0 commit comments