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 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 publishAction($treeId, $versionId) { // build $return = $this->build($treeId, $versionId); //data $form = $this->createForm(new AdminTreeVersionPublishType()); $request = $this->getRequest(); if ($request->getMethod() == 'POST') { $form->handleRequest($request); if ($form->isValid()) { $doctrine = $this->getDoctrine()->getManager(); $treeVersionPublished = new TreeVersionPublished(); $treeVersionPublished->setTreeVersion($this->treeVersion); $treeVersionPublished->setCommentPublishedAdmin($form->get('comment_admin')->getData()); $treeVersionPublished->setPublishedBy($this->getUser()); $doctrine->persist($treeVersionPublished); $doctrine->flush(); return $this->redirect($this->generateUrl('questionkey_admin_tree_version_show', array('treeId' => $this->tree->getPublicId(), 'versionId' => $this->treeVersion->getPublicId()))); } } return $this->render('QuestionKeyBundle:AdminTreeVersionEdit:publish.html.twig', array('tree' => $this->tree, 'treeVersion' => $this->treeVersion, 'form' => $form->createView())); }
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 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()); }