Parcourir la source

Ajout du test sur la selection de tags favoris

bastien il y a 13 ans
Parent
révision
c6f6ffd685

+ 28 - 21
src/Muzich/CoreBundle/Tests/Controller/IndexControllerTest.php Voir le fichier

@@ -85,31 +85,38 @@ class IndexControllerTest extends FunctionalTest
85 85
     $this->exist('form[action="'.$url.'"] input[id="fos_user_registration_form_plainPassword_second"]');
86 86
     $this->exist('form[action="'.$url.'"] input[type="submit"]');
87 87
     
88
-    $this->validate_registrate_user_form(
89
-      $this->selectForm('form[action="'.$url.'"] input[type="submit"]'), 
88
+    $this->procedure_registration_success(
90 89
       'raoula', 
91
-      'raoul.45gf64z@gmail.com', 
92
-      'toor',
90
+      'raoula.def4v65sds@gmail.com', 
91
+      'toor', 
93 92
       'toor'
94 93
     );
95 94
     
96
-    $this->isResponseRedirection();
97
-    $this->followRedirection();
98
-    $this->isResponseSuccess();
99
-
100
-    $user = $this->getUser();
101
-    $this->assertEquals('raoula', $user->getUsername());
102
-    
103
-    // L'utilisateur est enregistré, il doit donc être en base
104
-    $db_user = $this->getDoctrine()->getRepository('MuzichCoreBundle:User')
105
-      ->findOneByUsername('raoula')
106
-    ;
107
-    
108
-    $this->assertTrue(!is_null($db_user));
109
-    if ($db_user)
110
-    {
111
-      $this->assertEquals('raoula', $db_user->getUsername());
112
-    }
95
+//    $this->validate_registrate_user_form(
96
+//      $this->selectForm('form[action="'.$url.'"] input[type="submit"]'), 
97
+//      'raoula', 
98
+//      'raoul.45gf64z@gmail.com', 
99
+//      'toor',
100
+//      'toor'
101
+//    );
102
+//    
103
+//    $this->isResponseRedirection();
104
+//    $this->followRedirection();
105
+//    $this->isResponseSuccess();
106
+//
107
+//    $user = $this->getUser();
108
+//    $this->assertEquals('raoula', $user->getUsername());
109
+//    
110
+//    // L'utilisateur est enregistré, il doit donc être en base
111
+//    $db_user = $this->getDoctrine()->getRepository('MuzichCoreBundle:User')
112
+//      ->findOneByUsername('raoula')
113
+//    ;
114
+//    
115
+//    $this->assertTrue(!is_null($db_user));
116
+//    if ($db_user)
117
+//    {
118
+//      $this->assertEquals('raoula', $db_user->getUsername());
119
+//    }
113 120
   }
114 121
   
115 122
   public function testRegistrationFailure()

+ 75 - 0
src/Muzich/CoreBundle/Tests/Controller/UserControllerTest.php Voir le fichier

@@ -0,0 +1,75 @@
1
+<?php
2
+
3
+namespace Muzich\CoreBundle\Tests\Controller;
4
+
5
+use Muzich\CoreBundle\lib\FunctionalTest;
6
+
7
+class UserControllerTest extends FunctionalTest
8
+{
9
+  
10
+  public function testTagsFavoritesSuccess()
11
+  {
12
+    /**
13
+     * Inscription d'un utilisateur
14
+     */
15
+    $this->client = self::createClient();
16
+
17
+    $hardtek_id = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Hardtek')->getId();
18
+    $tribe_id   = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Tribe')->getId();
19
+    
20
+    $this->crawler = $this->client->request('GET', $this->generateUrl('index'));
21
+    $this->isResponseSuccess();
22
+
23
+    $this->procedure_registration_success(
24
+      'raoulc', 
25
+      'raoulc.def4v65sds@gmail.com', 
26
+      'toor', 
27
+      'toor'
28
+    );
29
+    
30
+    // Il ne doit y avoir aucun enregistrements de tags favoris
31
+    $Favorites = $this->getDoctrine()->getRepository('MuzichCoreBundle:UsersTagsFavorites')
32
+      ->findBy(array(
33
+          'user' => $this->getUser()->getId()
34
+      ))
35
+    ;
36
+    
37
+    $this->assertEquals(0, count($Favorites));
38
+    
39
+    // On a attérit sur la page de présentation et de sleection des tags favoris
40
+    $this->exist('form[action="'.($url = $this->generateUrl('update_tag_favorites')).'"]');
41
+    
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;
45
+    $this->submit($form);
46
+    
47
+    $this->isResponseRedirection();
48
+    $this->followRedirection();
49
+    $this->isResponseSuccess();
50
+    
51
+    // Désormais il y a deux tags favoris pour cet utilisateur
52
+    $Favorites = $this->getDoctrine()->getRepository('MuzichCoreBundle:UsersTagsFavorites')
53
+      ->findBy(array(
54
+          'user' => $this->getUser()->getId()
55
+      ))
56
+    ;
57
+    $this->assertEquals(2, count($Favorites));
58
+    
59
+    $Favorites = $this->getDoctrine()->getRepository('MuzichCoreBundle:UsersTagsFavorites')
60
+      ->findBy(array(
61
+          'user' => $this->getUser()->getId(),
62
+          'tag'  => $hardtek_id
63
+      ))
64
+    ;
65
+    $this->assertEquals(1, count($Favorites));
66
+    
67
+    $Favorites = $this->getDoctrine()->getRepository('MuzichCoreBundle:UsersTagsFavorites')
68
+      ->findBy(array(
69
+          'user' => $this->getUser()->getId(),
70
+          'tag'  => $tribe_id
71
+      ))
72
+    ;
73
+    $this->assertEquals(1, count($Favorites));
74
+  }
75
+}

+ 38 - 0
src/Muzich/CoreBundle/lib/FunctionalTest.php Voir le fichier

@@ -82,6 +82,44 @@ class FunctionalTest extends WebTestCase
82 82
     $this->submit($form);
83 83
   }
84 84
   
85
+  protected function procedure_registration_success($username, $email, $pass1, $pass2)
86
+  {
87
+    $this->crawler = $this->client->request('GET', $this->generateUrl('index'));
88
+    $this->isResponseSuccess();
89
+    $this->assertEquals('anon.', $this->getUser());
90
+    
91
+    $url = $this->generateUrl('register');
92
+    // Les mots de passes sont différents
93
+    $this->validate_registrate_user_form(
94
+      $this->selectForm('form[action="'.$url.'"] input[type="submit"]'), 
95
+      $username, 
96
+      $email, 
97
+      $pass1,
98
+      $pass2
99
+    );
100
+    
101
+    $this->isResponseRedirection();
102
+    $this->followRedirection();
103
+    $this->isResponseSuccess();
104
+
105
+    if ('anon.' != ($user = $this->getUser()))
106
+    {
107
+      // Nous ne sommes pas identifiés
108
+      $this->assertEquals($username, $user->getUsername());
109
+
110
+      // L'utilisateur n'est pas enregistré, il ne doit donc pas être en base
111
+      $db_user = $this->getDoctrine()->getRepository('MuzichCoreBundle:User')
112
+        ->findOneByUsername($username)
113
+      ;
114
+
115
+      $this->assertTrue(!is_null($db_user));
116
+    }
117
+    else
118
+    {
119
+      $this->assertTrue(false);
120
+    }
121
+  }
122
+  
85 123
   protected function procedure_registration_failure($username, $email, $pass1, $pass2)
86 124
   {
87 125
     $this->crawler = $this->client->request('GET', $this->generateUrl('index'));