| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- <?php
- namespace Tools\Test\TestCase\View\Helper;
- use Cake\Core\Configure;
- use Cake\View\View;
- use Tools\TestSuite\TestCase;
- use Tools\View\Helper\TypographyHelper;
- /**
- * TypographyHelper Test Case
- */
- class TypographyHelperTest extends TestCase {
- /**
- * @var \Tools\View\Helper\TypographyHelper
- */
- public $Typography;
- /**
- * SetUp method
- *
- * @return void
- */
- public function setUp() {
- parent::setUp();
- Configure::delete('Typography.locale');
- Configure::write('App.language', 'eng');
- $this->Typography = new TypographyHelper(new View(null));
- }
- /**
- * TearDown method
- *
- * @return void
- */
- public function tearDown() {
- unset($this->Typography);
- parent::tearDown();
- }
- /**
- * TestFormatCharacter method
- *
- * @return void
- */
- public function testFormatCharacter() {
- $strs = [
- '"double quotes"' => '“double quotes”',
- '"testing" in "theory" that is' => '“testing” in “theory” that is',
- "Here's what I'm" => 'Here’s what I’m',
- '&' => '&',
- '&' => '&',
- ' ' => ' ',
- '--' => '—',
- 'foo...' => 'foo…',
- 'foo..' => 'foo..',
- 'foo...bar.' => 'foo…bar.',
- 'test. new' => 'test. new',
- ];
- foreach ($strs as $str => $expected) {
- $result = $this->Typography->formatCharacters($str);
- //debug($result);
- $this->assertEquals($expected, $result);
- }
- Configure::write('Typography.locale', 'low');
- $strs = [
- '"double quotes"' => '„double quotes‟',
- '"testing" in "theory" that is' => '„testing‟ in „theory‟ that is',
- "Here's what I'm" => 'Here’s what I’m',
- ];
- foreach ($strs as $str => $expected) {
- $result = $this->Typography->formatCharacters($str);
- //echo pre($result);
- $this->assertEquals($expected, $result);
- }
- Configure::write('Typography.locale', 'angle');
- $strs = [
- '"double quotes"' => '«double quotes»',
- '"testing" in "theory" that is' => '«testing» in «theory» that is',
- "Here's what I'm" => 'Here’s what I’m',
- ];
- foreach ($strs as $str => $expected) {
- $result = $this->Typography->formatCharacters($str);
- //echo debug($result);
- $this->assertEquals($expected, $result);
- }
- }
- /**
- * TestAutoTypography method
- *
- * @return void
- */
- public function testAutoTypography() {
- $str = 'Some \'funny\' and "funky" test';
- $result = $this->Typography->autoTypography($str);
- //echo pre($result);
- $expected = '<p>Some ‘funny’ and “funky” test</p>';
- $this->assertEquals($expected, $result);
- Configure::write('App.language', 'deu');
- $result = $this->Typography->autoTypography($str);
- //echo pre($result);
- $expected = '<p>Some ‚funny‛ and „funky‟ test</p>';
- $this->assertEquals($expected, $result);
- Configure::write('App.language', 'fra');
- $result = $this->Typography->autoTypography($str);
- //echo debug($result);
- $expected = '<p>Some ‹funny› and «funky» test</p>';
- $this->assertEquals($expected, $result);
- }
- /**
- * TestNl2brExceptPre method
- *
- * @return void
- */
- public function testNl2brExceptPre() {
- $str = <<<EOH
- Hello, I'm a happy string with some new lines.
- I like to skip.
- Jump
- and sing.
- <pre>
- I am inside a pre tag. Please don't mess with me.
- k?
- </pre>
- That's my story and I'm sticking to it.
- The End.
- EOH;
- $expected = <<<EOH
- Hello, I'm a happy string with some new lines.<br />
- <br />
- I like to skip.<br />
- <br />
- Jump<br />
- <br />
- and sing.<br />
- <br />
- <pre>
- I am inside a pre tag. Please don't mess with me.
- k?
- </pre><br />
- <br />
- That's my story and I'm sticking to it.<br />
- <br />
- The End.
- EOH;
- $result = $this->Typography->nl2brExceptPre($str);
- $this->assertEquals($expected, $result);
- }
- }
|