2010-03-18 14:26:21 +00:00
< ? php
/*
2010-04-25 16:06:54 +01:00
* This file is part of the Symfony package .
2010-03-18 14:26:21 +00:00
*
2011-03-06 11:40:06 +00:00
* ( c ) Fabien Potencier < fabien @ symfony . com >
2010-04-07 02:07:59 +01:00
*
2010-03-18 14:26:21 +00:00
* For the full copyright and license information , please view the LICENSE
* file that was distributed with this source code .
*/
2010-08-20 22:09:55 +01:00
namespace Symfony\Tests\Component\Templating\Helper ;
2010-03-18 14:26:21 +00:00
2011-03-08 16:15:52 +00:00
use Symfony\Component\Templating\Asset\AssetPackage ;
2010-08-20 22:09:55 +01:00
use Symfony\Component\Templating\Helper\AssetsHelper ;
2010-03-18 14:26:21 +00:00
class AssetsHelperTest extends \PHPUnit_Framework_TestCase
{
2011-03-08 16:15:52 +00:00
public function testGetVersion ()
2010-05-06 12:25:53 +01:00
{
2011-03-08 16:15:52 +00:00
$helper = new AssetsHelper ( null , array (), 'foo' );
$this -> assertEquals ( 'foo' , $helper -> getVersion (), '->getVersion() returns the version' );
2010-03-18 14:26:21 +00:00
}
2010-05-06 12:25:53 +01:00
public function testGetUrl ()
{
$helper = new AssetsHelper ();
$this -> assertEquals ( 'http://example.com/foo.js' , $helper -> getUrl ( 'http://example.com/foo.js' ), '->getUrl() does nothing if an absolute URL is given' );
2010-03-18 14:26:21 +00:00
2010-05-06 12:25:53 +01:00
$helper = new AssetsHelper ();
$this -> assertEquals ( '/foo.js' , $helper -> getUrl ( 'foo.js' ), '->getUrl() appends a / on relative paths' );
$this -> assertEquals ( '/foo.js' , $helper -> getUrl ( '/foo.js' ), '->getUrl() does nothing on absolute paths' );
2010-03-18 14:26:21 +00:00
2010-05-06 12:25:53 +01:00
$helper = new AssetsHelper ( '/foo' );
$this -> assertEquals ( '/foo/foo.js' , $helper -> getUrl ( 'foo.js' ), '->getUrl() appends the basePath on relative paths' );
$this -> assertEquals ( '/foo.js' , $helper -> getUrl ( '/foo.js' ), '->getUrl() does not append the basePath on absolute paths' );
2010-03-18 14:26:21 +00:00
2010-05-06 12:25:53 +01:00
$helper = new AssetsHelper ( null , 'http://assets.example.com/' );
$this -> assertEquals ( 'http://assets.example.com/foo.js' , $helper -> getUrl ( 'foo.js' ), '->getUrl() prepends the base URL' );
$this -> assertEquals ( 'http://assets.example.com/foo.js' , $helper -> getUrl ( '/foo.js' ), '->getUrl() prepends the base URL' );
2010-03-18 14:26:21 +00:00
2010-05-06 12:25:53 +01:00
$helper = new AssetsHelper ( null , 'http://www.example.com/foo' );
$this -> assertEquals ( 'http://www.example.com/foo/foo.js' , $helper -> getUrl ( 'foo.js' ), '->getUrl() prepends the base URL with a path' );
$this -> assertEquals ( 'http://www.example.com/foo/foo.js' , $helper -> getUrl ( '/foo.js' ), '->getUrl() prepends the base URL with a path' );
2010-03-18 14:26:21 +00:00
2010-05-06 12:25:53 +01:00
$helper = new AssetsHelper ( '/foo' , 'http://www.example.com/' );
2010-08-19 15:17:20 +01:00
$this -> assertEquals ( 'http://www.example.com/foo.js' , $helper -> getUrl ( 'foo.js' ), '->getUrl() prepends the base URL and the base path if defined' );
2010-05-06 12:25:53 +01:00
$this -> assertEquals ( 'http://www.example.com/foo.js' , $helper -> getUrl ( '/foo.js' ), '->getUrl() prepends the base URL but not the base path on absolute paths' );
2010-03-18 14:26:21 +00:00
2010-05-06 12:25:53 +01:00
$helper = new AssetsHelper ( '/bar' , 'http://www.example.com/foo' );
2010-08-19 15:17:20 +01:00
$this -> assertEquals ( 'http://www.example.com/foo/foo.js' , $helper -> getUrl ( 'foo.js' ), '->getUrl() prepends the base URL and the base path if defined' );
2010-05-06 12:25:53 +01:00
$this -> assertEquals ( 'http://www.example.com/foo/foo.js' , $helper -> getUrl ( '/foo.js' ), '->getUrl() prepends the base URL but not the base path on absolute paths' );
2010-03-18 14:26:21 +00:00
2010-05-06 12:25:53 +01:00
$helper = new AssetsHelper ( '/bar' , 'http://www.example.com/foo' , 'abcd' );
2010-08-19 15:17:20 +01:00
$this -> assertEquals ( 'http://www.example.com/foo/foo.js?abcd' , $helper -> getUrl ( 'foo.js' ), '->getUrl() appends the version if defined' );
2010-05-06 12:25:53 +01:00
}
2011-03-23 18:10:43 +00:00
public function testGetUrlLeavesProtocolRelativePathsUntouched ()
{
$helper = new AssetsHelper ( null , 'http://foo.com' );
$this -> assertEquals ( '//bar.com/asset' , $helper -> getUrl ( '//bar.com/asset' ));
}
2010-03-18 14:26:21 +00:00
}