-
-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
35 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
use League\Uri\Schemes\Data as DataUri; | ||
use League\Uri\Schemes\Http as HttpUri; | ||
use PHPUnit_Framework_TestCase; | ||
use Zend\Diactoros\Uri as DiactorosUri; | ||
|
||
/** | ||
* @group formatter | ||
|
@@ -27,7 +28,7 @@ class FormatterTest extends PHPUnit_Framework_TestCase | |
|
||
protected function setUp() | ||
{ | ||
$this->uri = HttpUri::createFromString( | ||
$this->uri = new DiactorosUri( | ||
'http://login:pass@gwóźdź.pl:443/test/query.php?kingkong=toto&foo=bar+baz#doc3' | ||
); | ||
$this->formatter = new Formatter(); | ||
|
@@ -38,7 +39,8 @@ public function testFormatHostAscii() | |
$this->assertSame(Formatter::HOST_AS_UNICODE, $this->formatter->getHostEncoding()); | ||
$this->formatter->setHostEncoding(Formatter::HOST_AS_ASCII); | ||
$this->assertSame(Formatter::HOST_AS_ASCII, $this->formatter->getHostEncoding()); | ||
$this->assertSame('xn--gwd-hna98db.pl', $this->formatter->__invoke($this->uri->host)); | ||
$uri = HttpUri::createFromString($this->uri->__toString()); | ||
$this->assertSame('xn--gwd-hna98db.pl', $this->formatter->__invoke($uri->host)); | ||
} | ||
|
||
/** | ||
|
@@ -59,19 +61,16 @@ public function testInvalidQueryEncoding() | |
|
||
public function testFormatWithSimpleString() | ||
{ | ||
$uri = 'https://login:pass@gwóźdź.pl:443/test/query.php?kingkong=toto&foo=bar+baz#doc3'; | ||
$expected = 'https://login:[email protected]/test/query.php?kingkong=toto&foo=bar+baz#doc3'; | ||
$uri = HttpUri::createFromString($uri); | ||
|
||
$expected = 'http://login:[email protected]:443/test/query.php?kingkong=toto&foo=bar+baz#doc3'; | ||
$this->formatter->setQuerySeparator('&'); | ||
$this->formatter->setHostEncoding(Formatter::HOST_AS_ASCII); | ||
$this->assertSame($expected, $this->formatter->__invoke($uri)); | ||
$this->assertSame($expected, $this->formatter->__invoke($this->uri)); | ||
} | ||
|
||
public function testFormatWithZeroes() | ||
{ | ||
$expected = 'https://example.com/image.jpeg?0#0'; | ||
$uri = HttpUri::createFromString('https://example.com/image.jpeg?0#0'); | ||
$uri = new DiactorosUri('https://example.com/image.jpeg?0#0'); | ||
$this->assertSame($expected, $this->formatter->__invoke($uri)); | ||
} | ||
|
||
|
@@ -84,29 +83,33 @@ public function testFormatComponent() | |
public function testFormatHostUnicode() | ||
{ | ||
$this->formatter->setHostEncoding(Formatter::HOST_AS_UNICODE); | ||
$this->assertSame('gwóźdź.pl', $this->formatter->__invoke($this->uri->host)); | ||
$uri = HttpUri::createFromString($this->uri->__toString()); | ||
$this->assertSame('gwóźdź.pl', $this->formatter->__invoke($uri->host)); | ||
} | ||
|
||
public function testFormatQueryRFC1738() | ||
{ | ||
$this->assertSame(PHP_QUERY_RFC3986, $this->formatter->getQueryEncoding()); | ||
$this->formatter->setQueryEncoding(PHP_QUERY_RFC1738); | ||
$this->assertSame(PHP_QUERY_RFC1738, $this->formatter->getQueryEncoding()); | ||
$this->assertSame('kingkong=toto&foo=bar%2Bbaz', $this->formatter->__invoke($this->uri->query)); | ||
$uri = HttpUri::createFromString($this->uri->__toString()); | ||
$this->assertSame('kingkong=toto&foo=bar%2Bbaz', $this->formatter->__invoke($uri->query)); | ||
} | ||
|
||
public function testFormatQueryRFC3986() | ||
{ | ||
$this->formatter->setQueryEncoding(PHP_QUERY_RFC3986); | ||
$this->assertSame('kingkong=toto&foo=bar+baz', $this->formatter->__invoke($this->uri->query)); | ||
$uri = HttpUri::createFromString($this->uri->__toString()); | ||
$this->assertSame('kingkong=toto&foo=bar+baz', $this->formatter->__invoke($uri->query)); | ||
} | ||
|
||
public function testFormatQueryWithSeparator() | ||
{ | ||
$this->assertSame('&', $this->formatter->getQuerySeparator()); | ||
$this->formatter->setQuerySeparator('&'); | ||
$this->assertSame('&', $this->formatter->getQuerySeparator()); | ||
$this->assertSame('kingkong=toto&foo=bar+baz', $this->formatter->__invoke($this->uri->query)); | ||
$uri = HttpUri::createFromString($this->uri->__toString()); | ||
$this->assertSame('kingkong=toto&foo=bar+baz', $this->formatter->__invoke($uri->query)); | ||
} | ||
|
||
public function testFormat() | ||
|
@@ -146,7 +149,7 @@ public function testFormatterFailed() | |
public function testFormatterPreservedQuery() | ||
{ | ||
$expected = 'http://example.com'; | ||
$uri = HttpUri::createFromString($expected); | ||
$uri = new DiactorosUri($expected); | ||
$this->formatter->preserveQuery(true); | ||
$this->assertSame($expected, (string) $uri); | ||
$this->assertSame('http://example.com?', $this->formatter->__invoke($uri)); | ||
|
@@ -155,9 +158,15 @@ public function testFormatterPreservedQuery() | |
public function testFormatterPreservedFragment() | ||
{ | ||
$expected = 'http://example.com'; | ||
$uri = HttpUri::createFromString($expected); | ||
$uri = new DiactorosUri($expected); | ||
$this->formatter->preserveFragment(true); | ||
$this->assertSame($expected, (string) $uri); | ||
$this->assertSame('http://example.com#', $this->formatter->__invoke($uri)); | ||
} | ||
|
||
public function testValidFormatterRespectRFC3986() | ||
{ | ||
$psr7uri = (new DiactorosUri('http://bébé.be'))->withPath('foo/bar'); | ||
$this->assertSame('http://bébé.be/foo/bar', (string) $this->formatter->__invoke($psr7uri)); | ||
} | ||
} |
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