Browse Source

Merge branch 'feature/test' into unstable

bastien 13 years ago
parent
commit
ef40f83fc9

+ 160 - 0
app/Resources/FOSUserBundle/config/validation.xml View File

@@ -0,0 +1,160 @@
1
+<?xml version="1.0" ?>
2
+<constraint-mapping xmlns="http://symfony.com/schema/dic/constraint-mapping"
3
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
+    xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping
5
+        http://symfony.com/schema/dic/services/constraint-mapping-1.0.xsd">
6
+
7
+    <class name="FOS\UserBundle\Model\User">
8
+
9
+        <constraint name="FOS\UserBundle\Validator\Unique">
10
+            <option name="property">usernameCanonical</option>
11
+            <option name="message">The username is already used</option>
12
+            <option name="groups">
13
+                <value>Registration</value>
14
+                <value>Profile</value>
15
+            </option>
16
+        </constraint>
17
+
18
+        <constraint name="FOS\UserBundle\Validator\Unique">
19
+            <option name="property">emailCanonical</option>
20
+            <option name="message">The email is already used</option>
21
+            <option name="groups">
22
+                <value>Registration</value>
23
+                <value>Profile</value>
24
+            </option>
25
+        </constraint>
26
+
27
+        <property name="username">
28
+            <constraint name="NotBlank">
29
+                <option name="message">Please enter a username</option>
30
+                <option name="groups">
31
+                    <value>Registration</value>
32
+                    <value>Profile</value>
33
+                </option>
34
+            </constraint>
35
+            <constraint name="MinLength">
36
+                <option name="limit">6</option>
37
+                <option name="message">The username is too short</option>
38
+                <option name="groups">
39
+                    <value>Registration</value>
40
+                    <value>Profile</value>
41
+                </option>
42
+            </constraint>
43
+            <constraint name="MaxLength">
44
+                <option name="limit">32</option>
45
+                <option name="message">The username is too long</option>
46
+                <option name="groups">
47
+                    <value>Registration</value>
48
+                    <value>Profile</value>
49
+                </option>
50
+            </constraint>
51
+        </property>
52
+
53
+        <property name="email">
54
+            <constraint name="NotBlank">
55
+                <option name="message">Please enter an email</option>
56
+                <option name="groups">
57
+                    <value>Registration</value>
58
+                    <value>Profile</value>
59
+                </option>
60
+            </constraint>
61
+            <constraint name="MinLength">
62
+                <option name="limit">2</option>
63
+                <option name="message">The email is too short</option>
64
+                <option name="groups">
65
+                    <value>Registration</value>
66
+                    <value>Profile</value>
67
+                </option>
68
+            </constraint>
69
+            <constraint name="MaxLength">
70
+                <option name="limit">255</option>
71
+                <option name="message">The email is too long</option>
72
+                <option name="groups">
73
+                    <value>Registration</value>
74
+                    <value>Profile</value>
75
+                </option>
76
+            </constraint>
77
+            <constraint name="Email">
78
+                <option name="message">The email is not valid</option>
79
+                <option name="groups">
80
+                    <value>Registration</value>
81
+                    <value>Profile</value>
82
+                </option>
83
+            </constraint>
84
+        </property>
85
+
86
+        <property name="plainPassword">
87
+            <constraint name="NotBlank">
88
+                <option name="message">Please enter a password</option>
89
+                <option name="groups">Registration</option>
90
+            </constraint>
91
+            <constraint name="MinLength">
92
+                <option name="limit">2</option>
93
+                <option name="message">The password is too short</option>
94
+                <option name="groups">
95
+                    <value>Registration</value>
96
+                    <value>Profile</value>
97
+                </option>
98
+            </constraint>
99
+        </property>
100
+    </class>
101
+
102
+    <class name="FOS\UserBundle\Form\Model\CheckPassword">
103
+        <constraint name="FOS\UserBundle\Validator\Password">
104
+            <option name="passwordProperty">current</option>
105
+            <option name="userProperty">user</option>
106
+            <option name="groups">
107
+                <value>ChangePassword</value>
108
+                <value>Profile</value>
109
+            </option>
110
+        </constraint>
111
+    </class>
112
+
113
+    <class name="FOS\UserBundle\Form\Model\ChangePassword">
114
+        <property name="new">
115
+            <constraint name="NotBlank">
116
+                <option name="message">Please enter a new password</option>
117
+                <option name="groups">ChangePassword</option>
118
+            </constraint>
119
+            <constraint name="MinLength">
120
+                <option name="limit">2</option>
121
+                <option name="message">The new password is too short</option>
122
+                <option name="groups">ChangePassword</option>
123
+            </constraint>
124
+        </property>
125
+    </class>
126
+
127
+    <class name="FOS\UserBundle\Form\Model\ResetPassword">
128
+        <property name="new">
129
+            <constraint name="NotBlank">
130
+                <option name="message">Please enter a new password</option>
131
+                <option name="groups">ResetPassword</option>
132
+            </constraint>
133
+            <constraint name="MinLength">
134
+                <option name="limit">2</option>
135
+                <option name="message">The new password is too short</option>
136
+                <option name="groups">ResetPassword</option>
137
+            </constraint>
138
+        </property>
139
+    </class>
140
+
141
+    <class name="FOS\UserBundle\Model\Group">
142
+        <property name="name">
143
+            <constraint name="NotBlank">
144
+                <option name="message">Please enter a name</option>
145
+                <option name="groups">Registration</option>
146
+            </constraint>
147
+            <constraint name="MinLength">
148
+                <option name="limit">2</option>
149
+                <option name="message">The name is too short</option>
150
+                <option name="groups">Registration</option>
151
+            </constraint>
152
+            <constraint name="MaxLength">
153
+                <option name="limit">255</option>
154
+                <option name="message">The name is too long</option>
155
+                <option name="groups">Registration</option>
156
+            </constraint>
157
+        </property>
158
+    </class>
159
+
160
+</constraint-mapping>

+ 4 - 0
catalog.xml View File

@@ -0,0 +1,4 @@
1
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
+<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog" prefer="system">
3
+    <nextCatalog catalog="nbproject/private/retriever/catalog.xml"/>
4
+</catalog>

+ 7 - 0
src/Muzich/CoreBundle/Resources/config/validation.yml View File

@@ -0,0 +1,7 @@
1
+##
2
+
3
+Muzich\CoreBundle\Entity\User:
4
+  properties:
5
+    username:
6
+      - MinLength: { limit: 3}
7
+      - MaxLength: { limit: 32}

+ 135 - 0
src/Muzich/CoreBundle/Tests/Controller/HomeControllerTest.php View File

@@ -0,0 +1,135 @@
1
+<?php
2
+
3
+namespace Muzich\CoreBundle\Tests\Controller;
4
+
5
+use Muzich\CoreBundle\lib\FunctionalTest;
6
+use Muzich\CoreBundle\Searcher\ElementSearcher;
7
+
8
+class HomeControllerTest extends FunctionalTest
9
+{
10
+  /**
11
+   * Ce test contrôle l'affichage des elements sur la page d'accueil
12
+   * Il modifie egallement le filtre d'éléments
13
+   */
14
+  public function testFilter()
15
+  {
16
+    $this->connectUser('bux', 'toor');
17
+
18
+    // Présence du formulaire d'ajout d'un élément
19
+    $this->exist('form[action="'.($url = $this->generateUrl('element_add')).'"]');
20
+    $this->exist('form[action="'.$url.'"] input[id="element_add_name"]');
21
+    $this->exist('form[action="'.$url.'"] input[id="element_add_url"]');
22
+    $this->exist('form[action="'.$url.'"] select[id="element_add_group"]');
23
+    $this->exist('form[action="'.$url.'"] input[type="submit"]');
24
+    
25
+    // Présence du formulaire de filtrage
26
+    $this->exist('form[action="'.($url = $this->generateUrl('search_elements')).'"]');
27
+    $this->exist('form[action="'.$url.'"] select[id="element_search_form_network"]');
28
+    $this->exist('form[action="'.$url.'"] input[type="submit"]');
29
+    
30
+    $hardtek_id = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Hardtek')->getId();
31
+    $tribe_id   = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Tribe')->getId();
32
+    
33
+    // On récupére le formulaire de filtrage
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
+    
42
+    // On met ce que l'on veut dans le form
43
+    $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;
46
+    $this->submit($form);
47
+    
48
+    $this->client->submit($form);
49
+    
50
+    $this->isResponseRedirection();
51
+    $this->followRedirection();
52
+    $this->isResponseSuccess();
53
+    
54
+    $this->assertTrue($this->getSession()->has('user.element_search.params'));
55
+    $this->assertEquals(array(
56
+        'network'   => ElementSearcher::NETWORK_PUBLIC,
57
+        'tags'      => array(
58
+          $hardtek_id, $tribe_id
59
+        ),
60
+        'count'     => $this->getContainer()->getParameter('search_default_count'),
61
+        'user_id'   => null,
62
+        'group_id'  => null,
63
+        'favorite' => false
64
+    ), $this->getSession()->get('user.element_search.params'));
65
+    
66
+    // On fabrique l'ElementSearcher correspondant
67
+    $es = new ElementSearcher();
68
+    $es->init($this->getSession()->get('user.element_search.params'));
69
+    
70
+    foreach ($es->getElements($this->getDoctrine(), $this->getUser()->getId()) as $element)
71
+    {
72
+      $this->exist('html:contains("'.$element->getName().'")');
73
+    }
74
+  }
75
+  
76
+  /**
77
+   * Test de la présence des elements sur la page d'un utilisateur
78
+   */
79
+  public function testUserPage()
80
+  {
81
+    $this->connectUser('bux', 'toor');
82
+    $jean = $this->getDoctrine()->getRepository('MuzichCoreBundle:User')
83
+      ->findOneByUsername('jean')
84
+    ;
85
+    
86
+    $this->crawler = $this->client->request(
87
+      'GET', 
88
+      $this->generateUrl('show_user', array('slug' => $jean->getSlug()))
89
+    );
90
+    
91
+    $this->isResponseSuccess();
92
+    $this->exist('h2:contains("'.$jean->getName().'")');
93
+    
94
+    $es = new ElementSearcher();
95
+    $es->init(array(
96
+      'user_id' => $jean->getId()
97
+    ));
98
+    
99
+    foreach ($es->getElements($this->getDoctrine(), $this->getUser()->getId()) as $element)
100
+    {
101
+      $this->exist('html:contains("'.$element->getName().'")');
102
+    }
103
+  }
104
+  
105
+  /**
106
+   * Test de la présence des elements sur la page d'un utilisateur
107
+   */
108
+  public function testGroupPage()
109
+  {
110
+    $this->connectUser('bux', 'toor');
111
+    $fdp = $this->getDoctrine()->getRepository('MuzichCoreBundle:Group')
112
+      ->findOneBySlug('fans-de-psytrance')
113
+      ->getSingleResult()
114
+    ;
115
+    
116
+    $this->crawler = $this->client->request(
117
+      'GET', 
118
+      $this->generateUrl('show_group', array('slug' => $fdp->getSlug()))
119
+    );
120
+    
121
+    $this->isResponseSuccess();
122
+    $this->exist('h2:contains("'.$fdp->getName().'")');
123
+    
124
+    $es = new ElementSearcher();
125
+    $es->init(array(
126
+      'group_id' => $fdp->getId()
127
+    ));
128
+    
129
+    foreach ($es->getElements($this->getDoctrine(), $this->getUser()->getId()) as $element)
130
+    {
131
+      $this->exist('html:contains("'.$element->getName().'")');
132
+    }
133
+  }
134
+  
135
+}

+ 158 - 0
src/Muzich/CoreBundle/Tests/Controller/IndexControllerTest.php View File

@@ -0,0 +1,158 @@
1
+<?php
2
+
3
+namespace Muzich\CoreBundle\Tests\Controller;
4
+
5
+use Muzich\CoreBundle\lib\FunctionalTest;
6
+
7
+class IndexControllerTest extends FunctionalTest
8
+{
9
+  public function testIdentificationSuccess()
10
+  {
11
+    /**
12
+     * Test de l'identification de paul
13
+     */
14
+    $this->client = self::createClient();
15
+
16
+    $this->crawler = $this->client->request('GET', $this->generateUrl('index'));
17
+    $this->isResponseSuccess();
18
+
19
+    $this->assertEquals('anon.', $this->getUser());
20
+
21
+    $this->exist('div.login');
22
+    $this->exist('form[action="'.($url = $this->generateUrl('fos_user_security_check')).'"]');
23
+    $this->exist('form[action="'.$url.'"] input[id="username"]');
24
+    $this->exist('form[action="'.$url.'"] input[id="password"]');
25
+    $this->exist('form[action="'.$url.'"] input[id="remember_me"]');
26
+    $this->exist('form[action="'.$url.'"] input[type="submit"]');
27
+
28
+    $form = $this->selectForm('form[action="'.$url.'"] input[type="submit"]');
29
+    $form['_username'] = 'paul';
30
+    $form['_password'] = 'toor';
31
+    $form['_remember_me'] = true;
32
+    $this->submit($form);
33
+
34
+    $this->isResponseRedirection();
35
+    $this->followRedirection();
36
+    $this->isResponseSuccess();
37
+
38
+    $user = $this->getUser();
39
+    $this->assertEquals('paul', $user->getUsername());
40
+  }
41
+  
42
+  public function testIdentificationFail()
43
+  {
44
+    /**
45
+     * Test de l'identification de paul, avec erreur
46
+     */
47
+    $this->client = self::createClient();
48
+
49
+    $this->crawler = $this->client->request('GET', $this->generateUrl('index'));
50
+    $this->isResponseSuccess();
51
+
52
+    $this->assertEquals('anon.', $this->getUser());
53
+
54
+    $form = $this->selectForm('form[action="'.$this->generateUrl('fos_user_security_check').'"] input[type="submit"]');
55
+    $form['_username'] = 'paul';
56
+    $form['_password'] = 'toorr';
57
+    $form['_remember_me'] = true;
58
+    $this->submit($form);
59
+
60
+    $this->isResponseRedirection();
61
+    $this->followRedirection();
62
+    $this->isResponseSuccess();
63
+
64
+    $user = $this->getUser();
65
+    $this->assertEquals('anon.', $this->getUser());
66
+  }
67
+  
68
+  public function testRegistrationSuccess()
69
+  {
70
+    /**
71
+     * Inscription d'un utilisateur
72
+     */
73
+    $this->client = self::createClient();
74
+
75
+    $this->crawler = $this->client->request('GET', $this->generateUrl('index'));
76
+    $this->isResponseSuccess();
77
+
78
+    $this->assertEquals('anon.', $this->getUser());
79
+    
80
+    $this->exist('div.register');
81
+    $this->exist('form[action="'.($url = $this->generateUrl('register')).'"]');
82
+    $this->exist('form[action="'.$url.'"] input[id="fos_user_registration_form_username"]');
83
+    $this->exist('form[action="'.$url.'"] input[id="fos_user_registration_form_email"]');
84
+    $this->exist('form[action="'.$url.'"] input[id="fos_user_registration_form_plainPassword_first"]');
85
+    $this->exist('form[action="'.$url.'"] input[id="fos_user_registration_form_plainPassword_second"]');
86
+    $this->exist('form[action="'.$url.'"] input[type="submit"]');
87
+    
88
+    $this->validate_registrate_user_form(
89
+      $this->selectForm('form[action="'.$url.'"] input[type="submit"]'), 
90
+      'raoula', 
91
+      'raoul.45gf64z@gmail.com', 
92
+      'toor',
93
+      'toor'
94
+    );
95
+    
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
+    }
113
+  }
114
+  
115
+  public function testRegistrationFailure()
116
+  {
117
+    
118
+    /**
119
+     * Inscription d'un utilisateur
120
+     */
121
+    $this->client = self::createClient();
122
+
123
+    // Mots de passe différents
124
+    $this->procedure_registration_failure(
125
+      'raoulb', 
126
+      'raoulb.def4v65sds@gmail.com', 
127
+      'toor', 
128
+      'toorr'
129
+    );
130
+
131
+//    // Pseudo trop court
132
+//    $this->procedure_registration_failure(
133
+//      'ra', 
134
+//      'raoulb.def4v65sds@gmail.com', 
135
+//      'toor', 
136
+//      'toor'
137
+//    );
138
+//    
139
+//    // Pseudo trop long
140
+//    $this->procedure_registration_failure(
141
+//      'raouuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu'
142
+//         .'uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu'
143
+//         .'uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuul', 
144
+//      'raoulb.def4v65sds@gmail.com', 
145
+//      'toor', 
146
+//      'toor'
147
+//    );
148
+
149
+    // Email invalide
150
+    $this->procedure_registration_failure(
151
+      'raoulc', 
152
+      'raoulb.def4v65sds@gmail', 
153
+      'toor', 
154
+      'toor'
155
+    );
156
+  }
157
+  
158
+}

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

@@ -0,0 +1,228 @@
1
+<?php
2
+
3
+namespace Muzich\CoreBundle\lib;
4
+
5
+use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
6
+use Symfony\Bundle\FrameworkBundle\Client;
7
+use Symfony\Component\DomCrawler\Crawler;
8
+
9
+class FunctionalTest extends WebTestCase
10
+{
11
+  /**
12
+   *
13
+   * @var Client 
14
+   */
15
+  protected $client;
16
+  
17
+  /**
18
+   *
19
+   * @var Crawler 
20
+   */
21
+  protected $crawler;
22
+  
23
+  /**
24
+   * Retourne l'objet User
25
+   * 
26
+   * @return \Muzich\CoreBundle\Entity\User 
27
+   */
28
+  protected function getUser()
29
+  {
30
+    return $this->client->getContainer()->get('security.context')->getToken()->getUser();
31
+  }
32
+  
33
+  protected function connectUser($login, $password)
34
+  {
35
+    $this->client = self::createClient();
36
+
37
+    $this->crawler = $this->client->request('GET', $this->generateUrl('index'));
38
+    $this->isResponseSuccess();
39
+
40
+    $this->assertEquals('anon.', $this->getUser());
41
+
42
+    $this->exist('div.login');
43
+    $this->exist('form[action="'.($url = $this->generateUrl('fos_user_security_check')).'"]');
44
+    $this->exist('form[action="'.$url.'"] input[id="username"]');
45
+    $this->exist('form[action="'.$url.'"] input[id="password"]');
46
+    $this->exist('form[action="'.$url.'"] input[id="remember_me"]');
47
+    $this->exist('form[action="'.$url.'"] input[type="submit"]');
48
+
49
+    $form = $this->selectForm('form[action="'.$url.'"] input[type="submit"]');
50
+    $form['_username'] = $login;
51
+    $form['_password'] = $password;
52
+    $form['_remember_me'] = true;
53
+    $this->submit($form);
54
+
55
+    $this->isResponseRedirection();
56
+    $this->followRedirection();
57
+    $this->isResponseSuccess();
58
+
59
+    $user = $this->getUser();
60
+    $this->assertEquals($login, $user->getUsername());
61
+  }
62
+  
63
+  protected function validate_registrate_user_form($form, $username, $email, $pass1, $pass2)
64
+  {
65
+    $form['fos_user_registration_form[username]'] = $username;
66
+    $form['fos_user_registration_form[email]'] = $email;
67
+    $form['fos_user_registration_form[plainPassword][first]'] = $pass1;
68
+    // Un des mots de passe est incorrect
69
+    $form['fos_user_registration_form[plainPassword][second]'] = $pass2;
70
+    $this->submit($form);
71
+  }
72
+  
73
+  protected function procedure_registration_failure($username, $email, $pass1, $pass2)
74
+  {
75
+    $this->crawler = $this->client->request('GET', $this->generateUrl('index'));
76
+    $this->isResponseSuccess();
77
+    $this->assertEquals('anon.', $this->getUser());
78
+    
79
+    $url = $this->generateUrl('register');
80
+    // Les mots de passes sont différents
81
+    $this->validate_registrate_user_form(
82
+      $this->selectForm('form[action="'.$url.'"] input[type="submit"]'), 
83
+      $username, 
84
+      $email, 
85
+      $pass1,
86
+      $pass2
87
+    );
88
+    
89
+    $this->isResponseSuccess();
90
+
91
+    if ('anon.' === ($user = $this->getUser()))
92
+    {
93
+      // Nous ne sommes pas identifiés
94
+      $this->assertEquals('anon.', $user);
95
+
96
+      // L'utilisateur n'est pas enregistré, il ne doit donc pas être en base
97
+      $db_user = $this->getDoctrine()->getRepository('MuzichCoreBundle:User')
98
+        ->findOneByUsername($username)
99
+      ;
100
+
101
+      $this->assertTrue(is_null($db_user));
102
+    }
103
+    else
104
+    {
105
+      $this->assertTrue(false);
106
+    }
107
+  }
108
+  
109
+  /**
110
+   * Generates a URL from the given parameters.
111
+   *
112
+   * @param string $route
113
+   * @param array $parameters
114
+   * @param boolean $absolute 
115
+   * 
116
+   * @return string (url generated)
117
+   */
118
+  protected function generateUrl($route, $parameters = array(), $absolute = false)
119
+  {
120
+    return $this->client->getContainer()->get('router')->generate($route, $parameters, $absolute);
121
+  }
122
+  
123
+  protected function getContainer()
124
+  {
125
+    return $this->client->getContainer();
126
+  }
127
+  
128
+  protected function getSession()
129
+  {
130
+    return $this->getContainer()->get('session');
131
+  }
132
+  
133
+  /**
134
+   *
135
+   * @return \Symfony\Bundle\DoctrineBundle\Registry
136
+   */
137
+  protected function getDoctrine()
138
+  {
139
+    return $this->client->getContainer()->get('doctrine');
140
+  }
141
+  
142
+  /**
143
+   * Test l'existance d'un element
144
+   * 
145
+   * @param string $filter 
146
+   */
147
+  protected function exist($filter)
148
+  {
149
+    $this->assertTrue($this->crawler->filter($filter)->count() > 0);
150
+  }
151
+  
152
+  /**
153
+   * Retourne un objet lien
154
+   * 
155
+   * @param string $filter
156
+   * @return \Symfony\Component\DomCrawler\Link
157
+   */
158
+  protected function selectLink($filter)
159
+  {
160
+    return $this->crawler->filter($filter)->eq(1)->link();
161
+  }
162
+  
163
+//  /**
164
+//   * Clique sur un link
165
+//   *  
166
+//   * @param type $link 
167
+//   */
168
+//  protected function click($link)
169
+//  {
170
+//    $this->crawler = $this->client->click($link);
171
+//  }
172
+  
173
+  /**
174
+   * Retourne un formulaire
175
+   * 
176
+   * @param string $filter
177
+   * @return \Symfony\Component\DomCrawler\Form 
178
+   */
179
+  protected function selectForm($filter)
180
+  {
181
+    return $this->crawler->filter($filter)->form();
182
+  }
183
+  
184
+  /**
185
+   * Soumet un formulaire
186
+   * 
187
+   * @param type $form 
188
+   */
189
+  protected function submit($form)
190
+  {
191
+    $this->crawler = $this->client->submit($form);
192
+  }
193
+  
194
+  /**
195
+   * Ordonne au client de suivre la redirection
196
+   */
197
+  protected function followRedirection()
198
+  {
199
+    $this->crawler = $this->client->followRedirect();
200
+  }
201
+  
202
+  /**
203
+   * Contrôle le Codestatus de la réponse
204
+   * 
205
+   * @param int $code 
206
+   */
207
+  protected function isStatusCode($code)
208
+  {
209
+    $this->assertEquals($code, $this->client->getResponse()->getStatusCode());
210
+  }
211
+  
212
+  /**
213
+   * Contrôle que le CodeStatus de la Response correspond bien a celle d'une
214
+   *  redirection
215
+   */
216
+  protected function isResponseRedirection()
217
+  {
218
+    $this->client->getResponse()->isRedirection();
219
+  }
220
+  
221
+  /**
222
+   * Contrôle que le CodeStatus de la Response correspond bien a celle d'un Ok
223
+   */
224
+  protected function isResponseSuccess()
225
+  {
226
+    $this->client->getResponse()->isSuccessful();
227
+  }
228
+}

+ 40 - 0
src/Muzich/CoreBundle/lib/Test/Client.php View File

@@ -0,0 +1,40 @@
1
+<?php
2
+
3
+namespace Muzich\CoreBundle\lib\Test;
4
+
5
+use Symfony\Bundle\FrameworkBundle\Client as BaseClient;
6
+
7
+class Client extends BaseClient
8
+{
9
+  static protected $connection;
10
+  protected $requested;
11
+
12
+    protected function doRequest($request)
13
+    {
14
+        if ($this->requested) {
15
+            $this->kernel->shutdown();
16
+            $this->kernel->boot();
17
+        }
18
+
19
+        $this->injectConnection();
20
+        $this->requested = true;
21
+
22
+        return $this->kernel->handle($request);
23
+    }
24
+
25
+    protected function injectConnection()
26
+    {
27
+        if (null === self::$connection) {
28
+            self::$connection = $this->getContainer()->get('doctrine.dbal.default_connection');
29
+        } else {
30
+            if (! $this->requested) {
31
+                self::$connection->rollback();
32
+            }
33
+            $this->getContainer()->set('doctrine.dbal.default_connection', self::$connection);
34
+        }
35
+
36
+        if (! $this->requested) {
37
+            self::$connection->beginTransaction();
38
+        }
39
+    }
40
+}