@@ -115,6 +115,62 @@ public function testAddLocale(?string $user_locale, string $input_path, string $
115115
116116 $ this ->client ->followRedirects (false );
117117 $ this ->client ->request ('GET ' , $ input_path );
118- $ this -> assertResponseRedirects ($ redirect_path );
118+ self :: assertResponseRedirects ($ redirect_path );
119119 }
120+
121+ /**
122+ * Test if the user is redirected to the localized version of a page, based on his settings.
123+ * We simulate the situation of a reverse proxy here, by adding a prefix to the path.
124+ *
125+ * @dataProvider urlAddLocaleDataProvider
126+ * @group slow
127+ */
128+ public function testAddLocaleReverseProxy (?string $ user_locale , string $ input_path , string $ redirect_path ): void
129+ {
130+ //Input path remains unchanged, as this is what the server receives from the proxy
131+
132+ //Redirect path must contain the proxy prefix
133+ $ redirect_path = 'http://localhost ' . '/proxy ' . $ redirect_path ;
134+
135+ /** @var User $user */
136+ $ user = $ this ->userRepo ->findOneBy (['name ' => 'user ' ]);
137+ //Set user locale
138+ $ user ->setLanguage ($ user_locale );
139+ $ this ->em ->flush ();
140+
141+ $ this ->client ->followRedirects (false );
142+ $ this ->client ->request ('GET ' , $ input_path , [], [], ['HTTP_X_FORWARDED_PREFIX ' => '/proxy ' ]);
143+ self ::assertResponseRedirects ($ redirect_path );
144+ }
145+
146+
147+ /**
148+ * Test if the user is redirected to the localized version of a page, based on his settings.
149+ * We simulate the situation of serving Part-DB in a subfolder here.
150+ *
151+ * @dataProvider urlAddLocaleDataProvider
152+ * @group slow
153+ */
154+ public function testAddLocaleSubfolder (?string $ user_locale , string $ input_path , string $ redirect_path ): void
155+ {
156+ //Prefix our path with the proxy prefix
157+ $ input_path = '/folder ' .$ input_path ;
158+
159+ //Redirect path is absolute
160+ $ redirect_path = 'http://localhost ' . '/folder ' . $ redirect_path ;
161+
162+ /** @var User $user */
163+ $ user = $ this ->userRepo ->findOneBy (['name ' => 'user ' ]);
164+ //Set user locale
165+ $ user ->setLanguage ($ user_locale );
166+ $ this ->em ->flush ();
167+
168+ $ this ->client ->followRedirects (false );
169+ $ this ->client ->request ('GET ' , $ input_path , [], [], [
170+ 'SCRIPT_FILENAME ' => '/var/www/html/folder/public/index.php ' ,
171+ 'PHP_SELF ' => '/folder/index.php ' ,
172+ ]);
173+ self ::assertResponseRedirects ($ redirect_path );
174+ }
175+
120176}
0 commit comments