diff options
author | Chad Horohoe <demon@users.mediawiki.org> | 2010-12-14 16:26:35 +0000 |
---|---|---|
committer | Chad Horohoe <demon@users.mediawiki.org> | 2010-12-14 16:26:35 +0000 |
commit | 23f69f10ed07c7fbe7d752882a88d55351ce2e3d (patch) | |
tree | 43054aea852645def63951fcbf45eb2cf2551adb /tests/phpunit/includes/api/ApiSetup.php | |
parent | 5903e492a5c60f65182d6339f63693aa2dca92f0 (diff) | |
download | mediawikicore-23f69f10ed07c7fbe7d752882a88d55351ce2e3d.tar.gz mediawikicore-23f69f10ed07c7fbe7d752882a88d55351ce2e3d.zip |
Per wikitech-l discussion: Move tests from maintenance/tests/ to tests/. They're not strictly maintenance scripts, and some people want to do a selective checkout that doesn't include the tests. There's still debate on whether we should include these in the release downloads, but we had a pretty firm consensus to move this.
Notes
Notes:
http://mediawiki.org/wiki/Special:Code/MediaWiki/78383
Diffstat (limited to 'tests/phpunit/includes/api/ApiSetup.php')
-rw-r--r-- | tests/phpunit/includes/api/ApiSetup.php | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/tests/phpunit/includes/api/ApiSetup.php b/tests/phpunit/includes/api/ApiSetup.php new file mode 100644 index 000000000000..f004f3c6bea0 --- /dev/null +++ b/tests/phpunit/includes/api/ApiSetup.php @@ -0,0 +1,65 @@ +<?php + +abstract class ApiTestSetup extends PHPUnit_Framework_TestCase { + protected static $user; + protected static $sysopUser; + protected static $apiUrl; + + function setUp() { + global $wgServer, $wgContLang, $wgAuth, $wgMemc, $wgRequest; + + self::$apiUrl = $wgServer . wfScript( 'api' ); + + $wgMemc = new FakeMemCachedClient; + $wgContLang = Language::factory( 'en' ); + $wgAuth = new StubObject( 'wgAuth', 'AuthPlugin' ); + $wgRequest = new FauxRequest( array() ); + self::setupUser(); + } + + protected function doApiRequest( $params, $data = null ) { + $_SESSION = isset( $data[2] ) ? $data[2] : array(); + + $req = new FauxRequest( $params, true, $_SESSION ); + $module = new ApiMain( $req, true ); + $module->execute(); + + $data[0] = $module->getResultData(); + $data[1] = $req; + $data[2] = $_SESSION; + + return $data; + } + + static function setupUser() { + if ( self::$user == null || self::$sysopUser == null ) { + self::$user = new UserWrapper( 'User for MediaWiki automated tests', User::randomPassword() ); + self::$sysopUser = new UserWrapper( 'Sysop for MediaWiki automated tests', User::randomPassword(), 'sysop' ); + } + + $GLOBALS['wgUser'] = self::$sysopUser->user; + } +} + +class UserWrapper { + public $userName, $password, $user; + + public function __construct( $userName, $password, $group = '' ) { + $this->userName = $userName; + $this->password = $password; + + $this->user = User::newFromName( $this->userName ); + if ( !$this->user->getID() ) { + $this->user = User::createNew( $this->userName, array( + "email" => "test@example.com", + "real_name" => "Test User" ) ); + } + $this->user->setPassword( $this->password ); + + if ( $group !== '' ) { + $this->user->addGroup( $group ); + } + $this->user->saveSettings(); + } +} + |