1
0

RainTPL.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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->assertTag(
  57. array(
  58. 'id' => 'cipherdata',
  59. 'content' => htmlspecialchars(helper::getPaste()['data'], ENT_NOQUOTES)
  60. ),
  61. $this->_content,
  62. 'outputs data correctly'
  63. );
  64. $this->assertTag(
  65. array(
  66. 'id' => 'errormessage',
  67. 'content' => self::$error
  68. ),
  69. $this->_content,
  70. 'outputs error correctly'
  71. );
  72. $this->assertTag(
  73. array(
  74. 'id' => 'password',
  75. ),
  76. $this->_content,
  77. 'password available if configured'
  78. );
  79. $this->assertTag(
  80. array(
  81. 'id' => 'opendiscussion',
  82. 'attributes' => array(
  83. 'checked' => 'checked'
  84. ),
  85. ),
  86. $this->_content,
  87. 'checked discussion if configured'
  88. );
  89. $this->assertTag(
  90. array(
  91. 'id' => 'opendisc',
  92. ),
  93. $this->_content,
  94. 'discussions available if configured'
  95. );
  96. // testing version number in JS address, since other instances may not be present in different templates
  97. $this->assertTag(
  98. array(
  99. 'tag' => 'script',
  100. 'attributes' => array(
  101. 'src' => 'js/zerobin.js?' . rawurlencode(self::$version)
  102. ),
  103. ),
  104. $this->_content,
  105. 'outputs version correctly'
  106. );
  107. }
  108. /**
  109. * @expectedException RainTpl_Exception
  110. */
  111. public function testMissingTemplate()
  112. {
  113. $test = new RainTPL;
  114. $test->draw('123456789 does not exist!');
  115. }
  116. }