TYPO3  7.6
FormatterHelperTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11 
12 namespace Symfony\Component\Console\Tests\Helper;
13 
15 
16 class FormatterHelperTest extends \PHPUnit_Framework_TestCase
17 {
18  public function testFormatSection()
19  {
20  $formatter = new FormatterHelper();
21 
22  $this->assertEquals(
23  '<info>[cli]</info> Some text to display',
24  $formatter->formatSection('cli', 'Some text to display'),
25  '::formatSection() formats a message in a section'
26  );
27  }
28 
29  public function testFormatBlock()
30  {
31  $formatter = new FormatterHelper();
32 
33  $this->assertEquals(
34  '<error> Some text to display </error>',
35  $formatter->formatBlock('Some text to display', 'error'),
36  '::formatBlock() formats a message in a block'
37  );
38 
39  $this->assertEquals(
40  '<error> Some text to display </error>'."\n".
41  '<error> foo bar </error>',
42  $formatter->formatBlock(array('Some text to display', 'foo bar'), 'error'),
43  '::formatBlock() formats a message in a block'
44  );
45 
46  $this->assertEquals(
47  '<error> </error>'."\n".
48  '<error> Some text to display </error>'."\n".
49  '<error> </error>',
50  $formatter->formatBlock('Some text to display', 'error', true),
51  '::formatBlock() formats a message in a block'
52  );
53  }
54 
56  {
57  if (!function_exists('mb_detect_encoding')) {
58  $this->markTestSkipped('This test requires mbstring to work.');
59  }
60 
61  $formatter = new FormatterHelper();
62 
63  $this->assertEquals(
64  '<error> </error>'."\n".
65  '<error> Du texte à afficher </error>'."\n".
66  '<error> </error>',
67  $formatter->formatBlock('Du texte à afficher', 'error', true),
68  '::formatBlock() formats a message in a block'
69  );
70  }
71 
73  {
74  if (!extension_loaded('mbstring')) {
75  $this->markTestSkipped('This test requires mbstring to work.');
76  }
77  $formatter = new FormatterHelper();
78  $this->assertEquals(
79  '<error> </error>'."\n".
80  '<error> 表示するテキスト </error>'."\n".
81  '<error> </error>',
82  $formatter->formatBlock('表示するテキスト', 'error', true),
83  '::formatBlock() formats a message in a block'
84  );
85  }
86 
87  public function testFormatBlockLGEscaping()
88  {
89  $formatter = new FormatterHelper();
90 
91  $this->assertEquals(
92  '<error> </error>'."\n".
93  '<error> <info>some info</info> </error>'."\n".
94  '<error> </error>',
95  $formatter->formatBlock('<info>some info</info>', 'error', true),
96  '::formatBlock() escapes \'<\' chars'
97  );
98  }
99 }