14 |
14 |
15 class DocumentServiceTest extends \PHPUnit_Framework_TestCase |
15 class DocumentServiceTest extends \PHPUnit_Framework_TestCase |
16 { |
16 { |
17 |
17 |
18 protected $_container; |
18 protected $_container; |
|
19 protected $_doctrine; |
|
20 protected $_application; |
|
21 protected $_kernel; |
19 |
22 |
20 public function __construct() |
23 public function __construct() |
21 { |
24 { |
22 $kernel = new \AppKernel("test", true); |
25 $this->_kernel = new \AppKernel("test", true); |
23 $kernel->boot(); |
26 $this->_kernel->boot(); |
24 $this->_container = $kernel->getContainer(); |
27 $this->_container = $this->_kernel->getContainer(); |
25 parent::__construct(); |
28 parent::__construct(); |
26 } |
29 } |
27 |
30 |
28 protected function get($service) |
31 protected function get($service) |
29 { |
32 { |
30 return $this->_container->get($service); |
33 return $this->_container->get($service); |
31 } |
34 } |
32 |
35 |
|
36 protected function getDoctrine() |
|
37 { |
|
38 if(is_null($this->_doctrine)) |
|
39 { |
|
40 $this->_doctrine = $this->get('doctrine'); |
|
41 } |
|
42 return $this->_doctrine; |
|
43 } |
|
44 |
|
45 |
|
46 public function testGetTagLabels() |
|
47 { |
|
48 $doc_service = $this->get("wiki_tag.document"); |
|
49 $doc1 = $this->getDoctrine()->getRepository("CompanyBaseBundle:Document")->findOneByTitle("Title 1"); |
33 |
50 |
|
51 $tags = $doc_service->getTagLabels($doc1->getId()); |
|
52 |
|
53 $this->assertEquals(4,count($tags)); |
|
54 |
|
55 $this->assertEquals(array("Tag1","Tag2","Tag3","Tag4"),$tags); |
|
56 |
|
57 } |
|
58 |
34 public function testCopyTags() |
59 public function testCopyTags() |
35 { |
60 { |
36 |
61 |
37 $search_service = $this->get("wiki_tag.document"); |
62 $doc_service = $this->get("wiki_tag.document"); |
38 |
63 |
39 // TODO : get doc 1 |
64 $doc1 = $this->getDoctrine()->getRepository("CompanyBaseBundle:Document")->findOneByTitle("Title 1"); |
40 // TODO : get doc 2 |
65 |
41 // call copyTags |
66 $this->assertEquals(4,count($doc_service->getTagLabels($doc1->getId()))); |
42 |
67 |
|
68 $doc2 = $this->getDoctrine()->getRepository("CompanyBaseBundle:Document")->findOneByTitle("Title 4"); |
|
69 |
|
70 $this->assertEquals(0,count($doc_service->getTagLabels($doc2->getId()))); |
|
71 |
|
72 $doc_service->copyTags($doc1->getId(), $doc2->getId()); |
|
73 |
|
74 $this->assertEquals(4,count($doc_service->getTagLabels($doc2->getId()))); |
|
75 $this->assertEquals(array("Tag1","Tag2","Tag3","Tag4"),$doc_service->getTagLabels($doc2->getId())); |
|
76 |
43 } |
77 } |
44 |
78 |
|
79 public function setUp() |
|
80 { |
|
81 $this->_application = new \Symfony\Bundle\FrameworkBundle\Console\Application($this->_kernel); |
|
82 $this->_application->setAutoExit(false); |
|
83 $this->runConsole("doctrine:schema:drop", array("--force" => true)); |
|
84 $this->runConsole("wikitag:schema:create"); |
|
85 $this->runConsole("cache:warmup"); |
|
86 $this->runConsole("doctrine:fixtures:load", array("--fixtures" => __DIR__ . "/../../../../../../../src/Company/BaseBundle/DataFixtures")); |
|
87 } |
|
88 |
|
89 protected function runConsole($command, Array $options = array()) |
|
90 { |
|
91 |
|
92 $options["-e"] = "test"; |
|
93 $options["-q"] = null; |
|
94 $options = array_merge($options, array('command' => $command)); |
|
95 return $this->_application->run(new \Symfony\Component\Console\Input\ArrayInput($options)); |
|
96 } |
45 |
97 |
46 } |
98 } |
47 |
99 |