ElementSearcherTest.php 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  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. 'ids_display' => null,
  19. 'tag_strict' => false,
  20. 'string' => null
  21. ));
  22. $this->assertEquals($ia, $es->getParams());
  23. }
  24. public function testUpdate()
  25. {
  26. $es = new ElementSearcher();
  27. $es->init($ia = array(
  28. 'network' => ElementSearcher::NETWORK_PERSONAL,
  29. 'tags' => array(1 => '', 2 => '', 6 => ''),
  30. 'count' => 20,
  31. 'user_id' => 185,
  32. 'group_id' => null,
  33. 'favorite' => false
  34. ));
  35. $es->init($ua = array(
  36. 'network' => ElementSearcher::NETWORK_PUBLIC,
  37. 'tags' => array(5 => '', 8 => '', 123 => ''),
  38. 'count' => 21,
  39. 'user_id' => 115,
  40. 'group_id' => null,
  41. 'favorite' => false,
  42. 'ids' => null,
  43. 'ids_display' => null,
  44. 'tag_strict' => false,
  45. 'string' => null
  46. ));
  47. $this->assertEquals($ua, $es->getParams());
  48. }
  49. protected function checkElementSearchResults($es_results, $array_names)
  50. {
  51. $cpt = 0;
  52. $array_names_es = array();
  53. foreach ($es_results as $element)
  54. {
  55. $array_names_es[] = (string)$element->getName();
  56. }
  57. $this->assertEquals($array_names, $array_names_es);
  58. }
  59. /**
  60. * Test pour la configuration:
  61. * public
  62. * tags
  63. * limit
  64. *
  65. * Test basés sur les FIXTURES
  66. */
  67. public function testGetPublicForTags()
  68. {
  69. $r = $this->getDoctrine();
  70. $bux = $r->getRepository('MuzichCoreBundle:User')
  71. ->findOneByUsername('bux')
  72. ;
  73. $hardtek = $r->getRepository('MuzichCoreBundle:Tag')->findOneByName('Hardtek');
  74. $tribe = $r->getRepository('MuzichCoreBundle:Tag')->findOneByName('Tribe');
  75. $electro = $r->getRepository('MuzichCoreBundle:Tag')->findOneByName('Electro');
  76. $es = new ElementSearcher();
  77. $es->init(array(
  78. 'network' => ElementSearcher::NETWORK_PUBLIC,
  79. 'tags' => array(
  80. $hardtek->getId() => 'Hardtek',
  81. $tribe->getId() => 'Tribe',
  82. $electro->getId() => 'Electro'
  83. ),
  84. 'count' => 5
  85. ));
  86. $this->checkElementSearchResults(
  87. $es->getElements($r, $bux->getId()),
  88. array(
  89. 'Ed Cox - La fanfare des teuffeurs (Hardcordian)',
  90. 'CardioT3K - Juggernaut Trap',
  91. 'RE-FUCK (ReVeRB_FBC) mix.',
  92. 'All Is Full Of Pain',
  93. 'Acrotek Hardtek G01'
  94. )
  95. );
  96. }
  97. /**
  98. * Test pour la configuration:
  99. * personal
  100. * tags
  101. * limit
  102. *
  103. * Test basés sur les FIXTURES
  104. */
  105. public function testGetPersonalForTags()
  106. {
  107. $r = $this->getDoctrine();
  108. $bux = $r->getRepository('MuzichCoreBundle:User')
  109. ->findOneByUsername('bux')
  110. ;
  111. $hardtek = $r->getRepository('MuzichCoreBundle:Tag')->findOneByName('Hardtek');
  112. $tribe = $r->getRepository('MuzichCoreBundle:Tag')->findOneByName('Tribe');
  113. $electro = $r->getRepository('MuzichCoreBundle:Tag')->findOneByName('Electro');
  114. $es = new ElementSearcher();
  115. $es->init(array(
  116. 'network' => ElementSearcher::NETWORK_PERSONAL,
  117. 'tags' => array(
  118. $hardtek->getId() => 'Hardtek',
  119. $tribe->getId() => 'Tribe',
  120. $electro->getId() => 'Electro'
  121. ),
  122. 'count' => 5
  123. ));
  124. $this->checkElementSearchResults(
  125. $es->getElements($r, $bux->getId()),
  126. array(
  127. 'CardioT3K - Juggernaut Trap',
  128. 'RE-FUCK (ReVeRB_FBC) mix.',
  129. 'All Is Full Of Pain',
  130. 'Acrotek Hardtek G01',
  131. 'Dj antoine'
  132. )
  133. );
  134. }
  135. /**
  136. * Test pour la configuration:
  137. * public
  138. * limit
  139. *
  140. * Test basés sur les FIXTURES
  141. */
  142. public function testGetPublicWithoutTags()
  143. {
  144. $r = $this->getDoctrine();
  145. $bux = $r->getRepository('MuzichCoreBundle:User')
  146. ->findOneByUsername('bux')
  147. ;
  148. $es = new ElementSearcher();
  149. $es->init(array(
  150. 'network' => ElementSearcher::NETWORK_PUBLIC,
  151. 'count' => 5
  152. ));
  153. $this->checkElementSearchResults(
  154. $es->getElements($r, $bux->getId()),
  155. array(
  156. 'Ed Cox - La fanfare des teuffeurs (Hardcordian)',
  157. 'Babylon Pression - Des Tasers et des Pauvres',
  158. 'AZYD AZYLUM Live au Café Provisoire',
  159. 'SOULFLY - Prophecy',
  160. 'Dubstep Beatbox'
  161. )
  162. );
  163. }
  164. /**
  165. * Test pour la configuration:
  166. * personal
  167. * limit
  168. *
  169. * Test basés sur les FIXTURES
  170. */
  171. public function testGetPersonalWithoutTags()
  172. {
  173. $r = $this->getDoctrine();
  174. $bux = $r->getRepository('MuzichCoreBundle:User')
  175. ->findOneByUsername('bux')
  176. ;
  177. $es = new ElementSearcher();
  178. $es->init(array(
  179. 'network' => ElementSearcher::NETWORK_PERSONAL,
  180. 'count' => 5
  181. ));
  182. $this->checkElementSearchResults(
  183. $es->getElements($r, $bux->getId()),
  184. array(
  185. 'Infected mushroom - Muse Breaks',
  186. 'Infected Mushroom - Psycho',
  187. 'DUDELDRUM',
  188. 'CardioT3K - Juggernaut Trap',
  189. 'RE-FUCK (ReVeRB_FBC) mix.'
  190. )
  191. );
  192. }
  193. /**
  194. * Test pour la configuration:
  195. * personal
  196. * limit
  197. *
  198. * Test basés sur les FIXTURES
  199. */
  200. public function testGetProfile()
  201. {
  202. $r = $this->getDoctrine();
  203. $bux = $r->getRepository('MuzichCoreBundle:User')
  204. ->findOneByUsername('bux')
  205. ;
  206. $jean = $r->getRepository('MuzichCoreBundle:User')
  207. ->findOneByUsername('jean')
  208. ;
  209. $es = new ElementSearcher();
  210. $es->init(array(
  211. 'user_id' => $jean->getId(),
  212. 'count' => 5
  213. ));
  214. $this->checkElementSearchResults(
  215. $es->getElements($r, $bux->getId()),
  216. array(
  217. 'Acrotek Hardtek G01',
  218. 'Dj antoine',
  219. 'DJ FAB'
  220. )
  221. );
  222. $paul = $r->getRepository('MuzichCoreBundle:User')
  223. ->findOneByUsername('paul')
  224. ;
  225. $es = new ElementSearcher();
  226. $es->init(array(
  227. 'user_id' => $paul->getId(),
  228. 'count' => 5
  229. ));
  230. $this->checkElementSearchResults(
  231. $es->getElements($r, $bux->getId()),
  232. array(
  233. 'Infected Mushroom - Psycho',
  234. 'CardioT3K - Juggernaut Trap',
  235. 'RE-FUCK (ReVeRB_FBC) mix.',
  236. 'All Is Full Of Pain'
  237. )
  238. );
  239. }
  240. /**
  241. * Test pour la configuration:
  242. * personal
  243. * limit
  244. *
  245. * Test basés sur les FIXTURES
  246. */
  247. public function testGetFavoriteProfile()
  248. {
  249. $r = $this->getDoctrine();
  250. $bux = $r->getRepository('MuzichCoreBundle:User')
  251. ->findOneByUsername('bux')
  252. ;
  253. $paul = $r->getRepository('MuzichCoreBundle:User')
  254. ->findOneByUsername('paul')
  255. ;
  256. $es = new ElementSearcher();
  257. $es->init(array(
  258. 'user_id' => $paul->getId(),
  259. 'favorite' => true,
  260. 'count' => 5
  261. ));
  262. $this->checkElementSearchResults(
  263. $es->getElements($r, $bux->getId()),
  264. array(
  265. 'All Is Full Of Pain',
  266. 'Heretik System Popof - Resistance'
  267. )
  268. );
  269. }
  270. /**
  271. * Test pour la configuration:
  272. * personal
  273. * limit
  274. *
  275. * Test basés sur les FIXTURES
  276. */
  277. public function testGetGroup()
  278. {
  279. $r = $this->getDoctrine();
  280. $bux = $r->getRepository('MuzichCoreBundle:User')
  281. ->findOneByUsername('bux')
  282. ;
  283. $fdepsy = $r->getRepository('MuzichCoreBundle:Group')
  284. ->findOneByName('Fans de psytrance')
  285. ;
  286. $es = new ElementSearcher();
  287. $es->init(array(
  288. 'group_id' => $fdepsy->getId(),
  289. 'count' => 5
  290. ));
  291. $this->checkElementSearchResults(
  292. $es->getElements($r, $bux->getId()),
  293. array(
  294. 'Infected mushroom - Muse Breaks',
  295. 'Infected Mushroom - Psycho'
  296. )
  297. );
  298. }
  299. public function testTagStrict()
  300. {
  301. $r = $this->getDoctrine();
  302. $bux = $r->getRepository('MuzichCoreBundle:User')
  303. ->findOneByUsername('bux')
  304. ;
  305. $hardtek = $r->getRepository('MuzichCoreBundle:Tag')->findOneByName('Hardtek');
  306. $tribe = $r->getRepository('MuzichCoreBundle:Tag')->findOneByName('Tribe');
  307. $electro = $r->getRepository('MuzichCoreBundle:Tag')->findOneByName('Electro');
  308. $metal = $r->getRepository('MuzichCoreBundle:Tag')->findOneByName('Metal');
  309. $hardcore = $r->getRepository('MuzichCoreBundle:Tag')->findOneByName('Hardcore');
  310. $psytrance = $r->getRepository('MuzichCoreBundle:Tag')->findOneByName('Psytrance');
  311. $dubstep = $r->getRepository('MuzichCoreBundle:Tag')->findOneByName('Dubstep');
  312. $es = new ElementSearcher();
  313. $es->init(array(
  314. 'network' => ElementSearcher::NETWORK_PUBLIC,
  315. 'tags' => array(
  316. $hardtek->getId() => 'Hardtek',
  317. $tribe->getId() => 'Tribe'
  318. ),
  319. 'count' => 5,
  320. 'tag_strict' => true
  321. ));
  322. $this->checkElementSearchResults(
  323. $es->getElements($r, $bux->getId()),
  324. array(
  325. 0 => 'All Is Full Of Pain',
  326. 1 => 'Dj antoine'
  327. )
  328. );
  329. $es = new ElementSearcher();
  330. $es->init(array(
  331. 'network' => ElementSearcher::NETWORK_PUBLIC,
  332. 'tags' => array(
  333. $electro->getId() => 'Electro',
  334. $hardtek->getId() => 'Hardtek'
  335. ),
  336. 'count' => 5,
  337. 'tag_strict' => true
  338. ));
  339. $this->checkElementSearchResults(
  340. $es->getElements($r, $bux->getId()),
  341. array(
  342. 'KoinkOin - H5N1'
  343. )
  344. );
  345. $es = new ElementSearcher();
  346. $es->init(array(
  347. 'network' => ElementSearcher::NETWORK_PUBLIC,
  348. 'tags' => array(
  349. $metal->getId() => 'Metal',
  350. $hardcore->getId() => 'Hardcore'
  351. ),
  352. 'count' => 5,
  353. 'tag_strict' => true
  354. ));
  355. $this->checkElementSearchResults(
  356. $es->getElements($r, $bux->getId()),
  357. array(
  358. 'Babylon Pression - Des Tasers et des Pauvres'
  359. )
  360. );
  361. }
  362. }