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 $_content;
private $_content = array();
public function setUp()
{
@ -56,11 +56,18 @@ class ViewTest extends PHPUnit_Framework_TestCase
$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('page');
$this->_content = ob_get_contents();
$page->draw($template);
$this->_content[$template] = ob_get_contents();
ob_end_clean();
}
}
}
public function tearDown()
{
@ -69,40 +76,42 @@ class ViewTest extends PHPUnit_Framework_TestCase
public function testTemplateRendersCorrectly()
{
foreach ($this->_content as $template => $content) {
$this->assertContains(
'<div id="cipherdata" class="hidden">' .
htmlspecialchars(Helper::getPaste()['data'], ENT_NOQUOTES) .
'</div>',
$this->_content,
'outputs data correctly'
$content,
$template . ': outputs data correctly'
);
$this->assertRegExp(
'#<div[^>]+id="errormessage"[^>]*>.*' . self::$error . '</div>#',
$this->_content,
'outputs error correctly'
$content,
$template . ': outputs error correctly'
);
$this->assertRegExp(
'#<[^>]+id="password"[^>]*>#',
$this->_content,
'password available if configured'
$content,
$template . ': password available if configured'
);
$this->assertRegExp(
'#<input[^>]+id="opendiscussion"[^>]*checked="checked"[^>]*>#',
$this->_content,
'checked discussion if configured'
$content,
$template . ': checked discussion if configured'
);
$this->assertRegExp(
'#<[^>]+id="opendisc"[^>]*>#',
$this->_content,
'discussions available if configured'
$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) . '"[^>]*>#',
$this->_content,
'outputs version correctly'
$content,
$template . ': outputs version correctly'
);
}
}
/**
* @expectedException Exception