Sfoglia il codice sorgente

fixing deprecations with newer phpunit versions

El RIDO 10 anni fa
parent
commit
e89a8b6898
4 ha cambiato i file con 65 aggiunte e 127 eliminazioni
  1. 14 32
      tst/RainTPL.php
  2. 2 1
      tst/bootstrap.php
  3. 6 10
      tst/configGenerator.php
  4. 43 84
      tst/zerobin.php

+ 14 - 32
tst/RainTPL.php

@@ -62,54 +62,36 @@ class RainTPLTest extends PHPUnit_Framework_TestCase
 
 
     public function testTemplateRendersCorrectly()
     public function testTemplateRendersCorrectly()
     {
     {
-        $this->assertTag(
-            array(
-                'id' => 'cipherdata',
-                'content' => htmlspecialchars(helper::getPaste()['data'], ENT_NOQUOTES)
-            ),
+        $this->assertContains(
+            '<div id="cipherdata" class="hidden">' .
+            htmlspecialchars(helper::getPaste()['data'], ENT_NOQUOTES) .
+            '</div>',
             $this->_content,
             $this->_content,
             'outputs data correctly'
             'outputs data correctly'
         );
         );
-        $this->assertTag(
-            array(
-                'id' => 'errormessage',
-                'content' => self::$error
-            ),
+        $this->assertRegExp(
+            '#<div[^>]+id="errormessage"[^>]*>.*' . self::$error . '</div>#',
             $this->_content,
             $this->_content,
             'outputs error correctly'
             'outputs error correctly'
         );
         );
-        $this->assertTag(
-            array(
-                'id' => 'password',
-            ),
+        $this->assertRegExp(
+            '#<[^>]+id="password"[^>]*>#',
             $this->_content,
             $this->_content,
             'password available if configured'
             'password available if configured'
         );
         );
-        $this->assertTag(
-            array(
-                'id' => 'opendiscussion',
-                'attributes' => array(
-                    'checked' => 'checked'
-                ),
-            ),
+        $this->assertRegExp(
+            '#<input[^>]+id="opendiscussion"[^>]*checked="checked"[^>]*>#',
             $this->_content,
             $this->_content,
             'checked discussion if configured'
             'checked discussion if configured'
         );
         );
-        $this->assertTag(
-            array(
-                'id' => 'opendisc',
-            ),
+        $this->assertRegExp(
+            '#<[^>]+id="opendisc"[^>]*>#',
             $this->_content,
             $this->_content,
             'discussions available if configured'
             'discussions available if configured'
         );
         );
         // testing version number in JS address, since other instances may not be present in different templates
         // 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(
+            '#<script[^>]+src="js/zerobin.js\\?' . rawurlencode(self::$version) . '"[^>]*>#',
             $this->_content,
             $this->_content,
             'outputs version correctly'
             'outputs version correctly'
         );
         );

+ 2 - 1
tst/bootstrap.php

@@ -2,9 +2,10 @@
 error_reporting( E_ALL | E_STRICT );
 error_reporting( E_ALL | E_STRICT );
 
 
 // change this, if your php files and data is outside of your webservers document root
 // 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('PATH')) define('PATH', '..' . DIRECTORY_SEPARATOR);
 if (!defined('CONF')) define('CONF', PATH . 'cfg' . DIRECTORY_SEPARATOR . 'conf.ini');
 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';
 require PATH . 'lib/auto.php';
 
 

+ 6 - 10
tst/configGenerator.php

@@ -579,11 +579,10 @@ EOT;
             case 'Read':
             case 'Read':
                 $code .= <<<'EOT'
                 $code .= <<<'EOT'
 
 
-        $this->assertTag(
-            array(
-                'id' => 'cipherdata',
-                'content' => htmlspecialchars(helper::getPasteAsJson(), ENT_NOQUOTES)
-            ),
+        $this->assertContains(
+            '<div id="cipherdata" class="hidden">' .
+            htmlspecialchars(helper::getPasteAsJson(), ENT_NOQUOTES) .
+            '</div>',
             $content,
             $content,
             'outputs data correctly'
             'outputs data correctly'
         );
         );
@@ -592,11 +591,8 @@ EOT;
             case 'Delete':
             case 'Delete':
                 $code .= <<<'EOT'
                 $code .= <<<'EOT'
 
 
-        $this->assertTag(
-            array(
-                'id' => 'status',
-                'content' => 'Paste was properly deleted'
-            ),
+        $this->assertRegExp(
+            '#<div[^>]*id="status"[^>]*>.*Paste was properly deleted</div>#',
             $content,
             $content,
             'outputs deleted status correctly'
             'outputs deleted status correctly'
         );
         );

+ 43 - 84
tst/zerobin.php

@@ -36,18 +36,13 @@ class zerobinTest extends PHPUnit_Framework_TestCase
         ob_start();
         ob_start();
         new zerobin;
         new zerobin;
         $content = ob_get_contents();
         $content = ob_get_contents();
-        $this->assertTag(
-            array(
-                'tag' => 'title',
-                'content' => 'ZeroBin'
-            ),
+        $this->assertContains(
+            '<title>ZeroBin</title>',
             $content,
             $content,
             'outputs title correctly'
             'outputs title correctly'
         );
         );
-        $this->assertNotTag(
-            array(
-                'id' => 'shortenbutton'
-            ),
+        $this->assertNotContains(
+            'id="shortenbutton"',
             $content,
             $content,
             'doesn\'t output shortener button'
             'doesn\'t output shortener button'
         );
         );
@@ -67,11 +62,8 @@ class zerobinTest extends PHPUnit_Framework_TestCase
         ob_start();
         ob_start();
         new zerobin;
         new zerobin;
         $content = ob_get_contents();
         $content = ob_get_contents();
-        $this->assertTag(
-            array(
-                'tag' => 'title',
-                'content' => 'ZeroBin'
-            ),
+        $this->assertContains(
+            '<title>ZeroBin</title>',
             $content,
             $content,
             'outputs title correctly'
             'outputs title correctly'
         );
         );
@@ -92,11 +84,8 @@ class zerobinTest extends PHPUnit_Framework_TestCase
         ob_start();
         ob_start();
         new zerobin;
         new zerobin;
         $content = ob_get_contents();
         $content = ob_get_contents();
-        $this->assertTag(
-            array(
-                'tag' => 'title',
-                'content' => 'ZeroBin'
-            ),
+        $this->assertContains(
+            '<title>ZeroBin</title>',
             $content,
             $content,
             'outputs title correctly'
             'outputs title correctly'
         );
         );
@@ -117,11 +106,8 @@ class zerobinTest extends PHPUnit_Framework_TestCase
         ob_start();
         ob_start();
         new zerobin;
         new zerobin;
         $content = ob_get_contents();
         $content = ob_get_contents();
-        $this->assertTag(
-            array(
-                'id' => 'shortenbutton',
-                'attributes' => array('data-shortener' => $shortener)
-            ),
+        $this->assertRegExp(
+            '#id="shortenbutton"[^>]*data-shortener="' . preg_quote($shortener) . '"#',
             $content,
             $content,
             'outputs configured shortener URL correctly'
             'outputs configured shortener URL correctly'
         );
         );
@@ -248,6 +234,7 @@ class zerobinTest extends PHPUnit_Framework_TestCase
         $_SERVER['HTTP_X_FORWARDED_FOR'] = '::1';
         $_SERVER['HTTP_X_FORWARDED_FOR'] = '::1';
         $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
         $_SERVER['HTTP_X_REQUESTED_WITH'] = 'JSONHttpRequest';
         $_SERVER['REQUEST_METHOD'] = 'POST';
         $_SERVER['REQUEST_METHOD'] = 'POST';
+        $_SERVER['REMOTE_ADDR'] = '::1';
         ob_start();
         ob_start();
         new zerobin;
         new zerobin;
         $content = ob_get_contents();
         $content = ob_get_contents();
@@ -642,11 +629,10 @@ class zerobinTest extends PHPUnit_Framework_TestCase
         ob_start();
         ob_start();
         new zerobin;
         new zerobin;
         $content = ob_get_contents();
         $content = ob_get_contents();
-        $this->assertTag(
-            array(
-                'id' => 'cipherdata',
-                'content' => htmlspecialchars(helper::getPasteAsJson(), ENT_NOQUOTES)
-            ),
+        $this->assertContains(
+            '<div id="cipherdata" class="hidden">' .
+            htmlspecialchars(helper::getPasteAsJson(), ENT_NOQUOTES) .
+            '</div>',
             $content,
             $content,
             'outputs data correctly'
             'outputs data correctly'
         );
         );
@@ -662,11 +648,8 @@ class zerobinTest extends PHPUnit_Framework_TestCase
         ob_start();
         ob_start();
         new zerobin;
         new zerobin;
         $content = ob_get_contents();
         $content = ob_get_contents();
-        $this->assertTag(
-            array(
-                'id' => 'errormessage',
-                'content' => 'Invalid paste ID'
-            ),
+        $this->assertRegExp(
+            '#<div[^>]*id="errormessage"[^>]*>.*Invalid paste ID\.</div>#',
             $content,
             $content,
             'outputs error correctly'
             'outputs error correctly'
         );
         );
@@ -682,11 +665,8 @@ class zerobinTest extends PHPUnit_Framework_TestCase
         ob_start();
         ob_start();
         new zerobin;
         new zerobin;
         $content = ob_get_contents();
         $content = ob_get_contents();
-        $this->assertTag(
-            array(
-                'id' => 'errormessage',
-                'content' => 'Paste does not exist'
-            ),
+        $this->assertRegExp(
+            '#<div[^>]*id="errormessage"[^>]*>.*Paste does not exist[^<]*</div>#',
             $content,
             $content,
             'outputs error correctly'
             'outputs error correctly'
         );
         );
@@ -704,11 +684,8 @@ class zerobinTest extends PHPUnit_Framework_TestCase
         ob_start();
         ob_start();
         new zerobin;
         new zerobin;
         $content = ob_get_contents();
         $content = ob_get_contents();
-        $this->assertTag(
-            array(
-                'id' => 'errormessage',
-                'content' => 'Paste does not exist'
-            ),
+        $this->assertRegExp(
+            '#<div[^>]*id="errormessage"[^>]*>.*Paste does not exist[^<]*</div>#',
             $content,
             $content,
             'outputs error correctly'
             'outputs error correctly'
         );
         );
@@ -726,11 +703,10 @@ class zerobinTest extends PHPUnit_Framework_TestCase
         ob_start();
         ob_start();
         new zerobin;
         new zerobin;
         $content = ob_get_contents();
         $content = ob_get_contents();
-        $this->assertTag(
-            array(
-                'id' => 'cipherdata',
-                'content' => htmlspecialchars(helper::getPasteAsJson($burnPaste['meta']), ENT_NOQUOTES)
-            ),
+        $this->assertContains(
+            '<div id="cipherdata" class="hidden">' .
+            htmlspecialchars(helper::getPasteAsJson($burnPaste['meta']), ENT_NOQUOTES) .
+            '</div>',
             $content,
             $content,
             'outputs data correctly'
             'outputs data correctly'
         );
         );
@@ -795,11 +771,10 @@ class zerobinTest extends PHPUnit_Framework_TestCase
         new zerobin;
         new zerobin;
         $content = ob_get_contents();
         $content = ob_get_contents();
         $meta['formatter'] = 'syntaxhighlighting';
         $meta['formatter'] = 'syntaxhighlighting';
-        $this->assertTag(
-            array(
-                'id' => 'cipherdata',
-                'content' => htmlspecialchars(helper::getPasteAsJson($meta), ENT_NOQUOTES)
-            ),
+        $this->assertContains(
+            '<div id="cipherdata" class="hidden">' .
+            htmlspecialchars(helper::getPasteAsJson($meta), ENT_NOQUOTES) .
+            '</div>',
             $content,
             $content,
             'outputs data correctly'
             'outputs data correctly'
         );
         );
@@ -819,11 +794,10 @@ class zerobinTest extends PHPUnit_Framework_TestCase
         new zerobin;
         new zerobin;
         $content = ob_get_contents();
         $content = ob_get_contents();
         $oldPaste['meta']['formatter'] = 'plaintext';
         $oldPaste['meta']['formatter'] = 'plaintext';
-        $this->assertTag(
-            array(
-                'id' => 'cipherdata',
-                'content' => htmlspecialchars(helper::getPasteAsJson($oldPaste['meta']), ENT_NOQUOTES)
-            ),
+        $this->assertContains(
+            '<div id="cipherdata" class="hidden">' .
+            htmlspecialchars(helper::getPasteAsJson($oldPaste['meta']), ENT_NOQUOTES) .
+            '</div>',
             $content,
             $content,
             'outputs data correctly'
             'outputs data correctly'
         );
         );
@@ -842,11 +816,8 @@ class zerobinTest extends PHPUnit_Framework_TestCase
         ob_start();
         ob_start();
         new zerobin;
         new zerobin;
         $content = ob_get_contents();
         $content = ob_get_contents();
-        $this->assertTag(
-            array(
-                'id' => 'status',
-                'content' => 'Paste was properly deleted'
-            ),
+        $this->assertRegExp(
+            '#<div[^>]*id="status"[^>]*>.*Paste was properly deleted[^<]*</div>#s',
             $content,
             $content,
             'outputs deleted status correctly'
             'outputs deleted status correctly'
         );
         );
@@ -865,11 +836,8 @@ class zerobinTest extends PHPUnit_Framework_TestCase
         ob_start();
         ob_start();
         new zerobin;
         new zerobin;
         $content = ob_get_contents();
         $content = ob_get_contents();
-        $this->assertTag(
-            array(
-                'id' => 'errormessage',
-                'content' => 'Invalid paste ID'
-            ),
+        $this->assertRegExp(
+            '#<div[^>]*id="errormessage"[^>]*>.*Invalid paste ID\.</div>#',
             $content,
             $content,
             'outputs delete error correctly'
             'outputs delete error correctly'
         );
         );
@@ -887,11 +855,8 @@ class zerobinTest extends PHPUnit_Framework_TestCase
         ob_start();
         ob_start();
         new zerobin;
         new zerobin;
         $content = ob_get_contents();
         $content = ob_get_contents();
-        $this->assertTag(
-            array(
-                'id' => 'errormessage',
-                'content' => 'Paste does not exist'
-            ),
+        $this->assertRegExp(
+            '#<div[^>]*id="errormessage"[^>]*>.*Paste does not exist[^<]*</div>#',
             $content,
             $content,
             'outputs delete error correctly'
             'outputs delete error correctly'
         );
         );
@@ -909,11 +874,8 @@ class zerobinTest extends PHPUnit_Framework_TestCase
         ob_start();
         ob_start();
         new zerobin;
         new zerobin;
         $content = ob_get_contents();
         $content = ob_get_contents();
-        $this->assertTag(
-            array(
-                'id' => 'errormessage',
-                'content' => 'Wrong deletion token'
-            ),
+        $this->assertRegExp(
+            '#<div[^>]*id="errormessage"[^>]*>.*Wrong deletion token[^<]*</div>#',
             $content,
             $content,
             'outputs delete error correctly'
             'outputs delete error correctly'
         );
         );
@@ -976,11 +938,8 @@ class zerobinTest extends PHPUnit_Framework_TestCase
         ob_start();
         ob_start();
         new zerobin;
         new zerobin;
         $content = ob_get_contents();
         $content = ob_get_contents();
-        $this->assertTag(
-            array(
-                'id' => 'errormessage',
-                'content' => 'Paste does not exist'
-            ),
+        $this->assertRegExp(
+            '#<div[^>]*id="errormessage"[^>]*>.*Paste does not exist[^<]*</div>#',
             $content,
             $content,
             'outputs error correctly'
             'outputs error correctly'
         );
         );