From 7596d9f18e62ad041c41bcf3d36d5fb92f159770 Mon Sep 17 00:00:00 2001 From: Joshua Ramon Enslin Date: Thu, 5 Oct 2023 20:42:29 +0200 Subject: [PATCH] Add test for cases of actors dying about 95 years ago (between Berne convention expiry and max. expiry) and fix early variable access --- .../MDPlausiForLegalStatus.php | 5 +- tests/MDPlausiForLegalStatusTest.php | 72 +++++++++++++++++++ 2 files changed, 75 insertions(+), 2 deletions(-) diff --git a/src/Checks/PlausiForLegalStatus/MDPlausiForLegalStatus.php b/src/Checks/PlausiForLegalStatus/MDPlausiForLegalStatus.php index 49f9d5c..fad4555 100644 --- a/src/Checks/PlausiForLegalStatus/MDPlausiForLegalStatus.php +++ b/src/Checks/PlausiForLegalStatus/MDPlausiForLegalStatus.php @@ -49,12 +49,13 @@ final class MDPlausiForLegalStatus { private function _determineExpectedStatus():string { $currentYear = (int)date("Y"); - $deathYearOfLastCreator = (int)date("Y", $this->_death_of_last_creator); - if (!isset($deathYearOfLastCreator)) { + if (!isset($this->_death_of_last_creator)) { return 'any'; } + $deathYearOfLastCreator = (int)date("Y", $this->_death_of_last_creator); + if ($currentYear - self::YEARS_AFTER_DEATH_TO_PUBLIC_DOMAIN > $deathYearOfLastCreator) { return 'pd'; } diff --git a/tests/MDPlausiForLegalStatusTest.php b/tests/MDPlausiForLegalStatusTest.php index 5378f81..8ebbf9b 100644 --- a/tests/MDPlausiForLegalStatusTest.php +++ b/tests/MDPlausiForLegalStatusTest.php @@ -47,6 +47,29 @@ final class MDPlausiForLegalStatusTest extends TestCase { } + /** + * Ensures that no warning is present if no information has been provided. + * + * @return void + */ + public function testNoWarningForObjectWithActorsDeceased95YearsAgo():void { + + $plausiEvent = new MDPlausiEvent(1, + "", + "", + "", + "Somebody", + date("Y", strtotime("-95 years")), + date("Y", strtotime("-95 years"))); + + $plausiLegal = new MDPlausiForLegalStatus([$plausiEvent], [['name' => 'test.jpg', 'license' => 'RR-F']]); + $warningStatus = $plausiLegal->evaluateSimple(); + + self::assertFalse($warningStatus['has_warning']); + self::assertEmpty($warningStatus['msgs']); + + } + /** * Ensures that a warning is returned, if the object's representations are published under * restrictive licenses Checks the integration / evaluation function. @@ -105,6 +128,31 @@ final class MDPlausiForLegalStatusTest extends TestCase { } + /** + * Ensures that a warning is returned, if the object's representations are published under + * restrictive licenses Checks the integration / evaluation function. + * + * @return void + */ + public function testPublicDomainObjectExpectsPdForActorsWithNoDeathDateBornInMedievalTimes():void { + + $plausiEvent = new MDPlausiEvent(1, + "", + "", + "", + "Helmut Meyer23", + "1400", + ""); + + $plausiLegal = new MDPlausiForLegalStatus([$plausiEvent], [['name' => 'test23.jpg', 'license' => 'RR-F']]); + $warningStatus = $plausiLegal->evaluateSimple(); + + self::assertTrue($warningStatus['has_warning']); + self::assertNotEmpty($warningStatus['msgs']); + self::assertEquals(MDPlausiLegalCheckResultType::expect_public_domain, $warningStatus['msgs'][0]['type']); + + } + /** * Ensures that a warning is returned if the author / creator died only in the current year. * @@ -129,6 +177,30 @@ final class MDPlausiForLegalStatusTest extends TestCase { } + /** + * Ensures that a warning is returned if the author / creator died only in the current year. + * + * @return void + */ + public function testCreatorBornWithinLast100YearsAsksForRestrictedLicense():void { + + $plausiEvent = new MDPlausiEvent(1, + "", + "", + "", + "Helmut Meyer", + "1922", + ""); + + $plausiLegal = new MDPlausiForLegalStatus([$plausiEvent], [['name' => 'test.jpg', 'license' => 'Public Domain Mark']]); + $warningStatus = $plausiLegal->evaluateSimple(); + + self::assertTrue($warningStatus['has_warning']); + self::assertNotEmpty($warningStatus['msgs']); + self::assertEquals(MDPlausiLegalCheckResultType::expect_restricted_legal_status, $warningStatus['msgs'][0]['type']); + + } + /** * Ensures that a warning is returned if the creator is still alive. *