ElementSearcherTest.php 7.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. <?php
  2. namespace Muzich\CoreBundle\Tests\Searcher;
  3. use Muzich\CoreBundle\lib\UnitTest;
  4. use Muzich\CoreBundle\Searcher\ElementSearcher;
  5. class ElementSearcherTest extends UnitTest
  6. {
  7. public function testInit()
  8. {
  9. $es = new ElementSearcher();
  10. $es->init($ia = array(
  11. 'network' => ElementSearcher::NETWORK_PERSONAL,
  12. 'tags' => array(1 => '', 2 => '', 6 => ''),
  13. 'count' => 20,
  14. 'user_id' => 185,
  15. 'group_id' => null,
  16. 'favorite' => false,
  17. 'ids' => null
  18. ));
  19. $this->assertEquals($ia, $es->getParams());
  20. }
  21. public function testUpdate()
  22. {
  23. $es = new ElementSearcher();
  24. $es->init($ia = array(
  25. 'network' => ElementSearcher::NETWORK_PERSONAL,
  26. 'tags' => array(1 => '', 2 => '', 6 => ''),
  27. 'count' => 20,
  28. 'user_id' => 185,
  29. 'group_id' => null,
  30. 'favorite' => false
  31. ));
  32. $es->init($ua = array(
  33. 'network' => ElementSearcher::NETWORK_PUBLIC,
  34. 'tags' => array(5 => '', 8 => '', 123 => ''),
  35. 'count' => 21,
  36. 'user_id' => 115,
  37. 'group_id' => null,
  38. 'favorite' => false,
  39. 'ids' => null
  40. ));
  41. $this->assertEquals($ua, $es->getParams());
  42. }
  43. protected function checkElementSearchResults($es_results, $array_names)
  44. {
  45. $cpt = 0;
  46. $array_names_es = array();
  47. foreach ($es_results as $element)
  48. {
  49. $array_names_es[] = (string)$element->getName();
  50. }
  51. $this->assertEquals($array_names, $array_names_es);
  52. }
  53. /**
  54. * Test pour la configuration:
  55. * public
  56. * tags
  57. * limit
  58. *
  59. * Test basés sur les FIXTURES
  60. */
  61. public function testGetPublicForTags()
  62. {
  63. $r = $this->getDoctrine();
  64. $bux = $r->getRepository('MuzichCoreBundle:User')
  65. ->findOneByUsername('bux')
  66. ;
  67. $hardtek = $r->getRepository('MuzichCoreBundle:Tag')->findOneByName('Hardtek');
  68. $tribe = $r->getRepository('MuzichCoreBundle:Tag')->findOneByName('Tribe');
  69. $electro = $r->getRepository('MuzichCoreBundle:Tag')->findOneByName('Electro');
  70. $es = new ElementSearcher();
  71. $es->init(array(
  72. 'network' => ElementSearcher::NETWORK_PUBLIC,
  73. 'tags' => array(
  74. $hardtek->getId() => 'Hardtek',
  75. $tribe->getId() => 'Tribe',
  76. $electro->getId() => 'Electro'
  77. ),
  78. 'count' => 5
  79. ));
  80. $this->checkElementSearchResults(
  81. $es->getElements($r, $bux->getId()),
  82. array(
  83. 'Ed Cox - La fanfare des teuffeurs (Hardcordian)',
  84. 'CardioT3K - Juggernaut Trap',
  85. 'RE-FUCK (ReVeRB_FBC) mix.',
  86. 'All Is Full Of Pain',
  87. 'Acrotek Hardtek G01'
  88. )
  89. );
  90. }
  91. /**
  92. * Test pour la configuration:
  93. * personal
  94. * tags
  95. * limit
  96. *
  97. * Test basés sur les FIXTURES
  98. */
  99. public function testGetPersonalForTags()
  100. {
  101. $r = $this->getDoctrine();
  102. $bux = $r->getRepository('MuzichCoreBundle:User')
  103. ->findOneByUsername('bux')
  104. ;
  105. $hardtek = $r->getRepository('MuzichCoreBundle:Tag')->findOneByName('Hardtek');
  106. $tribe = $r->getRepository('MuzichCoreBundle:Tag')->findOneByName('Tribe');
  107. $electro = $r->getRepository('MuzichCoreBundle:Tag')->findOneByName('Electro');
  108. $es = new ElementSearcher();
  109. $es->init(array(
  110. 'network' => ElementSearcher::NETWORK_PERSONAL,
  111. 'tags' => array(
  112. $hardtek->getId() => 'Hardtek',
  113. $tribe->getId() => 'Tribe',
  114. $electro->getId() => 'Electro'
  115. ),
  116. 'count' => 5
  117. ));
  118. $this->checkElementSearchResults(
  119. $es->getElements($r, $bux->getId()),
  120. array(
  121. 'CardioT3K - Juggernaut Trap',
  122. 'RE-FUCK (ReVeRB_FBC) mix.',
  123. 'All Is Full Of Pain',
  124. 'Acrotek Hardtek G01',
  125. 'Dj antoine'
  126. )
  127. );
  128. }
  129. /**
  130. * Test pour la configuration:
  131. * public
  132. * limit
  133. *
  134. * Test basés sur les FIXTURES
  135. */
  136. public function testGetPublicWithoutTags()
  137. {
  138. $r = $this->getDoctrine();
  139. $bux = $r->getRepository('MuzichCoreBundle:User')
  140. ->findOneByUsername('bux')
  141. ;
  142. $es = new ElementSearcher();
  143. $es->init(array(
  144. 'network' => ElementSearcher::NETWORK_PUBLIC,
  145. 'count' => 5
  146. ));
  147. $this->checkElementSearchResults(
  148. $es->getElements($r, $bux->getId()),
  149. array(
  150. 'Ed Cox - La fanfare des teuffeurs (Hardcordian)',
  151. 'Babylon Pression - Des Tasers et des Pauvres',
  152. 'AZYD AZYLUM Live au Café Provisoire',
  153. 'SOULFLY - Prophecy',
  154. 'Dubstep Beatbox'
  155. )
  156. );
  157. }
  158. /**
  159. * Test pour la configuration:
  160. * personal
  161. * limit
  162. *
  163. * Test basés sur les FIXTURES
  164. */
  165. public function testGetPersonalWithoutTags()
  166. {
  167. $r = $this->getDoctrine();
  168. $bux = $r->getRepository('MuzichCoreBundle:User')
  169. ->findOneByUsername('bux')
  170. ;
  171. $es = new ElementSearcher();
  172. $es->init(array(
  173. 'network' => ElementSearcher::NETWORK_PERSONAL,
  174. 'count' => 5
  175. ));
  176. $this->checkElementSearchResults(
  177. $es->getElements($r, $bux->getId()),
  178. array(
  179. 'Infected mushroom - Muse Breaks',
  180. 'Infected Mushroom - Psycho',
  181. 'DUDELDRUM',
  182. 'CardioT3K - Juggernaut Trap',
  183. 'RE-FUCK (ReVeRB_FBC) mix.'
  184. )
  185. );
  186. }
  187. /**
  188. * Test pour la configuration:
  189. * personal
  190. * limit
  191. *
  192. * Test basés sur les FIXTURES
  193. */
  194. public function testGetProfile()
  195. {
  196. $r = $this->getDoctrine();
  197. $bux = $r->getRepository('MuzichCoreBundle:User')
  198. ->findOneByUsername('bux')
  199. ;
  200. $jean = $r->getRepository('MuzichCoreBundle:User')
  201. ->findOneByUsername('jean')
  202. ;
  203. $es = new ElementSearcher();
  204. $es->init(array(
  205. 'user_id' => $jean->getId(),
  206. 'count' => 5
  207. ));
  208. $this->checkElementSearchResults(
  209. $es->getElements($r, $bux->getId()),
  210. array(
  211. 'Acrotek Hardtek G01',
  212. 'Dj antoine',
  213. 'DJ FAB'
  214. )
  215. );
  216. $paul = $r->getRepository('MuzichCoreBundle:User')
  217. ->findOneByUsername('paul')
  218. ;
  219. $es = new ElementSearcher();
  220. $es->init(array(
  221. 'user_id' => $paul->getId(),
  222. 'count' => 5
  223. ));
  224. $this->checkElementSearchResults(
  225. $es->getElements($r, $bux->getId()),
  226. array(
  227. 'Infected Mushroom - Psycho',
  228. 'CardioT3K - Juggernaut Trap',
  229. 'RE-FUCK (ReVeRB_FBC) mix.',
  230. 'All Is Full Of Pain'
  231. )
  232. );
  233. }
  234. /**
  235. * Test pour la configuration:
  236. * personal
  237. * limit
  238. *
  239. * Test basés sur les FIXTURES
  240. */
  241. public function testGetFavoriteProfile()
  242. {
  243. $r = $this->getDoctrine();
  244. $bux = $r->getRepository('MuzichCoreBundle:User')
  245. ->findOneByUsername('bux')
  246. ;
  247. $paul = $r->getRepository('MuzichCoreBundle:User')
  248. ->findOneByUsername('paul')
  249. ;
  250. $es = new ElementSearcher();
  251. $es->init(array(
  252. 'user_id' => $paul->getId(),
  253. 'favorite' => true,
  254. 'count' => 5
  255. ));
  256. $this->checkElementSearchResults(
  257. $es->getElements($r, $bux->getId()),
  258. array(
  259. 'All Is Full Of Pain',
  260. 'Heretik System Popof - Resistance'
  261. )
  262. );
  263. }
  264. /**
  265. * Test pour la configuration:
  266. * personal
  267. * limit
  268. *
  269. * Test basés sur les FIXTURES
  270. */
  271. public function testGetGroup()
  272. {
  273. $r = $this->getDoctrine();
  274. $bux = $r->getRepository('MuzichCoreBundle:User')
  275. ->findOneByUsername('bux')
  276. ;
  277. $fdepsy = $r->getRepository('MuzichCoreBundle:Group')
  278. ->findOneByName('Fans de psytrance')
  279. ;
  280. $es = new ElementSearcher();
  281. $es->init(array(
  282. 'group_id' => $fdepsy->getId(),
  283. 'count' => 5
  284. ));
  285. $this->checkElementSearchResults(
  286. $es->getElements($r, $bux->getId()),
  287. array(
  288. 'Infected mushroom - Muse Breaks',
  289. 'Infected Mushroom - Psycho'
  290. )
  291. );
  292. }
  293. }