2
0

TextileAndHtmlTest.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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-2010 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. require_once dirname(dirname(dirname(__FILE__))) . '/TestHelper.php';
  23. if (!defined("PHPUnit_MAIN_METHOD")) {
  24. define("PHPUnit_MAIN_METHOD", "Zend_Markup_TextileAndHtmlTest::main");
  25. }
  26. require_once 'Zend/Markup.php';
  27. /**
  28. * Test class for Zend_Markup_Renderer_Html and Zend_Markup_Parser_Textile
  29. *
  30. * @category Zend
  31. * @package Zend_Markup
  32. * @subpackage UnitTests
  33. * @group Zend_Markup
  34. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  35. * @license http://framework.zend.com/license/new-bsd New BSD License
  36. */
  37. class Zend_Markup_TextileAndHtmlTest extends PHPUnit_Framework_TestCase
  38. {
  39. /**
  40. * Zend_Markup_Renderer_RendererAbstract instance
  41. *
  42. * @var Zend_Markup_Renderer_RendererAbstract
  43. */
  44. protected $_markup;
  45. /**
  46. * Runs the test methods of this class.
  47. *
  48. * @return void
  49. */
  50. public static function main()
  51. {
  52. require_once "PHPUnit/TextUI/TestRunner.php";
  53. $suite = new PHPUnit_Framework_TestSuite("Zend_Markup_MarkupTest");
  54. $result = PHPUnit_TextUI_TestRunner::run($suite);
  55. }
  56. /**
  57. * Sets up the fixture
  58. * This method is called before a test is executed.
  59. *
  60. * @return void
  61. */
  62. public function setUp()
  63. {
  64. $this->_markup = Zend_Markup::factory('Textile', 'html');
  65. }
  66. /**
  67. * Tears down the fixture
  68. * This method is called after a test is executed.
  69. *
  70. * @return void
  71. */
  72. public function tearDown()
  73. {
  74. unset($this->_markup);
  75. }
  76. public function testHtmlTags()
  77. {
  78. $m = $this->_markup;
  79. $this->assertEquals('<p><strong>foo</strong></p>', $m->render('*foo*'));
  80. $this->assertEquals('<p><strong>foo</strong></p>', $m->render('**foo**'));
  81. $this->assertEquals('<p><em>foo</em></p>', $m->render('_foo_'));
  82. $this->assertEquals('<p><em>foo</em></p>', $m->render('__foo__'));
  83. $this->assertEquals('<p><cite>foo</cite></p>', $m->render('??foo??'));
  84. $this->assertEquals('<p><del>foo</del></p>', $m->render('-foo-'));
  85. $this->assertEquals('<p><ins>foo</ins></p>', $m->render('+foo+'));
  86. $this->assertEquals('<p><sup>foo</sup></p>', $m->render('^foo^'));
  87. $this->assertEquals('<p><sub>foo</sub></p>', $m->render('~foo~'));
  88. $this->assertEquals('<p><span>foo</span></p>', $m->render('%foo%'));
  89. $this->assertEquals('<p><acronym title="Teh Zend Framework">TZF</acronym></p>',
  90. $m->render('TZF(Teh Zend Framework)'));
  91. $this->assertEquals('<p><a href="http://framework.zend.com/">Zend Framework</a></p>',
  92. $m->render('"Zend Framework":http://framework.zend.com/'));
  93. $this->assertEquals('<p><h1>foobar</h1></p>',
  94. $m->render('h1. foobar'));
  95. $this->assertEquals('<p><img src="http://framework.zend.com/images/logo.gif" alt="logo" /></p>',
  96. $m->render('!http://framework.zend.com/images/logo.gif!'));
  97. $value = "# Zend Framework\n# Unit Tests";
  98. $expected = '<p><ol style="list-style-type: decimal"><li>Zend Framework</li><li>Unit Tests</li></ol></p>';
  99. $this->assertEquals($expected, $m->render($value));
  100. $value = "* Zend Framework\n* Foo Bar";
  101. $expected = '<p><ul><li>Zend Framework</li><li>Foo Bar</li></ul></p>';
  102. $this->assertEquals($expected, $m->render($value));
  103. }
  104. public function testSimpleAttributes()
  105. {
  106. $m = $this->_markup;
  107. $this->assertEquals('<p><strong class="zend">foo</strong></p>', $m->render('*(zend)foo*'));
  108. $this->assertEquals('<p><strong id="zend">foo</strong></p>', $m->render('*(#zend)foo*'));
  109. $this->assertEquals('<p><strong id="framework" class="zend">foo</strong></p>',
  110. $m->render('*(zend#framework)foo*'));
  111. $this->assertEquals('<p><strong style="color:green;">foo</strong></p>', $m->render('*{color:green;}foo*'));
  112. $this->assertEquals('<p><strong lang="en">foo</strong></p>', $m->render('*[en]foo*'));
  113. }
  114. public function testBlockAttributes()
  115. {
  116. $m = $this->_markup;
  117. $this->assertEquals('<p class="zend">foo</p>', $m->render('p(zend). foo'));
  118. $this->assertEquals('<p id="zend">foo</p>', $m->render('p(#zend). foo'));
  119. $this->assertEquals('<p id="framework" class="zend">foo</p>', $m->render('p(zend#framework). foo'));
  120. $this->assertEquals('<p style="color:green;">foo</p>', $m->render('p{color:green;}. foo'));
  121. $this->assertEquals('<p lang="en">foo</p>', $m->render('p[en]. foo'));
  122. $this->assertEquals('<p style="text-align: right;">foo</p>', $m->render('p>. foo'));
  123. $this->assertEquals('<p style="text-align: left;">foo</p>', $m->render('p<. foo'));
  124. $this->assertEquals('<p style="text-align: justify;">foo</p>', $m->render('p<>. foo'));
  125. $this->assertEquals('<p style="text-align: center;">foo</p>', $m->render('p=. foo'));
  126. }
  127. public function testNewlines()
  128. {
  129. $this->assertEquals("<p>foo</p><p>bar<br />\nbaz</p>", $this->_markup->render("foo\n\nbar\nbaz"));
  130. $this->assertEquals("<p>foo</p><p style=\"color:green;\">bar<br />\nbaz</p>",
  131. $this->_markup->render("foo\n\np{color:green}. bar\nbaz"));
  132. $this->assertEquals("<p>foo</p><p>pahbarbaz</p>",
  133. $this->_markup->render("foo\n\npahbarbaz"));
  134. }
  135. public function testAttributeNotEndingDoesNotThrowNotice()
  136. {
  137. $m = $this->_markup;
  138. $this->assertEquals("<p><strong>[</strong></p>", $m->render('*['));
  139. $this->assertEquals("<p><strong>{</strong></p>", $m->render('*{'));
  140. $this->assertEquals("<p><strong>(</strong></p>", $m->render('*('));
  141. }
  142. public function testTagOnEofDoesNotThrowNotice()
  143. {
  144. $m = $this->_markup;
  145. $this->assertEquals("<p></p>", $m->render('!'));
  146. $this->assertEquals("<p></p>", $m->render('*'));
  147. }
  148. public function testAcronymOnEofDoesNotThrowNotice()
  149. {
  150. $this->assertEquals('<p>ZFC(</p>', $this->_markup->render('ZFC('));
  151. }
  152. }
  153. // Call Zend_Markup_BbcodeTest::main() if this source file is executed directly.
  154. if (PHPUnit_MAIN_METHOD == "Zend_Markup_TextileAndHtmlTest::main") {
  155. Zend_Markup_TextileAndHtmlTest::main();
  156. }