function testCountNodesForTreeVersion1()
 {
     $user = new User();
     $user->setEmail("*****@*****.**");
     $user->setUsername("test");
     $user->setPassword("ouhosu");
     $this->em->persist($user);
     $tree = new Tree();
     $tree->setTitleAdmin('Tree');
     $tree->setOwner($user);
     $tree->setPublicId('tree');
     $this->em->persist($tree);
     $treeVersion = new TreeVersion();
     $treeVersion->setTree($tree);
     $treeVersion->setPublicId('version');
     $this->em->persist($treeVersion);
     $startNode = new Node();
     $startNode->setTreeVersion($treeVersion);
     $startNode->setPublicId('start');
     $this->em->persist($startNode);
     $middleNode = new Node();
     $middleNode->setTreeVersion($treeVersion);
     $middleNode->setPublicId('middle');
     $this->em->persist($middleNode);
     $endNode = new Node();
     $endNode->setTreeVersion($treeVersion);
     $endNode->setPublicId('end');
     $this->em->persist($endNode);
     $this->em->flush();
     // #################################################### TEST
     $nodeRepo = $this->em->getRepository('QuestionKeyBundle:Node');
     $this->assertEquals(3, $nodeRepo->getCountNodesForTreeVersion($treeVersion));
 }
 function test1()
 {
     $user = new User();
     $user->setEmail("*****@*****.**");
     $user->setUsername("test");
     $user->setPassword("ouhosu");
     $this->em->persist($user);
     $tree = new Tree();
     $tree->setTitleAdmin('Tree');
     $tree->setPublicId('tree');
     $tree->setOwner($user);
     $this->em->persist($tree);
     $treeVersion = new TreeVersion();
     $treeVersion->setTree($tree);
     $treeVersion->setPublicId('version');
     $this->em->persist($treeVersion);
     $startNode = new Node();
     $startNode->setTreeVersion($treeVersion);
     $startNode->setTitle("START HERE");
     $startNode->setPublicId('start');
     $this->em->persist($startNode);
     $endNode = new Node();
     $endNode->setTreeVersion($treeVersion);
     $endNode->setTitle("END HERE");
     $endNode->setPublicId('end');
     $this->em->persist($endNode);
     $nodeOption = new NodeOption();
     $nodeOption->setTitle("LETS GO HERE");
     $nodeOption->setTreeVersion($treeVersion);
     $nodeOption->setNode($startNode);
     $nodeOption->setDestinationNode($endNode);
     $nodeOption->setPublicId('option');
     $this->em->persist($nodeOption);
     $treeVersionPublished = new TreeVersionPublished();
     $treeVersionPublished->setTreeVersion($treeVersion);
     $treeVersionPublished->setPublishedBy($user);
     $this->em->flush();
     $tvsn = new TreeVersionStartingNode();
     $tvsn->setNode($startNode);
     $tvsn->setTreeVersion($treeVersion);
     $this->em->persist($tvsn);
     $published = new TreeVersionPublished();
     $published->setTreeVersion($treeVersion);
     $this->em->persist($published);
     $this->em->flush();
     // ######################################################## LOAD PAGE
     $this->driver->get('http://localhost/app_dev.php/tree/tree/demo/cascade');
     $startLink = $this->driver->findElement(WebDriverBy::id('StartTreeLink'));
     $this->assertEquals('Start Tree!', $startLink->getText());
     // ######################################################## Start Tree
     $startLink->click();
     sleep($this->sleepOnActionWithNetwork);
     $nodeTitle = $this->driver->findElement(WebDriverBy::id('DemoHere'));
     $this->assertEquals(0, strpos($nodeTitle->getText(), 'START HERE'));
     // ######################################################## LOAD PAGE
     $this->driver->findElement(WebDriverBy::id('DemoHere'))->findElement(WebDriverBy::cssSelector('option[value="option"]'))->click();
     sleep($this->sleepOnActionNoNetwork);
     $nodeTitle = $this->driver->findElement(WebDriverBy::id('DemoHere'));
     $this->assertGreaterThan(0, strpos($nodeTitle->getText(), 'END HERE'));
 }
 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 testPurge1()
 {
     $user = new User();
     $user->setEmail("*****@*****.**");
     $user->setUsername("test");
     $user->setPassword("ouhosu");
     $this->em->persist($user);
     $tree = new Tree();
     $tree->setTitleAdmin('Tree');
     $tree->setOwner($user);
     $tree->setPublicId('tree');
     $this->em->persist($tree);
     $treeVersion = new TreeVersion();
     $treeVersion->setTree($tree);
     $treeVersion->setPublicId('version');
     $treeVersion->setFeatureLibraryContent(true);
     $this->em->persist($treeVersion);
     $node = new Node();
     $node->setTreeVersion($treeVersion);
     $node->setPublicId('start');
     $this->em->persist($node);
     $content1 = new LibraryContent();
     $content1->setTitleAdmin('cats');
     $content1->getBodyText('cats are nice');
     $content1->setTreeVersion($treeVersion);
     $this->em->persist($content1);
     $this->em->flush();
     $nodeHasLibraryContentRepo = $this->em->getRepository('QuestionKeyBundle:NodeHasLibraryContent');
     $nodeHasLibraryContentRepo->addLibraryContentToNode($content1, $node);
     ################################ Start Purging
     $purgeTreeVersion = new PurgeTreeVersion($this->em, $treeVersion);
     $purgeTreeVersion->go();
 }
 public function testAddTwoCheckOrder()
 {
     $user = new User();
     $user->setEmail("*****@*****.**");
     $user->setUsername("test");
     $user->setPassword("ouhosu");
     $this->em->persist($user);
     $tree = new Tree();
     $tree->setTitleAdmin('Tree');
     $tree->setOwner($user);
     $tree->setPublicId('tree');
     $this->em->persist($tree);
     $treeVersion = new TreeVersion();
     $treeVersion->setTree($tree);
     $treeVersion->setPublicId('version');
     $treeVersion->setFeatureLibraryContent(true);
     $this->em->persist($treeVersion);
     $node = new Node();
     $node->setTreeVersion($treeVersion);
     $node->setPublicId('start');
     $this->em->persist($node);
     $content1 = new LibraryContent();
     $content1->setTitleAdmin('cats');
     $content1->getBodyText('cats are nice');
     $content1->setTreeVersion($treeVersion);
     $this->em->persist($content1);
     $content2 = new LibraryContent();
     $content2->setTitleAdmin('cats');
     $content2->getBodyText('cats are evil');
     $content2->setTreeVersion($treeVersion);
     $this->em->persist($content2);
     $this->em->flush();
     $libraryContentRepo = $this->em->getRepository('QuestionKeyBundle:LibraryContent');
     $nodeHasLibraryContentRepo = $this->em->getRepository('QuestionKeyBundle:NodeHasLibraryContent');
     // #################################################### TEST NO CONTENT
     $contentWeGot = $libraryContentRepo->findForNode($node);
     $this->assertEquals(0, count($contentWeGot));
     // #################################################### TEST ADD FIRST
     $nodeHasLibraryContentRepo->addLibraryContentToNode($content1, $node);
     $contentWeGot = $libraryContentRepo->findForNode($node);
     $this->assertEquals(1, count($contentWeGot));
     $this->assertEquals($content1->getId(), $contentWeGot[0]->getId());
     $nodeHasLibraryContent = $nodeHasLibraryContentRepo->findOneBy(array('node' => $node, 'libraryContent' => $content1));
     $this->assertNotNull($nodeHasLibraryContent);
     $this->assertEquals(0, $nodeHasLibraryContent->getSort());
     // #################################################### TEST ADD SECOND
     $nodeHasLibraryContentRepo->addLibraryContentToNode($content2, $node);
     $contentWeGot = $libraryContentRepo->findForNode($node);
     $this->assertEquals(2, count($contentWeGot));
     $this->assertEquals($content1->getId(), $contentWeGot[0]->getId());
     $this->assertEquals($content2->getId(), $contentWeGot[1]->getId());
     $nodeHasLibraryContent = $nodeHasLibraryContentRepo->findOneBy(array('node' => $node, 'libraryContent' => $content1));
     $this->assertNotNull($nodeHasLibraryContent);
     $this->assertEquals(0, $nodeHasLibraryContent->getSort());
     $nodeHasLibraryContent = $nodeHasLibraryContentRepo->findOneBy(array('node' => $node, 'libraryContent' => $content2));
     $this->assertNotNull($nodeHasLibraryContent);
     $this->assertEquals(1, $nodeHasLibraryContent->getSort());
 }
 public function doesPublicIdExist($id, TreeVersion $treeVersion)
 {
     if ($treeVersion->getId()) {
         $s = $this->getEntityManager()->createQuery(' SELECT lc FROM QuestionKeyBundle:LibraryContent lc' . ' WHERE lc.treeVersion = :treeVersion AND lc.publicId = :public_id')->setParameter('treeVersion', $treeVersion)->setParameter('public_id', $id)->getResult();
         return (bool) $s;
     } else {
         return false;
     }
 }
 public function doesCodeExist($code, TreeVersion $treeVersion)
 {
     if ($treeVersion->getId()) {
         $tvs = $this->getEntityManager()->createQuery(' SELECT tvpc FROM QuestionKeyBundle:TreeVersionPreviewCode tvpc' . ' WHERE tvpc.treeVersion = :treeVersion AND tvpc.code = :code')->setParameter('treeVersion', $treeVersion)->setParameter('code', $code)->getResult();
         return (bool) $tvs;
     } else {
         return false;
     }
 }
 function test1()
 {
     $user = new User();
     $user->setEmail("*****@*****.**");
     $user->setUsername("test");
     $user->setPassword("ouhosu");
     $this->em->persist($user);
     $tree = new Tree();
     $tree->setTitleAdmin('Tree');
     $tree->setPublicId('tree');
     $tree->setOwner($user);
     $this->em->persist($tree);
     $treeVersion = new TreeVersion();
     $treeVersion->setTree($tree);
     $treeVersion->setPublicId('version');
     $treeVersion->setFeatureLibraryContent(true);
     $this->em->persist($treeVersion);
     $startNode = new Node();
     $startNode->setTreeVersion($treeVersion);
     $startNode->setTitle("START HERE");
     $startNode->setPublicId('start');
     $this->em->persist($startNode);
     $libraryContent = new LibraryContent();
     $libraryContent->setTreeVersion($treeVersion);
     $libraryContent->setBodyText('TREE CONTENT');
     $this->em->persist($libraryContent);
     $nodeHasLibraryContent = new NodeHasLibraryContent();
     $nodeHasLibraryContent->setSort(0);
     $nodeHasLibraryContent->setNode($startNode);
     $nodeHasLibraryContent->setLibraryContent($libraryContent);
     $this->em->persist($nodeHasLibraryContent);
     $treeVersionPublished = new TreeVersionPublished();
     $treeVersionPublished->setTreeVersion($treeVersion);
     $treeVersionPublished->setPublishedBy($user);
     $this->em->flush();
     $tvsn = new TreeVersionStartingNode();
     $tvsn->setNode($startNode);
     $tvsn->setTreeVersion($treeVersion);
     $this->em->persist($tvsn);
     $published = new TreeVersionPublished();
     $published->setTreeVersion($treeVersion);
     $this->em->persist($published);
     $this->em->flush();
     // ######################################################## LOAD PAGE
     $this->driver->get('http://localhost/app_dev.php/tree/tree/demo');
     $startLink = $this->driver->findElement(WebDriverBy::id('StartTreeLink'));
     $this->assertEquals('Start Tree!', $startLink->getText());
     // ######################################################## Start Tree
     $startLink->click();
     sleep($this->sleepOnActionWithNetwork);
     $nodeTitle = $this->driver->findElement(WebDriverBy::id('DemoHere'))->findElement(WebDriverBy::className('node'))->findElement(WebDriverBy::className('title'));
     $this->assertEquals('START HERE', $nodeTitle->getText());
     $nodeBody = $this->driver->findElement(WebDriverBy::id('DemoHere'))->findElement(WebDriverBy::className('node'))->findElement(WebDriverBy::className('body'));
     $this->assertEquals('TREE CONTENT', $nodeBody->getText());
 }
 function testTwoNodes()
 {
     $user = new User();
     $user->setEmail("*****@*****.**");
     $user->setUsername("test");
     $user->setPassword("ouhosu");
     $this->em->persist($user);
     $tree = new Tree();
     $tree->setTitleAdmin('Tree');
     $tree->setPublicId('tree');
     $tree->setOwner($user);
     $this->em->persist($tree);
     $treeVersion = new TreeVersion();
     $treeVersion->setTree($tree);
     $treeVersion->setPublicId('version');
     $this->em->persist($treeVersion);
     $startNode = new Node();
     $startNode->setTreeVersion($treeVersion);
     $startNode->setPublicId('start');
     $this->em->persist($startNode);
     $endNode = new Node();
     $endNode->setTreeVersion($treeVersion);
     $endNode->setPublicId('end');
     $this->em->persist($endNode);
     $nodeOption = new NodeOption();
     $nodeOption->setTreeVersion($treeVersion);
     $nodeOption->setNode($startNode);
     $nodeOption->setDestinationNode($endNode);
     $nodeOption->setPublicId('option');
     $this->em->persist($nodeOption);
     $this->em->flush();
     $tvsn = new TreeVersionStartingNode();
     $tvsn->setNode($startNode);
     $tvsn->setTreeVersion($treeVersion);
     $this->em->persist($tvsn);
     $this->em->flush();
     // TEST
     $process = new GetUnreachableBitsOfTree($this->em, $treeVersion);
     $process->go();
     $unreachableNodes = $process->getUnreachableNodes();
     $this->assertEquals(0, count($unreachableNodes));
 }
 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());
 }
 public function newVersionAction($treeId, $versionId)
 {
     // build
     $return = $this->build($treeId, $versionId);
     //process
     $doctrine = $this->getDoctrine()->getManager();
     $newTreeVersion = new TreeVersion();
     $newTreeVersion->setTree($this->tree);
     $form = $this->createForm(new AdminTreeNewVersionType());
     $request = $this->getRequest();
     if ($request->getMethod() == 'POST') {
         $form->handleRequest($request);
         if ($form->isValid()) {
             $newTreeVersion->setTitleAdmin($form->get('title')->getData());
             $doctrine->persist($newTreeVersion);
             $copyNewVersionOfTree = new CopyNewVersionOfTree($doctrine, $this->treeVersion, $newTreeVersion);
             $copyNewVersionOfTree->go();
             $doctrine->flush();
             return $this->redirect($this->generateUrl('questionkey_admin_tree_version_show', array('treeId' => $this->tree->getPublicId(), 'versionId' => $newTreeVersion->getPublicId())));
         }
     }
     return $this->render('QuestionKeyBundle:AdminTreeVersionEdit:newVersion.html.twig', array('tree' => $this->tree, 'treeVersion' => $this->treeVersion, 'form' => $form->createView()));
 }
 function testThreeNodesInLine()
 {
     $user = new User();
     $user->setEmail("*****@*****.**");
     $user->setUsername("test");
     $user->setPassword("ouhosu");
     $this->em->persist($user);
     $tree = new Tree();
     $tree->setTitleAdmin('Tree');
     $tree->setPublicId('tree');
     $tree->setOwner($user);
     $this->em->persist($tree);
     $treeVersion = new TreeVersion();
     $treeVersion->setTree($tree);
     $treeVersion->setPublicId('version');
     $this->em->persist($treeVersion);
     $startNode = new Node();
     $startNode->setTreeVersion($treeVersion);
     $startNode->setPublicId('start');
     $this->em->persist($startNode);
     $middleNode = new Node();
     $middleNode->setTreeVersion($treeVersion);
     $middleNode->setPublicId('middle');
     $this->em->persist($middleNode);
     $endNode = new Node();
     $endNode->setTreeVersion($treeVersion);
     $endNode->setPublicId('end');
     $this->em->persist($endNode);
     $nodeOption1 = new NodeOption();
     $nodeOption1->setTreeVersion($treeVersion);
     $nodeOption1->setNode($startNode);
     $nodeOption1->setDestinationNode($middleNode);
     $nodeOption1->setPublicId('no1');
     $this->em->persist($nodeOption1);
     $nodeOption2 = new NodeOption();
     $nodeOption2->setTreeVersion($treeVersion);
     $nodeOption2->setNode($middleNode);
     $nodeOption2->setDestinationNode($endNode);
     $nodeOption2->setPublicId('no2');
     $this->em->persist($nodeOption2);
     $this->em->flush();
     $tvsnRepo = $this->em->getRepository('QuestionKeyBundle:TreeVersionStartingNode');
     $tvsnRepo->setAsStartingNode($startNode);
     $process = new GetStackTracesForNode($this->em, $endNode);
     $process->go();
     $stackTraces = $process->getStackTraces();
     $this->assertEquals(1, count($stackTraces));
     $stackTrace = $stackTraces[0];
     $this->assertEquals('e49c9061b266fe01007a004ff2cb7be3', $stackTrace->getPublicId());
     $data = $stackTrace->getData();
     $this->assertEquals(3, count($data));
     // DATA
     $dataRow = array_shift($data);
     $this->assertNotNull($dataRow['node']);
     $this->assertEquals($startNode->getId(), $dataRow['node']->getId());
     $this->assertNotNull($dataRow['nodeOption']);
     $this->assertEquals($nodeOption1->getId(), $dataRow['nodeOption']->getId());
     // DATA
     $dataRow = array_shift($data);
     $this->assertNotNull($dataRow['node']);
     $this->assertEquals($middleNode->getId(), $dataRow['node']->getId());
     $this->assertNotNull($dataRow['nodeOption']);
     $this->assertEquals($nodeOption2->getId(), $dataRow['nodeOption']->getId());
     // DATA
     $dataRow = array_shift($data);
     $this->assertNotNull($dataRow['node']);
     $this->assertEquals($endNode->getId(), $dataRow['node']->getId());
     $this->assertNull($dataRow['nodeOption']);
 }
 public function go()
 {
     $doctrine = $this->container->get('doctrine');
     $treeStartingNodeRepo = $doctrine->getRepository('QuestionKeyBundle:TreeVersionStartingNode');
     $nodeRepo = $doctrine->getRepository('QuestionKeyBundle:Node');
     $nodeOptionRepo = $doctrine->getRepository('QuestionKeyBundle:NodeOption');
     $nodeOptionVariableActionRepo = $doctrine->getRepository('QuestionKeyBundle:NodeOptionVariableAction');
     $libraryContentRepo = $doctrine->getRepository('QuestionKeyBundle:LibraryContent');
     $nodeHaslibraryContentIfVariableRepo = $doctrine->getRepository('QuestionKeyBundle:NodeHasLibraryContentIfVariable');
     //data
     $out = array('public_id' => $this->treeVersion->getTree()->getPublicId(), 'nodes' => array(), 'nodeOptions' => array(), 'version' => array('public_id' => $this->treeVersion->getPublicId()), 'features' => array('library_content' => array('status' => false), 'variables' => array('status' => false)));
     if ($this->treeVersion->isFeatureLibraryContent()) {
         $out['features']['library_content'] = array('status' => true);
         $out['library_content'] = array();
         $libraryContents = $libraryContentRepo->findByTreeVersion($this->treeVersion);
         foreach ($libraryContents as $libraryContent) {
             $out['library_content'][$libraryContent->getPublicId()] = array('id' => $libraryContent->getPublicId(), 'body_html' => $libraryContent->getBodyHTML(), 'body_text' => $libraryContent->getBodyText());
         }
     }
     if ($this->treeVersion->isFeatureVariables()) {
         $out['features']['variables'] = array('status' => true);
         $out['variables'] = array();
         $variableRepo = $doctrine->getRepository('QuestionKeyBundle:Variable');
         $variableContents = $variableRepo->findByTreeVersion($this->treeVersion);
         foreach ($variableContents as $variableContent) {
             $out['variables'][$variableContent->getName()] = array('name' => $variableContent->getName(), 'type' => $variableContent->getType());
         }
     }
     $treeStartingNode = $treeStartingNodeRepo->findOneByTreeVersion($this->treeVersion);
     if ($treeStartingNode) {
         $out['start_node'] = array('id' => $treeStartingNode->getNode()->getPublicId());
     }
     $nodes = $nodeRepo->findByTreeVersion($this->treeVersion);
     foreach ($nodes as $node) {
         $outNode = array('id' => $node->getPublicId(), 'body_html' => $node->getBodyHTML(), 'body_text' => $node->getBodyText(), 'title' => $node->getTitle(), 'title_previous_answers' => $node->getTitlePreviousAnswers(), 'options' => array());
         if ($this->isAdmin) {
             $outNode['title_admin'] = $node->getTitleAdmin();
             $outNode['url'] = $this->container->get('router')->generate("questionkey_admin_tree_version_node_show", array("treeId" => $this->treeVersion->getTree()->getPublicId(), 'versionId' => $this->treeVersion->getPublicId(), 'nodeId' => $node->getPublicId()));
         }
         if ($this->treeVersion->isFeatureLibraryContent()) {
             $outNode['library_content'] = array();
             foreach ($libraryContentRepo->findForNode($node) as $libraryContent) {
                 $outNodeHasLibraryContent = array('id' => $libraryContent->getPublicId(), 'conditions' => array());
                 if ($this->treeVersion->isFeatureVariables()) {
                     foreach ($nodeHaslibraryContentIfVariableRepo->findBy(array('node' => $node, 'libraryContent' => $libraryContent)) as $nodeHasLibraryContentIfVariable) {
                         $outNodeHasLibraryContent['conditions'][$nodeHasLibraryContentIfVariable->getPublicId()] = array('id' => $nodeHasLibraryContentIfVariable->getPublicId(), 'variable' => $nodeHasLibraryContentIfVariable->getVariable()->getname(), 'action' => strtolower($nodeHasLibraryContentIfVariable->getAction()), 'value' => $nodeHasLibraryContentIfVariable->getValue());
                     }
                 }
                 $outNode['library_content'][$libraryContent->getPublicId()] = $outNodeHasLibraryContent;
             }
         }
         foreach ($nodeOptionRepo->findActiveNodeOptionsForNode($node) as $nodeOption) {
             $outNode['options'][$nodeOption->getPublicId()] = array('id' => $nodeOption->getPublicId());
         }
         $out['nodes'][$node->getPublicId()] = $outNode;
     }
     foreach ($nodeOptionRepo->findAllNodeOptionsForTreeVersion($this->treeVersion) as $nodeOption) {
         $outNodeOption = array('id' => $nodeOption->getPublicId(), 'title' => $nodeOption->getTitle(), 'body_html' => $nodeOption->getBodyHTML(), 'body_text' => $nodeOption->getBodyText(), 'node' => array('id' => $nodeOption->getNode()->getPublicId()), 'destination_node' => array('id' => $nodeOption->getDestinationNode()->getPublicId()), 'variableActions' => array());
         if ($this->treeVersion->isFeatureVariables()) {
             foreach ($nodeOptionVariableActionRepo->findByNodeOption($nodeOption) as $nodeOptionVariableAction) {
                 $outNodeOption['variableActions'][$nodeOptionVariableAction->getPublicId()] = array('id' => $nodeOptionVariableAction->getPublicId(), 'variable' => $nodeOptionVariableAction->getVariable()->getname(), 'action' => strtolower($nodeOptionVariableAction->getAction()), 'value' => $nodeOptionVariableAction->getValue());
             }
         }
         $out['nodeOptions'][$nodeOption->getPublicId()] = $outNodeOption;
     }
     return $out;
 }
Example #14
0
 /**
  *    start
  *    /
  *    (1)
  *    /
  *  middle  -----(2)---> loop back
  *   \
  *   (3)
  *   \
  *    end
  **/
 function testDiamond1()
 {
     $user = new User();
     $user->setEmail("*****@*****.**");
     $user->setUsername("test");
     $user->setPassword("ouhosu");
     $this->em->persist($user);
     $tree = new Tree();
     $tree->setTitleAdmin('Tree');
     $tree->setOwner($user);
     $tree->setPublicId('tree');
     $this->em->persist($tree);
     $treeVersion = new TreeVersion();
     $treeVersion->setTree($tree);
     $treeVersion->setPublicId('version');
     $this->em->persist($treeVersion);
     $startNode = new Node();
     $startNode->setTreeVersion($treeVersion);
     $startNode->setPublicId('start');
     $this->em->persist($startNode);
     $middleNode = new Node();
     $middleNode->setTreeVersion($treeVersion);
     $middleNode->setPublicId('middle');
     $this->em->persist($middleNode);
     $endNode = new Node();
     $endNode->setTreeVersion($treeVersion);
     $endNode->setPublicId('end');
     $this->em->persist($endNode);
     $nodeOption1 = new NodeOption();
     $nodeOption1->setTreeVersion($treeVersion);
     $nodeOption1->setNode($startNode);
     $nodeOption1->setDestinationNode($middleNode);
     $nodeOption1->setPublicId('no1');
     $this->em->persist($nodeOption1);
     $nodeOption2 = new NodeOption();
     $nodeOption2->setTreeVersion($treeVersion);
     $nodeOption2->setNode($middleNode);
     $nodeOption2->setDestinationNode($middleNode);
     $nodeOption2->setPublicId('no2');
     $this->em->persist($nodeOption2);
     $nodeOption3 = new NodeOption();
     $nodeOption3->setTreeVersion($treeVersion);
     $nodeOption3->setNode($middleNode);
     $nodeOption3->setDestinationNode($endNode);
     $nodeOption3->setPublicId('no3');
     $this->em->persist($nodeOption3);
     $this->em->flush();
     $tvsnRepo = $this->em->getRepository('QuestionKeyBundle:TreeVersionStartingNode');
     $tvsnRepo->setAsStartingNode($startNode);
     $process = new GetStackTracesForNode($this->em, $endNode);
     $process->go();
     $stackTraces = $process->getStackTraces();
     $this->assertEquals(2, count($stackTraces));
     // #################################################### STACK TRACE 1
     $stackTrace = array_shift($stackTraces);
     $this->assertEquals('78ba40d50aa5b6b171709cdabf3da25a', $stackTrace->getPublicId());
     $data = $stackTrace->getData();
     $this->assertEquals(3, count($data));
     // DATA
     $dataRow = array_shift($data);
     $this->assertNotNull($dataRow['node']);
     $this->assertEquals($startNode->getId(), $dataRow['node']->getId());
     $this->assertNotNull($dataRow['nodeOption']);
     $this->assertEquals($nodeOption1->getId(), $dataRow['nodeOption']->getId());
     // DATA
     $dataRow = array_shift($data);
     $this->assertNotNull($dataRow['node']);
     $this->assertEquals($middleNode->getId(), $dataRow['node']->getId());
     $this->assertNotNull($dataRow['nodeOption']);
     $this->assertEquals($nodeOption3->getId(), $dataRow['nodeOption']->getId());
     // DATA
     $dataRow = array_shift($data);
     $this->assertNotNull($dataRow['node']);
     $this->assertEquals($endNode->getId(), $dataRow['node']->getId());
     $this->assertNull($dataRow['nodeOption']);
     // #################################################### STACK TRACE 2
     $stackTrace = array_shift($stackTraces);
     $this->assertEquals('a3592b8780c8ed8da478f42ea06b160a', $stackTrace->getPublicId());
     $data = $stackTrace->getData();
     $this->assertEquals(4, count($data));
     // DATA
     $dataRow = array_shift($data);
     $this->assertNotNull($dataRow['node']);
     $this->assertEquals($startNode->getId(), $dataRow['node']->getId());
     $this->assertNotNull($dataRow['nodeOption']);
     $this->assertEquals($nodeOption1->getId(), $dataRow['nodeOption']->getId());
     // DATA
     $dataRow = array_shift($data);
     $this->assertNotNull($dataRow['node']);
     $this->assertEquals($middleNode->getId(), $dataRow['node']->getId());
     $this->assertNotNull($dataRow['nodeOption']);
     $this->assertEquals($nodeOption2->getId(), $dataRow['nodeOption']->getId());
     // DATA
     $dataRow = array_shift($data);
     $this->assertNotNull($dataRow['node']);
     $this->assertEquals($middleNode->getId(), $dataRow['node']->getId());
     $this->assertNotNull($dataRow['nodeOption']);
     $this->assertEquals($nodeOption3->getId(), $dataRow['nodeOption']->getId());
     // DATA
     $dataRow = array_shift($data);
     $this->assertNotNull($dataRow['node']);
     $this->assertEquals($endNode->getId(), $dataRow['node']->getId());
     $this->assertNull($dataRow['nodeOption']);
 }
 /**
  *    start
  *    /    \
  *    (1)  (2)
  *    /    \
  *  left  right
  *   \     /
  *   (3)   (4)
  *   \     /
  *    end
  **/
 function testDiamond1()
 {
     $user = new User();
     $user->setEmail("*****@*****.**");
     $user->setUsername("test");
     $user->setPassword("ouhosu");
     $this->em->persist($user);
     $tree = new Tree();
     $tree->setTitleAdmin('Tree');
     $tree->setOwner($user);
     $tree->setPublicId('tree');
     $this->em->persist($tree);
     $treeVersion = new TreeVersion();
     $treeVersion->setTree($tree);
     $treeVersion->setPublicId('version');
     $this->em->persist($treeVersion);
     $startNode = new Node();
     $startNode->setTreeVersion($treeVersion);
     $startNode->setPublicId('start');
     $this->em->persist($startNode);
     $leftNode = new Node();
     $leftNode->setTreeVersion($treeVersion);
     $leftNode->setPublicId('left');
     $this->em->persist($leftNode);
     $rightNode = new Node();
     $rightNode->setTreeVersion($treeVersion);
     $rightNode->setPublicId('right');
     $this->em->persist($rightNode);
     $endNode = new Node();
     $endNode->setTreeVersion($treeVersion);
     $endNode->setPublicId('end');
     $this->em->persist($endNode);
     $nodeOption1 = new NodeOption();
     $nodeOption1->setTreeVersion($treeVersion);
     $nodeOption1->setNode($startNode);
     $nodeOption1->setDestinationNode($leftNode);
     $nodeOption1->setPublicId('no1');
     $this->em->persist($nodeOption1);
     $nodeOption2 = new NodeOption();
     $nodeOption2->setTreeVersion($treeVersion);
     $nodeOption2->setNode($startNode);
     $nodeOption2->setDestinationNode($rightNode);
     $nodeOption2->setPublicId('no2');
     $this->em->persist($nodeOption2);
     $nodeOption3 = new NodeOption();
     $nodeOption3->setTreeVersion($treeVersion);
     $nodeOption3->setNode($leftNode);
     $nodeOption3->setDestinationNode($endNode);
     $nodeOption3->setPublicId('no3');
     $this->em->persist($nodeOption3);
     $nodeOption4 = new NodeOption();
     $nodeOption4->setTreeVersion($treeVersion);
     $nodeOption4->setNode($rightNode);
     $nodeOption4->setDestinationNode($endNode);
     $nodeOption4->setPublicId('no4');
     $this->em->persist($nodeOption4);
     $this->em->flush();
     $tvsnRepo = $this->em->getRepository('QuestionKeyBundle:TreeVersionStartingNode');
     $tvsnRepo->setAsStartingNode($startNode);
     $process = new GetStackTracesForNode($this->em, $endNode);
     $process->go();
     $stackTraces = $process->getStackTraces();
     $this->assertEquals(2, count($stackTraces));
     // #################################################### STACK TRACE 1
     $stackTrace = array_shift($stackTraces);
     $this->assertEquals('0e5c398d20010437c8a7c5282269e69a', $stackTrace->getPublicId());
     $data = $stackTrace->getData();
     $this->assertEquals(3, count($data));
     // DATA
     $dataRow = array_shift($data);
     $this->assertNotNull($dataRow['node']);
     $this->assertEquals($startNode->getId(), $dataRow['node']->getId());
     $this->assertNotNull($dataRow['nodeOption']);
     $this->assertEquals($nodeOption1->getId(), $dataRow['nodeOption']->getId());
     // DATA
     $dataRow = array_shift($data);
     $this->assertNotNull($dataRow['node']);
     $this->assertEquals($leftNode->getId(), $dataRow['node']->getId());
     $this->assertNotNull($dataRow['nodeOption']);
     $this->assertEquals($nodeOption3->getId(), $dataRow['nodeOption']->getId());
     // DATA
     $dataRow = array_shift($data);
     $this->assertNotNull($dataRow['node']);
     $this->assertEquals($endNode->getId(), $dataRow['node']->getId());
     $this->assertNull($dataRow['nodeOption']);
     // #################################################### STACK TRACE 2
     $stackTrace = array_shift($stackTraces);
     $this->assertEquals('10ff10dbc9b10356f7d53ed65b77a5e0', $stackTrace->getPublicId());
     $data = $stackTrace->getData();
     $this->assertEquals(3, count($data));
     // DATA
     $dataRow = array_shift($data);
     $this->assertNotNull($dataRow['node']);
     $this->assertEquals($startNode->getId(), $dataRow['node']->getId());
     $this->assertNotNull($dataRow['nodeOption']);
     $this->assertEquals($nodeOption2->getId(), $dataRow['nodeOption']->getId());
     // DATA
     $dataRow = array_shift($data);
     $this->assertNotNull($dataRow['node']);
     $this->assertEquals($rightNode->getId(), $dataRow['node']->getId());
     $this->assertNotNull($dataRow['nodeOption']);
     $this->assertEquals($nodeOption4->getId(), $dataRow['nodeOption']->getId());
     // DATA
     $dataRow = array_shift($data);
     $this->assertNotNull($dataRow['node']);
     $this->assertEquals($endNode->getId(), $dataRow['node']->getId());
     $this->assertNull($dataRow['nodeOption']);
 }
 function testCopyLibraryContent()
 {
     $nodeHasLibraryContentRepo = $this->em->getRepository('QuestionKeyBundle:NodeHasLibraryContent');
     $user = new User();
     $user->setEmail("*****@*****.**");
     $user->setUsername("test");
     $user->setPassword("ouhosu");
     $this->em->persist($user);
     $tree = new Tree();
     $tree->setTitleAdmin('Tree');
     $tree->setOwner($user);
     $tree->setPublicId('tree');
     $this->em->persist($tree);
     $treeVersionOld = new TreeVersion();
     $treeVersionOld->setTree($tree);
     $treeVersionOld->setPublicId('v1');
     $treeVersionOld->setTitleAdmin('v1');
     $treeVersionOld->setFeatureLibraryContent(true);
     $this->em->persist($treeVersionOld);
     $treeVersionNew = new TreeVersion();
     $treeVersionNew->setTree($tree);
     $treeVersionNew->setPublicId('v2');
     $treeVersionNew->setTitleAdmin('v2');
     $treeVersionNew->setFeatureLibraryContent(true);
     $this->em->persist($treeVersionNew);
     $nodeOld1 = new Node();
     $nodeOld1->setTreeVersion($treeVersionOld);
     $nodeOld1->setPublicId('start');
     $nodeOld1->setTitle('START HERE');
     $this->em->persist($nodeOld1);
     $libraryContentOld1 = new LibraryContent();
     $libraryContentOld1->setTitleAdmin('TEST');
     $libraryContentOld1->setBodyText('test1');
     $libraryContentOld1->setTreeVersion($treeVersionOld);
     $this->em->persist($libraryContentOld1);
     $libraryContentOld2 = new LibraryContent();
     $libraryContentOld2->setTitleAdmin('TEST');
     $libraryContentOld2->setBodyText('test2');
     $libraryContentOld2->setTreeVersion($treeVersionOld);
     $this->em->persist($libraryContentOld2);
     $this->em->flush();
     $this->em->getRepository('QuestionKeyBundle:NodeHasLibraryContent')->addLibraryContentToNode($libraryContentOld1, $nodeOld1);
     $this->em->getRepository('QuestionKeyBundle:NodeHasLibraryContent')->addLibraryContentToNode($libraryContentOld2, $nodeOld1);
     ##################### COPY
     $copyNewVersionOfTree = new CopyNewVersionOfTree($this->em, $treeVersionOld, $treeVersionNew);
     $copyNewVersionOfTree->go();
     #####################  TEST NODES DIRECTLY
     $nodes = $this->em->getRepository('QuestionKeyBundle:Node')->findBy(array('treeVersion' => $treeVersionNew), array('publicId' => 'ASC'));
     $this->assertEquals(1, count($nodes));
     $node = $nodes[0];
     $this->assertEquals($nodeOld1->getPublicId(), $node->getPublicId());
     $this->assertEquals($nodeOld1->getTitle(), $node->getTitle());
     $this->assertEquals($nodeOld1->getTitleAdmin(), $node->getTitleAdmin());
     $this->assertEquals($nodeOld1->getTitlePreviousAnswers(), $node->getTitlePreviousAnswers());
     #####################  TEST LIBRARY CONTENT DIRECTLY
     $libraryContents = $this->em->getRepository('QuestionKeyBundle:LibraryContent')->findBy(array('treeVersion' => $treeVersionNew), array('publicId' => 'ASC'));
     $this->assertEquals(2, count($libraryContents));
     $libraryContent = $libraryContents[0];
     $this->assertEquals($libraryContentOld1->getTitleAdmin(), $libraryContent->getTitleAdmin());
     $libraryContent = $libraryContents[1];
     $this->assertEquals($libraryContentOld2->getTitleAdmin(), $libraryContent->getTitleAdmin());
     #####################  TEST LIBRARY CONTENT LOADING OFF NODE, INC SORT ORDER
     $libraryContents = $this->em->getRepository('QuestionKeyBundle:LibraryContent')->findForNode($node);
     $this->assertEquals(2, count($libraryContents));
     $libraryContent = $libraryContents[0];
     $this->assertEquals($libraryContentOld1->getTitleAdmin(), $libraryContent->getTitleAdmin());
     $nodeHasLibraryContent = $nodeHasLibraryContentRepo->findOneBy(array('libraryContent' => $libraryContent));
     $this->assertNotNull($nodeHasLibraryContent);
     $this->assertEquals(0, $nodeHasLibraryContent->getSort());
     $libraryContent = $libraryContents[1];
     $this->assertEquals($libraryContentOld2->getTitleAdmin(), $libraryContent->getTitleAdmin());
     $nodeHasLibraryContent = $nodeHasLibraryContentRepo->findOneBy(array('libraryContent' => $libraryContent));
     $this->assertNotNull($nodeHasLibraryContent);
     $this->assertEquals(1, $nodeHasLibraryContent->getSort());
 }
 public function setUp()
 {
     parent::setUp();
     // ################################################ Basic Details
     $user = new User();
     $user->setEmail("*****@*****.**");
     $user->setUsername("test");
     $user->setPassword("ouhosu");
     $this->em->persist($user);
     $tree = new Tree();
     $tree->setTitleAdmin('Tree');
     $tree->setPublicId('tree');
     $tree->setOwner($user);
     $this->em->persist($tree);
     $treeVersion = new TreeVersion();
     $treeVersion->setTree($tree);
     $treeVersion->setPublicId('version');
     $treeVersion->setFeatureLibraryContent(true);
     $treeVersion->setFeatureVariables(true);
     $this->em->persist($treeVersion);
     // ################################################ Variable
     $variable = new Variable();
     $variable->setTreeVersion($treeVersion);
     $variable->setName('score');
     $variable->setType('Integer');
     $this->em->persist($variable);
     // ################################################ Nodes
     $startNode = new Node();
     $startNode->setTreeVersion($treeVersion);
     $startNode->setTitle("START HERE");
     $startNode->setPublicId('start');
     $this->em->persist($startNode);
     $endNode = new Node();
     $endNode->setTreeVersion($treeVersion);
     $endNode->setTitle("END HERE");
     $endNode->setPublicId('end');
     $this->em->persist($endNode);
     // ################################################ Node option for points with variable action
     $nodeOptionPoints = new NodeOption();
     $nodeOptionPoints->setTitle("POINTS");
     $nodeOptionPoints->setTreeVersion($treeVersion);
     $nodeOptionPoints->setNode($startNode);
     $nodeOptionPoints->setDestinationNode($endNode);
     $nodeOptionPoints->setSort(10);
     $nodeOptionPoints->setPublicId('points');
     $this->em->persist($nodeOptionPoints);
     $nodeOptionPointsAction = new NodeOptionVariableAction();
     $nodeOptionPointsAction->setNodeOption($nodeOptionPoints);
     $nodeOptionPointsAction->setVariable($variable);
     $nodeOptionPointsAction->setValue(10);
     $nodeOptionPointsAction->setAction('assign');
     $this->em->persist($nodeOptionPointsAction);
     // ################################################ Node option for no points
     $nodeOptionNoPoints = new NodeOption();
     $nodeOptionNoPoints->setTitle("NO POINTS");
     $nodeOptionNoPoints->setTreeVersion($treeVersion);
     $nodeOptionNoPoints->setNode($startNode);
     $nodeOptionNoPoints->setDestinationNode($endNode);
     $nodeOptionNoPoints->setPublicId('nopoints');
     $nodeOptionNoPoints->setSort(100);
     $this->em->persist($nodeOptionNoPoints);
     // ################################################ Library Content for points
     $libraryContentPoints = new LibraryContent();
     $libraryContentPoints->setTreeVersion($treeVersion);
     $libraryContentPoints->setBodyText('POINTS');
     $this->em->persist($libraryContentPoints);
     $nodeHasLibraryContentPoints = new NodeHasLibraryContent();
     $nodeHasLibraryContentPoints->setSort(0);
     $nodeHasLibraryContentPoints->setNode($endNode);
     $nodeHasLibraryContentPoints->setLibraryContent($libraryContentPoints);
     $this->em->persist($nodeHasLibraryContentPoints);
     $nodeHasLibraryContentPointsIfVariable = new NodeHasLibraryContentIfVariable();
     $nodeHasLibraryContentPointsIfVariable->setPublicId('points');
     $nodeHasLibraryContentPointsIfVariable->setLibraryContent($libraryContentPoints);
     $nodeHasLibraryContentPointsIfVariable->setNode($endNode);
     $nodeHasLibraryContentPointsIfVariable->setVariable($variable);
     $nodeHasLibraryContentPointsIfVariable->setAction('>');
     $nodeHasLibraryContentPointsIfVariable->setValue(0);
     $this->em->persist($nodeHasLibraryContentPointsIfVariable);
     // ################################################ Library Content for NO points
     $libraryContentNoPoints = new LibraryContent();
     $libraryContentNoPoints->setTreeVersion($treeVersion);
     $libraryContentNoPoints->setBodyText('NO POINTS');
     $this->em->persist($libraryContentNoPoints);
     $nodeHasLibraryContentNoPoints = new NodeHasLibraryContent();
     $nodeHasLibraryContentNoPoints->setSort(0);
     $nodeHasLibraryContentNoPoints->setNode($endNode);
     $nodeHasLibraryContentNoPoints->setLibraryContent($libraryContentNoPoints);
     $this->em->persist($nodeHasLibraryContentNoPoints);
     $nodeHasLibraryContentNoPointsIfVariable = new NodeHasLibraryContentIfVariable();
     $nodeHasLibraryContentNoPointsIfVariable->setPublicId('nopoints');
     $nodeHasLibraryContentNoPointsIfVariable->setLibraryContent($libraryContentNoPoints);
     $nodeHasLibraryContentNoPointsIfVariable->setNode($endNode);
     $nodeHasLibraryContentNoPointsIfVariable->setVariable($variable);
     $nodeHasLibraryContentNoPointsIfVariable->setAction('==');
     $nodeHasLibraryContentNoPointsIfVariable->setValue(0);
     $this->em->persist($nodeHasLibraryContentNoPointsIfVariable);
     // ################################################ MISC
     $treeVersionPublished = new TreeVersionPublished();
     $treeVersionPublished->setTreeVersion($treeVersion);
     $treeVersionPublished->setPublishedBy($user);
     $this->em->flush();
     $tvsn = new TreeVersionStartingNode();
     $tvsn->setNode($startNode);
     $tvsn->setTreeVersion($treeVersion);
     $this->em->persist($tvsn);
     $published = new TreeVersionPublished();
     $published->setTreeVersion($treeVersion);
     $this->em->persist($published);
     $this->em->flush();
 }
 function testTwoNodesInLoop()
 {
     $user = new User();
     $user->setEmail("*****@*****.**");
     $user->setUsername("test");
     $user->setPassword("ouhosu");
     $this->em->persist($user);
     $tree = new Tree();
     $tree->setTitleAdmin('Tree');
     $tree->setPublicId('tree');
     $tree->setOwner($user);
     $this->em->persist($tree);
     $treeVersion = new TreeVersion();
     $treeVersion->setTree($tree);
     $treeVersion->setPublicId('version');
     $this->em->persist($treeVersion);
     $nodeA = new Node();
     $nodeA->setTreeVersion($treeVersion);
     $nodeA->setPublicId('start');
     $this->em->persist($nodeA);
     $nodeB = new Node();
     $nodeB->setTreeVersion($treeVersion);
     $nodeB->setPublicId('end');
     $this->em->persist($nodeB);
     $nodeAtoB = new NodeOption();
     $nodeAtoB->setTreeVersion($treeVersion);
     $nodeAtoB->setNode($nodeA);
     $nodeAtoB->setDestinationNode($nodeB);
     $nodeAtoB->setPublicId('option1');
     $this->em->persist($nodeAtoB);
     $nodeBtoA = new NodeOption();
     $nodeBtoA->setTreeVersion($treeVersion);
     $nodeBtoA->setNode($nodeB);
     $nodeBtoA->setDestinationNode($nodeA);
     $nodeBtoA->setPublicId('option2');
     $this->em->persist($nodeBtoA);
     $this->em->flush();
     // TEST
     $process = new GetUnreachableBitsOfTree($this->em, $treeVersion);
     $process->go();
     $unreachableNodes = $process->getUnreachableNodes();
     $this->assertEquals(2, count($unreachableNodes));
     $unreachableNode = $unreachableNodes[0];
     $this->assertEquals($nodeA->getId(), $unreachableNode->getId());
     $unreachableNode = $unreachableNodes[1];
     $this->assertEquals($nodeB->getId(), $unreachableNode->getId());
 }
 public function setFromOldVersion(TreeVersion $fromOldVersion)
 {
     $this->fromOldVersion = $fromOldVersion;
     $this->featureVariables = $fromOldVersion->isFeatureVariables();
     $this->featureLibraryContent = $fromOldVersion->isFeatureLibraryContent();
     $this->graphLayout = $fromOldVersion->getGraphLayout();
 }
 function testGoBackByClickingReset()
 {
     $user = new User();
     $user->setEmail("*****@*****.**");
     $user->setUsername("test");
     $user->setPassword("ouhosu");
     $this->em->persist($user);
     $tree = new Tree();
     $tree->setTitleAdmin('Tree');
     $tree->setPublicId('tree');
     $tree->setOwner($user);
     $this->em->persist($tree);
     $treeVersion = new TreeVersion();
     $treeVersion->setTree($tree);
     $treeVersion->setPublicId('version');
     $this->em->persist($treeVersion);
     $startNode = new Node();
     $startNode->setTreeVersion($treeVersion);
     $startNode->setTitle("START HERE");
     $startNode->setPublicId('start');
     $this->em->persist($startNode);
     $endNode = new Node();
     $endNode->setTreeVersion($treeVersion);
     $endNode->setTitle("END HERE");
     $endNode->setPublicId('end');
     $this->em->persist($endNode);
     $nodeOption = new NodeOption();
     $nodeOption->setTitle("LETS GO HERE");
     $nodeOption->setTreeVersion($treeVersion);
     $nodeOption->setNode($startNode);
     $nodeOption->setDestinationNode($endNode);
     $nodeOption->setPublicId('option');
     $this->em->persist($nodeOption);
     $treeVersionPublished = new TreeVersionPublished();
     $treeVersionPublished->setTreeVersion($treeVersion);
     $treeVersionPublished->setPublishedBy($user);
     $this->em->flush();
     $tvsn = new TreeVersionStartingNode();
     $tvsn->setNode($startNode);
     $tvsn->setTreeVersion($treeVersion);
     $this->em->persist($tvsn);
     $published = new TreeVersionPublished();
     $published->setTreeVersion($treeVersion);
     $this->em->persist($published);
     $this->em->flush();
     // ######################################################## LOAD PAGE
     $this->driver->get('http://localhost/app_dev.php/tree/tree/demo');
     $startLink = $this->driver->findElement(WebDriverBy::id('StartTreeLink'));
     $this->assertEquals('Start Tree!', $startLink->getText());
     // ######################################################## Start Tree
     $startLink->click();
     sleep($this->sleepOnActionWithNetwork);
     $nodeTitle = $this->driver->findElement(WebDriverBy::id('DemoHere'))->findElement(WebDriverBy::className('node'))->findElement(WebDriverBy::className('title'));
     $this->assertEquals('START HERE', $nodeTitle->getText());
     // ######################################################## LOAD PAGE
     $this->driver->findElement(WebDriverBy::id('DemoHere'))->findElements(WebDriverBy::className('option'))[0]->click();
     $this->driver->findElement(WebDriverBy::id('DemoHere'))->findElement(WebDriverBy::cssSelector('input[type="submit"]'))->click();
     sleep($this->sleepOnActionNoNetwork);
     $nodeTitle = $this->driver->findElement(WebDriverBy::id('DemoHere'))->findElement(WebDriverBy::className('node'))->findElement(WebDriverBy::className('title'));
     $this->assertEquals('END HERE', $nodeTitle->getText());
     // ######################################################## GO BACK
     $this->driver->findElement(WebDriverBy::className('restart'))->findElement(WebDriverBy::tagName('a'))->click();
     sleep($this->sleepOnActionNoNetwork);
     $nodeTitle = $this->driver->findElement(WebDriverBy::id('DemoHere'))->findElement(WebDriverBy::className('node'))->findElement(WebDriverBy::className('title'));
     $this->assertEquals('START HERE', $nodeTitle->getText());
 }
 function testGetNextSortValueForNode1()
 {
     $user = new User();
     $user->setEmail("*****@*****.**");
     $user->setUsername("test");
     $user->setPassword("ouhosu");
     $this->em->persist($user);
     $tree = new Tree();
     $tree->setTitleAdmin('Tree');
     $tree->setOwner($user);
     $tree->setPublicId('tree');
     $this->em->persist($tree);
     $treeVersion = new TreeVersion();
     $treeVersion->setTree($tree);
     $treeVersion->setPublicId('version');
     $this->em->persist($treeVersion);
     $node = new Node();
     $node->setTreeVersion($treeVersion);
     $node->setPublicId('start');
     $this->em->persist($node);
     $this->em->flush();
     // #################################################### TEST NO NODES
     $nodeOptionRepo = $this->em->getRepository('QuestionKeyBundle:NodeOption');
     $nextSort = $nodeOptionRepo->getNextSortValueForNode($node);
     $this->assertEquals(10, $nextSort);
     // #################################################### Add A NodeOptionRepository
     $nodeOption = new NodeOption();
     $nodeOption->setTreeVersion($treeVersion);
     $nodeOption->setNode($node);
     $nodeOption->setDestinationNode($node);
     $nodeOption->setPublicId('no1');
     $nodeOption->setSort($nextSort);
     $this->em->persist($nodeOption);
     $this->em->flush();
     // #################################################### TEST NO NODES
     $nodeOptionRepo = $this->em->getRepository('QuestionKeyBundle:NodeOption');
     $nextSort = $nodeOptionRepo->getNextSortValueForNode($node);
     $this->assertEquals(20, $nextSort);
     // #################################################### Add A NodeOptionRepository
     $nodeOption = new NodeOption();
     $nodeOption->setTreeVersion($treeVersion);
     $nodeOption->setNode($node);
     $nodeOption->setDestinationNode($node);
     $nodeOption->setPublicId('no2');
     $nodeOption->setSort($nextSort);
     $this->em->persist($nodeOption);
     $this->em->flush();
     // #################################################### TEST NO NODES
     $nodeOptionRepo = $this->em->getRepository('QuestionKeyBundle:NodeOption');
     $nextSort = $nodeOptionRepo->getNextSortValueForNode($node);
     $this->assertEquals(30, $nextSort);
     // #################################################### Add A NodeOptionRepository
     $nodeOption = new NodeOption();
     $nodeOption->setTreeVersion($treeVersion);
     $nodeOption->setNode($node);
     $nodeOption->setDestinationNode($node);
     $nodeOption->setPublicId('no3');
     $nodeOption->setSort($nextSort);
     $this->em->persist($nodeOption);
     $this->em->flush();
     // #################################################### TEST NO NODES
     $nodeOptionRepo = $this->em->getRepository('QuestionKeyBundle:NodeOption');
     $nextSort = $nodeOptionRepo->getNextSortValueForNode($node);
     $this->assertEquals(40, $nextSort);
     // #################################################### Add A NodeOptionRepository
     $nodeOption = new NodeOption();
     $nodeOption->setTreeVersion($treeVersion);
     $nodeOption->setNode($node);
     $nodeOption->setDestinationNode($node);
     $nodeOption->setPublicId('no4');
     $nodeOption->setSort($nextSort);
     $this->em->persist($nodeOption);
     $this->em->flush();
 }
 function testNextNodeInExistingRun()
 {
     $user = new User();
     $user->setEmail("*****@*****.**");
     $user->setUsername("test");
     $user->setPassword("ouhosu");
     $this->em->persist($user);
     $tree = new Tree();
     $tree->setTitleAdmin('Tree');
     $tree->setOwner($user);
     $tree->setPublicId('tree');
     $this->em->persist($tree);
     $treeVersion = new TreeVersion();
     $treeVersion->setTree($tree);
     $treeVersion->setPublicId('version');
     $this->em->persist($treeVersion);
     $startNode = new Node();
     $startNode->setTreeVersion($treeVersion);
     $startNode->setPublicId('start');
     $this->em->persist($startNode);
     $endNode = new Node();
     $endNode->setTreeVersion($treeVersion);
     $endNode->setPublicId('end');
     $this->em->persist($endNode);
     $nodeOption1 = new NodeOption();
     $nodeOption1->setTreeVersion($treeVersion);
     $nodeOption1->setNode($startNode);
     $nodeOption1->setDestinationNode($endNode);
     $nodeOption1->setPublicId('no1');
     $this->em->persist($nodeOption1);
     $this->em->flush();
     $tvsn = new TreeVersionStartingNode();
     $tvsn->setNode($startNode);
     $tvsn->setTreeVersion($treeVersion);
     $this->em->persist($tvsn);
     $tp = new TreeVersionPublished();
     $tp->setTreeVersion($treeVersion);
     $tp->setPublishedBy($user);
     $tp->setPublishedAt(new \DateTime());
     $this->em->persist($tp);
     $session = new VisitorSession();
     $session->setPublicId('vspid');
     $this->em->persist($session);
     $visitorSessionRanTreeVersion = new VisitorSessionRanTreeVersion();
     $visitorSessionRanTreeVersion->setVisitorSession($session);
     $visitorSessionRanTreeVersion->setPublicId('vsrtvpid');
     $visitorSessionRanTreeVersion->setTreeVersion($treeVersion);
     $this->em->persist($visitorSessionRanTreeVersion);
     $visitorSessionOnNode = new VisitorSessionOnNode();
     $visitorSessionOnNode->setNode($startNode);
     $visitorSessionOnNode->setSessionRanTreeVersion($visitorSessionRanTreeVersion);
     $this->em->persist($visitorSessionOnNode);
     $this->em->flush();
     // Make Request
     $client = static::createClient();
     $crawler = $client->request('GET', '/api/v1/visitorsession/action.json?session_id=vspid&ran_tree_version_id=vsrtvpid&tree_id=tree&tree_version_id=version&node_id=end&node_option_id=no1');
     $response = $client->getResponse()->getContent();
     $responseData = json_decode($response);
     // Check Session
     $sessionLoaded = $this->em->getRepository('QuestionKeyBundle:VisitorSession')->findOneByPublicId($responseData->session->id);
     $this->assertNotNull($sessionLoaded);
     $this->assertEquals($responseData->session->id, $sessionLoaded->getPublicId());
     // test session we loaded is same as session we passed it get param
     $this->assertEquals($session->getId(), $sessionLoaded->getId());
     // Check Session Ran Tree
     $sessionRanTreeLoaded = $this->em->getRepository('QuestionKeyBundle:VisitorSessionRanTreeVersion')->findOneByPublicId($responseData->session_ran_tree_version->id);
     $this->assertNotNull($sessionRanTreeLoaded);
     $this->assertEquals($responseData->session_ran_tree_version->id, $sessionRanTreeLoaded->getPublicId());
     $this->assertEquals($sessionLoaded->getId(), $sessionRanTreeLoaded->getVisitorSession()->getId());
     $this->assertEquals($treeVersion->getId(), $sessionRanTreeLoaded->getTreeVersion()->getId());
     // test s-r-t we loaded is same as s-r-t we passed it get param
     $this->assertEquals($visitorSessionRanTreeVersion->getId(), $sessionRanTreeLoaded->getId());
     // Check Node Stored.
     $sessionOnNodesLoaded = $this->em->getRepository('QuestionKeyBundle:VisitorSessionOnNode')->findBy(array('sessionRanTreeVersion' => $sessionRanTreeLoaded));
     $this->assertEquals(2, count($sessionOnNodesLoaded));
     $sessionOnNodeLoaded = array_shift($sessionOnNodesLoaded);
     $this->assertEquals($startNode->getId(), $sessionOnNodeLoaded->getNode()->getId());
     $this->assertFalse($sessionOnNodeLoaded->getGoneBackTo());
     $this->assertNull($sessionOnNodeLoaded->getNodeOption());
     $sessionOnNodeLoaded = array_shift($sessionOnNodesLoaded);
     $this->assertEquals($endNode->getId(), $sessionOnNodeLoaded->getNode()->getId());
     $this->assertFalse($sessionOnNodeLoaded->getGoneBackTo());
     $this->assertNotNull($sessionOnNodeLoaded->getNodeOption());
     $this->assertEquals($nodeOption1->getId(), $sessionOnNodeLoaded->getNodeOption()->getId());
 }