UserStatusProviderTest.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2020, Georg Ehrke
  5. *
  6. * @author Georg Ehrke <oc.list@georgehrke.com>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. namespace OCA\UserStatus\Tests\Connector;
  25. use OCA\UserStatus\Connector\UserStatusProvider;
  26. use OCA\UserStatus\Db\UserStatus;
  27. use OCA\UserStatus\Service\StatusService;
  28. use Test\TestCase;
  29. class UserStatusProviderTest extends TestCase {
  30. /** @var \PHPUnit\Framework\MockObject\MockObject */
  31. private $service;
  32. /** @var UserStatusProvider */
  33. private $provider;
  34. protected function setUp(): void {
  35. parent::setUp();
  36. $this->service = $this->createMock(StatusService::class);
  37. $this->provider = new UserStatusProvider($this->service);
  38. }
  39. public function testGetUserStatuses(): void {
  40. $userStatus2 = new UserStatus();
  41. $userStatus2->setUserId('userId2');
  42. $userStatus2->setStatus('dnd');
  43. $userStatus2->setStatusTimestamp(5000);
  44. $userStatus2->setIsUserDefined(true);
  45. $userStatus2->setCustomIcon('💩');
  46. $userStatus2->setCustomMessage('Do not disturb');
  47. $userStatus2->setClearAt(50000);
  48. $userStatus3 = new UserStatus();
  49. $userStatus3->setUserId('userId3');
  50. $userStatus3->setStatus('away');
  51. $userStatus3->setStatusTimestamp(5000);
  52. $userStatus3->setIsUserDefined(false);
  53. $userStatus3->setCustomIcon('🏝');
  54. $userStatus3->setCustomMessage('On vacation');
  55. $userStatus3->setClearAt(60000);
  56. $this->service->expects($this->once())
  57. ->method('findByUserIds')
  58. ->with(['userId1', 'userId2', 'userId3'])
  59. ->willReturn([$userStatus2, $userStatus3]);
  60. $actual = $this->provider->getUserStatuses(['userId1', 'userId2', 'userId3']);
  61. $this->assertCount(2, $actual);
  62. $status2 = $actual['userId2'];
  63. $this->assertEquals('userId2', $status2->getUserId());
  64. $this->assertEquals('dnd', $status2->getStatus());
  65. $this->assertEquals('Do not disturb', $status2->getMessage());
  66. $this->assertEquals('💩', $status2->getIcon());
  67. $dateTime2 = $status2->getClearAt();
  68. $this->assertInstanceOf(\DateTimeImmutable::class, $dateTime2);
  69. $this->assertEquals('50000', $dateTime2->format('U'));
  70. $status3 = $actual['userId3'];
  71. $this->assertEquals('userId3', $status3->getUserId());
  72. $this->assertEquals('away', $status3->getStatus());
  73. $this->assertEquals('On vacation', $status3->getMessage());
  74. $this->assertEquals('🏝', $status3->getIcon());
  75. $dateTime3 = $status3->getClearAt();
  76. $this->assertInstanceOf(\DateTimeImmutable::class, $dateTime3);
  77. $this->assertEquals('60000', $dateTime3->format('U'));
  78. }
  79. }