AssetsHelperTest.php 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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\Component\Templating\Tests\Helper;
  11. use Symfony\Component\Templating\Helper\AssetsHelper;
  12. class AssetsHelperTest extends \PHPUnit_Framework_TestCase
  13. {
  14. public function testGetVersion()
  15. {
  16. $helper = new AssetsHelper(null, array(), 'foo');
  17. $this->assertEquals('foo', $helper->getVersion(), '->getVersion() returns the version');
  18. }
  19. public function testGetUrl()
  20. {
  21. $helper = new AssetsHelper();
  22. $this->assertEquals('http://example.com/foo.js', $helper->getUrl('http://example.com/foo.js'), '->getUrl() does nothing if an absolute URL is given');
  23. $helper = new AssetsHelper();
  24. $this->assertEquals('/foo.js', $helper->getUrl('foo.js'), '->getUrl() appends a / on relative paths');
  25. $this->assertEquals('/foo.js', $helper->getUrl('/foo.js'), '->getUrl() does nothing on absolute paths');
  26. $helper = new AssetsHelper('/foo');
  27. $this->assertEquals('/foo/foo.js', $helper->getUrl('foo.js'), '->getUrl() appends the basePath on relative paths');
  28. $this->assertEquals('/foo.js', $helper->getUrl('/foo.js'), '->getUrl() does not append the basePath on absolute paths');
  29. $helper = new AssetsHelper(null, 'http://assets.example.com/');
  30. $this->assertEquals('http://assets.example.com/foo.js', $helper->getUrl('foo.js'), '->getUrl() prepends the base URL');
  31. $this->assertEquals('http://assets.example.com/foo.js', $helper->getUrl('/foo.js'), '->getUrl() prepends the base URL');
  32. $helper = new AssetsHelper(null, 'http://www.example.com/foo');
  33. $this->assertEquals('http://www.example.com/foo/foo.js', $helper->getUrl('foo.js'), '->getUrl() prepends the base URL with a path');
  34. $this->assertEquals('http://www.example.com/foo/foo.js', $helper->getUrl('/foo.js'), '->getUrl() prepends the base URL with a path');
  35. $helper = new AssetsHelper('/foo', 'http://www.example.com/');
  36. $this->assertEquals('http://www.example.com/foo.js', $helper->getUrl('foo.js'), '->getUrl() prepends the base URL and the base path if defined');
  37. $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');
  38. $helper = new AssetsHelper('/bar', 'http://www.example.com/foo');
  39. $this->assertEquals('http://www.example.com/foo/foo.js', $helper->getUrl('foo.js'), '->getUrl() prepends the base URL and the base path if defined');
  40. $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');
  41. $helper = new AssetsHelper('/bar', 'http://www.example.com/foo', 'abcd');
  42. $this->assertEquals('http://www.example.com/foo/foo.js?abcd', $helper->getUrl('foo.js'), '->getUrl() appends the version if defined');
  43. $helper = new AssetsHelper();
  44. $this->assertEquals('/', $helper->getUrl(''), '->getUrl() with empty arg returns the prefix alone');
  45. }
  46. public function testGetUrlLeavesProtocolRelativePathsUntouched()
  47. {
  48. $helper = new AssetsHelper(null, 'http://foo.com');
  49. $this->assertEquals('//bar.com/asset', $helper->getUrl('//bar.com/asset'));
  50. }
  51. }