|
@@ -0,0 +1,133 @@
|
|
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
|
+ /**
|
|
34
|
+ * Generates a URL from the given parameters.
|
|
35
|
+ *
|
|
36
|
+ * @param string $route
|
|
37
|
+ * @param array $parameters
|
|
38
|
+ * @param boolean $absolute
|
|
39
|
+ *
|
|
40
|
+ * @return string (url generated)
|
|
41
|
+ */
|
|
42
|
+ protected function generateUrl($route, $parameters = array(), $absolute = false)
|
|
43
|
+ {
|
|
44
|
+ return $this->client->getContainer()->get('router')->generate($route, $parameters, $absolute);
|
|
45
|
+ }
|
|
46
|
+
|
|
47
|
+ /**
|
|
48
|
+ * Test l'existance d'un element
|
|
49
|
+ *
|
|
50
|
+ * @param string $filter
|
|
51
|
+ */
|
|
52
|
+ protected function exist($filter)
|
|
53
|
+ {
|
|
54
|
+ $this->assertTrue($this->crawler->filter($filter)->count() > 0);
|
|
55
|
+ }
|
|
56
|
+
|
|
57
|
+ /**
|
|
58
|
+ * Retourne un objet lien
|
|
59
|
+ *
|
|
60
|
+ * @param string $filter
|
|
61
|
+ * @return \Symfony\Component\DomCrawler\Link
|
|
62
|
+ */
|
|
63
|
+ protected function selectLink($filter)
|
|
64
|
+ {
|
|
65
|
+ return $this->crawler->filter($filter)->eq(1)->link();
|
|
66
|
+ }
|
|
67
|
+
|
|
68
|
+// /**
|
|
69
|
+// * Clique sur un link
|
|
70
|
+// *
|
|
71
|
+// * @param type $link
|
|
72
|
+// */
|
|
73
|
+// protected function click($link)
|
|
74
|
+// {
|
|
75
|
+// $this->crawler = $this->client->click($link);
|
|
76
|
+// }
|
|
77
|
+
|
|
78
|
+ /**
|
|
79
|
+ * Retourne un formulaire
|
|
80
|
+ *
|
|
81
|
+ * @param string $filter
|
|
82
|
+ * @return \Symfony\Component\DomCrawler\Form
|
|
83
|
+ */
|
|
84
|
+ protected function selectForm($filter)
|
|
85
|
+ {
|
|
86
|
+ return $this->crawler->filter($filter)->form();
|
|
87
|
+ }
|
|
88
|
+
|
|
89
|
+ /**
|
|
90
|
+ * Soumet un formulaire
|
|
91
|
+ *
|
|
92
|
+ * @param type $form
|
|
93
|
+ */
|
|
94
|
+ protected function submit($form)
|
|
95
|
+ {
|
|
96
|
+ $this->crawler = $this->client->submit($form);
|
|
97
|
+ }
|
|
98
|
+
|
|
99
|
+ /**
|
|
100
|
+ * Ordonne au client de suivre la redirection
|
|
101
|
+ */
|
|
102
|
+ protected function followRedirection()
|
|
103
|
+ {
|
|
104
|
+ $this->client->followRedirect();
|
|
105
|
+ }
|
|
106
|
+
|
|
107
|
+ /**
|
|
108
|
+ * Contrôle le Codestatus de la réponse
|
|
109
|
+ *
|
|
110
|
+ * @param int $code
|
|
111
|
+ */
|
|
112
|
+ protected function isStatusCode($code)
|
|
113
|
+ {
|
|
114
|
+ $this->assertEquals($code, $this->client->getResponse()->getStatusCode());
|
|
115
|
+ }
|
|
116
|
+
|
|
117
|
+ /**
|
|
118
|
+ * Contrôle que le CodeStatus de la Response correspond bien a celle d'une
|
|
119
|
+ * redirection
|
|
120
|
+ */
|
|
121
|
+ protected function isResponseRedirection()
|
|
122
|
+ {
|
|
123
|
+ $this->client->getResponse()->isRedirection();
|
|
124
|
+ }
|
|
125
|
+
|
|
126
|
+ /**
|
|
127
|
+ * Contrôle que le CodeStatus de la Response correspond bien a celle d'un Ok
|
|
128
|
+ */
|
|
129
|
+ protected function isResponseSuccess()
|
|
130
|
+ {
|
|
131
|
+ $this->client->getResponse()->isSuccessful();
|
|
132
|
+ }
|
|
133
|
+}
|