14 if (!function_exists(
'RepPathItem')) {
17 return dirname(__DIR__) .
"/tests.xml";
61 use Psr\Http\Message\ServerRequestInterface;
62 use Slim\Psr7\Factory\StreamFactory;
63 use Slim\Psr7\Headers;
64 use Slim\Psr7\Request;
65 use Slim\Psr7\Response;
67 use Symfony\Component\HttpFoundation\JsonResponse;
133 private $streamFactory;
201 protected function setUp(): void
209 $container = M::mock(
'ContainerBuilder');
210 $this->dbHelper = M::mock(DbHelper::class);
211 $this->
dbManager = M::mock(DbManager::class);
212 $this->restHelper = M::mock(RestHelper::class);
213 $this->uploadDao = M::mock(UploadDao::class);
214 $this->decisionTypes = M::mock(DecisionTypes::class);
215 $this->licenseDao = M::mock(LicenseDao::class);
216 $this->clearingDecisionEventProcessor = M::mock(ClearingDecisionProcessor::class);
217 $this->viewFilePlugin = M::mock(
'ui_view');
218 $this->viewLicensePlugin = M::mock(ClearingView::class);
219 $this->clearingDao = M::mock(ClearingDao::class);
220 $this->decisionScopes = M::mock(DecisionScopes::class);
221 $this->highlightDao = M::mock(HighlightDao::class);
222 $this->clearingEventTypes = M::mock(ClearingEventTypes::class);
223 $this->itemTreeBoundsMock = M::mock(ItemTreeBounds::class);
224 $this->concludeLicensePlugin = M::mock(AjaxClearingView::class);
225 $this->licenseDao = M::mock(LicenseDao::class);
226 $this->changeLicenseBulk = M::mock(ChangeLicenseBulk::class);
227 $this->licenseDao = M::mock(LicenseDao::class);
229 $this->restHelper->shouldReceive(
'getPlugin')
230 ->withArgs(array(
'view'))->andReturn($this->viewFilePlugin);
231 $this->restHelper->shouldReceive(
'getPlugin')
232 ->withArgs(array(
'view-license'))->andReturn($this->viewLicensePlugin);
233 $this->restHelper->shouldReceive(
'getPlugin')
234 ->withArgs(array(
'conclude-license'))->andReturn($this->concludeLicensePlugin);
235 $this->restHelper->shouldReceive(
'getPlugin')
236 ->withArgs(array(
'change-license-bulk'))->andReturn($this->changeLicenseBulk);
238 $this->
dbManager->shouldReceive(
'getSingleRow')
239 ->withArgs([M::any(), [$this->groupId, UploadStatus::OPEN,
241 $this->dbHelper->shouldReceive(
'getDbManager')->andReturn($this->
dbManager);
242 $this->restHelper->shouldReceive(
'getDbHelper')->andReturn($this->dbHelper);
243 $this->restHelper->shouldReceive(
'getGroupId')->andReturn($this->groupId);
244 $this->restHelper->shouldReceive(
'getUserId')->andReturn($this->userId);
245 $this->restHelper->shouldReceive(
'getUploadDao')
246 ->andReturn($this->uploadDao);
247 $container->shouldReceive(
'get')->withArgs(array(
248 'helper.restHelper'))->andReturn($this->restHelper);
249 $container->shouldReceive(
'get')->withArgs([
'decision.types'])->andReturn($this->decisionTypes);
250 $container->shouldReceive(
'get')->withArgs([
'dao.clearing'])->andReturn($this->clearingDao);
251 $container->shouldReceive(
'get')->withArgs([
'dao.license'])->andReturn($this->licenseDao);
253 $container->shouldReceive(
'get')->withArgs([
'businessrules.clearing_decision_processor'])->andReturn($this->clearingDecisionEventProcessor);
254 $container->shouldReceive(
'get')->withArgs([
'dao.highlight'])->andReturn($this->highlightDao);
255 $container->shouldReceive(
'get')->withArgs([
'dao.license'])->andReturn($this->licenseDao);
257 $this->assertCountBefore = \Hamcrest\MatcherAssert::getCount();
258 $this->streamFactory =
new StreamFactory();
269 $response->getBody()->seek(0);
270 return json_decode($response->getBody()->getContents(),
true);
282 $expectedContent = file_get_contents(dirname(__DIR__) .
"/tests.xml");
284 $this->uploadDao->shouldReceive(
'isAccessible')
285 ->withArgs([$upload_pk, $this->groupId])->andReturn(
true);
286 $this->dbHelper->shouldReceive(
'doesIdExist')
287 ->withArgs([
"upload",
"upload_pk", $upload_pk])->andReturn(
true);
288 $this->uploadDao->shouldReceive(
"getUploadtreeTableName")->withArgs([$upload_pk])->andReturn(
"uploadtree");
289 $this->dbHelper->shouldReceive(
'doesIdExist')
290 ->withArgs([
"uploadtree",
"uploadtree_pk", $item_pk])->andReturn(
true);
292 $this->viewFilePlugin->shouldReceive(
'getText')->withArgs([M::any(), 0, 0, -1,
null,
false,
true])->andReturn($expectedContent);
295 $expectedResponse->getBody()->write($expectedContent);
296 $actualResponse = $this->uploadTreeController->viewLicenseFile(
null,
new ResponseHelper(), [
'id' => $upload_pk,
'itemId' => $item_pk]);
297 $this->assertEquals($expectedResponse->getStatusCode(), $actualResponse->getStatusCode());
298 $this->assertEquals($expectedResponse->getBody()->getContents(), $actualResponse->getBody()->getContents());
313 "globalDecision" =>
false,
315 $dummyDecisionTypes = array_map(
function ($i) {
319 $this->decisionTypes->shouldReceive(
'getMap')
320 ->andReturn($dummyDecisionTypes);
321 $this->uploadDao->shouldReceive(
"getUploadtreeTableName")->withArgs([$upload_pk])->andReturn(
"uploadtree");
322 $this->uploadDao->shouldReceive(
'isAccessible')
323 ->withArgs([$upload_pk, $this->groupId])->andReturn(
true);
324 $this->dbHelper->shouldReceive(
'doesIdExist')
325 ->withArgs([
"upload",
"upload_pk", $upload_pk])->andReturn(
true);
326 $this->dbHelper->shouldReceive(
'doesIdExist')
327 ->withArgs([
"uploadtree",
"uploadtree_pk", $item_pk])->andReturn(
true);
330 $this->viewLicensePlugin->shouldReceive(
'updateLastItem')->withArgs([2, 2, $item_pk, $item_pk]);
332 $info =
new Info(200,
"Successfully set decision", InfoType::INFO);
334 $expectedResponse = (
new ResponseHelper())->withJson($info->getArray(), $info->getCode());
335 $reqBody = $this->streamFactory->createStream(json_encode(
338 $requestHeaders =
new Headers();
339 $requestHeaders->setHeader(
'Content-Type',
'application/json');
340 $request =
new Request(
"PUT",
new Uri(
"HTTP",
"localhost"),
341 $requestHeaders, [], [], $reqBody);
342 $actualResponse = $this->uploadTreeController->setClearingDecision($request,
new ResponseHelper(), [
'id' => $upload_pk,
'itemId' => $item_pk]);
344 $this->assertEquals($expectedResponse->getStatusCode(),
345 $actualResponse->getStatusCode());
360 "decisionType" => 40,
361 "globalDecision" =>
false,
363 $dummyDecisionTypes = array_map(
function ($i) {
367 $this->decisionTypes->shouldReceive(
'getMap')
368 ->andReturn($dummyDecisionTypes);
369 $this->uploadDao->shouldReceive(
"getUploadtreeTableName")->withArgs([$upload_pk])->andReturn(
"uploadtree");
370 $this->uploadDao->shouldReceive(
'isAccessible')
371 ->withArgs([$upload_pk, $this->groupId])->andReturn(
true);
372 $this->dbHelper->shouldReceive(
'doesIdExist')
373 ->withArgs([
"upload",
"upload_pk", $upload_pk])->andReturn(
true);
374 $this->dbHelper->shouldReceive(
'doesIdExist')
375 ->withArgs([
"uploadtree",
"uploadtree_pk", $item_pk])->andReturn(
true);
377 $this->viewLicensePlugin->shouldReceive(
'updateLastItem')->withArgs([2, 2, $item_pk, $item_pk]);
379 $reqBody = $this->streamFactory->createStream(json_encode(
382 $requestHeaders =
new Headers();
383 $requestHeaders->setHeader(
'Content-Type',
'application/json');
384 $request =
new Request(
"PUT",
new Uri(
"HTTP",
"localhost"),
385 $requestHeaders, [], [], $reqBody);
386 $this->expectException(HttpBadRequestException::class);
388 $this->uploadTreeController->setClearingDecision($request,
389 new ResponseHelper(), [
'id' => $upload_pk,
'itemId' => $item_pk]);
402 $itemTreeBounds1 =
new ItemTreeBounds($nextItemId,
'uploadtree_a', $uploadId, 1, 2);
403 $itemTreeBounds2 =
new ItemTreeBounds($prevItemId,
'uploadtree_a', $uploadId, 1, 2);
405 $item1 =
new Item($itemTreeBounds1, 1, 1, 1,
"fileName");
406 $item2 =
new Item($itemTreeBounds2, 1, 1, 1,
"fileName");
409 "prevItemId" => $prevItemId,
410 "nextItemId" => $nextItemId
412 $options = array(
'skipThese' =>
"",
'groupId' => $this->groupId);
414 $this->uploadDao->shouldReceive(
'isAccessible')
415 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
416 $this->dbHelper->shouldReceive(
'doesIdExist')
417 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
418 $this->uploadDao->shouldReceive(
'getUploadtreeTableName')->withArgs([$uploadId])->andReturn(
"uploadtree");
419 $this->dbHelper->shouldReceive(
'doesIdExist')
420 ->withArgs([
"uploadtree",
"uploadtree_pk", $itemId])->andReturn(
true);
422 $this->uploadDao->shouldReceive(
'getNextItem')->withArgs([$uploadId, $itemId, $options])->andReturn($item1);
423 $this->uploadDao->shouldReceive(
'getPreviousItem')->withArgs([$uploadId, $itemId, $options])->andReturn($item2);
424 $expectedResponse = (
new ResponseHelper())->withJson($result, 200);
425 $queryParams = [
'selection' =>
null];
426 $request = $this->getMockBuilder(ServerRequestInterface::class)
428 $request->expects($this->any())
429 ->method(
'getQueryParams')
430 ->willReturn($queryParams);
432 $actualResponse = $this->uploadTreeController->getNextPreviousItem($request,
new ResponseHelper(), [
'id' => $uploadId,
'itemId' => $itemId]);
433 $this->assertEquals($expectedResponse->getStatusCode(), $actualResponse->getStatusCode());
448 $itemTreeBounds1 =
new ItemTreeBounds($nextItemId,
'uploadtree_a', $uploadId, 1, 2);
449 $itemTreeBounds2 =
new ItemTreeBounds($prevItemId,
'uploadtree_a', $uploadId, 1, 2);
451 $item1 =
new Item($itemTreeBounds1, 1, 1, 1,
"fileName");
452 $item2 =
new Item($itemTreeBounds2, 1, 1, 1,
"fileName");
454 $options = array(
'skipThese' =>
"",
'groupId' => $this->groupId);
456 $this->uploadDao->shouldReceive(
'isAccessible')
457 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
458 $this->dbHelper->shouldReceive(
'doesIdExist')
459 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
460 $this->uploadDao->shouldReceive(
'getUploadtreeTableName')->withArgs([$uploadId])->andReturn(
"uploadtree");
461 $this->dbHelper->shouldReceive(
'doesIdExist')
462 ->withArgs([
"uploadtree",
"uploadtree_pk", $itemId])->andReturn(
true);
464 $this->uploadDao->shouldReceive(
'getNextItem')->withArgs([$uploadId, $itemId, $options])->andReturn($item1);
465 $this->uploadDao->shouldReceive(
'getPreviousItem')->withArgs([$uploadId, $itemId, $options])->andReturn($item2);
467 $queryParams = [
'selection' =>
"invalidSelection"];
468 $request = $this->getMockBuilder(ServerRequestInterface::class)
470 $request->expects($this->any())
471 ->method(
'getQueryParams')
472 ->willReturn($queryParams);
473 $this->expectException(HttpBadRequestException::class);
475 $this->uploadTreeController->getNextPreviousItem($request,
488 $itemTreeBounds =
new ItemTreeBounds($itemId,
'uploadtree', $uploadId, 1, 2);
496 "addedLicenses" => [],
497 "removedLicenses" => [],
500 $obj =
new BulkHistory(1, 1,
"test",
true,
true, [], []);
501 $updatedRes[] = $obj->getArray();
503 $this->uploadDao->shouldReceive(
'isAccessible')
504 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
505 $this->dbHelper->shouldReceive(
'doesIdExist')
506 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
508 $this->uploadDao->shouldReceive(
'getUploadtreeTableName')->withArgs([$uploadId])->andReturn(
"uploadtree");
509 $this->dbHelper->shouldReceive(
'doesIdExist')
510 ->withArgs([
"uploadtree",
"uploadtree_pk", $itemId])->andReturn(
true);
512 $this->uploadDao->shouldReceive(
"getItemTreeBounds")
513 ->withArgs([$itemId,
"uploadtree"])->andReturn($itemTreeBounds);
515 $this->clearingDao->shouldReceive(
"getBulkHistory")
516 ->withArgs([$itemTreeBounds, $this->groupId])->andReturn($res);
517 $expectedResponse = (
new ResponseHelper())->withJson($updatedRes, 200);
518 $actualResponse = $this->uploadTreeController->getBulkHistory(
null,
new ResponseHelper(), [
'id' => $uploadId,
'itemId' => $itemId]);
519 $this->assertEquals($expectedResponse->getStatusCode(), $actualResponse->getStatusCode());
532 $itemTreeBounds =
new ItemTreeBounds($itemId,
'uploadtree_a', $uploadId, 1, 2);
533 $fileClearings[] =
new ClearingDecision(1, 1, $itemId, 1, 1, 1, 3, 1, 1, [], 1, 1, 1);
542 $result[] = $obj->getArray();
544 $this->uploadDao->shouldReceive(
'isAccessible')
545 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
546 $this->dbHelper->shouldReceive(
'doesIdExist')
547 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
549 $this->uploadDao->shouldReceive(
'getUploadtreeTableName')->withArgs([$uploadId])->andReturn(
"uploadtree");
550 $this->dbHelper->shouldReceive(
'doesIdExist')
551 ->withArgs([
"uploadtree",
"uploadtree_pk", $itemId])->andReturn(
true);
553 $this->uploadDao->shouldReceive(
"getItemTreeBoundsFromUploadId")
554 ->withArgs([$itemId, $uploadId])->andReturn($itemTreeBounds);
555 $this->clearingDao->shouldReceive(
"getFileClearings")
556 ->withArgs([$itemTreeBounds, $this->groupId,
false,
true])->andReturn($fileClearings);
557 $this->decisionTypes->shouldReceive(
"getTypeName")
558 ->withArgs([$fileClearings[0]->getType()])->andReturn(
"test");
559 $this->decisionScopes->shouldReceive(
"getTypeName")->withArgs([$fileClearings[0]->getScope()])->andReturn(
"test");
560 $this->decisionTypes->shouldReceive(
"getConstantNameFromKey")
561 ->withArgs([$fileClearings[0]->getType()])->andReturn(
"TO_BE_DISCUSSED");
562 $expectedResponse = (
new ResponseHelper())->withJson($result, 200);
563 $actualResponse = $this->uploadTreeController->getClearingHistory(
null,
new ResponseHelper(), [
'id' => $uploadId,
'itemId' => $itemId]);
564 $this->assertEquals($expectedResponse->getStatusCode(), $actualResponse->getStatusCode());
584 "infoText" =>
"MIT: 'MIT License\n\nCopyright (c) <year> <copyright holders>'",
585 "htmlElement" =>
null
588 $highlight =
new Highlight($res[0][
"start"], $res[0][
"end"], $res[0][
"type"], $res[0][
"refStart"], $res[0][
"refEnd"], $res[0][
"infoText"]);
589 $itemTreeBounds =
new ItemTreeBounds($itemId,
'uploadtree', $uploadId, 1, 2);
591 $this->uploadDao->shouldReceive(
'isAccessible')
592 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
593 $this->dbHelper->shouldReceive(
'doesIdExist')
594 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
595 $this->uploadDao->shouldReceive(
"getUploadtreeTableName")->withArgs([$uploadId])->andReturn(
"uploadtree");
596 $this->dbHelper->shouldReceive(
'doesIdExist')
597 ->withArgs([
"uploadtree",
"uploadtree_pk", $itemId])->andReturn(
true);
598 $this->uploadDao->shouldReceive(
"getItemTreeBounds")->withArgs([$itemId,
"uploadtree"])->andReturn($itemTreeBounds);
599 $this->viewLicensePlugin->shouldReceive(
'getSelectedHighlighting')->withArgs([$itemTreeBounds,
null,
null,
null,
null, $uploadId])->andReturn([$highlight]);
602 $queryParams = [
'clearingId' =>
null,
'agentId' =>
null,
'highlightId' =>
null,
'licenseId' =>
null];
603 $request = $this->getMockBuilder(ServerRequestInterface::class)
605 $request->expects($this->any())
606 ->method(
'getQueryParams')
607 ->willReturn($queryParams);
609 $actualResponse = $this->uploadTreeController->getHighlightEntries($request,
new ResponseHelper(), [
'id' => $uploadId,
'itemId' => $itemId]);
610 $this->assertEquals($expectedResponse->getStatusCode(), $actualResponse->getStatusCode());
623 $this->dbHelper->shouldReceive(
'doesIdExist')
624 ->withArgs([
"upload",
"upload_pk", $this->uploadId])->andReturn(
false);
627 $reqBody = $this->streamFactory->createStream();
628 $requestHeaders =
new Headers();
631 "agentId" => $this->agentId,
635 $uri = (
new Uri(
'HTTP',
'localhost'))
636 ->withQuery(http_build_query($queryParams));
638 $requestHeaders->setHeader(
'Content-Type',
'application/json');
639 $request =
new Request(
"POST", $uri,
640 $requestHeaders, [], [], $reqBody);
642 $this->expectException(HttpNotFoundException::class);
643 $this->uploadTreeController->getTreeView($request,
new ResponseHelper(), [
"id" => $this->uploadId,
"itemId"=> 10]);
657 $this->dbHelper->shouldReceive(
'doesIdExist')
658 ->withArgs([
"upload",
"upload_pk", $this->uploadId])->andReturn(
false);
659 $this->dbHelper->shouldReceive(
'doesIdExist')
660 ->withArgs([
"agent",
"agent_pk", $this->agentId])->andReturn(
false);
661 $this->uploadDao->shouldReceive(
'isAccessible')
662 ->withArgs([$this->uploadId, $this->groupId])->andReturn(
true);
664 $reqBody = $this->streamFactory->createStream();
665 $requestHeaders =
new Headers();
668 "agentId" => $this->agentId,
672 $uri = (
new Uri(
'HTTP',
'localhost'))
673 ->withQuery(http_build_query($queryParams));
675 $requestHeaders->setHeader(
'Content-Type',
'application/json');
676 $request =
new Request(
"POST", $uri,
677 $requestHeaders, [], [], $reqBody);
679 $this->expectException(HttpNotFoundException::class);
680 $this->uploadTreeController->getTreeView($request,
new ResponseHelper(), [
"id" => $this->uploadId,
"itemId"=> 10]);
694 $this->dbHelper->shouldReceive(
'doesIdExist')
695 ->withArgs([
"upload",
"upload_pk", $this->uploadId])->andReturn(
false);
696 $this->dbHelper->shouldReceive(
'doesIdExist')
697 ->withArgs([
"tag",
"tag_pk", $this->tagId])->andReturn(
false);
698 $this->uploadDao->shouldReceive(
'isAccessible')
699 ->withArgs([$this->uploadId, $this->groupId])->andReturn(
true);
701 $reqBody = $this->streamFactory->createStream();
702 $requestHeaders =
new Headers();
705 "agentId" => $this->agentId,
709 $uri = (
new Uri(
'HTTP',
'localhost'))
710 ->withQuery(http_build_query($queryParams));
712 $requestHeaders->setHeader(
'Content-Type',
'application/json');
713 $request =
new Request(
"POST", $uri,
714 $requestHeaders, [], [], $reqBody);
716 $this->expectException(HttpNotFoundException::class);
717 $this->uploadTreeController->getTreeView($request,
new ResponseHelper(), [
"id" => $this->uploadId,
"itemId"=> 10]);
731 $this->dbHelper->shouldReceive(
'doesIdExist')
732 ->withArgs([
"upload",
"upload_pk", $this->uploadId])->andReturn(
true);
733 $this->uploadDao->shouldReceive(
'isAccessible')
734 ->withArgs([$this->uploadId, $this->groupId])->andReturn(
false);
736 $reqBody = $this->streamFactory->createStream();
737 $requestHeaders =
new Headers();
740 "agentId" => $this->agentId,
744 $uri = (
new Uri(
'HTTP',
'localhost'))
745 ->withQuery(http_build_query($queryParams));
746 $requestHeaders->setHeader(
'Content-Type',
'application/json');
747 $request =
new Request(
"POST", $uri,
748 $requestHeaders, [], [], $reqBody);
749 $this->expectException(HttpForbiddenException::class);
750 $this->uploadTreeController->getTreeView($request,
new ResponseHelper(), [
"id" => $this->uploadId,
"itemId"=> 10]);
768 $itemTreeBounds =
new ItemTreeBounds($itemId,
'uploadtree_a', $uploadId, 0, 1);
769 $addedClearingResults = [];
772 'name' =>
'Imported decision',
773 'clearingId' =>
null,
775 'highlightId' =>
null,
780 $license =
new License($licenseId,
"MIT",
"MIT License",
"text",
"url", [],
782 $licenseDecision =
new LicenseDecision($licenseId,
"MIT",
"MIT License",
'text',
"url", array($result),
783 '',
'',
false, [],
null,
false);
785 $licenseRef =
new LicenseRef($licenseId,
"MIT",
"MIT LICENSE",
"spx");
786 $clearingEvent =
new ClearingEvent(1, $itemId, 12, $this->userId, $this->groupId, 4,
new ClearingLicense($licenseRef,
false,
"",
"",
"",
""));
788 $addedClearingResults[$licenseId] = $licenseDecisionResult;
790 $this->uploadDao->shouldReceive(
'isAccessible')
791 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
792 $this->dbHelper->shouldReceive(
'doesIdExist')
793 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
795 $this->uploadDao->shouldReceive(
'getUploadtreeTableName')->withArgs([$uploadId])->andReturn(
"uploadtree");
796 $this->dbHelper->shouldReceive(
'doesIdExist')
797 ->withArgs([
"uploadtree",
"uploadtree_pk", $itemId])->andReturn(
true);
799 $this->uploadDao->shouldReceive(
"getItemTreeBoundsFromUploadId")->withArgs([$itemId, $uploadId])->andReturn($itemTreeBounds);
800 $this->itemTreeBoundsMock->shouldReceive(
"containsFiles")->andReturn(
false);
801 $this->clearingDao->shouldReceive(
'getMainLicenseIds')->andReturn([]);
802 $this->clearingEventTypes->shouldReceive(
'getTypeName')->withArgs([$clearingEvent->getEventType()])->andReturn($result[
'name']);
803 $this->highlightDao->shouldReceive(
'getHighlightRegion')->withArgs([1])->andReturn([
""]);
804 $this->clearingDecisionEventProcessor->shouldReceive(
"getCurrentClearings")->withArgs([$itemTreeBounds, $this->groupId, LicenseMap::CONCLUSION])->andReturn([$addedClearingResults, []]);
805 $this->licenseDao->shouldReceive(
'getLicenseObligations')->withArgs([[$licenseId],
false])->andReturn([]);
806 $this->licenseDao->shouldReceive(
'getLicenseObligations')->withArgs([[$licenseId],
true])->andReturn([]);
807 $this->licenseDao->shouldReceive(
'getLicenseById')->withArgs([$licenseId])->andReturn($license);
808 $licenses[] = $licenseDecision->getArray();
810 $expectedResponse = (
new ResponseHelper())->withJson($licenses, 200);
811 $actualResponse = $this->uploadTreeController->getLicenseDecisions(
null,
new ResponseHelper(), [
'id' => $uploadId,
'itemId' => $itemId]);
812 $this->assertEquals($expectedResponse->getStatusCode(), $actualResponse->getStatusCode());
827 $license =
new License($licenseId,
"MIT",
"MIT License",
"risk",
"texts", [],
829 $itemTreeBounds =
new ItemTreeBounds($itemId,
'uploadtree_a', $uploadId, 1, 2);
832 "shortName" =>
"MIT",
837 $existingLicenses = array([
'DT_RowId' =>
"$itemId,400",
'DT_RowClass' =>
'removed']);
839 $this->uploadDao->shouldReceive(
'isAccessible')
840 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
841 $this->dbHelper->shouldReceive(
'doesIdExist')
842 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
843 $this->uploadDao->shouldReceive(
"getUploadtreeTableName")->withArgs([$uploadId])->andReturn(
"uploadtree");
844 $this->dbHelper->shouldReceive(
'doesIdExist')
845 ->withArgs([
"uploadtree",
"uploadtree_pk", $itemId])->andReturn(
true);
846 $this->uploadDao->shouldReceive(
'getItemTreeBoundsFromUploadId')->withArgs([$itemId, $uploadId])->andReturn($itemTreeBounds);
847 $this->concludeLicensePlugin->shouldReceive(
'getCurrentSelectedLicensesTableData')->withArgs([$itemTreeBounds, $this->groupId,
true])->andReturn($existingLicenses);
848 $this->licenseDao->shouldReceive(
'getLicenseByShortName')
849 ->withArgs([$shortName, $this->groupId])->andReturn($license);
850 $this->clearingDao->shouldReceive(
'insertClearingEvent')
851 ->withArgs([$itemId, $this->userId, $this->groupId, $licenseId,
false])->andReturn(
null);
853 $info =
new Info(200,
'Successfully added MIT as a new license decision.', InfoType::INFO);
855 'success' => [$info->getArray()],
859 $reqBody = $this->streamFactory->createStream(json_encode(
862 $requestHeaders =
new Headers();
863 $requestHeaders->setHeader(
'Content-Type',
'application/json');
864 $request =
new Request(
"PUT",
new Uri(
"HTTP",
"localhost"),
865 $requestHeaders, [], [], $reqBody);
866 $actualResponse = $this->uploadTreeController->handleAddEditAndDeleteLicenseDecision($request,
new ResponseHelper(), [
'id' => $uploadId,
'itemId' => $itemId]);
868 $this->assertEquals($expectedResponse->getStatusCode(),
869 $actualResponse->getStatusCode());
885 $license =
new License($licenseId,
"MIT",
"MIT License",
"risk",
"texts", [],
887 $itemTreeBounds =
new ItemTreeBounds($itemId,
'uploadtree_a', $uploadId, 1, 2);
890 "shortName" =>
"MIT",
892 "text" =>
"Updated license text",
896 $existingLicenses = array([
'DT_RowId' =>
"$itemId,$licenseId",
'DT_RowClass' =>
'removed']);
898 $this->uploadDao->shouldReceive(
'isAccessible')
899 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
900 $this->dbHelper->shouldReceive(
'doesIdExist')
901 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
902 $this->uploadDao->shouldReceive(
"getUploadtreeTableName")->withArgs([$uploadId])->andReturn(
"uploadtree");
903 $this->dbHelper->shouldReceive(
'doesIdExist')
904 ->withArgs([
"uploadtree",
"uploadtree_pk", $itemId])->andReturn(
true);
905 $this->uploadDao->shouldReceive(
'getItemTreeBoundsFromUploadId')->withArgs([$itemId, $uploadId])->andReturn($itemTreeBounds);
906 $this->concludeLicensePlugin->shouldReceive(
'getCurrentSelectedLicensesTableData')->withArgs([$itemTreeBounds, $this->groupId,
true])->andReturn($existingLicenses);
907 $this->licenseDao->shouldReceive(
'getLicenseByShortName')
908 ->withArgs([$shortName, $this->groupId])->andReturn($license);
909 $this->clearingDao->shouldReceive(
'updateClearingEvent')
910 ->withArgs([$itemId, $this->userId, $this->groupId, $licenseId,
'reportinfo',
"Updated license text"])->andReturn(
null);
912 $info =
new Info(200,
"Successfully updated MIT's license reportinfo", InfoType::INFO);
914 'success' => [$info->getArray()],
918 $reqBody = $this->streamFactory->createStream(json_encode(
921 $requestHeaders =
new Headers();
922 $requestHeaders->setHeader(
'Content-Type',
'application/json');
923 $request =
new Request(
"PUT",
new Uri(
"HTTP",
"localhost"),
924 $requestHeaders, [], [], $reqBody);
925 $actualResponse = $this->uploadTreeController->handleAddEditAndDeleteLicenseDecision($request,
new ResponseHelper(), [
'id' => $uploadId,
'itemId' => $itemId]);
927 $this->assertEquals($expectedResponse->getStatusCode(),
928 $actualResponse->getStatusCode());
944 $license =
new License($licenseId,
"MIT",
"MIT License",
"risk",
"texts", [],
946 $itemTreeBounds =
new ItemTreeBounds($itemId,
'uploadtree_a', $uploadId, 1, 2);
949 "shortName" =>
"MIT",
951 "text" =>
"Updated license text",
955 $existingLicenses = array([
'DT_RowId' =>
"$itemId,$licenseId",
'DT_RowClass' =>
'removed']);
957 $this->uploadDao->shouldReceive(
'isAccessible')
958 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
959 $this->dbHelper->shouldReceive(
'doesIdExist')
960 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
961 $this->uploadDao->shouldReceive(
"getUploadtreeTableName")->withArgs([$uploadId])->andReturn(
"uploadtree");
962 $this->dbHelper->shouldReceive(
'doesIdExist')
963 ->withArgs([
"uploadtree",
"uploadtree_pk", $itemId])->andReturn(
true);
964 $this->uploadDao->shouldReceive(
'getItemTreeBoundsFromUploadId')->withArgs([$itemId, $uploadId])->andReturn($itemTreeBounds);
965 $this->concludeLicensePlugin->shouldReceive(
'getCurrentSelectedLicensesTableData')->withArgs([$itemTreeBounds, $this->groupId,
true])->andReturn($existingLicenses);
966 $this->licenseDao->shouldReceive(
'getLicenseByShortName')
967 ->withArgs([$shortName, $this->groupId])->andReturn($license);
968 $this->clearingDao->shouldReceive(
'insertClearingEvent')
969 ->withArgs([$itemId, $this->userId, $this->groupId, $licenseId,
true])->andReturn(
null);
971 $info =
new Info(200,
'Successfully deleted MIT from license decision list.', InfoType::INFO);
973 'success' => [$info->getArray()],
977 $reqBody = $this->streamFactory->createStream(json_encode(
980 $requestHeaders =
new Headers();
981 $requestHeaders->setHeader(
'Content-Type',
'application/json');
982 $request =
new Request(
"PUT",
new Uri(
"HTTP",
"localhost"),
983 $requestHeaders, [], [], $reqBody);
984 $actualResponse = $this->uploadTreeController->handleAddEditAndDeleteLicenseDecision($request,
new ResponseHelper(), [
'id' => $uploadId,
'itemId' => $itemId]);
986 $this->assertEquals($expectedResponse->getStatusCode(),
987 $actualResponse->getStatusCode());
1000 $licenseShortName =
"MIT";
1001 $existingLicense =
new License( $licenseId, $licenseShortName,
"FULL NAME",
"text",
"url", [],
"1");
1005 'licenseShortName' => $licenseShortName,
1006 'licenseText' =>
'',
1007 'acknowledgement' =>
'',
1009 'licenseAction' =>
'ADD'
1012 'refText' =>
'Copyright (c) 2011-2023 The Bootstrap Authors',
1013 'bulkScope' =>
'folder',
1014 'forceDecision' => 0,
1016 'delimiters' =>
'DEFAULT',
1017 'scanOnlyFindings' => 0
1020 $res =
new JsonResponse(array(
"jqid" => $jobId));
1025 $this->uploadDao->shouldReceive(
'isAccessible')
1026 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
1027 $this->dbHelper->shouldReceive(
'doesIdExist')
1028 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1029 $this->uploadDao->shouldReceive(
'getUploadtreeTableName')->withArgs([$uploadId])->andReturn(
"uploadtree");
1030 $this->dbHelper->shouldReceive(
'doesIdExist')
1031 ->withArgs([
"uploadtree",
"uploadtree_pk", $itemId])->andReturn(
true);
1032 $this->dbHelper->shouldReceive(
'doesIdExist')
1033 ->withArgs([
"license_ref",
"rf_pk", $licenseId])->andReturn(
true);
1034 $this->licenseDao->shouldReceive(
'getLicenseByShortName')
1035 ->withArgs([$licenseShortName, $this->groupId])
1036 ->andReturn($existingLicense);
1037 $this->changeLicenseBulk->shouldReceive(
'handle')
1038 ->withArgs([M::any()])
1041 $info =
new Info(201, json_decode($res->getContent(),
true)[
"jqid"], InfoType::INFO);
1043 $reqBody = $this->streamFactory->createStream(json_encode(
1047 $requestHeaders =
new Headers();
1048 $requestHeaders->setHeader(
'Content-Type',
'application/json');
1049 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost"),
1050 $requestHeaders, [], [], $reqBody);
1052 $expectedResponse = (
new ResponseHelper())->withJson($info->getArray(), $info->getCode());
1053 $actualResponse = $this->uploadTreeController->scheduleBulkScan($request,
new ResponseHelper(), [
'id' => $uploadId,
'itemId' => $itemId]);
1055 $this->assertEquals($expectedResponse->getStatusCode(),
1056 $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()
$clearingDecisionEventProcessor
testHandleAddEditAndDeleteLicenseDecision_Add()
testGetTreeViewUploadNotFound()
getResponseJson($response)
testGetHighlightEntries()
testGetNextPreviousItem_isSelectionValid()
testSetClearingDecisionReturnsOk()
testGetTreeViewTagNotFound()
testHandleAddEditAndDeleteLicenseDecision_Edit()
RepPathItem($Item, $Repo="files")
Given an uploadtree_pk, retrieve the pfile path.
fo_dbManager * dbManager
fo_dbManager object