mirror of
https://github.com/PrivateBin/PrivateBin.git
synced 2024-12-25 23:39:23 -05:00
145 lines
4.8 KiB
PHP
145 lines
4.8 KiB
PHP
<?php
|
|
|
|
use PrivateBin\I18n;
|
|
use PrivateBin\View;
|
|
|
|
class ViewTest extends PHPUnit_Framework_TestCase
|
|
{
|
|
private static $error = 'foo bar';
|
|
|
|
private static $status = '!*#@?$+';
|
|
|
|
private static $formatters = array(
|
|
'plaintext' => 'Plain Text',
|
|
'syntaxhighlighting' => 'Source Code',
|
|
'markdown' => 'Markdown',
|
|
);
|
|
|
|
private static $formatter_default = 'plaintext';
|
|
|
|
private static $expire = array(
|
|
'5min' => '5 minutes',
|
|
'1hour' => '1 hour',
|
|
'never' => 'Never',
|
|
);
|
|
|
|
private static $expire_default = '1hour';
|
|
|
|
private static $version = 'Version 1.2.3';
|
|
|
|
private $_content = array();
|
|
|
|
public function setUp()
|
|
{
|
|
/* Setup Routine */
|
|
$page = new View;
|
|
$page->assign('NAME', 'PrivateBinTest');
|
|
$page->assign('CIPHERDATA', Helper::getPaste()['data']);
|
|
$page->assign('ERROR', self::$error);
|
|
$page->assign('STATUS', self::$status);
|
|
$page->assign('VERSION', self::$version);
|
|
$page->assign('DISCUSSION', true);
|
|
$page->assign('OPENDISCUSSION', true);
|
|
$page->assign('MARKDOWN', true);
|
|
$page->assign('SYNTAXHIGHLIGHTING', true);
|
|
$page->assign('SYNTAXHIGHLIGHTINGTHEME', 'sons-of-obsidian');
|
|
$page->assign('FORMATTER', self::$formatters);
|
|
$page->assign('FORMATTERDEFAULT', self::$formatter_default);
|
|
$page->assign('BURNAFTERREADINGSELECTED', false);
|
|
$page->assign('PASSWORD', true);
|
|
$page->assign('FILEUPLOAD', false);
|
|
$page->assign('ZEROBINCOMPATIBILITY', false);
|
|
$page->assign('NOTICE', 'example');
|
|
$page->assign('LANGUAGESELECTION', '');
|
|
$page->assign('LANGUAGES', I18n::getLanguageLabels(I18n::getAvailableLanguages()));
|
|
$page->assign('EXPIRE', self::$expire);
|
|
$page->assign('EXPIREDEFAULT', self::$expire_default);
|
|
$page->assign('EXPIRECLONE', true);
|
|
$page->assign('URLSHORTENER', '');
|
|
|
|
$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();
|
|
}
|
|
}
|
|
// 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();
|
|
}
|
|
}
|
|
|
|
public function tearDown()
|
|
{
|
|
/* Tear Down Routine */
|
|
}
|
|
|
|
public function testTemplateRendersCorrectly()
|
|
{
|
|
foreach ($this->_content as $template => $content) {
|
|
$this->assertRegExp(
|
|
'#<div[^>]+id="cipherdata"[^>]*>' .
|
|
preg_quote(htmlspecialchars(Helper::getPaste()['data'], ENT_NOQUOTES)) .
|
|
'</div>#',
|
|
$content,
|
|
$template . ': outputs data correctly'
|
|
);
|
|
$this->assertRegExp(
|
|
'#<div[^>]+id="errormessage"[^>]*>.*' . self::$error . '#s',
|
|
$content,
|
|
$template . ': outputs error correctly'
|
|
);
|
|
$this->assertRegExp(
|
|
'#<[^>]+id="password"[^>]*>#',
|
|
$content,
|
|
$template . ': password available if configured'
|
|
);
|
|
$this->assertRegExp(
|
|
'#<input[^>]+id="opendiscussion"[^>]*checked="checked"[^>]*>#',
|
|
$content,
|
|
$template . ': checked discussion if configured'
|
|
);
|
|
$this->assertRegExp(
|
|
'#<[^>]+id="opendiscussionoption"[^>]*>#',
|
|
$content,
|
|
$template . ': discussions available if configured'
|
|
);
|
|
// testing version number in JS address, since other instances may not be present in different templates
|
|
$this->assertRegExp(
|
|
'#<script[^>]+src="js/privatebin.js\\?' . rawurlencode(self::$version) . '"[^>]*>#',
|
|
$content,
|
|
$template . ': outputs version correctly'
|
|
);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @expectedException Exception
|
|
* @expectedExceptionCode 80
|
|
*/
|
|
public function testMissingTemplate()
|
|
{
|
|
$test = new View;
|
|
$test->draw('123456789 does not exist!');
|
|
}
|
|
}
|