TextileAndHtmlTest.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Markup
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. if (!defined("PHPUnit_MAIN_METHOD")) {
  23. define("PHPUnit_MAIN_METHOD", "Zend_Markup_TextileAndHtmlTest::main");
  24. }
  25. require_once 'Zend/Markup.php';
  26. /**
  27. * Test class for Zend_Markup_Renderer_Html and Zend_Markup_Parser_Textile
  28. *
  29. * @category Zend
  30. * @package Zend_Markup
  31. * @subpackage UnitTests
  32. * @group Zend_Markup
  33. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  34. * @license http://framework.zend.com/license/new-bsd New BSD License
  35. */
  36. class Zend_Markup_TextileAndHtmlTest extends PHPUnit_Framework_TestCase
  37. {
  38. /**
  39. * Zend_Markup_Renderer_RendererAbstract instance
  40. *
  41. * @var Zend_Markup_Renderer_RendererAbstract
  42. */
  43. protected $_markup;
  44. /**
  45. * Runs the test methods of this class.
  46. *
  47. * @return void
  48. */
  49. public static function main()
  50. {
  51. $suite = new PHPUnit_Framework_TestSuite("Zend_Markup_MarkupTest");
  52. $result = PHPUnit_TextUI_TestRunner::run($suite);
  53. }
  54. /**
  55. * Sets up the fixture
  56. * This method is called before a test is executed.
  57. *
  58. * @return void
  59. */
  60. public function setUp()
  61. {
  62. $this->_markup = Zend_Markup::factory('Textile', 'html');
  63. }
  64. /**
  65. * Tears down the fixture
  66. * This method is called after a test is executed.
  67. *
  68. * @return void
  69. */
  70. public function tearDown()
  71. {
  72. unset($this->_markup);
  73. }
  74. public function testHtmlTags()
  75. {
  76. $m = $this->_markup;
  77. $this->assertEquals('<p><strong>foo</strong></p>', $m->render('*foo*'));
  78. $this->assertEquals('<p><strong>foo</strong> bar</p>', $m->render('**foo** bar'));
  79. $this->assertEquals('<p><em>foo</em></p>', $m->render('_foo_'));
  80. $this->assertEquals('<p><em>foo</em></p>', $m->render('__foo__'));
  81. $this->assertEquals('<p><cite>foo</cite></p>', $m->render('??foo??'));
  82. $this->assertEquals('<p><del>foo</del></p>', $m->render('-foo-'));
  83. $this->assertEquals('<p><ins>foo</ins></p>', $m->render('+foo+'));
  84. $this->assertEquals('<p><sup>foo</sup></p>', $m->render('^foo^'));
  85. $this->assertEquals('<p><sub>foo</sub></p>', $m->render('~foo~'));
  86. $this->assertEquals('<p><span>foo</span></p>', $m->render('%foo%'));
  87. $this->assertEquals('<p><acronym title="Teh Zend Framework">TZF</acronym></p>',
  88. $m->render('TZF(Teh Zend Framework)'));
  89. $this->assertEquals('<p><a href="http://framework.zend.com/">Zend Framework</a></p>',
  90. $m->render('"Zend Framework":http://framework.zend.com/'));
  91. $this->assertEquals('<p><h1>foobar</h1></p>',
  92. $m->render('h1. foobar'));
  93. $this->assertEquals('<p><img src="http://framework.zend.com/images/logo.gif" alt="logo" /></p>',
  94. $m->render('!http://framework.zend.com/images/logo.gif!'));
  95. $value = "# Zend Framework\n# Unit Tests";
  96. $expected = '<p><ol style="list-style-type: decimal"><li>Zend Framework</li><li>Unit Tests</li></ol></p>';
  97. $this->assertEquals($expected, $m->render($value));
  98. $value = "* Zend Framework\n* Foo Bar";
  99. $expected = '<p><ul><li>Zend Framework</li><li>Foo Bar</li></ul></p>';
  100. $this->assertEquals($expected, $m->render($value));
  101. }
  102. public function testSimpleAttributes()
  103. {
  104. $m = $this->_markup;
  105. $this->assertEquals('<p><strong class="zend">foo</strong></p>', $m->render('*(zend)foo*'));
  106. $this->assertEquals('<p><strong id="zend">foo</strong></p>', $m->render('*(#zend)foo*'));
  107. $this->assertEquals('<p><strong id="framework" class="zend">foo</strong></p>',
  108. $m->render('*(zend#framework)foo*'));
  109. $this->assertEquals('<p><strong style="color:green;">foo</strong></p>', $m->render('*{color:green;}foo*'));
  110. $this->assertEquals('<p><strong lang="en">foo</strong></p>', $m->render('*[en]foo*'));
  111. }
  112. public function testBlockAttributes()
  113. {
  114. $m = $this->_markup;
  115. $this->assertEquals('<p class="zend">foo</p>', $m->render('p(zend). foo'));
  116. $this->assertEquals('<p id="zend">foo</p>', $m->render('p(#zend). foo'));
  117. $this->assertEquals('<p id="framework" class="zend">foo</p>', $m->render('p(zend#framework). foo'));
  118. $this->assertEquals('<p style="color:green;">foo</p>', $m->render('p{color:green;}. foo'));
  119. $this->assertEquals('<p lang="en">foo</p>', $m->render('p[en]. foo'));
  120. $this->assertEquals('<p style="text-align: right;">foo</p>', $m->render('p>. foo'));
  121. $this->assertEquals('<p style="text-align: left;">foo</p>', $m->render('p<. foo'));
  122. $this->assertEquals('<p style="text-align: justify;">foo</p>', $m->render('p<>. foo'));
  123. $this->assertEquals('<p style="text-align: center;">foo</p>', $m->render('p=. foo'));
  124. }
  125. public function testNewlines()
  126. {
  127. $this->assertEquals("<p>foo</p><p>bar<br />\nbaz</p>", $this->_markup->render("foo\n\nbar\nbaz"));
  128. $this->assertEquals("<p>foo</p><p style=\"color:green;\">bar<br />\nbaz</p>",
  129. $this->_markup->render("foo\n\np{color:green}. bar\nbaz"));
  130. $this->assertEquals("<p>foo</p><p>pahbarbaz</p>",
  131. $this->_markup->render("foo\n\npahbarbaz"));
  132. }
  133. public function testAttributeNotEndingDoesNotThrowNotice()
  134. {
  135. $m = $this->_markup;
  136. $this->assertEquals("<p><strong>[</strong></p>", $m->render('*['));
  137. $this->assertEquals("<p><strong>{</strong></p>", $m->render('*{'));
  138. $this->assertEquals("<p><strong>(</strong></p>", $m->render('*('));
  139. }
  140. public function testTagOnEofDoesNotThrowNotice()
  141. {
  142. $m = $this->_markup;
  143. $this->assertEquals("<p></p>", $m->render('!'));
  144. $this->assertEquals("<p></p>", $m->render('*'));
  145. }
  146. public function testAcronymOnEofDoesNotThrowNotice()
  147. {
  148. $this->assertEquals('<p>ZFC(</p>', $this->_markup->render('ZFC('));
  149. }
  150. public function testListCombinedWithText()
  151. {
  152. $text = <<<TESTLIST
  153. * foo
  154. * bar
  155. baz
  156. TESTLIST;
  157. $this->assertEquals('<p><ul><li>foo</li><li>bar</li></ul>baz</p>', $this->_markup->render($text));
  158. }
  159. }
  160. // Call Zend_Markup_BbcodeTest::main() if this source file is executed directly.
  161. if (PHPUnit_MAIN_METHOD == "Zend_Markup_TextileAndHtmlTest::main") {
  162. Zend_Markup_TextileAndHtmlTest::main();
  163. }