1
0

RainTPL.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 $version = 'Version 1.2.3';
  7. private $_content;
  8. public function setUp()
  9. {
  10. /* Setup Routine */
  11. $page = new RainTPL;
  12. $page::configure(array('cache_dir' => 'tmp/'));
  13. // We escape it here because ENT_NOQUOTES can't be used in RainTPL templates.
  14. $page->assign('CIPHERDATA', htmlspecialchars(self::$data, ENT_NOQUOTES));
  15. $page->assign('ERRORMESSAGE', self::$error);
  16. $page->assign('OPENDISCUSSION', false);
  17. $page->assign('VERSION', self::$version);
  18. ob_start();
  19. $page->draw('page');
  20. $this->_content = ob_get_contents();
  21. // run a second time from cache
  22. $page->cache('page');
  23. $page->draw('page');
  24. ob_end_clean();
  25. }
  26. public function tearDown()
  27. {
  28. /* Tear Down Routine */
  29. helper::rmdir(PATH . 'tmp');
  30. }
  31. public function testTemplateRendersCorrectly()
  32. {
  33. $this->assertTag(
  34. array(
  35. 'id' => 'cipherdata',
  36. 'content' => htmlspecialchars(self::$data, ENT_NOQUOTES)
  37. ),
  38. $this->_content,
  39. 'outputs data correctly'
  40. );
  41. $this->assertTag(
  42. array(
  43. 'id' => 'errormessage',
  44. 'content' => self::$error
  45. ),
  46. $this->_content,
  47. 'outputs error correctly'
  48. );
  49. $this->assertTag(
  50. array(
  51. 'id' => 'opendiscussion',
  52. 'attributes' => array(
  53. 'disabled' => 'disabled'
  54. ),
  55. ),
  56. $this->_content,
  57. 'disables discussions if configured'
  58. );
  59. // testing version number in JS address, since other instances may not be present in different templates
  60. $this->assertTag(
  61. array(
  62. 'tag' => 'script',
  63. 'attributes' => array(
  64. 'src' => 'js/zerobin.js?' . rawurlencode(self::$version)
  65. ),
  66. ),
  67. $this->_content,
  68. 'outputs version correctly'
  69. );
  70. }
  71. }