diff --git a/tst/ViewTest.php b/tst/ViewTest.php index d2e21317..484ad468 100644 --- a/tst/ViewTest.php +++ b/tst/ViewTest.php @@ -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( - '', - $this->_content, - 'outputs data correctly' - ); - $this->assertRegExp( - '#]+id="errormessage"[^>]*>.*' . self::$error . '#', - $this->_content, - 'outputs error correctly' - ); - $this->assertRegExp( - '#<[^>]+id="password"[^>]*>#', - $this->_content, - 'password available if configured' - ); - $this->assertRegExp( - '#]+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( - '#]+src="js/privatebin.js\\?' . rawurlencode(self::$version) . '"[^>]*>#', - $this->_content, - 'outputs version correctly' - ); + foreach ($this->_content as $template => $content) { + $this->assertContains( + '', + $content, + $template . ': outputs data correctly' + ); + $this->assertRegExp( + '#]+id="errormessage"[^>]*>.*' . self::$error . '#', + $content, + $template . ': outputs error correctly' + ); + $this->assertRegExp( + '#<[^>]+id="password"[^>]*>#', + $content, + $template . ': password available if configured' + ); + $this->assertRegExp( + '#]+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( + '#]+src="js/privatebin.js\\?' . rawurlencode(self::$version) . '"[^>]*>#', + $content, + $template . ': outputs version correctly' + ); + } } /**