fix(talkbackend): Make function names positive and remove talk internals from docs

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2026-04-27 21:19:48 +02:00
parent c55cfc4367
commit 109eb0c8a9
No known key found for this signature in database
GPG key ID: F72FA5B49FFA96B0
4 changed files with 89 additions and 74 deletions

View file

@ -92,19 +92,19 @@ class Broker implements IBroker {
$this->backend->deleteConversation($id); $this->backend->deleteConversation($id);
} }
public function isDisabledForUser(): bool { public function isAllowedToCreateConversations(): bool {
if (!$this->hasBackend()) { if (!$this->isEnabledForUser()) {
return true; return false;
} }
return $this->backend->isDisabledForUser(); return $this->backend->isAllowedToCreateConversations();
} }
public function isNotAllowedToCreateConversations(): bool { public function isEnabledForUser(): bool {
if (!$this->hasBackend()) { if (!$this->hasBackend()) {
return true; return false;
} }
return $this->backend->isNotAllowedToCreateConversations(); return $this->backend->isEnabledForUser();
} }
} }

View file

@ -67,26 +67,22 @@ interface IBroker {
public function deleteConversation(string $id): void; public function deleteConversation(string $id): void;
/** /**
* Check if the logged in user is not allowed to create conversations, * Check if the logged-in user is allowed to create conversations
* respecting the per-group restrictions configured in Talk admin settings
* (allowed_groups).
* *
* Returns false when Talk is not available at all. * Also returns false when no backend is available
* *
* @return bool * @return bool
* @since 34.0.0 * @since 34.0.0
*/ */
public function isNotAllowedToCreateConversations(): bool; public function isAllowedToCreateConversations(): bool;
/** /**
* Check if Talk is disabled for the logged in user, respecting the * Check if the Talk backend is enabled for the logged-in user
* per-group restriction configured in Talk admin settings
* (start_conversations).
* *
* Returns false when Talk is not available at all. * Also returns false when no backend is available
* *
* @return bool * @return bool
* @since 34.0.0 * @since 34.0.0
*/ */
public function isDisabledForUser(): bool; public function isEnabledForUser(): bool;
} }

View file

@ -44,26 +44,20 @@ interface ITalkBackend {
public function deleteConversation(string $id): void; public function deleteConversation(string $id): void;
/** /**
* Check if the logged in user is not allowed to create conversations, * Check if the logged-in user is allowed to create conversations
* respecting the per-group restrictions configured in Talk admin settings
* (allowed_groups).
* *
* Returns false when Talk is not available at all. * Also returns false when no backend is enabled for the user
* *
* @return bool * @return bool
* @since 34.0.0 * @since 34.0.0
*/ */
public function isNotAllowedToCreateConversations(): bool; public function isAllowedToCreateConversations(): bool;
/** /**
* Check if Talk is disabled for the logged in user, respecting the * Check if the Talk backend is enabled for the logged-in user
* per-group restriction configured in Talk admin settings
* (start_conversations).
*
* Returns false when Talk is not available at all.
* *
* @return bool * @return bool
* @since 34.0.0 * @since 34.0.0
*/ */
public function isDisabledForUser(): bool; public function isEnabledForUser(): bool;
} }

View file

@ -17,6 +17,7 @@ use OCP\AppFramework\QueryException;
use OCP\IServerContainer; use OCP\IServerContainer;
use OCP\Talk\IConversationOptions; use OCP\Talk\IConversationOptions;
use OCP\Talk\ITalkBackend; use OCP\Talk\ITalkBackend;
use PHPUnit\Framework\Attributes\DataProvider;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use RuntimeException; use RuntimeException;
use Test\TestCase; use Test\TestCase;
@ -51,7 +52,7 @@ class BrokerTest extends TestCase {
} }
public function testHasNoBackend(): void { public function testHasNoBackend(): void {
$this->coordinator->expects(self::once()) $this->coordinator->expects($this->once())
->method('getRegistrationContext') ->method('getRegistrationContext')
->willReturn($this->createMock(RegistrationContext::class)); ->willReturn($this->createMock(RegistrationContext::class));
@ -63,16 +64,16 @@ class BrokerTest extends TestCase {
public function testHasFaultyBackend(): void { public function testHasFaultyBackend(): void {
$fakeTalkServiceClass = '\\OCA\\Spreed\\TalkBackend'; $fakeTalkServiceClass = '\\OCA\\Spreed\\TalkBackend';
$registrationContext = $this->createMock(RegistrationContext::class); $registrationContext = $this->createMock(RegistrationContext::class);
$this->coordinator->expects(self::once()) $this->coordinator->expects($this->once())
->method('getRegistrationContext') ->method('getRegistrationContext')
->willReturn($registrationContext); ->willReturn($registrationContext);
$registrationContext->expects(self::once()) $registrationContext->expects($this->once())
->method('getTalkBackendRegistration') ->method('getTalkBackendRegistration')
->willReturn(new ServiceRegistration('spreed', $fakeTalkServiceClass)); ->willReturn(new ServiceRegistration('spreed', $fakeTalkServiceClass));
$this->container->expects(self::once()) $this->container->expects($this->once())
->method('get') ->method('get')
->willThrowException(new QueryException()); ->willThrowException(new QueryException());
$this->logger->expects(self::once()) $this->logger->expects($this->once())
->method('error'); ->method('error');
self::assertFalse( self::assertFalse(
@ -83,14 +84,14 @@ class BrokerTest extends TestCase {
public function testHasBackend(): void { public function testHasBackend(): void {
$fakeTalkServiceClass = '\\OCA\\Spreed\\TalkBackend'; $fakeTalkServiceClass = '\\OCA\\Spreed\\TalkBackend';
$registrationContext = $this->createMock(RegistrationContext::class); $registrationContext = $this->createMock(RegistrationContext::class);
$this->coordinator->expects(self::once()) $this->coordinator->expects($this->once())
->method('getRegistrationContext') ->method('getRegistrationContext')
->willReturn($registrationContext); ->willReturn($registrationContext);
$registrationContext->expects(self::once()) $registrationContext->expects($this->once())
->method('getTalkBackendRegistration') ->method('getTalkBackendRegistration')
->willReturn(new ServiceRegistration('spreed', $fakeTalkServiceClass)); ->willReturn(new ServiceRegistration('spreed', $fakeTalkServiceClass));
$talkService = $this->createMock(ITalkBackend::class); $talkService = $this->createMock(ITalkBackend::class);
$this->container->expects(self::once()) $this->container->expects($this->once())
->method('get') ->method('get')
->with($fakeTalkServiceClass) ->with($fakeTalkServiceClass)
->willReturn($talkService); ->willReturn($talkService);
@ -110,19 +111,19 @@ class BrokerTest extends TestCase {
public function testCreateConversation(): void { public function testCreateConversation(): void {
$fakeTalkServiceClass = '\\OCA\\Spreed\\TalkBackend'; $fakeTalkServiceClass = '\\OCA\\Spreed\\TalkBackend';
$registrationContext = $this->createMock(RegistrationContext::class); $registrationContext = $this->createMock(RegistrationContext::class);
$this->coordinator->expects(self::once()) $this->coordinator->expects($this->once())
->method('getRegistrationContext') ->method('getRegistrationContext')
->willReturn($registrationContext); ->willReturn($registrationContext);
$registrationContext->expects(self::once()) $registrationContext->expects($this->once())
->method('getTalkBackendRegistration') ->method('getTalkBackendRegistration')
->willReturn(new ServiceRegistration('spreed', $fakeTalkServiceClass)); ->willReturn(new ServiceRegistration('spreed', $fakeTalkServiceClass));
$talkService = $this->createMock(ITalkBackend::class); $talkService = $this->createMock(ITalkBackend::class);
$this->container->expects(self::once()) $this->container->expects($this->once())
->method('get') ->method('get')
->with($fakeTalkServiceClass) ->with($fakeTalkServiceClass)
->willReturn($talkService); ->willReturn($talkService);
$options = $this->createMock(IConversationOptions::class); $options = $this->createMock(IConversationOptions::class);
$talkService->expects(self::once()) $talkService->expects($this->once())
->method('createConversation') ->method('createConversation')
->with('Watercooler', [], $options); ->with('Watercooler', [], $options);
@ -133,91 +134,115 @@ class BrokerTest extends TestCase {
); );
} }
public function testIsDisabledForUserNoBackend(): void { public function testIsEnabledForUserNoBackend(): void {
$this->coordinator->expects(self::once()) $this->coordinator->expects($this->once())
->method('getRegistrationContext') ->method('getRegistrationContext')
->willReturn($this->createMock(RegistrationContext::class)); ->willReturn($this->createMock(RegistrationContext::class));
self::assertTrue( self::assertFalse(
$this->broker->isDisabledForUser() $this->broker->isEnabledForUser()
); );
} }
public static function dataIsDisabledForUser(): array { public static function dataIsEnabledForUser(): array {
return [ return [
[true], [true],
[false], [false],
]; ];
} }
/** #[DataProvider('dataIsEnabledForUser')]
* @dataProvider dataIsDisabledForUser public function testIsEnabledForUser(bool $enabled): void {
*/
public function testIsDisabledForUser(bool $disabled): void {
$fakeTalkServiceClass = '\\OCA\\Spreed\\TalkBackend'; $fakeTalkServiceClass = '\\OCA\\Spreed\\TalkBackend';
$registrationContext = $this->createMock(RegistrationContext::class); $registrationContext = $this->createMock(RegistrationContext::class);
$this->coordinator->expects(self::once()) $this->coordinator->expects($this->once())
->method('getRegistrationContext') ->method('getRegistrationContext')
->willReturn($registrationContext); ->willReturn($registrationContext);
$registrationContext->expects(self::once()) $registrationContext->expects($this->once())
->method('getTalkBackendRegistration') ->method('getTalkBackendRegistration')
->willReturn(new ServiceRegistration('spreed', $fakeTalkServiceClass)); ->willReturn(new ServiceRegistration('spreed', $fakeTalkServiceClass));
$talkService = $this->createMock(ITalkBackend::class); $talkService = $this->createMock(ITalkBackend::class);
$this->container->expects(self::once()) $this->container->expects($this->once())
->method('get') ->method('get')
->with($fakeTalkServiceClass) ->with($fakeTalkServiceClass)
->willReturn($talkService); ->willReturn($talkService);
$talkService->expects(self::once()) $talkService->expects($this->once())
->method('isDisabledForUser') ->method('isEnabledForUser')
->willReturn($disabled); ->willReturn($enabled);
self::assertSame( self::assertSame(
$disabled, $enabled,
$this->broker->isDisabledForUser() $this->broker->isEnabledForUser()
); );
} }
public function testIsNotAllowedToCreateConversationsNoBackend(): void { public function testIsAllowedToCreateConversationsNoBackend(): void {
$this->coordinator->expects(self::once()) $this->coordinator->expects($this->once())
->method('getRegistrationContext') ->method('getRegistrationContext')
->willReturn($this->createMock(RegistrationContext::class)); ->willReturn($this->createMock(RegistrationContext::class));
self::assertTrue( self::assertFalse(
$this->broker->isNotAllowedToCreateConversations() $this->broker->isAllowedToCreateConversations()
); );
} }
public static function dataIsNotAllowedToCreateConversations(): array { public function testIsAllowedToCreateConversationsBackendDisabled(): void {
$fakeTalkServiceClass = '\\OCA\\Spreed\\TalkBackend';
$registrationContext = $this->createMock(RegistrationContext::class);
$this->coordinator->expects($this->once())
->method('getRegistrationContext')
->willReturn($registrationContext);
$registrationContext->expects($this->once())
->method('getTalkBackendRegistration')
->willReturn(new ServiceRegistration('spreed', $fakeTalkServiceClass));
$talkService = $this->createMock(ITalkBackend::class);
$this->container->expects($this->once())
->method('get')
->with($fakeTalkServiceClass)
->willReturn($talkService);
$talkService->expects($this->once())
->method('isEnabledForUser')
->willReturn(false);
$talkService->expects($this->never())
->method('isAllowedToCreateConversations');
self::assertFalse(
$this->broker->isAllowedToCreateConversations()
);
}
public static function dataIsAllowedToCreateConversations(): array {
return [ return [
[true], [true],
[false], [false],
]; ];
} }
/** #[DataProvider('dataIsAllowedToCreateConversations')]
* @dataProvider dataIsNotAllowedToCreateConversations public function testIsAllowedToCreateConversations(bool $allowed): void {
*/
public function testIsNotAllowedToCreateConversations(bool $notAllowed): void {
$fakeTalkServiceClass = '\\OCA\\Spreed\\TalkBackend'; $fakeTalkServiceClass = '\\OCA\\Spreed\\TalkBackend';
$registrationContext = $this->createMock(RegistrationContext::class); $registrationContext = $this->createMock(RegistrationContext::class);
$this->coordinator->expects(self::once()) $this->coordinator->expects($this->once())
->method('getRegistrationContext') ->method('getRegistrationContext')
->willReturn($registrationContext); ->willReturn($registrationContext);
$registrationContext->expects(self::once()) $registrationContext->expects($this->once())
->method('getTalkBackendRegistration') ->method('getTalkBackendRegistration')
->willReturn(new ServiceRegistration('spreed', $fakeTalkServiceClass)); ->willReturn(new ServiceRegistration('spreed', $fakeTalkServiceClass));
$talkService = $this->createMock(ITalkBackend::class); $talkService = $this->createMock(ITalkBackend::class);
$this->container->expects(self::once()) $this->container->expects($this->once())
->method('get') ->method('get')
->with($fakeTalkServiceClass) ->with($fakeTalkServiceClass)
->willReturn($talkService); ->willReturn($talkService);
$talkService->expects(self::once()) $talkService->expects($this->once())
->method('isNotAllowedToCreateConversations') ->method('isEnabledForUser')
->willReturn($notAllowed); ->willReturn(true);
$talkService->expects($this->once())
->method('isAllowedToCreateConversations')
->willReturn($allowed);
self::assertSame( self::assertSame(
$notAllowed, $allowed,
$this->broker->isNotAllowedToCreateConversations() $this->broker->isAllowedToCreateConversations()
); );
} }
} }