| author | ymh <ymh.work@gmail.com> |
| Wed, 14 Dec 2011 23:28:57 +0100 | |
| changeset 63 | 774ba82dca59 |
| parent 57 | 186c4121c7b3 |
| child 65 | ba6b8e38d90e |
| permissions | -rw-r--r-- |
|
57
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
1 |
<?php |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
2 |
/* |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
3 |
* This file is part of the WikiTagBundle package. |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
4 |
* |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
5 |
* (c) IRI <http://www.iri.centrepompidou.fr/> |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
6 |
* |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
7 |
* For the full copyright and license information, please view the LICENSE |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
8 |
* file that was distributed with this source code. |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
9 |
*/ |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
10 |
|
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
11 |
namespace IRI\Bundle\WikiTagBundle\Tests\Services; |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
12 |
|
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
13 |
require_once(__DIR__ . "/../../../../../../../app/AppKernel.php"); |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
14 |
|
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
15 |
class DocumentServiceTest extends \PHPUnit_Framework_TestCase |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
16 |
{ |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
17 |
|
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
18 |
protected $_container; |
| 63 | 19 |
protected $_doctrine; |
20 |
protected $_application; |
|
21 |
protected $_kernel; |
|
|
57
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
22 |
|
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
23 |
public function __construct() |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
24 |
{ |
| 63 | 25 |
$this->_kernel = new \AppKernel("test", true); |
26 |
$this->_kernel->boot(); |
|
27 |
$this->_container = $this->_kernel->getContainer(); |
|
|
57
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
28 |
parent::__construct(); |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
29 |
} |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
30 |
|
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
31 |
protected function get($service) |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
32 |
{ |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
33 |
return $this->_container->get($service); |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
34 |
} |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
35 |
|
| 63 | 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"); |
|
|
57
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
50 |
|
| 63 | 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 |
||
|
57
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
59 |
public function testCopyTags() |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
60 |
{ |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
61 |
|
| 63 | 62 |
$doc_service = $this->get("wiki_tag.document"); |
63 |
||
64 |
$doc1 = $this->getDoctrine()->getRepository("CompanyBaseBundle:Document")->findOneByTitle("Title 1"); |
|
65 |
||
66 |
$this->assertEquals(4,count($doc_service->getTagLabels($doc1->getId()))); |
|
67 |
||
68 |
$doc2 = $this->getDoctrine()->getRepository("CompanyBaseBundle:Document")->findOneByTitle("Title 4"); |
|
|
57
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
69 |
|
| 63 | 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 |
||
|
57
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
77 |
} |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
78 |
|
| 63 | 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 |
} |
|
|
57
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
97 |
|
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
98 |
} |
|
186c4121c7b3
add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
99 |