1 | <?php |
---|
2 | |
---|
3 | include(dirname(__FILE__).'/../bootstrap/unit.php'); |
---|
4 | |
---|
5 | new sfDatabaseManager(ProjectConfiguration::getApplicationConfiguration('frontend', 'test', true)); |
---|
6 | $t = new lime_test(17); |
---|
7 | |
---|
8 | $s = new SolrConnector(); |
---|
9 | |
---|
10 | $i = new Intervention(); |
---|
11 | $inter = "bonjour les amis comment allez vous ?"; |
---|
12 | $i->intervention = $inter; |
---|
13 | $i->md5 = md5($inter.rand()); |
---|
14 | $i->parlementaire_id = 1; |
---|
15 | $i->date = "2009-10-10"; |
---|
16 | $i->addTag('loi:1987'); |
---|
17 | $i->save(); |
---|
18 | $s->updateFromCommands(); |
---|
19 | $id = "Intervention/".$i->id; |
---|
20 | $a = $s->search("id:$id"); |
---|
21 | |
---|
22 | $t->is(count($a['response']['docs']), 1, "L'intervention a été ajoutée"); |
---|
23 | $a = $s->search("bonjour id:$id"); |
---|
24 | $t->is($a['response']['docs'][0]['id'], $id, "L'intervention est trouvable"); |
---|
25 | |
---|
26 | $a = $s->search("salut id:$id"); |
---|
27 | $t->is(count($a['response']['docs']), 0, "L'intervention n'est pas retournée sur des mots non indexé"); |
---|
28 | |
---|
29 | $i->intervention = $inter." salut"; |
---|
30 | $i->save(); |
---|
31 | $s->updateFromCommands(); |
---|
32 | $a = $s->search("salut id:$id"); |
---|
33 | $t->is($a['response']['docs'][0]['id'], $id, "L'intervention retournée sur des mots reindexés"); |
---|
34 | |
---|
35 | $p = new Parlementaire(); |
---|
36 | $p->nom = "Benjamin Ooghe"; |
---|
37 | $p->save(); |
---|
38 | $s->updateFromCommands(); |
---|
39 | $id = "Parlementaire/".$p->id; |
---|
40 | $a = $s->search("id:$id"); |
---|
41 | $t->is(count($a['response']['docs']), 1, "Le parlementaire a été ajouté"); |
---|
42 | $a = $s->search("ooghe id:$id"); |
---|
43 | $t->is($a['response']['docs'][0]['id'], $id, "Le parlementaire est trouvable"); |
---|
44 | /* |
---|
45 | $a = $s->search("oghe object_name:Parlementaire"); |
---|
46 | $t->is($a['response']['docs'][0]['id'], $id, "Le parlementaire avec des fautes"); |
---|
47 | */ |
---|
48 | |
---|
49 | $q = new QuestionEcrite(); |
---|
50 | $q->question = "Ca va après les régionales ?"; |
---|
51 | $q->reponse = "On pourait aller mieux"; |
---|
52 | $q->parlementaire_id = 2; |
---|
53 | $q->ministere = "Ministere de la crise et du déficit"; |
---|
54 | $q->save(); |
---|
55 | |
---|
56 | $iexists = Doctrine::getTable('Intervention')->find(3); |
---|
57 | $iexists->save(); |
---|
58 | |
---|
59 | $s->updateFromCommands(); |
---|
60 | $id = "QuestionEcrite/".$q->id; |
---|
61 | $a = $s->search("id:$id"); |
---|
62 | $t->is(count($a['response']['docs']), 1, "La question a été ajoutée"); |
---|
63 | $a = $s->search("régionales id:$id"); |
---|
64 | $t->is($a['response']['docs'][0]['id'], $id, "La question est trouvable"); |
---|
65 | |
---|
66 | $a = Doctrine::getTable('Amendement')->find(7); |
---|
67 | $a->save(); |
---|
68 | $s->updateFromCommands(); |
---|
69 | |
---|
70 | $id = "Amendement/".$a->id; |
---|
71 | $r = $s->search("id:$id"); |
---|
72 | $t->is(count($r['response']['docs']), 1, "L'amendement a été ajoutée"); |
---|
73 | $s->deleteLuceneRecord($id); |
---|
74 | $s->updateFromCommands(); |
---|
75 | $r = $s->search("id:$id"); |
---|
76 | $t->is(count($r['response']['docs']), 0, "L'amendement a été supprimé dans lucene"); |
---|
77 | |
---|
78 | $id = "Intervention/".$i->id; |
---|
79 | $i->delete(); |
---|
80 | $s->updateFromCommands(); |
---|
81 | $r = $s->search("id:$id"); |
---|
82 | $t->is(count($r['response']['docs']), 0, "L'intervention a été supprimée"); |
---|
83 | |
---|
84 | $id = "Parlementaire/".$p->id; |
---|
85 | $p->delete(); |
---|
86 | $s->updateFromCommands(); |
---|
87 | $r = $s->search("id:$id"); |
---|
88 | $t->is(count($r['response']['docs']), 0, "Le parlementaire a été supprimée"); |
---|
89 | |
---|
90 | $id = "QuestionEcrite/".$q->id; |
---|
91 | $q->delete(); |
---|
92 | $s->updateFromCommands(); |
---|
93 | $r = $s->search("id:$id"); |
---|
94 | $t->is(count($r['response']['docs']), 0, "La question ecrite a été supprimée"); |
---|
95 | |
---|
96 | $c = new Commentaire(); |
---|
97 | $c->commentaire = "commentaire test"; |
---|
98 | $c->is_public = 0; |
---|
99 | $c->object_type = "Parlementaire"; |
---|
100 | $c->object_id = "1"; |
---|
101 | $c->citoyen_id = 2; |
---|
102 | |
---|
103 | $c->save(); |
---|
104 | $s->updateFromCommands(); |
---|
105 | $id = $c->id; |
---|
106 | $r = $s->search("id:Commentaire/$id"); |
---|
107 | $t->is(count($r['response']['docs']), 0, "Le commentaire n'est pas trouvable car is_public = 0"); |
---|
108 | |
---|
109 | $c = Doctrine::getTable('Commentaire')->find($id); |
---|
110 | $c->is_public = 1; |
---|
111 | $c->save(); |
---|
112 | $s->updateFromCommands(); |
---|
113 | $r = $s->search("id:Commentaire/$id"); |
---|
114 | $t->is(count($r['response']['docs']), 1, "Le commentaire est trouvable car is_public = 1"); |
---|
115 | |
---|
116 | $c = Doctrine::getTable('Commentaire')->find($id); |
---|
117 | $c->is_public = 0; |
---|
118 | $c->save(); |
---|
119 | $s->updateFromCommands(); |
---|
120 | $r = $s->search("id:Commentaire/$id"); |
---|
121 | $t->is(count($r['response']['docs']), 0, "Le commentaire n'est pas trouvable car is_public = 0"); |
---|
122 | |
---|
123 | $c->delete(); |
---|
124 | $s->updateFromCommands(); |
---|
125 | $r = $s->search("id:Commentaire/$id"); |
---|
126 | $t->is(count($r['response']['docs']), 0, "Le commentaire n'est pas trouvable car il est supprimé"); |
---|