FormatterHelperTest.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. $formatter = new FormatterHelper();
  48. $this->assertEquals(
  49. '<error> </error>'."\n".
  50. '<error> Du texte à afficher </error>'."\n".
  51. '<error> </error>',
  52. $formatter->formatBlock('Du texte à afficher', 'error', true),
  53. '::formatBlock() formats a message in a block'
  54. );
  55. }
  56. public function testFormatBlockWithDoubleWidthDiacriticLetters()
  57. {
  58. $formatter = new FormatterHelper();
  59. $this->assertEquals(
  60. '<error> </error>'."\n".
  61. '<error> 表示するテキスト </error>'."\n".
  62. '<error> </error>',
  63. $formatter->formatBlock('表示するテキスト', 'error', true),
  64. '::formatBlock() formats a message in a block'
  65. );
  66. }
  67. public function testFormatBlockLGEscaping()
  68. {
  69. $formatter = new FormatterHelper();
  70. $this->assertEquals(
  71. '<error> </error>'."\n".
  72. '<error> \<info>some info\</info> </error>'."\n".
  73. '<error> </error>',
  74. $formatter->formatBlock('<info>some info</info>', 'error', true),
  75. '::formatBlock() escapes \'<\' chars'
  76. );
  77. }
  78. }