diff options
| -rw-r--r-- | app/Elements/RestrictionNotice.php | 13 | ||||
| -rw-r--r-- | tests/app/Elements/RestrictionNoticeTest.php | 10 |
2 files changed, 19 insertions, 4 deletions
diff --git a/app/Elements/RestrictionNotice.php b/app/Elements/RestrictionNotice.php index 2b3fd6491c..75df0cd38e 100644 --- a/app/Elements/RestrictionNotice.php +++ b/app/Elements/RestrictionNotice.php @@ -53,6 +53,13 @@ class RestrictionNotice extends AbstractElement public const RESTRICTION_CONFIDENTIAL = 'confidential'; public const RESTRICTION_LOCKED = 'locked'; + // Store the locked value after the privacy value. + private const CANONICAL = [ + self::RESTRICTION_LOCKED . ', ' . self::RESTRICTION_NONE => self::RESTRICTION_NONE . ', ' . self::RESTRICTION_LOCKED, + self::RESTRICTION_LOCKED . ', ' . self::RESTRICTION_PRIVACY => self::RESTRICTION_PRIVACY . ', ' . self::RESTRICTION_LOCKED, + self::RESTRICTION_LOCKED . ', ' . self::RESTRICTION_CONFIDENTIAL => self::RESTRICTION_CONFIDENTIAL . ', ' . self::RESTRICTION_LOCKED, + ]; + /** * Convert a value to a canonical form. * @@ -62,7 +69,11 @@ class RestrictionNotice extends AbstractElement */ public function canonical(string $value): string { - return strtolower(parent::canonical($value)); + $value = strtolower(parent::canonical($value)); + $value = trim($value, ', '); + $value = preg_replace('/[, ]+/', ', ', $value); + + return self::CANONICAL[$value] ?? $value; } /** diff --git a/tests/app/Elements/RestrictionNoticeTest.php b/tests/app/Elements/RestrictionNoticeTest.php index 72a4bd363e..595d842aa9 100644 --- a/tests/app/Elements/RestrictionNoticeTest.php +++ b/tests/app/Elements/RestrictionNoticeTest.php @@ -42,8 +42,12 @@ class RestrictionNoticeTest extends AbstractElementTest */ public function testCanonical(): void { - self::assertSame('foo bar baz', self::$element->canonical('Foo bAr baZ')); - self::assertSame('foo bar baz', self::$element->canonical("\t Foo\t bAr \tbaZ\t ")); - self::assertSame('foo bar baz', self::$element->canonical("\nFoo \n\r bAr \r\n baZ\r")); + self::assertSame('privacy', self::$element->canonical('pRiVacy')); + self::assertSame('none', self::$element->canonical('NONE')); + self::assertSame('confidential', self::$element->canonical('Confidential')); + self::assertSame('locked', self::$element->canonical(', locked ,')); + self::assertSame('confidential, locked', self::$element->canonical('locked confidential')); + self::assertSame('privacy, locked', self::$element->canonical('locked, privacy')); + self::assertSame('none, locked', self::$element->canonical('locked,, none')); } } |
