我有一个控制器函数,它需要来自我的 JSON 调用的标头“X-Bla-Bla”。我用这个抓住了标题:
$this->request->header('X-Bla-Bla')
现在我想为此编写一个测试,但我无法发送标头。
我的测试如下所示:
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest';
$url = Router::url(array('api' => true, 'controller' => 'test', 'action' => 'index'));
$options = array(
'return' => 'contents',
);
$result = $this->testAction($url, $options);
$this->assertNotEmpty($result);
如何发送标头?
如果没有,我该如何测试我的功能?