@@ -39,10 +39,7 @@ public function testReturnsStoreBaseUrl(): void
3939
4040 public function testBuildUrlConcatenatesPathOntoBaseUrl (): void
4141 {
42- $ store = $ this ->createMock (Store::class);
43- $ store ->method ('getBaseUrl ' )->with (UrlInterface::URL_TYPE_WEB )
44- ->willReturn ('https://example.com/ ' );
45- $ this ->storeManager ->method ('getStore ' )->willReturn ($ store );
42+ $ this ->withBaseUrl ('https://example.com/ ' );
4643
4744 self ::assertSame (
4845 'https://example.com/.well-known/oauth-protected-resource ' ,
@@ -53,4 +50,100 @@ public function testBuildUrlConcatenatesPathOntoBaseUrl(): void
5350 $ this ->builder ->buildUrl ('foo ' )
5451 );
5552 }
53+
54+ public function testGetAuthorityStripsPathComponent (): void
55+ {
56+ $ this ->withBaseUrl ('https://example.com/lv/ ' );
57+ self ::assertSame ('https://example.com ' , $ this ->builder ->getAuthority ());
58+ }
59+
60+ public function testGetAuthorityPreservesPort (): void
61+ {
62+ $ this ->withBaseUrl ('https://example.com:8443/lv/ ' );
63+ self ::assertSame ('https://example.com:8443 ' , $ this ->builder ->getAuthority ());
64+ }
65+
66+ public function testGetAuthorityFallsBackOnMalformedBaseUrl (): void
67+ {
68+ // parse_url can't yield scheme+host — never emit an empty authority.
69+ $ this ->withBaseUrl ('not a url ' );
70+ self ::assertSame ('not a url ' , $ this ->builder ->getAuthority ());
71+ }
72+
73+ /**
74+ * @dataProvider basePathProvider
75+ * @param string $baseUrl
76+ * @param string $expected
77+ * @return void
78+ */
79+ public function testGetBasePath (string $ baseUrl , string $ expected ): void
80+ {
81+ $ this ->withBaseUrl ($ baseUrl );
82+ self ::assertSame ($ expected , $ this ->builder ->getBasePath ());
83+ }
84+
85+ /**
86+ * @return array<string, array{string, string}>
87+ */
88+ public static function basePathProvider (): array
89+ {
90+ return [
91+ 'root ' => ['https://example.com/ ' , '' ],
92+ 'store code ' => ['https://example.com/lv/ ' , 'lv ' ],
93+ 'subfolder ' => ['https://example.com/shop/ ' , 'shop ' ],
94+ ];
95+ }
96+
97+ public function testGetResourceUrlKeepsBasePath (): void
98+ {
99+ $ this ->withBaseUrl ('https://example.com/lv/ ' );
100+ self ::assertSame ('https://example.com/lv/mcp ' , $ this ->builder ->getResourceUrl ());
101+ }
102+
103+ public function testProtectedResourceWellKnownUrlInsertsAfterAuthority (): void
104+ {
105+ $ this ->withBaseUrl ('https://example.com/lv/ ' );
106+ self ::assertSame (
107+ 'https://example.com/.well-known/oauth-protected-resource/lv/mcp ' ,
108+ $ this ->builder ->getProtectedResourceWellKnownUrl ()
109+ );
110+ }
111+
112+ public function testProtectedResourceWellKnownUrlOnCleanBaseUrl (): void
113+ {
114+ $ this ->withBaseUrl ('https://example.com/ ' );
115+ self ::assertSame (
116+ 'https://example.com/.well-known/oauth-protected-resource/mcp ' ,
117+ $ this ->builder ->getProtectedResourceWellKnownUrl ()
118+ );
119+ }
120+
121+ public function testAuthServerWellKnownUrlAppendsBasePath (): void
122+ {
123+ $ this ->withBaseUrl ('https://example.com/lv/ ' );
124+ self ::assertSame (
125+ 'https://example.com/.well-known/oauth-authorization-server/lv ' ,
126+ $ this ->builder ->getAuthServerWellKnownUrl ()
127+ );
128+ }
129+
130+ public function testAuthServerWellKnownUrlOnCleanBaseUrl (): void
131+ {
132+ $ this ->withBaseUrl ('https://example.com/ ' );
133+ self ::assertSame (
134+ 'https://example.com/.well-known/oauth-authorization-server ' ,
135+ $ this ->builder ->getAuthServerWellKnownUrl ()
136+ );
137+ }
138+
139+ /**
140+ * @param string $baseUrl
141+ * @return void
142+ */
143+ private function withBaseUrl (string $ baseUrl ): void
144+ {
145+ $ store = $ this ->createMock (Store::class);
146+ $ store ->method ('getBaseUrl ' )->with (UrlInterface::URL_TYPE_WEB )->willReturn ($ baseUrl );
147+ $ this ->storeManager ->method ('getStore ' )->willReturn ($ store );
148+ }
56149}
0 commit comments