FOSSology  4.5.1
Open Source License Compliance by Open Source Software
LicenseTest.php
Go to the documentation of this file.
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2021 Siemens AG
4  Author: Gaurav Mishra <mishra.gaurav@siemens.com>
5 
6  SPDX-License-Identifier: GPL-2.0-only
7 */
14 
16 
21 class LicenseTest extends \PHPUnit\Framework\TestCase
22 {
24 
30  public function testConstructor()
31  {
32  $license = new License(22, "MIT", "MIT License",
33  "MIT License Copyright (c) <year> <copyright holders> ...",
34  "https://opensource.org/licenses/MIT", [], 3, false);
35  $this->assertInstanceOf(License::class, $license);
36  }
37 
42  public function testDataFormat()
43  {
44  $expectedLicense = [
45  'id' => 22,
46  'shortName' => "MIT",
47  'fullName' => "MIT License",
48  'text' => "MIT License Copyright (c) <year> <copyright holders> ...",
49  'url' => "https://opensource.org/licenses/MIT",
50  'risk' => 3,
51  'isCandidate' => false,
52  'obligations' => []
53  ];
54 
55  $actualLicense = new License(22, "MIT", "MIT License",
56  "MIT License Copyright (c) <year> <copyright holders> ...",
57  "https://opensource.org/licenses/MIT", [], 3, false);
58 
59  $this->assertEquals($expectedLicense, $actualLicense->getArray());
60  }
61 
67  public function testDataFormatNoObligation()
68  {
69  $expectedLicense = [
70  'id' => 22,
71  'shortName' => "MIT",
72  'fullName' => "MIT License",
73  'text' => "MIT License Copyright (c) <year> <copyright holders> ...",
74  'url' => "https://opensource.org/licenses/MIT",
75  'risk' => 3,
76  'isCandidate' => true
77  ];
78 
79  $actualLicense = new License(22, "MIT", "MIT License",
80  "MIT License Copyright (c) <year> <copyright holders> ...",
81  "https://opensource.org/licenses/MIT", null, 3, true);
82 
83  $this->assertEquals($expectedLicense, $actualLicense->getArray());
84  }
85 
92  public function testArrayParser()
93  {
94  $inputLicense = [
95  'shortName' => "MIT",
96  'fullName' => "MIT License",
97  'text' => "MIT License Copyright (c) <year> <copyright holders> ...",
98  'url' => "https://opensource.org/licenses/MIT"
99  ];
100 
101  $sampleLicense = new License(0, "MIT", "MIT License",
102  "MIT License Copyright (c) <year> <copyright holders> ...",
103  "https://opensource.org/licenses/MIT");
104 
105  $actualLicense = License::parseFromArray($inputLicense);
106 
107  $this->assertEquals($sampleLicense->getArray(), $actualLicense->getArray());
108 
109  $bogusInput = array_merge($inputLicense, ["invalidKey" => 123]);
110  $bogusLicense = License::parseFromArray($bogusInput);
111  $this->assertEquals(-1, $bogusLicense);
112  }
113 }
static parseFromArray($inputLicense)
Definition: License.php:342