RainTPL.php 3.8 KB

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