FOSSology  4.5.1
Open Source License Compliance by Open Source Software
DeciderTest.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 */
14 
17 
22 class DeciderTest extends \PHPUnit\Framework\TestCase
23 {
25 
31  public function testConstructor()
32  {
33  $decider = new Decider(
34  true,
35  false,
36  true,
37  false,
38  'GPL-3.0'
39  );
40  $this->assertInstanceOf(Decider::class, $decider);
41  }
42 
49  public function testSetUsingArrayV1()
50  {
51  $this->testSetUsingArray(ApiVersion::V1);
52  }
53 
60  public function testSetUsingArrayV2()
61  {
62  $this->testSetUsingArray(ApiVersion::V2);
63  }
64 
70  private function testSetUsingArray($version)
71  {
72  if ($version == ApiVersion::V1) {
73  $deciderArray = [
74  "nomos_monk" => true,
75  "bulk_reused" => false,
76  "ojo_decider" => (1==1),
77  "conclude_license_type" => " Permissive ",
78  "copyright_deactivation" => false,
79  "copyright_clutter_removal" => true
80  ];
81  } else {
82  $deciderArray = [
83  "nomosMonk" => true,
84  "bulkReused" => false,
85  "ojoDecider" => (1==1),
86  "concludeLicenseType" => " Permissive ",
87  "copyrightDeactivation" => false,
88  "copyrightClutterRemoval" => true
89  ];
90  }
91 
92  $expectedObject = new Decider(true, false, false, true, "Permissive", false, true);
93 
94  $actualObject = new Decider();
95  $actualObject->setUsingArray($deciderArray, $version);
96 
97  $this->assertEquals($expectedObject, $actualObject);
98  }
99 
106  public function testDataFormatV1()
107  {
108  $this->testDataFormat(ApiVersion::V1);
109  }
110 
117  public function testDataFormatV2()
118  {
119  $this->testDataFormat(ApiVersion::V2);
120  }
121 
127  private function testDataFormat($version)
128  {
129  if ($version == ApiVersion::V1) {
130  $expectedArray = [
131  "nomos_monk" => true,
132  "bulk_reused" => false,
133  "new_scanner" => false,
134  "ojo_decider" => true,
135  "conclude_license_type" => "Permissive",
136  "copyright_deactivation" => false,
137  "copyright_clutter_removal" => false
138  ];
139  } else {
140  $expectedArray = [
141  "nomosMonk" => true,
142  "bulkReused" => false,
143  "newScanner" => false,
144  "ojoDecider" => true,
145  "concludeLicenseType" => "Permissive",
146  "copyrightDeactivation" => false,
147  "copyrightClutterRemoval" => false
148  ];
149  }
150 
151  $actualObject = new Decider();
152  $actualObject->setNomosMonk(true);
153  $actualObject->setOjoDecider(true);
154  $actualObject->setConcludeLicenseType(" Permissive ");
155 
156  $this->assertEquals($expectedArray, $actualObject->getArray($version));
157  }
158 }