bug #15183 [TwigBridge] fix for legacy asset() with EmptyVersionStrategy (xabbuh)

This PR was merged into the 2.7 branch.

Discussion
----------

[TwigBridge] fix for legacy asset() with EmptyVersionStrategy

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #15156
| License       | MIT
| Doc PR        |

Commits
-------

cf86a03 fix for legacy asset() with EmptyVersionStrategy
This commit is contained in:
Fabien Potencier 2015-07-04 13:07:22 +02:00
commit 5d2cc19fcc
2 changed files with 19 additions and 4 deletions

View File

@ -108,11 +108,15 @@ class AssetExtension extends \Twig_Extension
$v->setAccessible(true);
$currentVersionStrategy = $v->getValue($package);
$f = new \ReflectionProperty($currentVersionStrategy, 'format');
$f->setAccessible(true);
$format = $f->getValue($currentVersionStrategy);
if (property_exists($currentVersionStrategy, 'format')) {
$f = new \ReflectionProperty($currentVersionStrategy, 'format');
$f->setAccessible(true);
$format = $f->getValue($currentVersionStrategy);
$v->setValue($package, new StaticVersionStrategy($version, $format));
$v->setValue($package, new StaticVersionStrategy($version, $format));
} else {
$v->setValue($package, new StaticVersionStrategy($version));
}
}
try {

View File

@ -15,6 +15,7 @@ use Symfony\Bridge\Twig\Extension\AssetExtension;
use Symfony\Component\Asset\Package;
use Symfony\Component\Asset\Packages;
use Symfony\Component\Asset\PathPackage;
use Symfony\Component\Asset\VersionStrategy\EmptyVersionStrategy;
use Symfony\Component\Asset\VersionStrategy\StaticVersionStrategy;
class AssetExtensionTest extends \PHPUnit_Framework_TestCase
@ -41,6 +42,16 @@ class AssetExtensionTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('/foo/me.png?version=42', $extension->getAssetUrl('me.png', null, false, 42));
}
/**
* @group legacy
*/
public function testGetAssetUrlWithEmptyVersionStrategy()
{
$extension = $this->createExtension(new PathPackage('foo', new EmptyVersionStrategy()));
$this->assertEquals('/foo/me.png?42', $extension->getAssetUrl('me.png', null, false, 42));
}
private function createExtension(Package $package)
{
$foundationExtension = $this->getMockBuilder('Symfony\Bridge\Twig\Extension\HttpFoundationExtension')->disableOriginalConstructor()->getMock();