|
@@ -0,0 +1,87 @@
|
|
1
|
+<?php
|
|
2
|
+
|
|
3
|
+namespace Muzich\CoreBundle\Tests\Searcher;
|
|
4
|
+
|
|
5
|
+use Muzich\CoreBundle\lib\UnitTest;
|
|
6
|
+use Muzich\CoreBundle\Searcher\ElementSearcher;
|
|
7
|
+
|
|
8
|
+class ElementSearcherTest extends UnitTest
|
|
9
|
+{
|
|
10
|
+ public function testInit()
|
|
11
|
+ {
|
|
12
|
+ $es = new ElementSearcher();
|
|
13
|
+ $es->init($ia = array(
|
|
14
|
+ 'network' => ElementSearcher::NETWORK_PERSONAL,
|
|
15
|
+ 'tags' => array(1, 2, 6),
|
|
16
|
+ 'count' => 20,
|
|
17
|
+ 'user_id' => 185,
|
|
18
|
+ 'group_id' => null,
|
|
19
|
+ 'favorite' => false
|
|
20
|
+ ));
|
|
21
|
+
|
|
22
|
+ $this->assertEquals($ia, $es->getParams());
|
|
23
|
+ }
|
|
24
|
+
|
|
25
|
+ public function testUpdate()
|
|
26
|
+ {
|
|
27
|
+ $es = new ElementSearcher();
|
|
28
|
+ $es->init($ia = array(
|
|
29
|
+ 'network' => ElementSearcher::NETWORK_PERSONAL,
|
|
30
|
+ 'tags' => array(1, 2, 6),
|
|
31
|
+ 'count' => 20,
|
|
32
|
+ 'user_id' => 185,
|
|
33
|
+ 'group_id' => null,
|
|
34
|
+ 'favorite' => false
|
|
35
|
+ ));
|
|
36
|
+ $es->init($ua = array(
|
|
37
|
+ 'network' => ElementSearcher::NETWORK_PUBLIC,
|
|
38
|
+ 'tags' => array(5, 8, 123),
|
|
39
|
+ 'count' => 21,
|
|
40
|
+ 'user_id' => 115,
|
|
41
|
+ 'group_id' => null,
|
|
42
|
+ 'favorite' => false
|
|
43
|
+ ));
|
|
44
|
+
|
|
45
|
+ $this->assertEquals($ua, $es->getParams());
|
|
46
|
+ }
|
|
47
|
+
|
|
48
|
+ public function testGetElements()
|
|
49
|
+ {
|
|
50
|
+ $r = $this->getDoctrine();
|
|
51
|
+ $bux = $r->getRepository('MuzichCoreBundle:User')
|
|
52
|
+ ->findOneByUsername('bux')
|
|
53
|
+ ;
|
|
54
|
+
|
|
55
|
+ /*
|
|
56
|
+ * Première passe: On check que la recherche nous retourne bien les
|
|
57
|
+ * elements de jean
|
|
58
|
+ */
|
|
59
|
+ $jean = $r->getRepository('MuzichCoreBundle:User')
|
|
60
|
+ ->findOneByUsername('jean')
|
|
61
|
+ ;
|
|
62
|
+ $es = new ElementSearcher();
|
|
63
|
+ $es->init(array(
|
|
64
|
+ 'user_id' => $jean->getId(),
|
|
65
|
+ 'count' => 20
|
|
66
|
+ ));
|
|
67
|
+
|
|
68
|
+ // On récupére avec un requte standart ce que devra retourner l'objet de
|
|
69
|
+ // recherche
|
|
70
|
+ $query_results = $r->getEntityManager()
|
|
71
|
+ ->createQuery("SELECT e
|
|
72
|
+ FROM MuzichCoreBundle:Element e
|
|
73
|
+ WHERE e.owner = :suid
|
|
74
|
+ ORDER BY e.created DESC")
|
|
75
|
+ ->setParameter('suid', $jean->getId())
|
|
76
|
+ ->setMaxResults(20)
|
|
77
|
+ ->getResult()
|
|
78
|
+ ;
|
|
79
|
+
|
|
80
|
+ // Les résultats de la recherche
|
|
81
|
+ $searcher_results = $es->getElements($r, $bux->getId());
|
|
82
|
+
|
|
83
|
+ // Maintenant on compare
|
|
84
|
+ $this->assertEquals($query_results, $searcher_results);
|
|
85
|
+
|
|
86
|
+ }
|
|
87
|
+}
|