SpdxLicenseIdentifierTest.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace Composer\Test\Util;
  3. use Composer\Test\TestCase;
  4. use Composer\Util\SpdxLicenseIdentifier;
  5. class SpdxLicenseIdentifierTest extends TestCase
  6. {
  7. public static function provideValidLicenses()
  8. {
  9. $valid = array_merge(
  10. array(
  11. "MIT",
  12. "NONE",
  13. "NOASSERTION",
  14. "LicenseRef-3",
  15. array("LGPL-2.0", "GPL-3.0+"),
  16. "(LGPL-2.0 or GPL-3.0+)",
  17. "(EUDatagrid and GPL-3.0+)",
  18. ),
  19. json_decode(file_get_contents(__DIR__ . '/../../../../res/spdx-identifier.json'))
  20. );
  21. foreach ($valid as &$r) {
  22. $r = array($r);
  23. }
  24. return $valid;
  25. }
  26. public static function provideInvalidLicenses()
  27. {
  28. return array(
  29. array(""),
  30. array("The system pwns you"),
  31. array("()"),
  32. array("(MIT)"),
  33. array("MIT NONE"),
  34. array("MIT (MIT and MIT)"),
  35. array("(MIT and MIT) MIT"),
  36. array(array("LGPL-2.0", "The system pwns you")),
  37. array("and GPL-3.0+"),
  38. array("EUDatagrid and GPL-3.0+"),
  39. array("(GPL-3.0 and GPL-2.0 or GPL-3.0+)"),
  40. array("(EUDatagrid and GPL-3.0+ and )"),
  41. array("(EUDatagrid xor GPL-3.0+)"),
  42. array("(MIT Or MIT)"),
  43. array("(NONE or MIT)"),
  44. array("(NOASSERTION or MIT)"),
  45. );
  46. }
  47. /**
  48. * @dataProvider provideValidLicenses
  49. * @param $license
  50. */
  51. public function testValidate($license)
  52. {
  53. $validator = new SpdxLicenseIdentifier();
  54. $this->assertTrue($validator->validate($license));
  55. }
  56. /**
  57. * @dataProvider provideInvalidLicenses
  58. * @param string|array $invalidLicense
  59. */
  60. public function testInvalidLicenses($invalidLicense)
  61. {
  62. $validator = new SpdxLicenseIdentifier();
  63. $this->assertFalse($validator->validate($invalidLicense));
  64. }
  65. /**
  66. * @expectedException InvalidArgumentException
  67. */
  68. public function testInvalidArgument()
  69. {
  70. $validator = new SpdxLicenseIdentifier();
  71. $validator->validate(null);
  72. }
  73. }