FOSSology  4.4.0
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  ];
68  } else {
69  $analysisArray = [
70  "bucket" => true,
71  "copyright_email_author" => "true",
72  "ecc" => 1,
73  "keyword" => (1==1),
74  "mime" => false,
75  "monk" => "false",
76  "nomos" => 0,
77  "ojo" => (1==2)
78  ];
79  }
80 
81  $expectedObject = new Analysis(true, true, true, true);
82 
83  $actualObject = new Analysis();
84  $actualObject->setUsingArray($analysisArray, $version);
85 
86  $this->assertEquals($expectedObject, $actualObject);
87  }
88 
95  public function testSetUsingString()
96  {
97  $analysisStringComma = "bucket, ecc, keyword";
98  $analysisStringSemi = "bucket;ecc;monk";
99 
100  $expectedObjectComma = new Analysis();
101  $expectedObjectComma->setBucket(true);
102  $expectedObjectComma->setEcc(true);
103  $expectedObjectComma->setKeyword(true);
104 
105  $expectedObjectSemi = new Analysis();
106  $expectedObjectSemi->setBucket(true);
107  $expectedObjectSemi->setEcc(true);
108  $expectedObjectSemi->setMonk(true);
109 
110  $actualObjectComma = new Analysis();
111  $actualObjectComma->setUsingString($analysisStringComma);
112  $actualObjectSemi = new Analysis();
113  $actualObjectSemi->setUsingString($analysisStringSemi);
114 
115  $this->assertEquals($expectedObjectComma, $actualObjectComma);
116  $this->assertEquals($expectedObjectSemi, $actualObjectSemi);
117  }
118 
126  public function testDataFormatV1()
127  {
128  $this->testDataFormat(ApiVersion::V1);
129  }
130 
138  public function testDataFormatV2()
139  {
140  $this->testDataFormat(ApiVersion::V2);
141  }
142 
148  private function testDataFormat($version)
149  {
150  if($version==ApiVersion::V2){
151  $expectedArray = [
152  "bucket" => true,
153  "copyrightEmailAuthor" => true,
154  "ecc" => false,
155  "keyword" => false,
156  "mimetype" => true,
157  "monk" => false,
158  "nomos" => true,
159  "ojo" => true,
160  "package" => false,
161  "reso" => true,
162  "compatibility" => false
163  ];
164  } else{
165  $expectedArray = [
166  "bucket" => true,
167  "copyright_email_author" => true,
168  "ecc" => false,
169  "keyword" => false,
170  "mimetype" => true,
171  "monk" => false,
172  "nomos" => true,
173  "ojo" => true,
174  "package" => false,
175  "reso" => true,
176  "compatibility" => false
177  ];
178  }
179  $actualObject = new Analysis();
180  $actualObject->setBucket(true);
181  $actualObject->setCopyright(true);
182  $actualObject->setMime(true);
183  $actualObject->setNomos(true);
184  $actualObject->setOjo(true);
185  $actualObject->setReso(true);
186 
187  $this->assertEquals($expectedArray, $actualObject->getArray($version));
188  }
189 }
Model to hold analysis settings.
Definition: Analysis.php:21