UserStatusTest.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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\UserStatus;
  9. use OCA\UserStatus\Db;
  10. use Test\TestCase;
  11. class UserStatusTest extends TestCase {
  12. public function testUserStatus() {
  13. $status = new Db\UserStatus();
  14. $status->setUserId('user2');
  15. $status->setStatus('away');
  16. $status->setStatusTimestamp(5000);
  17. $status->setIsUserDefined(false);
  18. $status->setCustomIcon('🏝');
  19. $status->setCustomMessage('On vacation');
  20. $status->setClearAt(60000);
  21. $userStatus = new UserStatus($status);
  22. $this->assertEquals('user2', $userStatus->getUserId());
  23. $this->assertEquals('away', $userStatus->getStatus());
  24. $this->assertEquals('On vacation', $userStatus->getMessage());
  25. $this->assertEquals('🏝', $userStatus->getIcon());
  26. $dateTime = $userStatus->getClearAt();
  27. $this->assertInstanceOf(\DateTimeImmutable::class, $dateTime);
  28. $this->assertEquals('60000', $dateTime->format('U'));
  29. }
  30. public function testUserStatusInvisible() {
  31. $status = new Db\UserStatus();
  32. $status->setUserId('user2');
  33. $status->setStatus('invisible');
  34. $status->setStatusTimestamp(5000);
  35. $status->setIsUserDefined(false);
  36. $status->setCustomIcon('🏝');
  37. $status->setCustomMessage('On vacation');
  38. $status->setClearAt(60000);
  39. $userStatus = new UserStatus($status);
  40. $this->assertEquals('user2', $userStatus->getUserId());
  41. $this->assertEquals('offline', $userStatus->getStatus());
  42. $this->assertEquals('On vacation', $userStatus->getMessage());
  43. $this->assertEquals('🏝', $userStatus->getIcon());
  44. }
  45. }