From 57ef2eba9b58eb179422aa56eb32fb8a1a02d412 Mon Sep 17 00:00:00 2001
From: phpnut
<?php
class Log {
@@ -207,8 +207,8 @@ class Log {
function Log($file_path) {
}
- function message() {
- }
+ function message() {
+ }
}
?>;
diff --git a/vendors/simpletest/docs/en/reporter_documentation.html b/vendors/simpletest/docs/en/reporter_documentation.html
index db6f973b3..44be8b1e4 100644
--- a/vendors/simpletest/docs/en/reporter_documentation.html
+++ b/vendors/simpletest/docs/en/reporter_documentation.html
@@ -375,7 +375,7 @@ Test cases run: 1/1, Failures: 0, Exceptions: 0
File test
1) True assertion failed.
- in createnewfile
+ in createnewfile
FAILURES!!!
Test cases run: 1/1, Failures: 1, Exceptions: 0
diff --git a/vendors/simpletest/docs/en/web_tester_documentation.html b/vendors/simpletest/docs/en/web_tester_documentation.html
index c828e4231..51f604be6 100644
--- a/vendors/simpletest/docs/en/web_tester_documentation.html
+++ b/vendors/simpletest/docs/en/web_tester_documentation.html
@@ -283,9 +283,9 @@ class TestOfLastcraft extends WebTestCase {
Web site tests
1) Expecting response in [200] got [302]
- in testhomepage
- in testoflastcraft
- in lastcraft_test.php
+ in testhomepage
+ in testoflastcraft
+ in lastcraft_test.php
FAILURES!!!
Test cases run: 1/1, Failures: 1, Exceptions: 0
diff --git a/vendors/simpletest/docs/fr/group_test_documentation.html b/vendors/simpletest/docs/fr/group_test_documentation.html
index 567ac57c5..662f868e5 100644
--- a/vendors/simpletest/docs/fr/group_test_documentation.html
+++ b/vendors/simpletest/docs/fr/group_test_documentation.html
@@ -219,15 +219,15 @@
?>
Comme les scénarios de test normaux, un GroupTest peut être chargé avec la méthode GroupTest::addTestFile().
-
-<?php
- define('RUNNER', true);
-
- $test = &new BigGroupTest('Big group');
- $test->addTestFile('file_group_test.php');
- $test->addTestFile(...);
- $test->run(new HtmlReporter());
-?>
+
+<?php
+ define('RUNNER', true);
+
+ $test = &new BigGroupTest('Big group');
+ $test->addTestFile('file_group_test.php');
+ $test->addTestFile(...);
+ $test->run(new HtmlReporter());
+?>
<?php class Log { diff --git a/vendors/simpletest/docs/fr/reporter_documentation.html b/vendors/simpletest/docs/fr/reporter_documentation.html index 9c3480654..4f9277811 100644 --- a/vendors/simpletest/docs/fr/reporter_documentation.html +++ b/vendors/simpletest/docs/fr/reporter_documentation.html @@ -282,7 +282,7 @@ Test cases run: 1/1, Failures: 0, Exceptions: 0File test 1) True assertion failed. - in createnewfile + in createnewfile FAILURES!!! Test cases run: 1/1, Failures: 1, Exceptions: 0diff --git a/vendors/simpletest/docs/fr/web_tester_documentation.html b/vendors/simpletest/docs/fr/web_tester_documentation.html index 40396fdf8..86044e5ef 100644 --- a/vendors/simpletest/docs/fr/web_tester_documentation.html +++ b/vendors/simpletest/docs/fr/web_tester_documentation.html @@ -218,9 +218,9 @@ class TestOfLastcraft extends WebTestCase {Web site tests 1) Expecting response in [200] got [302] - in testhomepage - in testoflastcraft - in lastcraft_test.php + in testhomepage + in testoflastcraft + in lastcraft_test.php FAILURES!!! Test cases run: 1/1, Failures: 1, Exceptions: 0diff --git a/vendors/simpletest/dumper.php b/vendors/simpletest/dumper.php index bea909aef..35e110044 100644 --- a/vendors/simpletest/dumper.php +++ b/vendors/simpletest/dumper.php @@ -1,28 +1,30 @@ getType($value); switch($type) { @@ -42,12 +44,12 @@ return "Unknown"; } - /** - * Gets the string representation of a type. - * @param mixed $value Variable to check against. - * @return string Type. - * @access public - */ + /** + * Gets the string representation of a type. + * @param mixed $value Variable to check against. + * @return string Type. + * @access public + */ function getType($value) { if (! isset($value)) { return "Null"; @@ -69,16 +71,16 @@ return "Unknown"; } - /** - * Creates a human readable description of the - * difference between two variables. Uses a - * dynamic call. - * @param mixed $first First variable. - * @param mixed $second Value to compare with. - * @param boolean $identical If true then type anomolies count. - * @return string Description of difference. - * @access public - */ + /** + * Creates a human readable description of the + * difference between two variables. Uses a + * dynamic call. + * @param mixed $first First variable. + * @param mixed $second Value to compare with. + * @param boolean $identical If true then type anomolies count. + * @return string Description of difference. + * @access public + */ function describeDifference($first, $second, $identical = false) { if ($identical) { if (! $this->_isTypeMatch($first, $second)) { @@ -94,25 +96,25 @@ return $this->$method($first, $second, $identical); } - /** - * Tests to see if types match. - * @param mixed $first First variable. - * @param mixed $second Value to compare with. - * @return boolean True if matches. - * @access private - */ + /** + * Tests to see if types match. + * @param mixed $first First variable. + * @param mixed $second Value to compare with. + * @return boolean True if matches. + * @access private + */ function _isTypeMatch($first, $second) { return ($this->getType($first) == $this->getType($second)); } - /** - * Clips a string to a maximum length. - * @param string $value String to truncate. - * @param integer $size Minimum string size to show. - * @param integer $position Centre of string section. - * @return string Shortened version. - * @access public - */ + /** + * Clips a string to a maximum length. + * @param string $value String to truncate. + * @param integer $size Minimum string size to show. + * @param integer $position Centre of string section. + * @return string Shortened version. + * @access public + */ function clipString($value, $size, $position = 0) { $length = strlen($value); if ($length <= $size) { @@ -127,56 +129,56 @@ return ($start > 0 ? "..." : "") . $value . ($start + $size < $length ? "..." : ""); } - /** - * Creates a human readable description of the - * difference between two variables. The minimal - * version. - * @param null $first First value. - * @param mixed $second Value to compare with. - * @return string Human readable description. - * @access private - */ + /** + * Creates a human readable description of the + * difference between two variables. The minimal + * version. + * @param null $first First value. + * @param mixed $second Value to compare with. + * @return string Human readable description. + * @access private + */ function _describeGenericDifference($first, $second) { return "as [" . $this->describeValue($first) . "] does not match [" . $this->describeValue($second) . "]"; } - /** - * Creates a human readable description of the - * difference between a null and another variable. - * @param null $first First null. - * @param mixed $second Null to compare with. - * @param boolean $identical If true then type anomolies count. - * @return string Human readable description. - * @access private - */ + /** + * Creates a human readable description of the + * difference between a null and another variable. + * @param null $first First null. + * @param mixed $second Null to compare with. + * @param boolean $identical If true then type anomolies count. + * @return string Human readable description. + * @access private + */ function _describeNullDifference($first, $second, $identical) { return $this->_describeGenericDifference($first, $second); } - /** - * Creates a human readable description of the - * difference between a boolean and another variable. - * @param boolean $first First boolean. - * @param mixed $second Boolean to compare with. - * @param boolean $identical If true then type anomolies count. - * @return string Human readable description. - * @access private - */ + /** + * Creates a human readable description of the + * difference between a boolean and another variable. + * @param boolean $first First boolean. + * @param mixed $second Boolean to compare with. + * @param boolean $identical If true then type anomolies count. + * @return string Human readable description. + * @access private + */ function _describeBooleanDifference($first, $second, $identical) { return $this->_describeGenericDifference($first, $second); } - /** - * Creates a human readable description of the - * difference between a string and another variable. - * @param string $first First string. - * @param mixed $second String to compare with. - * @param boolean $identical If true then type anomolies count. - * @return string Human readable description. - * @access private - */ + /** + * Creates a human readable description of the + * difference between a string and another variable. + * @param string $first First string. + * @param mixed $second String to compare with. + * @param boolean $identical If true then type anomolies count. + * @return string Human readable description. + * @access private + */ function _describeStringDifference($first, $second, $identical) { if (is_object($second) || is_array($second)) { return $this->_describeGenericDifference($first, $second); @@ -189,15 +191,15 @@ return $message; } - /** - * Creates a human readable description of the - * difference between an integer and another variable. - * @param integer $first First number. - * @param mixed $second Number to compare with. - * @param boolean $identical If true then type anomolies count. - * @return string Human readable description. - * @access private - */ + /** + * Creates a human readable description of the + * difference between an integer and another variable. + * @param integer $first First number. + * @param mixed $second Number to compare with. + * @param boolean $identical If true then type anomolies count. + * @return string Human readable description. + * @access private + */ function _describeIntegerDifference($first, $second, $identical) { if (is_object($second) || is_array($second)) { return $this->_describeGenericDifference($first, $second); @@ -208,33 +210,34 @@ abs($first - $second); } - /** - * Creates a human readable description of the - * difference between two floating point numbers. - * @param float $first First float. - * @param mixed $second Float to compare with. - * @param boolean $identical If true then type anomolies count. - * @return string Human readable description. - * @access private - */ + /** + * Creates a human readable description of the + * difference between two floating point numbers. + * @param float $first First float. + * @param mixed $second Float to compare with. + * @param boolean $identical If true then type anomolies count. + * @return string Human readable description. + * @access private + */ function _describeFloatDifference($first, $second, $identical) { if (is_object($second) || is_array($second)) { return $this->_describeGenericDifference($first, $second); } - return "because " . $this->describeValue($first) . + return "because [" . $this->describeValue($first) . "] differs from [" . - $this->describeValue($second) . "]"; + $this->describeValue($second) . "] by " . + abs($first - $second); } - /** - * Creates a human readable description of the - * difference between two arrays. - * @param array $first First array. - * @param mixed $second Array to compare with. - * @param boolean $identical If true then type anomolies count. - * @return string Human readable description. - * @access private - */ + /** + * Creates a human readable description of the + * difference between two arrays. + * @param array $first First array. + * @param mixed $second Array to compare with. + * @param boolean $identical If true then type anomolies count. + * @return string Human readable description. + * @access private + */ function _describeArrayDifference($first, $second, $identical) { if (! is_array($second)) { return $this->_describeGenericDifference($first, $second); @@ -259,16 +262,16 @@ return ""; } - /** - * Compares two arrays to see if their key lists match. - * For an identical match, the ordering and types of the keys - * is significant. - * @param array $first First array. - * @param array $second Array to compare with. - * @param boolean $identical If true then type anomolies count. - * @return boolean True if matching. - * @access private - */ + /** + * Compares two arrays to see if their key lists match. + * For an identical match, the ordering and types of the keys + * is significant. + * @param array $first First array. + * @param array $second Array to compare with. + * @param boolean $identical If true then type anomolies count. + * @return boolean True if matching. + * @access private + */ function _isMatchingKeys($first, $second, $identical) { $first_keys = array_keys($first); $second_keys = array_keys($second); @@ -280,28 +283,28 @@ return ($first_keys == $second_keys); } - /** - * Creates a human readable description of the - * difference between a resource and another variable. - * @param resource $first First resource. - * @param mixed $second Resource to compare with. - * @param boolean $identical If true then type anomolies count. - * @return string Human readable description. - * @access private - */ + /** + * Creates a human readable description of the + * difference between a resource and another variable. + * @param resource $first First resource. + * @param mixed $second Resource to compare with. + * @param boolean $identical If true then type anomolies count. + * @return string Human readable description. + * @access private + */ function _describeResourceDifference($first, $second, $identical) { return $this->_describeGenericDifference($first, $second); } - /** - * Creates a human readable description of the - * difference between two objects. - * @param object $first First object. - * @param mixed $second Object to compare with. - * @param boolean $identical If true then type anomolies count. - * @return string Human readable description. - * @access private - */ + /** + * Creates a human readable description of the + * difference between two objects. + * @param object $first First object. + * @param mixed $second Object to compare with. + * @param boolean $identical If true then type anomolies count. + * @return string Human readable description. + * @access private + */ function _describeObjectDifference($first, $second, $identical) { if (! is_object($second)) { return $this->_describeGenericDifference($first, $second); @@ -312,15 +315,15 @@ $identical); } - /** - * Find the first character position that differs - * in two strings by binary chop. - * @param string $first First string. - * @param string $second String to compare with. - * @return integer Position of first differing - * character. - * @access private - */ + /** + * Find the first character position that differs + * in two strings by binary chop. + * @param string $first First string. + * @param string $second String to compare with. + * @return integer Position of first differing + * character. + * @access private + */ function _stringDiffersAt($first, $second) { if (! $first || ! $second) { return 0; @@ -339,13 +342,13 @@ return $position; } - /** - * Sends a formatted dump of a variable to a string. - * @param mixed $variable Variable to display. - * @return string Output from print_r(). - * @access public - * @static - */ + /** + * Sends a formatted dump of a variable to a string. + * @param mixed $variable Variable to display. + * @return string Output from print_r(). + * @access public + * @static + */ function dump($variable) { ob_start(); print_r($variable); @@ -354,15 +357,15 @@ return $formatted; } - /** - * Extracts the last assertion that was not within - * Simpletest itself. The name must start with "assert". - * @param array $stack List of stack frames. - * @param string $format String formatting. - * @param string $prefix Prefix of method to search for. - * @access public - * @static - */ + /** + * Extracts the last assertion that was not within + * Simpletest itself. The name must start with "assert". + * @param array $stack List of stack frames. + * @param string $format String formatting. + * @param string $prefix Prefix of method to search for. + * @access public + * @static + */ function getFormattedAssertionLine($stack, $format = '%d', $prefix = 'assert') { foreach ($stack as $frame) { if (isset($frame['file']) && strpos($frame['file'], 'simpletest') !== false) { // dirname() is a bit slow. diff --git a/vendors/simpletest/encoding.php b/vendors/simpletest/encoding.php index 009c9320a..a1a0d764a 100644 --- a/vendors/simpletest/encoding.php +++ b/vendors/simpletest/encoding.php @@ -1,74 +1,269 @@ _key = $key; + $this->_value = $value; + } + + /** + * The pair as a single string. + * @return string Encoded pair. + * @access public + */ + function asRequest() { + return $this->_key . '=' . urlencode($this->_value); + } + + /** + * The MIME part as a string. + * @return string MIME part encoding. + * @access public + */ + function asMime() { + $part = 'Content-Disposition: form-data; '; + $part .= "name=\"" . $this->_key . "\"\r\n"; + $part .= "\r\n" . $this->_value; + return $part; + } + + /** + * Is this the value we are looking for? + * @param string $key Identifier. + * @return boolean True if matched. + * @access public + */ + function isKey($key) { + return $key == $this->_key; + } + + /** + * Is this the value we are looking for? + * @return string Identifier. + * @access public + */ + function getKey() { + return $this->_key; + } + + /** + * Is this the value we are looking for? + * @return string Content. + * @access public + */ + function getValue() { + return $this->_value; + } + } + + /** + * Single post parameter. + * @package SimpleTest + * @subpackage WebTester + */ + class SimpleAttachment { + var $_key; + var $_content; + var $_filename; + + /** + * Stashes the data for rendering later. + * @param string $key Key to add value to. + * @param string $content Raw data. + * @param hash $filename Original filename. + */ + function SimpleAttachment($key, $content, $filename) { + $this->_key = $key; + $this->_content = $content; + $this->_filename = $filename; + } + + /** + * The pair as a single string. + * @return string Encoded pair. + * @access public + */ + function asRequest() { + return ''; + } + + /** + * The MIME part as a string. + * @return string MIME part encoding. + * @access public + */ + function asMime() { + $part = 'Content-Disposition: form-data; '; + $part .= 'name="' . $this->_key . '"; '; + $part .= 'filename="' . $this->_filename . '"'; + $part .= "\r\nContent-Type: " . $this->_deduceMimeType(); + $part .= "\r\n\r\n" . $this->_content; + return $part; + } + + /** + * Attempts to figure out the MIME type from the + * file extension and the content. + * @return string MIME type. + * @access private + */ + function _deduceMimeType() { + if ($this->_isOnlyAscii($this->_content)) { + return 'text/plain'; + } + return 'application/octet-stream'; + } + + /** + * Tests each character is in the range 0-127. + * @param string $ascii String to test. + * @access private + */ + function _isOnlyAscii($ascii) { + for ($i = 0, $length = strlen($ascii); $i < $length; $i++) { + if (ord($ascii[$i]) > 127) { + return false; + } + } + return true; + } + + /** + * Is this the value we are looking for? + * @param string $key Identifier. + * @return boolean True if matched. + * @access public + */ + function isKey($key) { + return $key == $this->_key; + } + + /** + * Is this the value we are looking for? + * @return string Identifier. + * @access public + */ + function getKey() { + return $this->_key; + } + + /** + * Is this the value we are looking for? + * @return string Content. + * @access public + */ + function getValue() { + return $this->_filename; + } + } + + /** + * Bundle of GET/POST parameters. Can include + * repeated parameters. + * @package SimpleTest + * @subpackage WebTester + */ + class SimpleEncoding { + var $_request; + + /** + * Starts empty. + * @param array $query Hash of parameters. + * Multiple values are + * as lists on a single key. + * @access public + */ + function SimpleEncoding($query = false) { if (! $query) { $query = array(); } - $this->_request = array(); - $this->setCoordinates(); + $this->clear(); $this->merge($query); } - /** - * Adds a parameter to the query. - * @param string $key Key to add value to. - * @param string/array $value New data. - * @access public - */ + /** + * Empties the request of parameters. + * @access public + */ + function clear() { + $this->_request = array(); + } + + /** + * Adds a parameter to the query. + * @param string $key Key to add value to. + * @param string/array $value New data. + * @access public + */ function add($key, $value) { if ($value === false) { return; } - if (! isset($this->_request[$key])) { - $this->_request[$key] = array(); - } if (is_array($value)) { foreach ($value as $item) { - $this->_request[$key][] = $item; + $this->_addPair($key, $item); } } else { - $this->_request[$key][] = $value; + $this->_addPair($key, $value); } } - /** - * Adds a set of parameters to this query. - * @param array/SimpleQueryString $query Multiple values are - * as lists on a single key. - * @access public - */ + /** + * Adds a new value into the request. + * @param string $key Key to add value to. + * @param string/array $value New data. + * @access private + */ + function _addPair($key, $value) { + $this->_request[] = new SimpleEncodedPair($key, $value); + } + + /** + * Adds a MIME part to the query. Does nothing for a + * form encoded packet. + * @param string $key Key to add value to. + * @param string $content Raw data. + * @param hash $filename Original filename. + * @access public + */ + function attach($key, $content, $filename) { + $this->_request[] = new SimpleAttachment($key, $content, $filename); + } + + /** + * Adds a set of parameters to this query. + * @param array/SimpleQueryString $query Multiple values are + * as lists on a single key. + * @access public + */ function merge($query) { if (is_object($query)) { - foreach ($query->getKeys() as $key) { - $this->add($key, $query->getValue($key)); - } - if ($query->getX() !== false) { - $this->setCoordinates($query->getX(), $query->getY()); - } + $this->_request = array_merge($this->_request, $query->getAll()); } elseif (is_array($query)) { foreach ($query as $key => $value) { $this->add($key, $value); @@ -76,81 +271,251 @@ } } - /** - * Sets image coordinates. Set to false to clear - * them. - * @param integer $x Horizontal position. - * @param integer $y Vertical position. - * @access public - */ - function setCoordinates($x = false, $y = false) { - if (($x === false) || ($y === false)) { - $this->_x = $this->_y = false; - return; - } - $this->_x = (integer)$x; - $this->_y = (integer)$y; - } - - /** - * Accessor for horizontal image coordinate. - * @return integer X value. - * @access public - */ - function getX() { - return $this->_x; - } - - /** - * Accessor for vertical image coordinate. - * @return integer Y value. - * @access public - */ - function getY() { - return $this->_y; - } - - /** - * Accessor for single value. - * @return string/array False if missing, string - * if present and array if - * multiple entries. - * @access public - */ + /** + * Accessor for single value. + * @return string/array False if missing, string + * if present and array if + * multiple entries. + * @access public + */ function getValue($key) { - if (! isset($this->_request[$key])) { - return false; - } elseif (count($this->_request[$key]) == 1) { - return $this->_request[$key][0]; - } else { - return $this->_request[$key]; - } - } - - /** - * Accessor for key list. - * @return array List of keys present. - * @access public - */ - function getKeys() { - return array_keys($this->_request); - } - - /** - * Renders the query string as a URL encoded - * request part. - * @return string Part of URL. - * @access public - */ - function asString() { - $statements = array(); - foreach ($this->_request as $key => $values) { - foreach ($values as $value) { - $statements[] = "$key=" . urlencode($value); + $values = array(); + foreach ($this->_request as $pair) { + if ($pair->isKey($key)) { + $values[] = $pair->getValue(); } } - $coords = ($this->_x !== false) ? '?' . $this->_x . ',' . $this->_y : ''; - return implode('&', $statements) . $coords; + if (count($values) == 0) { + return false; + } elseif (count($values) == 1) { + return $values[0]; + } else { + return $values; + } + } + + /** + * Accessor for listing of pairs. + * @return array All pair objects. + * @access public + */ + function getAll() { + return $this->_request; + } + + /** + * Renders the query string as a URL encoded + * request part. + * @return string Part of URL. + * @access protected + */ + function _encode() { + $statements = array(); + foreach ($this->_request as $pair) { + if ($statement = $pair->asRequest()) { + $statements[] = $statement; + } + } + return implode('&', $statements); + } + } + + /** + * Bundle of GET parameters. Can include + * repeated parameters. + * @package SimpleTest + * @subpackage WebTester + */ + class SimpleGetEncoding extends SimpleEncoding { + + /** + * Starts empty. + * @param array $query Hash of parameters. + * Multiple values are + * as lists on a single key. + * @access public + */ + function SimpleGetEncoding($query = false) { + $this->SimpleEncoding($query); + } + + /** + * HTTP request method. + * @return string Always GET. + * @access public + */ + function getMethod() { + return 'GET'; + } + + /** + * Writes no extra headers. + * @param SimpleSocket $socket Socket to write to. + * @access public + */ + function writeHeadersTo(&$socket) { + } + + /** + * No data is sent to the socket as the data is encoded into + * the URL. + * @param SimpleSocket $socket Socket to write to. + * @access public + */ + function writeTo(&$socket) { + } + + /** + * Renders the query string as a URL encoded + * request part for attaching to a URL. + * @return string Part of URL. + * @access public + */ + function asUrlRequest() { + return $this->_encode(); + } + } + + /** + * Bundle of URL parameters for a HEAD request. + * @package SimpleTest + * @subpackage WebTester + */ + class SimpleHeadEncoding extends SimpleGetEncoding { + + /** + * Starts empty. + * @param array $query Hash of parameters. + * Multiple values are + * as lists on a single key. + * @access public + */ + function SimpleHeadEncoding($query = false) { + $this->SimpleGetEncoding($query); + } + + /** + * HTTP request method. + * @return string Always HEAD. + * @access public + */ + function getMethod() { + return 'HEAD'; + } + } + + /** + * Bundle of POST parameters. Can include + * repeated parameters. + * @package SimpleTest + * @subpackage WebTester + */ + class SimplePostEncoding extends SimpleEncoding { + + /** + * Starts empty. + * @param array $query Hash of parameters. + * Multiple values are + * as lists on a single key. + * @access public + */ + function SimplePostEncoding($query = false) { + $this->SimpleEncoding($query); + } + + /** + * HTTP request method. + * @return string Always POST. + * @access public + */ + function getMethod() { + return 'POST'; + } + + /** + * Dispatches the form headers down the socket. + * @param SimpleSocket $socket Socket to write to. + * @access public + */ + function writeHeadersTo(&$socket) { + $socket->write("Content-Length: " . (integer)strlen($this->_encode()) . "\r\n"); + $socket->write("Content-Type: application/x-www-form-urlencoded\r\n"); + } + + /** + * Dispatches the form data down the socket. + * @param SimpleSocket $socket Socket to write to. + * @access public + */ + function writeTo(&$socket) { + $socket->write($this->_encode()); + } + + /** + * Renders the query string as a URL encoded + * request part for attaching to a URL. + * @return string Part of URL. + * @access public + */ + function asUrlRequest() { + return ''; + } + } + + /** + * Bundle of POST parameters in the multipart + * format. Can include file uploads. + * @package SimpleTest + * @subpackage WebTester + */ + class SimpleMultipartEncoding extends SimplePostEncoding { + var $_boundary; + + /** + * Starts empty. + * @param array $query Hash of parameters. + * Multiple values are + * as lists on a single key. + * @access public + */ + function SimpleMultipartEncoding($query = false, $boundary = false) { + $this->SimplePostEncoding($query); + $this->_boundary = ($boundary === false ? uniqid('st') : $boundary); + } + + /** + * Dispatches the form headers down the socket. + * @param SimpleSocket $socket Socket to write to. + * @access public + */ + function writeHeadersTo(&$socket) { + $socket->write("Content-Length: " . (integer)strlen($this->_encode()) . "\r\n"); + $socket->write("Content-Type: multipart/form-data, boundary=" . $this->_boundary . "\r\n"); + } + + /** + * Dispatches the form data down the socket. + * @param SimpleSocket $socket Socket to write to. + * @access public + */ + function writeTo(&$socket) { + $socket->write($this->_encode()); + } + + /** + * Renders the query string as a URL encoded + * request part. + * @return string Part of URL. + * @access public + */ + function _encode() { + $stream = ''; + foreach ($this->_request as $pair) { + $stream .= "--" . $this->_boundary . "\r\n"; + $stream .= $pair->asMime() . "\r\n"; + } + $stream .= "--" . $this->_boundary . "--\r\n"; + return $stream; } } ?> \ No newline at end of file diff --git a/vendors/simpletest/errors.php b/vendors/simpletest/errors.php index b5a327b2b..dc862fcf4 100644 --- a/vendors/simpletest/errors.php +++ b/vendors/simpletest/errors.php @@ -1,56 +1,56 @@ clear(); } - /** - * Adds an error to the front of the queue. - * @param $severity PHP error code. - * @param $message Text of error. - * @param $filename File error occoured in. - * @param $line Line number of error. - * @param $super_globals Hash of PHP super global arrays. - * @access public - */ + /** + * Adds an error to the front of the queue. + * @param $severity PHP error code. + * @param $message Text of error. + * @param $filename File error occoured in. + * @param $line Line number of error. + * @param $super_globals Hash of PHP super global arrays. + * @access public + */ function add($severity, $message, $filename, $line, $super_globals) { array_push( $this->_queue, array($severity, $message, $filename, $line, $super_globals)); } - /** - * Pulls the earliest error from the queue. - * @return False if none, or a list of error - * information. Elements are: severity - * as the PHP error code, the error message, - * the file with the error, the line number - * and a list of PHP super global arrays. - * @access public - */ + /** + * Pulls the earliest error from the queue. + * @return False if none, or a list of error + * information. Elements are: severity + * as the PHP error code, the error message, + * the file with the error, the line number + * and a list of PHP super global arrays. + * @access public + */ function extract() { if (count($this->_queue)) { return array_shift($this->_queue); @@ -58,28 +58,28 @@ return false; } - /** - * Discards the contents of the error queue. - * @access public - */ + /** + * Discards the contents of the error queue. + * @access public + */ function clear() { $this->_queue = array(); } - /** - * Tests to see if the queue is empty. - * @return True if empty. - */ + /** + * Tests to see if the queue is empty. + * @return True if empty. + */ function isEmpty() { return (count($this->_queue) == 0); } - /** - * Global access to a single error queue. - * @return Global error queue object. - * @access public - * @static - */ + /** + * Global access to a single error queue. + * @return Global error queue object. + * @access public + * @static + */ function &instance() { static $queue = false; if (! $queue) { @@ -88,14 +88,14 @@ return $queue; } - /** - * Converst an error code into it's string - * representation. - * @param $severity PHP integer error code. - * @return String version of error code. - * @access public - * @static - */ + /** + * Converst an error code into it's string + * representation. + * @param $severity PHP integer error code. + * @return String version of error code. + * @access public + * @static + */ function getSeverityAsString($severity) { static $map = array( E_STRICT => 'E_STRICT', @@ -114,18 +114,18 @@ } } - /** - * Error handler that simply stashes any errors into the global - * error queue. Simulates the existing behaviour with respect to - * logging errors, but this feature may be removed in future. - * @param $severity PHP error code. - * @param $message Text of error. - * @param $filename File error occoured in. - * @param $line Line number of error. - * @param $super_globals Hash of PHP super global arrays. - * @static - * @access public - */ + /** + * Error handler that simply stashes any errors into the global + * error queue. Simulates the existing behaviour with respect to + * logging errors, but this feature may be removed in future. + * @param $severity PHP error code. + * @param $message Text of error. + * @param $filename File error occoured in. + * @param $line Line number of error. + * @param $super_globals Hash of PHP super global arrays. + * @static + * @access public + */ function simpleTestErrorHandler($severity, $message, $filename, $line, $super_globals) { if ($severity = $severity & error_reporting()) { restore_error_handler(); diff --git a/vendors/simpletest/expectation.php b/vendors/simpletest/expectation.php index 326a73bb0..7d782cdb7 100644 --- a/vendors/simpletest/expectation.php +++ b/vendors/simpletest/expectation.php @@ -1,119 +1,119 @@ _dumper = &new SimpleDumper(); $this->_message = $message; } - /** - * Tests the expectation. True if correct. - * @param mixed $compare Comparison value. - * @return boolean True if correct. - * @access public - * @abstract - */ + /** + * Tests the expectation. True if correct. + * @param mixed $compare Comparison value. + * @return boolean True if correct. + * @access public + * @abstract + */ function test($compare) { } - /** - * Returns a human readable test message. - * @param mixed $compare Comparison value. - * @return string Description of success - * or failure. - * @access public - * @abstract - */ + /** + * Returns a human readable test message. + * @param mixed $compare Comparison value. + * @return string Description of success + * or failure. + * @access public + * @abstract + */ function testMessage($compare) { } - /** - * Overlays the generated message onto the stored user - * message. - * @param mixed $compare Comparison value. - * @return string Description of success - * or failure. - * @access public - */ + /** + * Overlays the generated message onto the stored user + * message. + * @param mixed $compare Comparison value. + * @return string Description of success + * or failure. + * @access public + */ function overlayMessage($compare) { return sprintf($this->_message, $this->testMessage($compare)); } - /** - * Accessor for the dumper. - * @return SimpleDumper Current value dumper. - * @access protected - */ + /** + * Accessor for the dumper. + * @return SimpleDumper Current value dumper. + * @access protected + */ function &_getDumper() { return $this->_dumper; } } - /** - * Test for equality. - * @package SimpleTest - * @subpackage UnitTester - */ + /** + * Test for equality. + * @package SimpleTest + * @subpackage UnitTester + */ class EqualExpectation extends SimpleExpectation { var $_value; - /** - * Sets the value to compare against. - * @param mixed $value Test value to match. - * @param string $message Customised message on failure. - * @access public - */ + /** + * Sets the value to compare against. + * @param mixed $value Test value to match. + * @param string $message Customised message on failure. + * @access public + */ function EqualExpectation($value, $message = '%s') { $this->SimpleExpectation($message); $this->_value = $value; } - /** - * Tests the expectation. True if it matches the - * held value. - * @param mixed $compare Comparison value. - * @return boolean True if correct. - * @access public - */ - function test($compare, $nasty = false) { + /** + * Tests the expectation. True if it matches the + * held value. + * @param mixed $compare Comparison value. + * @return boolean True if correct. + * @access public + */ + function test($compare) { return (($this->_value == $compare) && ($compare == $this->_value)); } - /** - * Returns a human readable test message. - * @param mixed $compare Comparison value. - * @return string Description of success - * or failure. - * @access public - */ + /** + * Returns a human readable test message. + * @param mixed $compare Comparison value. + * @return string Description of success + * or failure. + * @access public + */ function testMessage($compare) { if ($this->test($compare)) { return "Equal expectation [" . $this->_dumper->describeValue($this->_value) . "]"; @@ -123,51 +123,51 @@ } } - /** - * Accessor for comparison value. - * @return mixed Held value to compare with. - * @access protected - */ + /** + * Accessor for comparison value. + * @return mixed Held value to compare with. + * @access protected + */ function _getValue() { return $this->_value; } } - /** - * Test for inequality. - * @package SimpleTest - * @subpackage UnitTester - */ + /** + * Test for inequality. + * @package SimpleTest + * @subpackage UnitTester + */ class NotEqualExpectation extends EqualExpectation { - /** - * Sets the value to compare against. - * @param mixed $value Test value to match. - * @param string $message Customised message on failure. - * @access public - */ + /** + * Sets the value to compare against. + * @param mixed $value Test value to match. + * @param string $message Customised message on failure. + * @access public + */ function NotEqualExpectation($value, $message = '%s') { $this->EqualExpectation($value, $message); } - /** - * Tests the expectation. True if it differs from the - * held value. - * @param mixed $compare Comparison value. - * @return boolean True if correct. - * @access public - */ + /** + * Tests the expectation. True if it differs from the + * held value. + * @param mixed $compare Comparison value. + * @return boolean True if correct. + * @access public + */ function test($compare) { return ! parent::test($compare); } - /** - * Returns a human readable test message. - * @param mixed $compare Comparison value. - * @return string Description of success - * or failure. - * @access public - */ + /** + * Returns a human readable test message. + * @param mixed $compare Comparison value. + * @return string Description of success + * or failure. + * @access public + */ function testMessage($compare) { $dumper = &$this->_getDumper(); if ($this->test($compare)) { @@ -181,41 +181,162 @@ } } - /** - * Test for identity. - * @package SimpleTest - * @subpackage UnitTester - */ + /** + * Test for being within a range. + * @package SimpleTest + * @subpackage UnitTester + */ + class WithinMarginExpectation extends SimpleExpectation { + var $_upper; + var $_lower; + + /** + * Sets the value to compare against and the fuzziness of + * the match. Used for comparing floating point values. + * @param mixed $value Test value to match. + * @param mixed $margin Fuzziness of match. + * @param string $message Customised message on failure. + * @access public + */ + function WithinMarginExpectation($value, $margin, $message = '%s') { + $this->SimpleExpectation($message); + $this->_upper = $value + $margin; + $this->_lower = $value - $margin; + } + + /** + * Tests the expectation. True if it matches the + * held value. + * @param mixed $compare Comparison value. + * @return boolean True if correct. + * @access public + */ + function test($compare) { + return (($compare <= $this->_upper) && ($compare >= $this->_lower)); + } + + /** + * Returns a human readable test message. + * @param mixed $compare Comparison value. + * @return string Description of success + * or failure. + * @access public + */ + function testMessage($compare) { + if ($this->test($compare)) { + return $this->_withinMessage($compare); + } else { + return $this->_outsideMessage($compare); + } + } + + /** + * Creates a the message for being within the range. + * @param mixed $compare Value being tested. + * @access private + */ + function _withinMessage($compare) { + return "Within expectation [" . $this->_dumper->describeValue($this->_lower) . "] and [" . + $this->_dumper->describeValue($this->_upper) . "]"; + } + + /** + * Creates a the message for being within the range. + * @param mixed $compare Value being tested. + * @access private + */ + function _outsideMessage($compare) { + if ($compare > $this->_upper) { + return "Outside expectation " . + $this->_dumper->describeDifference($compare, $this->_upper); + } else { + return "Outside expectation " . + $this->_dumper->describeDifference($compare, $this->_lower); + } + } + } + + /** + * Test for being outside of a range. + * @package SimpleTest + * @subpackage UnitTester + */ + class OutsideMarginExpectation extends WithinMarginExpectation { + + /** + * Sets the value to compare against and the fuzziness of + * the match. Used for comparing floating point values. + * @param mixed $value Test value to not match. + * @param mixed $margin Fuzziness of match. + * @param string $message Customised message on failure. + * @access public + */ + function OutsideMarginExpectation($value, $margin, $message = '%s') { + $this->WithinMarginExpectation($value, $margin, $message); + } + + /** + * Tests the expectation. True if it matches the + * held value. + * @param mixed $compare Comparison value. + * @return boolean True if correct. + * @access public + */ + function test($compare) { + return ! parent::test($compare); + } + + /** + * Returns a human readable test message. + * @param mixed $compare Comparison value. + * @return string Description of success + * or failure. + * @access public + */ + function testMessage($compare) { + if (! $this->test($compare)) { + return $this->_withinMessage($compare); + } else { + return $this->_outsideMessage($compare); + } + } + } + + /** + * Test for identity. + * @package SimpleTest + * @subpackage UnitTester + */ class IdenticalExpectation extends EqualExpectation { - /** - * Sets the value to compare against. - * @param mixed $value Test value to match. - * @param string $message Customised message on failure. - * @access public - */ + /** + * Sets the value to compare against. + * @param mixed $value Test value to match. + * @param string $message Customised message on failure. + * @access public + */ function IdenticalExpectation($value, $message = '%s') { $this->EqualExpectation($value, $message); } - /** - * Tests the expectation. True if it exactly - * matches the held value. - * @param mixed $compare Comparison value. - * @return boolean True if correct. - * @access public - */ + /** + * Tests the expectation. True if it exactly + * matches the held value. + * @param mixed $compare Comparison value. + * @return boolean True if correct. + * @access public + */ function test($compare) { return SimpleTestCompatibility::isIdentical($this->_getValue(), $compare); } - /** - * Returns a human readable test message. - * @param mixed $compare Comparison value. - * @return string Description of success - * or failure. - * @access public - */ + /** + * Returns a human readable test message. + * @param mixed $compare Comparison value. + * @return string Description of success + * or failure. + * @access public + */ function testMessage($compare) { $dumper = &$this->_getDumper(); if ($this->test($compare)) { @@ -229,41 +350,41 @@ } } - /** - * Test for non-identity. - * @package SimpleTest - * @subpackage UnitTester - */ + /** + * Test for non-identity. + * @package SimpleTest + * @subpackage UnitTester + */ class NotIdenticalExpectation extends IdenticalExpectation { - /** - * Sets the value to compare against. - * @param mixed $value Test value to match. - * @param string $message Customised message on failure. - * @access public - */ + /** + * Sets the value to compare against. + * @param mixed $value Test value to match. + * @param string $message Customised message on failure. + * @access public + */ function NotIdenticalExpectation($value, $message = '%s') { $this->IdenticalExpectation($value, $message); } - /** - * Tests the expectation. True if it differs from the - * held value. - * @param mixed $compare Comparison value. - * @return boolean True if correct. - * @access public - */ + /** + * Tests the expectation. True if it differs from the + * held value. + * @param mixed $compare Comparison value. + * @return boolean True if correct. + * @access public + */ function test($compare) { return ! parent::test($compare); } - /** - * Returns a human readable test message. - * @param mixed $compare Comparison value. - * @return string Description of success - * or failure. - * @access public - */ + /** + * Returns a human readable test message. + * @param mixed $compare Comparison value. + * @return string Description of success + * or failure. + * @access public + */ function testMessage($compare) { $dumper = &$this->_getDumper(); if ($this->test($compare)) { @@ -275,52 +396,52 @@ } } - /** - * Test for a pattern using Perl regex rules. - * @package SimpleTest - * @subpackage UnitTester - */ - class WantedPatternExpectation extends SimpleExpectation { + /** + * Test for a pattern using Perl regex rules. + * @package SimpleTest + * @subpackage UnitTester + */ + class PatternExpectation extends SimpleExpectation { var $_pattern; - /** - * Sets the value to compare against. - * @param string $pattern Pattern to search for. - * @param string $message Customised message on failure. - * @access public - */ - function WantedPatternExpectation($pattern, $message = '%s') { + /** + * Sets the value to compare against. + * @param string $pattern Pattern to search for. + * @param string $message Customised message on failure. + * @access public + */ + function PatternExpectation($pattern, $message = '%s') { $this->SimpleExpectation($message); $this->_pattern = $pattern; } - /** - * Accessor for the pattern. - * @return string Perl regex as string. - * @access protected - */ + /** + * Accessor for the pattern. + * @return string Perl regex as string. + * @access protected + */ function _getPattern() { return $this->_pattern; } - /** - * Tests the expectation. True if the Perl regex - * matches the comparison value. - * @param string $compare Comparison value. - * @return boolean True if correct. - * @access public - */ + /** + * Tests the expectation. True if the Perl regex + * matches the comparison value. + * @param string $compare Comparison value. + * @return boolean True if correct. + * @access public + */ function test($compare) { return (boolean)preg_match($this->_getPattern(), $compare); } - /** - * Returns a human readable test message. - * @param mixed $compare Comparison value. - * @return string Description of success - * or failure. - * @access public - */ + /** + * Returns a human readable test message. + * @param mixed $compare Comparison value. + * @return string Description of success + * or failure. + * @access public + */ function testMessage($compare) { if ($this->test($compare)) { return $this->_describePatternMatch($this->_getPattern(), $compare); @@ -332,13 +453,13 @@ } } - /** - * Describes a pattern match including the string - * found and it's position. - * @param string $pattern Regex to match against. - * @param string $subject Subject to search. - * @access protected - */ + /** + * Describes a pattern match including the string + * found and it's position. + * @param string $pattern Regex to match against. + * @param string $subject Subject to search. + * @access protected + */ function _describePatternMatch($pattern, $subject) { preg_match($pattern, $subject, $matches); $position = strpos($subject, $matches[0]); @@ -350,42 +471,48 @@ } } - /** - * Fail if a pattern is detected within the - * comparison. - * @package SimpleTest - * @subpackage UnitTester - */ - class UnwantedPatternExpectation extends WantedPatternExpectation { + /** + * @deprecated + */ + class WantedPatternExpectation extends PatternExpectation { + } + + /** + * Fail if a pattern is detected within the + * comparison. + * @package SimpleTest + * @subpackage UnitTester + */ + class NoPatternExpectation extends PatternExpectation { - /** - * Sets the reject pattern - * @param string $pattern Pattern to search for. - * @param string $message Customised message on failure. - * @access public - */ - function UnwantedPatternExpectation($pattern, $message = '%s') { - $this->WantedPatternExpectation($pattern, $message); + /** + * Sets the reject pattern + * @param string $pattern Pattern to search for. + * @param string $message Customised message on failure. + * @access public + */ + function NoPatternExpectation($pattern, $message = '%s') { + $this->PatternExpectation($pattern, $message); } - /** - * Tests the expectation. False if the Perl regex - * matches the comparison value. - * @param string $compare Comparison value. - * @return boolean True if correct. - * @access public - */ + /** + * Tests the expectation. False if the Perl regex + * matches the comparison value. + * @param string $compare Comparison value. + * @return boolean True if correct. + * @access public + */ function test($compare) { return ! parent::test($compare); } - /** - * Returns a human readable test message. - * @param string $compare Comparison value. - * @return string Description of success - * or failure. - * @access public - */ + /** + * Returns a human readable test message. + * @param string $compare Comparison value. + * @return string Description of success + * or failure. + * @access public + */ function testMessage($compare) { if ($this->test($compare)) { $dumper = &$this->_getDumper(); @@ -398,41 +525,47 @@ } } - /** - * Tests either type or class name if it's an object. - * @package SimpleTest - * @subpackage UnitTester - */ + /** + * @deprecated + */ + class UnwantedPatternExpectation extends NoPatternExpectation { + } + + /** + * Tests either type or class name if it's an object. + * @package SimpleTest + * @subpackage UnitTester + */ class IsAExpectation extends SimpleExpectation { var $_type; - /** - * Sets the type to compare with. - * @param string $type Type or class name. - * @param string $message Customised message on failure. - * @access public - */ + /** + * Sets the type to compare with. + * @param string $type Type or class name. + * @param string $message Customised message on failure. + * @access public + */ function IsAExpectation($type, $message = '%s') { $this->SimpleExpectation($message); $this->_type = $type; } - /** - * Accessor for type to check against. - * @return string Type or class name. - * @access protected - */ + /** + * Accessor for type to check against. + * @return string Type or class name. + * @access protected + */ function _getType() { return $this->_type; } - /** - * Tests the expectation. True if the type or - * class matches the string value. - * @param string $compare Comparison value. - * @return boolean True if correct. - * @access public - */ + /** + * Tests the expectation. True if the type or + * class matches the string value. + * @param string $compare Comparison value. + * @return boolean True if correct. + * @access public + */ function test($compare) { if (is_object($compare)) { return SimpleTestCompatibility::isA($compare, $this->_type); @@ -441,12 +574,12 @@ } } - /** - * Coerces type name into a gettype() match. - * @param string $type User type. - * @return string Simpler type. - * @access private - */ + /** + * Coerces type name into a gettype() match. + * @param string $type User type. + * @return string Simpler type. + * @access private + */ function _canonicalType($type) { $type = strtolower($type); $map = array( @@ -460,13 +593,13 @@ return $type; } - /** - * Returns a human readable test message. - * @param mixed $compare Comparison value. - * @return string Description of success - * or failure. - * @access public - */ + /** + * Returns a human readable test message. + * @param mixed $compare Comparison value. + * @return string Description of success + * or failure. + * @access public + */ function testMessage($compare) { $dumper = &$this->_getDumper(); return "Value [" . $dumper->describeValue($compare) . @@ -474,43 +607,43 @@ } } - /** - * Tests either type or class name if it's an object. - * Will succeed if the type does not match. - * @package SimpleTest - * @subpackage UnitTester - */ + /** + * Tests either type or class name if it's an object. + * Will succeed if the type does not match. + * @package SimpleTest + * @subpackage UnitTester + */ class NotAExpectation extends IsAExpectation { var $_type; - /** - * Sets the type to compare with. - * @param string $type Type or class name. - * @param string $message Customised message on failure. - * @access public - */ + /** + * Sets the type to compare with. + * @param string $type Type or class name. + * @param string $message Customised message on failure. + * @access public + */ function NotAExpectation($type, $message = '%s') { $this->IsAExpectation($type, $message); } - /** - * Tests the expectation. False if the type or - * class matches the string value. - * @param string $compare Comparison value. - * @return boolean True if different. - * @access public - */ + /** + * Tests the expectation. False if the type or + * class matches the string value. + * @param string $compare Comparison value. + * @return boolean True if different. + * @access public + */ function test($compare) { return ! parent::test($compare); } - /** - * Returns a human readable test message. - * @param mixed $compare Comparison value. - * @return string Description of success - * or failure. - * @access public - */ + /** + * Returns a human readable test message. + * @param mixed $compare Comparison value. + * @return string Description of success + * or failure. + * @access public + */ function testMessage($compare) { $dumper = &$this->_getDumper(); return "Value [" . $dumper->describeValue($compare) . @@ -518,51 +651,51 @@ } } - /** - * Tests for existance of a method in an object - * @package SimpleTest - * @subpackage UnitTester - */ + /** + * Tests for existance of a method in an object + * @package SimpleTest + * @subpackage UnitTester + */ class MethodExistsExpectation extends SimpleExpectation { var $_method; - /** - * Sets the value to compare against. - * @param string $method Method to check. - * @param string $message Customised message on failure. - * @access public - * @return void - */ + /** + * Sets the value to compare against. + * @param string $method Method to check. + * @param string $message Customised message on failure. + * @access public + * @return void + */ function MethodExistsExpectation($method, $message = '%s') { $this->SimpleExpectation($message); $this->_method = &$method; } - /** - * Tests the expectation. True if the method exists in the test object. - * @param string $compare Comparison method name. - * @return boolean True if correct. - * @access public - */ + /** + * Tests the expectation. True if the method exists in the test object. + * @param string $compare Comparison method name. + * @return boolean True if correct. + * @access public + */ function test($compare) { return (boolean)(is_object($compare) && method_exists($compare, $this->_method)); } - /** - * Returns a human readable test message. - * @param mixed $compare Comparison value. - * @return string Description of success - * or failure. - * @access public - */ + /** + * Returns a human readable test message. + * @param mixed $compare Comparison value. + * @return string Description of success + * or failure. + * @access public + */ function testMessage($compare) { - $dumper = &$this->_getDumper(); - if (! is_object($compare)) { - return 'No method on non-object [' . $dumper->describeValue($compare) . ']'; - } - $method = $this->_method; - return "Object [" . $dumper->describeValue($compare) . - "] should contain method [$method]"; + $dumper = &$this->_getDumper(); + if (! is_object($compare)) { + return 'No method on non-object [' . $dumper->describeValue($compare) . ']'; + } + $method = $this->_method; + return "Object [" . $dumper->describeValue($compare) . + "] should contain method [$method]"; } } ?> \ No newline at end of file diff --git a/vendors/simpletest/extensions/pear_test_case.php b/vendors/simpletest/extensions/pear_test_case.php index ccad94a04..70c4b3a0b 100644 --- a/vendors/simpletest/extensions/pear_test_case.php +++ b/vendors/simpletest/extensions/pear_test_case.php @@ -1,84 +1,84 @@ SimpleTestCase($label); $this->_loosely_typed = false; } - /** - * Will test straight equality if set to loose - * typing, or identity if not. - * @param $first First value. - * @param $second Comparison value. - * @param $message Message to display. - * @public - */ + /** + * Will test straight equality if set to loose + * typing, or identity if not. + * @param $first First value. + * @param $second Comparison value. + * @param $message Message to display. + * @public + */ function assertEquals($first, $second, $message = "%s", $delta = 0) { if ($this->_loosely_typed) { $expectation = &new EqualExpectation($first); } else { $expectation = &new IdenticalExpectation($first); } - $this->assertExpectation($expectation, $second, $message); + $this->assert($expectation, $second, $message); } - /** - * Passes if the value tested is not null. - * @param $value Value to test against. - * @param $message Message to display. - * @public - */ + /** + * Passes if the value tested is not null. + * @param $value Value to test against. + * @param $message Message to display. + * @public + */ function assertNotNull($value, $message = "%s") { parent::assertTrue(isset($value), $message); } - /** - * Passes if the value tested is null. - * @param $value Value to test against. - * @param $message Message to display. - * @public - */ + /** + * Passes if the value tested is null. + * @param $value Value to test against. + * @param $message Message to display. + * @public + */ function assertNull($value, $message = "%s") { parent::assertTrue(!isset($value), $message); } - /** - * In PHP5 the identity test tests for the same - * object. This is a reference test in PHP4. - * @param $first First object handle. - * @param $second Hopefully the same handle. - * @param $message Message to display. - * @public - */ + /** + * In PHP5 the identity test tests for the same + * object. This is a reference test in PHP4. + * @param $first First object handle. + * @param $second Hopefully the same handle. + * @param $message Message to display. + * @public + */ function assertSame(&$first, &$second, $message = "%s") { $dumper = &new SimpleDumper(); $message = sprintf( @@ -91,14 +91,14 @@ $message); } - /** - * In PHP5 the identity test tests for the same - * object. This is a reference test in PHP4. - * @param $first First object handle. - * @param $second Hopefully a different handle. - * @param $message Message to display. - * @public - */ + /** + * In PHP5 the identity test tests for the same + * object. This is a reference test in PHP4. + * @param $first First object handle. + * @param $second Hopefully a different handle. + * @param $message Message to display. + * @public + */ function assertNotSame(&$first, &$second, $message = "%s") { $dumper = &new SimpleDumper(); $message = sprintf( @@ -111,88 +111,85 @@ $message); } - /** - * Sends pass if the test condition resolves true, - * a fail otherwise. - * @param $condition Condition to test true. - * @param $message Message to display. - * @public - */ + /** + * Sends pass if the test condition resolves true, + * a fail otherwise. + * @param $condition Condition to test true. + * @param $message Message to display. + * @public + */ function assertTrue($condition, $message = "%s") { parent::assertTrue($condition, $message); } - /** - * Sends pass if the test condition resolves false, - * a fail otherwise. - * @param $condition Condition to test false. - * @param $message Message to display. - * @public - */ + /** + * Sends pass if the test condition resolves false, + * a fail otherwise. + * @param $condition Condition to test false. + * @param $message Message to display. + * @public + */ function assertFalse($condition, $message = "%s") { parent::assertTrue(!$condition, $message); } - /** - * Tests a regex match. Needs refactoring. - * @param $pattern Regex to match. - * @param $subject String to search in. - * @param $message Message to display. - * @public - */ + /** + * Tests a regex match. Needs refactoring. + * @param $pattern Regex to match. + * @param $subject String to search in. + * @param $message Message to display. + * @public + */ function assertRegExp($pattern, $subject, $message = "%s") { - $this->assertExpectation( - new WantedPatternExpectation($pattern), - $subject, - $message); + $this->assert(new PatternExpectation($pattern), $subject, $message); } - /** - * Tests the type of a value. - * @param $value Value to take type of. - * @param $type Hoped for type. - * @param $message Message to display. - * @public - */ + /** + * Tests the type of a value. + * @param $value Value to take type of. + * @param $type Hoped for type. + * @param $message Message to display. + * @public + */ function assertType($value, $type, $message = "%s") { parent::assertTrue(gettype($value) == strtolower($type), $message); } - /** - * Sets equality operation to act as a simple equal - * comparison only, allowing a broader range of - * matches. - * @param $loosely_typed True for broader comparison. - * @public - */ + /** + * Sets equality operation to act as a simple equal + * comparison only, allowing a broader range of + * matches. + * @param $loosely_typed True for broader comparison. + * @public + */ function setLooselyTyped($loosely_typed) { $this->_loosely_typed = $loosely_typed; } - /** - * For progress indication during - * a test amongst other things. - * @return Usually one. - * @public - */ + /** + * For progress indication during + * a test amongst other things. + * @return Usually one. + * @public + */ function countTestCases() { return $this->getSize(); } - /** - * Accessor for name, normally just the class - * name. - * @public - */ + /** + * Accessor for name, normally just the class + * name. + * @public + */ function getName() { return $this->getLabel(); } - /** - * Does nothing. For compatibility only. - * @param $name Dummy - * @public - */ + /** + * Does nothing. For compatibility only. + * @param $name Dummy + * @public + */ function setName($name) { } } diff --git a/vendors/simpletest/extensions/phpunit_test_case.php b/vendors/simpletest/extensions/phpunit_test_case.php index 15c7ccad6..3c12b7d6e 100644 --- a/vendors/simpletest/extensions/phpunit_test_case.php +++ b/vendors/simpletest/extensions/phpunit_test_case.php @@ -1,106 +1,94 @@ SimpleTestCase($label); } - /** - * Sends pass if the test condition resolves true, - * a fail otherwise. - * @param $condition Condition to test true. - * @param $message Message to display. - * @public - */ + /** + * Sends pass if the test condition resolves true, + * a fail otherwise. + * @param $condition Condition to test true. + * @param $message Message to display. + * @public + */ function assert($condition, $message = false) { parent::assertTrue($condition, $message); } - /** - * Will test straight equality if set to loose - * typing, or identity if not. - * @param $first First value. - * @param $second Comparison value. - * @param $message Message to display. - * @public - */ + /** + * Will test straight equality if set to loose + * typing, or identity if not. + * @param $first First value. + * @param $second Comparison value. + * @param $message Message to display. + * @public + */ function assertEquals($first, $second, $message = false) { - $this->assertExpectation( - new EqualExpectation($first), - $second, - $message); + parent::assert(new EqualExpectation($first), $second, $message); } - /** - * Will test straight equality if set to loose - * typing, or identity if not. - * @param $first First value. - * @param $second Comparison value. - * @param $message Message to display. - * @public - */ + /** + * Simple string equality. + * @param $first First value. + * @param $second Comparison value. + * @param $message Message to display. + * @public + */ function assertEqualsMultilineStrings($first, $second, $message = false) { - $this->assertExpectation( - new EqualExpectation($first), - $second, - $message); + parent::assert(new EqualExpectation($first), $second, $message); } - /** - * Tests a regex match. - * @param $pattern Regex to match. - * @param $subject String to search in. - * @param $message Message to display. - * @public - */ + /** + * Tests a regex match. + * @param $pattern Regex to match. + * @param $subject String to search in. + * @param $message Message to display. + * @public + */ function assertRegexp($pattern, $subject, $message = false) { - $this->assertExpectation( - new WantedPatternExpectation($pattern), - $subject, - $message); + parent::assert(new PatternExpectation($pattern), $subject, $message); } - /** - * Sends an error which we interpret as a fail - * with a different message for compatibility. - * @param $message Message to display. - * @public - */ + /** + * Sends an error which we interpret as a fail + * with a different message for compatibility. + * @param $message Message to display. + * @public + */ function error($message) { - parent::assertTrue(false, "Error triggered [$message]"); + parent::fail("Error triggered [$message]"); } - /** - * Accessor for name. - * @public - */ + /** + * Accessor for name. + * @public + */ function name() { return $this->getLabel(); } diff --git a/vendors/simpletest/form.php b/vendors/simpletest/form.php index 59dfdc0ac..b1d28393e 100644 --- a/vendors/simpletest/form.php +++ b/vendors/simpletest/form.php @@ -1,108 +1,28 @@ _name = $name; - } - - /** - * Comparison. Compares with name attribute of - * widget. - * @param SimpleWidget $widget Control to compare. - * @access public - */ - function isMatch($widget) { - return ($widget->getName() == $this->_name); - } - } - - /** - * Used to extract form elements for testing against. - * Searches by visible label or alt text. - * @package SimpleTest - * @subpackage WebTester - */ - class SimpleLabelSelector { - var $_label; - - /** - * Stashes the name for later comparison. - * @param string $label Visible text to match. - */ - function SimpleLabelSelector($label) { - $this->_label = $label; - } - - /** - * Comparison. Compares visible text of widget. - * @param SimpleWidget $widget Control to compare. - * @access public - */ - function isMatch($widget) { - return (trim($widget->getLabel()) == trim($this->_label)); - } - } - - /** - * Used to extract form elements for testing against. - * Searches dy id attribute. - * @package SimpleTest - * @subpackage WebTester - */ - class SimpleIdSelector { - var $_id; - - /** - * Stashes the name for later comparison. - * @param string $id ID atribute to match. - */ - function SimpleIdSelector($id) { - $this->_id = $id; - } - - /** - * Comparison. Compares id attribute of widget. - * @param SimpleWidget $widget Control to compare. - * @access public - */ - function isMatch($widget) { - return $widget->isId($this->_id); - } - } - - /** - * Form tag class to hold widget values. - * @package SimpleTest - * @subpackage WebTester - */ + /** + * Form tag class to hold widget values. + * @package SimpleTest + * @subpackage WebTester + */ class SimpleForm { var $_method; var $_action; + var $_encoding; var $_default_target; var $_id; var $_buttons; @@ -111,14 +31,15 @@ var $_radios; var $_checkboxes; - /** - * Starts with no held controls/widgets. - * @param SimpleTag $tag Form tag to read. - * @param SimpleUrl $url Location of holding page. - */ + /** + * Starts with no held controls/widgets. + * @param SimpleTag $tag Form tag to read. + * @param SimpleUrl $url Location of holding page. + */ function SimpleForm($tag, $url) { $this->_method = $tag->getAttribute('method'); $this->_action = $this->_createAction($tag->getAttribute('action'), $url); + $this->_encoding = $this->_setEncodingClass($tag); $this->_default_target = false; $this->_id = $tag->getAttribute('id'); $this->_buttons = array(); @@ -128,48 +49,60 @@ $this->_checkboxes = array(); } - /** - * Sets the frame target within a frameset. - * @param string $frame Name of frame. - * @access public - */ + /** + * Creates the request packet to be sent by the form. + * @param SimpleTag $tag Form tag to read. + * @return string Packet class. + * @access private + */ + function _setEncodingClass($tag) { + if (strtolower($tag->getAttribute('method')) == 'post') { + if (strtolower($tag->getAttribute('enctype')) == 'multipart/form-data') { + return 'SimpleMultipartEncoding'; + } + return 'SimplePostEncoding'; + } + return 'SimpleGetEncoding'; + } + + /** + * Sets the frame target within a frameset. + * @param string $frame Name of frame. + * @access public + */ function setDefaultTarget($frame) { $this->_default_target = $frame; } - /** - * Accessor for form action. - * @return string Either get or post. - * @access public - */ + /** + * Accessor for form action. + * @return string Either get or post. + * @access public + */ function getMethod() { return ($this->_method ? strtolower($this->_method) : 'get'); } - /** - * Combined action attribute with current location - * to get an absolute form target. - * @param string $action Action attribute from form tag. - * @param SimpleUrl $base Page location. - * @return SimpleUrl Absolute form target. - */ + /** + * Combined action attribute with current location + * to get an absolute form target. + * @param string $action Action attribute from form tag. + * @param SimpleUrl $base Page location. + * @return SimpleUrl Absolute form target. + */ function _createAction($action, $base) { - if ($action === false) { + if (is_bool($action)) { return $base; } - if ($action === true) { - $url = new SimpleUrl(''); - } else { - $url = new SimpleUrl($action); - } + $url = new SimpleUrl($action); return $url->makeAbsolute($base); } - /** - * Absolute URL of the target. - * @return SimpleUrl URL target. - * @access public - */ + /** + * Absolute URL of the target. + * @return SimpleUrl URL target. + * @access public + */ function getAction() { $url = $this->_action; if ($this->_default_target && ! $url->getTarget()) { @@ -177,22 +110,37 @@ } return $url; } - - /** - * ID field of form for unique identification. - * @return string Unique tag ID. - * @access public - */ + + /** + * Creates the encoding for the current values in the + * form. + * @return SimpleFormEncoding Request to submit. + * @access private + */ + function _encode() { + $class = $this->_encoding; + $encoding = new $class(); + for ($i = 0, $count = count($this->_widgets); $i < $count; $i++) { + $this->_widgets[$i]->write($encoding); + } + return $encoding; + } + + /** + * ID field of form for unique identification. + * @return string Unique tag ID. + * @access public + */ function getId() { return $this->_id; } - /** - * Adds a tag contents to the form. - * @param SimpleWidget $tag Input tag to add. - * @access public - */ - function addWidget($tag) { + /** + * Adds a tag contents to the form. + * @param SimpleWidget $tag Input tag to add. + * @access public + */ + function addWidget(&$tag) { if (strtolower($tag->getAttribute('type')) == 'submit') { $this->_buttons[] = &$tag; } elseif (strtolower($tag->getAttribute('type')) == 'image') { @@ -202,13 +150,13 @@ } } - /** - * Sets the widget into the form, grouping radio - * buttons if any. - * @param SimpleWidget $tag Incoming form control. - * @access private - */ - function _setWidget($tag) { + /** + * Sets the widget into the form, grouping radio + * buttons if any. + * @param SimpleWidget $tag Incoming form control. + * @access private + */ + function _setWidget(&$tag) { if (strtolower($tag->getAttribute('type')) == 'radio') { $this->_addRadioButton($tag); } elseif (strtolower($tag->getAttribute('type')) == 'checkbox') { @@ -218,12 +166,12 @@ } } - /** - * Adds a radio button, building a group if necessary. - * @param SimpleRadioButtonTag $tag Incoming form control. - * @access private - */ - function _addRadioButton($tag) { + /** + * Adds a radio button, building a group if necessary. + * @param SimpleRadioButtonTag $tag Incoming form control. + * @access private + */ + function _addRadioButton(&$tag) { if (! isset($this->_radios[$tag->getName()])) { $this->_widgets[] = &new SimpleRadioGroup(); $this->_radios[$tag->getName()] = count($this->_widgets) - 1; @@ -231,12 +179,12 @@ $this->_widgets[$this->_radios[$tag->getName()]]->addWidget($tag); } - /** - * Adds a checkbox, making it a group on a repeated name. - * @param SimpleCheckboxTag $tag Incoming form control. - * @access private - */ - function _addCheckbox($tag) { + /** + * Adds a checkbox, making it a group on a repeated name. + * @param SimpleCheckboxTag $tag Incoming form control. + * @access private + */ + function _addCheckbox(&$tag) { if (! isset($this->_checkboxes[$tag->getName()])) { $this->_widgets[] = &$tag; $this->_checkboxes[$tag->getName()] = count($this->_widgets) - 1; @@ -251,14 +199,14 @@ } } - /** - * Extracts current value from form. - * @param SimpleSelector $selector Criteria to apply. - * @return string/array Value(s) as string or null - * if not set. - * @access public - */ - function _getValueBySelector($selector) { + /** + * Extracts current value from form. + * @param SimpleSelector $selector Criteria to apply. + * @return string/array Value(s) as string or null + * if not set. + * @access public + */ + function getValue($selector) { for ($i = 0, $count = count($this->_widgets); $i < $count; $i++) { if ($selector->isMatch($this->_widgets[$i])) { return $this->_widgets[$i]->getValue(); @@ -272,38 +220,16 @@ return null; } - /** - * Extracts current value from form. - * @param string $name Keyed by widget name. - * @return string/array Value(s) or null - * if not set. - * @access public - */ - function getValue($name) { - return $this->_getValueBySelector(new SimpleNameSelector($name)); - } - - /** - * Extracts current value from form by the ID. - * @param string/integer $id Keyed by widget ID attribute. - * @return string/array Value(s) or null - * if not set. - * @access public - */ - function getValueById($id) { - return $this->_getValueBySelector(new SimpleIdSelector($id)); - } - - /** - * Sets a widget value within the form. - * @param SimpleSelector $selector Criteria to apply. - * @param string $value Value to input into the widget. - * @return boolean True if value is legal, false - * otherwise. If the field is not - * present, nothing will be set. - * @access public - */ - function _setFieldBySelector($selector, $value) { + /** + * Sets a widget value within the form. + * @param SimpleSelector $selector Criteria to apply. + * @param string $value Value to input into the widget. + * @return boolean True if value is legal, false + * otherwise. If the field is not + * present, nothing will be set. + * @access public + */ + function setField($selector, $value) { $success = false; for ($i = 0, $count = count($this->_widgets); $i < $count; $i++) { if ($selector->isMatch($this->_widgets[$i])) { @@ -315,55 +241,31 @@ return $success; } - /** - * Sets a widget value within the form. - * @param string $name Name of widget tag. - * @param string $value Value to input into the widget. - * @return boolean True if value is legal, false - * otherwise. If the field is not - * present, nothing will be set. - * @access public - */ - function setField($name, $value) { - return $this->_setFieldBySelector(new SimpleNameSelector($name), $value); - } - - /** - * Sets a widget value within the form by using the ID. - * @param string/integer $id Name of widget tag. - * @param string $value Value to input into the widget. - * @return boolean True if value is legal, false - * otherwise. If the field is not - * present, nothing will be set. - * @access public - */ - function setFieldById($id, $value) { - return $this->_setFieldBySelector(new SimpleIdSelector($id), $value); - } - - /** - * Creates the encoding for the current values in the - * form. - * @return SimpleFormEncoding Request to submit. - * @access private - */ - function _getEncoding() { - $encoding = new SimpleFormEncoding(); + /** + * Used by the page object to set widgets labels to + * external label tags. + * @param SimpleSelector $selector Criteria to apply. + * @access public + */ + function attachLabelBySelector($selector, $label) { for ($i = 0, $count = count($this->_widgets); $i < $count; $i++) { - $encoding->add( - $this->_widgets[$i]->getName(), - $this->_widgets[$i]->getValue()); + if ($selector->isMatch($this->_widgets[$i])) { + if (method_exists($this->_widgets[$i], 'setLabel')) { + $this->_widgets[$i]->setLabel($label); + return; + } + } } - return $encoding; } - /** - * Test to see if a form has a submit button. - * @param SimpleSelector $selector Criteria to apply. - * @return boolean True if present. - * @access private - */ - function _hasSubmitBySelector($selector) { + /** + * Test to see if a form has a submit button. + * @param SimpleSelector $selector Criteria to apply. + * @return boolean True if present. + * @access private + * @access public + */ + function hasSubmit($selector) { foreach ($this->_buttons as $button) { if ($selector->isMatch($button)) { return true; @@ -372,46 +274,13 @@ return false; } - /** - * Test to see if a form has a submit button with this - * name attribute. - * @param string $name Name to look for. - * @return boolean True if present. - * @access public - */ - function hasSubmitName($name) { - return $this->_hasSubmitBySelector(new SimpleNameSelector($name)); - } - - /** - * Test to see if a form has a submit button with this - * value attribute. - * @param string $label Button label to search for. - * @return boolean True if present. - * @access public - */ - function hasSubmitLabel($label) { - return $this->_hasSubmitBySelector(new SimpleLabelSelector($label)); - } - - /** - * Test to see if a form has a submit button with this - * ID attribute. - * @param string $id Button ID attribute to search for. - * @return boolean True if present. - * @access public - */ - function hasSubmitId($id) { - return $this->_hasSubmitBySelector(new SimpleIdSelector($id)); - } - - /** - * Test to see if a form has an image control. - * @param SimpleSelector $selector Criteria to apply. - * @return boolean True if present. - * @access public - */ - function _hasImageBySelector($selector) { + /** + * Test to see if a form has an image control. + * @param SimpleSelector $selector Criteria to apply. + * @return boolean True if present. + * @access public + */ + function hasImage($selector) { foreach ($this->_images as $image) { if ($selector->isMatch($image)) { return true; @@ -419,54 +288,21 @@ } return false; } - - /** - * Test to see if a form has a submit button with this - * name attribute. - * @param string $label Button alt attribute to search for - * or nearest equivalent. - * @return boolean True if present. - * @access public - */ - function hasImageLabel($label) { - return $this->_hasImageBySelector(new SimpleLabelSelector($label)); - } - - /** - * Test to see if a form has a submittable image with this - * field name. - * @param string $name Image name to search for. - * @return boolean True if present. - * @access public - */ - function hasImageName($name) { - return $this->_hasImageBySelector(new SimpleNameSelector($name)); - } - - /** - * Test to see if a form has a submittable image with this - * ID attribute. - * @param string $id Button ID attribute to search for. - * @return boolean True if present. - * @access public - */ - function hasImageId($id) { - return $this->_hasImageBySelector(new SimpleIdSelector($id)); - } - /** - * Gets the submit values for a selected button. - * @param SimpleSelector $selector Criteria to apply. - * @param hash $additional Additional data for the form. - * @return SimpleEncoding Submitted values or false - * if there is no such button - * in the form. - * @access public - */ - function _submitButtonBySelector($selector, $additional) { + /** + * Gets the submit values for a selected button. + * @param SimpleSelector $selector Criteria to apply. + * @param hash $additional Additional data for the form. + * @return SimpleEncoding Submitted values or false + * if there is no such button + * in the form. + * @access public + */ + function submitButton($selector, $additional = false) { + $additional = $additional ? $additional : array(); foreach ($this->_buttons as $button) { if ($selector->isMatch($button)) { - $encoding = $this->_getEncoding(); + $encoding = $this->_encode(); $encoding->merge($button->getSubmitValues()); if ($additional) { $encoding->merge($additional); @@ -476,67 +312,23 @@ } return false; } - - /** - * Gets the submit values for a named button. - * @param string $name Button label to search for. - * @param hash $additional Additional data for the form. - * @return SimpleEncoding Submitted values or false - * if there is no such button in the - * form. - * @access public - */ - function submitButtonByName($name, $additional = false) { - return $this->_submitButtonBySelector( - new SimpleNameSelector($name), - $additional); - } - - /** - * Gets the submit values for a named button. - * @param string $label Button label to search for. - * @param hash $additional Additional data for the form. - * @return SimpleEncoding Submitted values or false - * if there is no such button in the - * form. - * @access public - */ - function submitButtonByLabel($label, $additional = false) { - return $this->_submitButtonBySelector( - new SimpleLabelSelector($label), - $additional); - } - - /** - * Gets the submit values for a button identified by the ID. - * @param string $id Button ID attribute to search for. - * @param hash $additional Additional data for the form. - * @return SimpleEncoding Submitted values or false - * if there is no such button in the - * form. - * @access public - */ - function submitButtonById($id, $additional = false) { - return $this->_submitButtonBySelector( - new SimpleIdSelector($id), - $additional); - } - /** - * Gets the submit values for an image. - * @param SimpleSelector $selector Criteria to apply. - * @param integer $x X-coordinate of click. - * @param integer $y Y-coordinate of click. - * @param hash $additional Additional data for the form. - * @return SimpleEncoding Submitted values or false - * if there is no such button in the - * form. - * @access public - */ - function _submitImageBySelector($selector, $x, $y, $additional) { + /** + * Gets the submit values for an image. + * @param SimpleSelector $selector Criteria to apply. + * @param integer $x X-coordinate of click. + * @param integer $y Y-coordinate of click. + * @param hash $additional Additional data for the form. + * @return SimpleEncoding Submitted values or false + * if there is no such button in the + * form. + * @access public + */ + function submitImage($selector, $x, $y, $additional = false) { + $additional = $additional ? $additional : array(); foreach ($this->_images as $image) { if ($selector->isMatch($image)) { - $encoding = $this->_getEncoding(); + $encoding = $this->_encode(); $encoding->merge($image->getSubmitValues($x, $y)); if ($additional) { $encoding->merge($additional); @@ -546,74 +338,16 @@ } return false; } - - /** - * Gets the submit values for an image identified by the alt - * tag or nearest equivalent. - * @param string $label Button label to search for. - * @param integer $x X-coordinate of click. - * @param integer $y Y-coordinate of click. - * @param hash $additional Additional data for the form. - * @return SimpleEncoding Submitted values or false - * if there is no such button in the - * form. - * @access public - */ - function submitImageByLabel($label, $x, $y, $additional = false) { - return $this->_submitImageBySelector( - new SimpleLabelSelector($label), - $x, - $y, - $additional); - } - - /** - * Gets the submit values for an image identified by the ID. - * @param string $name Image name to search for. - * @param integer $x X-coordinate of click. - * @param integer $y Y-coordinate of click. - * @param hash $additional Additional data for the form. - * @return SimpleEncoding Submitted values or false - * if there is no such button in the - * form. - * @access public - */ - function submitImageByName($name, $x, $y, $additional = false) { - return $this->_submitImageBySelector( - new SimpleNameSelector($name), - $x, - $y, - $additional); - } - - /** - * Gets the submit values for an image identified by the ID. - * @param string/integer $id Button ID attribute to search for. - * @param integer $x X-coordinate of click. - * @param integer $y Y-coordinate of click. - * @param hash $additional Additional data for the form. - * @return SimpleEncoding Submitted values or false - * if there is no such button in the - * form. - * @access public - */ - function submitImageById($id, $x, $y, $additional = false) { - return $this->_submitImageBySelector( - new SimpleIdSelector($id), - $x, - $y, - $additional); - } - /** - * Simply submits the form without the submit button - * value. Used when there is only one button or it - * is unimportant. - * @return hash Submitted values. - * @access public - */ + /** + * Simply submits the form without the submit button + * value. Used when there is only one button or it + * is unimportant. + * @return hash Submitted values. + * @access public + */ function submit() { - return $this->_getEncoding(); + return $this->_encode(); } } ?> \ No newline at end of file diff --git a/vendors/simpletest/frames.php b/vendors/simpletest/frames.php index 5e4258af2..45605e2fe 100644 --- a/vendors/simpletest/frames.php +++ b/vendors/simpletest/frames.php @@ -1,37 +1,37 @@ _frameset = &$page; $this->_frames = array(); @@ -39,12 +39,12 @@ $this->_names = array(); } - /** - * Adds a parsed page to the frameset. - * @param SimplePage $page Frame page. - * @param string $name Name of frame in frameset. - * @access public - */ + /** + * Adds a parsed page to the frameset. + * @param SimplePage $page Frame page. + * @param string $name Name of frame in frameset. + * @access public + */ function addFrame(&$page, $name = false) { $this->_frames[] = &$page; if ($name) { @@ -52,14 +52,14 @@ } } - /** - * Replaces existing frame with another. If the - * frame is nested, then the call is passed down - * one level. - * @param array $path Path of frame in frameset. - * @param SimplePage $page Frame source. - * @access public - */ + /** + * Replaces existing frame with another. If the + * frame is nested, then the call is passed down + * one level. + * @param array $path Path of frame in frameset. + * @param SimplePage $page Frame source. + * @access public + */ function setFrame($path, &$page) { $name = array_shift($path); if (isset($this->_names[$name])) { @@ -74,13 +74,13 @@ $this->_frames[$index]->setFrame($path, $page); } - /** - * Accessor for current frame focus. Will be - * false if no frame has focus. Will have the nested - * frame focus if any. - * @return array Labels or indexes of nested frames. - * @access public - */ + /** + * Accessor for current frame focus. Will be + * false if no frame has focus. Will have the nested + * frame focus if any. + * @return array Labels or indexes of nested frames. + * @access public + */ function getFrameFocus() { if ($this->_focus === false) { return array(); @@ -90,14 +90,14 @@ $this->_frames[$this->_focus]->getFrameFocus()); } - /** - * Turns an internal array index into the frames list - * into a public name, or if none, then a one offset - * index. - * @param integer $subject Internal index. - * @return integer/string Public name. - * @access private - */ + /** + * Turns an internal array index into the frames list + * into a public name, or if none, then a one offset + * index. + * @param integer $subject Internal index. + * @return integer/string Public name. + * @access private + */ function _getPublicNameFromIndex($subject) { foreach ($this->_names as $name => $index) { if ($subject == $index) { @@ -107,14 +107,14 @@ return $subject + 1; } - /** - * Sets the focus by index. The integer index starts from 1. - * If already focused and the target frame also has frames, - * then the nested frame will be focused. - * @param integer $choice Chosen frame. - * @return boolean True if frame exists. - * @access public - */ + /** + * Sets the focus by index. The integer index starts from 1. + * If already focused and the target frame also has frames, + * then the nested frame will be focused. + * @param integer $choice Chosen frame. + * @return boolean True if frame exists. + * @access public + */ function setFrameFocusByIndex($choice) { if (is_integer($this->_focus)) { if ($this->_frames[$this->_focus]->hasFrames()) { @@ -128,14 +128,14 @@ return true; } - /** - * Sets the focus by name. If already focused and the - * target frame also has frames, then the nested frame - * will be focused. - * @param string $name Chosen frame. - * @return boolean True if frame exists. - * @access public - */ + /** + * Sets the focus by name. If already focused and the + * target frame also has frames, then the nested frame + * will be focused. + * @param string $name Chosen frame. + * @return boolean True if frame exists. + * @access public + */ function setFrameFocus($name) { if (is_integer($this->_focus)) { if ($this->_frames[$this->_focus]->hasFrames()) { @@ -149,41 +149,41 @@ return false; } - /** - * Clears the frame focus. - * @access public - */ + /** + * Clears the frame focus. + * @access public + */ function clearFrameFocus() { $this->_focus = false; $this->_clearNestedFramesFocus(); } - /** - * Clears the frame focus for any nested frames. - * @access private - */ + /** + * Clears the frame focus for any nested frames. + * @access private + */ function _clearNestedFramesFocus() { for ($i = 0; $i < count($this->_frames); $i++) { $this->_frames[$i]->clearFrameFocus(); } } - /** - * Test for the presence of a frameset. - * @return boolean Always true. - * @access public - */ + /** + * Test for the presence of a frameset. + * @return boolean Always true. + * @access public + */ function hasFrames() { return true; } - /** - * Accessor for frames information. - * @return array/string Recursive hash of frame URL strings. - * The key is either a numerical - * index or the name attribute. - * @access public - */ + /** + * Accessor for frames information. + * @return array/string Recursive hash of frame URL strings. + * The key is either a numerical + * index or the name attribute. + * @access public + */ function getFrames() { $report = array(); for ($i = 0; $i < count($this->_frames); $i++) { @@ -193,12 +193,12 @@ return $report; } - /** - * Accessor for raw text of either all the pages or - * the frame in focus. - * @return string Raw unparsed content. - * @access public - */ + /** + * Accessor for raw text of either all the pages or + * the frame in focus. + * @return string Raw unparsed content. + * @access public + */ function getRaw() { if (is_integer($this->_focus)) { return $this->_frames[$this->_focus]->getRaw(); @@ -210,12 +210,12 @@ return $raw; } - /** - * Accessor for plain text of either all the pages or - * the frame in focus. - * @return string Plain text content. - * @access public - */ + /** + * Accessor for plain text of either all the pages or + * the frame in focus. + * @return string Plain text content. + * @access public + */ function getText() { if (is_integer($this->_focus)) { return $this->_frames[$this->_focus]->getText(); @@ -227,11 +227,11 @@ return trim($raw); } - /** - * Accessor for last error. - * @return string Error from last response. - * @access public - */ + /** + * Accessor for last error. + * @return string Error from last response. + * @access public + */ function getTransportError() { if (is_integer($this->_focus)) { return $this->_frames[$this->_focus]->getTransportError(); @@ -239,11 +239,11 @@ return $this->_frameset->getTransportError(); } - /** - * Request method used to fetch this frame. - * @return string GET, POST or HEAD. - * @access public - */ + /** + * Request method used to fetch this frame. + * @return string GET, POST or HEAD. + * @access public + */ function getMethod() { if (is_integer($this->_focus)) { return $this->_frames[$this->_focus]->getMethod(); @@ -251,11 +251,11 @@ return $this->_frameset->getMethod(); } - /** - * Original resource name. - * @return SimpleUrl Current url. - * @access public - */ + /** + * Original resource name. + * @return SimpleUrl Current url. + * @access public + */ function getUrl() { if (is_integer($this->_focus)) { $url = $this->_frames[$this->_focus]->getUrl(); @@ -266,11 +266,11 @@ return $url; } - /** - * Original request data. - * @return mixed Sent content. - * @access public - */ + /** + * Original request data. + * @return mixed Sent content. + * @access public + */ function getRequestData() { if (is_integer($this->_focus)) { return $this->_frames[$this->_focus]->getRequestData(); @@ -278,11 +278,11 @@ return $this->_frameset->getRequestData(); } - /** - * Accessor for current MIME type. - * @return string MIME type as string; e.g. 'text/html' - * @access public - */ + /** + * Accessor for current MIME type. + * @return string MIME type as string; e.g. 'text/html' + * @access public + */ function getMimeType() { if (is_integer($this->_focus)) { return $this->_frames[$this->_focus]->getMimeType(); @@ -290,11 +290,11 @@ return $this->_frameset->getMimeType(); } - /** - * Accessor for last response code. - * @return integer Last HTTP response code received. - * @access public - */ + /** + * Accessor for last response code. + * @return integer Last HTTP response code received. + * @access public + */ function getResponseCode() { if (is_integer($this->_focus)) { return $this->_frames[$this->_focus]->getResponseCode(); @@ -302,12 +302,12 @@ return $this->_frameset->getResponseCode(); } - /** - * Accessor for last Authentication type. Only valid - * straight after a challenge (401). - * @return string Description of challenge type. - * @access public - */ + /** + * Accessor for last Authentication type. Only valid + * straight after a challenge (401). + * @return string Description of challenge type. + * @access public + */ function getAuthentication() { if (is_integer($this->_focus)) { return $this->_frames[$this->_focus]->getAuthentication(); @@ -315,12 +315,12 @@ return $this->_frameset->getAuthentication(); } - /** - * Accessor for last Authentication realm. Only valid - * straight after a challenge (401). - * @return string Name of security realm. - * @access public - */ + /** + * Accessor for last Authentication realm. Only valid + * straight after a challenge (401). + * @return string Name of security realm. + * @access public + */ function getRealm() { if (is_integer($this->_focus)) { return $this->_frames[$this->_focus]->getRealm(); @@ -328,11 +328,11 @@ return $this->_frameset->getRealm(); } - /** - * Accessor for outgoing header information. - * @return string Header block. - * @access public - */ + /** + * Accessor for outgoing header information. + * @return string Header block. + * @access public + */ function getRequest() { if (is_integer($this->_focus)) { return $this->_frames[$this->_focus]->getRequest(); @@ -340,11 +340,11 @@ return $this->_frameset->getRequest(); } - /** - * Accessor for raw header information. - * @return string Header block. - * @access public - */ + /** + * Accessor for raw header information. + * @return string Header block. + * @access public + */ function getHeaders() { if (is_integer($this->_focus)) { return $this->_frames[$this->_focus]->getHeaders(); @@ -352,21 +352,21 @@ return $this->_frameset->getHeaders(); } - /** - * Accessor for parsed title. - * @return string Title or false if no title is present. - * @access public - */ + /** + * Accessor for parsed title. + * @return string Title or false if no title is present. + * @access public + */ function getTitle() { return $this->_frameset->getTitle(); } - /** - * Accessor for a list of all fixed links. - * @return array List of urls with scheme of - * http or https and hostname. - * @access public - */ + /** + * Accessor for a list of all fixed links. + * @return array List of urls with scheme of + * http or https and hostname. + * @access public + */ function getAbsoluteUrls() { if (is_integer($this->_focus)) { return $this->_frames[$this->_focus]->getAbsoluteUrls(); @@ -378,11 +378,11 @@ return array_values(array_unique($urls)); } - /** - * Accessor for a list of all relative links. - * @return array List of urls without hostname. - * @access public - */ + /** + * Accessor for a list of all relative links. + * @return array List of urls without hostname. + * @access public + */ function getRelativeUrls() { if (is_integer($this->_focus)) { return $this->_frames[$this->_focus]->getRelativeUrls(); @@ -394,13 +394,13 @@ return array_values(array_unique($urls)); } - /** - * Accessor for URLs by the link label. Label will match - * regardess of whitespace issues and case. - * @param string $label Text of link. - * @return array List of links with that label. - * @access public - */ + /** + * Accessor for URLs by the link label. Label will match + * regardess of whitespace issues and case. + * @param string $label Text of link. + * @return array List of links with that label. + * @access public + */ function getUrlsByLabel($label) { if (is_integer($this->_focus)) { return $this->_tagUrlsWithFrame( @@ -418,15 +418,15 @@ return $urls; } - /** - * Accessor for a URL by the id attribute. If in a frameset - * then the first link found with that ID attribute is - * returned only. Focus on a frame if you want one from - * a specific part of the frameset. - * @param string $id Id attribute of link. - * @return string URL with that id. - * @access public - */ + /** + * Accessor for a URL by the id attribute. If in a frameset + * then the first link found with that ID attribute is + * returned only. Focus on a frame if you want one from + * a specific part of the frameset. + * @param string $id Id attribute of link. + * @return string URL with that id. + * @access public + */ function getUrlById($id) { foreach ($this->_frames as $index => $frame) { if ($url = $frame->getUrlById($id)) { @@ -439,13 +439,13 @@ return false; } - /** - * Attaches the intended frame index to a list of URLs. - * @param array $urls List of SimpleUrls. - * @param string $frame Name of frame or index. - * @return array List of tagged URLs. - * @access private - */ + /** + * Attaches the intended frame index to a list of URLs. + * @param array $urls List of SimpleUrls. + * @param string $frame Name of frame or index. + * @return array List of tagged URLs. + * @access private + */ function _tagUrlsWithFrame($urls, $frame) { $tagged = array(); foreach ($urls as $url) { @@ -457,113 +457,121 @@ return $tagged; } - /** - * Finds a held form by button label. Will only - * search correctly built forms. The first form found - * either within the focused frame, or across frames, - * will be the one returned. - * @param string $label Button label, default 'Submit'. - * @return SimpleForm Form object containing the button. - * @access public - */ + /** + * Finds a held form by button label. Will only + * search correctly built forms. The first form found + * either within the focused frame, or across frames, + * will be the one returned. + * @param string $label Button label, default 'Submit'. + * @return SimpleForm Form object containing the button. + * @access public + */ function &getFormBySubmitLabel($label) { - return $this->_findForm('getFormBySubmitLabel', $label); + $form = &$this->_findForm('getFormBySubmitLabel', $label); + return $form; } - /** - * Finds a held form by button label. Will only - * search correctly built forms. The first form found - * either within the focused frame, or across frames, - * will be the one returned. - * @param string $name Button name attribute. - * @return SimpleForm Form object containing the button. - * @access public - */ + /** + * Finds a held form by button label. Will only + * search correctly built forms. The first form found + * either within the focused frame, or across frames, + * will be the one returned. + * @param string $name Button name attribute. + * @return SimpleForm Form object containing the button. + * @access public + */ function &getFormBySubmitName($name) { - return $this->_findForm('getFormBySubmitName', $name); + $form = &$this->_findForm('getFormBySubmitName', $name); + return $form; } - /** - * Finds a held form by button id. Will only - * search correctly built forms. The first form found - * either within the focused frame, or across frames, - * will be the one returned. - * @param string $id Button ID attribute. - * @return SimpleForm Form object containing the button. - * @access public - */ + /** + * Finds a held form by button id. Will only + * search correctly built forms. The first form found + * either within the focused frame, or across frames, + * will be the one returned. + * @param string $id Button ID attribute. + * @return SimpleForm Form object containing the button. + * @access public + */ function &getFormBySubmitId($id) { - return $this->_findForm('getFormBySubmitId', $id); + $form = &$this->_findForm('getFormBySubmitId', $id); + return $form; } - /** - * Finds a held form by image label. Will only - * search correctly built forms. The first form found - * either within the focused frame, or across frames, - * will be the one returned. - * @param string $label Usually the alt attribute. - * @return SimpleForm Form object containing the image. - * @access public - */ + /** + * Finds a held form by image label. Will only + * search correctly built forms. The first form found + * either within the focused frame, or across frames, + * will be the one returned. + * @param string $label Usually the alt attribute. + * @return SimpleForm Form object containing the image. + * @access public + */ function &getFormByImageLabel($label) { - return $this->_findForm('getFormByImageLabel', $label); + $form = &$this->_findForm('getFormByImageLabel', $label); + return $form; } - /** - * Finds a held form by image button id. Will only - * search correctly built forms. The first form found - * either within the focused frame, or across frames, - * will be the one returned. - * @param string $name Image name. - * @return SimpleForm Form object containing the image. - * @access public - */ + /** + * Finds a held form by image button id. Will only + * search correctly built forms. The first form found + * either within the focused frame, or across frames, + * will be the one returned. + * @param string $name Image name. + * @return SimpleForm Form object containing the image. + * @access public + */ function &getFormByImageName($name) { - return $this->_findForm('getFormByImageName', $name); + $form = &$this->_findForm('getFormByImageName', $name); + return $form; } - /** - * Finds a held form by image button id. Will only - * search correctly built forms. The first form found - * either within the focused frame, or across frames, - * will be the one returned. - * @param string $id Image ID attribute. - * @return SimpleForm Form object containing the image. - * @access public - */ + /** + * Finds a held form by image button id. Will only + * search correctly built forms. The first form found + * either within the focused frame, or across frames, + * will be the one returned. + * @param string $id Image ID attribute. + * @return SimpleForm Form object containing the image. + * @access public + */ function &getFormByImageId($id) { - return $this->_findForm('getFormByImageId', $id); + $form = &$this->_findForm('getFormByImageId', $id); + return $form; } - /** - * Finds a held form by the form ID. A way of - * identifying a specific form when we have control - * of the HTML code. The first form found - * either within the focused frame, or across frames, - * will be the one returned. - * @param string $id Form label. - * @return SimpleForm Form object containing the matching ID. - * @access public - */ + /** + * Finds a held form by the form ID. A way of + * identifying a specific form when we have control + * of the HTML code. The first form found + * either within the focused frame, or across frames, + * will be the one returned. + * @param string $id Form label. + * @return SimpleForm Form object containing the matching ID. + * @access public + */ function &getFormById($id) { - return $this->_findForm('getFormById', $id); + $form = &$this->_findForm('getFormById', $id); + return $form; } - /** - * General form finder. Will search all the frames or - * just the one in focus. - * @param string $method Method to use to find in a page. - * @param string $attribute Label, name or ID. - * @return SimpleForm Form object containing the matching ID. - * @access private - */ + /** + * General form finder. Will search all the frames or + * just the one in focus. + * @param string $method Method to use to find in a page. + * @param string $attribute Label, name or ID. + * @return SimpleForm Form object containing the matching ID. + * @access private + */ function &_findForm($method, $attribute) { if (is_integer($this->_focus)) { - return $this->_findFormInFrame( + $form = &$this->_findFormInFrame( $this->_frames[$this->_focus], $this->_focus, $method, $attribute); + return $form; } for ($i = 0; $i < count($this->_frames); $i++) { $form = &$this->_findFormInFrame( @@ -575,19 +583,20 @@ return $form; } } - return null; + $null = null; + return $null; } - /** - * Finds a form in a page using a form finding method. Will - * also tag the form with the frame name it belongs in. - * @param SimplePage $page Page content of frame. - * @param integer $index Internal frame representation. - * @param string $method Method to use to find in a page. - * @param string $attribute Label, name or ID. - * @return SimpleForm Form object containing the matching ID. - * @access private - */ + /** + * Finds a form in a page using a form finding method. Will + * also tag the form with the frame name it belongs in. + * @param SimplePage $page Page content of frame. + * @param integer $index Internal frame representation. + * @param string $method Method to use to find in a page. + * @param string $attribute Label, name or ID. + * @return SimpleForm Form object containing the matching ID. + * @access private + */ function &_findFormInFrame(&$page, $index, $method, $attribute) { $form = &$this->_frames[$index]->$method($attribute); if (isset($form)) { @@ -596,32 +605,51 @@ return $form; } - /** - * Sets a field on each form in which the field is - * available. - * @param string $name Field name. - * @param string $value Value to set field to. - * @return boolean True if value is valid. - * @access public - */ - function setField($name, $value) { + /** + * Sets a field on each form in which the field is + * available by label and then name. labels are not + * yet implemented. + * @param string $label Field name. + * @param string $value Value to set field to. + * @return boolean True if value is valid. + * @access public + */ + function setField($label, $value) { if (is_integer($this->_focus)) { - $this->_frames[$this->_focus]->setField($name, $value); + $this->_frames[$this->_focus]->setField($label, $value); } else { for ($i = 0; $i < count($this->_frames); $i++) { - $this->_frames[$i]->setField($name, $value); + $this->_frames[$i]->setField($label, $value); + } + } + } + + /** + * Sets a field on each form in which the field is + * available. + * @param string $name Field name. + * @param string $value Value to set field to. + * @return boolean True if value is valid. + * @access public + */ + function setFieldByName($name, $value) { + if (is_integer($this->_focus)) { + $this->_frames[$this->_focus]->setFieldByName($name, $value); + } else { + for ($i = 0; $i < count($this->_frames); $i++) { + $this->_frames[$i]->setFieldByName($name, $value); } } } - /** - * Sets a field on the form in which the unique field is - * available. - * @param string/integer $id Field ID attribute. - * @param string $value Value to set field to. - * @return boolean True if value is valid. - * @access public - */ + /** + * Sets a field on the form in which the unique field is + * available. + * @param string/integer $id Field ID attribute. + * @param string $value Value to set field to. + * @return boolean True if value is valid. + * @access public + */ function setFieldById($id, $value) { if (is_integer($this->_focus)) { $this->_frames[$this->_focus]->setFieldById($id, $value); @@ -632,18 +660,37 @@ } } - /** - * Accessor for a form element value within a frameset. - * Finds the first match amongst the frames. - * @param string $name Field name. - * @return string/boolean A string if the field is - * present, false if unchecked - * and null if missing. - * @access public - */ - function getField($name) { + /** + * Accessor for a form element value within a frameset. + * Finds the first match amongst the frames. + * @param string $label Field label. + * @return string/boolean A string if the field is + * present, false if unchecked + * and null if missing. + * @access public + */ + function getField($label) { for ($i = 0; $i < count($this->_frames); $i++) { - $value = $this->_frames[$i]->getField($name); + $value = $this->_frames[$i]->getField($label); + if (isset($value)) { + return $value; + } + } + return null; + } + + /** + * Accessor for a form element value within a frameset. + * Finds the first match amongst the frames. + * @param string $name Field name. + * @return string/boolean A string if the field is + * present, false if unchecked + * and null if missing. + * @access public + */ + function getFieldByName($name) { + for ($i = 0; $i < count($this->_frames); $i++) { + $value = $this->_frames[$i]->getFieldByName($name); if (isset($value)) { return $value; } @@ -651,15 +698,15 @@ return null; } - /** - * Accessor for a form element value within a page. - * Finds the first match. - * @param string/integer $id Field ID attribute. - * @return string/boolean A string if the field is - * present, false if unchecked - * and null if missing. - * @access public - */ + /** + * Accessor for a form element value within a page. + * Finds the first match. + * @param string/integer $id Field ID attribute. + * @return string/boolean A string if the field is + * present, false if unchecked + * and null if missing. + * @access public + */ function getFieldById($id) { for ($i = 0; $i < count($this->_frames); $i++) { $value = $this->_frames[$i]->getFieldById($id); diff --git a/vendors/simpletest/http.php b/vendors/simpletest/http.php index fcc8effd3..1f504fa5b 100644 --- a/vendors/simpletest/http.php +++ b/vendors/simpletest/http.php @@ -1,26 +1,26 @@ _host = false; $this->_name = $name; @@ -51,16 +51,16 @@ $this->_is_secure = $is_secure; } - /** - * Sets the host. The cookie rules determine - * that the first two parts are taken for - * certain TLDs and three for others. If the - * new host does not match these rules then the - * call will fail. - * @param string $host New hostname. - * @return boolean True if hostname is valid. - * @access public - */ + /** + * Sets the host. The cookie rules determine + * that the first two parts are taken for + * certain TLDs and three for others. If the + * new host does not match these rules then the + * call will fail. + * @param string $host New hostname. + * @return boolean True if hostname is valid. + * @access public + */ function setHost($host) { if ($host = $this->_truncateHost($host)) { $this->_host = $host; @@ -69,33 +69,33 @@ return false; } - /** - * Accessor for the truncated host to which this - * cookie applies. - * @return string Truncated hostname. - * @access public - */ + /** + * Accessor for the truncated host to which this + * cookie applies. + * @return string Truncated hostname. + * @access public + */ function getHost() { return $this->_host; } - /** - * Test for a cookie being valid for a host name. - * @param string $host Host to test against. - * @return boolean True if the cookie would be valid - * here. - */ + /** + * Test for a cookie being valid for a host name. + * @param string $host Host to test against. + * @return boolean True if the cookie would be valid + * here. + */ function isValidHost($host) { return ($this->_truncateHost($host) === $this->getHost()); } - /** - * Extracts just the domain part that determines a - * cookie's host validity. - * @param string $host Host name to truncate. - * @return string Domain or false on a bad host. - * @access private - */ + /** + * Extracts just the domain part that determines a + * cookie's host validity. + * @param string $host Host name to truncate. + * @return string Domain or false on a bad host. + * @access private + */ function _truncateHost($host) { $tlds = SimpleUrl::getAllTopLevelDomains(); if (preg_match('/[a-z\-]+\.(' . $tlds . ')$/i', $host, $matches)) { @@ -106,42 +106,42 @@ return false; } - /** - * Accessor for name. - * @return string Cookie key. - * @access public - */ + /** + * Accessor for name. + * @return string Cookie key. + * @access public + */ function getName() { return $this->_name; } - /** - * Accessor for value. A deleted cookie will - * have an empty string for this. - * @return string Cookie value. - * @access public - */ + /** + * Accessor for value. A deleted cookie will + * have an empty string for this. + * @return string Cookie value. + * @access public + */ function getValue() { return $this->_value; } - /** - * Accessor for path. - * @return string Valid cookie path. - * @access public - */ + /** + * Accessor for path. + * @return string Valid cookie path. + * @access public + */ function getPath() { return $this->_path; } - /** - * Tests a path to see if the cookie applies - * there. The test path must be longer or - * equal to the cookie path. - * @param string $path Path to test against. - * @return boolean True if cookie valid here. - * @access public - */ + /** + * Tests a path to see if the cookie applies + * there. The test path must be longer or + * equal to the cookie path. + * @param string $path Path to test against. + * @return boolean True if cookie valid here. + * @access public + */ function isValidPath($path) { return (strncmp( $this->_fixPath($path), @@ -149,11 +149,11 @@ strlen($this->getPath())) == 0); } - /** - * Accessor for expiry. - * @return string Expiry string. - * @access public - */ + /** + * Accessor for expiry. + * @return string Expiry string. + * @access public + */ function getExpiry() { if (! $this->_expiry) { return false; @@ -161,17 +161,17 @@ return gmdate("D, d M Y H:i:s", $this->_expiry) . " GMT"; } - /** - * Test to see if cookie is expired against - * the cookie format time or timestamp. - * Will give true for a session cookie. - * @param integer/string $now Time to test against. Result - * will be false if this time - * is later than the cookie expiry. - * Can be either a timestamp integer - * or a cookie format date. - * @access public - */ + /** + * Test to see if cookie is expired against + * the cookie format time or timestamp. + * Will give true for a session cookie. + * @param integer/string $now Time to test against. Result + * will be false if this time + * is later than the cookie expiry. + * Can be either a timestamp integer + * or a cookie format date. + * @access public + */ function isExpired($now) { if (! $this->_expiry) { return true; @@ -182,33 +182,33 @@ return ($this->_expiry < $now); } - /** - * Ages the cookie by the specified number of - * seconds. - * @param integer $interval In seconds. - * @public - */ + /** + * Ages the cookie by the specified number of + * seconds. + * @param integer $interval In seconds. + * @public + */ function agePrematurely($interval) { if ($this->_expiry) { $this->_expiry -= $interval; } } - /** - * Accessor for the secure flag. - * @return boolean True if cookie needs SSL. - * @access public - */ + /** + * Accessor for the secure flag. + * @return boolean True if cookie needs SSL. + * @access public + */ function isSecure() { return $this->_is_secure; } - /** - * Adds a trailing and leading slash to the path - * if missing. - * @param string $path Path to fix. - * @access private - */ + /** + * Adds a trailing and leading slash to the path + * if missing. + * @param string $path Path to fix. + * @access private + */ function _fixPath($path) { if (substr($path, 0, 1) != '/') { $path = '/' . $path; @@ -220,49 +220,49 @@ } } - /** - * Creates HTTP headers for the end point of - * a HTTP request. - * @package SimpleTest - * @subpackage WebTester - */ + /** + * Creates HTTP headers for the end point of + * a HTTP request. + * @package SimpleTest + * @subpackage WebTester + */ class SimpleRoute { var $_url; - /** - * Sets the target URL. - * @param SimpleUrl $url URL as object. - * @access public - */ + /** + * Sets the target URL. + * @param SimpleUrl $url URL as object. + * @access public + */ function SimpleRoute($url) { $this->_url = $url; } - /** - * Resource name. - * @return SimpleUrl Current url. - * @access protected - */ + /** + * Resource name. + * @return SimpleUrl Current url. + * @access protected + */ function getUrl() { return $this->_url; } - /** - * Creates the first line which is the actual request. - * @param string $method HTTP request method, usually GET. - * @return string Request line content. - * @access protected - */ + /** + * Creates the first line which is the actual request. + * @param string $method HTTP request method, usually GET. + * @return string Request line content. + * @access protected + */ function _getRequestLine($method) { return $method . ' ' . $this->_url->getPath() . $this->_url->getEncodedRequest() . ' HTTP/1.0'; } - /** - * Creates the host part of the request. - * @return string Host line content. - * @access protected - */ + /** + * Creates the host part of the request. + * @return string Host line content. + * @access protected + */ function _getHostLine() { $line = 'Host: ' . $this->_url->getHost(); if ($this->_url->getPort()) { @@ -271,13 +271,13 @@ return $line; } - /** - * Opens a socket to the route. - * @param string $method HTTP request method, usually GET. - * @param integer $timeout Connection timeout. - * @return SimpleSocket New socket. - * @access public - */ + /** + * Opens a socket to the route. + * @param string $method HTTP request method, usually GET. + * @param integer $timeout Connection timeout. + * @return SimpleSocket New socket. + * @access public + */ function &createConnection($method, $timeout) { $default_port = ('https' == $this->_url->getScheme()) ? 443 : 80; $socket = &$this->_createSocket( @@ -293,42 +293,44 @@ return $socket; } - /** - * Factory for socket. - * @param string $scheme Protocol to use. - * @param string $host Hostname to connect to. - * @param integer $port Remote port. - * @param integer $timeout Connection timeout. - * @return SimpleSocket/SimpleSecureSocket New socket. - * @access protected - */ + /** + * Factory for socket. + * @param string $scheme Protocol to use. + * @param string $host Hostname to connect to. + * @param integer $port Remote port. + * @param integer $timeout Connection timeout. + * @return SimpleSocket/SimpleSecureSocket New socket. + * @access protected + */ function &_createSocket($scheme, $host, $port, $timeout) { if (in_array($scheme, array('https'))) { - return new SimpleSecureSocket($host, $port, $timeout); + $socket = &new SimpleSecureSocket($host, $port, $timeout); + } else { + $socket = &new SimpleSocket($host, $port, $timeout); } - return new SimpleSocket($host, $port, $timeout); + return $socket; } } - /** - * Creates HTTP headers for the end point of - * a HTTP request via a proxy server. - * @package SimpleTest - * @subpackage WebTester - */ + /** + * Creates HTTP headers for the end point of + * a HTTP request via a proxy server. + * @package SimpleTest + * @subpackage WebTester + */ class SimpleProxyRoute extends SimpleRoute { var $_proxy; var $_username; var $_password; - /** - * Stashes the proxy address. - * @param SimpleUrl $url URL as object. - * @param string $proxy Proxy URL. - * @param string $username Username for autentication. - * @param string $password Password for autentication. - * @access public - */ + /** + * Stashes the proxy address. + * @param SimpleUrl $url URL as object. + * @param string $proxy Proxy URL. + * @param string $username Username for autentication. + * @param string $password Password for autentication. + * @access public + */ function SimpleProxyRoute($url, $proxy, $username = false, $password = false) { $this->SimpleRoute($url); $this->_proxy = $proxy; @@ -336,13 +338,13 @@ $this->_password = $password; } - /** - * Creates the first line which is the actual request. - * @param string $method HTTP request method, usually GET. - * @param SimpleUrl $url URL as object. - * @return string Request line content. - * @access protected - */ + /** + * Creates the first line which is the actual request. + * @param string $method HTTP request method, usually GET. + * @param SimpleUrl $url URL as object. + * @return string Request line content. + * @access protected + */ function _getRequestLine($method) { $url = $this->getUrl(); $scheme = $url->getScheme() ? $url->getScheme() : 'http'; @@ -351,153 +353,136 @@ $url->getPath() . $url->getEncodedRequest() . ' HTTP/1.0'; } - /** - * Creates the host part of the request. - * @param SimpleUrl $url URL as object. - * @return string Host line content. - * @access protected - */ + /** + * Creates the host part of the request. + * @param SimpleUrl $url URL as object. + * @return string Host line content. + * @access protected + */ function _getHostLine() { $host = 'Host: ' . $this->_proxy->getHost(); $port = $this->_proxy->getPort() ? $this->_proxy->getPort() : 8080; return "$host:$port"; } - /** - * Opens a socket to the route. - * @param string $method HTTP request method, usually GET. - * @param integer $timeout Connection timeout. - * @return SimpleSocket New socket. - * @access public - */ + /** + * Opens a socket to the route. + * @param string $method HTTP request method, usually GET. + * @param integer $timeout Connection timeout. + * @return SimpleSocket New socket. + * @access public + */ function &createConnection($method, $timeout) { $socket = &$this->_createSocket( $this->_proxy->getScheme() ? $this->_proxy->getScheme() : 'http', $this->_proxy->getHost(), $this->_proxy->getPort() ? $this->_proxy->getPort() : 8080, $timeout); - if (! $socket->isError()) { - $socket->write($this->_getRequestLine($method) . "\r\n"); - $socket->write($this->_getHostLine() . "\r\n"); - if ($this->_username && $this->_password) { - $socket->write('Proxy-Authorization: Basic ' . - base64_encode($this->_username . ':' . $this->_password) . - "\r\n"); - } - $socket->write("Connection: close\r\n"); + if ($socket->isError()) { + return $socket; } + $socket->write($this->_getRequestLine($method) . "\r\n"); + $socket->write($this->_getHostLine() . "\r\n"); + if ($this->_username && $this->_password) { + $socket->write('Proxy-Authorization: Basic ' . + base64_encode($this->_username . ':' . $this->_password) . + "\r\n"); + } + $socket->write("Connection: close\r\n"); return $socket; } } - /** - * HTTP request for a web page. Factory for - * HttpResponse object. - * @package SimpleTest - * @subpackage WebTester - */ + /** + * HTTP request for a web page. Factory for + * HttpResponse object. + * @package SimpleTest + * @subpackage WebTester + */ class SimpleHttpRequest { var $_route; - var $_method; var $_encoding; var $_headers; var $_cookies; - /** - * Saves the URL ready for fetching. - * @param SimpleRoute $route Request route. - * @param string $method HTTP request method, - * usually GET. - * @param SimpleFormEncoding $encoding Content to send with - * request or false. - * @access public - */ - function SimpleHttpRequest(&$route, $method, $encoding = false) { + /** + * Builds the socket request from the different pieces. + * These include proxy information, URL, cookies, headers, + * request method and choice of encoding. + * @param SimpleRoute $route Request route. + * @param SimpleFormEncoding $encoding Content to send with + * request. + * @access public + */ + function SimpleHttpRequest(&$route, $encoding) { $this->_route = &$route; - $this->_method = $method; $this->_encoding = $encoding; $this->_headers = array(); $this->_cookies = array(); } - /** - * Fetches the content and parses the headers. - * @param integer $timeout Connection timeout. - * @return SimpleHttpResponse A response which may only have - * an error. - * @access public - */ + /** + * Dispatches the content to the route's socket. + * @param integer $timeout Connection timeout. + * @return SimpleHttpResponse A response which may only have + * an error, but hopefully has a + * complete web page. + * @access public + */ function &fetch($timeout) { - $socket = &$this->_route->createConnection($this->_method, $timeout); - if ($socket->isError()) { - return $this->_createResponse($socket); + $socket = &$this->_route->createConnection($this->_encoding->getMethod(), $timeout); + if (! $socket->isError()) { + $this->_dispatchRequest($socket, $this->_encoding); } - $this->_dispatchRequest($socket, $this->_method, $this->_encoding); - return $this->_createResponse($socket); + $response = &$this->_createResponse($socket); + return $response; } - /** - * Sends the headers. - * @param SimpleSocket $socket Open socket. - * @param string $method HTTP request method, - * usually GET. - * @param SimpleFormEncoding $encoding Content to send with request. - * @access private - */ - function _dispatchRequest(&$socket, $method, $encoding) { - if ($encoding || ($method == 'POST')) { - $socket->write("Content-Length: " . $this->_getContentLength($encoding) . "\r\n"); - $socket->write("Content-Type: application/x-www-form-urlencoded\r\n"); - } + /** + * Sends the headers. + * @param SimpleSocket $socket Open socket. + * @param string $method HTTP request method, + * usually GET. + * @param SimpleFormEncoding $encoding Content to send with request. + * @access private + */ + function _dispatchRequest(&$socket, $encoding) { foreach ($this->_headers as $header_line) { $socket->write($header_line . "\r\n"); } if (count($this->_cookies) > 0) { $socket->write("Cookie: " . $this->_marshallCookies($this->_cookies) . "\r\n"); } + $encoding->writeHeadersTo($socket); $socket->write("\r\n"); - if ($encoding) { - $socket->write($encoding->asString()); - } + $encoding->writeTo($socket); } - /** - * Calculates the length of the encoded content. - * @param SimpleFormEncoding $encoding Content to send with - * request or false. - */ - function _getContentLength($encoding) { - if (! $encoding) { - return 0; - } - return (integer)strlen($encoding->asString()); - } - - /** - * Adds a header line to the request. - * @param string $header_line Text of header line. - * @access public - */ + /** + * Adds a header line to the request. + * @param string $header_line Text of full header line. + * @access public + */ function addHeaderLine($header_line) { $this->_headers[] = $header_line; } - /** - * Adds a cookie to the request. - * @param SimpleCookie $cookie Additional cookie. - * @access public - */ + /** + * Adds a cookie to the request. + * @param SimpleCookie $cookie Additional cookie. + * @access public + */ function setCookie($cookie) { $this->_cookies[] = $cookie; } - /** - * Serialises the cookie hash ready for - * transmission. - * @param hash $cookies Parsed cookies. - * @return array Cookies in header form. - * @access private - */ + /** + * Serialises the cookie hash ready for + * transmission. + * @param hash $cookies Parsed cookies. + * @return array Cookies in header form. + * @access private + */ function _marshallCookies($cookies) { $cookie_pairs = array(); foreach ($cookies as $cookie) { @@ -506,26 +491,26 @@ return implode(";", $cookie_pairs); } - /** - * Wraps the socket in a response parser. - * @param SimpleSocket $socket Responding socket. - * @return SimpleHttpResponse Parsed response object. - * @access protected - */ + /** + * Wraps the socket in a response parser. + * @param SimpleSocket $socket Responding socket. + * @return SimpleHttpResponse Parsed response object. + * @access protected + */ function &_createResponse(&$socket) { - return new SimpleHttpResponse( + $response = &new SimpleHttpResponse( $socket, - $this->_method, $this->_route->getUrl(), $this->_encoding); + return $response; } } - /** - * Collection of header lines in the response. - * @package SimpleTest - * @subpackage WebTester - */ + /** + * Collection of header lines in the response. + * @package SimpleTest + * @subpackage WebTester + */ class SimpleHttpHeaders { var $_raw_headers; var $_response_code; @@ -536,11 +521,11 @@ var $_authentication; var $_realm; - /** - * Parses the incoming header block. - * @param string $headers Header block. - * @access public - */ + /** + * Parses the incoming header block. + * @param string $headers Header block. + * @access public + */ function SimpleHttpHeaders($headers) { $this->_raw_headers = $headers; $this->_response_code = false; @@ -555,109 +540,109 @@ } } - /** - * Accessor for parsed HTTP protocol version. - * @return integer HTTP error code. - * @access public - */ + /** + * Accessor for parsed HTTP protocol version. + * @return integer HTTP error code. + * @access public + */ function getHttpVersion() { return $this->_http_version; } - /** - * Accessor for raw header block. - * @return string All headers as raw string. - * @access public - */ + /** + * Accessor for raw header block. + * @return string All headers as raw string. + * @access public + */ function getRaw() { return $this->_raw_headers; } - /** - * Accessor for parsed HTTP error code. - * @return integer HTTP error code. - * @access public - */ + /** + * Accessor for parsed HTTP error code. + * @return integer HTTP error code. + * @access public + */ function getResponseCode() { return (integer)$this->_response_code; } - /** - * Returns the redirected URL or false if - * no redirection. - * @return string URL or false for none. - * @access public - */ + /** + * Returns the redirected URL or false if + * no redirection. + * @return string URL or false for none. + * @access public + */ function getLocation() { return $this->_location; } - /** - * Test to see if the response is a valid redirect. - * @return boolean True if valid redirect. - * @access public - */ + /** + * Test to see if the response is a valid redirect. + * @return boolean True if valid redirect. + * @access public + */ function isRedirect() { return in_array($this->_response_code, array(301, 302, 303, 307)) && (boolean)$this->getLocation(); } - /** - * Test to see if the response is an authentication - * challenge. - * @return boolean True if challenge. - * @access public - */ + /** + * Test to see if the response is an authentication + * challenge. + * @return boolean True if challenge. + * @access public + */ function isChallenge() { return ($this->_response_code == 401) && (boolean)$this->_authentication && (boolean)$this->_realm; } - /** - * Accessor for MIME type header information. - * @return string MIME type. - * @access public - */ + /** + * Accessor for MIME type header information. + * @return string MIME type. + * @access public + */ function getMimeType() { return $this->_mime_type; } - /** - * Accessor for authentication type. - * @return string Type. - * @access public - */ + /** + * Accessor for authentication type. + * @return string Type. + * @access public + */ function getAuthentication() { return $this->_authentication; } - /** - * Accessor for security realm. - * @return string Realm. - * @access public - */ + /** + * Accessor for security realm. + * @return string Realm. + * @access public + */ function getRealm() { return $this->_realm; } - /** - * Accessor for any new cookies. - * @return array List of new cookies. - * @access public - */ + /** + * Accessor for any new cookies. + * @return array List of new cookies. + * @access public + */ function getNewCookies() { return $this->_cookies; } - /** - * Called on each header line to accumulate the held - * data within the class. - * @param string $header_line One line of header. - * @access protected - */ + /** + * Called on each header line to accumulate the held + * data within the class. + * @param string $header_line One line of header. + * @access protected + */ function _parseHeaderLine($header_line) { - if (preg_match('/HTTP\/(\d+\.\d+)\s+(.*?)\s/i', $header_line, $matches)) { + if (preg_match('/HTTP\/(\d+\.\d+)\s+(\S*)/i', $header_line, $matches)) { $this->_http_version = $matches[1]; $this->_response_code = $matches[2]; } @@ -676,12 +661,12 @@ } } - /** - * Parse the Set-cookie content. - * @param string $cookie_line Text after "Set-cookie:" - * @return SimpleCookie New cookie object. - * @access private - */ + /** + * Parse the Set-cookie content. + * @param string $cookie_line Text after "Set-cookie:" + * @return SimpleCookie New cookie object. + * @access private + */ function _parseCookie($cookie_line) { $parts = split(";", $cookie_line); $cookie = array(); @@ -699,34 +684,31 @@ } } - /** - * Basic HTTP response. - * @package SimpleTest - * @subpackage WebTester - */ + /** + * Basic HTTP response. + * @package SimpleTest + * @subpackage WebTester + */ class SimpleHttpResponse extends SimpleStickyError { - var $_method; var $_url; - var $_request_data; + var $_encoding; var $_sent; var $_content; var $_headers; - /** - * Constructor. Reads and parses the incoming - * content and headers. - * @param SimpleSocket $socket Network connection to fetch - * response text from. - * @param string $method HTTP request method. - * @param SimpleUrl $url Resource name. - * @param mixed $request_data Record of content sent. - * @access public - */ - function SimpleHttpResponse(&$socket, $method, $url, $request_data = '') { + /** + * Constructor. Reads and parses the incoming + * content and headers. + * @param SimpleSocket $socket Network connection to fetch + * response text from. + * @param SimpleUrl $url Resource name. + * @param mixed $encoding Record of content sent. + * @access public + */ + function SimpleHttpResponse(&$socket, $url, $encoding) { $this->SimpleStickyError(); - $this->_method = $method; $this->_url = $url; - $this->_request_data = $request_data; + $this->_encoding = $encoding; $this->_sent = $socket->getSent(); $this->_content = false; $raw = $this->_readAll($socket); @@ -737,11 +719,11 @@ $this->_parse($raw); } - /** - * Splits up the headers and the rest of the content. - * @param string $raw Content to parse. - * @access private - */ + /** + * Splits up the headers and the rest of the content. + * @param string $raw Content to parse. + * @access private + */ function _parse($raw) { if (! $raw) { $this->_setError('Nothing fetched'); @@ -755,79 +737,79 @@ } } - /** - * Original request method. - * @return string GET, POST or HEAD. - * @access public - */ + /** + * Original request method. + * @return string GET, POST or HEAD. + * @access public + */ function getMethod() { - return $this->_method; + return $this->_encoding->getMethod(); } - /** - * Resource name. - * @return SimpleUrl Current url. - * @access public - */ + /** + * Resource name. + * @return SimpleUrl Current url. + * @access public + */ function getUrl() { return $this->_url; } - /** - * Original request data. - * @return mixed Sent content. - * @access public - */ + /** + * Original request data. + * @return mixed Sent content. + * @access public + */ function getRequestData() { - return $this->_request_data; + return $this->_encoding; } - /** - * Raw request that was sent down the wire. - * @return string Bytes actually sent. - * @access public - */ + /** + * Raw request that was sent down the wire. + * @return string Bytes actually sent. + * @access public + */ function getSent() { return $this->_sent; } - /** - * Accessor for the content after the last - * header line. - * @return string All content. - * @access public - */ + /** + * Accessor for the content after the last + * header line. + * @return string All content. + * @access public + */ function getContent() { return $this->_content; } - /** - * Accessor for header block. The response is the - * combination of this and the content. - * @return SimpleHeaders Wrapped header block. - * @access public - */ + /** + * Accessor for header block. The response is the + * combination of this and the content. + * @return SimpleHeaders Wrapped header block. + * @access public + */ function getHeaders() { return $this->_headers; } - /** - * Accessor for any new cookies. - * @return array List of new cookies. - * @access public - */ + /** + * Accessor for any new cookies. + * @return array List of new cookies. + * @access public + */ function getNewCookies() { return $this->_headers->getNewCookies(); } - /** - * Reads the whole of the socket output into a - * single string. - * @param SimpleSocket $socket Unread socket. - * @return string Raw output if successful - * else false. - * @access private - */ + /** + * Reads the whole of the socket output into a + * single string. + * @param SimpleSocket $socket Unread socket. + * @return string Raw output if successful + * else false. + * @access private + */ function _readAll(&$socket) { $all = ''; while (! $this->_isLastPacket($next = $socket->read())) { @@ -836,13 +818,13 @@ return $all; } - /** - * Test to see if the packet from the socket is the - * last one. - * @param string $packet Chunk to interpret. - * @return boolean True if empty or EOF. - * @access private - */ + /** + * Test to see if the packet from the socket is the + * last one. + * @param string $packet Chunk to interpret. + * @return boolean True if empty or EOF. + * @access private + */ function _isLastPacket($packet) { if (is_string($packet)) { return $packet === ''; diff --git a/vendors/simpletest/mock_objects.php b/vendors/simpletest/mock_objects.php index d690936fa..30a77c108 100644 --- a/vendors/simpletest/mock_objects.php +++ b/vendors/simpletest/mock_objects.php @@ -1,92 +1,86 @@ SimpleExpectation(); - } - - /** - * Tests the expectation. Always true. - * @param mixed $compare Ignored. - * @return boolean True. - * @access public - */ + /** + * Tests the expectation. Always true. + * @param mixed $compare Ignored. + * @return boolean True. + * @access public + */ function test($compare) { return true; } - /** - * Returns a human readable test message. - * @param mixed $compare Comparison value. - * @return string Description of success - * or failure. - * @access public - */ + /** + * Returns a human readable test message. + * @param mixed $compare Comparison value. + * @return string Description of success + * or failure. + * @access public + */ function testMessage($compare) { $dumper = &$this->_getDumper(); return 'Wildcard always matches [' . $dumper->describeValue($compare) . ']'; } } - /** - * Parameter comparison assertion. - * @package SimpleTest - * @subpackage MockObjects - */ + /** + * Parameter comparison assertion. + * @package SimpleTest + * @subpackage MockObjects + */ class ParametersExpectation extends SimpleExpectation { var $_expected; - /** - * Sets the expected parameter list. - * @param array $parameters Array of parameters including - * those that are wildcarded. - * If the value is not an array - * then it is considered to match any. - * @param mixed $wildcard Any parameter matching this - * will always match. - * @param string $message Customised message on failure. - * @access public - */ + /** + * Sets the expected parameter list. + * @param array $parameters Array of parameters including + * those that are wildcarded. + * If the value is not an array + * then it is considered to match any. + * @param mixed $wildcard Any parameter matching this + * will always match. + * @param string $message Customised message on failure. + * @access public + */ function ParametersExpectation($expected = false, $message = '%s') { $this->SimpleExpectation($message); $this->_expected = $expected; } - /** - * Tests the assertion. True if correct. - * @param array $parameters Comparison values. - * @return boolean True if correct. - * @access public - */ + /** + * Tests the assertion. True if correct. + * @param array $parameters Comparison values. + * @return boolean True if correct. + * @access public + */ function test($parameters) { if (! is_array($this->_expected)) { return true; @@ -102,26 +96,26 @@ return true; } - /** - * Tests an individual parameter. - * @param mixed $parameter Value to test. - * @param mixed $expected Comparison value. - * @return boolean True if expectation - * fulfilled. - * @access private - */ + /** + * Tests an individual parameter. + * @param mixed $parameter Value to test. + * @param mixed $expected Comparison value. + * @return boolean True if expectation + * fulfilled. + * @access private + */ function _testParameter($parameter, $expected) { $comparison = $this->_coerceToExpectation($expected); return $comparison->test($parameter); } - /** - * Returns a human readable test message. - * @param array $comparison Incoming parameter list. - * @return string Description of success - * or failure. - * @access public - */ + /** + * Returns a human readable test message. + * @param array $comparison Incoming parameter list. + * @return string Description of success + * or failure. + * @access public + */ function testMessage($parameters) { if ($this->test($parameters)) { return "Expectation of " . count($this->_expected) . @@ -132,14 +126,14 @@ } } - /** - * Message to display if expectation differs from - * the parameters actually received. - * @param array $expected Expected parameters as list. - * @param array $parameters Actual parameters received. - * @return string Description of difference. - * @access private - */ + /** + * Message to display if expectation differs from + * the parameters actually received. + * @param array $expected Expected parameters as list. + * @param array $parameters Actual parameters received. + * @return string Description of difference. + * @access private + */ function _describeDifference($expected, $parameters) { if (count($expected) != count($parameters)) { return "Expected " . count($expected) . @@ -158,14 +152,14 @@ return "Parameter expectation differs at " . implode(" and ", $messages); } - /** - * Creates an identical expectation if the - * object/value is not already some type - * of expectation. - * @param mixed $expected Expected value. - * @return SimpleExpectation Expectation object. - * @access private - */ + /** + * Creates an identical expectation if the + * object/value is not already some type + * of expectation. + * @param mixed $expected Expected value. + * @return SimpleExpectation Expectation object. + * @access private + */ function _coerceToExpectation($expected) { if (SimpleTestCompatibility::isA($expected, 'SimpleExpectation')) { return $expected; @@ -173,13 +167,13 @@ return new IdenticalExpectation($expected); } - /** - * Renders the argument list as a string for - * messages. - * @param array $args Incoming arguments. - * @return string Simple description of type and value. - * @access private - */ + /** + * Renders the argument list as a string for + * messages. + * @param array $args Incoming arguments. + * @return string Simple description of type and value. + * @access private + */ function _renderArguments($args) { $descriptions = array(); if (is_array($args)) { @@ -192,42 +186,42 @@ } } - /** - * Confirms that the number of calls on a method is as expected. - */ + /** + * Confirms that the number of calls on a method is as expected. + */ class CallCountExpectation extends SimpleExpectation { var $_method; var $_count; - /** - * Stashes the method and expected count for later - * reporting. - * @param string $method Name of method to confirm against. - * @param integer $count Expected number of calls. - * @param string $message Custom error message. - */ + /** + * Stashes the method and expected count for later + * reporting. + * @param string $method Name of method to confirm against. + * @param integer $count Expected number of calls. + * @param string $message Custom error message. + */ function CallCountExpectation($method, $count, $message = '%s') { $this->_method = $method; $this->_count = $count; $this->SimpleExpectation($message); } - /** - * Tests the assertion. True if correct. - * @param integer $compare Measured call count. - * @return boolean True if expected. - * @access public - */ + /** + * Tests the assertion. True if correct. + * @param integer $compare Measured call count. + * @return boolean True if expected. + * @access public + */ function test($compare) { return ($this->_count == $compare); } - /** - * Reports the comparison. - * @param integer $compare Measured call count. - * @return string Message to show. - * @access public - */ + /** + * Reports the comparison. + * @param integer $compare Measured call count. + * @return string Message to show. + * @access public + */ function testMessage($compare) { return 'Expected call count for [' . $this->_method . '] was [' . $this->_count . @@ -235,42 +229,42 @@ } } - /** - * Confirms that the number of calls on a method is as expected. - */ + /** + * Confirms that the number of calls on a method is as expected. + */ class MinimumCallCountExpectation extends SimpleExpectation { var $_method; var $_count; - /** - * Stashes the method and expected count for later - * reporting. - * @param string $method Name of method to confirm against. - * @param integer $count Minimum number of calls. - * @param string $message Custom error message. - */ + /** + * Stashes the method and expected count for later + * reporting. + * @param string $method Name of method to confirm against. + * @param integer $count Minimum number of calls. + * @param string $message Custom error message. + */ function MinimumCallCountExpectation($method, $count, $message = '%s') { $this->_method = $method; $this->_count = $count; $this->SimpleExpectation($message); } - /** - * Tests the assertion. True if correct. - * @param integer $compare Measured call count. - * @return boolean True if enough. - * @access public - */ + /** + * Tests the assertion. True if correct. + * @param integer $compare Measured call count. + * @return boolean True if enough. + * @access public + */ function test($compare) { return ($this->_count <= $compare); } - /** - * Reports the comparison. - * @param integer $compare Measured call count. - * @return string Message to show. - * @access public - */ + /** + * Reports the comparison. + * @param integer $compare Measured call count. + * @return string Message to show. + * @access public + */ function testMessage($compare) { return 'Minimum call count for [' . $this->_method . '] was [' . $this->_count . @@ -278,42 +272,42 @@ } } - /** - * Confirms that the number of calls on a method is as expected. - */ + /** + * Confirms that the number of calls on a method is as expected. + */ class MaximumCallCountExpectation extends SimpleExpectation { var $_method; var $_count; - /** - * Stashes the method and expected count for later - * reporting. - * @param string $method Name of method to confirm against. - * @param integer $count Minimum number of calls. - * @param string $message Custom error message. - */ + /** + * Stashes the method and expected count for later + * reporting. + * @param string $method Name of method to confirm against. + * @param integer $count Minimum number of calls. + * @param string $message Custom error message. + */ function MaximumCallCountExpectation($method, $count, $message = '%s') { $this->_method = $method; $this->_count = $count; $this->SimpleExpectation($message); } - /** - * Tests the assertion. True if correct. - * @param integer $compare Measured call count. - * @return boolean True if not over. - * @access public - */ + /** + * Tests the assertion. True if correct. + * @param integer $compare Measured call count. + * @return boolean True if not over. + * @access public + */ function test($compare) { return ($this->_count >= $compare); } - /** - * Reports the comparison. - * @param integer $compare Measured call count. - * @return string Message to show. - * @access public - */ + /** + * Reports the comparison. + * @param integer $compare Measured call count. + * @return string Message to show. + * @access public + */ function testMessage($compare) { return 'Maximum call count for [' . $this->_method . '] was [' . $this->_count . @@ -321,39 +315,39 @@ } } - /** - * Retrieves values and references by searching the - * parameter lists until a match is found. - * @package SimpleTest - * @subpackage MockObjects - */ + /** + * Retrieves values and references by searching the + * parameter lists until a match is found. + * @package SimpleTest + * @subpackage MockObjects + */ class CallMap { var $_map; - /** - * Creates an empty call map. - * @access public - */ + /** + * Creates an empty call map. + * @access public + */ function CallMap() { $this->_map = array(); } - /** - * Stashes a value against a method call. - * @param array $parameters Arguments including wildcards. - * @param mixed $value Value copied into the map. - * @access public - */ + /** + * Stashes a value against a method call. + * @param array $parameters Arguments including wildcards. + * @param mixed $value Value copied into the map. + * @access public + */ function addValue($parameters, $value) { $this->addReference($parameters, $value); } - /** - * Stashes a reference against a method call. - * @param array $parameters Array of arguments (including wildcards). - * @param mixed $reference Array reference placed in the map. - * @access public - */ + /** + * Stashes a reference against a method call. + * @param array $parameters Array of arguments (including wildcards). + * @param mixed $reference Array reference placed in the map. + * @access public + */ function addReference($parameters, &$reference) { $place = count($this->_map); $this->_map[$place] = array(); @@ -361,42 +355,43 @@ $this->_map[$place]["content"] = &$reference; } - /** - * Searches the call list for a matching parameter - * set. Returned by reference. - * @param array $parameters Parameters to search by - * without wildcards. - * @return object Object held in the first matching - * slot, otherwise null. - * @access public - */ + /** + * Searches the call list for a matching parameter + * set. Returned by reference. + * @param array $parameters Parameters to search by + * without wildcards. + * @return object Object held in the first matching + * slot, otherwise null. + * @access public + */ function &findFirstMatch($parameters) { $slot = $this->_findFirstSlot($parameters); if (!isset($slot)) { - return null; + $null = null; + return $null; } return $slot["content"]; } - /** - * Searches the call list for a matching parameter - * set. True if successful. - * @param array $parameters Parameters to search by - * without wildcards. - * @return boolean True if a match is present. - * @access public - */ + /** + * Searches the call list for a matching parameter + * set. True if successful. + * @param array $parameters Parameters to search by + * without wildcards. + * @return boolean True if a match is present. + * @access public + */ function isMatch($parameters) { return ($this->_findFirstSlot($parameters) != null); } - /** - * Searches the map for a matching item. - * @param array $parameters Parameters to search by - * without wildcards. - * @return array Reference to slot or null. - * @access private - */ + /** + * Searches the map for a matching item. + * @param array $parameters Parameters to search by + * without wildcards. + * @return array Reference to slot or null. + * @access private + */ function &_findFirstSlot($parameters) { $count = count($this->_map); for ($i = 0; $i < $count; $i++) { @@ -404,16 +399,17 @@ return $this->_map[$i]; } } - return null; + $null = null; + return $null; } } - /** - * An empty collection of methods that can have their - * return values set. Used for prototyping. - * @package SimpleTest - * @subpackage MockObjects - */ + /** + * An empty collection of methods that can have their + * return values set. Used for prototyping. + * @package SimpleTest + * @subpackage MockObjects + */ class SimpleStub { var $_wildcard; var $_is_strict; @@ -421,12 +417,12 @@ var $_return_sequence; var $_call_counts; - /** - * Sets up the wildcard and everything else empty. - * @param mixed $wildcard Parameter matching wildcard. - * @param boolean $is_strict Enables method name checks. - * @access public - */ + /** + * Sets up the wildcard and everything else empty. + * @param mixed $wildcard Parameter matching wildcard. + * @param boolean $is_strict Enables method name checks. + * @access public + */ function SimpleStub($wildcard, $is_strict = true) { $this->_wildcard = $wildcard; $this->_is_strict = $is_strict; @@ -435,47 +431,48 @@ $this->_call_counts = array(); } - /** - * Replaces wildcard matches with wildcard - * expectations in the argument list. - * @param array $args Raw argument list. - * @return array Argument list with - * expectations. - * @access private - */ + /** + * Replaces wildcard matches with wildcard + * expectations in the argument list. + * @param array $args Raw argument list. + * @return array Argument list with + * expectations. + * @access private + */ function _replaceWildcards($args) { if ($args === false) { return false; } for ($i = 0; $i < count($args); $i++) { if ($args[$i] === $this->_wildcard) { - $args[$i] = new WildcardExpectation(); + $args[$i] = new AnythingExpectation(); } } return $args; } - /** - * Returns the expected value for the method name. - * @param string $method Name of method to simulate. - * @param array $args Arguments as an array. - * @return mixed Stored return. - * @access private - */ + /** + * Returns the expected value for the method name. + * @param string $method Name of method to simulate. + * @param array $args Arguments as an array. + * @return mixed Stored return. + * @access private + */ function &_invoke($method, $args) { $method = strtolower($method); $step = $this->getCallCount($method); $this->_addCall($method, $args); - return $this->_getReturn($method, $args, $step); + $result = &$this->_getReturn($method, $args, $step); + return $result; } - /** - * Triggers a PHP error if the method is not part - * of this object. - * @param string $method Name of method. - * @param string $task Description of task attempt. - * @access protected - */ + /** + * Triggers a PHP error if the method is not part + * of this object. + * @param string $method Name of method. + * @param string $task Description of task attempt. + * @access protected + */ function _dieOnNoMethod($method, $task) { if ($this->_is_strict && !method_exists($this, $method)) { trigger_error( @@ -484,12 +481,12 @@ } } - /** - * Adds one to the call count of a method. - * @param string $method Method called. - * @param array $args Arguments as an array. - * @access protected - */ + /** + * Adds one to the call count of a method. + * @param string $method Method called. + * @param array $args Arguments as an array. + * @access protected + */ function _addCall($method, $args) { if (!isset($this->_call_counts[$method])) { $this->_call_counts[$method] = 0; @@ -497,12 +494,12 @@ $this->_call_counts[$method]++; } - /** - * Fetches the call count of a method so far. - * @param string $method Method name called. - * @return Number of calls so far. - * @access public - */ + /** + * Fetches the call count of a method so far. + * @param string $method Method name called. + * @return Number of calls so far. + * @access public + */ function getCallCount($method) { $this->_dieOnNoMethod($method, "get call count"); $method = strtolower($method); @@ -512,15 +509,15 @@ return $this->_call_counts[$method]; } - /** - * Sets a return for a parameter list that will - * be passed by value for all calls to this method. - * @param string $method Method name. - * @param mixed $value Result of call passed by value. - * @param array $args List of parameters to match - * including wildcards. - * @access public - */ + /** + * Sets a return for a parameter list that will + * be passed by value for all calls to this method. + * @param string $method Method name. + * @param mixed $value Result of call passed by value. + * @param array $args List of parameters to match + * including wildcards. + * @access public + */ function setReturnValue($method, $value, $args = false) { $this->_dieOnNoMethod($method, "set return value"); $args = $this->_replaceWildcards($args); @@ -531,20 +528,20 @@ $this->_returns[$method]->addValue($args, $value); } - /** - * Sets a return for a parameter list that will - * be passed by value only when the required call count - * is reached. - * @param integer $timing Number of calls in the future - * to which the result applies. If - * not set then all calls will return - * the value. - * @param string $method Method name. - * @param mixed $value Result of call passed by value. - * @param array $args List of parameters to match - * including wildcards. - * @access public - */ + /** + * Sets a return for a parameter list that will + * be passed by value only when the required call count + * is reached. + * @param integer $timing Number of calls in the future + * to which the result applies. If + * not set then all calls will return + * the value. + * @param string $method Method name. + * @param mixed $value Result of call passed by value. + * @param array $args List of parameters to match + * including wildcards. + * @access public + */ function setReturnValueAt($timing, $method, $value, $args = false) { $this->_dieOnNoMethod($method, "set return value sequence"); $args = $this->_replaceWildcards($args); @@ -558,15 +555,15 @@ $this->_return_sequence[$method][$timing]->addValue($args, $value); } - /** - * Sets a return for a parameter list that will - * be passed by reference for all calls. - * @param string $method Method name. - * @param mixed $reference Result of the call will be this object. - * @param array $args List of parameters to match - * including wildcards. - * @access public - */ + /** + * Sets a return for a parameter list that will + * be passed by reference for all calls. + * @param string $method Method name. + * @param mixed $reference Result of the call will be this object. + * @param array $args List of parameters to match + * including wildcards. + * @access public + */ function setReturnReference($method, &$reference, $args = false) { $this->_dieOnNoMethod($method, "set return reference"); $args = $this->_replaceWildcards($args); @@ -577,20 +574,20 @@ $this->_returns[$method]->addReference($args, $reference); } - /** - * Sets a return for a parameter list that will - * be passed by value only when the required call count - * is reached. - * @param integer $timing Number of calls in the future - * to which the result applies. If - * not set then all calls will return - * the value. - * @param string $method Method name. - * @param mixed $reference Result of the call will be this object. - * @param array $args List of parameters to match - * including wildcards. - * @access public - */ + /** + * Sets a return for a parameter list that will + * be passed by value only when the required call count + * is reached. + * @param integer $timing Number of calls in the future + * to which the result applies. If + * not set then all calls will return + * the value. + * @param string $method Method name. + * @param mixed $reference Result of the call will be this object. + * @param array $args List of parameters to match + * including wildcards. + * @access public + */ function setReturnReferenceAt($timing, $method, &$reference, $args = false) { $this->_dieOnNoMethod($method, "set return reference sequence"); $args = $this->_replaceWildcards($args); @@ -604,39 +601,42 @@ $this->_return_sequence[$method][$timing]->addReference($args, $reference); } - /** - * Finds the return value matching the incoming - * arguments. If there is no matching value found - * then an error is triggered. - * @param string $method Method name. - * @param array $args Calling arguments. - * @param integer $step Current position in the - * call history. - * @return mixed Stored return. - * @access protected - */ + /** + * Finds the return value matching the incoming + * arguments. If there is no matching value found + * then an error is triggered. + * @param string $method Method name. + * @param array $args Calling arguments. + * @param integer $step Current position in the + * call history. + * @return mixed Stored return. + * @access protected + */ function &_getReturn($method, $args, $step) { if (isset($this->_return_sequence[$method][$step])) { if ($this->_return_sequence[$method][$step]->isMatch($args)) { - return $this->_return_sequence[$method][$step]->findFirstMatch($args); + $result = &$this->_return_sequence[$method][$step]->findFirstMatch($args); + return $result; } } if (isset($this->_returns[$method])) { - return $this->_returns[$method]->findFirstMatch($args); + $result = &$this->_returns[$method]->findFirstMatch($args); + return $result; } - return null; + $null = null; + return $null; } } - /** - * An empty collection of methods that can have their - * return values set and expectations made of the - * calls upon them. The mock will assert the - * expectations against it's attached test case in - * addition to the server stub behaviour. - * @package SimpleTest - * @subpackage MockObjects - */ + /** + * An empty collection of methods that can have their + * return values set and expectations made of the + * calls upon them. The mock will assert the + * expectations against it's attached test case in + * addition to the server stub behaviour. + * @package SimpleTest + * @subpackage MockObjects + */ class SimpleMock extends SimpleStub { var $_test; var $_expected_counts; @@ -644,15 +644,15 @@ var $_expected_args; var $_expected_args_at; - /** - * Creates an empty return list and expectation list. - * All call counts are set to zero. - * @param SimpleTestCase $test Test case to test expectations in. - * @param mixed $wildcard Parameter matching wildcard. - * @param boolean $is_strict Enables method name checks on - * expectations. - * @access public - */ + /** + * Creates an empty return list and expectation list. + * All call counts are set to zero. + * @param SimpleTestCase $test Test case to test expectations in. + * @param mixed $wildcard Parameter matching wildcard. + * @param boolean $is_strict Enables method name checks on + * expectations. + * @access public + */ function SimpleMock(&$test, $wildcard, $is_strict = true) { $this->SimpleStub($wildcard, $is_strict); if (! $test) { @@ -666,42 +666,42 @@ $this->_expected_args_at = array(); } - /** - * Accessor for attached unit test so that when - * subclassed, new expectations can be added easily. - * @return SimpleTestCase Unit test passed in constructor. - * @access public - */ + /** + * Accessor for attached unit test so that when + * subclassed, new expectations can be added easily. + * @return SimpleTestCase Unit test passed in constructor. + * @access public + */ function &getTest() { return $this->_test; } - /** - * Die if bad arguments array is passed - * @param mixed $args The arguments value to be checked. - * @param string $task Description of task attempt. - * @return boolean Valid arguments - * @access private - */ + /** + * Die if bad arguments array is passed + * @param mixed $args The arguments value to be checked. + * @param string $task Description of task attempt. + * @return boolean Valid arguments + * @access private + */ function _checkArgumentsIsArray($args, $task) { - if (! is_array($args)) { - trigger_error( - "Cannot $task as \$args parameter is not an array", - E_USER_ERROR); - } + if (! is_array($args)) { + trigger_error( + "Cannot $task as \$args parameter is not an array", + E_USER_ERROR); + } } - /** - * Sets up an expected call with a set of - * expected parameters in that call. All - * calls will be compared to these expectations - * regardless of when the call is made. - * @param string $method Method call to test. - * @param array $args Expected parameters for the call - * including wildcards. - * @param string $message Overridden message. - * @access public - */ + /** + * Sets up an expected call with a set of + * expected parameters in that call. All + * calls will be compared to these expectations + * regardless of when the call is made. + * @param string $method Method call to test. + * @param array $args Expected parameters for the call + * including wildcards. + * @param string $message Overridden message. + * @access public + */ function expectArguments($method, $args, $message = '%s') { $this->_dieOnNoMethod($method, 'set expected arguments'); $this->_checkArgumentsIsArray($args, 'set expected arguments'); @@ -711,19 +711,19 @@ new ParametersExpectation($args, $message); } - /** - * Sets up an expected call with a set of - * expected parameters in that call. The - * expected call count will be adjusted if it - * is set too low to reach this call. - * @param integer $timing Number of calls in the future at - * which to test. Next call is 0. - * @param string $method Method call to test. - * @param array $args Expected parameters for the call - * including wildcards. - * @param string $message Overridden message. - * @access public - */ + /** + * Sets up an expected call with a set of + * expected parameters in that call. The + * expected call count will be adjusted if it + * is set too low to reach this call. + * @param integer $timing Number of calls in the future at + * which to test. Next call is 0. + * @param string $method Method call to test. + * @param array $args Expected parameters for the call + * including wildcards. + * @param string $message Overridden message. + * @access public + */ function expectArgumentsAt($timing, $method, $args, $message = '%s') { $this->_dieOnNoMethod($method, 'set expected arguments at time'); $this->_checkArgumentsIsArray($args, 'set expected arguments at time'); @@ -737,16 +737,16 @@ new ParametersExpectation($args, $message); } - /** - * Sets an expectation for the number of times - * a method will be called. The tally method - * is used to check this. - * @param string $method Method call to test. - * @param integer $count Number of times it should - * have been called at tally. - * @param string $message Overridden message. - * @access public - */ + /** + * Sets an expectation for the number of times + * a method will be called. The tally method + * is used to check this. + * @param string $method Method call to test. + * @param integer $count Number of times it should + * have been called at tally. + * @param string $message Overridden message. + * @access public + */ function expectCallCount($method, $count, $message = '%s') { $this->_dieOnNoMethod($method, 'set expected call count'); $message .= Mock::getExpectationLine(' at line [%d]'); @@ -754,15 +754,15 @@ new CallCountExpectation($method, $count, $message); } - /** - * Sets the number of times a method may be called - * before a test failure is triggered. - * @param string $method Method call to test. - * @param integer $count Most number of times it should - * have been called. - * @param string $message Overridden message. - * @access public - */ + /** + * Sets the number of times a method may be called + * before a test failure is triggered. + * @param string $method Method call to test. + * @param integer $count Most number of times it should + * have been called. + * @param string $message Overridden message. + * @access public + */ function expectMaximumCallCount($method, $count, $message = '%s') { $this->_dieOnNoMethod($method, 'set maximum call count'); $message .= Mock::getExpectationLine(' at line [%d]'); @@ -770,15 +770,15 @@ new MaximumCallCountExpectation($method, $count, $message); } - /** - * Sets the number of times to call a method to prevent - * a failure on the tally. - * @param string $method Method call to test. - * @param integer $count Least number of times it should - * have been called. - * @param string $message Overridden message. - * @access public - */ + /** + * Sets the number of times to call a method to prevent + * a failure on the tally. + * @param string $method Method call to test. + * @param integer $count Least number of times it should + * have been called. + * @param string $message Overridden message. + * @access public + */ function expectMinimumCallCount($method, $count, $message = '%s') { $this->_dieOnNoMethod($method, 'set minimum call count'); $message .= Mock::getExpectationLine(' at line [%d]'); @@ -786,26 +786,26 @@ new MinimumCallCountExpectation($method, $count, $message); } - /** - * Convenience method for barring a method - * call. - * @param string $method Method call to ban. - * @param string $message Overridden message. - * @access public - */ + /** + * Convenience method for barring a method + * call. + * @param string $method Method call to ban. + * @param string $message Overridden message. + * @access public + */ function expectNever($method, $message = '%s') { $this->expectMaximumCallCount($method, 0, $message); } - /** - * Convenience method for a single method - * call. - * @param string $method Method call to track. - * @param array $args Expected argument list or - * false for any arguments. - * @param string $message Overridden message. - * @access public - */ + /** + * Convenience method for a single method + * call. + * @param string $method Method call to track. + * @param array $args Expected argument list or + * false for any arguments. + * @param string $message Overridden message. + * @access public + */ function expectOnce($method, $args = false, $message = '%s') { $this->expectCallCount($method, 1, $message); if ($args !== false) { @@ -813,15 +813,15 @@ } } - /** - * Convenience method for requiring a method - * call. - * @param string $method Method call to track. - * @param array $args Expected argument list or - * false for any arguments. - * @param string $message Overridden message. - * @access public - */ + /** + * Convenience method for requiring a method + * call. + * @param string $method Method call to track. + * @param array $args Expected argument list or + * false for any arguments. + * @param string $message Overridden message. + * @access public + */ function expectAtLeastOnce($method, $args = false, $message = '%s') { $this->expectMinimumCallCount($method, 1, $message); if ($args !== false) { @@ -829,14 +829,14 @@ } } - /** - * Totals up the call counts and triggers a test - * assertion if a test is present for expected - * call counts. - * This method must be called explicitly for the call - * count assertions to be triggered. - * @access public - */ + /** + * Totals up the call counts and triggers a test + * assertion if a test is present for expected + * call counts. + * This method must be called explicitly for the call + * count assertions to be triggered. + * @access public + */ function tally() { foreach ($this->_expected_counts as $method => $expectation) { $this->_assertTrue( @@ -852,32 +852,33 @@ } } - /** - * Returns the expected value for the method name - * and checks expectations. Will generate any - * test assertions as a result of expectations - * if there is a test present. - * @param string $method Name of method to simulate. - * @param array $args Arguments as an array. - * @return mixed Stored return. - * @access private - */ + /** + * Returns the expected value for the method name + * and checks expectations. Will generate any + * test assertions as a result of expectations + * if there is a test present. + * @param string $method Name of method to simulate. + * @param array $args Arguments as an array. + * @return mixed Stored return. + * @access private + */ function &_invoke($method, $args) { $method = strtolower($method); $step = $this->getCallCount($method); $this->_addCall($method, $args); $this->_checkExpectations($method, $args, $step); - return $this->_getReturn($method, $args, $step); + $result = &$this->_getReturn($method, $args, $step); + return $result; } - /** - * Tests the arguments against expectations. - * @param string $method Method to check. - * @param array $args Argument list to match. - * @param integer $timing The position of this call - * in the call history. - * @access private - */ + /** + * Tests the arguments against expectations. + * @param string $method Method to check. + * @param array $args Argument list to match. + * @param integer $timing The position of this call + * in the call history. + * @access private + */ function _checkExpectations($method, $args, $timing) { if (isset($this->_max_counts[$method])) { if (! $this->_max_counts[$method]->test($timing + 1)) { @@ -898,57 +899,57 @@ } } - /** - * Triggers an assertion on the held test case. - * Should be overridden when using another test - * framework other than the SimpleTest one if the - * assertion method has a different name. - * @param boolean $assertion True will pass. - * @param string $message Message that will go with - * the test event. - * @access protected - */ + /** + * Triggers an assertion on the held test case. + * Should be overridden when using another test + * framework other than the SimpleTest one if the + * assertion method has a different name. + * @param boolean $assertion True will pass. + * @param string $message Message that will go with + * the test event. + * @access protected + */ function _assertTrue($assertion, $message) { $test = &SimpleMock::injectTest($this->_test); $test->assertTrue($assertion, $message); } - /** - * Stashes the test case for later recovery. - * @param SimpleTestCase $test Test case. - * @return string Key to find it again. - * @access public - * @static - */ + /** + * Stashes the test case for later recovery. + * @param SimpleTestCase $test Test case. + * @return string Key to find it again. + * @access public + * @static + */ function registerTest(&$test) { $registry = &SimpleMock::_getRegistry(); $registry[$class = get_class($test)] = &$test; return $class; } - /** - * Resolves the dependency on the test case. - * @param string $class Key to look up test case in. - * @return SimpleTestCase Test case to send results to. - * @access public - * @static - */ + /** + * Resolves the dependency on the test case. + * @param string $class Key to look up test case in. + * @return SimpleTestCase Test case to send results to. + * @access public + * @static + */ function &injectTest($key) { $registry = &SimpleMock::_getRegistry(); return $registry[$key]; } - /** - * Registry for test cases. The reason for this is - * to break the reference between the test cases and - * the mocks. It was leading to a fatal error due to - * recursive dependencies during comparisons. See - * http://bugs.php.net/bug.php?id=31449 for the PHP - * bug. - * @return array List of references. - * @access private - * @static - */ + /** + * Registry for test cases. The reason for this is + * to break the reference between the test cases and + * the mocks. It was leading to a fatal error due to + * recursive dependencies during comparisons. See + * http://bugs.php.net/bug.php?id=31449 for the PHP + * bug. + * @return array List of references. + * @access private + * @static + */ function &_getRegistry() { static $registry; if (! isset($registry)) { @@ -958,44 +959,44 @@ } } - /** - * Static methods only service class for code generation of - * server stubs. - * @package SimpleTest - * @subpackage MockObjects - */ + /** + * Static methods only service class for code generation of + * server stubs. + * @package SimpleTest + * @subpackage MockObjects + */ class Stub { - /** - * Factory for server stub classes. - */ + /** + * Factory for server stub classes. + */ function Stub() { trigger_error('Stub factory methods are class only.'); } - /** - * Clones a class' interface and creates a stub version - * that can have return values set. - * @param string $class Class to clone. - * @param string $stub_class New class name. Default is - * the old name with "Stub" - * prepended. - * @param array $methods Additional methods to add beyond - * those in the cloned class. Use this - * to emulate the dynamic addition of - * methods in the cloned class or when - * the class hasn't been written yet. - * @static - * @access public - */ + /** + * Clones a class' interface and creates a stub version + * that can have return values set. + * @param string $class Class to clone. + * @param string $stub_class New class name. Default is + * the old name with "Stub" + * prepended. + * @param array $methods Additional methods to add beyond + * those in the cloned class. Use this + * to emulate the dynamic addition of + * methods in the cloned class or when + * the class hasn't been written yet. + * @static + * @access public + */ function generate($class, $stub_class = false, $methods = false) { - if (! SimpleTestCompatibility::classExists($class)) { + if (! class_exists($class)) { return false; } if (! $stub_class) { $stub_class = "Stub" . $class; } - if (SimpleTestCompatibility::classExists($stub_class)) { + if (class_exists($stub_class)) { return false; } return eval(Stub::_createClassCode( @@ -1004,18 +1005,18 @@ $methods ? $methods : array()) . " return true;"); } - /** - * The new server stub class code in string form. - * @param string $class Class to clone. - * @param string $mock_class New class name. - * @param array $methods Additional methods. - * @static - * @access private - */ + /** + * The new server stub class code in string form. + * @param string $class Class to clone. + * @param string $mock_class New class name. + * @param array $methods Additional methods. + * @static + * @access private + */ function _createClassCode($class, $stub_class, $methods) { $stub_base = SimpleTestOptions::getStubBaseClass(); $code = "class $stub_class extends $stub_base {\n"; - $code .= " function $stub_class(\$wildcard = MOCK_WILDCARD) {\n"; + $code .= " function $stub_class(\$wildcard = MOCK_ANYTHING) {\n"; $code .= " \$this->$stub_base(\$wildcard);\n"; $code .= " }\n"; $code .= Stub::_createHandlerCode($class, $stub_base, $methods); @@ -1023,92 +1024,139 @@ return $code; } - /** - * Creates code within a class to generate replaced - * methods. All methods call the _invoke() handler - * with the method name and the arguments in an - * array. - * @param string $class Class to clone. - * @param string $base Base mock/stub class with methods that - * cannot be cloned. Otherwise you - * would be stubbing the accessors used - * to set the stubs. - * @param array $methods Additional methods. - * @static - * @access private - */ + /** + * Creates code within a class to generate replaced + * methods. All methods call the _invoke() handler + * with the method name and the arguments in an + * array. + * @param string $class Class to clone. + * @param string $base Base mock/stub class with methods that + * cannot be cloned. Otherwise you + * would be stubbing the accessors used + * to set the stubs. + * @param array $methods Additional methods. + * @static + * @access private + */ function _createHandlerCode($class, $base, $methods) { $code = ""; $methods = array_merge($methods, get_class_methods($class)); foreach ($methods as $method) { - if (Stub::_isSpecialMethod($method)) { + if (Stub::_isConstructor($method)) { continue; } if (in_array($method, get_class_methods($base))) { continue; } - $code .= " function &$method() {\n"; + $code .= Stub::_createFunctionDeclaration($method); $code .= " \$args = func_get_args();\n"; - $code .= " return \$this->_invoke(\"$method\", \$args);\n"; + $code .= " \$result = &\$this->_invoke(\"$method\", \$args);\n"; + $code .= " return \$result;\n"; $code .= " }\n"; } return $code; } - /** - * Tests to see if a special PHP method is about to - * be stubbed by mistake. - * @param string $method Method name. - * @return boolean True if special. - * @access private - * @static - */ - function _isSpecialMethod($method) { + /** + * Creates the appropriate function declaration. + * @see _determineArguments(), _createHandlerCode() + * @param string $method Method name. + * @return string The proper function declaration + * @access private + * @static + */ + function _createFunctionDeclaration($method) { + $arguments = Stub::_determineArguments($method); + return sprintf(" function &%s(%s) {\n", $method, $arguments); + } + + /** + * Returns the necessary arguments for a given method. + * @param string $method Method name + * @return string The arguments string for a method, or + * blank if no arguments are required. + * @access private + * @static + */ + function _determineArguments($method) { + $code = ''; + if (Stub::_isSpecial($method)) { + $args = array( + '__call' => '$method, $value', + '__get' => '$key', + '__set' => '$key, $value'); + $code = $args[$method]; + } + return $code; + } + + /** + * Tests to see if a special PHP method is about to + * be stubbed by mistake. + * @param string $method Method name. + * @return boolean True if special. + * @access private + * @static + */ + function _isConstructor($method) { return in_array( strtolower($method), - array('__construct', '__clone', '__get', '__set', '__call')); + array('__construct', '__clone')); + } + + /** + * Tests for an special method. + * @param string $method Method name. + * @return boolean True if special. + * @access private + * @static + */ + function _isSpecial($method) { + return in_array( + strtolower($method), + array('__get', '__set', '__call')); } } - /** - * Static methods only service class for code generation of - * mock objects. - * @package SimpleTest - * @subpackage MockObjects - */ + /** + * Static methods only service class for code generation of + * mock objects. + * @package SimpleTest + * @subpackage MockObjects + */ class Mock { - /** - * Factory for mock object classes. - * @access public - */ + /** + * Factory for mock object classes. + * @access public + */ function Mock() { - trigger_error("Mock factory methods are class only."); + trigger_error('Mock factory methods are class only.'); } - /** - * Clones a class' interface and creates a mock version - * that can have return values and expectations set. - * @param string $class Class to clone. - * @param string $mock_class New class name. Default is - * the old name with "Mock" - * prepended. - * @param array $methods Additional methods to add beyond - * those in th cloned class. Use this - * to emulate the dynamic addition of - * methods in the cloned class or when - * the class hasn't been written yet. - * @static - * @access public - */ + /** + * Clones a class' interface and creates a mock version + * that can have return values and expectations set. + * @param string $class Class to clone. + * @param string $mock_class New class name. Default is + * the old name with "Mock" + * prepended. + * @param array $methods Additional methods to add beyond + * those in th cloned class. Use this + * to emulate the dynamic addition of + * methods in the cloned class or when + * the class hasn't been written yet. + * @static + * @access public + */ function generate($class, $mock_class = false, $methods = false) { - if (! SimpleTestCompatibility::classExists($class)) { + if (! class_exists($class)) { return false; } if (! $mock_class) { $mock_class = "Mock" . $class; } - if (SimpleTestCompatibility::classExists($mock_class)) { + if (class_exists($mock_class)) { return false; } return eval(Mock::_createClassCode( @@ -1117,42 +1165,42 @@ $methods ? $methods : array()) . " return true;"); } - /** - * Generates a version of a class with selected - * methods mocked only. Inherits the old class - * and chains the mock methods of an aggregated - * mock object. - * @param string $class Class to clone. - * @param string $mock_class New class name. - * @param array $methods Methods to be overridden - * with mock versions. - * @static - * @access public - */ + /** + * Generates a version of a class with selected + * methods mocked only. Inherits the old class + * and chains the mock methods of an aggregated + * mock object. + * @param string $class Class to clone. + * @param string $mock_class New class name. + * @param array $methods Methods to be overridden + * with mock versions. + * @static + * @access public + */ function generatePartial($class, $mock_class, $methods) { - if (! SimpleTestCompatibility::classExists($class)) { + if (! class_exists($class)) { return false; } - if (SimpleTestCompatibility::classExists($mock_class)) { + if (class_exists($mock_class)) { trigger_error("Partial mock class [$mock_class] already exists"); return false; } return eval(Mock::_extendClassCode($class, $mock_class, $methods)); } - /** - * The new mock class code as a string. - * @param string $class Class to clone. - * @param string $mock_class New class name. - * @param array $methods Additional methods. - * @return string Code for new mock class. - * @static - * @access private - */ + /** + * The new mock class code as a string. + * @param string $class Class to clone. + * @param string $mock_class New class name. + * @param array $methods Additional methods. + * @return string Code for new mock class. + * @static + * @access private + */ function _createClassCode($class, $mock_class, $methods) { $mock_base = SimpleTestOptions::getMockBaseClass(); $code = "class $mock_class extends $mock_base {\n"; - $code .= " function $mock_class(&\$test, \$wildcard = MOCK_WILDCARD) {\n"; + $code .= " function $mock_class(&\$test, \$wildcard = MOCK_ANYTHING) {\n"; $code .= " \$this->$mock_base(\$test, \$wildcard);\n"; $code .= " }\n"; $code .= Stub::_createHandlerCode($class, $mock_base, $methods); @@ -1160,24 +1208,24 @@ return $code; } - /** - * The extension class code as a string. The class - * composites a mock object and chains mocked methods - * to it. - * @param string $class Class to extend. - * @param string $mock_class New class name. - * @param array $methods Mocked methods. - * @return string Code for a new class. - * @static - * @access private - */ + /** + * The extension class code as a string. The class + * composites a mock object and chains mocked methods + * to it. + * @param string $class Class to extend. + * @param string $mock_class New class name. + * @param array $methods Mocked methods. + * @return string Code for a new class. + * @static + * @access private + */ function _extendClassCode($class, $mock_class, $methods) { $mock_base = SimpleTestOptions::getMockBaseClass(); $code = "class $mock_class extends $class {\n"; $code .= " var \$_mock;\n"; $code .= Mock::_addMethodList($methods); $code .= "\n"; - $code .= " function $mock_class(&\$test, \$wildcard = MOCK_WILDCARD) {\n"; + $code .= " function $mock_class(&\$test, \$wildcard = MOCK_ANYTHING) {\n"; $code .= " \$this->_mock = &new $mock_base(\$test, \$wildcard, false);\n"; $code .= " }\n"; $code .= Mock::_chainMockReturns(); @@ -1188,36 +1236,37 @@ return $code; } - /** - * Creates a list of mocked methods for error checking. - * @param array $methods Mocked methods. - * @return string Code for a method list. - * @access private - */ + /** + * Creates a list of mocked methods for error checking. + * @param array $methods Mocked methods. + * @return string Code for a method list. + * @access private + */ function _addMethodList($methods) { return " var \$_mocked_methods = array('" . implode("', '", $methods) . "');\n"; } - /** - * Creates code to abandon the expectation if not mocked. - * @param string $alias Parameter name of method name. - * @return string Code for bail out. - * @access private - */ + /** + * Creates code to abandon the expectation if not mocked. + * @param string $alias Parameter name of method name. + * @return string Code for bail out. + * @access private + */ function _bailOutIfNotMocked($alias) { $code = " if (! in_array($alias, \$this->_mocked_methods)) {\n"; $code .= " trigger_error(\"Method [$alias] is not mocked\");\n"; - $code .= " return;\n"; + $code .= " \$null = null;\n"; + $code .= " return \$null;\n"; $code .= " }\n"; return $code; } - /** - * Creates source code for chaining to the composited - * mock object. - * @return string Code for mock set up. - * @access private - */ + /** + * Creates source code for chaining to the composited + * mock object. + * @return string Code for mock set up. + * @access private + */ function _chainMockReturns() { $code = " function setReturnValue(\$method, \$value, \$args = false) {\n"; $code .= Mock::_bailOutIfNotMocked("\$method"); @@ -1238,12 +1287,12 @@ return $code; } - /** - * Creates source code for chaining to an aggregated - * mock object. - * @return string Code for expectations. - * @access private - */ + /** + * Creates source code for chaining to an aggregated + * mock object. + * @return string Code for expectations. + * @access private + */ function _chainMockExpectations() { $code = " function expectArguments(\$method, \$args = false) {\n"; $code .= Mock::_bailOutIfNotMocked("\$method"); @@ -1283,36 +1332,37 @@ return $code; } - /** - * Creates source code to override a list of methods - * with mock versions. - * @param array $methods Methods to be overridden - * with mock versions. - * @return string Code for overridden chains. - * @access private - */ + /** + * Creates source code to override a list of methods + * with mock versions. + * @param array $methods Methods to be overridden + * with mock versions. + * @return string Code for overridden chains. + * @access private + */ function _overrideMethods($methods) { $code = ""; foreach ($methods as $method) { - $code .= " function &$method() {\n"; + $code .= Stub::_createFunctionDeclaration($method); $code .= " \$args = func_get_args();\n"; - $code .= " return \$this->_mock->_invoke(\"$method\", \$args);\n"; + $code .= " \$result = &\$this->_mock->_invoke(\"$method\", \$args);\n"; + $code .= " return \$result;\n"; $code .= " }\n"; } return $code; } - /** - * Uses a stack trace to find the line of an assertion. - * @param string $format String formatting. - * @param array $stack Stack frames top most first. Only - * needed if not using the PHP - * backtrace function. - * @return string Line number of first expect* - * method embedded in format string. - * @access public - * @static - */ + /** + * Uses a stack trace to find the line of an assertion. + * @param string $format String formatting. + * @param array $stack Stack frames top most first. Only + * needed if not using the PHP + * backtrace function. + * @return string Line number of first expect* + * method embedded in format string. + * @access public + * @static + */ function getExpectationLine($format = '%d', $stack = false) { if ($stack === false) { $stack = SimpleTestCompatibility::getStackTrace(); diff --git a/vendors/simpletest/options.php b/vendors/simpletest/options.php index 022061a1a..205f829b3 100644 --- a/vendors/simpletest/options.php +++ b/vendors/simpletest/options.php @@ -1,139 +1,131 @@ 'SimpleStub', @@ -203,22 +195,38 @@ } } - /** - * Static methods for compatibility between different - * PHP versions. - * @package SimpleTest - */ + /** + * Static methods for compatibility between different + * PHP versions. + * @package SimpleTest + */ class SimpleTestCompatibility { + + /** + * Creates a copy whether in PHP5 or PHP4. + * @param object $object Thing to copy. + * @return object A copy. + * @access public + * @static + */ + function copy($object) { + if (version_compare(phpversion(), '5') >= 0) { + eval('$copy = clone $object;'); + return $copy; + } + return $object; + } - /** - * Identity test. Drops back to equality + types for PHP5 - * objects as the === operator counts as the - * stronger reference constraint. - * @param mixed $first Test subject. - * @param mixed $second Comparison object. - * @access public - * @static - */ + /** + * Identity test. Drops back to equality + types for PHP5 + * objects as the === operator counts as the + * stronger reference constraint. + * @param mixed $first Test subject. + * @param mixed $second Comparison object. + * @return boolean True if identical. + * @access public + * @static + */ function isIdentical($first, $second) { if ($first != $second) { return false; @@ -229,13 +237,14 @@ return ($first === $second); } - /** - * Recursive type test. - * @param mixed $first Test subject. - * @param mixed $second Comparison object. - * @access private - * @static - */ + /** + * Recursive type test. + * @param mixed $first Test subject. + * @param mixed $second Comparison object. + * @return boolean True if same type. + * @access private + * @static + */ function _isIdenticalType($first, $second) { if (gettype($first) != gettype($second)) { return false; @@ -254,13 +263,14 @@ return true; } - /** - * Recursive type test for each element of an array. - * @param mixed $first Test subject. - * @param mixed $second Comparison object. - * @access private - * @static - */ + /** + * Recursive type test for each element of an array. + * @param mixed $first Test subject. + * @param mixed $second Comparison object. + * @return boolean True if identical. + * @access private + * @static + */ function _isArrayOfIdenticalTypes($first, $second) { if (array_keys($first) != array_keys($second)) { return false; @@ -276,33 +286,42 @@ return true; } - /** - * Test for two variables being aliases. - * @param mixed $first Test subject. - * @param mixed $second Comparison object. - * @access public - * @static - */ + /** + * Test for two variables being aliases. + * @param mixed $first Test subject. + * @param mixed $second Comparison object. + * @return boolean True if same. + * @access public + * @static + */ function isReference(&$first, &$second) { if (version_compare(phpversion(), '5', '>=') - && is_object($first)) { - return ($first === $second); - } - $temp = $first; + && is_object($first)) { + return ($first === $second); + } + if (is_object($first) && is_object($second)) { + $id = uniqid("test"); + $first->$id = true; + $is_ref = isset($second->$id); + unset($first->$id); + return $is_ref; + } + $temp = $first; $first = uniqid("test"); $is_ref = ($first === $second); $first = $temp; return $is_ref; } - /** - * Test to see if an object is a member of a - * class hiearchy. - * @param object $object Object to test. - * @param string $class Root name of hiearchy. - * @access public - * @static - */ + /** + * Test to see if an object is a member of a + * class hiearchy. + * @param object $object Object to test. + * @param string $class Root name of hiearchy. + * @return boolean True if class in hiearchy. + * @access public + * @static + */ function isA($object, $class) { if (version_compare(phpversion(), '5') >= 0) { if (! class_exists($class, false)) { @@ -318,28 +337,13 @@ or (is_subclass_of($object, $class))); } - /** - * Autoload safe version of class_exists(). - * @param string $class Name of class to look for. - * @return boolean True if class is defined. - * @access public - * @static - */ - function classExists($class) { - if (version_compare(phpversion(), '5') >= 0) { - return class_exists($class, false); - } else { - return class_exists($class); - } - } - - /** - * Sets a socket timeout for each chunk. - * @param resource $handle Socket handle. - * @param integer $timeout Limit in seconds. - * @access public - * @static - */ + /** + * Sets a socket timeout for each chunk. + * @param resource $handle Socket handle. + * @param integer $timeout Limit in seconds. + * @access public + * @static + */ function setTimeout($handle, $timeout) { if (function_exists('stream_set_timeout')) { stream_set_timeout($handle, $timeout, 0); @@ -350,12 +354,12 @@ } } - /** - * Gets the current stack trace topmost first. - * @return array List of stack frames. - * @access public - * @static - */ + /** + * Gets the current stack trace topmost first. + * @return array List of stack frames. + * @access public + * @static + */ function getStackTrace() { if (function_exists('debug_backtrace')) { return array_reverse(debug_backtrace()); diff --git a/vendors/simpletest/page.php b/vendors/simpletest/page.php index 1900bc4bb..1b0088dd2 100644 --- a/vendors/simpletest/page.php +++ b/vendors/simpletest/page.php @@ -1,46 +1,142 @@ 'SimpleAnchorTag', + 'title' => 'SimpleTitleTag', + 'button' => 'SimpleButtonTag', + 'textarea' => 'SimpleTextAreaTag', + 'option' => 'SimpleOptionTag', + 'label' => 'SimpleLabelTag', + 'form' => 'SimpleFormTag', + 'frame' => 'SimpleFrameTag'); + $attributes = $this->_keysToLowerCase($attributes); + if (array_key_exists($name, $map)) { + $tag_class = $map[$name]; + return new $tag_class($attributes); + } elseif ($name == 'select') { + return $this->_createSelectionTag($attributes); + } elseif ($name == 'input') { + return $this->_createInputTag($attributes); + } + return new SimpleTag($name, $attributes); + } + + /** + * Factory for selection fields. + * @param hash $attributes Element attributes. + * @return SimpleTag Tag object. + * @access protected + */ + function _createSelectionTag($attributes) { + if (isset($attributes['multiple'])) { + return new MultipleSelectionTag($attributes); + } + return new SimpleSelectionTag($attributes); + } + + /** + * Factory for input tags. + * @param hash $attributes Element attributes. + * @return SimpleTag Tag object. + * @access protected + */ + function _createInputTag($attributes) { + if (! isset($attributes['type'])) { + return new SimpleTextTag($attributes); + } + $type = strtolower(trim($attributes['type'])); + $map = array( + 'submit' => 'SimpleSubmitTag', + 'image' => 'SimpleImageSubmitTag', + 'checkbox' => 'SimpleCheckboxTag', + 'radio' => 'SimpleRadioButtonTag', + 'text' => 'SimpleTextTag', + 'hidden' => 'SimpleTextTag', + 'password' => 'SimpleTextTag', + 'file' => 'SimpleUploadTag'); + if (array_key_exists($type, $map)) { + $tag_class = $map[$type]; + return new $tag_class($attributes); + } + return false; + } + + /** + * Make the keys lower case for case insensitive look-ups. + * @param hash $map Hash to convert. + * @return hash Unchanged values, but keys lower case. + * @access private + */ + function _keysToLowerCase($map) { + $lower = array(); + foreach ($map as $key => $value) { + $lower[strtolower($key)] = $value; + } + return $lower; + } + } + + /** + * SAX event handler. Maintains a list of + * open tags and dispatches them as they close. + * @package SimpleTest + * @subpackage WebTester + */ class SimplePageBuilder extends SimpleSaxListener { var $_tags; var $_page; + var $_in_option = false; - /** - * Sets the builder up empty. - * @access public - */ + /** + * Sets the builder up empty. + * @access public + */ function SimplePageBuilder() { $this->SimpleSaxListener(); } - /** - * Reads the raw content and send events - * into the page to be built. - * @param $response SimpleHttpResponse Fetched response. - * @return SimplePage Newly parsed page. - * @access public - */ - function parse($response) { + /** + * Reads the raw content and send events + * into the page to be built. + * @param $response SimpleHttpResponse Fetched response. + * @return SimplePage Newly parsed page. + * @access public + */ + function &parse($response) { $this->_tags = array(); $this->_page = &$this->_createPage($response); $parser = &$this->_createParser($this); @@ -49,62 +145,62 @@ return $this->_page; } - /** - * Creates an empty page. - * @return SimplePage New unparsed page. - * @access protected - */ + /** + * Creates an empty page. + * @return SimplePage New unparsed page. + * @access protected + */ function &_createPage($response) { - return new SimplePage($response); + $page = &new SimplePage($response); + return $page; } - /** - * Creates the parser used with the builder. - * @param $listener SimpleSaxListener Target of parser. - * @return SimpleSaxParser Parser to generate - * events for the builder. - * @access protected - */ + /** + * Creates the parser used with the builder. + * @param $listener SimpleSaxListener Target of parser. + * @return SimpleSaxParser Parser to generate + * events for the builder. + * @access protected + */ function &_createParser(&$listener) { - return new SimpleSaxParser($listener); + $parser = &new SimpleSaxParser($listener); + return $parser; } - /** - * Make the keys lower case for case insensitive look-ups. - * @param hash $map Hash to convert. - * @return hash Unchanged values, but keys lower case. - * @access private - */ - function _keysToLowerCase($map) { - $lower = array(); - foreach ($map as $key => $value) { - $lower[strtolower($key)] = $value; - } - return $lower; - } - - /** - * Start of element event. Opens a new tag. - * @param string $name Element name. - * @param hash $attributes Attributes without content - * are marked as true. - * @return boolean False on parse error. - * @access public - */ + /** + * Start of element event. Opens a new tag. + * @param string $name Element name. + * @param hash $attributes Attributes without content + * are marked as true. + * @return boolean False on parse error. + * @access public + */ function startElement($name, $attributes) { - $tag = &$this->_createTag($name, $this->_keysToLowerCase($attributes)); - if ($name == 'form') { + $factory = &new SimpleTagBuilder(); + $tag = $factory->createTag($name, $attributes); + if (! $tag) { + return true; + } + if ($tag->getTagName() == 'label') { + $this->_page->acceptLabelStart($tag); + $this->_openTag($tag); + return true; + } + if ($tag->getTagName() == 'form') { $this->_page->acceptFormStart($tag); return true; - } - if ($name == 'frameset') { + } + if ($tag->getTagName() == 'frameset') { $this->_page->acceptFramesetStart($tag); return true; - } - if ($name == 'frame') { + } + if ($tag->getTagName() == 'frame') { $this->_page->acceptFrame($tag); return true; - } + } + if ($tag->getTagName() == 'option') { + $this->_in_option = true; + } if ($tag->expectEndTag()) { $this->_openTag($tag); return true; @@ -113,13 +209,17 @@ return true; } - /** - * End of element event. - * @param string $name Element name. - * @return boolean False on parse error. - * @access public - */ + /** + * End of element event. + * @param string $name Element name. + * @return boolean False on parse error. + * @access public + */ function endElement($name) { + if ($name == 'label') { + $this->_page->acceptLabelEnd(); + return true; + } if ($name == 'form') { $this->_page->acceptFormEnd(); return true; @@ -128,7 +228,10 @@ $this->_page->acceptFramesetEnd(); return true; } - if (isset($this->_tags[$name]) && (count($this->_tags[$name]) > 0)) { + if ($name == 'option') { + $this->_in_option = false; + } + if ($this->_hasNamedTagOnOpenTagStack($name)) { $tag = array_pop($this->_tags[$name]); $this->_addContentTagToOpenTags($tag); $this->_page->acceptTag($tag); @@ -137,28 +240,65 @@ return true; } - /** - * Unparsed, but relevant data. The data is added - * to every open tag. - * @param string $text May include unparsed tags. - * @return boolean False on parse error. - * @access public - */ + /** + * Test to see if there are any open tags awaiting + * closure that match the tag name. + * @param string $name Element name. + * @return boolean True if any are still open. + * @access private + */ + function _hasNamedTagOnOpenTagStack($name) { + return isset($this->_tags[$name]) && (count($this->_tags[$name]) > 0); + } + + /** + * Unparsed, but relevant data. The data is added + * to every open tag. + * @param string $text May include unparsed tags. + * @return boolean False on parse error. + * @access public + */ function addContent($text) { + if ($this->_in_option) { + $this->_addContentToOptionTag($text); + } else { + $this->_addContentToAllOpenTags($text); + } + return true; + } + + /** + * Option tags swallow content and so we want any + * new content to go only to the most current option. + * @param string $text May include unparsed tags. + * @access private + */ + function _addContentToOptionTag($text) { + $current = count($this->_tags['option']) - 1; + $this->_tags['option'][$current]->addContent($text); + } + + /** + * Any content fills all currently open tags unless it + * is part of an option tag. + * @param string $text May include unparsed tags. + * @access private + */ + function _addContentToAllOpenTags($text) { foreach (array_keys($this->_tags) as $name) { for ($i = 0, $count = count($this->_tags[$name]); $i < $count; $i++) { $this->_tags[$name][$i]->addContent($text); } } - return true; } - /** - * Parsed relevant data. The parsed tag is added - * to every open tag. - * @param SimpleTag $tag May include unparsed tags. - * @access private - */ + /** + * Parsed data in tag form. The parsed tag is added + * to every open tag. Used for adding options to select + * fields only. + * @param SimpleTag $tag Option tags only. + * @access private + */ function _addContentTagToOpenTags(&$tag) { if ($tag->getTagName() != 'option') { return; @@ -170,97 +310,32 @@ } } - /** - * Opens a tag for receiving content. Multiple tags - * will be receiving input at the same time. - * @param SimpleTag $tag New content tag. - * @access private - */ + /** + * Opens a tag for receiving content. Multiple tags + * will be receiving input at the same time. + * @param SimpleTag $tag New content tag. + * @access private + */ function _openTag(&$tag) { $name = $tag->getTagName(); if (! in_array($name, array_keys($this->_tags))) { $this->_tags[$name] = array(); } - array_push($this->_tags[$name], $tag); - } - - /** - * Factory for the tag objects. Creates the - * appropriate tag object for the incoming tag name. - * @param string $name HTML tag name. - * @param hash $attributes Element attributes. - * @return SimpleTag Tag object. - * @access protected - */ - function &_createTag($name, $attributes) { - if ($name == 'a') { - return new SimpleAnchorTag($attributes); - } elseif ($name == 'title') { - return new SimpleTitleTag($attributes); - } elseif ($name == 'input') { - return $this->_createInputTag($attributes); - } elseif ($name == 'button') { - return new SimpleButtonTag($attributes); - } elseif ($name == 'textarea') { - return new SimpleTextAreaTag($attributes); - } elseif ($name == 'select') { - return $this->_createSelectionTag($attributes); - } elseif ($name == 'option') { - return new SimpleOptionTag($attributes); - } elseif ($name == 'form') { - return new SimpleFormTag($attributes); - } elseif ($name == 'frame') { - return new SimpleFrameTag($attributes); - } - return new SimpleTag($name, $attributes); - } - - /** - * Factory for selection fields. - * @param hash $attributes Element attributes. - * @return SimpleTag Tag object. - * @access protected - */ - function &_createSelectionTag($attributes) { - if (isset($attributes['multiple'])) { - return new MultipleSelectionTag($attributes); - } - return new SimpleSelectionTag($attributes); - } - - /** - * Factory for input tags. - * @param hash $attributes Element attributes. - * @return SimpleTag Tag object. - * @access protected - */ - function &_createInputTag($attributes) { - if (! isset($attributes['type'])) { - return new SimpleTextTag($attributes); - } - $type = strtolower($attributes['type']); - if ($type == 'submit') { - return new SimpleSubmitTag($attributes); - } elseif ($type == 'image') { - return new SimpleImageSubmitTag($attributes); - } elseif ($type == 'checkbox') { - return new SimpleCheckboxTag($attributes); - } elseif ($type == 'radio') { - return new SimpleRadioButtonTag($attributes); - } else { - return new SimpleTextTag($attributes); - } + $this->_tags[$name][] = &$tag; } } - /** - * A wrapper for a web page. - * @package SimpleTest - * @subpackage WebTester - */ + /** + * A wrapper for a web page. + * @package SimpleTest + * @subpackage WebTester + */ class SimplePage { var $_links; var $_title; + var $_last_widget; + var $_label; + var $_left_over_labels; var $_open_forms; var $_complete_forms; var $_frameset; @@ -275,14 +350,15 @@ var $_url; var $_request_data; - /** - * Parses a page ready to access it's contents. - * @param SimpleHttpResponse $response Result of HTTP fetch. - * @access public - */ + /** + * Parses a page ready to access it's contents. + * @param SimpleHttpResponse $response Result of HTTP fetch. + * @access public + */ function SimplePage($response = false) { $this->_links = array(); $this->_title = false; + $this->_left_over_labels = array(); $this->_open_forms = array(); $this->_complete_forms = array(); $this->_frameset = false; @@ -296,11 +372,11 @@ } } - /** - * Extracts all of the response information. - * @param SimpleHttpResponse $response Response being parsed. - * @access private - */ + /** + * Extracts all of the response information. + * @param SimpleHttpResponse $response Response being parsed. + * @access private + */ function _extractResponse($response) { $this->_transport_error = $response->getError(); $this->_raw = $response->getContent(); @@ -311,10 +387,10 @@ $this->_request_data = $response->getRequestData(); } - /** - * Sets up a missing response. - * @access private - */ + /** + * Sets up a missing response. + * @access private + */ function _noResponse() { $this->_transport_error = 'No page fetched yet'; $this->_raw = false; @@ -325,30 +401,30 @@ $this->_request_data = false; } - /** - * Original request as bytes sent down the wire. - * @return mixed Sent content. - * @access public - */ + /** + * Original request as bytes sent down the wire. + * @return mixed Sent content. + * @access public + */ function getRequest() { return $this->_sent; } - /** - * Accessor for raw text of page. - * @return string Raw unparsed content. - * @access public - */ + /** + * Accessor for raw text of page. + * @return string Raw unparsed content. + * @access public + */ function getRaw() { return $this->_raw; } - /** - * Accessor for plain text of page as a text browser - * would see it. - * @return string Plain text of page. - * @access public - */ + /** + * Accessor for plain text of page as a text browser + * would see it. + * @return string Plain text of page. + * @access public + */ function getText() { if (! $this->_text) { $this->_text = SimpleSaxParser::normalise($this->_raw); @@ -356,11 +432,11 @@ return $this->_text; } - /** - * Accessor for raw headers of page. - * @return string Header block as text. - * @access public - */ + /** + * Accessor for raw headers of page. + * @return string Header block as text. + * @access public + */ function getHeaders() { if ($this->_headers) { return $this->_headers->getRaw(); @@ -368,47 +444,47 @@ return false; } - /** - * Original request method. - * @return string GET, POST or HEAD. - * @access public - */ + /** + * Original request method. + * @return string GET, POST or HEAD. + * @access public + */ function getMethod() { return $this->_method; } - /** - * Original resource name. - * @return SimpleUrl Current url. - * @access public - */ + /** + * Original resource name. + * @return SimpleUrl Current url. + * @access public + */ function getUrl() { return $this->_url; } - /** - * Original request data. - * @return mixed Sent content. - * @access public - */ + /** + * Original request data. + * @return mixed Sent content. + * @access public + */ function getRequestData() { return $this->_request_data; } - /** - * Accessor for last error. - * @return string Error from last response. - * @access public - */ + /** + * Accessor for last error. + * @return string Error from last response. + * @access public + */ function getTransportError() { return $this->_transport_error; } - /** - * Accessor for current MIME type. - * @return string MIME type as string; e.g. 'text/html' - * @access public - */ + /** + * Accessor for current MIME type. + * @return string MIME type as string; e.g. 'text/html' + * @access public + */ function getMimeType() { if ($this->_headers) { return $this->_headers->getMimeType(); @@ -416,11 +492,11 @@ return false; } - /** - * Accessor for HTTP response code. - * @return integer HTTP response code received. - * @access public - */ + /** + * Accessor for HTTP response code. + * @return integer HTTP response code received. + * @access public + */ function getResponseCode() { if ($this->_headers) { return $this->_headers->getResponseCode(); @@ -428,12 +504,12 @@ return false; } - /** - * Accessor for last Authentication type. Only valid - * straight after a challenge (401). - * @return string Description of challenge type. - * @access public - */ + /** + * Accessor for last Authentication type. Only valid + * straight after a challenge (401). + * @return string Description of challenge type. + * @access public + */ function getAuthentication() { if ($this->_headers) { return $this->_headers->getAuthentication(); @@ -441,12 +517,12 @@ return false; } - /** - * Accessor for last Authentication realm. Only valid - * straight after a challenge (401). - * @return string Name of security realm. - * @access public - */ + /** + * Accessor for last Authentication realm. Only valid + * straight after a challenge (401). + * @return string Name of security realm. + * @access public + */ function getRealm() { if ($this->_headers) { return $this->_headers->getRealm(); @@ -454,48 +530,48 @@ return false; } - /** - * Accessor for current frame focus. Will be - * false as no frames. - * @return array Always empty. - * @access public - */ + /** + * Accessor for current frame focus. Will be + * false as no frames. + * @return array Always empty. + * @access public + */ function getFrameFocus() { return array(); } - /** - * Sets the focus by index. The integer index starts from 1. - * @param integer $choice Chosen frame. - * @return boolean Always false. - * @access public - */ + /** + * Sets the focus by index. The integer index starts from 1. + * @param integer $choice Chosen frame. + * @return boolean Always false. + * @access public + */ function setFrameFocusByIndex($choice) { return false; } - /** - * Sets the focus by name. Always fails for a leaf page. - * @param string $name Chosen frame. - * @return boolean False as no frames. - * @access public - */ + /** + * Sets the focus by name. Always fails for a leaf page. + * @param string $name Chosen frame. + * @return boolean False as no frames. + * @access public + */ function setFrameFocus($name) { return false; } - /** - * Clears the frame focus. Does nothing for a leaf page. - * @access public - */ + /** + * Clears the frame focus. Does nothing for a leaf page. + * @access public + */ function clearFrameFocus() { } - /** - * Adds a tag to the page. - * @param SimpleTag $tag Tag to accept. - * @access public - */ + /** + * Adds a tag to the page. + * @param SimpleTag $tag Tag to accept. + * @access public + */ function acceptTag(&$tag) { if ($tag->getTagName() == "a") { $this->_addLink($tag); @@ -505,45 +581,72 @@ for ($i = 0; $i < count($this->_open_forms); $i++) { $this->_open_forms[$i]->addWidget($tag); } + $this->_last_widget = &$tag; } } - /** - * Tests to see if a tag is a possible form - * element. - * @param string $name HTML element name. - * @return boolean True if form element. - * @access private - */ + /** + * Opens a label for a described widget. + * @param SimpleFormTag $tag Tag to accept. + * @access public + */ + function acceptLabelStart(&$tag) { + $this->_label = &$tag; + unset($this->_last_widget); + } + + /** + * Closes the most recently opened label. + * @access public + */ + function acceptLabelEnd() { + if (isset($this->_label)) { + if (isset($this->_last_widget)) { + $this->_last_widget->setLabel($this->_label->getText()); + unset($this->_last_widget); + } else { + $this->_left_over_labels[] = SimpleTestCompatibility::copy($this->_label); + } + unset($this->_label); + } + } + + /** + * Tests to see if a tag is a possible form + * element. + * @param string $name HTML element name. + * @return boolean True if form element. + * @access private + */ function _isFormElement($name) { return in_array($name, array('input', 'button', 'textarea', 'select')); } - /** - * Opens a form. New widgets go here. - * @param SimpleFormTag $tag Tag to accept. - * @access public - */ + /** + * Opens a form. New widgets go here. + * @param SimpleFormTag $tag Tag to accept. + * @access public + */ function acceptFormStart(&$tag) { $this->_open_forms[] = &new SimpleForm($tag, $this->getUrl()); } - /** - * Closes the most recently opened form. - * @access public - */ + /** + * Closes the most recently opened form. + * @access public + */ function acceptFormEnd() { if (count($this->_open_forms)) { $this->_complete_forms[] = array_pop($this->_open_forms); } } - /** - * Opens a frameset. A frameset may contain nested - * frameset tags. - * @param SimpleFramesetTag $tag Tag to accept. - * @access public - */ + /** + * Opens a frameset. A frameset may contain nested + * frameset tags. + * @param SimpleFramesetTag $tag Tag to accept. + * @access public + */ function acceptFramesetStart(&$tag) { if (! $this->_isLoadingFrames()) { $this->_frameset = &$tag; @@ -551,22 +654,22 @@ $this->_frameset_nesting_level++; } - /** - * Closes the most recently opened frameset. - * @access public - */ + /** + * Closes the most recently opened frameset. + * @access public + */ function acceptFramesetEnd() { if ($this->_isLoadingFrames()) { $this->_frameset_nesting_level--; } } - /** - * Takes a single frame tag and stashes it in - * the current frame set. - * @param SimpleFrameTag $tag Tag to accept. - * @access public - */ + /** + * Takes a single frame tag and stashes it in + * the current frame set. + * @param SimpleFrameTag $tag Tag to accept. + * @access public + */ function acceptFrame(&$tag) { if ($this->_isLoadingFrames()) { if ($tag->getAttribute('src')) { @@ -575,12 +678,12 @@ } } - /** - * Test to see if in the middle of reading - * a frameset. - * @return boolean True if inframeset. - * @access private - */ + /** + * Test to see if in the middle of reading + * a frameset. + * @return boolean True if inframeset. + * @access private + */ function _isLoadingFrames() { if (! $this->_frameset) { return false; @@ -588,55 +691,62 @@ return ($this->_frameset_nesting_level > 0); } - /** - * Test to see if link is an absolute one. - * @param string $url Url to test. - * @return boolean True if absolute. - * @access protected - */ + /** + * Test to see if link is an absolute one. + * @param string $url Url to test. + * @return boolean True if absolute. + * @access protected + */ function _linkIsAbsolute($url) { $parsed = new SimpleUrl($url); return (boolean)($parsed->getScheme() && $parsed->getHost()); } - /** - * Adds a link to the page. - * @param SimpleAnchorTag $tag Link to accept. - * @access protected - */ + /** + * Adds a link to the page. + * @param SimpleAnchorTag $tag Link to accept. + * @access protected + */ function _addLink($tag) { $this->_links[] = $tag; } - /** - * Marker for end of complete page. Any work in - * progress can now be closed. - * @access public - */ + /** + * Marker for end of complete page. Any work in + * progress can now be closed. + * @access public + */ function acceptPageEnd() { while (count($this->_open_forms)) { $this->_complete_forms[] = array_pop($this->_open_forms); } + foreach ($this->_left_over_labels as $label) { + for ($i = 0, $count = count($this->_complete_forms); $i < $count; $i++) { + $this->_complete_forms[$i]->attachLabelBySelector( + new SimpleById($label->getFor()), + $label->getText()); + } + } } - /** - * Test for the presence of a frameset. - * @return boolean True if frameset. - * @access public - */ + /** + * Test for the presence of a frameset. + * @return boolean True if frameset. + * @access public + */ function hasFrames() { return (boolean)$this->_frameset; } - /** - * Accessor for frame name and source URL for every frame that - * will need to be loaded. Immediate children only. - * @return boolean/array False if no frameset or - * otherwise a hash of frame URLs. - * The key is either a numerical - * base one index or the name attribute. - * @access public - */ + /** + * Accessor for frame name and source URL for every frame that + * will need to be loaded. Immediate children only. + * @return boolean/array False if no frameset or + * otherwise a hash of frame URLs. + * The key is either a numerical + * base one index or the name attribute. + * @access public + */ function getFrameset() { if (! $this->_frameset) { return false; @@ -650,22 +760,22 @@ return $urls; } - /** - * Fetches a list of loaded frames. - * @return array/string Just the URL for a single page. - * @access public - */ + /** + * Fetches a list of loaded frames. + * @return array/string Just the URL for a single page. + * @access public + */ function getFrames() { $url = $this->getUrl(); return $url->asString(); } - /** - * Accessor for a list of all fixed links. - * @return array List of urls with scheme of - * http or https and hostname. - * @access public - */ + /** + * Accessor for a list of all fixed links. + * @return array List of urls with scheme of + * http or https and hostname. + * @access public + */ function getAbsoluteUrls() { $all = array(); foreach ($this->_links as $link) { @@ -676,11 +786,11 @@ return $all; } - /** - * Accessor for a list of all relative links. - * @return array List of urls without hostname. - * @access public - */ + /** + * Accessor for a list of all relative links. + * @return array List of urls without hostname. + * @access public + */ function getRelativeUrls() { $all = array(); foreach ($this->_links as $link) { @@ -691,13 +801,13 @@ return $all; } - /** - * Accessor for URLs by the link label. Label will match - * regardess of whitespace issues and case. - * @param string $label Text of link. - * @return array List of links with that label. - * @access public - */ + /** + * Accessor for URLs by the link label. Label will match + * regardess of whitespace issues and case. + * @param string $label Text of link. + * @return array List of links with that label. + * @access public + */ function getUrlsByLabel($label) { $matches = array(); foreach ($this->_links as $link) { @@ -708,12 +818,12 @@ return $matches; } - /** - * Accessor for a URL by the id attribute. - * @param string $id Id attribute of link. - * @return SimpleUrl URL with that id of false if none. - * @access public - */ + /** + * Accessor for a URL by the id attribute. + * @param string $id Id attribute of link. + * @return SimpleUrl URL with that id of false if none. + * @access public + */ function getUrlById($id) { foreach ($this->_links as $link) { if ($link->getAttribute('id') === (string)$id) { @@ -723,12 +833,12 @@ return false; } - /** - * Converts a link into a target URL. - * @param SimpleAnchor $link Parsed link. - * @return SimpleUrl URL with frame target if any. - * @access private - */ + /** + * Converts a link into a target URL. + * @param SimpleAnchor $link Parsed link. + * @return SimpleUrl URL with frame target if any. + * @access private + */ function _getUrlFromLink($link) { $url = $this->_makeAbsolute($link->getHref()); if ($link->getAttribute('target')) { @@ -737,13 +847,13 @@ return $url; } - /** - * Expands expandomatic URLs into fully qualified - * URLs. - * @param SimpleUrl $url Relative URL. - * @return SimpleUrl Absolute URL. - * @access protected - */ + /** + * Expands expandomatic URLs into fully qualified + * URLs. + * @param SimpleUrl $url Relative URL. + * @return SimpleUrl Absolute URL. + * @access protected + */ function _makeAbsolute($url) { if (! is_object($url)) { $url = new SimpleUrl($url); @@ -751,20 +861,20 @@ return $url->makeAbsolute($this->getUrl()); } - /** - * Sets the title tag contents. - * @param SimpleTitleTag $tag Title of page. - * @access protected - */ + /** + * Sets the title tag contents. + * @param SimpleTitleTag $tag Title of page. + * @access protected + */ function _setTitle(&$tag) { $this->_title = &$tag; } - /** - * Accessor for parsed title. - * @return string Title or false if no title is present. - * @access public - */ + /** + * Accessor for parsed title. + * @return string Title or false if no title is present. + * @access public + */ function getTitle() { if ($this->_title) { return $this->_title->getText(); @@ -772,166 +882,215 @@ return false; } - /** - * Finds a held form by button label. Will only - * search correctly built forms. - * @param string $label Button label, default 'Submit'. - * @return SimpleForm Form object containing the button. - * @access public - */ + /** + * Finds a held form by button label. Will only + * search correctly built forms. + * @param string $label Button label, default 'Submit'. + * @return SimpleForm Form object containing the button. + * @access public + */ function &getFormBySubmitLabel($label) { for ($i = 0; $i < count($this->_complete_forms); $i++) { - if ($this->_complete_forms[$i]->hasSubmitLabel($label)) { + if ($this->_complete_forms[$i]->hasSubmit(new SimpleByLabel($label))) { return $this->_complete_forms[$i]; } } - return null; + $null = null; + return $null; } - /** - * Finds a held form by button label. Will only - * search correctly built forms. - * @param string $name Button name attribute. - * @return SimpleForm Form object containing the button. - * @access public - */ + /** + * Finds a held form by button label. Will only + * search correctly built forms. + * @param string $name Button name attribute. + * @return SimpleForm Form object containing the button. + * @access public + */ function &getFormBySubmitName($name) { for ($i = 0; $i < count($this->_complete_forms); $i++) { - if ($this->_complete_forms[$i]->hasSubmitName($name)) { + if ($this->_complete_forms[$i]->hasSubmit(new SimpleByName($name))) { return $this->_complete_forms[$i]; } } - return null; + $null = null; + return $null; } - /** - * Finds a held form by button id. Will only - * search correctly built forms. - * @param string $id Button ID attribute. - * @return SimpleForm Form object containing the button. - * @access public - */ + /** + * Finds a held form by button id. Will only + * search correctly built forms. + * @param string $id Button ID attribute. + * @return SimpleForm Form object containing the button. + * @access public + */ function &getFormBySubmitId($id) { for ($i = 0; $i < count($this->_complete_forms); $i++) { - if ($this->_complete_forms[$i]->hasSubmitId($id)) { + if ($this->_complete_forms[$i]->hasSubmit(new SimpleById($id))) { return $this->_complete_forms[$i]; } } - return null; + $null = null; + return $null; } - /** - * Finds a held form by image label. Will only - * search correctly built forms. - * @param string $label Usually the alt attribute. - * @return SimpleForm Form object containing the image. - * @access public - */ + /** + * Finds a held form by image label. Will only + * search correctly built forms. + * @param string $label Usually the alt attribute. + * @return SimpleForm Form object containing the image. + * @access public + */ function &getFormByImageLabel($label) { for ($i = 0; $i < count($this->_complete_forms); $i++) { - if ($this->_complete_forms[$i]->hasImageLabel($label)) { + if ($this->_complete_forms[$i]->hasImage(new SimpleByLabel($label))) { return $this->_complete_forms[$i]; } } - return null; + $null = null; + return $null; } - /** - * Finds a held form by image button id. Will only - * search correctly built forms. - * @param string $name Image name. - * @return SimpleForm Form object containing the image. - * @access public - */ + /** + * Finds a held form by image button id. Will only + * search correctly built forms. + * @param string $name Image name. + * @return SimpleForm Form object containing the image. + * @access public + */ function &getFormByImageName($name) { for ($i = 0; $i < count($this->_complete_forms); $i++) { - if ($this->_complete_forms[$i]->hasImageName($name)) { + if ($this->_complete_forms[$i]->hasImage(new SimpleByName($name))) { return $this->_complete_forms[$i]; } } - return null; + $null = null; + return $null; } - /** - * Finds a held form by image button id. Will only - * search correctly built forms. - * @param string $id Image ID attribute. - * @return SimpleForm Form object containing the image. - * @access public - */ + /** + * Finds a held form by image button id. Will only + * search correctly built forms. + * @param string $id Image ID attribute. + * @return SimpleForm Form object containing the image. + * @access public + */ function &getFormByImageId($id) { for ($i = 0; $i < count($this->_complete_forms); $i++) { - if ($this->_complete_forms[$i]->hasImageId($id)) { + if ($this->_complete_forms[$i]->hasImage(new SimpleById($id))) { return $this->_complete_forms[$i]; } } - return null; + $null = null; + return $null; } - /** - * Finds a held form by the form ID. A way of - * identifying a specific form when we have control - * of the HTML code. - * @param string $id Form label. - * @return SimpleForm Form object containing the matching ID. - * @access public - */ + /** + * Finds a held form by the form ID. A way of + * identifying a specific form when we have control + * of the HTML code. + * @param string $id Form label. + * @return SimpleForm Form object containing the matching ID. + * @access public + */ function &getFormById($id) { for ($i = 0; $i < count($this->_complete_forms); $i++) { if ($this->_complete_forms[$i]->getId() == $id) { return $this->_complete_forms[$i]; } } - return null; + $null = null; + return $null; } - /** - * Sets a field on each form in which the field is - * available. - * @param string $name Field name. - * @param string $value Value to set field to. - * @return boolean True if value is valid. - * @access public - */ - function setField($name, $value) { + /** + * Sets a field on each form in which the field is + * available. Sets by label, but for compatibility + * drops back to a name. + * @param string $label Field label or name. + * @param string $value Value to set field to. + * @return boolean True if value is valid. + * @access public + */ + function setField($label, $value) { $is_set = false; for ($i = 0; $i < count($this->_complete_forms); $i++) { - if ($this->_complete_forms[$i]->setField($name, $value)) { + if ($this->_complete_forms[$i]->setField(new SimpleByLabel($label), $value)) { + $is_set = true; + } + } + if ($is_set) { + return true; + } + return $this->setFieldByName($label, $value); + } + + /** + * Sets a field on each form in which the field is + * available by name. + * @param string $name Field name. + * @param string $value Value to set field to. + * @return boolean True if value is valid. + * @access public + */ + function setFieldByName($name, $value) { + $is_set = false; + for ($i = 0; $i < count($this->_complete_forms); $i++) { + if ($this->_complete_forms[$i]->setField(new SimpleByName($name), $value)) { $is_set = true; } } return $is_set; } - /** - * Sets a field on the form in which the unique field is - * available. - * @param string/integer $id Field ID attribute. - * @param string $value Value to set field to. - * @return boolean True if value is valid. - * @access public - */ + /** + * Sets a field on the form in which the unique field is + * available. + * @param string/integer $id Field ID attribute. + * @param string $value Value to set field to. + * @return boolean True if value is valid. + * @access public + */ function setFieldById($id, $value) { for ($i = 0; $i < count($this->_complete_forms); $i++) { - if ($this->_complete_forms[$i]->setFieldById($id, $value)) { + if ($this->_complete_forms[$i]->setField(new SimpleById($id), $value)) { return true; } } return false; } - /** - * Accessor for a form element value within a page. - * Finds the first match. - * @param string $name Field name. - * @return string/boolean A string if the field is - * present, false if unchecked - * and null if missing. - * @access public - */ - function getField($name) { + /** + * Accessor for a form element value within a page. + * Finds the first match by label first. If none are found + * then it does a search by name attribute instead. + * @param string $label Field label. + * @return string/boolean A string if the field is + * present, false if unchecked + * and null if missing. + * @access public + */ + function getField($label) { for ($i = 0; $i < count($this->_complete_forms); $i++) { - $value = $this->_complete_forms[$i]->getValue($name); + $value = $this->_complete_forms[$i]->getValue(new SimpleByLabel($label)); + if (isset($value)) { + return $value; + } + } + return $this->getFieldByName($label); + } + + /** + * Accessor for a form element value within a page. + * Finds the first match by name only. + * @param string $name Field name. + * @return string/boolean A string if the field is + * present, false if unchecked + * and null if missing. + * @access public + */ + function getFieldByName($name) { + for ($i = 0; $i < count($this->_complete_forms); $i++) { + $value = $this->_complete_forms[$i]->getValue(new SimpleByName($name)); if (isset($value)) { return $value; } @@ -939,18 +1098,18 @@ return null; } - /** - * Accessor for a form element value within a page. - * Finds the first match. - * @param string/integer $id Field ID attribute. - * @return string/boolean A string if the field is - * present, false if unchecked - * and null if missing. - * @access public - */ + /** + * Accessor for a form element value within a page. + * Finds the first match. + * @param string/integer $id Field ID attribute. + * @return string/boolean A string if the field is + * present, false if unchecked + * and null if missing. + * @access public + */ function getFieldById($id) { for ($i = 0; $i < count($this->_complete_forms); $i++) { - $value = $this->_complete_forms[$i]->getValueById($id); + $value = $this->_complete_forms[$i]->getValue(new SimpleById($id)); if (isset($value)) { return $value; } diff --git a/vendors/simpletest/parser.php b/vendors/simpletest/parser.php index 9829f4312..9c8f32afa 100644 --- a/vendors/simpletest/parser.php +++ b/vendors/simpletest/parser.php @@ -1,40 +1,50 @@ _case = $case; $this->_patterns = array(); @@ -42,14 +52,14 @@ $this->_regex = null; } - /** - * Adds a pattern with an optional label. - * @param string $pattern Perl style regex, but ( and ) - * lose the usual meaning. - * @param string $label Label of regex to be returned - * on a match. - * @access public - */ + /** + * Adds a pattern with an optional label. + * @param string $pattern Perl style regex, but ( and ) + * lose the usual meaning. + * @param string $label Label of regex to be returned + * on a match. + * @access public + */ function addPattern($pattern, $label = true) { $count = count($this->_patterns); $this->_patterns[$count] = $pattern; @@ -57,15 +67,15 @@ $this->_regex = null; } - /** - * Attempts to match all patterns at once against - * a string. - * @param string $subject String to match against. - * @param string $match First matched portion of - * subject. - * @return boolean True on success. - * @access public - */ + /** + * Attempts to match all patterns at once against + * a string. + * @param string $subject String to match against. + * @param string $match First matched portion of + * subject. + * @return boolean True on success. + * @access public + */ function match($subject, &$match) { if (count($this->_patterns) == 0) { return false; @@ -83,14 +93,14 @@ return true; } - /** - * Compounds the patterns into a single - * regular expression separated with the - * "or" operator. Caches the regex. - * Will automatically escape (, ) and / tokens. - * @param array $patterns List of patterns in order. - * @access private - */ + /** + * Compounds the patterns into a single + * regular expression separated with the + * "or" operator. Caches the regex. + * Will automatically escape (, ) and / tokens. + * @param array $patterns List of patterns in order. + * @access private + */ function _getCompoundedRegex() { if ($this->_regex == null) { for ($i = 0, $count = count($this->_patterns); $i < $count; $i++) { @@ -104,59 +114,59 @@ return $this->_regex; } - /** - * Accessor for perl regex mode flags to use. - * @return string Perl regex flags. - * @access private - */ + /** + * Accessor for perl regex mode flags to use. + * @return string Perl regex flags. + * @access private + */ function _getPerlMatchingFlags() { return ($this->_case ? "msS" : "msSi"); } } - /** - * States for a stack machine. - * @package SimpleTest - * @subpackage WebTester - */ + /** + * States for a stack machine. + * @package SimpleTest + * @subpackage WebTester + */ class SimpleStateStack { var $_stack; - /** - * Constructor. Starts in named state. - * @param string $start Starting state name. - * @access public - */ + /** + * Constructor. Starts in named state. + * @param string $start Starting state name. + * @access public + */ function SimpleStateStack($start) { $this->_stack = array($start); } - /** - * Accessor for current state. - * @return string State. - * @access public - */ + /** + * Accessor for current state. + * @return string State. + * @access public + */ function getCurrent() { return $this->_stack[count($this->_stack) - 1]; } - /** - * Adds a state to the stack and sets it - * to be the current state. - * @param string $state New state. - * @access public - */ + /** + * Adds a state to the stack and sets it + * to be the current state. + * @param string $state New state. + * @access public + */ function enter($state) { array_push($this->_stack, $state); } - /** - * Leaves the current state and reverts - * to the previous one. - * @return boolean False if we drop off - * the bottom of the list. - * @access public - */ + /** + * Leaves the current state and reverts + * to the previous one. + * @return boolean False if we drop off + * the bottom of the list. + * @access public + */ function leave() { if (count($this->_stack) == 1) { return false; @@ -166,15 +176,15 @@ } } - /** - * Accepts text and breaks it into tokens. - * Some optimisation to make the sure the - * content is only scanned by the PHP regex - * parser once. Lexer modes must not start - * with leading underscores. - * @package SimpleTest - * @subpackage WebTester - */ + /** + * Accepts text and breaks it into tokens. + * Some optimisation to make the sure the + * content is only scanned by the PHP regex + * parser once. Lexer modes must not start + * with leading underscores. + * @package SimpleTest + * @subpackage WebTester + */ class SimpleLexer { var $_regexes; var $_parser; @@ -182,15 +192,15 @@ var $_mode_handlers; var $_case; - /** - * Sets up the lexer in case insensitive matching - * by default. - * @param SimpleSaxParser $parser Handling strategy by - * reference. - * @param string $start Starting handler. - * @param boolean $case True for case sensitive. - * @access public - */ + /** + * Sets up the lexer in case insensitive matching + * by default. + * @param SimpleSaxParser $parser Handling strategy by + * reference. + * @param string $start Starting handler. + * @param boolean $case True for case sensitive. + * @access public + */ function SimpleLexer(&$parser, $start = "accept", $case = false) { $this->_case = $case; $this->_regexes = array(); @@ -199,17 +209,17 @@ $this->_mode_handlers = array($start => $start); } - /** - * Adds a token search pattern for a particular - * parsing mode. The pattern does not change the - * current mode. - * @param string $pattern Perl style regex, but ( and ) - * lose the usual meaning. - * @param string $mode Should only apply this - * pattern when dealing with - * this type of input. - * @access public - */ + /** + * Adds a token search pattern for a particular + * parsing mode. The pattern does not change the + * current mode. + * @param string $pattern Perl style regex, but ( and ) + * lose the usual meaning. + * @param string $mode Should only apply this + * pattern when dealing with + * this type of input. + * @access public + */ function addPattern($pattern, $mode = "accept") { if (! isset($this->_regexes[$mode])) { $this->_regexes[$mode] = new ParallelRegex($this->_case); @@ -220,19 +230,19 @@ } } - /** - * Adds a pattern that will enter a new parsing - * mode. Useful for entering parenthesis, strings, - * tags, etc. - * @param string $pattern Perl style regex, but ( and ) - * lose the usual meaning. - * @param string $mode Should only apply this - * pattern when dealing with - * this type of input. - * @param string $new_mode Change parsing to this new - * nested mode. - * @access public - */ + /** + * Adds a pattern that will enter a new parsing + * mode. Useful for entering parenthesis, strings, + * tags, etc. + * @param string $pattern Perl style regex, but ( and ) + * lose the usual meaning. + * @param string $mode Should only apply this + * pattern when dealing with + * this type of input. + * @param string $new_mode Change parsing to this new + * nested mode. + * @access public + */ function addEntryPattern($pattern, $mode, $new_mode) { if (! isset($this->_regexes[$mode])) { $this->_regexes[$mode] = new ParallelRegex($this->_case); @@ -243,14 +253,14 @@ } } - /** - * Adds a pattern that will exit the current mode - * and re-enter the previous one. - * @param string $pattern Perl style regex, but ( and ) - * lose the usual meaning. - * @param string $mode Mode to leave. - * @access public - */ + /** + * Adds a pattern that will exit the current mode + * and re-enter the previous one. + * @param string $pattern Perl style regex, but ( and ) + * lose the usual meaning. + * @param string $mode Mode to leave. + * @access public + */ function addExitPattern($pattern, $mode) { if (! isset($this->_regexes[$mode])) { $this->_regexes[$mode] = new ParallelRegex($this->_case); @@ -261,18 +271,18 @@ } } - /** - * Adds a pattern that has a special mode. Acts as an entry - * and exit pattern in one go, effectively calling a special - * parser handler for this token only. - * @param string $pattern Perl style regex, but ( and ) - * lose the usual meaning. - * @param string $mode Should only apply this - * pattern when dealing with - * this type of input. - * @param string $special Use this mode for this one token. - * @access public - */ + /** + * Adds a pattern that has a special mode. Acts as an entry + * and exit pattern in one go, effectively calling a special + * parser handler for this token only. + * @param string $pattern Perl style regex, but ( and ) + * lose the usual meaning. + * @param string $mode Should only apply this + * pattern when dealing with + * this type of input. + * @param string $special Use this mode for this one token. + * @access public + */ function addSpecialPattern($pattern, $mode, $special) { if (! isset($this->_regexes[$mode])) { $this->_regexes[$mode] = new ParallelRegex($this->_case); @@ -283,26 +293,26 @@ } } - /** - * Adds a mapping from a mode to another handler. - * @param string $mode Mode to be remapped. - * @param string $handler New target handler. - * @access public - */ + /** + * Adds a mapping from a mode to another handler. + * @param string $mode Mode to be remapped. + * @param string $handler New target handler. + * @access public + */ function mapHandler($mode, $handler) { $this->_mode_handlers[$mode] = $handler; } - /** - * Splits the page text into tokens. Will fail - * if the handlers report an error or if no - * content is consumed. If successful then each - * unparsed and parsed token invokes a call to the - * held listener. - * @param string $raw Raw HTML text. - * @return boolean True on success, else false. - * @access public - */ + /** + * Splits the page text into tokens. Will fail + * if the handlers report an error or if no + * content is consumed. If successful then each + * unparsed and parsed token invokes a call to the + * held listener. + * @param string $raw Raw HTML text. + * @return boolean True on success, else false. + * @access public + */ function parse($raw) { if (! isset($this->_parser)) { return false; @@ -327,18 +337,18 @@ return $this->_invokeParser($raw, LEXER_UNMATCHED); } - /** - * Sends the matched token and any leading unmatched - * text to the parser changing the lexer to a new - * mode if one is listed. - * @param string $unmatched Unmatched leading portion. - * @param string $matched Actual token match. - * @param string $mode Mode after match. A boolean - * false mode causes no change. - * @return boolean False if there was any error - * from the parser. - * @access private - */ + /** + * Sends the matched token and any leading unmatched + * text to the parser changing the lexer to a new + * mode if one is listed. + * @param string $unmatched Unmatched leading portion. + * @param string $matched Actual token match. + * @param string $mode Mode after match. A boolean + * false mode causes no change. + * @return boolean False if there was any error + * from the parser. + * @access private + */ function _dispatchTokens($unmatched, $matched, $mode = false) { if (! $this->_invokeParser($unmatched, LEXER_UNMATCHED)) { return false; @@ -363,50 +373,50 @@ return $this->_invokeParser($matched, LEXER_ENTER); } - /** - * Tests to see if the new mode is actually to leave - * the current mode and pop an item from the matching - * mode stack. - * @param string $mode Mode to test. - * @return boolean True if this is the exit mode. - * @access private - */ + /** + * Tests to see if the new mode is actually to leave + * the current mode and pop an item from the matching + * mode stack. + * @param string $mode Mode to test. + * @return boolean True if this is the exit mode. + * @access private + */ function _isModeEnd($mode) { return ($mode === "__exit"); } - /** - * Test to see if the mode is one where this mode - * is entered for this token only and automatically - * leaves immediately afterwoods. - * @param string $mode Mode to test. - * @return boolean True if this is the exit mode. - * @access private - */ + /** + * Test to see if the mode is one where this mode + * is entered for this token only and automatically + * leaves immediately afterwoods. + * @param string $mode Mode to test. + * @return boolean True if this is the exit mode. + * @access private + */ function _isSpecialMode($mode) { return (strncmp($mode, "_", 1) == 0); } - /** - * Strips the magic underscore marking single token - * modes. - * @param string $mode Mode to decode. - * @return string Underlying mode name. - * @access private - */ + /** + * Strips the magic underscore marking single token + * modes. + * @param string $mode Mode to decode. + * @return string Underlying mode name. + * @access private + */ function _decodeSpecial($mode) { return substr($mode, 1); } - /** - * Calls the parser method named after the current - * mode. Empty content will be ignored. The lexer - * has a parser handler for each mode in the lexer. - * @param string $content Text parsed. - * @param boolean $is_match Token is recognised rather - * than unparsed data. - * @access private - */ + /** + * Calls the parser method named after the current + * mode. Empty content will be ignored. The lexer + * has a parser handler for each mode in the lexer. + * @param string $content Text parsed. + * @param boolean $is_match Token is recognised rather + * than unparsed data. + * @access private + */ function _invokeParser($content, $is_match) { if (($content === '') || ($content === false)) { return true; @@ -415,20 +425,20 @@ return $this->_parser->$handler($content, $is_match); } - /** - * Tries to match a chunk of text and if successful - * removes the recognised chunk and any leading - * unparsed data. Empty strings will not be matched. - * @param string $raw The subject to parse. This is the - * content that will be eaten. - * @return array/boolean Three item list of unparsed - * content followed by the - * recognised token and finally the - * action the parser is to take. - * True if no match, false if there - * is a parsing error. - * @access private - */ + /** + * Tries to match a chunk of text and if successful + * removes the recognised chunk and any leading + * unparsed data. Empty strings will not be matched. + * @param string $raw The subject to parse. This is the + * content that will be eaten. + * @return array/boolean Three item list of unparsed + * content followed by the + * recognised token and finally the + * action the parser is to take. + * True if no match, false if there + * is a parsing error. + * @access private + */ function _reduce($raw) { if ($action = $this->_regexes[$this->_mode->getCurrent()]->match($raw, $match)) { $unparsed_character_count = strpos($raw, $match); @@ -440,11 +450,11 @@ } } - /** - * Converts HTML tokens into selected SAX events. - * @package SimpleTest - * @subpackage WebTester - */ + /** + * Converts HTML tokens into selected SAX events. + * @package SimpleTest + * @subpackage WebTester + */ class SimpleSaxParser { var $_lexer; var $_listener; @@ -452,11 +462,11 @@ var $_attributes; var $_current_attribute; - /** - * Sets the listener. - * @param SimpleSaxListener $listener SAX event handler. - * @access public - */ + /** + * Sets the listener. + * @param SimpleSaxListener $listener SAX event handler. + * @access public + */ function SimpleSaxParser(&$listener) { $this->_listener = &$listener; $this->_lexer = &$this->createLexer($this); @@ -465,24 +475,24 @@ $this->_current_attribute = ''; } - /** - * Runs the content through the lexer which - * should call back to the acceptors. - * @param string $raw Page text to parse. - * @return boolean False if parse error. - * @access public - */ + /** + * Runs the content through the lexer which + * should call back to the acceptors. + * @param string $raw Page text to parse. + * @return boolean False if parse error. + * @access public + */ function parse($raw) { return $this->_lexer->parse($raw); } - /** - * Sets up the matching lexer. Starts in 'text' mode. - * @param SimpleSaxParser $parser Event generator, usually $self. - * @return SimpleLexer Lexer suitable for this parser. - * @access public - * @static - */ + /** + * Sets up the matching lexer. Starts in 'text' mode. + * @param SimpleSaxParser $parser Event generator, usually $self. + * @return SimpleLexer Lexer suitable for this parser. + * @access public + * @static + */ function &createLexer(&$parser) { $lexer = &new SimpleLexer($parser, 'text'); $lexer->mapHandler('text', 'acceptTextToken'); @@ -494,23 +504,23 @@ return $lexer; } - /** - * List of parsed tags. Others are ignored. - * @return array List of searched for tags. - * @access private - */ + /** + * List of parsed tags. Others are ignored. + * @return array List of searched for tags. + * @access private + */ function _getParsedTags() { return array('a', 'title', 'form', 'input', 'button', 'textarea', 'select', - 'option', 'frameset', 'frame'); + 'option', 'frameset', 'frame', 'label'); } - /** - * The lexer has to skip certain sections such - * as server code, client code and styles. - * @param SimpleLexer $lexer Lexer to add patterns to. - * @access private - * @static - */ + /** + * The lexer has to skip certain sections such + * as server code, client code and styles. + * @param SimpleLexer $lexer Lexer to add patterns to. + * @access private + * @static + */ function _addSkipping(&$lexer) { $lexer->mapHandler('css', 'ignore'); $lexer->addEntryPattern('