15 if (session_status() == PHP_SESSION_NONE) {
19 require_once dirname(dirname(dirname(dirname(__DIR__)))) .
20 '/lib/php/Plugin/FO_Plugin.php';
71 protected function setUp() : void
74 $restHelper = M::mock(RestHelper::class);
75 $container = M::mock(
'ContainerBuilder');
76 $this->
dbManager = M::mock(ModernDbManager::class);
77 $this->folderDao = M::mock(FolderDao::class);
78 $this->uploadDao = M::mock(UploadDao::class);
82 $this->assertCountBefore = \Hamcrest\MatcherAssert::getCount();
83 $container->shouldReceive(
'get')->withArgs(array(
84 'helper.restHelper'))->andReturn($restHelper);
95 $this->addToAssertionCount(
96 \Hamcrest\MatcherAssert::getCount() - $this->assertCountBefore);
107 $agent_list[2] =
'nomos,monk';
108 $agent_list[3] =
'nomos,ojo';
109 $agent_list[4] =
'copyright,ecc';
117 for ($i = 2; $i <= 4; $i++) {
119 'user_pk' => $i,
'user_name' =>
"user$i",
'user_desc' =>
"user $i",
120 'user_email' =>
"user$i@local",
'email_notify' =>
'y',
121 'root_folder_fk' => 2,
'group_fk' => 2,
'user_perm' => $perm_list[$i],
122 'user_agent_list' => $agent_list[$i],
'default_bucketpool_fk' => 2
124 $userRows[$i] = $row;
139 foreach ($rows as $row) {
140 if ($currentUser ===
null || $row[
'user_pk'] == $currentUser) {
141 $user =
new User($row[
"user_pk"], $row[
"user_name"], $row[
"user_desc"],
142 $row[
"user_email"], $row[
"user_perm"], $row[
"root_folder_fk"],
143 $row[
"email_notify"], $row[
"user_agent_list"], $row[
'group_fk'], $row[
"default_bucketpool_fk"]);
145 $user =
new User($row[
"user_pk"], $row[
"user_name"], $row[
"user_desc"],
146 null,
null,
null,
null,
null,
null);
148 $users[$row[
"user_pk"]] = $user->getArray();
165 $sql =
'SELECT user_pk, user_name, user_desc, user_email,
166 email_notify, root_folder_fk, group_fk, user_perm, user_agent_list, ' .
167 'default_bucketpool_fk FROM users;';
168 $statement = DbHelper::class .
"::getUsers.getAllUsers";
171 $this->
dbManager->shouldReceive(
'getRows')
172 ->withArgs([$sql, [], $statement])
174 ->andReturn($userRows);
177 $actualUsers = $this->dbHelper->getUsers();
180 foreach ($actualUsers as $user) {
181 $allUsers[] = $user->getArray();
184 $this->assertEquals($expectedUsers, $allUsers);
199 $sql =
'SELECT user_pk, user_name, user_desc, user_email,
200 email_notify, root_folder_fk, group_fk, user_perm, user_agent_list, ' .
201 'default_bucketpool_fk FROM users;';
202 $statement = DbHelper::class .
"::getUsers.getAllUsers";
205 $this->
dbManager->shouldReceive(
'getRows')
206 ->withArgs([$sql, [], $statement])
208 ->andReturn($userRows);
212 $actualUsers = $this->dbHelper->getUsers();
214 foreach ($actualUsers as $user) {
215 $allUsers[] = $user->getArray();
217 $this->assertEquals($expectedUsers, $allUsers);
232 $sql =
"SELECT user_pk, user_name, user_desc, user_email,
233 email_notify, root_folder_fk, group_fk, user_perm, user_agent_list, default_bucketpool_fk FROM users
234 WHERE user_pk = $1;";
235 $statement = DbHelper::class .
"::getUsers.getSpecificUser";
238 $this->
dbManager->shouldReceive(
'getRows')
239 ->withArgs([$sql, [$userId], $statement])
241 ->andReturn([$userRows[$userId]]);
244 $actualUsers = $this->dbHelper->getUsers($userId);
247 foreach ($actualUsers as $user) {
248 $allUsers[] = $user->getArray();
250 $this->assertEquals([$expectedUsers[$userId]], $allUsers);
266 $sql =
"SELECT user_pk, user_name, user_desc, user_email,
267 email_notify, root_folder_fk, group_fk, user_perm, user_agent_list, default_bucketpool_fk FROM users
268 WHERE user_pk = $1;";
269 $statement = DbHelper::class .
"::getUsers.getSpecificUser";
272 $this->
dbManager->shouldReceive(
'getRows')
273 ->withArgs([$sql, [$fetchId], $statement])
275 ->andReturn([$userRows[$fetchId]]);
278 $actualUsers = $this->dbHelper->getUsers($fetchId);
281 foreach ($actualUsers as $user) {
282 $allUsers[] = $user->getArray();
284 $this->assertEquals([$expectedUsers[$fetchId]], $allUsers);
Contains the constants and helpers for authentication of user.
Provides helper methods to access database for REST api.
Provides various DAO helper functions for REST api.
Model to hold user information.
setUp()
Setup test objects.
testGetUsersAllNonAdmin()
testGetUsersSingleUserAdmin()
generateUserFromRow($rows, $currentUser=null)
tearDown()
Remove test objects.
testGetUsersSingleUserNonAdmin()
#define PLUGIN_DB_WRITE
Plugin requires write permission on DB.
#define PLUGIN_DB_READ
Plugin requires read permission on DB.
#define PLUGIN_DB_ADMIN
Plugin requires admin level permission on DB.
fo_dbManager * dbManager
fo_dbManager object