AsseticHelperTest.php 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /*
  3. * This file is part of the Symfony framework.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * This source file is subject to the MIT license that is bundled
  8. * with this source code in the file LICENSE.
  9. */
  10. namespace Symfony\Bundle\AsseticBundle\Tests\Templating;
  11. use Assetic\Asset\AssetCollection;
  12. use Assetic\Asset\AssetInterface;
  13. use Assetic\Asset\StringAsset;
  14. use Assetic\Factory\AssetFactory;
  15. use Symfony\Bundle\AsseticBundle\Templating\AsseticHelper;
  16. class AsseticHelperTest extends \PHPUnit_Framework_TestCase
  17. {
  18. protected function setUp()
  19. {
  20. if (!class_exists('Assetic\\AssetManager')) {
  21. $this->markTestSkipped('Assetic is not available.');
  22. }
  23. }
  24. /**
  25. * @dataProvider getDebugAndCount
  26. */
  27. public function testUrls($debug, $count, $message)
  28. {
  29. $helper = new AsseticHelperForTest(new AssetFactory('/foo', $debug), $debug);
  30. $urls = $helper->javascripts(array('js/jquery.js', 'js/jquery.plugin.js'));
  31. $this->assertInstanceOf('Traversable', $urls, '->javascripts() returns an array');
  32. $this->assertEquals($count, count($urls), $message);
  33. }
  34. public function getDebugAndCount()
  35. {
  36. return array(
  37. array(false, 1, '->javascripts() returns one url when not in debug mode'),
  38. array(true, 2, '->javascripts() returns many urls when in debug mode'),
  39. );
  40. }
  41. }
  42. class AsseticHelperForTest extends AsseticHelper
  43. {
  44. protected function getAssetUrl(AssetInterface $asset, $options = array())
  45. {
  46. return $asset->getTargetPath();
  47. }
  48. }