2015-08-15 16:32:31 +00:00
|
|
|
<?php
|
2016-07-21 15:09:48 +00:00
|
|
|
|
2020-10-10 10:08:58 +00:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2016-08-09 09:54:42 +00:00
|
|
|
use PrivateBin\I18n;
|
|
|
|
use PrivateBin\View;
|
2016-07-21 15:09:48 +00:00
|
|
|
|
2020-10-10 10:08:58 +00:00
|
|
|
class ViewTest extends TestCase
|
2015-08-15 16:32:31 +00:00
|
|
|
{
|
|
|
|
private static $error = 'foo bar';
|
|
|
|
|
|
|
|
private static $status = '!*#@?$+';
|
|
|
|
|
2016-07-19 12:02:26 +00:00
|
|
|
private static $formatters = array(
|
2016-10-29 08:24:08 +00:00
|
|
|
'plaintext' => 'Plain Text',
|
2016-07-19 12:02:26 +00:00
|
|
|
'syntaxhighlighting' => 'Source Code',
|
2016-10-29 08:24:08 +00:00
|
|
|
'markdown' => 'Markdown',
|
2016-07-19 12:02:26 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
private static $formatter_default = 'plaintext';
|
|
|
|
|
2015-08-15 16:32:31 +00:00
|
|
|
private static $expire = array(
|
2016-10-29 08:24:08 +00:00
|
|
|
'5min' => '5 minutes',
|
2015-08-15 16:32:31 +00:00
|
|
|
'1hour' => '1 hour',
|
|
|
|
'never' => 'Never',
|
|
|
|
);
|
|
|
|
|
|
|
|
private static $expire_default = '1hour';
|
|
|
|
|
|
|
|
private static $version = 'Version 1.2.3';
|
|
|
|
|
2017-01-08 07:28:05 +00:00
|
|
|
private $_content = array();
|
2015-08-15 16:32:31 +00:00
|
|
|
|
2020-10-10 10:22:20 +00:00
|
|
|
public function setUp(): void
|
2015-08-15 16:32:31 +00:00
|
|
|
{
|
|
|
|
/* Setup Routine */
|
2016-08-09 09:54:42 +00:00
|
|
|
$page = new View;
|
2017-01-01 15:33:11 +00:00
|
|
|
$page->assign('NAME', 'PrivateBinTest');
|
2020-07-03 19:00:42 +00:00
|
|
|
$page->assign('BASEPATH', '');
|
2015-08-15 16:32:31 +00:00
|
|
|
$page->assign('ERROR', self::$error);
|
|
|
|
$page->assign('STATUS', self::$status);
|
|
|
|
$page->assign('VERSION', self::$version);
|
2015-08-30 22:01:35 +00:00
|
|
|
$page->assign('DISCUSSION', true);
|
|
|
|
$page->assign('OPENDISCUSSION', true);
|
2015-09-12 15:33:16 +00:00
|
|
|
$page->assign('MARKDOWN', true);
|
2015-08-15 16:32:31 +00:00
|
|
|
$page->assign('SYNTAXHIGHLIGHTING', true);
|
2015-08-17 21:18:33 +00:00
|
|
|
$page->assign('SYNTAXHIGHLIGHTINGTHEME', 'sons-of-obsidian');
|
2016-07-19 12:02:26 +00:00
|
|
|
$page->assign('FORMATTER', self::$formatters);
|
|
|
|
$page->assign('FORMATTERDEFAULT', self::$formatter_default);
|
2015-08-30 22:01:35 +00:00
|
|
|
$page->assign('BURNAFTERREADINGSELECTED', false);
|
|
|
|
$page->assign('PASSWORD', true);
|
2015-09-16 20:51:48 +00:00
|
|
|
$page->assign('FILEUPLOAD', false);
|
2016-08-16 09:11:03 +00:00
|
|
|
$page->assign('ZEROBINCOMPATIBILITY', false);
|
2020-10-13 05:28:35 +00:00
|
|
|
$page->assign('INFO', 'example');
|
2015-08-17 21:18:33 +00:00
|
|
|
$page->assign('NOTICE', 'example');
|
2015-09-19 15:23:10 +00:00
|
|
|
$page->assign('LANGUAGESELECTION', '');
|
2017-01-01 15:33:11 +00:00
|
|
|
$page->assign('LANGUAGES', I18n::getLanguageLabels(I18n::getAvailableLanguages()));
|
2015-08-15 16:32:31 +00:00
|
|
|
$page->assign('EXPIRE', self::$expire);
|
|
|
|
$page->assign('EXPIREDEFAULT', self::$expire_default);
|
2016-01-31 08:56:06 +00:00
|
|
|
$page->assign('URLSHORTENER', '');
|
2018-01-02 06:56:46 +00:00
|
|
|
$page->assign('QRCODE', true);
|
2019-06-17 19:40:37 +00:00
|
|
|
$page->assign('HTTPWARNING', true);
|
2019-09-19 17:14:48 +00:00
|
|
|
$page->assign('HTTPSLINK', 'https://example.com/');
|
2019-06-23 17:45:40 +00:00
|
|
|
$page->assign('COMPRESSION', 'zlib');
|
2022-03-13 16:24:47 +00:00
|
|
|
$page->assign('CSPHEADER', 'default-src \'none\'');
|
2017-01-08 07:28:05 +00:00
|
|
|
|
|
|
|
$dir = dir(PATH . 'tpl');
|
|
|
|
while (false !== ($file = $dir->read())) {
|
|
|
|
if (substr($file, -4) === '.php') {
|
|
|
|
$template = substr($file, 0, -4);
|
|
|
|
ob_start();
|
|
|
|
$page->draw($template);
|
|
|
|
$this->_content[$template] = ob_get_contents();
|
|
|
|
ob_end_clean();
|
|
|
|
}
|
|
|
|
}
|
2017-01-08 09:02:07 +00:00
|
|
|
// check bootstrap variants
|
|
|
|
$template = 'bootstrap-page';
|
|
|
|
ob_start();
|
|
|
|
$page->draw($template);
|
|
|
|
$this->_content[$template] = ob_get_contents();
|
|
|
|
ob_end_clean();
|
|
|
|
foreach (array('-dark', '-compact') as $suffix) {
|
|
|
|
$template = 'bootstrap' . $suffix;
|
|
|
|
ob_start();
|
|
|
|
$page->draw($template);
|
|
|
|
$this->_content[$template] = ob_get_contents();
|
|
|
|
ob_end_clean();
|
|
|
|
|
|
|
|
$template .= '-page';
|
|
|
|
ob_start();
|
|
|
|
$page->draw($template);
|
|
|
|
$this->_content[$template] = ob_get_contents();
|
|
|
|
ob_end_clean();
|
|
|
|
}
|
2015-08-15 16:32:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testTemplateRendersCorrectly()
|
|
|
|
{
|
2017-01-08 07:28:05 +00:00
|
|
|
foreach ($this->_content as $template => $content) {
|
2020-10-11 08:31:24 +00:00
|
|
|
$this->assertMatchesRegularExpression(
|
2017-03-12 13:16:08 +00:00
|
|
|
'#<div[^>]+id="errormessage"[^>]*>.*' . self::$error . '#s',
|
2017-01-08 07:28:05 +00:00
|
|
|
$content,
|
|
|
|
$template . ': outputs error correctly'
|
|
|
|
);
|
2022-10-23 07:12:31 +00:00
|
|
|
if ($template === 'yourlsproxy') {
|
|
|
|
// yourlsproxy template only displays error message
|
|
|
|
continue;
|
|
|
|
}
|
2020-10-11 08:31:24 +00:00
|
|
|
$this->assertMatchesRegularExpression(
|
2017-01-08 07:28:05 +00:00
|
|
|
'#<[^>]+id="password"[^>]*>#',
|
|
|
|
$content,
|
|
|
|
$template . ': password available if configured'
|
|
|
|
);
|
2020-10-11 08:31:24 +00:00
|
|
|
$this->assertMatchesRegularExpression(
|
2017-01-08 07:28:05 +00:00
|
|
|
'#<input[^>]+id="opendiscussion"[^>]*checked="checked"[^>]*>#',
|
|
|
|
$content,
|
|
|
|
$template . ': checked discussion if configured'
|
|
|
|
);
|
2020-10-11 08:31:24 +00:00
|
|
|
$this->assertMatchesRegularExpression(
|
2017-02-25 08:35:55 +00:00
|
|
|
'#<[^>]+id="opendiscussionoption"[^>]*>#',
|
2017-01-08 07:28:05 +00:00
|
|
|
$content,
|
|
|
|
$template . ': discussions available if configured'
|
|
|
|
);
|
|
|
|
// testing version number in JS address, since other instances may not be present in different templates
|
2020-10-11 08:31:24 +00:00
|
|
|
$this->assertMatchesRegularExpression(
|
2017-01-08 07:28:05 +00:00
|
|
|
'#<script[^>]+src="js/privatebin.js\\?' . rawurlencode(self::$version) . '"[^>]*>#',
|
|
|
|
$content,
|
|
|
|
$template . ': outputs version correctly'
|
|
|
|
);
|
|
|
|
}
|
2015-08-15 16:32:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testMissingTemplate()
|
|
|
|
{
|
2016-08-09 09:54:42 +00:00
|
|
|
$test = new View;
|
2020-10-11 08:31:24 +00:00
|
|
|
$this->expectException(Exception::class);
|
|
|
|
$this->expectExceptionCode(80);
|
2015-08-15 16:32:31 +00:00
|
|
|
$test->draw('123456789 does not exist!');
|
|
|
|
}
|
|
|
|
}
|