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(); }
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 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(); }
public function newLibraryContentAction($treeId, $versionId) { // build $this->build($treeId, $versionId); if (!$this->treeVersionEditable) { throw new AccessDeniedException(); } //data $form = $this->createForm(new AdminLibraryContentNewType()); $request = $this->getRequest(); if ($request->getMethod() == 'POST') { $form->handleRequest($request); if ($form->isValid()) { $doctrine = $this->getDoctrine()->getManager(); $libraryContent = new LibraryContent(); $libraryContent->setTreeVersion($this->treeVersion); $libraryContent->setTitleAdmin($form->get('titleAdmin')->getData()); $libraryContent->setBodyText($form->get('body_text')->getData()); $libraryContent->setBodyHTML($form->get('body_html')->getData()); $doctrine->persist($libraryContent); $doctrine->flush(); return $this->redirect($this->generateUrl('questionkey_admin_tree_version_library_content_show', array('treeId' => $this->tree->getPublicId(), 'versionId' => $this->treeVersion->getPublicId(), 'contentId' => $libraryContent->getPublicId()))); } } return $this->render('QuestionKeyBundle:AdminTreeVersionEdit:newLibraryContent.html.twig', array('tree' => $this->tree, 'treeVersion' => $this->treeVersion, 'form' => $form->createView())); }
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()); }