From c874c6ad5b2e7c88a07d5ac2a92feb874cb52782 Mon Sep 17 00:00:00 2001 From: Ruben van der Linde Date: Tue, 17 Nov 2026 13:49:30 +0000 Subject: [PATCH] test(launchpad): cover middleware successor link without prefix [skip ci] Assisted-by: ClaudeCode:claude-opus-5-5 --- .../Middleware/ApiContractMiddlewareTest.php | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/tests/Unit/Middleware/ApiContractMiddlewareTest.php b/tests/Unit/Middleware/ApiContractMiddlewareTest.php index 2c4e6d71a..65d57bcf4 100644 --- a/tests/Unit/Middleware/ApiContractMiddlewareTest.php +++ b/tests/Unit/Middleware/ApiContractMiddlewareTest.php @@ -41,13 +41,14 @@ class ApiContractMiddlewareTest extends TestCase { * * @param string|false $path The request path info. * @param Response $response The controller response. + * @param string|null $uri The request URI; null puts `/index.php` before the path. * * @return Response The decorated response. */ - private function decorate(string|false $path, Response $response): Response { + private function decorate(string|false $path, Response $response, ?string $uri = null): Response { $request = $this->createMock(originalClassName: IRequest::class); $request->method('getPathInfo')->willReturn($path); - $request->method('getRequestUri')->willReturn('/index.php'.(string) $path.'?q=1'); + $request->method('getRequestUri')->willReturn($uri ?? '/index.php'.(string) $path.'?q=1'); $appManager = $this->createMock(originalClassName: IAppManager::class); $appManager->method('getAppVersion')->willReturn('1.2.3'); @@ -198,6 +199,24 @@ public function testUnversionedPathAnnouncesItsSuccessor(): void { $this->assertSame(expected: '; rel="successor-version"', actual: $headers['Link']); }//end testUnversionedPathAnnouncesItsSuccessor() + /** + * When the request URI does not contain the path info (a rewritten URL), the + * successor link carries no front-controller prefix. + * + * @return void + */ + public function testSuccessorLinkHasNoPrefixWhenTheUriLacksThePath(): void { + $response = $this->decorate( + path: '/apps/launchpad/api/things/7/parts', + response: new JSONResponse(data: ['id' => 7]), + uri: '/rewritten/elsewhere' + ); + $headers = $this->headersOf(response: $response); + + $this->assertSame(expected: '@1794441600', actual: $headers['Deprecation']); + $this->assertSame(expected: '; rel="successor-version"', actual: $headers['Link']); + }//end testSuccessorLinkHasNoPrefixWhenTheUriLacksThePath() + /** * A versioned API path is not deprecated, and still carries the version. *