1717use OCP \IServerContainer ;
1818use OCP \Talk \IConversationOptions ;
1919use OCP \Talk \ITalkBackend ;
20+ use PHPUnit \Framework \Attributes \DataProvider ;
2021use Psr \Log \LoggerInterface ;
2122use RuntimeException ;
2223use Test \TestCase ;
@@ -52,7 +53,7 @@ public function testHasNoBackendCalledTooEarly(): void {
5253 }
5354
5455 public function testHasNoBackend (): void {
55- $ this ->coordinator ->expects (self :: once ())
56+ $ this ->coordinator ->expects ($ this -> once ())
5657 ->method ('getRegistrationContext ' )
5758 ->willReturn ($ this ->createMock (RegistrationContext::class));
5859
@@ -64,16 +65,16 @@ public function testHasNoBackend(): void {
6465 public function testHasFaultyBackend (): void {
6566 $ fakeTalkServiceClass = '\\OCA \\Spreed \\TalkBackend ' ;
6667 $ registrationContext = $ this ->createMock (RegistrationContext::class);
67- $ this ->coordinator ->expects (self :: once ())
68+ $ this ->coordinator ->expects ($ this -> once ())
6869 ->method ('getRegistrationContext ' )
6970 ->willReturn ($ registrationContext );
70- $ registrationContext ->expects (self :: once ())
71+ $ registrationContext ->expects ($ this -> once ())
7172 ->method ('getTalkBackendRegistration ' )
7273 ->willReturn (new ServiceRegistration ('spreed ' , $ fakeTalkServiceClass ));
73- $ this ->container ->expects (self :: once ())
74+ $ this ->container ->expects ($ this -> once ())
7475 ->method ('get ' )
7576 ->willThrowException (new QueryException ());
76- $ this ->logger ->expects (self :: once ())
77+ $ this ->logger ->expects ($ this -> once ())
7778 ->method ('error ' );
7879
7980 self ::assertFalse (
@@ -84,14 +85,14 @@ public function testHasFaultyBackend(): void {
8485 public function testHasBackend (): void {
8586 $ fakeTalkServiceClass = '\\OCA \\Spreed \\TalkBackend ' ;
8687 $ registrationContext = $ this ->createMock (RegistrationContext::class);
87- $ this ->coordinator ->expects (self :: once ())
88+ $ this ->coordinator ->expects ($ this -> once ())
8889 ->method ('getRegistrationContext ' )
8990 ->willReturn ($ registrationContext );
90- $ registrationContext ->expects (self :: once ())
91+ $ registrationContext ->expects ($ this -> once ())
9192 ->method ('getTalkBackendRegistration ' )
9293 ->willReturn (new ServiceRegistration ('spreed ' , $ fakeTalkServiceClass ));
9394 $ talkService = $ this ->createMock (ITalkBackend::class);
94- $ this ->container ->expects (self :: once ())
95+ $ this ->container ->expects ($ this -> once ())
9596 ->method ('get ' )
9697 ->with ($ fakeTalkServiceClass )
9798 ->willReturn ($ talkService );
@@ -111,19 +112,19 @@ public function testNewConversationOptions(): void {
111112 public function testCreateConversation (): void {
112113 $ fakeTalkServiceClass = '\\OCA \\Spreed \\TalkBackend ' ;
113114 $ registrationContext = $ this ->createMock (RegistrationContext::class);
114- $ this ->coordinator ->expects (self :: once ())
115+ $ this ->coordinator ->expects ($ this -> once ())
115116 ->method ('getRegistrationContext ' )
116117 ->willReturn ($ registrationContext );
117- $ registrationContext ->expects (self :: once ())
118+ $ registrationContext ->expects ($ this -> once ())
118119 ->method ('getTalkBackendRegistration ' )
119120 ->willReturn (new ServiceRegistration ('spreed ' , $ fakeTalkServiceClass ));
120121 $ talkService = $ this ->createMock (ITalkBackend::class);
121- $ this ->container ->expects (self :: once ())
122+ $ this ->container ->expects ($ this -> once ())
122123 ->method ('get ' )
123124 ->with ($ fakeTalkServiceClass )
124125 ->willReturn ($ talkService );
125126 $ options = $ this ->createMock (IConversationOptions::class);
126- $ talkService ->expects (self :: once ())
127+ $ talkService ->expects ($ this -> once ())
127128 ->method ('createConversation ' )
128129 ->with ('Watercooler ' , [], $ options );
129130
@@ -133,4 +134,116 @@ public function testCreateConversation(): void {
133134 $ options
134135 );
135136 }
137+
138+ public function testIsEnabledForUserNoBackend (): void {
139+ $ this ->coordinator ->expects ($ this ->once ())
140+ ->method ('getRegistrationContext ' )
141+ ->willReturn ($ this ->createMock (RegistrationContext::class));
142+
143+ self ::assertFalse (
144+ $ this ->broker ->isEnabledForUser ()
145+ );
146+ }
147+
148+ public static function dataIsEnabledForUser (): array {
149+ return [
150+ [true ],
151+ [false ],
152+ ];
153+ }
154+
155+ #[DataProvider('dataIsEnabledForUser ' )]
156+ public function testIsEnabledForUser (bool $ enabled ): void {
157+ $ fakeTalkServiceClass = '\\OCA \\Spreed \\TalkBackend ' ;
158+ $ registrationContext = $ this ->createMock (RegistrationContext::class);
159+ $ this ->coordinator ->expects ($ this ->once ())
160+ ->method ('getRegistrationContext ' )
161+ ->willReturn ($ registrationContext );
162+ $ registrationContext ->expects ($ this ->once ())
163+ ->method ('getTalkBackendRegistration ' )
164+ ->willReturn (new ServiceRegistration ('spreed ' , $ fakeTalkServiceClass ));
165+ $ talkService = $ this ->createMock (ITalkBackend::class);
166+ $ this ->container ->expects ($ this ->once ())
167+ ->method ('get ' )
168+ ->with ($ fakeTalkServiceClass )
169+ ->willReturn ($ talkService );
170+ $ talkService ->expects ($ this ->once ())
171+ ->method ('isEnabledForUser ' )
172+ ->willReturn ($ enabled );
173+
174+ self ::assertSame (
175+ $ enabled ,
176+ $ this ->broker ->isEnabledForUser ()
177+ );
178+ }
179+
180+ public function testIsAllowedToCreateConversationsNoBackend (): void {
181+ $ this ->coordinator ->expects ($ this ->once ())
182+ ->method ('getRegistrationContext ' )
183+ ->willReturn ($ this ->createMock (RegistrationContext::class));
184+
185+ self ::assertFalse (
186+ $ this ->broker ->isAllowedToCreateConversations ()
187+ );
188+ }
189+
190+ public function testIsAllowedToCreateConversationsBackendDisabled (): void {
191+ $ fakeTalkServiceClass = '\\OCA \\Spreed \\TalkBackend ' ;
192+ $ registrationContext = $ this ->createMock (RegistrationContext::class);
193+ $ this ->coordinator ->expects ($ this ->once ())
194+ ->method ('getRegistrationContext ' )
195+ ->willReturn ($ registrationContext );
196+ $ registrationContext ->expects ($ this ->once ())
197+ ->method ('getTalkBackendRegistration ' )
198+ ->willReturn (new ServiceRegistration ('spreed ' , $ fakeTalkServiceClass ));
199+ $ talkService = $ this ->createMock (ITalkBackend::class);
200+ $ this ->container ->expects ($ this ->once ())
201+ ->method ('get ' )
202+ ->with ($ fakeTalkServiceClass )
203+ ->willReturn ($ talkService );
204+ $ talkService ->expects ($ this ->once ())
205+ ->method ('isEnabledForUser ' )
206+ ->willReturn (false );
207+ $ talkService ->expects ($ this ->never ())
208+ ->method ('isAllowedToCreateConversations ' );
209+
210+ self ::assertFalse (
211+ $ this ->broker ->isAllowedToCreateConversations ()
212+ );
213+ }
214+
215+ public static function dataIsAllowedToCreateConversations (): array {
216+ return [
217+ [true ],
218+ [false ],
219+ ];
220+ }
221+
222+ #[DataProvider('dataIsAllowedToCreateConversations ' )]
223+ public function testIsAllowedToCreateConversations (bool $ allowed ): void {
224+ $ fakeTalkServiceClass = '\\OCA \\Spreed \\TalkBackend ' ;
225+ $ registrationContext = $ this ->createMock (RegistrationContext::class);
226+ $ this ->coordinator ->expects ($ this ->once ())
227+ ->method ('getRegistrationContext ' )
228+ ->willReturn ($ registrationContext );
229+ $ registrationContext ->expects ($ this ->once ())
230+ ->method ('getTalkBackendRegistration ' )
231+ ->willReturn (new ServiceRegistration ('spreed ' , $ fakeTalkServiceClass ));
232+ $ talkService = $ this ->createMock (ITalkBackend::class);
233+ $ this ->container ->expects ($ this ->once ())
234+ ->method ('get ' )
235+ ->with ($ fakeTalkServiceClass )
236+ ->willReturn ($ talkService );
237+ $ talkService ->expects ($ this ->once ())
238+ ->method ('isEnabledForUser ' )
239+ ->willReturn (true );
240+ $ talkService ->expects ($ this ->once ())
241+ ->method ('isAllowedToCreateConversations ' )
242+ ->willReturn ($ allowed );
243+
244+ self ::assertSame (
245+ $ allowed ,
246+ $ this ->broker ->isAllowedToCreateConversations ()
247+ );
248+ }
136249}
0 commit comments