GroupControllerTest.php 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <?php
  2. namespace Muzich\CoreBundle\Tests\Controller;
  3. use Muzich\CoreBundle\lib\FunctionalTest;
  4. class GroupControllerTest extends FunctionalTest
  5. {
  6. /**
  7. * Test de création d'un groupe
  8. */
  9. public function testGroupAdd()
  10. {
  11. $this->client = self::createClient();
  12. $this->connectUser('bob', 'toor');
  13. $Fans_de_psytrance = $this->getDoctrine()->getRepository('MuzichCoreBundle:Group')->findOneByName('Fans de psytrance');
  14. $hardtek_id = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Hardtek')->getId();
  15. $tribe_id = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Tribe')->getId();
  16. $this->crawler = $this->client->request('GET', $this->generateUrl('groups_own_list'));
  17. // Le groupe que nous voulons créer n'existe pas dans la base
  18. $group = $this->getDoctrine()->getRepository('MuzichCoreBundle:Group')
  19. ->findOneByName('HardtekMania')
  20. ;
  21. $this->assertTrue(is_null($group));
  22. // bob administre le groupe Fan de psutrance
  23. $this->exist('a[href="'.$this->generateUrl('show_group', array('slug' => $Fans_de_psytrance->getSlug())).'"]');
  24. // On a le formulaire de création sur la page
  25. $this->exist('form[action="'.($url = $this->generateUrl('group_add')).'"]');
  26. $this->exist('form[action="'.$url.'"] input[id="group_name"]');
  27. $this->exist('form[action="'.$url.'"] textarea[id="group_description"]');
  28. $this->exist('form[action="'.$url.'"] input[type="submit"]');
  29. $form = $this->selectForm('form[action="'.$url.'"] input[type="submit"]');
  30. $form['group[name]'] = 'HardtekMania';
  31. $form['group[description]'] = 'Des bass, des bpm, des gros caissons !';
  32. $form['group[tags]['.$hardtek_id.']'] = $hardtek_id;
  33. $form['group[tags]['.$tribe_id.']'] = $tribe_id;
  34. $this->submit($form);
  35. $this->isResponseRedirection();
  36. $this->followRedirection();
  37. $this->isResponseSuccess();
  38. // Le groupe que créé existe bien dans la base
  39. $group = $this->getDoctrine()->getRepository('MuzichCoreBundle:Group')
  40. ->findOneBy(array(
  41. 'name' => 'HardtekMania',
  42. 'description' => 'Des bass, des bpm, des gros caissons !'
  43. ))
  44. ;
  45. $this->assertTrue(!is_null($group));
  46. // On vérifie egallement le lien avec les tags
  47. if (!is_null($group))
  48. {
  49. $group_tags = $this->getDoctrine()->getRepository('MuzichCoreBundle:GroupsTagsFavorites')
  50. ->findBy(array(
  51. 'group' => $group->getId(),
  52. 'tag' => $hardtek_id
  53. ))
  54. ;
  55. $this->assertEquals(1, count($group_tags));
  56. $group_tags = $this->getDoctrine()->getRepository('MuzichCoreBundle:GroupsTagsFavorites')
  57. ->findBy(array(
  58. 'group' => $group->getId(),
  59. 'tag' => $tribe_id
  60. ))
  61. ;
  62. $this->assertEquals(1, count($group_tags));
  63. }
  64. }
  65. /**
  66. * Test de la mise a jour d'un groupe
  67. */
  68. public function testGroupUpdate()
  69. {
  70. $this->client = self::createClient();
  71. $this->connectUser('bob', 'toor');
  72. $Fans_de_psytrance = $this->getDoctrine()->getRepository('MuzichCoreBundle:Group')->findOneByName('Fans de psytrance');
  73. $psytrance_id = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Psytrance')->getId();
  74. $electro_id = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Electro')->getId();
  75. // Le groupe n'a pas encore les modifs que nous voulons effectuer
  76. $group = $this->getDoctrine()->getRepository('MuzichCoreBundle:Group')
  77. ->findOneBy(array(
  78. 'name' => 'Les Fans de Psytrance'
  79. ))
  80. ;
  81. $this->assertTrue(is_null($group));
  82. // On se rend sur la page de listing des groupes possédés
  83. $this->crawler = $this->client->request('GET', $this->generateUrl('groups_own_list'));
  84. // Il y a bien le lien vers son groupe
  85. $this->exist('a[href="'.($url = $this->generateUrl('show_group', array('slug' => $Fans_de_psytrance->getSlug()))).'"]');
  86. $link = $this->selectLink('a[href="'.$url.'"]');
  87. // On clique dessus
  88. $this->clickOnLink($link);
  89. $this->isResponseSuccess();
  90. // On est sur la page du groupe, bob doit voir le lien vers la page d'edition
  91. $this->exist('a[href="'.($url = $this->generateUrl('group_edit', array('slug' => $Fans_de_psytrance->getSlug()))).'"]');
  92. $link = $this->selectLink('a[href="'.$url.'"]');
  93. // On clique dessus
  94. $this->clickOnLink($link);
  95. $this->isResponseSuccess();
  96. // On vérifie al présence du forumaire
  97. $this->exist('form[action="'.($url = $this->generateUrl('group_update', array('slug' => $Fans_de_psytrance->getSlug()))).'"]');
  98. $this->exist('form[action="'.$url.'"] input[id="group_name"]');
  99. $this->exist('form[action="'.$url.'"] textarea[id="group_description"]');
  100. $this->exist('form[action="'.$url.'"] input[type="submit"]');
  101. // On valide ce formulaire
  102. $form = $this->selectForm('form[action="'.$url.'"] input[type="submit"]');
  103. $form['group[name]'] = 'Les Fans de Psytrance';
  104. $form['group[description]'] = 'Ca va swiguer !';
  105. $form['group[tags]['.$psytrance_id.']'] = $psytrance_id;
  106. // On rajoute le lien vers le tag electro
  107. $form['group[tags]['.$electro_id.']'] = $electro_id;
  108. $this->submit($form);
  109. $this->isResponseRedirection();
  110. $this->followRedirection();
  111. $this->isResponseSuccess();
  112. // Le groupe est bien modifié en base
  113. $group = $this->getDoctrine()->getRepository('MuzichCoreBundle:Group')
  114. ->findOneBy(array(
  115. 'name' => 'Les Fans de Psytrance',
  116. 'description' => 'Ca va swiguer !'
  117. ))
  118. ;
  119. $this->assertTrue(!is_null($group));
  120. // On vérifie egallement le lien avec les tags
  121. if (!is_null($group))
  122. {
  123. $group_tags = $this->getDoctrine()->getRepository('MuzichCoreBundle:GroupsTagsFavorites')
  124. ->findBy(array(
  125. 'group' => $group->getId(),
  126. 'tag' => $psytrance_id
  127. ))
  128. ;
  129. $this->assertEquals(1, count($group_tags));
  130. $group_tags = $this->getDoctrine()->getRepository('MuzichCoreBundle:GroupsTagsFavorites')
  131. ->findBy(array(
  132. 'group' => $group->getId(),
  133. 'tag' => $electro_id
  134. ))
  135. ;
  136. $this->assertEquals(1, count($group_tags));
  137. }
  138. // Et sur la page aussi
  139. $this->exist('h2:contains("Les Fans de Psytrance")');
  140. }
  141. }