Index: trunk/phase3/tests/phpunit/includes/api/ApiTestCase.php |
— | — | @@ -7,6 +7,11 @@ |
8 | 8 | public static $users; |
9 | 9 | protected static $apiUrl; |
10 | 10 | |
| 11 | + /** |
| 12 | + * @var ApiTestContext |
| 13 | + */ |
| 14 | + protected $apiContext; |
| 15 | + |
11 | 16 | function setUp() { |
12 | 17 | global $wgContLang, $wgAuth, $wgMemc, $wgRequest, $wgUser, $wgServer; |
13 | 18 | |
— | — | @@ -34,6 +39,8 @@ |
35 | 40 | |
36 | 41 | $wgUser = self::$users['sysop']->user; |
37 | 42 | |
| 43 | + $this->apiContext = new ApiTestContext(); |
| 44 | + |
38 | 45 | } |
39 | 46 | |
40 | 47 | protected function doApiRequest( $params, $session = null, $appendModule = false ) { |
— | — | @@ -41,11 +48,15 @@ |
42 | 49 | $session = array(); |
43 | 50 | } |
44 | 51 | |
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 ); |
47 | 54 | $module->execute(); |
48 | 55 | |
49 | | - $results = array( $module->getResultData(), $request, $request->getSessionArray() ); |
| 56 | + $results = array( |
| 57 | + $module->getResultData(), |
| 58 | + $context->getRequest(), |
| 59 | + $context->getRequest()->getSessionArray() |
| 60 | + ); |
50 | 61 | if( $appendModule ) { |
51 | 62 | $results[] = $module; |
52 | 63 | } |
— | — | @@ -137,3 +148,19 @@ |
138 | 149 | ); |
139 | 150 | } |
140 | 151 | } |
| 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 | +} |