diff --git a/tst/RainTPL.php b/tst/RainTPL.php index 9741a08..bb3d3e4 100644 --- a/tst/RainTPL.php +++ b/tst/RainTPL.php @@ -62,54 +62,36 @@ class RainTPLTest extends PHPUnit_Framework_TestCase public function testTemplateRendersCorrectly() { - $this->assertTag( - array( - 'id' => 'cipherdata', - 'content' => htmlspecialchars(helper::getPaste()['data'], ENT_NOQUOTES) - ), + $this->assertContains( + '', $this->_content, 'outputs data correctly' ); - $this->assertTag( - array( - 'id' => 'errormessage', - 'content' => self::$error - ), + $this->assertRegExp( + '#]+id="errormessage"[^>]*>.*' . self::$error . '#', $this->_content, 'outputs error correctly' ); - $this->assertTag( - array( - 'id' => 'password', - ), + $this->assertRegExp( + '#<[^>]+id="password"[^>]*>#', $this->_content, 'password available if configured' ); - $this->assertTag( - array( - 'id' => 'opendiscussion', - 'attributes' => array( - 'checked' => 'checked' - ), - ), + $this->assertRegExp( + '#]+id="opendiscussion"[^>]*checked="checked"[^>]*>#', $this->_content, 'checked discussion if configured' ); - $this->assertTag( - array( - 'id' => 'opendisc', - ), + $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->assertTag( - array( - 'tag' => 'script', - 'attributes' => array( - 'src' => 'js/zerobin.js?' . rawurlencode(self::$version) - ), - ), + $this->assertRegExp( + '#]+src="js/zerobin.js\\?' . rawurlencode(self::$version) . '"[^>]*>#', $this->_content, 'outputs version correctly' ); diff --git a/tst/bootstrap.php b/tst/bootstrap.php index 117c5dd..5585e79 100644 --- a/tst/bootstrap.php +++ b/tst/bootstrap.php @@ -2,9 +2,10 @@ error_reporting( E_ALL | E_STRICT ); // change this, if your php files and data is outside of your webservers document root +if (!defined('PUBLIC_PATH')) define('PUBLIC_PATH', '..'); if (!defined('PATH')) define('PATH', '..' . DIRECTORY_SEPARATOR); if (!defined('CONF')) define('CONF', PATH . 'cfg' . DIRECTORY_SEPARATOR . 'conf.ini'); -if (!defined('PUBLIC_PATH')) define('PUBLIC_PATH', '..'); +if (!is_file(CONF)) copy(CONF . '.sample', CONF); require PATH . 'lib/auto.php'; diff --git a/tst/configGenerator.php b/tst/configGenerator.php index e0b688e..504f6a9 100755 --- a/tst/configGenerator.php +++ b/tst/configGenerator.php @@ -579,11 +579,10 @@ EOT; case 'Read': $code .= <<<'EOT' - $this->assertTag( - array( - 'id' => 'cipherdata', - 'content' => htmlspecialchars(helper::getPasteAsJson(), ENT_NOQUOTES) - ), + $this->assertContains( + '', $content, 'outputs data correctly' ); @@ -592,11 +591,8 @@ EOT; case 'Delete': $code .= <<<'EOT' - $this->assertTag( - array( - 'id' => 'status', - 'content' => 'Paste was properly deleted' - ), + $this->assertRegExp( + '#]*id="status"[^>]*>.*Paste was properly deleted#', $content, 'outputs deleted status correctly' ); diff --git a/tst/zerobin.php b/tst/zerobin.php index 4ed8326..27ca76c 100644 --- a/tst/zerobin.php +++ b/tst/zerobin.php @@ -36,18 +36,13 @@ class zerobinTest extends PHPUnit_Framework_TestCase ob_start(); new zerobin; $content = ob_get_contents(); - $this->assertTag( - array( - 'tag' => 'title', - 'content' => 'ZeroBin' - ), + $this->assertContains( + 'ZeroBin', $content, 'outputs title correctly' ); - $this->assertNotTag( - array( - 'id' => 'shortenbutton' - ), + $this->assertNotContains( + 'id="shortenbutton"', $content, 'doesn\'t output shortener button' ); @@ -67,11 +62,8 @@ class zerobinTest extends PHPUnit_Framework_TestCase ob_start(); new zerobin; $content = ob_get_contents(); - $this->assertTag( - array( - 'tag' => 'title', - 'content' => 'ZeroBin' - ), + $this->assertContains( + 'ZeroBin', $content, 'outputs title correctly' ); @@ -92,11 +84,8 @@ class zerobinTest extends PHPUnit_Framework_TestCase ob_start(); new zerobin; $content = ob_get_contents(); - $this->assertTag( - array( - 'tag' => 'title', - 'content' => 'ZeroBin' - ), + $this->assertContains( + 'ZeroBin', $content, 'outputs title correctly' ); @@ -117,11 +106,8 @@ class zerobinTest extends PHPUnit_Framework_TestCase ob_start(); new zerobin; $content = ob_get_contents(); - $this->assertTag( - array( - 'id' => 'shortenbutton', - 'attributes' => array('data-shortener' => $shortener) - ), + $this->assertRegExp( + '#id="shortenbutton"[^>]*data-shortener="' . preg_quote($shortener) . '"#', $content, 'outputs configured shortener URL correctly' ); @@ -248,6 +234,7 @@ class zerobinTest extends PHPUnit_Framework_TestCase $_SERVER['HTTP_X_FORWARDED_FOR'] = '::1'; $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest'; $_SERVER['REQUEST_METHOD'] = 'POST'; + $_SERVER['REMOTE_ADDR'] = '::1'; ob_start(); new zerobin; $content = ob_get_contents(); @@ -642,11 +629,10 @@ class zerobinTest extends PHPUnit_Framework_TestCase ob_start(); new zerobin; $content = ob_get_contents(); - $this->assertTag( - array( - 'id' => 'cipherdata', - 'content' => htmlspecialchars(helper::getPasteAsJson(), ENT_NOQUOTES) - ), + $this->assertContains( + '', $content, 'outputs data correctly' ); @@ -662,11 +648,8 @@ class zerobinTest extends PHPUnit_Framework_TestCase ob_start(); new zerobin; $content = ob_get_contents(); - $this->assertTag( - array( - 'id' => 'errormessage', - 'content' => 'Invalid paste ID' - ), + $this->assertRegExp( + '#]*id="errormessage"[^>]*>.*Invalid paste ID\.#', $content, 'outputs error correctly' ); @@ -682,11 +665,8 @@ class zerobinTest extends PHPUnit_Framework_TestCase ob_start(); new zerobin; $content = ob_get_contents(); - $this->assertTag( - array( - 'id' => 'errormessage', - 'content' => 'Paste does not exist' - ), + $this->assertRegExp( + '#]*id="errormessage"[^>]*>.*Paste does not exist[^<]*#', $content, 'outputs error correctly' ); @@ -704,11 +684,8 @@ class zerobinTest extends PHPUnit_Framework_TestCase ob_start(); new zerobin; $content = ob_get_contents(); - $this->assertTag( - array( - 'id' => 'errormessage', - 'content' => 'Paste does not exist' - ), + $this->assertRegExp( + '#]*id="errormessage"[^>]*>.*Paste does not exist[^<]*#', $content, 'outputs error correctly' ); @@ -726,11 +703,10 @@ class zerobinTest extends PHPUnit_Framework_TestCase ob_start(); new zerobin; $content = ob_get_contents(); - $this->assertTag( - array( - 'id' => 'cipherdata', - 'content' => htmlspecialchars(helper::getPasteAsJson($burnPaste['meta']), ENT_NOQUOTES) - ), + $this->assertContains( + '', $content, 'outputs data correctly' ); @@ -795,11 +771,10 @@ class zerobinTest extends PHPUnit_Framework_TestCase new zerobin; $content = ob_get_contents(); $meta['formatter'] = 'syntaxhighlighting'; - $this->assertTag( - array( - 'id' => 'cipherdata', - 'content' => htmlspecialchars(helper::getPasteAsJson($meta), ENT_NOQUOTES) - ), + $this->assertContains( + '', $content, 'outputs data correctly' ); @@ -819,11 +794,10 @@ class zerobinTest extends PHPUnit_Framework_TestCase new zerobin; $content = ob_get_contents(); $oldPaste['meta']['formatter'] = 'plaintext'; - $this->assertTag( - array( - 'id' => 'cipherdata', - 'content' => htmlspecialchars(helper::getPasteAsJson($oldPaste['meta']), ENT_NOQUOTES) - ), + $this->assertContains( + '', $content, 'outputs data correctly' ); @@ -842,11 +816,8 @@ class zerobinTest extends PHPUnit_Framework_TestCase ob_start(); new zerobin; $content = ob_get_contents(); - $this->assertTag( - array( - 'id' => 'status', - 'content' => 'Paste was properly deleted' - ), + $this->assertRegExp( + '#]*id="status"[^>]*>.*Paste was properly deleted[^<]*#s', $content, 'outputs deleted status correctly' ); @@ -865,11 +836,8 @@ class zerobinTest extends PHPUnit_Framework_TestCase ob_start(); new zerobin; $content = ob_get_contents(); - $this->assertTag( - array( - 'id' => 'errormessage', - 'content' => 'Invalid paste ID' - ), + $this->assertRegExp( + '#]*id="errormessage"[^>]*>.*Invalid paste ID\.#', $content, 'outputs delete error correctly' ); @@ -887,11 +855,8 @@ class zerobinTest extends PHPUnit_Framework_TestCase ob_start(); new zerobin; $content = ob_get_contents(); - $this->assertTag( - array( - 'id' => 'errormessage', - 'content' => 'Paste does not exist' - ), + $this->assertRegExp( + '#]*id="errormessage"[^>]*>.*Paste does not exist[^<]*#', $content, 'outputs delete error correctly' ); @@ -909,11 +874,8 @@ class zerobinTest extends PHPUnit_Framework_TestCase ob_start(); new zerobin; $content = ob_get_contents(); - $this->assertTag( - array( - 'id' => 'errormessage', - 'content' => 'Wrong deletion token' - ), + $this->assertRegExp( + '#]*id="errormessage"[^>]*>.*Wrong deletion token[^<]*#', $content, 'outputs delete error correctly' ); @@ -976,11 +938,8 @@ class zerobinTest extends PHPUnit_Framework_TestCase ob_start(); new zerobin; $content = ob_get_contents(); - $this->assertTag( - array( - 'id' => 'errormessage', - 'content' => 'Paste does not exist' - ), + $this->assertRegExp( + '#]*id="errormessage"[^>]*>.*Paste does not exist[^<]*#', $content, 'outputs error correctly' );