Skip to content

Commit c55cfc4

Browse files
committed
test: Add tests for whether spreed is enabled
Signed-off-by: Hamza <hamzamahjoubi221@gmail.com>
1 parent 950a3f8 commit c55cfc4

1 file changed

Lines changed: 88 additions & 0 deletions

File tree

tests/lib/Talk/BrokerTest.php

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,92 @@ public function testCreateConversation(): void {
132132
$options
133133
);
134134
}
135+
136+
public function testIsDisabledForUserNoBackend(): void {
137+
$this->coordinator->expects(self::once())
138+
->method('getRegistrationContext')
139+
->willReturn($this->createMock(RegistrationContext::class));
140+
141+
self::assertTrue(
142+
$this->broker->isDisabledForUser()
143+
);
144+
}
145+
146+
public static function dataIsDisabledForUser(): array {
147+
return [
148+
[true],
149+
[false],
150+
];
151+
}
152+
153+
/**
154+
* @dataProvider dataIsDisabledForUser
155+
*/
156+
public function testIsDisabledForUser(bool $disabled): void {
157+
$fakeTalkServiceClass = '\\OCA\\Spreed\\TalkBackend';
158+
$registrationContext = $this->createMock(RegistrationContext::class);
159+
$this->coordinator->expects(self::once())
160+
->method('getRegistrationContext')
161+
->willReturn($registrationContext);
162+
$registrationContext->expects(self::once())
163+
->method('getTalkBackendRegistration')
164+
->willReturn(new ServiceRegistration('spreed', $fakeTalkServiceClass));
165+
$talkService = $this->createMock(ITalkBackend::class);
166+
$this->container->expects(self::once())
167+
->method('get')
168+
->with($fakeTalkServiceClass)
169+
->willReturn($talkService);
170+
$talkService->expects(self::once())
171+
->method('isDisabledForUser')
172+
->willReturn($disabled);
173+
174+
self::assertSame(
175+
$disabled,
176+
$this->broker->isDisabledForUser()
177+
);
178+
}
179+
180+
public function testIsNotAllowedToCreateConversationsNoBackend(): void {
181+
$this->coordinator->expects(self::once())
182+
->method('getRegistrationContext')
183+
->willReturn($this->createMock(RegistrationContext::class));
184+
185+
self::assertTrue(
186+
$this->broker->isNotAllowedToCreateConversations()
187+
);
188+
}
189+
190+
public static function dataIsNotAllowedToCreateConversations(): array {
191+
return [
192+
[true],
193+
[false],
194+
];
195+
}
196+
197+
/**
198+
* @dataProvider dataIsNotAllowedToCreateConversations
199+
*/
200+
public function testIsNotAllowedToCreateConversations(bool $notAllowed): void {
201+
$fakeTalkServiceClass = '\\OCA\\Spreed\\TalkBackend';
202+
$registrationContext = $this->createMock(RegistrationContext::class);
203+
$this->coordinator->expects(self::once())
204+
->method('getRegistrationContext')
205+
->willReturn($registrationContext);
206+
$registrationContext->expects(self::once())
207+
->method('getTalkBackendRegistration')
208+
->willReturn(new ServiceRegistration('spreed', $fakeTalkServiceClass));
209+
$talkService = $this->createMock(ITalkBackend::class);
210+
$this->container->expects(self::once())
211+
->method('get')
212+
->with($fakeTalkServiceClass)
213+
->willReturn($talkService);
214+
$talkService->expects(self::once())
215+
->method('isNotAllowedToCreateConversations')
216+
->willReturn($notAllowed);
217+
218+
self::assertSame(
219+
$notAllowed,
220+
$this->broker->isNotAllowedToCreateConversations()
221+
);
222+
}
135223
}

0 commit comments

Comments
 (0)