UserStatusProviderTest.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\UserStatus\Tests\Connector;
  8. use OCA\UserStatus\Connector\UserStatusProvider;
  9. use OCA\UserStatus\Db\UserStatus;
  10. use OCA\UserStatus\Service\StatusService;
  11. use Test\TestCase;
  12. class UserStatusProviderTest extends TestCase {
  13. /** @var \PHPUnit\Framework\MockObject\MockObject */
  14. private $service;
  15. /** @var UserStatusProvider */
  16. private $provider;
  17. protected function setUp(): void {
  18. parent::setUp();
  19. $this->service = $this->createMock(StatusService::class);
  20. $this->provider = new UserStatusProvider($this->service);
  21. }
  22. public function testGetUserStatuses(): void {
  23. $userStatus2 = new UserStatus();
  24. $userStatus2->setUserId('userId2');
  25. $userStatus2->setStatus('dnd');
  26. $userStatus2->setStatusTimestamp(5000);
  27. $userStatus2->setIsUserDefined(true);
  28. $userStatus2->setCustomIcon('💩');
  29. $userStatus2->setCustomMessage('Do not disturb');
  30. $userStatus2->setClearAt(50000);
  31. $userStatus3 = new UserStatus();
  32. $userStatus3->setUserId('userId3');
  33. $userStatus3->setStatus('away');
  34. $userStatus3->setStatusTimestamp(5000);
  35. $userStatus3->setIsUserDefined(false);
  36. $userStatus3->setCustomIcon('🏝');
  37. $userStatus3->setCustomMessage('On vacation');
  38. $userStatus3->setClearAt(60000);
  39. $this->service->expects($this->once())
  40. ->method('findByUserIds')
  41. ->with(['userId1', 'userId2', 'userId3'])
  42. ->willReturn([$userStatus2, $userStatus3]);
  43. $actual = $this->provider->getUserStatuses(['userId1', 'userId2', 'userId3']);
  44. $this->assertCount(2, $actual);
  45. $status2 = $actual['userId2'];
  46. $this->assertEquals('userId2', $status2->getUserId());
  47. $this->assertEquals('dnd', $status2->getStatus());
  48. $this->assertEquals('Do not disturb', $status2->getMessage());
  49. $this->assertEquals('💩', $status2->getIcon());
  50. $dateTime2 = $status2->getClearAt();
  51. $this->assertInstanceOf(\DateTimeImmutable::class, $dateTime2);
  52. $this->assertEquals('50000', $dateTime2->format('U'));
  53. $status3 = $actual['userId3'];
  54. $this->assertEquals('userId3', $status3->getUserId());
  55. $this->assertEquals('away', $status3->getStatus());
  56. $this->assertEquals('On vacation', $status3->getMessage());
  57. $this->assertEquals('🏝', $status3->getIcon());
  58. $dateTime3 = $status3->getClearAt();
  59. $this->assertInstanceOf(\DateTimeImmutable::class, $dateTime3);
  60. $this->assertEquals('60000', $dateTime3->format('U'));
  61. }
  62. }