ResponseTest.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Service_ReCaptcha
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * Test helper
  24. */
  25. require_once dirname(__FILE__) . '/../../../TestHelper.php';
  26. /** @see Zend_Service_ReCaptcha_Response */
  27. require_once 'Zend/Service/ReCaptcha/Response.php';
  28. /**
  29. * @category Zend
  30. * @package Zend_Service_ReCaptcha
  31. * @subpackage UnitTests
  32. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  33. * @license http://framework.zend.com/license/new-bsd New BSD License
  34. */
  35. class Zend_Service_ReCaptcha_ResponseTest extends PHPUnit_Framework_TestCase
  36. {
  37. protected $_response = null;
  38. public function setUp() {
  39. $this->_response = new Zend_Service_ReCaptcha_Response();
  40. }
  41. public function testSetAndGet() {
  42. /* Set and get status */
  43. $status = 'true';
  44. $this->_response->setStatus($status);
  45. $this->assertSame(true, $this->_response->getStatus());
  46. $status = 'false';
  47. $this->_response->setStatus($status);
  48. $this->assertSame(false, $this->_response->getStatus());
  49. /* Set and get the error code */
  50. $errorCode = 'foobar';
  51. $this->_response->setErrorCode($errorCode);
  52. $this->assertSame($errorCode, $this->_response->getErrorCode());
  53. }
  54. public function testIsValid() {
  55. $this->_response->setStatus('true');
  56. $this->assertSame(true, $this->_response->isValid());
  57. }
  58. public function testIsInvalid() {
  59. $this->_response->setStatus('false');
  60. $this->assertSame(false, $this->_response->isValid());
  61. }
  62. public function testSetFromHttpResponse() {
  63. $status = 'false';
  64. $errorCode = 'foobar';
  65. $responseBody = $status . "\n" . $errorCode;
  66. $httpResponse = new Zend_Http_Response(200, array('Content-Type' => 'text/html'), $responseBody);
  67. $this->_response->setFromHttpResponse($httpResponse);
  68. $this->assertSame(false, $this->_response->getStatus());
  69. $this->assertSame($errorCode, $this->_response->getErrorCode());
  70. }
  71. public function testConstructor() {
  72. $status = 'true';
  73. $errorCode = 'ok';
  74. $response = new Zend_Service_ReCaptcha_Response($status, $errorCode);
  75. $this->assertSame(true, $response->getStatus());
  76. $this->assertSame($errorCode, $response->getErrorCode());
  77. }
  78. public function testConstructorWithHttpResponse() {
  79. $status = 'false';
  80. $errorCode = 'foobar';
  81. $responseBody = $status . "\n" . $errorCode;
  82. $httpResponse = new Zend_Http_Response(200, array('Content-Type' => 'text/html'), $responseBody);
  83. $response = new Zend_Service_ReCaptcha_Response(null, null, $httpResponse);
  84. $this->assertSame(false, $response->getStatus());
  85. $this->assertSame($errorCode, $response->getErrorCode());
  86. }
  87. }