TypographyHelperTest.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php
  2. App::uses('TypographyHelper', 'Tools.View/Helper');
  3. App::uses('View', 'View');
  4. App::uses('MyCakeTestCase', 'Tools.TestSuite');
  5. /**
  6. * TypographyHelper Test Case
  7. *
  8. */
  9. class TypographyHelperTest extends MyCakeTestCase {
  10. public $Typography;
  11. /**
  12. * setUp method
  13. *
  14. * @return void
  15. */
  16. public function setUp() {
  17. parent::setUp();
  18. Configure::write('Typography.locale', '');
  19. $this->Typography = new TypographyHelper(new View(null));
  20. }
  21. /**
  22. * tearDown method
  23. *
  24. * @return void
  25. */
  26. public function tearDown() {
  27. unset($this->Typography);
  28. parent::tearDown();
  29. }
  30. /**
  31. * testFormatCharacter method
  32. *
  33. * @return void
  34. */
  35. public function testFormatCharacter() {
  36. $strs = array(
  37. '"double quotes"' => '&#8220;double quotes&#8221;',
  38. '"testing" in "theory" that is' => '&#8220;testing&#8221; in &#8220;theory&#8221; that is',
  39. "Here's what I'm" => 'Here&#8217;s what I&#8217;m',
  40. '&' => '&amp;',
  41. '&amp;' => '&amp;',
  42. '&nbsp;' => '&nbsp;',
  43. '--' => '&#8212;',
  44. 'foo...' => 'foo&#8230;',
  45. 'foo..' => 'foo..',
  46. 'foo...bar.' => 'foo&#8230;bar.',
  47. 'test. new' => 'test.&nbsp; new',
  48. );
  49. foreach ($strs as $str => $expected) {
  50. $result = $this->Typography->formatCharacters($str);
  51. //debug($result);
  52. $this->assertEquals($expected, $result);
  53. }
  54. //$this->tearDown();
  55. //$this->setUp();
  56. Configure::write('Typography.locale', 'low');
  57. $strs = array(
  58. '"double quotes"' => '&bdquo;double quotes&#8223;',
  59. '"testing" in "theory" that is' => '&bdquo;testing&#8223; in &bdquo;theory&#8223; that is',
  60. "Here's what I'm" => 'Here&#8219;s what I&#8219;m',
  61. );
  62. foreach ($strs as $str => $expected) {
  63. $result = $this->Typography->formatCharacters($str);
  64. //echo pre($result);
  65. $this->assertEquals($expected, $result);
  66. }
  67. }
  68. /**
  69. * testAutoTypography method
  70. *
  71. * @return void
  72. */
  73. public function testAutoTypography() {
  74. $str = 'Some \'funny\' and "funky" test with a new
  75. paragraph and a
  76. new line tabbed in.';
  77. $res = $this->Typography->autoTypography($str);
  78. //echo pre($res);
  79. //debug($res);
  80. }
  81. /**
  82. * testNl2brExceptPre method
  83. *
  84. * @return void
  85. */
  86. public function testNl2brExceptPre() {
  87. $str = <<<EOH
  88. Hello, I'm a happy string with some new lines.
  89. I like to skip.
  90. Jump
  91. and sing.
  92. <pre>
  93. I am inside a pre tag. Please don't mess with me.
  94. k?
  95. </pre>
  96. That's my story and I'm sticking to it.
  97. The End.
  98. EOH;
  99. $expected = <<<EOH
  100. Hello, I'm a happy string with some new lines.<br />
  101. <br />
  102. I like to skip.<br />
  103. <br />
  104. Jump<br />
  105. <br />
  106. and sing.<br />
  107. <br />
  108. <pre>
  109. I am inside a pre tag. Please don't mess with me.
  110. k?
  111. </pre><br />
  112. <br />
  113. That's my story and I'm sticking to it.<br />
  114. <br />
  115. The End.
  116. EOH;
  117. $result = $this->Typography->nl2brExceptPre($str);
  118. $this->assertEquals($expected, $result);
  119. }
  120. }