Skip to content

Commit

Permalink
Merge "REST: Use CONTEXT_LABEL/CONTEXT_DESCRIPTION over CONTEXT_VALUE"
Browse files Browse the repository at this point in the history
  • Loading branch information
jenkins-bot authored and Gerrit Code Review committed Oct 9, 2023
2 parents f008935 + c7676f5 commit 9dfa45d
Show file tree
Hide file tree
Showing 14 changed files with 25 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function validateAndDeserialize( ItemDescriptionEditRequest $request ): T
case ItemDescriptionValidator::CODE_INVALID:
throw new UseCaseError(
UseCaseError::INVALID_DESCRIPTION,
"Not a valid description: {$context[ItemDescriptionValidator::CONTEXT_VALUE]}"
"Not a valid description: {$context[ItemDescriptionValidator::CONTEXT_DESCRIPTION]}"
);
case ItemDescriptionValidator::CODE_EMPTY:
throw new UseCaseError(
Expand All @@ -50,7 +50,7 @@ public function validateAndDeserialize( ItemDescriptionEditRequest $request ): T
UseCaseError::DESCRIPTION_TOO_LONG,
"Description must be no more than $limit characters long",
[
UseCaseError::CONTEXT_VALUE => $context[ItemDescriptionValidator::CONTEXT_VALUE],
UseCaseError::CONTEXT_VALUE => $context[ItemDescriptionValidator::CONTEXT_DESCRIPTION],
UseCaseError::CONTEXT_CHARACTER_LIMIT => $limit,
]
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function validateAndDeserialize( ItemLabelEditRequest $request ): Term {
case ItemLabelValidator::CODE_INVALID:
throw new UseCaseError(
UseCaseError::INVALID_LABEL,
"Not a valid label: {$context[ItemLabelValidator::CONTEXT_VALUE]}"
"Not a valid label: {$context[ItemLabelValidator::CONTEXT_LABEL]}"
);
case ItemLabelValidator::CODE_EMPTY:
throw new UseCaseError( UseCaseError::LABEL_EMPTY, 'Label must not be empty' );
Expand All @@ -44,7 +44,7 @@ public function validateAndDeserialize( ItemLabelEditRequest $request ): Term {
UseCaseError::LABEL_TOO_LONG,
"Label must be no more than $maxLabelLength characters long",
[
UseCaseError::CONTEXT_VALUE => $context[ItemLabelValidator::CONTEXT_VALUE],
UseCaseError::CONTEXT_VALUE => $context[ItemLabelValidator::CONTEXT_LABEL],
UseCaseError::CONTEXT_CHARACTER_LIMIT => $maxLabelLength,
]
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private function validateDescription( ItemId $itemId, Term $description ): void
$context = $validationError->getContext();
switch ( $validationError->getCode() ) {
case ItemDescriptionValidator::CODE_INVALID:
$descriptionText = $context[ ItemDescriptionValidator::CONTEXT_VALUE ];
$descriptionText = $context[ ItemDescriptionValidator::CONTEXT_DESCRIPTION ];
throw new UseCaseError(
UseCaseError::PATCHED_DESCRIPTION_INVALID,
"Changed description for '{$description->getLanguageCode()}' is invalid: $descriptionText",
Expand All @@ -118,7 +118,7 @@ private function validateDescription( ItemId $itemId, Term $description ): void
"Changed description for '$languageCode' must not be more than $maxDescriptionLength characters long",
[
UseCaseError::CONTEXT_LANGUAGE => $languageCode,
UseCaseError::CONTEXT_VALUE => $context[ ItemDescriptionValidator::CONTEXT_VALUE ],
UseCaseError::CONTEXT_VALUE => $context[ ItemDescriptionValidator::CONTEXT_DESCRIPTION ],
UseCaseError::CONTEXT_CHARACTER_LIMIT => $context[ ItemDescriptionValidator::CONTEXT_LIMIT ],
]
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ private function validateLabel( ItemId $itemId, Term $label ): void {
"Changed label for '{$label->getLanguageCode()}' must not be more than $maxLabelLength characters long",
[
UseCaseError::CONTEXT_LANGUAGE => $label->getLanguageCode(),
UseCaseError::CONTEXT_VALUE => $context[ItemLabelValidator::CONTEXT_VALUE],
UseCaseError::CONTEXT_VALUE => $context[ItemLabelValidator::CONTEXT_LABEL],
UseCaseError::CONTEXT_CHARACTER_LIMIT => $context[ItemLabelValidator::CONTEXT_LIMIT],
]
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ interface ItemDescriptionValidator {
public const CODE_LABEL_DESCRIPTION_EQUAL = 'label-description-equal';
public const CODE_LABEL_DESCRIPTION_DUPLICATE = 'label-description-duplicate';

public const CONTEXT_VALUE = 'value';
public const CONTEXT_LIMIT = 'character-limit';
public const CONTEXT_LANGUAGE = 'language';
public const CONTEXT_LABEL = 'label';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ interface ItemLabelValidator {
public const CONTEXT_LABEL = 'label';
public const CONTEXT_DESCRIPTION = 'description';
public const CONTEXT_MATCHING_ITEM_ID = 'matching-item-id';
public const CONTEXT_VALUE = 'value';
public const CONTEXT_LIMIT = 'character-limit';

public function validate( ItemId $itemId, string $language, string $label ): ?ValidationError;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ public function validate( string $labelText ): ?ValidationError {
return new ValidationError(
ItemLabelValidator::CODE_TOO_LONG,
[
ItemLabelValidator::CONTEXT_VALUE => $labelText,
ItemLabelValidator::CONTEXT_LABEL => $labelText,
ItemLabelValidator::CONTEXT_LIMIT => $error->getParameters()[0],
]
);
default:
return new ValidationError(
ItemLabelValidator::CODE_INVALID,
[ ItemLabelValidator::CONTEXT_VALUE => $labelText ]
[ ItemLabelValidator::CONTEXT_LABEL => $labelText ]
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ private function validateDescription( string $description ): ?ValidationError {
return new ValidationError(
self::CODE_TOO_LONG,
[
self::CONTEXT_VALUE => $description,
self::CONTEXT_DESCRIPTION => $description,
self::CONTEXT_LIMIT => $error->getParameters()[0],
]
);
default:
return new ValidationError(
self::CODE_INVALID,
[ self::CONTEXT_VALUE => $description ]
[ self::CONTEXT_DESCRIPTION => $description ]
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public static function invalidDescriptionProvider(): Generator {
new ValidationError(
ItemDescriptionValidator::CODE_TOO_LONG,
[
ItemDescriptionValidator::CONTEXT_VALUE => $description,
ItemDescriptionValidator::CONTEXT_DESCRIPTION => $description,
ItemDescriptionValidator::CONTEXT_LIMIT => $limit,
]
),
Expand All @@ -90,7 +90,7 @@ public static function invalidDescriptionProvider(): Generator {
yield 'invalid description' => [
new ValidationError(
ItemDescriptionValidator::CODE_INVALID,
[ ItemDescriptionValidator::CONTEXT_VALUE => $description ],
[ ItemDescriptionValidator::CONTEXT_DESCRIPTION => $description ],
),
UseCaseError::INVALID_DESCRIPTION,
"Not a valid description: $description",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static function invalidLabelProvider(): Generator {
yield 'invalid label' => [
new ValidationError(
ItemLabelValidator::CODE_INVALID,
[ ItemLabelValidator::CONTEXT_VALUE => $label ],
[ ItemLabelValidator::CONTEXT_LABEL => $label ],
),
UseCaseError::INVALID_LABEL,
"Not a valid label: $label",
Expand All @@ -82,7 +82,7 @@ public static function invalidLabelProvider(): Generator {
$limit = 250;
yield 'label too long' => [
new ValidationError( ItemLabelValidator::CODE_TOO_LONG, [
ItemLabelValidator::CONTEXT_VALUE => $label,
ItemLabelValidator::CONTEXT_LABEL => $label,
ItemLabelValidator::CONTEXT_LIMIT => $limit,
] ),
UseCaseError::LABEL_TOO_LONG,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public static function invalidDescriptionsProvider(): Generator {
[ $language => $description ],
new ValidationError(
ItemDescriptionValidator::CODE_INVALID,
[ ItemDescriptionValidator::CONTEXT_VALUE => $description ],
[ ItemDescriptionValidator::CONTEXT_DESCRIPTION => $description ],
),
UseCaseError::PATCHED_DESCRIPTION_INVALID,
"Changed description for '$language' is invalid: {$description}",
Expand All @@ -130,7 +130,7 @@ public static function invalidDescriptionsProvider(): Generator {
new ValidationError(
ItemDescriptionValidator::CODE_TOO_LONG,
[
ItemDescriptionValidator::CONTEXT_VALUE => $tooLongDescription,
ItemDescriptionValidator::CONTEXT_DESCRIPTION => $tooLongDescription,
ItemDescriptionValidator::CONTEXT_LIMIT => 250,
ItemDescriptionValidator::CONTEXT_LANGUAGE => $language,
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public static function invalidLabelsProvider(): Generator {
[ $language => $label ],
new ValidationError(
ItemLabelValidator::CODE_INVALID,
[ ItemLabelValidator::CONTEXT_VALUE => $label ],
[ ItemLabelValidator::CONTEXT_LABEL => $label ],
),
UseCaseError::PATCHED_LABEL_INVALID,
"Changed label for '$language' is invalid: {$label}",
Expand All @@ -130,7 +130,7 @@ public static function invalidLabelsProvider(): Generator {
new ValidationError(
ItemLabelValidator::CODE_TOO_LONG,
[
ItemLabelValidator::CONTEXT_VALUE => $tooLongLabel,
ItemLabelValidator::CONTEXT_LABEL => $tooLongLabel,
ItemLabelValidator::CONTEXT_LIMIT => 250,
ItemLabelValidator::CONTEXT_LANGUAGE => $language,
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ public function testEmptyLabel_returnsValidationError(): void {
}

public function testLabelTooLong_returnsValidationError(): void {
$tooLonglabel = str_repeat( 'a', self::MAX_LENGTH + 1 );
$tooLongLabel = str_repeat( 'a', self::MAX_LENGTH + 1 );
$this->assertEquals(
new ValidationError(
ItemLabelValidator::CODE_TOO_LONG,
[
ItemLabelValidator::CONTEXT_VALUE => $tooLonglabel,
ItemLabelValidator::CONTEXT_LABEL => $tooLongLabel,
ItemLabelValidator::CONTEXT_LIMIT => self::MAX_LENGTH,
]
),
$this->newValidator()->validate( $tooLonglabel )
$this->newValidator()->validate( $tooLongLabel )
);
}

Expand All @@ -51,7 +51,7 @@ public function testInvalidLabel_returnsValidationError(): void {
$this->assertEquals(
new ValidationError(
ItemLabelValidator::CODE_INVALID,
[ ItemLabelValidator::CONTEXT_VALUE => $invalidLabel ]
[ ItemLabelValidator::CONTEXT_LABEL => $invalidLabel ]
),
$this->newValidator()->validate( $invalidLabel )
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public static function provideInvalidDescription(): Generator {
$description,
ItemDescriptionValidator::CODE_TOO_LONG,
[
ItemDescriptionValidator::CONTEXT_VALUE => $description,
ItemDescriptionValidator::CONTEXT_DESCRIPTION => $description,
ItemDescriptionValidator::CONTEXT_LIMIT => self::MAX_LENGTH,
],
];
Expand All @@ -104,7 +104,7 @@ public static function provideInvalidDescription(): Generator {
yield 'description has invalid character' => [
$description,
ItemDescriptionValidator::CODE_INVALID,
[ ItemDescriptionValidator::CONTEXT_VALUE => $description ],
[ ItemDescriptionValidator::CONTEXT_DESCRIPTION => $description ],
];
}

Expand Down

0 comments on commit 9dfa45d

Please sign in to comment.