3 class MockApi
extends ApiBase
{
4 public function execute() { }
5 public function getVersion() { }
7 public function __construct() { }
9 public function getAllowedParams() {
12 'enablechunks' => false,
18 class ApiTest
extends ApiTestSetup
{
24 function testRequireOnlyOneParameterDefault() {
25 $mock = new MockApi();
28 null, $mock->requireOnlyOneParameter( array( "filename" => "foo.txt",
29 "enablechunks" => false ), "filename", "enablechunks" ) );
33 * @expectedException UsageException
35 function testRequireOnlyOneParameterZero() {
36 $mock = new MockApi();
39 null, $mock->requireOnlyOneParameter( array( "filename" => "foo.txt",
40 "enablechunks" => 0 ), "filename", "enablechunks" ) );
44 * @expectedException UsageException
46 function testRequireOnlyOneParameterTrue() {
47 $mock = new MockApi();
50 null, $mock->requireOnlyOneParameter( array( "filename" => "foo.txt",
51 "enablechunks" => true ), "filename", "enablechunks" ) );
55 global $wgServerName, $wgServer;
57 if ( !isset( $wgServerName ) ||
!isset( $wgServer ) ) {
58 $this->markTestIncomplete( 'This test needs $wgServerName and $wgServer to ' .
59 'be set in LocalSettings.php' );
61 /* Haven't thought about test ordering yet -- but this depends on HttpTest.php */
62 $resp = Http
::get( self
::$apiUrl . "?format=xml" );
64 libxml_use_internal_errors( true );
65 $sxe = simplexml_load_string( $resp );
66 $this->assertNotType( "bool", $sxe );
67 $this->assertThat( $sxe, $this->isInstanceOf( "SimpleXMLElement" ) );
70 function testApiLoginNoName() {
71 global $wgServerName, $wgServer;
73 if ( !isset( $wgServerName ) ||
!isset( $wgServer ) ) {
74 $this->markTestIncomplete( 'This test needs $wgServerName and $wgServer to ' .
75 'be set in LocalSettings.php' );
77 $resp = Http
::post( self
::$apiUrl . "?action=login&format=xml",
78 array( "postData" => array(
80 "lgpassword" => self
::$passWord ) ) );
81 libxml_use_internal_errors( true );
82 $sxe = simplexml_load_string( $resp );
83 $this->assertNotType( "bool", $sxe );
84 $this->assertThat( $sxe, $this->isInstanceOf( "SimpleXMLElement" ) );
85 $a = $sxe->login
[0]->attributes()->result
;
86 $this->assertEquals( ' result="NoName"', $a->asXML() );
89 function testApiLoginBadPass() {
90 global $wgServerName, $wgServer;
92 if ( !isset( $wgServerName ) ||
!isset( $wgServer ) ) {
93 $this->markTestIncomplete( 'This test needs $wgServerName and $wgServer to ' .
94 'be set in LocalSettings.php' );
96 $resp = Http
::post( self
::$apiUrl . "?action=login&format=xml",
97 array( "postData" => array(
98 "lgname" => self
::$userName,
99 "lgpassword" => "bad" ) ) );
100 libxml_use_internal_errors( true );
101 $sxe = simplexml_load_string( $resp );
102 $this->assertNotType( "bool", $sxe );
103 $this->assertThat( $sxe, $this->isInstanceOf( "SimpleXMLElement" ) );
104 $a = $sxe->login
[0]->attributes()->result
[0];
105 $this->assertEquals( ' result="NeedToken"', $a->asXML() );
107 $token = (string)$sxe->login
[0]->attributes()->token
;
109 $resp = Http
::post( self
::$apiUrl . "?action=login&format=xml",
110 array( "postData" => array(
112 "lgname" => self
::$userName,
113 "lgpassword" => "bad" ) ) );
116 $sxe = simplexml_load_string( $resp );
117 $this->assertNotType( "bool", $sxe );
118 $this->assertThat( $sxe, $this->isInstanceOf( "SimpleXMLElement" ) );
119 $a = $sxe->login
[0]->attributes()->result
[0];
121 $this->assertEquals( ' result="NeedToken"', $a->asXML() );
124 function testApiLoginGoodPass() {
125 global $wgServerName, $wgServer;
127 if ( !isset( $wgServerName ) ||
!isset( $wgServer ) ) {
128 $this->markTestIncomplete( 'This test needs $wgServerName and $wgServer to ' .
129 'be set in LocalSettings.php' );
131 $req = HttpRequest
::factory( self
::$apiUrl . "?action=login&format=xml",
132 array( "method" => "POST",
134 "lgname" => self
::$userName,
135 "lgpassword" => self
::$passWord ) ) );
138 libxml_use_internal_errors( true );
139 $sxe = simplexml_load_string( $req->getContent() );
140 $this->assertNotType( "bool", $sxe );
141 $this->assertThat( $sxe, $this->isInstanceOf( "SimpleXMLElement" ) );
143 $a = $sxe->login
[0]->attributes()->result
[0];
144 $this->assertEquals( ' result="NeedToken"', $a->asXML() );
145 $token = (string)$sxe->login
[0]->attributes()->token
;
147 $req->setData( array(
149 "lgname" => self
::$userName,
150 "lgpassword" => self
::$passWord ) );
153 $sxe = simplexml_load_string( $req->getContent() );
155 $this->assertNotType( "bool", $sxe );
156 $this->assertThat( $sxe, $this->isInstanceOf( "SimpleXMLElement" ) );
157 $a = $sxe->login
[0]->attributes()->result
[0];
159 $this->assertEquals( ' result="Success"', $a->asXML() );
162 function testApiGotCookie() {
163 global $wgServerName, $wgServer, $wgScriptPath;
165 if ( !isset( $wgServerName ) ||
!isset( $wgServer ) ) {
166 $this->markTestIncomplete( 'This test needs $wgServerName and $wgServer to ' .
167 'be set in LocalSettings.php' );
169 $req = HttpRequest
::factory( self
::$apiUrl . "?action=login&format=xml",
170 array( "method" => "POST",
172 "lgname" => self
::$userName,
173 "lgpassword" => self
::$passWord ) ) );
176 libxml_use_internal_errors( true );
177 $sxe = simplexml_load_string( $req->getContent() );
178 $this->assertNotType( "bool", $sxe );
179 $this->assertThat( $sxe, $this->isInstanceOf( "SimpleXMLElement" ) );
181 $a = $sxe->login
[0]->attributes()->result
[0];
182 $this->assertEquals( ' result="NeedToken"', $a->asXML() );
183 $token = (string)$sxe->login
[0]->attributes()->token
;
185 $req->setData( array(
187 "lgname" => self
::$userName,
188 "lgpassword" => self
::$passWord ) );
191 $cj = $req->getCookieJar();
192 $this->assertRegexp( '/_session=[^;]*; .*UserID=[0-9]*; .*UserName=' . self
::$userName . '; .*Token=/',
193 $cj->serializeToHttpRequest( $wgScriptPath, $wgServerName ) );
200 * @depends testApiGotCookie
202 function testApiListPages( CookieJar
$cj ) {
203 $this->markTestIncomplete( "Not done with this yet" );
204 global $wgServerName, $wgServer;
206 if ( $wgServerName == "localhost" ||
$wgServer == "http://localhost" ) {
207 $this->markTestIncomplete( 'This test needs $wgServerName and $wgServer to ' .
208 'be set in LocalSettings.php' );
210 $req = HttpRequest
::factory( self
::$apiUrl . "?action=query&format=xml&prop=revisions&" .
211 "titles=Main%20Page&rvprop=timestamp|user|comment|content" );
212 $req->setCookieJar( $cj );
214 libxml_use_internal_errors( true );
215 $sxe = simplexml_load_string( $req->getContent() );
216 $this->assertNotType( "bool", $sxe );
217 $this->assertThat( $sxe, $this->isInstanceOf( "SimpleXMLElement" ) );
218 $a = $sxe->query
[0]->pages
[0]->page
[0]->attributes();