svn: /pear/packages/HTML_QuickForm2/trunk/ HTML/QuickForm2/Element/InputCheckbox.php HTML/QuickForm2/Node.php
tests/QuickForm2/Element/InputCheckboxTest.php tests/QuickForm2/ElementTest.php

From: Date: Fri, 06 Apr 2012 17:08:12 +0000
Subject: svn: /pear/packages/HTML_QuickForm2/trunk/ HTML/QuickForm2/Element/InputCheckbox.php HTML/QuickForm2/Node.php
tests/QuickForm2/Element/InputCheckboxTest.php tests/QuickForm2/ElementTest.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-64648@lists.php.net to get a copy of this message
avb Fri, 06 Apr 2012 17:08:12 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=324926 Log: Fixed a couple of bugs spotted in http://news.php.net/php.pear.general/31496 * Autogenerated ids should not start with numbers * Explicitly given value="0" for checkboxes should not be replaced by value="1" Changed paths: U pear/packages/HTML_QuickForm2/trunk/HTML/QuickForm2/Element/InputCheckbox.php U pear/packages/HTML_QuickForm2/trunk/HTML/QuickForm2/Node.php U pear/packages/HTML_QuickForm2/trunk/tests/QuickForm2/Element/InputCheckboxTest.php U pear/packages/HTML_QuickForm2/trunk/tests/QuickForm2/ElementTest.php Modified: pear/packages/HTML_QuickForm2/trunk/HTML/QuickForm2/Element/InputCheckbox.php =================================================================== --- pear/packages/HTML_QuickForm2/trunk/HTML/QuickForm2/Element/InputCheckbox.php 2012-04-06 15:58:06 UTC (rev 324925) +++ pear/packages/HTML_QuickForm2/trunk/HTML/QuickForm2/Element/InputCheckbox.php 2012-04-06 17:08:12 UTC (rev 324926) @@ -71,7 +71,7 @@ public function __construct($name = null, $attributes = null, array $data = array()) { parent::__construct($name, $attributes, $data); - if (!$this->getAttribute('value')) { + if (null === $this->getAttribute('value')) { $this->setAttribute('value', 1); } } Modified: pear/packages/HTML_QuickForm2/trunk/HTML/QuickForm2/Node.php =================================================================== --- pear/packages/HTML_QuickForm2/trunk/HTML/QuickForm2/Node.php 2012-04-06 15:58:06 UTC (rev 324925) +++ pear/packages/HTML_QuickForm2/trunk/HTML/QuickForm2/Node.php 2012-04-06 17:08:12 UTC (rev 324926) @@ -232,6 +232,10 @@ do { $token = array_shift($tokens); + // prevent generated ids starting with numbers + if ('' == $id && is_numeric($token)) { + $token = 'qf' . $token; + } // Handle the 'array[]' names if ('' === $token) { if (empty($container)) { Modified: pear/packages/HTML_QuickForm2/trunk/tests/QuickForm2/Element/InputCheckboxTest.php =================================================================== --- pear/packages/HTML_QuickForm2/trunk/tests/QuickForm2/Element/InputCheckboxTest.php 2012-04-06 15:58:06 UTC (rev 324925) +++ pear/packages/HTML_QuickForm2/trunk/tests/QuickForm2/Element/InputCheckboxTest.php 2012-04-06 17:08:12 UTC (rev 324926) @@ -127,5 +127,17 @@ ); $boxHtml = $box->__toString(); } + + /** + * Explicitly setting value to 0 resulted in value="1" + * @see http://news.php.net/php.pear.general/31496 + */ + public function testValue0() + { + $box = new HTML_QuickForm2_Element_InputCheckbox( + 'testBox', array('value' => 0) + ); + $this->assertContains('value="0"', $box->__toString()); + } } ?> Modified: pear/packages/HTML_QuickForm2/trunk/tests/QuickForm2/ElementTest.php =================================================================== --- pear/packages/HTML_QuickForm2/trunk/tests/QuickForm2/ElementTest.php 2012-04-06 15:58:06 UTC (rev 324925) +++ pear/packages/HTML_QuickForm2/trunk/tests/QuickForm2/ElementTest.php 2012-04-06 17:08:12 UTC (rev 324926) @@ -253,5 +253,15 @@ $this->testUniqueIdsGenerated(); } + + /** + * Prevent generating ids like "0-0" for (grouped) elements named "0" + * @see http://news.php.net/php.pear.general/31496 + */ + public function testGeneratedIdsShouldNotStartWithNumbers() + { + $el = new HTML_QuickForm2_ElementImpl('0'); + $this->assertNotRegExp('/^\d/', $el->getId()); + } } ?>

« previous php.pear.cvs (#64648) next »