RainTPL.php 3.7 KB

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