@@ -16,21 +16,87 @@ public function test_translate_path(string $path, ?string $locale, string $expec
16
16
public static function providerTranslatePath (): array
17
17
{
18
18
return [
19
+ // Translating from one locale to another
19
20
['/es/blog ' , 'ar ' , '/ar/blog ' ],
20
21
['/ar/blog ' , 'fr-CA ' , '/fr-CA/blog ' ],
21
- ['/fr-CA/blog ' , 'fr-CA ' , '/fr-CA/blog ' ],
22
22
['/ar/blog ' , 'haw-US ' , '/haw-US/blog ' ],
23
- ['/haw-US/blog ' , 'haw-US ' , '/haw-US/blog ' ],
24
23
['/fr-CA/blog ' , 'haw-US ' , '/haw-US/blog ' ],
25
24
['/haw-US/blog ' , 'fr-CA ' , '/fr-CA/blog ' ],
25
+
26
+ // Keeping the same locale (should remain unchanged)
27
+ ['/fr-CA/blog ' , 'fr-CA ' , '/fr-CA/blog ' ],
28
+ ['/haw-US/blog ' , 'haw-US ' , '/haw-US/blog ' ],
29
+ ['/ar/blog ' , 'ar ' , '/ar/blog ' ],
30
+ ['/en-UK/blog ' , 'en-UK ' , '/en-UK/blog ' ],
31
+
32
+ // Translating a path without a locale to a new locale
26
33
['/blog ' , 'ar ' , '/ar/blog ' ],
27
34
['/blog ' , 'en-UK ' , '/en-UK/blog ' ],
28
35
['/blog ' , 'haw-US ' , '/haw-US/blog ' ],
29
- ['/blog ' , packageDefaultLocale (), '/blog ' ],
36
+
37
+ // Converting to the default locale (removing locale prefix)
38
+ ['/ar/blog ' , packageDefaultLocale (), '/blog ' ],
39
+ ['/fr-CA/blog ' , packageDefaultLocale (), '/blog ' ],
40
+ ['/haw-US/blog ' , packageDefaultLocale (), '/blog ' ],
41
+
42
+ // If `target_locale` is `null`, it should return to the default locale
30
43
['/ar/blog ' , null , '/blog ' ],
31
44
['/en-UK/blog ' , null , '/blog ' ],
32
45
['/haw-US/blog ' , null , '/blog ' ],
33
46
['/blog ' , null , '/blog ' ],
47
+
48
+ // If already in the default locale and `target_locale` is `null`
49
+ ['/about ' , null , '/about ' ],
50
+ ['/contact ' , null , '/contact ' ],
51
+
52
+ // If `target_locale` is the same as `current_locale`
53
+ ['/es ' , 'es ' , '/es ' ],
54
+ ['/es/contact ' , 'es ' , '/es/contact ' ],
55
+ ['/fr-CA/page ' , 'fr-CA ' , '/fr-CA/page ' ],
56
+
57
+ // Testing multi-segment paths
58
+ ['/es/blog/posts/123 ' , 'ar ' , '/ar/blog/posts/123 ' ],
59
+ ['/ar/news/article/456 ' , 'fr-CA ' , '/fr-CA/news/article/456 ' ],
60
+ ['/haw-US/shop/products/789 ' , 'en-UK ' , '/en-UK/shop/products/789 ' ],
61
+
62
+ // Testing `/` as a root path (edge case)
63
+ ['/ ' , 'ar ' , '/ar ' ],
64
+ ['/ ' , null , '/ ' ],
65
+ ['/ ' , packageDefaultLocale (), '/ ' ],
66
+
67
+ // Testing paths with unrecognized prefixes (should keep them)
68
+ ['/custom-path/blog ' , 'fr-CA ' , '/fr-CA/custom-path/blog ' ],
69
+ ['/random/path ' , 'es ' , '/es/random/path ' ],
70
+
71
+ // Short prefixes that could cause substring errors
72
+ ['/a/blog ' , 'ar ' , '/ar/a/blog ' ],
73
+ ['/fr/page ' , 'haw-US ' , '/haw-US/page ' ],
74
+
75
+ // Handling an empty path (should default to `/`)
76
+ ['' , 'ar ' , '/ar ' ],
77
+ ['' , null , '/ ' ],
78
+
79
+ // Deeply nested paths
80
+ ['/es/a/b/c/d/e ' , 'ar ' , '/ar/a/b/c/d/e ' ],
81
+ ['/fr-CA/deeply/nested/path/example ' , 'en-UK ' , '/en-UK/deeply/nested/path/example ' ],
82
+
83
+ // Paths with special characters
84
+ ['/fr-CA/à-propos ' , 'es ' , '/es/à-propos ' ],
85
+ ['/es/blog/café ' , 'ar ' , '/ar/blog/café ' ],
86
+ ['/haw-US/ümlaut ' , 'en-UK ' , '/en-UK/ümlaut ' ],
87
+
88
+ // Case sensitivity (should not modify case)
89
+ ['/FR/blog ' , 'es ' , '/es/FR/blog ' ],
90
+ ['/Es/blog ' , 'fr-CA ' , '/fr-CA/Es/blog ' ],
91
+
92
+ // Handling trailing slashes
93
+ ['/es/ ' , 'ar ' , '/ar ' ],
94
+ ['/fr-CA/ ' , null , '/ ' ],
95
+ ['/blog/ ' , 'ar ' , '/ar/blog ' ],
96
+
97
+ /**
98
+ * @todo Unexpected locale prefixes (should behave as a normal path)
99
+ */
34
100
];
35
101
}
36
102
}
0 commit comments