ElementSearcherTest.php 11KB

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