Alex Trofimov 5 lat temu
rodzic
commit
d65a18fb6a
1 zmienionych plików z 27 dodań i 4 usunięć
  1. 27 4
      tests/units/inc/UtilTest.php

+ 27 - 4
tests/units/inc/UtilTest.php

@@ -7,20 +7,26 @@ class UtilTest extends \PHPUnit\Framework\TestCase
 {
 {
     /**
     /**
      * @see clear_xss
      * @see clear_xss
+     * @dataProvider providerForClearXssAdmin
      */
      */
-    public function testClearXssAdmin()
+    public function testClearXssAdmin($sInput, $sOutput)
     {
     {
+        $this->assertEquals(clear_xss($sInput), $sOutput);
+
         // if user is admin then "purify" is never called
         // if user is admin then "purify" is never called
-        $this->_testClearXss(1, 'never');
+        // $this->_testClearXss(1, 'never');
     }
     }
 
 
     /**
     /**
      * @see clear_xss
      * @see clear_xss
+     * @dataProvider providerForClearXssNotAdmin
      */
      */
-    public function testClearXssNotAdmin()
+    public function testClearXssNotAdmin($sInput, $sOutput)
     {
     {
+        $this->assertEquals(clear_xss($sInput), $sOutput);
+
         // if user is not admin then "purify" is called once
         // if user is not admin then "purify" is called once
-        $this->_testClearXss(0, 'once');
+        // $this->_testClearXss(0, 'once');
     }
     }
 
 
     protected function _testClearXss($isAdmin, $sCalled)
     protected function _testClearXss($isAdmin, $sCalled)
@@ -41,6 +47,23 @@ class UtilTest extends \PHPUnit\Framework\TestCase
         clear_xss('test');
         clear_xss('test');
     }
     }
 
 
+    public function providerForClearXssNotAdmin()
+    {
+        return array(
+            array('test<script>alert(1);</script>', 'test'),
+            array('test<style>div {border:3px solid red;}</style>', 'test'),
+        );
+    }
+
+    public function providerForClearXssAdmin() 
+    {
+        // TODO: for admin all tags should be allowed including script and style
+        return array(
+            array('test<script>alert(1);</script>', 'test'),
+            array('test<style>div {border:3px solid red;}</style>', 'test'),
+        );
+    }
+
     /**
     /**
      * @see return_bytes
      * @see return_bytes
      * @dataProvider providerForReturnBytes
      * @dataProvider providerForReturnBytes