|
38 | 38 | use OCA\UserStatus\Service\StatusService; |
39 | 39 | use OCP\AppFramework\Db\DoesNotExistException; |
40 | 40 | use OCP\AppFramework\Utility\ITimeFactory; |
| 41 | +use OCP\UserStatus\IUserStatus; |
41 | 42 | use Test\TestCase; |
42 | 43 |
|
43 | 44 | class StatusServiceTest extends TestCase { |
@@ -624,4 +625,44 @@ public function testRemoveUserStatusDoesNotExist(): void { |
624 | 625 | $actual = $this->service->removeUserStatus('john.doe'); |
625 | 626 | $this->assertFalse($actual); |
626 | 627 | } |
| 628 | + |
| 629 | + public function testCleanStatusAutomaticOnline(): void { |
| 630 | + $status = new UserStatus(); |
| 631 | + $status->setStatus(IUserStatus::ONLINE); |
| 632 | + $status->setStatusTimestamp(1337); |
| 633 | + $status->setIsUserDefined(false); |
| 634 | + |
| 635 | + $this->mapper->expects(self::once()) |
| 636 | + ->method('update') |
| 637 | + ->with($status); |
| 638 | + |
| 639 | + parent::invokePrivate($this->service, 'cleanStatus', [$status]); |
| 640 | + } |
| 641 | + |
| 642 | + public function testCleanStatusCustomOffline(): void { |
| 643 | + $status = new UserStatus(); |
| 644 | + $status->setStatus(IUserStatus::OFFLINE); |
| 645 | + $status->setStatusTimestamp(1337); |
| 646 | + $status->setIsUserDefined(true); |
| 647 | + |
| 648 | + $this->mapper->expects(self::once()) |
| 649 | + ->method('update') |
| 650 | + ->with($status); |
| 651 | + |
| 652 | + parent::invokePrivate($this->service, 'cleanStatus', [$status]); |
| 653 | + } |
| 654 | + |
| 655 | + public function testCleanStatusCleanedAlready(): void { |
| 656 | + $status = new UserStatus(); |
| 657 | + $status->setStatus(IUserStatus::OFFLINE); |
| 658 | + $status->setStatusTimestamp(1337); |
| 659 | + $status->setIsUserDefined(false); |
| 660 | + |
| 661 | + // Don't update the status again and again when no value changed |
| 662 | + $this->mapper->expects(self::never()) |
| 663 | + ->method('update') |
| 664 | + ->with($status); |
| 665 | + |
| 666 | + parent::invokePrivate($this->service, 'cleanStatus', [$status]); |
| 667 | + } |
627 | 668 | } |
0 commit comments