FOSSology  4.5.1
Open Source License Compliance by Open Source Software
AnalysisTest.php
Go to the documentation of this file.
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2020 Siemens AG
4  Author: Gaurav Mishra <mishra.gaurav@siemens.com>
5 
6  SPDX-License-Identifier: GPL-2.0-only
7 */
20 
23 
28 class AnalysisTest extends \PHPUnit\Framework\TestCase
29 {
35  public function testSetUsingArrayV1()
36  {
37  $this->testSetUsingArray(ApiVersion::V1);
38  }
39 
45  public function testSetUsingArrayV2()
46  {
47  $this->testSetUsingArray(ApiVersion::V2);
48  }
49 
55  private function testSetUsingArray($version)
56  {
57  if ($version == ApiVersion::V2) {
58  $analysisArray = [
59  "bucket" => true,
60  "copyrightEmailAuthor" => "true",
61  "ecc" => 1,
62  "keyword" => (1==1),
63  "mime" => false,
64  "monk" => "false",
65  "nomos" => 0,
66  "ojo" => (1==2),
67  "scanoss" => true,
68  "reso" => true,
69  "pkgagent" => false,
70  "ipra" => true,
71  "softwareHeritage" => true,
72  "compatibility" => false
73  ];
74  } else {
75  $analysisArray = [
76  "bucket" => true,
77  "copyright_email_author" => "true",
78  "ecc" => 1,
79  "keyword" => (1==1),
80  "mime" => false,
81  "monk" => "false",
82  "nomos" => 0,
83  "ojo" => (1==2),
84  "scanoss" => true,
85  "reso" => true,
86  "package" => false,
87  "patent" => true,
88  "heritage" => true,
89  "compatibility" => false
90  ];
91  }
92 
93  $expectedObject = new Analysis(true, true, true, true, false, false, false, false, true, false, false, true, true, true);
94 
95  $actualObject = new Analysis();
96  $actualObject->setUsingArray($analysisArray, $version);
97 
98  $this->assertEquals($expectedObject, $actualObject);
99  }
100 
107  public function testSetUsingString()
108  {
109  $analysisString = "bucket, ecc, keyword, scanoss, ipra, softwareHeritage";
110 
111  $expectedObject = new Analysis();
112  $expectedObject->setBucket(true);
113  $expectedObject->setEcc(true);
114  $expectedObject->setKeyword(true);
115  $expectedObject->setScanoss(true);
116  $expectedObject->setIpra(true);
117  $expectedObject->setSoftwareHeritage(true);
118 
119  $actualObject = new Analysis();
120  $actualObject->setUsingString($analysisString);
121 
122  $this->assertEquals($expectedObject, $actualObject);
123  }
124 
132  public function testDataFormatV1()
133  {
134  $this->testDataFormat(ApiVersion::V1);
135  }
136 
144  public function testDataFormatV2()
145  {
146  $this->testDataFormat(ApiVersion::V2);
147  }
148 
154  private function testDataFormat($version)
155  {
156  if($version==ApiVersion::V2){
157  $expectedArray = [
158  "bucket" => true,
159  "copyrightEmailAuthor" => true,
160  "ecc" => true,
161  "keyword" => true,
162  "mimetype" => true,
163  "monk" => true,
164  "nomos" => true,
165  "ojo" => true,
166  "scanoss" => true,
167  "reso" => true,
168  "pkgagent" => true,
169  "ipra" => true,
170  "softwareHeritage" => true,
171  "compatibility" => true
172  ];
173  } else {
174  $expectedArray = [
175  "bucket" => true,
176  "copyright_email_author" => true,
177  "ecc" => true,
178  "keyword" => true,
179  "mimetype" => true,
180  "monk" => true,
181  "nomos" => true,
182  "ojo" => true,
183  "scanoss" => true,
184  "reso" => true,
185  "package" => true,
186  "patent" => true,
187  "heritage" => true,
188  "compatibility" => true
189  ];
190  }
191 
192  $actualObject = new Analysis(true, true, true, true, true, true, true, true, true, true, true, true, true, true);
193 
194  $this->assertEquals($expectedArray, $actualObject->getArray($version));
195  }
196 
198 
203  public function testGetBucket()
204  {
205  $analysis = new Analysis(true);
206  $this->assertTrue($analysis->getBucket());
207  }
208 
213  public function testSetBucket()
214  {
215  $analysis = new Analysis();
216  $analysis->setBucket(true);
217  $this->assertTrue($analysis->getBucket());
218  }
219 
224  public function testGetCopyright()
225  {
226  $analysis = new Analysis(false, true);
227  $this->assertTrue($analysis->getCopyright());
228  }
229 
234  public function testSetCopyright()
235  {
236  $analysis = new Analysis();
237  $analysis->setCopyright(true);
238  $this->assertTrue($analysis->getCopyright());
239  }
240 
245  public function testGetEcc()
246  {
247  $analysis = new Analysis(false, false, true);
248  $this->assertTrue($analysis->getEcc());
249  }
250 
255  public function testSetEcc()
256  {
257  $analysis = new Analysis();
258  $analysis->setEcc(true);
259  $this->assertTrue($analysis->getEcc());
260  }
261 
266  public function testGetKeyword()
267  {
268  $analysis = new Analysis(false, false, false, true);
269  $this->assertTrue($analysis->getKeyword());
270  }
271 
276  public function testSetKeyword()
277  {
278  $analysis = new Analysis();
279  $analysis->setKeyword(true);
280  $this->assertTrue($analysis->getKeyword());
281  }
282 
287  public function testGetMime()
288  {
289  $analysis = new Analysis(false, false, false, false, true);
290  $this->assertTrue($analysis->getMime());
291  }
292 
297  public function testSetMime()
298  {
299  $analysis = new Analysis();
300  $analysis->setMime(true);
301  $this->assertTrue($analysis->getMime());
302  }
303 
308  public function testGetMonk()
309  {
310  $analysis = new Analysis(false, false, false, false, false, true);
311  $this->assertTrue($analysis->getMonk());
312  }
313 
314  public function testScanoss()
315  {
316  $analysis = new Analysis();
317  $analysis->setScanoss(true);
318  $this->assertTrue($analysis->getScanoss());
319  }
320 
321  public function testIpra()
322  {
323  $analysis = new Analysis();
324  $analysis->setIpra(true);
325  $this->assertTrue($analysis->getIpra());
326  }
327 
328  public function testSoftwareHeritage()
329  {
330  $analysis = new Analysis();
331  $analysis->setSoftwareHeritage(true);
332  $this->assertTrue($analysis->getSoftwareHeritage());
333  }
334 
335  public function testPkgagent()
336  {
337  $analysis = new Analysis();
338  $analysis->setPkgagent(true);
339  $this->assertTrue($analysis->getPkgagent());
340  }
341 
342  public function testCompatibility()
343  {
344  $analysis = new Analysis();
345  $analysis->setCompatibility(true);
346  $this->assertTrue($analysis->getCompatibility());
347  }
348 }
Model to hold analysis settings.
Definition: Analysis.php:21