FormatterHelperTest.php 3.0 KB

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