2012-05-07 19:34:25 +00:00
|
|
|
<?php
|
|
|
|
namespace Composer\Test\Util;
|
|
|
|
|
|
|
|
use Composer\Test\TestCase;
|
2012-05-12 15:10:28 +00:00
|
|
|
use Composer\Util\SpdxLicenseIdentifier;
|
2012-05-07 19:34:25 +00:00
|
|
|
|
2012-05-12 15:10:28 +00:00
|
|
|
class SpdxLicenseIdentifierTest extends TestCase
|
2012-05-07 19:34:25 +00:00
|
|
|
{
|
|
|
|
public static function provideValidLicenses()
|
|
|
|
{
|
|
|
|
$valid = array_merge(
|
|
|
|
array(
|
|
|
|
"MIT",
|
|
|
|
"NONE",
|
|
|
|
"NOASSERTION",
|
|
|
|
"LicenseRef-3",
|
|
|
|
array("LGPL-2.0", "GPL-3.0+"),
|
|
|
|
"(LGPL-2.0 or GPL-3.0+)",
|
|
|
|
"(EUDatagrid and GPL-3.0+)",
|
|
|
|
),
|
|
|
|
json_decode(file_get_contents(__DIR__ . '/../../../../res/spdx-identifier.json'))
|
|
|
|
);
|
|
|
|
|
|
|
|
foreach ($valid as &$r) {
|
|
|
|
$r = array($r);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $valid;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function provideInvalidLicenses()
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
array(""),
|
2012-05-12 22:41:15 +00:00
|
|
|
array(array()),
|
2012-05-07 19:34:25 +00:00
|
|
|
array("The system pwns you"),
|
|
|
|
array("()"),
|
|
|
|
array("(MIT)"),
|
|
|
|
array("MIT NONE"),
|
|
|
|
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+)"),
|
|
|
|
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)"),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2012-05-12 22:41:15 +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
|
|
|
{
|
2012-05-12 15:10:28 +00:00
|
|
|
$validator = new SpdxLicenseIdentifier();
|
|
|
|
$this->assertTrue($validator->validate($license));
|
2012-05-07 19:34:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider provideInvalidLicenses
|
|
|
|
* @param string|array $invalidLicense
|
|
|
|
*/
|
|
|
|
public function testInvalidLicenses($invalidLicense)
|
|
|
|
{
|
2012-05-12 15:10:28 +00:00
|
|
|
$validator = new SpdxLicenseIdentifier();
|
|
|
|
$this->assertFalse($validator->validate($invalidLicense));
|
2012-05-07 19:34:25 +00:00
|
|
|
}
|
|
|
|
|
2012-05-12 15:10:28 +00:00
|
|
|
/**
|
2012-05-12 22:41:15 +00:00
|
|
|
* @dataProvider provideInvalidArgument
|
2012-05-12 15:10:28 +00:00
|
|
|
* @expectedException InvalidArgumentException
|
|
|
|
*/
|
2012-05-12 22:41:15 +00:00
|
|
|
public function testInvalidArgument($invalidArgument)
|
2012-05-07 19:34:25 +00:00
|
|
|
{
|
2012-05-12 15:10:28 +00:00
|
|
|
$validator = new SpdxLicenseIdentifier();
|
2012-05-12 22:41:15 +00:00
|
|
|
$validator->validate($invalidArgument);
|
2012-05-07 19:34:25 +00:00
|
|
|
}
|
2012-06-14 10:10:01 +00:00
|
|
|
}
|