FormatterHelperTest.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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\Console\Tests\Helper;
  11. use Symfony\Component\Console\Helper\FormatterHelper;
  12. class FormatterHelperTest extends \PHPUnit_Framework_TestCase
  13. {
  14. public function testFormatSection()
  15. {
  16. $formatter = new FormatterHelper();
  17. $this->assertEquals(
  18. '<info>[cli]</info> Some text to display',
  19. $formatter->formatSection('cli', 'Some text to display'),
  20. '::formatSection() formats a message in a section'
  21. );
  22. }
  23. public function testFormatBlock()
  24. {
  25. $formatter = new FormatterHelper();
  26. $this->assertEquals(
  27. '<error> Some text to display </error>',
  28. $formatter->formatBlock('Some text to display', 'error'),
  29. '::formatBlock() formats a message in a block'
  30. );
  31. $this->assertEquals(
  32. '<error> Some text to display </error>'."\n".
  33. '<error> foo bar </error>',
  34. $formatter->formatBlock(array('Some text to display', 'foo bar'), 'error'),
  35. '::formatBlock() formats a message in a block'
  36. );
  37. $this->assertEquals(
  38. '<error> </error>'."\n".
  39. '<error> Some text to display </error>'."\n".
  40. '<error> </error>',
  41. $formatter->formatBlock('Some text to display', 'error', true),
  42. '::formatBlock() formats a message in a block'
  43. );
  44. }
  45. public function testFormatBlockWithDiacriticLetters()
  46. {
  47. if (!function_exists('mb_detect_encoding')) {
  48. $this->markTestSkipped('This test requires mbstring to work.');
  49. }
  50. $formatter = new FormatterHelper();
  51. $this->assertEquals(
  52. '<error> </error>'."\n".
  53. '<error> Du texte à afficher </error>'."\n".
  54. '<error> </error>',
  55. $formatter->formatBlock('Du texte à afficher', 'error', true),
  56. '::formatBlock() formats a message in a block'
  57. );
  58. }
  59. public function testFormatBlockWithDoubleWidthDiacriticLetters()
  60. {
  61. if (!extension_loaded('mbstring')) {
  62. $this->markTestSkipped('This test requires mbstring to work.');
  63. }
  64. $formatter = new FormatterHelper();
  65. $this->assertEquals(
  66. '<error> </error>'."\n".
  67. '<error> 表示するテキスト </error>'."\n".
  68. '<error> </error>',
  69. $formatter->formatBlock('表示するテキスト', 'error', true),
  70. '::formatBlock() formats a message in a block'
  71. );
  72. }
  73. public function testFormatBlockLGEscaping()
  74. {
  75. $formatter = new FormatterHelper();
  76. $this->assertEquals(
  77. '<error> </error>'."\n".
  78. '<error> \<info>some info\</info> </error>'."\n".
  79. '<error> </error>',
  80. $formatter->formatBlock('<info>some info</info>', 'error', true),
  81. '::formatBlock() escapes \'<\' chars'
  82. );
  83. }
  84. }