123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197 |
- <?php
-
- namespace Muzich\CoreBundle\Tests\Controller;
-
- use Muzich\CoreBundle\lib\FunctionalTest;
-
- class ElementControllerTest extends FunctionalTest
- {
-
- public function testAddElementAjax()
- {
- $this->client = self::createClient();
- $this->connectUser('joelle', 'toor');
-
- $hardtek = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Hardtek');
- $tribe = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Tribe');
-
- // L'élément n'existe pas encore
- $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
- ->findOneByName('Musique qui dechire')
- ;
- $this->assertTrue(is_null($element));
-
- // On commence par ajouter un tag
- $url = $this->generateUrl('element_add');
-
- $extract = $this->crawler->filter('input[name="element_add[_token]"]')
- ->extract(array('value'));
- $csrf = $extract[0];
-
- $crawler = $this->client->request(
- 'POST',
- $url,
- array(
- 'element_add' => array(
- '_token' => $csrf,
- 'name' => 'Musique qui dechire',
- 'url' => 'http://www.youtube.com/watch?v=WC8qb_of04E',
- 'tags' => json_encode(array($hardtek->getId(), $tribe->getId()))
- )
-
- ),
- array(),
- array('HTTP_X-Requested-With' => 'XMLHttpRequest')
- );
-
- $this->isResponseSuccess();
-
- $response = json_decode($this->client->getResponse()->getContent(), true);
- $this->assertEquals($response['status'], 'success');
-
-
- $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
- ->findOneByName('Musique qui dechire')
- ;
- $this->assertTrue(!is_null($element));
-
- }
-
- public function testAddElementInGroupAjax()
- {
- $this->client = self::createClient();
- $this->connectUser('joelle', 'toor');
-
- $Fans_de_psytrance = $this->getDoctrine()->getRepository('MuzichCoreBundle:Group')->findOneByName('Fans de psytrance');
- $hardtek = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Hardtek');
- $tribe = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Tribe');
-
- // L'élément n'existe pas encore
- $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
- ->findOneByName('Musique qui dechire dans psytrance')
- ;
- $this->assertTrue(is_null($element));
-
- // On commence par ajouter un tag
- $url = $this->generateUrl('element_add', array('group_slug' => $Fans_de_psytrance->getSlug()));
-
- $extract = $this->crawler->filter('input[name="element_add[_token]"]')
- ->extract(array('value'));
- $csrf = $extract[0];
-
- $crawler = $this->client->request(
- 'POST',
- $url,
- array(
- 'element_add' => array(
- '_token' => $csrf,
- 'name' => 'Musique qui dechire dans psytrance',
- 'url' => 'http://www.youtube.com/watch?v=WC8qb_of04E',
- 'tags' => json_encode(array($hardtek->getId(), $tribe->getId()))
- )
-
- ),
- array(),
- array('HTTP_X-Requested-With' => 'XMLHttpRequest')
- );
-
- $this->isResponseSuccess();
-
- $response = json_decode($this->client->getResponse()->getContent(), true);
- $this->assertEquals($response['status'], 'success');
-
-
- $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
- ->findOneBy(array(
- 'name' => 'Musique qui dechire dans psytrance',
- 'group' => $Fans_de_psytrance->getId()
- ))
- ;
- $this->assertTrue(!is_null($element));
-
- }
-
- public function testAddElementAjaxFail()
- {
- $this->client = self::createClient();
- $this->connectUser('joelle', 'toor');
-
- $hardtek = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Hardtek');
- $tribe = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Tribe');
-
- // L'élément n'existe pas encore
- $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
- ->findOneByName('Musique qui dechire')
- ;
- $this->assertTrue(is_null($element));
-
- // On commence par ajouter un tag
- $url = $this->generateUrl('element_add');
-
- $extract = $this->crawler->filter('input[name="element_add[_token]"]')
- ->extract(array('value'));
- $csrf = $extract[0];
-
- $crawler = $this->client->request(
- 'POST',
- $url,
- array(
- 'element_add' => array(
- '_token' => $csrf,
- 'name' => 'Musique qui dechire',
- 'url' => 'http://www',
- 'tags' => json_encode(array($hardtek->getId(), $tribe->getId()))
- )
-
- ),
- array(),
- array('HTTP_X-Requested-With' => 'XMLHttpRequest')
- );
-
- $this->isResponseSuccess();
-
- $response = json_decode($this->client->getResponse()->getContent(), true);
- $this->assertEquals($response['status'], 'error');
-
- $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
- ->findOneByName('Musique qui dechire')
- ;
- $this->assertTrue(is_null($element));
-
- }
-
- public function testAddElementInGroupAjaxFail()
- {
- $this->client = self::createClient();
- $this->connectUser('joelle', 'toor');
-
- $Fans_de_psytrance = $this->getDoctrine()->getRepository('MuzichCoreBundle:Group')->findOneByName('Fans de psytrance');
- $hardtek = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Hardtek');
- $tribe = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Tribe');
-
- // L'élément n'existe pas encore
- $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
- ->findOneByName('zo')
- ;
- $this->assertTrue(is_null($element));
-
- // On commence par ajouter un tag
- $url = $this->generateUrl('element_add', array('group_slug' => $Fans_de_psytrance->getSlug()));
-
- $extract = $this->crawler->filter('input[name="element_add[_token]"]')
- ->extract(array('value'));
- $csrf = $extract[0];
-
- $crawler = $this->client->request(
- 'POST',
- $url,
- array(
- 'element_add' => array(
- '_token' => $csrf,
- 'name' => 'zo',
- 'url' => 'http://www.youtube.com/watch?v=WC8qb_of04E',
- 'tags' => json_encode(array($hardtek->getId(), $tribe->getId()))
- )
-
- ),
- array(),
- array('HTTP_X-Requested-With' => 'XMLHttpRequest')
- );
-
- $this->isResponseSuccess();
-
- $response = json_decode($this->client->getResponse()->getContent(), true);
- $this->assertEquals($response['status'], 'error');
-
-
- $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
- ->findOneBy(array(
- 'name' => 'zo',
- 'group' => $Fans_de_psytrance->getId()
- ))
- ;
- $this->assertTrue(is_null($element));
-
- }
-
- public function testUpdateElement()
- {
- $this->client = self::createClient();
- $this->connectUser('bux', 'toor');
-
- $bux = $this->getUser();
-
- $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
- ->findOneByName('Ed Cox - La fanfare des teuffeurs (Hardcordian)')
- ;
-
- // On est sur la page home, on peut voir le lien de modification de l'élément
- $this->exist('a[href="'.($url = $this->generateUrl('element_edit', array('element_id' => $element->getId()))).'"]');
-
- // On effectue la demande ajax d'edition
- $crawler = $this->client->request(
- 'GET',
- $url,
- array(),
- array(),
- array('HTTP_X-Requested-With' => 'XMLHttpRequest')
- );
-
- $this->isResponseSuccess();
-
- $response = json_decode($this->client->getResponse()->getContent(), true);
- $this->assertEquals($response['status'], 'success');
- $this->assertEquals($response['form_name'], 'element_'.$element->getId());
- $this->assertTrue(strpos($response['html'], 'class="edit_element"') !== false);
-
- // Il faut que l'on récupère le token
- preg_match("#name=\"element_add\[_token\]\" value=\"([a-zA-Z0-9]+)\" />#", $response['html'], $chaines);
- $csrf = $chaines[1];
-
- // On effectue la modification en ajax
- $url = $this->generateUrl('element_update', array(
- 'element_id' => $element->getId(),
- 'dom_id' => 'element_'.$element->getId()
- ));
-
- $crawler = $this->client->request(
- 'POST',
- $url,
- array(
- 'element_add' => array(
- '_token' => $csrf,
- 'name' => $element->getName().'555',
- 'url' => $element->getUrl(),
- 'tags' => $element->getTagsIdsJson()
- )
-
- ),
- array(),
- array('HTTP_X-Requested-With' => 'XMLHttpRequest')
- );
-
- $this->isResponseSuccess();
-
- $response = json_decode($this->client->getResponse()->getContent(), true);
- $this->assertEquals($response['status'], 'success');
- $this->assertTrue(strpos($response['html'], $element->getName().'555') !== false);
-
- $this->crawler = $this->client->request('GET', $this->generateUrl('home'));
- $this->exist('span.element_name:contains("'.$element->getName().'555'.'")');
-
- $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
- ->findOneByName($element->getName().'555')
- ;
- $this->assertTrue(!is_null($element));
- }
-
- public function testDeleteElement()
- {
- $this->client = self::createClient();
- $this->connectUser('bux', 'toor');
-
- $bux = $this->getUser();
-
- $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
- ->findOneByName('Ed Cox - La fanfare des teuffeurs (Hardcordian)')
- ;
-
- // On est sur la page home, on peut voir le lien de suppression l'élément
- $this->exist('a[href="'.($url = $this->generateUrl('element_remove', array(
- 'element_id' => $element->getId()
- ))).'"]');
-
- // Suppression de l'élément
-
- // On effectue la demande ajax d'edition
- $crawler = $this->client->request(
- 'GET',
- $url,
- array(),
- array(),
- array('HTTP_X-Requested-With' => 'XMLHttpRequest')
- );
-
- $this->isResponseSuccess();
-
- $response = json_decode($this->client->getResponse()->getContent(), true);
- $this->assertEquals($response['status'], 'success');
-
- $this->crawler = $this->client->request('GET', $this->generateUrl('home'));
- $this->notExist('span.element_name:contains("'.$element->getName().'")');
-
- $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
- ->findOneByName('Ed Cox - La fanfare des teuffeurs (Hardcordian)')
- ;
- $this->assertTrue(is_null($element));
- }
-
- /**
- * Procédure de vote
- */
- public function testVote()
- {
- $this->client = self::createClient();
- $this->connectUser('paul', 'toor');
-
- $paul = $this->getUser();
- $joelle = $this->getUser('joelle');
- $jean = $this->getUser('jean');
-
- // D'après les fixtures, un des élément porte le vote de paul
- $element_soul = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
- ->findOneByName('SOULFLY - Prophecy')
- ;
-
- // On peut donc voir le lien pour "dé-voter"
- $url_unvote_soul = $this->generateUrl('ajax_element_remove_vote_good', array(
- 'element_id' => $element_soul->getId(),
- 'token' => $paul->getPersonalHash()
- ));
- $this->exist('a.vote[href="'.$url_unvote_soul.'"]');
-
- // On contrôle le contenu pour cet element
- $this->assertEquals($element_soul->getPoints(), 1);
-
- // Et son id est la
- $this->assertEquals($element_soul->getVoteGoodIds(), array(
- (string)$paul->getId()
- ));
-
- // On va voter pour un element a bux
- $element_ed = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
- ->findOneByName('Ed Cox - La fanfare des teuffeurs (Hardcordian)')
- ;
-
- // Actuellement (fixtures) son score est de 2
- $this->assertEquals($element_ed->getPoints(), 2);
-
- // Et ce sont (fixtures) ces deux user qui ont voté
- $this->assertEquals($element_ed->getVoteGoodIds(), array((string)$joelle->getId(), (string)$jean->getId()));
-
- // On peut d'ailleur constater que la reputation de bux est de 7 (fixtures)
- $bux = $this->getUser('bux');
- $this->assertEquals($bux->getReputation(), 22);
-
- // paul va voter
- $crawler = $this->client->request(
- 'GET',
- $this->generateUrl('ajax_element_add_vote_good', array(
- 'element_id' => $element_ed->getId(),
- 'token' => $paul->getPersonalHash()
- )),
- array(),
- array(),
- array('HTTP_X-Requested-With' => 'XMLHttpRequest')
- );
-
- $this->isResponseSuccess();
-
- $response = json_decode($this->client->getResponse()->getContent(), true);
- $this->assertEquals($response['status'], 'success');
-
- // On recontrôle l'élément voir si tout a été enregistré
- $element_ed = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
- ->findOneByName('Ed Cox - La fanfare des teuffeurs (Hardcordian)')
- ;
-
- // Son score est mainteannt de 3
- $this->assertEquals($element_ed->getPoints(), 3);
-
- // Et son id est la
- $this->assertEquals($element_ed->getVoteGoodIds(), array(
- (string)$joelle->getId(),
- (string)$jean->getId(),
- (string)$paul->getId()
- ));
-
- // On peut d'ailleur constater que la reputation de bux est maintenant de 8
- $bux = $this->getUser('bux');
- $this->assertEquals($bux->getReputation(), 23);
-
- // Pau retire son vote de soulfy
- $crawler = $this->client->request(
- 'GET',
- $url_unvote_soul,
- array(),
- array(),
- array('HTTP_X-Requested-With' => 'XMLHttpRequest')
- );
-
- $element_soul = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
- ->findOneByName('SOULFLY - Prophecy')
- ;
- // On contrôle le contenu pour cet element
- $this->assertEquals($element_soul->getPoints(), 0);
-
- // Et son id est la
- $this->assertEquals($element_soul->getVoteGoodIds(), array());
-
- // On peut d'ailleur constater que la reputation de bux est maintenant de 7
- $bux = $this->getUser('bux');
- $this->assertEquals($bux->getReputation(), 22);
-
- // On déconnecte paul, pour faire voter bob sur le partage ed cox
- $this->disconnectUser();
- $this->connectUser('bob', 'toor');
-
- $bob = $this->getUser();
- // bob va donc votre pour le partage d'ed cox
- $crawler = $this->client->request(
- 'GET',
- $this->generateUrl('ajax_element_add_vote_good', array(
- 'element_id' => $element_ed->getId(),
- 'token' => $bob->getPersonalHash()
- )),
- array(),
- array(),
- array('HTTP_X-Requested-With' => 'XMLHttpRequest')
- );
-
- $this->isResponseSuccess();
-
- $response = json_decode($this->client->getResponse()->getContent(), true);
- $this->assertEquals($response['status'], 'success');
-
- // On recontrôle l'élément voir si tout a été enregistré
- $element_ed = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
- ->findOneByName('Ed Cox - La fanfare des teuffeurs (Hardcordian)')
- ;
-
- // Son score est mainteannt de 3
- $this->assertEquals($element_ed->getPoints(), 4);
-
- // Et son id est la
- $this->assertEquals($element_ed->getVoteGoodIds(), array(
- (string)$joelle->getId(),
- (string)$jean->getId(),
- (string)$paul->getId(),
- (string)$bob->getId()
- ));
-
- // On peut d'ailleur constater que la reputation de bux est maintenant de 8
- $bux = $this->getUser('bux');
- $this->assertEquals($bux->getReputation(), 23);
- }
-
- /**
- * Test des procédure concernants al proposition de tags sur un élément
- *
- * On test ici:
- * * Proposition de tags
- * * La consultation de ces propositions
- * * L'acceptation
- */
- public function testTagsPropositionAccept()
- {
- $this->client = self::createClient();
- $this->connectUser('paul', 'toor');
-
- $hardtek = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Hardtek');
- $tribe = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Tribe');
- $tsouzoumi = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Tsouzoumi');
- $soug = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Soug');
- $metal = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Metal');
-
- $paul = $this->getUser();
- $bux = $this->getUser('bux');
- $joelle = $this->getUser('joelle');
-
- $points_pour_tags_add = $this->getContainer()->getParameter('reputation_element_tags_element_prop_value');
- $points_joelle = $joelle->getReputation();
- $points_bux = $bux->getReputation();
- $points_paul = $paul->getReputation();
-
- $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
- ->findOneByName('AZYD AZYLUM Live au Café Provisoire')
- ;
-
- // Pas de proposition en base pur cet élément
- $propositions = $this->getDoctrine()->getEntityManager()->getRepository('MuzichCoreBundle:ElementTagsProposition')
- ->findOneByElement($element->getId())
- ;
-
- $this->assertEquals(0, count($propositions));
-
- // Pas d'événement pour bux
- $events = $this->getDoctrine()->getEntityManager()
- ->createQuery('SELECT e FROM MuzichCoreBundle:Event e
- WHERE e.user = :uid AND e.type = :type'
- )
- ->setParameters(array(
- 'uid' => $bux->getId(),
- 'type' => \Muzich\CoreBundle\Entity\Event::TYPE_TAGS_PROPOSED
- ))
- ->getArrayResult()
- ;
- $this->assertEquals(count($events), 0);
-
- // On teste la récupération du formulaire au moin une fois
- $crawler = $this->client->request(
- 'GET',
- $this->generateUrl('ajax_element_propose_tags_open',
- array('element_id' => $element->getId())
- ),
- array(),
- array(),
- array('HTTP_X-Requested-With' => 'XMLHttpRequest')
- );
-
- $this->isResponseSuccess();
-
- $response = json_decode($this->client->getResponse()->getContent(), true);
- $this->assertEquals($response['status'], 'success');
- $this->assertEquals($response['form_name'], 'element_tag_proposition_'.$element->getId());
- $this->assertTrue(strpos($response['html'], 'class="tag_proposition"') !== false);
-
- // paul propose une serie de tags
- $crawler = $this->client->request(
- 'POST',
- $this->generateUrl('ajax_element_propose_tags_proceed',
- array('element_id' => $element->getId(), 'token' => $paul->getPersonalHash())
- ),
- array(
- 'element_tag_proposition_'.$element->getId() => array(
- 'tags' => json_encode(array($hardtek->getId(), $tribe->getId()))
- )
- ),
- array(),
- array('HTTP_X-Requested-With' => 'XMLHttpRequest')
- );
-
- $this->isResponseSuccess();
-
- $response = json_decode($this->client->getResponse()->getContent(), true);
- $this->assertEquals($response['status'], 'success');
-
- // On a maintenant la proposition en base
- $propositions = $this->getDoctrine()->getEntityManager()
- ->createQuery('SELECT p, t FROM MuzichCoreBundle:ElementTagsProposition p'
- .' JOIN p.tags t WHERE p.element = :eid AND p.user = :uid')
- ->setParameters(array(
- 'eid' => $element->getId(),
- 'uid' => $paul->getId()
- ))
- ->getResult()
- ;
-
- $this->assertEquals(1, count($propositions));
- $proposition_paul = $propositions[0];
-
- // Les tags sont aussi en base
- foreach ($propositions[0]->getTags() as $tag)
- {
- if (in_array($tag->getId(), array($hardtek->getId(), $tribe->getId())))
- {
- $this->assertTrue(true);
- }
- else
- {
- $this->assertTrue(false);
- }
- }
-
- // Il y a maintenant un event pour bux
- $events = $this->getDoctrine()->getEntityManager()
- ->createQuery('SELECT e FROM MuzichCoreBundle:Event e
- WHERE e.user = :uid AND e.type = :type'
- )
- ->setParameters(array(
- 'uid' => $bux->getId(),
- 'type' => \Muzich\CoreBundle\Entity\Event::TYPE_TAGS_PROPOSED
- ))
- ->getArrayResult()
- ;
- $this->assertEquals(count($events), 1);
- $this->assertEquals($events[0]['type'], \Muzich\CoreBundle\Entity\Event::TYPE_TAGS_PROPOSED);
- //
- $this->assertEquals($events[0]['count'], 1);
- $this->assertEquals($events[0]['ids'], json_encode(array((string)$element->getId())));
-
- // si il propose un liste vide de tags, c'est refusé bien entendu
- $crawler = $this->client->request(
- 'POST',
- $this->generateUrl('ajax_element_propose_tags_proceed',
- array('element_id' => $element->getId(), 'token' => $paul->getPersonalHash())
- ),
- array(
- 'element_tag_proposition_'.$element->getId() => array(
- 'tags' => json_encode(array())
- )
- ),
- array(),
- array('HTTP_X-Requested-With' => 'XMLHttpRequest')
- );
-
- $this->isResponseSuccess();
-
- $response = json_decode($this->client->getResponse()->getContent(), true);
- $this->assertEquals($response['status'], 'error');
-
- /*
- * joelle va aussi proposer des tags sur cet élément
- */
- $this->disconnectUser();
- $this->connectUser('joelle', 'toor');
-
- $joelle = $this->getUser();
-
- // joelle propose une serie de tags
- $crawler = $this->client->request(
- 'POST',
- $this->generateUrl('ajax_element_propose_tags_proceed',
- array('element_id' => $element->getId(), 'token' => $joelle->getPersonalHash())
- ),
- array(
- 'element_tag_proposition_'.$element->getId() => array(
- 'tags' => json_encode(array($tsouzoumi->getId(), $soug->getId(), $metal->getId()))
- )
- ),
- array(),
- array('HTTP_X-Requested-With' => 'XMLHttpRequest')
- );
-
- $this->isResponseSuccess();
-
- $response = json_decode($this->client->getResponse()->getContent(), true);
- $this->assertEquals($response['status'], 'success');
-
- // On a maintenant la proposition en base
- $propositions = $this->getDoctrine()->getEntityManager()
- ->createQuery('SELECT p, t FROM MuzichCoreBundle:ElementTagsProposition p'
- .' JOIN p.tags t WHERE p.element = :eid AND p.user = :uid')
- ->setParameters(array(
- 'eid' => $element->getId(),
- 'uid' => $joelle->getId()
- ))
- ->getResult()
- ;
-
- $this->assertEquals(1, count($propositions));
- $proposition_joelle = $propositions[0];
-
- // Les tags sont aussi en base
- foreach ($propositions[0]->getTags() as $tag)
- {
- if (in_array($tag->getId(), array($tsouzoumi->getId(), $soug->getId(), $metal->getId())))
- {
- $this->assertTrue(true);
- }
- else
- {
- $this->assertTrue(false);
- }
- }
-
- // avec la propsoition de joelle le nombre d'event n'a pas bougé (le compteur compte les éléments)
- $events = $this->getDoctrine()->getEntityManager()
- ->createQuery('SELECT e FROM MuzichCoreBundle:Event e
- WHERE e.user = :uid AND e.type = :type'
- )
- ->setParameters(array(
- 'uid' => $bux->getId(),
- 'type' => \Muzich\CoreBundle\Entity\Event::TYPE_TAGS_PROPOSED
- ))
- ->getArrayResult()
- ;
- $this->assertEquals(count($events), 1);
- $this->assertEquals($events[0]['type'], \Muzich\CoreBundle\Entity\Event::TYPE_TAGS_PROPOSED);
- //
- $this->assertEquals($events[0]['count'], 1);
- $this->assertEquals($events[0]['ids'], json_encode(array((string)$element->getId())));
-
- /*
- * C'est au tour de bux d'aller voir ces proposition
- */
-
- $this->disconnectUser();
- $this->connectUser('bux', 'toor');
-
- $bux = $this->getUser();
-
- // Il peut voir le lien vers l'ouverture des propositions
- $url = $this->generateUrl('ajax_element_proposed_tags_view', array('element_id' => $element->getId()));
- $this->exist('a[href="'.$url.'"]');
-
- // On récupére ces propositions
- $crawler = $this->client->request(
- 'GET',
- $url,
- array(),
- array(),
- array('HTTP_X-Requested-With' => 'XMLHttpRequest')
- );
-
- $this->isResponseSuccess();
-
- $response = json_decode($this->client->getResponse()->getContent(), true);
- $this->assertEquals($response['status'], 'success');
-
- $url_accept_paul = $this->generateUrl('ajax_element_proposed_tags_accept', array(
- 'proposition_id' => $proposition_paul->getId(),
- 'token' => $bux->getPersonalHash()
- ));
- $url_accept_joelle = $this->generateUrl('ajax_element_proposed_tags_accept', array(
- 'proposition_id' => $proposition_joelle->getId(),
- 'token' => $bux->getPersonalHash()
- ));
- $this->assertTrue(strpos($response['html'], 'href="'.$url_accept_paul.'"') !== false);
- $this->assertTrue(strpos($response['html'], 'href="'.$url_accept_joelle.'"') !== false);
- $url_refuse = $this->generateUrl('ajax_element_proposed_tags_refuse', array(
- 'element_id' => $element->getId(),
- 'token' => $bux->getPersonalHash()
- ));
-
- // On accepete la poposition de joelle
- $crawler = $this->client->request(
- 'GET',
- $url_accept_joelle,
- array(),
- array(),
- array('HTTP_X-Requested-With' => 'XMLHttpRequest')
- );
-
- $this->isResponseSuccess();
-
- $response = json_decode($this->client->getResponse()->getContent(), true);
- $this->assertEquals($response['status'], 'success');
-
- $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
- ->findOneByName('AZYD AZYLUM Live au Café Provisoire')
- ;
- // Les tags de l'élément ont bien été mis a jour
- foreach (json_decode($element->getTagsIdsJson(), true) as $id)
- {
- if (in_array($id, array($metal->getId(), $soug->getId(), $tsouzoumi->getId())))
- {
- $this->assertTrue(true);
- }
- else
- {
- $this->assertTrue(false);
- }
- }
- $ids = json_decode($element->getTagsIdsJson(), true);
- foreach (array($metal->getId(), $soug->getId(), $tsouzoumi->getId()) as $id)
- {
- if (in_array($id, $ids))
- {
- $this->assertTrue(true);
- }
- else
- {
- $this->assertTrue(false);
- }
- }
-
- // La proposition de joelle a disparu
- $propositions = $this->getDoctrine()->getEntityManager()
- ->createQuery('SELECT p, t FROM MuzichCoreBundle:ElementTagsProposition p'
- .' JOIN p.tags t WHERE p.element = :eid AND p.user = :uid')
- ->setParameters(array(
- 'eid' => $element->getId(),
- 'uid' => $joelle->getId()
- ))
- ->getResult()
- ;
- $this->assertEquals(0, count($propositions));
-
- // celle de paul aussi
- $propositions = $this->getDoctrine()->getEntityManager()
- ->createQuery('SELECT p, t FROM MuzichCoreBundle:ElementTagsProposition p'
- .' JOIN p.tags t WHERE p.element = :eid AND p.user = :uid')
- ->setParameters(array(
- 'eid' => $element->getId(),
- 'uid' => $paul->getId()
- ))
- ->getResult()
- ;
- $this->assertEquals(0, count($propositions));
-
- // Mais on a un event en archive pour joelle
- $archives = $this->getDoctrine()->getEntityManager()
- ->createQuery('SELECT a FROM MuzichCoreBundle:EventArchive a'
- .' WHERE a.user = :uid AND a.type = :type')
- ->setParameters(array(
- 'uid' => $joelle->getId(),
- 'type' => \Muzich\CoreBundle\Entity\EventArchive::PROP_TAGS_ELEMENT_ACCEPTED
- ))
- ->getResult()
- ;
- $this->assertEquals(1, count($archives));
- $this->assertEquals(1, $archives[0]->getCount());
-
- // paul lui n'a pas d'archives
- $archives = $this->getDoctrine()->getEntityManager()
- ->createQuery('SELECT a FROM MuzichCoreBundle:EventArchive a'
- .' WHERE a.user = :uid AND a.type = :type')
- ->setParameters(array(
- 'uid' => $paul->getId(),
- 'type' => \Muzich\CoreBundle\Entity\EventArchive::PROP_TAGS_ELEMENT_ACCEPTED
- ))
- ->getResult()
- ;
- $this->assertEquals(0, count($archives));
-
- // contrôle de l'évolution des points
- $bux = $this->getUser('bux');
- $joelle = $this->getUser('joelle');
- $paul = $this->getUser('paul');
-
- $this->assertEquals($points_bux, $bux->getReputation());
- $this->assertEquals($points_joelle + $points_pour_tags_add, $joelle->getReputation());
- $this->assertEquals($points_paul, $paul->getReputation());
-
- }
-
- /**
- * Test des procédure concernants al proposition de tags sur un élément
- *
- * On test ici:
- * * Proposition de tags
- * * La consultation de ces propositions
- * * Le refus
- */
- public function testTagsPropositionRefuse()
- {
- $this->client = self::createClient();
- $this->connectUser('paul', 'toor');
-
- $hardtek = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Hardtek');
- $tribe = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Tribe');
- $tsouzoumi = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Tsouzoumi');
- $soug = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Soug');
- $metal = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Metal');
-
- $paul = $this->getUser();
- $bux = $this->getUser('bux');
- $joelle = $this->getUser('joelle');
-
- $points_pour_tags_add = $this->getContainer()->getParameter('reputation_element_tags_element_prop_value');
- $points_joelle = $joelle->getReputation();
- $points_bux = $bux->getReputation();
- $points_paul = $paul->getReputation();
-
- $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
- ->findOneByName('AZYD AZYLUM Live au Café Provisoire')
- ;
-
- // Pas de proposition en base pur cet élément
- $propositions = $this->getDoctrine()->getEntityManager()->getRepository('MuzichCoreBundle:ElementTagsProposition')
- ->findOneByElement($element->getId())
- ;
-
- $this->assertEquals(0, count($propositions));
-
- // Pas d'événement pour bux
- $events = $this->getDoctrine()->getEntityManager()
- ->createQuery('SELECT e FROM MuzichCoreBundle:Event e
- WHERE e.user = :uid AND e.type = :type'
- )
- ->setParameters(array(
- 'uid' => $bux->getId(),
- 'type' => \Muzich\CoreBundle\Entity\Event::TYPE_TAGS_PROPOSED
- ))
- ->getArrayResult()
- ;
- $this->assertEquals(count($events), 0);
-
- // On teste la récupération du formulaire au moin une fois
- $crawler = $this->client->request(
- 'GET',
- $this->generateUrl('ajax_element_propose_tags_open',
- array('element_id' => $element->getId())
- ),
- array(),
- array(),
- array('HTTP_X-Requested-With' => 'XMLHttpRequest')
- );
-
- $this->isResponseSuccess();
-
- $response = json_decode($this->client->getResponse()->getContent(), true);
- $this->assertEquals($response['status'], 'success');
- $this->assertEquals($response['form_name'], 'element_tag_proposition_'.$element->getId());
- $this->assertTrue(strpos($response['html'], 'class="tag_proposition"') !== false);
-
- // paul propose une serie de tags
- $crawler = $this->client->request(
- 'POST',
- $this->generateUrl('ajax_element_propose_tags_proceed',
- array('element_id' => $element->getId(), 'token' => $paul->getPersonalHash())
- ),
- array(
- 'element_tag_proposition_'.$element->getId() => array(
- 'tags' => json_encode(array($hardtek->getId(), $tribe->getId()))
- )
- ),
- array(),
- array('HTTP_X-Requested-With' => 'XMLHttpRequest')
- );
-
- $this->isResponseSuccess();
-
- $response = json_decode($this->client->getResponse()->getContent(), true);
- $this->assertEquals($response['status'], 'success');
-
- // On a maintenant la proposition en base
- $propositions = $this->getDoctrine()->getEntityManager()
- ->createQuery('SELECT p, t FROM MuzichCoreBundle:ElementTagsProposition p'
- .' JOIN p.tags t WHERE p.element = :eid AND p.user = :uid')
- ->setParameters(array(
- 'eid' => $element->getId(),
- 'uid' => $paul->getId()
- ))
- ->getResult()
- ;
-
- $this->assertEquals(1, count($propositions));
- $proposition_paul = $propositions[0];
-
- // Les tags sont aussi en base
- foreach ($propositions[0]->getTags() as $tag)
- {
- if (in_array($tag->getId(), array($hardtek->getId(), $tribe->getId())))
- {
- $this->assertTrue(true);
- }
- else
- {
- $this->assertTrue(false);
- }
- }
-
- // Il y a maintenant un event pour bux
- $events = $this->getDoctrine()->getEntityManager()
- ->createQuery('SELECT e FROM MuzichCoreBundle:Event e
- WHERE e.user = :uid AND e.type = :type'
- )
- ->setParameters(array(
- 'uid' => $bux->getId(),
- 'type' => \Muzich\CoreBundle\Entity\Event::TYPE_TAGS_PROPOSED
- ))
- ->getArrayResult()
- ;
- $this->assertEquals(count($events), 1);
- $this->assertEquals($events[0]['type'], \Muzich\CoreBundle\Entity\Event::TYPE_TAGS_PROPOSED);
- //
- $this->assertEquals($events[0]['count'], 1);
- $this->assertEquals($events[0]['ids'], json_encode(array((string)$element->getId())));
-
- // si il propose un liste vide de tags, c'est refusé bien entendu
- $crawler = $this->client->request(
- 'POST',
- $this->generateUrl('ajax_element_propose_tags_proceed',
- array('element_id' => $element->getId(), 'token' => $paul->getPersonalHash())
- ),
- array(
- 'element_tag_proposition_'.$element->getId() => array(
- 'tags' => json_encode(array())
- )
- ),
- array(),
- array('HTTP_X-Requested-With' => 'XMLHttpRequest')
- );
-
- $this->isResponseSuccess();
-
- $response = json_decode($this->client->getResponse()->getContent(), true);
- $this->assertEquals($response['status'], 'error');
-
- /*
- * joelle va aussi proposer des tags sur cet élément
- */
- $this->disconnectUser();
- $this->connectUser('joelle', 'toor');
-
- $joelle = $this->getUser();
-
- // joelle propose une serie de tags
- $crawler = $this->client->request(
- 'POST',
- $this->generateUrl('ajax_element_propose_tags_proceed',
- array('element_id' => $element->getId(), 'token' => $joelle->getPersonalHash())
- ),
- array(
- 'element_tag_proposition_'.$element->getId() => array(
- 'tags' => json_encode(array($tsouzoumi->getId(), $soug->getId(), $metal->getId()))
- )
- ),
- array(),
- array('HTTP_X-Requested-With' => 'XMLHttpRequest')
- );
-
- $this->isResponseSuccess();
-
- $response = json_decode($this->client->getResponse()->getContent(), true);
- $this->assertEquals($response['status'], 'success');
-
- // On a maintenant la proposition en base
- $propositions = $this->getDoctrine()->getEntityManager()
- ->createQuery('SELECT p, t FROM MuzichCoreBundle:ElementTagsProposition p'
- .' JOIN p.tags t WHERE p.element = :eid AND p.user = :uid')
- ->setParameters(array(
- 'eid' => $element->getId(),
- 'uid' => $joelle->getId()
- ))
- ->getResult()
- ;
-
- $this->assertEquals(1, count($propositions));
- $proposition_joelle = $propositions[0];
-
- // Les tags sont aussi en base
- foreach ($propositions[0]->getTags() as $tag)
- {
- if (in_array($tag->getId(), array($tsouzoumi->getId(), $soug->getId(), $metal->getId())))
- {
- $this->assertTrue(true);
- }
- else
- {
- $this->assertTrue(false);
- }
- }
-
- // avec la propsoition de joelle le nombre d'event n'a pas bougé (le compteur compte les éléments)
- $events = $this->getDoctrine()->getEntityManager()
- ->createQuery('SELECT e FROM MuzichCoreBundle:Event e
- WHERE e.user = :uid AND e.type = :type'
- )
- ->setParameters(array(
- 'uid' => $bux->getId(),
- 'type' => \Muzich\CoreBundle\Entity\Event::TYPE_TAGS_PROPOSED
- ))
- ->getArrayResult()
- ;
- $this->assertEquals(count($events), 1);
- $this->assertEquals($events[0]['type'], \Muzich\CoreBundle\Entity\Event::TYPE_TAGS_PROPOSED);
- //
- $this->assertEquals($events[0]['count'], 1);
- $this->assertEquals($events[0]['ids'], json_encode(array((string)$element->getId())));
-
- /*
- * C'est au tour de bux d'aller voir ces proposition
- */
-
- $this->disconnectUser();
- $this->connectUser('bux', 'toor');
-
- $bux = $this->getUser();
-
- // Il peut voir le lien vers l'ouverture des propositions
- $url = $this->generateUrl('ajax_element_proposed_tags_view', array('element_id' => $element->getId()));
- $this->exist('a[href="'.$url.'"]');
-
- // On récupére ces propositions
- $crawler = $this->client->request(
- 'GET',
- $url,
- array(),
- array(),
- array('HTTP_X-Requested-With' => 'XMLHttpRequest')
- );
-
- $this->isResponseSuccess();
-
- $response = json_decode($this->client->getResponse()->getContent(), true);
- $this->assertEquals($response['status'], 'success');
-
- $url_accept_paul = $this->generateUrl('ajax_element_proposed_tags_accept', array(
- 'proposition_id' => $proposition_paul->getId(),
- 'token' => $bux->getPersonalHash()
- ));
- $url_accept_joelle = $this->generateUrl('ajax_element_proposed_tags_accept', array(
- 'proposition_id' => $proposition_joelle->getId(),
- 'token' => $bux->getPersonalHash()
- ));
- $this->assertTrue(strpos($response['html'], 'href="'.$url_accept_paul.'"') !== false);
- $this->assertTrue(strpos($response['html'], 'href="'.$url_accept_joelle.'"') !== false);
- $url_refuse = $this->generateUrl('ajax_element_proposed_tags_refuse', array(
- 'element_id' => $element->getId(),
- 'token' => $bux->getPersonalHash()
- ));
-
- // On accepete la poposition de joelle
- $crawler = $this->client->request(
- 'GET',
- $url_refuse,
- array(),
- array(),
- array('HTTP_X-Requested-With' => 'XMLHttpRequest')
- );
-
- $this->isResponseSuccess();
-
- $response = json_decode($this->client->getResponse()->getContent(), true);
- $this->assertEquals($response['status'], 'success');
-
- $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
- ->findOneByName('AZYD AZYLUM Live au Café Provisoire')
- ;
- // Les tags de l'élément n'ont pas bougés
- $this->assertEquals(
- json_encode(array($metal->getId())),
- $element->getTagsIdsJson()
- );
-
- // La proposition de joelle a disparu
- $propositions = $this->getDoctrine()->getEntityManager()
- ->createQuery('SELECT p, t FROM MuzichCoreBundle:ElementTagsProposition p'
- .' JOIN p.tags t WHERE p.element = :eid AND p.user = :uid')
- ->setParameters(array(
- 'eid' => $element->getId(),
- 'uid' => $joelle->getId()
- ))
- ->getResult()
- ;
- $this->assertEquals(0, count($propositions));
-
- // celle de paul aussi
- $propositions = $this->getDoctrine()->getEntityManager()
- ->createQuery('SELECT p, t FROM MuzichCoreBundle:ElementTagsProposition p'
- .' JOIN p.tags t WHERE p.element = :eid AND p.user = :uid')
- ->setParameters(array(
- 'eid' => $element->getId(),
- 'uid' => $paul->getId()
- ))
- ->getResult()
- ;
- $this->assertEquals(0, count($propositions));
-
- // Et on as pas d'archive pour joelle
- $archives = $this->getDoctrine()->getEntityManager()
- ->createQuery('SELECT a FROM MuzichCoreBundle:EventArchive a'
- .' WHERE a.user = :uid AND a.type = :type')
- ->setParameters(array(
- 'uid' => $joelle->getId(),
- 'type' => \Muzich\CoreBundle\Entity\EventArchive::PROP_TAGS_ELEMENT_ACCEPTED
- ))
- ->getResult()
- ;
- $this->assertEquals(0, count($archives));
-
- // paul lui n'a pas d'archives non plus
- $archives = $this->getDoctrine()->getEntityManager()
- ->createQuery('SELECT a FROM MuzichCoreBundle:EventArchive a'
- .' WHERE a.user = :uid AND a.type = :type')
- ->setParameters(array(
- 'uid' => $paul->getId(),
- 'type' => \Muzich\CoreBundle\Entity\EventArchive::PROP_TAGS_ELEMENT_ACCEPTED
- ))
- ->getResult()
- ;
- $this->assertEquals(0, count($archives));
-
- // contrôle de l'évolution des points
- $bux = $this->getUser('bux');
- $joelle = $this->getUser('joelle');
- $paul = $this->getUser('paul');
-
- $this->assertEquals($points_bux, $bux->getReputation());
- $this->assertEquals($points_joelle, $joelle->getReputation());
- $this->assertEquals($points_paul, $paul->getReputation());
-
- }
-
- }
|