ViewTest.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. use PrivateBin\I18n;
  3. use PrivateBin\View;
  4. class ViewTest extends PHPUnit_Framework_TestCase
  5. {
  6. private static $error = 'foo bar';
  7. private static $status = '!*#@?$+';
  8. private static $formatters = array(
  9. 'plaintext' => 'Plain Text',
  10. 'syntaxhighlighting' => 'Source Code',
  11. 'markdown' => 'Markdown',
  12. );
  13. private static $formatter_default = 'plaintext';
  14. private static $expire = array(
  15. '5min' => '5 minutes',
  16. '1hour' => '1 hour',
  17. 'never' => 'Never',
  18. );
  19. private static $expire_default = '1hour';
  20. private static $version = 'Version 1.2.3';
  21. private $_content;
  22. public function setUp()
  23. {
  24. /* Setup Routine */
  25. $page = new View;
  26. $page->assign('NAME', 'PrivateBinTest');
  27. $page->assign('CIPHERDATA', Helper::getPaste()['data']);
  28. $page->assign('ERROR', self::$error);
  29. $page->assign('STATUS', self::$status);
  30. $page->assign('VERSION', self::$version);
  31. $page->assign('DISCUSSION', true);
  32. $page->assign('OPENDISCUSSION', true);
  33. $page->assign('MARKDOWN', true);
  34. $page->assign('SYNTAXHIGHLIGHTING', true);
  35. $page->assign('SYNTAXHIGHLIGHTINGTHEME', 'sons-of-obsidian');
  36. $page->assign('FORMATTER', self::$formatters);
  37. $page->assign('FORMATTERDEFAULT', self::$formatter_default);
  38. $page->assign('BURNAFTERREADINGSELECTED', false);
  39. $page->assign('PASSWORD', true);
  40. $page->assign('FILEUPLOAD', false);
  41. $page->assign('ZEROBINCOMPATIBILITY', false);
  42. $page->assign('NOTICE', 'example');
  43. $page->assign('LANGUAGESELECTION', '');
  44. $page->assign('LANGUAGES', I18n::getLanguageLabels(I18n::getAvailableLanguages()));
  45. $page->assign('EXPIRE', self::$expire);
  46. $page->assign('EXPIREDEFAULT', self::$expire_default);
  47. $page->assign('EXPIRECLONE', true);
  48. $page->assign('URLSHORTENER', '');
  49. ob_start();
  50. $page->draw('page');
  51. $this->_content = ob_get_contents();
  52. ob_end_clean();
  53. }
  54. public function tearDown()
  55. {
  56. /* Tear Down Routine */
  57. }
  58. public function testTemplateRendersCorrectly()
  59. {
  60. $this->assertContains(
  61. '<div id="cipherdata" class="hidden">' .
  62. htmlspecialchars(Helper::getPaste()['data'], ENT_NOQUOTES) .
  63. '</div>',
  64. $this->_content,
  65. 'outputs data correctly'
  66. );
  67. $this->assertRegExp(
  68. '#<div[^>]+id="errormessage"[^>]*>.*' . self::$error . '</div>#',
  69. $this->_content,
  70. 'outputs error correctly'
  71. );
  72. $this->assertRegExp(
  73. '#<[^>]+id="password"[^>]*>#',
  74. $this->_content,
  75. 'password available if configured'
  76. );
  77. $this->assertRegExp(
  78. '#<input[^>]+id="opendiscussion"[^>]*checked="checked"[^>]*>#',
  79. $this->_content,
  80. 'checked discussion if configured'
  81. );
  82. $this->assertRegExp(
  83. '#<[^>]+id="opendisc"[^>]*>#',
  84. $this->_content,
  85. 'discussions available if configured'
  86. );
  87. // testing version number in JS address, since other instances may not be present in different templates
  88. $this->assertRegExp(
  89. '#<script[^>]+src="js/privatebin.js\\?' . rawurlencode(self::$version) . '"[^>]*>#',
  90. $this->_content,
  91. 'outputs version correctly'
  92. );
  93. }
  94. /**
  95. * @expectedException Exception
  96. * @expectedExceptionCode 80
  97. */
  98. public function testMissingTemplate()
  99. {
  100. $test = new View;
  101. $test->draw('123456789 does not exist!');
  102. }
  103. }