r108104 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r108103‎ | r108104 | r108105 >
Date:00:26, 5 January 2012
Author:dantman
Status:ok
Tags:
Comment:
Followup r105809; Split up the tests with a dataProvider and add a round trip test.
Modified paths:
  • /trunk/phase3/tests/phpunit/includes/GlobalFunctions/GlobalTest.php (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/phpunit/includes/GlobalFunctions/GlobalTest.php
@@ -94,27 +94,82 @@
9595 $this->assertTrue( $end > $start, "Time is running backwards!" );
9696 }
9797
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() {
99125 $this->assertEquals(
100 - "baz=AT%26T&empty=&true=1&foo=bar",
 126+ "baz=bar&foo=bar",
101127 wfArrayToCGI(
102 - array( 'baz' => 'AT&T', 'empty' => '', 'ignored' => null, 'ignored2' => false, 'true' => true ),
 128+ array( 'baz' => 'bar' ),
103129 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' ) ) ) ) );
109130 }
110131
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+ );
117145 }
118146
 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+
119174 function testMimeTypeMatch() {
120175 $this->assertEquals(
121176 'text/html',

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r105809Update wfArrayToCGI and wfCgiToArray:...dantman18:25, 11 December 2011

Status & tagging log