Index: trunk/phase3/maintenance/tests/phpunit/includes/api/ApiTest.php |
— | — | @@ -124,36 +124,37 @@ |
125 | 125 | if ( !isset( $wgServer ) ) { |
126 | 126 | $this->markTestIncomplete( 'This test needs $wgServer to be set in LocalSettings.php' ); |
127 | 127 | } |
128 | | - $req = HttpRequest::factory( self::$apiUrl . "?action=login&format=xml", |
129 | | - array( "method" => "POST", |
130 | | - "postData" => array( |
131 | | - "lgname" => self::$userName, |
132 | | - "lgpassword" => self::$passWord ) ) ); |
133 | | - $req->execute(); |
134 | 128 | |
| 129 | + $ret = $this->doApiRequest( array( |
| 130 | + "action" => "login", |
| 131 | + "lgname" => self::$userName, |
| 132 | + "lgpassword" => self::$passWord, |
| 133 | + ) |
| 134 | + ); |
| 135 | + |
135 | 136 | libxml_use_internal_errors( true ); |
136 | | - $sxe = simplexml_load_string( $req->getContent() ); |
137 | | - $this->assertNotType( "bool", $sxe ); |
138 | | - $this->assertThat( $sxe, $this->isInstanceOf( "SimpleXMLElement" ) ); |
139 | | - $this->assertNotType( "null", $sxe->login[0] ); |
| 137 | + $result = $ret[0]; |
| 138 | + $this->assertNotType( "bool", $result ); |
| 139 | + $this->assertNotType( "null", $result["login"] ); |
140 | 140 | |
141 | | - $a = $sxe->login[0]->attributes()->result[0]; |
142 | | - $this->assertEquals( ' result="NeedToken"', $a->asXML() ); |
143 | | - $token = (string)$sxe->login[0]->attributes()->token; |
| 141 | + $a = $result["login"]["result"]; |
| 142 | + $this->assertEquals( "NeedToken", $a ); |
| 143 | + $token = $result["login"]["token"]; |
144 | 144 | |
145 | | - $req->setData( array( |
| 145 | + $ret = $this->doApiRequest( array( |
| 146 | + "action" => "login", |
146 | 147 | "lgtoken" => $token, |
147 | 148 | "lgname" => self::$userName, |
148 | | - "lgpassword" => self::$passWord ) ); |
149 | | - $req->execute(); |
| 149 | + "lgpassword" => self::$passWord, |
| 150 | + ) |
| 151 | + ); |
150 | 152 | |
151 | | - $sxe = simplexml_load_string( $req->getContent() ); |
| 153 | + $result = $ret[0]; |
152 | 154 | |
153 | | - $this->assertNotType( "bool", $sxe ); |
154 | | - $this->assertThat( $sxe, $this->isInstanceOf( "SimpleXMLElement" ) ); |
155 | | - $a = $sxe->login[0]->attributes()->result[0]; |
| 155 | + $this->assertNotType( "bool", $result ); |
| 156 | + $a = $result["login"]["result"]; |
156 | 157 | |
157 | | - $this->assertEquals( ' result="Success"', $a->asXML() ); |
| 158 | + $this->assertEquals( "Success", $a ); |
158 | 159 | } |
159 | 160 | |
160 | 161 | function testApiGotCookie() { |
— | — | @@ -192,7 +193,6 @@ |
193 | 194 | $this->assertNotEquals( '', $serializedCookie ); |
194 | 195 | $this->assertRegexp( '/_session=[^;]*; .*UserID=[0-9]*; .*UserName=' . self::$userName . '; .*Token=/', $serializedCookie ); |
195 | 196 | |
196 | | - |
197 | 197 | return $cj; |
198 | 198 | } |
199 | 199 | |