8 namespace Fossology\Lib\Proxy;
19 private $groupId = 401;
21 protected function setUp() :
void
24 $this->testDb->createPlainTables( array(
'upload',
'upload_clearing',
'perm_upload',
'upload_events') );
25 $this->testDb->getDbManager()->insertTableRow(
'upload', array(
'upload_pk'=>1,
'upload_filename'=>
'for.all',
'user_fk'=>1,
'upload_mode'=>1,
'public_perm'=>
Auth::PERM_READ,
'pfile_fk'=>31415));
26 $this->testDb->getDbManager()->insertTableRow(
'upload', array(
'upload_pk'=>2,
'upload_filename'=>
'for.this',
'user_fk'=>1,
'upload_mode'=>1,
'public_perm'=>
Auth::PERM_NONE));
27 $this->testDb->getDbManager()->insertTableRow(
'perm_upload', array(
'perm_upload_pk'=>1,
'upload_fk'=>2,
'group_fk'=>$this->groupId,
'perm'=>
Auth::PERM_READ));
28 $this->testDb->getDbManager()->insertTableRow(
'upload', array(
'upload_pk'=>3,
'upload_filename'=>
'for.noone',
'user_fk'=>1,
'upload_mode'=>1,
'public_perm'=>
Auth::PERM_NONE));
29 $this->assertCountBefore = \Hamcrest\MatcherAssert::getCount();
32 protected function tearDown() :
void
34 $this->addToAssertionCount(\Hamcrest\MatcherAssert::getCount()-$this->assertCountBefore);
38 public function testConstructAndSanity()
40 $uploadBrowseProxy =
new UploadBrowseProxy($this->groupId, UserDao::USER, $this->testDb->getDbManager(),
true);
41 assertThat($uploadBrowseProxy,is(anInstanceOf(UploadBrowseProxy::class)));
44 public function testUpdateTableStatus()
46 $this->testDb->getDbManager()->insertTableRow(
'upload_clearing', array(
'upload_fk'=>1,
'group_fk'=>$this->groupId,
'status_fk'=> UploadStatus::OPEN));
47 $uploadBrowseProxy =
new UploadBrowseProxy($this->groupId, UserDao::USER, $this->testDb->getDbManager());
48 $uploadBrowseProxy->updateTable(
'status_fk', $uploadId=1, $newStatus=UploadStatus::IN_PROGRESS);
49 $updatedRow = $this->testDb->getDbManager()->getSingleRow(
'SELECT status_fk FROM upload_clearing WHERE upload_fk=$1 AND group_fk=$2',array($uploadId,$this->groupId));
50 assertThat($updatedRow[
'status_fk'],equalTo($newStatus));
53 public function testUpdateTableStatusFromRejectByUser()
55 $this->testDb->getDbManager()->insertTableRow(
'upload_clearing', array(
'upload_fk'=>1,
'group_fk'=>$this->groupId,
'status_fk'=> UploadStatus::REJECTED));
56 $uploadBrowseProxy =
new UploadBrowseProxy($this->groupId, UserDao::USER, $this->testDb->getDbManager());
57 $uploadBrowseProxy->updateTable(
'status_fk', $uploadId=1, $newStatus=UploadStatus::IN_PROGRESS);
58 $updatedRow = $this->testDb->getDbManager()->getSingleRow(
'SELECT status_fk FROM upload_clearing WHERE upload_fk=$1 AND group_fk=$2',array($uploadId,$this->groupId));
59 assertThat($updatedRow[
'status_fk'],equalTo(UploadStatus::REJECTED));
62 public function testUpdateTableStatusByAdvisor()
64 $this->testDb->getDbManager()->insertTableRow(
'upload_clearing', array(
'upload_fk'=>1,
'group_fk'=>$this->groupId,
'status_fk'=> UploadStatus::OPEN));
65 $uploadBrowseProxy =
new UploadBrowseProxy($this->groupId, UserDao::ADVISOR, $this->testDb->getDbManager());
66 $uploadBrowseProxy->updateTable(
'status_fk', $uploadId=1, $newStatus=UploadStatus::IN_PROGRESS);
67 $updatedRow = $this->testDb->getDbManager()->getSingleRow(
'SELECT status_fk FROM upload_clearing WHERE upload_fk=$1 AND group_fk=$2',array($uploadId,$this->groupId));
68 assertThat($updatedRow[
'status_fk'],equalTo($newStatus));
71 public function testUpdateTableStatusToRejectByUser()
73 $this->expectException(Exception::class);
74 $this->testDb->getDbManager()->insertTableRow(
'upload_clearing', array(
'upload_fk'=>1,
'group_fk'=>$this->groupId,
'status_fk'=> UploadStatus::OPEN));
75 $uploadBrowseProxy =
new UploadBrowseProxy($this->groupId, UserDao::USER, $this->testDb->getDbManager());
76 $uploadBrowseProxy->updateTable(
'status_fk', $uploadId=1, $newStatus=UploadStatus::REJECTED);
79 public function testUpdateTableStatusToRejectByAdvisor()
81 $this->testDb->getDbManager()->insertTableRow(
'upload_clearing', array(
'upload_fk'=>1,
'group_fk'=>$this->groupId,
'status_fk'=> UploadStatus::OPEN));
82 $uploadBrowseProxy =
new UploadBrowseProxy($this->groupId, UserDao::ADVISOR, $this->testDb->getDbManager());
83 $uploadBrowseProxy->updateTable(
'status_fk', $uploadId=1, $newStatus=UploadStatus::REJECTED);
84 $updatedRow = $this->testDb->getDbManager()->getSingleRow(
'SELECT status_fk FROM upload_clearing WHERE upload_fk=$1 AND group_fk=$2',array($uploadId,$this->groupId));
85 assertThat($updatedRow[
'status_fk'],equalTo($newStatus));
88 public function testUpdateTableNonEditableColum()
90 $this->expectException(Exception::class);
91 $uploadBrowseProxy =
new UploadBrowseProxy($this->groupId, UserDao::USER, $this->testDb->getDbManager());
92 $uploadBrowseProxy->updateTable(
'nonEditableColumn', 1, 123);
95 public function testUpdateTableAssigneeByAdvisor()
97 $uploadBrowseProxy =
new UploadBrowseProxy($this->groupId, UserDao::ADVISOR, $this->testDb->getDbManager());
98 $uploadBrowseProxy->updateTable(
'assignee', $uploadId=1, $newAssignee=123);
99 $updatedRow = $this->testDb->getDbManager()->getSingleRow(
'SELECT assignee FROM upload_clearing WHERE upload_fk=$1 AND group_fk=$2',array($uploadId,$this->groupId));
100 assertThat($updatedRow[
'assignee'],equalTo($newAssignee));
103 public function testUpdateTableAssigneeForbidden()
105 $this->expectException(Exception::class);
106 $uploadBrowseProxy =
new UploadBrowseProxy($this->groupId, UserDao::USER, $this->testDb->getDbManager());
107 $uploadBrowseProxy->updateTable(
'assignee', 1, 123);
111 private function wrapperTestMoveUploadToInfinity($uploadId, $order=
'DESC')
113 $this->testDb->getDbManager()->insertTableRow(
'upload_clearing', array(
'upload_fk'=>1,
'group_fk'=>$this->groupId, UploadBrowseProxy::PRIO_COLUMN=>1));
114 $this->testDb->getDbManager()->insertTableRow(
'upload_clearing', array(
'upload_fk'=>2,
'group_fk'=>$this->groupId, UploadBrowseProxy::PRIO_COLUMN=>2));
116 $uploadBrowseProxy =
new UploadBrowseProxy($this->groupId, UserDao::USER, $this->testDb->getDbManager());
117 $uploadBrowseProxy->moveUploadToInfinity($uploadId,
'DESC'==$order);
119 $updatedRow = $this->testDb->getDbManager()->getSingleRow(
'SELECT upload_fk FROM upload_clearing WHERE group_fk=$1 ORDER BY '.UploadBrowseProxy::PRIO_COLUMN.
" $order LIMIT 1",array($this->groupId));
120 assertThat($updatedRow[
'upload_fk'],equalTo($uploadId));
123 public function testMoveUploadToInfinityTop()
125 $this->wrapperTestMoveUploadToInfinity(1,
'DESC');
128 public function testMoveUploadToInfinityDown()
130 $this->wrapperTestMoveUploadToInfinity(2,
'ASC');
134 private function wrapperTestMoveUploadBeyond($moveUpload=4, $beyondUpload=2, $expectedPrio = 1.5)
136 $this->testDb->getDbManager()->insertTableRow(
'upload', array(
'upload_pk'=>4,
'upload_filename'=>
'for.all4',
'user_fk'=>1,
'upload_mode'=>1,
'public_perm'=>
Auth::PERM_READ));
137 $this->testDb->getDbManager()->insertTableRow(
'upload', array(
'upload_pk'=>5,
'upload_filename'=>
'for.all5',
'user_fk'=>1,
'upload_mode'=>1,
'public_perm'=>
Auth::PERM_READ));
139 $this->testDb->getDbManager()->insertTableRow(
'upload_clearing', array(
'upload_fk'=>1,
'group_fk'=>$this->groupId, UploadBrowseProxy::PRIO_COLUMN=>1));
140 $this->testDb->getDbManager()->insertTableRow(
'upload_clearing', array(
'upload_fk'=>2,
'group_fk'=>$this->groupId, UploadBrowseProxy::PRIO_COLUMN=>2));
141 $this->testDb->getDbManager()->insertTableRow(
'upload_clearing', array(
'upload_fk'=>4,
'group_fk'=>$this->groupId, UploadBrowseProxy::PRIO_COLUMN=>4));
142 $this->testDb->getDbManager()->insertTableRow(
'upload_clearing', array(
'upload_fk'=>5,
'group_fk'=>$this->groupId, UploadBrowseProxy::PRIO_COLUMN=>5));
144 $uploadBrowseProxy =
new UploadBrowseProxy($this->groupId, UserDao::USER, $this->testDb->getDbManager());
145 $uploadBrowseProxy->moveUploadBeyond($moveUpload, $beyondUpload);
146 $updatedRow = $this->testDb->getDbManager()->getSingleRow(
'SELECT '.UploadBrowseProxy::PRIO_COLUMN.
' FROM upload_clearing WHERE upload_fk=$1 AND group_fk=$2',array($moveUpload,$this->groupId));
147 assertThat($updatedRow[UploadBrowseProxy::PRIO_COLUMN],equalTo($expectedPrio));
151 public function testMoveUploadBeyondDown()
153 $this->wrapperTestMoveUploadBeyond(4,2,1.5);
156 public function testMoveUploadBeyondUp()
158 $this->wrapperTestMoveUploadBeyond(2,4,4.5);
161 public function testMoveUploadBeyondFarDown()
163 $this->wrapperTestMoveUploadBeyond(4,1,0.5);
166 public function testMoveUploadBeyondFarUp()
168 $this->wrapperTestMoveUploadBeyond(4,5,5.5);
172 public function testGetFolderPartialQuery()
174 $this->testDb->createPlainTables(array(
'foldercontents',
'uploadtree'));
177 $this->testDb->getDbManager()->insertTableRow(
'upload_clearing', array(
'upload_fk'=>1,
'group_fk'=>$this->groupId, UploadBrowseProxy::PRIO_COLUMN=>1));
178 $this->testDb->getDbManager()->insertTableRow(
'uploadtree',array(
'uploadtree_pk'=>201,
'upload_fk'=>$uploadId,
'lft'=>1,
'ufile_name'=>
'A.zip',
'pfile_fk'=>31415));
179 $this->testDb->getDbManager()->insertTableRow(
'foldercontents',array(
'foldercontents_pk'=>1,
'parent_fk'=>$folderId,
'foldercontents_mode'=>2,
'child_id'=>$uploadId));
180 $params = array($folderId);
181 $uploadBrowseProxy =
new UploadBrowseProxy($this->groupId, UserDao::USER, $this->testDb->getDbManager());
182 $view = $uploadBrowseProxy->getFolderPartialQuery($params);
183 $row = $this->testDb->getDbManager()->getSingleRow(
"SELECT count(*) FROM $view", $params);
184 assertThat($row[
'count'],equalTo(1));
187 public function testGetFolderPartialQueryWithUserInTwoGoodGroups()
189 $this->testDb->createPlainTables(array(
'foldercontents',
'uploadtree'));
192 $otherGroupId = $this->groupId+1;
193 $this->testDb->getDbManager()->insertTableRow(
'upload_clearing', array(
'upload_fk'=>1,
'group_fk'=>$this->groupId, UploadBrowseProxy::PRIO_COLUMN=>1));
194 $this->testDb->getDbManager()->insertTableRow(
'upload_clearing', array(
'upload_fk'=>1,
'group_fk'=>$otherGroupId, UploadBrowseProxy::PRIO_COLUMN=>1));
195 $this->testDb->getDbManager()->insertTableRow(
'uploadtree',array(
'uploadtree_pk'=>201,
'upload_fk'=>$uploadId,
'lft'=>1,
'ufile_name'=>
'A.zip',
'pfile_fk'=>31415));
196 $this->testDb->getDbManager()->insertTableRow(
'foldercontents',array(
'foldercontents_pk'=>1,
'parent_fk'=>$folderId,
'foldercontents_mode'=>2,
'child_id'=>$uploadId));
197 $params = array($folderId);
198 $uploadBrowseProxy =
new UploadBrowseProxy($this->groupId, UserDao::USER, $this->testDb->getDbManager());
199 $view = $uploadBrowseProxy->getFolderPartialQuery($params);
200 $row = $this->testDb->getDbManager()->getSingleRow(
"SELECT count(*) FROM $view", $params);
201 assertThat($row[
'count'],equalTo(1));
205 public function testGetFolderPartialQueryWithInvalidParamCount()
207 $this->expectException(Exception::class);
208 $uploadBrowseProxy =
new UploadBrowseProxy($this->groupId, UserDao::USER, $this->testDb->getDbManager());
210 $uploadBrowseProxy->getFolderPartialQuery($params);
213 public function testGetStatus()
215 $uploadBrowseProxy =
new UploadBrowseProxy($this->groupId, UserDao::USER, $this->testDb->getDbManager());
217 assertThat($uploadBrowseProxy->getStatus($uploadId), equalTo(UploadStatus::OPEN));
218 $uploadBrowseProxy->updateTable(
'status_fk', $uploadId, $newStatus=UploadStatus::IN_PROGRESS);
219 assertThat($uploadBrowseProxy->getStatus($uploadId), equalTo($newStatus));
222 public function testGetStatusException()
224 $this->expectException(Exception::class);
225 $uploadBrowseProxy =
new UploadBrowseProxy($this->groupId, UserDao::USER, $this->testDb->getDbManager(),
false);
226 $uploadBrowseProxy->getStatus(-1);
Contains the constants and helpers for authentication of user.