FOSSology  4.7.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 {
31 
37  public function testConstructor()
38  {
39  $analysis = new Analysis();
40  $this->assertInstanceOf(Analysis::class, $analysis);
41  }
42 
48  public function testSetUsingArrayV1()
49  {
50  $this->testSetUsingArray(ApiVersion::V1);
51  }
52 
58  public function testSetUsingArrayV2()
59  {
60  $this->testSetUsingArray(ApiVersion::V2);
61  }
62 
68  private function testSetUsingArray($version)
69  {
70  if ($version == ApiVersion::V2) {
71  $analysisArray = [
72  "bucket" => true,
73  "copyrightEmailAuthor" => "true",
74  "ecc" => 1,
75  "keyword" => (1==1),
76  "mime" => false,
77  "monk" => "false",
78  "nomos" => 0,
79  "ojo" => (1==2),
80  "scanoss" => true,
81  "reso" => true,
82  "pkgagent" => false,
83  "ipra" => true,
84  "softwareHeritage" => true,
85  "compatibility" => false
86  ];
87  } else {
88  $analysisArray = [
89  "bucket" => true,
90  "copyright_email_author" => "true",
91  "ecc" => 1,
92  "keyword" => (1==1),
93  "mime" => false,
94  "monk" => "false",
95  "nomos" => 0,
96  "ojo" => (1==2),
97  "scanoss" => true,
98  "reso" => true,
99  "package" => false,
100  "patent" => true,
101  "heritage" => true,
102  "compatibility" => false
103  ];
104  }
105 
106  $expectedObject = new Analysis(true, true, true, true, false, false, false, false, true, false, false, true, true, true);
107 
108  $actualObject = new Analysis();
109  $actualObject->setUsingArray($analysisArray, $version);
110 
111  $this->assertEquals($expectedObject, $actualObject);
112  }
113 
120  public function testSetUsingString()
121  {
122  $analysisString = "bucket, ecc, keyword, scanoss, ipra, softwareHeritage";
123 
124  $expectedObject = new Analysis();
125  $expectedObject->setBucket(true);
126  $expectedObject->setEcc(true);
127  $expectedObject->setKeyword(true);
128  $expectedObject->setScanoss(true);
129  $expectedObject->setIpra(true);
130  $expectedObject->setSoftwareHeritage(true);
131 
132  $actualObject = new Analysis();
133  $actualObject->setUsingString($analysisString);
134 
135  $this->assertEquals($expectedObject, $actualObject);
136  }
137 
145  public function testDataFormatV1()
146  {
147  $this->testDataFormat(ApiVersion::V1);
148  }
149 
157  public function testDataFormatV2()
158  {
159  $this->testDataFormat(ApiVersion::V2);
160  }
161 
167  private function testDataFormat($version)
168  {
169  if($version==ApiVersion::V2){
170  $expectedArray = [
171  "bucket" => true,
172  "copyrightEmailAuthor" => true,
173  "ecc" => true,
174  "keyword" => true,
175  "mimetype" => true,
176  "monk" => true,
177  "nomos" => true,
178  "ojo" => true,
179  "scanoss" => true,
180  "reso" => true,
181  "pkgagent" => true,
182  "ipra" => true,
183  "softwareHeritage" => true,
184  "compatibility" => true,
185  "kotoba" => true
186  ];
187  } else {
188  $expectedArray = [
189  "bucket" => true,
190  "copyright_email_author" => true,
191  "ecc" => true,
192  "keyword" => true,
193  "mimetype" => true,
194  "monk" => true,
195  "nomos" => true,
196  "ojo" => true,
197  "scanoss" => true,
198  "reso" => true,
199  "package" => true,
200  "patent" => true,
201  "heritage" => true,
202  "compatibility" => true,
203  "kotoba_bulk" => true
204  ];
205  }
206 
207  $actualObject = new Analysis(true, true, true, true, true, true, true, true, true, true, true, true, true, true, true);
208 
209  $this->assertEquals($expectedArray, $actualObject->getArray($version));
210  }
211 
213 
218  public function testGetBucket()
219  {
220  $analysis = new Analysis(true);
221  $this->assertTrue($analysis->getBucket());
222  }
223 
228  public function testSetBucket()
229  {
230  $analysis = new Analysis();
231  $analysis->setBucket(true);
232  $this->assertTrue($analysis->getBucket());
233  }
234 
239  public function testGetCopyright()
240  {
241  $analysis = new Analysis(false, true);
242  $this->assertTrue($analysis->getCopyright());
243  }
244 
249  public function testSetCopyright()
250  {
251  $analysis = new Analysis();
252  $analysis->setCopyright(true);
253  $this->assertTrue($analysis->getCopyright());
254  }
255 
260  public function testGetEcc()
261  {
262  $analysis = new Analysis(false, false, true);
263  $this->assertTrue($analysis->getEcc());
264  }
265 
270  public function testSetEcc()
271  {
272  $analysis = new Analysis();
273  $analysis->setEcc(true);
274  $this->assertTrue($analysis->getEcc());
275  }
276 
281  public function testGetKeyword()
282  {
283  $analysis = new Analysis(false, false, false, true);
284  $this->assertTrue($analysis->getKeyword());
285  }
286 
291  public function testSetKeyword()
292  {
293  $analysis = new Analysis();
294  $analysis->setKeyword(true);
295  $this->assertTrue($analysis->getKeyword());
296  }
297 
302  public function testGetMime()
303  {
304  $analysis = new Analysis(false, false, false, false, true);
305  $this->assertTrue($analysis->getMime());
306  }
307 
312  public function testSetMime()
313  {
314  $analysis = new Analysis();
315  $analysis->setMime(true);
316  $this->assertTrue($analysis->getMime());
317  }
318 
323  public function testGetMonk()
324  {
325  $analysis = new Analysis(false, false, false, false, false, true);
326  $this->assertTrue($analysis->getMonk());
327  }
328 
329  public function testScanoss()
330  {
331  $analysis = new Analysis();
332  $analysis->setScanoss(true);
333  $this->assertTrue($analysis->getScanoss());
334  }
335 
336  public function testIpra()
337  {
338  $analysis = new Analysis();
339  $analysis->setIpra(true);
340  $this->assertTrue($analysis->getIpra());
341  }
342 
343  public function testSoftwareHeritage()
344  {
345  $analysis = new Analysis();
346  $analysis->setSoftwareHeritage(true);
347  $this->assertTrue($analysis->getSoftwareHeritage());
348  }
349 
350  public function testPkgagent()
351  {
352  $analysis = new Analysis();
353  $analysis->setPkgagent(true);
354  $this->assertTrue($analysis->getPkgagent());
355  }
356 
357  public function testCompatibility()
358  {
359  $analysis = new Analysis();
360  $analysis->setCompatibility(true);
361  $this->assertTrue($analysis->getCompatibility());
362  }
363 }
Model to hold analysis settings.
Definition: Analysis.php:21