Index: trunk/phase3/tests/MediaWikiAPITest.php |
— | — | @@ -0,0 +1,74 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +require_once("MediaWikiAPI_TestCase.php"); |
| 5 | + |
| 6 | +class MediaWikiAPITest extends MediaWikiAPI_TestCase { |
| 7 | + |
| 8 | + function setup() { |
| 9 | + parent::setup(); |
| 10 | + } |
| 11 | + |
| 12 | + function testApi() { |
| 13 | + /* Haven't thought about test ordering yet -- but this depends on HttpTest.php */ |
| 14 | + $resp = Http::get(self::$apiUrl."?format=xml"); |
| 15 | + |
| 16 | + libxml_use_internal_errors(true); |
| 17 | + $sxe = simplexml_load_string($resp); |
| 18 | + $this->assertNotType("bool", $sxe); |
| 19 | + $this->assertThat($sxe, $this->isInstanceOf("SimpleXMLElement")); |
| 20 | + } |
| 21 | + |
| 22 | + function testApiLoginNoName() { |
| 23 | + $resp = Http::post(self::$apiUrl."?action=login&format=xml", |
| 24 | + array("postData" => array( |
| 25 | + "lgname" => "", |
| 26 | + "lgpassword" => self::$passWord))); |
| 27 | + libxml_use_internal_errors(true); |
| 28 | + $sxe = simplexml_load_string($resp); |
| 29 | + $this->assertNotType("bool", $sxe); |
| 30 | + $this->assertThat($sxe, $this->isInstanceOf("SimpleXMLElement")); |
| 31 | + $a = $sxe->login[0]->attributes()->result; |
| 32 | + $this->assertEquals( ' result="NoName"', $a->asXML() ); |
| 33 | + } |
| 34 | + |
| 35 | + function testApiLoginBadPass() { |
| 36 | + $resp = Http::post(self::$apiUrl."?action=login&format=xml", |
| 37 | + array("postData" => array( |
| 38 | + "lgname" => self::$userName, |
| 39 | + "lgpassword" => "bad"))); |
| 40 | + libxml_use_internal_errors(true); |
| 41 | + $sxe = simplexml_load_string($resp); |
| 42 | + $this->assertNotType("bool", $sxe); |
| 43 | + $this->assertThat($sxe, $this->isInstanceOf("SimpleXMLElement")); |
| 44 | + $a = $sxe->login[0]->attributes()->result; |
| 45 | + $this->assertEquals( ' result="WrongPass"', $a->asXML() ); |
| 46 | + } |
| 47 | + |
| 48 | + function testApiLoginGoodPass() { |
| 49 | + $resp = Http::post(self::$apiUrl."?action=login&format=xml", |
| 50 | + array("postData" => array( |
| 51 | + "lgname" => self::$userName, |
| 52 | + "lgpassword" => self::$passWord))); |
| 53 | + libxml_use_internal_errors(true); |
| 54 | + $sxe = simplexml_load_string($resp); |
| 55 | + $this->assertNotType("bool", $sxe); |
| 56 | + $this->assertThat($sxe, $this->isInstanceOf("SimpleXMLElement")); |
| 57 | + $a = $sxe->login[0]->attributes()->result; |
| 58 | + $this->assertEquals( ' result="Success"', $a->asXML() ); |
| 59 | + } |
| 60 | + |
| 61 | + function testApiGotCookie() { |
| 62 | + global $wgScriptPath, $wgServerName; |
| 63 | + |
| 64 | + $req = HttpRequest::factory(self::$apiUrl."?action=login&format=xml", |
| 65 | + array("method" => "POST", |
| 66 | + "postData" => array( |
| 67 | + "lgname" => self::$userName, |
| 68 | + "lgpassword" => self::$passWord))); |
| 69 | + $req->execute(); |
| 70 | + $cj = $req->getCookieJar(); |
| 71 | + |
| 72 | + $this->assertRegexp( '/_session=[^;]*; .*UserID=[0-9]*; .*UserName='.self::$userName.'; .*Token=/', |
| 73 | + $cj->serializeToHttpRequest($wgScriptPath, $wgServerName) ); |
| 74 | + } |
| 75 | +} |
Property changes on: trunk/phase3/tests/MediaWikiAPITest.php |
___________________________________________________________________ |
Name: svn:eol-syle |
1 | 76 | + native |
Index: trunk/phase3/tests/MediaWikiAPI_TestCase.php |
— | — | @@ -0,0 +1,42 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +abstract class MediaWikiAPI_TestCase extends PHPUnit_Framework_TestCase { |
| 5 | + protected static $userName; |
| 6 | + protected static $passWord; |
| 7 | + protected static $user; |
| 8 | + protected static $apiUrl; |
| 9 | + |
| 10 | + function setup() { |
| 11 | + global $wgServerName, $wgServer, $wgContLang, $wgAuth, $wgScriptPath, |
| 12 | + $wgScriptExtension, $wgMemc; |
| 13 | + |
| 14 | + if($wgServerName == "localhost" || $wgServer == "http://localhost") { |
| 15 | + $this->markTestIncomplete('This test needs $wgServerName and $wgServer to '. |
| 16 | + 'be set in LocalSettings.php'); |
| 17 | + } |
| 18 | + self::$apiUrl = $wgServer.$wgScriptPath."/api".$wgScriptExtension; |
| 19 | + |
| 20 | + $wgMemc = new FakeMemCachedClient; |
| 21 | + $wgContLang = Language::factory( 'en' ); |
| 22 | + $wgAuth = new StubObject( 'wgAuth', 'AuthPlugin' ); |
| 23 | + self::setupUser(); |
| 24 | + } |
| 25 | + |
| 26 | + static function setupUser() { |
| 27 | + if ( self::$user == NULL ) { |
| 28 | + self::$userName = "Useruser"; |
| 29 | + self::$passWord = User::randomPassword(); |
| 30 | + |
| 31 | + self::$user = User::newFromName(self::$userName); |
| 32 | + if ( !self::$user->getID() ) { |
| 33 | + self::$user = User::createNew(self::$userName, array( |
| 34 | + "password" => self::$passWord, |
| 35 | + "email" => "test@example.com", |
| 36 | + "real_name" => "Test User")); |
| 37 | + } else { |
| 38 | + self::$user->setPassword(self::$passWord); |
| 39 | + } |
| 40 | + self::$user->saveSettings(); |
| 41 | + } |
| 42 | + } |
| 43 | +} |
Property changes on: trunk/phase3/tests/MediaWikiAPI_TestCase.php |
___________________________________________________________________ |
Name: svn:eol-syle |
1 | 44 | + native |
Index: trunk/phase3/includes/HttpFunctions.php |
— | — | @@ -257,7 +257,9 @@ |
258 | 258 | $list = array(); |
259 | 259 | |
260 | 260 | if( $this->cookieJar ) { |
261 | | - $this->reqHeaders['Cookie'] = $this->cookieJar->serializeToHttpRequest(); |
| 261 | + $this->reqHeaders['Cookie'] = |
| 262 | + $this->cookieJar->serializeToHttpRequest($this->parsedURL['path'], |
| 263 | + $this->parsedURL['host']); |
262 | 264 | } |
263 | 265 | foreach($this->reqHeaders as $name => $value) { |
264 | 266 | $list[] = "$name: $value"; |
— | — | @@ -553,6 +555,12 @@ |
554 | 556 | $attr[strtolower( $parts[0] )] = true; |
555 | 557 | } |
556 | 558 | } |
| 559 | + |
| 560 | + if( !isset( $attr['domain'] ) ) { |
| 561 | + $attr['domain'] = $domain; |
| 562 | + } else { |
| 563 | + /* FIXME: Check that domain is valid */ |
| 564 | + } |
557 | 565 | $this->setCookie( $name, $value, $attr ); |
558 | 566 | } |
559 | 567 | } |