PackageTest.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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\Asset\Tests;
  11. use Symfony\Component\Asset\Package;
  12. use Symfony\Component\Asset\VersionStrategy\StaticVersionStrategy;
  13. use Symfony\Component\Asset\VersionStrategy\EmptyVersionStrategy;
  14. class PackageTest extends \PHPUnit_Framework_TestCase
  15. {
  16. /**
  17. * @dataProvider getConfigs
  18. */
  19. public function testGetUrl($version, $format, $path, $expected)
  20. {
  21. $package = new Package($version ? new StaticVersionStrategy($version, $format) : new EmptyVersionStrategy());
  22. $this->assertEquals($expected, $package->getUrl($path));
  23. }
  24. public function getConfigs()
  25. {
  26. return array(
  27. array('v1', '', 'http://example.com/foo', 'http://example.com/foo'),
  28. array('v1', '', 'https://example.com/foo', 'https://example.com/foo'),
  29. array('v1', '', '//example.com/foo', '//example.com/foo'),
  30. array('v1', '', '/foo', '/foo?v1'),
  31. array('v1', '', 'foo', 'foo?v1'),
  32. array(null, '', '/foo', '/foo'),
  33. array(null, '', 'foo', 'foo'),
  34. array('v1', 'version-%2$s/%1$s', '/foo', '/version-v1/foo'),
  35. array('v1', 'version-%2$s/%1$s', 'foo', 'version-v1/foo'),
  36. array('v1', 'version-%2$s/%1$s', 'foo/', 'version-v1/foo/'),
  37. array('v1', 'version-%2$s/%1$s', '/foo/', '/version-v1/foo/'),
  38. );
  39. }
  40. public function testGetVersion()
  41. {
  42. $package = new Package(new StaticVersionStrategy('v1'));
  43. $this->assertEquals('v1', $package->getVersion('/foo'));
  44. }
  45. }