14 if (!function_exists(
'RepPathItem')) {
17 return dirname(__DIR__) .
"/tests.xml";
62 use Psr\Http\Message\ServerRequestInterface;
63 use Slim\Psr7\Factory\StreamFactory;
64 use Slim\Psr7\Headers;
65 use Slim\Psr7\Request;
66 use Slim\Psr7\Response;
68 use Symfony\Component\HttpFoundation\JsonResponse;
76 public $assertCountBefore;
138 private $streamFactory;
206 protected function setUp(): void
214 $container = M::mock(
'ContainerBuilder');
215 $this->dbHelper = M::mock(DbHelper::class);
216 $this->
dbManager = M::mock(DbManager::class);
217 $this->restHelper = M::mock(RestHelper::class);
218 $this->uploadDao = M::mock(UploadDao::class);
219 $this->decisionTypes = M::mock(DecisionTypes::class);
220 $this->licenseDao = M::mock(LicenseDao::class);
221 $this->clearingDecisionEventProcessor = M::mock(ClearingDecisionProcessor::class);
222 $this->viewFilePlugin = M::mock(
'ui_view');
223 $this->viewLicensePlugin = M::mock(ClearingView::class);
224 $this->clearingDao = M::mock(ClearingDao::class);
225 $this->decisionScopes = M::mock(DecisionScopes::class);
226 $this->highlightDao = M::mock(HighlightDao::class);
227 $this->clearingEventTypes = M::mock(ClearingEventTypes::class);
228 $this->itemTreeBoundsMock = M::mock(ItemTreeBounds::class);
229 $this->concludeLicensePlugin = M::mock(AjaxClearingView::class);
230 $this->licenseDao = M::mock(LicenseDao::class);
231 $this->changeLicenseBulk = M::mock(ChangeLicenseBulk::class);
232 $this->licenseDao = M::mock(LicenseDao::class);
234 $this->restHelper->shouldReceive(
'getPlugin')
235 ->withArgs(array(
'view'))->andReturn($this->viewFilePlugin);
236 $this->restHelper->shouldReceive(
'getPlugin')
237 ->withArgs(array(
'view-license'))->andReturn($this->viewLicensePlugin);
238 $this->restHelper->shouldReceive(
'getPlugin')
239 ->withArgs(array(
'conclude-license'))->andReturn($this->concludeLicensePlugin);
240 $this->restHelper->shouldReceive(
'getPlugin')
241 ->withArgs(array(
'change-license-bulk'))->andReturn($this->changeLicenseBulk);
243 $this->
dbManager->shouldReceive(
'getSingleRow')
244 ->withArgs([M::any(), [$this->groupId, UploadStatus::OPEN,
246 $this->dbHelper->shouldReceive(
'getDbManager')->andReturn($this->
dbManager);
247 $this->restHelper->shouldReceive(
'getDbHelper')->andReturn($this->dbHelper);
248 $this->restHelper->shouldReceive(
'getGroupId')->andReturn($this->groupId);
249 $this->restHelper->shouldReceive(
'getUserId')->andReturn($this->userId);
250 $this->restHelper->shouldReceive(
'getUploadDao')
251 ->andReturn($this->uploadDao);
252 $container->shouldReceive(
'get')->withArgs(array(
253 'helper.restHelper'))->andReturn($this->restHelper);
254 $container->shouldReceive(
'get')->withArgs([
'decision.types'])->andReturn($this->decisionTypes);
255 $container->shouldReceive(
'get')->withArgs([
'dao.clearing'])->andReturn($this->clearingDao);
256 $container->shouldReceive(
'get')->withArgs([
'dao.license'])->andReturn($this->licenseDao);
258 $container->shouldReceive(
'get')->withArgs([
'businessrules.clearing_decision_processor'])->andReturn($this->clearingDecisionEventProcessor);
259 $container->shouldReceive(
'get')->withArgs([
'dao.highlight'])->andReturn($this->highlightDao);
260 $container->shouldReceive(
'get')->withArgs([
'dao.license'])->andReturn($this->licenseDao);
262 $this->assertCountBefore = \Hamcrest\MatcherAssert::getCount();
263 $this->streamFactory =
new StreamFactory();
274 $response->getBody()->seek(0);
275 return json_decode($response->getBody()->getContents(),
true);
288 $expectedContent = file_get_contents(dirname(__DIR__) .
"/tests.xml");
290 $this->uploadDao->shouldReceive(
'isAccessible')
291 ->withArgs([$upload_pk, $this->groupId])->andReturn(
true);
292 $this->dbHelper->shouldReceive(
'doesIdExist')
293 ->withArgs([
"upload",
"upload_pk", $upload_pk])->andReturn(
true);
294 $this->uploadDao->shouldReceive(
"getUploadtreeTableName")
295 ->withArgs([$upload_pk])->andReturn($tableName);
296 $this->uploadDao->shouldReceive(
'getUploadEntry')
297 ->withArgs([$item_pk, $tableName])->once()
298 ->andReturn([
'upload_fk' => (
string) $upload_pk]);
300 $this->viewFilePlugin->shouldReceive(
'getText')->withArgs([M::any(), 0, 0, -1,
null,
false,
true])->andReturn($expectedContent);
303 $expectedResponse->getBody()->write($expectedContent);
304 $request = (
new Request(
'GET',
new Uri(
'http',
'localhost'),
305 new Headers(), [], [], $this->streamFactory->createStream()))
306 ->withAttribute(ApiVersion::ATTRIBUTE_NAME, $version);
307 $actualResponse = $this->uploadTreeController->viewLicenseFile($request,
308 new ResponseHelper(), [
'id' => $upload_pk,
'itemId' => $item_pk]);
309 $this->assertEquals($expectedResponse->getStatusCode(), $actualResponse->getStatusCode());
310 $this->assertEquals($expectedResponse->getBody()->getContents(), $actualResponse->getBody()->getContents());
313 public function itemTableProvider(): array
316 foreach ([ApiVersion::V1, ApiVersion::V2] as $version) {
317 foreach ([
'uploadtree',
'uploadtree_a',
'uploadtree_1'] as $tableName) {
318 $cases[
"v$version $tableName"] = [$version, $tableName];
329 $this->dbHelper->shouldReceive(
'doesIdExist')
330 ->with(
'upload',
'upload_pk', 1)->andReturn(
true);
331 $this->uploadDao->shouldReceive(
'isAccessible')
332 ->with(1, $this->groupId)->andReturn(
false);
333 $this->uploadDao->shouldReceive(
'getUploadtreeTableName')
334 ->with(1)->andReturn($tableName);
335 $this->uploadDao->shouldNotReceive(
'getUploadEntry');
336 $this->viewFilePlugin->shouldNotReceive(
'getText');
338 $request = (
new Request(
'GET',
new Uri(
'http',
'localhost'),
339 new Headers(), [], [], $this->streamFactory->createStream()))
340 ->withAttribute(ApiVersion::ATTRIBUTE_NAME, $version);
341 $this->expectException(HttpForbiddenException::class);
342 $this->expectExceptionCode(403);
343 $this->uploadTreeController->viewLicenseFile($request,
new ResponseHelper(),
344 [
'id' => 1,
'itemId' => 200]);
351 $itemExists, $otherUploadAccessible)
355 $this->dbHelper->shouldReceive(
'doesIdExist')
356 ->with(
'upload',
'upload_pk', $uploadId)->andReturn(
true);
357 $this->uploadDao->shouldReceive(
'isAccessible')
358 ->with($uploadId, $this->groupId)->andReturn(
true);
359 $this->uploadDao->shouldReceive(
'isAccessible')
360 ->with(2, $this->groupId)->andReturn($otherUploadAccessible);
361 $this->uploadDao->shouldReceive(
'getUploadtreeTableName')
362 ->with($uploadId)->andReturn($tableName);
363 $this->uploadDao->shouldReceive(
'getUploadEntry')
364 ->with($itemId, $tableName)->once()
365 ->andReturn($itemExists ? [
'upload_fk' =>
'2'] :
false);
366 $this->viewFilePlugin->shouldNotReceive(
'getText');
368 $request = (
new Request(
'GET',
new Uri(
'http',
'localhost'),
369 new Headers(), [], [], $this->streamFactory->createStream()))
370 ->withAttribute(ApiVersion::ATTRIBUTE_NAME, $version);
371 $this->expectException(HttpNotFoundException::class);
372 $this->expectExceptionCode(404);
373 $this->uploadTreeController->viewLicenseFile($request,
new ResponseHelper(),
374 [
'id' => $uploadId,
'itemId' => $itemId]);
377 public function invalidItemProvider(): array
380 foreach ([ApiVersion::V1, ApiVersion::V2] as $version) {
381 foreach ([
'uploadtree',
'uploadtree_a',
'uploadtree_1'] as $tableName) {
382 $cases[
"v$version $tableName inaccessible foreign item"] =
383 [$version, $tableName,
true,
false];
384 $cases[
"v$version $tableName accessible foreign item"] =
385 [$version, $tableName,
true,
true];
386 $cases[
"v$version $tableName missing item"] =
387 [$version, $tableName,
false,
false];
404 "globalDecision" =>
false,
406 $dummyDecisionTypes = array_map(
function ($i) {
410 $this->decisionTypes->shouldReceive(
'getMap')
411 ->andReturn($dummyDecisionTypes);
412 $this->uploadDao->shouldReceive(
"getUploadtreeTableName")->withArgs([$upload_pk])->andReturn(
"uploadtree");
413 $this->uploadDao->shouldReceive(
'isAccessible')
414 ->withArgs([$upload_pk, $this->groupId])->andReturn(
true);
415 $this->dbHelper->shouldReceive(
'doesIdExist')
416 ->withArgs([
"upload",
"upload_pk", $upload_pk])->andReturn(
true);
417 $this->uploadDao->shouldReceive(
'getUploadEntry')
418 ->withArgs([$item_pk,
"uploadtree"])
419 ->andReturn([
'upload_fk' => (
string) $upload_pk]);
422 $this->viewLicensePlugin->shouldReceive(
'updateLastItem')->withArgs([2, 2, $item_pk, $item_pk]);
424 $info =
new Info(200,
"Successfully set decision", InfoType::INFO);
426 $expectedResponse = (
new ResponseHelper())->withJson($info->getArray(), $info->getCode());
427 $reqBody = $this->streamFactory->createStream(json_encode(
430 $requestHeaders =
new Headers();
431 $requestHeaders->setHeader(
'Content-Type',
'application/json');
432 $request =
new Request(
"PUT",
new Uri(
"HTTP",
"localhost"),
433 $requestHeaders, [], [], $reqBody);
434 $actualResponse = $this->uploadTreeController->setClearingDecision($request,
new ResponseHelper(), [
'id' => $upload_pk,
'itemId' => $item_pk]);
436 $this->assertEquals($expectedResponse->getStatusCode(),
437 $actualResponse->getStatusCode());
452 "decisionType" => 40,
453 "globalDecision" =>
false,
455 $dummyDecisionTypes = array_map(
function ($i) {
459 $this->decisionTypes->shouldReceive(
'getMap')
460 ->andReturn($dummyDecisionTypes);
461 $this->uploadDao->shouldReceive(
"getUploadtreeTableName")->withArgs([$upload_pk])->andReturn(
"uploadtree");
462 $this->uploadDao->shouldReceive(
'isAccessible')
463 ->withArgs([$upload_pk, $this->groupId])->andReturn(
true);
464 $this->dbHelper->shouldReceive(
'doesIdExist')
465 ->withArgs([
"upload",
"upload_pk", $upload_pk])->andReturn(
true);
466 $this->uploadDao->shouldReceive(
'getUploadEntry')
467 ->withArgs([$item_pk,
"uploadtree"])
468 ->andReturn([
'upload_fk' => (
string) $upload_pk]);
470 $this->viewLicensePlugin->shouldReceive(
'updateLastItem')->withArgs([2, 2, $item_pk, $item_pk]);
472 $reqBody = $this->streamFactory->createStream(json_encode(
475 $requestHeaders =
new Headers();
476 $requestHeaders->setHeader(
'Content-Type',
'application/json');
477 $request =
new Request(
"PUT",
new Uri(
"HTTP",
"localhost"),
478 $requestHeaders, [], [], $reqBody);
479 $this->expectException(HttpBadRequestException::class);
481 $this->uploadTreeController->setClearingDecision($request,
482 new ResponseHelper(), [
'id' => $upload_pk,
'itemId' => $item_pk]);
495 $itemTreeBounds1 =
new ItemTreeBounds($nextItemId,
'uploadtree_a', $uploadId, 1, 2);
496 $itemTreeBounds2 =
new ItemTreeBounds($prevItemId,
'uploadtree_a', $uploadId, 1, 2);
498 $item1 =
new Item($itemTreeBounds1, 1, 1, 1,
"fileName");
499 $item2 =
new Item($itemTreeBounds2, 1, 1, 1,
"fileName");
502 "prevItemId" => $prevItemId,
503 "nextItemId" => $nextItemId
505 $options = array(
'skipThese' =>
"",
'groupId' => $this->groupId);
507 $this->uploadDao->shouldReceive(
'isAccessible')
508 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
509 $this->dbHelper->shouldReceive(
'doesIdExist')
510 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
511 $this->uploadDao->shouldReceive(
'getUploadtreeTableName')->withArgs([$uploadId])->andReturn(
"uploadtree");
512 $this->uploadDao->shouldReceive(
'getUploadEntry')
513 ->withArgs([$itemId,
"uploadtree"])
514 ->andReturn([
'upload_fk' => (
string) $uploadId]);
516 $this->uploadDao->shouldReceive(
'getNextItem')->withArgs([$uploadId, $itemId, $options])->andReturn($item1);
517 $this->uploadDao->shouldReceive(
'getPreviousItem')->withArgs([$uploadId, $itemId, $options])->andReturn($item2);
518 $expectedResponse = (
new ResponseHelper())->withJson($result, 200);
519 $queryParams = [
'selection' =>
null];
520 $request = $this->getMockBuilder(ServerRequestInterface::class)
522 $request->expects($this->any())
523 ->method(
'getQueryParams')
524 ->willReturn($queryParams);
526 $actualResponse = $this->uploadTreeController->getNextPreviousItem($request,
new ResponseHelper(), [
'id' => $uploadId,
'itemId' => $itemId]);
527 $this->assertEquals($expectedResponse->getStatusCode(), $actualResponse->getStatusCode());
542 $itemTreeBounds1 =
new ItemTreeBounds($nextItemId,
'uploadtree_a', $uploadId, 1, 2);
543 $itemTreeBounds2 =
new ItemTreeBounds($prevItemId,
'uploadtree_a', $uploadId, 1, 2);
545 $item1 =
new Item($itemTreeBounds1, 1, 1, 1,
"fileName");
546 $item2 =
new Item($itemTreeBounds2, 1, 1, 1,
"fileName");
548 $options = array(
'skipThese' =>
"",
'groupId' => $this->groupId);
550 $this->uploadDao->shouldReceive(
'isAccessible')
551 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
552 $this->dbHelper->shouldReceive(
'doesIdExist')
553 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
554 $this->uploadDao->shouldReceive(
'getUploadtreeTableName')->withArgs([$uploadId])->andReturn(
"uploadtree");
555 $this->uploadDao->shouldReceive(
'getUploadEntry')
556 ->withArgs([$itemId,
"uploadtree"])
557 ->andReturn([
'upload_fk' => (
string) $uploadId]);
559 $this->uploadDao->shouldReceive(
'getNextItem')->withArgs([$uploadId, $itemId, $options])->andReturn($item1);
560 $this->uploadDao->shouldReceive(
'getPreviousItem')->withArgs([$uploadId, $itemId, $options])->andReturn($item2);
562 $queryParams = [
'selection' =>
"invalidSelection"];
563 $request = $this->getMockBuilder(ServerRequestInterface::class)
565 $request->expects($this->any())
566 ->method(
'getQueryParams')
567 ->willReturn($queryParams);
568 $this->expectException(HttpBadRequestException::class);
570 $this->uploadTreeController->getNextPreviousItem($request,
583 $itemTreeBounds =
new ItemTreeBounds($itemId,
'uploadtree', $uploadId, 1, 2);
591 "addedLicenses" => [],
592 "removedLicenses" => [],
595 $obj =
new BulkHistory(1, 1,
"test",
true,
true, [], []);
596 $updatedRes[] = $obj->getArray();
598 $this->uploadDao->shouldReceive(
'isAccessible')
599 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
600 $this->dbHelper->shouldReceive(
'doesIdExist')
601 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
603 $this->uploadDao->shouldReceive(
'getUploadtreeTableName')->withArgs([$uploadId])->andReturn(
"uploadtree");
604 $this->uploadDao->shouldReceive(
'getUploadEntry')
605 ->withArgs([$itemId,
"uploadtree"])
606 ->andReturn([
'upload_fk' => (
string) $uploadId]);
608 $this->uploadDao->shouldReceive(
"getItemTreeBounds")
609 ->withArgs([$itemId,
"uploadtree"])->andReturn($itemTreeBounds);
611 $this->clearingDao->shouldReceive(
"getBulkHistory")
612 ->withArgs([$itemTreeBounds, $this->groupId])->andReturn($res);
613 $expectedResponse = (
new ResponseHelper())->withJson($updatedRes, 200);
614 $actualResponse = $this->uploadTreeController->getBulkHistory(
null,
new ResponseHelper(), [
'id' => $uploadId,
'itemId' => $itemId]);
615 $this->assertEquals($expectedResponse->getStatusCode(), $actualResponse->getStatusCode());
628 $itemTreeBounds =
new ItemTreeBounds($itemId,
'uploadtree_a', $uploadId, 1, 2);
629 $fileClearings[] =
new ClearingDecision(1, 1, $itemId, 1, 1, 1, 3, 1, 1, [], 1, 1, 1);
638 $result[] = $obj->getArray();
640 $this->uploadDao->shouldReceive(
'isAccessible')
641 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
642 $this->dbHelper->shouldReceive(
'doesIdExist')
643 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
645 $this->uploadDao->shouldReceive(
'getUploadtreeTableName')->withArgs([$uploadId])->andReturn(
"uploadtree");
646 $this->uploadDao->shouldReceive(
'getUploadEntry')
647 ->withArgs([$itemId,
"uploadtree"])
648 ->andReturn([
'upload_fk' => (
string) $uploadId]);
650 $this->uploadDao->shouldReceive(
"getItemTreeBoundsFromUploadId")
651 ->withArgs([$itemId, $uploadId])->andReturn($itemTreeBounds);
652 $this->clearingDao->shouldReceive(
"getFileClearings")
653 ->withArgs([$itemTreeBounds, $this->groupId,
false,
true])->andReturn($fileClearings);
654 $this->decisionTypes->shouldReceive(
"getTypeName")
655 ->withArgs([$fileClearings[0]->getType()])->andReturn(
"test");
656 $this->decisionScopes->shouldReceive(
"getTypeName")->withArgs([$fileClearings[0]->getScope()])->andReturn(
"test");
657 $this->decisionTypes->shouldReceive(
"getConstantNameFromKey")
658 ->withArgs([$fileClearings[0]->getType()])->andReturn(
"TO_BE_DISCUSSED");
659 $expectedResponse = (
new ResponseHelper())->withJson($result, 200);
660 $actualResponse = $this->uploadTreeController->getClearingHistory(
null,
new ResponseHelper(), [
'id' => $uploadId,
'itemId' => $itemId]);
661 $this->assertEquals($expectedResponse->getStatusCode(), $actualResponse->getStatusCode());
681 "infoText" =>
"MIT: 'MIT License\n\nCopyright (c) <year> <copyright holders>'",
682 "htmlElement" =>
null
685 $highlight =
new Highlight($res[0][
"start"], $res[0][
"end"], $res[0][
"type"], $res[0][
"refStart"], $res[0][
"refEnd"], $res[0][
"infoText"]);
686 $itemTreeBounds =
new ItemTreeBounds($itemId,
'uploadtree', $uploadId, 1, 2);
688 $this->uploadDao->shouldReceive(
'isAccessible')
689 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
690 $this->dbHelper->shouldReceive(
'doesIdExist')
691 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
692 $this->uploadDao->shouldReceive(
"getUploadtreeTableName")->withArgs([$uploadId])->andReturn(
"uploadtree");
693 $this->uploadDao->shouldReceive(
'getUploadEntry')
694 ->withArgs([$itemId,
"uploadtree"])
695 ->andReturn([
'upload_fk' => (
string) $uploadId]);
696 $this->uploadDao->shouldReceive(
"getItemTreeBounds")->withArgs([$itemId,
"uploadtree"])->andReturn($itemTreeBounds);
697 $this->viewLicensePlugin->shouldReceive(
'getSelectedHighlighting')->withArgs([$itemTreeBounds,
null,
null,
null,
null, $uploadId])->andReturn([$highlight]);
700 $queryParams = [
'clearingId' =>
null,
'agentId' =>
null,
'highlightId' =>
null,
'licenseId' =>
null];
701 $request = $this->getMockBuilder(ServerRequestInterface::class)
703 $request->expects($this->any())
704 ->method(
'getQueryParams')
705 ->willReturn($queryParams);
707 $actualResponse = $this->uploadTreeController->getHighlightEntries($request,
new ResponseHelper(), [
'id' => $uploadId,
'itemId' => $itemId]);
708 $this->assertEquals($expectedResponse->getStatusCode(), $actualResponse->getStatusCode());
721 $this->dbHelper->shouldReceive(
'doesIdExist')
722 ->withArgs([
"upload",
"upload_pk", $this->uploadId])->andReturn(
false);
725 $reqBody = $this->streamFactory->createStream();
726 $requestHeaders =
new Headers();
729 "agentId" => $this->agentId,
733 $uri = (
new Uri(
'HTTP',
'localhost'))
734 ->withQuery(http_build_query($queryParams));
736 $requestHeaders->setHeader(
'Content-Type',
'application/json');
737 $request =
new Request(
"POST", $uri,
738 $requestHeaders, [], [], $reqBody);
740 $this->expectException(HttpNotFoundException::class);
741 $this->uploadTreeController->getTreeView($request,
new ResponseHelper(), [
"id" => $this->uploadId,
"itemId"=> 10]);
755 $this->dbHelper->shouldReceive(
'doesIdExist')
756 ->withArgs([
"upload",
"upload_pk", $this->uploadId])->andReturn(
false);
757 $this->dbHelper->shouldReceive(
'doesIdExist')
758 ->withArgs([
"agent",
"agent_pk", $this->agentId])->andReturn(
false);
759 $this->uploadDao->shouldReceive(
'isAccessible')
760 ->withArgs([$this->uploadId, $this->groupId])->andReturn(
true);
762 $reqBody = $this->streamFactory->createStream();
763 $requestHeaders =
new Headers();
766 "agentId" => $this->agentId,
770 $uri = (
new Uri(
'HTTP',
'localhost'))
771 ->withQuery(http_build_query($queryParams));
773 $requestHeaders->setHeader(
'Content-Type',
'application/json');
774 $request =
new Request(
"POST", $uri,
775 $requestHeaders, [], [], $reqBody);
777 $this->expectException(HttpNotFoundException::class);
778 $this->uploadTreeController->getTreeView($request,
new ResponseHelper(), [
"id" => $this->uploadId,
"itemId"=> 10]);
792 $this->dbHelper->shouldReceive(
'doesIdExist')
793 ->withArgs([
"upload",
"upload_pk", $this->uploadId])->andReturn(
false);
794 $this->dbHelper->shouldReceive(
'doesIdExist')
795 ->withArgs([
"tag",
"tag_pk", $this->tagId])->andReturn(
false);
796 $this->uploadDao->shouldReceive(
'isAccessible')
797 ->withArgs([$this->uploadId, $this->groupId])->andReturn(
true);
799 $reqBody = $this->streamFactory->createStream();
800 $requestHeaders =
new Headers();
803 "agentId" => $this->agentId,
807 $uri = (
new Uri(
'HTTP',
'localhost'))
808 ->withQuery(http_build_query($queryParams));
810 $requestHeaders->setHeader(
'Content-Type',
'application/json');
811 $request =
new Request(
"POST", $uri,
812 $requestHeaders, [], [], $reqBody);
814 $this->expectException(HttpNotFoundException::class);
815 $this->uploadTreeController->getTreeView($request,
new ResponseHelper(), [
"id" => $this->uploadId,
"itemId"=> 10]);
829 $this->dbHelper->shouldReceive(
'doesIdExist')
830 ->withArgs([
"upload",
"upload_pk", $this->uploadId])->andReturn(
true);
831 $this->uploadDao->shouldReceive(
'isAccessible')
832 ->withArgs([$this->uploadId, $this->groupId])->andReturn(
false);
834 $reqBody = $this->streamFactory->createStream();
835 $requestHeaders =
new Headers();
838 "agentId" => $this->agentId,
842 $uri = (
new Uri(
'HTTP',
'localhost'))
843 ->withQuery(http_build_query($queryParams));
844 $requestHeaders->setHeader(
'Content-Type',
'application/json');
845 $request =
new Request(
"POST", $uri,
846 $requestHeaders, [], [], $reqBody);
847 $this->expectException(HttpForbiddenException::class);
848 $this->uploadTreeController->getTreeView($request,
new ResponseHelper(), [
"id" => $this->uploadId,
"itemId"=> 10]);
866 $itemTreeBounds =
new ItemTreeBounds($itemId,
'uploadtree_a', $uploadId, 0, 1);
867 $addedClearingResults = [];
870 'name' =>
'Imported decision',
871 'clearingId' =>
null,
873 'highlightId' =>
null,
878 $license =
new License($licenseId,
"MIT",
"MIT License",
"text",
"url", [],
880 $licenseDecision =
new LicenseDecision($licenseId,
"MIT",
"MIT License",
'text',
"url", array($result),
881 '',
'',
false, [],
null,
false);
883 $licenseRef =
new LicenseRef($licenseId,
"MIT",
"MIT LICENSE",
"spx");
884 $clearingEvent =
new ClearingEvent(1, $itemId, 12, $this->userId, $this->groupId, 4,
new ClearingLicense($licenseRef,
false,
"",
"",
"",
""));
886 $addedClearingResults[$licenseId] = $licenseDecisionResult;
888 $this->uploadDao->shouldReceive(
'isAccessible')
889 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
890 $this->dbHelper->shouldReceive(
'doesIdExist')
891 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
893 $this->uploadDao->shouldReceive(
'getUploadtreeTableName')->withArgs([$uploadId])->andReturn(
"uploadtree");
894 $this->uploadDao->shouldReceive(
'getUploadEntry')
895 ->withArgs([$itemId,
"uploadtree"])
896 ->andReturn([
'upload_fk' => (
string) $uploadId]);
898 $this->uploadDao->shouldReceive(
"getItemTreeBoundsFromUploadId")->withArgs([$itemId, $uploadId])->andReturn($itemTreeBounds);
899 $this->itemTreeBoundsMock->shouldReceive(
"containsFiles")->andReturn(
false);
900 $this->clearingDao->shouldReceive(
'getMainLicenseIds')->andReturn([]);
901 $this->clearingEventTypes->shouldReceive(
'getTypeName')->withArgs([$clearingEvent->getEventType()])->andReturn($result[
'name']);
902 $this->highlightDao->shouldReceive(
'getHighlightRegion')->withArgs([1])->andReturn([
""]);
903 $this->clearingDecisionEventProcessor->shouldReceive(
"getCurrentClearings")->withArgs([$itemTreeBounds, $this->groupId, LicenseMap::CONCLUSION])->andReturn([$addedClearingResults, []]);
904 $this->licenseDao->shouldReceive(
'getLicenseObligations')->withArgs([[$licenseId],
false])->andReturn([]);
905 $this->licenseDao->shouldReceive(
'getLicenseObligations')->withArgs([[$licenseId],
true])->andReturn([]);
906 $this->licenseDao->shouldReceive(
'getLicenseById')->withArgs([$licenseId, $this->groupId])->andReturn($license);
907 $licenses[] = $licenseDecision->getArray();
909 $expectedResponse = (
new ResponseHelper())->withJson($licenses, 200);
910 $actualResponse = $this->uploadTreeController->getLicenseDecisions(
null,
new ResponseHelper(), [
'id' => $uploadId,
'itemId' => $itemId]);
911 $this->assertEquals($expectedResponse->getStatusCode(), $actualResponse->getStatusCode());
926 $license =
new License($licenseId,
"MIT",
"MIT License",
"risk",
"texts", [],
928 $itemTreeBounds =
new ItemTreeBounds($itemId,
'uploadtree_a', $uploadId, 1, 2);
931 "shortName" =>
"MIT",
936 $existingLicenses = array([
'DT_RowId' =>
"$itemId,400",
'DT_RowClass' =>
'removed']);
938 $this->uploadDao->shouldReceive(
'isAccessible')
939 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
940 $this->dbHelper->shouldReceive(
'doesIdExist')
941 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
942 $this->uploadDao->shouldReceive(
"getUploadtreeTableName")->withArgs([$uploadId])->andReturn(
"uploadtree");
943 $this->uploadDao->shouldReceive(
'getUploadEntry')
944 ->withArgs([$itemId,
"uploadtree"])
945 ->andReturn([
'upload_fk' => (
string) $uploadId]);
946 $this->uploadDao->shouldReceive(
'getItemTreeBoundsFromUploadId')->withArgs([$itemId, $uploadId])->andReturn($itemTreeBounds);
947 $this->concludeLicensePlugin->shouldReceive(
'getCurrentSelectedLicensesTableData')->withArgs([$itemTreeBounds, $this->groupId,
true])->andReturn($existingLicenses);
948 $this->licenseDao->shouldReceive(
'getLicenseByShortName')
949 ->withArgs([$shortName, $this->groupId])->andReturn($license);
950 $this->clearingDao->shouldReceive(
'insertClearingEvent')
951 ->withArgs([$itemId, $this->userId, $this->groupId, $licenseId,
false])->andReturn(
null);
953 $info =
new Info(200,
'Successfully added MIT as a new license decision.', InfoType::INFO);
955 'success' => [$info->getArray()],
959 $reqBody = $this->streamFactory->createStream(json_encode(
962 $requestHeaders =
new Headers();
963 $requestHeaders->setHeader(
'Content-Type',
'application/json');
964 $request =
new Request(
"PUT",
new Uri(
"HTTP",
"localhost"),
965 $requestHeaders, [], [], $reqBody);
966 $actualResponse = $this->uploadTreeController->handleAddEditAndDeleteLicenseDecision($request,
new ResponseHelper(), [
'id' => $uploadId,
'itemId' => $itemId]);
968 $this->assertEquals($expectedResponse->getStatusCode(),
969 $actualResponse->getStatusCode());
985 $license =
new License($licenseId,
"MIT",
"MIT License",
"risk",
"texts", [],
987 $itemTreeBounds =
new ItemTreeBounds($itemId,
'uploadtree_a', $uploadId, 1, 2);
990 "shortName" =>
"MIT",
992 "text" =>
"Updated license text",
996 $existingLicenses = array([
'DT_RowId' =>
"$itemId,$licenseId",
'DT_RowClass' =>
'removed']);
998 $this->uploadDao->shouldReceive(
'isAccessible')
999 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
1000 $this->dbHelper->shouldReceive(
'doesIdExist')
1001 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1002 $this->uploadDao->shouldReceive(
"getUploadtreeTableName")->withArgs([$uploadId])->andReturn(
"uploadtree");
1003 $this->uploadDao->shouldReceive(
'getUploadEntry')
1004 ->withArgs([$itemId,
"uploadtree"])
1005 ->andReturn([
'upload_fk' => (
string) $uploadId]);
1006 $this->uploadDao->shouldReceive(
'getItemTreeBoundsFromUploadId')->withArgs([$itemId, $uploadId])->andReturn($itemTreeBounds);
1007 $this->concludeLicensePlugin->shouldReceive(
'getCurrentSelectedLicensesTableData')->withArgs([$itemTreeBounds, $this->groupId,
true])->andReturn($existingLicenses);
1008 $this->licenseDao->shouldReceive(
'getLicenseByShortName')
1009 ->withArgs([$shortName, $this->groupId])->andReturn($license);
1010 $this->clearingDao->shouldReceive(
'updateClearingEvent')
1011 ->withArgs([$itemId, $this->userId, $this->groupId, $licenseId,
'reportinfo',
"Updated license text"])->andReturn(
null);
1013 $info =
new Info(200,
"Successfully updated MIT's license reportinfo", InfoType::INFO);
1015 'success' => [$info->getArray()],
1019 $reqBody = $this->streamFactory->createStream(json_encode(
1022 $requestHeaders =
new Headers();
1023 $requestHeaders->setHeader(
'Content-Type',
'application/json');
1024 $request =
new Request(
"PUT",
new Uri(
"HTTP",
"localhost"),
1025 $requestHeaders, [], [], $reqBody);
1026 $actualResponse = $this->uploadTreeController->handleAddEditAndDeleteLicenseDecision($request,
new ResponseHelper(), [
'id' => $uploadId,
'itemId' => $itemId]);
1028 $this->assertEquals($expectedResponse->getStatusCode(),
1029 $actualResponse->getStatusCode());
1045 $license =
new License($licenseId,
"MIT",
"MIT License",
"risk",
"texts", [],
1047 $itemTreeBounds =
new ItemTreeBounds($itemId,
'uploadtree_a', $uploadId, 1, 2);
1050 "shortName" =>
"MIT",
1052 "text" =>
"Updated license text",
1056 $existingLicenses = array([
'DT_RowId' =>
"$itemId,$licenseId",
'DT_RowClass' =>
'removed']);
1058 $this->uploadDao->shouldReceive(
'isAccessible')
1059 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
1060 $this->dbHelper->shouldReceive(
'doesIdExist')
1061 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1062 $this->uploadDao->shouldReceive(
"getUploadtreeTableName")->withArgs([$uploadId])->andReturn(
"uploadtree");
1063 $this->uploadDao->shouldReceive(
'getUploadEntry')
1064 ->withArgs([$itemId,
"uploadtree"])
1065 ->andReturn([
'upload_fk' => (
string) $uploadId]);
1066 $this->uploadDao->shouldReceive(
'getItemTreeBoundsFromUploadId')->withArgs([$itemId, $uploadId])->andReturn($itemTreeBounds);
1067 $this->concludeLicensePlugin->shouldReceive(
'getCurrentSelectedLicensesTableData')->withArgs([$itemTreeBounds, $this->groupId,
true])->andReturn($existingLicenses);
1068 $this->licenseDao->shouldReceive(
'getLicenseByShortName')
1069 ->withArgs([$shortName, $this->groupId])->andReturn($license);
1070 $this->clearingDao->shouldReceive(
'insertClearingEvent')
1071 ->withArgs([$itemId, $this->userId, $this->groupId, $licenseId,
true])->andReturn(
null);
1073 $info =
new Info(200,
'Successfully deleted MIT from license decision list.', InfoType::INFO);
1075 'success' => [$info->getArray()],
1079 $reqBody = $this->streamFactory->createStream(json_encode(
1082 $requestHeaders =
new Headers();
1083 $requestHeaders->setHeader(
'Content-Type',
'application/json');
1084 $request =
new Request(
"PUT",
new Uri(
"HTTP",
"localhost"),
1085 $requestHeaders, [], [], $reqBody);
1086 $actualResponse = $this->uploadTreeController->handleAddEditAndDeleteLicenseDecision($request,
new ResponseHelper(), [
'id' => $uploadId,
'itemId' => $itemId]);
1088 $this->assertEquals($expectedResponse->getStatusCode(),
1089 $actualResponse->getStatusCode());
1102 $licenseShortName =
"MIT";
1103 $existingLicense =
new License( $licenseId, $licenseShortName,
"FULL NAME",
"text",
"url", [],
"1");
1107 'licenseShortName' => $licenseShortName,
1108 'licenseText' =>
'',
1109 'acknowledgement' =>
'',
1111 'licenseAction' =>
'ADD'
1114 'refText' =>
'Copyright (c) 2011-2023 The Bootstrap Authors',
1115 'bulkScope' =>
'folder',
1116 'forceDecision' => 0,
1118 'delimiters' =>
'DEFAULT',
1119 'scanOnlyFindings' => 0
1122 $res =
new JsonResponse(array(
"jqid" => $jobId));
1127 $this->uploadDao->shouldReceive(
'isAccessible')
1128 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
1129 $this->dbHelper->shouldReceive(
'doesIdExist')
1130 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1131 $this->uploadDao->shouldReceive(
'getUploadtreeTableName')->withArgs([$uploadId])->andReturn(
"uploadtree");
1132 $this->uploadDao->shouldReceive(
'getUploadEntry')
1133 ->withArgs([$itemId,
"uploadtree"])
1134 ->andReturn([
'upload_fk' => (
string) $uploadId]);
1135 $this->dbHelper->shouldReceive(
'doesIdExist')
1136 ->withArgs([
"license_ref",
"rf_pk", $licenseId])->andReturn(
true);
1137 $this->licenseDao->shouldReceive(
'getLicenseByShortName')
1138 ->withArgs([$licenseShortName, $this->groupId])
1139 ->andReturn($existingLicense);
1140 $this->changeLicenseBulk->shouldReceive(
'handle')
1141 ->withArgs([M::any()])
1144 $info =
new Info(201, json_decode($res->getContent(),
true)[
"jqid"], InfoType::INFO);
1146 $reqBody = $this->streamFactory->createStream(json_encode(
1150 $requestHeaders =
new Headers();
1151 $requestHeaders->setHeader(
'Content-Type',
'application/json');
1152 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost"),
1153 $requestHeaders, [], [], $reqBody);
1155 $expectedResponse = (
new ResponseHelper())->withJson($info->getArray(), $info->getCode());
1156 $actualResponse = $this->uploadTreeController->scheduleBulkScan($request,
new ResponseHelper(), [
'id' => $uploadId,
'itemId' => $itemId]);
1158 $this->assertEquals($expectedResponse->getStatusCode(),
1159 $actualResponse->getStatusCode());
Contains the constants and helpers for authentication of user.
Utility functions to process ClearingDecision.
Wrapper class for license map.
Controller for UploadTree model.
Provides helper methods to access database for REST api.
Override Slim response for withJson function.
Provides various DAO helper functions for REST api.
Different type of infos provided by REST.
Info model to contain general error and return values.
testGetTreeViewAgentNotFound()
testHandleAddEditAndDeleteLicenseDecision_Delete()
testGetTreeViewUploadNotAccessible()
testGetNextPreviousItem()
$groupId
Setup test objects.
testGetLicenseDecisions()
testSetClearingDecisionReturnsError()
testViewLicenseFile($version, $tableName)
testViewLicenseFileRejectsInvalidItem($version, $tableName, $itemExists, $otherUploadAccessible)
$clearingDecisionEventProcessor
testHandleAddEditAndDeleteLicenseDecision_Add()
testGetTreeViewUploadNotFound()
getResponseJson($response)
testGetHighlightEntries()
testGetNextPreviousItem_isSelectionValid()
testSetClearingDecisionReturnsOk()
testGetTreeViewTagNotFound()
testViewLicenseFileRejectsInaccessibleUpload($version, $tableName)
testHandleAddEditAndDeleteLicenseDecision_Edit()
RepPathItem($Item, $Repo="files")
Given an uploadtree_pk, retrieve the pfile path.
fo_dbManager * dbManager
fo_dbManager object