Index: trunk/phase3/maintenance/tests/ApiTest.php |
— | — | @@ -112,8 +112,24 @@ |
113 | 113 | $sxe = simplexml_load_string( $resp ); |
114 | 114 | $this->assertNotType( "bool", $sxe ); |
115 | 115 | $this->assertThat( $sxe, $this->isInstanceOf( "SimpleXMLElement" ) ); |
116 | | - $a = $sxe->login[0]->attributes()->result; |
117 | | - $this->assertEquals( ' result="WrongPass"', $a->asXML() ); |
| 116 | + $a = $sxe->login[0]->attributes()->result[0]; |
| 117 | + $this->assertEquals( ' result="NeedToken"', $a->asXML() ); |
| 118 | + |
| 119 | + $token = (string)$sxe->login[0]->attributes()->token; |
| 120 | + |
| 121 | + $resp = Http::post( self::$apiUrl . "?action=login&format=xml", |
| 122 | + array( "postData" => array( |
| 123 | + "lgtoken" => $token, |
| 124 | + "lgname" => self::$userName, |
| 125 | + "lgpassword" => "bad" ) ) ); |
| 126 | + |
| 127 | + |
| 128 | + $sxe = simplexml_load_string( $resp ); |
| 129 | + $this->assertNotType( "bool", $sxe ); |
| 130 | + $this->assertThat( $sxe, $this->isInstanceOf( "SimpleXMLElement" ) ); |
| 131 | + $a = $sxe->login[0]->attributes()->result[0]; |
| 132 | + |
| 133 | + $this->assertEquals( ' result="NeedToken"', $a->asXML() ); |
118 | 134 | } |
119 | 135 | |
120 | 136 | function testApiLoginGoodPass() { |
— | — | @@ -125,15 +141,34 @@ |
126 | 142 | $this->markTestIncomplete('This test needs $wgServerName and $wgServer to '. |
127 | 143 | 'be set in LocalSettings.php'); |
128 | 144 | } |
129 | | - $resp = Http::post( self::$apiUrl . "?action=login&format=xml", |
130 | | - array( "postData" => array( |
131 | | - "lgname" => self::$userName, |
132 | | - "lgpassword" => self::$passWord ) ) ); |
| 145 | + $req = HttpRequest::factory(self::$apiUrl . "?action=login&format=xml", |
| 146 | + array( "method" => "POST", |
| 147 | + "postData" => array( |
| 148 | + "lgname" => self::$userName, |
| 149 | + "lgpassword" => self::$passWord ) ) ); |
| 150 | + $req->execute(); |
| 151 | + |
133 | 152 | libxml_use_internal_errors( true ); |
134 | | - $sxe = simplexml_load_string( $resp ); |
| 153 | + $sxe = simplexml_load_string( $req->getContent() ); |
135 | 154 | $this->assertNotType( "bool", $sxe ); |
136 | 155 | $this->assertThat( $sxe, $this->isInstanceOf( "SimpleXMLElement" ) ); |
137 | | - $a = $sxe->login[0]->attributes()->result; |
| 156 | + |
| 157 | + $a = $sxe->login[0]->attributes()->result[0]; |
| 158 | + $this->assertEquals( ' result="NeedToken"', $a->asXML() ); |
| 159 | + $token = (string)$sxe->login[0]->attributes()->token; |
| 160 | + |
| 161 | + $req->setData(array( |
| 162 | + "lgtoken" => $token, |
| 163 | + "lgname" => self::$userName, |
| 164 | + "lgpassword" => self::$passWord ) ); |
| 165 | + $req->execute(); |
| 166 | + |
| 167 | + $sxe = simplexml_load_string( $req->getContent() ); |
| 168 | + |
| 169 | + $this->assertNotType( "bool", $sxe ); |
| 170 | + $this->assertThat( $sxe, $this->isInstanceOf( "SimpleXMLElement" ) ); |
| 171 | + $a = $sxe->login[0]->attributes()->result[0]; |
| 172 | + |
138 | 173 | $this->assertEquals( ' result="Success"', $a->asXML() ); |
139 | 174 | } |
140 | 175 | |
— | — | @@ -146,11 +181,28 @@ |
147 | 182 | $this->markTestIncomplete('This test needs $wgServerName and $wgServer to '. |
148 | 183 | 'be set in LocalSettings.php'); |
149 | 184 | } |
150 | | - $req = HttpRequest::factory( self::$apiUrl . "?action=login&format=xml", |
151 | | - array( "method" => "POST", |
152 | | - "postData" => array( "lgname" => self::$userName, |
153 | | - "lgpassword" => self::$passWord ) ) ); |
| 185 | + $req = HttpRequest::factory(self::$apiUrl . "?action=login&format=xml", |
| 186 | + array( "method" => "POST", |
| 187 | + "postData" => array( |
| 188 | + "lgname" => self::$userName, |
| 189 | + "lgpassword" => self::$passWord ) ) ); |
154 | 190 | $req->execute(); |
| 191 | + |
| 192 | + libxml_use_internal_errors( true ); |
| 193 | + $sxe = simplexml_load_string( $req->getContent() ); |
| 194 | + $this->assertNotType( "bool", $sxe ); |
| 195 | + $this->assertThat( $sxe, $this->isInstanceOf( "SimpleXMLElement" ) ); |
| 196 | + |
| 197 | + $a = $sxe->login[0]->attributes()->result[0]; |
| 198 | + $this->assertEquals( ' result="NeedToken"', $a->asXML() ); |
| 199 | + $token = (string)$sxe->login[0]->attributes()->token; |
| 200 | + |
| 201 | + $req->setData(array( |
| 202 | + "lgtoken" => $token, |
| 203 | + "lgname" => self::$userName, |
| 204 | + "lgpassword" => self::$passWord ) ); |
| 205 | + $req->execute(); |
| 206 | + |
155 | 207 | $cj = $req->getCookieJar(); |
156 | 208 | $this->assertRegexp( '/_session=[^;]*; .*UserID=[0-9]*; .*UserName=' . self::$userName . '; .*Token=/', |
157 | 209 | $cj->serializeToHttpRequest( $wgScriptPath, $wgServerName ) ); |
Index: trunk/phase3/includes/WebRequest.php |
— | — | @@ -774,7 +774,7 @@ |
775 | 775 | } |
776 | 776 | |
777 | 777 | public function setSessionData( $key, $data ) { |
778 | | - $this->notImplemented( __METHOD__ ); |
| 778 | + $this->session[$key] = $data; |
779 | 779 | } |
780 | 780 | |
781 | 781 | public function isPathInfoBad() { |
Index: trunk/phase3/includes/HttpFunctions.php |
— | — | @@ -212,6 +212,15 @@ |
213 | 213 | } |
214 | 214 | |
215 | 215 | /** |
| 216 | + * Set the parameters of the request |
| 217 | + * @param $params array |
| 218 | + * @todo overload the args param |
| 219 | + */ |
| 220 | + public function setData($args) { |
| 221 | + $this->postData = $args; |
| 222 | + } |
| 223 | + |
| 224 | + /** |
216 | 225 | * Take care of setting up the proxy |
217 | 226 | * (override in subclass) |
218 | 227 | * @return string |
— | — | @@ -296,6 +305,8 @@ |
297 | 306 | public function execute() { |
298 | 307 | global $wgTitle; |
299 | 308 | |
| 309 | + $this->content = ""; |
| 310 | + |
300 | 311 | if( strtoupper($this->method) == "HEAD" ) { |
301 | 312 | $this->headersOnly = true; |
302 | 313 | } |