public function importAction()
 {
     $doctrine = $this->getDoctrine()->getManager();
     $tree = new Tree();
     $tree->setOwner($this->getUser());
     $treeVersion = new TreeVersion();
     $treeVersion->setTree($tree);
     $form = $this->createForm(new AdminTreeNewImportType(), $tree);
     $request = $this->getRequest();
     if ($request->getMethod() == 'POST') {
         $form->handleRequest($request);
         $importJSON = new ImportTreeVersionJSON($doctrine, $treeVersion, $form->get('data')->getData());
         if (!$importJSON->hasData()) {
             $form->addError(new FormError("That Import Data does not seem valid"));
         }
         if ($form->isValid()) {
             $doctrine->persist($tree);
             $doctrine->persist($treeVersion);
             $importJSON->process();
             $doctrine->flush();
             return $this->redirect($this->generateUrl('questionkey_admin_tree_show', array('treeId' => $tree->getPublicId())));
         }
     }
     return $this->render('QuestionKeyBundle:AdminTreeNew:index.html.twig', array('form' => $form->createView()));
 }
 function test1()
 {
     $user = new User();
     $user->setEmail("*****@*****.**");
     $user->setUsername("test");
     $user->setPassword("ouhosu");
     $this->em->persist($user);
     $tree = new Tree();
     $tree->setTitleAdmin('Tree IMPORTED');
     $tree->setPublicId('tree_imported');
     $tree->setOwner($user);
     $this->em->persist($tree);
     $treeVersion = new TreeVersion();
     $treeVersion->setTree($tree);
     $treeVersion->setPublicId('version');
     $this->em->persist($treeVersion);
     $this->em->flush();
     $importJSON = new ImportTreeVersionJSON($this->em, $treeVersion, file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'json_import_1.json'));
     $this->assertTrue($importJSON->hasData());
     $importJSON->process();
     $this->em->flush();
     ///////////////////////////////////////////////////////////////////// TEST IMPORTED TREE
     $nodeRepo = $this->em->getRepository('QuestionKeyBundle:Node');
     $startNode = $nodeRepo->findOneBy(array('treeVersion' => $treeVersion, 'publicId' => 'start'));
     $this->assertNotNull($startNode);
     $this->assertEquals('Start Here', $startNode->getTitle());
     $endNode = $nodeRepo->findOneBy(array('treeVersion' => $treeVersion, 'publicId' => 'end'));
     $this->assertNotNull($endNode);
     $this->assertEquals('End Here', $endNode->getTitle());
     $nodeOptionRepo = $this->em->getRepository('QuestionKeyBundle:NodeOption');
     $nodeOption = $nodeOptionRepo->findOneBy(array('treeVersion' => $treeVersion, 'publicId' => 'option'));
     $this->assertNotNull($nodeOption);
     $this->assertEquals('Click Here', $nodeOption->getTitle());
     $this->assertEquals('start', $nodeOption->getNode()->getPublicId());
     $this->assertEquals('end', $nodeOption->getDestinationNode()->getPublicId());
     $tvsnRepo = $this->em->getRepository('QuestionKeyBundle:TreeVersionStartingNode');
     $tvsn = $tvsnRepo->findOneBy(array('treeVersion' => $treeVersion));
     $this->assertNotNull($tvsn);
     $this->assertEquals('start', $tvsn->getNode()->getPublicId());
 }