RainTPL.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. ob_start();
  40. $page->draw('page');
  41. $this->_content = ob_get_contents();
  42. // run a second time from cache
  43. $page->cache('page');
  44. $page->draw('page');
  45. ob_end_clean();
  46. }
  47. public function tearDown()
  48. {
  49. /* Tear Down Routine */
  50. helper::rmdir(PATH . 'tmp');
  51. }
  52. public function testTemplateRendersCorrectly()
  53. {
  54. $this->assertTag(
  55. array(
  56. 'id' => 'cipherdata',
  57. 'content' => htmlspecialchars(helper::getPaste()['data'], ENT_NOQUOTES)
  58. ),
  59. $this->_content,
  60. 'outputs data correctly'
  61. );
  62. $this->assertTag(
  63. array(
  64. 'id' => 'errormessage',
  65. 'content' => self::$error
  66. ),
  67. $this->_content,
  68. 'outputs error correctly'
  69. );
  70. $this->assertTag(
  71. array(
  72. 'id' => 'password',
  73. ),
  74. $this->_content,
  75. 'password available if configured'
  76. );
  77. $this->assertTag(
  78. array(
  79. 'id' => 'opendiscussion',
  80. 'attributes' => array(
  81. 'checked' => 'checked'
  82. ),
  83. ),
  84. $this->_content,
  85. 'checked discussion if configured'
  86. );
  87. $this->assertTag(
  88. array(
  89. 'id' => 'opendisc',
  90. ),
  91. $this->_content,
  92. 'discussions available if configured'
  93. );
  94. // testing version number in JS address, since other instances may not be present in different templates
  95. $this->assertTag(
  96. array(
  97. 'tag' => 'script',
  98. 'attributes' => array(
  99. 'src' => 'js/zerobin.js?' . rawurlencode(self::$version)
  100. ),
  101. ),
  102. $this->_content,
  103. 'outputs version correctly'
  104. );
  105. }
  106. /**
  107. * @expectedException RainTpl_Exception
  108. */
  109. public function testMissingTemplate()
  110. {
  111. $test = new RainTPL;
  112. $test->draw('123456789 does not exist!');
  113. }
  114. }