AssetsHelperTest.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Tests\Component\Templating\Helper;
  11. use Symfony\Component\Templating\Asset\AssetPackage;
  12. use Symfony\Component\Templating\Helper\AssetsHelper;
  13. class AssetsHelperTest extends \PHPUnit_Framework_TestCase
  14. {
  15. public function testGetVersion()
  16. {
  17. $helper = new AssetsHelper(null, array(), 'foo');
  18. $this->assertEquals('foo', $helper->getVersion(), '->getVersion() returns the version');
  19. }
  20. public function testGetUrl()
  21. {
  22. $helper = new AssetsHelper();
  23. $this->assertEquals('http://example.com/foo.js', $helper->getUrl('http://example.com/foo.js'), '->getUrl() does nothing if an absolute URL is given');
  24. $helper = new AssetsHelper();
  25. $this->assertEquals('/foo.js', $helper->getUrl('foo.js'), '->getUrl() appends a / on relative paths');
  26. $this->assertEquals('/foo.js', $helper->getUrl('/foo.js'), '->getUrl() does nothing on absolute paths');
  27. $helper = new AssetsHelper('/foo');
  28. $this->assertEquals('/foo/foo.js', $helper->getUrl('foo.js'), '->getUrl() appends the basePath on relative paths');
  29. $this->assertEquals('/foo.js', $helper->getUrl('/foo.js'), '->getUrl() does not append the basePath on absolute paths');
  30. $helper = new AssetsHelper(null, 'http://assets.example.com/');
  31. $this->assertEquals('http://assets.example.com/foo.js', $helper->getUrl('foo.js'), '->getUrl() prepends the base URL');
  32. $this->assertEquals('http://assets.example.com/foo.js', $helper->getUrl('/foo.js'), '->getUrl() prepends the base URL');
  33. $helper = new AssetsHelper(null, 'http://www.example.com/foo');
  34. $this->assertEquals('http://www.example.com/foo/foo.js', $helper->getUrl('foo.js'), '->getUrl() prepends the base URL with a path');
  35. $this->assertEquals('http://www.example.com/foo/foo.js', $helper->getUrl('/foo.js'), '->getUrl() prepends the base URL with a path');
  36. $helper = new AssetsHelper('/foo', 'http://www.example.com/');
  37. $this->assertEquals('http://www.example.com/foo.js', $helper->getUrl('foo.js'), '->getUrl() prepends the base URL and the base path if defined');
  38. $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');
  39. $helper = new AssetsHelper('/bar', 'http://www.example.com/foo');
  40. $this->assertEquals('http://www.example.com/foo/foo.js', $helper->getUrl('foo.js'), '->getUrl() prepends the base URL and the base path if defined');
  41. $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');
  42. $helper = new AssetsHelper('/bar', 'http://www.example.com/foo', 'abcd');
  43. $this->assertEquals('http://www.example.com/foo/foo.js?abcd', $helper->getUrl('foo.js'), '->getUrl() appends the version if defined');
  44. }
  45. public function testGetUrlLeavesProtocolRelativePathsUntouched()
  46. {
  47. $helper = new AssetsHelper(null, 'http://foo.com');
  48. $this->assertEquals('//bar.com/asset', $helper->getUrl('//bar.com/asset'));
  49. }
  50. }