diff -r 10be6b9e55e7 -r 774ba82dca59 Tests/Services/DocumentServiceTest.php --- a/Tests/Services/DocumentServiceTest.php Fri Dec 09 06:43:49 2011 +0100 +++ b/Tests/Services/DocumentServiceTest.php Wed Dec 14 23:28:57 2011 +0100 @@ -16,12 +16,15 @@ { protected $_container; + protected $_doctrine; + protected $_application; + protected $_kernel; public function __construct() { - $kernel = new \AppKernel("test", true); - $kernel->boot(); - $this->_container = $kernel->getContainer(); + $this->_kernel = new \AppKernel("test", true); + $this->_kernel->boot(); + $this->_container = $this->_kernel->getContainer(); parent::__construct(); } @@ -30,18 +33,67 @@ return $this->_container->get($service); } + protected function getDoctrine() + { + if(is_null($this->_doctrine)) + { + $this->_doctrine = $this->get('doctrine'); + } + return $this->_doctrine; + } + + + public function testGetTagLabels() + { + $doc_service = $this->get("wiki_tag.document"); + $doc1 = $this->getDoctrine()->getRepository("CompanyBaseBundle:Document")->findOneByTitle("Title 1"); + $tags = $doc_service->getTagLabels($doc1->getId()); + + $this->assertEquals(4,count($tags)); + + $this->assertEquals(array("Tag1","Tag2","Tag3","Tag4"),$tags); + + } + public function testCopyTags() { - $search_service = $this->get("wiki_tag.document"); + $doc_service = $this->get("wiki_tag.document"); + + $doc1 = $this->getDoctrine()->getRepository("CompanyBaseBundle:Document")->findOneByTitle("Title 1"); + + $this->assertEquals(4,count($doc_service->getTagLabels($doc1->getId()))); + + $doc2 = $this->getDoctrine()->getRepository("CompanyBaseBundle:Document")->findOneByTitle("Title 4"); - // TODO : get doc 1 - // TODO : get doc 2 - // call copyTags - + $this->assertEquals(0,count($doc_service->getTagLabels($doc2->getId()))); + + $doc_service->copyTags($doc1->getId(), $doc2->getId()); + + $this->assertEquals(4,count($doc_service->getTagLabels($doc2->getId()))); + $this->assertEquals(array("Tag1","Tag2","Tag3","Tag4"),$doc_service->getTagLabels($doc2->getId())); + } + public function setUp() + { + $this->_application = new \Symfony\Bundle\FrameworkBundle\Console\Application($this->_kernel); + $this->_application->setAutoExit(false); + $this->runConsole("doctrine:schema:drop", array("--force" => true)); + $this->runConsole("wikitag:schema:create"); + $this->runConsole("cache:warmup"); + $this->runConsole("doctrine:fixtures:load", array("--fixtures" => __DIR__ . "/../../../../../../../src/Company/BaseBundle/DataFixtures")); + } + + protected function runConsole($command, Array $options = array()) + { + + $options["-e"] = "test"; + $options["-q"] = null; + $options = array_merge($options, array('command' => $command)); + return $this->_application->run(new \Symfony\Component\Console\Input\ArrayInput($options)); + } }