11<?php
2- namespace PhpWaf ;
2+ namespace PhpWaf \ Tests ;
33
44use PHPUnit \Framework \TestCase ;
5+ use PhpWaf \Firewall ;
56
67class FirewallTest extends TestCase
78{
@@ -20,4 +21,96 @@ public function testAttributes()
2021 }
2122 }
2223
24+ public function testFilters ()
25+ {
26+ try {
27+ $ firewall = new Firewall ();
28+ $ this ->assertIsArray ($ firewall ->getFilters ());
29+ } catch (\Exception $ e ) {
30+
31+ }
32+
33+ return $ firewall ;
34+ }
35+
36+ /**
37+ * @depends testFilters
38+ * @param Firewall $firewall
39+ * @return Firewall
40+ * @throws \Exception
41+ */
42+ public function testEnable (Firewall $ firewall )
43+ {
44+ $ this ->assertInstanceOf (Firewall::class, $ firewall ->enable ('XML ' ));
45+ $ filters = $ firewall ->getFilters ();
46+ $ this ->assertIsArray ($ filters );
47+ $ this ->assertTrue ($ filters ['XML ' ]);
48+
49+ return $ firewall ;
50+ }
51+
52+ /**
53+ * @depends testEnable
54+ * @param Firewall $firewall
55+ * @return Firewall
56+ * @throws \Exception
57+ */
58+ public function testDisable (Firewall $ firewall )
59+ {
60+ $ this ->assertInstanceOf (Firewall::class, $ firewall ->disable ('SQL ' ));
61+ $ filters = $ firewall ->getFilters ();
62+ $ this ->assertIsArray ($ filters );
63+ $ this ->assertFalse ($ filters ['SQL ' ]);
64+
65+ return $ firewall ;
66+ }
67+
68+ /**
69+ * @depends testDisable
70+ * @param Firewall $firewall
71+ * @return Firewall
72+ * @throws \Exception
73+ */
74+ public function testSetters (Firewall $ firewall )
75+ {
76+ $ this ->assertInstanceOf (Firewall::class, $ firewall ->setLogFile ('' ));
77+ $ this ->assertInstanceOf (Firewall::class, $ firewall ->setLogFormat ('' ));
78+ $ this ->assertInstanceOf (Firewall::class, $ firewall ->setMode (3 ));
79+
80+ return $ firewall ;
81+ }
82+
83+ /**
84+ * @depends testSetters
85+ * @param Firewall $firewall
86+ * @return Firewall
87+ * @throws \Exception
88+ */
89+ public function testRun (Firewall $ firewall )
90+ {
91+ $ firewall
92+ ->setMode (3 )
93+ ->setLogFormat ('' )
94+ ->setLogFile ('' )
95+ ->disable ('XSS ' )
96+ ->disable ('XML ' )
97+ ->disable ('CRLF ' )
98+ ->enable ('SQL ' )
99+ ->run ();
100+
101+ $ this ->assertInstanceOf (Firewall::class, $ firewall );
102+
103+ return $ firewall ;
104+ }
105+
106+ /**
107+ * @depends testRun
108+ * @param Firewall $firewall
109+ * @throws \Exception
110+ */
111+ public function testException (Firewall $ firewall )
112+ {
113+ $ this ->expectException (\Exception::class);
114+ $ firewall ->setMode (100 );
115+ }
23116}
0 commit comments