/**
  * @param $formId
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function postAction($formId)
 {
     $form = $this->getForm($formId, true);
     $dm = $this->get('doctrine_mongodb.odm.document_manager');
     $protocol = new Protocol();
     $protocol->setForm($form);
     $dm->persist($protocol);
     $dm->flush();
     return ['id' => $protocol->getId()];
 }
Example #2
0
 /**
  * Test Protocol Document
  * @depends testForm
  * @param Form $form
  */
 public function testProtocol(Form $form)
 {
     $formRepo = $this->documentManager->getRepository('FormBundle:Form');
     $formObj = $formRepo->find($form->getId());
     $protocol = new Protocol();
     $protocol->setForm($formObj);
     $protocol->setFirstSaveDate(new \MongoDate());
     $protocol->setLastSaveDate(new \MongoDate());
     $protocol->setConclusion('Conclusion');
     $file = new ProtocolFile();
     $upload = new UploadedFile(__FILE__, get_class());
     $file->setFile($upload);
     $file->setTitle('file_title');
     $file->setDescription('file_description');
     $file->setFilename($upload->getClientOriginalName());
     $file->setMimeType($upload->getClientMimeType());
     $file->setUploadDate(new \MongoDate());
     $file->setLength($upload->getSize());
     $file->setMd5('123');
     $file->setChunkSize(123);
     $file->setProtocol($protocol);
     $protocol->addFile($file);
     // Comment, User and NonUser are tested on ProtocolControllerTest
     $this->documentManager->persist($file);
     $this->documentManager->persist($protocol);
     $this->documentManager->flush();
     //        $this->documentManager->clear();
     $protocol = $this->documentManager->getRepository('FormBundle:Protocol')->find($protocol->getId());
     $this->assertNotEmpty($protocol->getId());
     $this->assertNotEmpty($protocol->getCreatedAt());
     $this->assertNotEmpty($protocol->getFirstSaveDate());
     $this->assertNotEmpty($protocol->getLastSaveDate());
     $this->assertNotEmpty($protocol->getForm());
     $this->assertEquals('Conclusion', $protocol->getConclusion());
     $this->assertTrue($protocol->getForm() instanceof Form);
     $this->assertEmpty($protocol->getOneComment('fake_123'));
     // Testing ProtocolFile
     //        $this->assertInstanceOf(get_class(new ArrayCollection()), $protocol->getFile());
     /** @var ProtocolFile $protocolFile */
     $protocolFile = $protocol->getFile()->first();
     $this->assertEquals('file_title', $protocolFile->getTitle());
     $this->assertEquals('file_description', $protocolFile->getDescription());
     $this->assertNotNull($protocolFile->getUploadDate());
     $this->assertNotNull($protocolFile->getLength());
     $this->assertNotNull($protocolFile->getChunkSize());
     $this->assertNotNull($protocolFile->getMd5());
     $protocol->removeFile($file);
     $this->documentManager->remove($protocol);
     $this->documentManager->remove($formObj);
     $this->documentManager->flush();
 }
 /**
  * @depends testCreateProtocol
  * @depends testDeleteUpload
  */
 public function testDeleteProtocol(Protocol $protocol)
 {
     $forms = $this->dm->getRepository('FormBundle:Form')->findByName($protocol->getForm()->getName());
     foreach ($forms as $form) {
         $this->dm->remove($form);
     }
     $this->dm->flush();
 }