TextileAndHtmlTest.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <?php
  2. // Call Zend_Markup_TextileAndHtmlTest::main()
  3. // if this source file is executed directly.
  4. if (!defined("PHPUnit_MAIN_METHOD")) {
  5. define("PHPUnit_MAIN_METHOD", "Zend_Markup_TextileAndHtmlTest::main");
  6. }
  7. require_once dirname(__FILE__) . '/../../TestHelper.php';
  8. require_once 'Zend/Markup.php';
  9. /**
  10. * Test class for Zend_Markup_Renderer_Html and Zend_Markup_Parser_Textile
  11. */
  12. class Zend_Markup_TextileAndHtmlTest extends PHPUnit_Framework_TestCase
  13. {
  14. /**
  15. * Zend_Markup_Renderer_RendererAbstract instance
  16. *
  17. * @var Zend_Markup_Renderer_RendererAbstract
  18. */
  19. protected $_markup;
  20. /**
  21. * Runs the test methods of this class.
  22. *
  23. * @return void
  24. */
  25. public static function main()
  26. {
  27. require_once "PHPUnit/TextUI/TestRunner.php";
  28. $suite = new PHPUnit_Framework_TestSuite("Zend_Markup_MarkupTest");
  29. $result = PHPUnit_TextUI_TestRunner::run($suite);
  30. }
  31. /**
  32. * Sets up the fixture
  33. * This method is called before a test is executed.
  34. *
  35. * @return void
  36. */
  37. public function setUp()
  38. {
  39. $this->_markup = Zend_Markup::factory('Textile', 'html');
  40. }
  41. /**
  42. * Tears down the fixture
  43. * This method is called after a test is executed.
  44. *
  45. * @return void
  46. */
  47. public function tearDown()
  48. {
  49. unset($this->_markup);
  50. }
  51. public function testHtmlTags()
  52. {
  53. $m = $this->_markup;
  54. $this->assertEquals('<p><strong>foo</strong></p>', $m->render('*foo*'));
  55. $this->assertEquals('<p><strong>foo</strong></p>', $m->render('**foo**'));
  56. $this->assertEquals('<p><em>foo</em></p>', $m->render('_foo_'));
  57. $this->assertEquals('<p><em>foo</em></p>', $m->render('__foo__'));
  58. $this->assertEquals('<p><cite>foo</cite></p>', $m->render('??foo??'));
  59. $this->assertEquals('<p><del>foo</del></p>', $m->render('-foo-'));
  60. $this->assertEquals('<p><ins>foo</ins></p>', $m->render('+foo+'));
  61. $this->assertEquals('<p><sup>foo</sup></p>', $m->render('^foo^'));
  62. $this->assertEquals('<p><sub>foo</sub></p>', $m->render('~foo~'));
  63. $this->assertEquals('<p><span>foo</span></p>', $m->render('%foo%'));
  64. $this->assertEquals('<p><acronym title="Teh Zend Framework">TZF</acronym></p>',
  65. $m->render('TZF(Teh Zend Framework)'));
  66. $this->assertEquals('<p><a href="http://framework.zend.com/">Zend Framework</a></p>',
  67. $m->render('"Zend Framework":http://framework.zend.com/'));
  68. $this->assertEquals('<p><h1>foobar</h1></p>',
  69. $m->render('h1. foobar'));
  70. $this->assertEquals('<p><img src="http://framework.zend.com/images/logo.gif" alt="logo" /></p>',
  71. $m->render('!http://framework.zend.com/images/logo.gif!'));
  72. $value = "# Zend Framework\n# Unit Tests";
  73. $expected = '<p><ol style="list-style-type: decimal"><li>Zend Framework</li><li>Unit Tests</li></ol></p>';
  74. $this->assertEquals($expected, $m->render($value));
  75. $value = "* Zend Framework\n* Foo Bar";
  76. $expected = '<p><ul><li>Zend Framework</li><li>Foo Bar</li></ul></p>';
  77. $this->assertEquals($expected, $m->render($value));
  78. }
  79. public function testSimpleAttributes()
  80. {
  81. $m = $this->_markup;
  82. $this->assertEquals('<p><strong class="zend">foo</strong></p>', $m->render('*(zend)foo*'));
  83. $this->assertEquals('<p><strong id="zend">foo</strong></p>', $m->render('*(#zend)foo*'));
  84. $this->assertEquals('<p><strong id="framework" class="zend">foo</strong></p>',
  85. $m->render('*(zend#framework)foo*'));
  86. $this->assertEquals('<p><strong style="color:green;">foo</strong></p>', $m->render('*{color:green;}foo*'));
  87. $this->assertEquals('<p><strong lang="en">foo</strong></p>', $m->render('*[en]foo*'));
  88. }
  89. public function testBlockAttributes()
  90. {
  91. $m = $this->_markup;
  92. $this->assertEquals('<p class="zend">foo</p>', $m->render('p(zend). foo'));
  93. $this->assertEquals('<p id="zend">foo</p>', $m->render('p(#zend). foo'));
  94. $this->assertEquals('<p id="framework" class="zend">foo</p>', $m->render('p(zend#framework). foo'));
  95. $this->assertEquals('<p style="color:green;">foo</p>', $m->render('p{color:green;}. foo'));
  96. $this->assertEquals('<p lang="en">foo</p>', $m->render('p[en]. foo'));
  97. $this->assertEquals('<p style="text-align: right;">foo</p>', $m->render('p>. foo'));
  98. $this->assertEquals('<p style="text-align: left;">foo</p>', $m->render('p<. foo'));
  99. $this->assertEquals('<p style="text-align: justify;">foo</p>', $m->render('p<>. foo'));
  100. $this->assertEquals('<p style="text-align: center;">foo</p>', $m->render('p=. foo'));
  101. }
  102. public function testNewlines()
  103. {
  104. $this->assertEquals("<p>foo</p><p>bar<br />\nbaz</p>", $this->_markup->render("foo\n\nbar\nbaz"));
  105. $this->assertEquals("<p>foo</p><p style=\"color:green;\">bar<br />\nbaz</p>",
  106. $this->_markup->render("foo\n\np{color:green}. bar\nbaz"));
  107. $this->assertEquals("<p>foo</p><p>pahbarbaz</p>",
  108. $this->_markup->render("foo\n\npahbarbaz"));
  109. }
  110. public function testAttributeNotEndingDoesNotThrowNotice()
  111. {
  112. $m = $this->_markup;
  113. $this->assertEquals("<p><strong>[</strong></p>", $m->render('*['));
  114. $this->assertEquals("<p><strong>{</strong></p>", $m->render('*{'));
  115. $this->assertEquals("<p><strong>(</strong></p>", $m->render('*('));
  116. }
  117. public function testTagOnEofDoesNotThrowNotice()
  118. {
  119. $m = $this->_markup;
  120. $this->assertEquals("<p></p>", $m->render('!'));
  121. $this->assertEquals("<p>*</p>", $m->render('*'));
  122. }
  123. public function testAcronymOnEofDoesNotThrowNotice()
  124. {
  125. $this->assertEquals('<p>ZFC(</p>', $this->_markup->render('ZFC('));
  126. }
  127. }
  128. // Call Zend_Markup_BbcodeTest::main() if this source file is executed directly.
  129. if (PHPUnit_MAIN_METHOD == "Zend_Markup_TextileAndHtmlTest::main") {
  130. Zend_Markup_TextileAndHtmlTest::main();
  131. }