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'));
 }
 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());
 }
 public function setAsStartingNode(Node $startingNode)
 {
     $treeStartingNode = $this->findOneByTreeVersion($startingNode->getTreeVersion());
     if (!$treeStartingNode) {
         $treeStartingNode = new TreeVersionStartingNode();
         $treeStartingNode->setTreeVersion($startingNode->getTreeVersion());
     }
     $treeStartingNode->setNode($startingNode);
     $this->getEntityManager()->persist($treeStartingNode);
     $this->getEntityManager()->flush($treeStartingNode);
 }
 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));
 }
 public function process()
 {
     $nodes = array();
     foreach ($this->data->nodes as $publicId => $nodeData) {
         $nodes[$publicId] = new Node();
         $nodes[$publicId]->setPublicId($publicId);
         $nodes[$publicId]->setTreeVersion($this->treeVersion);
         $nodes[$publicId]->setTitle($nodeData->title);
         $nodes[$publicId]->setTitleAdmin($nodeData->title_admin);
         $nodes[$publicId]->setTitlePreviousAnswers($nodeData->title_previous_answers);
         $nodes[$publicId]->setBodyHTML($nodeData->body_html);
         $nodes[$publicId]->setBodyText($nodeData->body_text);
         $this->doctrine->persist($nodes[$publicId]);
     }
     foreach ($this->data->nodeOptions as $publicId => $nodeOptionData) {
         $nodeOption = new NodeOption();
         $nodeOption->setPublicId($publicId);
         $nodeOption->setTreeVersion($this->treeVersion);
         $nodeOption->setTitle($nodeOptionData->title);
         $nodeOption->setBodyHTML($nodeOptionData->body_html);
         $nodeOption->setBodyText($nodeOptionData->body_text);
         $nodeOption->setSort($nodeOptionData->sort);
         $nodeOption->setNode($nodes[$nodeOptionData->node->id]);
         $nodeOption->setDestinationNode($nodes[$nodeOptionData->destination_node->id]);
         $this->doctrine->persist($nodeOption);
     }
     // If this is removed the tests will pass ... but the web app will crash.
     $this->doctrine->flush();
     if ($this->data->start_node && $this->data->start_node->id) {
         $startingNode = new TreeVersionStartingNode();
         $startingNode->setTreeVersion($this->treeVersion);
         $startingNode->setNode($nodes[$this->data->start_node->id]);
         $this->doctrine->persist($startingNode);
     }
     // Seeing as we have to flush in this function, also flush at end to make sure all written.
     $this->doctrine->flush();
 }
 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();
 }
 public function go()
 {
     // Tree Option
     $this->newVersion->setFromOldVersion($this->oldVersion);
     // As we call flush in this function, make sure new version will definetly be part of that.
     $this->doctrine->persist($this->newVersion);
     // repos
     $nodeRepo = $this->doctrine->getRepository('QuestionKeyBundle:Node');
     $nodeOptionRepo = $this->doctrine->getRepository('QuestionKeyBundle:NodeOption');
     $libraryContentRepo = $this->doctrine->getRepository('QuestionKeyBundle:LibraryContent');
     $nodeHasLibraryContentRepo = $this->doctrine->getRepository('QuestionKeyBundle:NodeHasLibraryContent');
     $treeStartingNodeRepo = $this->doctrine->getRepository('QuestionKeyBundle:TreeVersionStartingNode');
     // Library Content
     $libraryContents = array();
     foreach ($libraryContentRepo->findByTreeVersion($this->oldVersion) as $libraryContent) {
         $libraryContents[$libraryContent->getPublicId()] = new LibraryContent();
         $libraryContents[$libraryContent->getPublicId()]->setTitleAdmin($libraryContent->getTitleAdmin());
         $libraryContents[$libraryContent->getPublicId()]->setBodyHTML($libraryContent->getBodyHTML());
         $libraryContents[$libraryContent->getPublicId()]->setBodyText($libraryContent->getBodyText());
         $libraryContents[$libraryContent->getPublicId()]->setTreeVersion($this->newVersion);
         $libraryContents[$libraryContent->getPublicId()]->setPublicId($libraryContent->getPublicId());
         $this->doctrine->persist($libraryContents[$libraryContent->getPublicId()]);
     }
     // Nodes
     $nodes = $nodeRepo->findByTreeVersion($this->oldVersion);
     $newNodes = array();
     foreach ($nodes as $node) {
         $newNodes[$node->getId()] = new Node();
         $newNodes[$node->getId()]->setTreeVersion($this->newVersion);
         $newNodes[$node->getId()]->setTitle($node->getTitle());
         $newNodes[$node->getId()]->setBodyText($node->getBodyText());
         $newNodes[$node->getId()]->setBodyHTML($node->getBodyHTML());
         $newNodes[$node->getId()]->setPublicId($node->getPublicId());
         $newNodes[$node->getId()]->setFromOldVersion($node);
         $this->doctrine->persist($newNodes[$node->getId()]);
         $sort = 0;
         foreach ($libraryContentRepo->findForNode($node) as $oldLibraryContent) {
             // We create a NodeHasLibraryContent record directly instead of using
             //     $nodeHasLibraryContentRepo->addLibraryContentToNode($libraryContents[$oldLibraryContent->getPublicId()],  $newNodes[$node->getId()]);
             // because it's much more efficient in DB queries. Also, given some records might not have saved I'm not sure addLibraryContentToNode() would find the correct sort values anyway.
             $nodeHasLibraryContent = new NodeHasLibraryContent();
             $nodeHasLibraryContent->setLibraryContent($libraryContents[$oldLibraryContent->getPublicId()]);
             $nodeHasLibraryContent->setNode($newNodes[$node->getId()]);
             $nodeHasLibraryContent->setSort($sort++);
             $this->doctrine->persist($nodeHasLibraryContent);
         }
     }
     // Node Options
     $nodeOptions = $nodeOptionRepo->findAllNodeOptionsForTreeVersion($this->oldVersion);
     foreach ($nodeOptions as $nodeOption) {
         $newNodeOption = new NodeOption();
         $newNodeOption->setTreeVersion($this->newVersion);
         $newNodeOption->setNode($newNodes[$nodeOption->getNode()->getId()]);
         $newNodeOption->setDestinationNode($newNodes[$nodeOption->getDestinationNode()->getId()]);
         $newNodeOption->setTitle($nodeOption->getTitle());
         $newNodeOption->setBodyHTML($nodeOption->getBodyHTML());
         $newNodeOption->setBodyText($nodeOption->getBodyText());
         $newNodeOption->setSort($nodeOption->getSort());
         $newNodeOption->setPublicId($nodeOption->getPublicId());
         $newNodeOption->setFromOldVersion($nodeOption);
         $this->doctrine->persist($newNodeOption);
     }
     // Tree Start
     $treeStartingNode = $treeStartingNodeRepo->findOneByTreeVersion($this->oldVersion);
     if ($treeStartingNode) {
         // we have to flush at this point otherwise when we try and persist at the next stage you get an error.
         $this->doctrine->flush();
         $newTreeVersionStartingNode = new TreeVersionStartingNode();
         $newTreeVersionStartingNode->setTreeVersion($this->newVersion);
         $newTreeVersionStartingNode->setNode($newNodes[$treeStartingNode->getNode()->getId()]);
         $this->doctrine->persist($newTreeVersionStartingNode);
     }
     // final flush
     $this->doctrine->flush();
 }
 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);
     $otherEndNode = new Node();
     $otherEndNode->setTreeVersion($treeVersion);
     $otherEndNode->setPublicId('otherend');
     $this->em->persist($otherEndNode);
     $nodeOption = new NodeOption();
     $nodeOption->setTreeVersion($treeVersion);
     $nodeOption->setNode($startNode);
     $nodeOption->setDestinationNode($endNode);
     $nodeOption->setPublicId('option');
     $this->em->persist($nodeOption);
     $otherNodeOption = new NodeOption();
     $otherNodeOption->setTreeVersion($treeVersion);
     $otherNodeOption->setNode($startNode);
     $otherNodeOption->setDestinationNode($otherEndNode);
     $otherNodeOption->setPublicId('optionOther');
     $this->em->persist($otherNodeOption);
     $this->em->flush();
     $tvsn = new TreeVersionStartingNode();
     $tvsn->setNode($startNode);
     $tvsn->setTreeVersion($treeVersion);
     $this->em->persist($tvsn);
     $this->em->flush();
     $process = new GetStackTracesForNode($this->em, $endNode);
     $process->go();
     $stackTraces = $process->getStackTraces();
     $this->assertEquals(1, count($stackTraces));
     $stackTrace = $stackTraces[0];
     $data = $stackTrace->getData();
     $this->assertEquals(2, count($data));
     $this->assertEquals('d6151cdb913fbf06a614965109b97355', $stackTrace->getPublicId());
     // DATA
     $dataRow = array_shift($data);
     $this->assertNotNull($dataRow['node']);
     $this->assertEquals($startNode->getId(), $dataRow['node']->getId());
     $this->assertNotNull($dataRow['nodeOption']);
     $this->assertEquals($nodeOption->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 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());
 }
 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->setPublicId('start');
     $startNode->setTitle('Start Here');
     $this->em->persist($startNode);
     $endNode = new Node();
     $endNode->setTreeVersion($treeVersion);
     $endNode->setPublicId('end');
     $endNode->setTitle('End Here');
     $this->em->persist($endNode);
     $nodeOption = new NodeOption();
     $nodeOption->setTreeVersion($treeVersion);
     $nodeOption->setTitle('Click Here');
     $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();
     ///////////////////////////////////////////////////////////////////// NOW EXPORT
     $exportJSON = new ExportTreeVersionJSON($this->em, $treeVersion);
     $json = $exportJSON->getAsText();
     ///////////////////////////////////////////////////////////////////// NOW IMPORT
     $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, $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());
 }
 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());
 }