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