cvs: pear /HTML_Common2 Common2.php package.xml package2.xml /HTML_Common2/tests HTML_Common2_Test.php
| From: | Alexey Borzov | Date: | Mon, 16 Oct 2006 13:06:46 +0000 |
| Subject: | cvs: pear /HTML_Common2 Common2.php package.xml package2.xml /HTML_Common2/tests HTML_Common2_Test.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-42590@lists.php.net to get a copy of this message | ||
avb Mon Oct 16 13:06:46 2006 UTC
Added files:
/pear/HTML_Common2 package2.xml
Removed files:
/pear/HTML_Common2 package.xml
Modified files:
/pear/HTML_Common2 Common2.php
/pear/HTML_Common2/tests HTML_Common2_Test.php
Log:
Prepare release 0.3.0 (full list of changes is in package2.xml)
http://cvs.php.net/viewvc.cgi/pear/HTML_Common2/Common2.php?r1=1.3&r2=1.4&diff_format=u Index: pear/HTML_Common2/Common2.php diff -u pear/HTML_Common2/Common2.php:1.3 pear/HTML_Common2/Common2.php:1.4 --- pear/HTML_Common2/Common2.php:1.3 Fri Jun 23 14:09:40 2006 +++ pear/HTML_Common2/Common2.php Mon Oct 16 13:06:45 2006 @@ -2,18 +2,43 @@ /** * HTML_Common2: port of HTML_Common package to PHP5 * - * LICENSE: This source file is subject to version 3.0 of the PHP license - * that is available through the world-wide-web at the following URI: - * http://www.php.net/license/3_0.txt. If you did not receive a copy of - * the PHP License and are unable to obtain it through the web, please - * send a note to license@php.net so we can mail you a copy immediately. + * PHP version 5 + * + * LICENSE: + * + * Copyright (c) 2004-2006, Alexey Borzov <avb@php.net> + * + * 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_Common2 * @author Alexey Borzov <avb@php.net> - * @copyright 2004, 2005, 2006 The PHP Group - * @license http://www.php.net/license/3_0.txt PHP License - * @version CVS: $Id: Common2.php,v 1.3 2006/06/23 14:09:40 avb Exp $ + * @license http://opensource.org/licenses/bsd-license.php New BSD License + * @version CVS: $Id: Common2.php,v 1.4 2006/10/16 13:06:45 avb Exp $ * @link http://pear.php.net/package/HTML_Common2 */ @@ -24,8 +49,10 @@ * attribute strings. Port of HTML_Common class for PHP4 originally written by * Adam Daniel with contributions from numerous other developers. * - * @version $Revision: 1.3 $ - * @author Alexey Borzov <avb@php.net> + * @category HTML + * @package HTML_Common2 + * @author Alexey Borzov <avb@php.net> + * @version Release: @package_version@ */ abstract class HTML_Common2 { @@ -58,15 +85,16 @@ /** * Global options for all elements generated by subclasses of HTML_Common2 * - * Known options are - * 'encoding': encoding used in htmlspecialchars() calls - * 'indent': string used to indent HTML elements - * 'linebreak': string used to indicate linebreak + * Preset options are + * - 'charset': charset parameter used in htmlspecialchars() calls, + * defaults to 'ISO-8859-1' + * - 'indent': string used to indent HTML elements, defaults to "\11" + * - 'linebreak': string used to indicate linebreak, defaults to "\12" * * @var array */ private static $_options = array( - 'encoding' => 'ISO-8859-1', + 'charset' => 'ISO-8859-1', 'indent' => "\11", 'linebreak' => "\12" ); @@ -139,15 +167,16 @@ { $prepared = array(); if (is_string($attributes)) { - $prepared = self::parseAttributes($attributes); + return self::parseAttributes($attributes); + } elseif (is_array($attributes)) { foreach ($attributes as $key => $value) { if (is_int($key)) { - $key = $value = strtolower($value); + $key = strtolower($value); + $prepared[$key] = $key; } else { - $key = strtolower($key); + $prepared[strtolower($key)] = (string)$value; } - $prepared[$key] = (string)$value; } } return $prepared; @@ -161,10 +190,7 @@ */ protected static function removeAttributeArray(&$attributes, $name) { - $name = strtolower($name); - if (isset($attributes[$name])) { - unset($attributes[$name]); - } + unset($attributes[strtolower($name)]); } /** @@ -177,9 +203,9 @@ { $str = ''; if (is_array($attributes)) { - $encoding = self::getOption('encoding'); + $charset = self::getOption('charset'); foreach ($attributes as $key => $value) { - $str .= ' ' . $key . '="' . htmlspecialchars($value, ENT_QUOTES, $encoding) . '"'; + $str .= ' ' . $key . '="' . htmlspecialchars($value, ENT_QUOTES, $charset) . '"'; } } return $str; @@ -210,7 +236,7 @@ if (in_array($name, $this->watchedAttributes)) { $this->onAttributeChange($name, $value); } else { - $this->attributes[$name] = $value; + $this->attributes[$name] = (string)$value; } } @@ -350,31 +376,13 @@ /** * Returns the HTML representation of the element - * - * @return string - */ - abstract public function toHtml(); - - /** - * A magic method to let the object work with echo and print constructs * - * @return string - * @see toHtml() - */ - public function __toString() - { - return $this->toHtml(); - } - - /** - * Displays the element + * This magic method allows using the instances of HTML_Common2 in string + * contexts * - * @deprecated Deprecated, using <code>echo $obj;</code> will work just as well + * @return string */ - public function display() - { - echo $this->toHtml(); - } + abstract public function __toString(); /** * Called if trying to change an attribute with name in $watchedAttributes http://cvs.php.net/viewvc.cgi/pear/HTML_Common2/tests/HTML_Common2_Test.php?r1=1.3&r2=1.4&diff_format=u Index: pear/HTML_Common2/tests/HTML_Common2_Test.php diff -u pear/HTML_Common2/tests/HTML_Common2_Test.php:1.3 pear/HTML_Common2/tests/HTML_Common2_Test.php:1.4 --- pear/HTML_Common2/tests/HTML_Common2_Test.php:1.3 Fri Jun 23 14:09:41 2006 +++ pear/HTML_Common2/tests/HTML_Common2_Test.php Mon Oct 16 13:06:46 2006 @@ -2,26 +2,82 @@ /** * Unit test suite for HTML_Common2 class * - * @author Alexey Borzov <avb@php.net> - * @version $Id: HTML_Common2_Test.php,v 1.3 2006/06/23 14:09:41 avb Exp $ + * PHP version 5 + * + * LICENSE: + * + * Copyright (c) 2004-2006, Alexey Borzov <avb@php.net> + * + * 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_Common2 + * @author Alexey Borzov <avb@php.net> + * @license http://opensource.org/licenses/bsd-license.php New BSD License + * @version CVS: $Id: HTML_Common2_Test.php,v 1.4 2006/10/16 13:06:46 avb Exp $ + * @link http://pear.php.net/package/HTML_Common2 */ if (!defined('PHPUnit2_MAIN_METHOD')) { define('PHPUnit2_MAIN_METHOD', 'this is getting ridiculous'); } +/** + * PHPUnit2 Test Case + */ require_once 'PHPUnit2/Framework/TestCase.php'; + +/** + * HTML_Common2 class + */ require_once 'HTML/Common2.php'; -// HTML_Common2 cannot be instantiated directly +/** + * A non-abstract subclass of HTML_Common2 + * + * HTML_Common2 cannot be instantiated due to abstract __toString() method, + * we need to (sort of) implement that. + */ class HTML_Common2_Concrete extends HTML_Common2 { - public function toHtml() + public function __toString() { return ''; } } +/** + * A subclass to test the 'watched attributes' functionality of HTML_Common2 + * + * Two attributes are watched here: 'readonly' and 'uppercase'. The former + * should not be changed by any of the methods and the value of the latter + * should always be uppercase. This is achieved by implementing the + * onAttributeChange() method defined in HTML_Common2 + */ class HTML_Common2_WatchedAttributes extends HTML_Common2_Concrete { protected $watchedAttributes = array('readonly', 'uppercase'); @@ -46,6 +102,9 @@ } } +/** + * Unit test for HTML_Common2 class + */ class HTML_Common2_Test extends PHPUnit2_Framework_TestCase { public function testUnknownOptionIsNull() @@ -89,6 +148,17 @@ ); } + public function testAttributeValuesAreStrings() + { + $obj = new HTML_Common2_Concrete(); + $obj->setAttributes(array('foo' => null, 'bar' => 10)); + $obj->setAttribute('baz', 2.5); + $obj->mergeAttributes(array('foobar' => 42)); + foreach ($obj->getAttributes() as $attribute) { + $this->assertType('string', $attribute); + } + } + public function testDefaultIndentLevelIsZero() { $obj = new HTML_Common2_Concrete(); http://cvs.php.net/viewvc.cgi/pear/HTML_Common2/package2.xml?view=markup&rev=1.1 Index: pear/HTML_Common2/package2.xml +++ pear/HTML_Common2/package2.xml <?xml version="1.0" encoding="ISO-8859-1"?> <package version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.0 http://pear.php.net/dtd/package-2.0.xsd"> <name>HTML_Common2</name> <channel>pear.php.net</channel> <extends>HTML_Common</extends> <summary>Abstract base class for HTML classes (PHP5 port of HTML_Common package).</summary> <description> The HTML_Common2 package provides methods for HTML code display and attributes handling. * Provides methods to set, remove, merge HTML attributes. * Handles global document options (charset, linebreak and indentation characters). * Provides methods to handle indentation and HTML comments (useful in subclasses). </description> <lead> <name>Alexey Borzov</name> <user>avb</user> <email>avb@php.net</email> <active>yes</active> </lead> <lead> <name>Klaus Guenther</name> <user>thesaur</user> <email>thesaur@php.net</email> <active>no</active> </lead> <date>2006-10-16</date> <version> <release>0.3.0</release> <api>0.3.0</api> </version> <stability> <release>alpha</release> <api>alpha</api> </stability> <license uri="http://opensource.org/licenses/bsd-license.php">BSD License</license> <notes> Radical changes to API are not expected after this release, you may use the package for development. Changes: * Renamed 'encoding' option to 'charset', as htmlspecialchars() parameter is named * Removed toHtml() and display() methods, __toString() is now declared abstract * Attribute values are always converted to strings * Minor performance tweaks * Switched to BSD license and package.xml 2.0 </notes> <contents> <dir name="/"> <file role="php" name="Common2.php" baseinstalldir="HTML"> <tasks:replace from="@package_version@" to="version" type="package-info" /> </file> <dir name="tests"> <file baseinstalldir="HTML_Common2" role="test" name="HTML_Common2_Test.php" /> </dir> </dir> </contents> <dependencies> <required> <php> <min>5.1.0</min> </php> <pearinstaller> <min>1.4.0</min> </pearinstaller> </required> </dependencies> <phprelease /> <changelog> <release> <version> <release>0.2.0</release> <api>0.2.0</api> </version> <stability> <release>devel</release> <api>devel</api> </stability> <date>2006-07-03</date> <license uri="http://www.php.net/license">PHP License</license> <notes> * $attributes array is now protected rather than private (and thus renamed from $_attributes) * parseAttributes() was renamed to prepareAttributes(), string parsing logic was extracted into the new parseAttributes() method * Added magic __toString() method as an alias for toHtml(), deprecated display(): it is now possible to print an instance of HTML_Common2 subclass by simply using the 'echo $object;' * It is now possible to watch some attributes for changes, this can be used to - Make attributes read-only (like 'type' attribute of <input /> tag) - Do some custom processing (update the element's value if its name changes) </notes> </release> <release> <version> <release>0.1.0</release> <api>0.1.0</api> </version> <stability> <release>devel</release> <api>devel</api> </stability> <date>2004-10-27</date> <license uri="http://www.php.net/license">PHP License</license> <notes> First release of a new major version. </notes> </release> </changelog> </package>
http://cvs.php.net/viewvc.cgi/pear/HTML_Common2/Common2.php?r1=1.3&r2=1.4&diff_format=u Index: pear/HTML_Common2/Common2.php diff -u pear/HTML_Common2/Common2.php:1.3 pear/HTML_Common2/Common2.php:1.4 --- pear/HTML_Common2/Common2.php:1.3 Fri Jun 23 14:09:40 2006 +++ pear/HTML_Common2/Common2.php Mon Oct 16 13:06:45 2006 @@ -2,18 +2,43 @@ /** * HTML_Common2: port of HTML_Common package to PHP5 * - * LICENSE: This source file is subject to version 3.0 of the PHP license - * that is available through the world-wide-web at the following URI: - * http://www.php.net/license/3_0.txt. If you did not receive a copy of - * the PHP License and are unable to obtain it through the web, please - * send a note to license@php.net so we can mail you a copy immediately. + * PHP version 5 + * + * LICENSE: + * + * Copyright (c) 2004-2006, Alexey Borzov <avb@php.net> + * + * 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_Common2 * @author Alexey Borzov <avb@php.net> - * @copyright 2004, 2005, 2006 The PHP Group - * @license http://www.php.net/license/3_0.txt PHP License - * @version CVS: $Id: Common2.php,v 1.3 2006/06/23 14:09:40 avb Exp $ + * @license http://opensource.org/licenses/bsd-license.php New BSD License + * @version CVS: $Id: Common2.php,v 1.4 2006/10/16 13:06:45 avb Exp $ * @link http://pear.php.net/package/HTML_Common2 */ @@ -24,8 +49,10 @@ * attribute strings. Port of HTML_Common class for PHP4 originally written by * Adam Daniel with contributions from numerous other developers. * - * @version $Revision: 1.3 $ - * @author Alexey Borzov <avb@php.net> + * @category HTML + * @package HTML_Common2 + * @author Alexey Borzov <avb@php.net> + * @version Release: @package_version@ */ abstract class HTML_Common2 { @@ -58,15 +85,16 @@ /** * Global options for all elements generated by subclasses of HTML_Common2 * - * Known options are - * 'encoding': encoding used in htmlspecialchars() calls - * 'indent': string used to indent HTML elements - * 'linebreak': string used to indicate linebreak + * Preset options are + * - 'charset': charset parameter used in htmlspecialchars() calls, + * defaults to 'ISO-8859-1' + * - 'indent': string used to indent HTML elements, defaults to "\11" + * - 'linebreak': string used to indicate linebreak, defaults to "\12" * * @var array */ private static $_options = array( - 'encoding' => 'ISO-8859-1', + 'charset' => 'ISO-8859-1', 'indent' => "\11", 'linebreak' => "\12" ); @@ -139,15 +167,16 @@ { $prepared = array(); if (is_string($attributes)) { - $prepared = self::parseAttributes($attributes); + return self::parseAttributes($attributes); + } elseif (is_array($attributes)) { foreach ($attributes as $key => $value) { if (is_int($key)) { - $key = $value = strtolower($value); + $key = strtolower($value); + $prepared[$key] = $key; } else { - $key = strtolower($key); + $prepared[strtolower($key)] = (string)$value; } - $prepared[$key] = (string)$value; } } return $prepared; @@ -161,10 +190,7 @@ */ protected static function removeAttributeArray(&$attributes, $name) { - $name = strtolower($name); - if (isset($attributes[$name])) { - unset($attributes[$name]); - } + unset($attributes[strtolower($name)]); } /** @@ -177,9 +203,9 @@ { $str = ''; if (is_array($attributes)) { - $encoding = self::getOption('encoding'); + $charset = self::getOption('charset'); foreach ($attributes as $key => $value) { - $str .= ' ' . $key . '="' . htmlspecialchars($value, ENT_QUOTES, $encoding) . '"'; + $str .= ' ' . $key . '="' . htmlspecialchars($value, ENT_QUOTES, $charset) . '"'; } } return $str; @@ -210,7 +236,7 @@ if (in_array($name, $this->watchedAttributes)) { $this->onAttributeChange($name, $value); } else { - $this->attributes[$name] = $value; + $this->attributes[$name] = (string)$value; } } @@ -350,31 +376,13 @@ /** * Returns the HTML representation of the element - * - * @return string - */ - abstract public function toHtml(); - - /** - * A magic method to let the object work with echo and print constructs * - * @return string - * @see toHtml() - */ - public function __toString() - { - return $this->toHtml(); - } - - /** - * Displays the element + * This magic method allows using the instances of HTML_Common2 in string + * contexts * - * @deprecated Deprecated, using <code>echo $obj;</code> will work just as well + * @return string */ - public function display() - { - echo $this->toHtml(); - } + abstract public function __toString(); /** * Called if trying to change an attribute with name in $watchedAttributes http://cvs.php.net/viewvc.cgi/pear/HTML_Common2/tests/HTML_Common2_Test.php?r1=1.3&r2=1.4&diff_format=u Index: pear/HTML_Common2/tests/HTML_Common2_Test.php diff -u pear/HTML_Common2/tests/HTML_Common2_Test.php:1.3 pear/HTML_Common2/tests/HTML_Common2_Test.php:1.4 --- pear/HTML_Common2/tests/HTML_Common2_Test.php:1.3 Fri Jun 23 14:09:41 2006 +++ pear/HTML_Common2/tests/HTML_Common2_Test.php Mon Oct 16 13:06:46 2006 @@ -2,26 +2,82 @@ /** * Unit test suite for HTML_Common2 class * - * @author Alexey Borzov <avb@php.net> - * @version $Id: HTML_Common2_Test.php,v 1.3 2006/06/23 14:09:41 avb Exp $ + * PHP version 5 + * + * LICENSE: + * + * Copyright (c) 2004-2006, Alexey Borzov <avb@php.net> + * + * 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_Common2 + * @author Alexey Borzov <avb@php.net> + * @license http://opensource.org/licenses/bsd-license.php New BSD License + * @version CVS: $Id: HTML_Common2_Test.php,v 1.4 2006/10/16 13:06:46 avb Exp $ + * @link http://pear.php.net/package/HTML_Common2 */ if (!defined('PHPUnit2_MAIN_METHOD')) { define('PHPUnit2_MAIN_METHOD', 'this is getting ridiculous'); } +/** + * PHPUnit2 Test Case + */ require_once 'PHPUnit2/Framework/TestCase.php'; + +/** + * HTML_Common2 class + */ require_once 'HTML/Common2.php'; -// HTML_Common2 cannot be instantiated directly +/** + * A non-abstract subclass of HTML_Common2 + * + * HTML_Common2 cannot be instantiated due to abstract __toString() method, + * we need to (sort of) implement that. + */ class HTML_Common2_Concrete extends HTML_Common2 { - public function toHtml() + public function __toString() { return ''; } } +/** + * A subclass to test the 'watched attributes' functionality of HTML_Common2 + * + * Two attributes are watched here: 'readonly' and 'uppercase'. The former + * should not be changed by any of the methods and the value of the latter + * should always be uppercase. This is achieved by implementing the + * onAttributeChange() method defined in HTML_Common2 + */ class HTML_Common2_WatchedAttributes extends HTML_Common2_Concrete { protected $watchedAttributes = array('readonly', 'uppercase'); @@ -46,6 +102,9 @@ } } +/** + * Unit test for HTML_Common2 class + */ class HTML_Common2_Test extends PHPUnit2_Framework_TestCase { public function testUnknownOptionIsNull() @@ -89,6 +148,17 @@ ); } + public function testAttributeValuesAreStrings() + { + $obj = new HTML_Common2_Concrete(); + $obj->setAttributes(array('foo' => null, 'bar' => 10)); + $obj->setAttribute('baz', 2.5); + $obj->mergeAttributes(array('foobar' => 42)); + foreach ($obj->getAttributes() as $attribute) { + $this->assertType('string', $attribute); + } + } + public function testDefaultIndentLevelIsZero() { $obj = new HTML_Common2_Concrete(); http://cvs.php.net/viewvc.cgi/pear/HTML_Common2/package2.xml?view=markup&rev=1.1 Index: pear/HTML_Common2/package2.xml +++ pear/HTML_Common2/package2.xml <?xml version="1.0" encoding="ISO-8859-1"?> <package version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.0 http://pear.php.net/dtd/package-2.0.xsd"> <name>HTML_Common2</name> <channel>pear.php.net</channel> <extends>HTML_Common</extends> <summary>Abstract base class for HTML classes (PHP5 port of HTML_Common package).</summary> <description> The HTML_Common2 package provides methods for HTML code display and attributes handling. * Provides methods to set, remove, merge HTML attributes. * Handles global document options (charset, linebreak and indentation characters). * Provides methods to handle indentation and HTML comments (useful in subclasses). </description> <lead> <name>Alexey Borzov</name> <user>avb</user> <email>avb@php.net</email> <active>yes</active> </lead> <lead> <name>Klaus Guenther</name> <user>thesaur</user> <email>thesaur@php.net</email> <active>no</active> </lead> <date>2006-10-16</date> <version> <release>0.3.0</release> <api>0.3.0</api> </version> <stability> <release>alpha</release> <api>alpha</api> </stability> <license uri="http://opensource.org/licenses/bsd-license.php">BSD License</license> <notes> Radical changes to API are not expected after this release, you may use the package for development. Changes: * Renamed 'encoding' option to 'charset', as htmlspecialchars() parameter is named * Removed toHtml() and display() methods, __toString() is now declared abstract * Attribute values are always converted to strings * Minor performance tweaks * Switched to BSD license and package.xml 2.0 </notes> <contents> <dir name="/"> <file role="php" name="Common2.php" baseinstalldir="HTML"> <tasks:replace from="@package_version@" to="version" type="package-info" /> </file> <dir name="tests"> <file baseinstalldir="HTML_Common2" role="test" name="HTML_Common2_Test.php" /> </dir> </dir> </contents> <dependencies> <required> <php> <min>5.1.0</min> </php> <pearinstaller> <min>1.4.0</min> </pearinstaller> </required> </dependencies> <phprelease /> <changelog> <release> <version> <release>0.2.0</release> <api>0.2.0</api> </version> <stability> <release>devel</release> <api>devel</api> </stability> <date>2006-07-03</date> <license uri="http://www.php.net/license">PHP License</license> <notes> * $attributes array is now protected rather than private (and thus renamed from $_attributes) * parseAttributes() was renamed to prepareAttributes(), string parsing logic was extracted into the new parseAttributes() method * Added magic __toString() method as an alias for toHtml(), deprecated display(): it is now possible to print an instance of HTML_Common2 subclass by simply using the 'echo $object;' * It is now possible to watch some attributes for changes, this can be used to - Make attributes read-only (like 'type' attribute of <input /> tag) - Do some custom processing (update the element's value if its name changes) </notes> </release> <release> <version> <release>0.1.0</release> <api>0.1.0</api> </version> <stability> <release>devel</release> <api>devel</api> </stability> <date>2004-10-27</date> <license uri="http://www.php.net/license">PHP License</license> <notes> First release of a new major version. </notes> </release> </changelog> </package>