Skip to content

Commit

Permalink
[TASK] Include sorting in test fixtures, add verbose header error
Browse files Browse the repository at this point in the history
Also refactor index key matching to use simplified version.
  • Loading branch information
garvinhicking committed Jan 23, 2025
1 parent 823c16f commit cac4798
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 10 deletions.
17 changes: 8 additions & 9 deletions legacy_hook/src/DocumentationLinker.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,17 +232,16 @@ private function parseInventoryForIndex(string $index, array $json): string
return 0;
});

foreach ($json as $mainKey => $subKeys) {
foreach ($json as $subKeys) {
foreach ($subKeys as $indexName => $indexMetaData) {
// Note: In the future, we may want to do a check for
// in_array($mainKey, $docNodes, true)
// ($mainKey would be the key of the foreach($json) loop)
// to differentiate between a match contained in the $docNodes
// array above, or a fallback match. For now, this all just leads
// to the resolved links like 'ApiOverview/Events/Events/Core/Security/InvestigateMutationsEvent.html#typo3-cms-core-security-contentsecuritypolicy-event-investigatemutationsevent-policy'
if ($indexName === $index) {
if (in_array($mainKey, $docNodes, true)) {
// Resolves to an entry like 'ApiOverview/Events/Events/Core/Security/InvestigateMutationsEvent.html#typo3-cms-core-security-contentsecuritypolicy-event-investigatemutationsevent-policy'
return $indexMetaData[2];
} else {
// Currently, no replacement is needed, but let's have a distinct case for this
// for forward compatibility.
return $indexMetaData[2];
}
return $indexMetaData[2];
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{
"std:doc": {
"dupe-entry": [
"Dummy",
"main",
"Index.html#std-doc",
"Dummy"
]
},
"std:title": {
"dupe-entry": [
"Dummy",
"main",
"Index.html#std-title",
"Dummy"
]
},
"std:confval": {
"dupe-entry": [
"Dummy",
"main",
"Index.html#std-confval",
"Dummy"
]
},
"std:option": {
"dupe-entry": [
"Dummy",
"main",
"Index.html#std-option",
"Dummy"
]
},
"std:console:command-list": {
"dupe-entry": [
"Dummy",
"main",
"Index.html#std-console-command-list",
"Dummy"
]
},
"std:console:command": {
"dupe-entry": [
"Dummy",
"main",
"Index.html#std-console-command",
"Dummy"
]
},
"php:property": {
"dupe-entry": [
"Dummy",
"main",
"Index.html#php-property",
"Dummy"
]
},
"000anything:random": {
"dupe-entry": [
"Dummy",
"main",
"Index.html#anything-random",
"Dummy"
]
},
"std:label": {
"dupe-entry": [
"Dummy",
"main",
"Index.html#dupe-entry",
"The real dupe target to prove sorting kind of works"
]
}
}
6 changes: 5 additions & 1 deletion legacy_hook/tests/Unit/PermalinksTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ public static function redirectFailsDataProvider(): array
public static function redirectWorksDataProvider(): array
{
return [
'dupe sorting' => [
'permalink' => 'dummyvendor-dummy:dupe-entry',
'location' => 'https://docs.typo3.org/p/dummyvendor/dummy/main/en-us/Index.html#dupe-entry',
],
'core manual, no version' => [
'permalink' => 'changelog:important-100889-1690476872',
'location' => 'https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/11.5.x/Important-100889-AllowInsecureSiteResolutionByQueryParameters.html#important-100889-1690476872',
Expand Down Expand Up @@ -285,7 +289,7 @@ public function redirectWorksForPermalink(string $permalink, string $location):
self::assertInstanceOf(DocumentationLinker::class, $this->subject);
$describer = $this->subject->resolvePermalink($permalink);

self::assertSame(307, $describer->statusCode);
self::assertSame(307, $describer->statusCode, 'Header mismatch: ' . $describer->body);
self::assertSame(['Location' => $location], $describer->headers);
self::assertStringContainsString('Redirect to', $describer->body);
}
Expand Down

0 comments on commit cac4798

Please sign in to comment.