Add bootstrapping for tests, add praise instead of warning in case of
attribution licenses
This commit is contained in:
		
							
								
								
									
										17
									
								
								phpunit.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								phpunit.xml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,17 @@ | |||||||
|  | <?xml version="1.0"?> | ||||||
|  | <phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.2/phpunit.xsd" backupGlobals="false" beStrictAboutChangesToGlobalState="false" beStrictAboutOutputDuringTests="false" bootstrap="tests/bootstrap.php" cacheResult="false" colors="true" enforceTimeLimit="true" failOnWarning="true" processIsolation="true" stopOnError="true" stopOnFailure="true" stopOnIncomplete="true" stopOnSkipped="true" stopOnRisky="true" stopOnWarning="true" timeoutForSmallTests="1" timeoutForMediumTests="10" timeoutForLargeTests="60" cacheDirectory=".phpunit.cache" backupStaticProperties="false" requireCoverageMetadata="false" beStrictAboutCoverageMetadata="false" | ||||||
|  |     displayDetailsOnIncompleteTests="true" | ||||||
|  |     displayDetailsOnSkippedTests="true" | ||||||
|  |     displayDetailsOnTestsThatTriggerDeprecations="true" | ||||||
|  |     displayDetailsOnTestsThatTriggerErrors="true" | ||||||
|  |     displayDetailsOnTestsThatTriggerNotices="true" | ||||||
|  |     displayDetailsOnTestsThatTriggerWarnings="true"> | ||||||
|  |     <testsuite name="tests"> | ||||||
|  |         <directory>tests</directory> | ||||||
|  |     </testsuite> | ||||||
|  |     <source> | ||||||
|  |         <include> | ||||||
|  |             <directory suffix=".php">./src</directory> | ||||||
|  |         </include> | ||||||
|  |     </source> | ||||||
|  | </phpunit> | ||||||
| @@ -894,7 +894,7 @@ final class MDPuqi { | |||||||
| 
 | 
 | ||||||
|             $this->_messages[] = new MDPuqiMessage( |             $this->_messages[] = new MDPuqiMessage( | ||||||
|                 MDPuqiCheckSection::metadataLicense, |                 MDPuqiCheckSection::metadataLicense, | ||||||
|                 MDPuqiMessageStatus::warning, |                 MDPuqiMessageStatus::praise, | ||||||
|                 $this->_tlLoader->tl("basis", "basis", "metadata") . ': ' . $this->_tlLoader->tl("quality", "quality", "open_access_licence_used"), |                 $this->_tlLoader->tl("basis", "basis", "metadata") . ': ' . $this->_tlLoader->tl("quality", "quality", "open_access_licence_used"), | ||||||
|                 self::QI_REWARD_METADATA_LICENCE_OPEN_ACCESS_ATTRIBUTION, |                 self::QI_REWARD_METADATA_LICENCE_OPEN_ACCESS_ATTRIBUTION, | ||||||
|             ); |             ); | ||||||
|   | |||||||
| @@ -7,22 +7,13 @@ | |||||||
| declare(strict_types = 1); | declare(strict_types = 1); | ||||||
| 
 | 
 | ||||||
| use PHPUnit\Framework\TestCase; | use PHPUnit\Framework\TestCase; | ||||||
| 
 | if (!defined('TL_FILE_DIRS')) { | ||||||
|     define('TL_FILE_DIRS', [ |     define('TL_FILE_DIRS', [ | ||||||
|         __DIR__ . '/../../../l10n/musdb/', |         __DIR__ . '/../../../l10n/musdb/', | ||||||
|         __DIR__ . '/../../../l10n/quality-web/', |         __DIR__ . '/../../../l10n/quality-web/', | ||||||
|         __DIR__ . '/../../importer/dependencies/MDAllowedValueSets/l18n/', |         __DIR__ . '/../../importer/dependencies/MDAllowedValueSets/l18n/', | ||||||
|     ]); |     ]); | ||||||
| 
 | } | ||||||
| require_once __DIR__ . '/../src/Checks/Plausi/MDPlausi.php'; |  | ||||||
| require_once __DIR__ . '/../src/Checks/Plausi/MDEventCategory.php'; |  | ||||||
| require_once __DIR__ . '/../src/Checks/Plausi/MDPlausiEventCategory.php'; |  | ||||||
| require_once __DIR__ . '/../src/Checks/Plausi/MDPlausiEvent.php'; |  | ||||||
| # require_once __DIR__ . '/../../MDTlLoader/src/MDTlLoader.php';
 |  | ||||||
| require_once __DIR__ . '/../../importer/dependencies/MDAllowedValueSets/src/MDRequirementsSet.php'; |  | ||||||
| require_once __DIR__ . '/../../importer/dependencies/MDAllowedValueSets/src/MDValueSet.php'; |  | ||||||
| require_once __DIR__ . '/../../importer/dependencies/MDAllowedValueSets/src/MDEventsSet.php'; |  | ||||||
| require_once __DIR__ . '/../../importer/dependencies/MDTlLoader/src/MDTlLoader.php'; |  | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * Tests for plausi. |  * Tests for plausi. | ||||||
|   | |||||||
| @@ -7,10 +7,79 @@ | |||||||
| declare(strict_types = 1); | declare(strict_types = 1); | ||||||
| 
 | 
 | ||||||
| use PHPUnit\Framework\TestCase; | use PHPUnit\Framework\TestCase; | ||||||
|  | use PHPUnit\Framework\Attributes\DataProvider; | ||||||
|  | use PHPUnit\Framework\Attributes\CoversClass; | ||||||
|  | use PHPUnit\Framework\Attributes\Small; | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * Tests for PUQI. |  * Tests for PUQI. | ||||||
|  */ |  */ | ||||||
|  | #[small]
 | ||||||
|  | #[CoversClass(\MDPuqi::class)]
 | ||||||
| final class MDPuqiTest extends TestCase { | 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); | ||||||
|  | 
 | ||||||
|  |     } | ||||||
|  | } | ||||||
|   | |||||||
							
								
								
									
										48
									
								
								tests/bootstrap.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								tests/bootstrap.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,48 @@ | |||||||
|  | <?PHP | ||||||
|  | /** | ||||||
|  |  * Bootstraps tests by running provideEnv and then resetting the error handler. | ||||||
|  |  */ | ||||||
|  | declare(strict_types = 1); | ||||||
|  | 
 | ||||||
|  | define('TL_FILE_DIRS', [ | ||||||
|  |     __DIR__ . '/../../../l10n/musdb/', | ||||||
|  |     __DIR__ . '/../../../l10n/quality-web/', | ||||||
|  |     __DIR__ . '/../../importer/dependencies/MDAllowedValueSets/l18n/', | ||||||
|  | ]); | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * Autoloader for musdb. | ||||||
|  |  * | ||||||
|  |  * @param string $className Name of the class to load. | ||||||
|  |  * | ||||||
|  |  * @return void | ||||||
|  |  */ | ||||||
|  | \spl_autoload_register(function(string $className):void { | ||||||
|  | 
 | ||||||
|  |     // Try using class map as defined through /scripts/buildClassMap.php
 | ||||||
|  | 
 | ||||||
|  |     foreach ([ | ||||||
|  |         __DIR__ . '/../tests', | ||||||
|  |         __DIR__ . '/../src', | ||||||
|  |         __DIR__ . '/../src/Checks', | ||||||
|  |         __DIR__ . '/../src/Checks/Puqi', | ||||||
|  |         __DIR__ . '/../src/Checks/Plausi', | ||||||
|  |         __DIR__ . '/../../importer/dependencies/MDAllowedValueSets/src', | ||||||
|  |         __DIR__ . '/../../importer/dependencies/MDAllowedValueSets/exceptions', | ||||||
|  |         __DIR__ . '/../../importer/dependencies/MDErrorReporter/src', | ||||||
|  |         __DIR__ . '/../../importer/dependencies/MDErrorReporter/exceptions', | ||||||
|  |         __DIR__ . '/../../importer/dependencies/MDTlLoader/src', | ||||||
|  |         __DIR__ . '/../../importer/dependencies/MDTlLoader/exceptions', | ||||||
|  |     ] as $classDir) { | ||||||
|  | 
 | ||||||
|  |         if (\file_exists("$classDir/$className.php")) { | ||||||
|  |             include "$classDir/$className.php"; | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |     } | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | restore_error_handler(); | ||||||
|  | restore_exception_handler(); | ||||||
		Reference in New Issue
	
	Block a user