Skip to content

Commit 8c9d766

Browse files
committed
pretend logged in user
Signed-off-by: dartcafe <github@dartcafe.de>
1 parent 9a12fa3 commit 8c9d766

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

tests/Unit/Service/ShareServiceTest.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use OCA\Polls\Exceptions\InvalidShareTypeException;
1616
use OCA\Polls\Service\ShareService;
1717
use OCA\Polls\Tests\Unit\UnitTestCase;
18+
use OCA\Polls\UserSession;
1819
use OCP\ISession;
1920
use OCP\Server;
2021

@@ -23,15 +24,15 @@ class ShareServiceTest extends UnitTestCase {
2324
private ShareMapper $shareMapper;
2425
private PollMapper $pollMapper;
2526
private ISession $session;
27+
private UserSession $userSession;
2628

2729
private Poll $poll;
2830
private Share $userShare;
2931

3032
protected function setUp(): void {
3133
parent::setUp();
3234
$this->session = Server::get(ISession::class);
33-
$this->session->set('ncPollsUserId', 'admin');
34-
35+
$this->userSession = Server::get(UserSession::class);
3536
$this->shareService = Server::get(ShareService::class);
3637
$this->shareMapper = Server::get(ShareMapper::class);
3738
$this->pollMapper = Server::get(PollMapper::class);
@@ -40,12 +41,16 @@ protected function setUp(): void {
4041
$poll->setOwner('admin');
4142
$this->poll = $this->pollMapper->insert($poll);
4243

43-
// Pre-create a TYPE_USER share for admin (used in setType tests)
44+
// Pre-create a TYPE_USER share for admin.
45+
// Also used to establish a proper logged-in session so that
46+
// UserSession::getIsLoggedIn() returns true (required for PERMISSION_SHARE_ADD).
4447
$share = $this->fm->instance('OCA\Polls\Db\Share');
4548
$share->setPollId($this->poll->getId());
4649
$share->setType(Share::TYPE_USER);
4750
$share->setUserId('admin');
4851
$this->userShare = $this->shareMapper->insert($share);
52+
53+
$this->login();
4954
}
5055

5156
protected function tearDown(): void {
@@ -57,6 +62,12 @@ protected function tearDown(): void {
5762
}
5863
}
5964

65+
private function login(): void {
66+
$this->userSession->cleanSession();
67+
$this->session->set(UserSession::SESSION_KEY_SHARE_TOKEN, $this->userShare->getToken());
68+
$this->session->set(UserSession::SESSION_KEY_USER_ID, 'admin');
69+
}
70+
6071
// --- add ---
6172

6273
public function testAddPublicShareCreatesShare(): void {

0 commit comments

Comments
 (0)