Browse Source

Mise a jour des tests (Evolution #59);

bastien 12 years ago
parent
commit
4067f42f2c

+ 2 - 5
src/Muzich/CoreBundle/Tests/Controller/GroupControllerTest.php View File

@@ -39,8 +39,7 @@ class GroupControllerTest extends FunctionalTest
39 39
     $form = $this->selectForm('form[action="'.$url.'"] input[type="submit"]');
40 40
     $form['group[name]'] = 'HardtekMania';
41 41
     $form['group[description]'] = 'Des bass, des bpm, des gros caissons !';
42
-    $form['group[tags]['.$hardtek_id.']'] = $hardtek_id;
43
-    $form['group[tags]['.$tribe_id.']'] = $tribe_id;
42
+    $form['group[tags]'] = json_encode(array($hardtek_id,$tribe_id));
44 43
     $this->submit($form);
45 44
     
46 45
     $this->isResponseRedirection();
@@ -129,9 +128,7 @@ class GroupControllerTest extends FunctionalTest
129 128
     $form = $this->selectForm('form[action="'.$url.'"] input[type="submit"]');
130 129
     $form['group[name]'] = 'Les Fans de Psytrance';
131 130
     $form['group[description]'] = 'Ca va swiguer !';
132
-    $form['group[tags]['.$psytrance_id.']'] = $psytrance_id;
133
-    // On rajoute le lien vers le tag electro
134
-    $form['group[tags]['.$electro_id.']'] = $electro_id;
131
+    $form['group[tags]'] = json_encode(array($psytrance_id,$electro_id));
135 132
     $this->submit($form);
136 133
     
137 134
     $this->isResponseRedirection();

+ 4 - 10
src/Muzich/CoreBundle/Tests/Controller/HomeControllerTest.php View File

@@ -32,17 +32,10 @@ class HomeControllerTest extends FunctionalTest
32 32
     
33 33
     // On récupére le formulaire de filtrage
34 34
     $form = $this->selectForm('form[action="'.$url.'"] input[type="submit"]');
35
-    
36
-    // On décoche les tags
37
-    foreach ($this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findAll() as $tag)
38
-    {
39
-      $form['element_search_form[tags]['.$tag->getId().']']->untick();
40
-    }
41
-    
35
+        
42 36
     // On met ce que l'on veut dans le form
43 37
     $form['element_search_form[network]'] = ElementSearcher::NETWORK_PUBLIC;
44
-    $form['element_search_form[tags]['.$hardtek_id.']'] = $hardtek_id;
45
-    $form['element_search_form[tags]['.$tribe_id.']'] = $tribe_id;
38
+    $form['element_search_form[tags]'] = json_encode(array($hardtek_id, $tribe_id));
46 39
     $this->submit($form);
47 40
     
48 41
     $this->client->submit($form);
@@ -55,7 +48,8 @@ class HomeControllerTest extends FunctionalTest
55 48
     $this->assertEquals(array(
56 49
         'network'   => ElementSearcher::NETWORK_PUBLIC,
57 50
         'tags'      => array(
58
-          $hardtek_id, $tribe_id
51
+          $hardtek_id => 'Hardtek', 
52
+          $tribe_id   => 'Tribe'
59 53
         ),
60 54
         'count'     => $this->getContainer()->getParameter('search_default_count'),
61 55
         'user_id'   => null,

+ 2 - 4
src/Muzich/CoreBundle/Tests/Controller/UserControllerTest.php View File

@@ -40,8 +40,7 @@ class UserControllerTest extends FunctionalTest
40 40
     $this->exist('form[action="'.($url = $this->generateUrl('update_tag_favorites')).'"]');
41 41
     
42 42
     $form = $this->selectForm('form[action="'.$url.'"] input[type="submit"]');
43
-    $form['tag_favorites_form[tags]['.$hardtek_id.']'] = $hardtek_id;
44
-    $form['tag_favorites_form[tags]['.$tribe_id.']'] = $tribe_id;
43
+    $form['tag_favorites_form[tags]'] = json_encode(array($hardtek_id,$tribe_id));
45 44
     $this->submit($form);
46 45
     
47 46
     $this->isResponseRedirection();
@@ -136,8 +135,7 @@ class UserControllerTest extends FunctionalTest
136 135
     $this->exist('form[action="'.$url.'"] input[type="submit"]');
137 136
     
138 137
     $form = $this->selectForm('form[action="'.$url.'"] input[type="submit"]');
139
-    $form['tag_favorites_form[tags]['.$hardtek_id.']'] = $hardtek_id;
140
-    $form['tag_favorites_form[tags]['.$tribe_id.']'] = $tribe_id;
138
+    $form['tag_favorites_form[tags]'] = json_encode(array($hardtek_id,$tribe_id));
141 139
     $this->submit($form);
142 140
     
143 141
     $this->isResponseRedirection();

+ 1 - 4
src/Muzich/CoreBundle/lib/FunctionalTest.php View File

@@ -188,10 +188,7 @@ class FunctionalTest extends WebTestCase
188 188
     $form = $this->selectForm('form[action="'.$form_url.'"] input[type="submit"]');
189 189
     $form['element_add[name]'] = $name;
190 190
     $form['element_add[url]'] = $url;
191
-    foreach ($tags as $tag_id)
192
-    {
193
-      $form['element_add[tags]['.$tag_id.']'] = $tag_id;
194
-    }
191
+    $form['element_add[tags]'] = json_encode($tags);
195 192
     
196 193
     $this->submit($form);
197 194
   }

+ 1 - 1
src/Muzich/GroupBundle/Controller/DefaultController.php View File

@@ -161,7 +161,7 @@ class DefaultController extends Controller
161 161
     if ($form->isValid())
162 162
     {
163 163
       $factory = new GroupManager($group, $em, $this->container);
164
-      $factory->proceedTags($group->getTags());
164
+      $factory->proceedTags(json_decode($group->getTags()));
165 165
       
166 166
       $em->persist($group);
167 167
       $em->flush();

+ 15 - 1
src/Muzich/UserBundle/Controller/UserController.php View File

@@ -48,8 +48,22 @@ class UserController extends Controller
48 48
   {
49 49
     if ($this->tags_favorites === null || $force)
50 50
     {
51
+      $user = $this->getUser();
52
+      
53
+      /**
54
+       * Bug lors des tests: L'user n'est pas 'lié' a celui en base par doctrine.
55
+       * Docrine le voit si on faire une requete directe.
56
+       */
57
+      if ($this->container->getParameter('env') == 'test')
58
+      {
59
+        $user = $this->getDoctrine()->getRepository('MuzichCoreBundle:User')->findOneById(
60
+          $this->container->get('security.context')->getToken()->getUser()->getId(),
61
+          array()
62
+        )->getSingleResult();
63
+      }
64
+      
51 65
       $this->tags_favorites = $this->getDoctrine()->getRepository('MuzichCoreBundle:User')
52
-        ->getTagsFavorites($this->getUser()->getId())
66
+        ->getTagsFavorites($user->getId())
53 67
       ;
54 68
     }
55 69