2
0

ResponseTest.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. * @group Zend_Service
  35. * @group Zend_Service_ReCaptcha
  36. */
  37. class Zend_Service_ReCaptcha_ResponseTest extends PHPUnit_Framework_TestCase
  38. {
  39. protected $_response = null;
  40. public function setUp() {
  41. $this->_response = new Zend_Service_ReCaptcha_Response();
  42. }
  43. public function testSetAndGet() {
  44. /* Set and get status */
  45. $status = 'true';
  46. $this->_response->setStatus($status);
  47. $this->assertSame(true, $this->_response->getStatus());
  48. $status = 'false';
  49. $this->_response->setStatus($status);
  50. $this->assertSame(false, $this->_response->getStatus());
  51. /* Set and get the error code */
  52. $errorCode = 'foobar';
  53. $this->_response->setErrorCode($errorCode);
  54. $this->assertSame($errorCode, $this->_response->getErrorCode());
  55. }
  56. public function testIsValid() {
  57. $this->_response->setStatus('true');
  58. $this->assertSame(true, $this->_response->isValid());
  59. }
  60. public function testIsInvalid() {
  61. $this->_response->setStatus('false');
  62. $this->assertSame(false, $this->_response->isValid());
  63. }
  64. public function testSetFromHttpResponse() {
  65. $status = 'false';
  66. $errorCode = 'foobar';
  67. $responseBody = $status . "\n" . $errorCode;
  68. $httpResponse = new Zend_Http_Response(200, array('Content-Type' => 'text/html'), $responseBody);
  69. $this->_response->setFromHttpResponse($httpResponse);
  70. $this->assertSame(false, $this->_response->getStatus());
  71. $this->assertSame($errorCode, $this->_response->getErrorCode());
  72. }
  73. public function testConstructor() {
  74. $status = 'true';
  75. $errorCode = 'ok';
  76. $response = new Zend_Service_ReCaptcha_Response($status, $errorCode);
  77. $this->assertSame(true, $response->getStatus());
  78. $this->assertSame($errorCode, $response->getErrorCode());
  79. }
  80. public function testConstructorWithHttpResponse() {
  81. $status = 'false';
  82. $errorCode = 'foobar';
  83. $responseBody = $status . "\n" . $errorCode;
  84. $httpResponse = new Zend_Http_Response(200, array('Content-Type' => 'text/html'), $responseBody);
  85. $response = new Zend_Service_ReCaptcha_Response(null, null, $httpResponse);
  86. $this->assertSame(false, $response->getStatus());
  87. $this->assertSame($errorCode, $response->getErrorCode());
  88. }
  89. }