예제 #1
0
 /**
  * @param Request $request
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function postAction(Request $request)
 {
     $dm = $this->get('doctrine_mongodb')->getManager();
     $form = new Form();
     $form->setName($request->get('name'));
     $form->setCreatedAt(new \MongoDate());
     $dm->persist($form);
     $dm->flush();
     $view = $this->view($form);
     return $this->handleView($view);
 }
 /**
  * @return Protocol
  */
 public function testCreateProtocol()
 {
     $form = new Form();
     $form->setName(static::$formName);
     $this->dm->persist($form);
     $protocol = new Protocol();
     $protocol->setForm($form);
     $this->dm->persist($protocol);
     $this->dm->flush();
     return $protocol;
 }
예제 #3
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();
 }
예제 #4
0
 /**
  * {@inheritDoc}
  */
 public function load(ObjectManager $manager)
 {
     $documentManager = $this->container->get('doctrine_mongodb.odm.document_manager');
     $form = new Form();
     $form->setName(static::NAME);
     $form->setTemplate(static::NAME);
     $page = new FormPage();
     $page->setNumber(1);
     $page->setTitle('First page');
     $page->setGroup('group_1');
     $form->addPage($page);
     unset($page);
     $page = new FormPage();
     $page->setNumber(2);
     $page->setTitle('Second page');
     $page->setGroup('group_1');
     $form->addPage($page);
     unset($page);
     $page = new FormPage();
     $page->setNumber(3);
     $page->setTitle('Third page');
     $page->setGroup('group_2');
     $form->addPage($page);
     unset($page);
     $page = new FormPage();
     $page->setNumber(4);
     $page->setTitle('Fourth page');
     $page->setGroup('group_2');
     $form->addPage($page);
     unset($page);
     $documentManager->persist($form);
     $documentManager->flush();
     $this->addReference(static::NAME, $form);
 }
 /**
  * @depends testFormNew
  * @param Form $form
  * @return Protocol
  */
 public function testPostProtocol($form)
 {
     $client = static::createClient();
     $client->request(Request::METHOD_POST, '/form/protocol/' . $form->getId(), [], [], ['HTTP_ACCEPT' => 'application/json']);
     $protocol = $this->assertJsonResponse($client->getResponse(), Response::HTTP_OK, true);
     $this->assertObjectHasAttributes(['id'], $protocol);
     return $protocol;
 }