Index: trunk/phase3/tests/phpunit/includes/GlobalFunctions/GlobalTest.php |
— | — | @@ -94,27 +94,82 @@ |
95 | 95 | $this->assertTrue( $end > $start, "Time is running backwards!" ); |
96 | 96 | } |
97 | 97 | |
98 | | - function testArrayToCGI() { |
| 98 | + function dataArrayToCGI() { |
| 99 | + return array( |
| 100 | + array( array(), '' ), // empty |
| 101 | + array( array( 'foo' => 'bar' ), 'foo=bar' ), // string test |
| 102 | + array( array( 'foo' => '' ), 'foo=' ), // empty string test |
| 103 | + array( array( 'foo' => 1 ), 'foo=1' ), // number test |
| 104 | + array( array( 'foo' => true ), 'foo=1' ), // true test |
| 105 | + array( array( 'foo' => false ), '' ), // false test |
| 106 | + array( array( 'foo' => null ), '' ), // null test |
| 107 | + array( array( 'foo' => 'A&B=5+6@!"\'' ), 'foo=A%26B%3D5%2B6%40%21%22%27' ), // urlencoding test |
| 108 | + array( array( 'foo' => 'bar', 'baz' => 'is', 'asdf' => 'qwerty' ), 'foo=bar&baz=is&asdf=qwerty' ), // multi-item test |
| 109 | + array( array( 'foo' => array( 'bar' => 'baz' ) ), 'foo%5Bbar%5D=baz' ), |
| 110 | + array( array( 'foo' => array( 'bar' => 'baz', 'qwerty' => 'asdf' ) ), 'foo%5Bbar%5D=baz&foo%5Bqwerty%5D=asdf' ), |
| 111 | + array( array( 'foo' => array( 'bar', 'baz' ) ), 'foo%5B0%5D=bar&foo%5B1%5D=baz' ), |
| 112 | + array( array( 'foo' => array( 'bar' => array( 'bar' => 'baz' ) ) ), 'foo%5Bbar%5D%5Bbar%5D=baz' ), |
| 113 | + ); |
| 114 | + } |
| 115 | + |
| 116 | + /** |
| 117 | + * @dataProvider dataArrayToCGI |
| 118 | + */ |
| 119 | + function testArrayToCGI( $array, $result ) { |
| 120 | + $this->assertEquals( $result, wfArrayToCGI( $array ) ); |
| 121 | + } |
| 122 | + |
| 123 | + |
| 124 | + function testArrayToCGI2() { |
99 | 125 | $this->assertEquals( |
100 | | - "baz=AT%26T&empty=&true=1&foo=bar", |
| 126 | + "baz=bar&foo=bar", |
101 | 127 | wfArrayToCGI( |
102 | | - array( 'baz' => 'AT&T', 'empty' => '', 'ignored' => null, 'ignored2' => false, 'true' => true ), |
| 128 | + array( 'baz' => 'bar' ), |
103 | 129 | array( 'foo' => 'bar', 'baz' => 'overridden value' ) ) ); |
104 | | - $this->assertEquals( |
105 | | - "path%5B0%5D=wiki&path%5B1%5D=test&cfg%5Bservers%5D%5Bhttp%5D=localhost", |
106 | | - wfArrayToCGI( array( |
107 | | - 'path' => array( 'wiki', 'test' ), |
108 | | - 'cfg' => array( 'servers' => array( 'http' => 'localhost' ) ) ) ) ); |
109 | 130 | } |
110 | 131 | |
111 | | - function testCgiToArray() { |
112 | | - $this->assertEquals( |
113 | | - array( 'path' => array( 'wiki', 'test' ), |
114 | | - 'cfg' => array( 'servers' => array( 'http' => 'localhost' ) ), |
115 | | - 'qwerty' => '' ), |
116 | | - wfCgiToArray( 'path%5B0%5D=wiki&path%5B1%5D=test&cfg%5Bservers%5D%5Bhttp%5D=localhost&qwerty' ) ); |
| 132 | + function dataCgiToArray() { |
| 133 | + return array( |
| 134 | + array( '', array() ), // empty |
| 135 | + array( 'foo=bar', array( 'foo' => 'bar' ) ), // string |
| 136 | + array( 'foo=', array( 'foo' => '' ) ), // empty string |
| 137 | + array( 'foo', array( 'foo' => '' ) ), // missing = |
| 138 | + array( 'foo=bar&qwerty=asdf', array( 'foo' => 'bar', 'qwerty' => 'asdf' ) ), // multiple value |
| 139 | + array( 'foo=A%26B%3D5%2B6%40%21%22%27', array( 'foo' => 'A&B=5+6@!"\'' ) ), // urldecoding test |
| 140 | + array( 'foo%5Bbar%5D=baz', array( 'foo' => array( 'bar' => 'baz' ) ) ), |
| 141 | + array( 'foo%5Bbar%5D=baz&foo%5Bqwerty%5D=asdf', array( 'foo' => array( 'bar' => 'baz', 'qwerty' => 'asdf' ) ) ), |
| 142 | + array( 'foo%5B0%5D=bar&foo%5B1%5D=baz', array( 'foo' => array( 0 => 'bar', 1 => 'baz' ) ) ), |
| 143 | + array( 'foo%5Bbar%5D%5Bbar%5D=baz', array( 'foo' => array( 'bar' => array( 'bar' => 'baz' ) ) ) ), |
| 144 | + ); |
117 | 145 | } |
118 | 146 | |
| 147 | + /** |
| 148 | + * @dataProvider dataCgiToArray |
| 149 | + */ |
| 150 | + function testCgiToArray( $cgi, $result ) { |
| 151 | + $this->assertEquals( $result, wfCgiToArray( $cgi ) ); |
| 152 | + } |
| 153 | + |
| 154 | + function dataCgiRoundTrip() { |
| 155 | + return array( |
| 156 | + array( '' ), |
| 157 | + array( 'foo=bar' ), |
| 158 | + array( 'foo=' ), |
| 159 | + array( 'foo=bar&baz=biz' ), |
| 160 | + array( 'foo=A%26B%3D5%2B6%40%21%22%27' ), |
| 161 | + array( 'foo%5Bbar%5D=baz' ), |
| 162 | + array( 'foo%5B0%5D=bar&foo%5B1%5D=baz' ), |
| 163 | + array( 'foo%5Bbar%5D%5Bbar%5D=baz' ), |
| 164 | + ); |
| 165 | + } |
| 166 | + |
| 167 | + /** |
| 168 | + * @dataProvider dataCgiRoundTrip |
| 169 | + */ |
| 170 | + function testCgiRoundTrip( $cgi ) { |
| 171 | + $this->assertEquals( $cgi, wfArrayToCGI( wfCgiToArray( $cgi ) ) ); |
| 172 | + } |
| 173 | + |
119 | 174 | function testMimeTypeMatch() { |
120 | 175 | $this->assertEquals( |
121 | 176 | 'text/html', |