RainTPL.php 3.1 KB

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