Merge "Remove useless $out parameter from SkinTemplate::prepareQuickTemplate()"
[lhc/web/wiklou.git] / tests / phpunit / includes / api / ApiTestCase.php
index ad297dd..f633315 100644 (file)
@@ -43,11 +43,11 @@ abstract class ApiTestCase extends MediaWikiLangTestCase {
 
        /**
         * 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()
+        * @param string $pageName Page title
+        * @param string $text Content of the page
+        * @param string $summary Optional summary string for the revision
+        * @param int $defaultNs Optional namespace id
+        * @return Array as returned by WikiPage::doEditContent()
         */
        protected function editPage( $pageName, $text, $summary = '', $defaultNs = NS_MAIN ) {
                $title = Title::newFromText( $pageName, $defaultNs );
@@ -72,7 +72,9 @@ abstract class ApiTestCase extends MediaWikiLangTestCase {
         *
         * @return array
         */
-       protected function doApiRequest( array $params, array $session = null, $appendModule = false, User $user = null ) {
+       protected function doApiRequest( array $params, array $session = null,
+               $appendModule = false, User $user = null
+       ) {
                global $wgRequest, $wgUser;
 
                if ( is_null( $session ) ) {
@@ -112,22 +114,26 @@ abstract class ApiTestCase extends MediaWikiLangTestCase {
 
        /**
         * Add an edit token to the API request
-        * This is cheating a bit -- we grab a token in the correct format and then add it to the pseudo-session and to the
-        * request, without actually requesting a "real" edit token
-        * @param $params Array: key-value API params
-        * @param $session Array|null: session array
-        * @param $user User|null A User object for the context
-        * @return mixed result of the API call
-        * @throws Exception in case wsToken is not set in the session
+        * This is cheating a bit -- we grab a token in the correct format and then
+        * add it to the pseudo-session and to the request, without actually
+        * requesting a "real" edit token.
+        *
+        * @param array $params Key-value API params
+        * @param array|null $session Session array
+        * @param User|null $user 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 ) {
+       protected function doApiRequestWithToken( array $params, array $session = null,
+               User $user = null
+       ) {
                global $wgRequest;
 
                if ( $session === null ) {
                        $session = $wgRequest->getSessionArray();
                }
 
-               if ( $session['wsToken'] ) {
+               if ( isset( $session['wsToken'] ) && $session['wsToken'] ) {
                        // add edit token to fake session
                        $session['wsEditToken'] = $session['wsToken'];
                        // add token to request parameters
@@ -135,7 +141,7 @@ abstract class ApiTestCase extends MediaWikiLangTestCase {
 
                        return $this->doApiRequest( $params, $session, false, $user );
                } else {
-                       throw new Exception( "request data not in right format" );
+                       throw new Exception( "Session token not available" );
                }
        }
 
@@ -146,8 +152,8 @@ abstract class ApiTestCase extends MediaWikiLangTestCase {
 
                $data = $this->doApiRequest( array(
                        'action' => 'login',
-                       'lgname' => self::$users[ $user ]->username,
-                       'lgpassword' => self::$users[ $user ]->password ) );
+                       'lgname' => self::$users[$user]->username,
+                       'lgpassword' => self::$users[$user]->password ) );
 
                $token = $data[0]['login']['token'];
 
@@ -155,8 +161,8 @@ abstract class ApiTestCase extends MediaWikiLangTestCase {
                        array(
                                'action' => 'login',
                                'lgtoken' => $token,
-                               'lgname' => self::$users[ $user ]->username,
-                               'lgpassword' => self::$users[ $user ]->password,
+                               'lgname' => self::$users[$user]->username,
+                               'lgpassword' => self::$users[$user]->password,
                        ),
                        $data[2]
                );