From c8042c09403091b0cbbac23d897a36220e8e921f Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Fri, 21 May 2021 16:42:34 +0100 Subject: [PATCH] Refactor errors section --- bin/src/Validator/SpecGenerator.php | 1 + bin/src/Validator/SpecGenerator/Dumper.php | 4 + .../Validator/SpecGenerator/FileManager.php | 25 +- .../SpecGenerator/Section/AttributeLists.php | 16 - .../SpecGenerator/Section/CssRulesets.php | 18 - .../Section/DeclarationLists.php | 16 - .../Section/DescendantTagLists.php | 16 - .../SpecGenerator/Section/DocRulesets.php | 18 - .../SpecGenerator/Section/Errors.php | 88 ++- .../Validator/SpecGenerator/Section/Tags.php | 18 - .../SpecGenerator/Template/Error.php | 61 ++ .../SpecGenerator/Template/Errors.php | 78 ++ src/Exception/InvalidErrorCode.php | 27 + src/Validator/Spec/Error.php | 65 ++ .../Error/AmpEmailMissingStrictCssAttr.php | 30 + .../Error/AttrDisallowedByImpliedLayout.php | 31 + .../Error/AttrDisallowedBySpecifiedLayout.php | 31 + .../Error/AttrMissingRequiredExtension.php | 31 + .../Spec/Error/AttrRequiredButMissing.php | 31 + .../Spec/Error/AttrValueRequiredByLayout.php | 31 + .../Spec/Error/BaseTagMustPreceedAllUrls.php | 31 + .../Spec/Error/CdataViolatesDenylist.php | 31 + .../ChildTagDoesNotSatisfyReferencePoint.php | 31 + ...agDoesNotSatisfyReferencePointSingular.php | 31 + .../Spec/Error/CssExcessivelyNested.php | 31 + src/Validator/Spec/Error/CssSyntaxBadUrl.php | 31 + .../Error/CssSyntaxDisallowedAttrSelector.php | 31 + .../Spec/Error/CssSyntaxDisallowedDomain.php | 31 + .../Error/CssSyntaxDisallowedImportant.php | 31 + ...SyntaxDisallowedKeyframeInsideKeyframe.php | 31 + .../Error/CssSyntaxDisallowedMediaFeature.php | 31 + .../Error/CssSyntaxDisallowedMediaType.php | 31 + .../CssSyntaxDisallowedPropertyValue.php | 31 + ...sSyntaxDisallowedPropertyValueWithHint.php | 31 + .../Error/CssSyntaxDisallowedPseudoClass.php | 31 + .../CssSyntaxDisallowedPseudoElement.php | 31 + ...lowedQualifiedRuleMustBeInsideKeyframe.php | 31 + .../Error/CssSyntaxDisallowedRelativeUrl.php | 31 + .../CssSyntaxEofInPreludeOfQualifiedRule.php | 31 + .../Error/CssSyntaxErrorInPseudoSelector.php | 31 + .../Error/CssSyntaxIncompleteDeclaration.php | 31 + .../Spec/Error/CssSyntaxInvalidAtRule.php | 31 + .../Error/CssSyntaxInvalidAttrSelector.php | 31 + .../Error/CssSyntaxInvalidDeclaration.php | 31 + .../Spec/Error/CssSyntaxInvalidProperty.php | 31 + .../Error/CssSyntaxInvalidPropertyNolist.php | 31 + .../Spec/Error/CssSyntaxInvalidUrl.php | 31 + .../Error/CssSyntaxInvalidUrlProtocol.php | 31 + .../Error/CssSyntaxMalformedMediaQuery.php | 31 + .../Spec/Error/CssSyntaxMissingSelector.php | 31 + .../Spec/Error/CssSyntaxMissingUrl.php | 31 + .../Spec/Error/CssSyntaxNotASelectorStart.php | 31 + ...ssSyntaxPropertyDisallowedTogetherWith.php | 31 + ...ssSyntaxPropertyDisallowedWithinAtRule.php | 31 + ...CssSyntaxPropertyRequiresQualification.php | 31 + ...ssSyntaxQualifiedRuleHasNoDeclarations.php | 31 + .../Error/CssSyntaxStrayTrailingBackslash.php | 31 + ...ssSyntaxUnparsedInputRemainsInSelector.php | 31 + .../Error/CssSyntaxUnterminatedComment.php | 31 + .../Error/CssSyntaxUnterminatedString.php | 31 + src/Validator/Spec/Error/DeprecatedAttr.php | 31 + src/Validator/Spec/Error/DeprecatedTag.php | 31 + src/Validator/Spec/Error/DevModeOnly.php | 31 + src/Validator/Spec/Error/DisallowedAttr.php | 31 + .../Spec/Error/DisallowedChildTagName.php | 31 + src/Validator/Spec/Error/DisallowedDomain.php | 31 + .../Error/DisallowedFirstChildTagName.php | 31 + .../Spec/Error/DisallowedManufacturedBody.php | 31 + .../Error/DisallowedPropertyInAttrValue.php | 31 + .../Spec/Error/DisallowedRelativeUrl.php | 31 + .../Spec/Error/DisallowedScriptTag.php | 31 + .../Spec/Error/DisallowedStyleAttr.php | 31 + src/Validator/Spec/Error/DisallowedTag.php | 31 + .../Spec/Error/DisallowedTagAncestor.php | 31 + .../Spec/Error/DocumentSizeLimitExceeded.php | 31 + .../Spec/Error/DocumentTooComplex.php | 31 + .../Spec/Error/DuplicateAttribute.php | 31 + .../Spec/Error/DuplicateDimension.php | 31 + .../Spec/Error/DuplicateReferencePoint.php | 31 + .../Spec/Error/DuplicateUniqueTag.php | 31 + .../Spec/Error/DuplicateUniqueTagWarning.php | 31 + src/Validator/Spec/Error/ExtensionUnused.php | 31 + .../Spec/Error/GeneralDisallowedTag.php | 31 + .../Spec/Error/ImpliedLayoutInvalid.php | 31 + .../InconsistentUnitsForWidthAndHeight.php | 31 + .../Spec/Error/IncorrectMinNumChildTags.php | 31 + .../Spec/Error/IncorrectNumChildTags.php | 31 + .../Error/IncorrectScriptReleaseVersion.php | 31 + .../Spec/Error/InlineScriptTooLong.php | 31 + .../Spec/Error/InlineStyleTooLong.php | 31 + src/Validator/Spec/Error/InvalidAttrValue.php | 31 + .../Spec/Error/InvalidDoctypeHtml.php | 31 + src/Validator/Spec/Error/InvalidJsonCdata.php | 31 + .../Error/InvalidPropertyValueInAttrValue.php | 31 + src/Validator/Spec/Error/InvalidUrl.php | 31 + .../Spec/Error/InvalidUrlProtocol.php | 31 + src/Validator/Spec/Error/InvalidUtf8.php | 31 + .../Spec/Error/LtsScriptAfterNonLts.php | 31 + .../Spec/Error/MandatoryAnyofAttrMissing.php | 31 + .../Spec/Error/MandatoryAttrMissing.php | 31 + .../MandatoryCdataMissingOrIncorrect.php | 31 + .../Spec/Error/MandatoryLastChildTag.php | 31 + .../Spec/Error/MandatoryOneofAttrMissing.php | 31 + .../MandatoryPropertyMissingFromAttrValue.php | 31 + .../Error/MandatoryReferencePointMissing.php | 31 + .../Spec/Error/MandatoryTagAncestor.php | 31 + .../Error/MandatoryTagAncestorWithHint.php | 31 + .../Spec/Error/MandatoryTagMissing.php | 31 + .../Spec/Error/MissingLayoutAttributes.php | 31 + .../Spec/Error/MissingRequiredExtension.php | 31 + src/Validator/Spec/Error/MissingUrl.php | 31 + .../Spec/Error/MutuallyExclusiveAttrs.php | 31 + .../Spec/Error/NonLtsScriptAfterLts.php | 31 + .../Error/NonWhitespaceCdataEncountered.php | 31 + .../Spec/Error/SpecifiedLayoutInvalid.php | 31 + .../Error/StylesheetAndInlineStyleTooLong.php | 31 + .../Spec/Error/StylesheetTooLong.php | 31 + src/Validator/Spec/Error/TagExcludedByTag.php | 31 + .../Error/TagNotAllowedToHaveSiblings.php | 31 + .../Spec/Error/TagReferencePointConflict.php | 31 + .../Spec/Error/TagRequiredByMissing.php | 31 + .../Spec/Error/TemplateInAttrName.php | 31 + .../Spec/Error/TemplatePartialInAttrValue.php | 31 + .../Error/UnescapedTemplateInAttrValue.php | 31 + src/Validator/Spec/Error/UnknownCode.php | 31 + src/Validator/Spec/Error/ValueSetMismatch.php | 31 + .../WarningExtensionDeprecatedVersion.php | 31 + .../Spec/Error/WarningExtensionUnused.php | 31 + .../Error/WarningTagRequiredByMissing.php | 31 + src/Validator/Spec/Error/WrongParentTag.php | 31 + src/Validator/Spec/Section/Errors.php | 671 ++++++------------ tests/Exception/InvalidErrorCodeTest.php | 26 + tests/Validator/Spec/ErrorTest.php | 44 ++ .../Spec/Section/AttributeListsTest.php | 1 - .../Spec/Section/DeclarationListsTest.php | 2 - .../Spec/Section/DescendantTagListsTest.php | 1 - tests/Validator/Spec/Section/ErrorsTest.php | 64 ++ tests/src/ValidatorFixtures/DummyError.php | 18 + 138 files changed, 4263 insertions(+), 610 deletions(-) create mode 100644 bin/src/Validator/SpecGenerator/Template/Error.php create mode 100644 bin/src/Validator/SpecGenerator/Template/Errors.php create mode 100644 src/Exception/InvalidErrorCode.php create mode 100644 src/Validator/Spec/Error.php create mode 100644 src/Validator/Spec/Error/AmpEmailMissingStrictCssAttr.php create mode 100644 src/Validator/Spec/Error/AttrDisallowedByImpliedLayout.php create mode 100644 src/Validator/Spec/Error/AttrDisallowedBySpecifiedLayout.php create mode 100644 src/Validator/Spec/Error/AttrMissingRequiredExtension.php create mode 100644 src/Validator/Spec/Error/AttrRequiredButMissing.php create mode 100644 src/Validator/Spec/Error/AttrValueRequiredByLayout.php create mode 100644 src/Validator/Spec/Error/BaseTagMustPreceedAllUrls.php create mode 100644 src/Validator/Spec/Error/CdataViolatesDenylist.php create mode 100644 src/Validator/Spec/Error/ChildTagDoesNotSatisfyReferencePoint.php create mode 100644 src/Validator/Spec/Error/ChildTagDoesNotSatisfyReferencePointSingular.php create mode 100644 src/Validator/Spec/Error/CssExcessivelyNested.php create mode 100644 src/Validator/Spec/Error/CssSyntaxBadUrl.php create mode 100644 src/Validator/Spec/Error/CssSyntaxDisallowedAttrSelector.php create mode 100644 src/Validator/Spec/Error/CssSyntaxDisallowedDomain.php create mode 100644 src/Validator/Spec/Error/CssSyntaxDisallowedImportant.php create mode 100644 src/Validator/Spec/Error/CssSyntaxDisallowedKeyframeInsideKeyframe.php create mode 100644 src/Validator/Spec/Error/CssSyntaxDisallowedMediaFeature.php create mode 100644 src/Validator/Spec/Error/CssSyntaxDisallowedMediaType.php create mode 100644 src/Validator/Spec/Error/CssSyntaxDisallowedPropertyValue.php create mode 100644 src/Validator/Spec/Error/CssSyntaxDisallowedPropertyValueWithHint.php create mode 100644 src/Validator/Spec/Error/CssSyntaxDisallowedPseudoClass.php create mode 100644 src/Validator/Spec/Error/CssSyntaxDisallowedPseudoElement.php create mode 100644 src/Validator/Spec/Error/CssSyntaxDisallowedQualifiedRuleMustBeInsideKeyframe.php create mode 100644 src/Validator/Spec/Error/CssSyntaxDisallowedRelativeUrl.php create mode 100644 src/Validator/Spec/Error/CssSyntaxEofInPreludeOfQualifiedRule.php create mode 100644 src/Validator/Spec/Error/CssSyntaxErrorInPseudoSelector.php create mode 100644 src/Validator/Spec/Error/CssSyntaxIncompleteDeclaration.php create mode 100644 src/Validator/Spec/Error/CssSyntaxInvalidAtRule.php create mode 100644 src/Validator/Spec/Error/CssSyntaxInvalidAttrSelector.php create mode 100644 src/Validator/Spec/Error/CssSyntaxInvalidDeclaration.php create mode 100644 src/Validator/Spec/Error/CssSyntaxInvalidProperty.php create mode 100644 src/Validator/Spec/Error/CssSyntaxInvalidPropertyNolist.php create mode 100644 src/Validator/Spec/Error/CssSyntaxInvalidUrl.php create mode 100644 src/Validator/Spec/Error/CssSyntaxInvalidUrlProtocol.php create mode 100644 src/Validator/Spec/Error/CssSyntaxMalformedMediaQuery.php create mode 100644 src/Validator/Spec/Error/CssSyntaxMissingSelector.php create mode 100644 src/Validator/Spec/Error/CssSyntaxMissingUrl.php create mode 100644 src/Validator/Spec/Error/CssSyntaxNotASelectorStart.php create mode 100644 src/Validator/Spec/Error/CssSyntaxPropertyDisallowedTogetherWith.php create mode 100644 src/Validator/Spec/Error/CssSyntaxPropertyDisallowedWithinAtRule.php create mode 100644 src/Validator/Spec/Error/CssSyntaxPropertyRequiresQualification.php create mode 100644 src/Validator/Spec/Error/CssSyntaxQualifiedRuleHasNoDeclarations.php create mode 100644 src/Validator/Spec/Error/CssSyntaxStrayTrailingBackslash.php create mode 100644 src/Validator/Spec/Error/CssSyntaxUnparsedInputRemainsInSelector.php create mode 100644 src/Validator/Spec/Error/CssSyntaxUnterminatedComment.php create mode 100644 src/Validator/Spec/Error/CssSyntaxUnterminatedString.php create mode 100644 src/Validator/Spec/Error/DeprecatedAttr.php create mode 100644 src/Validator/Spec/Error/DeprecatedTag.php create mode 100644 src/Validator/Spec/Error/DevModeOnly.php create mode 100644 src/Validator/Spec/Error/DisallowedAttr.php create mode 100644 src/Validator/Spec/Error/DisallowedChildTagName.php create mode 100644 src/Validator/Spec/Error/DisallowedDomain.php create mode 100644 src/Validator/Spec/Error/DisallowedFirstChildTagName.php create mode 100644 src/Validator/Spec/Error/DisallowedManufacturedBody.php create mode 100644 src/Validator/Spec/Error/DisallowedPropertyInAttrValue.php create mode 100644 src/Validator/Spec/Error/DisallowedRelativeUrl.php create mode 100644 src/Validator/Spec/Error/DisallowedScriptTag.php create mode 100644 src/Validator/Spec/Error/DisallowedStyleAttr.php create mode 100644 src/Validator/Spec/Error/DisallowedTag.php create mode 100644 src/Validator/Spec/Error/DisallowedTagAncestor.php create mode 100644 src/Validator/Spec/Error/DocumentSizeLimitExceeded.php create mode 100644 src/Validator/Spec/Error/DocumentTooComplex.php create mode 100644 src/Validator/Spec/Error/DuplicateAttribute.php create mode 100644 src/Validator/Spec/Error/DuplicateDimension.php create mode 100644 src/Validator/Spec/Error/DuplicateReferencePoint.php create mode 100644 src/Validator/Spec/Error/DuplicateUniqueTag.php create mode 100644 src/Validator/Spec/Error/DuplicateUniqueTagWarning.php create mode 100644 src/Validator/Spec/Error/ExtensionUnused.php create mode 100644 src/Validator/Spec/Error/GeneralDisallowedTag.php create mode 100644 src/Validator/Spec/Error/ImpliedLayoutInvalid.php create mode 100644 src/Validator/Spec/Error/InconsistentUnitsForWidthAndHeight.php create mode 100644 src/Validator/Spec/Error/IncorrectMinNumChildTags.php create mode 100644 src/Validator/Spec/Error/IncorrectNumChildTags.php create mode 100644 src/Validator/Spec/Error/IncorrectScriptReleaseVersion.php create mode 100644 src/Validator/Spec/Error/InlineScriptTooLong.php create mode 100644 src/Validator/Spec/Error/InlineStyleTooLong.php create mode 100644 src/Validator/Spec/Error/InvalidAttrValue.php create mode 100644 src/Validator/Spec/Error/InvalidDoctypeHtml.php create mode 100644 src/Validator/Spec/Error/InvalidJsonCdata.php create mode 100644 src/Validator/Spec/Error/InvalidPropertyValueInAttrValue.php create mode 100644 src/Validator/Spec/Error/InvalidUrl.php create mode 100644 src/Validator/Spec/Error/InvalidUrlProtocol.php create mode 100644 src/Validator/Spec/Error/InvalidUtf8.php create mode 100644 src/Validator/Spec/Error/LtsScriptAfterNonLts.php create mode 100644 src/Validator/Spec/Error/MandatoryAnyofAttrMissing.php create mode 100644 src/Validator/Spec/Error/MandatoryAttrMissing.php create mode 100644 src/Validator/Spec/Error/MandatoryCdataMissingOrIncorrect.php create mode 100644 src/Validator/Spec/Error/MandatoryLastChildTag.php create mode 100644 src/Validator/Spec/Error/MandatoryOneofAttrMissing.php create mode 100644 src/Validator/Spec/Error/MandatoryPropertyMissingFromAttrValue.php create mode 100644 src/Validator/Spec/Error/MandatoryReferencePointMissing.php create mode 100644 src/Validator/Spec/Error/MandatoryTagAncestor.php create mode 100644 src/Validator/Spec/Error/MandatoryTagAncestorWithHint.php create mode 100644 src/Validator/Spec/Error/MandatoryTagMissing.php create mode 100644 src/Validator/Spec/Error/MissingLayoutAttributes.php create mode 100644 src/Validator/Spec/Error/MissingRequiredExtension.php create mode 100644 src/Validator/Spec/Error/MissingUrl.php create mode 100644 src/Validator/Spec/Error/MutuallyExclusiveAttrs.php create mode 100644 src/Validator/Spec/Error/NonLtsScriptAfterLts.php create mode 100644 src/Validator/Spec/Error/NonWhitespaceCdataEncountered.php create mode 100644 src/Validator/Spec/Error/SpecifiedLayoutInvalid.php create mode 100644 src/Validator/Spec/Error/StylesheetAndInlineStyleTooLong.php create mode 100644 src/Validator/Spec/Error/StylesheetTooLong.php create mode 100644 src/Validator/Spec/Error/TagExcludedByTag.php create mode 100644 src/Validator/Spec/Error/TagNotAllowedToHaveSiblings.php create mode 100644 src/Validator/Spec/Error/TagReferencePointConflict.php create mode 100644 src/Validator/Spec/Error/TagRequiredByMissing.php create mode 100644 src/Validator/Spec/Error/TemplateInAttrName.php create mode 100644 src/Validator/Spec/Error/TemplatePartialInAttrValue.php create mode 100644 src/Validator/Spec/Error/UnescapedTemplateInAttrValue.php create mode 100644 src/Validator/Spec/Error/UnknownCode.php create mode 100644 src/Validator/Spec/Error/ValueSetMismatch.php create mode 100644 src/Validator/Spec/Error/WarningExtensionDeprecatedVersion.php create mode 100644 src/Validator/Spec/Error/WarningExtensionUnused.php create mode 100644 src/Validator/Spec/Error/WarningTagRequiredByMissing.php create mode 100644 src/Validator/Spec/Error/WrongParentTag.php create mode 100644 tests/Exception/InvalidErrorCodeTest.php create mode 100644 tests/Validator/Spec/ErrorTest.php create mode 100644 tests/Validator/Spec/Section/ErrorsTest.php create mode 100644 tests/src/ValidatorFixtures/DummyError.php diff --git a/bin/src/Validator/SpecGenerator.php b/bin/src/Validator/SpecGenerator.php index 854d41c70..39672e2cd 100644 --- a/bin/src/Validator/SpecGenerator.php +++ b/bin/src/Validator/SpecGenerator.php @@ -52,6 +52,7 @@ public function generate($jsonSpec, $rootNamespace, $destination) $this->generateEntityClass('DescendantTagList', $fileManager); $this->generateEntityClass('CssRuleset', $fileManager); $this->generateEntityClass('DocRuleset', $fileManager); + $this->generateEntityClass('Error', $fileManager); $this->generateEntityClass('Tag', $fileManager); $this->generateEntityClass('TagWithExtensionSpec', $fileManager, 'interface'); $this->generateEntityClass('ExtensionSpec', $fileManager, 'trait'); diff --git a/bin/src/Validator/SpecGenerator/Dumper.php b/bin/src/Validator/SpecGenerator/Dumper.php index b4ff69b7b..be5319fa9 100644 --- a/bin/src/Validator/SpecGenerator/Dumper.php +++ b/bin/src/Validator/SpecGenerator/Dumper.php @@ -249,6 +249,10 @@ public function filterValueStrings($value) || strpos($value, 'Element::') === 0 || + strpos($value, 'Error::') === 0 + || + strpos($value, 'Error\\') === 0 + || strpos($value, 'ErrorCode::') === 0 || strpos($value, 'Extension::') === 0 diff --git a/bin/src/Validator/SpecGenerator/FileManager.php b/bin/src/Validator/SpecGenerator/FileManager.php index 1716eda9f..685b16953 100644 --- a/bin/src/Validator/SpecGenerator/FileManager.php +++ b/bin/src/Validator/SpecGenerator/FileManager.php @@ -65,6 +65,7 @@ public function ensureDirectoriesExist() "{$this->destination}/Spec/DocRuleset", "{$this->destination}/Spec/DeclarationList", "{$this->destination}/Spec/DescendantTagList", + "{$this->destination}/Spec/Error", "{$this->destination}/Spec/Section", "{$this->destination}/Spec/Tag", ]; @@ -305,6 +306,10 @@ private function getFullyQualifiedName($class) return "AmpProject\\Validator\\Spec\\DocSpecRule"; } + if (strpos($class, 'Error\\') === 0) { + return "AmpProject\\Validator\\Spec\\Error"; + } + if (strpos($class, 'AttributeList\\') === 0) { return "AmpProject\\Validator\\Spec\\AttributeList"; } @@ -320,7 +325,15 @@ private function getFullyQualifiedName($class) if ( in_array( $class, - ['AttributeList', 'CssRuleset', 'DocRuleset', 'DeclarationList', 'DescendantTagList', 'SpecRule'], + [ + 'AttributeList', + 'CssRuleset', + 'DocRuleset', + 'DeclarationList', + 'DescendantTagList', + 'Error', + 'SpecRule' + ], true ) ) { @@ -330,7 +343,15 @@ private function getFullyQualifiedName($class) if ( in_array( $class, - ['AttributeLists', 'CssRulesets', 'DocRulesets', 'DeclarationLists', 'DescendantTagLists', 'Tags'], + [ + 'AttributeLists', + 'CssRulesets', + 'DocRulesets', + 'DeclarationLists', + 'DescendantTagLists', + 'Errors', + 'Tags' + ], true ) ) { diff --git a/bin/src/Validator/SpecGenerator/Section/AttributeLists.php b/bin/src/Validator/SpecGenerator/Section/AttributeLists.php index 7e56fa72f..049a8b845 100644 --- a/bin/src/Validator/SpecGenerator/Section/AttributeLists.php +++ b/bin/src/Validator/SpecGenerator/Section/AttributeLists.php @@ -4,7 +4,6 @@ use AmpProject\Tooling\Validator\SpecGenerator\ClassNames; use AmpProject\Tooling\Validator\SpecGenerator\ConstantNames; -use AmpProject\Tooling\Validator\SpecGenerator\Dumper; use AmpProject\Tooling\Validator\SpecGenerator\FileManager; use AmpProject\Tooling\Validator\SpecGenerator\Section; use AmpProject\Tooling\Validator\SpecGenerator\Template; @@ -16,21 +15,6 @@ final class AttributeLists implements Section use ClassNames; use ConstantNames; - /** - * Dumper instance to use. - * - * @var Dumper - */ - private $dumper; - - /** - * AttributeLists constructor. - */ - public function __construct() - { - $this->dumper = new Dumper(); - } - /** * Process a section. * diff --git a/bin/src/Validator/SpecGenerator/Section/CssRulesets.php b/bin/src/Validator/SpecGenerator/Section/CssRulesets.php index bdd0ed53e..3629aa5c1 100644 --- a/bin/src/Validator/SpecGenerator/Section/CssRulesets.php +++ b/bin/src/Validator/SpecGenerator/Section/CssRulesets.php @@ -2,10 +2,8 @@ namespace AmpProject\Tooling\Validator\SpecGenerator\Section; -use AmpProject\Tooling\Validator\SpecGenerator\ArrayKeyFirstPolyfill; use AmpProject\Tooling\Validator\SpecGenerator\ClassNames; use AmpProject\Tooling\Validator\SpecGenerator\ConstantNames; -use AmpProject\Tooling\Validator\SpecGenerator\Dumper; use AmpProject\Tooling\Validator\SpecGenerator\FileManager; use AmpProject\Tooling\Validator\SpecGenerator\Section; use AmpProject\Tooling\Validator\SpecGenerator\Template; @@ -14,25 +12,9 @@ final class CssRulesets implements Section { - use ArrayKeyFirstPolyfill; use ClassNames; use ConstantNames; - /** - * Dumper instance to use. - * - * @var Dumper - */ - private $dumper; - - /** - * CssRulesets constructor. - */ - public function __construct() - { - $this->dumper = new Dumper(); - } - /** * Process a section. * diff --git a/bin/src/Validator/SpecGenerator/Section/DeclarationLists.php b/bin/src/Validator/SpecGenerator/Section/DeclarationLists.php index 9fe55d8ee..d4be797ef 100644 --- a/bin/src/Validator/SpecGenerator/Section/DeclarationLists.php +++ b/bin/src/Validator/SpecGenerator/Section/DeclarationLists.php @@ -4,7 +4,6 @@ use AmpProject\Tooling\Validator\SpecGenerator\ClassNames; use AmpProject\Tooling\Validator\SpecGenerator\ConstantNames; -use AmpProject\Tooling\Validator\SpecGenerator\Dumper; use AmpProject\Tooling\Validator\SpecGenerator\FileManager; use AmpProject\Tooling\Validator\SpecGenerator\Section; use AmpProject\Tooling\Validator\SpecGenerator\Template; @@ -16,21 +15,6 @@ final class DeclarationLists implements Section use ClassNames; use ConstantNames; - /** - * Dumper instance to use. - * - * @var Dumper - */ - private $dumper; - - /** - * DeclarationLists constructor. - */ - public function __construct() - { - $this->dumper = new Dumper(); - } - /** * Process a section. * diff --git a/bin/src/Validator/SpecGenerator/Section/DescendantTagLists.php b/bin/src/Validator/SpecGenerator/Section/DescendantTagLists.php index ced9d9709..6c77a5e8b 100644 --- a/bin/src/Validator/SpecGenerator/Section/DescendantTagLists.php +++ b/bin/src/Validator/SpecGenerator/Section/DescendantTagLists.php @@ -4,7 +4,6 @@ use AmpProject\Tooling\Validator\SpecGenerator\ClassNames; use AmpProject\Tooling\Validator\SpecGenerator\ConstantNames; -use AmpProject\Tooling\Validator\SpecGenerator\Dumper; use AmpProject\Tooling\Validator\SpecGenerator\FileManager; use AmpProject\Tooling\Validator\SpecGenerator\Section; use AmpProject\Tooling\Validator\SpecGenerator\Template; @@ -16,21 +15,6 @@ final class DescendantTagLists implements Section use ClassNames; use ConstantNames; - /** - * Dumper instance to use. - * - * @var Dumper - */ - private $dumper; - - /** - * DescendantTagLists constructor. - */ - public function __construct() - { - $this->dumper = new Dumper(); - } - /** * Process a section. * diff --git a/bin/src/Validator/SpecGenerator/Section/DocRulesets.php b/bin/src/Validator/SpecGenerator/Section/DocRulesets.php index 61026f3a5..155054ac7 100644 --- a/bin/src/Validator/SpecGenerator/Section/DocRulesets.php +++ b/bin/src/Validator/SpecGenerator/Section/DocRulesets.php @@ -2,10 +2,8 @@ namespace AmpProject\Tooling\Validator\SpecGenerator\Section; -use AmpProject\Tooling\Validator\SpecGenerator\ArrayKeyFirstPolyfill; use AmpProject\Tooling\Validator\SpecGenerator\ClassNames; use AmpProject\Tooling\Validator\SpecGenerator\ConstantNames; -use AmpProject\Tooling\Validator\SpecGenerator\Dumper; use AmpProject\Tooling\Validator\SpecGenerator\FileManager; use AmpProject\Tooling\Validator\SpecGenerator\Section; use AmpProject\Tooling\Validator\SpecGenerator\Template; @@ -14,25 +12,9 @@ final class DocRulesets implements Section { - use ArrayKeyFirstPolyfill; use ClassNames; use ConstantNames; - /** - * Dumper instance to use. - * - * @var Dumper - */ - private $dumper; - - /** - * DocRulesets constructor. - */ - public function __construct() - { - $this->dumper = new Dumper(); - } - /** * Process a section. * diff --git a/bin/src/Validator/SpecGenerator/Section/Errors.php b/bin/src/Validator/SpecGenerator/Section/Errors.php index 93b88f9c4..5ef476208 100644 --- a/bin/src/Validator/SpecGenerator/Section/Errors.php +++ b/bin/src/Validator/SpecGenerator/Section/Errors.php @@ -2,32 +2,19 @@ namespace AmpProject\Tooling\Validator\SpecGenerator\Section; +use AmpProject\Tooling\Validator\SpecGenerator\ClassNames; use AmpProject\Tooling\Validator\SpecGenerator\ConstantNames; -use AmpProject\Tooling\Validator\SpecGenerator\Dumper; use AmpProject\Tooling\Validator\SpecGenerator\FileManager; use AmpProject\Tooling\Validator\SpecGenerator\Section; +use AmpProject\Tooling\Validator\SpecGenerator\Template; use Nette\PhpGenerator\ClassType; use Nette\PhpGenerator\PhpNamespace; final class Errors implements Section { + use ClassNames; use ConstantNames; - /** - * Dumper instance to use. - * - * @var Dumper - */ - private $dumper; - - /** - * Errors constructor. - */ - public function __construct() - { - $this->dumper = new Dumper(); - } - /** * Process a section. * @@ -39,29 +26,68 @@ public function __construct() */ public function process(FileManager $fileManager, $spec, PhpNamespace $namespace, ClassType $class) { - $propertyName = lcfirst($class->getName()); + $namespace->addUse('AmpProject\Exception\InvalidListName'); + $namespace->addUse("{$fileManager->getRootNamespace()}\\Spec"); + $namespace->addUse("{$fileManager->getRootNamespace()}\\Spec\\Error"); + $namespace->addUse("{$fileManager->getRootNamespace()}\\Spec\\IterableSection"); + $namespace->addUse("{$fileManager->getRootNamespace()}\\Spec\\Iteration"); - $namespace->addUse('AmpProject\\Validator\\ErrorCode'); + $class->addImplement("{$fileManager->getRootNamespace()}\\Spec\\IterableSection"); + $class->addTrait( + "{$fileManager->getRootNamespace()}\\Spec\\Iteration", + ['Iteration::current as parentCurrent'] + ); - $class->addProperty($propertyName) - ->addComment('@var array'); - - $errorData = []; + $class->addProperty('errors') + ->setValue([]) + ->setPrivate() + ->addComment("Cache of instantiated Error objects.\n\n@var array"); + $errors = []; foreach ($spec as $key => $value) { - $key = $this->getErrorCodeConstant($this->getConstantName($key)); - $errorData[$key] = $value; + $className = $this->generateErrorSpecificClass($key, $value, $fileManager); + + $errors["Error\\{$className}::CODE"] = "Error\\{$className}::class"; } + $class->addConstant('ERRORS', $errors) + ->addComment("Mapping of error code to error implementation.\n\n@var array"); - ksort($errorData); + $errorsTemplateClass = ClassType::withBodiesFrom(Template\Errors::class); + foreach ($errorsTemplateClass->getMethods() as $method) { + $class->addMember($method); + } + } - $constructor = $class->addMethod('__construct'); - $constructor->addBody('$this->? = [', [$propertyName]); + /** + * Generate the Error-specific class file. + * + * @param string $errorCode Code of the error to generate the class for. + * @param array $jsonSpec Array of spec data for the error. + * @param FileManager $fileManager File manager instance to use. + * @return string Short name of the class that was generated. + */ + private function generateErrorSpecificClass($errorCode, $jsonSpec, FileManager $fileManager) + { + list($file, $namespace) = $fileManager->createNewNamespacedFile('Spec\\Error'); - foreach ($errorData as $key => $value) { - $constructor->addBody(" {$this->dumper->dumpWithKey($key, $value, 1)},"); - } + $className = $this->getClassNameFromId($errorCode); + + $namespace->addUse("{$fileManager->getRootNamespace()}\\Spec\\SpecRule"); + $namespace->addUse("{$fileManager->getRootNamespace()}\\Spec\\Error"); + + /** @var ClassType $class */ + $class = $namespace->addClass($className) + ->setFinal() + ->addExtend('AmpProject\Validator\Spec\Error'); + + $class->addConstant('CODE', $errorCode) + ->addComment("Code of the error.\n\n@var string"); + + $class->addConstant('SPEC', $jsonSpec) + ->addComment("Array of spec data.\n\n@var array"); + + $fileManager->saveFile($file, "Spec/Error/{$className}.php"); - $constructor->addBody('];'); + return $className; } } diff --git a/bin/src/Validator/SpecGenerator/Section/Tags.php b/bin/src/Validator/SpecGenerator/Section/Tags.php index 8b0944438..96ce3a69a 100644 --- a/bin/src/Validator/SpecGenerator/Section/Tags.php +++ b/bin/src/Validator/SpecGenerator/Section/Tags.php @@ -2,10 +2,8 @@ namespace AmpProject\Tooling\Validator\SpecGenerator\Section; -use AmpProject\Tooling\Validator\SpecGenerator\ArrayKeyFirstPolyfill; use AmpProject\Tooling\Validator\SpecGenerator\ClassNames; use AmpProject\Tooling\Validator\SpecGenerator\ConstantNames; -use AmpProject\Tooling\Validator\SpecGenerator\Dumper; use AmpProject\Tooling\Validator\SpecGenerator\FileManager; use AmpProject\Tooling\Validator\SpecGenerator\Section; use AmpProject\Tooling\Validator\SpecGenerator\Template; @@ -14,25 +12,9 @@ final class Tags implements Section { - use ArrayKeyFirstPolyfill; use ClassNames; use ConstantNames; - /** - * Dumper instance to use. - * - * @var Dumper - */ - private $dumper; - - /** - * Tags constructor. - */ - public function __construct() - { - $this->dumper = new Dumper(); - } - /** * Process a section. * diff --git a/bin/src/Validator/SpecGenerator/Template/Error.php b/bin/src/Validator/SpecGenerator/Template/Error.php new file mode 100644 index 000000000..e0e13c95d --- /dev/null +++ b/bin/src/Validator/SpecGenerator/Template/Error.php @@ -0,0 +1,61 @@ + + */ + const SPEC = []; + + /** + * Get the code of the error. + * + * @return string Code of the error. + */ + public function getCode() + { + return static::CODE; + } + + /** + * Check whether the error has a given spec rule. + * + * @param string $specRule Spec rule to check for. + * @return bool Whether the error has the given spec rule. + */ + public function has($specRule) + { + return array_key_exists($specRule, static::SPEC); + } + + /** + * Get a specific spec rule. + * + * @param string $specRuleName Name of the spec rule to get. + * @return array Spec rule data that was requested. + */ + public function get($specRuleName) + { + if (!$this->has($specRuleName)) { + throw InvalidSpecRuleName::forSpecRuleName($specRuleName); + } + + return static::SPEC[$specRuleName]; + } +} diff --git a/bin/src/Validator/SpecGenerator/Template/Errors.php b/bin/src/Validator/SpecGenerator/Template/Errors.php new file mode 100644 index 000000000..967e91182 --- /dev/null +++ b/bin/src/Validator/SpecGenerator/Template/Errors.php @@ -0,0 +1,78 @@ + */ + const ERRORS = []; + + /** @var array */ + private $errors = []; + + /** + * Get a specific error. + * + * @param string $errorCode Code of the error to get. + * @return Spec\Error Error with the given error code. + * @throws InvalidErrorCode If an invalid error code is requested. + */ + public function get($errorCode) + { + if (!array_key_exists($errorCode, self::ERRORS)) { + throw InvalidErrorCode::forErrorCode($errorCode); + } + + if (array_key_exists($errorCode, $this->errors)) { + return $this->errors[$errorCode]; + } + + $errorClassName = self::ERRORS[$errorCode]; + + /** @var Spec\Error $error */ + $error = new $errorClassName(); + + $this->errors[$errorCode] = $error; + + return $error; + } + + /** + * Get the list of available keys. + * + * @return array Array of available keys. + */ + public function getAvailableKeys() + { + return array_keys(self::ERRORS); + } + + /** + * Find the instantiated object for the current key. + * + * This should use its own caching mechanism as needed. + * + * Ideally, current() should be overridden as well to provide the correct object type-hint. + * + * @param string $key Key to retrieve the instantiated object for. + * @return object Instantiated object for the current key. + */ + public function findByKey($key) + { + return $this->get($key); + } + + /** + * Return the current iterable object. + * + * @return Error Error object. + */ + public function current() + { + return $this->parentCurrent(); + } +} diff --git a/src/Exception/InvalidErrorCode.php b/src/Exception/InvalidErrorCode.php new file mode 100644 index 000000000..f4f061856 --- /dev/null +++ b/src/Exception/InvalidErrorCode.php @@ -0,0 +1,27 @@ + + */ + const SPEC = []; + + /** + * Get the code of the error. + * + * @return string Code of the error. + */ + public function getCode() + { + return static::CODE; + } + + /** + * Check whether the error has a given spec rule. + * + * @param string $specRule Spec rule to check for. + * @return bool Whether the error has the given spec rule. + */ + public function has($specRule) + { + return array_key_exists($specRule, static::SPEC); + } + + /** + * Get a specific spec rule. + * + * @param string $specRuleName Name of the spec rule to get. + * @return array Spec rule data that was requested. + */ + public function get($specRuleName) + { + if (!$this->has($specRuleName)) { + throw InvalidSpecRuleName::forSpecRuleName($specRuleName); + } + + return static::SPEC[$specRuleName]; + } +} diff --git a/src/Validator/Spec/Error/AmpEmailMissingStrictCssAttr.php b/src/Validator/Spec/Error/AmpEmailMissingStrictCssAttr.php new file mode 100644 index 000000000..514f4eabc --- /dev/null +++ b/src/Validator/Spec/Error/AmpEmailMissingStrictCssAttr.php @@ -0,0 +1,30 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'Tag \'html\' marked with attribute \'amp4email\' is missing the corresponding attribute \'data-css-strict\' for enabling strict CSS validation. This may become an error in the future.', + ]; +} diff --git a/src/Validator/Spec/Error/AttrDisallowedByImpliedLayout.php b/src/Validator/Spec/Error/AttrDisallowedByImpliedLayout.php new file mode 100644 index 000000000..f161ce912 --- /dev/null +++ b/src/Validator/Spec/Error/AttrDisallowedByImpliedLayout.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'The attribute \'%1\' in tag \'%2\' is disallowed by implied layout \'%3\'.', + SpecRule::SPECIFICITY => 48, + ]; +} diff --git a/src/Validator/Spec/Error/AttrDisallowedBySpecifiedLayout.php b/src/Validator/Spec/Error/AttrDisallowedBySpecifiedLayout.php new file mode 100644 index 000000000..6f246f31b --- /dev/null +++ b/src/Validator/Spec/Error/AttrDisallowedBySpecifiedLayout.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'The attribute \'%1\' in tag \'%2\' is disallowed by specified layout \'%3\'.', + SpecRule::SPECIFICITY => 49, + ]; +} diff --git a/src/Validator/Spec/Error/AttrMissingRequiredExtension.php b/src/Validator/Spec/Error/AttrMissingRequiredExtension.php new file mode 100644 index 000000000..e88f139b0 --- /dev/null +++ b/src/Validator/Spec/Error/AttrMissingRequiredExtension.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'The attribute \'%1\' requires including the \'%2\' extension JavaScript.', + SpecRule::SPECIFICITY => 13, + ]; +} diff --git a/src/Validator/Spec/Error/AttrRequiredButMissing.php b/src/Validator/Spec/Error/AttrRequiredButMissing.php new file mode 100644 index 000000000..4f992ffdc --- /dev/null +++ b/src/Validator/Spec/Error/AttrRequiredButMissing.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'The attribute \'%1\' in tag \'%2\' is missing or incorrect, but required by attribute \'%3\'.', + SpecRule::SPECIFICITY => 29, + ]; +} diff --git a/src/Validator/Spec/Error/AttrValueRequiredByLayout.php b/src/Validator/Spec/Error/AttrValueRequiredByLayout.php new file mode 100644 index 000000000..719bd8bf7 --- /dev/null +++ b/src/Validator/Spec/Error/AttrValueRequiredByLayout.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'Invalid value \'%1\' for attribute \'%2\' in tag \'%3\' - for layout \'%4\', set the attribute \'%2\' to value \'%5\'.', + SpecRule::SPECIFICITY => 25, + ]; +} diff --git a/src/Validator/Spec/Error/BaseTagMustPreceedAllUrls.php b/src/Validator/Spec/Error/BaseTagMustPreceedAllUrls.php new file mode 100644 index 000000000..a3fc4b110 --- /dev/null +++ b/src/Validator/Spec/Error/BaseTagMustPreceedAllUrls.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'The tag \'%1\', which contains URLs, was found earlier in the document than the BASE element.', + SpecRule::SPECIFICITY => 87, + ]; +} diff --git a/src/Validator/Spec/Error/CdataViolatesDenylist.php b/src/Validator/Spec/Error/CdataViolatesDenylist.php new file mode 100644 index 000000000..777575b63 --- /dev/null +++ b/src/Validator/Spec/Error/CdataViolatesDenylist.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'The text inside tag \'%1\' contains \'%2\', which is disallowed.', + SpecRule::SPECIFICITY => 2, + ]; +} diff --git a/src/Validator/Spec/Error/ChildTagDoesNotSatisfyReferencePoint.php b/src/Validator/Spec/Error/ChildTagDoesNotSatisfyReferencePoint.php new file mode 100644 index 000000000..30730a90b --- /dev/null +++ b/src/Validator/Spec/Error/ChildTagDoesNotSatisfyReferencePoint.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'The tag \'%1\', a child tag of \'%2\', does not satisfy one of the acceptable reference points: %3.', + SpecRule::SPECIFICITY => 77, + ]; +} diff --git a/src/Validator/Spec/Error/ChildTagDoesNotSatisfyReferencePointSingular.php b/src/Validator/Spec/Error/ChildTagDoesNotSatisfyReferencePointSingular.php new file mode 100644 index 000000000..51b944592 --- /dev/null +++ b/src/Validator/Spec/Error/ChildTagDoesNotSatisfyReferencePointSingular.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'The tag \'%1\', a child tag of \'%2\', does not satisfy the reference point \'%3\'.', + SpecRule::SPECIFICITY => 81, + ]; +} diff --git a/src/Validator/Spec/Error/CssExcessivelyNested.php b/src/Validator/Spec/Error/CssExcessivelyNested.php new file mode 100644 index 000000000..9b5e47fe4 --- /dev/null +++ b/src/Validator/Spec/Error/CssExcessivelyNested.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'CSS excessively nested in tag \'%1\'.', + SpecRule::SPECIFICITY => 125, + ]; +} diff --git a/src/Validator/Spec/Error/CssSyntaxBadUrl.php b/src/Validator/Spec/Error/CssSyntaxBadUrl.php new file mode 100644 index 000000000..1687fdb63 --- /dev/null +++ b/src/Validator/Spec/Error/CssSyntaxBadUrl.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'CSS syntax error in tag \'%1\' - bad url.', + SpecRule::SPECIFICITY => 60, + ]; +} diff --git a/src/Validator/Spec/Error/CssSyntaxDisallowedAttrSelector.php b/src/Validator/Spec/Error/CssSyntaxDisallowedAttrSelector.php new file mode 100644 index 000000000..e66f22e51 --- /dev/null +++ b/src/Validator/Spec/Error/CssSyntaxDisallowedAttrSelector.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'CSS error in tag \'%1\' - disallowed attribute selector \'%2\'.', + SpecRule::SPECIFICITY => 120, + ]; +} diff --git a/src/Validator/Spec/Error/CssSyntaxDisallowedDomain.php b/src/Validator/Spec/Error/CssSyntaxDisallowedDomain.php new file mode 100644 index 000000000..d763f0f66 --- /dev/null +++ b/src/Validator/Spec/Error/CssSyntaxDisallowedDomain.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'CSS syntax error in tag \'%1\' - invalid domain \'%2\'.', + SpecRule::SPECIFICITY => 69, + ]; +} diff --git a/src/Validator/Spec/Error/CssSyntaxDisallowedImportant.php b/src/Validator/Spec/Error/CssSyntaxDisallowedImportant.php new file mode 100644 index 000000000..2ab8e5ec4 --- /dev/null +++ b/src/Validator/Spec/Error/CssSyntaxDisallowedImportant.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'Usage of the !important CSS qualifier is not allowed.', + SpecRule::SPECIFICITY => 123, + ]; +} diff --git a/src/Validator/Spec/Error/CssSyntaxDisallowedKeyframeInsideKeyframe.php b/src/Validator/Spec/Error/CssSyntaxDisallowedKeyframeInsideKeyframe.php new file mode 100644 index 000000000..ad059a0a4 --- /dev/null +++ b/src/Validator/Spec/Error/CssSyntaxDisallowedKeyframeInsideKeyframe.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'CSS syntax error in tag \'%1\' - keyframe inside keyframe is not allowed.', + SpecRule::SPECIFICITY => 115, + ]; +} diff --git a/src/Validator/Spec/Error/CssSyntaxDisallowedMediaFeature.php b/src/Validator/Spec/Error/CssSyntaxDisallowedMediaFeature.php new file mode 100644 index 000000000..d7347b953 --- /dev/null +++ b/src/Validator/Spec/Error/CssSyntaxDisallowedMediaFeature.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'CSS syntax error in tag \'%1\' - disallowed media feature \'%2\'.', + SpecRule::SPECIFICITY => 119, + ]; +} diff --git a/src/Validator/Spec/Error/CssSyntaxDisallowedMediaType.php b/src/Validator/Spec/Error/CssSyntaxDisallowedMediaType.php new file mode 100644 index 000000000..6129d8e2e --- /dev/null +++ b/src/Validator/Spec/Error/CssSyntaxDisallowedMediaType.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'CSS syntax error in tag \'%1\' - disallowed media type \'%2\'.', + SpecRule::SPECIFICITY => 118, + ]; +} diff --git a/src/Validator/Spec/Error/CssSyntaxDisallowedPropertyValue.php b/src/Validator/Spec/Error/CssSyntaxDisallowedPropertyValue.php new file mode 100644 index 000000000..d020f7cd2 --- /dev/null +++ b/src/Validator/Spec/Error/CssSyntaxDisallowedPropertyValue.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'CSS syntax error in tag \'%1\' - the property \'%2\' is set to the disallowed value \'%3\'.', + SpecRule::SPECIFICITY => 82, + ]; +} diff --git a/src/Validator/Spec/Error/CssSyntaxDisallowedPropertyValueWithHint.php b/src/Validator/Spec/Error/CssSyntaxDisallowedPropertyValueWithHint.php new file mode 100644 index 000000000..b83c82b48 --- /dev/null +++ b/src/Validator/Spec/Error/CssSyntaxDisallowedPropertyValueWithHint.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'CSS syntax error in tag \'%1\' - the property \'%2\' is set to the disallowed value \'%3\'. Allowed values: %4.', + SpecRule::SPECIFICITY => 83, + ]; +} diff --git a/src/Validator/Spec/Error/CssSyntaxDisallowedPseudoClass.php b/src/Validator/Spec/Error/CssSyntaxDisallowedPseudoClass.php new file mode 100644 index 000000000..e0b2161d7 --- /dev/null +++ b/src/Validator/Spec/Error/CssSyntaxDisallowedPseudoClass.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'CSS error in tag \'%1\' - disallowed pseudo class \'%2\'.', + SpecRule::SPECIFICITY => 121, + ]; +} diff --git a/src/Validator/Spec/Error/CssSyntaxDisallowedPseudoElement.php b/src/Validator/Spec/Error/CssSyntaxDisallowedPseudoElement.php new file mode 100644 index 000000000..3a21f4f06 --- /dev/null +++ b/src/Validator/Spec/Error/CssSyntaxDisallowedPseudoElement.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'CSS error in tag \'%1\' - disallowed pseudo element \'%2\'.', + SpecRule::SPECIFICITY => 122, + ]; +} diff --git a/src/Validator/Spec/Error/CssSyntaxDisallowedQualifiedRuleMustBeInsideKeyframe.php b/src/Validator/Spec/Error/CssSyntaxDisallowedQualifiedRuleMustBeInsideKeyframe.php new file mode 100644 index 000000000..e1c9a0403 --- /dev/null +++ b/src/Validator/Spec/Error/CssSyntaxDisallowedQualifiedRuleMustBeInsideKeyframe.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'CSS syntax error in tag \'%1\' - qualified rule \'%2\' must be located inside of a keyframe.', + SpecRule::SPECIFICITY => 114, + ]; +} diff --git a/src/Validator/Spec/Error/CssSyntaxDisallowedRelativeUrl.php b/src/Validator/Spec/Error/CssSyntaxDisallowedRelativeUrl.php new file mode 100644 index 000000000..aa7a4b37d --- /dev/null +++ b/src/Validator/Spec/Error/CssSyntaxDisallowedRelativeUrl.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'CSS syntax error in tag \'%1\' - disallowed relative url \'%2\'.', + SpecRule::SPECIFICITY => 72, + ]; +} diff --git a/src/Validator/Spec/Error/CssSyntaxEofInPreludeOfQualifiedRule.php b/src/Validator/Spec/Error/CssSyntaxEofInPreludeOfQualifiedRule.php new file mode 100644 index 000000000..8b6b4cb3e --- /dev/null +++ b/src/Validator/Spec/Error/CssSyntaxEofInPreludeOfQualifiedRule.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'CSS syntax error in tag \'%1\' - end of stylesheet encountered in prelude of a qualified rule.', + SpecRule::SPECIFICITY => 61, + ]; +} diff --git a/src/Validator/Spec/Error/CssSyntaxErrorInPseudoSelector.php b/src/Validator/Spec/Error/CssSyntaxErrorInPseudoSelector.php new file mode 100644 index 000000000..037345ae3 --- /dev/null +++ b/src/Validator/Spec/Error/CssSyntaxErrorInPseudoSelector.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'CSS syntax error in tag \'%1\' - invalid pseudo selector.', + SpecRule::SPECIFICITY => 64, + ]; +} diff --git a/src/Validator/Spec/Error/CssSyntaxIncompleteDeclaration.php b/src/Validator/Spec/Error/CssSyntaxIncompleteDeclaration.php new file mode 100644 index 000000000..1706a8d38 --- /dev/null +++ b/src/Validator/Spec/Error/CssSyntaxIncompleteDeclaration.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'CSS syntax error in tag \'%1\' - incomplete declaration.', + SpecRule::SPECIFICITY => 63, + ]; +} diff --git a/src/Validator/Spec/Error/CssSyntaxInvalidAtRule.php b/src/Validator/Spec/Error/CssSyntaxInvalidAtRule.php new file mode 100644 index 000000000..33ed79dad --- /dev/null +++ b/src/Validator/Spec/Error/CssSyntaxInvalidAtRule.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'CSS syntax error in tag \'%1\' - saw invalid at rule \'@%2\'.', + SpecRule::SPECIFICITY => 36, + ]; +} diff --git a/src/Validator/Spec/Error/CssSyntaxInvalidAttrSelector.php b/src/Validator/Spec/Error/CssSyntaxInvalidAttrSelector.php new file mode 100644 index 000000000..813f107fc --- /dev/null +++ b/src/Validator/Spec/Error/CssSyntaxInvalidAttrSelector.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'CSS syntax error in tag \'%1\' - invalid attribute selector.', + SpecRule::SPECIFICITY => 76, + ]; +} diff --git a/src/Validator/Spec/Error/CssSyntaxInvalidDeclaration.php b/src/Validator/Spec/Error/CssSyntaxInvalidDeclaration.php new file mode 100644 index 000000000..bba9e7e1f --- /dev/null +++ b/src/Validator/Spec/Error/CssSyntaxInvalidDeclaration.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'CSS syntax error in tag \'%1\' - invalid declaration.', + SpecRule::SPECIFICITY => 62, + ]; +} diff --git a/src/Validator/Spec/Error/CssSyntaxInvalidProperty.php b/src/Validator/Spec/Error/CssSyntaxInvalidProperty.php new file mode 100644 index 000000000..b0d5fdecd --- /dev/null +++ b/src/Validator/Spec/Error/CssSyntaxInvalidProperty.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'CSS syntax error in tag \'%1\' - invalid property \'%2\'. The only allowed properties are \'%3\'.', + SpecRule::SPECIFICITY => 111, + ]; +} diff --git a/src/Validator/Spec/Error/CssSyntaxInvalidPropertyNolist.php b/src/Validator/Spec/Error/CssSyntaxInvalidPropertyNolist.php new file mode 100644 index 000000000..ae17f5414 --- /dev/null +++ b/src/Validator/Spec/Error/CssSyntaxInvalidPropertyNolist.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'CSS syntax error in tag \'%1\' - invalid property \'%2\'.', + SpecRule::SPECIFICITY => 112, + ]; +} diff --git a/src/Validator/Spec/Error/CssSyntaxInvalidUrl.php b/src/Validator/Spec/Error/CssSyntaxInvalidUrl.php new file mode 100644 index 000000000..9d69f8ddc --- /dev/null +++ b/src/Validator/Spec/Error/CssSyntaxInvalidUrl.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'CSS syntax error in tag \'%1\' - invalid url \'%2\'.', + SpecRule::SPECIFICITY => 70, + ]; +} diff --git a/src/Validator/Spec/Error/CssSyntaxInvalidUrlProtocol.php b/src/Validator/Spec/Error/CssSyntaxInvalidUrlProtocol.php new file mode 100644 index 000000000..b2b5830cb --- /dev/null +++ b/src/Validator/Spec/Error/CssSyntaxInvalidUrlProtocol.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'CSS syntax error in tag \'%1\' - invalid url protocol \'%2:\'.', + SpecRule::SPECIFICITY => 71, + ]; +} diff --git a/src/Validator/Spec/Error/CssSyntaxMalformedMediaQuery.php b/src/Validator/Spec/Error/CssSyntaxMalformedMediaQuery.php new file mode 100644 index 000000000..2a3a3b84c --- /dev/null +++ b/src/Validator/Spec/Error/CssSyntaxMalformedMediaQuery.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'CSS syntax error in tag \'%1\' - malformed media query.', + SpecRule::SPECIFICITY => 117, + ]; +} diff --git a/src/Validator/Spec/Error/CssSyntaxMissingSelector.php b/src/Validator/Spec/Error/CssSyntaxMissingSelector.php new file mode 100644 index 000000000..bbbbdd338 --- /dev/null +++ b/src/Validator/Spec/Error/CssSyntaxMissingSelector.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'CSS syntax error in tag \'%1\' - missing selector.', + SpecRule::SPECIFICITY => 65, + ]; +} diff --git a/src/Validator/Spec/Error/CssSyntaxMissingUrl.php b/src/Validator/Spec/Error/CssSyntaxMissingUrl.php new file mode 100644 index 000000000..af082e27c --- /dev/null +++ b/src/Validator/Spec/Error/CssSyntaxMissingUrl.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'CSS syntax error in tag \'%1\' - missing url.', + SpecRule::SPECIFICITY => 68, + ]; +} diff --git a/src/Validator/Spec/Error/CssSyntaxNotASelectorStart.php b/src/Validator/Spec/Error/CssSyntaxNotASelectorStart.php new file mode 100644 index 000000000..f4758039e --- /dev/null +++ b/src/Validator/Spec/Error/CssSyntaxNotASelectorStart.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'CSS syntax error in tag \'%1\' - not a selector start.', + SpecRule::SPECIFICITY => 66, + ]; +} diff --git a/src/Validator/Spec/Error/CssSyntaxPropertyDisallowedTogetherWith.php b/src/Validator/Spec/Error/CssSyntaxPropertyDisallowedTogetherWith.php new file mode 100644 index 000000000..111e65c96 --- /dev/null +++ b/src/Validator/Spec/Error/CssSyntaxPropertyDisallowedTogetherWith.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'CSS syntax error in tag \'%1\' - the property \'%2\' is disallowed together with \'%3\'. Allowed properties: %4.', + SpecRule::SPECIFICITY => 85, + ]; +} diff --git a/src/Validator/Spec/Error/CssSyntaxPropertyDisallowedWithinAtRule.php b/src/Validator/Spec/Error/CssSyntaxPropertyDisallowedWithinAtRule.php new file mode 100644 index 000000000..8b22c4a30 --- /dev/null +++ b/src/Validator/Spec/Error/CssSyntaxPropertyDisallowedWithinAtRule.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'CSS syntax error in tag \'%1\' - the property \'%2\' is disallowed within @%3. Allowed properties: %4.', + SpecRule::SPECIFICITY => 84, + ]; +} diff --git a/src/Validator/Spec/Error/CssSyntaxPropertyRequiresQualification.php b/src/Validator/Spec/Error/CssSyntaxPropertyRequiresQualification.php new file mode 100644 index 000000000..5fe43ad0c --- /dev/null +++ b/src/Validator/Spec/Error/CssSyntaxPropertyRequiresQualification.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'CSS syntax error in tag \'%1\' - the property \'%2\' is disallowed unless the enclosing rule is prefixed with the \'%3\' qualification.', + SpecRule::SPECIFICITY => 86, + ]; +} diff --git a/src/Validator/Spec/Error/CssSyntaxQualifiedRuleHasNoDeclarations.php b/src/Validator/Spec/Error/CssSyntaxQualifiedRuleHasNoDeclarations.php new file mode 100644 index 000000000..b1d42808e --- /dev/null +++ b/src/Validator/Spec/Error/CssSyntaxQualifiedRuleHasNoDeclarations.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'CSS syntax error in tag \'%1\' - qualified rule \'%2\' has no declarations.', + SpecRule::SPECIFICITY => 113, + ]; +} diff --git a/src/Validator/Spec/Error/CssSyntaxStrayTrailingBackslash.php b/src/Validator/Spec/Error/CssSyntaxStrayTrailingBackslash.php new file mode 100644 index 000000000..03f58b974 --- /dev/null +++ b/src/Validator/Spec/Error/CssSyntaxStrayTrailingBackslash.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'CSS syntax error in tag \'%1\' - stray trailing backslash.', + SpecRule::SPECIFICITY => 57, + ]; +} diff --git a/src/Validator/Spec/Error/CssSyntaxUnparsedInputRemainsInSelector.php b/src/Validator/Spec/Error/CssSyntaxUnparsedInputRemainsInSelector.php new file mode 100644 index 000000000..74e47b41b --- /dev/null +++ b/src/Validator/Spec/Error/CssSyntaxUnparsedInputRemainsInSelector.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'CSS syntax error in tag \'%1\' - unparsed input remains in selector.', + SpecRule::SPECIFICITY => 67, + ]; +} diff --git a/src/Validator/Spec/Error/CssSyntaxUnterminatedComment.php b/src/Validator/Spec/Error/CssSyntaxUnterminatedComment.php new file mode 100644 index 000000000..e8f4966e5 --- /dev/null +++ b/src/Validator/Spec/Error/CssSyntaxUnterminatedComment.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'CSS syntax error in tag \'%1\' - unterminated comment.', + SpecRule::SPECIFICITY => 58, + ]; +} diff --git a/src/Validator/Spec/Error/CssSyntaxUnterminatedString.php b/src/Validator/Spec/Error/CssSyntaxUnterminatedString.php new file mode 100644 index 000000000..2049227e8 --- /dev/null +++ b/src/Validator/Spec/Error/CssSyntaxUnterminatedString.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'CSS syntax error in tag \'%1\' - unterminated string.', + SpecRule::SPECIFICITY => 59, + ]; +} diff --git a/src/Validator/Spec/Error/DeprecatedAttr.php b/src/Validator/Spec/Error/DeprecatedAttr.php new file mode 100644 index 000000000..c2ac2ddb6 --- /dev/null +++ b/src/Validator/Spec/Error/DeprecatedAttr.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'The attribute \'%1\' in tag \'%2\' is deprecated - use \'%3\' instead.', + SpecRule::SPECIFICITY => 104, + ]; +} diff --git a/src/Validator/Spec/Error/DeprecatedTag.php b/src/Validator/Spec/Error/DeprecatedTag.php new file mode 100644 index 000000000..d0447e645 --- /dev/null +++ b/src/Validator/Spec/Error/DeprecatedTag.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'The tag \'%1\' is deprecated - use \'%2\' instead.', + SpecRule::SPECIFICITY => 105, + ]; +} diff --git a/src/Validator/Spec/Error/DevModeOnly.php b/src/Validator/Spec/Error/DevModeOnly.php new file mode 100644 index 000000000..54457abfa --- /dev/null +++ b/src/Validator/Spec/Error/DevModeOnly.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'Tag \'html\' marked with attribute \'data-ampdevmode\'. Validator will suppress errors regarding any other tag with this attribute.', + SpecRule::SPECIFICITY => 1000, + ]; +} diff --git a/src/Validator/Spec/Error/DisallowedAttr.php b/src/Validator/Spec/Error/DisallowedAttr.php new file mode 100644 index 000000000..88907716b --- /dev/null +++ b/src/Validator/Spec/Error/DisallowedAttr.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'The attribute \'%1\' may not appear in tag \'%2\'.', + SpecRule::SPECIFICITY => 22, + ]; +} diff --git a/src/Validator/Spec/Error/DisallowedChildTagName.php b/src/Validator/Spec/Error/DisallowedChildTagName.php new file mode 100644 index 000000000..57e110aa9 --- /dev/null +++ b/src/Validator/Spec/Error/DisallowedChildTagName.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'Tag \'%1\' is disallowed as child of tag \'%2\'. Child tag must be one of %3.', + SpecRule::SPECIFICITY => 74, + ]; +} diff --git a/src/Validator/Spec/Error/DisallowedDomain.php b/src/Validator/Spec/Error/DisallowedDomain.php new file mode 100644 index 000000000..38ac021a0 --- /dev/null +++ b/src/Validator/Spec/Error/DisallowedDomain.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'The domain \'%3\' for attribute \'%1\' in tag \'%2\' is disallowed.', + SpecRule::SPECIFICITY => 53, + ]; +} diff --git a/src/Validator/Spec/Error/DisallowedFirstChildTagName.php b/src/Validator/Spec/Error/DisallowedFirstChildTagName.php new file mode 100644 index 000000000..1828be6b0 --- /dev/null +++ b/src/Validator/Spec/Error/DisallowedFirstChildTagName.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'Tag \'%1\' is disallowed as first child of tag \'%2\'. First child tag must be one of %3.', + SpecRule::SPECIFICITY => 75, + ]; +} diff --git a/src/Validator/Spec/Error/DisallowedManufacturedBody.php b/src/Validator/Spec/Error/DisallowedManufacturedBody.php new file mode 100644 index 000000000..ad28fc0e2 --- /dev/null +++ b/src/Validator/Spec/Error/DisallowedManufacturedBody.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'Tag or text which is only allowed inside the body section found outside of the body section.', + SpecRule::SPECIFICITY => 106, + ]; +} diff --git a/src/Validator/Spec/Error/DisallowedPropertyInAttrValue.php b/src/Validator/Spec/Error/DisallowedPropertyInAttrValue.php new file mode 100644 index 000000000..3fd67ec34 --- /dev/null +++ b/src/Validator/Spec/Error/DisallowedPropertyInAttrValue.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'The property \'%1\' in attribute \'%2\' in tag \'%3\' is disallowed.', + SpecRule::SPECIFICITY => 39, + ]; +} diff --git a/src/Validator/Spec/Error/DisallowedRelativeUrl.php b/src/Validator/Spec/Error/DisallowedRelativeUrl.php new file mode 100644 index 000000000..290dc8c51 --- /dev/null +++ b/src/Validator/Spec/Error/DisallowedRelativeUrl.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'The relative URL \'%3\' for attribute \'%1\' in tag \'%2\' is disallowed.', + SpecRule::SPECIFICITY => 51, + ]; +} diff --git a/src/Validator/Spec/Error/DisallowedScriptTag.php b/src/Validator/Spec/Error/DisallowedScriptTag.php new file mode 100644 index 000000000..d5338af54 --- /dev/null +++ b/src/Validator/Spec/Error/DisallowedScriptTag.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'Custom JavaScript is not allowed.', + SpecRule::SPECIFICITY => 102, + ]; +} diff --git a/src/Validator/Spec/Error/DisallowedStyleAttr.php b/src/Validator/Spec/Error/DisallowedStyleAttr.php new file mode 100644 index 000000000..0231eddc4 --- /dev/null +++ b/src/Validator/Spec/Error/DisallowedStyleAttr.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'The inline \'style\' attribute is not allowed in AMP documents. Use \'style amp-custom\' tag instead.', + SpecRule::SPECIFICITY => 56, + ]; +} diff --git a/src/Validator/Spec/Error/DisallowedTag.php b/src/Validator/Spec/Error/DisallowedTag.php new file mode 100644 index 000000000..18bb8a7a3 --- /dev/null +++ b/src/Validator/Spec/Error/DisallowedTag.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'The tag \'%1\' is disallowed.', + SpecRule::SPECIFICITY => 21, + ]; +} diff --git a/src/Validator/Spec/Error/DisallowedTagAncestor.php b/src/Validator/Spec/Error/DisallowedTagAncestor.php new file mode 100644 index 000000000..20f1fc0f1 --- /dev/null +++ b/src/Validator/Spec/Error/DisallowedTagAncestor.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'The tag \'%1\' may not appear as a descendant of tag \'%2\'.', + SpecRule::SPECIFICITY => 5, + ]; +} diff --git a/src/Validator/Spec/Error/DocumentSizeLimitExceeded.php b/src/Validator/Spec/Error/DocumentSizeLimitExceeded.php new file mode 100644 index 000000000..032088bc3 --- /dev/null +++ b/src/Validator/Spec/Error/DocumentSizeLimitExceeded.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'Document exceeded %1 bytes limit. Actual size %2 bytes.', + SpecRule::SPECIFICITY => 126, + ]; +} diff --git a/src/Validator/Spec/Error/DocumentTooComplex.php b/src/Validator/Spec/Error/DocumentTooComplex.php new file mode 100644 index 000000000..d3c7b3063 --- /dev/null +++ b/src/Validator/Spec/Error/DocumentTooComplex.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'The document is too complex.', + SpecRule::SPECIFICITY => 107, + ]; +} diff --git a/src/Validator/Spec/Error/DuplicateAttribute.php b/src/Validator/Spec/Error/DuplicateAttribute.php new file mode 100644 index 000000000..6477049c9 --- /dev/null +++ b/src/Validator/Spec/Error/DuplicateAttribute.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'The tag \'%1\' contains the attribute \'%2\' repeated multiple times.', + SpecRule::SPECIFICITY => 24, + ]; +} diff --git a/src/Validator/Spec/Error/DuplicateDimension.php b/src/Validator/Spec/Error/DuplicateDimension.php new file mode 100644 index 000000000..8f74f8cc5 --- /dev/null +++ b/src/Validator/Spec/Error/DuplicateDimension.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'Multiple image candidates with the same width or pixel density found in attribute \'%1\' in tag \'%2\'.', + SpecRule::SPECIFICITY => 50, + ]; +} diff --git a/src/Validator/Spec/Error/DuplicateReferencePoint.php b/src/Validator/Spec/Error/DuplicateReferencePoint.php new file mode 100644 index 000000000..08d1955fa --- /dev/null +++ b/src/Validator/Spec/Error/DuplicateReferencePoint.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'The reference point \'%1\' for \'%2\' must be unique but a duplicate was encountered.', + SpecRule::SPECIFICITY => 79, + ]; +} diff --git a/src/Validator/Spec/Error/DuplicateUniqueTag.php b/src/Validator/Spec/Error/DuplicateUniqueTag.php new file mode 100644 index 000000000..4c9cbd321 --- /dev/null +++ b/src/Validator/Spec/Error/DuplicateUniqueTag.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'The tag \'%1\' appears more than once in the document.', + SpecRule::SPECIFICITY => 30, + ]; +} diff --git a/src/Validator/Spec/Error/DuplicateUniqueTagWarning.php b/src/Validator/Spec/Error/DuplicateUniqueTagWarning.php new file mode 100644 index 000000000..47ad4075a --- /dev/null +++ b/src/Validator/Spec/Error/DuplicateUniqueTagWarning.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'The tag \'%1\' appears more than once in the document. This will soon be an error.', + SpecRule::SPECIFICITY => 31, + ]; +} diff --git a/src/Validator/Spec/Error/ExtensionUnused.php b/src/Validator/Spec/Error/ExtensionUnused.php new file mode 100644 index 000000000..bcee41f6c --- /dev/null +++ b/src/Validator/Spec/Error/ExtensionUnused.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'The extension \'%1\' was found on this page, but is unused. Please remove this extension.', + SpecRule::SPECIFICITY => 15, + ]; +} diff --git a/src/Validator/Spec/Error/GeneralDisallowedTag.php b/src/Validator/Spec/Error/GeneralDisallowedTag.php new file mode 100644 index 000000000..465722a79 --- /dev/null +++ b/src/Validator/Spec/Error/GeneralDisallowedTag.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'The tag \'%1\' is disallowed except in specific forms.', + SpecRule::SPECIFICITY => 103, + ]; +} diff --git a/src/Validator/Spec/Error/ImpliedLayoutInvalid.php b/src/Validator/Spec/Error/ImpliedLayoutInvalid.php new file mode 100644 index 000000000..378110c21 --- /dev/null +++ b/src/Validator/Spec/Error/ImpliedLayoutInvalid.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'The implied layout \'%1\' is not supported by tag \'%2\'.', + SpecRule::SPECIFICITY => 46, + ]; +} diff --git a/src/Validator/Spec/Error/InconsistentUnitsForWidthAndHeight.php b/src/Validator/Spec/Error/InconsistentUnitsForWidthAndHeight.php new file mode 100644 index 000000000..a94b9359c --- /dev/null +++ b/src/Validator/Spec/Error/InconsistentUnitsForWidthAndHeight.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'Inconsistent units for width and height in tag \'%1\' - width is specified in \'%2\' whereas height is specified in \'%3\'.', + SpecRule::SPECIFICITY => 44, + ]; +} diff --git a/src/Validator/Spec/Error/IncorrectMinNumChildTags.php b/src/Validator/Spec/Error/IncorrectMinNumChildTags.php new file mode 100644 index 000000000..539d93b70 --- /dev/null +++ b/src/Validator/Spec/Error/IncorrectMinNumChildTags.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'Tag \'%1\' must have a minimum of %2 child tags - saw %3 child tags.', + SpecRule::SPECIFICITY => 108, + ]; +} diff --git a/src/Validator/Spec/Error/IncorrectNumChildTags.php b/src/Validator/Spec/Error/IncorrectNumChildTags.php new file mode 100644 index 000000000..65672d4d8 --- /dev/null +++ b/src/Validator/Spec/Error/IncorrectNumChildTags.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'Tag \'%1\' must have %2 child tags - saw %3 child tags.', + SpecRule::SPECIFICITY => 73, + ]; +} diff --git a/src/Validator/Spec/Error/IncorrectScriptReleaseVersion.php b/src/Validator/Spec/Error/IncorrectScriptReleaseVersion.php new file mode 100644 index 000000000..dc74b70f7 --- /dev/null +++ b/src/Validator/Spec/Error/IncorrectScriptReleaseVersion.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'The script version for \'%1\' is a %2 version which mismatches with the first script on the page using the %3 version.', + SpecRule::SPECIFICITY => 20, + ]; +} diff --git a/src/Validator/Spec/Error/InlineScriptTooLong.php b/src/Validator/Spec/Error/InlineScriptTooLong.php new file mode 100644 index 000000000..20a88ac26 --- /dev/null +++ b/src/Validator/Spec/Error/InlineScriptTooLong.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'The inline script is %1 bytes, which exceeds the limit of %2 bytes.', + SpecRule::SPECIFICITY => 35, + ]; +} diff --git a/src/Validator/Spec/Error/InlineStyleTooLong.php b/src/Validator/Spec/Error/InlineStyleTooLong.php new file mode 100644 index 000000000..b5eeba5f3 --- /dev/null +++ b/src/Validator/Spec/Error/InlineStyleTooLong.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'The inline style specified in tag \'%1\' is too long - it contains %2 bytes whereas the limit is %3 bytes.', + SpecRule::SPECIFICITY => 34, + ]; +} diff --git a/src/Validator/Spec/Error/InvalidAttrValue.php b/src/Validator/Spec/Error/InvalidAttrValue.php new file mode 100644 index 000000000..a20661b20 --- /dev/null +++ b/src/Validator/Spec/Error/InvalidAttrValue.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'The attribute \'%1\' in tag \'%2\' is set to the invalid value \'%3\'.', + SpecRule::SPECIFICITY => 23, + ]; +} diff --git a/src/Validator/Spec/Error/InvalidDoctypeHtml.php b/src/Validator/Spec/Error/InvalidDoctypeHtml.php new file mode 100644 index 000000000..b3e000d7a --- /dev/null +++ b/src/Validator/Spec/Error/InvalidDoctypeHtml.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'Invalid or missing doctype declaration. Should be \'!doctype html\'.', + SpecRule::SPECIFICITY => 128, + ]; +} diff --git a/src/Validator/Spec/Error/InvalidJsonCdata.php b/src/Validator/Spec/Error/InvalidJsonCdata.php new file mode 100644 index 000000000..d4db72056 --- /dev/null +++ b/src/Validator/Spec/Error/InvalidJsonCdata.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'The script tag contains invalid JSON that cannot be parsed.', + SpecRule::SPECIFICITY => 4, + ]; +} diff --git a/src/Validator/Spec/Error/InvalidPropertyValueInAttrValue.php b/src/Validator/Spec/Error/InvalidPropertyValueInAttrValue.php new file mode 100644 index 000000000..be5a284b4 --- /dev/null +++ b/src/Validator/Spec/Error/InvalidPropertyValueInAttrValue.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'The property \'%1\' in attribute \'%2\' in tag \'%3\' is set to \'%4\', which is invalid.', + SpecRule::SPECIFICITY => 38, + ]; +} diff --git a/src/Validator/Spec/Error/InvalidUrl.php b/src/Validator/Spec/Error/InvalidUrl.php new file mode 100644 index 000000000..84b45f683 --- /dev/null +++ b/src/Validator/Spec/Error/InvalidUrl.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'Malformed URL \'%3\' for attribute \'%1\' in tag \'%2\'.', + SpecRule::SPECIFICITY => 55, + ]; +} diff --git a/src/Validator/Spec/Error/InvalidUrlProtocol.php b/src/Validator/Spec/Error/InvalidUrlProtocol.php new file mode 100644 index 000000000..f1b3a8e06 --- /dev/null +++ b/src/Validator/Spec/Error/InvalidUrlProtocol.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'Invalid URL protocol \'%3:\' for attribute \'%1\' in tag \'%2\'.', + SpecRule::SPECIFICITY => 54, + ]; +} diff --git a/src/Validator/Spec/Error/InvalidUtf8.php b/src/Validator/Spec/Error/InvalidUtf8.php new file mode 100644 index 000000000..9633de1c0 --- /dev/null +++ b/src/Validator/Spec/Error/InvalidUtf8.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'The document contains invalid UTF8.', + SpecRule::SPECIFICITY => 124, + ]; +} diff --git a/src/Validator/Spec/Error/LtsScriptAfterNonLts.php b/src/Validator/Spec/Error/LtsScriptAfterNonLts.php new file mode 100644 index 000000000..5d0ba65e5 --- /dev/null +++ b/src/Validator/Spec/Error/LtsScriptAfterNonLts.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => '\'%1\' must use the non-LTS version to correspond with the first script in the page, which does not use LTS.', + SpecRule::SPECIFICITY => 19, + ]; +} diff --git a/src/Validator/Spec/Error/MandatoryAnyofAttrMissing.php b/src/Validator/Spec/Error/MandatoryAnyofAttrMissing.php new file mode 100644 index 000000000..03ddba535 --- /dev/null +++ b/src/Validator/Spec/Error/MandatoryAnyofAttrMissing.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'The tag \'%1\' is missing a mandatory attribute - pick at least one of %2.', + SpecRule::SPECIFICITY => 28, + ]; +} diff --git a/src/Validator/Spec/Error/MandatoryAttrMissing.php b/src/Validator/Spec/Error/MandatoryAttrMissing.php new file mode 100644 index 000000000..8b90ac0c2 --- /dev/null +++ b/src/Validator/Spec/Error/MandatoryAttrMissing.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'The mandatory attribute \'%1\' is missing in tag \'%2\'.', + SpecRule::SPECIFICITY => 26, + ]; +} diff --git a/src/Validator/Spec/Error/MandatoryCdataMissingOrIncorrect.php b/src/Validator/Spec/Error/MandatoryCdataMissingOrIncorrect.php new file mode 100644 index 000000000..946f4fe8c --- /dev/null +++ b/src/Validator/Spec/Error/MandatoryCdataMissingOrIncorrect.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'The mandatory text inside tag \'%1\' is missing or incorrect.', + SpecRule::SPECIFICITY => 1, + ]; +} diff --git a/src/Validator/Spec/Error/MandatoryLastChildTag.php b/src/Validator/Spec/Error/MandatoryLastChildTag.php new file mode 100644 index 000000000..37702c379 --- /dev/null +++ b/src/Validator/Spec/Error/MandatoryLastChildTag.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'Tag \'%1\', if present, must be the last child of tag \'%2\'.', + SpecRule::SPECIFICITY => 110, + ]; +} diff --git a/src/Validator/Spec/Error/MandatoryOneofAttrMissing.php b/src/Validator/Spec/Error/MandatoryOneofAttrMissing.php new file mode 100644 index 000000000..1a7f14efd --- /dev/null +++ b/src/Validator/Spec/Error/MandatoryOneofAttrMissing.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'The tag \'%1\' is missing a mandatory attribute - pick one of %2.', + SpecRule::SPECIFICITY => 27, + ]; +} diff --git a/src/Validator/Spec/Error/MandatoryPropertyMissingFromAttrValue.php b/src/Validator/Spec/Error/MandatoryPropertyMissingFromAttrValue.php new file mode 100644 index 000000000..386723406 --- /dev/null +++ b/src/Validator/Spec/Error/MandatoryPropertyMissingFromAttrValue.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'The property \'%1\' is missing from attribute \'%2\' in tag \'%3\'.', + SpecRule::SPECIFICITY => 37, + ]; +} diff --git a/src/Validator/Spec/Error/MandatoryReferencePointMissing.php b/src/Validator/Spec/Error/MandatoryReferencePointMissing.php new file mode 100644 index 000000000..7cbd242dd --- /dev/null +++ b/src/Validator/Spec/Error/MandatoryReferencePointMissing.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'The mandatory reference point \'%1\' for \'%2\' is missing.', + SpecRule::SPECIFICITY => 78, + ]; +} diff --git a/src/Validator/Spec/Error/MandatoryTagAncestor.php b/src/Validator/Spec/Error/MandatoryTagAncestor.php new file mode 100644 index 000000000..2b898f988 --- /dev/null +++ b/src/Validator/Spec/Error/MandatoryTagAncestor.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'The tag \'%1\' may only appear as a descendant of tag \'%2\'.', + SpecRule::SPECIFICITY => 6, + ]; +} diff --git a/src/Validator/Spec/Error/MandatoryTagAncestorWithHint.php b/src/Validator/Spec/Error/MandatoryTagAncestorWithHint.php new file mode 100644 index 000000000..e3b79f172 --- /dev/null +++ b/src/Validator/Spec/Error/MandatoryTagAncestorWithHint.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'The tag \'%1\' may only appear as a descendant of tag \'%2\'. Did you mean \'%3\'?', + SpecRule::SPECIFICITY => 7, + ]; +} diff --git a/src/Validator/Spec/Error/MandatoryTagMissing.php b/src/Validator/Spec/Error/MandatoryTagMissing.php new file mode 100644 index 000000000..d582c2430 --- /dev/null +++ b/src/Validator/Spec/Error/MandatoryTagMissing.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'The mandatory tag \'%1\' is missing or incorrect.', + SpecRule::SPECIFICITY => 8, + ]; +} diff --git a/src/Validator/Spec/Error/MissingLayoutAttributes.php b/src/Validator/Spec/Error/MissingLayoutAttributes.php new file mode 100644 index 000000000..e31354c04 --- /dev/null +++ b/src/Validator/Spec/Error/MissingLayoutAttributes.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'Incomplete layout attributes specified for tag \'%1\'. For example, provide attributes \'width\' and \'height\'.', + SpecRule::SPECIFICITY => 45, + ]; +} diff --git a/src/Validator/Spec/Error/MissingRequiredExtension.php b/src/Validator/Spec/Error/MissingRequiredExtension.php new file mode 100644 index 000000000..74c1e5fa3 --- /dev/null +++ b/src/Validator/Spec/Error/MissingRequiredExtension.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'The tag \'%1\' requires including the \'%2\' extension JavaScript.', + SpecRule::SPECIFICITY => 12, + ]; +} diff --git a/src/Validator/Spec/Error/MissingUrl.php b/src/Validator/Spec/Error/MissingUrl.php new file mode 100644 index 000000000..82542ab21 --- /dev/null +++ b/src/Validator/Spec/Error/MissingUrl.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'Missing URL for attribute \'%1\' in tag \'%2\'.', + SpecRule::SPECIFICITY => 52, + ]; +} diff --git a/src/Validator/Spec/Error/MutuallyExclusiveAttrs.php b/src/Validator/Spec/Error/MutuallyExclusiveAttrs.php new file mode 100644 index 000000000..b53b2fcde --- /dev/null +++ b/src/Validator/Spec/Error/MutuallyExclusiveAttrs.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'Mutually exclusive attributes encountered in tag \'%1\' - pick one of %2.', + SpecRule::SPECIFICITY => 40, + ]; +} diff --git a/src/Validator/Spec/Error/NonLtsScriptAfterLts.php b/src/Validator/Spec/Error/NonLtsScriptAfterLts.php new file mode 100644 index 000000000..94a1136d7 --- /dev/null +++ b/src/Validator/Spec/Error/NonLtsScriptAfterLts.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => '\'%1\' must use the LTS version to correspond with the first script in the page, which uses LTS.', + SpecRule::SPECIFICITY => 18, + ]; +} diff --git a/src/Validator/Spec/Error/NonWhitespaceCdataEncountered.php b/src/Validator/Spec/Error/NonWhitespaceCdataEncountered.php new file mode 100644 index 000000000..0c12de307 --- /dev/null +++ b/src/Validator/Spec/Error/NonWhitespaceCdataEncountered.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'The tag \'%1\' contains text, which is disallowed.', + SpecRule::SPECIFICITY => 3, + ]; +} diff --git a/src/Validator/Spec/Error/SpecifiedLayoutInvalid.php b/src/Validator/Spec/Error/SpecifiedLayoutInvalid.php new file mode 100644 index 000000000..4217bcdcc --- /dev/null +++ b/src/Validator/Spec/Error/SpecifiedLayoutInvalid.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'The specified layout \'%1\' is not supported by tag \'%2\'.', + SpecRule::SPECIFICITY => 47, + ]; +} diff --git a/src/Validator/Spec/Error/StylesheetAndInlineStyleTooLong.php b/src/Validator/Spec/Error/StylesheetAndInlineStyleTooLong.php new file mode 100644 index 000000000..3eb45aecd --- /dev/null +++ b/src/Validator/Spec/Error/StylesheetAndInlineStyleTooLong.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'The author stylesheet specified in tag \'style amp-custom\' and the combined inline styles is too large - document contains %1 bytes whereas the limit is %2 bytes.', + SpecRule::SPECIFICITY => 33, + ]; +} diff --git a/src/Validator/Spec/Error/StylesheetTooLong.php b/src/Validator/Spec/Error/StylesheetTooLong.php new file mode 100644 index 000000000..ca9ff0a21 --- /dev/null +++ b/src/Validator/Spec/Error/StylesheetTooLong.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'The author stylesheet specified in tag \'%1\' is too long - document contains %2 bytes whereas the limit is %3 bytes.', + SpecRule::SPECIFICITY => 32, + ]; +} diff --git a/src/Validator/Spec/Error/TagExcludedByTag.php b/src/Validator/Spec/Error/TagExcludedByTag.php new file mode 100644 index 000000000..f31efa25b --- /dev/null +++ b/src/Validator/Spec/Error/TagExcludedByTag.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'The tag \'%1\' is present, but is excluded by the presence of \'%2\'.', + SpecRule::SPECIFICITY => 11, + ]; +} diff --git a/src/Validator/Spec/Error/TagNotAllowedToHaveSiblings.php b/src/Validator/Spec/Error/TagNotAllowedToHaveSiblings.php new file mode 100644 index 000000000..c3aa566d1 --- /dev/null +++ b/src/Validator/Spec/Error/TagNotAllowedToHaveSiblings.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'Tag \'%1\' is not allowed to have any sibling tags (\'%2\' should only have 1 child).', + SpecRule::SPECIFICITY => 109, + ]; +} diff --git a/src/Validator/Spec/Error/TagReferencePointConflict.php b/src/Validator/Spec/Error/TagReferencePointConflict.php new file mode 100644 index 000000000..818e7da4a --- /dev/null +++ b/src/Validator/Spec/Error/TagReferencePointConflict.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'The tag \'%1\' conflicts with reference point \'%2\' because both define reference points.', + SpecRule::SPECIFICITY => 80, + ]; +} diff --git a/src/Validator/Spec/Error/TagRequiredByMissing.php b/src/Validator/Spec/Error/TagRequiredByMissing.php new file mode 100644 index 000000000..089389e79 --- /dev/null +++ b/src/Validator/Spec/Error/TagRequiredByMissing.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'The tag \'%1\' is missing or incorrect, but required by \'%2\'.', + SpecRule::SPECIFICITY => 10, + ]; +} diff --git a/src/Validator/Spec/Error/TemplateInAttrName.php b/src/Validator/Spec/Error/TemplateInAttrName.php new file mode 100644 index 000000000..aa1d96d46 --- /dev/null +++ b/src/Validator/Spec/Error/TemplateInAttrName.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'Mustache template syntax in attribute name \'%1\' in tag \'%2\'.', + SpecRule::SPECIFICITY => 43, + ]; +} diff --git a/src/Validator/Spec/Error/TemplatePartialInAttrValue.php b/src/Validator/Spec/Error/TemplatePartialInAttrValue.php new file mode 100644 index 000000000..999e761b7 --- /dev/null +++ b/src/Validator/Spec/Error/TemplatePartialInAttrValue.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'The attribute \'%1\' in tag \'%2\' is set to \'%3\', which contains a Mustache template partial.', + SpecRule::SPECIFICITY => 42, + ]; +} diff --git a/src/Validator/Spec/Error/UnescapedTemplateInAttrValue.php b/src/Validator/Spec/Error/UnescapedTemplateInAttrValue.php new file mode 100644 index 000000000..31a281fb9 --- /dev/null +++ b/src/Validator/Spec/Error/UnescapedTemplateInAttrValue.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'The attribute \'%1\' in tag \'%2\' is set to \'%3\', which contains unescaped Mustache template syntax.', + SpecRule::SPECIFICITY => 41, + ]; +} diff --git a/src/Validator/Spec/Error/UnknownCode.php b/src/Validator/Spec/Error/UnknownCode.php new file mode 100644 index 000000000..be8b171cd --- /dev/null +++ b/src/Validator/Spec/Error/UnknownCode.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'Unknown error.', + SpecRule::SPECIFICITY => 0, + ]; +} diff --git a/src/Validator/Spec/Error/ValueSetMismatch.php b/src/Validator/Spec/Error/ValueSetMismatch.php new file mode 100644 index 000000000..a4f4e1af5 --- /dev/null +++ b/src/Validator/Spec/Error/ValueSetMismatch.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'Attribute \'%1\' in tag \'%2\' contains a value that does not match any other tags on the page.', + SpecRule::SPECIFICITY => 127, + ]; +} diff --git a/src/Validator/Spec/Error/WarningExtensionDeprecatedVersion.php b/src/Validator/Spec/Error/WarningExtensionDeprecatedVersion.php new file mode 100644 index 000000000..24a95ede5 --- /dev/null +++ b/src/Validator/Spec/Error/WarningExtensionDeprecatedVersion.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'The extension \'%1\' is referenced at version \'%2\' which is a deprecated version. Please use a more recent version of this extension. This may become an error in the future.', + SpecRule::SPECIFICITY => 17, + ]; +} diff --git a/src/Validator/Spec/Error/WarningExtensionUnused.php b/src/Validator/Spec/Error/WarningExtensionUnused.php new file mode 100644 index 000000000..1c0fadef1 --- /dev/null +++ b/src/Validator/Spec/Error/WarningExtensionUnused.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'The extension \'%1\' was found on this page, but is unused (no \'%2\' tag seen). This may become an error in the future.', + SpecRule::SPECIFICITY => 16, + ]; +} diff --git a/src/Validator/Spec/Error/WarningTagRequiredByMissing.php b/src/Validator/Spec/Error/WarningTagRequiredByMissing.php new file mode 100644 index 000000000..eca4023a7 --- /dev/null +++ b/src/Validator/Spec/Error/WarningTagRequiredByMissing.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'The tag \'%1\' is missing or incorrect, but required by \'%2\'. This will soon be an error.', + SpecRule::SPECIFICITY => 14, + ]; +} diff --git a/src/Validator/Spec/Error/WrongParentTag.php b/src/Validator/Spec/Error/WrongParentTag.php new file mode 100644 index 000000000..a60e8711f --- /dev/null +++ b/src/Validator/Spec/Error/WrongParentTag.php @@ -0,0 +1,31 @@ + + */ + const SPEC = [ + SpecRule::FORMAT => 'The parent tag of tag \'%1\' is \'%2\', but it can only be \'%3\'.', + SpecRule::SPECIFICITY => 9, + ]; +} diff --git a/src/Validator/Spec/Section/Errors.php b/src/Validator/Spec/Section/Errors.php index 1512d8200..6b47d28c3 100644 --- a/src/Validator/Spec/Section/Errors.php +++ b/src/Validator/Spec/Section/Errors.php @@ -7,480 +7,209 @@ namespace AmpProject\Validator\Spec\Section; -use AmpProject\Validator\ErrorCode; -use AmpProject\Validator\Spec\SpecRule; +use AmpProject\Exception\InvalidErrorCode; +use AmpProject\Exception\InvalidListName; +use AmpProject\Validator\Spec; +use AmpProject\Validator\Spec\Error; +use AmpProject\Validator\Spec\IterableSection; +use AmpProject\Validator\Spec\Iteration; -final class Errors +final class Errors implements IterableSection { - /** @var array */ - public $errors; + use Iteration { + Iteration::current as parentCurrent; + } + + /** + * Mapping of error code to error implementation. + * + * @var array + */ + const ERRORS = [ + Error\UnknownCode::CODE => Error\UnknownCode::class, + Error\InvalidDoctypeHtml::CODE => Error\InvalidDoctypeHtml::class, + Error\MandatoryTagMissing::CODE => Error\MandatoryTagMissing::class, + Error\TagRequiredByMissing::CODE => Error\TagRequiredByMissing::class, + Error\WarningTagRequiredByMissing::CODE => Error\WarningTagRequiredByMissing::class, + Error\TagExcludedByTag::CODE => Error\TagExcludedByTag::class, + Error\WarningExtensionUnused::CODE => Error\WarningExtensionUnused::class, + Error\ExtensionUnused::CODE => Error\ExtensionUnused::class, + Error\WarningExtensionDeprecatedVersion::CODE => Error\WarningExtensionDeprecatedVersion::class, + Error\IncorrectScriptReleaseVersion::CODE => Error\IncorrectScriptReleaseVersion::class, + Error\NonLtsScriptAfterLts::CODE => Error\NonLtsScriptAfterLts::class, + Error\LtsScriptAfterNonLts::CODE => Error\LtsScriptAfterNonLts::class, + Error\AttrRequiredButMissing::CODE => Error\AttrRequiredButMissing::class, + Error\DisallowedTag::CODE => Error\DisallowedTag::class, + Error\GeneralDisallowedTag::CODE => Error\GeneralDisallowedTag::class, + Error\DisallowedScriptTag::CODE => Error\DisallowedScriptTag::class, + Error\DisallowedAttr::CODE => Error\DisallowedAttr::class, + Error\DisallowedStyleAttr::CODE => Error\DisallowedStyleAttr::class, + Error\InvalidAttrValue::CODE => Error\InvalidAttrValue::class, + Error\DuplicateAttribute::CODE => Error\DuplicateAttribute::class, + Error\AttrValueRequiredByLayout::CODE => Error\AttrValueRequiredByLayout::class, + Error\MissingLayoutAttributes::CODE => Error\MissingLayoutAttributes::class, + Error\ImpliedLayoutInvalid::CODE => Error\ImpliedLayoutInvalid::class, + Error\SpecifiedLayoutInvalid::CODE => Error\SpecifiedLayoutInvalid::class, + Error\MandatoryAttrMissing::CODE => Error\MandatoryAttrMissing::class, + Error\InconsistentUnitsForWidthAndHeight::CODE => Error\InconsistentUnitsForWidthAndHeight::class, + Error\StylesheetTooLong::CODE => Error\StylesheetTooLong::class, + Error\StylesheetAndInlineStyleTooLong::CODE => Error\StylesheetAndInlineStyleTooLong::class, + Error\InlineStyleTooLong::CODE => Error\InlineStyleTooLong::class, + Error\InlineScriptTooLong::CODE => Error\InlineScriptTooLong::class, + Error\MandatoryCdataMissingOrIncorrect::CODE => Error\MandatoryCdataMissingOrIncorrect::class, + Error\CdataViolatesDenylist::CODE => Error\CdataViolatesDenylist::class, + Error\NonWhitespaceCdataEncountered::CODE => Error\NonWhitespaceCdataEncountered::class, + Error\InvalidJsonCdata::CODE => Error\InvalidJsonCdata::class, + Error\DisallowedPropertyInAttrValue::CODE => Error\DisallowedPropertyInAttrValue::class, + Error\InvalidPropertyValueInAttrValue::CODE => Error\InvalidPropertyValueInAttrValue::class, + Error\DuplicateDimension::CODE => Error\DuplicateDimension::class, + Error\MissingUrl::CODE => Error\MissingUrl::class, + Error\InvalidUrl::CODE => Error\InvalidUrl::class, + Error\InvalidUrlProtocol::CODE => Error\InvalidUrlProtocol::class, + Error\DisallowedDomain::CODE => Error\DisallowedDomain::class, + Error\DisallowedRelativeUrl::CODE => Error\DisallowedRelativeUrl::class, + Error\MandatoryPropertyMissingFromAttrValue::CODE => Error\MandatoryPropertyMissingFromAttrValue::class, + Error\UnescapedTemplateInAttrValue::CODE => Error\UnescapedTemplateInAttrValue::class, + Error\TemplatePartialInAttrValue::CODE => Error\TemplatePartialInAttrValue::class, + Error\DeprecatedTag::CODE => Error\DeprecatedTag::class, + Error\DeprecatedAttr::CODE => Error\DeprecatedAttr::class, + Error\MutuallyExclusiveAttrs::CODE => Error\MutuallyExclusiveAttrs::class, + Error\MandatoryOneofAttrMissing::CODE => Error\MandatoryOneofAttrMissing::class, + Error\MandatoryAnyofAttrMissing::CODE => Error\MandatoryAnyofAttrMissing::class, + Error\WrongParentTag::CODE => Error\WrongParentTag::class, + Error\DisallowedTagAncestor::CODE => Error\DisallowedTagAncestor::class, + Error\MandatoryTagAncestor::CODE => Error\MandatoryTagAncestor::class, + Error\MandatoryTagAncestorWithHint::CODE => Error\MandatoryTagAncestorWithHint::class, + Error\DuplicateUniqueTag::CODE => Error\DuplicateUniqueTag::class, + Error\DuplicateUniqueTagWarning::CODE => Error\DuplicateUniqueTagWarning::class, + Error\TemplateInAttrName::CODE => Error\TemplateInAttrName::class, + Error\AttrDisallowedByImpliedLayout::CODE => Error\AttrDisallowedByImpliedLayout::class, + Error\AttrDisallowedBySpecifiedLayout::CODE => Error\AttrDisallowedBySpecifiedLayout::class, + Error\IncorrectNumChildTags::CODE => Error\IncorrectNumChildTags::class, + Error\IncorrectMinNumChildTags::CODE => Error\IncorrectMinNumChildTags::class, + Error\TagNotAllowedToHaveSiblings::CODE => Error\TagNotAllowedToHaveSiblings::class, + Error\MandatoryLastChildTag::CODE => Error\MandatoryLastChildTag::class, + Error\DisallowedChildTagName::CODE => Error\DisallowedChildTagName::class, + Error\DisallowedFirstChildTagName::CODE => Error\DisallowedFirstChildTagName::class, + Error\DisallowedManufacturedBody::CODE => Error\DisallowedManufacturedBody::class, + Error\ChildTagDoesNotSatisfyReferencePoint::CODE => Error\ChildTagDoesNotSatisfyReferencePoint::class, + Error\ChildTagDoesNotSatisfyReferencePointSingular::CODE => Error\ChildTagDoesNotSatisfyReferencePointSingular::class, + Error\MandatoryReferencePointMissing::CODE => Error\MandatoryReferencePointMissing::class, + Error\DuplicateReferencePoint::CODE => Error\DuplicateReferencePoint::class, + Error\TagReferencePointConflict::CODE => Error\TagReferencePointConflict::class, + Error\BaseTagMustPreceedAllUrls::CODE => Error\BaseTagMustPreceedAllUrls::class, + Error\MissingRequiredExtension::CODE => Error\MissingRequiredExtension::class, + Error\AttrMissingRequiredExtension::CODE => Error\AttrMissingRequiredExtension::class, + Error\DocumentTooComplex::CODE => Error\DocumentTooComplex::class, + Error\InvalidUtf8::CODE => Error\InvalidUtf8::class, + Error\CssSyntaxInvalidAtRule::CODE => Error\CssSyntaxInvalidAtRule::class, + Error\CssSyntaxStrayTrailingBackslash::CODE => Error\CssSyntaxStrayTrailingBackslash::class, + Error\CssSyntaxUnterminatedComment::CODE => Error\CssSyntaxUnterminatedComment::class, + Error\CssSyntaxUnterminatedString::CODE => Error\CssSyntaxUnterminatedString::class, + Error\CssSyntaxBadUrl::CODE => Error\CssSyntaxBadUrl::class, + Error\CssSyntaxEofInPreludeOfQualifiedRule::CODE => Error\CssSyntaxEofInPreludeOfQualifiedRule::class, + Error\CssSyntaxInvalidProperty::CODE => Error\CssSyntaxInvalidProperty::class, + Error\CssSyntaxInvalidPropertyNolist::CODE => Error\CssSyntaxInvalidPropertyNolist::class, + Error\CssSyntaxQualifiedRuleHasNoDeclarations::CODE => Error\CssSyntaxQualifiedRuleHasNoDeclarations::class, + Error\CssSyntaxDisallowedQualifiedRuleMustBeInsideKeyframe::CODE => Error\CssSyntaxDisallowedQualifiedRuleMustBeInsideKeyframe::class, + Error\CssSyntaxDisallowedKeyframeInsideKeyframe::CODE => Error\CssSyntaxDisallowedKeyframeInsideKeyframe::class, + Error\CssSyntaxInvalidDeclaration::CODE => Error\CssSyntaxInvalidDeclaration::class, + Error\CssSyntaxIncompleteDeclaration::CODE => Error\CssSyntaxIncompleteDeclaration::class, + Error\CssSyntaxErrorInPseudoSelector::CODE => Error\CssSyntaxErrorInPseudoSelector::class, + Error\CssSyntaxMissingSelector::CODE => Error\CssSyntaxMissingSelector::class, + Error\CssSyntaxNotASelectorStart::CODE => Error\CssSyntaxNotASelectorStart::class, + Error\CssSyntaxUnparsedInputRemainsInSelector::CODE => Error\CssSyntaxUnparsedInputRemainsInSelector::class, + Error\CssSyntaxMissingUrl::CODE => Error\CssSyntaxMissingUrl::class, + Error\CssSyntaxInvalidUrl::CODE => Error\CssSyntaxInvalidUrl::class, + Error\CssSyntaxInvalidUrlProtocol::CODE => Error\CssSyntaxInvalidUrlProtocol::class, + Error\CssSyntaxDisallowedDomain::CODE => Error\CssSyntaxDisallowedDomain::class, + Error\CssSyntaxDisallowedRelativeUrl::CODE => Error\CssSyntaxDisallowedRelativeUrl::class, + Error\CssSyntaxInvalidAttrSelector::CODE => Error\CssSyntaxInvalidAttrSelector::class, + Error\CssSyntaxDisallowedPropertyValue::CODE => Error\CssSyntaxDisallowedPropertyValue::class, + Error\CssSyntaxDisallowedPropertyValueWithHint::CODE => Error\CssSyntaxDisallowedPropertyValueWithHint::class, + Error\CssSyntaxDisallowedImportant::CODE => Error\CssSyntaxDisallowedImportant::class, + Error\CssSyntaxPropertyDisallowedWithinAtRule::CODE => Error\CssSyntaxPropertyDisallowedWithinAtRule::class, + Error\CssSyntaxPropertyDisallowedTogetherWith::CODE => Error\CssSyntaxPropertyDisallowedTogetherWith::class, + Error\CssSyntaxPropertyRequiresQualification::CODE => Error\CssSyntaxPropertyRequiresQualification::class, + Error\CssSyntaxMalformedMediaQuery::CODE => Error\CssSyntaxMalformedMediaQuery::class, + Error\CssSyntaxDisallowedMediaType::CODE => Error\CssSyntaxDisallowedMediaType::class, + Error\CssSyntaxDisallowedMediaFeature::CODE => Error\CssSyntaxDisallowedMediaFeature::class, + Error\CssSyntaxDisallowedAttrSelector::CODE => Error\CssSyntaxDisallowedAttrSelector::class, + Error\CssSyntaxDisallowedPseudoClass::CODE => Error\CssSyntaxDisallowedPseudoClass::class, + Error\CssSyntaxDisallowedPseudoElement::CODE => Error\CssSyntaxDisallowedPseudoElement::class, + Error\CssExcessivelyNested::CODE => Error\CssExcessivelyNested::class, + Error\DocumentSizeLimitExceeded::CODE => Error\DocumentSizeLimitExceeded::class, + Error\ValueSetMismatch::CODE => Error\ValueSetMismatch::class, + Error\DevModeOnly::CODE => Error\DevModeOnly::class, + Error\AmpEmailMissingStrictCssAttr::CODE => Error\AmpEmailMissingStrictCssAttr::class, + ]; + + /** + * Cache of instantiated Error objects. + * + * @var array + */ + private $errors = []; + + /** + * Get a specific error. + * + * @param string $errorCode Code of the error to get. + * @return Spec\Error Error with the given error code. + * @throws InvalidErrorCode If an invalid error code is requested. + */ + public function get($errorCode) + { + if (!array_key_exists($errorCode, self::ERRORS)) { + throw InvalidErrorCode::forErrorCode($errorCode); + } + + if (array_key_exists($errorCode, $this->errors)) { + return $this->errors[$errorCode]; + } + + $errorClassName = self::ERRORS[$errorCode]; + + /** @var Spec\Error $error */ + $error = new $errorClassName(); + + $this->errors[$errorCode] = $error; + + return $error; + } + + /** + * Get the list of available keys. + * + * @return array Array of available keys. + */ + public function getAvailableKeys() + { + return array_keys(self::ERRORS); + } + + /** + * Find the instantiated object for the current key. + * + * This should use its own caching mechanism as needed. + * + * Ideally, current() should be overridden as well to provide the correct object type-hint. + * + * @param string $key Key to retrieve the instantiated object for. + * @return object Instantiated object for the current key. + */ + public function findByKey($key) + { + return $this->get($key); + } - public function __construct() + /** + * Return the current iterable object. + * + * @return Error Error object. + */ + public function current() { - $this->errors = [ - ErrorCode::AMP_EMAIL_MISSING_STRICT_CSS_ATTR => [ - SpecRule::FORMAT => 'Tag \'html\' marked with attribute \'amp4email\' is missing the corresponding attribute \'data-css-strict\' for enabling strict CSS validation. This may become an error in the future.', - ], - ErrorCode::ATTR_DISALLOWED_BY_IMPLIED_LAYOUT => [ - SpecRule::FORMAT => 'The attribute \'%1\' in tag \'%2\' is disallowed by implied layout \'%3\'.', - SpecRule::SPECIFICITY => 48, - ], - ErrorCode::ATTR_DISALLOWED_BY_SPECIFIED_LAYOUT => [ - SpecRule::FORMAT => 'The attribute \'%1\' in tag \'%2\' is disallowed by specified layout \'%3\'.', - SpecRule::SPECIFICITY => 49, - ], - ErrorCode::ATTR_MISSING_REQUIRED_EXTENSION => [ - SpecRule::FORMAT => 'The attribute \'%1\' requires including the \'%2\' extension JavaScript.', - SpecRule::SPECIFICITY => 13, - ], - ErrorCode::ATTR_REQUIRED_BUT_MISSING => [ - SpecRule::FORMAT => 'The attribute \'%1\' in tag \'%2\' is missing or incorrect, but required by attribute \'%3\'.', - SpecRule::SPECIFICITY => 29, - ], - ErrorCode::ATTR_VALUE_REQUIRED_BY_LAYOUT => [ - SpecRule::FORMAT => 'Invalid value \'%1\' for attribute \'%2\' in tag \'%3\' - for layout \'%4\', set the attribute \'%2\' to value \'%5\'.', - SpecRule::SPECIFICITY => 25, - ], - ErrorCode::BASE_TAG_MUST_PRECEED_ALL_URLS => [ - SpecRule::FORMAT => 'The tag \'%1\', which contains URLs, was found earlier in the document than the BASE element.', - SpecRule::SPECIFICITY => 87, - ], - ErrorCode::CDATA_VIOLATES_DENYLIST => [ - SpecRule::FORMAT => 'The text inside tag \'%1\' contains \'%2\', which is disallowed.', - SpecRule::SPECIFICITY => 2, - ], - ErrorCode::CHILD_TAG_DOES_NOT_SATISFY_REFERENCE_POINT => [ - SpecRule::FORMAT => 'The tag \'%1\', a child tag of \'%2\', does not satisfy one of the acceptable reference points: %3.', - SpecRule::SPECIFICITY => 77, - ], - ErrorCode::CHILD_TAG_DOES_NOT_SATISFY_REFERENCE_POINT_SINGULAR => [ - SpecRule::FORMAT => 'The tag \'%1\', a child tag of \'%2\', does not satisfy the reference point \'%3\'.', - SpecRule::SPECIFICITY => 81, - ], - ErrorCode::CSS_EXCESSIVELY_NESTED => [ - SpecRule::FORMAT => 'CSS excessively nested in tag \'%1\'.', - SpecRule::SPECIFICITY => 125, - ], - ErrorCode::CSS_SYNTAX_BAD_URL => [ - SpecRule::FORMAT => 'CSS syntax error in tag \'%1\' - bad url.', - SpecRule::SPECIFICITY => 60, - ], - ErrorCode::CSS_SYNTAX_DISALLOWED_ATTR_SELECTOR => [ - SpecRule::FORMAT => 'CSS error in tag \'%1\' - disallowed attribute selector \'%2\'.', - SpecRule::SPECIFICITY => 120, - ], - ErrorCode::CSS_SYNTAX_DISALLOWED_DOMAIN => [ - SpecRule::FORMAT => 'CSS syntax error in tag \'%1\' - invalid domain \'%2\'.', - SpecRule::SPECIFICITY => 69, - ], - ErrorCode::CSS_SYNTAX_DISALLOWED_IMPORTANT => [ - SpecRule::FORMAT => 'Usage of the !important CSS qualifier is not allowed.', - SpecRule::SPECIFICITY => 123, - ], - ErrorCode::CSS_SYNTAX_DISALLOWED_KEYFRAME_INSIDE_KEYFRAME => [ - SpecRule::FORMAT => 'CSS syntax error in tag \'%1\' - keyframe inside keyframe is not allowed.', - SpecRule::SPECIFICITY => 115, - ], - ErrorCode::CSS_SYNTAX_DISALLOWED_MEDIA_FEATURE => [ - SpecRule::FORMAT => 'CSS syntax error in tag \'%1\' - disallowed media feature \'%2\'.', - SpecRule::SPECIFICITY => 119, - ], - ErrorCode::CSS_SYNTAX_DISALLOWED_MEDIA_TYPE => [ - SpecRule::FORMAT => 'CSS syntax error in tag \'%1\' - disallowed media type \'%2\'.', - SpecRule::SPECIFICITY => 118, - ], - ErrorCode::CSS_SYNTAX_DISALLOWED_PROPERTY_VALUE => [ - SpecRule::FORMAT => 'CSS syntax error in tag \'%1\' - the property \'%2\' is set to the disallowed value \'%3\'.', - SpecRule::SPECIFICITY => 82, - ], - ErrorCode::CSS_SYNTAX_DISALLOWED_PROPERTY_VALUE_WITH_HINT => [ - SpecRule::FORMAT => 'CSS syntax error in tag \'%1\' - the property \'%2\' is set to the disallowed value \'%3\'. Allowed values: %4.', - SpecRule::SPECIFICITY => 83, - ], - ErrorCode::CSS_SYNTAX_DISALLOWED_PSEUDO_CLASS => [ - SpecRule::FORMAT => 'CSS error in tag \'%1\' - disallowed pseudo class \'%2\'.', - SpecRule::SPECIFICITY => 121, - ], - ErrorCode::CSS_SYNTAX_DISALLOWED_PSEUDO_ELEMENT => [ - SpecRule::FORMAT => 'CSS error in tag \'%1\' - disallowed pseudo element \'%2\'.', - SpecRule::SPECIFICITY => 122, - ], - ErrorCode::CSS_SYNTAX_DISALLOWED_QUALIFIED_RULE_MUST_BE_INSIDE_KEYFRAME => [ - SpecRule::FORMAT => 'CSS syntax error in tag \'%1\' - qualified rule \'%2\' must be located inside of a keyframe.', - SpecRule::SPECIFICITY => 114, - ], - ErrorCode::CSS_SYNTAX_DISALLOWED_RELATIVE_URL => [ - SpecRule::FORMAT => 'CSS syntax error in tag \'%1\' - disallowed relative url \'%2\'.', - SpecRule::SPECIFICITY => 72, - ], - ErrorCode::CSS_SYNTAX_EOF_IN_PRELUDE_OF_QUALIFIED_RULE => [ - SpecRule::FORMAT => 'CSS syntax error in tag \'%1\' - end of stylesheet encountered in prelude of a qualified rule.', - SpecRule::SPECIFICITY => 61, - ], - ErrorCode::CSS_SYNTAX_ERROR_IN_PSEUDO_SELECTOR => [ - SpecRule::FORMAT => 'CSS syntax error in tag \'%1\' - invalid pseudo selector.', - SpecRule::SPECIFICITY => 64, - ], - ErrorCode::CSS_SYNTAX_INCOMPLETE_DECLARATION => [ - SpecRule::FORMAT => 'CSS syntax error in tag \'%1\' - incomplete declaration.', - SpecRule::SPECIFICITY => 63, - ], - ErrorCode::CSS_SYNTAX_INVALID_ATTR_SELECTOR => [ - SpecRule::FORMAT => 'CSS syntax error in tag \'%1\' - invalid attribute selector.', - SpecRule::SPECIFICITY => 76, - ], - ErrorCode::CSS_SYNTAX_INVALID_AT_RULE => [ - SpecRule::FORMAT => 'CSS syntax error in tag \'%1\' - saw invalid at rule \'@%2\'.', - SpecRule::SPECIFICITY => 36, - ], - ErrorCode::CSS_SYNTAX_INVALID_DECLARATION => [ - SpecRule::FORMAT => 'CSS syntax error in tag \'%1\' - invalid declaration.', - SpecRule::SPECIFICITY => 62, - ], - ErrorCode::CSS_SYNTAX_INVALID_PROPERTY => [ - SpecRule::FORMAT => 'CSS syntax error in tag \'%1\' - invalid property \'%2\'. The only allowed properties are \'%3\'.', - SpecRule::SPECIFICITY => 111, - ], - ErrorCode::CSS_SYNTAX_INVALID_PROPERTY_NOLIST => [ - SpecRule::FORMAT => 'CSS syntax error in tag \'%1\' - invalid property \'%2\'.', - SpecRule::SPECIFICITY => 112, - ], - ErrorCode::CSS_SYNTAX_INVALID_URL => [ - SpecRule::FORMAT => 'CSS syntax error in tag \'%1\' - invalid url \'%2\'.', - SpecRule::SPECIFICITY => 70, - ], - ErrorCode::CSS_SYNTAX_INVALID_URL_PROTOCOL => [ - SpecRule::FORMAT => 'CSS syntax error in tag \'%1\' - invalid url protocol \'%2:\'.', - SpecRule::SPECIFICITY => 71, - ], - ErrorCode::CSS_SYNTAX_MALFORMED_MEDIA_QUERY => [ - SpecRule::FORMAT => 'CSS syntax error in tag \'%1\' - malformed media query.', - SpecRule::SPECIFICITY => 117, - ], - ErrorCode::CSS_SYNTAX_MISSING_SELECTOR => [ - SpecRule::FORMAT => 'CSS syntax error in tag \'%1\' - missing selector.', - SpecRule::SPECIFICITY => 65, - ], - ErrorCode::CSS_SYNTAX_MISSING_URL => [ - SpecRule::FORMAT => 'CSS syntax error in tag \'%1\' - missing url.', - SpecRule::SPECIFICITY => 68, - ], - ErrorCode::CSS_SYNTAX_NOT_A_SELECTOR_START => [ - SpecRule::FORMAT => 'CSS syntax error in tag \'%1\' - not a selector start.', - SpecRule::SPECIFICITY => 66, - ], - ErrorCode::CSS_SYNTAX_PROPERTY_DISALLOWED_TOGETHER_WITH => [ - SpecRule::FORMAT => 'CSS syntax error in tag \'%1\' - the property \'%2\' is disallowed together with \'%3\'. Allowed properties: %4.', - SpecRule::SPECIFICITY => 85, - ], - ErrorCode::CSS_SYNTAX_PROPERTY_DISALLOWED_WITHIN_AT_RULE => [ - SpecRule::FORMAT => 'CSS syntax error in tag \'%1\' - the property \'%2\' is disallowed within @%3. Allowed properties: %4.', - SpecRule::SPECIFICITY => 84, - ], - ErrorCode::CSS_SYNTAX_PROPERTY_REQUIRES_QUALIFICATION => [ - SpecRule::FORMAT => 'CSS syntax error in tag \'%1\' - the property \'%2\' is disallowed unless the enclosing rule is prefixed with the \'%3\' qualification.', - SpecRule::SPECIFICITY => 86, - ], - ErrorCode::CSS_SYNTAX_QUALIFIED_RULE_HAS_NO_DECLARATIONS => [ - SpecRule::FORMAT => 'CSS syntax error in tag \'%1\' - qualified rule \'%2\' has no declarations.', - SpecRule::SPECIFICITY => 113, - ], - ErrorCode::CSS_SYNTAX_STRAY_TRAILING_BACKSLASH => [ - SpecRule::FORMAT => 'CSS syntax error in tag \'%1\' - stray trailing backslash.', - SpecRule::SPECIFICITY => 57, - ], - ErrorCode::CSS_SYNTAX_UNPARSED_INPUT_REMAINS_IN_SELECTOR => [ - SpecRule::FORMAT => 'CSS syntax error in tag \'%1\' - unparsed input remains in selector.', - SpecRule::SPECIFICITY => 67, - ], - ErrorCode::CSS_SYNTAX_UNTERMINATED_COMMENT => [ - SpecRule::FORMAT => 'CSS syntax error in tag \'%1\' - unterminated comment.', - SpecRule::SPECIFICITY => 58, - ], - ErrorCode::CSS_SYNTAX_UNTERMINATED_STRING => [ - SpecRule::FORMAT => 'CSS syntax error in tag \'%1\' - unterminated string.', - SpecRule::SPECIFICITY => 59, - ], - ErrorCode::DEPRECATED_ATTR => [ - SpecRule::FORMAT => 'The attribute \'%1\' in tag \'%2\' is deprecated - use \'%3\' instead.', - SpecRule::SPECIFICITY => 104, - ], - ErrorCode::DEPRECATED_TAG => [ - SpecRule::FORMAT => 'The tag \'%1\' is deprecated - use \'%2\' instead.', - SpecRule::SPECIFICITY => 105, - ], - ErrorCode::DEV_MODE_ONLY => [ - SpecRule::FORMAT => 'Tag \'html\' marked with attribute \'data-ampdevmode\'. Validator will suppress errors regarding any other tag with this attribute.', - SpecRule::SPECIFICITY => 1000, - ], - ErrorCode::DISALLOWED_ATTR => [ - SpecRule::FORMAT => 'The attribute \'%1\' may not appear in tag \'%2\'.', - SpecRule::SPECIFICITY => 22, - ], - ErrorCode::DISALLOWED_CHILD_TAG_NAME => [ - SpecRule::FORMAT => 'Tag \'%1\' is disallowed as child of tag \'%2\'. Child tag must be one of %3.', - SpecRule::SPECIFICITY => 74, - ], - ErrorCode::DISALLOWED_DOMAIN => [ - SpecRule::FORMAT => 'The domain \'%3\' for attribute \'%1\' in tag \'%2\' is disallowed.', - SpecRule::SPECIFICITY => 53, - ], - ErrorCode::DISALLOWED_FIRST_CHILD_TAG_NAME => [ - SpecRule::FORMAT => 'Tag \'%1\' is disallowed as first child of tag \'%2\'. First child tag must be one of %3.', - SpecRule::SPECIFICITY => 75, - ], - ErrorCode::DISALLOWED_MANUFACTURED_BODY => [ - SpecRule::FORMAT => 'Tag or text which is only allowed inside the body section found outside of the body section.', - SpecRule::SPECIFICITY => 106, - ], - ErrorCode::DISALLOWED_PROPERTY_IN_ATTR_VALUE => [ - SpecRule::FORMAT => 'The property \'%1\' in attribute \'%2\' in tag \'%3\' is disallowed.', - SpecRule::SPECIFICITY => 39, - ], - ErrorCode::DISALLOWED_RELATIVE_URL => [ - SpecRule::FORMAT => 'The relative URL \'%3\' for attribute \'%1\' in tag \'%2\' is disallowed.', - SpecRule::SPECIFICITY => 51, - ], - ErrorCode::DISALLOWED_SCRIPT_TAG => [ - SpecRule::FORMAT => 'Custom JavaScript is not allowed.', - SpecRule::SPECIFICITY => 102, - ], - ErrorCode::DISALLOWED_STYLE_ATTR => [ - SpecRule::FORMAT => 'The inline \'style\' attribute is not allowed in AMP documents. Use \'style amp-custom\' tag instead.', - SpecRule::SPECIFICITY => 56, - ], - ErrorCode::DISALLOWED_TAG => [ - SpecRule::FORMAT => 'The tag \'%1\' is disallowed.', - SpecRule::SPECIFICITY => 21, - ], - ErrorCode::DISALLOWED_TAG_ANCESTOR => [ - SpecRule::FORMAT => 'The tag \'%1\' may not appear as a descendant of tag \'%2\'.', - SpecRule::SPECIFICITY => 5, - ], - ErrorCode::DOCUMENT_SIZE_LIMIT_EXCEEDED => [ - SpecRule::FORMAT => 'Document exceeded %1 bytes limit. Actual size %2 bytes.', - SpecRule::SPECIFICITY => 126, - ], - ErrorCode::DOCUMENT_TOO_COMPLEX => [ - SpecRule::FORMAT => 'The document is too complex.', - SpecRule::SPECIFICITY => 107, - ], - ErrorCode::DUPLICATE_ATTRIBUTE => [ - SpecRule::FORMAT => 'The tag \'%1\' contains the attribute \'%2\' repeated multiple times.', - SpecRule::SPECIFICITY => 24, - ], - ErrorCode::DUPLICATE_DIMENSION => [ - SpecRule::FORMAT => 'Multiple image candidates with the same width or pixel density found in attribute \'%1\' in tag \'%2\'.', - SpecRule::SPECIFICITY => 50, - ], - ErrorCode::DUPLICATE_REFERENCE_POINT => [ - SpecRule::FORMAT => 'The reference point \'%1\' for \'%2\' must be unique but a duplicate was encountered.', - SpecRule::SPECIFICITY => 79, - ], - ErrorCode::DUPLICATE_UNIQUE_TAG => [ - SpecRule::FORMAT => 'The tag \'%1\' appears more than once in the document.', - SpecRule::SPECIFICITY => 30, - ], - ErrorCode::DUPLICATE_UNIQUE_TAG_WARNING => [ - SpecRule::FORMAT => 'The tag \'%1\' appears more than once in the document. This will soon be an error.', - SpecRule::SPECIFICITY => 31, - ], - ErrorCode::EXTENSION_UNUSED => [ - SpecRule::FORMAT => 'The extension \'%1\' was found on this page, but is unused. Please remove this extension.', - SpecRule::SPECIFICITY => 15, - ], - ErrorCode::GENERAL_DISALLOWED_TAG => [ - SpecRule::FORMAT => 'The tag \'%1\' is disallowed except in specific forms.', - SpecRule::SPECIFICITY => 103, - ], - ErrorCode::IMPLIED_LAYOUT_INVALID => [ - SpecRule::FORMAT => 'The implied layout \'%1\' is not supported by tag \'%2\'.', - SpecRule::SPECIFICITY => 46, - ], - ErrorCode::INCONSISTENT_UNITS_FOR_WIDTH_AND_HEIGHT => [ - SpecRule::FORMAT => 'Inconsistent units for width and height in tag \'%1\' - width is specified in \'%2\' whereas height is specified in \'%3\'.', - SpecRule::SPECIFICITY => 44, - ], - ErrorCode::INCORRECT_MIN_NUM_CHILD_TAGS => [ - SpecRule::FORMAT => 'Tag \'%1\' must have a minimum of %2 child tags - saw %3 child tags.', - SpecRule::SPECIFICITY => 108, - ], - ErrorCode::INCORRECT_NUM_CHILD_TAGS => [ - SpecRule::FORMAT => 'Tag \'%1\' must have %2 child tags - saw %3 child tags.', - SpecRule::SPECIFICITY => 73, - ], - ErrorCode::INCORRECT_SCRIPT_RELEASE_VERSION => [ - SpecRule::FORMAT => 'The script version for \'%1\' is a %2 version which mismatches with the first script on the page using the %3 version.', - SpecRule::SPECIFICITY => 20, - ], - ErrorCode::INLINE_SCRIPT_TOO_LONG => [ - SpecRule::FORMAT => 'The inline script is %1 bytes, which exceeds the limit of %2 bytes.', - SpecRule::SPECIFICITY => 35, - ], - ErrorCode::INLINE_STYLE_TOO_LONG => [ - SpecRule::FORMAT => 'The inline style specified in tag \'%1\' is too long - it contains %2 bytes whereas the limit is %3 bytes.', - SpecRule::SPECIFICITY => 34, - ], - ErrorCode::INVALID_ATTR_VALUE => [ - SpecRule::FORMAT => 'The attribute \'%1\' in tag \'%2\' is set to the invalid value \'%3\'.', - SpecRule::SPECIFICITY => 23, - ], - ErrorCode::INVALID_DOCTYPE_HTML => [ - SpecRule::FORMAT => 'Invalid or missing doctype declaration. Should be \'!doctype html\'.', - SpecRule::SPECIFICITY => 128, - ], - ErrorCode::INVALID_JSON_CDATA => [ - SpecRule::FORMAT => 'The script tag contains invalid JSON that cannot be parsed.', - SpecRule::SPECIFICITY => 4, - ], - ErrorCode::INVALID_PROPERTY_VALUE_IN_ATTR_VALUE => [ - SpecRule::FORMAT => 'The property \'%1\' in attribute \'%2\' in tag \'%3\' is set to \'%4\', which is invalid.', - SpecRule::SPECIFICITY => 38, - ], - ErrorCode::INVALID_URL => [ - SpecRule::FORMAT => 'Malformed URL \'%3\' for attribute \'%1\' in tag \'%2\'.', - SpecRule::SPECIFICITY => 55, - ], - ErrorCode::INVALID_URL_PROTOCOL => [ - SpecRule::FORMAT => 'Invalid URL protocol \'%3:\' for attribute \'%1\' in tag \'%2\'.', - SpecRule::SPECIFICITY => 54, - ], - ErrorCode::INVALID_UTF8 => [ - SpecRule::FORMAT => 'The document contains invalid UTF8.', - SpecRule::SPECIFICITY => 124, - ], - ErrorCode::LTS_SCRIPT_AFTER_NON_LTS => [ - SpecRule::FORMAT => '\'%1\' must use the non-LTS version to correspond with the first script in the page, which does not use LTS.', - SpecRule::SPECIFICITY => 19, - ], - ErrorCode::MANDATORY_ANYOF_ATTR_MISSING => [ - SpecRule::FORMAT => 'The tag \'%1\' is missing a mandatory attribute - pick at least one of %2.', - SpecRule::SPECIFICITY => 28, - ], - ErrorCode::MANDATORY_ATTR_MISSING => [ - SpecRule::FORMAT => 'The mandatory attribute \'%1\' is missing in tag \'%2\'.', - SpecRule::SPECIFICITY => 26, - ], - ErrorCode::MANDATORY_CDATA_MISSING_OR_INCORRECT => [ - SpecRule::FORMAT => 'The mandatory text inside tag \'%1\' is missing or incorrect.', - SpecRule::SPECIFICITY => 1, - ], - ErrorCode::MANDATORY_LAST_CHILD_TAG => [ - SpecRule::FORMAT => 'Tag \'%1\', if present, must be the last child of tag \'%2\'.', - SpecRule::SPECIFICITY => 110, - ], - ErrorCode::MANDATORY_ONEOF_ATTR_MISSING => [ - SpecRule::FORMAT => 'The tag \'%1\' is missing a mandatory attribute - pick one of %2.', - SpecRule::SPECIFICITY => 27, - ], - ErrorCode::MANDATORY_PROPERTY_MISSING_FROM_ATTR_VALUE => [ - SpecRule::FORMAT => 'The property \'%1\' is missing from attribute \'%2\' in tag \'%3\'.', - SpecRule::SPECIFICITY => 37, - ], - ErrorCode::MANDATORY_REFERENCE_POINT_MISSING => [ - SpecRule::FORMAT => 'The mandatory reference point \'%1\' for \'%2\' is missing.', - SpecRule::SPECIFICITY => 78, - ], - ErrorCode::MANDATORY_TAG_ANCESTOR => [ - SpecRule::FORMAT => 'The tag \'%1\' may only appear as a descendant of tag \'%2\'.', - SpecRule::SPECIFICITY => 6, - ], - ErrorCode::MANDATORY_TAG_ANCESTOR_WITH_HINT => [ - SpecRule::FORMAT => 'The tag \'%1\' may only appear as a descendant of tag \'%2\'. Did you mean \'%3\'?', - SpecRule::SPECIFICITY => 7, - ], - ErrorCode::MANDATORY_TAG_MISSING => [ - SpecRule::FORMAT => 'The mandatory tag \'%1\' is missing or incorrect.', - SpecRule::SPECIFICITY => 8, - ], - ErrorCode::MISSING_LAYOUT_ATTRIBUTES => [ - SpecRule::FORMAT => 'Incomplete layout attributes specified for tag \'%1\'. For example, provide attributes \'width\' and \'height\'.', - SpecRule::SPECIFICITY => 45, - ], - ErrorCode::MISSING_REQUIRED_EXTENSION => [ - SpecRule::FORMAT => 'The tag \'%1\' requires including the \'%2\' extension JavaScript.', - SpecRule::SPECIFICITY => 12, - ], - ErrorCode::MISSING_URL => [ - SpecRule::FORMAT => 'Missing URL for attribute \'%1\' in tag \'%2\'.', - SpecRule::SPECIFICITY => 52, - ], - ErrorCode::MUTUALLY_EXCLUSIVE_ATTRS => [ - SpecRule::FORMAT => 'Mutually exclusive attributes encountered in tag \'%1\' - pick one of %2.', - SpecRule::SPECIFICITY => 40, - ], - ErrorCode::NON_LTS_SCRIPT_AFTER_LTS => [ - SpecRule::FORMAT => '\'%1\' must use the LTS version to correspond with the first script in the page, which uses LTS.', - SpecRule::SPECIFICITY => 18, - ], - ErrorCode::NON_WHITESPACE_CDATA_ENCOUNTERED => [ - SpecRule::FORMAT => 'The tag \'%1\' contains text, which is disallowed.', - SpecRule::SPECIFICITY => 3, - ], - ErrorCode::SPECIFIED_LAYOUT_INVALID => [ - SpecRule::FORMAT => 'The specified layout \'%1\' is not supported by tag \'%2\'.', - SpecRule::SPECIFICITY => 47, - ], - ErrorCode::STYLESHEET_AND_INLINE_STYLE_TOO_LONG => [ - SpecRule::FORMAT => 'The author stylesheet specified in tag \'style amp-custom\' and the combined inline styles is too large - document contains %1 bytes whereas the limit is %2 bytes.', - SpecRule::SPECIFICITY => 33, - ], - ErrorCode::STYLESHEET_TOO_LONG => [ - SpecRule::FORMAT => 'The author stylesheet specified in tag \'%1\' is too long - document contains %2 bytes whereas the limit is %3 bytes.', - SpecRule::SPECIFICITY => 32, - ], - ErrorCode::TAG_EXCLUDED_BY_TAG => [ - SpecRule::FORMAT => 'The tag \'%1\' is present, but is excluded by the presence of \'%2\'.', - SpecRule::SPECIFICITY => 11, - ], - ErrorCode::TAG_NOT_ALLOWED_TO_HAVE_SIBLINGS => [ - SpecRule::FORMAT => 'Tag \'%1\' is not allowed to have any sibling tags (\'%2\' should only have 1 child).', - SpecRule::SPECIFICITY => 109, - ], - ErrorCode::TAG_REFERENCE_POINT_CONFLICT => [ - SpecRule::FORMAT => 'The tag \'%1\' conflicts with reference point \'%2\' because both define reference points.', - SpecRule::SPECIFICITY => 80, - ], - ErrorCode::TAG_REQUIRED_BY_MISSING => [ - SpecRule::FORMAT => 'The tag \'%1\' is missing or incorrect, but required by \'%2\'.', - SpecRule::SPECIFICITY => 10, - ], - ErrorCode::TEMPLATE_IN_ATTR_NAME => [ - SpecRule::FORMAT => 'Mustache template syntax in attribute name \'%1\' in tag \'%2\'.', - SpecRule::SPECIFICITY => 43, - ], - ErrorCode::TEMPLATE_PARTIAL_IN_ATTR_VALUE => [ - SpecRule::FORMAT => 'The attribute \'%1\' in tag \'%2\' is set to \'%3\', which contains a Mustache template partial.', - SpecRule::SPECIFICITY => 42, - ], - ErrorCode::UNESCAPED_TEMPLATE_IN_ATTR_VALUE => [ - SpecRule::FORMAT => 'The attribute \'%1\' in tag \'%2\' is set to \'%3\', which contains unescaped Mustache template syntax.', - SpecRule::SPECIFICITY => 41, - ], - ErrorCode::UNKNOWN_CODE => [ - SpecRule::FORMAT => 'Unknown error.', - SpecRule::SPECIFICITY => 0, - ], - ErrorCode::VALUE_SET_MISMATCH => [ - SpecRule::FORMAT => 'Attribute \'%1\' in tag \'%2\' contains a value that does not match any other tags on the page.', - SpecRule::SPECIFICITY => 127, - ], - ErrorCode::WARNING_EXTENSION_DEPRECATED_VERSION => [ - SpecRule::FORMAT => 'The extension \'%1\' is referenced at version \'%2\' which is a deprecated version. Please use a more recent version of this extension. This may become an error in the future.', - SpecRule::SPECIFICITY => 17, - ], - ErrorCode::WARNING_EXTENSION_UNUSED => [ - SpecRule::FORMAT => 'The extension \'%1\' was found on this page, but is unused (no \'%2\' tag seen). This may become an error in the future.', - SpecRule::SPECIFICITY => 16, - ], - ErrorCode::WARNING_TAG_REQUIRED_BY_MISSING => [ - SpecRule::FORMAT => 'The tag \'%1\' is missing or incorrect, but required by \'%2\'. This will soon be an error.', - SpecRule::SPECIFICITY => 14, - ], - ErrorCode::WRONG_PARENT_TAG => [ - SpecRule::FORMAT => 'The parent tag of tag \'%1\' is \'%2\', but it can only be \'%3\'.', - SpecRule::SPECIFICITY => 9, - ], - ]; + return $this->parentCurrent(); } } diff --git a/tests/Exception/InvalidErrorCodeTest.php b/tests/Exception/InvalidErrorCodeTest.php new file mode 100644 index 000000000..15d2d57e1 --- /dev/null +++ b/tests/Exception/InvalidErrorCodeTest.php @@ -0,0 +1,26 @@ +expectException(InvalidErrorCode::class); + $this->expectExceptionMessage("Invalid error code 'errorCode' was requested from the validator spec."); + + throw InvalidErrorCode::forErrorCode('errorCode'); + } +} diff --git a/tests/Validator/Spec/ErrorTest.php b/tests/Validator/Spec/ErrorTest.php new file mode 100644 index 000000000..044fd2387 --- /dev/null +++ b/tests/Validator/Spec/ErrorTest.php @@ -0,0 +1,44 @@ +assertEquals('dummy', $dummyError->getCode()); + + $this->assertTrue($dummyError->has('format')); + $this->assertFalse($dummyError->has('utter nonsense')); + + $format = $dummyError->get('format'); + + $this->assertIsString($format); + $this->assertEquals('this is an error', $format); + } + + /** + * @covers \AmpProject\Validator\Spec\Error::get() + * @covers \AmpProject\Exception\InvalidSpecRuleName::forSpecRuleName() + */ + public function testThrowsExceptionForUnknownError() + { + $dummyError = new DummyError(); + + $this->expectException(InvalidSpecRuleName::class); + $this->expectExceptionMessage("Invalid spec rule name 'utter nonsense' was requested from the validator spec."); + $dummyError->get('utter nonsense'); + } +} diff --git a/tests/Validator/Spec/Section/AttributeListsTest.php b/tests/Validator/Spec/Section/AttributeListsTest.php index 24b1885df..1e8fa121c 100644 --- a/tests/Validator/Spec/Section/AttributeListsTest.php +++ b/tests/Validator/Spec/Section/AttributeListsTest.php @@ -2,7 +2,6 @@ namespace AmpProject\Validator\Spec\Section; -use AmpProject\Attribute; use AmpProject\Exception\InvalidAttributeName; use AmpProject\Exception\InvalidListName; use AmpProject\Tests\TestCase; diff --git a/tests/Validator/Spec/Section/DeclarationListsTest.php b/tests/Validator/Spec/Section/DeclarationListsTest.php index 7b691e661..c3c5fffa1 100644 --- a/tests/Validator/Spec/Section/DeclarationListsTest.php +++ b/tests/Validator/Spec/Section/DeclarationListsTest.php @@ -2,8 +2,6 @@ namespace AmpProject\Validator\Spec\Section; -use AmpProject\Attribute; -use AmpProject\Exception\InvalidDeclarationName; use AmpProject\Exception\InvalidListName; use AmpProject\Tests\TestCase; use AmpProject\Validator\Spec; diff --git a/tests/Validator/Spec/Section/DescendantTagListsTest.php b/tests/Validator/Spec/Section/DescendantTagListsTest.php index a21442f09..e0658016d 100644 --- a/tests/Validator/Spec/Section/DescendantTagListsTest.php +++ b/tests/Validator/Spec/Section/DescendantTagListsTest.php @@ -2,7 +2,6 @@ namespace AmpProject\Validator\Spec\Section; -use AmpProject\Tag; use AmpProject\Exception\InvalidDescendantTagName; use AmpProject\Exception\InvalidListName; use AmpProject\Tests\TestCase; diff --git a/tests/Validator/Spec/Section/ErrorsTest.php b/tests/Validator/Spec/Section/ErrorsTest.php new file mode 100644 index 000000000..ff172c644 --- /dev/null +++ b/tests/Validator/Spec/Section/ErrorsTest.php @@ -0,0 +1,64 @@ +errors = $spec->errors(); + } + + /** + * @covers \AmpProject\Validator\Spec\Section\Errors::get() + */ + public function testGetByErrorName() + { + $error = $this->errors->get('DISALLOWED_TAG'); + + $this->assertInstanceOf(Spec\Error::class, $error); + $this->assertInstanceOf(Spec\Error\DisallowedTag::class, $error); + } + + /** + * @covers \AmpProject\Validator\Spec\Section\Errors::get() + * @covers \AmpProject\Exception\InvalidErrorCode::forErrorCode() + */ + public function testGetThrowsExceptionForUnknownErrorName() + { + $this->expectException(InvalidErrorCode::class); + $this->errors->get('utter nonsense'); + } + + public function testGetThrowsExceptionForUnknownErrorCode() + { + $this->expectException(InvalidSpecRuleName::class); + $error = $this->errors->get('DISALLOWED_TAG'); + $error->get('utter nonsense'); + } + + public function testIteration() + { + $this->assertGreaterThan(10, count($this->errors)); + foreach ($this->errors as $error) { + $this->assertInstanceOf(Spec\Error::class, $error); + $this->assertNotEmpty($error::SPEC); + } + } +} diff --git a/tests/src/ValidatorFixtures/DummyError.php b/tests/src/ValidatorFixtures/DummyError.php new file mode 100644 index 000000000..df493b815 --- /dev/null +++ b/tests/src/ValidatorFixtures/DummyError.php @@ -0,0 +1,18 @@ + */ + const SPEC = [ + SpecRule::FORMAT => 'this is an error', + ]; +}