ParserIntegrityTest.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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_Json
  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_ParserIntegrityTest::main");
  25. }
  26. require_once 'Zend/Markup.php';
  27. /**
  28. * @category Zend
  29. * @package Zend_Markup
  30. * @subpackage UnitTests
  31. * @group Zend_Markup
  32. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  33. * @license http://framework.zend.com/license/new-bsd New BSD License
  34. */
  35. class Zend_Markup_ParserIntegrityTest extends PHPUnit_Framework_TestCase
  36. {
  37. /**
  38. * Runs the test methods of this class.
  39. *
  40. * @return void
  41. */
  42. public static function main()
  43. {
  44. require_once "PHPUnit/TextUI/TestRunner.php";
  45. $suite = new PHPUnit_Framework_TestSuite("Zend_Markup_MarkupTest");
  46. $result = PHPUnit_TextUI_TestRunner::run($suite);
  47. }
  48. public function testBbcodeParser()
  49. {
  50. $parser = Zend_Markup::factory('bbcode')->getParser();
  51. $value = '[b][s][i]foobar[/i][/s][/b]';
  52. $output = '';
  53. $tree = $parser->parse($value);
  54. // iterate trough the tree and check if we can generate the original value
  55. $iterator = new RecursiveIteratorIterator($tree, RecursiveIteratorIterator::SELF_FIRST);
  56. foreach ($iterator as $token) {
  57. $output .= $token->getTag();
  58. if ($token->getStopper() != '') {
  59. $token->addChild(new Zend_Markup_Token(
  60. $token->getStopper(),
  61. Zend_Markup_Token::TYPE_NONE,
  62. '', array(), $token)
  63. );
  64. }
  65. }
  66. $this->assertEquals($value, $output);
  67. }
  68. }
  69. // Call Zend_Markup_BbcodeTest::main() if this source file is executed directly.
  70. if (PHPUnit_MAIN_METHOD == "Zend_Markup_ParserIntegrityTest::main") {
  71. Zend_Markup_BbcodeTest::main();
  72. }