updated View test to test every available template instead of just the page one

This commit is contained in:
El RIDO 2017-01-08 08:28:05 +01:00
parent 228280e3d6
commit 06496f2ede
No known key found for this signature in database
GPG Key ID: 0F5C940A6BD81F92

View File

@ -27,7 +27,7 @@ class ViewTest extends PHPUnit_Framework_TestCase
private static $version = 'Version 1.2.3'; private static $version = 'Version 1.2.3';
private $_content; private $_content = array();
public function setUp() public function setUp()
{ {
@ -56,11 +56,18 @@ class ViewTest extends PHPUnit_Framework_TestCase
$page->assign('EXPIREDEFAULT', self::$expire_default); $page->assign('EXPIREDEFAULT', self::$expire_default);
$page->assign('EXPIRECLONE', true); $page->assign('EXPIRECLONE', true);
$page->assign('URLSHORTENER', ''); $page->assign('URLSHORTENER', '');
$dir = dir(PATH . 'tpl');
while (false !== ($file = $dir->read())) {
if (substr($file, -4) === '.php') {
$template = substr($file, 0, -4);
ob_start(); ob_start();
$page->draw('page'); $page->draw($template);
$this->_content = ob_get_contents(); $this->_content[$template] = ob_get_contents();
ob_end_clean(); ob_end_clean();
} }
}
}
public function tearDown() public function tearDown()
{ {
@ -69,40 +76,42 @@ class ViewTest extends PHPUnit_Framework_TestCase
public function testTemplateRendersCorrectly() public function testTemplateRendersCorrectly()
{ {
foreach ($this->_content as $template => $content) {
$this->assertContains( $this->assertContains(
'<div id="cipherdata" class="hidden">' . '<div id="cipherdata" class="hidden">' .
htmlspecialchars(Helper::getPaste()['data'], ENT_NOQUOTES) . htmlspecialchars(Helper::getPaste()['data'], ENT_NOQUOTES) .
'</div>', '</div>',
$this->_content, $content,
'outputs data correctly' $template . ': outputs data correctly'
); );
$this->assertRegExp( $this->assertRegExp(
'#<div[^>]+id="errormessage"[^>]*>.*' . self::$error . '</div>#', '#<div[^>]+id="errormessage"[^>]*>.*' . self::$error . '</div>#',
$this->_content, $content,
'outputs error correctly' $template . ': outputs error correctly'
); );
$this->assertRegExp( $this->assertRegExp(
'#<[^>]+id="password"[^>]*>#', '#<[^>]+id="password"[^>]*>#',
$this->_content, $content,
'password available if configured' $template . ': password available if configured'
); );
$this->assertRegExp( $this->assertRegExp(
'#<input[^>]+id="opendiscussion"[^>]*checked="checked"[^>]*>#', '#<input[^>]+id="opendiscussion"[^>]*checked="checked"[^>]*>#',
$this->_content, $content,
'checked discussion if configured' $template . ': checked discussion if configured'
); );
$this->assertRegExp( $this->assertRegExp(
'#<[^>]+id="opendisc"[^>]*>#', '#<[^>]+id="opendisc"[^>]*>#',
$this->_content, $content,
'discussions available if configured' $template . ': discussions available if configured'
); );
// testing version number in JS address, since other instances may not be present in different templates // testing version number in JS address, since other instances may not be present in different templates
$this->assertRegExp( $this->assertRegExp(
'#<script[^>]+src="js/privatebin.js\\?' . rawurlencode(self::$version) . '"[^>]*>#', '#<script[^>]+src="js/privatebin.js\\?' . rawurlencode(self::$version) . '"[^>]*>#',
$this->_content, $content,
'outputs version correctly' $template . ': outputs version correctly'
); );
} }
}
/** /**
* @expectedException Exception * @expectedException Exception