123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260 |
- <?php
-
- namespace Muzich\CoreBundle\Tests\Controller;
-
- use Muzich\CoreBundle\lib\FunctionalTest;
-
- class MynetworkControllerTest extends FunctionalTest
- {
- /**
- * Test de l'affichage de la page "mon réseau"
- */
- public function testMyNetwork()
- {
- /**
- * Avec l'utilisateur 'bux' , qui d'après les fixtures suis: jean, paul,
- * les groupes DUDELDRUM et Fans de psytrance
- * et est suivis par joelle
- */
- $this->client = self::createClient();
- $this->connectUser('bux', 'toor');
- $link = $this->selectLink('a[href="'.$this->generateUrl('mynetwork_index').'"]');
- $this->clickOnLink($link);
- $this->isResponseSuccess();
-
- // Récupération des entités
- $jean = $this->getDoctrine()->getRepository('MuzichCoreBundle:User')->findOneByUsername('jean');
- $paul = $this->getDoctrine()->getRepository('MuzichCoreBundle:User')->findOneByUsername('paul');
- $joelle = $this->getDoctrine()->getRepository('MuzichCoreBundle:User')->findOneByUsername('joelle');
- $DUDELDRUM = $this->getDoctrine()->getRepository('MuzichCoreBundle:Group')->findOneByName('DUDELDRUM');
- $Fans_de_psytrance = $this->getDoctrine()->getRepository('MuzichCoreBundle:Group')->findOneByName('Fans de psytrance');
-
- $this->exist('ul#followeds_users li a[href="'.$this->generateUrl('show_user', array('slug' => $jean->getSlug())).'"]');
- $this->exist('ul#followeds_users li a[href="'.$this->generateUrl('show_user', array('slug' => $paul->getSlug())).'"]');
- $this->exist('ul#followers_users li a[href="'.$this->generateUrl('show_user', array('slug' => $joelle->getSlug())).'"]');
- $this->exist('ul#followeds_groups li a[href="'.$this->generateUrl('show_group', array('slug' => $DUDELDRUM->getSlug())).'"]');
- $this->exist('ul#followeds_groups li a[href="'.$this->generateUrl('show_group', array('slug' => $Fans_de_psytrance->getSlug())).'"]');
- }
-
- /**
- * Test de la recherche
- */
- public function testSearch()
- {
- $this->client = self::createClient();
- $this->connectUser('bux', 'toor');
-
- $this->exist('form[action="'.($url = $this->generateUrl('global_search')).'"]');
- $this->exist('form[action="'.$url.'"] input[id="form_string"]');
- $this->exist('form[action="'.$url.'"] input[type="submit"]');
-
- $bob = $this->getDoctrine()->getRepository('MuzichCoreBundle:User')->findOneByUsername('bob');
- // On va rechercher l'utilisateur bob
- $form = $this->selectForm('form[action="'.$url.'"] input[type="submit"]');
- $form['form[string]'] = 'bob';
- $this->submit($form);
-
- $this->isResponseSuccess();
-
- // On trouve bob
- $this->exist('ul#search_users li a[href="'.$this->generateUrl('show_user', array('slug' => $bob->getSlug())).'"]');
-
- $joelle = $this->getDoctrine()->getRepository('MuzichCoreBundle:User')->findOneByUsername('joelle');
- $Le_groupe_de_joelle = $this->getDoctrine()->getRepository('MuzichCoreBundle:Group')->findOneByName('Le groupe de joelle');
- // On va maintenant rechercher le groupe de joelle
- $form = $this->selectForm('form[action="'.$url.'"] input[type="submit"]');
- $form['form[string]'] = 'joelle';
- $this->submit($form);
- $this->isResponseSuccess();
-
- // On trouve joelle mais aussi son groupe (il y a joelle dans le nom)
- $this->exist('ul#search_users li a[href="'.$this->generateUrl('show_user', array('slug' => $joelle->getSlug())).'"]');
- $this->exist('ul#search_groups li a[href="'.$this->generateUrl('show_group', array('slug' => $Le_groupe_de_joelle->getSlug())).'"]');
-
- // On cherche des éléments
- $form = $this->selectForm('form[action="'.$url.'"] input[type="submit"]');
- $form['form[string]'] = 'har';
- $this->submit($form);
- $this->isResponseSuccess();
-
- $this->exist('span.element_name:contains("Ed Cox - La fanfare des teuffeurs (Hardcordian)")');
- $this->exist('span.element_name:contains("Acrotek Hardtek G01")');
-
- // On cherche des éléments en jouant avec le principe de découpe (' ', ',' '-' ...)
- $form = $this->selectForm('form[action="'.$url.'"] input[type="submit"]');
- $form['form[string]'] = 'azyd babylon cox';
- $this->submit($form);
- $this->isResponseSuccess();
-
- $this->exist('span.element_name:contains("Ed Cox - La fanfare des teuffeurs (Hardcordian)")');
- $this->exist('span.element_name:contains("Babylon Pression - Des Tasers et des Pauvres")');
- $this->exist('span.element_name:contains("AZYD AZYLUM Live au Café Provisoire")');
- }
-
- /**
- * Test de l'action 'suivre' et 'ne plus suivre' sur un user
- */
- public function testUserFollow()
- {
- $this->client = self::createClient();
- // Connection de bob
- $this->connectUser('bob', 'toor');
-
- // Récupération des entités (bob ne les suit pas)
- $bux = $this->getDoctrine()->getRepository('MuzichCoreBundle:User')->findOneByUsername('bux');
-
- // On tente de récupérer l'entité FollowUser
- $FollowUser = $this->getDoctrine()->getRepository('MuzichCoreBundle:FollowUser')
- ->findOneBy(array(
- 'follower' => $this->getUser()->getId(),
- 'followed' => $bux->getId()
- ))
- ;
-
- // Mais celle-ci doit-être innexistante
- $this->assertTrue(is_null($FollowUser));
-
- // Ouverture de la page d'un user (bux)
- $this->crawler = $this->client->request('GET', $this->generateUrl('show_user', array('slug' => $bux->getSlug())));
- $this->isResponseSuccess();
-
- // Controle de l'évolution du score de bux
- $bux = $this->getUser('bux');
- $this->assertEquals($bux->getReputation(), 22);
-
- $url_follow = $this->generateUrl('follow', array(
- 'type' => 'user',
- 'id' => $bux->getId(),
- 'token' => $this->getUser()->getPersonalHash()
- ));
-
- // On lance l'action de suivre
- $this->exist('a.notfollowing[href="'.$url_follow.'"]');
- $link = $this->selectLink('a[href="'.$url_follow.'"]');
- $this->clickOnLink($link);
-
- $this->isResponseRedirection();
- $this->followRedirection();
- $this->isResponseSuccess();
-
- $this->exist('a.following[href="'.$url_follow.'"]');
-
- // On tente de récupérer l'entité FollowUser
- $FollowUser = $this->getDoctrine()->getRepository('MuzichCoreBundle:FollowUser')
- ->findOneBy(array(
- 'follower' => $this->getUser()->getId(),
- 'followed' => $bux->getId()
- ))
- ;
-
- // Celle-ci doit exister maintenant
- $this->assertTrue(!is_null($FollowUser));
-
- // Controle de l'évolution du score de bux
- $bux = $this->getUser('bux');
- $this->assertEquals($bux->getReputation(), 32);
-
- // On lance l'action de ne plus suivre
- $link = $this->selectLink('a[href="'.$url_follow.'"]');
- $this->clickOnLink($link);
-
- $this->isResponseRedirection();
- $this->followRedirection();
- $this->isResponseSuccess();
-
- $this->exist('a.notfollowing[href="'.$url_follow.'"]');
-
- // On tente de récupérer l'entité FollowUser
- $FollowUser = $this->getDoctrine()->getRepository('MuzichCoreBundle:FollowUser')
- ->findOneBy(array(
- 'follower' => $this->getUser()->getId(),
- 'followed' => $bux->getId()
- ))
- ;
-
- // Celle-ci ne doit plus exister maintenant
- $this->assertTrue(is_null($FollowUser));
-
- // Controle de l'évolution du score de bux
- $bux = $this->getUser('bux');
- $this->assertEquals($bux->getReputation(), 22);
- }
-
- /**
- * Test de l'action 'suivre' et 'ne plus suivre' sur un groupe
- */
- public function testGroupFollow()
- {
- $this->client = self::createClient();
- // Connection de bob
- $this->connectUser('bob', 'toor');
-
- // Récupération des entités (bob ne les suit pas)
- $DUDELDRUM = $this->getDoctrine()->getRepository('MuzichCoreBundle:Group')->findOneByName('DUDELDRUM');
-
- // On tente de récupérer l'entité FollowUser
- $FollowGroup = $this->getDoctrine()->getRepository('MuzichCoreBundle:FollowGroup')
- ->findOneBy(array(
- 'follower' => $this->getUser()->getId(),
- 'group' => $DUDELDRUM->getId()
- ))
- ;
-
- // Mais celle-ci doit-être innexistante
- $this->assertTrue(is_null($FollowGroup));
-
- // Ouverture de la page d'un user (bux)
- $this->crawler = $this->client->request('GET', $this->generateUrl('show_group', array('slug' => $DUDELDRUM->getSlug())));
- $this->isResponseSuccess();
-
- $url_follow = $this->generateUrl('follow', array(
- 'type' => 'group',
- 'id' => $DUDELDRUM->getId(),
- 'token' => $this->getUser()->getPersonalHash()
- ));
-
- // On lance l'action de suivre
- $this->exist('a.notfollowing[href="'.$url_follow.'"]');
- $link = $this->selectLink('a[href="'.$url_follow.'"]');
- $this->clickOnLink($link);
-
- $this->isResponseRedirection();
- $this->followRedirection();
- $this->isResponseSuccess();
-
- $this->exist('a.following[href="'.$url_follow.'"]');
-
- // On tente de récupérer l'entité FollowUser
- $FollowGroup = $this->getDoctrine()->getRepository('MuzichCoreBundle:FollowGroup')
- ->findOneBy(array(
- 'follower' => $this->getUser()->getId(),
- 'group' => $DUDELDRUM->getId()
- ))
- ;
-
- // Celle-ci doit exister maintenant
- $this->assertTrue(!is_null($FollowGroup));
-
- // On lance l'action de ne plus suivre
- $link = $this->selectLink('a[href="'.$url_follow.'"]');
- $this->clickOnLink($link);
-
- $this->isResponseRedirection();
- $this->followRedirection();
- $this->isResponseSuccess();
-
- $this->exist('a.notfollowing[href="'.$url_follow.'"]');
-
- // On tente de récupérer l'entité FollowUser
- $FollowGroup = $this->getDoctrine()->getRepository('MuzichCoreBundle:FollowGroup')
- ->findOneBy(array(
- 'follower' => $this->getUser()->getId(),
- 'group' => $DUDELDRUM->getId()
- ))
- ;
-
- // Celle-ci ne doit plus exister maintenant
- $this->assertTrue(is_null($FollowGroup));
- }
- }
|