RequestTest.php (1809B)
1 <?php 2 3 class RequestTest extends PHPUnit_Framework_TestCase 4 { 5 /** 6 * Testing the post() method of the Request class 7 */ 8 public function testPost() 9 { 10 $_POST["test"] = 22; 11 $this->assertEquals(22, Request::post('test')); 12 $this->assertEquals(null, Request::post('not_existing_key')); 13 14 // test trim & strip_tags: Method is used with second argument "true", triggering a cleaning of the input 15 $_POST["attacker_string"] = ' <script>alert("yo!");</script> '; 16 $this->assertEquals('alert("yo!");', Request::post('attacker_string', true)); 17 } 18 19 /** 20 * Testing the postCheckbox() method of the Request class 21 */ 22 public function testPostCheckbox() 23 { 24 // Weird side-fact: a checked checkbox that has no manually set value will mostly contain 'on' as the default 25 // value in most modern browsers btw, so it makes sense to test this 26 $_POST['checkboxName'] = 'on'; 27 $this->assertEquals(1, Request::postCheckbox('checkboxName')); 28 29 $_POST['checkboxName'] = 1; 30 $this->assertEquals(1, Request::postCheckbox('checkboxName')); 31 32 $_POST['checkboxName'] = null; 33 $this->assertEquals(null, Request::postCheckbox('checkboxName')); 34 } 35 36 /** 37 * Testing the get() method of the Request class 38 */ 39 public function testGet() 40 { 41 $_GET["test"] = 33; 42 $this->assertEquals(33, Request::get('test')); 43 $this->assertEquals(null, Request::get('not_existing_key')); 44 } 45 46 /** 47 * Testing the cookie() method of the Request class 48 */ 49 public function testCookie() 50 { 51 $_COOKIE["test"] = 44; 52 $this->assertEquals(44, Request::cookie('test')); 53 $this->assertEquals(null, Request::cookie('not_existing_key')); 54 } 55 }