Add bootstrapping for tests, add praise instead of warning in case of

attribution licenses
This commit is contained in:
2025-07-06 13:06:49 +02:00
parent a0621216ec
commit f66fd1d9a0
5 changed files with 142 additions and 17 deletions

View File

@ -7,10 +7,79 @@
declare(strict_types = 1);
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Small;
/**
* Tests for PUQI.
*/
#[small]
#[CoversClass(\MDPuqi::class)]
final class MDPuqiTest extends TestCase {
/**
* Provider for licenses.
*
* @return Generator<array{0: string, 1: MDPuqiMessageStatus, 2: bool}>
*/
public static function licenseProvider():Generator {
yield 'Empty' => ['', MDPuqiMessageStatus::warning, false];
yield 'Open' => ['CC0', MDPuqiMessageStatus::praise, true];
yield 'Open Attr' => ['CC BY', MDPuqiMessageStatus::praise, true];
yield 'Closed' => ['RR-F', MDPuqiMessageStatus::warning, false];
}
/**
* Test for license.
*
* @param string $input Input string.
* @param MDPuqiMessageStatus $warningStatus Expected message status.
* @param boolean $positive Positive or negative result.
*
* @return void
*/
#[DataProvider('licenseProvider')]
public function testMetadataLicensesResultInExpectedAccessment(string $input, MDPuqiMessageStatus $warningStatus, bool $positive):void {
$tlLoader = new MDTlLoader("abc", "en");
$puqi = new MDPuqi($tlLoader);
$puqi->checkMetadataLicense($input);
$msgs = $puqi->getMessages();
self::assertEquals(1, count($msgs));
$msg = $msgs[0];
self::assertEquals($warningStatus, $msg->status);
$score = $puqi->getScore();
self::assertEquals($positive, $score > 0, "Expected score to be positive or negative, got the oppite result. Score is: " . $score);
}
/**
* Test for license.
*
* @param string $input Input string.
* @param MDPuqiMessageStatus $warningStatus Expected message status.
* @param boolean $positive Positive or negative result.
*
* @return void
*/
#[DataProvider('licenseProvider')]
public function testImageLicensesResultInExpectedAccessment(string $input, MDPuqiMessageStatus $warningStatus, bool $positive):void {
$tlLoader = new MDTlLoader("abc", "en");
$puqi = new MDPuqi($tlLoader);
$puqi->checkImageLicenses([['license' => $input, 'rightsholder' => 'Somebody']]);
$msgs = $puqi->getMessages();
self::assertEquals(1, count($msgs));
$msg = $msgs[0];
self::assertEquals($warningStatus, $msg->status);
$score = $puqi->getScore();
self::assertEquals($positive, $score > 0, "Expected score to be positive or negative, got the oppite result. Score is: " . $score);
}
}