From 12b96a39c23866eab2b739c76b4d97d414a53e3d Mon Sep 17 00:00:00 2001 From: Xavier Lacot Date: Fri, 13 Nov 2026 18:16:39 +0100 Subject: [PATCH 1/2] Make the merge of the blocks sharing an identifier an audit option exposed as items --- .castor/validate.php | 176 +++++++++------ CHANGELOG.md | 15 +- README.md | 49 +++- src/Audit/Audit.php | 48 +++- src/Audit/AuditOptions.php | 2 + src/Audit/Item.php | 70 ++++++ src/Mapper/MappedError.php | 11 - src/Mapper/MappedErrorTemplate.php | 1 - src/Mapper/MappedProperty.php | 5 - src/Mapper/MappedType.php | 12 - src/Mapper/MappedTypeMerger.php | 213 +++++++----------- .../ValidationSnippetTemplateApplier.php | 1 - .../ValidationSnippetTemplateBuilder.php | 1 - src/Validator.php | 103 +++++---- .../Validators/AbstractValidator.php | 3 +- .../Validators/Google/GoogleValidator.php | 14 +- tests/Validation/SharedIdentifierTest.php | 196 ++++++++++++---- .../Validation/fixtures/google-baseline.json | 19 +- 18 files changed, 582 insertions(+), 357 deletions(-) create mode 100644 src/Audit/Item.php diff --git a/.castor/validate.php b/.castor/validate.php index 023c4d0b..8dcd0c3e 100644 --- a/.castor/validate.php +++ b/.castor/validate.php @@ -10,15 +10,18 @@ */ use Castor\Attribute\AsArgument; +use Castor\Attribute\AsOption; use Castor\Attribute\AsTask; use function Castor\http_request; use function Castor\io; use JoliCode\StructuredData\Audit\AuditOptions; +use JoliCode\StructuredData\Audit\Item; use JoliCode\StructuredData\Mapper\MappedError; use JoliCode\StructuredData\Mapper\MappedProperty; use JoliCode\StructuredData\Mapper\MappedType; +use JoliCode\StructuredData\Mapper\MappedTypeMerger; use JoliCode\StructuredData\Validator; use JoliCode\StructuredData\Vocabularies\Validators\Google\GoogleValidator; use Symfony\Component\Console\Command\Command; @@ -30,8 +33,10 @@ function check( string $fileOrUrl, #[AsArgument(name: 'validator', description: 'The specific validator to use. Accepted values are: "schema-org", "schemaorg", "google".')] false|string $specificValidator = false, + #[AsOption(name: 'no-merge', description: 'Audit every block on its own, instead of merging the blocks sharing an identifier as Google does')] + bool $noMerge = false, ): int { - return runValidation($fileOrUrl, $specificValidator, false); + return runValidation($fileOrUrl, $specificValidator, false, !$noMerge); } #[AsTask(name: 'validate', description: 'Fully validate a local file or a remote URL')] @@ -40,8 +45,10 @@ function validate( string $fileOrUrl, #[AsArgument(name: 'validator', description: 'The specific validator to use. Accepted values are: "schema-org", "schemaorg", "google".')] false|string $specificValidator = false, + #[AsOption(name: 'no-merge', description: 'Audit every block on its own, instead of merging the blocks sharing an identifier as Google does')] + bool $noMerge = false, ): int { - return runValidation($fileOrUrl, $specificValidator, true); + return runValidation($fileOrUrl, $specificValidator, true, !$noMerge); } /** @@ -72,7 +79,7 @@ function resolveInput(string $fileOrUrl): string return $content; } -function runValidation(string $fileOrUrl, false|string $specificValidator, bool $withDetails): int +function runValidation(string $fileOrUrl, false|string $specificValidator, bool $withDetails, bool $merge): int { io()->title(sprintf($withDetails ? 'Validating %s' : 'Checking %s', $fileOrUrl)); @@ -100,9 +107,9 @@ function runValidation(string $fileOrUrl, false|string $specificValidator, bool return Command::INVALID; } - $audit = $validator->audit($document); - $types = $audit->getTypes(); - $typesCount = count($types); + $audit = $validator->audit($document, mergeNodesSharingAnIdentifier: $merge); + $typesCount = count($audit->getTypes()); + $items = $audit->getItems(); if (0 === $typesCount) { io()->warning('No schema.org types were found in the provided document.'); @@ -116,71 +123,25 @@ function runValidation(string $fileOrUrl, false|string $specificValidator, bool io()->info(sprintf('%d schema.org types were found in the provided document.', $typesCount)); } + if (count($items) !== $typesCount) { + io()->info(sprintf( + 'The blocks sharing an identifier are merged, as Google does: they describe %d %s. Use --no-merge to audit every block on its own.', + count($items), + 1 === count($items) ? 'node' : 'nodes', + )); + } + if ($withDetails) { - foreach ($types as $index => $type) { + foreach ($items as $index => $item) { io()->section(sprintf('Type N° %d', $index + 1)); - displayType($type); - io()->writeln(''); - - $hasGoogleErrors = false; - $hasGoogleWarnings = false; - $hasSchemaOrgErrors = false; - $hasSchemaOrgWarnings = false; - - if ($errors = $type->getMergedErrors()) { - foreach ($errors as $error) { - if (MappedError::SEVERITY_ERROR === $error->getSeverity()) { - io()->writeln(sprintf('%s', $error->getFormattedMessage())); - - if (GoogleValidator::VALIDATOR_NAME === $error->getValidatorName()) { - $hasGoogleErrors = true; - } else { - $hasSchemaOrgErrors = true; - } - } else { - io()->writeln(sprintf('%s', $error->getFormattedMessage())); - - if (GoogleValidator::VALIDATOR_NAME === $error->getValidatorName()) { - $hasGoogleWarnings = true; - } else { - $hasSchemaOrgWarnings = true; - } - } - - io()->writeln(sprintf( - "The above %s was raised for %s%s\nFound on input positions %s (line:col)", - $error->getSeverity(), - $error->getType() ? sprintf('the type "%s"', $error->getType()) : 'an unknown type (with no @type property)', - $error->getProperty() ? sprintf(' on its "%s" property', $error->getProperty()) : '', - $error->getRanges(), - )); - io()->writeln(''); - } - } else { - io()->writeln('Type is fully valid!'); - io()->writeln(''); - } - - $googleSpecific = strtolower(GoogleValidator::VALIDATOR_NAME) === $specificValidator; - - if (!$specificValidator || $googleSpecific) { - io()->writeln(sprintf( - 'Google Validation: %s', - $hasGoogleErrors ? 'magenta' : ($hasGoogleWarnings ? 'yellow' : 'blue'), - $hasGoogleErrors ? 'FAILURE' : ($hasGoogleWarnings ? 'WARNINGS' : 'PASSES'), - )); - } - - if (!$googleSpecific) { - io()->writeln(sprintf( - 'Schema.org Validation: %s', - $hasSchemaOrgErrors ? 'magenta' : ($hasSchemaOrgWarnings ? 'yellow' : 'blue'), - $hasSchemaOrgErrors ? 'FAILURE' : ($hasSchemaOrgWarnings ? 'WARNINGS' : 'PASSES'), - )); + if ($item->isMerged()) { + displaySources($item); } + displayType($item->getType()); io()->writeln(''); + displayDiagnostics($item->getType(), $specificValidator); } } @@ -216,6 +177,91 @@ function runValidation(string $fileOrUrl, false|string $specificValidator, bool return Command::SUCCESS; } +function displaySources(Item $item): void +{ + $sources = $item->getSources(); + + io()->writeln(sprintf('Merged from %d blocks sharing the identifier "%s":', count($sources), $item->getIdentifier())); + + foreach ($sources as $source) { + $line = ($source->getValueRanges()[0] ?? null)?->start?->line; + + io()->writeln(sprintf( + ' * a %s block%s', + $source->getSourceFormat(), + null !== $line ? sprintf(' on line %d', $line) : '', + )); + } + + io()->writeln(''); +} + +function displayDiagnostics(MappedType $type, false|string $specificValidator): void +{ + $hasGoogleErrors = false; + $hasGoogleWarnings = false; + $hasSchemaOrgErrors = false; + $hasSchemaOrgWarnings = false; + + if ($errors = $type->getMergedErrors()) { + foreach ($errors as $error) { + // The values the merged blocks disagree on weigh on no verdict. + $isMergeIssue = MappedTypeMerger::VALIDATOR_NAME === $error->getValidatorName(); + $isGoogleIssue = GoogleValidator::VALIDATOR_NAME === $error->getValidatorName(); + + if (MappedError::SEVERITY_ERROR === $error->getSeverity()) { + io()->writeln(sprintf('%s', $error->getFormattedMessage())); + + if ($isGoogleIssue) { + $hasGoogleErrors = true; + } elseif (!$isMergeIssue) { + $hasSchemaOrgErrors = true; + } + } else { + io()->writeln(sprintf('%s', $error->getFormattedMessage())); + + if ($isGoogleIssue) { + $hasGoogleWarnings = true; + } elseif (!$isMergeIssue) { + $hasSchemaOrgWarnings = true; + } + } + + io()->writeln(sprintf( + "The above %s was raised for %s%s\nFound on input positions %s (line:col)", + $error->getSeverity(), + $error->getType() ? sprintf('the type "%s"', $error->getType()) : 'an unknown type (with no @type property)', + $error->getProperty() ? sprintf(' on its "%s" property', $error->getProperty()) : '', + $error->getRanges(), + )); + io()->writeln(''); + } + } else { + io()->writeln('Type is fully valid!'); + io()->writeln(''); + } + + $googleSpecific = strtolower(GoogleValidator::VALIDATOR_NAME) === $specificValidator; + + if (!$specificValidator || $googleSpecific) { + io()->writeln(sprintf( + 'Google Validation: %s', + $hasGoogleErrors ? 'magenta' : ($hasGoogleWarnings ? 'yellow' : 'blue'), + $hasGoogleErrors ? 'FAILURE' : ($hasGoogleWarnings ? 'WARNINGS' : 'PASSES'), + )); + } + + if (!$googleSpecific) { + io()->writeln(sprintf( + 'Schema.org Validation: %s', + $hasSchemaOrgErrors ? 'magenta' : ($hasSchemaOrgWarnings ? 'yellow' : 'blue'), + $hasSchemaOrgErrors ? 'FAILURE' : ($hasSchemaOrgWarnings ? 'WARNINGS' : 'PASSES'), + )); + } + + io()->writeln(''); +} + function displayType(MappedType $type, int $level = 0): void { $prefix = str_repeat(' ', $level); diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ee43dc4..350a1432 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,14 +10,19 @@ - `BENCHMARKS.md` documents the benchmark figures and what each of them measures. `castor qa:bench:validators` now also runs the worker benchmark, which audits a stream of distinct documents and is the figure to quote for a crawler. +- The blocks of a document that share an identifier (a JSON-LD `@id`, a microdata + `itemid`) describe one node for Google, whatever their format, with the union of their + properties. The audit now merges them into one item, validated as a whole: a property one + block omits is no longer reported missing when another block provides it, and the issues + of the node are reported once. `Audit::getItems()` lists the items, each with its node + and its source blocks, which keep their own audit; `Audit::getTypes()` still lists the + blocks. Values the blocks disagree on are a warning of the merged item (validator + `Merge`, `AuditOptions::VALIDATOR_MERGE`), since Google keeps them all. The merge is on + by default; pass `mergeNodesSharingAnIdentifier: false` to `Validator::audit()`, or + `--no-merge` to `castor validate` and `castor check`, to audit every block on its own. ### Fixed -- The blocks of a document that share an identifier (a JSON-LD `@id`, a microdata - `itemid`) describe one node for Google, whatever their format, with the union of their - properties. A property one block omits is no longer reported missing when another block - provides it; each block keeps its own diagnostics and positions otherwise. Values the - blocks disagree on are reported as a document warning, since Google keeps them all. - Google validator: the address sub-properties of an event location (`streetAddress`, `addressRegion`...) are no longer reported when missing: the documentation only shows them in an example, and Google does not report them. diff --git a/README.md b/README.md index b8ea4c36..8e1f25e0 100644 --- a/README.md +++ b/README.md @@ -148,12 +148,41 @@ The validator accepts the following data formats: Google reads a page as one graph: the blocks that share an identifier (a JSON-LD `@id`, a microdata `itemid`) are one node holding the union of their properties, whatever their format, and a property one block omits is not missing when another block provides it. -The validator does the same. Each block is still audited on its own, with its positions -in the document, but the "missing property" issues that another block resolves are not -reported, and the audit is valid when the merged node is. When the blocks disagree on a -value, Google keeps every value and reports nothing; the disagreement is reported as a -document warning, outside the Google diagnostics. Blank node identifiers are local to -their block and never merge. + +By default, the validator does the same. The audit is made of items, one per node, listed +by `Audit::getItems()`: the blocks sharing an identifier make one item, the others one +item each. The diagnostics of the audit (`isValid()`, `getDiagnostic()`) are the ones of +the items, so an issue of a merged node is reported once, with the positions of every +block it comes from. + +```php +foreach ($audit->getItems() as $item) { + $item->getType(); // the node: merged from several blocks, or the block itself + $item->isMerged(); // true when the node comes from several blocks + $item->getIdentifier(); // its absolute "@id" or "itemid", if any + $item->getSources(); // the blocks it comes from +} +``` + +Each source block keeps its own audit, as if it were alone in the document: a block may +report a property another block provides, while the merged item, which makes the verdict, +does not. `Audit::getTypes()` still lists the blocks. + +When the blocks disagree on a value, Google keeps every value and reports nothing; the +validator raises a warning on the property of the merged node, with the `Merge` validator +name (`AuditOptions::VALIDATOR_MERGE`), outside the Google diagnostics. Blank node +identifiers are local to their block and never merge, and identifiers are compared as +written. Only the top-level node of each block is merged: nested nodes sharing an +identifier are not. + +Google is not the only consumer of structured data, though. To audit every block on its +own, with no merge, disable the option: + +```php +$audit = $validator->audit($document, mergeNodesSharingAnIdentifier: false); +``` + +Each block is then an item of its own. ### Using the validator @@ -250,6 +279,14 @@ castor validate google castor validate schema-org ``` +The blocks sharing an identifier are merged, as Google does (see +[Blocks describing the same node](#blocks-describing-the-same-node)); pass `--no-merge` +to audit every block on its own: + +```bash +castor validate --no-merge +``` + Sample result of the validate command: Output of the castor validate command diff --git a/src/Audit/Audit.php b/src/Audit/Audit.php index d9a2424b..708701a9 100644 --- a/src/Audit/Audit.php +++ b/src/Audit/Audit.php @@ -13,6 +13,7 @@ use JoliCode\StructuredData\Mapper\MappedError; use JoliCode\StructuredData\Mapper\MappedType; +use JoliCode\StructuredData\Mapper\MappedTypeMerger; use JoliCode\StructuredData\Vocabularies\Validators\Google\GoogleValidator; use JoliCode\StructuredData\Vocabularies\Validators\SchemaOrg\SchemaOrgValidator; @@ -43,19 +44,36 @@ final class Audit */ private array $byDocument = []; + /** + * @var array + */ + private array $byMerge = []; + /** * @var array */ private array $full = []; /** - * @param array $types + * @var list + */ + private array $items; + + /** + * @param array $types the blocks found in the document * @param array $documentIssues + * @param list|null $items the nodes the diagnostics are computed from; one item per block when null */ public function __construct( private array $types = [], private array $documentIssues = [], + ?array $items = null, ) { + $this->items = $items ?? array_map( + static fn (MappedType $type): Item => new Item($type, [$type], MappedTypeMerger::identifierOf($type)), + array_values($types), + ); + $this->sort(); } @@ -70,6 +88,9 @@ public function isFullyValid(): bool } /** + * Returns the structured data blocks found in the document, each with its own + * diagnostics, whether or not some of them were merged into one item. + * * @return array */ public function getTypes(): array @@ -77,6 +98,18 @@ public function getTypes(): array return $this->types; } + /** + * Returns the nodes of the document: one item per block, except for the + * blocks sharing an identifier, which make one item when they are merged. + * The diagnostics of the audit are the ones of its items. + * + * @return list + */ + public function getItems(): array + { + return $this->items; + } + /** * Returns validation errors for the provided input. * @@ -171,6 +204,10 @@ private function filterBy(AuditOptions $query): array return $this->byDocument; } + if (AuditOptions::VALIDATOR_MERGE === $validatorName) { + return $this->byMerge; + } + throw new \InvalidArgumentException(\sprintf('Invalid validator query option provided: %s', $validatorName)); } @@ -219,10 +256,11 @@ private function sort(): void $this->byGoogle = []; $this->bySchemaOrg = []; $this->byDocument = []; + $this->byMerge = []; $this->full = []; - $callback = function (MappedType $type): void { - foreach ($type->getMergedErrors() as $error) { + $callback = function (Item $item): void { + foreach ($item->getType()->getMergedErrors() as $error) { if (MappedError::SEVERITY_ERROR === $error->getSeverity()) { $this->byErrors[] = $error; } else { @@ -236,13 +274,15 @@ private function sort(): void $this->byGoogle[] = $error; } elseif (SchemaOrgValidator::VALIDATOR_NAME === $error->getValidatorName()) { $this->bySchemaOrg[] = $error; + } elseif (MappedTypeMerger::VALIDATOR_NAME === $error->getValidatorName()) { + $this->byMerge[] = $error; } $this->full[] = $error; } }; - array_walk($this->types, $callback); + array_walk($this->items, $callback); foreach ($this->documentIssues as $documentIssue) { if (MappedError::SEVERITY_ERROR === $documentIssue->getSeverity()) { diff --git a/src/Audit/AuditOptions.php b/src/Audit/AuditOptions.php index d90aa65b..d5b698cd 100644 --- a/src/Audit/AuditOptions.php +++ b/src/Audit/AuditOptions.php @@ -20,6 +20,7 @@ public const VALIDATOR_GOOGLE = 'google'; public const VALIDATOR_SCHEMA_ORG = 'schema.org'; public const VALIDATOR_DOCUMENT = 'document'; + public const VALIDATOR_MERGE = 'merge'; public const GROUP_BY_VALIDATOR = 'validator'; public const GROUP_BY_SEVERITY = 'severity'; @@ -41,6 +42,7 @@ * - `AuditOptions::VALIDATOR_GOOGLE` * - `AuditOptions::VALIDATOR_SCHEMA_ORG` * - `AuditOptions::VALIDATOR_DOCUMENT`: document-level issues found while parsing/extracting + * - `AuditOptions::VALIDATOR_MERGE`: values the blocks merged into one item disagree on * @param ?string $groupBy * Group results instead of returning a flat list. * diff --git a/src/Audit/Item.php b/src/Audit/Item.php new file mode 100644 index 00000000..d1874ce0 --- /dev/null +++ b/src/Audit/Item.php @@ -0,0 +1,70 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace JoliCode\StructuredData\Audit; + +use JoliCode\StructuredData\Mapper\MappedType; + +/** + * One node of the audited document, as a consumer of the structured data sees it. + * + * When the blocks sharing an identifier are merged (the default, as Google does), + * an item holds the node built from all of them, and the blocks it comes from. + * Otherwise, and for a block sharing its identifier with no other, the item is the + * block itself. + */ +final readonly class Item +{ + /** + * @param list $sources + */ + public function __construct( + private MappedType $type, + private array $sources, + private ?string $identifier = null, + ) { + } + + /** + * The node, with the diagnostics that make the verdict of the item: the + * merged node for a merged item, the block itself otherwise. + */ + public function getType(): MappedType + { + return $this->type; + } + + /** + * The blocks of the document the item comes from, in document order, each + * with its source format, its positions and its own diagnostics: a block of a + * merged item is audited as if it were alone, so it may report a property + * another block provides. + * + * @return list + */ + public function getSources(): array + { + return $this->sources; + } + + /** + * The absolute identifier ("@id", "itemid") of the node, if it has one. + */ + public function getIdentifier(): ?string + { + return $this->identifier; + } + + public function isMerged(): bool + { + return isset($this->sources[1]); + } +} diff --git a/src/Mapper/MappedError.php b/src/Mapper/MappedError.php index ae45990d..51363b34 100644 --- a/src/Mapper/MappedError.php +++ b/src/Mapper/MappedError.php @@ -25,12 +25,6 @@ public function __construct( private string $ranges, private MappedType|MappedProperty|null $parent = null, private ?string $documentationLink = null, - /** - * The property (or the alternatives, comma-separated) whose absence this - * error reports, when it reports an absence: such an error can be - * resolved by another block of the document describing the same node. - */ - private ?string $missingProperty = null, ) { } @@ -102,11 +96,6 @@ public function getDocumentationLink(): ?string return $this->documentationLink; } - public function getMissingProperty(): ?string - { - return $this->missingProperty; - } - public function getPath(): string { $parentPath = $this->parent?->getPath(); diff --git a/src/Mapper/MappedErrorTemplate.php b/src/Mapper/MappedErrorTemplate.php index b4c5d10e..0a783fcd 100644 --- a/src/Mapper/MappedErrorTemplate.php +++ b/src/Mapper/MappedErrorTemplate.php @@ -21,7 +21,6 @@ public function __construct( public string $severity, public ?string $validatorName, public ?string $documentationLink, - public ?string $missingProperty = null, ) { } } diff --git a/src/Mapper/MappedProperty.php b/src/Mapper/MappedProperty.php index b31b295c..d5ca38e8 100644 --- a/src/Mapper/MappedProperty.php +++ b/src/Mapper/MappedProperty.php @@ -151,11 +151,6 @@ public function addError(MappedError $error): void $this->errors[] = $error; } - public function removeError(MappedError $error): void - { - $this->errors = array_values(array_filter($this->errors, static fn (MappedError $candidate): bool => $candidate !== $error)); - } - /** * @return array */ diff --git a/src/Mapper/MappedType.php b/src/Mapper/MappedType.php index 90b1bbad..3f17e557 100644 --- a/src/Mapper/MappedType.php +++ b/src/Mapper/MappedType.php @@ -211,12 +211,6 @@ public function addError(MappedError $error): void } } - public function removeError(MappedError $error): void - { - $this->errors = array_values(array_filter($this->errors, static fn (MappedError $candidate): bool => $candidate !== $error)); - $this->mergedErrors = null; - } - public function addChildrenError(MappedError $error): void { $this->childrenErrors[] = $error; @@ -226,12 +220,6 @@ public function addChildrenError(MappedError $error): void } } - public function removeChildrenError(MappedError $error): void - { - $this->childrenErrors = array_values(array_filter($this->childrenErrors, static fn (MappedError $candidate): bool => $candidate !== $error)); - $this->mergedErrors = null; - } - /** * @return array */ diff --git a/src/Mapper/MappedTypeMerger.php b/src/Mapper/MappedTypeMerger.php index 9cd406a1..41765798 100644 --- a/src/Mapper/MappedTypeMerger.php +++ b/src/Mapper/MappedTypeMerger.php @@ -15,24 +15,44 @@ use JoliCode\StructuredData\JsonLd\Algorithms\JsonLd\Keyword; /** - * Reconciles the structured data blocks of a document that describe the same - * node. + * Merges the structured data blocks of a document that describe the same node. * * Google reads a page as one graph: the blocks sharing an identifier (a JSON-LD * "@id", a microdata "itemid") are one node holding the union of their * properties, whatever their format, and a property one block omits is not - * missing when another block provides it. The blocks are still audited one by - * one, with their positions in the document; the merged node only tells which - * of their "missing property" issues Google would not report. + * missing when another block provides it. The merged node is a fresh tree, to be + * validated apart: the blocks themselves are left untouched, with their own + * audit and positions. * - * @phpstan-type Conflict array{key: string, properties: list, values: list} + * @phpstan-type Conflict array{key: string, property: MappedProperty, values: list} */ final class MappedTypeMerger { /** - * Groups the types describing the same node: the ones sharing an absolute - * identifier. Blank node identifiers are local to their block and never - * merge. + * The validator name of the warnings raised on a merged node, when its + * blocks disagree on a value. + */ + public const VALIDATOR_NAME = 'Merge'; + + /** + * The identifier under which a type merges with the others: its absolute + * "@id". Blank node identifiers are local to their block and never merge. + * Identifiers are compared as they are written. + */ + public static function identifierOf(MappedType $type): ?string + { + $identifier = $type->getProperty(Keyword::ID->value)?->getValue(); + + if (!\is_string($identifier) || IriResolver::isBlankNodeIdentifier($identifier) || !IriResolver::isAbsoluteIri($identifier)) { + return null; + } + + return $identifier; + } + + /** + * Groups the types describing the same node: the ones sharing an identifier + * (see identifierOf()). * * @param array $types * @@ -43,13 +63,9 @@ public static function groupByIdentifier(array $types): array $groups = []; foreach ($types as $type) { - $identifier = $type->getProperty(Keyword::ID->value)?->getValue(); - - if (!\is_string($identifier) || IriResolver::isBlankNodeIdentifier($identifier) || !IriResolver::isAbsoluteIri($identifier)) { - continue; + if (null !== $identifier = self::identifierOf($type)) { + $groups[$identifier][] = $type; } - - $groups[$identifier][] = $type; } return array_filter($groups, static fn (array $group): bool => isset($group[1])); @@ -57,17 +73,28 @@ public static function groupByIdentifier(array $types): array /** * Builds the node Google sees: a fresh type, free of any error, holding the - * union of the members' types and properties. Equal scalar values are kept - * once, nested nodes are all kept, as in a graph. + * union of the members' types and properties, and the positions of every + * member. Equal scalar values are kept once, nested nodes are all kept, as + * in a graph. * * @param list $members * - * @return array{type: MappedType, conflicts: list} + * @return array{type: MappedType, conflicts: list} the merged node, and its properties holding a different scalar value in several members */ public static function merge(array $members): array { $merged = new MappedType(sourceFormat: $members[0]->getSourceFormat(), type: self::unionOfTypes($members)); + foreach ($members as $member) { + foreach ($member->getKeyRanges() as $range) { + $merged->addKeyRange($range); + } + + foreach ($member->getValueRanges() as $range) { + $merged->addValueRange($range); + } + } + /** @var array> $sources */ $sources = []; @@ -116,7 +143,7 @@ public static function merge(array $members): array $merged->setProperty($key, $property); if (isset($scalars[1]) && '@' !== $key[0]) { - $conflicts[] = ['key' => $key, 'properties' => $properties, 'values' => $scalars]; + $conflicts[] = ['key' => $key, 'property' => $property, 'values' => $scalars]; } } @@ -124,40 +151,43 @@ public static function merge(array $members): array } /** - * Withdraws, from the members, the "missing property" issues the merged node - * does not have: another block provides what they report missing. The - * members' validity and severities are recomputed afterwards. - * - * @param list $members + * Raises a warning on each property of the merged node whose members + * disagree on the value. Google keeps every value and reports nothing, so + * the warning carries its own validator name, outside the Google verdict. + * It does not make the node invalid. * - * @return list the withdrawn issues + * @param list $conflicts as returned by merge() + * @param int $members the number of blocks merged into the node */ - public static function withdrawIssuesResolvedBy(MappedType $merged, array $members): array + public static function reportConflicts(string $identifier, int $members, array $conflicts): void { - $remaining = []; - - foreach ($merged->getMergedErrors() as $error) { - if (null !== $error->getMissingProperty()) { - $remaining[self::issueKey($error)] = true; - } - } - - $withdrawn = []; - - foreach ($members as $member) { - foreach ($member->getMergedErrors() as $error) { - if (null === $error->getMissingProperty() || isset($remaining[self::issueKey($error)])) { - continue; - } - - self::withdraw($member, $error); - $withdrawn[] = $error; + foreach ($conflicts as $conflict) { + $property = $conflict['property']; + $owner = $property->getOwnerType(); + + $error = new MappedError( + message: \sprintf( + 'The %d blocks describing "%s" give it different values (%s): Google merges them and keeps every value.', + $members, + $identifier, + implode(', ', array_map(static fn (mixed $value): string => json_encode($value, \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE) ?: '', $conflict['values'])), + ), + property: $conflict['key'], + type: MappedErrorFormatter::formatTypeLabel($owner?->getType()), + severity: MappedError::SEVERITY_WARNING, + validatorName: self::VALIDATOR_NAME, + ranges: MappedErrorFormatter::formatRanges($property->getValueRanges()), + parent: $property, + ); + + $property->addError($error); + $property->setErrorSeverity($property->getErrorSeverity() ?? MappedError::SEVERITY_WARNING); + + if (null !== $owner) { + $owner->addChildrenError($error); + $owner->setErrorSeverity($owner->getErrorSeverity() ?? MappedError::SEVERITY_WARNING); } - - self::recompute($member); } - - return $withdrawn; } /** @@ -262,91 +292,4 @@ private static function copyValue(mixed $value, MappedType $owner, MappedPropert return $value; } - - /** - * What makes two "missing property" issues the same across the members and - * the merged node: where in the node they are (relative to the root, whose - * label may differ), what is missing, and how badly. - */ - private static function issueKey(MappedError $error): string - { - $target = $error->getParent(); - $path = $target instanceof MappedType && null === $target->getParentProperty() - ? '' - : ($target?->getPath() ?? ''); - - return $path . '|' . $error->getMissingProperty() . '|' . $error->getSeverity(); - } - - /** - * Removes the error from the whole tree of the type: the error of a - * multi-typed entry is raised on a short-lived clone and copied onto the - * entry, so its own parent cannot be trusted to find where it is held. - */ - private static function withdraw(MappedType $type, MappedError $error): void - { - $type->removeError($error); - $type->removeChildrenError($error); - - foreach ($type->getProperties() as $property) { - $property->removeError($error); - - foreach (self::valuesOf($property) as $value) { - if ($value instanceof MappedType) { - self::withdraw($value, $error); - } - } - } - } - - /** - * Recomputes the validity and severity of a type tree from the errors it - * still holds: a type is valid when it has no error of its own and its - * nested types are valid, and carries the highest severity found on it or - * below it. - */ - private static function recompute(MappedType $type): bool - { - $valid = [] === $type->getErrors(); - - foreach ($type->getProperties() as $property) { - $propertyValid = [] === $property->getErrors(); - $property->setErrorSeverity(self::highestSeverity($property->getErrors())); - - foreach (self::valuesOf($property) as $value) { - if ($value instanceof MappedType && !self::recompute($value)) { - $propertyValid = false; - } - } - - $property->setIsValid($propertyValid); - - if (!$propertyValid) { - $valid = false; - } - } - - $type->setIsValid($valid); - $type->setErrorSeverity(self::highestSeverity($type->getMergedErrors())); - - return $valid; - } - - /** - * @param array $errors - */ - private static function highestSeverity(array $errors): ?string - { - $severity = null; - - foreach ($errors as $error) { - if (MappedError::SEVERITY_ERROR === $error->getSeverity()) { - return MappedError::SEVERITY_ERROR; - } - - $severity = $error->getSeverity(); - } - - return $severity; - } } diff --git a/src/Mapper/ValidationSnippetTemplateApplier.php b/src/Mapper/ValidationSnippetTemplateApplier.php index ee2a6a0c..2ed6af5a 100644 --- a/src/Mapper/ValidationSnippetTemplateApplier.php +++ b/src/Mapper/ValidationSnippetTemplateApplier.php @@ -92,7 +92,6 @@ private static function replayMappedError(MappedType|MappedProperty $target, Map ranges: MappedErrorFormatter::formatRanges($target->getValueRanges()), parent: $target, documentationLink: $errorTemplate->documentationLink, - missingProperty: $errorTemplate->missingProperty, ); $target->addError($error); diff --git a/src/Mapper/ValidationSnippetTemplateBuilder.php b/src/Mapper/ValidationSnippetTemplateBuilder.php index 19058177..84f44885 100644 --- a/src/Mapper/ValidationSnippetTemplateBuilder.php +++ b/src/Mapper/ValidationSnippetTemplateBuilder.php @@ -94,7 +94,6 @@ private static function buildErrorTemplates(array $errors): array severity: $error->getSeverity(), validatorName: $error->getValidatorName(), documentationLink: $error->getDocumentationLink(), - missingProperty: $error->getMissingProperty(), ); } diff --git a/src/Validator.php b/src/Validator.php index f51711f4..6b85639d 100644 --- a/src/Validator.php +++ b/src/Validator.php @@ -12,6 +12,7 @@ namespace JoliCode\StructuredData; use JoliCode\StructuredData\Audit\Audit; +use JoliCode\StructuredData\Audit\Item; use JoliCode\StructuredData\Extraction\Extractor; use JoliCode\StructuredData\Extraction\ExtractorFormat; use JoliCode\StructuredData\Extraction\JsonLdElement; @@ -25,9 +26,7 @@ use JoliCode\StructuredData\JsonLd\Parser\JsonLdParser; use JoliCode\StructuredData\Mapper\DocumentError; use JoliCode\StructuredData\Mapper\DocumentIssueInterface; -use JoliCode\StructuredData\Mapper\DocumentWarning; use JoliCode\StructuredData\Mapper\MappedError; -use JoliCode\StructuredData\Mapper\MappedErrorFormatter; use JoliCode\StructuredData\Mapper\MappedProperty; use JoliCode\StructuredData\Mapper\MappedType; use JoliCode\StructuredData\Mapper\MappedTypeMerger; @@ -110,15 +109,26 @@ public function setValidator(string $validator): void * Deciding what may be fetched, and under which restrictions, belongs to the * application - see the "Accepted inputs" section of the README. * - * @param bool $reportPendingVocabularyUsage Terms hosted under - * pending.schema.org are still - * under development and may change - * or be removed. Using them is - * accepted silently by default; - * pass true to report each usage - * as a warning. + * @param bool $reportPendingVocabularyUsage Terms hosted under + * pending.schema.org are still + * under development and may change + * or be removed. Using them is + * accepted silently by default; + * pass true to report each usage + * as a warning. + * @param bool $mergeNodesSharingAnIdentifier The blocks sharing an + * identifier (a JSON-LD "@id", + * a microdata "itemid") + * describe one node, as Google + * reads them: by default, they + * make one item of the audit, + * validated as a whole. Pass + * false to audit every block on + * its own. See the "Blocks + * describing the same node" + * section of the README. */ - public function audit(string $document, bool $reportPendingVocabularyUsage = false): Audit + public function audit(string $document, bool $reportPendingVocabularyUsage = false, bool $mergeNodesSharingAnIdentifier = true): Audit { $this->validationMapper->reset(); @@ -241,60 +251,61 @@ public function audit(string $document, bool $reportPendingVocabularyUsage = fal } } - $documentIssues = $this->mapDocumentIssuesToMappedErrors([ - ...$documentIssues, - ...$this->reconcileTypesSharingAnIdentifier($types), - ]); - - return new Audit($types, $documentIssues); + return new Audit( + $types, + $this->mapDocumentIssuesToMappedErrors($documentIssues), + $mergeNodesSharingAnIdentifier ? $this->buildMergedItems($types) : null, + ); } /** * Google reads the page as one graph: the blocks sharing an identifier are one * node, whatever their format, and a property one block omits is not missing - * when another block provides it. Each block keeps its own audit and - * positions; the node Google sees is validated apart, and the "missing - * property" issues it does not have are withdrawn from the blocks. + * when another block provides it. Such blocks make one item, whose node is + * built and validated apart; each block keeps its own audit and positions. + * The other blocks are items of their own, in document order. * * Google keeps every value when the blocks disagree on one, and reports - * nothing: the disagreement is reported as a document warning, outside the + * nothing: the disagreement is a warning of the merged node, outside the * Google verdict. * + * The merged nodes are rebuilt on each call, after the snippet cache is + * replayed, so the cache does not depend on this option. + * * @param array $types * - * @return list + * @return list */ - private function reconcileTypesSharingAnIdentifier(array $types): array + private function buildMergedItems(array $types): array { - $issues = []; + $groups = MappedTypeMerger::groupByIdentifier($types); + $items = []; - foreach (MappedTypeMerger::groupByIdentifier($types) as $identifier => $members) { - $merged = MappedTypeMerger::merge($members); + foreach ($types as $type) { + $identifier = MappedTypeMerger::identifierOf($type); - $this->validateType($merged['type']); - MappedTypeMerger::withdrawIssuesResolvedBy($merged['type'], $members); - - foreach ($merged['conflicts'] as $conflict) { - $ranges = array_map( - static fn (MappedProperty $property): string => MappedErrorFormatter::formatRanges($property->getValueRanges()), - $conflict['properties'], - ); - - $issues[] = new DocumentWarning( - 'Document', - \sprintf( - 'The "%s" of "%s" has a different value in each of the %d blocks describing it (%s): Google merges them and keeps every value.', - $conflict['key'], - $identifier, - \count($conflict['properties']), - implode(', ', array_map(static fn (mixed $value): string => json_encode($value, \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE) ?: '', $conflict['values'])), - ), - implode(', ', array_filter($ranges)), - ); + if (null === $identifier || !isset($groups[$identifier])) { + $items[] = new Item($type, [$type], $identifier); + + continue; } + + // The group was turned into an item at its first block. + if ([] === $groups[$identifier]) { + continue; + } + + $members = $groups[$identifier]; + $groups[$identifier] = []; + + $merged = MappedTypeMerger::merge($members); + $this->validateType($merged['type']); + MappedTypeMerger::reportConflicts($identifier, \count($members), $merged['conflicts']); + + $items[] = new Item($merged['type'], $members, $identifier); } - return $issues; + return $items; } /** diff --git a/src/Vocabularies/Validators/AbstractValidator.php b/src/Vocabularies/Validators/AbstractValidator.php index c10a93a8..1a96702a 100644 --- a/src/Vocabularies/Validators/AbstractValidator.php +++ b/src/Vocabularies/Validators/AbstractValidator.php @@ -99,7 +99,7 @@ protected function validatePropertyCasing(MappedType $type, MappedProperty $prop ]; } - protected function addMappedError(MappedType|MappedProperty $target, string $message, MappedType $typeWithError, string $severity, ?string $documentationLink = null, ?string $missingProperty = null): MappedError + protected function addMappedError(MappedType|MappedProperty $target, string $message, MappedType $typeWithError, string $severity, ?string $documentationLink = null): MappedError { $typeLabel = MappedErrorFormatter::formatTypeLabel($typeWithError->getType()); $range = MappedErrorFormatter::formatRanges($target->getValueRanges()); @@ -113,7 +113,6 @@ protected function addMappedError(MappedType|MappedProperty $target, string $mes $range, parent: $target, documentationLink: $documentationLink, - missingProperty: $missingProperty, ); $target->addError($error); diff --git a/src/Vocabularies/Validators/Google/GoogleValidator.php b/src/Vocabularies/Validators/Google/GoogleValidator.php index 2a657142..3a8a471a 100644 --- a/src/Vocabularies/Validators/Google/GoogleValidator.php +++ b/src/Vocabularies/Validators/Google/GoogleValidator.php @@ -310,14 +310,13 @@ private function validateRequiredProperty(MappedType $type, array $missingProper $expectedProperties = $missingProperty['value'] ?? []; if (!$this->hasAnyPropertyKey($type, $expectedProperties)) { - $alternatives = implode(', ', array_keys($expectedProperties)); $message = \sprintf( 'Missing required property: at least one of the following properties must be present "%s" for the type "%s"', - $alternatives, + implode(', ', array_keys($expectedProperties)), $this->getTypeLabel($type), ); - $errors[] = $this->addMappedError($type, $message, $type, MappedError::SEVERITY_ERROR, $this->resolveDocumentationLink($missingProperty), $alternatives); + $errors[] = $this->addMappedError($type, $message, $type, MappedError::SEVERITY_ERROR, $this->resolveDocumentationLink($missingProperty)); } return; @@ -325,7 +324,7 @@ private function validateRequiredProperty(MappedType $type, array $missingProper $message = \sprintf('Missing required property: "%s" for the type "%s"', $missingProperty['name'], $this->getTypeLabel($type)); - $errors[] = $this->addMappedError($type, $message, $type, MappedError::SEVERITY_ERROR, $this->resolveDocumentationLink($missingProperty), $missingProperty['name']); + $errors[] = $this->addMappedError($type, $message, $type, MappedError::SEVERITY_ERROR, $this->resolveDocumentationLink($missingProperty)); } /** @@ -342,13 +341,12 @@ private function validateRecommendedProperty(MappedType $type, array $missingPro $expectedProperties = $missingProperty['value'] ?? []; if (!$this->hasAnyPropertyKey($type, $expectedProperties)) { - $alternatives = implode(', ', array_keys($expectedProperties)); $message = \sprintf( 'Missing recommended property: at least one of the following properties should be present "%s"', - $alternatives, + implode(', ', array_keys($expectedProperties)), ); - $errors[] = $this->addMappedError($type, $message, $type, MappedError::SEVERITY_WARNING, $this->resolveDocumentationLink($missingProperty), $alternatives); + $errors[] = $this->addMappedError($type, $message, $type, MappedError::SEVERITY_WARNING, $this->resolveDocumentationLink($missingProperty)); } return; @@ -356,7 +354,7 @@ private function validateRecommendedProperty(MappedType $type, array $missingPro $message = \sprintf('Missing recommended property: "%s" for the type "%s"', $missingProperty['name'], $this->getTypeLabel($type)); - $errors[] = $this->addMappedError($type, $message, $type, MappedError::SEVERITY_WARNING, $this->resolveDocumentationLink($missingProperty), $missingProperty['name']); + $errors[] = $this->addMappedError($type, $message, $type, MappedError::SEVERITY_WARNING, $this->resolveDocumentationLink($missingProperty)); } /** diff --git a/tests/Validation/SharedIdentifierTest.php b/tests/Validation/SharedIdentifierTest.php index 73c22e1f..45ef8108 100644 --- a/tests/Validation/SharedIdentifierTest.php +++ b/tests/Validation/SharedIdentifierTest.php @@ -11,7 +11,9 @@ namespace JoliCode\StructuredData\Tests\Validation; +use JoliCode\StructuredData\Audit\Audit; use JoliCode\StructuredData\Audit\AuditOptions; +use JoliCode\StructuredData\Mapper\MappedError; use JoliCode\StructuredData\Mapper\MappedProperty; use JoliCode\StructuredData\Mapper\MappedType; use JoliCode\StructuredData\Mapper\MappedTypeMerger; @@ -21,76 +23,144 @@ /** * The blocks of a document sharing an identifier describe one node for Google: - * a property one block omits is not missing when another block provides it. + * by default, they make one item of the audit, validated as a whole, and a + * property one block omits is not missing when another block provides it. */ class SharedIdentifierTest extends TestCase { private const FIXTURE = __DIR__ . '/fixtures/google/event-two-blocks-same-id.html'; + private const CONFLICTING_FIXTURE = __DIR__ . '/fixtures/google/event-two-blocks-same-id-conflicting-values.html'; + private const IDENTIFIER = 'https://example.com/events/symfonylive-2026'; - public function testAPropertyProvidedByAnotherBlockIsNotMissing(): void + public function testTheBlocksSharingAnIdentifierMakeOneItem(): void { - $validator = new Validator(); - $validator->setValidator(GoogleValidator::class); + $audit = $this->audit(self::FIXTURE); + + $this->assertCount(2, $audit->getTypes()); + $this->assertCount(1, $audit->getItems()); + + $item = $audit->getItems()[0]; + $this->assertTrue($item->isMerged()); + $this->assertSame(self::IDENTIFIER, $item->getIdentifier()); + $this->assertSame($audit->getTypes(), $item->getSources()); + $this->assertSame(['jsonld', 'microdata'], array_map(static fn (MappedType $source): string => $source->getSourceFormat(), $item->getSources())); + + // The merged node holds the union of the properties. + foreach (['name', 'description', 'location', 'startDate', 'endDate', 'image'] as $key) { + $this->assertTrue($item->getType()->hasProperty($key), \sprintf('The merged node lacks "%s".', $key)); + } + } - $audit = $validator->audit((string) file_get_contents(self::FIXTURE)); + public function testAPropertyProvidedByAnotherBlockIsNotMissing(): void + { + $audit = $this->audit(self::FIXTURE); $this->assertTrue($audit->isValid()); $this->assertSame([], $audit->getDiagnostic(new AuditOptions(severity: AuditOptions::SEVERITY_ERROR))); - // What no block provides is still reported, by each block. - /** @var list $warnings */ - $warnings = $audit->getDiagnostic(new AuditOptions(severity: AuditOptions::SEVERITY_WARNING)); - $this->assertCount(8, $warnings); - $this->assertCount(2, array_filter($warnings, static fn (string $message): bool => str_contains($message, '"offers"'))); - $this->assertSame([], array_filter($warnings, static fn (string $message): bool => str_contains($message, '"image"') || str_contains($message, '"description"'))); + // What no block provides is reported once, for the node, with the + // positions of both blocks. + /** @var list $warnings */ + $warnings = $audit->getDiagnostic(new AuditOptions(severity: AuditOptions::SEVERITY_WARNING, asObject: true)); + $this->assertCount(4, $warnings); + $this->assertCount(1, array_filter($warnings, static fn (MappedError $warning): bool => str_contains($warning->getMessage(), '"offers"'))); + $this->assertSame([], array_filter($warnings, static fn (MappedError $warning): bool => str_contains($warning->getMessage(), '"image"') || str_contains($warning->getMessage(), '"description"'))); + $this->assertCount(2, explode(\PHP_EOL, $warnings[0]->getRanges())); + } + + public function testTheSourcesKeepTheirOwnAudit(): void + { + $sources = $this->audit(self::FIXTURE)->getItems()[0]->getSources(); + + // Alone, the JSON-LD block lacks its dates and the microdata one its location. + $this->assertSame('error', $sources[0]->getErrorSeverity()); + $this->assertSame(['startDate', 'endDate'], $this->missingRequiredProperties($sources[0])); + $this->assertSame(['location'], $this->missingRequiredProperties($sources[1])); + } + + public function testDisablingTheMergeAuditsEveryBlockOnItsOwn(): void + { + $audit = $this->audit(self::FIXTURE, merge: false); + + $this->assertCount(2, $audit->getItems()); - // The withdrawn errors no longer weigh on the blocks' severity. - foreach ($audit->getTypes() as $type) { - $this->assertSame('warning', $type->getErrorSeverity()); + foreach ($audit->getItems() as $index => $item) { + $this->assertFalse($item->isMerged()); + $this->assertSame(self::IDENTIFIER, $item->getIdentifier()); + $this->assertSame([$audit->getTypes()[$index]], $item->getSources()); + $this->assertSame($audit->getTypes()[$index], $item->getType()); } + + $this->assertFalse($audit->isValid()); + $this->assertCount(3, (array) $audit->getDiagnostic(new AuditOptions(severity: AuditOptions::SEVERITY_ERROR))); + $this->assertCount(10, (array) $audit->getDiagnostic(new AuditOptions(severity: AuditOptions::SEVERITY_WARNING))); + + // No merged node, so no disagreement to report either. + $conflicting = $this->audit(self::CONFLICTING_FIXTURE, merge: false); + $this->assertSame([], $conflicting->getDiagnostic(new AuditOptions(validator: AuditOptions::VALIDATOR_MERGE))); + $this->assertSame([], $conflicting->getDiagnostic(new AuditOptions(severity: AuditOptions::SEVERITY_DOCUMENT))); } - public function testTheReconciliationSurvivesTheSnippetCache(): void + public function testTheMergeSurvivesTheSnippetCache(): void { - $validator = new Validator(); - $validator->setValidator(GoogleValidator::class); - $document = (string) file_get_contents(self::FIXTURE); + $validator = $this->createValidator(); + $document = (string) file_get_contents(self::CONFLICTING_FIXTURE); - /** @var list $first */ - $first = $validator->audit($document)->getDiagnostic(); - /** @var list $second */ - $second = $validator->audit($document)->getDiagnostic(); + $first = $validator->audit($document); + $second = $validator->audit($document); - $this->assertCount(8, $first); - $this->assertSame($first, $second); + $this->assertCount(6, (array) $first->getDiagnostic()); + $this->assertSame($first->getDiagnostic(), $second->getDiagnostic()); + $this->assertNotSame($first->getItems()[0]->getType(), $second->getItems()[0]->getType()); } - public function testDisagreeingValuesAreReportedAsADocumentWarningOnly(): void + public function testOneValidatorCanAlternateBetweenBothModes(): void { - $validator = new Validator(); - $validator->setValidator(GoogleValidator::class); + $merged = $this->diagnose($this->createValidator(), self::FIXTURE, true); + $unmerged = $this->diagnose($this->createValidator(), self::FIXTURE, false); + $this->assertNotSame($merged, $unmerged); + + $worker = $this->createValidator(); + + foreach ([true, false, true, false, true] as $round => $merge) { + $this->assertSame( + $merge ? $merged : $unmerged, + $this->diagnose($worker, self::FIXTURE, $merge), + \sprintf('Round %d (%s) drifted from a fresh validator.', $round, $merge ? 'merged' : 'unmerged'), + ); + } + } - $audit = $validator->audit((string) file_get_contents(__DIR__ . '/fixtures/google/event-two-blocks-same-id-conflicting-values.html')); + public function testDisagreeingValuesAreAWarningOfTheMergedItem(): void + { + $audit = $this->audit(self::CONFLICTING_FIXTURE); $this->assertTrue($audit->isValid()); + $this->assertSame([], $audit->getDiagnostic(new AuditOptions(severity: AuditOptions::SEVERITY_DOCUMENT))); - /** @var list $documentIssues */ - $documentIssues = $audit->getDiagnostic(new AuditOptions(severity: AuditOptions::SEVERITY_DOCUMENT)); - $this->assertCount(2, $documentIssues); - $this->assertStringContainsString('The "description" of "https://example.com/events/symfonylive-2026" has a different value in each of the 2 blocks', $documentIssues[0]); - $this->assertStringContainsString('"startDate"', $documentIssues[1]); + /** @var list $conflicts */ + $conflicts = $audit->getDiagnostic(new AuditOptions(validator: AuditOptions::VALIDATOR_MERGE, asObject: true)); + $this->assertCount(2, $conflicts); + $this->assertSame(['description', 'startDate'], array_map(static fn (MappedError $conflict): ?string => $conflict->getProperty(), $conflicts)); + $this->assertSame(MappedError::SEVERITY_WARNING, $conflicts[0]->getSeverity()); + $this->assertStringContainsString('The 2 blocks describing "' . self::IDENTIFIER . '" give it different values ("Two days of talks about the Symfony framework.", "Another description")', $conflicts[0]->getMessage()); + $this->assertCount(2, explode(\PHP_EOL, $conflicts[0]->getRanges())); + + // The warnings belong to the merged node, not to the blocks. + $this->assertContains($conflicts[0], $audit->getItems()[0]->getType()->getMergedErrors()); + + foreach ($audit->getTypes() as $source) { + $this->assertNotContains($conflicts[0], $source->getMergedErrors()); + } // Google reports nothing about it: the Google diagnostics stay the same. /** @var list $googleMessages */ $googleMessages = $audit->getDiagnostic(new AuditOptions(validator: AuditOptions::VALIDATOR_GOOGLE)); - $this->assertSame([], array_filter($googleMessages, static fn (string $message): bool => str_contains($message, 'different value'))); + $this->assertSame([], array_filter($googleMessages, static fn (string $message): bool => str_contains($message, 'different values'))); } public function testBlocksWithDifferentOrBlankIdentifiersAreNotMerged(): void { - $validator = new Validator(); - $validator->setValidator(GoogleValidator::class); - $document = <<<'HTML' + HTML; + $validator = $this->createValidator(); $audit = $validator->audit($document); + $this->assertCount(3, $audit->getItems()); + $this->assertSame([null, null, 'https://example.com/other'], array_map(static fn ($item): ?string => $item->getIdentifier(), $audit->getItems())); $this->assertFalse($audit->isValid()); - /** @var list $errors */ - $errors = $audit->getDiagnostic(new AuditOptions(severity: AuditOptions::SEVERITY_ERROR)); - $this->assertCount(3, $errors); + $this->assertCount(3, (array) $audit->getDiagnostic(new AuditOptions(severity: AuditOptions::SEVERITY_ERROR))); } public function testGroupingIgnoresTypesWithoutAnAbsoluteIdentifier(): void @@ -133,4 +207,46 @@ public function testGroupingIgnoresTypesWithoutAnAbsoluteIdentifier(): void $this->assertSame(['https://example.com/a'], array_keys($groups)); $this->assertCount(2, $groups['https://example.com/a']); } + + private function createValidator(): Validator + { + $validator = new Validator(); + $validator->setValidator(GoogleValidator::class); + + return $validator; + } + + private function audit(string $fixture, bool $merge = true): Audit + { + return $this->createValidator()->audit((string) file_get_contents($fixture), mergeNodesSharingAnIdentifier: $merge); + } + + /** + * @return array{bool, int, array} + */ + private function diagnose(Validator $validator, string $fixture, bool $merge): array + { + $audit = $validator->audit((string) file_get_contents($fixture), mergeNodesSharingAnIdentifier: $merge); + + /** @var array $messages */ + $messages = $audit->getDiagnostic(); + + return [$audit->isValid(), \count($audit->getItems()), $messages]; + } + + /** + * @return list + */ + private function missingRequiredProperties(MappedType $type): array + { + $missing = []; + + foreach ($type->getMergedErrors() as $error) { + if (MappedError::SEVERITY_ERROR === $error->getSeverity() && preg_match('/^Missing required property: "([^"]+)"/', $error->getMessage(), $matches)) { + $missing[] = $matches[1]; + } + } + + return $missing; + } } diff --git a/tests/Validation/fixtures/google-baseline.json b/tests/Validation/fixtures/google-baseline.json index 5921e8b5..2059e98e 100644 --- a/tests/Validation/fixtures/google-baseline.json +++ b/tests/Validation/fixtures/google-baseline.json @@ -294,25 +294,14 @@ "[Google warning] Event: Missing recommended property: \"offers\" for the type \"Event\"", "[Google warning] Event: Missing recommended property: \"organizer\" for the type \"Event\"", "[Google warning] Event: Missing recommended property: \"performer\" for the type \"Event\"", - "[Google warning] Event: Missing recommended property: \"eventStatus\" for the type \"Event\"", - "[Google warning] Event: Missing recommended property: \"offers\" for the type \"Event\"", - "[Google warning] Event: Missing recommended property: \"organizer\" for the type \"Event\"", - "[Google warning] Event: Missing recommended property: \"performer\" for the type \"Event\"", - "[Document warning] The \"description\" of \"https:\/\/example.com\/events\/symfonylive-2026\" has a different value in each of the 2 blocks describing it (\"Two days of talks about the Symfony framework.\", \"Another description\"): Google merges them and keeps every value.", - "[Document warning] The \"startDate\" of \"https:\/\/example.com\/events\/symfonylive-2026\" has a different value in each of the 2 blocks describing it (\"2026-03-22T08:55:00+01:00\", \"2026-03-26T09:00:00+01:00\"): Google merges them and keeps every value." + "[Merge warning] description: The 2 blocks describing \"https:\/\/example.com\/events\/symfonylive-2026\" give it different values (\"Two days of talks about the Symfony framework.\", \"Another description\"): Google merges them and keeps every value.", + "[Merge warning] startDate: The 2 blocks describing \"https:\/\/example.com\/events\/symfonylive-2026\" give it different values (\"2026-03-22T08:55:00+01:00\", \"2026-03-26T09:00:00+01:00\"): Google merges them and keeps every value." ], - "documentIssues": [ - "[Document warning] The \"description\" of \"https:\/\/example.com\/events\/symfonylive-2026\" has a different value in each of the 2 blocks describing it (\"Two days of talks about the Symfony framework.\", \"Another description\"): Google merges them and keeps every value.", - "[Document warning] The \"startDate\" of \"https:\/\/example.com\/events\/symfonylive-2026\" has a different value in each of the 2 blocks describing it (\"2026-03-22T08:55:00+01:00\", \"2026-03-26T09:00:00+01:00\"): Google merges them and keeps every value." - ] + "documentIssues": [] }, "event-two-blocks-same-id.html": { "errors": [], "warnings": [ - "[Google warning] Event: Missing recommended property: \"eventStatus\" for the type \"Event\"", - "[Google warning] Event: Missing recommended property: \"offers\" for the type \"Event\"", - "[Google warning] Event: Missing recommended property: \"organizer\" for the type \"Event\"", - "[Google warning] Event: Missing recommended property: \"performer\" for the type \"Event\"", "[Google warning] Event: Missing recommended property: \"eventStatus\" for the type \"Event\"", "[Google warning] Event: Missing recommended property: \"offers\" for the type \"Event\"", "[Google warning] Event: Missing recommended property: \"organizer\" for the type \"Event\"", @@ -808,7 +797,7 @@ }, "softwareapplication-price-with-currency-symbol.jsonld": { "errors": [ - "[Google error] offers.price: Incorrect number format: \"1 800,00 €\" given. Google expects a plain number, without currency symbol, thousands separator or unit: \"1800.00\"." + "[Google error] offers.price: Incorrect number format: \"1 800,00 \u20ac\" given. Google expects a plain number, without currency symbol, thousands separator or unit: \"1800.00\"." ], "warnings": [], "documentIssues": [] From 97ee63791e20c5a5d9cc8d66216fbeba527074ab Mon Sep 17 00:00:00 2001 From: Xavier Lacot Date: Fri, 13 Nov 2026 18:17:10 +0100 Subject: [PATCH 2/2] Make the baseline task audit the fixtures as the tests do and sort its output --- .castor/qa.php | 16 ++++- resources/schema.org/examples-baseline.json | 64 +++++++++---------- .../Validation/fixtures/google-baseline.json | 32 +++++----- 3 files changed, 62 insertions(+), 50 deletions(-) diff --git a/.castor/qa.php b/.castor/qa.php index 760383c9..2b439908 100644 --- a/.castor/qa.php +++ b/.castor/qa.php @@ -25,6 +25,7 @@ use JoliCode\StructuredData\Audit\AuditOptions; use JoliCode\StructuredData\JsonLd\Algorithms; use JoliCode\StructuredData\Tests\Validation\Benchmark\WorkerValidationBench; +use JoliCode\StructuredData\Tests\Validation\SnapshotDocumentLoader; use JoliCode\StructuredData\Validator; use JoliCode\StructuredData\Vocabularies\Generators\Google\Filesystem as GoogleFilesystem; use JoliCode\StructuredData\Vocabularies\Generators\SchemaOrg\Filesystem as SchemaOrgFilesystem; @@ -500,12 +501,17 @@ function updateBaseline( string $baselinePath, ): void { $finder = finder()->files()->in($path)->sortByName(); - $validator = new Validator(); + // Resolve the remote contexts as the tests do, from the committed snapshots: + // the default loader refuses every host. + $validator = new Validator(documentLoader: new SnapshotDocumentLoader()); $validator->setValidator($specificValidator); $baseline = []; foreach ($finder as $file) { - $audit = $validator->audit($file->getContents()); + // Audit as the tests do: the baselines also record the usages of the + // pending.schema.org vocabulary (this option only affects the schema.org + // validator). + $audit = $validator->audit($file->getContents(), reportPendingVocabularyUsage: true); /** @var array $documentIssues */ $documentIssues = $audit->getDiagnostic(new AuditOptions( severity: AuditOptions::SEVERITY_DOCUMENT, @@ -522,6 +528,12 @@ function updateBaseline( // A document issue is an error or a warning too, and the tests compare the // errors and the warnings as the audit reports them, document issues // included: the baseline lists it on both sides. + // The tests compare sorted lists: sorting here keeps the files stable, so a + // regeneration only shows the diagnostics that actually changed. + sort($errorMessages); + sort($warningMessages); + sort($documentIssues); + $baseline[$file->getFilename()] = [ 'errors' => $errorMessages, 'warnings' => $warningMessages, diff --git a/resources/schema.org/examples-baseline.json b/resources/schema.org/examples-baseline.json index 3acf8b4a..2c6056f3 100644 --- a/resources/schema.org/examples-baseline.json +++ b/resources/schema.org/examples-baseline.json @@ -720,8 +720,8 @@ "https-schema-org-59c32bead52f72f8200c0f13cada56f9.jsonld": { "errors": [], "warnings": [ - "[SchemaOrg warning] hasOccupation.hasOccupation.occupationalCategory: The \"occupationalCategory\" property is part of the pending.schema.org extension: it is still under development and subject to change.", - "[SchemaOrg warning] hasOccupation.educationRequirements: The \"educationRequirements\" property is part of the pending.schema.org extension: it is still under development and subject to change." + "[SchemaOrg warning] hasOccupation.educationRequirements: The \"educationRequirements\" property is part of the pending.schema.org extension: it is still under development and subject to change.", + "[SchemaOrg warning] hasOccupation.hasOccupation.occupationalCategory: The \"occupationalCategory\" property is part of the pending.schema.org extension: it is still under development and subject to change." ], "documentIssues": [] }, @@ -1190,8 +1190,8 @@ "warnings": [ "[SchemaOrg warning] @type: The \"MathSolver\" type is part of the pending.schema.org extension: it is still under development and subject to change.", "[SchemaOrg warning] potentialAction.@type: The \"SolveMathAction\" type is part of the pending.schema.org extension: it is still under development and subject to change.", - "[SchemaOrg warning] potentialAction.mathExpression-input: The \"mathExpression\" property is part of the pending.schema.org extension: it is still under development and subject to change.", "[SchemaOrg warning] potentialAction.@type: The \"SolveMathAction\" type is part of the pending.schema.org extension: it is still under development and subject to change.", + "[SchemaOrg warning] potentialAction.mathExpression-input: The \"mathExpression\" property is part of the pending.schema.org extension: it is still under development and subject to change.", "[SchemaOrg warning] potentialAction.mathExpression-input: The \"mathExpression\" property is part of the pending.schema.org extension: it is still under development and subject to change." ], "documentIssues": [] @@ -1661,8 +1661,8 @@ }, "https-schema-org-c9a96f4f568a0bc237d24f6b0cca9ca5.jsonld": { "errors": [ - "[SchemaOrg error] object: The \"object\" property does not accept the \"Energy\" type as a value", - "[SchemaOrg error] object.name: The property \"name\" does not exist on the type \"Energy\"" + "[SchemaOrg error] object.name: The property \"name\" does not exist on the type \"Energy\"", + "[SchemaOrg error] object: The \"object\" property does not accept the \"Energy\" type as a value" ], "warnings": [], "documentIssues": [] @@ -1701,37 +1701,37 @@ "[SchemaOrg warning] healthPlanId: The \"healthPlanId\" property is part of the pending.schema.org extension: it is still under development and subject to change.", "[SchemaOrg warning] healthPlanMarketingUrl: The \"healthPlanMarketingUrl\" property is part of the pending.schema.org extension: it is still under development and subject to change.", "[SchemaOrg warning] includesHealthPlanFormulary.@type: The \"HealthPlanFormulary\" type is part of the pending.schema.org extension: it is still under development and subject to change.", + "[SchemaOrg warning] includesHealthPlanFormulary.@type: The \"HealthPlanFormulary\" type is part of the pending.schema.org extension: it is still under development and subject to change.", "[SchemaOrg warning] includesHealthPlanFormulary.healthPlanCostSharing.@type: The \"HealthPlanCostSharingSpecification\" type is part of the pending.schema.org extension: it is still under development and subject to change.", - "[SchemaOrg warning] includesHealthPlanFormulary.healthPlanCostSharing.healthPlanCoinsuranceOption: The \"healthPlanCoinsuranceOption\" property is part of the pending.schema.org extension: it is still under development and subject to change.", - "[SchemaOrg warning] includesHealthPlanFormulary.healthPlanCostSharing.healthPlanCoinsuranceRate: The \"healthPlanCoinsuranceRate\" property is part of the pending.schema.org extension: it is still under development and subject to change.", - "[SchemaOrg warning] includesHealthPlanFormulary.healthPlanCostSharing.healthPlanCopay: The \"healthPlanCopay\" property is part of the pending.schema.org extension: it is still under development and subject to change.", - "[SchemaOrg warning] includesHealthPlanFormulary.healthPlanCostSharing.healthPlanCopayOption: The \"healthPlanCopayOption\" property is part of the pending.schema.org extension: it is still under development and subject to change.", - "[SchemaOrg warning] includesHealthPlanFormulary.healthPlanCostSharing.healthPlanPharmacyCategory: The \"healthPlanPharmacyCategory\" property is part of the pending.schema.org extension: it is still under development and subject to change.", "[SchemaOrg warning] includesHealthPlanFormulary.healthPlanCostSharing.@type: The \"HealthPlanCostSharingSpecification\" type is part of the pending.schema.org extension: it is still under development and subject to change.", - "[SchemaOrg warning] includesHealthPlanFormulary.healthPlanCostSharing.healthPlanCoinsuranceOption: The \"healthPlanCoinsuranceOption\" property is part of the pending.schema.org extension: it is still under development and subject to change.", - "[SchemaOrg warning] includesHealthPlanFormulary.healthPlanCostSharing.healthPlanCoinsuranceRate: The \"healthPlanCoinsuranceRate\" property is part of the pending.schema.org extension: it is still under development and subject to change.", - "[SchemaOrg warning] includesHealthPlanFormulary.healthPlanCostSharing.healthPlanCopay: The \"healthPlanCopay\" property is part of the pending.schema.org extension: it is still under development and subject to change.", - "[SchemaOrg warning] includesHealthPlanFormulary.healthPlanCostSharing.healthPlanCopayOption: The \"healthPlanCopayOption\" property is part of the pending.schema.org extension: it is still under development and subject to change.", - "[SchemaOrg warning] includesHealthPlanFormulary.healthPlanCostSharing.healthPlanPharmacyCategory: The \"healthPlanPharmacyCategory\" property is part of the pending.schema.org extension: it is still under development and subject to change.", - "[SchemaOrg warning] includesHealthPlanFormulary.healthPlanCostSharing: The \"healthPlanCostSharing\" property is part of the pending.schema.org extension: it is still under development and subject to change.", - "[SchemaOrg warning] includesHealthPlanFormulary.healthPlanDrugTier: The \"healthPlanDrugTier\" property is part of the pending.schema.org extension: it is still under development and subject to change.", - "[SchemaOrg warning] includesHealthPlanFormulary.offersPrescriptionByMail: The \"offersPrescriptionByMail\" property is part of the pending.schema.org extension: it is still under development and subject to change.", - "[SchemaOrg warning] includesHealthPlanFormulary.@type: The \"HealthPlanFormulary\" type is part of the pending.schema.org extension: it is still under development and subject to change.", "[SchemaOrg warning] includesHealthPlanFormulary.healthPlanCostSharing.@type: The \"HealthPlanCostSharingSpecification\" type is part of the pending.schema.org extension: it is still under development and subject to change.", - "[SchemaOrg warning] includesHealthPlanFormulary.healthPlanCostSharing.healthPlanCoinsuranceOption: The \"healthPlanCoinsuranceOption\" property is part of the pending.schema.org extension: it is still under development and subject to change.", - "[SchemaOrg warning] includesHealthPlanFormulary.healthPlanCostSharing.healthPlanCoinsuranceRate: The \"healthPlanCoinsuranceRate\" property is part of the pending.schema.org extension: it is still under development and subject to change.", - "[SchemaOrg warning] includesHealthPlanFormulary.healthPlanCostSharing.healthPlanCopay: The \"healthPlanCopay\" property is part of the pending.schema.org extension: it is still under development and subject to change.", - "[SchemaOrg warning] includesHealthPlanFormulary.healthPlanCostSharing.healthPlanCopayOption: The \"healthPlanCopayOption\" property is part of the pending.schema.org extension: it is still under development and subject to change.", - "[SchemaOrg warning] includesHealthPlanFormulary.healthPlanCostSharing.healthPlanPharmacyCategory: The \"healthPlanPharmacyCategory\" property is part of the pending.schema.org extension: it is still under development and subject to change.", "[SchemaOrg warning] includesHealthPlanFormulary.healthPlanCostSharing.@type: The \"HealthPlanCostSharingSpecification\" type is part of the pending.schema.org extension: it is still under development and subject to change.", "[SchemaOrg warning] includesHealthPlanFormulary.healthPlanCostSharing.healthPlanCoinsuranceOption: The \"healthPlanCoinsuranceOption\" property is part of the pending.schema.org extension: it is still under development and subject to change.", + "[SchemaOrg warning] includesHealthPlanFormulary.healthPlanCostSharing.healthPlanCoinsuranceOption: The \"healthPlanCoinsuranceOption\" property is part of the pending.schema.org extension: it is still under development and subject to change.", + "[SchemaOrg warning] includesHealthPlanFormulary.healthPlanCostSharing.healthPlanCoinsuranceOption: The \"healthPlanCoinsuranceOption\" property is part of the pending.schema.org extension: it is still under development and subject to change.", + "[SchemaOrg warning] includesHealthPlanFormulary.healthPlanCostSharing.healthPlanCoinsuranceOption: The \"healthPlanCoinsuranceOption\" property is part of the pending.schema.org extension: it is still under development and subject to change.", + "[SchemaOrg warning] includesHealthPlanFormulary.healthPlanCostSharing.healthPlanCoinsuranceRate: The \"healthPlanCoinsuranceRate\" property is part of the pending.schema.org extension: it is still under development and subject to change.", + "[SchemaOrg warning] includesHealthPlanFormulary.healthPlanCostSharing.healthPlanCoinsuranceRate: The \"healthPlanCoinsuranceRate\" property is part of the pending.schema.org extension: it is still under development and subject to change.", + "[SchemaOrg warning] includesHealthPlanFormulary.healthPlanCostSharing.healthPlanCoinsuranceRate: The \"healthPlanCoinsuranceRate\" property is part of the pending.schema.org extension: it is still under development and subject to change.", "[SchemaOrg warning] includesHealthPlanFormulary.healthPlanCostSharing.healthPlanCoinsuranceRate: The \"healthPlanCoinsuranceRate\" property is part of the pending.schema.org extension: it is still under development and subject to change.", "[SchemaOrg warning] includesHealthPlanFormulary.healthPlanCostSharing.healthPlanCopay: The \"healthPlanCopay\" property is part of the pending.schema.org extension: it is still under development and subject to change.", + "[SchemaOrg warning] includesHealthPlanFormulary.healthPlanCostSharing.healthPlanCopay: The \"healthPlanCopay\" property is part of the pending.schema.org extension: it is still under development and subject to change.", + "[SchemaOrg warning] includesHealthPlanFormulary.healthPlanCostSharing.healthPlanCopay: The \"healthPlanCopay\" property is part of the pending.schema.org extension: it is still under development and subject to change.", + "[SchemaOrg warning] includesHealthPlanFormulary.healthPlanCostSharing.healthPlanCopay: The \"healthPlanCopay\" property is part of the pending.schema.org extension: it is still under development and subject to change.", + "[SchemaOrg warning] includesHealthPlanFormulary.healthPlanCostSharing.healthPlanCopayOption: The \"healthPlanCopayOption\" property is part of the pending.schema.org extension: it is still under development and subject to change.", "[SchemaOrg warning] includesHealthPlanFormulary.healthPlanCostSharing.healthPlanCopayOption: The \"healthPlanCopayOption\" property is part of the pending.schema.org extension: it is still under development and subject to change.", + "[SchemaOrg warning] includesHealthPlanFormulary.healthPlanCostSharing.healthPlanCopayOption: The \"healthPlanCopayOption\" property is part of the pending.schema.org extension: it is still under development and subject to change.", + "[SchemaOrg warning] includesHealthPlanFormulary.healthPlanCostSharing.healthPlanCopayOption: The \"healthPlanCopayOption\" property is part of the pending.schema.org extension: it is still under development and subject to change.", + "[SchemaOrg warning] includesHealthPlanFormulary.healthPlanCostSharing.healthPlanPharmacyCategory: The \"healthPlanPharmacyCategory\" property is part of the pending.schema.org extension: it is still under development and subject to change.", + "[SchemaOrg warning] includesHealthPlanFormulary.healthPlanCostSharing.healthPlanPharmacyCategory: The \"healthPlanPharmacyCategory\" property is part of the pending.schema.org extension: it is still under development and subject to change.", + "[SchemaOrg warning] includesHealthPlanFormulary.healthPlanCostSharing.healthPlanPharmacyCategory: The \"healthPlanPharmacyCategory\" property is part of the pending.schema.org extension: it is still under development and subject to change.", "[SchemaOrg warning] includesHealthPlanFormulary.healthPlanCostSharing.healthPlanPharmacyCategory: The \"healthPlanPharmacyCategory\" property is part of the pending.schema.org extension: it is still under development and subject to change.", "[SchemaOrg warning] includesHealthPlanFormulary.healthPlanCostSharing: The \"healthPlanCostSharing\" property is part of the pending.schema.org extension: it is still under development and subject to change.", + "[SchemaOrg warning] includesHealthPlanFormulary.healthPlanCostSharing: The \"healthPlanCostSharing\" property is part of the pending.schema.org extension: it is still under development and subject to change.", + "[SchemaOrg warning] includesHealthPlanFormulary.healthPlanDrugTier: The \"healthPlanDrugTier\" property is part of the pending.schema.org extension: it is still under development and subject to change.", "[SchemaOrg warning] includesHealthPlanFormulary.healthPlanDrugTier: The \"healthPlanDrugTier\" property is part of the pending.schema.org extension: it is still under development and subject to change.", "[SchemaOrg warning] includesHealthPlanFormulary.offersPrescriptionByMail: The \"offersPrescriptionByMail\" property is part of the pending.schema.org extension: it is still under development and subject to change.", + "[SchemaOrg warning] includesHealthPlanFormulary.offersPrescriptionByMail: The \"offersPrescriptionByMail\" property is part of the pending.schema.org extension: it is still under development and subject to change.", "[SchemaOrg warning] includesHealthPlanFormulary: The \"includesHealthPlanFormulary\" property is part of the pending.schema.org extension: it is still under development and subject to change." ], "documentIssues": [] @@ -1785,9 +1785,9 @@ "errors": [ "[SchemaOrg error] healthPlanNetworkTiers: This property does not exist: healthPlanNetworkTiers", "[SchemaOrg error] includesHealthPlanFormulary.healthPlanCostSharing.healthPlanCopay.currency: The property \"currency\" does not exist on the type \"PriceSpecification\"", - "[SchemaOrg error] includesHealthPlanFormulary.healthPlanCostSharing.healthPlanPharmacyType: This property does not exist: healthPlanPharmacyType", "[SchemaOrg error] includesHealthPlanFormulary.healthPlanCostSharing.healthPlanCopay.currency: The property \"currency\" does not exist on the type \"PriceSpecification\"", "[SchemaOrg error] includesHealthPlanFormulary.healthPlanCostSharing.healthPlanPharmacyType: This property does not exist: healthPlanPharmacyType", + "[SchemaOrg error] includesHealthPlanFormulary.healthPlanCostSharing.healthPlanPharmacyType: This property does not exist: healthPlanPharmacyType", "[SchemaOrg error] marketingUrl: This property does not exist: marketingUrl", "[SchemaOrg error] summaryUrl: This property does not exist: summaryUrl", "[SchemaOrg error] usesHealthPlanIdType: This property does not exist: usesHealthPlanIdType" @@ -1795,22 +1795,22 @@ "warnings": [ "[SchemaOrg warning] @type: The \"HealthInsurancePlan\" type is part of the pending.schema.org extension: it is still under development and subject to change.", "[SchemaOrg warning] healthPlanId: The \"healthPlanId\" property is part of the pending.schema.org extension: it is still under development and subject to change.", - "[SchemaOrg warning] includesHealthPlanFormulary.healthPlanDrugTier: Duplicate property key \"healthPlanDrugTier\": only the last value is used.", - "[SchemaOrg warning] includesHealthPlanFormulary.offersPrescriptionByMail: Duplicate property key \"offersPrescriptionByMail\": only the last value is used.", - "[SchemaOrg warning] includesHealthPlanFormulary.healthPlanCostSharing: Duplicate property key \"healthPlanCostSharing\": only the last value is used.", "[SchemaOrg warning] includesHealthPlanFormulary.@type: The \"HealthPlanFormulary\" type is part of the pending.schema.org extension: it is still under development and subject to change.", "[SchemaOrg warning] includesHealthPlanFormulary.healthPlanCostSharing.@type: The \"HealthPlanCostSharingSpecification\" type is part of the pending.schema.org extension: it is still under development and subject to change.", - "[SchemaOrg warning] includesHealthPlanFormulary.healthPlanCostSharing.healthPlanCoinsuranceOption: The \"healthPlanCoinsuranceOption\" property is part of the pending.schema.org extension: it is still under development and subject to change.", - "[SchemaOrg warning] includesHealthPlanFormulary.healthPlanCostSharing.healthPlanCoinsuranceRate: The \"healthPlanCoinsuranceRate\" property is part of the pending.schema.org extension: it is still under development and subject to change.", - "[SchemaOrg warning] includesHealthPlanFormulary.healthPlanCostSharing.healthPlanCopay: The \"healthPlanCopay\" property is part of the pending.schema.org extension: it is still under development and subject to change.", - "[SchemaOrg warning] includesHealthPlanFormulary.healthPlanCostSharing.healthPlanCopayOption: The \"healthPlanCopayOption\" property is part of the pending.schema.org extension: it is still under development and subject to change.", "[SchemaOrg warning] includesHealthPlanFormulary.healthPlanCostSharing.@type: The \"HealthPlanCostSharingSpecification\" type is part of the pending.schema.org extension: it is still under development and subject to change.", "[SchemaOrg warning] includesHealthPlanFormulary.healthPlanCostSharing.healthPlanCoinsuranceOption: The \"healthPlanCoinsuranceOption\" property is part of the pending.schema.org extension: it is still under development and subject to change.", + "[SchemaOrg warning] includesHealthPlanFormulary.healthPlanCostSharing.healthPlanCoinsuranceOption: The \"healthPlanCoinsuranceOption\" property is part of the pending.schema.org extension: it is still under development and subject to change.", + "[SchemaOrg warning] includesHealthPlanFormulary.healthPlanCostSharing.healthPlanCoinsuranceRate: The \"healthPlanCoinsuranceRate\" property is part of the pending.schema.org extension: it is still under development and subject to change.", "[SchemaOrg warning] includesHealthPlanFormulary.healthPlanCostSharing.healthPlanCoinsuranceRate: The \"healthPlanCoinsuranceRate\" property is part of the pending.schema.org extension: it is still under development and subject to change.", "[SchemaOrg warning] includesHealthPlanFormulary.healthPlanCostSharing.healthPlanCopay: The \"healthPlanCopay\" property is part of the pending.schema.org extension: it is still under development and subject to change.", + "[SchemaOrg warning] includesHealthPlanFormulary.healthPlanCostSharing.healthPlanCopay: The \"healthPlanCopay\" property is part of the pending.schema.org extension: it is still under development and subject to change.", + "[SchemaOrg warning] includesHealthPlanFormulary.healthPlanCostSharing.healthPlanCopayOption: The \"healthPlanCopayOption\" property is part of the pending.schema.org extension: it is still under development and subject to change.", "[SchemaOrg warning] includesHealthPlanFormulary.healthPlanCostSharing.healthPlanCopayOption: The \"healthPlanCopayOption\" property is part of the pending.schema.org extension: it is still under development and subject to change.", + "[SchemaOrg warning] includesHealthPlanFormulary.healthPlanCostSharing: Duplicate property key \"healthPlanCostSharing\": only the last value is used.", "[SchemaOrg warning] includesHealthPlanFormulary.healthPlanCostSharing: The \"healthPlanCostSharing\" property is part of the pending.schema.org extension: it is still under development and subject to change.", + "[SchemaOrg warning] includesHealthPlanFormulary.healthPlanDrugTier: Duplicate property key \"healthPlanDrugTier\": only the last value is used.", "[SchemaOrg warning] includesHealthPlanFormulary.healthPlanDrugTier: The \"healthPlanDrugTier\" property is part of the pending.schema.org extension: it is still under development and subject to change.", + "[SchemaOrg warning] includesHealthPlanFormulary.offersPrescriptionByMail: Duplicate property key \"offersPrescriptionByMail\": only the last value is used.", "[SchemaOrg warning] includesHealthPlanFormulary.offersPrescriptionByMail: The \"offersPrescriptionByMail\" property is part of the pending.schema.org extension: it is still under development and subject to change.", "[SchemaOrg warning] includesHealthPlanFormulary: The \"includesHealthPlanFormulary\" property is part of the pending.schema.org extension: it is still under development and subject to change." ], diff --git a/tests/Validation/fixtures/google-baseline.json b/tests/Validation/fixtures/google-baseline.json index 2059e98e..2fa1ad0e 100644 --- a/tests/Validation/fixtures/google-baseline.json +++ b/tests/Validation/fixtures/google-baseline.json @@ -53,25 +53,25 @@ }, "book.jsonld": { "errors": [ + "[Google error] LibrarySystem: Missing required property: \"url\" for the type \"LibrarySystem\"", "[Google error] dataFeedElement.workExample.potentialAction.lender: Missing required property: \"additionalProperty\" for the type \"LibrarySystem\"", - "[Google error] dataFeedElement.workExample.potentialAction.lender: Missing required property: \"url\" for the type \"LibrarySystem\"", - "[Google error] dataFeedElement.workExample.potentialAction.lender: Missing required property: \"member\" for the type \"LibrarySystem\"", - "[Google error] dataFeedElement.workExample.potentialAction.lender: Missing required property: \"name\" for the type \"LibrarySystem\"", "[Google error] dataFeedElement.workExample.potentialAction.lender: Missing required property: \"additionalProperty\" for the type \"LibrarySystem\"", - "[Google error] dataFeedElement.workExample.potentialAction.lender: Missing required property: \"url\" for the type \"LibrarySystem\"", + "[Google error] dataFeedElement.workExample.potentialAction.lender: Missing required property: \"member\" for the type \"LibrarySystem\"", "[Google error] dataFeedElement.workExample.potentialAction.lender: Missing required property: \"member\" for the type \"LibrarySystem\"", "[Google error] dataFeedElement.workExample.potentialAction.lender: Missing required property: \"name\" for the type \"LibrarySystem\"", - "[Google error] LibrarySystem: Missing required property: \"url\" for the type \"LibrarySystem\"" + "[Google error] dataFeedElement.workExample.potentialAction.lender: Missing required property: \"name\" for the type \"LibrarySystem\"", + "[Google error] dataFeedElement.workExample.potentialAction.lender: Missing required property: \"url\" for the type \"LibrarySystem\"", + "[Google error] dataFeedElement.workExample.potentialAction.lender: Missing required property: \"url\" for the type \"LibrarySystem\"" ], "warnings": [ "[Google warning] dataFeedElement.author: Missing recommended property: \"sameAs\" for the type \"Person\"", - "[Google warning] dataFeedElement.workExample: Missing recommended property: \"sameAs\" for the type \"Book\"", + "[Google warning] dataFeedElement.author: Missing recommended property: \"sameAs\" for the type \"Person\"", + "[Google warning] dataFeedElement.workExample.potentialAction.expectsAcceptanceOf.category: The value is correct, but is not lowercased. Google expects lowercased values.", + "[Google warning] dataFeedElement.workExample: Missing recommended property: \"identifier\" for the type \"Book\"", "[Google warning] dataFeedElement.workExample: Missing recommended property: \"identifier\" for the type \"Book\"", "[Google warning] dataFeedElement.workExample: Missing recommended property: \"sameAs\" for the type \"Book\"", - "[Google warning] dataFeedElement.workExample.potentialAction.expectsAcceptanceOf.category: The value is correct, but is not lowercased. Google expects lowercased values.", - "[Google warning] dataFeedElement.author: Missing recommended property: \"sameAs\" for the type \"Person\"", "[Google warning] dataFeedElement.workExample: Missing recommended property: \"sameAs\" for the type \"Book\"", - "[Google warning] dataFeedElement.workExample: Missing recommended property: \"identifier\" for the type \"Book\"", + "[Google warning] dataFeedElement.workExample: Missing recommended property: \"sameAs\" for the type \"Book\"", "[Google warning] dataFeedElement.workExample: Missing recommended property: \"sameAs\" for the type \"Book\"" ], "documentIssues": [] @@ -170,12 +170,12 @@ "course-info.jsonld": { "errors": [], "warnings": [ - "[Google warning] video: Missing recommended property: at least one of the following properties should be present \"creator, author\"", "[Google warning] video: Missing recommended property: \"duration\" for the type \"VideoObject\"", "[Google warning] video: Missing recommended property: \"embedUrl\" for the type \"VideoObject\"", "[Google warning] video: Missing recommended property: \"expires\" for the type \"VideoObject\"", + "[Google warning] video: Missing recommended property: \"ineligibleRegion\" for the type \"VideoObject\"", "[Google warning] video: Missing recommended property: \"regionsAllowed\" for the type \"VideoObject\"", - "[Google warning] video: Missing recommended property: \"ineligibleRegion\" for the type \"VideoObject\"" + "[Google warning] video: Missing recommended property: at least one of the following properties should be present \"creator, author\"" ], "documentIssues": [] }, @@ -588,14 +588,14 @@ "[Google warning] Product: Missing recommended property: \"size\" for the type \"Product\"", "[Google warning] Product: Missing recommended property: \"sku\" for the type \"Product\"", "[Google warning] Product: Missing recommended property: at least one of the following properties should be present \"gtin, gtin8, gtin12, gtin13, gtin14, isbn\"", + "[Google warning] offers.hasMerchantReturnPolicy: Missing recommended property: \"returnMethod\" for the type \"MerchantReturnPolicy\" when returns are accepted.", "[Google warning] offers: Missing recommended property: \"availability\" for the type \"Offer\"", "[Google warning] offers: Missing recommended property: \"itemCondition\" for the type \"Offer\"", "[Google warning] offers: Missing recommended property: \"priceValidUntil\" for the type \"Offer\"", "[Google warning] offers: Missing recommended property: \"shippingDetails\" for the type \"Offer\"", "[Google warning] offers: Missing recommended property: \"url\" for the type \"Offer\"", "[Google warning] offers: Missing recommended property: \"validFrom\" for the type \"Offer\"", - "[Google warning] offers: Missing recommended property: \"validThrough\" for the type \"Offer\"", - "[Google warning] offers.hasMerchantReturnPolicy: Missing recommended property: \"returnMethod\" for the type \"MerchantReturnPolicy\" when returns are accepted." + "[Google warning] offers: Missing recommended property: \"validThrough\" for the type \"Offer\"" ], "documentIssues": [] }, @@ -604,7 +604,6 @@ "[Google error] offers.price: Invalid value: \"price\" must be greater than 0 for merchant listing offers." ], "warnings": [ - "[Google warning] offers: Missing recommended property: \"shippingDetails\" for the type \"Offer\"", "[Google warning] Product: Missing recommended property: \"aggregateRating\" for the type \"Product\"", "[Google warning] Product: Missing recommended property: \"category\" for the type \"Product\"", "[Google warning] Product: Missing recommended property: \"color\" for the type \"Product\"", @@ -619,6 +618,7 @@ "[Google warning] Product: Missing recommended property: at least one of the following properties should be present \"gtin, gtin8, gtin12, gtin13, gtin14, isbn\"", "[Google warning] offers: Missing recommended property: \"itemCondition\" for the type \"Offer\"", "[Google warning] offers: Missing recommended property: \"priceValidUntil\" for the type \"Offer\"", + "[Google warning] offers: Missing recommended property: \"shippingDetails\" for the type \"Offer\"", "[Google warning] offers: Missing recommended property: \"url\" for the type \"Offer\"", "[Google warning] offers: Missing recommended property: \"validFrom\" for the type \"Offer\"", "[Google warning] offers: Missing recommended property: \"validThrough\" for the type \"Offer\"" @@ -930,8 +930,8 @@ "[Google error] VideoObject: Missing required property: \"name\" for the type \"VideoObject\"" ], "warnings": [ - "[Google warning] VideoObject: Missing recommended property: at least one of the following properties should be present \"creator, author\"", - "[Google warning] VideoObject: Missing recommended property: \"embedUrl\" for the type \"VideoObject\"" + "[Google warning] VideoObject: Missing recommended property: \"embedUrl\" for the type \"VideoObject\"", + "[Google warning] VideoObject: Missing recommended property: at least one of the following properties should be present \"creator, author\"" ], "documentIssues": [] },