public function testHttpMethodOverrides() { $request = new HTTPRequest('GET', 'admin/crm'); $this->assertTrue($request->isGET(), 'GET with no method override'); $request = new HTTPRequest('POST', 'admin/crm'); $this->assertTrue($request->isPOST(), 'POST with no method override'); $request = new HTTPRequest('GET', 'admin/crm', array('_method' => 'DELETE')); $this->assertTrue($request->isGET(), 'GET with invalid POST method override'); $request = new HTTPRequest('POST', 'admin/crm', array(), array('_method' => 'DELETE')); $this->assertTrue($request->isDELETE(), 'POST with valid method override to DELETE'); $request = new HTTPRequest('POST', 'admin/crm', array(), array('_method' => 'put')); $this->assertTrue($request->isPUT(), 'POST with valid method override to PUT'); $request = new HTTPRequest('POST', 'admin/crm', array(), array('_method' => 'head')); $this->assertTrue($request->isHEAD(), 'POST with valid method override to HEAD '); $request = new HTTPRequest('POST', 'admin/crm', array(), array('_method' => 'head')); $this->assertTrue($request->isHEAD(), 'POST with valid method override to HEAD'); $request = new HTTPRequest('POST', 'admin/crm', array('_method' => 'head')); $this->assertTrue($request->isPOST(), 'POST with invalid method override by GET parameters to HEAD'); }
/** * Retrieves details for files that this field wishes to attache to the * client-side form * * @param HTTPRequest $request * @return HTTPResponse */ public function attach(HTTPRequest $request) { if (!$request->isPOST()) { return $this->httpError(403); } if (!$this->canAttachExisting()) { return $this->httpError(403); } // Retrieve file attributes required by front end $return = array(); $files = File::get()->byIDs($request->postVar('ids')); foreach ($files as $file) { $return[] = $this->encodeFileAttributes($file); } $response = new HTTPResponse(Convert::raw2json($return)); $response->addHeader('Content-Type', 'application/json'); return $response; }