36 use Slim\Psr7\Factory\StreamFactory;
37 use Slim\Psr7\Headers;
38 use Slim\Psr7\Request;
40 use Symfony\Component\HttpFoundation\Response;
148 $container = M::mock(
'ContainerBuilder');
149 $this->dbHelper = M::mock(DbHelper::class);
150 $this->auth = M::mock(Auth::class);
151 $this->
dbManager = M::mock(DbManager::class);
152 $this->restHelper = M::mock(RestHelper::class);
153 $this->licenseDao = M::mock(LicenseDao::class);
154 $this->userDao = M::mock(UserDao::class);
155 $this->adminLicenseAckDao = M::mock(LicenseAcknowledgementDao::class);
156 $this->adminLicensePlugin = M::mock(
'admin_license_from_csv');
157 $this->licenseCandidatePlugin = M::mock(
'admin_license_candidate');
158 $this->licenseStdCommentDao = M::mock(LicenseStdCommentDao::class);
160 $this->dbHelper->shouldReceive(
'getDbManager')->andReturn($this->
dbManager);
162 $this->restHelper->shouldReceive(
'getPlugin')->withArgs([
"admin_license_candidate"])->andReturn($this->licenseCandidatePlugin);
163 $this->restHelper->shouldReceive(
'getDbHelper')->andReturn($this->dbHelper);
164 $this->restHelper->shouldReceive(
'getGroupId')->andReturn($this->groupId);
165 $this->restHelper->shouldReceive(
'getUserId')->andReturn($this->userId);
166 $this->restHelper->shouldReceive(
'getUserDao')->andReturn($this->userDao);
168 $this->restHelper->shouldReceive(
'getPlugin')
169 ->withArgs(array(
'admin_license_from_csv'))->andReturn($this->adminLicensePlugin);
170 $container->shouldReceive(
'get')->withArgs(array(
171 'dao.license.stdc'))->andReturn($this->licenseStdCommentDao);
172 $container->shouldReceive(
'get')->withArgs(array(
173 'helper.restHelper'))->andReturn($this->restHelper);
174 $container->shouldReceive(
'get')->withArgs(array(
175 'dao.license.acknowledgement'))->andReturn($this->adminLicenseAckDao);
176 $container->shouldReceive(
'get')->withArgs(array(
177 'dao.license'))->andReturn($this->licenseDao);
178 $container->shouldReceive(
'get')->withArgs(array(
179 'dao.license.acknowledgement'))->andReturn($this->adminLicenseAckDao);
181 $this->assertCountBefore = \Hamcrest\MatcherAssert::getCount();
182 $this->streamFactory =
new StreamFactory();
191 $this->addToAssertionCount(
192 \Hamcrest\MatcherAssert::getCount() - $this->assertCountBefore);
204 $response->getBody()->seek(0);
205 return json_decode($response->getBody()->getContents(),
true);
215 return new Obligation($id,
'My obligation',
'Obligation',
216 'This should represent some valid obligation text.',
'yellow');
228 'ob_topic' =>
'My obligation',
229 'ob_text' =>
'This should represent some valid obligation text.',
232 'ob_type' =>
'Obligation',
233 'ob_classification' =>
'yellow',
235 'rf_shortname' => null
247 $emptyObligation=
true)
254 if ($shortname ==
"MIT") {
255 $license =
new License(22,
"MIT",
"MIT License",
256 "MIT License Copyright (c) <year> <copyright holders> ...",
257 "https://opensource.org/licenses/MIT",
null, 2,
false);
259 $license =
new License(25, $shortname,
"Exotic License",
260 "Exotic license for magical codes",
"",
null, 0,
true);
263 if ($emptyObligation) {
264 $license->setObligations([]);
266 $license->setObligations($obligationList);
280 if ($shortname ==
"MIT") {
281 $license = new \Fossology\Lib\Data\License(22,
"MIT",
"MIT License",
282 2,
"MIT License Copyright (c) <year> <copyright holders> ...",
283 "https://opensource.org/licenses/MIT", 1,
true);
285 $license = new \Fossology\Lib\Data\License(25, $shortname,
286 "Exotic License", 0,
"Exotic license for magical codes",
"", 1,
300 foreach ($licenses as $license) {
302 'rf_pk' => $license->getId(),
303 'rf_shortname' => $license->getShortName(),
304 'rf_fullname' => $license->getFullName(),
305 'rf_text' => $license->getText(),
306 'rf_url' => $license->getUrl(),
307 'rf_risk' => $license->getRisk(),
308 'group_fk' => $license->getIsCandidate() ? $this->groupId : 0
321 $licenseShortName =
"MIT";
322 $license = $this->
getLicense($licenseShortName,
true);
324 $requestHeaders =
new Headers();
325 $body = $this->streamFactory->createStream();
326 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost", 80,
327 "/license/$licenseShortName"), $requestHeaders, [], [], $body);
328 $this->licenseDao->shouldReceive(
'getLicenseByShortName')
329 ->withArgs([$licenseShortName, $this->groupId])
331 $this->licenseDao->shouldReceive(
'getLicenseObligations')
332 ->withArgs([[22],
false])->andReturn([]);
333 $this->licenseDao->shouldReceive(
'getLicenseObligations')
334 ->withArgs([[22],
true])->andReturn([]);
335 $expectedResponse = (
new ResponseHelper())->withJson($license->getArray(), 200);
337 $actualResponse = $this->licenseController->getLicense($request,
339 $this->assertEquals($expectedResponse->getStatusCode(),
340 $actualResponse->getStatusCode());
353 $licenseShortName =
"MIT";
354 $license = $this->
getLicense($licenseShortName,
true,
false);
356 $requestHeaders =
new Headers();
357 $body = $this->streamFactory->createStream();
358 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost", 80,
359 "/license/$licenseShortName"), $requestHeaders, [], [], $body);
360 $this->licenseDao->shouldReceive(
'getLicenseByShortName')
361 ->withArgs([$licenseShortName, $this->groupId])
363 $this->licenseDao->shouldReceive(
'getLicenseObligations')
365 $this->licenseDao->shouldReceive(
'getLicenseObligations')
367 $expectedResponse = (
new ResponseHelper())->withJson($license->getArray(), 200);
369 $actualResponse = $this->licenseController->getLicense($request,
371 $this->assertEquals($expectedResponse->getStatusCode(),
372 $actualResponse->getStatusCode());
384 $licenseShortName =
"Bogus";
386 $requestHeaders =
new Headers();
387 $body = $this->streamFactory->createStream();
388 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost", 80,
389 "/license/$licenseShortName"), $requestHeaders, [], [], $body);
390 $this->licenseDao->shouldReceive(
'getLicenseByShortName')
391 ->withArgs([$licenseShortName, $this->groupId])
393 $this->expectException(HttpNotFoundException::class);
395 $this->licenseController->getLicense($request,
new ResponseHelper(),
396 [
'shortname' => $licenseShortName]);
407 $this->testGetAllLicense(ApiVersion::V1);
417 $this->testGetAllLicense();
419 private function testGetAllLicense($version = ApiVersion::V2)
428 $requestHeaders =
new Headers();
429 $body = $this->streamFactory->createStream();
430 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost", 80,
431 "/license"), $requestHeaders, [], [], $body);
432 if ($version == ApiVersion::V2) {
433 $request = $request->withQueryParams([
"page"=>1,
"limit"=>100]);
435 $request = $request->withHeader(
'limit', 100)
436 ->withHeader(
'page', 1);
438 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,$version);
439 $this->dbHelper->shouldReceive(
'getLicenseCount')
440 ->withArgs([
"all", $this->groupId])->andReturn(4);
441 $this->dbHelper->shouldReceive(
'getLicensesPaginated')
442 ->withArgs([1, 100,
"all", $this->groupId,
false])
445 $responseLicense = [];
446 foreach ($licenses as $license) {
447 $responseLicense[] = $license->getArray();
449 $expectedResponse = (
new ResponseHelper())->withHeader(
"X-Total-Pages", 1)
450 ->withJson($responseLicense, 200);
452 $actualResponse = $this->licenseController->getAllLicenses($request,
453 new ResponseHelper(), []);
454 $this->assertEquals($expectedResponse->getStatusCode(),
455 $actualResponse->getStatusCode());
458 $this->assertEquals($expectedResponse->getHeaders(),
459 $actualResponse->getHeaders());
490 $requestHeaders =
new Headers();
491 $body = $this->streamFactory->createStream();
492 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost", 80,
493 "/license"), $requestHeaders, [], [], $body);
494 if ($version == ApiVersion::V2) {
495 $request = $request->withQueryParams([
"page"=>2,
"limit"=>5]);
497 $request = $request->withHeader(
'limit', 5)
498 ->withHeader(
'page', 2);
500 $request = $request->withAttribute(Apiversion::ATTRIBUTE_NAME,$version);
501 $this->dbHelper->shouldReceive(
'getLicenseCount')
502 ->withArgs([
"all", $this->groupId])->andReturn(4);
503 $this->expectException(HttpBadRequestException::class);
505 $this->licenseController->getAllLicenses($request,
new ResponseHelper(), []);
533 $requestHeaders =
new Headers();
534 $body = $this->streamFactory->createStream();
535 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost", 80,
536 "/license",
"kind=all"), $requestHeaders, [], [], $body);
537 $this->dbHelper->shouldReceive(
'getLicenseCount')
538 ->withArgs([
"all", $this->groupId])->andReturn(4)->once();
539 $this->dbHelper->shouldReceive(
'getLicensesPaginated')
540 ->withArgs([1, 100,
"all", $this->groupId,
false])
541 ->andReturn([])->once();
543 $this->licenseController->getAllLicenses($request,
new ResponseHelper(), []);
546 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost", 80,
547 "/license",
"kind=main"), $requestHeaders, [], [], $body);
548 $this->dbHelper->shouldReceive(
'getLicenseCount')
549 ->withArgs([
"main", $this->groupId])->andReturn(4)->once();
550 $this->dbHelper->shouldReceive(
'getLicensesPaginated')
551 ->withArgs([1, 100,
"main", $this->groupId,
false])
552 ->andReturn([])->once();
554 $this->licenseController->getAllLicenses($request,
new ResponseHelper(), []);
557 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost", 80,
558 "/license",
"kind=candidate"), $requestHeaders, [], [], $body);
559 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME, $version);
560 $this->dbHelper->shouldReceive(
'getLicenseCount')
561 ->withArgs([
"candidate", $this->groupId])->andReturn(4)->once();
562 $this->dbHelper->shouldReceive(
'getLicensesPaginated')
563 ->withArgs([1, 100,
"candidate", $this->groupId,
false])
564 ->andReturn([])->once();
566 $this->licenseController->getAllLicenses($request,
new ResponseHelper(), []);
569 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost", 80,
570 "/license",
"kind=bogus"), $requestHeaders, [], [], $body);
571 $this->dbHelper->shouldReceive(
'getLicenseCount')
572 ->withArgs([
"all", $this->groupId])->andReturn(4)->once();
573 $this->dbHelper->shouldReceive(
'getLicensesPaginated')
574 ->withArgs([1, 100,
"all", $this->groupId,
false])
575 ->andReturn([])->once();
577 $this->licenseController->getAllLicenses($request,
new ResponseHelper(), []);
588 $requestBody = $license->getArray();
589 $requestBody[
"isCandidate"] =
true;
590 unset($requestBody[
'id']);
592 $requestHeaders =
new Headers();
593 $requestHeaders->setHeader(
'Content-Type',
'application/json');
594 $body = $this->streamFactory->createStream();
595 $body->write(json_encode($requestBody));
597 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost", 80,
598 "/license"), $requestHeaders, [], [], $body);
600 $tableName =
"license_candidate";
602 "rf_shortname" => $license->getShortName(),
603 "rf_fullname" => $license->getFullName(),
604 "rf_text" => $license->getText(),
605 "rf_md5" => md5($license->getText()),
606 "rf_risk" => $license->getRisk(),
607 "rf_url" => $license->getUrl(),
608 "rf_detector_type" => 1,
615 $sql =
"SELECT count(*) cnt FROM ".
616 "$tableName WHERE rf_shortname = $1 AND group_fk = $2;";
618 $this->
dbManager->shouldReceive(
'insertTableRow')
619 ->withArgs([$tableName, $assocData, M::any(),
"rf_pk"])->andReturn(4);
620 $this->
dbManager->shouldReceive(
'getSingleRow')
621 ->withArgs([$sql, [$license->getShortName(), $this->groupId], M::any()])
622 ->andReturn([
"cnt" => 0]);
624 $info =
new Info(201,
'4', InfoType::INFO);
625 $expectedResponse = (
new ResponseHelper())->withJson($info->getArray(),
628 $actualResponse = $this->licenseController->createLicense($request,
630 $this->assertEquals($expectedResponse->getStatusCode(),
631 $actualResponse->getStatusCode());
645 $requestBody = $license->getArray();
646 $requestBody[
"isCandidate"] =
true;
647 unset($requestBody[
'id']);
648 unset($requestBody[
'shortName']);
650 $requestHeaders =
new Headers();
651 $requestHeaders->setHeader(
'Content-Type',
'application/json');
652 $body = $this->streamFactory->createStream();
653 $body->write(json_encode($requestBody));
655 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost", 80,
656 "/license"), $requestHeaders, [], [], $body);
657 $this->expectException(HttpBadRequestException::class);
659 $this->licenseController->createLicense($request,
new ResponseHelper(), []);
671 $requestBody = $license->getArray();
672 unset($requestBody[
'id']);
674 $requestHeaders =
new Headers();
675 $requestHeaders->setHeader(
'Content-Type',
'application/json');
676 $body = $this->streamFactory->createStream();
677 $body->write(json_encode($requestBody));
679 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost", 80,
680 "/license"), $requestHeaders, [], [], $body);
682 $this->expectException(HttpForbiddenException::class);
684 $this->licenseController->createLicense($request,
new ResponseHelper(), []);
714 $requestBody = $license->getArray();
715 $requestBody[
"isCandidate"] =
true;
716 unset($requestBody[
'id']);
718 $requestHeaders =
new Headers();
719 $requestHeaders->setHeader(
'Content-Type',
'application/json');
720 $body = $this->streamFactory->createStream();
721 $body->write(json_encode($requestBody));
723 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost", 80,
724 "/license"), $requestHeaders, [], [], $body);
725 $request = $request->withAttribute(Apiversion::class, $version);
726 $tableName =
"license_candidate";
728 $sql =
"SELECT count(*) cnt FROM ".
729 "$tableName WHERE rf_shortname = $1 AND group_fk = $2;";
731 $this->
dbManager->shouldReceive(
'getSingleRow')
732 ->withArgs([$sql, [$license->getShortName(), $this->groupId], M::any()])
733 ->andReturn([
"cnt" => 1]);
734 $this->expectException(HttpConflictException::class);
736 $this->licenseController->createLicense($request,
new ResponseHelper(), []);
765 "fullName" =>
"Exotic License - style",
769 $requestHeaders =
new Headers();
770 $requestHeaders->setHeader(
'Content-Type',
'application/json');
771 $body = $this->streamFactory->createStream();
772 $body->write(json_encode($requestBody));
774 $request =
new Request(
"PATCH",
new Uri(
"HTTP",
"localhost", 80,
775 "/license/" . $license->getShortName()), $requestHeaders, [], [], $body);
776 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,$version);
778 $tableName =
"license_candidate";
780 "rf_fullname" =>
"Exotic License - style",
784 $this->userDao->shouldReceive(
'isAdvisorOrAdmin')
785 ->withArgs([$this->userId, $this->groupId])->andReturn(
true);
786 $this->licenseDao->shouldReceive(
'getLicenseByShortName')
787 ->withArgs([$license->getShortName(), $this->groupId])
788 ->andReturn($license);
789 $this->dbHelper->shouldReceive(
'doesIdExist')
790 ->withArgs([
"license_candidate",
"rf_pk", $license->getId()])
792 $this->
dbManager->shouldReceive(
'updateTableRow')
793 ->withArgs([$tableName, $assocData,
"rf_pk", $license->getId(), M::any()]);
795 $info =
new Info(200,
"License " . $license->getShortName() .
" updated.",
797 $expectedResponse = (
new ResponseHelper())->withJson($info->getArray(),
800 $actualResponse = $this->licenseController->updateLicense($request,
802 $this->assertEquals($expectedResponse->getStatusCode(),
803 $actualResponse->getStatusCode());
836 "fullName" =>
"Exotic License - style",
840 $requestHeaders =
new Headers();
841 $requestHeaders->setHeader(
'Content-Type',
'application/json');
842 $body = $this->streamFactory->createStream();
843 $body->write(json_encode($requestBody));
845 $request =
new Request(
"PATCH",
new Uri(
"HTTP",
"localhost", 80,
846 "/license/" . $license->getShortName()), $requestHeaders, [], [], $body);
847 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME, $version);
848 $this->userDao->shouldReceive(
'isAdvisorOrAdmin')
849 ->withArgs([$this->userId, $this->groupId])->andReturn(
false);
850 $this->licenseDao->shouldReceive(
'getLicenseByShortName')
851 ->withArgs([$license->getShortName(), $this->groupId])
852 ->andReturn($license);
853 $this->dbHelper->shouldReceive(
'doesIdExist')
854 ->withArgs([
"license_candidate",
"rf_pk", $license->getId()])
856 $this->expectException(HttpForbiddenException::class);
858 $this->licenseController->updateLicense($request,
new ResponseHelper(),
859 [
"shortname" => $license->getShortName()]);
890 "fullName" =>
"MIT License - style",
894 $requestHeaders =
new Headers();
895 $requestHeaders->setHeader(
'Content-Type',
'application/json');
896 $body = $this->streamFactory->createStream();
897 $body->write(json_encode($requestBody));
899 $request =
new Request(
"PATCH",
new Uri(
"HTTP",
"localhost", 80,
900 "/license/" . $license->getShortName()), $requestHeaders, [], [], $body);
902 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,$version);
904 $this->userDao->shouldReceive(
'isAdvisorOrAdmin')
905 ->withArgs([$this->userId, $this->groupId])->andReturn(
true);
906 $this->licenseDao->shouldReceive(
'getLicenseByShortName')
907 ->withArgs([$license->getShortName(), $this->groupId])
908 ->andReturn($license);
909 $this->dbHelper->shouldReceive(
'doesIdExist')
910 ->withArgs([
"license_candidate",
"rf_pk", $license->getId()])
912 $this->expectException(HttpForbiddenException::class);
914 $this->licenseController->updateLicense($request,
new ResponseHelper(),
915 [
"shortname" => $license->getShortName()]);
953 $requestHeaders =
new Headers();
954 $requestHeaders->setHeader(
'Content-Type',
'application/json');
956 $body = $this->streamFactory->createStream(json_encode([]));
958 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost"),
959 $requestHeaders, [], [], $body);
960 $request = $request->withAttribute(ApiVersion::ATTRIBUTE_NAME,$version);
962 $FILE_INPUT_NAME =
"file_input";
964 $this->adminLicensePlugin->shouldReceive(
'getFileInputName')
965 ->andReturn($FILE_INPUT_NAME);
967 $res = array(
true,
"random_message",200);
969 $this->adminLicensePlugin->shouldReceive(
'handleFileUpload')-> withArgs([NULL,$delimiter,$enclosure])
972 $this->auth->shouldReceive(
'isAdmin')->andReturn(
true);
974 $info =
new Info(200,
"random_message", InfoType::INFO);
975 $expectedResponse = (
new ResponseHelper())->withJson($info->getArray(),
977 $actualResponse = $this->licenseController->handleImportLicense($request,
979 $this->assertEquals($expectedResponse->getStatusCode(),
980 $actualResponse->getStatusCode());
997 $this->auth->shouldReceive(
'isAdmin')->andReturn(
true);
998 $this->licenseCandidatePlugin->shouldReceive(
'getDataRow')->withArgs([$id])->andReturn(
true);
999 $res =
new Response(
'true',Response::HTTP_OK,array(
'Content-type'=>
'text/plain'));
1000 $this->licenseCandidatePlugin->shouldReceive(
"doDeleteCandidate")->withArgs([$id,
false])->andReturn($res);
1001 $expectedResponse =
new Info(202,
"License candidate will be deleted.", InfoType::INFO);
1002 $actualResponse = $this->licenseController->deleteAdminLicenseCandidate(
null,
1004 $this->assertEquals($expectedResponse->getCode(),
1005 $actualResponse->getStatusCode());
1006 $this->assertEquals($expectedResponse->getArray(),
1007 $this->getResponseJson($actualResponse));
1021 $this->auth->shouldReceive(
'isAdmin')->andReturn(
false);
1022 $this->expectException(HttpForbiddenException::class);
1024 $this->licenseController->deleteAdminLicenseCandidate(
null,
1039 $this->auth->shouldReceive(
'isAdmin')->andReturn(
true);
1040 $this->licenseCandidatePlugin->shouldReceive(
'getDataRow')->withArgs([$id])->andReturn(
false);
1041 $res =
new Response(
'true',Response::HTTP_OK,array(
'Content-type'=>
'text/plain'));
1042 $this->licenseCandidatePlugin->shouldReceive(
"doDeleteCandidate")->withArgs([$id])->andReturn($res);
1043 $this->expectException(HttpNotFoundException::class);
1045 $this->licenseController->deleteAdminLicenseCandidate(
null,
1060 $dummyLicenseAcknowledgments = [
1063 "name" =>
"MIT license",
1064 "acknowledgement" =>
"Permission is hereby granted, free of charge",
1065 "updated" =>
"2024-06-16 15:02:22.245855+02",
1067 "is_enabled" =>
false,
1071 "name" =>
"GPL-2.0-or-later",
1072 "acknowledgement" =>
"Permission is hereby granted, free of charge",
1073 "updated" =>
"2024-08-16 15:02:22.245855+02",
1075 "is_enabled" =>
true,
1081 'name' => $dummyLicenseAcknowledgments[0][
"name"],
1082 'acknowledgement' => $dummyLicenseAcknowledgments[0][
"acknowledgement"],
1083 'is_enabled' =>
false,
1087 'name' => $dummyLicenseAcknowledgments[1][
"name"],
1088 'acknowledgement' => $dummyLicenseAcknowledgments[1][
'acknowledgement'],
1089 'is_enabled' =>
true,
1094 $this->adminLicenseAckDao->shouldReceive(
'getAllAcknowledgements')->andReturn($dummyLicenseAcknowledgments);
1095 $requestHeaders =
new Headers();
1096 $requestHeaders->setHeader(
'Content-Type',
'application/json');
1097 $body = $this->streamFactory->createStream();
1098 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost"),
1099 $requestHeaders, [], [], $body);
1101 $expectedResponse = (
new ResponseHelper())->withJson($expectedInfo, 200);
1102 $actualResponse = $this->licenseController->getAllAdminAcknowledgements($request,$response,[]);
1104 $this->assertEquals(200,$actualResponse->getStatusCode());
1105 $this->assertEquals($expectedResponse->getBody()->getContents(),$actualResponse->getBody()->getContents());
1122 $requestHeaders =
new Headers();
1123 $requestHeaders->setHeader(
'Content-Type',
'application/json');
1124 $body = $this->streamFactory->createStream();
1125 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost"),
1126 $requestHeaders, [], [], $body);
1128 $this->expectException(HttpForbiddenException::class);
1129 $this->licenseController->getAllAdminAcknowledgements($request,$response,[]);
1141 $requestHeaders =
new Headers();
1142 $requestHeaders->setHeader(
'Content-Type',
'application/json');
1143 $body = $this->streamFactory->createStream();
1144 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost"),
1145 $requestHeaders, [], [], $body);
1147 $this->expectException(HttpBadRequestException::class);
1149 $this->licenseController->handleAdminLicenseAcknowledgement($request,$response,[]);
1162 $requestHeaders =
new Headers();
1163 $requestHeaders->setHeader(
'Content-Type',
'application/json');
1164 $body = $this->streamFactory->createStream(json_encode([]));
1165 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost"),
1166 $requestHeaders, [], [], $body);
1168 $this->expectException(HttpBadRequestException::class);
1170 $this->licenseController->handleAdminLicenseAcknowledgement($request,$response,[]);
1186 $this->dbHelper->shouldReceive(
"doesIdExist")
1187 ->withArgs([
"license_std_acknowledgement",
"name", $this->
getDummyVars()[
"bodyContent"][0][
"name"]])->andReturn(
true);
1188 $this->
dbManager->shouldReceive(
"getSingleRow")
1189 ->withAnyArgs()->andReturn($this->
getDummyVars()[
"dummyExistingAck"]);
1190 $this->adminLicenseAckDao->shouldReceive(
'updateAcknowledgement')->withArgs([$this->
getDummyVars()[
"bodyContent"][0][
"id"], $this->
getDummyVars()[
"bodyContent"][0][
"name"], $this->
getDummyVars()[
"bodyContent"][0][
"ack"]]);
1191 $this->adminLicenseAckDao->shouldReceive(
'toggleAcknowledgement')->withArgs([$this->
getDummyVars()[
"bodyContent"][0][
"id"]]);
1194 $requestHeaders =
new Headers();
1195 $requestHeaders->setHeader(
'Content-Type',
'application/json');
1196 $body = $this->streamFactory->createStream(json_encode($this->
getDummyVars()[
"bodyContent"]));
1197 $request =
new Request(
"PUT",
new Uri(
"HTTP",
"localhost"),
1198 $requestHeaders, [], [], $body);
1201 $expectedInfo =
new Info(200,
"Successfully updated admin license acknowledgement with name '" . $this->
getDummyVars()[
"dummyExistingAck"][
"name"] .
"'", InfoType::INFO);
1202 $success [] =$expectedInfo->getArray();
1203 $expectedResponse = (
new ResponseHelper())->withJson([
"success" => $success,
"errors" => []], 200);
1205 $actualResponse = $this->licenseController->handleAdminLicenseAcknowledgement($request,$response,[]);
1207 $this->assertEquals(200,$actualResponse->getStatusCode());
1209 $this->assertEquals($expectedResponse->getBody()->getContents(),$actualResponse->getBody()->getContents());
1225 $bodyContent[0][
"update"] =
false;
1227 $this->dbHelper->shouldReceive(
"doesIdExist")
1228 ->withArgs([
"license_std_acknowledgement",
"name", $this->
getDummyVars()[
"bodyContent"][0][
"name"]])->andReturn(
true);
1229 $this->
dbManager->shouldReceive(
"getSingleRow")
1230 ->withAnyArgs()->andReturn($this->
getDummyVars()[
"dummyExistingAck"]);
1231 $this->adminLicenseAckDao->shouldReceive(
'updateAcknowledgement')->withArgs([$this->
getDummyVars()[
"bodyContent"][0][
"id"], $this->
getDummyVars()[
"bodyContent"][0][
"name"], $this->
getDummyVars()[
"bodyContent"][0][
"ack"]]);
1232 $this->adminLicenseAckDao->shouldReceive(
'toggleAcknowledgement')->withArgs([$this->
getDummyVars()[
"bodyContent"][0][
"id"]]);
1235 $requestHeaders =
new Headers();
1236 $requestHeaders->setHeader(
'Content-Type',
'application/json');
1237 $body = $this->streamFactory->createStream(json_encode($bodyContent));
1238 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost"),
1239 $requestHeaders, [], [], $body);
1243 $actualResponse = $this->licenseController->handleAdminLicenseAcknowledgement($request,$response,[]);
1244 $this->assertEquals(400,$this->
getResponseJson($actualResponse)[
"errors"][0][
"code"]);
1245 $this->assertEquals([],$this->
getResponseJson($actualResponse)[
"success"]);
1260 $bodyContent[0][
"update"] =
false;
1262 $this->dbHelper->shouldReceive(
"doesIdExist")
1263 ->withArgs([
"license_std_acknowledgement",
"name", $this->
getDummyVars()[
"bodyContent"][0][
"name"]])->andReturn(
false);
1264 $this->
dbManager->shouldReceive(
"getSingleRow")
1265 ->withAnyArgs()->andReturn($this->
getDummyVars()[
"dummyExistingAck"]);
1266 $this->adminLicenseAckDao->shouldReceive(
'updateAcknowledgement')->withArgs([$this->
getDummyVars()[
"bodyContent"][0][
"id"], $this->
getDummyVars()[
"bodyContent"][0][
"name"], $this->
getDummyVars()[
"bodyContent"][0][
"ack"]]);
1267 $this->adminLicenseAckDao->shouldReceive(
'toggleAcknowledgement')->withArgs([$this->
getDummyVars()[
"bodyContent"][0][
"id"]]);
1268 $this->adminLicenseAckDao->shouldReceive(
"insertAcknowledgement")
1269 ->withArgs([$bodyContent[0][
'name'], $bodyContent[0][
'ack']])->andReturn(-1);
1271 $requestHeaders =
new Headers();
1272 $requestHeaders->setHeader(
'Content-Type',
'application/json');
1273 $body = $this->streamFactory->createStream(json_encode($bodyContent));
1274 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost"),
1275 $requestHeaders, [], [], $body);
1278 $info =
new Info(201,
"Acknowledgement added successfully.", InfoType::INFO);
1279 $success [] = $info->getArray();
1281 $expectedResponse = (
new ResponseHelper())->withJson([
"success" => $success,
"errors" => []], 200);
1282 $actualResponse = $this->licenseController->handleAdminLicenseAcknowledgement($request,$response,[]);
1283 $this->assertEquals(201,$this->
getResponseJson($actualResponse)[
"success"][0][
"code"]);
1284 $this->assertEmpty($this->
getResponseJson($actualResponse)[
"errors"]);
1286 $this->assertEquals($expectedResponse->getBody()->getContents(),$actualResponse->getBody()->getContents());
1300 $bodyContent[0][
"update"] =
false;
1302 $this->dbHelper->shouldReceive(
"doesIdExist")
1303 ->withArgs([
"license_std_acknowledgement",
"name", $this->
getDummyVars()[
"bodyContent"][0][
"name"]])->andReturn(
false);
1304 $this->
dbManager->shouldReceive(
"getSingleRow")
1305 ->withAnyArgs()->andReturn($this->
getDummyVars()[
"dummyExistingAck"]);
1306 $this->adminLicenseAckDao->shouldReceive(
'updateAcknowledgement')->withArgs([$this->
getDummyVars()[
"bodyContent"][0][
"id"], $this->
getDummyVars()[
"bodyContent"][0][
"name"], $this->
getDummyVars()[
"bodyContent"][0][
"ack"]]);
1307 $this->adminLicenseAckDao->shouldReceive(
'toggleAcknowledgement')->withArgs([$this->
getDummyVars()[
"bodyContent"][0][
"id"]]);
1308 $this->adminLicenseAckDao->shouldReceive(
"insertAcknowledgement")
1309 ->withArgs([$bodyContent[0][
'name'], $bodyContent[0][
'ack']])->andReturn(-2);
1311 $requestHeaders =
new Headers();
1312 $requestHeaders->setHeader(
'Content-Type',
'application/json');
1313 $body = $this->streamFactory->createStream(json_encode($bodyContent));
1314 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost"),
1315 $requestHeaders, [], [], $body);
1318 $expectedError =
new Info(500,
"Error while inserting new acknowledgement.", InfoType::ERROR);
1319 $errors [] = $expectedError->getArray();
1321 $expectedResponse = (
new ResponseHelper())->withJson([
"success" => [],
"errors" => $errors], 200);
1322 $actualResponse = $this->licenseController->handleAdminLicenseAcknowledgement($request,$response,[]);
1323 $this->assertEquals(500,$this->
getResponseJson($actualResponse)[
"errors"][0][
"code"]);
1324 $this->assertEmpty($this->
getResponseJson($actualResponse)[
"success"]);
1326 $this->assertEquals($expectedResponse->getBody()->getContents(),$actualResponse->getBody()->getContents());
1339 $dbLicenseStdComments = [
1342 "name" =>
"Test License Standard",
1343 "comment" =>
"MIT License Standard",
1344 "updated" =>
"2024-06-16 15:04:08.07613+02",
1346 "is_enabled" =>
true
1350 $requestHeaders =
new Headers();
1351 $requestHeaders->setHeader(
'Content-Type',
'application/json');
1352 $body = $this->streamFactory->createStream();
1353 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost"),
1354 $requestHeaders, [], [], $body);
1357 $this->licenseStdCommentDao->shouldReceive(
'getAllComments')
1358 ->andReturn($dbLicenseStdComments);
1359 $actualResponse = $this->licenseController->getAllLicenseStandardComments($request, $response,[]);
1361 $this->assertEquals(200,intval($actualResponse->getStatusCode()));
1362 $this->assertEquals($dbLicenseStdComments[0][
'lsc_pk'], $this->
getResponseJson($actualResponse)[0][
'id']);
1363 $this->assertEquals($dbLicenseStdComments[0][
'name'], $this->
getResponseJson($actualResponse)[0][
'name']);
1364 $this->assertEquals($dbLicenseStdComments[0][
'comment'], $this->
getResponseJson($actualResponse)[0][
'comment']);
1365 $this->assertEquals($dbLicenseStdComments[0][
'is_enabled'], $this->
getResponseJson($actualResponse)[0][
'is_enabled']);
1380 $requestHeaders =
new Headers();
1381 $requestHeaders->setHeader(
'Content-Type',
'application/json');
1382 $body = $this->streamFactory->createStream();
1383 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost"),
1384 $requestHeaders, [], [], $body);
1387 $this->expectException(HttpForbiddenException::class);
1388 $this->licenseController->handleLicenseStandardComment($request, $response,[]);
1402 $requestHeaders =
new Headers();
1403 $requestHeaders->setHeader(
'Content-Type',
'application/json');
1404 $body = $this->streamFactory->createStream(json_encode([]));
1405 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost"),
1406 $requestHeaders, [], [], $body);
1408 $this->expectException(HttpBadRequestException::class);
1410 $this->licenseController->handleLicenseStandardComment($request,$response,[]);
1422 "ack" =>
"acknowledgement",
1423 "name" =>
"MIT license",
1424 "toggle" =>
"toggle license",
1428 $dummyExistingAck = [
1430 "name" =>
"MIT license",
1431 "acknowledgement" =>
"Permission is hereby granted, free of charge",
1432 "updated" =>
"2024-06-16 15:02:22.245855+02",
1434 "is_enabled" => false
1436 $licenseStdComments = [
1439 "name" =>
"Test License Standard",
1440 "comment" =>
"MIT License Standard",
1445 $existingLicenseStdComment = [
1446 "name" =>
"Test License Standard",
1447 "comment" =>
"MIT License Standard",
1451 $tableName =
"license_std_acknowledgement";
1454 "bodyContent" => $bodyContent,
1455 "dummyExistingAck" => $dummyExistingAck,
1456 "tableName" => $tableName,
1457 "licenseStdComments" => $licenseStdComments,
1458 "existingLicenseStdComment" => $existingLicenseStdComment
1473 $bodyContent = $this->
getDummyVars()[
'licenseStdComments'];
1474 $existingLicenseStdComments = [
1475 "name" =>
"Test License Standard",
1476 "comment" =>
"MIT License Standard",
1480 $this->
dbManager->shouldReceive(
"getSingleRow")
1481 ->withAnyArgs()->andReturn($existingLicenseStdComments);
1482 $this->licenseStdCommentDao->shouldReceive(
'updateComment')->withArgs([$bodyContent[0][
"id"], $bodyContent[0][
"name"], $bodyContent[0][
"comment"]]);
1483 $this->licenseStdCommentDao->shouldReceive(
'toggleComment')->withArgs([$bodyContent[0][
"id"]]);
1486 $requestHeaders =
new Headers();
1487 $requestHeaders->setHeader(
'Content-Type',
'application/json');
1488 $body = $this->streamFactory->createStream(json_encode($bodyContent));
1489 $request =
new Request(
"PUT",
new Uri(
"HTTP",
"localhost"),
1490 $requestHeaders, [], [], $body);
1493 $expectedInfo =
new Info(200,
"Successfully updated standard comment", InfoType::INFO);
1494 $success [] =$expectedInfo->getArray();
1495 $expectedResponse = (
new ResponseHelper())->withJson([
"success" => $success,
"errors" => []], 200);
1497 $actualResponse = $this->licenseController->handleLicenseStandardComment($request,$response,[]);
1499 $this->assertEquals(200,$actualResponse->getStatusCode());
1501 $this->assertEquals($expectedResponse->getBody()->getContents(),$actualResponse->getBody()->getContents());
1516 $bodyContent = $this->
getDummyVars()[
'licenseStdComments'];
1517 $bodyContent[0][
"update"] =
false;
1519 $this->dbHelper->shouldReceive(
"doesIdExist")
1520 ->withArgs([
"license_std_comment",
"name", $bodyContent[0][
'name']])->andReturn(
true);
1522 $requestHeaders =
new Headers();
1523 $requestHeaders->setHeader(
'Content-Type',
'application/json');
1524 $body = $this->streamFactory->createStream(json_encode($bodyContent));
1525 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost"),
1526 $requestHeaders, [], [], $body);
1529 $actualResponse = $this->licenseController->handleAdminLicenseAcknowledgement($request,$response,[]);
1530 $this->assertEquals(400,$this->
getResponseJson($actualResponse)[
"errors"][0][
"code"]);
1531 $this->assertEquals([],$this->
getResponseJson($actualResponse)[
"success"]);
1546 $bodyContent = $this->
getDummyVars()[
'licenseStdComments'];
1547 $bodyContent[0][
"update"] =
false;
1549 $this->dbHelper->shouldReceive(
"doesIdExist")
1550 ->withArgs([
"license_std_comment",
"name", $bodyContent[0][
"name"]])->andReturn(
false);
1551 $this->licenseStdCommentDao->shouldReceive(
"insertComment")
1552 ->withArgs([$bodyContent[0][
'name'], $bodyContent[0][
'comment']])->andReturn(-1);
1554 $requestHeaders =
new Headers();
1555 $requestHeaders->setHeader(
'Content-Type',
'application/json');
1556 $body = $this->streamFactory->createStream(json_encode($bodyContent));
1557 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost"),
1558 $requestHeaders, [], [], $body);
1561 $info =
new Info(201,
"Comment with name '". $bodyContent[0][
'name'] .
"' added successfully.", InfoType::INFO);
1562 $success [] = $info->getArray();
1564 $expectedResponse = (
new ResponseHelper())->withJson([
"success" => $success,
"errors" => []], 200);
1565 $actualResponse = $this->licenseController->handleLicenseStandardComment($request,$response,[]);
1567 $this->assertEquals(201,$this->
getResponseJson($actualResponse)[
"success"][0][
"code"]);
1568 $this->assertEmpty($this->
getResponseJson($actualResponse)[
"errors"]);
1570 $this->assertEquals($expectedResponse->getBody()->getContents(),$actualResponse->getBody()->getContents());
1585 $bodyContent = $this->
getDummyVars()[
'licenseStdComments'];
1586 $bodyContent[0][
"update"] =
false;
1588 $this->dbHelper->shouldReceive(
"doesIdExist")
1589 ->withArgs([
"license_std_comment",
"name", $bodyContent[0][
"name"]])->andReturn(
false);
1590 $this->licenseStdCommentDao->shouldReceive(
"insertComment")
1591 ->withArgs([$bodyContent[0][
'name'], $bodyContent[0][
'comment']])->andReturn(-2);
1593 $requestHeaders =
new Headers();
1594 $requestHeaders->setHeader(
'Content-Type',
'application/json');
1595 $body = $this->streamFactory->createStream(json_encode($bodyContent));
1596 $request =
new Request(
"POST",
new Uri(
"HTTP",
"localhost"),
1597 $requestHeaders, [], [], $body);
1600 $expectedError =
new Info(500,
"Error while inserting new comment.", InfoType::ERROR);
1601 $errors [] = $expectedError->getArray();
1603 $expectedResponse = (
new ResponseHelper())->withJson([
"success" => [],
"errors" => $errors], 200);
1604 $actualResponse = $this->licenseController->handleLicenseStandardComment($request,$response,[]);
1605 $this->assertEquals(500,$this->
getResponseJson($actualResponse)[
"errors"][0][
"code"]);
1606 $this->assertEmpty($this->
getResponseJson($actualResponse)[
"success"]);
1608 $this->assertEquals($expectedResponse->getBody()->getContents(),$actualResponse->getBody()->getContents());
1622 $this->dbHelper->shouldReceive(
"doesIdExist")->withArgs(array(
"license_ref",
"rf_pk",$id))->andReturn(
true);
1623 $this->dbHelper->shouldReceive(
"doesIdExist")->withArgs(array(
"license_candidate",
"rf_pk",$id))->andReturn(
true);
1624 $this->
dbManager->shouldReceive(
'prepare');
1625 $this->
dbManager->shouldReceive(
'fetchAll')->andReturn([]);;
1626 $this->
dbManager->shouldReceive(
'freeResult')->andReturn([]);
1627 $this->
dbManager->shouldReceive(
'execute');
1628 $this->
dbManager->shouldReceive(
"getSingleRow")->withAnyArgs()->andReturn([]);
1630 $requestHeaders =
new Headers();
1631 $body = $this->streamFactory->createStream(json_encode([
"referenceText" =>
"rftext"]));
1632 $request =
new Request(
"GET",
new Uri(
"HTTP",
"localhost"),
1633 $requestHeaders, [], [], $body);
1636 $actualResponse = $this->licenseController->exportAdminLicenseToCSV($request,
new ResponseHelper(), []);
1637 $this->assertEquals(200,$actualResponse->getStatusCode());
1652 $this->expectException(HttpForbiddenException::class);
1653 $actualResponse = $this->licenseController->exportAdminLicenseToCSV($request,
new ResponseHelper(), []);
1654 $this->assertEquals(200,$actualResponse->getStatusCode());
1664 $requestHeaders =
new Headers();
1665 $body = $this->streamFactory->createStream();
1666 $request =
new Request($method,
new Uri(
"HTTP",
"localhost"),
1667 $requestHeaders, [], [], $body);
1676 $requestHeaders =
new Headers();
1677 $requestHeaders->setHeader(
'Content-Type',
'application/json');
1679 $request =
new Request($method,
new Uri(
"HTTP",
"localhost"),
1680 $requestHeaders, [], [], $body);
1696 $this->expectException(HttpForbiddenException::class);
1697 $this->licenseController->verifyLicense($request,
new ResponseHelper(),[]);
1715 $body = $this->streamFactory->createStream(json_encode([
1716 "parentShortname" => $parentLicense->getShortName(),
1719 $this->expectException(HttpBadRequestException::class);
1720 $this->licenseController->verifyLicense($request,
new ResponseHelper(), [
1741 $body = $this->streamFactory->createStream(json_encode([
1742 "parentShortname" => $parentLicense->getShortName(),
1745 $this->licenseDao->shouldReceive(
"getLicenseByShortName")
1746 ->withArgs([$license->getShortName(),$this->groupId])->andReturn($license);
1747 $this->licenseDao->shouldReceive(
"getLicenseByShortName")
1748 ->withArgs([$parentLicense->getShortName(), $this->groupId])->andReturn($parentLicense);
1750 $this->licenseCandidatePlugin->shouldReceive(
"verifyCandidate")
1751 ->withArgs([$license->getId(),$license->getShortName(), $parentLicense->getId()])
1755 $this->expectException(HttpBadRequestException::class);
1756 $this->licenseController->verifyLicense($request,
new ResponseHelper(), [
"shortname" => $license->getShortName()]);
1773 $body = $this->streamFactory->createStream(json_encode([
1774 "parentShortname" => $parentLicense->getShortName(),
1777 $this->licenseDao->shouldReceive(
"getLicenseByShortName")
1778 ->withArgs([$license->getShortName(),$this->groupId])->andReturn([]);
1779 $this->licenseDao->shouldReceive(
"getLicenseByShortName")
1780 ->withArgs([$parentLicense->getShortName(), $this->groupId])->andReturn($parentLicense);
1784 $this->expectException(HttpNotFoundException::class);
1785 $this->licenseController->verifyLicense($request,
new ResponseHelper(), [
"shortname" => $license->getShortName()]);
1803 $body = $this->streamFactory->createStream(json_encode([
1804 "parentShortname" => $parentLicense->getShortName(),
1807 $this->licenseDao->shouldReceive(
"getLicenseByShortName")
1808 ->withArgs([$license->getShortName(),$this->groupId])->andReturn($license);
1809 $this->licenseDao->shouldReceive(
"getLicenseByShortName")
1810 ->withArgs([$parentLicense->getShortName(), $this->groupId])->andReturn($parentLicense);
1812 $this->licenseCandidatePlugin->shouldReceive(
"verifyCandidate")
1813 ->withArgs([$license->getId(),$license->getShortName(), $parentLicense->getId()])
1817 $info =
new Info(200,
'Successfully verified candidate ('.$license->getShortName().
')'.
' as variant of ('.$parentLicense->getShortName().
').', InfoType::INFO);
1819 "code" => $info->getCode(),
1820 "message" => $info->getMessage(),
1821 "type" => $info->getType()
1824 $actualResponse = $this->licenseController->verifyLicense($request,
new ResponseHelper(), [
"shortname" => $license->getShortName()]);
1826 $this->assertEquals($expectedResponse->getStatusCode(), $actualResponse->getStatusCode());
1840 "GNU GENERAL PUBLIC LICENSE Copyright (C) 1989 Free Software ",
1843 $parentLicense =
new License(3,
1846 "GNU GENERAL PUBLIC LICENSE Copyright (C) 1989 Free Software ",
1850 "license" => $license,
1851 "parentLicense" => $parentLicense
1865 $body = $this->streamFactory->createStream(json_encode([]));
1868 $this->expectException(HttpForbiddenException::class);
1869 $this->licenseController->mergeLicense($request,
new ResponseHelper(), []);
1885 $body = $this->streamFactory->createStream(json_encode([
1886 "parentShortname" => $parentLicense->getShortName(),
1890 $this->expectException(HttpBadRequestException::class);
1891 $this->licenseController->mergeLicense($request,
new ResponseHelper(), [
"shortname" =>
""]);
1907 $body = $this->streamFactory->createStream(json_encode([
1908 "parentShortname" => $parentLicense->getShortName(),
1912 $this->expectException(HttpBadRequestException::class);
1913 $this->licenseController->mergeLicense($request,
new ResponseHelper(), [
"shortname" => $parentLicense->getShortName()]);
1930 $body = $this->streamFactory->createStream(json_encode([
1931 "parentShortname" => $parentLicense->getShortName(),
1933 $this->licenseDao->shouldReceive(
"getLicenseByShortName")
1934 ->withArgs([$license->getShortName(),$this->groupId])->andReturn(
null);
1935 $this->licenseDao->shouldReceive(
"getLicenseByShortName")
1936 ->withArgs([$parentLicense->getShortName(), $this->groupId])->andReturn($parentLicense);
1940 $this->expectException(HttpNotFoundException::class);
1941 $this->licenseController->mergeLicense($request,
new ResponseHelper(), [
"shortname" => $license->getShortName()]);
1959 $body = $this->streamFactory->createStream(json_encode([
1960 "parentShortname" => $parentLicense->getShortName(),
1962 $this->licenseDao->shouldReceive(
"getLicenseByShortName")
1963 ->withArgs([$license->getShortName(),$this->groupId])->andReturn($license);
1964 $this->licenseDao->shouldReceive(
"getLicenseByShortName")
1965 ->withArgs([$parentLicense->getShortName(), $this->groupId])->andReturn($parentLicense);
1966 $this->licenseCandidatePlugin->shouldReceive(
"getDataRow")
1967 ->withArgs([$license->getId()])->andReturn([]);
1971 $this->expectException(HttpNotFoundException::class);
1972 $this->licenseController->mergeLicense($request,
new ResponseHelper(), [
"shortname" => $license->getShortName()]);
1990 "rf_shortname" =>
"AGPL-1.0-or-later",
1991 "rf_text" =>
"License by OJO.",
1992 "shortname" =>
"AGPL-1.0-or-later",
1994 $body = $this->streamFactory->createStream(json_encode([
1995 "parentShortname" => $parentLicense->getShortName(),
1997 $this->licenseDao->shouldReceive(
"getLicenseByShortName")
1998 ->withArgs([$license->getShortName(),$this->groupId])->andReturn($license);
1999 $this->licenseDao->shouldReceive(
"getLicenseByShortName")
2000 ->withArgs([$parentLicense->getShortName(), $this->groupId])->andReturn($parentLicense);
2001 $this->licenseCandidatePlugin->shouldReceive(
"getDataRow")
2002 ->withArgs([$license->getId()])->andReturn($vars);
2003 $this->licenseCandidatePlugin->shouldReceive(
"mergeCandidate")
2004 ->withArgs([$license->getId(), $parentLicense->getId(), $vars ])->andReturn(
false);
2007 $this->expectException(HttpInternalServerErrorException::class);
2008 $this->licenseController->mergeLicense($request,
new ResponseHelper(), [
"shortname" => $license->getShortName()]);
2027 "rf_shortname" =>
"AGPL-1.0-or-later",
2028 "rf_text" =>
"License by OJO.",
2029 "shortname" =>
"AGPL-1.0-or-later",
2031 $body = $this->streamFactory->createStream(json_encode([
2032 "parentShortname" => $parentLicense->getShortName(),
2034 $this->licenseDao->shouldReceive(
"getLicenseByShortName")
2035 ->withArgs([$license->getShortName(),$this->groupId])->andReturn($license);
2036 $this->licenseDao->shouldReceive(
"getLicenseByShortName")
2037 ->withArgs([$parentLicense->getShortName(), $this->groupId])->andReturn($parentLicense);
2038 $this->licenseCandidatePlugin->shouldReceive(
"getDataRow")
2039 ->withArgs([$license->getId()])->andReturn($vars);
2040 $this->licenseCandidatePlugin->shouldReceive(
"mergeCandidate")
2041 ->withArgs([$license->getId(), $parentLicense->getId(), $vars ])->andReturn(
true);
2044 $info =
new Info(200,
"Successfully merged candidate (". $parentLicense->getShortName() .
") into (".$license->getShortName() .
").", InfoType::INFO);
2045 $expectedResponse = (
new ResponseHelper())->withJson($info->getArray(), $info->getCode());
2047 $actualResponse = $this->licenseController->mergeLicense($request,
new ResponseHelper(), [
"shortname" => $license->getShortName()]);
2048 $this->assertEquals(200, $actualResponse->getStatusCode());
2064 $this->expectException(HttpForbiddenException::class);
2065 $this->licenseController->getSuggestedLicense($request,
new ResponseHelper(), []);
2079 $body = $this->streamFactory->createStream(json_encode([
2080 "referenceText" =>
""
2083 $licenseCandidate = [
2086 "rf_fullname" =>
"GFDL-1.3-no-invariants-or-later",
2087 "rf_shortname" =>
"GFDL-1.1-no-invariants-only",
2088 "rf_text" =>
"License by OJO.",
2095 $this->licenseCandidatePlugin->shouldReceive(
"suggestLicenseId")
2096 ->withArgs([$licenseCandidate[
'rf_text'],
true])->andReturn([[2,3,5,4],[]]);
2097 $this->licenseCandidatePlugin->shouldReceive(
"getDataRow")
2098 ->withArgs([2,
"ONLY license-ref"])->andReturn($licenseCandidate);
2100 'id' => intval($licenseCandidate[
'rf_pk']),
2101 'spdxName' => $licenseCandidate[
'rf_spdx_id'],
2102 'shortName' => $licenseCandidate[
'rf_shortname'],
2103 'fullName' => $licenseCandidate[
'rf_fullname'],
2104 'text' => $licenseCandidate[
'rf_text'],
2105 'url' => $licenseCandidate[
'rf_url'],
2106 'notes' => $licenseCandidate[
'rf_notes'],
2107 'risk' => intval($licenseCandidate[
'rf_risk']),
2112 $this->expectException(HttpBadRequestException::class);
2113 $actualResponse = $this->licenseController->getSuggestedLicense($request,
new ResponseHelper(), []);
2114 $this->assertEquals(200,$actualResponse->getStatusCode());
2132 $this->testGetCandidates(ApiVersion::V1);
2142 $this->testGetCandidates();
2144 private function testGetCandidates($version = ApiVersion::V2)
2146 $request = M::mock(Request::class);
2147 $request->shouldReceive(
'getAttribute')->andReturn($version);
2149 $this->licenseCandidatePlugin->shouldReceive(
'getCandidateArrayData')->andReturn([]);
2152 $actualResponse = $this->licenseController->getCandidates($request,
2154 $this->assertEquals($expectedResponse->getStatusCode(),
2155 $actualResponse->getStatusCode());
2185 $request = M::mock(Request::class);
2186 $request->shouldReceive(
'getAttribute')->andReturn($version);
2189 $this->expectException(HttpForbiddenException::class);
2191 $this->licenseController->getCandidates($request,
Contains the constants and helpers for authentication of user.
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.
Unit tests for LicenseController.
testCreateDuplicateLicenseV2()
getResponseJson($response)
testCreateLicenseNoAdmin()
testCreateDuplicateLicense($version=ApiVersion::V2)
testUpdateLicenseNonAdminV1()
testMergeLicenseNotAdmin()
testUpdateLicenseNonAdvisorV1()
testGetAllLicenseFiltersV1()
testExportAdminLicenseToCSVNotAdmin()
testGetCandidatesNoAdminV1()
testVerifyLicenseWithBadRequest()
testImportLicense($version=ApiVersion::V2)
testMergeLicenseWithNoCandidateLicense()
testHandleAdminLicenseAcknowledgementLicenseExists()
testHandleLicenseStandardCommentCreateNew()
testCreateLicenseNoShort()
testGetAllLicenseBoundsV1()
testHandleLicenseStandardCommentWithInvalidBody()
testGetSuggestedLicenseWithBadRequest()
testUpdateLicenseNonAdvisorV2()
testGetSuggestedLicensesNotAdmin()
testHandleAdminLicenseAcknowledgementInvalidBody()
testMergeNotFoundLicense()
testMergeLicenseWithSameName()
testCreateDuplicateLicenseV1()
testHandleAdminLicenseAcknowledgementWithNoPermission()
testVerifyLicenseWithNonUniqueName()
testHandleAdminLicenseAcknowledgementWithUpdate()
testGetAllLicenseBounds($version=ApiVersion::V2)
testUpdateLicense($version=ApiVersion::V2)
testGetAllLicenseFilters($version=ApiVersion::V2)
testHandleLicenseStandardCommentExists()
testGetAllLicenseBoundsV2()
setUp()
Setup test objects.
tearDown()
Remove test objects.
translateLicenseToDb($licenses)
getRequestWithBody($method, $body)
testDeleteAdminLicenseCandidateIsAdmin()
testGetAllLicenseStandardComments()
getDaoLicense($shortname)
testGetAllLicenseFiltersV2()
testExportAdminLicenseToCSV()
testHandleLicenseStandardCommentNoPermission()
testUpdateLicenseNonAdminV2()
testMergeLicenseInternalServerError()
testHandleAdminLicenseAcknowledgementBadRequest()
testHandleLicenseStandardComment()
testHandleLicenseStandardCommentWithUpdate()
getLicense($shortname, $obligations=false, $emptyObligation=true)
testGetAllAdminAcknowledgements()
testUpdateLicenseNonAdmin($version=ApiVersion::V2)
testGetLicenseObligations()
testGetCandidatesNoAdminV2()
testVerifyLicenseNotAdmin()
testDeleteAdminLicenseCandidateNotAdmin()
testMergeLicenseWithBadRequest()
testUpdateLicenseNonAdvisor($version=ApiVersion::V2)
testGetAllAdminAcknowledgementsNotAdmin()
testHandleAdminLicenseAcknowledgementCreateNew()
testVerifyNotFoundLicense()
testDeleteAdminLicenseCandidateNotFound()
testGetCandidatesNoAdmin($version=ApiVersion::V2)
fo_dbManager * dbManager
fo_dbManager object