FOSSology  4.7.1
Open Source License Compliance by Open Source Software
ConfTest.php
Go to the documentation of this file.
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2025 Harshit Gandhi <gandhiharshit716@gmail.com>
4  SPDX-License-Identifier: GPL-2.0-only
5 */
6 
13 
16 use PHPUnit\Framework\TestCase;
17 
22 class ConfTest extends TestCase
23 {
25  private $sampleData;
26 
30  protected function setUp(): void
31  {
32  $this->sampleData = [
33  "ri_reviewed" => true,
34  "ri_footer" => "Test Footer",
35  "ri_report_rel" => "1.0.0",
36  "ri_community" => "Test Community",
37  "ri_component" => "Test Component",
38  "ri_version" => "1.0",
39  "ri_release_date" => "2025-02-15",
40  "ri_sw360_link" => "https://example.com",
41  "ri_component_type" => 1,
42  "ri_component_id" => "TEST-123",
43  "ri_general_assesment" => "Test Assessment",
44  "ri_ga_additional" => "Additional Notes",
45  "ri_ga_risk" => "Low",
46  "ri_ga_checkbox_selection" => "Option 1",
47  "ri_spdx_selection" => "MIT",
48  "ri_cyclonedx_selection" => '{"licenseComment":true,"ignoreFilesWithoutInfo":false,"osselotExport":false,"tagNamespace":"acme:","specVersion":"1.6"}',
49  "ri_excluded_obligations" => json_encode(["obligation1", "obligation2"]),
50  "ri_department" => "Test Department",
51  "ri_depnotes" => "Department Notes",
52  "ri_exportnotes" => "Export Notes",
53  "ri_copyrightnotes" => "Copyright Notes",
54  "ri_unifiedcolumns" => json_encode(["col1", "col2"]),
55  "ri_globaldecision" => 1
56  ];
57  }
58 
60 
66  public function testConstructor()
67  {
68  $conf = new Conf();
69  $this->assertInstanceOf(Conf::class, $conf);
70  }
71 
76  public function testGetArray()
77  {
78  $conf = new Conf($this->sampleData);
79  $result = $conf->getArray();
80 
81  $this->assertIsArray($result);
82  $this->assertEquals(true, $result['reviewed']);
83  $this->assertEquals("Test Footer", $result['footer']);
84  $this->assertEquals("1.0.0", $result['reportRel']);
85  $this->assertEquals("Test Community", $result['community']);
86  $this->assertEquals("Test Component", $result['component']);
87  $this->assertEquals("1.0", $result['version']);
88  $this->assertEquals("2025-02-15", $result['releaseDate']);
89  $this->assertEquals("https://example.com", $result['sw360Link']);
90  $this->assertEquals(ComponentType::TYPE_MAP[1], $result['componentType']);
91  $this->assertEquals("TEST-123", $result['componentId']);
92  $this->assertEquals("Test Assessment", $result['generalAssesment']);
93  $this->assertEquals("Additional Notes", $result['gaAdditional']);
94  $this->assertEquals("Low", $result['gaRisk']);
95  $this->assertEquals("Option 1", $result['gaCheckbox']);
96  $this->assertEquals("MIT", $result['spdxSelection']);
97  $this->assertEquals("acme:", $result['cyclonedxSelection']['tagNamespace']);
98  $this->assertEquals("1.6", $result['cyclonedxSelection']['specVersion']);
99  $this->assertTrue($result['cyclonedxSelection']['licenseComment']);
100  $this->assertEquals(["obligation1", "obligation2"], $result['excludedObligations']);
101  $this->assertEquals("Test Department", $result['department']);
102  $this->assertEquals("Department Notes", $result['depNotes']);
103  $this->assertEquals("Export Notes", $result['exportNotes']);
104  $this->assertEquals("Copyright Notes", $result['copyrightNotes']);
105  $this->assertEquals(["col1", "col2"], $result['unifiedColumns']);
106  $this->assertEquals(true, $result['globalDecision']);
107  }
108 
113  public function testGetJson()
114  {
115  $conf = new Conf($this->sampleData);
116  $result = $conf->getJSON();
117 
118  $this->assertIsString($result);
119  $this->assertJson($result);
120 
121  $decodedJson = json_decode($result, true);
122  $this->assertEquals($conf->getArray(), $decodedJson);
123  }
124 
129  public function testGetKeyColumnName()
130  {
131  $conf = new Conf();
132 
133  $this->assertEquals("ri_reviewed", $conf->getKeyColumnName("reviewed"));
134  $this->assertEquals("ri_footer", $conf->getKeyColumnName("footer"));
135  $this->assertEquals("ri_component_type", $conf->getKeyColumnName("componentType"));
136  $this->assertEquals("ri_globaldecision", $conf->getKeyColumnName("globalDecision"));
137  }
138 
143  public function testDoesKeyExistValidKeys()
144  {
145  $conf = new Conf();
146 
147  $this->assertTrue($conf->doesKeyExist("reviewed"));
148  $this->assertTrue($conf->doesKeyExist("footer"));
149  $this->assertTrue($conf->doesKeyExist("componentType"));
150  $this->assertTrue($conf->doesKeyExist("globalDecision"));
151  }
152 
157  public function testDoesKeyExistInvalidKeys()
158  {
159  $conf = new Conf();
160 
161  $this->assertFalse($conf->doesKeyExist("invalidKey"));
162  $this->assertFalse($conf->doesKeyExist(""));
163  $this->assertFalse($conf->doesKeyExist("123"));
164  }
165 }
Conf model to contain general error and return values.
Definition: Conf.php:23