/** * Test conditional headers output * @dataProvider provideConditionalRequestHeadersOutput * @param array $conditions Return data for ApiBase::getConditionalRequestData * @param array $headers Expected output headers * @param bool $isError $isError flag * @param bool $post Request is a POST */ public function testConditionalRequestHeadersOutput($conditions, $headers, $isError = false, $post = false) { $request = new FauxRequest(array('action' => 'query', 'meta' => 'siteinfo'), $post); $response = $request->response(); $api = new ApiMain($request); $priv = TestingAccessWrapper::newFromObject($api); $priv->mInternalMode = false; $module = $this->getMockBuilder('ApiBase')->setConstructorArgs(array($api, 'mock'))->setMethods(array('getConditionalRequestData'))->getMockForAbstractClass(); $module->expects($this->any())->method('getConditionalRequestData')->will($this->returnCallback(function ($condition) use($conditions) { return isset($conditions[$condition]) ? $conditions[$condition] : null; })); $priv->mModule = $module; $priv->sendCacheHeaders($isError); foreach (array('Last-Modified', 'ETag') as $header) { $this->assertEquals(isset($headers[$header]) ? $headers[$header] : null, $response->getHeader($header), $header); } }