X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Fapi%2FApiTestCase.php;h=552fbfbfb55d5979874fcacd58d8df4eabe52a11;hb=fba656f9861bab41f0d94735bbc5cde672575fd8;hp=7e054a466396c072ee1490811615cf2b736a0201;hpb=83e0bbb15913017ebd65081ac97a56d4369a01f6;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/api/ApiTestCase.php b/tests/phpunit/includes/api/ApiTestCase.php index 7e054a4663..552fbfbfb5 100644 --- a/tests/phpunit/includes/api/ApiTestCase.php +++ b/tests/phpunit/includes/api/ApiTestCase.php @@ -1,4 +1,4 @@ -user; + $this->setMwGlobals( array( + 'wgMemc' => new EmptyBagOStuff(), + 'wgAuth' => new StubObject( 'wgAuth', 'AuthPlugin' ), + 'wgRequest' => new FauxRequest( array() ), + 'wgUser' => self::$users['sysop']->user, + ) ); $this->apiContext = new ApiTestContext(); + } + /** + * Edits or creates a page/revision + * @param $pageName string page title + * @param $text string content of the page + * @param $summary string optional summary string for the revision + * @param $defaultNs int optional namespace id + * @return array as returned by WikiPage::doEditContent() + */ + protected function editPage( $pageName, $text, $summary = '', $defaultNs = NS_MAIN ) { + $title = Title::newFromText( $pageName, $defaultNs ); + $page = WikiPage::factory( $title ); + return $page->doEditContent( ContentHandler::makeContent( $text, $title ), $summary ); } /** @@ -102,6 +116,8 @@ abstract class ApiTestCase extends MediaWikiLangTestCase { * @param $params Array: key-value API params * @param $session Array|null: session array * @param $user User|null A User object for the context + * @return result of the API call + * @throws Exception in case wsToken is not set in the session */ protected function doApiRequestWithToken( array $params, array $session = null, User $user = null ) { global $wgRequest; @@ -129,12 +145,15 @@ abstract class ApiTestCase extends MediaWikiLangTestCase { $token = $data[0]['login']['token']; - $data = $this->doApiRequest( array( - 'action' => 'login', - 'lgtoken' => $token, - 'lgname' => self::$users['sysop']->username, - 'lgpassword' => self::$users['sysop']->password - ), $data[2] ); + $data = $this->doApiRequest( + array( + 'action' => 'login', + 'lgtoken' => $token, + 'lgname' => self::$users['sysop']->username, + 'lgpassword' => self::$users['sysop']->password, + ), + $data[2] + ); return $data; } @@ -147,10 +166,23 @@ abstract class ApiTestCase extends MediaWikiLangTestCase { 'prop' => 'info' ), $session, false, $user->user ); return $data; } + + public function testApiTestGroup() { + $groups = PHPUnit_Util_Test::getGroups( get_class( $this ) ); + $constraint = PHPUnit_Framework_Assert::logicalOr( + $this->contains( 'medium' ), + $this->contains( 'large' ) + ); + $this->assertThat( $groups, $constraint, + 'ApiTestCase::setUp can be slow, tests must be "medium" or "large"' + ); + } } class UserWrapper { - public $userName, $password, $user; + public $userName; + public $password; + public $user; public function __construct( $userName, $password, $group = '' ) { $this->userName = $userName; @@ -172,10 +204,11 @@ class UserWrapper { } class MockApi extends ApiBase { - public function execute() { } - public function getVersion() { } + public function execute() {} + + public function getVersion() {} - public function __construct() { } + public function __construct() {} public function getAllowedParams() { return array(