FOSSology  4.4.0
Open Source License Compliance by Open Source Software
CopyrightControllerTest.php
Go to the documentation of this file.
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2022 Valens Niyonsenga <valensniyonsenga2003@gmail.com>
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
14 
27 use Mockery as M;
28 use Slim\Psr7\Request;
29 use Slim\Psr7\Uri;
30 use Slim\Psr7\Factory\StreamFactory;
31 use Slim\Psr7\Headers;
32 
33 /*
34  SPDX-FileCopyrightText: © 2022 Valens Niyonsenga <valensniyonsenga2003@gmail.com>
35 
36  SPDX-License-Identifier: GPL-2.0-only
37 */
38 class CopyrightControllerTest extends \PHPUnit\Framework\TestCase
39 {
44  private $dbHelper;
45 
50  private $restHelper;
51 
56  private $copyrightDao;
61  private $uploadDao;
62 
74  private $copyrightHist;
79  private $streamFactory;
80 
85  public function setUp(): void
86  {
87  global $container;
88  $container = M::mock('ContainerBuilder');
89  $this->dbHelper = M::mock(DbHelper::class);
90  $this->restHelper = M::mock(RestHelper::class);
91  $this->userDao = M::mock(UserDao::class);
92  $this->uploadDao = M::mock(UploadDao::class);
93  $this->auth = M::mock(Auth::class);
94  $this->copyrightDao = M::mock(CopyrightDao::class);
95  $this->copyrightHist = M::mock('ajax_copyright_hist');
96 
97  $this->restHelper->shouldReceive('getDbHelper')->andReturn($this->dbHelper);
98  $this->restHelper->shouldReceive('getPlugin')
99  ->withArgs(['ajax_copyright_hist'])->andReturn($this->copyrightHist);
100  $this->restHelper->shouldReceive('getUploadDao')
101  ->andReturn($this->uploadDao);
102  $container->shouldReceive('get')->withArgs(array(
103  'helper.restHelper'))->andReturn($this->restHelper);
104  $container->shouldReceive('get')->withArgs(array(
105  'dao.copyright'
106  ))->andReturn($this->copyrightDao);
107  $this->streamFactory = new StreamFactory();
108  $this->copyrightController = new CopyrightController($container);
109  }
110 
117  private function getResponseJson($response)
118  {
119  $response->getBody()->seek(0);
120  return json_decode($response->getBody()->getContents(), true);
121  }
128  {
129  $args = [
130  "id" => 4,
131  "itemId" => 2,
132  ];
133  $this->dbHelper->shouldReceive("doesIdExist")
134  ->withArgs(['upload','upload_pk', $args['id']])->andReturn(false);
135  $requestHeaders = new Headers();
136  $body = $this->streamFactory->createStream();
137  $request = new Request("GET", new Uri("HTTP", "localhost"),
138  $requestHeaders, [], [], $body);
139  $request = $request->withQueryParams([]);
140  $this->expectException(HttpNotFoundException::class);
141  $this->copyrightController->getTotalFileCopyrights($request, new ResponseHelper(),$args);
142  }
143 
150  {
151  $args = [
152  "id" => 4,
153  "itemId" => 2,
154  ];
155  $this->dbHelper->shouldReceive("doesIdExist")
156  ->withArgs(['upload','upload_pk', $args['id']])->andReturn(true);
157  $this->uploadDao->shouldReceive("getUploadtreeTableName")
158  ->withArgs([$args['id']])->andReturn("uploadtree");
159  $this->restHelper->shouldReceive("getGroupId")
160  ->andReturn(4);
161  $this->uploadDao->shouldReceive("isAccessible")
162  ->withArgs([$args['id'],4])->andReturn(true);
163  $this->dbHelper->shouldReceive("doesIdExist")
164  ->withArgs(['uploadtree','uploadtree_pk', $args['itemId']])->andReturn(false);
165 
166  $requestHeaders = new Headers();
167  $body = $this->streamFactory->createStream();
168  $request = new Request("GET", new Uri("HTTP", "localhost"),
169  $requestHeaders, [], [], $body);
170  $request = $request->withQueryParams([]);
171  $this->expectException(HttpNotFoundException::class);
172  $this->copyrightController->getTotalFileCopyrights($request, new ResponseHelper(),$args);
173  }
174 
175 
182  {
183  $args = [
184  "id" => 4,
185  "itemId" => 2,
186  ];
187  $this->dbHelper->shouldReceive("doesIdExist")
188  ->withArgs(['upload','upload_pk', $args['id']])->andReturn(true);
189  $this->uploadDao->shouldReceive("getUploadtreeTableName")
190  ->withArgs([$args['id']])->andReturn("uploadtree");
191  $this->restHelper->shouldReceive("getGroupId")
192  ->andReturn(4);
193  $this->uploadDao->shouldReceive("isAccessible")
194  ->withArgs([$args['id'],4])->andReturn(true);
195  $this->dbHelper->shouldReceive("doesIdExist")
196  ->withArgs(['uploadtree','uploadtree_pk', $args['itemId']])->andReturn(true);
197 
198  $requestHeaders = new Headers();
199  $body = $this->streamFactory->createStream();
200  $request = new Request("GET", new Uri("HTTP", "localhost"),
201  $requestHeaders, [], [], $body);
202  $request = $request->withQueryParams([]);
203  $this->expectException(HttpBadRequestException::class);
204  $this->copyrightController->getTotalFileCopyrights($request, new ResponseHelper(),$args);
205  }
206 
207 
215  {
216  $args = [
217  "id" => 4,
218  "itemId" => 2,
219  ];
220  $this->dbHelper->shouldReceive("doesIdExist")
221  ->withArgs(['upload','upload_pk', $args['id']])->andReturn(true);
222  $this->uploadDao->shouldReceive("getUploadtreeTableName")
223  ->withArgs([$args['id']])->andReturn("uploadtree");
224  $this->restHelper->shouldReceive("getGroupId")
225  ->andReturn(4);
226  $this->uploadDao->shouldReceive("isAccessible")
227  ->withArgs([$args['id'],4])->andReturn(true);
228  $this->dbHelper->shouldReceive("doesIdExist")
229  ->withArgs(['uploadtree','uploadtree_pk', $args['itemId']])->andReturn(true);
230  $this->copyrightHist->shouldReceive('getAgentId')
231  ->withArgs([$args['id'],'copyright_ars'])->andReturn(1);
232  $this->copyrightDao->shouldReceive('getTotalCopyrights')
233  ->withArgs([$args['id'],4,'uploadtree',3])->andReturn(10);
234 
235  $requestHeaders = new Headers();
236  $body = $this->streamFactory->createStream();
237  $request = new Request("GET", new Uri("HTTP", "localhost"),
238  $requestHeaders, [], [], $body);
239  $request = $request->withQueryParams(["status" => "invalid"]);
240  $this->expectException(HttpBadRequestException::class);
241 
242  $expectedResponse = (new ResponseHelper())->withJson(array('total_copyrights' => 10));
243  $actualResponse = $this->copyrightController->getTotalFileCopyrights($request, new ResponseHelper(),$args);
244  $this->assertEquals($expectedResponse, $actualResponse);
245  $this->assertEquals($this->getResponseJson($expectedResponse), $this->getResponseJson($actualResponse));
246  $this->assertEquals(200,$actualResponse->getStatusCode());
247  }
248 
255  {
256  $args = [
257  "id" => 4,
258  "itemId" => 2,
259  ];
260  $requestHeaders = new Headers();
261  $requestHeaders->setHeader('limit', 0);
262  $body = $this->streamFactory->createStream();
263  $request = new Request("GET", new Uri("HTTP", "localhost"),
264  $requestHeaders, [], [], $body);
265  $request = $request->withQueryParams(["status" => "invalid"]);
266  $this->expectException(HttpBadRequestException::class);
267  $this->copyrightController->getFileCopyrights($request, new ResponseHelper(),$args);
268 
269  }
270 
271 
278  public function testGetFileCopyrights()
279  {
280  $dumRows = $this->getDummyData()['dumRows'];
281  $args = $this->getDummyData()['args'];
282 
283  $this->uploadDao->shouldReceive("getUploadtreeTableName")
284  ->withArgs([$args['id']])->andReturn("uploadtree");
285  $this->dbHelper->shouldReceive("doesIdExist")
286  ->withArgs(['uploadtree','uploadtree_pk', $args['itemId']])->andReturn(true);
287  $this->dbHelper->shouldReceive("doesIdExist")
288  ->withArgs(['upload','upload_pk', $args['id']])->andReturn(true);
289  $this->restHelper->shouldReceive("getGroupId")
290  ->andReturn(4);
291  $this->uploadDao->shouldReceive("isAccessible")
292  ->withArgs([$args['id'],4])->andReturn(true);
293  $this->copyrightHist->shouldReceive('getAgentId')
294  ->withArgs([$args['id'],'copyright_ars'])->andReturn(1);
295 
296  $this->copyrightHist->shouldReceive('getCopyrights')
297  ->withArgs([$args['id'],2,'uploadtree',1,'statement', 'active',true,0,100])->andReturn([$dumRows,10,10]);
298  $requestHeaders = new Headers();
299  $requestHeaders->setHeader('limit', 100);
300  $body = $this->streamFactory->createStream();
301  $request = new Request("GET", new Uri("HTTP", "localhost"),
302  $requestHeaders, [], [], $body);
303  $request = $request->withQueryParams(["status" => "active"]);
304 
305  foreach ($dumRows as $row) {
306  $row['count'] = intval($row['copyright_count']);
307  unset($row['copyright_count']);
308  $finalVal[] = $row;
309  }
310  $totalPages = intval(ceil(10/100));
311  $expectedResponse = (new ResponseHelper())->withHeader('X-Total-Pages',$totalPages)->withJson($finalVal,200);
312  $actualResponse = $this->copyrightController->getFileCopyrights($request, new ResponseHelper(),$args);
313  $this->assertEquals($this->getResponseJson($expectedResponse), $this->getResponseJson($actualResponse));
314  $this->assertEquals(200,$actualResponse->getStatusCode());
315  }
316 
323  {
324  $args = [
325  "id" => 4,
326  "itemId" => 2,
327  ];
328 
329  $this->uploadDao->shouldReceive("getUploadtreeTableName")
330  ->withArgs([$args['id']])->andReturn("uploadtree");
331  $this->dbHelper->shouldReceive("doesIdExist")
332  ->withArgs(['uploadtree','uploadtree_pk', $args['itemId']])->andReturn(true);
333  $this->dbHelper->shouldReceive("doesIdExist")
334  ->withArgs(['upload','upload_pk', $args['id']])->andReturn(true);
335  $this->restHelper->shouldReceive("getGroupId")
336  ->andReturn(4);
337  $this->uploadDao->shouldReceive("isAccessible")
338  ->withArgs([$args['id'],4])->andReturn(true);
339  $this->copyrightHist->shouldReceive('getAgentId')
340  ->withArgs([$args['id'],'copyright_ars'])->andReturn(1);
341 
342  $requestHeaders = new Headers();
343  $requestHeaders->setHeader('limit', 100);
344  $requestHeaders->setHeader("page",-1);
345  $body = $this->streamFactory->createStream();
346  $request = new Request("GET", new Uri("HTTP", "localhost"),
347  $requestHeaders, [], [], $body);
348  $request = $request->withQueryParams(["status" => "active"]);
349 
350  $this->expectException(HttpBadRequestException::class);
351  $this->copyrightController->getFileCopyrights($request, new ResponseHelper(),$args);
352  }
353 
354 
355  public function getDummyData()
356  {
357  $dumRows = array(
358  array(
359  "count" => 10,
360  "copyright_count" => 10,
361  ),
362  array(
363  "count" => 15,
364  "copyright_count" => 12,
365  )
366  );
367  $args = [
368  "id" => 4,
369  "itemId" => 2,
370  ];
371  return [
372  'dumRows' => $dumRows,
373  'args' => $args,
374  ];
375  }
382  public function testGetFileEmail()
383  {
384  $dumRows = $this->getDummyData()['dumRows'];
385  $args = $this->getDummyData()['args'];
386  $this->uploadDao->shouldReceive("getUploadtreeTableName")
387  ->withArgs([$args['id']])->andReturn("uploadtree");
388  $this->dbHelper->shouldReceive("doesIdExist")
389  ->withArgs(['uploadtree','uploadtree_pk', $args['itemId']])->andReturn(true);
390  $this->dbHelper->shouldReceive("doesIdExist")
391  ->withArgs(['upload','upload_pk', $args['id']])->andReturn(true);
392  $this->restHelper->shouldReceive("getGroupId")
393  ->andReturn(4);
394  $this->uploadDao->shouldReceive("isAccessible")
395  ->withArgs([$args['id'],4])->andReturn(true);
396  $this->copyrightHist->shouldReceive('getAgentId')
397  ->withArgs([$args['id'],'copyright_ars'])->andReturn(1);
398 
399  $this->copyrightHist->shouldReceive('getCopyrights')
400  ->withArgs([$args['id'],2,'uploadtree',1,'email', 'active',true,0,100])->andReturn([$dumRows,10,10]);
401  $requestHeaders = new Headers();
402  $requestHeaders->setHeader('limit', 100);
403  $body = $this->streamFactory->createStream();
404  $request = new Request("GET", new Uri("HTTP", "localhost"),
405  $requestHeaders, [], [], $body);
406  $request = $request->withQueryParams(["status" => "active"]);
407 
408  foreach ($dumRows as $row) {
409  $row['count'] = intval($row['copyright_count']);
410  unset($row['copyright_count']);
411  $finalVal[] = $row;
412  }
413  $totalPages = intval(ceil(10/100));
414  $expectedResponse = (new ResponseHelper())->withHeader('X-Total-Pages',$totalPages)->withJson($finalVal,200);
415  $actualResponse = $this->copyrightController->getFileEmail($request, new ResponseHelper(),$args);
416  $this->assertEquals($this->getResponseJson($expectedResponse), $this->getResponseJson($actualResponse));
417  $this->assertEquals(200,$actualResponse->getStatusCode());
418  }
419 
420 
421 
428  public function testGetFileUrl()
429  {
430  $dumRows = $this->getDummyData()['dumRows'];
431  $args = $this->getDummyData()['args'];
432  $this->uploadDao->shouldReceive("getUploadtreeTableName")
433  ->withArgs([$args['id']])->andReturn("uploadtree");
434  $this->dbHelper->shouldReceive("doesIdExist")
435  ->withArgs(['uploadtree','uploadtree_pk', $args['itemId']])->andReturn(true);
436  $this->dbHelper->shouldReceive("doesIdExist")
437  ->withArgs(['upload','upload_pk', $args['id']])->andReturn(true);
438  $this->restHelper->shouldReceive("getGroupId")
439  ->andReturn(4);
440  $this->uploadDao->shouldReceive("isAccessible")
441  ->withArgs([$args['id'],4])->andReturn(true);
442  $this->copyrightHist->shouldReceive('getAgentId')
443  ->withArgs([$args['id'],'copyright_ars'])->andReturn(1);
444 
445  $this->copyrightHist->shouldReceive('getCopyrights')
446  ->withArgs([$args['id'],2,'uploadtree',1,'url', 'active',true,0,100])->andReturn([$dumRows,10,10]);
447  $requestHeaders = new Headers();
448  $requestHeaders->setHeader('limit', 100);
449  $body = $this->streamFactory->createStream();
450  $request = new Request("GET", new Uri("HTTP", "localhost"),
451  $requestHeaders, [], [], $body);
452  $request = $request->withQueryParams(["status" => "active"]);
453 
454  foreach ($dumRows as $row) {
455  $row['count'] = intval($row['copyright_count']);
456  unset($row['copyright_count']);
457  $finalVal[] = $row;
458  }
459  $totalPages = intval(ceil(10/100));
460  $expectedResponse = (new ResponseHelper())->withHeader('X-Total-Pages',$totalPages)->withJson($finalVal,200);
461  $actualResponse = $this->copyrightController->getFileUrl($request, new ResponseHelper(),$args);
462  $this->assertEquals($this->getResponseJson($expectedResponse), $this->getResponseJson($actualResponse));
463  $this->assertEquals(200,$actualResponse->getStatusCode());
464  }
465 
466 
467 
468 
475  public function testGetFileAuthor()
476  {
477  $dumRows = $this->getDummyData()['dumRows'];
478  $args = $this->getDummyData()['args'];
479  $this->uploadDao->shouldReceive("getUploadtreeTableName")
480  ->withArgs([$args['id']])->andReturn("uploadtree");
481  $this->dbHelper->shouldReceive("doesIdExist")
482  ->withArgs(['uploadtree','uploadtree_pk', $args['itemId']])->andReturn(true);
483  $this->dbHelper->shouldReceive("doesIdExist")
484  ->withArgs(['upload','upload_pk', $args['id']])->andReturn(true);
485  $this->restHelper->shouldReceive("getGroupId")
486  ->andReturn(4);
487  $this->uploadDao->shouldReceive("isAccessible")
488  ->withArgs([$args['id'],4])->andReturn(true);
489  $this->copyrightHist->shouldReceive('getAgentId')
490  ->withArgs([$args['id'],'copyright_ars'])->andReturn(1);
491 
492  $this->copyrightHist->shouldReceive('getCopyrights')
493  ->withArgs([$args['id'],2,'uploadtree',1,'author', 'active',true,0,100])->andReturn([$dumRows,10,10]);
494  $requestHeaders = new Headers();
495  $requestHeaders->setHeader('limit', 100);
496  $body = $this->streamFactory->createStream();
497  $request = new Request("GET", new Uri("HTTP", "localhost"),
498  $requestHeaders, [], [], $body);
499  $request = $request->withQueryParams(["status" => "active"]);
500 
501  foreach ($dumRows as $row) {
502  $row['count'] = intval($row['copyright_count']);
503  unset($row['copyright_count']);
504  $finalVal[] = $row;
505  }
506  $totalPages = intval(ceil(10/100));
507  $expectedResponse = (new ResponseHelper())->withHeader('X-Total-Pages',$totalPages)->withJson($finalVal,200);
508  $actualResponse = $this->copyrightController->getFileAuthor($request, new ResponseHelper(),$args);
509  $this->assertEquals($this->getResponseJson($expectedResponse), $this->getResponseJson($actualResponse));
510  $this->assertEquals(200,$actualResponse->getStatusCode());
511  }
512 
513 
520  public function testGetFileEcc()
521  {
522  $dumRows = $this->getDummyData()['dumRows'];
523  $args = $this->getDummyData()['args'];
524  $this->uploadDao->shouldReceive("getUploadtreeTableName")
525  ->withArgs([$args['id']])->andReturn("uploadtree");
526  $this->dbHelper->shouldReceive("doesIdExist")
527  ->withArgs(['uploadtree','uploadtree_pk', $args['itemId']])->andReturn(true);
528  $this->dbHelper->shouldReceive("doesIdExist")
529  ->withArgs(['upload','upload_pk', $args['id']])->andReturn(true);
530  $this->restHelper->shouldReceive("getGroupId")
531  ->andReturn(4);
532  $this->uploadDao->shouldReceive("isAccessible")
533  ->withArgs([$args['id'],4])->andReturn(true);
534  $this->copyrightHist->shouldReceive('getAgentId')
535  ->withArgs([$args['id'],'ecc_ars'])->andReturn(1);
536 
537  $this->copyrightHist->shouldReceive('getCopyrights')
538  ->withArgs([$args['id'],2,'uploadtree',1,'ecc', 'active',true,0,100])->andReturn([$dumRows,10,10]);
539  $requestHeaders = new Headers();
540  $requestHeaders->setHeader('limit', 100);
541  $body = $this->streamFactory->createStream();
542  $request = new Request("GET", new Uri("HTTP", "localhost"),
543  $requestHeaders, [], [], $body);
544  $request = $request->withQueryParams(["status" => "active"]);
545 
546  foreach ($dumRows as $row) {
547  $row['count'] = intval($row['copyright_count']);
548  unset($row['copyright_count']);
549  $finalVal[] = $row;
550  }
551  $totalPages = intval(ceil(10/100));
552  $expectedResponse = (new ResponseHelper())->withHeader('X-Total-Pages',$totalPages)->withJson($finalVal,200);
553  $actualResponse = $this->copyrightController->getFileEcc($request, new ResponseHelper(),$args);
554  $this->assertEquals($this->getResponseJson($expectedResponse), $this->getResponseJson($actualResponse));
555  $this->assertEquals(200,$actualResponse->getStatusCode());
556  }
557 
558 
559 
566  public function testGetFileKeyword()
567  {
568  $dumRows = $this->getDummyData()['dumRows'];
569  $args = $this->getDummyData()['args'];
570  $this->uploadDao->shouldReceive("getUploadtreeTableName")
571  ->withArgs([$args['id']])->andReturn("uploadtree");
572  $this->dbHelper->shouldReceive("doesIdExist")
573  ->withArgs(['uploadtree','uploadtree_pk', $args['itemId']])->andReturn(true);
574  $this->dbHelper->shouldReceive("doesIdExist")
575  ->withArgs(['upload','upload_pk', $args['id']])->andReturn(true);
576  $this->restHelper->shouldReceive("getGroupId")
577  ->andReturn(4);
578  $this->uploadDao->shouldReceive("isAccessible")
579  ->withArgs([$args['id'],4])->andReturn(true);
580  $this->copyrightHist->shouldReceive('getAgentId')
581  ->withArgs([$args['id'],'keyword_ars'])->andReturn(1);
582 
583  $this->copyrightHist->shouldReceive('getCopyrights')
584  ->withArgs([$args['id'],2,'uploadtree',1,'keyword', 'active',true,0,100])->andReturn([$dumRows,10,10]);
585  $requestHeaders = new Headers();
586  $requestHeaders->setHeader('limit', 100);
587  $body = $this->streamFactory->createStream();
588  $request = new Request("GET", new Uri("HTTP", "localhost"),
589  $requestHeaders, [], [], $body);
590  $request = $request->withQueryParams(["status" => "active"]);
591 
592  foreach ($dumRows as $row) {
593  $row['count'] = intval($row['copyright_count']);
594  unset($row['copyright_count']);
595  $finalVal[] = $row;
596  }
597  $totalPages = intval(ceil(10/100));
598  $expectedResponse = (new ResponseHelper())->withHeader('X-Total-Pages',$totalPages)->withJson($finalVal,200);
599  $actualResponse = $this->copyrightController->getFileKeyword($request, new ResponseHelper(),$args);
600  $this->assertEquals($this->getResponseJson($expectedResponse), $this->getResponseJson($actualResponse));
601  $this->assertEquals(200,$actualResponse->getStatusCode());
602  }
603 
604 
611  public function testGetFileIpra()
612  {
613  $dumRows = $this->getDummyData()['dumRows'];
614  $args = $this->getDummyData()['args'];
615  $this->uploadDao->shouldReceive("getUploadtreeTableName")
616  ->withArgs([$args['id']])->andReturn("uploadtree");
617  $this->dbHelper->shouldReceive("doesIdExist")
618  ->withArgs(['uploadtree','uploadtree_pk', $args['itemId']])->andReturn(true);
619  $this->dbHelper->shouldReceive("doesIdExist")
620  ->withArgs(['upload','upload_pk', $args['id']])->andReturn(true);
621  $this->restHelper->shouldReceive("getGroupId")
622  ->andReturn(4);
623  $this->uploadDao->shouldReceive("isAccessible")
624  ->withArgs([$args['id'],4])->andReturn(true);
625  $this->copyrightHist->shouldReceive('getAgentId')
626  ->withArgs([$args['id'],'ipra_ars'])->andReturn(1);
627 
628  $this->copyrightHist->shouldReceive('getCopyrights')
629  ->withArgs([$args['id'],2,'uploadtree',1,'ipra', 'active',true,0,100])->andReturn([$dumRows,10,10]);
630  $requestHeaders = new Headers();
631  $requestHeaders->setHeader('limit', 100);
632  $body = $this->streamFactory->createStream();
633  $request = new Request("GET", new Uri("HTTP", "localhost"),
634  $requestHeaders, [], [], $body);
635  $request = $request->withQueryParams(["status" => "active"]);
636 
637  foreach ($dumRows as $row) {
638  $row['count'] = intval($row['copyright_count']);
639  unset($row['copyright_count']);
640  $finalVal[] = $row;
641  }
642  $totalPages = intval(ceil(10/100));
643  $expectedResponse = (new ResponseHelper())->withHeader('X-Total-Pages',$totalPages)->withJson($finalVal,200);
644  $actualResponse = $this->copyrightController->getFileIpra($request, new ResponseHelper(),$args);
645  $this->assertEquals($this->getResponseJson($expectedResponse), $this->getResponseJson($actualResponse));
646  $this->assertEquals(200,$actualResponse->getStatusCode());
647  }
648 
655  public function testDeleteFileCopyright()
656  {
657  $args = $this->getDummyData()['args'];
658  $args['hash'] = "hash";
659  $userId = 4;
660 
661  $itemTreeBounds = [
662  'itemId' => 2,
663  'uploadId' => 2,
664  'uploadTreeTableName' => "uploadtree",
665  'left' => 1,
666  'right' => 31314
667  ];
668  $this->dbHelper->shouldReceive("doesIdExist")
669  ->withArgs(['uploadtree','uploadtree_pk', $args['itemId']])->andReturn(true);
670  $this->dbHelper->shouldReceive("doesIdExist")
671  ->withArgs(['upload','upload_pk', $args['id']])->andReturn(true);
672  $this->restHelper->shouldReceive("getGroupId")
673  ->andReturn(4);
674  $this->uploadDao->shouldReceive("isAccessible")
675  ->withArgs([$args['id'],4])->andReturn(true);
676 
677  $this->uploadDao->shouldReceive("getUploadTreeTableName")
678  ->withAnyArgs()->andReturn("uploadtree");
679 
680  $this->restHelper->shouldReceive("getUserId")
681  ->andReturn($userId);
682  $this->copyrightHist->shouldReceive('getTableName')
683  ->withArgs(['statement'])->andReturn("statement");
684  $this->uploadDao->shouldReceive("getItemTreeBounds")
685  ->andReturn($itemTreeBounds);
686  $this->copyrightDao->shouldReceive('updateTable');
687 
688  $requestHeaders = new Headers();
689  $body = $this->streamFactory->createStream();
690  $request = new Request("GET", new Uri("HTTP", "localhost"),
691  $requestHeaders, [], [], $body);
692  $request = $request->withQueryParams(["status" => "active"]);
693 
694  $returnVal = new Info(200, "Successfully removed copyright.", InfoType::INFO);
695  $expectedResponse = (new ResponseHelper())->withJson($returnVal->getArray(),$returnVal->getCode());
696  $actualResponse = $this->copyrightController->deleteFileCopyright($request, new ResponseHelper(),$args);
697 
698  $this->assertEquals($this->getResponseJson($expectedResponse), $this->getResponseJson($actualResponse));
699 
700  }
701 
708  public function testDeleteFileEmail()
709  {
710  $args = $this->getDummyData()['args'];
711  $args['hash'] = "hash";
712  $userId = 4;
713 
714  $itemTreeBounds = [
715  'itemId' => 2,
716  'uploadId' => 2,
717  'uploadTreeTableName' => "uploadtree",
718  'left' => 1,
719  'right' => 31314
720  ];
721  $this->dbHelper->shouldReceive("doesIdExist")
722  ->withArgs(['uploadtree','uploadtree_pk', $args['itemId']])->andReturn(true);
723  $this->dbHelper->shouldReceive("doesIdExist")
724  ->withArgs(['upload','upload_pk', $args['id']])->andReturn(true);
725  $this->restHelper->shouldReceive("getGroupId")
726  ->andReturn(4);
727  $this->uploadDao->shouldReceive("isAccessible")
728  ->withArgs([$args['id'],4])->andReturn(true);
729 
730  $this->uploadDao->shouldReceive("getUploadTreeTableName")
731  ->withAnyArgs()->andReturn("uploadtree");
732 
733  $this->restHelper->shouldReceive("getUserId")
734  ->andReturn($userId);
735  $this->copyrightHist->shouldReceive('getTableName')
736  ->withArgs(['email'])->andReturn("copyrights");
737  $this->uploadDao->shouldReceive("getItemTreeBounds")
738  ->andReturn($itemTreeBounds);
739  $this->copyrightDao->shouldReceive('updateTable');
740 
741  $requestHeaders = new Headers();
742  $body = $this->streamFactory->createStream();
743  $request = new Request("GET", new Uri("HTTP", "localhost"),
744  $requestHeaders, [], [], $body);
745  $request = $request->withQueryParams(["status" => "active"]);
746 
747  $returnVal = new Info(200, "Successfully removed email.", InfoType::INFO);
748  $expectedResponse = (new ResponseHelper())->withJson($returnVal->getArray(),$returnVal->getCode());
749  $actualResponse = $this->copyrightController->deleteFileEmail($request, new ResponseHelper(),$args);
750 
751  $this->assertEquals($this->getResponseJson($expectedResponse), $this->getResponseJson($actualResponse));
752 
753  }
760  public function testDeleteFileUrl()
761  {
762  $args = $this->getDummyData()['args'];
763  $args['hash'] = "hash";
764  $userId = 4;
765 
766  $itemTreeBounds = [
767  'itemId' => 2,
768  'uploadId' => 2,
769  'uploadTreeTableName' => "uploadtree",
770  'left' => 1,
771  'right' => 31314
772  ];
773  $this->dbHelper->shouldReceive("doesIdExist")
774  ->withArgs(['uploadtree','uploadtree_pk', $args['itemId']])->andReturn(true);
775  $this->dbHelper->shouldReceive("doesIdExist")
776  ->withArgs(['upload','upload_pk', $args['id']])->andReturn(true);
777  $this->restHelper->shouldReceive("getGroupId")
778  ->andReturn(4);
779  $this->uploadDao->shouldReceive("isAccessible")
780  ->withArgs([$args['id'],4])->andReturn(true);
781 
782  $this->uploadDao->shouldReceive("getUploadTreeTableName")
783  ->withAnyArgs()->andReturn("uploadtree");
784 
785  $this->restHelper->shouldReceive("getUserId")
786  ->andReturn($userId);
787  $this->copyrightHist->shouldReceive('getTableName')
788  ->withArgs(['url'])->andReturn("copyrights");
789  $this->uploadDao->shouldReceive("getItemTreeBounds")
790  ->andReturn($itemTreeBounds);
791  $this->copyrightDao->shouldReceive('updateTable');
792 
793  $requestHeaders = new Headers();
794  $body = $this->streamFactory->createStream();
795  $request = new Request("GET", new Uri("HTTP", "localhost"),
796  $requestHeaders, [], [], $body);
797  $request = $request->withQueryParams(["status" => "active"]);
798 
799  $returnVal = new Info(200, "Successfully removed url.", InfoType::INFO);
800  $expectedResponse = (new ResponseHelper())->withJson($returnVal->getArray(),$returnVal->getCode());
801  $actualResponse = $this->copyrightController->deleteFileUrl($request, new ResponseHelper(),$args);
802 
803  $this->assertEquals($this->getResponseJson($expectedResponse), $this->getResponseJson($actualResponse));
804 
805  }
806 
807 
808 
815  public function testDeleteFileAuthor()
816  {
817  $args = $this->getDummyData()['args'];
818  $args['hash'] = "hash";
819  $userId = 4;
820 
821  $itemTreeBounds = [
822  'itemId' => 2,
823  'uploadId' => 2,
824  'uploadTreeTableName' => "uploadtree",
825  'left' => 1,
826  'right' => 31314
827  ];
828  $this->dbHelper->shouldReceive("doesIdExist")
829  ->withArgs(['uploadtree','uploadtree_pk', $args['itemId']])->andReturn(true);
830  $this->dbHelper->shouldReceive("doesIdExist")
831  ->withArgs(['upload','upload_pk', $args['id']])->andReturn(true);
832  $this->restHelper->shouldReceive("getGroupId")
833  ->andReturn(4);
834  $this->uploadDao->shouldReceive("isAccessible")
835  ->withArgs([$args['id'],4])->andReturn(true);
836 
837  $this->uploadDao->shouldReceive("getUploadTreeTableName")
838  ->withAnyArgs()->andReturn("uploadtree");
839 
840  $this->restHelper->shouldReceive("getUserId")
841  ->andReturn($userId);
842  $this->copyrightHist->shouldReceive('getTableName')
843  ->withArgs(['author'])->andReturn("copyrights");
844  $this->uploadDao->shouldReceive("getItemTreeBounds")
845  ->andReturn($itemTreeBounds);
846  $this->copyrightDao->shouldReceive('updateTable');
847 
848  $requestHeaders = new Headers();
849  $body = $this->streamFactory->createStream();
850  $request = new Request("GET", new Uri("HTTP", "localhost"),
851  $requestHeaders, [], [], $body);
852  $request = $request->withQueryParams(["status" => "active"]);
853 
854  $returnVal = new Info(200, "Successfully removed author.", InfoType::INFO);
855  $expectedResponse = (new ResponseHelper())->withJson($returnVal->getArray(),$returnVal->getCode());
856  $actualResponse = $this->copyrightController->deleteFileAuthor($request, new ResponseHelper(),$args);
857 
858  $this->assertEquals($this->getResponseJson($expectedResponse), $this->getResponseJson($actualResponse));
859 
860  }
867  public function testDeleteFileEcc()
868  {
869  $args = $this->getDummyData()['args'];
870  $args['hash'] = "hash";
871  $userId = 4;
872 
873  $itemTreeBounds = [
874  'itemId' => 2,
875  'uploadId' => 2,
876  'uploadTreeTableName' => "uploadtree",
877  'left' => 1,
878  'right' => 31314
879  ];
880  $this->dbHelper->shouldReceive("doesIdExist")
881  ->withArgs(['uploadtree','uploadtree_pk', $args['itemId']])->andReturn(true);
882  $this->dbHelper->shouldReceive("doesIdExist")
883  ->withArgs(['upload','upload_pk', $args['id']])->andReturn(true);
884  $this->restHelper->shouldReceive("getGroupId")
885  ->andReturn(4);
886  $this->uploadDao->shouldReceive("isAccessible")
887  ->withArgs([$args['id'],4])->andReturn(true);
888 
889  $this->uploadDao->shouldReceive("getUploadTreeTableName")
890  ->withAnyArgs()->andReturn("uploadtree");
891 
892  $this->restHelper->shouldReceive("getUserId")
893  ->andReturn($userId);
894  $this->copyrightHist->shouldReceive('getTableName')
895  ->withArgs(['ecc'])->andReturn("copyrights");
896  $this->uploadDao->shouldReceive("getItemTreeBounds")
897  ->andReturn($itemTreeBounds);
898  $this->copyrightDao->shouldReceive('updateTable');
899 
900  $requestHeaders = new Headers();
901  $body = $this->streamFactory->createStream();
902  $request = new Request("GET", new Uri("HTTP", "localhost"),
903  $requestHeaders, [], [], $body);
904  $request = $request->withQueryParams(["status" => "active"]);
905 
906  $returnVal = new Info(200, "Successfully removed ecc.", InfoType::INFO);
907  $expectedResponse = (new ResponseHelper())->withJson($returnVal->getArray(),$returnVal->getCode());
908  $actualResponse = $this->copyrightController->deleteFileEcc($request, new ResponseHelper(),$args);
909 
910  $this->assertEquals($this->getResponseJson($expectedResponse), $this->getResponseJson($actualResponse));
911 
912  }
913 
920  public function testDeleteFileKeyword()
921  {
922  $args = $this->getDummyData()['args'];
923  $args['hash'] = "hash";
924  $userId = 4;
925 
926  $itemTreeBounds = [
927  'itemId' => 2,
928  'uploadId' => 2,
929  'uploadTreeTableName' => "uploadtree",
930  'left' => 1,
931  'right' => 31314
932  ];
933  $this->dbHelper->shouldReceive("doesIdExist")
934  ->withArgs(['uploadtree','uploadtree_pk', $args['itemId']])->andReturn(true);
935  $this->dbHelper->shouldReceive("doesIdExist")
936  ->withArgs(['upload','upload_pk', $args['id']])->andReturn(true);
937  $this->restHelper->shouldReceive("getGroupId")
938  ->andReturn(4);
939  $this->uploadDao->shouldReceive("isAccessible")
940  ->withArgs([$args['id'],4])->andReturn(true);
941 
942  $this->uploadDao->shouldReceive("getUploadTreeTableName")
943  ->withAnyArgs()->andReturn("uploadtree");
944 
945  $this->restHelper->shouldReceive("getUserId")
946  ->andReturn($userId);
947  $this->copyrightHist->shouldReceive('getTableName')
948  ->withArgs(['keyword'])->andReturn("copyrights");
949  $this->uploadDao->shouldReceive("getItemTreeBounds")
950  ->andReturn($itemTreeBounds);
951  $this->copyrightDao->shouldReceive('updateTable');
952 
953  $requestHeaders = new Headers();
954  $body = $this->streamFactory->createStream();
955  $request = new Request("GET", new Uri("HTTP", "localhost"),
956  $requestHeaders, [], [], $body);
957  $request = $request->withQueryParams(["status" => "active"]);
958 
959  $returnVal = new Info(200, "Successfully removed keyword.", InfoType::INFO);
960  $expectedResponse = (new ResponseHelper())->withJson($returnVal->getArray(),$returnVal->getCode());
961  $actualResponse = $this->copyrightController->deleteFileKeyword($request, new ResponseHelper(),$args);
962 
963  $this->assertEquals($this->getResponseJson($expectedResponse), $this->getResponseJson($actualResponse));
964  }
965 
966 
967 
974  public function testDeleteFileIpra()
975  {
976  $args = $this->getDummyData()['args'];
977  $args['hash'] = "hash";
978  $userId = 4;
979 
980  $itemTreeBounds = [
981  'itemId' => 2,
982  'uploadId' => 2,
983  'uploadTreeTableName' => "uploadtree",
984  'left' => 1,
985  'right' => 31314
986  ];
987  $this->dbHelper->shouldReceive("doesIdExist")
988  ->withArgs(['uploadtree','uploadtree_pk', $args['itemId']])->andReturn(true);
989  $this->dbHelper->shouldReceive("doesIdExist")
990  ->withArgs(['upload','upload_pk', $args['id']])->andReturn(true);
991  $this->restHelper->shouldReceive("getGroupId")
992  ->andReturn(4);
993  $this->uploadDao->shouldReceive("isAccessible")
994  ->withArgs([$args['id'],4])->andReturn(true);
995 
996  $this->uploadDao->shouldReceive("getUploadTreeTableName")
997  ->withAnyArgs()->andReturn("uploadtree");
998 
999  $this->restHelper->shouldReceive("getUserId")
1000  ->andReturn($userId);
1001  $this->copyrightHist->shouldReceive('getTableName')
1002  ->withArgs(['ipra'])->andReturn("copyrights");
1003  $this->uploadDao->shouldReceive("getItemTreeBounds")
1004  ->andReturn($itemTreeBounds);
1005  $this->copyrightDao->shouldReceive('updateTable');
1006 
1007  $requestHeaders = new Headers();
1008  $body = $this->streamFactory->createStream();
1009  $request = new Request("GET", new Uri("HTTP", "localhost"),
1010  $requestHeaders, [], [], $body);
1011  $request = $request->withQueryParams(["status" => "active"]);
1012 
1013  $returnVal = new Info(200, "Successfully removed ipra.", InfoType::INFO);
1014  $expectedResponse = (new ResponseHelper())->withJson($returnVal->getArray(),$returnVal->getCode());
1015  $actualResponse = $this->copyrightController->deleteFileIpra($request, new ResponseHelper(),$args);
1016 
1017  $this->assertEquals($this->getResponseJson($expectedResponse), $this->getResponseJson($actualResponse));
1018  }
1019 
1020 }
Contains the constants and helpers for authentication of user.
Definition: Auth.php:24
Provides helper methods to access database for REST api.
Definition: DbHelper.php:38
Override Slim response for withJson function.
Provides various DAO helper functions for REST api.
Definition: RestHelper.php:32
Different type of infos provided by REST.
Definition: InfoType.php:16
Info model to contain general error and return values.
Definition: Info.php:19