/**
  * Tests how the first textnode of a topic gets found based on the topic ID.
  */
 public function testReadTopic()
 {
     $textnode = new Textnode();
     $textnode->setId("55f5ab3708985c4b188b4577");
     $textnode->setTopicId("foobar");
     $textnode->setAccess(true);
     $textnode->setStatus(Textnode::STATUS_ACTIVE);
     $textnode->setText("Lorem ipsum dolor sit amet.");
     $container = $this->getMock("Symfony\\Component\\DependencyInjection\\ContainerInterface");
     $mongo = $this->getMockBuilder("Doctrine\\Bundle\\MongoDBBundle\\ManagerRegistry")->disableOriginalConstructor()->getMock();
     $repository = $this->getMockBuilder("Doctrine\\ODM\\MongoDB\\DocumentRepository")->disableOriginalConstructor()->getMock();
     $router = $this->getMock("Symfony\\Component\\Routing\\RouterInterface");
     $queryBuilder = $this->getMockBuilder("Doctrine\\ODM\\MongoDB\\QueryBuilder")->setMethods(array('field', 'equals', 'getQuery', 'getSingleResult'))->getMock();
     $container->expects($this->at(0))->method("get")->with($this->equalTo('doctrine_mongodb'))->will($this->returnValue($mongo));
     $mongo->expects($this->once())->method("getRepository")->with($this->equalTo('DembeloMain:Textnode'))->will($this->returnValue($repository));
     $queryBuilder->expects($this->at(0))->method('field')->with('topicId')->will($this->returnSelf());
     $queryBuilder->expects($this->at(1))->method('equals')->will($this->returnSelf());
     $queryBuilder->expects($this->at(2))->method('field')->with('status')->will($this->returnSelf());
     $queryBuilder->expects($this->at(3))->method('equals')->will($this->returnSelf());
     $queryBuilder->expects($this->at(4))->method('field')->with('access')->will($this->returnSelf());
     $queryBuilder->expects($this->at(5))->method('equals')->will($this->returnSelf());
     $queryBuilder->expects($this->once())->method('getQuery')->will($this->returnSelf());
     $queryBuilder->expects($this->once())->method('getSingleResult')->will($this->returnValue($textnode));
     $repository->expects($this->once())->method("createQueryBuilder")->will($this->returnValue($queryBuilder));
     $container->expects($this->at(1))->method("get")->with($this->equalTo('router'))->will($this->returnValue($router));
     $router->expects($this->once())->method("generate")->with("text", array('textnodeId' => $textnode->getId()))->will($this->returnValue("text/" . $textnode->getId()));
     $controller = new DefaultController();
     $controller->setContainer($container);
     $result = $controller->readTopicAction("55d2b934658f5cc23c3c986c");
     $this->assertEquals('Symfony\\Component\\HttpFoundation\\RedirectResponse', get_class($result));
     $this->assertEquals('302', $result->getStatusCode());
     $this->assertEquals('text/' . $textnode->getId(), $result->getTargetUrl());
 }
 private function createTextnodes(ManagerRegistry $mongo, DocumentManager $dm)
 {
     $loremIpsumLength = 3500;
     $repository = $mongo->getRepository('DembeloMain:Textnode');
     $allAccessNodes = $repository->findByAccess(true);
     if (count($allAccessNodes) >= 7) {
         return;
     }
     $loremIpsum = $this->getContainer()->get('apoutchika.lorem_ipsum');
     $textnodeData = array(array('topic' => $this->dummyData['topics'][0], 'text' => $loremIpsum->getWords($loremIpsumLength), 'access' => true, 'licensee' => $this->dummyData['licensees'][0], 'metadata' => array('Titel' => 'Titel 1', 'Autor' => 'Autor 1', 'Verlag' => 'Verlag 1')), array('text' => $loremIpsum->getWords($loremIpsumLength), 'access' => false, 'licensee' => $this->dummyData['licensees'][0], 'metadata' => array('Titel' => 'Titel 2', 'Autor' => 'Autor 2', 'Verlag' => 'Verlag 2')), array('text' => $loremIpsum->getWords($loremIpsumLength), 'access' => false, 'licensee' => $this->dummyData['licensees'][0], 'metadata' => array('Titel' => 'Titel 3', 'Autor' => 'Autor 3', 'Verlag' => 'Verlag 3')), array('topic' => $this->dummyData['topics'][1], 'text' => $loremIpsum->getWords($loremIpsumLength), 'access' => true, 'licensee' => $this->dummyData['licensees'][0], 'metadata' => array('Titel' => 'Titel 4', 'Autor' => 'Autor 4', 'Verlag' => 'Verlag 4')), array('text' => $loremIpsum->getWords($loremIpsumLength), 'access' => false, 'licensee' => $this->dummyData['licensees'][0], 'metadata' => array('Titel' => 'Titel 5', 'Autor' => 'Autor 5', 'Verlag' => 'Verlag 5')), array('text' => $loremIpsum->getWords($loremIpsumLength), 'access' => false, 'licensee' => $this->dummyData['licensees'][0], 'metadata' => array('Titel' => 'Titel 6', 'Autor' => 'Autor 6', 'Verlag' => 'Verlag 6')));
     foreach ($textnodeData as $textnodeDatum) {
         $textnode = new Textnode();
         $textnode->setStatus(Textnode::STATUS_ACTIVE);
         if (isset($textnodeDatum['topic'])) {
             $textnode->setTopicId($textnodeDatum['topic']->getId());
         }
         if (isset($textnodeDatum['licensee'])) {
             $textnode->setLicenseeId($textnodeDatum['licensee']->getId());
         }
         $textnode->setCreated(date('Y-m-d H:i:s'));
         $textnode->setText($textnodeDatum['text']);
         $textnode->setAccess($textnodeDatum['access']);
         $textnode->setMetadata($textnodeDatum['metadata']);
         $dm->persist($textnode);
         $this->dummyData['textnodes'][] = $textnode;
     }
 }
 /**
  * tests the topicId
  */
 public function testTopicId()
 {
     $topicId = 'asd23123';
     $this->textnode->setTopicId($topicId);
     $this->assertEquals($topicId, $this->textnode->getTopicId());
 }