r100926 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r100925‎ | r100926 | r100927 >
Date:01:06, 27 October 2011
Author:johnduhart
Status:ok
Tags:
Comment:
Followup r100905, fixed the ApiTests
Modified paths:
  • /trunk/phase3/tests/phpunit/includes/api/ApiTestCase.php (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/phpunit/includes/api/ApiTestCase.php
@@ -7,6 +7,11 @@
88 public static $users;
99 protected static $apiUrl;
1010
 11+ /**
 12+ * @var ApiTestContext
 13+ */
 14+ protected $apiContext;
 15+
1116 function setUp() {
1217 global $wgContLang, $wgAuth, $wgMemc, $wgRequest, $wgUser, $wgServer;
1318
@@ -34,6 +39,8 @@
3540
3641 $wgUser = self::$users['sysop']->user;
3742
 43+ $this->apiContext = new ApiTestContext();
 44+
3845 }
3946
4047 protected function doApiRequest( $params, $session = null, $appendModule = false ) {
@@ -41,11 +48,15 @@
4249 $session = array();
4350 }
4451
45 - $request = new FauxRequest( $params, true, $session );
46 - $module = new ApiMain( $request, true );
 52+ $context = $this->apiContext->newTestContext( $params, $session );
 53+ $module = new ApiMain( $context, true );
4754 $module->execute();
4855
49 - $results = array( $module->getResultData(), $request, $request->getSessionArray() );
 56+ $results = array(
 57+ $module->getResultData(),
 58+ $context->getRequest(),
 59+ $context->getRequest()->getSessionArray()
 60+ );
5061 if( $appendModule ) {
5162 $results[] = $module;
5263 }
@@ -137,3 +148,19 @@
138149 );
139150 }
140151 }
 152+
 153+class ApiTestContext extends RequestContext {
 154+
 155+ /**
 156+ * Returns a DerivativeContext with the request variables in place
 157+ *
 158+ * @param $params Array key-value API params
 159+ * @param $session Array session data
 160+ * @return DerivativeContext
 161+ */
 162+ public function newTestContext( $params, $session ) {
 163+ $context = new DerivativeContext( $this );
 164+ $context->setRequest( new FauxRequest( $params, true, $session ) );
 165+ return $context;
 166+ }
 167+}

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r100905Adding context to the API...johnduhart23:27, 26 October 2011

Status & tagging log