-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix locale url change, from default locale to other locale #105
Changes from all commits
518aea9
973d0ef
963895c
d464723
966a7cb
eecdcb9
4ec2f8d
2b47ecc
bf8e937
0abec27
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,8 +127,7 @@ public function testDetectWithBaseUrlReturnsRightPartOfPath() | |
$this->event->setResponse(new HttpResponse()); | ||
|
||
$locale = $this->strategy->detect($this->event); | ||
$expected = 'en'; | ||
$this->assertEquals($expected, $locale); | ||
$this->assertSame('en', $locale); | ||
} | ||
|
||
public function testFoundRedirectsByDefault() | ||
|
@@ -169,6 +168,46 @@ public function testFoundShouldRespectDisabledRedirectWhenFound() | |
$this->assertFalse($header); | ||
} | ||
|
||
public function testFoundRedirectsByDefaultWithBasePath() | ||
{ | ||
$uri = 'http://example.com/my-app/public/nl/some/deep/path/some.file?withsomeparam=true'; | ||
$request = new HttpRequest(); | ||
$request->setUri($uri); | ||
$request->setBasePath('/my-app/public'); | ||
|
||
$this->event->setLocale('en'); | ||
$this->event->setRequest($request); | ||
$this->event->setResponse(new HttpResponse()); | ||
|
||
$this->strategy->found($this->event); | ||
|
||
$statusCode = $this->event->getResponse()->getStatusCode(); | ||
$header = $this->event->getResponse()->getHeaders()->get('Location'); | ||
$expected = 'Location: http://example.com/my-app/public/en/some/deep/path/some.file?withsomeparam=true'; | ||
$this->assertEquals(302, $statusCode); | ||
$this->assertContains($expected, (string) $header); | ||
} | ||
|
||
public function testFoundRedirectsByDefaultWithBasePathDisabledRedirectWhenFound() | ||
{ | ||
$this->strategy->setOptions(['redirect_when_found' => false]); | ||
$uri = 'http://example.com/my-app/public/nl/some/deep/path/some.file?withsomeparam=true'; | ||
$request = new HttpRequest(); | ||
$request->setUri($uri); | ||
$request->setBasePath('/my-app/public'); | ||
|
||
$this->event->setLocale('en'); | ||
$this->event->setRequest($request); | ||
$this->event->setResponse(new HttpResponse()); | ||
|
||
$this->strategy->found($this->event); | ||
|
||
$statusCode = $this->event->getResponse()->getStatusCode(); | ||
$header = $this->event->getResponse()->getHeaders()->has('Location'); | ||
$this->assertNotEquals(302, $statusCode); | ||
$this->assertFalse($header); | ||
} | ||
|
||
// public function testFoundWithDisabledRedirectWhenFoundOptionLocaleShouldStillBeDirectedAnywayWhenPathContainsNothingFurther() | ||
// { | ||
// $this->strategy->setOptions(['redirect_when_found' => false]); | ||
|
@@ -391,6 +430,8 @@ public function testAssembleWithDefault() | |
$this->event->setLocale('en'); | ||
$this->event->setUri($uri); | ||
|
||
$this->router->setBaseUrl('/nl'); | ||
$this->strategy = new UriPathStrategy($this->router); | ||
$this->strategy->setOptions([ | ||
'default' => 'en', | ||
]); | ||
|
@@ -409,15 +450,79 @@ public function testAssembleWithDefaultNotMatching() | |
$this->event->setLocale('en'); | ||
$this->event->setUri($uri); | ||
|
||
$this->router->setBaseUrl('/nl'); | ||
$this->strategy = new UriPathStrategy($this->router); | ||
$this->strategy->setOptions([ | ||
'default' => 'fr', | ||
]); | ||
$this->strategy->assemble($this->event); | ||
|
||
$expected = '/en/foo/bar/baz'; | ||
$actual = $this->event->getUri()->getPath(); | ||
$this->assertSame('/en/foo/bar/baz', $this->event->getUri()->getPath()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. strategies should not change base path. Should have been There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. but also it is base path @basz am I right here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i will add a test for this (when im home) Document_root There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added 2 tests for this, with default language to other language and without default language There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. install your app in '/var/www/my-app' thats all There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so as I understand baseurl is Do I still not understand something? please rename your public folder so mething like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added more tests, like if you rename your public directory to i also added the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, I looked deeper and now understand why you append language and change base path. As I understand that because you testing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added tests for found |
||
} | ||
|
||
$this->assertSame($expected, $actual); | ||
public function testAssembleWithDefaultWithBasePath() | ||
{ | ||
$uri = new Uri('/my-app/nl/foo/bar/baz'); | ||
|
||
$this->event->setLocale('en'); | ||
$this->event->setUri($uri); | ||
|
||
$this->router->setBaseUrl('/my-app/nl'); | ||
$this->strategy = new UriPathStrategy($this->router); | ||
$this->strategy->setOptions([ | ||
'default' => 'fr', | ||
]); | ||
$this->strategy->assemble($this->event); | ||
|
||
$this->assertSame('/my-app/en/foo/bar/baz', $this->event->getUri()->getPath()); | ||
} | ||
|
||
public function testAssembleWithDefaultWithBasePathWithMatching() | ||
{ | ||
$uri = new Uri('/my-app/foo/bar/baz'); | ||
|
||
$this->event->setLocale('en'); | ||
$this->event->setUri($uri); | ||
|
||
$this->router->setBaseUrl('/my-app'); | ||
$this->strategy = new UriPathStrategy($this->router); | ||
$this->strategy->setOptions([ | ||
'default' => 'nl', | ||
]); | ||
$this->strategy->assemble($this->event); | ||
|
||
$this->assertSame('/my-app/en/foo/bar/baz', $this->event->getUri()->getPath()); | ||
} | ||
|
||
public function testAssembleWithDefaultWithBasePathWithMatchingPubic() | ||
{ | ||
$uri = new Uri('/my-app/public/foo/bar/baz'); | ||
|
||
$this->event->setLocale('en'); | ||
$this->event->setUri($uri); | ||
|
||
$this->router->setBaseUrl('/my-app/public'); | ||
$this->strategy = new UriPathStrategy($this->router); | ||
$this->strategy->setOptions([ | ||
'default' => 'nl', | ||
]); | ||
$this->strategy->assemble($this->event); | ||
|
||
$this->assertSame('/my-app/public/en/foo/bar/baz', $this->event->getUri()->getPath()); | ||
} | ||
|
||
public function testAssembleWithBasePathWithMatchingLanguageName() | ||
{ | ||
$uri = new Uri('/my-app/nl/nl/foo/bar/baz'); | ||
|
||
$this->event->setLocale('en'); | ||
$this->event->setUri($uri); | ||
|
||
$this->router->setBaseUrl('/my-app/nl/nl'); | ||
$this->strategy = new UriPathStrategy($this->router); | ||
$this->strategy->assemble($this->event); | ||
|
||
$this->assertSame('/my-app/nl/en/foo/bar/baz', $this->event->getUri()->getPath()); | ||
} | ||
|
||
public function testDisableUriPathStrategyPhpunit() | ||
|
@@ -442,6 +547,21 @@ public function testDisableUriPathStrategyPhpunit() | |
$_SERVER['DISABLE_URIPATHSTRATEGY'] = false; | ||
} | ||
|
||
public function testAssembleWithDefaultMatchingCurrent() | ||
{ | ||
$uri = new Uri('/foo/bar/baz'); | ||
|
||
$this->event->setLocale('en'); | ||
$this->event->setUri($uri); | ||
|
||
$this->strategy->setOptions([ | ||
'default' => 'fr', | ||
]); | ||
$this->strategy->assemble($this->event); | ||
|
||
$this->assertSame('/en/foo/bar/baz', $this->event->getUri()->getPath()); | ||
} | ||
|
||
protected function getPluginManager($console = false) | ||
{ | ||
$sl = new ServiceManager(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why router does not have baseUrl?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check #40
i had the same problem
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
then we can remove
$this->router->getBaseUrl();
if we can get it from request?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes and no, to get it from the router is much better, as to use it from the request, should just be a fallback.