Index: trunk/phase3/maintenance/tests/phpunit/includes/api/ApiTest.php |
— | — | @@ -90,32 +90,36 @@ |
91 | 91 | if ( !isset( $wgServer ) ) { |
92 | 92 | $this->markTestIncomplete( 'This test needs $wgServer to be set in LocalSettings.php' ); |
93 | 93 | } |
94 | | - $resp = Http::post( self::$apiUrl . "?action=login&format=xml", |
95 | | - array( "postData" => array( |
96 | | - "lgname" => self::$userName, |
97 | | - "lgpassword" => "bad" ) ) ); |
98 | | - libxml_use_internal_errors( true ); |
99 | | - $sxe = simplexml_load_string( $resp ); |
100 | | - $this->assertNotType( "bool", $sxe ); |
101 | | - $this->assertThat( $sxe, $this->isInstanceOf( "SimpleXMLElement" ) ); |
102 | | - $a = $sxe->login[0]->attributes()->result[0]; |
103 | | - $this->assertEquals( ' result="NeedToken"', $a->asXML() ); |
| 94 | + $ret = $this->doApiRequest( array( |
| 95 | + "action" => "login", |
| 96 | + "lgname" => self::$userName, |
| 97 | + "lgpassword" => "bad", |
| 98 | + ) |
| 99 | + ); |
104 | 100 | |
105 | | - $token = (string)$sxe->login[0]->attributes()->token; |
| 101 | + $result = $ret[0]; |
106 | 102 | |
107 | | - $resp = Http::post( self::$apiUrl . "?action=login&format=xml", |
108 | | - array( "postData" => array( |
109 | | - "lgtoken" => $token, |
110 | | - "lgname" => self::$userName, |
111 | | - "lgpassword" => "bad" ) ) ); |
| 103 | + $this->assertNotType( "bool", $result ); |
112 | 104 | |
| 105 | + $a = $result["login"]["result"]; |
| 106 | + $this->assertEquals( "NeedToken", $a ); |
113 | 107 | |
114 | | - $sxe = simplexml_load_string( $resp ); |
115 | | - $this->assertNotType( "bool", $sxe ); |
116 | | - $this->assertThat( $sxe, $this->isInstanceOf( "SimpleXMLElement" ) ); |
117 | | - $a = $sxe->login[0]->attributes()->result[0]; |
| 108 | + $token = $result["login"]["token"]; |
118 | 109 | |
119 | | - $this->assertEquals( ' result="NeedToken"', $a->asXML() ); |
| 110 | + $ret = $this->doApiRequest( array( |
| 111 | + "action" => "login", |
| 112 | + "lgtoken" => $token, |
| 113 | + "lgname" => self::$userName, |
| 114 | + "lgpassword" => "bad", |
| 115 | + ) |
| 116 | + ); |
| 117 | + |
| 118 | + $result = $ret[0]; |
| 119 | + |
| 120 | + $this->assertNotType( "bool", $result ); |
| 121 | + $a = $result["login"]["result"]; |
| 122 | + |
| 123 | + $this->assertEquals( "NeedToken", $a ); |
120 | 124 | } |
121 | 125 | |
122 | 126 | function testApiLoginGoodPass() { |
— | — | @@ -132,7 +136,6 @@ |
133 | 137 | ) |
134 | 138 | ); |
135 | 139 | |
136 | | - libxml_use_internal_errors( true ); |
137 | 140 | $result = $ret[0]; |
138 | 141 | $this->assertNotType( "bool", $result ); |
139 | 142 | $this->assertNotType( "null", $result["login"] ); |