4b838ce73da0844d05c4b272b1f2e49a4ec7ee4d
3 require_once( "ApiSetup.php" );
5 class MockApi
extends ApiBase
{
6 public function execute() {}
7 public function getVersion() {}
9 public function __construct() {}
11 public function getAllowedParams() {
14 'enablechunks' => false,
23 class ApiTest
extends ApiSetup
{
29 function testRequireOnlyOneParameterDefault() {
30 $mock = new MockApi();
33 null, $mock->requireOnlyOneParameter(array("filename" => "foo.txt",
34 "enablechunks" => false), "filename", "enablechunks"));
38 * @expectedException UsageException
40 function testRequireOnlyOneParameterZero() {
41 $mock = new MockApi();
44 null, $mock->requireOnlyOneParameter(array("filename" => "foo.txt",
45 "enablechunks" => 0), "filename", "enablechunks"));
49 * @expectedException UsageException
51 function testRequireOnlyOneParameterTrue() {
52 $mock = new MockApi();
55 null, $mock->requireOnlyOneParameter(array("filename" => "foo.txt",
56 "enablechunks" => true), "filename", "enablechunks"));
60 global $wgServerName, $wgServer, $wgDBprefix, $wgDBtype;
62 if($wgDBprefix === "parsertest_" ||
($wgDBtype == 'oracle' && $wgDBprefix === 'pt_'))
63 $this->markTestSkipped("This test can't (yet?) be run with the parser tests");
64 if(!isset($wgServerName) ||
!isset($wgServer)) {
65 $this->markTestIncomplete('This test needs $wgServerName and $wgServer to '.
66 'be set in LocalSettings.php');
68 /* Haven't thought about test ordering yet -- but this depends on HttpTest.php */
69 $resp = Http
::get( self
::$apiUrl . "?format=xml" );
71 libxml_use_internal_errors( true );
72 $sxe = simplexml_load_string( $resp );
73 $this->assertNotType( "bool", $sxe );
74 $this->assertThat( $sxe, $this->isInstanceOf( "SimpleXMLElement" ) );
77 function testApiLoginNoName() {
78 global $wgServerName, $wgServer, $wgDBprefix, $wgDBtype;
80 if($wgDBprefix === "parsertest_" ||
($wgDBtype == 'oracle' && $wgDBprefix === 'pt_'))
81 $this->markTestSkipped("This test can't (yet?) be run with the parser tests");
82 if(!isset($wgServerName) ||
!isset($wgServer)) {
83 $this->markTestIncomplete('This test needs $wgServerName and $wgServer to '.
84 'be set in LocalSettings.php');
86 $resp = Http
::post( self
::$apiUrl . "?action=login&format=xml",
87 array( "postData" => array(
89 "lgpassword" => self
::$passWord ) ) );
90 libxml_use_internal_errors( true );
91 $sxe = simplexml_load_string( $resp );
92 $this->assertNotType( "bool", $sxe );
93 $this->assertThat( $sxe, $this->isInstanceOf( "SimpleXMLElement" ) );
94 $a = $sxe->login
[0]->attributes()->result
;
95 $this->assertEquals( ' result="NoName"', $a->asXML() );
98 function testApiLoginBadPass() {
99 global $wgServerName, $wgServer, $wgDBprefix, $wgDBtype;
101 if($wgDBprefix === "parsertest_" ||
($wgDBtype == 'oracle' && $wgDBprefix === 'pt_'))
102 $this->markTestSkipped("This test can't (yet?) be run with the parser tests");
103 if(!isset($wgServerName) ||
!isset($wgServer)) {
104 $this->markTestIncomplete('This test needs $wgServerName and $wgServer to '.
105 'be set in LocalSettings.php');
107 $resp = Http
::post( self
::$apiUrl . "?action=login&format=xml",
108 array( "postData" => array(
109 "lgname" => self
::$userName,
110 "lgpassword" => "bad" ) ) );
111 libxml_use_internal_errors( true );
112 $sxe = simplexml_load_string( $resp );
113 $this->assertNotType( "bool", $sxe );
114 $this->assertThat( $sxe, $this->isInstanceOf( "SimpleXMLElement" ) );
115 $a = $sxe->login
[0]->attributes()->result
;
116 $this->assertEquals( ' result="WrongPass"', $a->asXML() );
119 function testApiLoginGoodPass() {
120 global $wgServerName, $wgServer, $wgDBprefix, $wgDBtype;
122 if($wgDBprefix === "parsertest_" ||
($wgDBtype == 'oracle' && $wgDBprefix === 'pt_'))
123 $this->markTestSkipped("This test can't (yet?) be run with the parser tests");
124 if(!isset($wgServerName) ||
!isset($wgServer)) {
125 $this->markTestIncomplete('This test needs $wgServerName and $wgServer to '.
126 'be set in LocalSettings.php');
128 $resp = Http
::post( self
::$apiUrl . "?action=login&format=xml",
129 array( "postData" => array(
130 "lgname" => self
::$userName,
131 "lgpassword" => self
::$passWord ) ) );
132 libxml_use_internal_errors( true );
133 $sxe = simplexml_load_string( $resp );
134 $this->assertNotType( "bool", $sxe );
135 $this->assertThat( $sxe, $this->isInstanceOf( "SimpleXMLElement" ) );
136 $a = $sxe->login
[0]->attributes()->result
;
137 $this->assertEquals( ' result="Success"', $a->asXML() );
140 function testApiGotCookie() {
141 global $wgServerName, $wgServer, $wgScriptPath, $wgDBprefix, $wgDBtype;
143 if($wgDBprefix === "parsertest_" ||
($wgDBtype == 'oracle' && $wgDBprefix === 'pt_'))
144 $this->markTestSkipped("This test can't (yet?) be run with the parser tests");
145 if(!isset($wgServerName) ||
!isset($wgServer)) {
146 $this->markTestIncomplete('This test needs $wgServerName and $wgServer to '.
147 'be set in LocalSettings.php');
149 $req = HttpRequest
::factory( self
::$apiUrl . "?action=login&format=xml",
150 array( "method" => "POST",
151 "postData" => array( "lgname" => self
::$userName,
152 "lgpassword" => self
::$passWord ) ) );
154 $cj = $req->getCookieJar();
155 $this->assertRegexp( '/_session=[^;]*; .*UserID=[0-9]*; .*UserName=' . self
::$userName . '; .*Token=/',
156 $cj->serializeToHttpRequest( $wgScriptPath, $wgServerName ) );
163 * @depends testApiGotCookie
165 function testApiListPages(CookieJar
$cj) {
166 $this->markTestIncomplete("Not done with this yet");
167 global $wgServerName, $wgServer, $wgDBprefix, $wgDBtype;
169 if($wgDBprefix === "parsertest_" ||
($wgDBtype == 'oracle' && $wgDBprefix === 'pt_'))
170 $this->markTestSkipped("This test can't (yet?) be run with the parser tests");
171 if($wgServerName == "localhost" ||
$wgServer == "http://localhost") {
172 $this->markTestIncomplete('This test needs $wgServerName and $wgServer to '.
173 'be set in LocalSettings.php');
175 $req = HttpRequest
::factory( self
::$apiUrl . "?action=query&format=xml&prop=revisions&".
176 "titles=Main%20Page&rvprop=timestamp|user|comment|content" );
177 $req->setCookieJar($cj);
179 libxml_use_internal_errors( true );
180 $sxe = simplexml_load_string( $req->getContent() );
181 $this->assertNotType( "bool", $sxe );
182 $this->assertThat( $sxe, $this->isInstanceOf( "SimpleXMLElement" ) );
183 $a = $sxe->query
[0]->pages
[0]->page
[0]->attributes();