29 private $groupId = 401;
31 protected function setUp()
34 $this->testDb->createPlainTables( array(
'upload',
'upload_clearing',
'perm_upload') );
35 $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));
36 $this->testDb->getDbManager()->insertTableRow(
'upload', array(
'upload_pk'=>2,
'upload_filename'=>
'for.this',
'user_fk'=>1,
'upload_mode'=>1,
'public_perm'=>
Auth::PERM_NONE));
37 $this->testDb->getDbManager()->insertTableRow(
'perm_upload', array(
'perm_upload_pk'=>1,
'upload_fk'=>2,
'group_fk'=>$this->groupId,
'perm'=>
Auth::PERM_READ));
38 $this->testDb->getDbManager()->insertTableRow(
'upload', array(
'upload_pk'=>3,
'upload_filename'=>
'for.noone',
'user_fk'=>1,
'upload_mode'=>1,
'public_perm'=>
Auth::PERM_NONE));
39 $this->assertCountBefore = \Hamcrest\MatcherAssert::getCount();
42 protected function tearDown()
44 $this->addToAssertionCount(\Hamcrest\MatcherAssert::getCount()-$this->assertCountBefore);
48 public function testConstructAndSanity()
50 $uploadBrowseProxy =
new UploadBrowseProxy($this->groupId, UserDao::USER, $this->testDb->getDbManager(),
true);
51 assertThat($uploadBrowseProxy,is(anInstanceOf(UploadBrowseProxy::class)));
54 public function testUpdateTableStatus()
56 $this->testDb->getDbManager()->insertTableRow(
'upload_clearing', array(
'upload_fk'=>1,
'group_fk'=>$this->groupId,
'status_fk'=> UploadStatus::OPEN));
57 $uploadBrowseProxy =
new UploadBrowseProxy($this->groupId, UserDao::USER, $this->testDb->getDbManager());
58 $uploadBrowseProxy->updateTable(
'status_fk', $uploadId=1, $newStatus=UploadStatus::IN_PROGRESS);
59 $updatedRow = $this->testDb->getDbManager()->getSingleRow(
'SELECT status_fk FROM upload_clearing WHERE upload_fk=$1 AND group_fk=$2',array($uploadId,$this->groupId));
60 assertThat($updatedRow[
'status_fk'],equalTo($newStatus));
63 public function testUpdateTableStatusFromRejectByUser()
65 $this->testDb->getDbManager()->insertTableRow(
'upload_clearing', array(
'upload_fk'=>1,
'group_fk'=>$this->groupId,
'status_fk'=> UploadStatus::REJECTED));
66 $uploadBrowseProxy =
new UploadBrowseProxy($this->groupId, UserDao::USER, $this->testDb->getDbManager());
67 $uploadBrowseProxy->updateTable(
'status_fk', $uploadId=1, $newStatus=UploadStatus::IN_PROGRESS);
68 $updatedRow = $this->testDb->getDbManager()->getSingleRow(
'SELECT status_fk FROM upload_clearing WHERE upload_fk=$1 AND group_fk=$2',array($uploadId,$this->groupId));
69 assertThat($updatedRow[
'status_fk'],equalTo(UploadStatus::REJECTED));
72 public function testUpdateTableStatusByAdvisor()
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::ADVISOR, $this->testDb->getDbManager());
76 $uploadBrowseProxy->updateTable(
'status_fk', $uploadId=1, $newStatus=UploadStatus::IN_PROGRESS);
77 $updatedRow = $this->testDb->getDbManager()->getSingleRow(
'SELECT status_fk FROM upload_clearing WHERE upload_fk=$1 AND group_fk=$2',array($uploadId,$this->groupId));
78 assertThat($updatedRow[
'status_fk'],equalTo($newStatus));
86 $this->testDb->getDbManager()->insertTableRow(
'upload_clearing', array(
'upload_fk'=>1,
'group_fk'=>$this->groupId,
'status_fk'=> UploadStatus::OPEN));
87 $uploadBrowseProxy =
new UploadBrowseProxy($this->groupId, UserDao::USER, $this->testDb->getDbManager());
88 $uploadBrowseProxy->updateTable(
'status_fk', $uploadId=1, $newStatus=UploadStatus::REJECTED);
91 public function testUpdateTableStatusToRejectByAdvisor()
93 $this->testDb->getDbManager()->insertTableRow(
'upload_clearing', array(
'upload_fk'=>1,
'group_fk'=>$this->groupId,
'status_fk'=> UploadStatus::OPEN));
94 $uploadBrowseProxy =
new UploadBrowseProxy($this->groupId, UserDao::ADVISOR, $this->testDb->getDbManager());
95 $uploadBrowseProxy->updateTable(
'status_fk', $uploadId=1, $newStatus=UploadStatus::REJECTED);
96 $updatedRow = $this->testDb->getDbManager()->getSingleRow(
'SELECT status_fk FROM upload_clearing WHERE upload_fk=$1 AND group_fk=$2',array($uploadId,$this->groupId));
97 assertThat($updatedRow[
'status_fk'],equalTo($newStatus));
105 $uploadBrowseProxy =
new UploadBrowseProxy($this->groupId, UserDao::USER, $this->testDb->getDbManager());
106 $uploadBrowseProxy->updateTable(
'nonEditableColumn', 1, 123);
109 public function testUpdateTableAssigneeByAdvisor()
111 $uploadBrowseProxy =
new UploadBrowseProxy($this->groupId, UserDao::ADVISOR, $this->testDb->getDbManager());
112 $uploadBrowseProxy->updateTable(
'assignee', $uploadId=1, $newAssignee=123);
113 $updatedRow = $this->testDb->getDbManager()->getSingleRow(
'SELECT assignee FROM upload_clearing WHERE upload_fk=$1 AND group_fk=$2',array($uploadId,$this->groupId));
114 assertThat($updatedRow[
'assignee'],equalTo($newAssignee));
122 $uploadBrowseProxy =
new UploadBrowseProxy($this->groupId, UserDao::USER, $this->testDb->getDbManager());
123 $uploadBrowseProxy->updateTable(
'assignee', 1, 123);
127 private function wrapperTestMoveUploadToInfinity($uploadId, $order=
'DESC')
129 $this->testDb->getDbManager()->insertTableRow(
'upload_clearing', array(
'upload_fk'=>1,
'group_fk'=>$this->groupId, UploadBrowseProxy::PRIO_COLUMN=>1));
130 $this->testDb->getDbManager()->insertTableRow(
'upload_clearing', array(
'upload_fk'=>2,
'group_fk'=>$this->groupId, UploadBrowseProxy::PRIO_COLUMN=>2));
132 $uploadBrowseProxy =
new UploadBrowseProxy($this->groupId, UserDao::USER, $this->testDb->getDbManager());
133 $uploadBrowseProxy->moveUploadToInfinity($uploadId,
'DESC'==$order);
135 $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));
136 assertThat($updatedRow[
'upload_fk'],equalTo($uploadId));
139 public function testMoveUploadToInfinityTop()
141 $this->wrapperTestMoveUploadToInfinity(1,
'DESC');
144 public function testMoveUploadToInfinityDown()
146 $this->wrapperTestMoveUploadToInfinity(2,
'ASC');
150 private function wrapperTestMoveUploadBeyond($moveUpload=4, $beyondUpload=2, $expectedPrio = 1.5)
152 $this->testDb->getDbManager()->insertTableRow(
'upload', array(
'upload_pk'=>4,
'upload_filename'=>
'for.all4',
'user_fk'=>1,
'upload_mode'=>1,
'public_perm'=>
Auth::PERM_READ));
153 $this->testDb->getDbManager()->insertTableRow(
'upload', array(
'upload_pk'=>5,
'upload_filename'=>
'for.all5',
'user_fk'=>1,
'upload_mode'=>1,
'public_perm'=>
Auth::PERM_READ));
155 $this->testDb->getDbManager()->insertTableRow(
'upload_clearing', array(
'upload_fk'=>1,
'group_fk'=>$this->groupId, UploadBrowseProxy::PRIO_COLUMN=>1));
156 $this->testDb->getDbManager()->insertTableRow(
'upload_clearing', array(
'upload_fk'=>2,
'group_fk'=>$this->groupId, UploadBrowseProxy::PRIO_COLUMN=>2));
157 $this->testDb->getDbManager()->insertTableRow(
'upload_clearing', array(
'upload_fk'=>4,
'group_fk'=>$this->groupId, UploadBrowseProxy::PRIO_COLUMN=>4));
158 $this->testDb->getDbManager()->insertTableRow(
'upload_clearing', array(
'upload_fk'=>5,
'group_fk'=>$this->groupId, UploadBrowseProxy::PRIO_COLUMN=>5));
160 $uploadBrowseProxy =
new UploadBrowseProxy($this->groupId, UserDao::USER, $this->testDb->getDbManager());
161 $uploadBrowseProxy->moveUploadBeyond($moveUpload, $beyondUpload);
162 $updatedRow = $this->testDb->getDbManager()->getSingleRow(
'SELECT '.UploadBrowseProxy::PRIO_COLUMN.
' FROM upload_clearing WHERE upload_fk=$1 AND group_fk=$2',array($moveUpload,$this->groupId));
163 assertThat($updatedRow[UploadBrowseProxy::PRIO_COLUMN],equalTo($expectedPrio));
167 public function testMoveUploadBeyondDown()
169 $this->wrapperTestMoveUploadBeyond(4,2,1.5);
172 public function testMoveUploadBeyondUp()
174 $this->wrapperTestMoveUploadBeyond(2,4,4.5);
177 public function testMoveUploadBeyondFarDown()
179 $this->wrapperTestMoveUploadBeyond(4,1,0.5);
182 public function testMoveUploadBeyondFarUp()
184 $this->wrapperTestMoveUploadBeyond(4,5,5.5);
188 public function testGetFolderPartialQuery()
190 $this->testDb->createPlainTables(array(
'foldercontents',
'uploadtree'));
193 $this->testDb->getDbManager()->insertTableRow(
'upload_clearing', array(
'upload_fk'=>1,
'group_fk'=>$this->groupId, UploadBrowseProxy::PRIO_COLUMN=>1));
194 $this->testDb->getDbManager()->insertTableRow(
'uploadtree',array(
'uploadtree_pk'=>201,
'upload_fk'=>$uploadId,
'lft'=>1,
'ufile_name'=>
'A.zip',
'pfile_fk'=>31415));
195 $this->testDb->getDbManager()->insertTableRow(
'foldercontents',array(
'foldercontents_pk'=>1,
'parent_fk'=>$folderId,
'foldercontents_mode'=>2,
'child_id'=>$uploadId));
196 $params = array($folderId);
197 $uploadBrowseProxy =
new UploadBrowseProxy($this->groupId, UserDao::USER, $this->testDb->getDbManager());
198 $view = $uploadBrowseProxy->getFolderPartialQuery($params);
199 $row = $this->testDb->getDbManager()->getSingleRow(
"SELECT count(*) FROM $view", $params);
200 assertThat($row[
'count'],equalTo(1));
203 public function testGetFolderPartialQueryWithUserInTwoGoodGroups()
205 $this->testDb->createPlainTables(array(
'foldercontents',
'uploadtree'));
208 $otherGroupId = $this->groupId+1;
209 $this->testDb->getDbManager()->insertTableRow(
'upload_clearing', array(
'upload_fk'=>1,
'group_fk'=>$this->groupId, UploadBrowseProxy::PRIO_COLUMN=>1));
210 $this->testDb->getDbManager()->insertTableRow(
'upload_clearing', array(
'upload_fk'=>1,
'group_fk'=>$otherGroupId, UploadBrowseProxy::PRIO_COLUMN=>1));
211 $this->testDb->getDbManager()->insertTableRow(
'uploadtree',array(
'uploadtree_pk'=>201,
'upload_fk'=>$uploadId,
'lft'=>1,
'ufile_name'=>
'A.zip',
'pfile_fk'=>31415));
212 $this->testDb->getDbManager()->insertTableRow(
'foldercontents',array(
'foldercontents_pk'=>1,
'parent_fk'=>$folderId,
'foldercontents_mode'=>2,
'child_id'=>$uploadId));
213 $params = array($folderId);
214 $uploadBrowseProxy =
new UploadBrowseProxy($this->groupId, UserDao::USER, $this->testDb->getDbManager());
215 $view = $uploadBrowseProxy->getFolderPartialQuery($params);
216 $row = $this->testDb->getDbManager()->getSingleRow(
"SELECT count(*) FROM $view", $params);
217 assertThat($row[
'count'],equalTo(1));
226 $uploadBrowseProxy =
new UploadBrowseProxy($this->groupId, UserDao::USER, $this->testDb->getDbManager());
228 $uploadBrowseProxy->getFolderPartialQuery($params);
231 public function testGetStatus()
233 $uploadBrowseProxy =
new UploadBrowseProxy($this->groupId, UserDao::USER, $this->testDb->getDbManager());
235 assertThat($uploadBrowseProxy->getStatus($uploadId), equalTo(UploadStatus::OPEN));
236 $uploadBrowseProxy->updateTable(
'status_fk', $uploadId, $newStatus=UploadStatus::IN_PROGRESS);
237 assertThat($uploadBrowseProxy->getStatus($uploadId), equalTo($newStatus));
246 $uploadBrowseProxy =
new UploadBrowseProxy($this->groupId, UserDao::USER, $this->testDb->getDbManager(),
false);
247 $uploadBrowseProxy->getStatus(-1);
testUpdateTableStatusToRejectByUser()
testGetFolderPartialQueryWithInvalidParamCount()
testUpdateTableAssigneeForbidden()
testUpdateTableNonEditableColum()