FOSSology  4.5.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_excluded_obligations" => json_encode(["obligation1", "obligation2"]),
49  "ri_department" => "Test Department",
50  "ri_depnotes" => "Department Notes",
51  "ri_exportnotes" => "Export Notes",
52  "ri_copyrightnotes" => "Copyright Notes",
53  "ri_unifiedcolumns" => json_encode(["col1", "col2"]),
54  "ri_globaldecision" => 1
55  ];
56  }
57 
59 
65  public function testConstructor()
66  {
67  $conf = new Conf();
68  $this->assertInstanceOf(Conf::class, $conf);
69  }
70 
75  public function testGetArray()
76  {
77  $conf = new Conf($this->sampleData);
78  $result = $conf->getArray();
79 
80  $this->assertIsArray($result);
81  $this->assertEquals(true, $result['reviewed']);
82  $this->assertEquals("Test Footer", $result['footer']);
83  $this->assertEquals("1.0.0", $result['reportRel']);
84  $this->assertEquals("Test Community", $result['community']);
85  $this->assertEquals("Test Component", $result['component']);
86  $this->assertEquals("1.0", $result['version']);
87  $this->assertEquals("2025-02-15", $result['releaseDate']);
88  $this->assertEquals("https://example.com", $result['sw360Link']);
89  $this->assertEquals(ComponentType::TYPE_MAP[1], $result['componentType']);
90  $this->assertEquals("TEST-123", $result['componentId']);
91  $this->assertEquals("Test Assessment", $result['generalAssesment']);
92  $this->assertEquals("Additional Notes", $result['gaAdditional']);
93  $this->assertEquals("Low", $result['gaRisk']);
94  $this->assertEquals("Option 1", $result['gaCheckbox']);
95  $this->assertEquals("MIT", $result['spdxSelection']);
96  $this->assertEquals(["obligation1", "obligation2"], $result['excludedObligations']);
97  $this->assertEquals("Test Department", $result['department']);
98  $this->assertEquals("Department Notes", $result['depNotes']);
99  $this->assertEquals("Export Notes", $result['exportNotes']);
100  $this->assertEquals("Copyright Notes", $result['copyrightNotes']);
101  $this->assertEquals(["col1", "col2"], $result['unifiedColumns']);
102  $this->assertEquals(true, $result['globalDecision']);
103  }
104 
109  public function testGetJson()
110  {
111  $conf = new Conf($this->sampleData);
112  $result = $conf->getJSON();
113 
114  $this->assertIsString($result);
115  $this->assertJson($result);
116 
117  $decodedJson = json_decode($result, true);
118  $this->assertEquals($conf->getArray(), $decodedJson);
119  }
120 
125  public function testGetKeyColumnName()
126  {
127  $conf = new Conf();
128 
129  $this->assertEquals("ri_reviewed", $conf->getKeyColumnName("reviewed"));
130  $this->assertEquals("ri_footer", $conf->getKeyColumnName("footer"));
131  $this->assertEquals("ri_component_type", $conf->getKeyColumnName("componentType"));
132  $this->assertEquals("ri_globaldecision", $conf->getKeyColumnName("globalDecision"));
133  }
134 
139  public function testDoesKeyExistValidKeys()
140  {
141  $conf = new Conf();
142 
143  $this->assertTrue($conf->doesKeyExist("reviewed"));
144  $this->assertTrue($conf->doesKeyExist("footer"));
145  $this->assertTrue($conf->doesKeyExist("componentType"));
146  $this->assertTrue($conf->doesKeyExist("globalDecision"));
147  }
148 
153  public function testDoesKeyExistInvalidKeys()
154  {
155  $conf = new Conf();
156 
157  $this->assertFalse($conf->doesKeyExist("invalidKey"));
158  $this->assertFalse($conf->doesKeyExist(""));
159  $this->assertFalse($conf->doesKeyExist("123"));
160  }
161 }
Conf model to contain general error and return values.
Definition: Conf.php:23