-
-
Notifications
You must be signed in to change notification settings - Fork 47
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
3 changed files
with
114 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Bridge\Twig\Tests\Extension; | ||
|
||
use Symfony\Bridge\Twig\Extension\HttpFoundationExtension; | ||
use Symfony\Component\HttpFoundation\RequestStack; | ||
use Symfony\Component\HttpFoundation\Request; | ||
|
||
class HttpFoundationExtensionTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @dataProvider getGenerateAbsoluteUrlData() | ||
*/ | ||
public function testGenerateAbsoluteUrl($expected, $path, $pathinfo) | ||
{ | ||
$stack = new RequestStack(); | ||
$stack->push(Request::create($pathinfo)); | ||
$extension = new HttpFoundationExtension($stack); | ||
|
||
$this->assertEquals($expected, $extension->generateAbsoluteUrl($path)); | ||
} | ||
|
||
public function getGenerateAbsoluteUrlData() | ||
{ | ||
return array( | ||
array('http://localhost/foo.png', '/foo.png', '/foo/bar.html'), | ||
array('http://localhost/foo/foo.png', 'foo.png', '/foo/bar.html'), | ||
array('http://localhost/foo/foo.png', 'foo.png', '/foo/bar'), | ||
array('http://localhost/foo/bar/foo.png', 'foo.png', '/foo/bar/'), | ||
|
||
array('http://example.com/baz', 'http://example.com/baz', '/'), | ||
array('https://example.com/baz', 'https://example.com/baz', '/'), | ||
array('//example.com/baz', '//example.com/baz', '/'), | ||
); | ||
} | ||
|
||
/** | ||
* @dataProvider getGenerateRelativePathData() | ||
*/ | ||
public function testGenerateRelativePath($expected, $path, $pathinfo) | ||
{ | ||
if (!method_exists('Symfony\Component\HttpFoundation\Request', 'getRelativeUriForPath')) { | ||
$this->markTestSkipped('Your version of Symfony HttpFoundation is too old.'); | ||
} | ||
|
||
$stack = new RequestStack(); | ||
$stack->push(Request::create($pathinfo)); | ||
$extension = new HttpFoundationExtension($stack); | ||
|
||
$this->assertEquals($expected, $extension->generateRelativePath($path)); | ||
} | ||
|
||
public function getGenerateRelativePathData() | ||
{ | ||
return array( | ||
array('../foo.png', '/foo.png', '/foo/bar.html'), | ||
array('../baz/foo.png', '/baz/foo.png', '/foo/bar.html'), | ||
array('baz/foo.png', 'baz/foo.png', '/foo/bar.html'), | ||
|
||
array('http://example.com/baz', 'http://example.com/baz', '/'), | ||
array('https://example.com/baz', 'https://example.com/baz', '/'), | ||
array('//example.com/baz', '//example.com/baz', '/'), | ||
); | ||
} | ||
} |