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

pull/161/head
El RIDO 8 years ago
parent 228280e3d6
commit 06496f2ede
No known key found for this signature in database
GPG Key ID: 0F5C940A6BD81F92

@ -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,10 +56,17 @@ class ViewTest extends PHPUnit_Framework_TestCase
$page->assign('EXPIREDEFAULT', self::$expire_default);
$page->assign('EXPIRECLONE', true);
$page->assign('URLSHORTENER', '');
ob_start();
$page->draw('page');
$this->_content = ob_get_contents();
ob_end_clean();
$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();
}
}
}
public function tearDown()
@ -69,39 +76,41 @@ class ViewTest extends PHPUnit_Framework_TestCase
public function testTemplateRendersCorrectly()
{
$this->assertContains(
'<div id="cipherdata" class="hidden">' .
htmlspecialchars(Helper::getPaste()['data'], ENT_NOQUOTES) .
'</div>',
$this->_content,
'outputs data correctly'
);
$this->assertRegExp(
'#<div[^>]+id="errormessage"[^>]*>.*' . self::$error . '</div>#',
$this->_content,
'outputs error correctly'
);
$this->assertRegExp(
'#<[^>]+id="password"[^>]*>#',
$this->_content,
'password available if configured'
);
$this->assertRegExp(
'#<input[^>]+id="opendiscussion"[^>]*checked="checked"[^>]*>#',
$this->_content,
'checked discussion if configured'
);
$this->assertRegExp(
'#<[^>]+id="opendisc"[^>]*>#',
$this->_content,
'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'
);
foreach ($this->_content as $template => $content) {
$this->assertContains(
'<div id="cipherdata" class="hidden">' .
htmlspecialchars(Helper::getPaste()['data'], ENT_NOQUOTES) .
'</div>',
$content,
$template . ': outputs data correctly'
);
$this->assertRegExp(
'#<div[^>]+id="errormessage"[^>]*>.*' . self::$error . '</div>#',
$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="opendisc"[^>]*>#',
$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'
);
}
}
/**

Loading…
Cancel
Save