Source for file tag.php
Documentation is available at tag.php
* Base include file for SimpleTest.
* @version $Id: tag.php 1723 2008-04-08 00:34:10Z lastcraft $
* include SimpleTest files
require_once(dirname(__FILE__
) .
'/parser.php');
require_once(dirname(__FILE__
) .
'/encoding.php');
* Starts with a named tag with attributes only.
* @param string $name Tag name.
* @param hash $attributes Attribute names and
* string values. Note that
* the keys must have been
* converted to lower case.
* Check to see if the tag can have both start and
* end tags with content in between.
* @return boolean True if content allowed.
* The current tag should not swallow all content for
* itself as it's searchable page content. Private
* content tags are usually widgets that contain default
* @return boolean False as content is available
* to other tags by default.
* Appends string content to the current content.
* @param string $content Additional text.
* Adds an enclosed tag to the content.
* @param SimpleTag $tag New tag.
* @return string Name of tag.
* List of legal child elements.
* @return array List of element names.
* Accessor for an attribute.
* @param string $label Attribute name.
* @return string Attribute value.
* @param string $label Attribute name.
* @return string $value New attribute value.
* Accessor for the whole content so far.
* @return string Content as big raw string.
* Accessor for content reduced to visible text. Acts
* like a text mode browser, normalising space and
* reducing images to their alt text.
* @return string Content as plain text.
* Test to see if id attribute matches.
* @param string $id ID to test against.
* @return boolean True on match.
* Starts with a named tag with attributes only.
* @param hash $attributes Attribute names and
* Base tag is not a block tag.
* Starts with a named tag with attributes only.
* @param hash $attributes Attribute names and
* Starts with a named tag with attributes only.
* @param hash $attributes Attribute names and
* Accessor for URL as string.
* @return string Coerced as string.
* Starts with a named tag with attributes only.
* @param string $name Tag name.
* @param hash $attributes Attribute names and
* Accessor for name submitted as the key in
* GET/POST variables hash.
* @return string Parsed value.
* Accessor for default value parsed with the tag.
* @return string Parsed value.
* Accessor for currently set value or default if
* @return string Value set by form or default
* Sets the current form element value.
* @param string $value New value.
* @return boolean True if allowed.
* Resets the form element value back to the
* Allows setting of a label externally, say by a
* @param string $label Label to attach.
* Reads external or internal label.
* @param string $label Label to test.
* @return boolean True is match.
* Dispatches the value into the form encoded packet.
* @param SimpleEncoding $encoding Form packet.
function write(&$encoding) {
* Text, password and hidden field.
* Starts with a named tag with attributes only.
* @param hash $attributes Attribute names and
* Tag contains no content.
* Sets the current form element value. Cannot
* change the value of a hidden field.
* @param string $value New value.
* @return boolean True if allowed.
* Submit button as input tag.
* Starts with a named tag with attributes only.
* @param hash $attributes Attribute names and
* Tag contains no end element.
* Disables the setting of the button value.
* @param string $value Ignored.
* @return boolean True if allowed.
* Value of browser visible text.
* @return string Visible label.
* Test for a label match when searching.
* @param string $label Label to test.
* @return boolean True on match.
* Image button as input tag.
* Starts with a named tag with attributes only.
* @param hash $attributes Attribute names and
* Tag contains no end element.
* Disables the setting of the button value.
* @param string $value Ignored.
* @return boolean True if allowed.
* Value of browser visible text.
* @return string Visible label.
* Test for a label match when searching.
* @param string $label Label to test.
* @return boolean True on match.
* Dispatches the value into the form encoded packet.
* @param SimpleEncoding $encoding Form packet.
* @param integer $x X coordinate of click.
* @param integer $y Y coordinate of click.
function write(&$encoding, $x, $y) {
$encoding->add($this->getName() .
'.x', $x);
$encoding->add($this->getName() .
'.y', $y);
* Submit button as button tag.
* Starts with a named tag with attributes only.
* Defaults are very browser dependent.
* @param hash $attributes Attribute names and
* Check to see if the tag can have both start and
* end tags with content in between.
* @return boolean True if content allowed.
* Disables the setting of the button value.
* @param string $value Ignored.
* @return boolean True if allowed.
* Value of browser visible text.
* @return string Visible label.
* Test for a label match when searching.
* @param string $label Label to test.
* @return boolean True on match.
* Content tag for text area.
* Starts with a named tag with attributes only.
* @param hash $attributes Attribute names and
* Accessor for starting value.
* @return string Parsed value.
* Applies word wrapping if needed.
* @param string $value New value.
* @return boolean True if allowed.
return parent::setValue($this->_wrap($value));
* Test to see if text should be wrapped.
* @return boolean True if wrapping on.
function _wrapIsEnabled() {
if (($wrap ==
'physical') ||
($wrap ==
'hard')) {
* Performs the formatting that is peculiar to
* this tag. There is strange behaviour in this
* one, including stripping a leading new line.
* Go figure. I am using Firefox as a guide.
* @param string $text Text to wrap.
* @return string Text wrapped with carriage
if ($this->_wrapIsEnabled()) {
* The content of textarea is not part of the page.
* Starts with attributes only.
* @param hash $attributes Attribute names and
* Tag contains no content.
* Dispatches the value into the form encoded packet.
* @param SimpleEncoding $encoding Form packet.
function write(&$encoding) {
* Starts with attributes only.
* @param hash $attributes Attribute names and
* Adds an option tag to a selection field.
* @param SimpleOptionTag $tag New option.
if ($tag->getTagName() ==
'option') {
* Text within the selection element is ignored.
* @param string $content Ignored.
* Scans options for defaults. If none, then
* the first option is selected.
* @return string Selected field.
for ($i =
0, $count =
count($this->_options); $i <
$count; $i++
) {
if ($this->_options[$i]->getAttribute('selected') !==
false) {
return $this->_options[$i]->getDefault();
return $this->_options[0]->getDefault();
* Can only set allowed values.
* @param string $value New choice.
* @return boolean True if allowed.
for ($i =
0, $count =
count($this->_options); $i <
$count; $i++
) {
if ($this->_options[$i]->isValue($value)) {
* Accessor for current selection value.
* @return string Value attribute or
* Starts with attributes only.
* @param hash $attributes Attribute names and
* Adds an option tag to a selection field.
* @param SimpleOptionTag $tag New option.
if ($tag->getTagName() ==
'option') {
* Text within the selection element is ignored.
* @param string $content Ignored.
* Scans options for defaults to populate the
* @return array Selected fields.
for ($i =
0, $count =
count($this->_options); $i <
$count; $i++
) {
if ($this->_options[$i]->getAttribute('selected') !==
false) {
$default[] =
$this->_options[$i]->getDefault();
* Can only set allowed values. Any illegal value
* will result in a failure, but all correct values
* @param array $desired New choices.
* @return boolean True if all allowed.
foreach ($desired as $value) {
for ($i =
0, $count =
count($this->_options); $i <
$count; $i++
) {
if ($this->_options[$i]->isValue($value)) {
$achieved[] =
$this->_options[$i]->getValue();
* Accessor for current selection value.
* @return array List of currently set options.
* Option for selection field.
* Stashes the attributes.
* @param string $value Ignored.
* @return boolean Not allowed.
* Test to see if a value matches the option.
* @param string $compare Value to compare with.
* @return boolean True if possible match.
$compare =
trim($compare);
* Accessor for starting value. Will be set to
* the option label if no value exists.
* @return string Parsed value.
* The content of options is not part of the page.
* Stashes the attributes.
* @param array $attributes Hash of attributes.
* Tag contains no content.
* The only allowed value sn the one in the
* @param string $value New value.
* @return boolean True if allowed.
* Accessor for starting value.
* @return string Parsed value.
* Starts with attributes only.
* @param hash $attributes Attribute names and
* Tag contains no content.
* The only allowed value in the one in the
* "value" attribute. The default for this
* attribute is "on". If this widget is set to
* true, then the usual value will be taken.
* @param string $value New value.
* @return boolean True if allowed.
* Accessor for starting value. The default
* @return string Parsed value.
* A group of multiple widgets with some shared behaviour.
* Adds a tag to the group.
* @param SimpleWidget $widget
* Accessor to widget set.
* @return array All widgets.
* Accessor for an attribute.
* @param string $label Attribute name.
* @return boolean Always false.
* Fetches the name for the widget from the first
* @return string Name of widget.
* Scans the widgets for one with the appropriate
* @param string $id ID value to try.
* @return boolean True if matched.
for ($i =
0, $count =
count($this->_widgets); $i <
$count; $i++
) {
* Scans the widgets for one with the appropriate
* @param string $label Attached label to try.
* @return boolean True if matched.
for ($i =
0, $count =
count($this->_widgets); $i <
$count; $i++
) {
if ($this->_widgets[$i]->isLabel($label)) {
* Dispatches the value into the form encoded packet.
* @param SimpleEncoding $encoding Form packet.
function write(&$encoding) {
$encoding->add($this->getName(), $this->getValue());
* A group of tags with the same name within a form.
* Accessor for current selected widget or false
* @return string/array Widget values or false if none.
for ($i =
0, $count =
count($widgets); $i <
$count; $i++
) {
if ($widgets[$i]->getValue() !==
false) {
$values[] =
$widgets[$i]->getValue();
return $this->_coerceValues($values);
* Accessor for starting value that is active.
* @return string/array Widget values or false if none.
for ($i =
0, $count =
count($widgets); $i <
$count; $i++
) {
if ($widgets[$i]->getDefault() !==
false) {
$values[] =
$widgets[$i]->getDefault();
return $this->_coerceValues($values);
* Accessor for current set values.
* @param string/array/boolean $values Either a single string, a
* hash or false for nothing set.
* @return boolean True if all values can be set.
$values =
$this->_makeArray($values);
if (! $this->_valuesArePossible($values)) {
for ($i =
0, $count =
count($widgets); $i <
$count; $i++
) {
$possible =
$widgets[$i]->getAttribute('value');
if (in_array($widgets[$i]->getAttribute('value'), $values)) {
$widgets[$i]->setValue($possible);
$widgets[$i]->setValue(false);
* Tests to see if a possible value set is legal.
* @param string/array/boolean $values Either a single string, a
* hash or false for nothing set.
* @return boolean False if trying to set a
function _valuesArePossible($values) {
for ($i =
0, $count =
count($widgets); $i <
$count; $i++
) {
$possible =
$widgets[$i]->getAttribute('value');
return ($values ==
$matches);
* Converts the output to an appropriate format. This means
* that no values is false, a single value is just that
* value and only two or more are contained in an array.
* @param array $values List of values of widgets.
* @return string/array/boolean Expected format for a tag.
function _coerceValues($values) {
if (count($values) ==
0) {
} elseif (count($values) ==
1) {
* Converts false or string into array. The opposite of
* @param string/array/boolean $value A single item is converted
* to a one item list. False
* @return array List of values, possibly empty.
function _makeArray($value) {
* A group of tags with the same name within a form.
* Used for radio buttons.
* Each tag is tried in turn until one is
* successfully set. The others will be
* unchecked if successful.
* @param string $value New value.
* @return boolean True if any allowed.
if (! $this->_valueIsPossible($value)) {
for ($i =
0, $count =
count($widgets); $i <
$count; $i++
) {
if (! $widgets[$i]->setValue($value)) {
$widgets[$i]->setValue(false);
* Tests to see if a value is allowed.
* @param string Attempted value.
* @return boolean True if a valid value.
function _valueIsPossible($value) {
for ($i =
0, $count =
count($widgets); $i <
$count; $i++
) {
if ($widgets[$i]->getAttribute('value') ==
$value) {
* Accessor for current selected widget or false
* @return string/boolean Value attribute or
for ($i =
0, $count =
count($widgets); $i <
$count; $i++
) {
if ($widgets[$i]->getValue() !==
false) {
return $widgets[$i]->getValue();
* Accessor for starting value that is active.
* @return string/boolean Value of first checked
* widget or false if none.
for ($i =
0, $count =
count($widgets); $i <
$count; $i++
) {
if ($widgets[$i]->getDefault() !==
false) {
return $widgets[$i]->getDefault();
* Tag to keep track of labels.
* Starts with a named tag with attributes only.
* @param hash $attributes Attribute names and
* Access for the ID to attach the label to.
* @return string For attribute.
* Tag to aid parsing the form.
* Starts with a named tag with attributes only.
* @param hash $attributes Attribute names and
* Tag to aid parsing the frames in a page.
* Starts with a named tag with attributes only.
* @param hash $attributes Attribute names and
* Tag contains no content.
Documentation generated on Sun, 04 May 2008 09:22:14 -0500 by phpDocumentor 1.3.0