blob: 622e891e083b820231f4904352c592b369bae6fe (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
<?php
declare(strict_types=1);
// Nextcloud - Social Support
// SPDX-FileCopyrightText: 2022 Carl Schwan <carl@carlschwan.eu>
// SPDX-License-Identifier: AGPL-3.0-or-later
namespace OCA\Social\Tests\Service;
use OCA\Social\Entity\Account;
use OCA\Social\Entity\Follow;
use OCA\Social\Service\AccountFinder;
use OCP\DB\ORM\IEntityManager;
use OCP\Server;
use Test\TestCase;
/**
* @group DB
*/
class AccountFinderTest extends TestCase {
private ?Account $account1 = null;
private ?Account $account2 = null;
private ?AccountFinder $accountFinder = null;
public function setUp(): void {
parent::setUp();
$em = Server::get(IEntityManager::class);
$this->account1 = Account::newLocal('user1', 'user1', 'User1');
$this->account2 = Account::newLocal('user2', 'user2', 'User2');
$this->account2->follow($this->account1);
$em->persist($this->account1);
$em->persist($this->account2);
$em->flush();
$this->accountFinder = Server::get(AccountFinder::class);
}
public function tearDown(): void {
$em = Server::get(IEntityManager::class);
$em->remove($this->account1);
$em->remove($this->account2);
$em->flush();
parent::tearDown();
}
public function testGetLocalFollower(): void {
$accounts = $this->accountFinder->getLocalFollowersOf($this->account1);
$this->assertSame(count($accounts), 1);
$this->assertSame($accounts[0]->getAccount()->getId(), $this->account2->getId());
}
public function testGetRepresentive(): void {
$account = $this->accountFinder->getRepresentative();
$account1 = $this->accountFinder->getRepresentative();
// Caching works
$this->assertSame($account, $account1);
}
}
|