DumbTest.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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_Captcha
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2012 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. // Call Zend_Captcha_DumbTest::main() if this source file is executed directly.
  23. if (!defined("PHPUnit_MAIN_METHOD")) {
  24. define("PHPUnit_MAIN_METHOD", "Zend_Captcha_DumbTest::main");
  25. }
  26. require_once 'Zend/Form/Element/Captcha.php';
  27. require_once 'Zend/View.php';
  28. /**
  29. * @category Zend
  30. * @package Zend_Captcha
  31. * @subpackage UnitTests
  32. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  33. * @license http://framework.zend.com/license/new-bsd New BSD License
  34. * @group Zend_Captcha
  35. */
  36. class Zend_Captcha_DumbTest extends PHPUnit_Framework_TestCase
  37. {
  38. /**
  39. * Runs the test methods of this class.
  40. *
  41. * @return void
  42. */
  43. public static function main()
  44. {
  45. $suite = new PHPUnit_Framework_TestSuite("Zend_Captcha_DumbTest");
  46. $result = PHPUnit_TextUI_TestRunner::run($suite);
  47. }
  48. /**
  49. * Sets up the fixture, for example, open a network connection.
  50. * This method is called before a test is executed.
  51. *
  52. * @return void
  53. */
  54. public function setUp()
  55. {
  56. if (isset($this->word)) {
  57. unset($this->word);
  58. }
  59. $this->element = new Zend_Form_Element_Captcha(
  60. 'captchaD',
  61. array(
  62. 'captcha' => array(
  63. 'Dumb',
  64. 'sessionClass' => 'Zend_Captcha_DumbTest_SessionContainer'
  65. )
  66. )
  67. );
  68. $this->captcha = $this->element->getCaptcha();
  69. }
  70. /**
  71. * Tears down the fixture, for example, close a network connection.
  72. * This method is called after a test is executed.
  73. *
  74. * @return void
  75. */
  76. public function tearDown()
  77. {
  78. }
  79. public function testRendersWordInReverse()
  80. {
  81. $id = $this->captcha->generate('test');
  82. $word = $this->captcha->getWord();
  83. $html = $this->captcha->render(new Zend_View);
  84. $this->assertContains(strrev($word), $html);
  85. $this->assertNotContains($word, $html);
  86. }
  87. }
  88. class Zend_Captcha_DumbTest_SessionContainer
  89. {
  90. protected static $_word;
  91. public function __get($name)
  92. {
  93. if ('word' == $name) {
  94. return self::$_word;
  95. }
  96. return null;
  97. }
  98. public function __set($name, $value)
  99. {
  100. if ('word' == $name) {
  101. self::$_word = $value;
  102. } else {
  103. $this->$name = $value;
  104. }
  105. }
  106. public function __isset($name)
  107. {
  108. if (('word' == $name) && (null !== self::$_word)) {
  109. return true;
  110. }
  111. return false;
  112. }
  113. public function __call($method, $args)
  114. {
  115. switch ($method) {
  116. case 'setExpirationHops':
  117. case 'setExpirationSeconds':
  118. $this->$method = array_shift($args);
  119. break;
  120. default:
  121. }
  122. }
  123. }
  124. // Call Zend_Captcha_DumbTest::main() if this source file is executed directly.
  125. if (PHPUnit_MAIN_METHOD == "Zend_Captcha_DumbTest::main") {
  126. Zend_Captcha_DumbTest::main();
  127. }