Browse Source

Ecriture de test portants sur mynetwork, recherche, suivre.

bastien 13 years ago
parent
commit
4d60294246

+ 12 - 16
app/phpunit.xml.dist View File

@@ -15,10 +15,7 @@
15 15
 
16 16
     <testsuites>
17 17
         <testsuite name="Project Test Suite">
18
-            <!--<directory>../src/*/*Bundle/Tests</directory>-->
19
-            <directory>../src/Muzich/CoreBundle/Tests/Controller</directory>
20
-            <directory>../src/Muzich/CoreBundle/Tests/ElementFactory</directory>
21
-            <directory>../src/Muzich/CoreBundle/Tests/Searcher</directory>
18
+            <directory>../src/Muzich/CoreBundle/Tests</directory>
22 19
         </testsuite>
23 20
     </testsuites>
24 21
 
@@ -27,19 +24,18 @@
27 24
         <server name="KERNEL_DIR" value="/path/to/your/app/" />
28 25
     </php>
29 26
     -->
30
-
31
-    <!--
27
+    
32 28
     <filter>
33
-        <whitelist>
34
-            <directory>../src</directory>
35
-            <exclude>
36
-                <directory>../src/*/*Bundle/Resources</directory>
37
-                <directory>../src/*/*Bundle/Tests</directory>
38
-                <directory>../src/*/Bundle/*Bundle/Resources</directory>
39
-                <directory>../src/*/Bundle/*Bundle/Tests</directory>
40
-            </exclude>
41
-        </whitelist>
29
+      <blacklist>
30
+        <directory suffix=".php">../src/Acme</directory>
31
+        <exclude>
32
+          <directory suffix=".php">../src/Acme/DemoBundle</directory>
33
+        </exclude>
34
+      </blacklist>
35
+
36
+      <whitelist addUncoveredFilesFromWhitelist="true">
37
+        <directory suffix=".php">../src/Muzich</directory>
38
+      </whitelist>
42 39
     </filter>
43
-    -->
44 40
 
45 41
 </phpunit>

+ 13 - 0
src/Muzich/CoreBundle/Controller/CoreController.php View File

@@ -57,6 +57,19 @@ class CoreController extends Controller
57 57
   public function followAction($type, $id, $token)
58 58
   {
59 59
     $user = $this->getUser();
60
+    
61
+    /**
62
+     * Bug lors des tests: L'user n'est pas 'lié' a celui en base par doctrine.
63
+     * Docrine le voit si on faire une requete directe.
64
+     */
65
+    if ($this->container->getParameter('env') == 'test')
66
+    {
67
+      $user = $this->getDoctrine()->getRepository('MuzichCoreBundle:User')->findOneById(
68
+        $this->container->get('security.context')->getToken()->getUser()->getId(),
69
+        array()
70
+      )->getSingleResult();
71
+    }
72
+    
60 73
     // Vérifications préléminaires
61 74
     if ($user->getPersonalHash() != $token || !in_array($type, array('user', 'group')) || !is_numeric($id))
62 75
     {

+ 3 - 0
src/Muzich/CoreBundle/Searcher/UserAndGroupSearcher.php View File

@@ -5,6 +5,9 @@ namespace Muzich\CoreBundle\Searcher;
5 5
 use Symfony\Component\Validator\Constraints as Assert;
6 6
 use Symfony\Bundle\DoctrineBundle\Registry;
7 7
 
8
+/**
9
+ * Objet de recherche
10
+ */
8 11
 class UserAndGroupSearcher extends Searcher implements SearcherInterface
9 12
 {
10 13
   

+ 230 - 0
src/Muzich/CoreBundle/Tests/Controller/MynetworkControllerTest.php View File

@@ -0,0 +1,230 @@
1
+<?php
2
+
3
+namespace Muzich\CoreBundle\Tests\Controller;
4
+
5
+use Muzich\CoreBundle\lib\FunctionalTest;
6
+
7
+class MynetworkControllerTest extends FunctionalTest
8
+{
9
+  /**
10
+   * Test de l'affichage de la page "mon réseau"
11
+   */
12
+  public function testMyNetwork()
13
+  {
14
+    /**
15
+     * Avec l'utilisateur 'bux' , qui d'après les fixtures suis: jean, paul,
16
+     * les groupes DUDELDRUM et Fans de psytrance
17
+     * et est suivis par joelle
18
+     */
19
+    $this->connectUser('bux', 'toor');
20
+    $link = $this->selectLink('a[href="'.$this->generateUrl('mynetwork_index').'"]');
21
+    $this->clickOnLink($link);
22
+    $this->isResponseSuccess();
23
+    
24
+    // Récupération des entités
25
+    $jean = $this->getDoctrine()->getRepository('MuzichCoreBundle:User')->findOneByUsername('jean');
26
+    $paul = $this->getDoctrine()->getRepository('MuzichCoreBundle:User')->findOneByUsername('paul');
27
+    $joelle = $this->getDoctrine()->getRepository('MuzichCoreBundle:User')->findOneByUsername('joelle');
28
+    $DUDELDRUM = $this->getDoctrine()->getRepository('MuzichCoreBundle:Group')->findOneByName('DUDELDRUM');
29
+    $Fans_de_psytrance = $this->getDoctrine()->getRepository('MuzichCoreBundle:Group')->findOneByName('Fans de psytrance');
30
+    
31
+    $this->exist('ul#followeds_users li a[href="'.$this->generateUrl('show_user', array('slug' => $jean->getSlug())).'"]');
32
+    $this->exist('ul#followeds_users li a[href="'.$this->generateUrl('show_user', array('slug' => $paul->getSlug())).'"]');
33
+    $this->exist('ul#followers_users li a[href="'.$this->generateUrl('show_user', array('slug' => $joelle->getSlug())).'"]');
34
+    $this->exist('ul#followeds_groups li a[href="'.$this->generateUrl('show_group', array('slug' => $DUDELDRUM->getSlug())).'"]');
35
+    $this->exist('ul#followeds_groups li a[href="'.$this->generateUrl('show_group', array('slug' => $Fans_de_psytrance->getSlug())).'"]');
36
+  }
37
+  
38
+  /**
39
+   * Test de la recherche
40
+   */
41
+  public function testSearch()
42
+  {
43
+    $this->connectUser('bux', 'toor');
44
+    $link = $this->selectLink('a[href="'.$this->generateUrl('mynetwork_index').'"]');
45
+    $this->clickOnLink($link);
46
+    $this->isResponseSuccess();
47
+    $link = $this->selectLink('a[href="'.$this->generateUrl('mynetwork_search').'"]');
48
+    $this->clickOnLink($link);
49
+    $this->isResponseSuccess();
50
+    
51
+    $this->exist('form[action="'.($url = $this->generateUrl('mynetwork_search')).'"]');
52
+    $this->exist('form[action="'.$url.'"] input[id="form_string"]');
53
+    $this->exist('form[action="'.$url.'"] input[type="submit"]');
54
+    
55
+    $bob = $this->getDoctrine()->getRepository('MuzichCoreBundle:User')->findOneByUsername('bob');
56
+    // On va rechercher l'utilisateur bob
57
+    $form = $this->selectForm('form[action="'.$url.'"] input[type="submit"]');
58
+    $form['form[string]'] = 'bob';
59
+    $this->submit($form);
60
+    $this->outputDebug();
61
+    $this->isResponseSuccess();
62
+    
63
+    // On trouve bob
64
+    $this->exist('ul#search_users li a[href="'.$this->generateUrl('show_user', array('slug' => $bob->getSlug())).'"]');
65
+    
66
+    $joelle = $this->getDoctrine()->getRepository('MuzichCoreBundle:User')->findOneByUsername('joelle');
67
+    $Le_groupe_de_joelle = $this->getDoctrine()->getRepository('MuzichCoreBundle:Group')->findOneByName('Le groupe de joelle');
68
+    // On va maintenant rechercher le groupe de joelle
69
+    $form = $this->selectForm('form[action="'.$url.'"] input[type="submit"]');
70
+    $form['form[string]'] = 'joelle';
71
+    $this->submit($form);
72
+    $this->isResponseSuccess();
73
+    
74
+    // On trouve joelle mais aussi son groupe (il y a joelle dans le nom)
75
+    $this->exist('ul#search_users li a[href="'.$this->generateUrl('show_user', array('slug' => $joelle->getSlug())).'"]');
76
+    $this->exist('ul#search_groups li a[href="'.$this->generateUrl('show_group', array('slug' => $Le_groupe_de_joelle->getSlug())).'"]');
77
+  }
78
+  
79
+  /**
80
+   * Test de l'action 'suivre' et 'ne plus suivre' sur un user
81
+   */
82
+  public function testUserFollow()
83
+  {
84
+    // Connection de bob
85
+    $this->connectUser('bob', 'toor');
86
+    
87
+    // Récupération des entités (bob ne les suit pas)
88
+    $bux = $this->getDoctrine()->getRepository('MuzichCoreBundle:User')->findOneByUsername('bux');
89
+    
90
+    // On tente de récupérer l'entité FollowUser
91
+    $FollowUser = $this->getDoctrine()->getRepository('MuzichCoreBundle:FollowUser')
92
+      ->findOneBy(array(
93
+        'follower' => $this->getUser()->getId(),
94
+        'followed' => $bux->getId()
95
+      ))
96
+    ;
97
+    
98
+    // Mais celle-ci doit-être innexistante
99
+    $this->assertTrue(is_null($FollowUser));
100
+    
101
+    // Ouverture de la page d'un user (bux)
102
+    $this->crawler = $this->client->request('GET', $this->generateUrl('show_user', array('slug' => $bux->getSlug())));
103
+    $this->isResponseSuccess();
104
+    
105
+    $url_follow = $this->generateUrl('follow', array(
106
+      'type' => 'user', 
107
+      'id' => $bux->getId(),
108
+      'token' => $this->getUser()->getPersonalHash()
109
+    ));
110
+    
111
+    // On lance l'action de suivre
112
+    $this->exist('a.notfollowing[href="'.$url_follow.'"]');
113
+    $link = $this->selectLink('a[href="'.$url_follow.'"]');
114
+    $this->clickOnLink($link);
115
+    
116
+    $this->isResponseRedirection();
117
+    $this->followRedirection();
118
+    $this->isResponseSuccess();
119
+    
120
+    $this->exist('a.following[href="'.$url_follow.'"]');
121
+    
122
+    // On tente de récupérer l'entité FollowUser
123
+    $FollowUser = $this->getDoctrine()->getRepository('MuzichCoreBundle:FollowUser')
124
+      ->findOneBy(array(
125
+        'follower' => $this->getUser()->getId(),
126
+        'followed' => $bux->getId()
127
+      ))
128
+    ;
129
+    
130
+    // Celle-ci doit exister maintenant
131
+    $this->assertTrue(!is_null($FollowUser));
132
+    
133
+    // On lance l'action de ne plus suivre
134
+    $link = $this->selectLink('a[href="'.$url_follow.'"]');
135
+    $this->clickOnLink($link);
136
+    
137
+    $this->isResponseRedirection();
138
+    $this->followRedirection();
139
+    $this->isResponseSuccess();
140
+    
141
+    $this->exist('a.notfollowing[href="'.$url_follow.'"]');
142
+    
143
+    // On tente de récupérer l'entité FollowUser
144
+    $FollowUser = $this->getDoctrine()->getRepository('MuzichCoreBundle:FollowUser')
145
+      ->findOneBy(array(
146
+        'follower' => $this->getUser()->getId(),
147
+        'followed' => $bux->getId()
148
+      ))
149
+    ;
150
+    
151
+    // Celle-ci ne doit plus exister maintenant
152
+    $this->assertTrue(is_null($FollowUser));
153
+  }
154
+  
155
+  /**
156
+   * Test de l'action 'suivre' et 'ne plus suivre' sur un groupe
157
+   */
158
+  public function testGroupFollow()
159
+  {
160
+    // Connection de bob
161
+    $this->connectUser('bob', 'toor');
162
+    
163
+    // Récupération des entités (bob ne les suit pas)
164
+    $DUDELDRUM = $this->getDoctrine()->getRepository('MuzichCoreBundle:Group')->findOneByName('DUDELDRUM');
165
+    
166
+    // On tente de récupérer l'entité FollowUser
167
+    $FollowGroup = $this->getDoctrine()->getRepository('MuzichCoreBundle:FollowGroup')
168
+      ->findOneBy(array(
169
+        'follower' => $this->getUser()->getId(),
170
+        'group' => $DUDELDRUM->getId()
171
+      ))
172
+    ;
173
+    
174
+    // Mais celle-ci doit-être innexistante
175
+    $this->assertTrue(is_null($FollowGroup));
176
+    
177
+    // Ouverture de la page d'un user (bux)
178
+    $this->crawler = $this->client->request('GET', $this->generateUrl('show_group', array('slug' => $DUDELDRUM->getSlug())));
179
+    $this->isResponseSuccess();
180
+    
181
+    $url_follow = $this->generateUrl('follow', array(
182
+      'type' => 'group', 
183
+      'id' => $DUDELDRUM->getId(),
184
+      'token' => $this->getUser()->getPersonalHash()
185
+    ));
186
+    
187
+    // On lance l'action de suivre
188
+    $this->exist('a.notfollowing[href="'.$url_follow.'"]');
189
+    $link = $this->selectLink('a[href="'.$url_follow.'"]');
190
+    $this->clickOnLink($link);
191
+    
192
+    $this->isResponseRedirection();
193
+    $this->followRedirection();
194
+    $this->isResponseSuccess();
195
+    
196
+    $this->exist('a.following[href="'.$url_follow.'"]');
197
+    
198
+    // On tente de récupérer l'entité FollowUser
199
+    $FollowGroup = $this->getDoctrine()->getRepository('MuzichCoreBundle:FollowGroup')
200
+      ->findOneBy(array(
201
+        'follower' => $this->getUser()->getId(),
202
+        'group' => $DUDELDRUM->getId()
203
+      ))
204
+    ;
205
+    
206
+    // Celle-ci doit exister maintenant
207
+    $this->assertTrue(!is_null($FollowGroup));
208
+    
209
+    // On lance l'action de ne plus suivre
210
+    $link = $this->selectLink('a[href="'.$url_follow.'"]');
211
+    $this->clickOnLink($link);
212
+    
213
+    $this->isResponseRedirection();
214
+    $this->followRedirection();
215
+    $this->isResponseSuccess();
216
+    
217
+    $this->exist('a.notfollowing[href="'.$url_follow.'"]');
218
+    
219
+    // On tente de récupérer l'entité FollowUser
220
+    $FollowGroup = $this->getDoctrine()->getRepository('MuzichCoreBundle:FollowGroup')
221
+      ->findOneBy(array(
222
+        'follower' => $this->getUser()->getId(),
223
+        'group' => $DUDELDRUM->getId()
224
+      ))
225
+    ;
226
+    
227
+    // Celle-ci ne doit plus exister maintenant
228
+    $this->assertTrue(is_null($FollowGroup));
229
+  }
230
+}

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

@@ -218,7 +218,7 @@ class FunctionalTest extends WebTestCase
218 218
    */
219 219
   protected function selectLink($filter)
220 220
   {
221
-    return $this->crawler->filter($filter)->eq(1)->link();
221
+    return $this->crawler->filter($filter)->link();
222 222
   }
223 223
   
224 224
 //  /**
@@ -232,7 +232,7 @@ class FunctionalTest extends WebTestCase
232 232
 //  }
233 233
   
234 234
   /**
235
-   * Retourne un formulaire
235
+   * Retourne un formulaire, en filtrant le BOUTON SUBMIT !!
236 236
    * 
237 237
    * @param string $filter
238 238
    * @return \Symfony\Component\DomCrawler\Form 

+ 2 - 1
src/Muzich/HomeBundle/Resources/views/Show/showGroup.html.twig View File

@@ -12,7 +12,8 @@
12 12
       </a> |
13 13
     {% endif %}
14 14
 
15
-    <a href="{{ path('follow', { 'type': 'group', 'id': group.id, 'token': user.personalHash }) }}" >
15
+    <a href="{{ path('follow', { 'type': 'group', 'id': group.id, 'token': user.personalHash }) }}" 
16
+       class="{% if following %}following{% else %}notfollowing{% endif %}">
16 17
       {% if following %}
17 18
         {{ 'group.notfollow'|trans({}, 'groups') }}
18 19
       {% else %}

+ 2 - 1
src/Muzich/HomeBundle/Resources/views/Show/showUser.html.twig View File

@@ -10,7 +10,8 @@
10 10
       {{ 'user.view_favorites'|trans({}, 'users') }}
11 11
     </a>
12 12
     | 
13
-    <a href="{{ path('follow', { 'type': 'user', 'id': viewed_user.id, 'token': user.personalHash }) }}" class="follow_link following" >
13
+    <a href="{{ path('follow', { 'type': 'user', 'id': viewed_user.id, 'token': user.personalHash }) }}" 
14
+       class="follow_link {% if following %}following{% else %}notfollowing{% endif %}" >
14 15
       {% if following %}
15 16
         {{ 'user.notfollow'|trans({}, 'users') }}
16 17
       {% else %}

+ 3 - 3
src/Muzich/MynetworkBundle/Resources/views/Mynetwork/index.html.twig View File

@@ -10,7 +10,7 @@
10 10
   
11 11
   {% if followeds_users %}
12 12
     <b>{{ 'users'|trans({}, 'network') }}</b>
13
-    <ul class="inline">
13
+    <ul id="followeds_users" class="inline">
14 14
     {% for user in followeds_users %} 
15 15
       <li>
16 16
         <a href="{{ path('show_user', { 'slug': user.slug }) }}">{{ user.username }}</a>
@@ -21,7 +21,7 @@
21 21
   
22 22
   {% if followeds_groups %}
23 23
     <b>{{ 'groups'|trans({}, 'network') }}</b>
24
-    <ul class="inline">
24
+    <ul id="followeds_groups" class="inline">
25 25
     {% for group in followeds_groups %} 
26 26
       <li>
27 27
         <a href="{{ path('show_group', { 'slug': group.slug }) }}">{{ group.name }}</a>
@@ -32,7 +32,7 @@
32 32
   
33 33
   {% if followers_users %}
34 34
     <b>{{ 'followed_by'|trans({}, 'network') }}</b>
35
-    <ul class="inline">
35
+    <ul id="followers_users" class="inline">
36 36
     {% for user in followers_users %} 
37 37
       <li>
38 38
         <a href="{{ path('show_user', { 'slug': user.slug }) }}">{{ user.username }}</a>

+ 2 - 2
src/Muzich/MynetworkBundle/Resources/views/Mynetwork/search.html.twig View File

@@ -27,7 +27,7 @@
27 27
 
28 28
       <b>{{ 'search.users'|trans({}, 'network') }}</b>
29 29
       
30
-      <ul class="inline">
30
+      <ul id="search_users" class="inline">
31 31
       {% for user in results.users %} 
32 32
         <li>
33 33
           <a href="{{ path('show_user', { 'slug': user.slug }) }}">{{ user.username }}</a>
@@ -41,7 +41,7 @@
41 41
 
42 42
       <b>{{ 'search.groups'|trans({}, 'network') }}</b>
43 43
       
44
-      <ul class="inline">
44
+      <ul id="search_groups" class="inline">
45 45
       {% for group in results.groups %} 
46 46
         <li>
47 47
           <a href="{{ path('show_group', { 'slug': group.slug }) }}">{{ group.name }}</a>

+ 0 - 17
src/Muzich/MynetworkBundle/Tests/Controller/DefaultControllerTest.php View File

@@ -1,17 +0,0 @@
1
-<?php
2
-
3
-namespace Muzich\MynetworkBundle\Tests\Controller;
4
-
5
-use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
6
-
7
-class DefaultControllerTest extends WebTestCase
8
-{
9
-    public function testIndex()
10
-    {
11
-        $client = static::createClient();
12
-
13
-        $crawler = $client->request('GET', '/hello/Fabien');
14
-
15
-        $this->assertTrue($crawler->filter('html:contains("Hello Fabien")')->count() > 0);
16
-    }
17
-}