2015-08-15 18:32:31 +02:00
|
|
|
<?php
|
2016-07-21 17:09:48 +02:00
|
|
|
|
2016-08-09 11:54:42 +02:00
|
|
|
use PrivateBin\I18n;
|
|
|
|
use PrivateBin\View;
|
2016-07-21 17:09:48 +02:00
|
|
|
|
2016-08-09 11:54:42 +02:00
|
|
|
class ViewTest extends PHPUnit_Framework_TestCase
|
2015-08-15 18:32:31 +02:00
|
|
|
{
|
|
|
|
private static $error = 'foo bar';
|
|
|
|
|
|
|
|
private static $status = '!*#@?$+';
|
|
|
|
|
2016-07-19 14:02:26 +02:00
|
|
|
private static $formatters = array(
|
|
|
|
'plaintext' => 'Plain Text',
|
|
|
|
'syntaxhighlighting' => 'Source Code',
|
|
|
|
'markdown' => 'Markdown',
|
|
|
|
);
|
|
|
|
|
|
|
|
private static $formatter_default = 'plaintext';
|
|
|
|
|
2015-08-15 18:32:31 +02:00
|
|
|
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;
|
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
/* Setup Routine */
|
2016-08-09 11:54:42 +02:00
|
|
|
$page = new View;
|
2016-07-19 14:02:26 +02:00
|
|
|
$page->assign('CIPHERDATA', helper::getPaste()['data']);
|
2015-08-15 18:32:31 +02:00
|
|
|
$page->assign('ERROR', self::$error);
|
|
|
|
$page->assign('STATUS', self::$status);
|
|
|
|
$page->assign('VERSION', self::$version);
|
2015-08-31 00:01:35 +02:00
|
|
|
$page->assign('DISCUSSION', true);
|
|
|
|
$page->assign('OPENDISCUSSION', true);
|
2015-09-12 17:33:16 +02:00
|
|
|
$page->assign('MARKDOWN', true);
|
2015-08-15 18:32:31 +02:00
|
|
|
$page->assign('SYNTAXHIGHLIGHTING', true);
|
2015-08-17 23:18:33 +02:00
|
|
|
$page->assign('SYNTAXHIGHLIGHTINGTHEME', 'sons-of-obsidian');
|
2016-07-19 14:02:26 +02:00
|
|
|
$page->assign('FORMATTER', self::$formatters);
|
|
|
|
$page->assign('FORMATTERDEFAULT', self::$formatter_default);
|
2015-08-31 00:01:35 +02:00
|
|
|
$page->assign('BURNAFTERREADINGSELECTED', false);
|
|
|
|
$page->assign('PASSWORD', true);
|
2015-09-16 22:51:48 +02:00
|
|
|
$page->assign('FILEUPLOAD', false);
|
2016-08-16 11:11:03 +02:00
|
|
|
$page->assign('ZEROBINCOMPATIBILITY', false);
|
2015-08-17 23:18:33 +02:00
|
|
|
$page->assign('NOTICE', 'example');
|
2015-09-19 17:23:10 +02:00
|
|
|
$page->assign('LANGUAGESELECTION', '');
|
2016-08-09 11:54:42 +02:00
|
|
|
$page->assign('LANGUAGES', I18n::getLanguageLabels(i18n::getAvailableLanguages()));
|
2015-08-15 18:32:31 +02:00
|
|
|
$page->assign('EXPIRE', self::$expire);
|
|
|
|
$page->assign('EXPIREDEFAULT', self::$expire_default);
|
2015-10-18 17:56:45 +02:00
|
|
|
$page->assign('EXPIRECLONE', true);
|
2016-01-31 09:56:06 +01:00
|
|
|
$page->assign('URLSHORTENER', '');
|
2015-08-15 18:32:31 +02:00
|
|
|
ob_start();
|
|
|
|
$page->draw('page');
|
|
|
|
$this->_content = ob_get_contents();
|
|
|
|
ob_end_clean();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function tearDown()
|
|
|
|
{
|
|
|
|
/* Tear Down Routine */
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testTemplateRendersCorrectly()
|
|
|
|
{
|
2016-05-22 18:35:07 +02:00
|
|
|
$this->assertContains(
|
|
|
|
'<div id="cipherdata" class="hidden">' .
|
|
|
|
htmlspecialchars(helper::getPaste()['data'], ENT_NOQUOTES) .
|
|
|
|
'</div>',
|
2015-08-15 18:32:31 +02:00
|
|
|
$this->_content,
|
|
|
|
'outputs data correctly'
|
|
|
|
);
|
2016-05-22 18:35:07 +02:00
|
|
|
$this->assertRegExp(
|
|
|
|
'#<div[^>]+id="errormessage"[^>]*>.*' . self::$error . '</div>#',
|
2015-08-15 18:32:31 +02:00
|
|
|
$this->_content,
|
|
|
|
'outputs error correctly'
|
|
|
|
);
|
2016-05-22 18:35:07 +02:00
|
|
|
$this->assertRegExp(
|
|
|
|
'#<[^>]+id="password"[^>]*>#',
|
2015-08-31 00:01:35 +02:00
|
|
|
$this->_content,
|
|
|
|
'password available if configured'
|
|
|
|
);
|
2016-05-22 18:35:07 +02:00
|
|
|
$this->assertRegExp(
|
|
|
|
'#<input[^>]+id="opendiscussion"[^>]*checked="checked"[^>]*>#',
|
2015-08-15 18:32:31 +02:00
|
|
|
$this->_content,
|
2015-08-31 00:01:35 +02:00
|
|
|
'checked discussion if configured'
|
|
|
|
);
|
2016-05-22 18:35:07 +02:00
|
|
|
$this->assertRegExp(
|
|
|
|
'#<[^>]+id="opendisc"[^>]*>#',
|
2015-08-31 00:01:35 +02:00
|
|
|
$this->_content,
|
|
|
|
'discussions available if configured'
|
2015-08-15 18:32:31 +02:00
|
|
|
);
|
|
|
|
// testing version number in JS address, since other instances may not be present in different templates
|
2016-05-22 18:35:07 +02:00
|
|
|
$this->assertRegExp(
|
2016-07-11 11:58:15 +02:00
|
|
|
'#<script[^>]+src="js/privatebin.js\\?' . rawurlencode(self::$version) . '"[^>]*>#',
|
2015-08-15 18:32:31 +02:00
|
|
|
$this->_content,
|
|
|
|
'outputs version correctly'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-07-19 14:02:26 +02:00
|
|
|
* @expectedException Exception
|
|
|
|
* @expectedExceptionCode 80
|
2015-08-15 18:32:31 +02:00
|
|
|
*/
|
|
|
|
public function testMissingTemplate()
|
|
|
|
{
|
2016-08-09 11:54:42 +02:00
|
|
|
$test = new View;
|
2015-08-15 18:32:31 +02:00
|
|
|
$test->draw('123456789 does not exist!');
|
|
|
|
}
|
|
|
|
}
|