1
0
Fork 0
composer/tests/Composer/Test/Util/SpdxLicenseTest.php

146 lines
4.1 KiB
PHP
Raw Normal View History

2012-05-07 19:34:25 +00:00
<?php
namespace Composer\Test\Util;
2013-09-25 08:14:42 +00:00
use Composer\TestCase;
use Composer\Util\SpdxLicense;
2012-05-07 19:34:25 +00:00
class SpdxLicenseTest extends TestCase
2012-05-07 19:34:25 +00:00
{
/**
* @var object
*/
private $license;
public function setUp()
{
$this->license = new SpdxLicense;
}
2012-05-07 19:34:25 +00:00
public static function provideValidLicenses()
{
$json = file_get_contents(__DIR__ . '/../../../../res/spdx-licenses.json');
$licenses = json_decode($json, true);
$identifiers = array_keys($licenses);
2012-05-07 19:34:25 +00:00
$valid = array_merge(
array(
"MIT",
2015-07-02 09:23:15 +00:00
"MIT+",
2012-05-07 19:34:25 +00:00
"NONE",
"NOASSERTION",
"LicenseRef-3",
array("LGPL-2.0", "GPL-3.0+"),
"(LGPL-2.0 or GPL-3.0+)",
2015-07-02 09:23:15 +00:00
"(LGPL-2.0 OR GPL-3.0+)",
2012-05-07 19:34:25 +00:00
"(EUDatagrid and GPL-3.0+)",
2015-07-02 09:23:15 +00:00
"(EUDatagrid AND GPL-3.0+)",
"GPL-2.0 with Autoconf-exception-2.0",
"GPL-2.0 WITH Autoconf-exception-2.0",
"GPL-2.0+ WITH Autoconf-exception-2.0",
2012-05-07 19:34:25 +00:00
),
$identifiers
2012-05-07 19:34:25 +00:00
);
foreach ($valid as &$r) {
$r = array($r);
}
return $valid;
}
public static function provideInvalidLicenses()
{
return array(
array(""),
array(array()),
2012-05-07 19:34:25 +00:00
array("The system pwns you"),
array("()"),
array("(MIT)"),
2015-07-02 09:23:15 +00:00
array("(MIT"),
array("MIT)"),
2012-05-07 19:34:25 +00:00
array("MIT NONE"),
2015-07-02 09:23:15 +00:00
array("MIT AND NONE"),
2012-05-07 19:34:25 +00:00
array("MIT (MIT and MIT)"),
array("(MIT and MIT) MIT"),
array(array("LGPL-2.0", "The system pwns you")),
array("and GPL-3.0+"),
array("EUDatagrid and GPL-3.0+"),
array("(GPL-3.0 and GPL-2.0 or GPL-3.0+)"),
2012-05-07 19:34:25 +00:00
array("(EUDatagrid and GPL-3.0+ and )"),
array("(EUDatagrid xor GPL-3.0+)"),
array("(MIT Or MIT)"),
array("(NONE or MIT)"),
array("(NOASSERTION or MIT)"),
2015-07-02 09:23:15 +00:00
array("Autoconf-exception-2.0 WITH MIT"),
array("MIT WITH"),
array("MIT OR"),
array("MIT AND"),
2012-05-07 19:34:25 +00:00
);
}
public static function provideInvalidArgument()
{
return array(
array(null),
array(new \stdClass),
array(array(new \stdClass)),
array(array("mixed", new \stdClass)),
array(array(new \stdClass, new \stdClass)),
);
}
2012-05-07 19:34:25 +00:00
/**
* @dataProvider provideValidLicenses
* @param $license
*/
2012-05-12 15:10:28 +00:00
public function testValidate($license)
2012-05-07 19:34:25 +00:00
{
$this->assertTrue($this->license->validate($license));
2012-05-07 19:34:25 +00:00
}
/**
* @dataProvider provideInvalidLicenses
* @param string|array $invalidLicense
*/
public function testInvalidLicenses($invalidLicense)
{
$this->assertFalse($this->license->validate($invalidLicense));
2012-05-07 19:34:25 +00:00
}
2012-05-12 15:10:28 +00:00
/**
* @dataProvider provideInvalidArgument
2012-05-12 15:10:28 +00:00
* @expectedException InvalidArgumentException
*/
public function testInvalidArgument($invalidArgument)
2012-05-07 19:34:25 +00:00
{
$this->license->validate($invalidArgument);
}
public function testGetLicenseByIdentifier()
{
$license = $this->license->getLicenseByIdentifier('AGPL-1.0');
$this->assertEquals($license[0], 'Affero General Public License v1.0'); // fullname
$this->assertFalse($license[1]); // osi approved
}
public function testGetIdentifierByName()
{
$identifier = $this->license->getIdentifierByName('Affero General Public License v1.0');
$this->assertEquals($identifier, 'AGPL-1.0');
$identifier = $this->license->getIdentifierByName('BSD 2-clause "Simplified" License');
$this->assertEquals($identifier, 'BSD-2-Clause');
}
public function testIsOsiApprovedByIdentifier()
{
$osiApproved = $this->license->isOsiApprovedByIdentifier('MIT');
$this->assertTrue($osiApproved);
$osiApproved = $this->license->isOsiApprovedByIdentifier('AGPL-1.0');
$this->assertFalse($osiApproved);
2012-05-07 19:34:25 +00:00
}
2012-06-14 10:10:01 +00:00
}