File tree Expand file tree Collapse file tree
tests/SlmLocaleTest/Strategy Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -113,6 +113,33 @@ Inject the detected language here with the following code:
113113<html lang="<?= Locale::getPrimaryLanguage(Locale::getDefault())?>">
114114```
115115
116+ ### Disable UriPathStrategy in PHPUNIT
117+ This is necessary (at the moment) if you want to use `` this->dispatch('my/uri'); `` in your ` AbstractHttpControllerTestCase ` unit tests.
118+ Otherwise, if you check for responseCode you will get ` 302 ` where it should be ` 200 ` .
119+
120+ Example:
121+ ```
122+ $this->dispatch('/to/my/uri');
123+ $this->assertResponseStatusCode(200); // this will be 302 instead of 200
124+
125+ $this->dispatch('/en/to/my/uri');
126+ $this->assertResponseStatusCode(200); // this will be 302 instead of 200
127+ ```
128+
129+ To fix add the following to your phpunit config.
130+
131+ phpunit.xml:
132+ ```
133+ <phpunit...>
134+ ...
135+ <php>
136+ <server name="DISABLE_URIPATHSTRATEGY" value="true" />
137+ </php>
138+ </phpunit>
139+ ```
140+
141+ Or set `` $_SERVER['DISABLE_URIPATHSTRATEGY'] = true; `` in your bootstrap file of phpunit.
142+
116143### Create a list of available locales
117144
118145T.B.D
Original file line number Diff line number Diff line change 2222 "ext-intl" : " *" ,
2323 "zendframework/zend-eventmanager" : " ^3.1" ,
2424 "zendframework/zend-http" : " ^2.7" ,
25- "zendframework/zend-modulemanager" : " ^2.8.1 " ,
25+ "zendframework/zend-modulemanager" : " ^2.8.2 " ,
2626 "zendframework/zend-router" : " ^3.0" ,
2727 "zendframework/zend-servicemanager" : " ^3.2" ,
2828 "zendframework/zend-stdlib" : " ^3.1" ,
Original file line number Diff line number Diff line change @@ -118,6 +118,10 @@ public function detect(LocaleEvent $event)
118118
119119 public function found (LocaleEvent $ event )
120120 {
121+ if (array_key_exists ('DISABLE_URIPATHSTRATEGY ' , $ _SERVER ) && true === $ _SERVER ['DISABLE_URIPATHSTRATEGY ' ]) {
122+ return ;
123+ }
124+
121125 $ request = $ event ->getRequest ();
122126 if (! $ this ->isHttpRequest ($ request )) {
123127 return ;
Original file line number Diff line number Diff line change @@ -348,6 +348,28 @@ public function testAssembleWorksWithAliasesToo()
348348 $ this ->assertEquals ($ expected , $ actual );
349349 }
350350
351+ public function testDisableUriPathStrategyPhpunit ()
352+ {
353+ $ _SERVER ['DISABLE_URIPATHSTRATEGY ' ] = true ;
354+
355+ $ uri = 'http://username:password@example.com:8080/some/deep/path/some.file?withsomeparam=true ' ;
356+ $ request = new HttpRequest ();
357+ $ request ->setUri ($ uri );
358+
359+ $ this ->event ->setLocale ('en ' );
360+ $ this ->event ->setRequest ($ request );
361+ $ this ->event ->setResponse (new HttpResponse ());
362+
363+ $ this ->strategy ->found ($ this ->event );
364+
365+ $ statusCode = $ this ->event ->getResponse ()->getStatusCode ();
366+ $ header = $ this ->event ->getResponse ()->getHeaders ()->get ('Location ' );
367+ $ expected = 'Location: http://username:password@example.com:8080/en/some/deep/path/some.file?withsomeparam=true ' ;
368+ $ this ->assertEquals (200 , $ statusCode );
369+
370+ $ _SERVER ['DISABLE_URIPATHSTRATEGY ' ] = false ;
371+ }
372+
351373 protected function getPluginManager ($ console = false )
352374 {
353375 $ sl = new ServiceManager ();
You can’t perform that action at this time.
0 commit comments