RequestParametersTest.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * This is a PHP library that handles calling reCAPTCHA.
  4. *
  5. * BSD 3-Clause License
  6. * @copyright (c) 2019, Google Inc.
  7. * @link https://www.google.com/recaptcha
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions are met:
  12. * 1. Redistributions of source code must retain the above copyright notice, this
  13. * list of conditions and the following disclaimer.
  14. *
  15. * 2. Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. *
  19. * 3. Neither the name of the copyright holder nor the names of its
  20. * contributors may be used to endorse or promote products derived from
  21. * this software without specific prior written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  24. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  25. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  26. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  27. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  28. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  29. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  30. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  31. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  32. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. namespace ReCaptcha;
  35. use PHPUnit\Framework\TestCase;
  36. class RequestParametersTest extends Testcase
  37. {
  38. public function provideValidData()
  39. {
  40. return array(
  41. array('SECRET', 'RESPONSE', 'REMOTEIP', 'VERSION',
  42. array('secret' => 'SECRET', 'response' => 'RESPONSE', 'remoteip' => 'REMOTEIP', 'version' => 'VERSION'),
  43. 'secret=SECRET&response=RESPONSE&remoteip=REMOTEIP&version=VERSION'),
  44. array('SECRET', 'RESPONSE', null, null,
  45. array('secret' => 'SECRET', 'response' => 'RESPONSE'),
  46. 'secret=SECRET&response=RESPONSE'),
  47. );
  48. }
  49. /**
  50. * @dataProvider provideValidData
  51. */
  52. public function testToArray($secret, $response, $remoteIp, $version, $expectedArray, $expectedQuery)
  53. {
  54. $params = new RequestParameters($secret, $response, $remoteIp, $version);
  55. $this->assertEquals($params->toArray(), $expectedArray);
  56. }
  57. /**
  58. * @dataProvider provideValidData
  59. */
  60. public function testToQueryString($secret, $response, $remoteIp, $version, $expectedArray, $expectedQuery)
  61. {
  62. $params = new RequestParameters($secret, $response, $remoteIp, $version);
  63. $this->assertEquals($params->toQueryString(), $expectedQuery);
  64. }
  65. }