-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #61 from prolic/host
create correct urls for locale menu with host strategy
- Loading branch information
Showing
5 changed files
with
163 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
<?php | ||
|
||
namespace SlmLocaleTest\Strategy; | ||
|
||
use PHPUnit_Framework_TestCase as TestCase; | ||
use SlmLocale\LocaleEvent; | ||
use SlmLocale\Strategy\HostStrategy; | ||
use Zend\Http\PhpEnvironment\Request; | ||
use Zend\Stdlib\Parameters; | ||
use Zend\Uri\Uri; | ||
|
||
class HostStrategyTest extends TestCase | ||
{ | ||
public function testDetectNonHttpRequestReturnsNull() | ||
{ | ||
$event = new LocaleEvent(); | ||
$event->setRequest($this->getMockForAbstractClass('Zend\Stdlib\RequestInterface')); | ||
|
||
$strategy = new HostStrategy(); | ||
$this->assertNull($strategy->detect($event)); | ||
} | ||
|
||
public function testDetectWithoutSupportedReturnsNull() | ||
{ | ||
$event = new LocaleEvent(); | ||
$event->setRequest($this->getMockForAbstractClass('Zend\Http\Request')); | ||
$event->setSupported(array()); | ||
|
||
$strategy = new HostStrategy(); | ||
$this->assertNull($strategy->detect($event)); | ||
} | ||
|
||
/** | ||
* @expectedException \SlmLocale\Strategy\Exception\InvalidArgumentException | ||
*/ | ||
public function testDetectWithoutDomainThrowsInvalidArgumentException() | ||
{ | ||
$event = new LocaleEvent(); | ||
$event->setRequest($this->getMockForAbstractClass('Zend\Http\Request')); | ||
$event->setSupported(array('en_GB', 'de_DE')); | ||
|
||
$strategy = new HostStrategy(); | ||
$strategy->setOptions(array('domain' => 'test')); | ||
$this->assertNull($strategy->detect($event)); | ||
} | ||
|
||
public function testDetectUnsupportedReturnsNull() | ||
{ | ||
$request = new Request(); | ||
$request->setUri('http://test.fr'); | ||
$event = new LocaleEvent(); | ||
$event->setRequest($request); | ||
$event->setSupported(array('en_GB', 'de_DE')); | ||
|
||
$strategy = new HostStrategy(); | ||
$strategy->setOptions(array( | ||
'domain' => 'test.:locale', | ||
'aliases' => array('de' => 'de_DE', 'co.uk' => 'en_GB') | ||
)); | ||
$result = $strategy->detect($event); | ||
|
||
$this->assertNull($result); | ||
} | ||
|
||
public function testDetect() | ||
{ | ||
$request = new Request(); | ||
$request->setUri('http://test.de'); | ||
$event = new LocaleEvent(); | ||
$event->setRequest($request); | ||
$event->setSupported(array('en_GB', 'de_DE')); | ||
|
||
$strategy = new HostStrategy(); | ||
$strategy->setOptions(array( | ||
'domain' => 'test.:locale', | ||
'aliases' => array('de' => 'de_DE', 'co.uk' => 'en_GB') | ||
)); | ||
$result = $strategy->detect($event); | ||
|
||
$this->assertSame('de_DE', $result); | ||
} | ||
|
||
public function testAssemble() | ||
{ | ||
$params = new Parameters(array('SERVER_NAME' => 'test.co.uk')); | ||
$request = new Request(); | ||
$request->setServer($params); | ||
|
||
$event = new LocaleEvent(); | ||
$event->setLocale('de_DE'); | ||
$event->setUri(new Uri('http://test.co.uk')); | ||
$event->setRequest($request); | ||
|
||
$strategy = new HostStrategy(); | ||
$strategy->setOptions(array( | ||
'domain' => 'test.:locale', | ||
'aliases' => array('de' => 'de_DE', 'co.uk' => 'en_GB') | ||
)); | ||
|
||
$result = $strategy->assemble($event)->getHost(); | ||
$this->assertSame('test.de', $result); | ||
} | ||
|
||
public function testAssembleWithPort() | ||
{ | ||
$params = new Parameters(array('SERVER_NAME' => 'test.co.uk', 'SERVER_PORT' => 8080)); | ||
$request = new Request(); | ||
$request->setServer($params); | ||
|
||
$event = new LocaleEvent(); | ||
$event->setLocale('de_DE'); | ||
$event->setUri(new Uri('http://test.co.uk')); | ||
$event->setRequest($request); | ||
|
||
$strategy = new HostStrategy(); | ||
$strategy->setOptions(array( | ||
'domain' => 'test.:locale', | ||
'aliases' => array('de' => 'de_DE', 'co.uk' => 'en_GB') | ||
)); | ||
|
||
$result = $strategy->assemble($event)->getHost(); | ||
$this->assertSame('test.de:8080', $result); | ||
} | ||
} |