From c026c13cfbdba81917fa0d4e9115e1aa62a4c2c2 Mon Sep 17 00:00:00 2001 From: "Mark A. Hershberger" Date: Mon, 15 Feb 2010 07:10:58 +0000 Subject: [PATCH] follow up r62498 tests for the requireOnlyOneParameter() change --- maintenance/tests/ApiTest.php | 76 +++++++++++++++++++++++++++++++++-- 1 file changed, 72 insertions(+), 4 deletions(-) diff --git a/maintenance/tests/ApiTest.php b/maintenance/tests/ApiTest.php index b177ebf200..d098b1a2a9 100644 --- a/maintenance/tests/ApiTest.php +++ b/maintenance/tests/ApiTest.php @@ -2,17 +2,65 @@ require_once( "ApiSetup.php" ); +class MockApi extends ApiBase { + public function execute() {} + public function getVersion() {} + + public function __construct() {} + + public function getAllowedParams() { + $params = array( + 'filename' => null, + 'enablechunks' => false, + 'sessionkey' => null, + ); + } + + +} + + class ApiTest extends ApiSetup { function setup() { - if($wgServerName == "localhost" || $wgServer == "http://localhost") { - $this->markTestIncomplete('This test needs $wgServerName and $wgServer to '. - 'be set in LocalSettings.php'); - } parent::setup(); } + function testRequireOnlyOneParameterDefault() { + $mock = new MockApi(); + + $this->assertEquals( + null, $mock->requireOnlyOneParameter(array("filename" => "foo.txt", + "enablechunks" => false), "filename", "enablechunks")); + } + + /** + * @expectedException UsageException + */ + function testRequireOnlyOneParameterZero() { + $mock = new MockApi(); + + $this->assertEquals( + null, $mock->requireOnlyOneParameter(array("filename" => "foo.txt", + "enablechunks" => 0), "filename", "enablechunks")); + } + + /** + * @expectedException UsageException + */ + function testRequireOnlyOneParameterTrue() { + $mock = new MockApi(); + + $this->assertEquals( + null, $mock->requireOnlyOneParameter(array("filename" => "foo.txt", + "enablechunks" => true), "filename", "enablechunks")); + } + function testApi() { + if(!isset($wgServername) || !isset($wgServer)) { + $this->markTestIncomplete('This test needs $wgServerName and $wgServer to '. + 'be set in LocalSettings.php'); + } /* Haven't thought about test ordering yet -- but this depends on HttpTest.php */ $resp = Http::get( self::$apiUrl . "?format=xml" ); @@ -23,6 +71,10 @@ class ApiTest extends ApiSetup { } function testApiLoginNoName() { + if(!isset($wgServername) || !isset($wgServer)) { + $this->markTestIncomplete('This test needs $wgServerName and $wgServer to '. + 'be set in LocalSettings.php'); + } $resp = Http::post( self::$apiUrl . "?action=login&format=xml", array( "postData" => array( "lgname" => "", @@ -36,6 +88,10 @@ class ApiTest extends ApiSetup { } function testApiLoginBadPass() { + if(!isset($wgServername) || !isset($wgServer)) { + $this->markTestIncomplete('This test needs $wgServerName and $wgServer to '. + 'be set in LocalSettings.php'); + } $resp = Http::post( self::$apiUrl . "?action=login&format=xml", array( "postData" => array( "lgname" => self::$userName, @@ -49,6 +105,10 @@ class ApiTest extends ApiSetup { } function testApiLoginGoodPass() { + if(!isset($wgServername) || !isset($wgServer)) { + $this->markTestIncomplete('This test needs $wgServerName and $wgServer to '. + 'be set in LocalSettings.php'); + } $resp = Http::post( self::$apiUrl . "?action=login&format=xml", array( "postData" => array( "lgname" => self::$userName, @@ -64,6 +124,10 @@ class ApiTest extends ApiSetup { function testApiGotCookie() { global $wgScriptPath, $wgServerName; + if(!isset($wgServername) || !isset($wgServer)) { + $this->markTestIncomplete('This test needs $wgServerName and $wgServer to '. + 'be set in LocalSettings.php'); + } $req = HttpRequest::factory( self::$apiUrl . "?action=login&format=xml", array( "method" => "POST", "postData" => array( "lgname" => self::$userName, @@ -83,6 +147,10 @@ class ApiTest extends ApiSetup { function testApiListPages(CookieJar $cj) { $this->markTestIncomplete("Not done with this yet"); + if($wgServerName == "localhost" || $wgServer == "http://localhost") { + $this->markTestIncomplete('This test needs $wgServerName and $wgServer to '. + 'be set in LocalSettings.php'); + } $req = HttpRequest::factory( self::$apiUrl . "?action=query&format=xml&prop=revisions&". "titles=Main%20Page&rvprop=timestamp|user|comment|content" ); $req->setCookieJar($cj); -- 2.20.1