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;
134 private $streamFactory;
202 protected function setUp(): void
210 $container = M::mock(
'ContainerBuilder');
211 $this->dbHelper = M::mock(DbHelper::class);
212 $this->
dbManager = M::mock(DbManager::class);
213 $this->restHelper = M::mock(RestHelper::class);
214 $this->uploadDao = M::mock(UploadDao::class);
215 $this->decisionTypes = M::mock(DecisionTypes::class);
216 $this->licenseDao = M::mock(LicenseDao::class);
217 $this->clearingDecisionEventProcessor = M::mock(ClearingDecisionProcessor::class);
218 $this->viewFilePlugin = M::mock(
'ui_view');
219 $this->viewLicensePlugin = M::mock(ClearingView::class);
220 $this->clearingDao = M::mock(ClearingDao::class);
221 $this->decisionScopes = M::mock(DecisionScopes::class);
222 $this->highlightDao = M::mock(HighlightDao::class);
223 $this->clearingEventTypes = M::mock(ClearingEventTypes::class);
224 $this->itemTreeBoundsMock = M::mock(ItemTreeBounds::class);
225 $this->concludeLicensePlugin = M::mock(AjaxClearingView::class);
226 $this->licenseDao = M::mock(LicenseDao::class);
227 $this->changeLicenseBulk = M::mock(ChangeLicenseBulk::class);
228 $this->licenseDao = M::mock(LicenseDao::class);
230 $this->restHelper->shouldReceive(
'getPlugin')
231 ->withArgs(array(
'view'))->andReturn($this->viewFilePlugin);
232 $this->restHelper->shouldReceive(
'getPlugin')
233 ->withArgs(array(
'view-license'))->andReturn($this->viewLicensePlugin);
234 $this->restHelper->shouldReceive(
'getPlugin')
235 ->withArgs(array(
'conclude-license'))->andReturn($this->concludeLicensePlugin);
236 $this->restHelper->shouldReceive(
'getPlugin')
237 ->withArgs(array(
'change-license-bulk'))->andReturn($this->changeLicenseBulk);
239 $this->
dbManager->shouldReceive(
'getSingleRow')
240 ->withArgs([M::any(), [$this->groupId, UploadStatus::OPEN,
242 $this->dbHelper->shouldReceive(
'getDbManager')->andReturn($this->
dbManager);
243 $this->restHelper->shouldReceive(
'getDbHelper')->andReturn($this->dbHelper);
244 $this->restHelper->shouldReceive(
'getGroupId')->andReturn($this->groupId);
245 $this->restHelper->shouldReceive(
'getUserId')->andReturn($this->userId);
246 $this->restHelper->shouldReceive(
'getUploadDao')
247 ->andReturn($this->uploadDao);
248 $container->shouldReceive(
'get')->withArgs(array(
249 'helper.restHelper'))->andReturn($this->restHelper);
250 $container->shouldReceive(
'get')->withArgs([
'decision.types'])->andReturn($this->decisionTypes);
251 $container->shouldReceive(
'get')->withArgs([
'dao.clearing'])->andReturn($this->clearingDao);
252 $container->shouldReceive(
'get')->withArgs([
'dao.license'])->andReturn($this->licenseDao);
254 $container->shouldReceive(
'get')->withArgs([
'businessrules.clearing_decision_processor'])->andReturn($this->clearingDecisionEventProcessor);
255 $container->shouldReceive(
'get')->withArgs([
'dao.highlight'])->andReturn($this->highlightDao);
256 $container->shouldReceive(
'get')->withArgs([
'dao.license'])->andReturn($this->licenseDao);
258 $this->assertCountBefore = \Hamcrest\MatcherAssert::getCount();
259 $this->streamFactory =
new StreamFactory();
270 $response->getBody()->seek(0);
271 return json_decode($response->getBody()->getContents(),
true);
284 $expectedContent = file_get_contents(dirname(__DIR__) .
"/tests.xml");
286 $this->uploadDao->shouldReceive(
'isAccessible')
287 ->withArgs([$upload_pk, $this->groupId])->andReturn(
true);
288 $this->dbHelper->shouldReceive(
'doesIdExist')
289 ->withArgs([
"upload",
"upload_pk", $upload_pk])->andReturn(
true);
290 $this->uploadDao->shouldReceive(
"getUploadtreeTableName")
291 ->withArgs([$upload_pk])->andReturn($tableName);
292 $this->uploadDao->shouldReceive(
'getUploadEntry')
293 ->withArgs([$item_pk, $tableName])->once()
294 ->andReturn([
'upload_fk' => (
string) $upload_pk]);
296 $this->viewFilePlugin->shouldReceive(
'getText')->withArgs([M::any(), 0, 0, -1,
null,
false,
true])->andReturn($expectedContent);
299 $expectedResponse->getBody()->write($expectedContent);
300 $request = (
new Request(
'GET',
new Uri(
'http',
'localhost'),
301 new Headers(), [], [], $this->streamFactory->createStream()))
302 ->withAttribute(ApiVersion::ATTRIBUTE_NAME, $version);
303 $actualResponse = $this->uploadTreeController->viewLicenseFile($request,
304 new ResponseHelper(), [
'id' => $upload_pk,
'itemId' => $item_pk]);
305 $this->assertEquals($expectedResponse->getStatusCode(), $actualResponse->getStatusCode());
306 $this->assertEquals($expectedResponse->getBody()->getContents(), $actualResponse->getBody()->getContents());
309 public function itemTableProvider(): array
312 foreach ([ApiVersion::V1, ApiVersion::V2] as $version) {
313 foreach ([
'uploadtree',
'uploadtree_a',
'uploadtree_1'] as $tableName) {
314 $cases[
"v$version $tableName"] = [$version, $tableName];
325 $this->dbHelper->shouldReceive(
'doesIdExist')
326 ->with(
'upload',
'upload_pk', 1)->andReturn(
true);
327 $this->uploadDao->shouldReceive(
'isAccessible')
328 ->with(1, $this->groupId)->andReturn(
false);
329 $this->uploadDao->shouldReceive(
'getUploadtreeTableName')
330 ->with(1)->andReturn($tableName);
331 $this->uploadDao->shouldNotReceive(
'getUploadEntry');
332 $this->viewFilePlugin->shouldNotReceive(
'getText');
334 $request = (
new Request(
'GET',
new Uri(
'http',
'localhost'),
335 new Headers(), [], [], $this->streamFactory->createStream()))
336 ->withAttribute(ApiVersion::ATTRIBUTE_NAME, $version);
337 $this->expectException(HttpForbiddenException::class);
338 $this->expectExceptionCode(403);
339 $this->uploadTreeController->viewLicenseFile($request,
new ResponseHelper(),
340 [
'id' => 1,
'itemId' => 200]);
347 $itemExists, $otherUploadAccessible)
351 $this->dbHelper->shouldReceive(
'doesIdExist')
352 ->with(
'upload',
'upload_pk', $uploadId)->andReturn(
true);
353 $this->uploadDao->shouldReceive(
'isAccessible')
354 ->with($uploadId, $this->groupId)->andReturn(
true);
355 $this->uploadDao->shouldReceive(
'isAccessible')
356 ->with(2, $this->groupId)->andReturn($otherUploadAccessible);
357 $this->uploadDao->shouldReceive(
'getUploadtreeTableName')
358 ->with($uploadId)->andReturn($tableName);
359 $this->uploadDao->shouldReceive(
'getUploadEntry')
360 ->with($itemId, $tableName)->once()
361 ->andReturn($itemExists ? [
'upload_fk' =>
'2'] :
false);
362 $this->viewFilePlugin->shouldNotReceive(
'getText');
364 $request = (
new Request(
'GET',
new Uri(
'http',
'localhost'),
365 new Headers(), [], [], $this->streamFactory->createStream()))
366 ->withAttribute(ApiVersion::ATTRIBUTE_NAME, $version);
367 $this->expectException(HttpNotFoundException::class);
368 $this->expectExceptionCode(404);
369 $this->uploadTreeController->viewLicenseFile($request,
new ResponseHelper(),
370 [
'id' => $uploadId,
'itemId' => $itemId]);
373 public function invalidItemProvider(): array
376 foreach ([ApiVersion::V1, ApiVersion::V2] as $version) {
377 foreach ([
'uploadtree',
'uploadtree_a',
'uploadtree_1'] as $tableName) {
378 $cases[
"v$version $tableName inaccessible foreign item"] =
379 [$version, $tableName,
true,
false];
380 $cases[
"v$version $tableName accessible foreign item"] =
381 [$version, $tableName,
true,
true];
382 $cases[
"v$version $tableName missing item"] =
383 [$version, $tableName,
false,
false];
400 "globalDecision" =>
false,
402 $dummyDecisionTypes = array_map(
function ($i) {
406 $this->decisionTypes->shouldReceive(
'getMap')
407 ->andReturn($dummyDecisionTypes);
408 $this->uploadDao->shouldReceive(
"getUploadtreeTableName")->withArgs([$upload_pk])->andReturn(
"uploadtree");
409 $this->uploadDao->shouldReceive(
'isAccessible')
410 ->withArgs([$upload_pk, $this->groupId])->andReturn(
true);
411 $this->dbHelper->shouldReceive(
'doesIdExist')
412 ->withArgs([
"upload",
"upload_pk", $upload_pk])->andReturn(
true);
413 $this->uploadDao->shouldReceive(
'getUploadEntry')
414 ->withArgs([$item_pk,
"uploadtree"])
415 ->andReturn([
'upload_fk' => (
string) $upload_pk]);
418 $this->viewLicensePlugin->shouldReceive(
'updateLastItem')->withArgs([2, 2, $item_pk, $item_pk]);
420 $info =
new Info(200,
"Successfully set decision", InfoType::INFO);
422 $expectedResponse = (
new ResponseHelper())->withJson($info->getArray(), $info->getCode());
423 $reqBody = $this->streamFactory->createStream(json_encode(
426 $requestHeaders =
new Headers();
427 $requestHeaders->setHeader(
'Content-Type',
'application/json');
428 $request =
new Request(
"PUT",
new Uri(
"HTTP",
"localhost"),
429 $requestHeaders, [], [], $reqBody);
430 $actualResponse = $this->uploadTreeController->setClearingDecision($request,
new ResponseHelper(), [
'id' => $upload_pk,
'itemId' => $item_pk]);
432 $this->assertEquals($expectedResponse->getStatusCode(),
433 $actualResponse->getStatusCode());
448 "decisionType" => 40,
449 "globalDecision" =>
false,
451 $dummyDecisionTypes = array_map(
function ($i) {
455 $this->decisionTypes->shouldReceive(
'getMap')
456 ->andReturn($dummyDecisionTypes);
457 $this->uploadDao->shouldReceive(
"getUploadtreeTableName")->withArgs([$upload_pk])->andReturn(
"uploadtree");
458 $this->uploadDao->shouldReceive(
'isAccessible')
459 ->withArgs([$upload_pk, $this->groupId])->andReturn(
true);
460 $this->dbHelper->shouldReceive(
'doesIdExist')
461 ->withArgs([
"upload",
"upload_pk", $upload_pk])->andReturn(
true);
462 $this->uploadDao->shouldReceive(
'getUploadEntry')
463 ->withArgs([$item_pk,
"uploadtree"])
464 ->andReturn([
'upload_fk' => (
string) $upload_pk]);
466 $this->viewLicensePlugin->shouldReceive(
'updateLastItem')->withArgs([2, 2, $item_pk, $item_pk]);
468 $reqBody = $this->streamFactory->createStream(json_encode(
471 $requestHeaders =
new Headers();
472 $requestHeaders->setHeader(
'Content-Type',
'application/json');
473 $request =
new Request(
"PUT",
new Uri(
"HTTP",
"localhost"),
474 $requestHeaders, [], [], $reqBody);
475 $this->expectException(HttpBadRequestException::class);
477 $this->uploadTreeController->setClearingDecision($request,
478 new ResponseHelper(), [
'id' => $upload_pk,
'itemId' => $item_pk]);
491 $itemTreeBounds1 =
new ItemTreeBounds($nextItemId,
'uploadtree_a', $uploadId, 1, 2);
492 $itemTreeBounds2 =
new ItemTreeBounds($prevItemId,
'uploadtree_a', $uploadId, 1, 2);
494 $item1 =
new Item($itemTreeBounds1, 1, 1, 1,
"fileName");
495 $item2 =
new Item($itemTreeBounds2, 1, 1, 1,
"fileName");
498 "prevItemId" => $prevItemId,
499 "nextItemId" => $nextItemId
501 $options = array(
'skipThese' =>
"",
'groupId' => $this->groupId);
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);
507 $this->uploadDao->shouldReceive(
'getUploadtreeTableName')->withArgs([$uploadId])->andReturn(
"uploadtree");
508 $this->uploadDao->shouldReceive(
'getUploadEntry')
509 ->withArgs([$itemId,
"uploadtree"])
510 ->andReturn([
'upload_fk' => (
string) $uploadId]);
512 $this->uploadDao->shouldReceive(
'getNextItem')->withArgs([$uploadId, $itemId, $options])->andReturn($item1);
513 $this->uploadDao->shouldReceive(
'getPreviousItem')->withArgs([$uploadId, $itemId, $options])->andReturn($item2);
514 $expectedResponse = (
new ResponseHelper())->withJson($result, 200);
515 $queryParams = [
'selection' =>
null];
516 $request = $this->getMockBuilder(ServerRequestInterface::class)
518 $request->expects($this->any())
519 ->method(
'getQueryParams')
520 ->willReturn($queryParams);
522 $actualResponse = $this->uploadTreeController->getNextPreviousItem($request,
new ResponseHelper(), [
'id' => $uploadId,
'itemId' => $itemId]);
523 $this->assertEquals($expectedResponse->getStatusCode(), $actualResponse->getStatusCode());
538 $itemTreeBounds1 =
new ItemTreeBounds($nextItemId,
'uploadtree_a', $uploadId, 1, 2);
539 $itemTreeBounds2 =
new ItemTreeBounds($prevItemId,
'uploadtree_a', $uploadId, 1, 2);
541 $item1 =
new Item($itemTreeBounds1, 1, 1, 1,
"fileName");
542 $item2 =
new Item($itemTreeBounds2, 1, 1, 1,
"fileName");
544 $options = array(
'skipThese' =>
"",
'groupId' => $this->groupId);
546 $this->uploadDao->shouldReceive(
'isAccessible')
547 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
548 $this->dbHelper->shouldReceive(
'doesIdExist')
549 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
550 $this->uploadDao->shouldReceive(
'getUploadtreeTableName')->withArgs([$uploadId])->andReturn(
"uploadtree");
551 $this->uploadDao->shouldReceive(
'getUploadEntry')
552 ->withArgs([$itemId,
"uploadtree"])
553 ->andReturn([
'upload_fk' => (
string) $uploadId]);
555 $this->uploadDao->shouldReceive(
'getNextItem')->withArgs([$uploadId, $itemId, $options])->andReturn($item1);
556 $this->uploadDao->shouldReceive(
'getPreviousItem')->withArgs([$uploadId, $itemId, $options])->andReturn($item2);
558 $queryParams = [
'selection' =>
"invalidSelection"];
559 $request = $this->getMockBuilder(ServerRequestInterface::class)
561 $request->expects($this->any())
562 ->method(
'getQueryParams')
563 ->willReturn($queryParams);
564 $this->expectException(HttpBadRequestException::class);
566 $this->uploadTreeController->getNextPreviousItem($request,
579 $itemTreeBounds =
new ItemTreeBounds($itemId,
'uploadtree', $uploadId, 1, 2);
587 "addedLicenses" => [],
588 "removedLicenses" => [],
591 $obj =
new BulkHistory(1, 1,
"test",
true,
true, [], []);
592 $updatedRes[] = $obj->getArray();
594 $this->uploadDao->shouldReceive(
'isAccessible')
595 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
596 $this->dbHelper->shouldReceive(
'doesIdExist')
597 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
599 $this->uploadDao->shouldReceive(
'getUploadtreeTableName')->withArgs([$uploadId])->andReturn(
"uploadtree");
600 $this->uploadDao->shouldReceive(
'getUploadEntry')
601 ->withArgs([$itemId,
"uploadtree"])
602 ->andReturn([
'upload_fk' => (
string) $uploadId]);
604 $this->uploadDao->shouldReceive(
"getItemTreeBounds")
605 ->withArgs([$itemId,
"uploadtree"])->andReturn($itemTreeBounds);
607 $this->clearingDao->shouldReceive(
"getBulkHistory")
608 ->withArgs([$itemTreeBounds, $this->groupId])->andReturn($res);
609 $expectedResponse = (
new ResponseHelper())->withJson($updatedRes, 200);
610 $actualResponse = $this->uploadTreeController->getBulkHistory(
null,
new ResponseHelper(), [
'id' => $uploadId,
'itemId' => $itemId]);
611 $this->assertEquals($expectedResponse->getStatusCode(), $actualResponse->getStatusCode());
624 $itemTreeBounds =
new ItemTreeBounds($itemId,
'uploadtree_a', $uploadId, 1, 2);
625 $fileClearings[] =
new ClearingDecision(1, 1, $itemId, 1, 1, 1, 3, 1, 1, [], 1, 1, 1);
634 $result[] = $obj->getArray();
636 $this->uploadDao->shouldReceive(
'isAccessible')
637 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
638 $this->dbHelper->shouldReceive(
'doesIdExist')
639 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
641 $this->uploadDao->shouldReceive(
'getUploadtreeTableName')->withArgs([$uploadId])->andReturn(
"uploadtree");
642 $this->uploadDao->shouldReceive(
'getUploadEntry')
643 ->withArgs([$itemId,
"uploadtree"])
644 ->andReturn([
'upload_fk' => (
string) $uploadId]);
646 $this->uploadDao->shouldReceive(
"getItemTreeBoundsFromUploadId")
647 ->withArgs([$itemId, $uploadId])->andReturn($itemTreeBounds);
648 $this->clearingDao->shouldReceive(
"getFileClearings")
649 ->withArgs([$itemTreeBounds, $this->groupId,
false,
true])->andReturn($fileClearings);
650 $this->decisionTypes->shouldReceive(
"getTypeName")
651 ->withArgs([$fileClearings[0]->getType()])->andReturn(
"test");
652 $this->decisionScopes->shouldReceive(
"getTypeName")->withArgs([$fileClearings[0]->getScope()])->andReturn(
"test");
653 $this->decisionTypes->shouldReceive(
"getConstantNameFromKey")
654 ->withArgs([$fileClearings[0]->getType()])->andReturn(
"TO_BE_DISCUSSED");
655 $expectedResponse = (
new ResponseHelper())->withJson($result, 200);
656 $actualResponse = $this->uploadTreeController->getClearingHistory(
null,
new ResponseHelper(), [
'id' => $uploadId,
'itemId' => $itemId]);
657 $this->assertEquals($expectedResponse->getStatusCode(), $actualResponse->getStatusCode());
677 "infoText" =>
"MIT: 'MIT License\n\nCopyright (c) <year> <copyright holders>'",
678 "htmlElement" =>
null
681 $highlight =
new Highlight($res[0][
"start"], $res[0][
"end"], $res[0][
"type"], $res[0][
"refStart"], $res[0][
"refEnd"], $res[0][
"infoText"]);
682 $itemTreeBounds =
new ItemTreeBounds($itemId,
'uploadtree', $uploadId, 1, 2);
684 $this->uploadDao->shouldReceive(
'isAccessible')
685 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
686 $this->dbHelper->shouldReceive(
'doesIdExist')
687 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
688 $this->uploadDao->shouldReceive(
"getUploadtreeTableName")->withArgs([$uploadId])->andReturn(
"uploadtree");
689 $this->uploadDao->shouldReceive(
'getUploadEntry')
690 ->withArgs([$itemId,
"uploadtree"])
691 ->andReturn([
'upload_fk' => (
string) $uploadId]);
692 $this->uploadDao->shouldReceive(
"getItemTreeBounds")->withArgs([$itemId,
"uploadtree"])->andReturn($itemTreeBounds);
693 $this->viewLicensePlugin->shouldReceive(
'getSelectedHighlighting')->withArgs([$itemTreeBounds,
null,
null,
null,
null, $uploadId])->andReturn([$highlight]);
696 $queryParams = [
'clearingId' =>
null,
'agentId' =>
null,
'highlightId' =>
null,
'licenseId' =>
null];
697 $request = $this->getMockBuilder(ServerRequestInterface::class)
699 $request->expects($this->any())
700 ->method(
'getQueryParams')
701 ->willReturn($queryParams);
703 $actualResponse = $this->uploadTreeController->getHighlightEntries($request,
new ResponseHelper(), [
'id' => $uploadId,
'itemId' => $itemId]);
704 $this->assertEquals($expectedResponse->getStatusCode(), $actualResponse->getStatusCode());
717 $this->dbHelper->shouldReceive(
'doesIdExist')
718 ->withArgs([
"upload",
"upload_pk", $this->uploadId])->andReturn(
false);
721 $reqBody = $this->streamFactory->createStream();
722 $requestHeaders =
new Headers();
725 "agentId" => $this->agentId,
729 $uri = (
new Uri(
'HTTP',
'localhost'))
730 ->withQuery(http_build_query($queryParams));
732 $requestHeaders->setHeader(
'Content-Type',
'application/json');
733 $request =
new Request(
"POST", $uri,
734 $requestHeaders, [], [], $reqBody);
736 $this->expectException(HttpNotFoundException::class);
737 $this->uploadTreeController->getTreeView($request,
new ResponseHelper(), [
"id" => $this->uploadId,
"itemId"=> 10]);
751 $this->dbHelper->shouldReceive(
'doesIdExist')
752 ->withArgs([
"upload",
"upload_pk", $this->uploadId])->andReturn(
false);
753 $this->dbHelper->shouldReceive(
'doesIdExist')
754 ->withArgs([
"agent",
"agent_pk", $this->agentId])->andReturn(
false);
755 $this->uploadDao->shouldReceive(
'isAccessible')
756 ->withArgs([$this->uploadId, $this->groupId])->andReturn(
true);
758 $reqBody = $this->streamFactory->createStream();
759 $requestHeaders =
new Headers();
762 "agentId" => $this->agentId,
766 $uri = (
new Uri(
'HTTP',
'localhost'))
767 ->withQuery(http_build_query($queryParams));
769 $requestHeaders->setHeader(
'Content-Type',
'application/json');
770 $request =
new Request(
"POST", $uri,
771 $requestHeaders, [], [], $reqBody);
773 $this->expectException(HttpNotFoundException::class);
774 $this->uploadTreeController->getTreeView($request,
new ResponseHelper(), [
"id" => $this->uploadId,
"itemId"=> 10]);
788 $this->dbHelper->shouldReceive(
'doesIdExist')
789 ->withArgs([
"upload",
"upload_pk", $this->uploadId])->andReturn(
false);
790 $this->dbHelper->shouldReceive(
'doesIdExist')
791 ->withArgs([
"tag",
"tag_pk", $this->tagId])->andReturn(
false);
792 $this->uploadDao->shouldReceive(
'isAccessible')
793 ->withArgs([$this->uploadId, $this->groupId])->andReturn(
true);
795 $reqBody = $this->streamFactory->createStream();
796 $requestHeaders =
new Headers();
799 "agentId" => $this->agentId,
803 $uri = (
new Uri(
'HTTP',
'localhost'))
804 ->withQuery(http_build_query($queryParams));
806 $requestHeaders->setHeader(
'Content-Type',
'application/json');
807 $request =
new Request(
"POST", $uri,
808 $requestHeaders, [], [], $reqBody);
810 $this->expectException(HttpNotFoundException::class);
811 $this->uploadTreeController->getTreeView($request,
new ResponseHelper(), [
"id" => $this->uploadId,
"itemId"=> 10]);
825 $this->dbHelper->shouldReceive(
'doesIdExist')
826 ->withArgs([
"upload",
"upload_pk", $this->uploadId])->andReturn(
true);
827 $this->uploadDao->shouldReceive(
'isAccessible')
828 ->withArgs([$this->uploadId, $this->groupId])->andReturn(
false);
830 $reqBody = $this->streamFactory->createStream();
831 $requestHeaders =
new Headers();
834 "agentId" => $this->agentId,
838 $uri = (
new Uri(
'HTTP',
'localhost'))
839 ->withQuery(http_build_query($queryParams));
840 $requestHeaders->setHeader(
'Content-Type',
'application/json');
841 $request =
new Request(
"POST", $uri,
842 $requestHeaders, [], [], $reqBody);
843 $this->expectException(HttpForbiddenException::class);
844 $this->uploadTreeController->getTreeView($request,
new ResponseHelper(), [
"id" => $this->uploadId,
"itemId"=> 10]);
862 $itemTreeBounds =
new ItemTreeBounds($itemId,
'uploadtree_a', $uploadId, 0, 1);
863 $addedClearingResults = [];
866 'name' =>
'Imported decision',
867 'clearingId' =>
null,
869 'highlightId' =>
null,
874 $license =
new License($licenseId,
"MIT",
"MIT License",
"text",
"url", [],
876 $licenseDecision =
new LicenseDecision($licenseId,
"MIT",
"MIT License",
'text',
"url", array($result),
877 '',
'',
false, [],
null,
false);
879 $licenseRef =
new LicenseRef($licenseId,
"MIT",
"MIT LICENSE",
"spx");
880 $clearingEvent =
new ClearingEvent(1, $itemId, 12, $this->userId, $this->groupId, 4,
new ClearingLicense($licenseRef,
false,
"",
"",
"",
""));
882 $addedClearingResults[$licenseId] = $licenseDecisionResult;
884 $this->uploadDao->shouldReceive(
'isAccessible')
885 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
886 $this->dbHelper->shouldReceive(
'doesIdExist')
887 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
889 $this->uploadDao->shouldReceive(
'getUploadtreeTableName')->withArgs([$uploadId])->andReturn(
"uploadtree");
890 $this->uploadDao->shouldReceive(
'getUploadEntry')
891 ->withArgs([$itemId,
"uploadtree"])
892 ->andReturn([
'upload_fk' => (
string) $uploadId]);
894 $this->uploadDao->shouldReceive(
"getItemTreeBoundsFromUploadId")->withArgs([$itemId, $uploadId])->andReturn($itemTreeBounds);
895 $this->itemTreeBoundsMock->shouldReceive(
"containsFiles")->andReturn(
false);
896 $this->clearingDao->shouldReceive(
'getMainLicenseIds')->andReturn([]);
897 $this->clearingEventTypes->shouldReceive(
'getTypeName')->withArgs([$clearingEvent->getEventType()])->andReturn($result[
'name']);
898 $this->highlightDao->shouldReceive(
'getHighlightRegion')->withArgs([1])->andReturn([
""]);
899 $this->clearingDecisionEventProcessor->shouldReceive(
"getCurrentClearings")->withArgs([$itemTreeBounds, $this->groupId, LicenseMap::CONCLUSION])->andReturn([$addedClearingResults, []]);
900 $this->licenseDao->shouldReceive(
'getLicenseObligations')->withArgs([[$licenseId],
false])->andReturn([]);
901 $this->licenseDao->shouldReceive(
'getLicenseObligations')->withArgs([[$licenseId],
true])->andReturn([]);
902 $this->licenseDao->shouldReceive(
'getLicenseById')->withArgs([$licenseId, $this->groupId])->andReturn($license);
903 $licenses[] = $licenseDecision->getArray();
905 $expectedResponse = (
new ResponseHelper())->withJson($licenses, 200);
906 $actualResponse = $this->uploadTreeController->getLicenseDecisions(
null,
new ResponseHelper(), [
'id' => $uploadId,
'itemId' => $itemId]);
907 $this->assertEquals($expectedResponse->getStatusCode(), $actualResponse->getStatusCode());
922 $license =
new License($licenseId,
"MIT",
"MIT License",
"risk",
"texts", [],
924 $itemTreeBounds =
new ItemTreeBounds($itemId,
'uploadtree_a', $uploadId, 1, 2);
927 "shortName" =>
"MIT",
932 $existingLicenses = array([
'DT_RowId' =>
"$itemId,400",
'DT_RowClass' =>
'removed']);
934 $this->uploadDao->shouldReceive(
'isAccessible')
935 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
936 $this->dbHelper->shouldReceive(
'doesIdExist')
937 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
938 $this->uploadDao->shouldReceive(
"getUploadtreeTableName")->withArgs([$uploadId])->andReturn(
"uploadtree");
939 $this->uploadDao->shouldReceive(
'getUploadEntry')
940 ->withArgs([$itemId,
"uploadtree"])
941 ->andReturn([
'upload_fk' => (
string) $uploadId]);
942 $this->uploadDao->shouldReceive(
'getItemTreeBoundsFromUploadId')->withArgs([$itemId, $uploadId])->andReturn($itemTreeBounds);
943 $this->concludeLicensePlugin->shouldReceive(
'getCurrentSelectedLicensesTableData')->withArgs([$itemTreeBounds, $this->groupId,
true])->andReturn($existingLicenses);
944 $this->licenseDao->shouldReceive(
'getLicenseByShortName')
945 ->withArgs([$shortName, $this->groupId])->andReturn($license);
946 $this->clearingDao->shouldReceive(
'insertClearingEvent')
947 ->withArgs([$itemId, $this->userId, $this->groupId, $licenseId,
false])->andReturn(
null);
949 $info =
new Info(200,
'Successfully added MIT as a new license decision.', InfoType::INFO);
951 'success' => [$info->getArray()],
955 $reqBody = $this->streamFactory->createStream(json_encode(
958 $requestHeaders =
new Headers();
959 $requestHeaders->setHeader(
'Content-Type',
'application/json');
960 $request =
new Request(
"PUT",
new Uri(
"HTTP",
"localhost"),
961 $requestHeaders, [], [], $reqBody);
962 $actualResponse = $this->uploadTreeController->handleAddEditAndDeleteLicenseDecision($request,
new ResponseHelper(), [
'id' => $uploadId,
'itemId' => $itemId]);
964 $this->assertEquals($expectedResponse->getStatusCode(),
965 $actualResponse->getStatusCode());
981 $license =
new License($licenseId,
"MIT",
"MIT License",
"risk",
"texts", [],
983 $itemTreeBounds =
new ItemTreeBounds($itemId,
'uploadtree_a', $uploadId, 1, 2);
986 "shortName" =>
"MIT",
988 "text" =>
"Updated license text",
992 $existingLicenses = array([
'DT_RowId' =>
"$itemId,$licenseId",
'DT_RowClass' =>
'removed']);
994 $this->uploadDao->shouldReceive(
'isAccessible')
995 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
996 $this->dbHelper->shouldReceive(
'doesIdExist')
997 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
998 $this->uploadDao->shouldReceive(
"getUploadtreeTableName")->withArgs([$uploadId])->andReturn(
"uploadtree");
999 $this->uploadDao->shouldReceive(
'getUploadEntry')
1000 ->withArgs([$itemId,
"uploadtree"])
1001 ->andReturn([
'upload_fk' => (
string) $uploadId]);
1002 $this->uploadDao->shouldReceive(
'getItemTreeBoundsFromUploadId')->withArgs([$itemId, $uploadId])->andReturn($itemTreeBounds);
1003 $this->concludeLicensePlugin->shouldReceive(
'getCurrentSelectedLicensesTableData')->withArgs([$itemTreeBounds, $this->groupId,
true])->andReturn($existingLicenses);
1004 $this->licenseDao->shouldReceive(
'getLicenseByShortName')
1005 ->withArgs([$shortName, $this->groupId])->andReturn($license);
1006 $this->clearingDao->shouldReceive(
'updateClearingEvent')
1007 ->withArgs([$itemId, $this->userId, $this->groupId, $licenseId,
'reportinfo',
"Updated license text"])->andReturn(
null);
1009 $info =
new Info(200,
"Successfully updated MIT's license reportinfo", InfoType::INFO);
1011 'success' => [$info->getArray()],
1015 $reqBody = $this->streamFactory->createStream(json_encode(
1018 $requestHeaders =
new Headers();
1019 $requestHeaders->setHeader(
'Content-Type',
'application/json');
1020 $request =
new Request(
"PUT",
new Uri(
"HTTP",
"localhost"),
1021 $requestHeaders, [], [], $reqBody);
1022 $actualResponse = $this->uploadTreeController->handleAddEditAndDeleteLicenseDecision($request,
new ResponseHelper(), [
'id' => $uploadId,
'itemId' => $itemId]);
1024 $this->assertEquals($expectedResponse->getStatusCode(),
1025 $actualResponse->getStatusCode());
1041 $license =
new License($licenseId,
"MIT",
"MIT License",
"risk",
"texts", [],
1043 $itemTreeBounds =
new ItemTreeBounds($itemId,
'uploadtree_a', $uploadId, 1, 2);
1046 "shortName" =>
"MIT",
1048 "text" =>
"Updated license text",
1052 $existingLicenses = array([
'DT_RowId' =>
"$itemId,$licenseId",
'DT_RowClass' =>
'removed']);
1054 $this->uploadDao->shouldReceive(
'isAccessible')
1055 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
1056 $this->dbHelper->shouldReceive(
'doesIdExist')
1057 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1058 $this->uploadDao->shouldReceive(
"getUploadtreeTableName")->withArgs([$uploadId])->andReturn(
"uploadtree");
1059 $this->uploadDao->shouldReceive(
'getUploadEntry')
1060 ->withArgs([$itemId,
"uploadtree"])
1061 ->andReturn([
'upload_fk' => (
string) $uploadId]);
1062 $this->uploadDao->shouldReceive(
'getItemTreeBoundsFromUploadId')->withArgs([$itemId, $uploadId])->andReturn($itemTreeBounds);
1063 $this->concludeLicensePlugin->shouldReceive(
'getCurrentSelectedLicensesTableData')->withArgs([$itemTreeBounds, $this->groupId,
true])->andReturn($existingLicenses);
1064 $this->licenseDao->shouldReceive(
'getLicenseByShortName')
1065 ->withArgs([$shortName, $this->groupId])->andReturn($license);
1066 $this->clearingDao->shouldReceive(
'insertClearingEvent')
1067 ->withArgs([$itemId, $this->userId, $this->groupId, $licenseId,
true])->andReturn(
null);
1069 $info =
new Info(200,
'Successfully deleted MIT from license decision list.', InfoType::INFO);
1071 'success' => [$info->getArray()],
1075 $reqBody = $this->streamFactory->createStream(json_encode(
1078 $requestHeaders =
new Headers();
1079 $requestHeaders->setHeader(
'Content-Type',
'application/json');
1080 $request =
new Request(
"PUT",
new Uri(
"HTTP",
"localhost"),
1081 $requestHeaders, [], [], $reqBody);
1082 $actualResponse = $this->uploadTreeController->handleAddEditAndDeleteLicenseDecision($request,
new ResponseHelper(), [
'id' => $uploadId,
'itemId' => $itemId]);
1084 $this->assertEquals($expectedResponse->getStatusCode(),
1085 $actualResponse->getStatusCode());
1098 $licenseShortName =
"MIT";
1099 $existingLicense =
new License( $licenseId, $licenseShortName,
"FULL NAME",
"text",
"url", [],
"1");
1103 'licenseShortName' => $licenseShortName,
1104 'licenseText' =>
'',
1105 'acknowledgement' =>
'',
1107 'licenseAction' =>
'ADD'
1110 'refText' =>
'Copyright (c) 2011-2023 The Bootstrap Authors',
1111 'bulkScope' =>
'folder',
1112 'forceDecision' => 0,
1114 'delimiters' =>
'DEFAULT',
1115 'scanOnlyFindings' => 0
1118 $res =
new JsonResponse(array(
"jqid" => $jobId));
1123 $this->uploadDao->shouldReceive(
'isAccessible')
1124 ->withArgs([$uploadId, $this->groupId])->andReturn(
true);
1125 $this->dbHelper->shouldReceive(
'doesIdExist')
1126 ->withArgs([
"upload",
"upload_pk", $uploadId])->andReturn(
true);
1127 $this->uploadDao->shouldReceive(
'getUploadtreeTableName')->withArgs([$uploadId])->andReturn(
"uploadtree");
1128 $this->uploadDao->shouldReceive(
'getUploadEntry')
1129 ->withArgs([$itemId,
"uploadtree"])
1130 ->andReturn([
'upload_fk' => (
string) $uploadId]);
1131 $this->dbHelper->shouldReceive(
'doesIdExist')
1132 ->withArgs([
"license_ref",
"rf_pk", $licenseId])->andReturn(
true);
1133 $this->licenseDao->shouldReceive(
'getLicenseByShortName')
1134 ->withArgs([$licenseShortName, $this->groupId])
1135 ->andReturn($existingLicense);
1136 $this->changeLicenseBulk->shouldReceive(
'handle')
1137 ->withArgs([M::any()])
1140 $info =
new Info(201, json_decode($res->getContent(),
true)[
"jqid"], InfoType::INFO);
1142 $reqBody = $this->streamFactory->createStream(json_encode(
1146 $requestHeaders =
new Headers();
1147 $requestHeaders->setHeader(
'Content-Type',
'application/json');
1148 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost"),
1149 $requestHeaders, [], [], $reqBody);
1151 $expectedResponse = (
new ResponseHelper())->withJson($info->getArray(), $info->getCode());
1152 $actualResponse = $this->uploadTreeController->scheduleBulkScan($request,
new ResponseHelper(), [
'id' => $uploadId,
'itemId' => $itemId]);
1154 $this->assertEquals($expectedResponse->getStatusCode(),
1155 $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