123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430 |
- <?php
-
- namespace Muzich\CoreBundle\Tests\Searcher;
-
- use Muzich\CoreBundle\lib\UnitTest;
- use Muzich\CoreBundle\Searcher\ElementSearcher;
-
- class ElementSearcherTest extends UnitTest
- {
- public function testInit()
- {
- $es = new ElementSearcher();
- $es->init($ia = array(
- 'network' => ElementSearcher::NETWORK_PERSONAL,
- 'tags' => array(1 => '', 2 => '', 6 => ''),
- 'count' => 20,
- 'user_id' => 185,
- 'group_id' => null,
- 'favorite' => false,
- 'ids' => null,
- 'ids_display' => null,
- 'tag_strict' => false,
- 'string' => null,
- 'need_tags' => false
- ));
-
- $this->assertEquals($ia, $es->getParams());
- }
-
- public function testUpdate()
- {
- $es = new ElementSearcher();
- $es->init($ia = array(
- 'network' => ElementSearcher::NETWORK_PERSONAL,
- 'tags' => array(1 => '', 2 => '', 6 => ''),
- 'count' => 20,
- 'user_id' => 185,
- 'group_id' => null,
- 'favorite' => false
- ));
- $es->init($ua = array(
- 'network' => ElementSearcher::NETWORK_PUBLIC,
- 'tags' => array(5 => '', 8 => '', 123 => ''),
- 'count' => 21,
- 'user_id' => 115,
- 'group_id' => null,
- 'favorite' => false,
- 'ids' => null,
- 'ids_display' => null,
- 'tag_strict' => false,
- 'string' => null,
- 'need_tags' => false
- ));
-
- $this->assertEquals($ua, $es->getParams());
- }
-
- protected function checkElementSearchResults($es_results, $array_names)
- {
- $cpt = 0;
- $array_names_es = array();
- foreach ($es_results as $element)
- {
- $array_names_es[] = (string)$element->getName();
- }
-
- $this->assertEquals($array_names, $array_names_es);
- }
-
- /**
- * Test pour la configuration:
- * public
- * tags
- * limit
- *
- * Test basés sur les FIXTURES
- */
- public function testGetPublicForTags()
- {
- $r = $this->getDoctrine();
- $bux = $r->getRepository('MuzichCoreBundle:User')
- ->findOneByUsername('bux')
- ;
- $hardtek = $r->getRepository('MuzichCoreBundle:Tag')->findOneByName('Hardtek');
- $tribe = $r->getRepository('MuzichCoreBundle:Tag')->findOneByName('Tribe');
- $electro = $r->getRepository('MuzichCoreBundle:Tag')->findOneByName('Electro');
-
- $es = new ElementSearcher();
- $es->init(array(
- 'network' => ElementSearcher::NETWORK_PUBLIC,
- 'tags' => array(
- $hardtek->getId() => 'Hardtek',
- $tribe->getId() => 'Tribe',
- $electro->getId() => 'Electro'
- ),
- 'count' => 5
- ));
-
- $this->checkElementSearchResults(
- $es->getElements($r, $bux->getId()),
- array(
- 'Ed Cox - La fanfare des teuffeurs (Hardcordian)',
- 'CardioT3K - Juggernaut Trap',
- 'RE-FUCK (ReVeRB_FBC) mix.',
- 'All Is Full Of Pain',
- 'Acrotek Hardtek G01'
- )
- );
-
- }
-
- /**
- * Test pour la configuration:
- * personal
- * tags
- * limit
- *
- * Test basés sur les FIXTURES
- */
- public function testGetPersonalForTags()
- {
- $r = $this->getDoctrine();
- $bux = $r->getRepository('MuzichCoreBundle:User')
- ->findOneByUsername('bux')
- ;
- $hardtek = $r->getRepository('MuzichCoreBundle:Tag')->findOneByName('Hardtek');
- $tribe = $r->getRepository('MuzichCoreBundle:Tag')->findOneByName('Tribe');
- $electro = $r->getRepository('MuzichCoreBundle:Tag')->findOneByName('Electro');
-
- $es = new ElementSearcher();
- $es->init(array(
- 'network' => ElementSearcher::NETWORK_PERSONAL,
- 'tags' => array(
- $hardtek->getId() => 'Hardtek',
- $tribe->getId() => 'Tribe',
- $electro->getId() => 'Electro'
- ),
- 'count' => 5
- ));
-
- $this->checkElementSearchResults(
- $es->getElements($r, $bux->getId()),
- array(
- 'CardioT3K - Juggernaut Trap',
- 'RE-FUCK (ReVeRB_FBC) mix.',
- 'All Is Full Of Pain',
- 'Acrotek Hardtek G01',
- 'Dj antoine'
- )
- );
-
- }
-
- /**
- * Test pour la configuration:
- * public
- * limit
- *
- * Test basés sur les FIXTURES
- */
- public function testGetPublicWithoutTags()
- {
- $r = $this->getDoctrine();
- $bux = $r->getRepository('MuzichCoreBundle:User')
- ->findOneByUsername('bux')
- ;
-
- $es = new ElementSearcher();
- $es->init(array(
- 'network' => ElementSearcher::NETWORK_PUBLIC,
- 'count' => 5
- ));
-
- $this->checkElementSearchResults(
- $es->getElements($r, $bux->getId()),
- array(
- 'Ed Cox - La fanfare des teuffeurs (Hardcordian)',
- 'Babylon Pression - Des Tasers et des Pauvres',
- 'AZYD AZYLUM Live au Café Provisoire',
- 'SOULFLY - Prophecy',
- 'Dubstep Beatbox'
- )
- );
-
- }
-
- /**
- * Test pour la configuration:
- * personal
- * limit
- *
- * Test basés sur les FIXTURES
- */
- public function testGetPersonalWithoutTags()
- {
- $r = $this->getDoctrine();
- $bux = $r->getRepository('MuzichCoreBundle:User')
- ->findOneByUsername('bux')
- ;
-
- $es = new ElementSearcher();
- $es->init(array(
- 'network' => ElementSearcher::NETWORK_PERSONAL,
- 'count' => 5
- ));
-
- $this->checkElementSearchResults(
- $es->getElements($r, $bux->getId()),
- array(
- 'Infected mushroom - Muse Breaks',
- 'Infected Mushroom - Psycho',
- 'DUDELDRUM',
- 'CardioT3K - Juggernaut Trap',
- 'RE-FUCK (ReVeRB_FBC) mix.'
- )
- );
-
- }
-
- /**
- * Test pour la configuration:
- * personal
- * limit
- *
- * Test basés sur les FIXTURES
- */
- public function testGetProfile()
- {
- $r = $this->getDoctrine();
- $bux = $r->getRepository('MuzichCoreBundle:User')
- ->findOneByUsername('bux')
- ;
- $jean = $r->getRepository('MuzichCoreBundle:User')
- ->findOneByUsername('jean')
- ;
-
- $es = new ElementSearcher();
- $es->init(array(
- 'user_id' => $jean->getId(),
- 'count' => 5
- ));
-
- $this->checkElementSearchResults(
- $es->getElements($r, $bux->getId()),
- array(
- 'Acrotek Hardtek G01',
- 'Dj antoine',
- 'DJ FAB'
- )
- );
-
- $paul = $r->getRepository('MuzichCoreBundle:User')
- ->findOneByUsername('paul')
- ;
-
- $es = new ElementSearcher();
- $es->init(array(
- 'user_id' => $paul->getId(),
- 'count' => 5
- ));
-
- $this->checkElementSearchResults(
- $es->getElements($r, $bux->getId()),
- array(
- 'Infected Mushroom - Psycho',
- 'CardioT3K - Juggernaut Trap',
- 'RE-FUCK (ReVeRB_FBC) mix.',
- 'All Is Full Of Pain'
- )
- );
-
- }
-
- /**
- * Test pour la configuration:
- * personal
- * limit
- *
- * Test basés sur les FIXTURES
- */
- public function testGetFavoriteProfile()
- {
- $r = $this->getDoctrine();
- $bux = $r->getRepository('MuzichCoreBundle:User')
- ->findOneByUsername('bux')
- ;
-
- $paul = $r->getRepository('MuzichCoreBundle:User')
- ->findOneByUsername('paul')
- ;
-
- $es = new ElementSearcher();
- $es->init(array(
- 'user_id' => $paul->getId(),
- 'favorite' => true,
- 'count' => 5
- ));
-
- $this->checkElementSearchResults(
- $es->getElements($r, $bux->getId()),
- array(
- 'All Is Full Of Pain',
- 'Heretik System Popof - Resistance'
- )
- );
-
- }
-
- /**
- * Test pour la configuration:
- * personal
- * limit
- *
- * Test basés sur les FIXTURES
- */
- public function testGetGroup()
- {
- $r = $this->getDoctrine();
- $bux = $r->getRepository('MuzichCoreBundle:User')
- ->findOneByUsername('bux')
- ;
- $fdepsy = $r->getRepository('MuzichCoreBundle:Group')
- ->findOneByName('Fans de psytrance')
- ;
-
- $es = new ElementSearcher();
- $es->init(array(
- 'group_id' => $fdepsy->getId(),
- 'count' => 5
- ));
-
- $this->checkElementSearchResults(
- $es->getElements($r, $bux->getId()),
- array(
- 'Infected mushroom - Muse Breaks',
- 'Infected Mushroom - Psycho'
- )
- );
-
- }
-
- public function testTagStrict()
- {
- $r = $this->getDoctrine();
- $bux = $r->getRepository('MuzichCoreBundle:User')
- ->findOneByUsername('bux')
- ;
- $hardtek = $r->getRepository('MuzichCoreBundle:Tag')->findOneByName('Hardtek');
- $tribe = $r->getRepository('MuzichCoreBundle:Tag')->findOneByName('Tribe');
- $electro = $r->getRepository('MuzichCoreBundle:Tag')->findOneByName('Electro');
- $metal = $r->getRepository('MuzichCoreBundle:Tag')->findOneByName('Metal');
- $hardcore = $r->getRepository('MuzichCoreBundle:Tag')->findOneByName('Hardcore');
- $psytrance = $r->getRepository('MuzichCoreBundle:Tag')->findOneByName('Psytrance');
- $dubstep = $r->getRepository('MuzichCoreBundle:Tag')->findOneByName('Dubstep');
-
- $es = new ElementSearcher();
- $es->init(array(
- 'network' => ElementSearcher::NETWORK_PUBLIC,
- 'tags' => array(
- $hardtek->getId() => 'Hardtek',
- $tribe->getId() => 'Tribe'
- ),
- 'count' => 5,
- 'tag_strict' => true
- ));
-
- $this->checkElementSearchResults(
- $es->getElements($r, $bux->getId()),
- array(
- 0 => 'All Is Full Of Pain',
- 1 => 'Dj antoine'
- )
- );
-
- $es = new ElementSearcher();
- $es->init(array(
- 'network' => ElementSearcher::NETWORK_PUBLIC,
- 'tags' => array(
- $electro->getId() => 'Electro',
- $hardtek->getId() => 'Hardtek'
- ),
- 'count' => 5,
- 'tag_strict' => true
- ));
-
- $this->checkElementSearchResults(
- $es->getElements($r, $bux->getId()),
- array(
- 'KoinkOin - H5N1'
- )
- );
-
- $es = new ElementSearcher();
- $es->init(array(
- 'network' => ElementSearcher::NETWORK_PUBLIC,
- 'tags' => array(
- $metal->getId() => 'Metal',
- $hardcore->getId() => 'Hardcore'
- ),
- 'count' => 5,
- 'tag_strict' => true
- ));
-
- $this->checkElementSearchResults(
- $es->getElements($r, $bux->getId()),
- array(
- 'Babylon Pression - Des Tasers et des Pauvres'
- )
- );
-
- $es = new ElementSearcher();
- $es->init(array(
- 'network' => ElementSearcher::NETWORK_PUBLIC,
- 'tags' => array(
- $metal->getId() => 'Metal',
- $hardcore->getId() => 'Hardcore',
- $tribe->getId() => 'Tribe'
- ),
- 'count' => 5,
- 'tag_strict' => true
- ));
-
- $this->checkElementSearchResults(
- $es->getElements($r, $bux->getId()),
- array()
- );
-
- }
-
- }
|