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.
16 * @package Zend_Captcha
17 * @subpackage UnitTests
18 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19 * @license http://framework.zend.com/license/new-bsd New BSD License
23 // Call Zend_Captcha_DumbTest::main() if this source file is executed directly.
24 if (!defined("PHPUnit_MAIN_METHOD")) {
25 define("PHPUnit_MAIN_METHOD", "Zend_Captcha_DumbTest::main");
28 require_once dirname(__FILE__
) . '/../../TestHelper.php';
30 require_once 'Zend/Form/Element/Captcha.php';
31 require_once 'Zend/View.php';
35 * @package Zend_Captcha
36 * @subpackage UnitTests
37 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
38 * @license http://framework.zend.com/license/new-bsd New BSD License
41 class Zend_Captcha_DumbTest
extends PHPUnit_Framework_TestCase
44 * Runs the test methods of this class.
48 public static function main()
50 $suite = new PHPUnit_Framework_TestSuite("Zend_Captcha_DumbTest");
51 $result = PHPUnit_TextUI_TestRunner
::run($suite);
55 * Sets up the fixture, for example, open a network connection.
56 * This method is called before a test is executed.
60 public function setUp()
62 if (isset($this->word
)) {
66 $this->element
= new Zend_Form_Element_Captcha(
71 'sessionClass' => 'Zend_Captcha_DumbTest_SessionContainer'
75 $this->captcha
= $this->element
->getCaptcha();
79 * Tears down the fixture, for example, close a network connection.
80 * This method is called after a test is executed.
84 public function tearDown()
88 public function testRendersWordInReverse()
90 $id = $this->captcha
->generate('test');
91 $word = $this->captcha
->getWord();
92 $html = $this->captcha
->render(new Zend_View
);
93 $this->assertContains(strrev($word), $html);
94 $this->assertNotContains($word, $html);
98 class Zend_Captcha_DumbTest_SessionContainer
100 protected static $_word;
102 public function __get($name)
104 if ('word' == $name) {
111 public function __set($name, $value)
113 if ('word' == $name) {
114 self
::$_word = $value;
116 $this->$name = $value;
120 public function __isset($name)
122 if (('word' == $name) && (null !== self
::$_word)) {
129 public function __call($method, $args)
132 case 'setExpirationHops':
133 case 'setExpirationSeconds':
134 $this->$method = array_shift($args);
141 // Call Zend_Captcha_DumbTest::main() if this source file is executed directly.
142 if (PHPUnit_MAIN_METHOD
== "Zend_Captcha_DumbTest::main") {
143 Zend_Captcha_DumbTest
::main();