public function testRunPost() { $this->mapper->expects($this->once())->method('prepareObject')->with($this->equalTo($this->child_type))->will($this->returnValue('testmodel')); $this->type->expects($this->any())->method('getRevOptions')->will($this->returnValue(array('dcterms:partOf'))); $this->type->expects($this->any())->method('createWithObject')->will($this->returnValue($this->entity)); $rest = new RestService($this->mapper); $data = array('<http://purl.org/dc/terms/title>' => 'the title', '<http://purl.org/dc/terms/partOf>' => array('</parent/subject>')); $return = $rest->run($data, $this->type, null, RestService::HTTP_POST); $this->assertEquals(array('@subject' => '</the/subject>', '<http://purl.org/dc/terms/title>' => 'stored title'), $return); }
/** * Handle document POST (creation) * * @param Request $request * * @return Response * * @throws AccessDeniedException If the action is not allowed by the access * checker. */ public function postDocumentAction(Request $request) { if (!$this->accessChecker->check($request)) { throw new AccessDeniedException(); } $rdfType = trim($request->request->get('@type'), '<>'); $type = $this->typeFactory->getTypeByRdf($rdfType); $result = $this->restHandler->run($request->request->all(), $type, null, RestService::HTTP_POST); if (!is_null($result)) { $view = View::create($result)->setFormat('json'); return $this->viewHandler->handle($view, $request); } return Response::create('The document was not created', 500); }