RainTPL.php 3.6 KB

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