|
@@ -0,0 +1,213 @@
|
|
1
|
+<?php
|
|
2
|
+
|
|
3
|
+namespace Muzich\CoreBundle\Tests\Searcher;
|
|
4
|
+
|
|
5
|
+use Muzich\CoreBundle\lib\UnitTest;
|
|
6
|
+use Muzich\CoreBundle\Util\TagLike;
|
|
7
|
+
|
|
8
|
+class TagReadTest extends UnitTest
|
|
9
|
+{
|
|
10
|
+ private function getTagsNames($response = array())
|
|
11
|
+ {
|
|
12
|
+ if (count($response))
|
|
13
|
+ {
|
|
14
|
+ $tags_clean = array();
|
|
15
|
+ if (count($response['tags']))
|
|
16
|
+ {
|
|
17
|
+ foreach ($response['tags'] as $tag)
|
|
18
|
+ {
|
|
19
|
+ $tags_clean[] = $tag['name'];
|
|
20
|
+ }
|
|
21
|
+ }
|
|
22
|
+ return $tags_clean;
|
|
23
|
+ }
|
|
24
|
+ }
|
|
25
|
+ private function getTagsNamesForQuery($response = array())
|
|
26
|
+ {
|
|
27
|
+ if (count($response))
|
|
28
|
+ {
|
|
29
|
+ $tags_clean = array();
|
|
30
|
+ foreach ($response as $tag)
|
|
31
|
+ {
|
|
32
|
+ $tags_clean[] = $tag->getName();
|
|
33
|
+ }
|
|
34
|
+ return $tags_clean;
|
|
35
|
+ }
|
|
36
|
+ }
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+ /**
|
|
40
|
+ * Simple test des tags retournés
|
|
41
|
+ */
|
|
42
|
+ public function testSearchTag()
|
|
43
|
+ {
|
|
44
|
+ $bux = $this->getUser('bux');
|
|
45
|
+
|
|
46
|
+ $cresults = array(
|
|
47
|
+ 'Anarcho-punk', 'Dance-Punk', 'Horror punk', 'Pop-punk', 'Post-Punk',
|
|
48
|
+ 'Punk rock', 'Ska-punk', 'Skate punk', 'Synthpunk'
|
|
49
|
+ );
|
|
50
|
+
|
|
51
|
+ $TagLike = new TagLike($this->getDoctrine());
|
|
52
|
+ $response = $TagLike->getSimilarTags('punk', $bux->getId());
|
|
53
|
+
|
|
54
|
+ $this->assertEquals(count($cresults), count($response['tags']));
|
|
55
|
+
|
|
56
|
+ foreach ($response['tags'] as $tag)
|
|
57
|
+ {
|
|
58
|
+ $this->assertTrue(in_array($tag['name'], $cresults));
|
|
59
|
+ }
|
|
60
|
+ }
|
|
61
|
+
|
|
62
|
+ /**
|
|
63
|
+ * Test de l'ordre dans lequel les tags sont retourné
|
|
64
|
+ */
|
|
65
|
+ public function testSearchTagOrdered()
|
|
66
|
+ {
|
|
67
|
+ $bux = $this->getUser('bux');
|
|
68
|
+
|
|
69
|
+ //////////////////////////
|
|
70
|
+ $cresults = array(
|
|
71
|
+ 'Anarcho-punk', 'Dance-Punk', 'Horror punk', 'Pop-punk', 'Post-Punk',
|
|
72
|
+ 'Punk rock', 'Ska-punk', 'Skate punk', 'Synthpunk'
|
|
73
|
+ );
|
|
74
|
+
|
|
75
|
+ $TagLike = new TagLike($this->getDoctrine());
|
|
76
|
+ $tags = $this->getTagsNames($result = $TagLike->getSimilarTags('punk', $bux->getId()));
|
|
77
|
+
|
|
78
|
+ $this->assertEquals($cresults, $tags);
|
|
79
|
+ $this->assertEquals($result['same_found'], false);
|
|
80
|
+
|
|
81
|
+ //////////////////////////
|
|
82
|
+ $cresults = array(
|
|
83
|
+ 'Anarcho-punk', 'Dance-Punk', 'Horror punk', 'Pop-punk', 'Post-Punk',
|
|
84
|
+ 'Punk rock', 'Ska-punk', 'Skate punk', 'Synthpunk'
|
|
85
|
+ );
|
|
86
|
+
|
|
87
|
+ $TagLike = new TagLike($this->getDoctrine());
|
|
88
|
+ $tags = $this->getTagsNames($result = $TagLike->getSimilarTags('anarcho punk', $bux->getId()));
|
|
89
|
+
|
|
90
|
+ $this->assertEquals($cresults, $tags);
|
|
91
|
+ $this->assertEquals($result['same_found'], true);
|
|
92
|
+
|
|
93
|
+ //////////////////////////
|
|
94
|
+ $cresults = array(
|
|
95
|
+ 'Anarcho-punk', 'Dance-Punk', 'Horror punk', 'Pop-punk', 'Post-Punk',
|
|
96
|
+ 'Punk rock', 'Ska-punk', 'Skate punk', 'Synthpunk'
|
|
97
|
+ );
|
|
98
|
+
|
|
99
|
+ $TagLike = new TagLike($this->getDoctrine());
|
|
100
|
+ $tags = $this->getTagsNames($result = $TagLike->getSimilarTags('punk anarcho', $bux->getId()));
|
|
101
|
+
|
|
102
|
+ $this->assertEquals($cresults, $tags);
|
|
103
|
+ $this->assertEquals($result['same_found'], true);
|
|
104
|
+
|
|
105
|
+ //////////////////////////
|
|
106
|
+ $cresults = array(
|
|
107
|
+ 'Anarcho-punk', 'Dance-Punk', 'Horror punk', 'Pop-punk', 'Post-Punk',
|
|
108
|
+ 'Punk rock', 'Ska-punk', 'Skate punk', 'Synthpunk'
|
|
109
|
+ );
|
|
110
|
+
|
|
111
|
+ $TagLike = new TagLike($this->getDoctrine());
|
|
112
|
+ $tags = $this->getTagsNames($result = $TagLike->getSimilarTags('punk anar', $bux->getId()));
|
|
113
|
+
|
|
114
|
+ $this->assertEquals($cresults, $tags);
|
|
115
|
+ $this->assertEquals($result['same_found'], true);
|
|
116
|
+
|
|
117
|
+ //////////////////////////
|
|
118
|
+ $cresults = array(
|
|
119
|
+ 'Skate punk', 'Ska-punk', 'Ska', 'Anarcho-punk', 'Dance-Punk', 'Horror punk',
|
|
120
|
+ 'Pop-punk', 'Post-Punk', 'Punk rock', 'Skacore', 'Ska-jazz', 'Synthpunk'
|
|
121
|
+ );
|
|
122
|
+
|
|
123
|
+ $TagLike = new TagLike($this->getDoctrine());
|
|
124
|
+ $tags = $this->getTagsNames($result = $TagLike->getSimilarTags('ska punk', $bux->getId()));
|
|
125
|
+
|
|
126
|
+ $this->assertEquals($cresults, $tags);
|
|
127
|
+ $this->assertEquals($result['same_found'], true);
|
|
128
|
+
|
|
129
|
+ //////////////////////////
|
|
130
|
+ $cresults = array(
|
|
131
|
+ 'Horror punk'
|
|
132
|
+ );
|
|
133
|
+
|
|
134
|
+ $TagLike = new TagLike($this->getDoctrine());
|
|
135
|
+ $tags = $this->getTagsNames($result = $TagLike->getSimilarTags('horror', $bux->getId()));
|
|
136
|
+
|
|
137
|
+ $this->assertEquals($cresults, $tags);
|
|
138
|
+ $this->assertEquals($result['same_found'], false);
|
|
139
|
+ }
|
|
140
|
+
|
|
141
|
+ /**
|
|
142
|
+ * Check de la récupération des tags de profil
|
|
143
|
+ */
|
|
144
|
+ public function testSearchTagProfile()
|
|
145
|
+ {
|
|
146
|
+ $bux = $this->getUser('bux');
|
|
147
|
+ $joelle = $this->getUser('joelle');
|
|
148
|
+ $paul = $this->getUser('paul');
|
|
149
|
+
|
|
150
|
+ ////////////////////////////////
|
|
151
|
+ $rtags = array('Electro', 'Hardcore', 'Hardtek', 'Metal', 'Tribe');
|
|
152
|
+
|
|
153
|
+ $tags = $this->getTagsNamesForQuery($this->getDoctrine()->getRepository('MuzichCoreBundle:User')
|
|
154
|
+ ->getElementsTags($bux->getId())
|
|
155
|
+ );
|
|
156
|
+
|
|
157
|
+ $this->assertEquals($rtags, $tags);
|
|
158
|
+
|
|
159
|
+ ////////////////////////////////
|
|
160
|
+ $rtags = array('Beatbox', 'Chanteuse', 'Dubstep', 'Medieval');
|
|
161
|
+
|
|
162
|
+ $tags = $this->getTagsNamesForQuery($this->getDoctrine()->getRepository('MuzichCoreBundle:User')
|
|
163
|
+ ->getElementsTags($joelle->getId())
|
|
164
|
+ );
|
|
165
|
+
|
|
166
|
+ $this->assertEquals($rtags, $tags);
|
|
167
|
+
|
|
168
|
+ ////////////////////////////////
|
|
169
|
+ $rtags = array('Hardtek', 'Psytrance', 'Tribe');
|
|
170
|
+
|
|
171
|
+ $tags = $this->getTagsNamesForQuery($this->getDoctrine()->getRepository('MuzichCoreBundle:User')
|
|
172
|
+ ->getElementsTags($paul->getId())
|
|
173
|
+ );
|
|
174
|
+
|
|
175
|
+ $this->assertEquals($rtags, $tags);
|
|
176
|
+ }
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+ public function testSearchTagFavorites()
|
|
180
|
+ {
|
|
181
|
+ $bux = $this->getUser('bux');
|
|
182
|
+ $joelle = $this->getUser('joelle');
|
|
183
|
+ $paul = $this->getUser('paul');
|
|
184
|
+
|
|
185
|
+ ////////////////////////////////
|
|
186
|
+ $rtags = array('Hardtek');
|
|
187
|
+
|
|
188
|
+ $tags = $this->getTagsNamesForQuery($this->getDoctrine()->getRepository('MuzichCoreBundle:UsersElementsFavorites')
|
|
189
|
+ ->getTags($bux->getId())
|
|
190
|
+ );
|
|
191
|
+
|
|
192
|
+ $this->assertEquals($rtags, $tags);
|
|
193
|
+
|
|
194
|
+ ////////////////////////////////
|
|
195
|
+ $rtags = null;
|
|
196
|
+
|
|
197
|
+ $tags = $this->getTagsNamesForQuery($this->getDoctrine()->getRepository('MuzichCoreBundle:UsersElementsFavorites')
|
|
198
|
+ ->getTags($joelle->getId())
|
|
199
|
+ );
|
|
200
|
+
|
|
201
|
+ $this->assertEquals($rtags, $tags);
|
|
202
|
+
|
|
203
|
+ ////////////////////////////////
|
|
204
|
+ $rtags = array('Hardtek', 'Tribe');
|
|
205
|
+
|
|
206
|
+ $tags = $this->getTagsNamesForQuery($this->getDoctrine()->getRepository('MuzichCoreBundle:UsersElementsFavorites')
|
|
207
|
+ ->getTags($paul->getId())
|
|
208
|
+ );
|
|
209
|
+
|
|
210
|
+ $this->assertEquals($rtags, $tags);
|
|
211
|
+ }
|
|
212
|
+
|
|
213
|
+}
|