RainTPL.php 3.6 KB

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