3 * @copyright Copyright (C) 2010-2023, the Friendica project
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Test\src\Core\Session;
24 use Friendica\Core\Session\Model\UserSession;
25 use Friendica\Core\Session\Type\ArraySession;
26 use Friendica\Test\MockedTest;
28 class UserSessionTest extends MockedTest
30 public function dataLocalUserId()
35 'authenticated' => true,
42 'authenticated' => false,
49 'authenticated' => true,
61 'authenticated' => false,
70 * @dataProvider dataLocalUserId
72 public function testGetLocalUserId(array $data, $expected)
74 $userSession = new UserSession(new ArraySession($data));
75 $this->assertEquals($expected, $userSession->getLocalUserId());
78 public function testPublicContactId()
80 $this->markTestSkipped('Needs Contact::getIdForURL testable first');
83 public function dataGetRemoteUserId()
88 'authenticated' => true,
95 'authenticated' => false,
102 'authenticated' => true,
114 'authenticated' => false,
115 'visitor_id' => 'test',
123 * @dataProvider dataGetRemoteUserId
125 public function testGetRemoteUserId(array $data, $expected)
127 $userSession = new UserSession(new ArraySession($data));
128 $this->assertEquals($expected, $userSession->getRemoteUserId());
131 /// @fixme Add more data when Contact::getIdForUrl is a dynamic class
132 public function dataGetRemoteContactId()
138 'remote' => ['1' => '21'],
146 * @dataProvider dataGetRemoteContactId
148 public function testGetRemoteContactId(int $uid, array $data, $expected)
150 $userSession = new UserSession(new ArraySession($data));
151 $this->assertEquals($expected, $userSession->getRemoteContactID($uid));
154 public function dataGetUserIdForVisitorContactID()
160 'remote' => ['3' => '21'],
167 'remote' => ['3' => '21'],
180 /** @dataProvider dataGetUserIdForVisitorContactID */
181 public function testGetUserIdForVisitorContactID(int $cid, array $data, $expected)
183 $userSession = new UserSession(new ArraySession($data));
184 $this->assertEquals($expected, $userSession->getUserIDForVisitorContactID($cid));
187 public function dataAuthenticated()
192 'authenticated' => true,
196 'not_authenticated' => [
198 'authenticated' => false,
211 * @dataProvider dataAuthenticated
213 public function testIsAuthenticated(array $data, $expected)
215 $userSession = new UserSession(new ArraySession($data));
216 $this->assertEquals($expected, $userSession->isAuthenticated());