CodeExtensionTest.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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\Bridge\Twig\Tests\Extension;
  11. use Symfony\Bridge\Twig\Extension\CodeExtension;
  12. class CodeExtensionTest extends \PHPUnit_Framework_TestCase
  13. {
  14. protected $helper;
  15. public function testFormatFile()
  16. {
  17. $expected = sprintf('<a href="txmt://open?url=file://%s&amp;line=25" title="Click to open this file" class="file_link">%s at line 25</a>', __FILE__, __FILE__);
  18. $this->assertEquals($expected, $this->getExtension()->formatFile(__FILE__, 25));
  19. }
  20. /**
  21. * @dataProvider getClassNameProvider
  22. */
  23. public function testGettingClassAbbreviation($class, $abbr)
  24. {
  25. $this->assertEquals($this->getExtension()->abbrClass($class), $abbr);
  26. }
  27. /**
  28. * @dataProvider getMethodNameProvider
  29. */
  30. public function testGettingMethodAbbreviation($method, $abbr)
  31. {
  32. $this->assertEquals($this->getExtension()->abbrMethod($method), $abbr);
  33. }
  34. public function getClassNameProvider()
  35. {
  36. return array(
  37. array('F\Q\N\Foo', '<abbr title="F\Q\N\Foo">Foo</abbr>'),
  38. array('Bare', '<abbr title="Bare">Bare</abbr>'),
  39. );
  40. }
  41. public function getMethodNameProvider()
  42. {
  43. return array(
  44. array('F\Q\N\Foo::Method', '<abbr title="F\Q\N\Foo">Foo</abbr>::Method()'),
  45. array('Bare::Method', '<abbr title="Bare">Bare</abbr>::Method()'),
  46. array('Closure', '<abbr title="Closure">Closure</abbr>'),
  47. array('Method', '<abbr title="Method">Method</abbr>()')
  48. );
  49. }
  50. public function testGetName()
  51. {
  52. $this->assertEquals('code', $this->getExtension()->getName());
  53. }
  54. protected function getExtension()
  55. {
  56. return new CodeExtension('txmt://open?url=file://%f&line=%l', '/root', 'UTF-8');
  57. }
  58. }