@@ -19,13 +19,14 @@ class CurlHelpers extends Helper
19
19
*
20
20
* @param string $url
21
21
* @param string $expectedString
22
+ * @param string $formKey
22
23
* @return void
23
24
*
24
25
*/
25
- public function assertCurlResponseContainsString ($ url , $ expectedString ): void
26
+ public function assertCurlResponseContainsString ($ url , $ expectedString, $ formKey = null ): void
26
27
{
27
28
$ cookie = $ this ->getCookie ('admin ' );
28
- $ curlResponse = $ this ->getCurlResponse ($ url , $ cookie );
29
+ $ curlResponse = $ this ->getCurlResponse ($ url , $ cookie, $ formKey );
29
30
$ this ->assertStringContainsString ($ expectedString , $ curlResponse );
30
31
}
31
32
@@ -34,29 +35,31 @@ public function assertCurlResponseContainsString($url, $expectedString): void
34
35
*
35
36
* @param string $url
36
37
* @param string $cookie
38
+ * @param string $formKey
37
39
* @return string
38
40
*
39
41
*/
40
- public function getCurlResponse ($ url , $ cookie ): string
42
+ public function getCurlResponse ($ url , $ cookie = null , $ formKey = null ): string
41
43
{
42
- try {
43
- // Start Session
44
- $ session = curl_init ($ url );
44
+ // Start Session
45
+ $ session = curl_init ($ url );
45
46
46
- // Set Options
47
- curl_setopt ($ session , CURLOPT_COOKIE , $ cookie );
48
- curl_setopt ($ session , CURLOPT_HEADER , false );
49
- curl_setopt ($ session , CURLOPT_RETURNTRANSFER , true );
50
- curl_setopt ($ session , CURLOPT_FOLLOWLOCATION , true );
47
+ // Set Options
48
+ if ($ formKey ) {
49
+ $ data = [
50
+ 'form_key ' => $ formKey
51
+ ];
52
+ curl_setopt ($ session , CURLOPT_POST , true );
53
+ curl_setopt ($ session , CURLOPT_POSTFIELDS , $ data );
54
+ }
55
+ curl_setopt ($ session , CURLOPT_COOKIE , $ cookie );
56
+ curl_setopt ($ session , CURLOPT_RETURNTRANSFER , true );
51
57
52
- // Execute
53
- $ response = curl_exec ($ session );
54
- curl_close ($ session );
58
+ // Execute
59
+ $ response = curl_exec ($ session );
60
+ curl_close ($ session );
55
61
56
- return $ response ;
57
- } catch (\Exception $ exception ) {
58
- $ this ->fail ($ exception ->getMessage ());
59
- }
62
+ return $ response ;
60
63
}
61
64
62
65
/**
@@ -75,6 +78,7 @@ public function getCookie($cookieName = 'admin'): string
75
78
return $ cookieName . '= ' . $ cookieValue ;
76
79
} catch (\Exception $ exception ) {
77
80
$ this ->fail ($ exception ->getMessage ());
81
+ return '' ;
78
82
}
79
83
}
80
84
}
0 commit comments