@@ -84,4 +84,79 @@ public function testAroundDispatchProlongStorage()
84
84
85
85
$ this ->assertEquals ($ expectedResult , $ this ->plugin ->aroundDispatch ($ subject , $ proceed , $ request ));
86
86
}
87
+
88
+ /**
89
+ * Calls aroundDispatch to access protected method _processNotLoggedInUser
90
+ *
91
+ * Data provider supplies different possibilities of request parameters and properties
92
+ * @dataProvider userNotLoggedInRequest
93
+ */
94
+ public function testProcessNotLoggedInUser ($ isIFrameParam , $ isAjaxParam , $ isForwardedFlag )
95
+ {
96
+ $ subject = $ this ->getMockBuilder ('Magento\Backend\Controller\Adminhtml\Index ' )
97
+ ->disableOriginalConstructor ()
98
+ ->getMock ();
99
+ $ request = $ this ->getMockBuilder ('Magento\Framework\App\Request\Http ' )
100
+ ->disableOriginalConstructor ()
101
+ ->getMock ();
102
+ $ storage = $ this ->getMockBuilder ('Magento\Backend\Model\Auth\Session ' )
103
+ ->disableOriginalConstructor ()
104
+ ->getMock ();
105
+
106
+ // Stubs to control the flow of execution in aroundDispatch
107
+ $ this ->auth ->expects ($ this ->any ())->method ('getAuthStorage ' )->will ($ this ->returnValue ($ storage ));
108
+ $ request ->expects ($ this ->once ())->method ('getActionName ' )->will ($ this ->returnValue ('non/open/action/name ' ));
109
+ $ this ->auth ->expects ($ this ->any ())->method ('getUser ' )->willReturn (false );
110
+ $ this ->auth ->expects ($ this ->once ())->method ('isLoggedIn ' )->will ($ this ->returnValue (false ));
111
+ $ request ->expects ($ this ->any ())->method ('getPost ' )->willReturn (false );
112
+
113
+ // Test cases and expectations based on provided data
114
+ $ request ->expects ($ this ->once ())->method ('isForwarded ' )->willReturn ($ isForwardedFlag );
115
+ $ getParamCalls = 0 ;
116
+ $ actionName = '' ;
117
+
118
+ // If forwarded flag is set, getParam never gets called
119
+ if (!$ isForwardedFlag ) {
120
+ if ($ isIFrameParam ) {
121
+ $ getParamCalls = 1 ;
122
+ $ actionName = 'deniedIframe ' ;
123
+ } else if ($ isAjaxParam ) {
124
+ $ getParamCalls = 2 ;
125
+ $ actionName = 'deniedJson ' ;
126
+ } else {
127
+ $ getParamCalls = 2 ;
128
+ $ actionName = 'login ' ;
129
+ }
130
+ }
131
+
132
+ $ requestParams = [
133
+ ['isIframe ' , null , $ isIFrameParam ],
134
+ ['isAjax ' , null , $ isAjaxParam ]
135
+ ];
136
+
137
+ $ setterCalls = $ isForwardedFlag ? 0 : 1 ;
138
+ $ request ->expects ($ this ->exactly ($ getParamCalls ))->method ('getParam ' )->willReturnMap ($ requestParams );
139
+ $ request ->expects ($ this ->exactly ($ setterCalls ))->method ('setForwarded ' )->with (true )->willReturnSelf ();
140
+ $ request ->expects ($ this ->exactly ($ setterCalls ))->method ('setRouteName ' )->with ('adminhtml ' )->willReturnSelf ();
141
+ $ request ->expects ($ this ->exactly ($ setterCalls ))->method ('setControllerName ' )->with ('auth ' )->willReturnSelf ();
142
+ $ request ->expects ($ this ->exactly ($ setterCalls ))->method ('setActionName ' )->with ($ actionName )->willReturnSelf ();
143
+ $ request ->expects ($ this ->exactly ($ setterCalls ))->method ('setDispatched ' )->with (false )->willReturnSelf ();
144
+
145
+ $ expectedResult = 'expectedResult ' ;
146
+ $ proceed = function ($ request ) use ($ expectedResult )
147
+ {
148
+ return $ expectedResult ;
149
+ };
150
+ $ this ->assertEquals ($ expectedResult , $ this ->plugin ->aroundDispatch ($ subject , $ proceed , $ request ));
151
+ }
152
+
153
+ public function userNotLoggedInRequest ()
154
+ {
155
+ return [
156
+ 'iFrame ' => [true , false , false ],
157
+ 'Ajax ' => [false , true , false ],
158
+ 'Neither iFrame nor Ajax ' => [false , false , false ],
159
+ 'Forwarded request ' => [true , true , true ]
160
+ ];
161
+ }
87
162
}
0 commit comments