2015-08-16 00:32:31 +08:00
|
|
|
<?php
|
|
|
|
class RainTPLTest extends PHPUnit_Framework_TestCase
|
|
|
|
{
|
|
|
|
private static $error = 'foo bar';
|
|
|
|
|
|
|
|
private static $status = '!*#@?$+';
|
|
|
|
|
|
|
|
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 */
|
|
|
|
$page = new RainTPL;
|
|
|
|
$page::configure(array('cache_dir' => 'tmp/'));
|
2015-08-16 18:27:06 +08:00
|
|
|
$page::$path_replace = false;
|
2015-08-16 00:32:31 +08:00
|
|
|
|
|
|
|
// We escape it here because ENT_NOQUOTES can't be used in RainTPL templates.
|
2015-09-22 04:32:52 +08:00
|
|
|
$page->assign('CIPHERDATA', htmlspecialchars(helper::getPaste()['data'], ENT_NOQUOTES));
|
2015-08-16 00:32:31 +08:00
|
|
|
$page->assign('ERROR', self::$error);
|
|
|
|
$page->assign('STATUS', self::$status);
|
|
|
|
$page->assign('VERSION', self::$version);
|
2015-08-31 06:01:35 +08:00
|
|
|
$page->assign('DISCUSSION', true);
|
|
|
|
$page->assign('OPENDISCUSSION', true);
|
2015-09-12 23:33:16 +08:00
|
|
|
$page->assign('MARKDOWN', true);
|
2015-08-16 00:32:31 +08:00
|
|
|
$page->assign('SYNTAXHIGHLIGHTING', true);
|
2015-08-18 05:18:33 +08:00
|
|
|
$page->assign('SYNTAXHIGHLIGHTINGTHEME', 'sons-of-obsidian');
|
2015-08-31 06:01:35 +08:00
|
|
|
$page->assign('BURNAFTERREADINGSELECTED', false);
|
|
|
|
$page->assign('PASSWORD', true);
|
2015-09-17 04:51:48 +08:00
|
|
|
$page->assign('FILEUPLOAD', false);
|
2015-08-16 18:27:06 +08:00
|
|
|
$page->assign('BASE64JSVERSION', '2.1.9');
|
2015-08-18 05:18:33 +08:00
|
|
|
$page->assign('NOTICE', 'example');
|
2015-09-19 23:23:10 +08:00
|
|
|
$page->assign('LANGUAGESELECTION', '');
|
|
|
|
$page->assign('LANGUAGES', i18n::getLanguageLabels(i18n::getAvailableLanguages()));
|
2015-08-16 00:32:31 +08:00
|
|
|
$page->assign('EXPIRE', self::$expire);
|
|
|
|
$page->assign('EXPIREDEFAULT', self::$expire_default);
|
2015-10-18 23:56:45 +08:00
|
|
|
$page->assign('EXPIRECLONE', true);
|
2016-01-31 16:56:06 +08:00
|
|
|
$page->assign('URLSHORTENER', '');
|
2015-08-16 00:32:31 +08:00
|
|
|
ob_start();
|
|
|
|
$page->draw('page');
|
|
|
|
$this->_content = ob_get_contents();
|
|
|
|
// run a second time from cache
|
|
|
|
$page->cache('page');
|
|
|
|
$page->draw('page');
|
|
|
|
ob_end_clean();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function tearDown()
|
|
|
|
{
|
|
|
|
/* Tear Down Routine */
|
|
|
|
helper::rmdir(PATH . 'tmp');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testTemplateRendersCorrectly()
|
|
|
|
{
|
2016-05-23 00:35:07 +08:00
|
|
|
$this->assertContains(
|
|
|
|
'<div id="cipherdata" class="hidden">' .
|
|
|
|
htmlspecialchars(helper::getPaste()['data'], ENT_NOQUOTES) .
|
|
|
|
'</div>',
|
2015-08-16 00:32:31 +08:00
|
|
|
$this->_content,
|
|
|
|
'outputs data correctly'
|
|
|
|
);
|
2016-05-23 00:35:07 +08:00
|
|
|
$this->assertRegExp(
|
|
|
|
'#<div[^>]+id="errormessage"[^>]*>.*' . self::$error . '</div>#',
|
2015-08-16 00:32:31 +08:00
|
|
|
$this->_content,
|
|
|
|
'outputs error correctly'
|
|
|
|
);
|
2016-05-23 00:35:07 +08:00
|
|
|
$this->assertRegExp(
|
|
|
|
'#<[^>]+id="password"[^>]*>#',
|
2015-08-31 06:01:35 +08:00
|
|
|
$this->_content,
|
|
|
|
'password available if configured'
|
|
|
|
);
|
2016-05-23 00:35:07 +08:00
|
|
|
$this->assertRegExp(
|
|
|
|
'#<input[^>]+id="opendiscussion"[^>]*checked="checked"[^>]*>#',
|
2015-08-16 00:32:31 +08:00
|
|
|
$this->_content,
|
2015-08-31 06:01:35 +08:00
|
|
|
'checked discussion if configured'
|
|
|
|
);
|
2016-05-23 00:35:07 +08:00
|
|
|
$this->assertRegExp(
|
|
|
|
'#<[^>]+id="opendisc"[^>]*>#',
|
2015-08-31 06:01:35 +08:00
|
|
|
$this->_content,
|
|
|
|
'discussions available if configured'
|
2015-08-16 00:32:31 +08:00
|
|
|
);
|
|
|
|
// testing version number in JS address, since other instances may not be present in different templates
|
2016-05-23 00:35:07 +08:00
|
|
|
$this->assertRegExp(
|
|
|
|
'#<script[^>]+src="js/zerobin.js\\?' . rawurlencode(self::$version) . '"[^>]*>#',
|
2015-08-16 00:32:31 +08:00
|
|
|
$this->_content,
|
|
|
|
'outputs version correctly'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException RainTpl_Exception
|
|
|
|
*/
|
|
|
|
public function testMissingTemplate()
|
|
|
|
{
|
|
|
|
$test = new RainTPL;
|
|
|
|
$test->draw('123456789 does not exist!');
|
|
|
|
}
|
|
|
|
}
|