Browse Source

Merge branch 'feature/forms' into unstable

bastien 13 years ago
parent
commit
0388d5a0f9

+ 17 - 11
src/Muzich/CoreBundle/Controller/CoreController.php View File

@@ -122,6 +122,20 @@ class CoreController extends Controller
122 122
     $user = $this->getUser();
123 123
     $em = $this->getDoctrine()->getEntityManager();
124 124
     
125
+    /*
126
+     * Contrôle préléminaire si groupe précisé
127
+     */
128
+    $group = null;
129
+    if ($group_slug)
130
+    {
131
+      $group = $this->findGroupWithSlug($group_slug);
132
+      if (!$group->userCanAddElement($this->getUserId()))
133
+      {
134
+        $group = null;
135
+        throw  $this->createNotFoundException('Vous ne pouvez pas ajouter d\'éléments a ce groupe');
136
+      }
137
+    }
138
+    
125 139
     $element = new Element();
126 140
     $form = $this->createForm(
127 141
       new ElementAddForm(),
@@ -156,18 +170,10 @@ class CoreController extends Controller
156 170
         $factory->proceedFill($user);
157 171
         
158 172
         // Si on a précisé un groupe dans lequel mettre l'element
159
-        if ($group_slug)
173
+        if ($group)
160 174
         {
161
-          $group = $this->findGroupWithSlug($group_slug);
162
-          if ($group->userCanAddElement($this->getUserId()))
163
-          {
164
-            $element->setGroup($group);
165
-          }
166
-          else
167
-          {
168
-            throw $this->createNotFoundException('Vous ne pouvez ajouter d\'element a ce groupe.');
169
-          }
170
-          $redirect_url = $this->generateUrl('show_group', array('slug' => $group->getSlug()));
175
+          $element->setGroup($group);
176
+          $redirect_url = $this->generateUrl('show_group', array('slug' => $group_slug));
171 177
         }
172 178
         else
173 179
         {

+ 19 - 8
src/Muzich/CoreBundle/ElementFactory/Site/base/VideoSiteFactory.php View File

@@ -21,14 +21,25 @@ class VideoSiteFactory extends BaseFactory
21 21
   {
22 22
     parent::__construct($element, $container);
23 23
     
24
-    // Configuration de VideoEmbed
25
-    define('SITEBASE', $container->getParameter('sitebase'));
26
-    define('VIDEO_EMBED_CONFIG_FILE', SITEBASE.$container->getParameter('video_embed_config_file'));
27
-    //to activate debug mode and false for production usage. it will write 
28
-    //to a log file when something goes wrong but should not produce 
29
-    //exceptions in production enviroment
30
-    define('DEBUG', $container->getParameter('video_embed_debug')); 
31
-    
24
+    //if ($container->getParameter('env') != 'test')
25
+    //{
26
+      // Configuration de VideoEmbed
27
+      if (!defined('SITEBASE')) 
28
+      {
29
+        define('SITEBASE', $container->getParameter('sitebase'));
30
+      }
31
+    //}
32
+      if (!defined('VIDEO_EMBED_CONFIG_FILE')) 
33
+      {
34
+      define('VIDEO_EMBED_CONFIG_FILE', SITEBASE.$container->getParameter('video_embed_config_file'));
35
+      }
36
+      //to activate debug mode and false for production usage. it will write 
37
+      //to a log file when something goes wrong but should not produce 
38
+      //exceptions in production enviroment
39
+      if (!defined('DEBUG')) 
40
+      {
41
+        define('DEBUG', $container->getParameter('video_embed_debug')); 
42
+      }
32 43
     try {
33 44
       $this->video_engine =  new VideoEmbed($this->element->getUrl());
34 45
     } catch (Exception $exc) {

+ 83 - 20
src/Muzich/CoreBundle/Tests/Controller/HomeControllerTest.php View File

@@ -141,9 +141,6 @@ class HomeControllerTest extends FunctionalTest
141 141
     $hardtek = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Hardtek');
142 142
     $tribe = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Tribe');
143 143
     
144
-    // Un groupe open
145
-    $fan_de_psy = $this->getDoctrine()->getRepository('MuzichCoreBundle:Group')->findOneByName('Fans de psytrance');
146
-    
147 144
     /*
148 145
      *  Ajout d'un élément avec succés
149 146
      */
@@ -175,9 +172,6 @@ class HomeControllerTest extends FunctionalTest
175 172
     $hardtek = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Hardtek');
176 173
     $tribe = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Tribe');
177 174
     
178
-    // Un groupe no open
179
-    $dudeldrum = $this->getDoctrine()->getRepository('MuzichCoreBundle:Group')->findOneByName('DUDELDRUM');
180
-    
181 175
     /*
182 176
      *  Ajouts d'éléments avec echec
183 177
      */
@@ -190,10 +184,10 @@ class HomeControllerTest extends FunctionalTest
190 184
     );
191 185
     
192 186
     $this->isResponseSuccess();
193
-    
194
-    $this->notExist('li:contains("Mon bel element")');
187
+        
188
+    $this->notExist('li:contains("Mon bel element a4er563a1r")');
195 189
     $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
196
-      ->findOneByName('Mon bel element')
190
+      ->findOneByName('Mon bel element a4er563a1r')
197 191
     ;
198 192
     $this->assertTrue(is_null($element));
199 193
     
@@ -221,9 +215,9 @@ class HomeControllerTest extends FunctionalTest
221 215
     
222 216
     $this->isResponseSuccess();
223 217
     
224
-    $this->notExist('li:contains("Mon bel element")');
218
+    $this->notExist('li:contains("Mon bel element gfez7f")');
225 219
     $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
226
-      ->findOneByName('Mon bel element')
220
+      ->findOneByName('Mon bel element gfez7f')
227 221
     ;
228 222
     $this->assertTrue(is_null($element));
229 223
     
@@ -243,41 +237,110 @@ class HomeControllerTest extends FunctionalTest
243 237
     
244 238
   }
245 239
   
246
-  public function testAddElementAtGroupFailure()
240
+  /**
241
+   * L'ajout d'un Element a un de ses groupe ne doit pas poser de problème
242
+   */
243
+  public function testAddElementAtMyGroupSuccess()
247 244
   {
248 245
     $this->connectUser('bux', 'toor');
246
+    // Un groupe open, donc pas de soucis
247
+    $fan_de_psy = $this->getDoctrine()->getRepository('MuzichCoreBundle:Group')->findOneByName('Fans de psytrance');
248
+    
249
+    $hardtek = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Hardtek');
250
+    $tribe = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Tribe');
251
+        
252
+    $this->isResponseSuccess();
253
+    $this->procedure_add_element(
254
+      'Element mis dans le groupe de psytrance', 
255
+      'http://www.youtube.com/watch?v=WC8qb_of04E', 
256
+      array($hardtek->getId(), $tribe->getId()),
257
+      $fan_de_psy->getSlug()
258
+    );
259
+    
260
+    $this->isResponseRedirection();
261
+    $this->followRedirection();
262
+    $this->isResponseSuccess();
263
+    
264
+    $this->exist('li:contains("Element mis dans le groupe de psytrance")');
265
+    $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
266
+      ->findOneByName('Element mis dans le groupe de psytrance')
267
+    ;
268
+    $this->assertTrue(!is_null($element));
269
+    
270
+    if (!is_null($element))
271
+    {
272
+      $this->assertEquals($fan_de_psy->getId(), $element->getGroup()->getId());
273
+    }
274
+    else
275
+    {
276
+      $this->assertTrue(false);
277
+    }
278
+    
279
+    $this->disconnectUser();
249 280
     
250 281
     /*
251
-     * Ajout d'un élément lié a un groupe (success)
282
+     * Ajout d'un element dans un groupe que l'on posséde.
252 283
      */
284
+    $this->connectUser('joelle', 'toor');
285
+    $this->isResponseSuccess();
286
+    
287
+    // Ce groupe appartient a joelle
288
+    $groupe_de_joelle = $this->getDoctrine()->getRepository('MuzichCoreBundle:Group')->findOneByName('Le groupe de joelle');
289
+    
253 290
     $this->procedure_add_element(
254
-      'Mon bel element', 
291
+      'Element mis dans le groupe de joelle', 
255 292
       'http://www.youtube.com/watch?v=WC8qb_of04E', 
256 293
       array($hardtek->getId(), $tribe->getId()),
257
-      $fan_de_psy->getId()
294
+      $groupe_de_joelle->getSlug()
258 295
     );
259 296
     
260 297
     $this->isResponseRedirection();
261 298
     $this->followRedirection();
262 299
     $this->isResponseSuccess();
263 300
     
264
-    $this->exist('li:contains("Mon bel element")');
301
+    $this->exist('li:contains("Element mis dans le groupe de joelle")');
265 302
     $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
266
-      ->findOneByName('Mon bel element')
303
+      ->findOneByName('Element mis dans le groupe de joelle')
267 304
     ;
268 305
     $this->assertTrue(!is_null($element));
306
+    
269 307
     if (!is_null($element))
270 308
     {
271
-      $this->assertEquals($fan_de_psy->getId(), $element->getGroup()->getId());
309
+      $this->assertEquals($groupe_de_joelle->getId(), $element->getGroup()->getId());
310
+    }
311
+    else
312
+    {
313
+      $this->assertTrue(false);
272 314
     }
273 315
   }
274 316
   
275 317
   /**
276
-   * L'ajout d'un Element a un de ses groupe ne doit pas poser de problème
318
+   * L'ajout a un group qui n'est pas a sois, ou qui n'est pas open
319
+   * doit être impossible.
277 320
    */
278
-  public function testAddElementAtMyGroupSuccess()
321
+  public function testAddElementAtGroupFailure()
279 322
   {
323
+    $this->connectUser('bux', 'toor');
324
+    // Un groupe no open
325
+    $dudeldrum = $this->getDoctrine()->getRepository('MuzichCoreBundle:Group')->findOneByName('DUDELDRUM');
326
+    
327
+    $hardtek = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Hardtek');
328
+    $tribe = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Tribe');
329
+        
330
+    // Nous tentons d'ouvrir l'url d'ajout d'élément avec un groupe qui n'est pas ouvert
331
+    // et qui n'appartient pas a l'utilisateur connecté
332
+    $this->crawler = $this->client->request(
333
+      'POST', 
334
+      $this->generateUrl('element_add', array('group_slug' => $dudeldrum->getSlug())),
335
+      array(
336
+        'element_add[name]' => 'Yohoho trululu',
337
+        'element_add[url]'  => 'http://www.youtube.com/watch?v=WC8qb_of04E',
338
+        'element_add[tags]['.$hardtek->getId().']' => $hardtek->getId(),
339
+        'element_add[tags]['.$tribe->getId().']' => $tribe->getId()
340
+      )
341
+    );
280 342
     
343
+    $this->isResponseNotFound();
281 344
   }
282 345
   
283 346
 }

+ 35 - 7
src/Muzich/CoreBundle/lib/FunctionalTest.php View File

@@ -67,6 +67,11 @@ class FunctionalTest extends WebTestCase
67 67
     $this->assertEquals($login, $user->getUsername());
68 68
   }
69 69
   
70
+  protected function disconnectUser()
71
+  {
72
+    $this->crawler = $this->client->request('GET', $this->generateUrl('fos_user_security_logout'));
73
+  }
74
+  
70 75
   protected function validate_registrate_user_form($form, $username, $email, $pass1, $pass2)
71 76
   {
72 77
     $form['fos_user_registration_form[username]'] = $username;
@@ -114,26 +119,35 @@ class FunctionalTest extends WebTestCase
114 119
   }
115 120
   
116 121
   /**
117
-   * Procédure d'ajout d'un élément a partir de la page home
122
+   * Procédure d'ajout d'un élément
118 123
    * 
119 124
    * @param string $name
120 125
    * @param string $url
121 126
    * @param array $tags
122 127
    * @param int $group_id 
123 128
    */
124
-  protected function procedure_add_element($name, $url, $tags, $group_id = '')
129
+  protected function procedure_add_element($name, $url, $tags, $group_slug = null)
125 130
   {
126
-    $this->crawler = $this->client->request('GET', $this->generateUrl('home'));
131
+    if (!$group_slug)
132
+    {
133
+      $this->crawler = $this->client->request('GET', $this->generateUrl('home'));
134
+      $form_url = $this->generateUrl('element_add');
135
+    }
136
+    else
137
+    {
138
+      $this->crawler = $this->client->request('GET', $this->generateUrl('show_group', array('slug' => $group_slug)));
139
+      $form_url = $this->generateUrl('element_add', array('group_slug' => $group_slug));
140
+    }
127 141
     $this->isResponseSuccess();
128 142
     
129
-    $form = $this->selectForm('form[action="'.$this->generateUrl('element_add').'"] input[type="submit"]');
143
+    $form = $this->selectForm('form[action="'.$form_url.'"] input[type="submit"]');
130 144
     $form['element_add[name]'] = $name;
131 145
     $form['element_add[url]'] = $url;
132 146
     foreach ($tags as $tag_id)
133 147
     {
134 148
       $form['element_add[tags]['.$tag_id.']'] = $tag_id;
135 149
     }
136
-    $form['element_add[group]'] = $group_id;
150
+    
137 151
     $this->submit($form);
138 152
   }
139 153
   
@@ -161,6 +175,12 @@ class FunctionalTest extends WebTestCase
161 175
     return $this->getContainer()->get('session');
162 176
   }
163 177
   
178
+  protected function clickOnLink($link)
179
+  {
180
+    $this->crawler = $this->client->click($link);
181
+  }
182
+
183
+
164 184
   /**
165 185
    *
166 186
    * @return \Symfony\Bundle\DoctrineBundle\Registry
@@ -256,7 +276,7 @@ class FunctionalTest extends WebTestCase
256 276
    */
257 277
   protected function isResponseRedirection()
258 278
   {
259
-    $this->client->getResponse()->isRedirection();
279
+    $this->assertTrue($this->client->getResponse()->isRedirection());
260 280
   }
261 281
   
262 282
   /**
@@ -264,6 +284,14 @@ class FunctionalTest extends WebTestCase
264 284
    */
265 285
   protected function isResponseSuccess()
266 286
   {
267
-    $this->client->getResponse()->isSuccessful();
287
+    $this->assertTrue($this->client->getResponse()->isSuccessful());
288
+  }
289
+  
290
+  /**
291
+   * Contrôle que le CodeStatus de la Response correspond bien a celle d'un Ok
292
+   */
293
+  protected function isResponseNotFound()
294
+  {
295
+    $this->assertTrue($this->client->getResponse()->isNotFound());
268 296
   }
269 297
 }