@@ -34,26 +34,61 @@ class ResponseTest extends TestCase
34
34
/**
35
35
* @dataProvider provideJson
36
36
*/
37
- public function testFromJson ($ json , $ success , $ errorCodes , $ hostname )
37
+ public function testFromJson ($ json , $ success , $ errorCodes , $ hostname, $ challengeTs , $ apkPackageName , $ score , $ action )
38
38
{
39
39
$ response = Response::fromJson ($ json );
40
40
$ this ->assertEquals ($ success , $ response ->isSuccess ());
41
41
$ this ->assertEquals ($ errorCodes , $ response ->getErrorCodes ());
42
42
$ this ->assertEquals ($ hostname , $ response ->getHostname ());
43
+ $ this ->assertEquals ($ challengeTs , $ response ->getChallengeTs ());
44
+ $ this ->assertEquals ($ apkPackageName , $ response ->getApkPackageName ());
45
+ $ this ->assertEquals ($ score , $ response ->getScore ());
46
+ $ this ->assertEquals ($ action , $ response ->getAction ());
43
47
}
44
48
45
49
public function provideJson ()
46
50
{
47
51
return array (
48
- array ('{"success": true} ' , true , array (), null ),
49
- array ('{"success": true, "hostname": "google.com"} ' , true , array (), 'google.com ' ),
50
- array ('{"success": false, "error-codes": ["test"]} ' , false , array ('test ' ), null ),
51
- array ('{"success": false, "error-codes": ["test"], "hostname": "google.com"} ' , false , array ('test ' ), 'google.com ' ),
52
- array ('{"success": true, "error-codes": ["test"]} ' , true , array (), null ),
53
- array ('{"success": true, "error-codes": ["test"], "hostname": "google.com"} ' , true , array (), 'google.com ' ),
54
- array ('{"success": false} ' , false , array (), null ),
55
- array ('{"success": false, "hostname": "google.com"} ' , false , array (), 'google.com ' ),
56
- array ('BAD JSON ' , false , array ('invalid-json ' ), null ),
52
+ array (
53
+ '{"success": true} ' ,
54
+ true , array (), null , null , null , null , null ,
55
+ ),
56
+ array (
57
+ '{"success": true, "hostname": "google.com"} ' ,
58
+ true , array (), 'google.com ' , null , null , null , null ,
59
+ ),
60
+ array (
61
+ '{"success": false, "error-codes": ["test"]} ' ,
62
+ false , array ('test ' ), null , null , null , null , null ,
63
+ ),
64
+ array (
65
+ '{"success": false, "error-codes": ["test"], "hostname": "google.com"} ' ,
66
+ false , array ('test ' ), 'google.com ' , null , null , null , null ,
67
+ ),
68
+ array (
69
+ '{"success": false, "error-codes": ["test"], "hostname": "google.com", "challenge_ts": "timestamp", "apk_package_name": "apk", "score": "0.5", "action": "action"} ' ,
70
+ false , array ('test ' ), 'google.com ' , 'timestamp ' , 'apk ' , 0.5 , 'action ' ,
71
+ ),
72
+ array (
73
+ '{"success": true, "error-codes": ["test"]} ' ,
74
+ true , array (), null , null , null , null , null ,
75
+ ),
76
+ array (
77
+ '{"success": true, "error-codes": ["test"], "hostname": "google.com"} ' ,
78
+ true , array (), 'google.com ' , null , null , null , null ,
79
+ ),
80
+ array (
81
+ '{"success": false} ' ,
82
+ false , array (ReCaptcha::E_UNKNOWN_ERROR ), null , null , null , null , null ,
83
+ ),
84
+ array (
85
+ '{"success": false, "hostname": "google.com"} ' ,
86
+ false , array (ReCaptcha::E_UNKNOWN_ERROR ), 'google.com ' , null , null , null , null ,
87
+ ),
88
+ array (
89
+ 'BAD JSON ' ,
90
+ false , array (ReCaptcha::E_INVALID_JSON ), null , null , null , null , null ,
91
+ ),
57
92
);
58
93
}
59
94
@@ -84,27 +119,44 @@ public function testGetHostname()
84
119
$ this ->assertEquals ($ hostname , $ response ->getHostname ());
85
120
}
86
121
122
+ public function testGetChallengeTs ()
123
+ {
124
+ $ timestamp = 'timestamp ' ;
125
+ $ errorCodes = array ();
126
+ $ response = new Response (true , array (), 'hostname ' , $ timestamp );
127
+ $ this ->assertEquals ($ timestamp , $ response ->getChallengeTs ());
128
+ }
129
+
130
+ public function TestGetApkPackageName ()
131
+ {
132
+ $ apk = 'apk ' ;
133
+ $ response = new Response (true , array (), 'hostname ' , 'timestamp ' , 'apk ' );
134
+ $ this ->assertEquals ($ apk , $ response ->getApkPackageName ());
135
+ }
136
+
87
137
public function testGetScore ()
88
138
{
89
139
$ score = 0.5 ;
90
- $ response = new Response (true , array (), '' , $ score );
140
+ $ response = new Response (true , array (), 'hostname ' , ' timestamp ' , ' apk ' , $ score );
91
141
$ this ->assertEquals ($ score , $ response ->getScore ());
92
142
}
93
143
94
144
public function testGetAction ()
95
145
{
96
146
$ action = 'homepage ' ;
97
- $ response = new Response (true , array (), '' , 0.5 , $ action );
147
+ $ response = new Response (true , array (), 'hostname ' , ' timestamp ' , ' apk ' , ' 0.5 ' , ' homepage ' );
98
148
$ this ->assertEquals ($ action , $ response ->getAction ());
99
149
}
100
150
101
151
public function testToArray ()
102
152
{
103
- $ response = new Response (true , array (), 'hostname ' , 0.5 , 'homepage ' );
153
+ $ response = new Response (true , array (), 'hostname ' , ' timestamp ' , ' apk ' , ' 0.5 ' , 'homepage ' );
104
154
$ expected = array (
105
155
'success ' => true ,
106
156
'error-codes ' => array (),
107
157
'hostname ' => 'hostname ' ,
158
+ 'challenge_ts ' => 'timestamp ' ,
159
+ 'apk_package_name ' => 'apk ' ,
108
160
'score ' => 0.5 ,
109
161
'action ' => 'homepage ' ,
110
162
);
0 commit comments