FOSSology  4.4.0
Open Source License Compliance by Open Source Software
ScanOptionsTest.php
Go to the documentation of this file.
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2021 Siemens AG
4  Author: Gaurav Mishra <mishra.gaurav@siemens.com>
5 
6  SPDX-License-Identifier: GPL-2.0-only
7 */
14 {
15  use Mockery as M;
23  use Symfony\Component\HttpFoundation\Request;
24 
29  class ScanOptionsTest extends \PHPUnit\Framework\TestCase
30  {
35  public static $functions;
36 
41  private $agentAdderMock;
42 
47  private $userDao;
48 
53  public function setUp() : void
54  {
55  global $container;
56  $container = M::mock('ContainerBuilder');
57  $this->agentAdderMock = M::mock('overload:\AgentAdder');
58  $this->userDao = M::mock(UserDao::class);
59  $container->shouldReceive('get')->withArgs(["dao.user"])
60  ->andReturn($this->userDao);
61  $container->shouldReceive('get')->andReturn(null);
62 
63  self::$functions = M::mock(\stdClass::class);
64  self::$functions->shouldReceive('FolderListUploads_perm')
65  ->withArgs([2, Auth::PERM_WRITE])->andReturn([
66  ['upload_pk' => 2],
67  ['upload_pk' => 3],
68  ['upload_pk' => 4]
69  ]);
70  self::$functions->shouldReceive('register_plugin')
71  ->with(\Hamcrest\Matchers::identicalTo(
72  new ScanOptions(null, null, null, null)));
73  }
74 
82  private function prepareRequest($request, $reuserOpts, $deciderOpts)
83  {
84  if (!empty($reuserOpts)) {
85  $reuserSelector = $reuserOpts['upload'] . "," . $reuserOpts['group'];
86  $request->request->set('uploadToReuse', $reuserSelector);
87  if (key_exists('rules', $reuserOpts)) {
88  $request->request->set('reuseMode', $reuserOpts['rules']);
89  }
90  }
91  if (!empty($deciderOpts)) {
92  $request->request->set('deciderRules', $deciderOpts);
93  if (in_array('nomosInMonk', $deciderOpts)) {
94  $request->request->set('Check_agent_nomos', 1);
95  }
96  }
97  return $request;
98  }
99 
106  public function testScheduleAgents()
107  {
108  $reuseUploadId = 2;
109  $uploadId = 4;
110  $folderId = 2;
111  $groupId = 2;
112  $groupName = "fossy";
113  $agentsToAdd = ['agent_nomos', 'agent_ojo', 'agent_monk'];
114  $reuserOpts = [
115  'upload' => $reuseUploadId,
116  'group' => $groupId,
117  'rules' => []
118  ];
119  $deciderOpts = [
120  'nomosInMonk',
121  'ojoNoContradiction'
122  ];
123  $request = new Request();
124  $request = $this->prepareRequest($request, $reuserOpts, $deciderOpts);
125 
126  $analysis = new Analysis();
127  $analysis->setUsingString("nomos,ojo,monk");
128 
129  $reuse = new Reuser($reuseUploadId, $groupName);
130 
131  $decider = new Decider();
132  $decider->setOjoDecider(true);
133  $decider->setNomosMonk(true);
134  $decider->setConcludeLicenseType("Permissive");
135 
136  $scancode = new Scancode();
137 
138  $scanOption = new ScanOptions($analysis, $reuse, $decider, $scancode);
139 
140  $this->userDao->shouldReceive('getGroupIdByName')
141  ->withArgs([$groupName])->andReturn($groupId);
142  $this->agentAdderMock->shouldReceive('scheduleAgents')
143  ->once()
144  ->andReturn(25);
145 
146  $scanOption->scheduleAgents($folderId, $uploadId);
147  }
148  }
149 }
150 
151 namespace Fossology\UI\Api\Models
152 {
153  function register_plugin($obj)
154  {
155  return \Fossology\Ui\Api\Test\Models\ScanOptionsTest::$functions
156  ->register_plugin($obj);
157  }
158 
159  function FolderListUploads_perm($parentFolder, $perm)
160  {
161  return \Fossology\Ui\Api\Test\Models\ScanOptionsTest::$functions
162  ->FolderListUploads_perm($parentFolder, $perm);
163  }
164 }
Contains the constants and helpers for authentication of user.
Definition: Auth.php:24
Model to hold analysis settings.
Definition: Analysis.php:21
Model to hold info required by Reuser agent.
Definition: Reuser.php:18
Model to hold add settings for new scan.
Definition: ScanOptions.php:30
prepareRequest($request, $reuserOpts, $deciderOpts)
FolderListUploads_perm($ParentFolder, $perm)
Returns an array of uploads in a folder.