@@ -137,4 +137,84 @@ public static function abstractUrlProvider(): array
137137 ],
138138 ];
139139 }
140+
141+ #[DataProvider('documentPathProvider ' )]
142+ public function testRelativeDocUrl (
143+ string $ currentDirectory ,
144+ string $ destinationPath ,
145+ string $ linkedDocument ,
146+ string $ result ,
147+ string |null $ anchor = null ,
148+ ): void {
149+ $ urlGenerator = new UrlGenerator ();
150+ self ::assertSame ($ result , $ urlGenerator ->generateOutputUrlFromDocumentPath (
151+ $ currentDirectory ,
152+ $ destinationPath ,
153+ $ linkedDocument ,
154+ 'txt ' ,
155+ $ anchor ,
156+ ));
157+ }
158+
159+ /** @return array<string, array<string, bool|string>> */
160+ public static function documentPathProvider (): array
161+ {
162+ return [
163+ 'relative document ' => [
164+ 'currentDirectory ' => 'getting-started ' ,
165+ 'destinationPath ' => 'guide ' ,
166+ 'linkedDocument ' => 'installing ' ,
167+ 'result ' => 'guide/getting-started/installing.txt ' ,
168+ ],
169+ 'absolute document path ' => [
170+ 'currentDirectory ' => 'getting-started ' ,
171+ 'destinationPath ' => 'guide ' ,
172+ 'linkedDocument ' => '/installing ' ,
173+ 'result ' => 'guide/installing.txt ' ,
174+ ],
175+ 'absolute document path with anchor ' => [
176+ 'currentDirectory ' => 'getting-started ' ,
177+ 'destinationPath ' => 'guide ' ,
178+ 'linkedDocument ' => '/getting-started/configuration ' ,
179+ 'result ' => 'guide/getting-started/configuration.txt#composer ' ,
180+ 'anchor ' => 'composer ' ,
181+ ],
182+ 'relative document path up in directory ' => [
183+ 'currentDirectory ' => 'getting-started ' ,
184+ 'destinationPath ' => 'guide ' ,
185+ 'linkedDocument ' => '../references/installing ' ,
186+ 'result ' => 'guide/references/installing.txt ' ,
187+ ],
188+ 'relative document path up in subdirectory ' => [
189+ 'currentDirectory ' => 'getting-started/something ' ,
190+ 'destinationPath ' => 'guide ' ,
191+ 'linkedDocument ' => '../references/installing ' ,
192+ 'result ' => 'guide/getting-started/references/installing.txt ' ,
193+ ],
194+ 'relative document path two up in directory ' => [
195+ 'currentDirectory ' => 'getting-started/something ' ,
196+ 'destinationPath ' => 'guide ' ,
197+ 'linkedDocument ' => '../../references/installing ' ,
198+ 'result ' => 'guide/references/installing.txt ' ,
199+ ],
200+ 'Empty destination ' => [
201+ 'currentDirectory ' => 'getting-started/something ' ,
202+ 'destinationPath ' => '' ,
203+ 'linkedDocument ' => '../../references/installing ' ,
204+ 'result ' => 'references/installing.txt ' ,
205+ ],
206+ 'Destination is empty absolute path ' => [
207+ 'currentDirectory ' => 'getting-started/something ' ,
208+ 'destinationPath ' => '/ ' ,
209+ 'linkedDocument ' => '../../references/installing ' ,
210+ 'result ' => '/references/installing.txt ' ,
211+ ],
212+ 'Destination is absolute ' => [
213+ 'currentDirectory ' => 'getting-started/something ' ,
214+ 'destinationPath ' => '/guide/ ' ,
215+ 'linkedDocument ' => '../../references/installing ' ,
216+ 'result ' => '/guide/references/installing.txt ' ,
217+ ],
218+ ];
219+ }
140220}
0 commit comments