cvs: pear /HTML_QuickForm2/QuickForm2 Element.php /HTML_QuickForm2/QuickForm2/Element Input.php /HTML_QuickForm2/tests/QuickForm2 AllTests.php
/HTML_QuickForm2/tests/QuickForm2/Element AllTests.php InputTest.php
| From: | Alexey Borzov | Date: | Mon, 04 Sep 2006 18:40:30 +0000 |
| Subject: | cvs: pear /HTML_QuickForm2/QuickForm2 Element.php /HTML_QuickForm2/QuickForm2/Element Input.php /HTML_QuickForm2/tests/QuickForm2 AllTests.php /HTML_QuickForm2/tests/QuickForm2/Element AllTests.php InputTest.php |
||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-41978@lists.php.net to get a copy of this message | ||
avb Mon Sep 4 18:40:30 2006 UTC
Added files:
/pear/HTML_QuickForm2/QuickForm2/Element Input.php
/pear/HTML_QuickForm2/tests/QuickForm2/Element AllTests.php
InputTest.php
Modified files:
/pear/HTML_QuickForm2/QuickForm2 Element.php
/pear/HTML_QuickForm2/tests/QuickForm2 AllTests.php
Log:
+ HTML_QuickForm2_Element_Input class with unit tests
http://cvs.php.net/viewvc.cgi/pear/HTML_QuickForm2/QuickForm2/Element.php?r1=1.1&r2=1.2&diff_format=u Index: pear/HTML_QuickForm2/QuickForm2/Element.php diff -u pear/HTML_QuickForm2/QuickForm2/Element.php:1.1 pear/HTML_QuickForm2/QuickForm2/Element.php:1.2 --- pear/HTML_QuickForm2/QuickForm2/Element.php:1.1 Fri Jul 7 15:29:47 2006 +++ pear/HTML_QuickForm2/QuickForm2/Element.php Mon Sep 4 18:40:30 2006 @@ -39,7 +39,7 @@ * @author Alexey Borzov <avb@php.net> * @author Bertrand Mansion <golgote@mamasam.com> * @license http://opensource.org/licenses/bsd-license.php New BSD License - * @version CVS: $Id: Element.php,v 1.1 2006/07/07 15:29:47 avb Exp $ + * @version CVS: $Id: Element.php,v 1.2 2006/09/04 18:40:30 avb Exp $ * @link http://pear.php.net/package/HTML_QuickForm2 */ @@ -111,5 +111,37 @@ } $this->attributes['id'] = (string)$id; } + + /** + * Generates hidden form field containing the element's value + * + * This is used to pass the frozen element's value if 'persistent freeze' + * feature is on + * + * @return string + */ + protected function getPersistentData() + { + if (!$this->persistent) { + return ''; + } + return '<input' . self::getAttributesString(array( + 'type' => 'hidden', + 'name' => $this->getName(), + 'value' => $this->getValue(), + 'id' => $this->getId() + )) . ' />'; + } + + /** + * Returns the field's value without HTML tags + * @return string + */ + protected function getFrozenHtml() + { + $value = $this->getValue(); + return (('' != $value)? htmlspecialchars($value, ENT_QUOTES, self::getOption('encoding')): '') . + $this->getPersistentData(); + } } ?> http://cvs.php.net/viewvc.cgi/pear/HTML_QuickForm2/tests/QuickForm2/AllTests.php?r1=1.3&r2=1.4&diff_format=u Index: pear/HTML_QuickForm2/tests/QuickForm2/AllTests.php diff -u pear/HTML_QuickForm2/tests/QuickForm2/AllTests.php:1.3 pear/HTML_QuickForm2/tests/QuickForm2/AllTests.php:1.4 --- pear/HTML_QuickForm2/tests/QuickForm2/AllTests.php:1.3 Fri Jul 7 15:29:47 2006 +++ pear/HTML_QuickForm2/tests/QuickForm2/AllTests.php Mon Sep 4 18:40:30 2006 @@ -39,7 +39,7 @@ * @author Alexey Borzov <avb@php.net> * @author Bertrand Mansion <golgote@mamasam.com> * @license http://opensource.org/licenses/bsd-license.php New BSD License - * @version CVS: $Id: AllTests.php,v 1.3 2006/07/07 15:29:47 avb Exp $ + * @version CVS: $Id: AllTests.php,v 1.4 2006/09/04 18:40:30 avb Exp $ * @link http://pear.php.net/package/HTML_QuickForm2 */ @@ -54,6 +54,7 @@ require_once dirname(__FILE__) . '/FactoryTest.php'; require_once dirname(__FILE__) . '/AbstractElementTest.php'; require_once dirname(__FILE__) . '/ElementTest.php'; +require_once dirname(__FILE__) . '/Element/AllTests.php'; class QuickForm2_AllTests { @@ -69,6 +70,7 @@ $suite->addTestSuite('HTML_QuickForm2_FactoryTest'); $suite->addTestSuite('HTML_QuickForm2_AbstractElementTest'); $suite->addTestSuite('HTML_QuickForm2_ElementTest'); + $suite->addTest(QuickForm2_Element_AllTests::suite()); return $suite; } http://cvs.php.net/viewvc.cgi/pear/HTML_QuickForm2/QuickForm2/Element/Input.php?view=markup&rev=1.1 Index: pear/HTML_QuickForm2/QuickForm2/Element/Input.php +++ pear/HTML_QuickForm2/QuickForm2/Element/Input.php <?php /** * Base class for <input> elements * * PHP version 5 * * LICENSE: * * Copyright (c) 2006, Alexey Borzov <avb@php.net>, * Bertrand Mansion <golgote@mamasam.com> * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * The names of the authors may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * @category HTML * @package HTML_QuickForm2 * @author Alexey Borzov <avb@php.net> * @author Bertrand Mansion <golgote@mamasam.com> * @license http://opensource.org/licenses/bsd-license.php New BSD License * @version CVS: $Id: Input.php,v 1.1 2006/09/04 18:40:30 avb Exp $ * @link http://pear.php.net/package/HTML_QuickForm2 */ /** * Base class for simple HTML_QuickForm2 elements (not Containers) */ require_once 'HTML/QuickForm2/Element.php'; /** * Base class for <input> elements * * @category HTML * @package HTML_QuickForm2 * @author Alexey Borzov <avb@php.net> * @author Bertrand Mansion <golgote@mamasam.com> * @version Release: @package_version@ */ class HTML_QuickForm2_Element_Input extends HTML_QuickForm2_Element { /** * 'type' attribute should not be changeable * @var array */ protected $watchedAttributes = array('id', 'name', 'type'); protected function onAttributeChange($name, $value = null) { if ('type' == $name) { throw new HTML_QuickForm2_InvalidArgumentException( "Attribute 'type' is read-only" ); } parent::onAttributeChange($name, $value); } public function getType() { return $this->attributes['type']; } public function setValue($value) { $this->setAttribute('value', $value); } public function getValue() { return $this->getAttribute('value'); } public function toHtml() { if ($this->frozen) { return $this->getFrozenHtml(); } else { return '<input' . $this->getAttributes(true) . ' />'; } } } ?> http://cvs.php.net/viewvc.cgi/pear/HTML_QuickForm2/tests/QuickForm2/Element/AllTests.php?view=markup&rev=1.1 Index: pear/HTML_QuickForm2/tests/QuickForm2/Element/AllTests.php +++ pear/HTML_QuickForm2/tests/QuickForm2/Element/AllTests.php <?php /** * Unit tests for HTML_QuickForm2 package * * PHP version 5 * * LICENSE: * * Copyright (c) 2006, Alexey Borzov <avb@php.net>, * Bertrand Mansion <golgote@mamasam.com> * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * The names of the authors may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * @category HTML * @package HTML_QuickForm2 * @author Alexey Borzov <avb@php.net> * @author Bertrand Mansion <golgote@mamasam.com> * @license http://opensource.org/licenses/bsd-license.php New BSD License * @version CVS: $Id: AllTests.php,v 1.1 2006/09/04 18:40:30 avb Exp $ * @link http://pear.php.net/package/HTML_QuickForm2 */ if (!defined('PHPUnit2_MAIN_METHOD')) { define('PHPUnit2_MAIN_METHOD', 'QuickForm2_Element_AllTests::main'); } require_once 'PHPUnit2/Framework/TestSuite.php'; require_once 'PHPUnit2/TextUI/TestRunner.php'; require_once dirname(__FILE__) . '/InputTest.php'; class QuickForm2_Element_AllTests { public static function main() { PHPUnit2_TextUI_TestRunner::run(self::suite()); } public static function suite() { $suite = new PHPUnit2_Framework_TestSuite('HTML_QuickForm2 package - QuickForm2 - Element'); $suite->addTestSuite('HTML_QuickForm2_Element_InputTest'); return $suite; } } if (PHPUnit2_MAIN_METHOD == 'QuickForm2_Element_AllTests::main') { QuickForm2_Element_AllTests::main(); } ?> http://cvs.php.net/viewvc.cgi/pear/HTML_QuickForm2/tests/QuickForm2/Element/InputTest.php?view=markup&rev=1.1 Index: pear/HTML_QuickForm2/tests/QuickForm2/Element/InputTest.php +++ pear/HTML_QuickForm2/tests/QuickForm2/Element/InputTest.php <?php /** * Unit tests for HTML_QuickForm2 package * * PHP version 5 * * LICENSE: * * Copyright (c) 2006, Alexey Borzov <avb@php.net>, * Bertrand Mansion <golgote@mamasam.com> * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * The names of the authors may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * @category HTML * @package HTML_QuickForm2 * @author Alexey Borzov <avb@php.net> * @license http://opensource.org/licenses/bsd-license.php New BSD License * @version CVS: $Id: InputTest.php,v 1.1 2006/09/04 18:40:30 avb Exp $ * @link http://pear.php.net/package/HTML_QuickForm2 */ /** * Class for <input> elements */ require_once 'HTML/QuickForm2/Element/Input.php'; /** * PHPUnit2 Test Case */ require_once 'PHPUnit2/Framework/TestCase.php'; /** * We need to set the element's type */ class HTML_QuickForm2_Element_InputImpl extends HTML_QuickForm2_Element_Input { public function __construct($name = null, $options = null, $label = null, $attributes = null) { parent::__construct($name, $options, $label, $attributes); $this->attributes['type'] = 'concrete'; } } /** * Unit test for HTML_QuickForm2_Element_Input class */ class HTML_QuickForm2_Element_InputTest extends PHPUnit2_Framework_TestCase { public function testTypeAttributeIsReadonly() { $obj = new HTML_QuickForm2_Element_InputImpl(); try { $obj->removeAttribute('type'); } catch (HTML_QuickForm2_InvalidArgumentException $e) { $this->assertEquals("Attribute 'type' is read-only", $e->getMessage()); try { $obj->setAttribute('type', 'bogus'); } catch (HTML_QuickForm2_InvalidArgumentException $e) { $this->assertEquals("Attribute 'type' is read-only", $e->getMessage()); return; } } $this->fail('Expected HTML_QuickForm2_InvalidArgumentException was not thrown'); } public function testCanSetValue() { $obj = new HTML_QuickForm2_Element_InputImpl(); $obj->setValue('foo'); $this->assertEquals($obj->getValue(), 'foo'); $obj->setAttribute('value', 'bar'); $this->assertEquals($obj->getValue(), 'bar'); } public function testHtmlGeneration() { $obj = new HTML_QuickForm2_Element_InputImpl(); $this->assertRegExp('!<input[^>]*type="concrete"[^>]*/>!', $obj->toHtml()); } public function testFrozenHtmlGeneration() { $obj = new HTML_QuickForm2_Element_InputImpl('test'); $obj->setValue('bar'); $obj->toggleFrozen(true); $obj->persistentFreeze(false); $this->assertNotRegExp('/[<>]/', $obj->toHtml()); $this->assertRegExp('/bar/', $obj->toHtml()); $obj->persistentFreeze(true); $this->assertRegExp('!<input[^>]*type="hidden"[^>]*/>!', $obj->toHtml()); } } ?>
http://cvs.php.net/viewvc.cgi/pear/HTML_QuickForm2/QuickForm2/Element.php?r1=1.1&r2=1.2&diff_format=u Index: pear/HTML_QuickForm2/QuickForm2/Element.php diff -u pear/HTML_QuickForm2/QuickForm2/Element.php:1.1 pear/HTML_QuickForm2/QuickForm2/Element.php:1.2 --- pear/HTML_QuickForm2/QuickForm2/Element.php:1.1 Fri Jul 7 15:29:47 2006 +++ pear/HTML_QuickForm2/QuickForm2/Element.php Mon Sep 4 18:40:30 2006 @@ -39,7 +39,7 @@ * @author Alexey Borzov <avb@php.net> * @author Bertrand Mansion <golgote@mamasam.com> * @license http://opensource.org/licenses/bsd-license.php New BSD License - * @version CVS: $Id: Element.php,v 1.1 2006/07/07 15:29:47 avb Exp $ + * @version CVS: $Id: Element.php,v 1.2 2006/09/04 18:40:30 avb Exp $ * @link http://pear.php.net/package/HTML_QuickForm2 */ @@ -111,5 +111,37 @@ } $this->attributes['id'] = (string)$id; } + + /** + * Generates hidden form field containing the element's value + * + * This is used to pass the frozen element's value if 'persistent freeze' + * feature is on + * + * @return string + */ + protected function getPersistentData() + { + if (!$this->persistent) { + return ''; + } + return '<input' . self::getAttributesString(array( + 'type' => 'hidden', + 'name' => $this->getName(), + 'value' => $this->getValue(), + 'id' => $this->getId() + )) . ' />'; + } + + /** + * Returns the field's value without HTML tags + * @return string + */ + protected function getFrozenHtml() + { + $value = $this->getValue(); + return (('' != $value)? htmlspecialchars($value, ENT_QUOTES, self::getOption('encoding')): '') . + $this->getPersistentData(); + } } ?> http://cvs.php.net/viewvc.cgi/pear/HTML_QuickForm2/tests/QuickForm2/AllTests.php?r1=1.3&r2=1.4&diff_format=u Index: pear/HTML_QuickForm2/tests/QuickForm2/AllTests.php diff -u pear/HTML_QuickForm2/tests/QuickForm2/AllTests.php:1.3 pear/HTML_QuickForm2/tests/QuickForm2/AllTests.php:1.4 --- pear/HTML_QuickForm2/tests/QuickForm2/AllTests.php:1.3 Fri Jul 7 15:29:47 2006 +++ pear/HTML_QuickForm2/tests/QuickForm2/AllTests.php Mon Sep 4 18:40:30 2006 @@ -39,7 +39,7 @@ * @author Alexey Borzov <avb@php.net> * @author Bertrand Mansion <golgote@mamasam.com> * @license http://opensource.org/licenses/bsd-license.php New BSD License - * @version CVS: $Id: AllTests.php,v 1.3 2006/07/07 15:29:47 avb Exp $ + * @version CVS: $Id: AllTests.php,v 1.4 2006/09/04 18:40:30 avb Exp $ * @link http://pear.php.net/package/HTML_QuickForm2 */ @@ -54,6 +54,7 @@ require_once dirname(__FILE__) . '/FactoryTest.php'; require_once dirname(__FILE__) . '/AbstractElementTest.php'; require_once dirname(__FILE__) . '/ElementTest.php'; +require_once dirname(__FILE__) . '/Element/AllTests.php'; class QuickForm2_AllTests { @@ -69,6 +70,7 @@ $suite->addTestSuite('HTML_QuickForm2_FactoryTest'); $suite->addTestSuite('HTML_QuickForm2_AbstractElementTest'); $suite->addTestSuite('HTML_QuickForm2_ElementTest'); + $suite->addTest(QuickForm2_Element_AllTests::suite()); return $suite; } http://cvs.php.net/viewvc.cgi/pear/HTML_QuickForm2/QuickForm2/Element/Input.php?view=markup&rev=1.1 Index: pear/HTML_QuickForm2/QuickForm2/Element/Input.php +++ pear/HTML_QuickForm2/QuickForm2/Element/Input.php <?php /** * Base class for <input> elements * * PHP version 5 * * LICENSE: * * Copyright (c) 2006, Alexey Borzov <avb@php.net>, * Bertrand Mansion <golgote@mamasam.com> * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * The names of the authors may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * @category HTML * @package HTML_QuickForm2 * @author Alexey Borzov <avb@php.net> * @author Bertrand Mansion <golgote@mamasam.com> * @license http://opensource.org/licenses/bsd-license.php New BSD License * @version CVS: $Id: Input.php,v 1.1 2006/09/04 18:40:30 avb Exp $ * @link http://pear.php.net/package/HTML_QuickForm2 */ /** * Base class for simple HTML_QuickForm2 elements (not Containers) */ require_once 'HTML/QuickForm2/Element.php'; /** * Base class for <input> elements * * @category HTML * @package HTML_QuickForm2 * @author Alexey Borzov <avb@php.net> * @author Bertrand Mansion <golgote@mamasam.com> * @version Release: @package_version@ */ class HTML_QuickForm2_Element_Input extends HTML_QuickForm2_Element { /** * 'type' attribute should not be changeable * @var array */ protected $watchedAttributes = array('id', 'name', 'type'); protected function onAttributeChange($name, $value = null) { if ('type' == $name) { throw new HTML_QuickForm2_InvalidArgumentException( "Attribute 'type' is read-only" ); } parent::onAttributeChange($name, $value); } public function getType() { return $this->attributes['type']; } public function setValue($value) { $this->setAttribute('value', $value); } public function getValue() { return $this->getAttribute('value'); } public function toHtml() { if ($this->frozen) { return $this->getFrozenHtml(); } else { return '<input' . $this->getAttributes(true) . ' />'; } } } ?> http://cvs.php.net/viewvc.cgi/pear/HTML_QuickForm2/tests/QuickForm2/Element/AllTests.php?view=markup&rev=1.1 Index: pear/HTML_QuickForm2/tests/QuickForm2/Element/AllTests.php +++ pear/HTML_QuickForm2/tests/QuickForm2/Element/AllTests.php <?php /** * Unit tests for HTML_QuickForm2 package * * PHP version 5 * * LICENSE: * * Copyright (c) 2006, Alexey Borzov <avb@php.net>, * Bertrand Mansion <golgote@mamasam.com> * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * The names of the authors may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * @category HTML * @package HTML_QuickForm2 * @author Alexey Borzov <avb@php.net> * @author Bertrand Mansion <golgote@mamasam.com> * @license http://opensource.org/licenses/bsd-license.php New BSD License * @version CVS: $Id: AllTests.php,v 1.1 2006/09/04 18:40:30 avb Exp $ * @link http://pear.php.net/package/HTML_QuickForm2 */ if (!defined('PHPUnit2_MAIN_METHOD')) { define('PHPUnit2_MAIN_METHOD', 'QuickForm2_Element_AllTests::main'); } require_once 'PHPUnit2/Framework/TestSuite.php'; require_once 'PHPUnit2/TextUI/TestRunner.php'; require_once dirname(__FILE__) . '/InputTest.php'; class QuickForm2_Element_AllTests { public static function main() { PHPUnit2_TextUI_TestRunner::run(self::suite()); } public static function suite() { $suite = new PHPUnit2_Framework_TestSuite('HTML_QuickForm2 package - QuickForm2 - Element'); $suite->addTestSuite('HTML_QuickForm2_Element_InputTest'); return $suite; } } if (PHPUnit2_MAIN_METHOD == 'QuickForm2_Element_AllTests::main') { QuickForm2_Element_AllTests::main(); } ?> http://cvs.php.net/viewvc.cgi/pear/HTML_QuickForm2/tests/QuickForm2/Element/InputTest.php?view=markup&rev=1.1 Index: pear/HTML_QuickForm2/tests/QuickForm2/Element/InputTest.php +++ pear/HTML_QuickForm2/tests/QuickForm2/Element/InputTest.php <?php /** * Unit tests for HTML_QuickForm2 package * * PHP version 5 * * LICENSE: * * Copyright (c) 2006, Alexey Borzov <avb@php.net>, * Bertrand Mansion <golgote@mamasam.com> * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * The names of the authors may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * @category HTML * @package HTML_QuickForm2 * @author Alexey Borzov <avb@php.net> * @license http://opensource.org/licenses/bsd-license.php New BSD License * @version CVS: $Id: InputTest.php,v 1.1 2006/09/04 18:40:30 avb Exp $ * @link http://pear.php.net/package/HTML_QuickForm2 */ /** * Class for <input> elements */ require_once 'HTML/QuickForm2/Element/Input.php'; /** * PHPUnit2 Test Case */ require_once 'PHPUnit2/Framework/TestCase.php'; /** * We need to set the element's type */ class HTML_QuickForm2_Element_InputImpl extends HTML_QuickForm2_Element_Input { public function __construct($name = null, $options = null, $label = null, $attributes = null) { parent::__construct($name, $options, $label, $attributes); $this->attributes['type'] = 'concrete'; } } /** * Unit test for HTML_QuickForm2_Element_Input class */ class HTML_QuickForm2_Element_InputTest extends PHPUnit2_Framework_TestCase { public function testTypeAttributeIsReadonly() { $obj = new HTML_QuickForm2_Element_InputImpl(); try { $obj->removeAttribute('type'); } catch (HTML_QuickForm2_InvalidArgumentException $e) { $this->assertEquals("Attribute 'type' is read-only", $e->getMessage()); try { $obj->setAttribute('type', 'bogus'); } catch (HTML_QuickForm2_InvalidArgumentException $e) { $this->assertEquals("Attribute 'type' is read-only", $e->getMessage()); return; } } $this->fail('Expected HTML_QuickForm2_InvalidArgumentException was not thrown'); } public function testCanSetValue() { $obj = new HTML_QuickForm2_Element_InputImpl(); $obj->setValue('foo'); $this->assertEquals($obj->getValue(), 'foo'); $obj->setAttribute('value', 'bar'); $this->assertEquals($obj->getValue(), 'bar'); } public function testHtmlGeneration() { $obj = new HTML_QuickForm2_Element_InputImpl(); $this->assertRegExp('!<input[^>]*type="concrete"[^>]*/>!', $obj->toHtml()); } public function testFrozenHtmlGeneration() { $obj = new HTML_QuickForm2_Element_InputImpl('test'); $obj->setValue('bar'); $obj->toggleFrozen(true); $obj->persistentFreeze(false); $this->assertNotRegExp('/[<>]/', $obj->toHtml()); $this->assertRegExp('/bar/', $obj->toHtml()); $obj->persistentFreeze(true); $this->assertRegExp('!<input[^>]*type="hidden"[^>]*/>!', $obj->toHtml()); } } ?>