FOSSology  4.4.0
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 {
27  public function testDataFormat()
28  {
29  $expectedLicense = [
30  'id' => 22,
31  'shortName' => "MIT",
32  'fullName' => "MIT License",
33  'text' => "MIT License Copyright (c) <year> <copyright holders> ...",
34  'url' => "https://opensource.org/licenses/MIT",
35  'risk' => 3,
36  'isCandidate' => false,
37  'obligations' => []
38  ];
39 
40  $actualLicense = new License(22, "MIT", "MIT License",
41  "MIT License Copyright (c) <year> <copyright holders> ...",
42  "https://opensource.org/licenses/MIT", [], 3, false);
43 
44  $this->assertEquals($expectedLicense, $actualLicense->getArray());
45  }
46 
52  public function testDataFormatNoObligation()
53  {
54  $expectedLicense = [
55  'id' => 22,
56  'shortName' => "MIT",
57  'fullName' => "MIT License",
58  'text' => "MIT License Copyright (c) <year> <copyright holders> ...",
59  'url' => "https://opensource.org/licenses/MIT",
60  'risk' => 3,
61  'isCandidate' => true
62  ];
63 
64  $actualLicense = new License(22, "MIT", "MIT License",
65  "MIT License Copyright (c) <year> <copyright holders> ...",
66  "https://opensource.org/licenses/MIT", null, 3, true);
67 
68  $this->assertEquals($expectedLicense, $actualLicense->getArray());
69  }
70 
77  public function testArrayParser()
78  {
79  $inputLicense = [
80  'shortName' => "MIT",
81  'fullName' => "MIT License",
82  'text' => "MIT License Copyright (c) <year> <copyright holders> ...",
83  'url' => "https://opensource.org/licenses/MIT"
84  ];
85 
86  $sampleLicense = new License(0, "MIT", "MIT License",
87  "MIT License Copyright (c) <year> <copyright holders> ...",
88  "https://opensource.org/licenses/MIT");
89 
90  $actualLicense = License::parseFromArray($inputLicense);
91 
92  $this->assertEquals($sampleLicense->getArray(), $actualLicense->getArray());
93 
94  $bogusInput = array_merge($inputLicense, ["invalidKey" => 123]);
95  $bogusLicense = License::parseFromArray($bogusInput);
96  $this->assertEquals(-1, $bogusLicense);
97  }
98 }
static parseFromArray($inputLicense)
Definition: License.php:338