You are here

class ResponseTest in reCAPTCHA 6.2

Same name and namespace in other branches
  1. 7.2 recaptcha-php/tests/ReCaptcha/ResponseTest.php \ReCaptcha\ResponseTest

Hierarchy

  • class \ReCaptcha\ResponseTest extends \ReCaptcha\PHPUnit_Framework_TestCase

Expanded class hierarchy of ResponseTest

File

recaptcha-php/tests/ReCaptcha/ResponseTest.php, line 29

Namespace

ReCaptcha
View source
class ResponseTest extends \PHPUnit_Framework_TestCase {

  /**
   * @dataProvider provideJson
   */
  public function testFromJson($json, $success, $errorCodes) {
    $response = Response::fromJson($json);
    $this
      ->assertEquals($success, $response
      ->isSuccess());
    $this
      ->assertEquals($errorCodes, $response
      ->getErrorCodes());
  }
  public function provideJson() {
    return array(
      array(
        '{"success": true}',
        true,
        array(),
      ),
      array(
        '{"success": false, "error-codes": ["test"]}',
        false,
        array(
          'test',
        ),
      ),
      array(
        '{"success": true, "error-codes": ["test"]}',
        true,
        array(),
      ),
      array(
        '{"success": false}',
        false,
        array(),
      ),
      array(
        'BAD JSON',
        false,
        array(
          'invalid-json',
        ),
      ),
    );
  }
  public function testIsSuccess() {
    $response = new Response(true);
    $this
      ->assertTrue($response
      ->isSuccess());
    $response = new Response(false);
    $this
      ->assertFalse($response
      ->isSuccess());
  }
  public function testGetErrorCodes() {
    $errorCodes = array(
      'test',
    );
    $response = new Response(true, $errorCodes);
    $this
      ->assertEquals($errorCodes, $response
      ->getErrorCodes());
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ResponseTest::provideJson public function
ResponseTest::testFromJson public function @dataProvider provideJson
ResponseTest::testGetErrorCodes public function
ResponseTest::testIsSuccess public function