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 {
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  ];
186  } else {
187  $expectedArray = [
188  "bucket" => true,
189  "copyright_email_author" => true,
190  "ecc" => true,
191  "keyword" => true,
192  "mimetype" => true,
193  "monk" => true,
194  "nomos" => true,
195  "ojo" => true,
196  "scanoss" => true,
197  "reso" => true,
198  "package" => true,
199  "patent" => true,
200  "heritage" => true,
201  "compatibility" => true
202  ];
203  }
204 
205  $actualObject = new Analysis(true, true, true, true, true, true, true, true, true, true, true, true, true, true);
206 
207  $this->assertEquals($expectedArray, $actualObject->getArray($version));
208  }
209 
211 
216  public function testGetBucket()
217  {
218  $analysis = new Analysis(true);
219  $this->assertTrue($analysis->getBucket());
220  }
221 
226  public function testSetBucket()
227  {
228  $analysis = new Analysis();
229  $analysis->setBucket(true);
230  $this->assertTrue($analysis->getBucket());
231  }
232 
237  public function testGetCopyright()
238  {
239  $analysis = new Analysis(false, true);
240  $this->assertTrue($analysis->getCopyright());
241  }
242 
247  public function testSetCopyright()
248  {
249  $analysis = new Analysis();
250  $analysis->setCopyright(true);
251  $this->assertTrue($analysis->getCopyright());
252  }
253 
258  public function testGetEcc()
259  {
260  $analysis = new Analysis(false, false, true);
261  $this->assertTrue($analysis->getEcc());
262  }
263 
268  public function testSetEcc()
269  {
270  $analysis = new Analysis();
271  $analysis->setEcc(true);
272  $this->assertTrue($analysis->getEcc());
273  }
274 
279  public function testGetKeyword()
280  {
281  $analysis = new Analysis(false, false, false, true);
282  $this->assertTrue($analysis->getKeyword());
283  }
284 
289  public function testSetKeyword()
290  {
291  $analysis = new Analysis();
292  $analysis->setKeyword(true);
293  $this->assertTrue($analysis->getKeyword());
294  }
295 
300  public function testGetMime()
301  {
302  $analysis = new Analysis(false, false, false, false, true);
303  $this->assertTrue($analysis->getMime());
304  }
305 
310  public function testSetMime()
311  {
312  $analysis = new Analysis();
313  $analysis->setMime(true);
314  $this->assertTrue($analysis->getMime());
315  }
316 
321  public function testGetMonk()
322  {
323  $analysis = new Analysis(false, false, false, false, false, true);
324  $this->assertTrue($analysis->getMonk());
325  }
326 
327  public function testScanoss()
328  {
329  $analysis = new Analysis();
330  $analysis->setScanoss(true);
331  $this->assertTrue($analysis->getScanoss());
332  }
333 
334  public function testIpra()
335  {
336  $analysis = new Analysis();
337  $analysis->setIpra(true);
338  $this->assertTrue($analysis->getIpra());
339  }
340 
341  public function testSoftwareHeritage()
342  {
343  $analysis = new Analysis();
344  $analysis->setSoftwareHeritage(true);
345  $this->assertTrue($analysis->getSoftwareHeritage());
346  }
347 
348  public function testPkgagent()
349  {
350  $analysis = new Analysis();
351  $analysis->setPkgagent(true);
352  $this->assertTrue($analysis->getPkgagent());
353  }
354 
355  public function testCompatibility()
356  {
357  $analysis = new Analysis();
358  $analysis->setCompatibility(true);
359  $this->assertTrue($analysis->getCompatibility());
360  }
361 }
Model to hold analysis settings.
Definition: Analysis.php:21