AssetsHelperTest.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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\Bundle\FrameworkBundle\Tests\Templating\Helper;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Bundle\FrameworkBundle\Templating\Helper\AssetsHelper;
  13. use Symfony\Component\Asset\Package;
  14. use Symfony\Component\Asset\Packages;
  15. use Symfony\Component\Asset\PathPackage;
  16. use Symfony\Component\Asset\VersionStrategy\StaticVersionStrategy;
  17. class AssetsHelperTest extends TestCase
  18. {
  19. /**
  20. * @group legacy
  21. */
  22. public function testLegacyGetUrl()
  23. {
  24. $versionStrategy = new StaticVersionStrategy('22', '%s?version=%s');
  25. $package = new Package($versionStrategy);
  26. $imagePackage = new PathPackage('images', $versionStrategy);
  27. $packages = new Packages($package, array('images' => $imagePackage));
  28. $helper = new AssetsHelper($packages);
  29. $this->assertEquals('me.png?version=42', $helper->getUrl('me.png', null, '42'));
  30. $this->assertEquals('/images/me.png?version=42', $helper->getUrl('me.png', 'images', '42'));
  31. }
  32. /**
  33. * @group legacy
  34. */
  35. public function testLegacyGetVersion()
  36. {
  37. $package = new Package(new StaticVersionStrategy('22'));
  38. $imagePackage = new Package(new StaticVersionStrategy('42'));
  39. $packages = new Packages($package, array('images' => $imagePackage));
  40. $helper = new AssetsHelper($packages);
  41. $this->assertEquals('22', $helper->getVersion());
  42. $this->assertEquals('22', $helper->getVersion('/foo'));
  43. $this->assertEquals('42', $helper->getVersion('images'));
  44. $this->assertEquals('42', $helper->getVersion('/foo', 'images'));
  45. }
  46. }