[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class AphrontRequestTestCase extends PhabricatorTestCase { 4 5 public function testRequestDataAccess() { 6 $r = new AphrontRequest('example.com', '/'); 7 $r->setRequestData( 8 array( 9 'str_empty' => '', 10 'str' => 'derp', 11 'str_true' => 'true', 12 'str_false' => 'false', 13 14 'zero' => '0', 15 'one' => '1', 16 17 'arr_empty' => array(), 18 'arr_num' => array(1, 2, 3), 19 20 'comma' => ',', 21 'comma_1' => 'a, b', 22 'comma_2' => ' ,a ,, b ,,,, ,, ', 23 'comma_3' => '0', 24 'comma_4' => 'a, a, b, a', 25 'comma_5' => "a\nb, c\n\nd\n\n\n,\n", 26 )); 27 28 $this->assertEqual(1, $r->getInt('one')); 29 $this->assertEqual(0, $r->getInt('zero')); 30 $this->assertEqual(null, $r->getInt('does-not-exist')); 31 $this->assertEqual(0, $r->getInt('str_empty')); 32 33 $this->assertEqual(true, $r->getBool('one')); 34 $this->assertEqual(false, $r->getBool('zero')); 35 $this->assertEqual(true, $r->getBool('str_true')); 36 $this->assertEqual(false, $r->getBool('str_false')); 37 $this->assertEqual(true, $r->getBool('str')); 38 $this->assertEqual(null, $r->getBool('does-not-exist')); 39 $this->assertEqual(false, $r->getBool('str_empty')); 40 41 $this->assertEqual('derp', $r->getStr('str')); 42 $this->assertEqual('', $r->getStr('str_empty')); 43 $this->assertEqual(null, $r->getStr('does-not-exist')); 44 45 $this->assertEqual(array(), $r->getArr('arr_empty')); 46 $this->assertEqual(array(1, 2, 3), $r->getArr('arr_num')); 47 $this->assertEqual(null, $r->getArr('str_empty', null)); 48 $this->assertEqual(null, $r->getArr('str_true', null)); 49 $this->assertEqual(null, $r->getArr('does-not-exist', null)); 50 $this->assertEqual(array(), $r->getArr('does-not-exist')); 51 52 $this->assertEqual(array(), $r->getStrList('comma')); 53 $this->assertEqual(array('a', 'b'), $r->getStrList('comma_1')); 54 $this->assertEqual(array('a', 'b'), $r->getStrList('comma_2')); 55 $this->assertEqual(array('0'), $r->getStrList('comma_3')); 56 $this->assertEqual(array('a', 'a', 'b', 'a'), $r->getStrList('comma_4')); 57 $this->assertEqual(array('a', 'b', 'c', 'd'), $r->getStrList('comma_5')); 58 $this->assertEqual(array(), $r->getStrList('does-not-exist')); 59 $this->assertEqual(null, $r->getStrList('does-not-exist', null)); 60 61 $this->assertEqual(true, $r->getExists('str')); 62 $this->assertEqual(false, $r->getExists('does-not-exist')); 63 } 64 65 public function testHostAttacks() { 66 static $tests = array( 67 'domain.com' => 'domain.com', 68 'domain.com:80' => 'domain.com', 69 'evil.com:[email protected]' => 'real.com', 70 'evil.com:[email protected]:80' => 'real.com', 71 ); 72 73 foreach ($tests as $input => $expect) { 74 $r = new AphrontRequest($input, '/'); 75 $this->assertEqual( 76 $expect, 77 $r->getHost(), 78 'Host: '.$input); 79 } 80 } 81 82 public function testFlattenRequestData() { 83 $test_cases = array( 84 array( 85 'a' => 'a', 86 'b' => '1', 87 'c' => '', 88 ), 89 array( 90 'a' => 'a', 91 'b' => '1', 92 'c' => '', 93 ), 94 95 array( 96 'x' => array( 97 0 => 'a', 98 1 => 'b', 99 2 => 'c', 100 ), 101 ), 102 array( 103 'x[0]' => 'a', 104 'x[1]' => 'b', 105 'x[2]' => 'c', 106 ), 107 108 array( 109 'x' => array( 110 'y' => array( 111 'z' => array( 112 40 => 'A', 113 50 => 'B', 114 'C' => 60, 115 ), 116 ), 117 ), 118 ), 119 array( 120 'x[y][z][40]' => 'A', 121 'x[y][z][50]' => 'B', 122 'x[y][z][C]' => '60', 123 ), 124 ); 125 126 for ($ii = 0; $ii < count($test_cases); $ii += 2) { 127 $input = $test_cases[$ii]; 128 $expect = $test_cases[$ii + 1]; 129 130 $this->assertEqual($expect, AphrontRequest::flattenData($input)); 131 } 132 } 133 134 public function testGetHTTPHeader() { 135 $server_data = array( 136 'HTTP_ACCEPT_ENCODING' => 'duck/quack', 137 'CONTENT_TYPE' => 'cow/moo', 138 ); 139 140 $this->assertEqual( 141 'duck/quack', 142 AphrontRequest::getHTTPHeader('AcCePt-EncOdING', null, $server_data)); 143 $this->assertEqual( 144 'cow/moo', 145 AphrontRequest::getHTTPHeader('cONTent-TyPE', null, $server_data)); 146 $this->assertEqual( 147 null, 148 AphrontRequest::getHTTPHeader('Pie-Flavor', null, $server_data)); 149 } 150 151 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |