From 06496f2ede161de9845a3a7733c60fc42b996c28 Mon Sep 17 00:00:00 2001 From: El RIDO Date: Sun, 8 Jan 2017 08:28:05 +0100 Subject: [PATCH] updated View test to test every available template instead of just the page one --- tst/ViewTest.php | 85 ++++++++++++++++++++++++++---------------------- 1 file changed, 47 insertions(+), 38 deletions(-) diff --git a/tst/ViewTest.php b/tst/ViewTest.php index d2e2131..484ad46 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' + ); + } } /**