Index: trunk/phase3/maintenance/tests/ApiTest.php |
— | — | @@ -2,17 +2,65 @@ |
3 | 3 | |
4 | 4 | require_once( "ApiSetup.php" ); |
5 | 5 | |
| 6 | +class MockApi extends ApiBase { |
| 7 | + public function execute() {} |
| 8 | + public function getVersion() {} |
| 9 | + |
| 10 | + public function __construct() {} |
| 11 | + |
| 12 | + public function getAllowedParams() { |
| 13 | + $params = array( |
| 14 | + 'filename' => null, |
| 15 | + 'enablechunks' => false, |
| 16 | + 'sessionkey' => null, |
| 17 | + ); |
| 18 | + } |
| 19 | + |
| 20 | + |
| 21 | +} |
| 22 | + |
| 23 | + |
6 | 24 | class ApiTest extends ApiSetup { |
7 | 25 | |
8 | 26 | function setup() { |
9 | | - if($wgServerName == "localhost" || $wgServer == "http://localhost") { |
10 | | - $this->markTestIncomplete('This test needs $wgServerName and $wgServer to '. |
11 | | - 'be set in LocalSettings.php'); |
12 | | - } |
13 | 27 | parent::setup(); |
14 | 28 | } |
15 | 29 | |
| 30 | + function testRequireOnlyOneParameterDefault() { |
| 31 | + $mock = new MockApi(); |
| 32 | + |
| 33 | + $this->assertEquals( |
| 34 | + null, $mock->requireOnlyOneParameter(array("filename" => "foo.txt", |
| 35 | + "enablechunks" => false), "filename", "enablechunks")); |
| 36 | + } |
| 37 | + |
| 38 | + /** |
| 39 | + * @expectedException UsageException |
| 40 | + */ |
| 41 | + function testRequireOnlyOneParameterZero() { |
| 42 | + $mock = new MockApi(); |
| 43 | + |
| 44 | + $this->assertEquals( |
| 45 | + null, $mock->requireOnlyOneParameter(array("filename" => "foo.txt", |
| 46 | + "enablechunks" => 0), "filename", "enablechunks")); |
| 47 | + } |
| 48 | + |
| 49 | + /** |
| 50 | + * @expectedException UsageException |
| 51 | + */ |
| 52 | + function testRequireOnlyOneParameterTrue() { |
| 53 | + $mock = new MockApi(); |
| 54 | + |
| 55 | + $this->assertEquals( |
| 56 | + null, $mock->requireOnlyOneParameter(array("filename" => "foo.txt", |
| 57 | + "enablechunks" => true), "filename", "enablechunks")); |
| 58 | + } |
| 59 | + |
16 | 60 | function testApi() { |
| 61 | + if(!isset($wgServername) || !isset($wgServer)) { |
| 62 | + $this->markTestIncomplete('This test needs $wgServerName and $wgServer to '. |
| 63 | + 'be set in LocalSettings.php'); |
| 64 | + } |
17 | 65 | /* Haven't thought about test ordering yet -- but this depends on HttpTest.php */ |
18 | 66 | $resp = Http::get( self::$apiUrl . "?format=xml" ); |
19 | 67 | |
— | — | @@ -23,6 +71,10 @@ |
24 | 72 | } |
25 | 73 | |
26 | 74 | function testApiLoginNoName() { |
| 75 | + if(!isset($wgServername) || !isset($wgServer)) { |
| 76 | + $this->markTestIncomplete('This test needs $wgServerName and $wgServer to '. |
| 77 | + 'be set in LocalSettings.php'); |
| 78 | + } |
27 | 79 | $resp = Http::post( self::$apiUrl . "?action=login&format=xml", |
28 | 80 | array( "postData" => array( |
29 | 81 | "lgname" => "", |
— | — | @@ -36,6 +88,10 @@ |
37 | 89 | } |
38 | 90 | |
39 | 91 | function testApiLoginBadPass() { |
| 92 | + if(!isset($wgServername) || !isset($wgServer)) { |
| 93 | + $this->markTestIncomplete('This test needs $wgServerName and $wgServer to '. |
| 94 | + 'be set in LocalSettings.php'); |
| 95 | + } |
40 | 96 | $resp = Http::post( self::$apiUrl . "?action=login&format=xml", |
41 | 97 | array( "postData" => array( |
42 | 98 | "lgname" => self::$userName, |
— | — | @@ -49,6 +105,10 @@ |
50 | 106 | } |
51 | 107 | |
52 | 108 | function testApiLoginGoodPass() { |
| 109 | + if(!isset($wgServername) || !isset($wgServer)) { |
| 110 | + $this->markTestIncomplete('This test needs $wgServerName and $wgServer to '. |
| 111 | + 'be set in LocalSettings.php'); |
| 112 | + } |
53 | 113 | $resp = Http::post( self::$apiUrl . "?action=login&format=xml", |
54 | 114 | array( "postData" => array( |
55 | 115 | "lgname" => self::$userName, |
— | — | @@ -64,6 +124,10 @@ |
65 | 125 | function testApiGotCookie() { |
66 | 126 | global $wgScriptPath, $wgServerName; |
67 | 127 | |
| 128 | + if(!isset($wgServername) || !isset($wgServer)) { |
| 129 | + $this->markTestIncomplete('This test needs $wgServerName and $wgServer to '. |
| 130 | + 'be set in LocalSettings.php'); |
| 131 | + } |
68 | 132 | $req = HttpRequest::factory( self::$apiUrl . "?action=login&format=xml", |
69 | 133 | array( "method" => "POST", |
70 | 134 | "postData" => array( "lgname" => self::$userName, |
— | — | @@ -83,6 +147,10 @@ |
84 | 148 | function testApiListPages(CookieJar $cj) { |
85 | 149 | $this->markTestIncomplete("Not done with this yet"); |
86 | 150 | |
| 151 | + if($wgServerName == "localhost" || $wgServer == "http://localhost") { |
| 152 | + $this->markTestIncomplete('This test needs $wgServerName and $wgServer to '. |
| 153 | + 'be set in LocalSettings.php'); |
| 154 | + } |
87 | 155 | $req = HttpRequest::factory( self::$apiUrl . "?action=query&format=xml&prop=revisions&". |
88 | 156 | "titles=Main%20Page&rvprop=timestamp|user|comment|content" ); |
89 | 157 | $req->setCookieJar($cj); |