class CurlPostTest in reCAPTCHA 7.2
Same name and namespace in other branches
- 6.2 recaptcha-php/tests/ReCaptcha/RequestMethod/CurlPostTest.php \ReCaptcha\RequestMethod\CurlPostTest
Hierarchy
- class \ReCaptcha\RequestMethod\CurlPostTest extends \PHPUnit\Framework\TestCase
Expanded class hierarchy of CurlPostTest
File
- recaptcha-php/
tests/ ReCaptcha/ RequestMethod/ CurlPostTest.php, line 33
Namespace
ReCaptcha\RequestMethodView source
class CurlPostTest extends TestCase {
protected function setUp() {
if (!extension_loaded('curl')) {
$this
->markTestSkipped('The cURL extension is not available.');
}
}
public function testSubmit() {
$curl = $this
->getMockBuilder(\ReCaptcha\RequestMethod\Curl::class)
->disableOriginalConstructor()
->setMethods(array(
'init',
'setoptArray',
'exec',
'close',
))
->getMock();
$curl
->expects($this
->once())
->method('init')
->willReturn(new \stdClass());
$curl
->expects($this
->once())
->method('setoptArray')
->willReturn(true);
$curl
->expects($this
->once())
->method('exec')
->willReturn('RESPONSEBODY');
$curl
->expects($this
->once())
->method('close');
$pc = new CurlPost($curl);
$response = $pc
->submit(new RequestParameters("secret", "response"));
$this
->assertEquals('RESPONSEBODY', $response);
}
public function testOverrideSiteVerifyUrl() {
$url = 'OVERRIDE';
$curl = $this
->getMockBuilder(\ReCaptcha\RequestMethod\Curl::class)
->disableOriginalConstructor()
->setMethods(array(
'init',
'setoptArray',
'exec',
'close',
))
->getMock();
$curl
->expects($this
->once())
->method('init')
->with($url)
->willReturn(new \stdClass());
$curl
->expects($this
->once())
->method('setoptArray')
->willReturn(true);
$curl
->expects($this
->once())
->method('exec')
->willReturn('RESPONSEBODY');
$curl
->expects($this
->once())
->method('close');
$pc = new CurlPost($curl, $url);
$response = $pc
->submit(new RequestParameters("secret", "response"));
$this
->assertEquals('RESPONSEBODY', $response);
}
public function testConnectionFailureReturnsError() {
$curl = $this
->getMockBuilder(\ReCaptcha\RequestMethod\Curl::class)
->disableOriginalConstructor()
->setMethods(array(
'init',
'setoptArray',
'exec',
'close',
))
->getMock();
$curl
->expects($this
->once())
->method('init')
->willReturn(new \stdClass());
$curl
->expects($this
->once())
->method('setoptArray')
->willReturn(true);
$curl
->expects($this
->once())
->method('exec')
->willReturn(false);
$curl
->expects($this
->once())
->method('close');
$pc = new CurlPost($curl);
$response = $pc
->submit(new RequestParameters("secret", "response"));
$this
->assertEquals('{"success": false, "error-codes": ["' . ReCaptcha::E_CONNECTION_FAILED . '"]}', $response);
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CurlPostTest:: |
protected | function | ||
CurlPostTest:: |
public | function | ||
CurlPostTest:: |
public | function | ||
CurlPostTest:: |
public | function |