RainTPL.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. class RainTPLTest extends PHPUnit_Framework_TestCase
  3. {
  4. private static $error = 'foo bar';
  5. private static $status = '!*#@?$+';
  6. private static $expire = array(
  7. '5min' => '5 minutes',
  8. '1hour' => '1 hour',
  9. 'never' => 'Never',
  10. );
  11. private static $expire_default = '1hour';
  12. private static $version = 'Version 1.2.3';
  13. private $_content;
  14. public function setUp()
  15. {
  16. /* Setup Routine */
  17. $page = new RainTPL;
  18. $page::configure(array('cache_dir' => 'tmp/'));
  19. $page::$path_replace = false;
  20. // We escape it here because ENT_NOQUOTES can't be used in RainTPL templates.
  21. $page->assign('CIPHERDATA', htmlspecialchars(helper::getPaste()['data'], ENT_NOQUOTES));
  22. $page->assign('ERROR', self::$error);
  23. $page->assign('STATUS', self::$status);
  24. $page->assign('VERSION', self::$version);
  25. $page->assign('DISCUSSION', true);
  26. $page->assign('OPENDISCUSSION', true);
  27. $page->assign('MARKDOWN', true);
  28. $page->assign('SYNTAXHIGHLIGHTING', true);
  29. $page->assign('SYNTAXHIGHLIGHTINGTHEME', 'sons-of-obsidian');
  30. $page->assign('BURNAFTERREADINGSELECTED', false);
  31. $page->assign('PASSWORD', true);
  32. $page->assign('FILEUPLOAD', false);
  33. $page->assign('BASE64JSVERSION', '2.1.9');
  34. $page->assign('NOTICE', 'example');
  35. $page->assign('LANGUAGESELECTION', '');
  36. $page->assign('LANGUAGES', i18n::getLanguageLabels(i18n::getAvailableLanguages()));
  37. $page->assign('EXPIRE', self::$expire);
  38. $page->assign('EXPIREDEFAULT', self::$expire_default);
  39. $page->assign('EXPIRECLONE', true);
  40. $page->assign('URLSHORTENER', '');
  41. ob_start();
  42. $page->draw('page');
  43. $this->_content = ob_get_contents();
  44. // run a second time from cache
  45. $page->cache('page');
  46. $page->draw('page');
  47. ob_end_clean();
  48. }
  49. public function tearDown()
  50. {
  51. /* Tear Down Routine */
  52. helper::rmdir(PATH . 'tmp');
  53. }
  54. public function testTemplateRendersCorrectly()
  55. {
  56. $this->assertContains(
  57. '<div id="cipherdata" class="hidden">' .
  58. htmlspecialchars(helper::getPaste()['data'], ENT_NOQUOTES) .
  59. '</div>',
  60. $this->_content,
  61. 'outputs data correctly'
  62. );
  63. $this->assertRegExp(
  64. '#<div[^>]+id="errormessage"[^>]*>.*' . self::$error . '</div>#',
  65. $this->_content,
  66. 'outputs error correctly'
  67. );
  68. $this->assertRegExp(
  69. '#<[^>]+id="password"[^>]*>#',
  70. $this->_content,
  71. 'password available if configured'
  72. );
  73. $this->assertRegExp(
  74. '#<input[^>]+id="opendiscussion"[^>]*checked="checked"[^>]*>#',
  75. $this->_content,
  76. 'checked discussion if configured'
  77. );
  78. $this->assertRegExp(
  79. '#<[^>]+id="opendisc"[^>]*>#',
  80. $this->_content,
  81. 'discussions available if configured'
  82. );
  83. // testing version number in JS address, since other instances may not be present in different templates
  84. $this->assertRegExp(
  85. '#<script[^>]+src="js/zerobin.js\\?' . rawurlencode(self::$version) . '"[^>]*>#',
  86. $this->_content,
  87. 'outputs version correctly'
  88. );
  89. }
  90. /**
  91. * @expectedException RainTpl_Exception
  92. */
  93. public function testMissingTemplate()
  94. {
  95. $test = new RainTPL;
  96. $test->draw('123456789 does not exist!');
  97. }
  98. }