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 ;
@@ -51,7 +52,7 @@ public function testHasNoBackendCalledTooEarly(): void {
5152 }
5253
5354 public function testHasNoBackend (): void {
54- $ this ->coordinator ->expects (self :: once ())
55+ $ this ->coordinator ->expects ($ this -> once ())
5556 ->method ('getRegistrationContext ' )
5657 ->willReturn ($ this ->createMock (RegistrationContext::class));
5758
@@ -63,16 +64,16 @@ public function testHasNoBackend(): void {
6364 public function testHasFaultyBackend (): void {
6465 $ fakeTalkServiceClass = '\\OCA \\Spreed \\TalkBackend ' ;
6566 $ registrationContext = $ this ->createMock (RegistrationContext::class);
66- $ this ->coordinator ->expects (self :: once ())
67+ $ this ->coordinator ->expects ($ this -> once ())
6768 ->method ('getRegistrationContext ' )
6869 ->willReturn ($ registrationContext );
69- $ registrationContext ->expects (self :: once ())
70+ $ registrationContext ->expects ($ this -> once ())
7071 ->method ('getTalkBackendRegistration ' )
7172 ->willReturn (new ServiceRegistration ('spreed ' , $ fakeTalkServiceClass ));
72- $ this ->container ->expects (self :: once ())
73+ $ this ->container ->expects ($ this -> once ())
7374 ->method ('get ' )
7475 ->willThrowException (new QueryException ());
75- $ this ->logger ->expects (self :: once ())
76+ $ this ->logger ->expects ($ this -> once ())
7677 ->method ('error ' );
7778
7879 self ::assertFalse (
@@ -83,14 +84,14 @@ public function testHasFaultyBackend(): void {
8384 public function testHasBackend (): void {
8485 $ fakeTalkServiceClass = '\\OCA \\Spreed \\TalkBackend ' ;
8586 $ registrationContext = $ this ->createMock (RegistrationContext::class);
86- $ this ->coordinator ->expects (self :: once ())
87+ $ this ->coordinator ->expects ($ this -> once ())
8788 ->method ('getRegistrationContext ' )
8889 ->willReturn ($ registrationContext );
89- $ registrationContext ->expects (self :: once ())
90+ $ registrationContext ->expects ($ this -> once ())
9091 ->method ('getTalkBackendRegistration ' )
9192 ->willReturn (new ServiceRegistration ('spreed ' , $ fakeTalkServiceClass ));
9293 $ talkService = $ this ->createMock (ITalkBackend::class);
93- $ this ->container ->expects (self :: once ())
94+ $ this ->container ->expects ($ this -> once ())
9495 ->method ('get ' )
9596 ->with ($ fakeTalkServiceClass )
9697 ->willReturn ($ talkService );
@@ -110,19 +111,19 @@ public function testNewConversationOptions(): void {
110111 public function testCreateConversation (): void {
111112 $ fakeTalkServiceClass = '\\OCA \\Spreed \\TalkBackend ' ;
112113 $ registrationContext = $ this ->createMock (RegistrationContext::class);
113- $ this ->coordinator ->expects (self :: once ())
114+ $ this ->coordinator ->expects ($ this -> once ())
114115 ->method ('getRegistrationContext ' )
115116 ->willReturn ($ registrationContext );
116- $ registrationContext ->expects (self :: once ())
117+ $ registrationContext ->expects ($ this -> once ())
117118 ->method ('getTalkBackendRegistration ' )
118119 ->willReturn (new ServiceRegistration ('spreed ' , $ fakeTalkServiceClass ));
119120 $ talkService = $ this ->createMock (ITalkBackend::class);
120- $ this ->container ->expects (self :: once ())
121+ $ this ->container ->expects ($ this -> once ())
121122 ->method ('get ' )
122123 ->with ($ fakeTalkServiceClass )
123124 ->willReturn ($ talkService );
124125 $ options = $ this ->createMock (IConversationOptions::class);
125- $ talkService ->expects (self :: once ())
126+ $ talkService ->expects ($ this -> once ())
126127 ->method ('createConversation ' )
127128 ->with ('Watercooler ' , [], $ options );
128129
@@ -133,91 +134,115 @@ public function testCreateConversation(): void {
133134 );
134135 }
135136
136- public function testIsDisabledForUserNoBackend (): void {
137- $ this ->coordinator ->expects (self :: once ())
137+ public function testIsEnabledForUserNoBackend (): void {
138+ $ this ->coordinator ->expects ($ this -> once ())
138139 ->method ('getRegistrationContext ' )
139140 ->willReturn ($ this ->createMock (RegistrationContext::class));
140141
141- self ::assertTrue (
142- $ this ->broker ->isDisabledForUser ()
142+ self ::assertFalse (
143+ $ this ->broker ->isEnabledForUser ()
143144 );
144145 }
145146
146- public static function dataIsDisabledForUser (): array {
147+ public static function dataIsEnabledForUser (): array {
147148 return [
148149 [true ],
149150 [false ],
150151 ];
151152 }
152153
153- /**
154- * @dataProvider dataIsDisabledForUser
155- */
156- public function testIsDisabledForUser (bool $ disabled ): void {
154+ #[DataProvider('dataIsEnabledForUser ' )]
155+ public function testIsEnabledForUser (bool $ enabled ): void {
157156 $ fakeTalkServiceClass = '\\OCA \\Spreed \\TalkBackend ' ;
158157 $ registrationContext = $ this ->createMock (RegistrationContext::class);
159- $ this ->coordinator ->expects (self :: once ())
158+ $ this ->coordinator ->expects ($ this -> once ())
160159 ->method ('getRegistrationContext ' )
161160 ->willReturn ($ registrationContext );
162- $ registrationContext ->expects (self :: once ())
161+ $ registrationContext ->expects ($ this -> once ())
163162 ->method ('getTalkBackendRegistration ' )
164163 ->willReturn (new ServiceRegistration ('spreed ' , $ fakeTalkServiceClass ));
165164 $ talkService = $ this ->createMock (ITalkBackend::class);
166- $ this ->container ->expects (self :: once ())
165+ $ this ->container ->expects ($ this -> once ())
167166 ->method ('get ' )
168167 ->with ($ fakeTalkServiceClass )
169168 ->willReturn ($ talkService );
170- $ talkService ->expects (self :: once ())
171- ->method ('isDisabledForUser ' )
172- ->willReturn ($ disabled );
169+ $ talkService ->expects ($ this -> once ())
170+ ->method ('isEnabledForUser ' )
171+ ->willReturn ($ enabled );
173172
174173 self ::assertSame (
175- $ disabled ,
176- $ this ->broker ->isDisabledForUser ()
174+ $ enabled ,
175+ $ this ->broker ->isEnabledForUser ()
177176 );
178177 }
179178
180- public function testIsNotAllowedToCreateConversationsNoBackend (): void {
181- $ this ->coordinator ->expects (self :: once ())
179+ public function testIsAllowedToCreateConversationsNoBackend (): void {
180+ $ this ->coordinator ->expects ($ this -> once ())
182181 ->method ('getRegistrationContext ' )
183182 ->willReturn ($ this ->createMock (RegistrationContext::class));
184183
185- self ::assertTrue (
186- $ this ->broker ->isNotAllowedToCreateConversations ()
184+ self ::assertFalse (
185+ $ this ->broker ->isAllowedToCreateConversations ()
186+ );
187+ }
188+
189+ public function testIsAllowedToCreateConversationsBackendDisabled (): void {
190+ $ fakeTalkServiceClass = '\\OCA \\Spreed \\TalkBackend ' ;
191+ $ registrationContext = $ this ->createMock (RegistrationContext::class);
192+ $ this ->coordinator ->expects ($ this ->once ())
193+ ->method ('getRegistrationContext ' )
194+ ->willReturn ($ registrationContext );
195+ $ registrationContext ->expects ($ this ->once ())
196+ ->method ('getTalkBackendRegistration ' )
197+ ->willReturn (new ServiceRegistration ('spreed ' , $ fakeTalkServiceClass ));
198+ $ talkService = $ this ->createMock (ITalkBackend::class);
199+ $ this ->container ->expects ($ this ->once ())
200+ ->method ('get ' )
201+ ->with ($ fakeTalkServiceClass )
202+ ->willReturn ($ talkService );
203+ $ talkService ->expects ($ this ->once ())
204+ ->method ('isEnabledForUser ' )
205+ ->willReturn (false );
206+ $ talkService ->expects ($ this ->never ())
207+ ->method ('isAllowedToCreateConversations ' );
208+
209+ self ::assertFalse (
210+ $ this ->broker ->isAllowedToCreateConversations ()
187211 );
188212 }
189213
190- public static function dataIsNotAllowedToCreateConversations (): array {
214+ public static function dataIsAllowedToCreateConversations (): array {
191215 return [
192216 [true ],
193217 [false ],
194218 ];
195219 }
196220
197- /**
198- * @dataProvider dataIsNotAllowedToCreateConversations
199- */
200- public function testIsNotAllowedToCreateConversations (bool $ notAllowed ): void {
221+ #[DataProvider('dataIsAllowedToCreateConversations ' )]
222+ public function testIsAllowedToCreateConversations (bool $ allowed ): void {
201223 $ fakeTalkServiceClass = '\\OCA \\Spreed \\TalkBackend ' ;
202224 $ registrationContext = $ this ->createMock (RegistrationContext::class);
203- $ this ->coordinator ->expects (self :: once ())
225+ $ this ->coordinator ->expects ($ this -> once ())
204226 ->method ('getRegistrationContext ' )
205227 ->willReturn ($ registrationContext );
206- $ registrationContext ->expects (self :: once ())
228+ $ registrationContext ->expects ($ this -> once ())
207229 ->method ('getTalkBackendRegistration ' )
208230 ->willReturn (new ServiceRegistration ('spreed ' , $ fakeTalkServiceClass ));
209231 $ talkService = $ this ->createMock (ITalkBackend::class);
210- $ this ->container ->expects (self :: once ())
232+ $ this ->container ->expects ($ this -> once ())
211233 ->method ('get ' )
212234 ->with ($ fakeTalkServiceClass )
213235 ->willReturn ($ talkService );
214- $ talkService ->expects (self ::once ())
215- ->method ('isNotAllowedToCreateConversations ' )
216- ->willReturn ($ notAllowed );
236+ $ talkService ->expects ($ this ->once ())
237+ ->method ('isEnabledForUser ' )
238+ ->willReturn (true );
239+ $ talkService ->expects ($ this ->once ())
240+ ->method ('isAllowedToCreateConversations ' )
241+ ->willReturn ($ allowed );
217242
218243 self ::assertSame (
219- $ notAllowed ,
220- $ this ->broker ->isNotAllowedToCreateConversations ()
244+ $ allowed ,
245+ $ this ->broker ->isAllowedToCreateConversations ()
221246 );
222247 }
223248}
0 commit comments