2626use ChristophWurst \Nextcloud \Testing \TestCase ;
2727use OCA \Mail \Controller \PageController ;
2828use OCA \Mail \Http \Middleware \ProvisioningMiddleware ;
29+ use OCA \Mail \Service \Provisioning \Config ;
2930use OCA \Mail \Service \Provisioning \Manager ;
3031use OCP \Authentication \Exceptions \CredentialsUnavailableException ;
3132use OCP \Authentication \Exceptions \PasswordUnavailableException ;
@@ -86,6 +87,13 @@ public function testBeforeControllerNoCredentialsAvailable() {
8687 $ this ->userSession ->expects ($ this ->once ())
8788 ->method ('getUser ' )
8889 ->willReturn ($ user );
90+ $ config = $ this ->createMock (Config::class);
91+ $ this ->provisioningManager ->expects ($ this ->once ())
92+ ->method ('getConfig ' )
93+ ->willReturn ($ config );
94+ $ config ->expects ($ this ->once ())
95+ ->method ('isActive ' )
96+ ->willReturn (true );
8997 $ this ->credentialStore ->expects ($ this ->once ())
9098 ->method ('getLoginCredentials ' )
9199 ->willThrowException ($ this ->createMock (CredentialsUnavailableException::class));
@@ -103,6 +111,13 @@ public function testBeforeControllerNoPasswordAvailable() {
103111 $ this ->userSession ->expects ($ this ->once ())
104112 ->method ('getUser ' )
105113 ->willReturn ($ user );
114+ $ config = $ this ->createMock (Config::class);
115+ $ this ->provisioningManager ->expects ($ this ->once ())
116+ ->method ('getConfig ' )
117+ ->willReturn ($ config );
118+ $ config ->expects ($ this ->once ())
119+ ->method ('isActive ' )
120+ ->willReturn (true );
106121 $ credentials = $ this ->createMock (ICredentials::class);
107122 $ this ->credentialStore ->expects ($ this ->once ())
108123 ->method ('getLoginCredentials ' )
@@ -119,11 +134,60 @@ public function testBeforeControllerNoPasswordAvailable() {
119134 );
120135 }
121136
137+ public function testBeforeControllerNoConfigAvailable () {
138+ $ user = $ this ->createMock (IUser::class);
139+ $ this ->userSession ->expects ($ this ->once ())
140+ ->method ('getUser ' )
141+ ->willReturn ($ user );
142+ $ this ->provisioningManager ->expects ($ this ->once ())
143+ ->method ('getConfig ' )
144+ ->willReturn (null );
145+ $ this ->credentialStore ->expects ($ this ->never ())
146+ ->method ('getLoginCredentials ' );
147+ $ this ->provisioningManager ->expects ($ this ->never ())
148+ ->method ('updatePassword ' );
149+
150+ $ this ->middleware ->beforeController (
151+ $ this ->createMock (PageController::class),
152+ 'index '
153+ );
154+ }
155+
156+ public function testBeforeControllerNotActive () {
157+ $ user = $ this ->createMock (IUser::class);
158+ $ this ->userSession ->expects ($ this ->once ())
159+ ->method ('getUser ' )
160+ ->willReturn ($ user );
161+ $ config = $ this ->createMock (Config::class);
162+ $ this ->provisioningManager ->expects ($ this ->once ())
163+ ->method ('getConfig ' )
164+ ->willReturn ($ config );
165+ $ config ->expects ($ this ->once ())
166+ ->method ('isActive ' )
167+ ->willReturn (false );
168+ $ this ->credentialStore ->expects ($ this ->never ())
169+ ->method ('getLoginCredentials ' );
170+ $ this ->provisioningManager ->expects ($ this ->never ())
171+ ->method ('updatePassword ' );
172+
173+ $ this ->middleware ->beforeController (
174+ $ this ->createMock (PageController::class),
175+ 'index '
176+ );
177+ }
178+
122179 public function testBeforeController () {
123180 $ user = $ this ->createMock (IUser::class);
124181 $ this ->userSession ->expects ($ this ->once ())
125182 ->method ('getUser ' )
126183 ->willReturn ($ user );
184+ $ config = $ this ->createMock (Config::class);
185+ $ this ->provisioningManager ->expects ($ this ->once ())
186+ ->method ('getConfig ' )
187+ ->willReturn ($ config );
188+ $ config ->expects ($ this ->once ())
189+ ->method ('isActive ' )
190+ ->willReturn (true );
127191 $ credentials = $ this ->createMock (ICredentials::class);
128192 $ this ->credentialStore ->expects ($ this ->once ())
129193 ->method ('getLoginCredentials ' )
0 commit comments