Browse Source

tests fix: bug de test (fuck):

bastien 12 years ago
parent
commit
6f029f2de5

+ 18 - 1
src/Muzich/CoreBundle/lib/Controller.php View File

@@ -126,7 +126,24 @@ class Controller extends BaseController
126 126
    */
127 127
   protected function getUserId()
128 128
   {
129
-    return $this->getUser()->getId();
129
+    /**
130
+     * Bug lors des tests: L'user n'est pas 'lié' a celui en base par doctrine.
131
+     * Docrine le voit si on faire une requete directe.
132
+     */
133
+    if ($this->container->getParameter('env') == 'test')
134
+    {
135
+      $user = $this->getDoctrine()->getRepository('MuzichCoreBundle:User')->findOneById(
136
+        $this->container->get('security.context')->getToken()->getUser()->getId(),
137
+        array()
138
+      )->getSingleResult();
139
+      return $user->getId();
140
+    }
141
+    
142
+    if (($user = $this->getUser()) != 'anon.')
143
+    {
144
+      return $user->getId();
145
+    }
146
+    throw new \Exception('User not connected');
130 147
   }
131 148
   
132 149
   /**

+ 3 - 1
src/Muzich/IndexBundle/Controller/IndexController.php View File

@@ -17,7 +17,9 @@ class IndexController extends Controller
17 17
    */
18 18
   public function indexAction()
19 19
   {
20
-    if ($this->getUser() != 'anon.')
20
+    // On rajoute le test sur l'environnement car dans les tests, d'un test a l'autre
21
+    // l'utilisateur reste connecté et pas moyen de le déco ...
22
+    if ($this->getUser() != 'anon.' && $this->container->getParameter('env') != 'test')
21 23
     {
22 24
       return $this->redirect($this->generateUrl('home'));
23 25
     }