diff --git a/vendors/simpletest/CAKE_README.txt b/vendors/simpletest/CAKE_README.txt new file mode 100644 index 000000000..ef07a666c --- /dev/null +++ b/vendors/simpletest/CAKE_README.txt @@ -0,0 +1,7 @@ +SimpleTest is the testing suite we have decided to use for using Test Driven Development in the Cake core. + +More information can be found here: http://www.lastcraft.com/simple_test.php + +Note this code is not developed by the Developers of Cake. +We will update this vendors package as new releases become available +Current release is 1.0.1alpha \ No newline at end of file diff --git a/vendors/simpletest/HELP_MY_TESTS_DONT_WORK_ANYMORE.txt b/vendors/simpletest/HELP_MY_TESTS_DONT_WORK_ANYMORE.txt index 99c3be2d5..132fd682c 100644 --- a/vendors/simpletest/HELP_MY_TESTS_DONT_WORK_ANYMORE.txt +++ b/vendors/simpletest/HELP_MY_TESTS_DONT_WORK_ANYMORE.txt @@ -1,201 +1,241 @@ -Simple Test interface changes -============================= -Because the SimpleTest tool set is still evolving it is likely that tests -written with earlier versions will fail with the newest ones. The most -dramatic changes are in the alpha releases. Here is a list of possible -problems... - -No HTML when matching page elements ------------------------------------ -This behaviour has been switched to using plain text as if it -were seen by the user of the browser. This means that HTML tags -are suppressed, entities are converted and whitespace is -normalised. This should make it easier to match items in forms. -Also images are replaced with their "alt" text so that they -can be matched as well. - -No method SimpleRunner::_getTestCase() --------------------------------------- -This was made public as getTestCase() in 1.0RC2. - -No method restartSession() --------------------------- -This was renamed to restart() in the WebTestCase, SimpleBrowser -and the underlying SimpleUserAgent in 1.0RC2. Because it was -undocumented anyway, no attempt was made at backward -compatibility. - -My custom test case ignored by tally() --------------------------------------- -The _assertTrue method has had it's signature changed due to a bug -in the PHP 5.0.1 release. You must now use getTest() from within -that method to get the test case. - -Broken code extending SimpleRunner ----------------------------------- -This was replaced with SimpleScorer so that I could use the runner -name in another class. This happened in RC1 development and there -is no easy backward compatibility fix. The solution is simply to -extend SimpleScorer instead. - -Missing method getBaseCookieValue() ------------------------------------ -This was renamed getCurrentCookieValue() in RC1. - -Missing files from the SimpleTest suite ---------------------------------------- -Versions of SimpleTest prior to Beta6 required a SIMPLE_TEST constant -to point at the SimpleTest folder location before any of the toolset -was loaded. This is no longer documented as it is now unnecessary -for later versions. If you are using an earlier version you may -need this constant. Consult the documentation that was bundled with -the release that you are using or upgrade to Beta6 or later. - -No method SimpleBrowser::getCurrentUrl() --------------------------------------- -This is replaced with the more versatile showRequest() for -debugging. It only existed in this context for version Beta5. -Later versions will have SimpleBrowser::getHistory() for tracking -paths through pages. It is renamed as getUrl() since 1.0RC1. - -No method Stub::setStubBaseClass() ----------------------------------- -This method has finally been removed in 1.0RC1. Use -SimpleTestOptions::setStubBaseClass() instead. - -No class CommandLineReporter ----------------------------- -This was renamed to TextReporter in Beta3 and the deprecated version -was removed in 1.0RC1. - -No method requireReturn() -------------------------- -This was deprecated in Beta3 and is now removed. - -No method expectCookie() ------------------------- -This method was abruptly removed in Beta4 so as to simplify the internals -until another mechanism can replace it. As a workaround it is necessary -to assert that the cookie has changed by setting it before the page -fetch and then assert the desired value. - -No method clickSubmitByFormId() -------------------------------- -This method had an incorrect name as no button was involved. It was -renamed to submitByFormId() in Beta4 and the old version deprecated. -Now removed. - -No method paintStart() or paintEnd() ------------------------------------- -You should only get this error if you have subclassed the lower level -reporting and test runner machinery. These methods have been broken -down into events for test methods, events for test cases and events -for group tests. The new methods are... - -paintStart() --> paintMethodStart(), paintCaseStart(), paintGroupStart() -paintEnd() --> paintMethodEnd(), paintCaseEnd(), paintGroupEnd() - -This change was made in Beta3, ironically to make it easier to subclass -the inner machinery. Simply duplicating the code you had in the previous -methods should provide a temporary fix. - -No class TestDisplay --------------------- -This has been folded into SimpleReporter in Beta3 and is now deprecated. -It was removed in RC1. - -No method WebTestCase::fetch() ------------------------------- -This was renamed get() in Alpha8. It is removed in Beta3. - -No method submit() ------------------- -This has been renamed clickSubmit() in Beta1. The old method was -removed in Beta2. - -No method clearHistory() ------------------------- -This method is deprecated in Beta2 and removed in RC1. - -No method getCallCount() ------------------------- -This method has been deprecated since Beta1 and has now been -removed. There are now more ways to set expectations on counts -and so this method should be unecessery. Removed in RC1. - -Cannot find file * ------------------- -The following public name changes have occoured... - -simple_html_test.php --> reporter.php -simple_mock.php --> mock_objects.php -simple_unit.php --> unit_tester.php -simple_web.php --> web_tester.php - -The old names were deprecated in Alpha8 and removed in Beta1. - -No method attachObserver() --------------------------- -Prior to the Alpha8 release the old internal observer pattern was -gutted and replaced with a visitor. This is to trade flexibility of -test case expansion against the ease of writing user interfaces. - -Code such as... - -$test = &new MyTestCase(); -$test->attachObserver(new TestHtmlDisplay()); -$test->run(); - -...should be rewritten as... - -$test = &new MyTestCase(); -$test->run(new HtmlReporter()); - -If you previously attached multiple observers then the workaround -is to run the tests twice, once with each, until they can be combined. -For one observer the old method is simulated in Alpha 8, but is -removed in Beta1. - -No class TestHtmlDisplay ------------------------- -This class has been renamed to HtmlReporter in Alpha8. It is supported, -but deprecated in Beta1 and removed in Beta2. If you have subclassed -the display for your own design, then you will have to extend this -class (HtmlReporter) instead. - -If you have accessed the event queue by overriding the notify() method -then I am afraid you are in big trouble :(. The reporter is now -carried around the test suite by the runner classes and the methods -called directly. In the unlikely event that this is a problem and -you don't want to upgrade the test tool then simplest is to write your -own runner class and invoke the tests with... - -$test->accept(new MyRunner(new MyReporter())); - -...rather than the run method. This should be easier to extend -anyway and gives much more control. Even this method is overhauled -in Beta3 where the runner class can be set within the test case. Really -the best thing to do is to upgrade to this version as whatever you were -trying to achieve before should now be very much easier. - -Missing set options method --------------------------- -All test suite options are now in one class called SimpleTestOptions. -This means that options are set differently... - -GroupTest::ignore() --> SimpleTestOptions::ignore() -Mock::setMockBaseClass() --> SimpleTestOptions::setMockBaseClass() - -These changed in Alpha8 and the old versions are now removed in RC1. - -No method setExpected*() ------------------------- -The mock expectations changed their names in Alpha4 and the old names -ceased to be supported in Alpha8. The changes are... - -setExpectedArguments() --> expectArguments() -setExpectedArgumentsSequence() --> expectArgumentsAt() -setExpectedCallCount() --> expectCallCount() -setMaximumCallCount() --> expectMaximumCallCount() - -The parameters remained the same. +Simple Test interface changes +============================= +Because the SimpleTest tool set is still evolving it is likely that tests +written with earlier versions will fail with the newest ones. The most +dramatic changes are in the alpha releases. Here is a list of possible +problems and their fixes... + +No class WantedPatternExpectation +--------------------------------- +This was deprecated in 1.0.1alpha in favour of the simpler +name PatternExpectation. + +No class NoUnwantedPatternExpectation +------------------------------------- +This was deprecated in 1.0.1alpha in favour of the simpler +name NoPatternExpectation. + +No method assertNoUnwantedPattern() +----------------------------------- +This has been renamed to assertNoPattern() in 1.0.1alpha and +the old form is deprecated. + +No method assertWantedPattern() +------------------------------- +This has been renamed to assertPattern() in 1.0.1alpha and +the old form is deprecated. + +No method assertExpectation() +----------------------------- +This was renamed as assert() in 1.0.1alpha and the old form +has been deprecated. + +No class WildcardExpectation +---------------------------- +This was a mostly internal class for the mock objects. It was +renamed AnythingExpectation to bring it closer to JMock and +NMock in version 1.0.1alpha. + +Missing UnitTestCase::assertErrorPattern() +------------------------------------------ +This method is deprecated for version 1.0.1 onwards. +This method has been subsumed by assertError() that can now +take an expectation. Simply pass a PatternExpectation +into assertError() to simulate the old behaviour. + +No HTML when matching page elements +----------------------------------- +This behaviour has been switched to using plain text as if it +were seen by the user of the browser. This means that HTML tags +are suppressed, entities are converted and whitespace is +normalised. This should make it easier to match items in forms. +Also images are replaced with their "alt" text so that they +can be matched as well. + +No method SimpleRunner::_getTestCase() +-------------------------------------- +This was made public as getTestCase() in 1.0RC2. + +No method restartSession() +-------------------------- +This was renamed to restart() in the WebTestCase, SimpleBrowser +and the underlying SimpleUserAgent in 1.0RC2. Because it was +undocumented anyway, no attempt was made at backward +compatibility. + +My custom test case ignored by tally() +-------------------------------------- +The _assertTrue method has had it's signature changed due to a bug +in the PHP 5.0.1 release. You must now use getTest() from within +that method to get the test case. Mock compatibility with other +unit testers is now deprecated as of 1.0.1alpha as PEAR::PHUnit2 +should soon have mock support of it's own. + +Broken code extending SimpleRunner +---------------------------------- +This was replaced with SimpleScorer so that I could use the runner +name in another class. This happened in RC1 development and there +is no easy backward compatibility fix. The solution is simply to +extend SimpleScorer instead. + +Missing method getBaseCookieValue() +----------------------------------- +This was renamed getCurrentCookieValue() in RC1. + +Missing files from the SimpleTest suite +--------------------------------------- +Versions of SimpleTest prior to Beta6 required a SIMPLE_TEST constant +to point at the SimpleTest folder location before any of the toolset +was loaded. This is no longer documented as it is now unnecessary +for later versions. If you are using an earlier version you may +need this constant. Consult the documentation that was bundled with +the release that you are using or upgrade to Beta6 or later. + +No method SimpleBrowser::getCurrentUrl() +-------------------------------------- +This is replaced with the more versatile showRequest() for +debugging. It only existed in this context for version Beta5. +Later versions will have SimpleBrowser::getHistory() for tracking +paths through pages. It is renamed as getUrl() since 1.0RC1. + +No method Stub::setStubBaseClass() +---------------------------------- +This method has finally been removed in 1.0RC1. Use +SimpleTestOptions::setStubBaseClass() instead. + +No class CommandLineReporter +---------------------------- +This was renamed to TextReporter in Beta3 and the deprecated version +was removed in 1.0RC1. + +No method requireReturn() +------------------------- +This was deprecated in Beta3 and is now removed. + +No method expectCookie() +------------------------ +This method was abruptly removed in Beta4 so as to simplify the internals +until another mechanism can replace it. As a workaround it is necessary +to assert that the cookie has changed by setting it before the page +fetch and then assert the desired value. + +No method clickSubmitByFormId() +------------------------------- +This method had an incorrect name as no button was involved. It was +renamed to submitByFormId() in Beta4 and the old version deprecated. +Now removed. + +No method paintStart() or paintEnd() +------------------------------------ +You should only get this error if you have subclassed the lower level +reporting and test runner machinery. These methods have been broken +down into events for test methods, events for test cases and events +for group tests. The new methods are... + +paintStart() --> paintMethodStart(), paintCaseStart(), paintGroupStart() +paintEnd() --> paintMethodEnd(), paintCaseEnd(), paintGroupEnd() + +This change was made in Beta3, ironically to make it easier to subclass +the inner machinery. Simply duplicating the code you had in the previous +methods should provide a temporary fix. + +No class TestDisplay +-------------------- +This has been folded into SimpleReporter in Beta3 and is now deprecated. +It was removed in RC1. + +No method WebTestCase::fetch() +------------------------------ +This was renamed get() in Alpha8. It is removed in Beta3. + +No method submit() +------------------ +This has been renamed clickSubmit() in Beta1. The old method was +removed in Beta2. + +No method clearHistory() +------------------------ +This method is deprecated in Beta2 and removed in RC1. + +No method getCallCount() +------------------------ +This method has been deprecated since Beta1 and has now been +removed. There are now more ways to set expectations on counts +and so this method should be unecessery. Removed in RC1. + +Cannot find file * +------------------ +The following public name changes have occoured... + +simple_html_test.php --> reporter.php +simple_mock.php --> mock_objects.php +simple_unit.php --> unit_tester.php +simple_web.php --> web_tester.php + +The old names were deprecated in Alpha8 and removed in Beta1. + +No method attachObserver() +-------------------------- +Prior to the Alpha8 release the old internal observer pattern was +gutted and replaced with a visitor. This is to trade flexibility of +test case expansion against the ease of writing user interfaces. + +Code such as... + +$test = &new MyTestCase(); +$test->attachObserver(new TestHtmlDisplay()); +$test->run(); + +...should be rewritten as... + +$test = &new MyTestCase(); +$test->run(new HtmlReporter()); + +If you previously attached multiple observers then the workaround +is to run the tests twice, once with each, until they can be combined. +For one observer the old method is simulated in Alpha 8, but is +removed in Beta1. + +No class TestHtmlDisplay +------------------------ +This class has been renamed to HtmlReporter in Alpha8. It is supported, +but deprecated in Beta1 and removed in Beta2. If you have subclassed +the display for your own design, then you will have to extend this +class (HtmlReporter) instead. + +If you have accessed the event queue by overriding the notify() method +then I am afraid you are in big trouble :(. The reporter is now +carried around the test suite by the runner classes and the methods +called directly. In the unlikely event that this is a problem and +you don't want to upgrade the test tool then simplest is to write your +own runner class and invoke the tests with... + +$test->accept(new MyRunner(new MyReporter())); + +...rather than the run method. This should be easier to extend +anyway and gives much more control. Even this method is overhauled +in Beta3 where the runner class can be set within the test case. Really +the best thing to do is to upgrade to this version as whatever you were +trying to achieve before should now be very much easier. + +Missing set options method +-------------------------- +All test suite options are now in one class called SimpleTestOptions. +This means that options are set differently... + +GroupTest::ignore() --> SimpleTestOptions::ignore() +Mock::setMockBaseClass() --> SimpleTestOptions::setMockBaseClass() + +These changed in Alpha8 and the old versions are now removed in RC1. + +No method setExpected*() +------------------------ +The mock expectations changed their names in Alpha4 and the old names +ceased to be supported in Alpha8. The changes are... + +setExpectedArguments() --> expectArguments() +setExpectedArgumentsSequence() --> expectArgumentsAt() +setExpectedCallCount() --> expectCallCount() +setMaximumCallCount() --> expectMaximumCallCount() + +The parameters remained the same. \ No newline at end of file diff --git a/vendors/simpletest/LICENSE.txt b/vendors/simpletest/LICENSE.txt index 65c8cf307..8c0225646 100644 --- a/vendors/simpletest/LICENSE.txt +++ b/vendors/simpletest/LICENSE.txt @@ -18,10 +18,10 @@ If you find a bug in one of the standards mode test cases, please let us know so Definitions: - * "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. - * "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder. - * "Copyright Holder" is whoever is named in the copyright or copyrights for the package. "You" is you, if you're thinking about copying or distributing this Package. - * "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) + * "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. + * "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder. + * "Copyright Holder" is whoever is named in the copyright or copyrights for the package. "You" is you, if you're thinking about copying or distributing this Package. + * "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) * "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. @@ -46,4 +46,4 @@ accompany any non-standard executables and testcases with their corresponding St 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. -The End +The End \ No newline at end of file diff --git a/vendors/simpletest/README.txt b/vendors/simpletest/README.txt index 50fa4aaac..f8ab2cd99 100644 --- a/vendors/simpletest/README.txt +++ b/vendors/simpletest/README.txt @@ -107,4 +107,4 @@ Feucks. Early adopters are always an inspiration. yours Marcus Baker, Jason Sweat and Perrick Penet. -- -marcus@lastcraft.com +marcus@lastcraft.com \ No newline at end of file diff --git a/vendors/simpletest/VERSION.txt b/vendors/simpletest/VERSION.txt index d3827e75a..5f6886693 100644 --- a/vendors/simpletest/VERSION.txt +++ b/vendors/simpletest/VERSION.txt @@ -1 +1 @@ -1.0 +1.0.1alpha \ No newline at end of file diff --git a/vendors/simpletest/authentication.php b/vendors/simpletest/authentication.php index f759395be..98fe4118d 100644 --- a/vendors/simpletest/authentication.php +++ b/vendors/simpletest/authentication.php @@ -1,34 +1,34 @@ _type = $type; $this->_root = $url->getBasePath(); @@ -36,22 +36,22 @@ $this->_password = false; } - /** - * Adds another location to the realm. - * @param SimpleUrl $url Somewhere in realm. - * @access public - */ + /** + * Adds another location to the realm. + * @param SimpleUrl $url Somewhere in realm. + * @access public + */ function stretch($url) { $this->_root = $this->_getCommonPath($this->_root, $url->getPath()); } - /** - * Finds the common starting path. - * @param string $first Path to compare. - * @param string $second Path to compare. - * @return string Common directories. - * @access private - */ + /** + * Finds the common starting path. + * @param string $first Path to compare. + * @param string $second Path to compare. + * @return string Common directories. + * @access private + */ function _getCommonPath($first, $second) { $first = explode('/', $first); $second = explode('/', $second); @@ -63,112 +63,131 @@ return implode('/', $first) . '/'; } - /** - * Sets the identity to try within this realm. - * @param string $username Username in authentication dialog. - * @param string $username Password in authentication dialog. - * @access public - */ + /** + * Sets the identity to try within this realm. + * @param string $username Username in authentication dialog. + * @param string $username Password in authentication dialog. + * @access public + */ function setIdentity($username, $password) { $this->_username = $username; $this->_password = $password; } - /** - * Accessor for current identity. - * @return string Last succesful username. - * @access public - */ + /** + * Accessor for current identity. + * @return string Last succesful username. + * @access public + */ function getUsername() { return $this->_username; } - /** - * Accessor for current identity. - * @return string Last succesful password. - * @access public - */ + /** + * Accessor for current identity. + * @return string Last succesful password. + * @access public + */ function getPassword() { return $this->_password; } - /** - * Test to see if the URL is within the directory - * tree of the realm. - * @param SimpleUrl $url URL to test. - * @return boolean True if subpath. - * @access public - */ + /** + * Test to see if the URL is within the directory + * tree of the realm. + * @param SimpleUrl $url URL to test. + * @return boolean True if subpath. + * @access public + */ function isWithin($url) { - return (strpos($url->getBasePath(), $this->_root) === 0); + if ($this->_isIn($this->_root, $url->getBasePath())) { + return true; + } + if ($this->_isIn($this->_root, $url->getBasePath() . $url->getPage() . '/')) { + return true; + } + return false; + } + + /** + * Tests to see if one string is a substring of + * another. + * @param string $part Small bit. + * @param string $whole Big bit. + * @return boolean True if the small bit is + * in the big bit. + * @access private + */ + function _isIn($part, $whole) { + return strpos($whole, $part) === 0; } } - /** - * Manages security realms. - * @package SimpleTest - * @subpackage WebTester - */ + /** + * Manages security realms. + * @package SimpleTest + * @subpackage WebTester + */ class SimpleAuthenticator { var $_realms; - /** - * Clears the realms. - * @access public - */ + /** + * Clears the realms. + * @access public + */ function SimpleAuthenticator() { $this->restartSession(); } - /** - * Starts with no realms set up. - * @access public - */ + /** + * Starts with no realms set up. + * @access public + */ function restartSession() { $this->_realms = array(); } - /** - * Adds a new realm centered the current URL. - * Browsers vary wildly on their behaviour in this - * regard. Mozilla ignores the realm and presents - * only when challenged, wasting bandwidth. IE - * just carries on presenting until a new challenge - * occours. SimpleTest tries to follow the spirit of - * the original standards committee and treats the - * base URL as the root of a file tree shaped realm. - * @param SimpleUrl $url Base of realm. - * @param string $type Authentication type for this - * realm. Only Basic authentication - * is currently supported. - * @param string $realm Name of realm. - * @access public - */ + /** + * Adds a new realm centered the current URL. + * Browsers vary wildly on their behaviour in this + * regard. Mozilla ignores the realm and presents + * only when challenged, wasting bandwidth. IE + * just carries on presenting until a new challenge + * occours. SimpleTest tries to follow the spirit of + * the original standards committee and treats the + * base URL as the root of a file tree shaped realm. + * @param SimpleUrl $url Base of realm. + * @param string $type Authentication type for this + * realm. Only Basic authentication + * is currently supported. + * @param string $realm Name of realm. + * @access public + */ function addRealm($url, $type, $realm) { $this->_realms[$url->getHost()][$realm] = new SimpleRealm($type, $url); } - /** - * Sets the current identity to be presented - * against that realm. - * @param string $host Server hosting realm. - * @param string $realm Name of realm. - * @param string $username Username for realm. - * @param string $password Password for realm. - * @access public - */ + /** + * Sets the current identity to be presented + * against that realm. + * @param string $host Server hosting realm. + * @param string $realm Name of realm. + * @param string $username Username for realm. + * @param string $password Password for realm. + * @access public + */ function setIdentityForRealm($host, $realm, $username, $password) { if (isset($this->_realms[$host][$realm])) { $this->_realms[$host][$realm]->setIdentity($username, $password); } } - /** - * Finds the name of the realm by comparing URLs. - * @param SimpleUrl $url URL to test. - * @return SimpleRealm Name of realm. - * @access private - */ + /** + * Finds the name of the realm by comparing URLs. + * @param SimpleUrl $url URL to test. + * @return SimpleRealm Name of realm. + * @access private + */ function _findRealmFromUrl($url) { if (! isset($this->_realms[$url->getHost()])) { return false; @@ -181,12 +200,12 @@ return false; } - /** - * Presents the appropriate headers for this location. - * @param SimpleHttpRequest $request Request to modify. - * @param SimpleUrl $url Base of realm. - * @access public - */ + /** + * Presents the appropriate headers for this location. + * @param SimpleHttpRequest $request Request to modify. + * @param SimpleUrl $url Base of realm. + * @access public + */ function addHeaders(&$request, $url) { if ($url->getUsername() && $url->getPassword()) { $username = $url->getUsername(); @@ -200,15 +219,15 @@ $this->addBasicHeaders($request, $username, $password); } - /** - * Presents the appropriate headers for this - * location for basic authentication. - * @param SimpleHttpRequest $request Request to modify. - * @param string $username Username for realm. - * @param string $password Password for realm. - * @access public - * @static - */ + /** + * Presents the appropriate headers for this + * location for basic authentication. + * @param SimpleHttpRequest $request Request to modify. + * @param string $username Username for realm. + * @param string $password Password for realm. + * @access public + * @static + */ function addBasicHeaders(&$request, $username, $password) { if ($username && $password) { $request->addHeaderLine( diff --git a/vendors/simpletest/browser.php b/vendors/simpletest/browser.php index 24247688d..ea341b318 100644 --- a/vendors/simpletest/browser.php +++ b/vendors/simpletest/browser.php @@ -1,104 +1,92 @@ _sequence = array(); $this->_position = -1; } - /** - * Test for no entries yet. - * @return boolean True if empty. - * @access private - */ + /** + * Test for no entries yet. + * @return boolean True if empty. + * @access private + */ function _isEmpty() { return ($this->_position == -1); } - /** - * Test for being at the beginning. - * @return boolean True if first. - * @access private - */ + /** + * Test for being at the beginning. + * @return boolean True if first. + * @access private + */ function _atBeginning() { return ($this->_position == 0) && ! $this->_isEmpty(); } - /** - * Test for being at the last entry. - * @return boolean True if last. - * @access private - */ + /** + * Test for being at the last entry. + * @return boolean True if last. + * @access private + */ function _atEnd() { return ($this->_position + 1 >= count($this->_sequence)) && ! $this->_isEmpty(); } - /** - * Adds a successfully fetched page to the history. - * @param string $method GET or POST. - * @param SimpleUrl $url URL of fetch. - * @param SimpleFormEncoding $parameters Any post data with the fetch. - * @access public - */ - function recordEntry($method, $url, $parameters) { + /** + * Adds a successfully fetched page to the history. + * @param SimpleUrl $url URL of fetch. + * @param SimpleEncoding $parameters Any post data with the fetch. + * @access public + */ + function recordEntry($url, $parameters) { $this->_dropFuture(); array_push( $this->_sequence, - array('method' => $method, 'url' => $url, 'parameters' => $parameters)); + array('url' => $url, 'parameters' => $parameters)); $this->_position++; } - /** - * Last fetching method for current history - * position. - * @return string GET or POST for this point in - * the history. - * @access public - */ - function getMethod() { - if ($this->_isEmpty()) { - return false; - } - return $this->_sequence[$this->_position]['method']; - } - - /** - * Last fully qualified URL for current history - * position. - * @return SimpleUrl URL for this position. - * @access public - */ + /** + * Last fully qualified URL for current history + * position. + * @return SimpleUrl URL for this position. + * @access public + */ function getUrl() { if ($this->_isEmpty()) { return false; @@ -106,12 +94,12 @@ return $this->_sequence[$this->_position]['url']; } - /** - * Parameters of last fetch from current history - * position. - * @return SimpleFormEncoding Post parameters. - * @access public - */ + /** + * Parameters of last fetch from current history + * position. + * @return SimpleFormEncoding Post parameters. + * @access public + */ function getParameters() { if ($this->_isEmpty()) { return false; @@ -119,12 +107,12 @@ return $this->_sequence[$this->_position]['parameters']; } - /** - * Step back one place in the history. Stops at - * the first page. - * @return boolean True if any previous entries. - * @access public - */ + /** + * Step back one place in the history. Stops at + * the first page. + * @return boolean True if any previous entries. + * @access public + */ function back() { if ($this->_isEmpty() || $this->_atBeginning()) { return false; @@ -133,12 +121,12 @@ return true; } - /** - * Step forward one place. If already at the - * latest entry then nothing will happen. - * @return boolean True if any future entries. - * @access public - */ + /** + * Step forward one place. If already at the + * latest entry then nothing will happen. + * @return boolean True if any future entries. + * @access public + */ function forward() { if ($this->_isEmpty() || $this->_atEnd()) { return false; @@ -147,11 +135,11 @@ return true; } - /** - * Ditches all future entries beyond the current - * point. - * @access private - */ + /** + * Ditches all future entries beyond the current + * point. + * @access private + */ function _dropFuture() { if ($this->_isEmpty()) { return; @@ -162,13 +150,13 @@ } } - /** - * Simulated web browser. This is an aggregate of - * the user agent, the HTML parsing, request history - * and the last header set. - * @package SimpleTest - * @subpackage WebTester - */ + /** + * Simulated web browser. This is an aggregate of + * the user agent, the HTML parsing, request history + * and the last header set. + * @package SimpleTest + * @subpackage WebTester + */ class SimpleBrowser { var $_user_agent; var $_page; @@ -176,13 +164,13 @@ var $_ignore_frames; var $_maximum_nested_frames; - /** - * Starts with a fresh browser with no - * cookie or any other state information. The - * exception is that a default proxy will be - * set up if specified in the options. - * @access public - */ + /** + * Starts with a fresh browser with no + * cookie or any other state information. The + * exception is that a default proxy will be + * set up if specified in the options. + * @access public + */ function SimpleBrowser() { $this->_user_agent = &$this->_createUserAgent(); $this->_user_agent->useProxy( @@ -195,50 +183,52 @@ $this->_maximum_nested_frames = DEFAULT_MAX_NESTED_FRAMES; } - /** - * Creates the underlying user agent. - * @return SimpleFetcher Content fetcher. - * @access protected - */ + /** + * Creates the underlying user agent. + * @return SimpleFetcher Content fetcher. + * @access protected + */ function &_createUserAgent() { - return new SimpleUserAgent(); + $user_agent = &new SimpleUserAgent(); + return $user_agent; } - /** - * Creates a new empty history list. - * @return SimpleBrowserHistory New list. - * @access protected - */ + /** + * Creates a new empty history list. + * @return SimpleBrowserHistory New list. + * @access protected + */ function &_createHistory() { - return new SimpleBrowserHistory(); + $history = &new SimpleBrowserHistory(); + return $history; } - /** - * Disables frames support. Frames will not be fetched - * and the frameset page will be used instead. - * @access public - */ + /** + * Disables frames support. Frames will not be fetched + * and the frameset page will be used instead. + * @access public + */ function ignoreFrames() { $this->_ignore_frames = true; } - /** - * Enables frames support. Frames will be fetched from - * now on. - * @access public - */ + /** + * Enables frames support. Frames will be fetched from + * now on. + * @access public + */ function useFrames() { $this->_ignore_frames = false; } - /** - * Parses the raw content into a page. Will load further - * frame pages unless frames are disabled. - * @param SimpleHttpResponse $response Response from fetch. - * @param integer $depth Nested frameset depth. - * @return SimplePage Parsed HTML. - * @access protected - */ + /** + * Parses the raw content into a page. Will load further + * frame pages unless frames are disabled. + * @param SimpleHttpResponse $response Response from fetch. + * @param integer $depth Nested frameset depth. + * @return SimplePage Parsed HTML. + * @access protected + */ function &_parse($response, $depth = 0) { $builder = &new SimplePageBuilder(); $page = &$builder->parse($response); @@ -247,293 +237,275 @@ } $frameset = &new SimpleFrameset($page); foreach ($page->getFrameset() as $key => $url) { - $frame = &$this->_fetch('GET', $url, array(), $depth + 1); + $frame = &$this->_fetch($url, new SimpleGetEncoding(), $depth + 1); $frameset->addFrame($frame, $key); } return $frameset; } - /** - * Fetches a page. - * @param string $method GET or POST. - * @param string/SimpleUrl $url Target to fetch as string. - * @param SimpleFormEncoding $parameters POST parameters. - * @param integer $depth Nested frameset depth protection. - * @return SimplePage Parsed page. - * @access private - */ - function &_fetch($method, $url, $parameters, $depth = 0) { - $response = &$this->_user_agent->fetchResponse($method, $url, $parameters); + /** + * Fetches a page. + * @param string/SimpleUrl $url Target to fetch. + * @param SimpleEncoding $encoding GET/POST parameters. + * @param integer $depth Nested frameset depth protection. + * @return SimplePage Parsed page. + * @access private + */ + function &_fetch($url, $encoding, $depth = 0) { + $response = &$this->_user_agent->fetchResponse($url, $encoding); if ($response->isError()) { - return new SimplePage($response); + $page = &new SimplePage($response); + } else { + $page = &$this->_parse($response, $depth); } - return $this->_parse($response, $depth); + return $page; } - /** - * Fetches a page or a single frame if that is the current - * focus. - * @param string $method GET or POST. - * @param string/SimpleUrl $url Target to fetch as string. - * @param SimpleFormEncoding $parameters POST parameters. - * @return string Raw content of page. - * @access private - */ - function _load($method, $url, $parameters = false) { + /** + * Fetches a page or a single frame if that is the current + * focus. + * @param SimpleUrl $url Target to fetch. + * @param SimpleEncoding $parameters GET/POST parameters. + * @return string Raw content of page. + * @access private + */ + function _load($url, $parameters) { $frame = $url->getTarget(); if (! $frame || ! $this->_page->hasFrames() || (strtolower($frame) == '_top')) { - return $this->_loadPage($method, $url, $parameters); + return $this->_loadPage($url, $parameters); } - return $this->_loadFrame(array($frame), $method, $url, $parameters); + return $this->_loadFrame(array($frame), $url, $parameters); } - /** - * Fetches a page and makes it the current page/frame. - * @param string $method GET or POST. - * @param string/SimpleUrl $url Target to fetch as string. - * @param SimpleFormEncoding $parameters POST parameters. - * @return string Raw content of page. - * @access private - */ - function _loadPage($method, $url, $parameters = false) { - $this->_page = &$this->_fetch(strtoupper($method), $url, $parameters); + /** + * Fetches a page and makes it the current page/frame. + * @param string/SimpleUrl $url Target to fetch as string. + * @param SimplePostEncoding $parameters POST parameters. + * @return string Raw content of page. + * @access private + */ + function _loadPage($url, $parameters) { + $this->_page = &$this->_fetch($url, $parameters); $this->_history->recordEntry( - $this->_page->getMethod(), $this->_page->getUrl(), $this->_page->getRequestData()); return $this->_page->getRaw(); } - /** - * Fetches a frame into the existing frameset replacing the - * original. - * @param array $frames List of names to drill down. - * @param string $method GET or POST. - * @param string/SimpleUrl $url Target to fetch as string. - * @param SimpleFormEncoding $parameters POST parameters. - * @return string Raw content of page. - * @access private - */ - function _loadFrame($frames, $method, $url, $parameters = false) { - $page = &$this->_fetch(strtoupper($method), $url, $parameters); + /** + * Fetches a frame into the existing frameset replacing the + * original. + * @param array $frames List of names to drill down. + * @param string/SimpleUrl $url Target to fetch as string. + * @param SimpleFormEncoding $parameters POST parameters. + * @return string Raw content of page. + * @access private + */ + function _loadFrame($frames, $url, $parameters) { + $page = &$this->_fetch($url, $parameters); $this->_page->setFrame($frames, $page); } - /** - * Removes expired and temporary cookies as if - * the browser was closed and re-opened. - * @param string/integer $date Time when session restarted. - * If omitted then all persistent - * cookies are kept. - * @access public - */ + /** + * Removes expired and temporary cookies as if + * the browser was closed and re-opened. + * @param string/integer $date Time when session restarted. + * If omitted then all persistent + * cookies are kept. + * @access public + */ function restart($date = false) { $this->_user_agent->restart($date); } - /** - * Adds a header to every fetch. - * @param string $header Header line to add to every - * request until cleared. - * @access public - */ + /** + * Adds a header to every fetch. + * @param string $header Header line to add to every + * request until cleared. + * @access public + */ function addHeader($header) { $this->_user_agent->addHeader($header); } - /** - * Ages the cookies by the specified time. - * @param integer $interval Amount in seconds. - * @access public - */ + /** + * Ages the cookies by the specified time. + * @param integer $interval Amount in seconds. + * @access public + */ function ageCookies($interval) { $this->_user_agent->ageCookies($interval); } - /** - * Sets an additional cookie. If a cookie has - * the same name and path it is replaced. - * @param string $name Cookie key. - * @param string $value Value of cookie. - * @param string $host Host upon which the cookie is valid. - * @param string $path Cookie path if not host wide. - * @param string $expiry Expiry date. - * @access public - */ + /** + * Sets an additional cookie. If a cookie has + * the same name and path it is replaced. + * @param string $name Cookie key. + * @param string $value Value of cookie. + * @param string $host Host upon which the cookie is valid. + * @param string $path Cookie path if not host wide. + * @param string $expiry Expiry date. + * @access public + */ function setCookie($name, $value, $host = false, $path = '/', $expiry = false) { $this->_user_agent->setCookie($name, $value, $host, $path, $expiry); } - /** - * Reads the most specific cookie value from the - * browser cookies. - * @param string $host Host to search. - * @param string $path Applicable path. - * @param string $name Name of cookie to read. - * @return string False if not present, else the - * value as a string. - * @access public - */ + /** + * Reads the most specific cookie value from the + * browser cookies. + * @param string $host Host to search. + * @param string $path Applicable path. + * @param string $name Name of cookie to read. + * @return string False if not present, else the + * value as a string. + * @access public + */ function getCookieValue($host, $path, $name) { return $this->_user_agent->getCookieValue($host, $path, $name); } - /** - * Reads the current cookies for the current URL. - * @param string $name Key of cookie to find. - * @return string Null if there is no current URL, false - * if the cookie is not set. - * @access public - */ + /** + * Reads the current cookies for the current URL. + * @param string $name Key of cookie to find. + * @return string Null if there is no current URL, false + * if the cookie is not set. + * @access public + */ function getCurrentCookieValue($name) { return $this->_user_agent->getBaseCookieValue($name, $this->_page->getUrl()); } - /** - * Sets the maximum number of redirects before - * a page will be loaded anyway. - * @param integer $max Most hops allowed. - * @access public - */ + /** + * Sets the maximum number of redirects before + * a page will be loaded anyway. + * @param integer $max Most hops allowed. + * @access public + */ function setMaximumRedirects($max) { $this->_user_agent->setMaximumRedirects($max); } - /** - * Sets the maximum number of nesting of framed pages - * within a framed page to prevent loops. - * @param integer $max Highest depth allowed. - * @access public - */ + /** + * Sets the maximum number of nesting of framed pages + * within a framed page to prevent loops. + * @param integer $max Highest depth allowed. + * @access public + */ function setMaximumNestedFrames($max) { $this->_maximum_nested_frames = $max; } - /** - * Sets the socket timeout for opening a connection. - * @param integer $timeout Maximum time in seconds. - * @access public - */ + /** + * Sets the socket timeout for opening a connection. + * @param integer $timeout Maximum time in seconds. + * @access public + */ function setConnectionTimeout($timeout) { $this->_user_agent->setConnectionTimeout($timeout); } - /** - * Sets proxy to use on all requests for when - * testing from behind a firewall. Set URL - * to false to disable. - * @param string $proxy Proxy URL. - * @param string $username Proxy username for authentication. - * @param string $password Proxy password for authentication. - * @access public - */ + /** + * Sets proxy to use on all requests for when + * testing from behind a firewall. Set URL + * to false to disable. + * @param string $proxy Proxy URL. + * @param string $username Proxy username for authentication. + * @param string $password Proxy password for authentication. + * @access public + */ function useProxy($proxy, $username = false, $password = false) { $this->_user_agent->useProxy($proxy, $username, $password); } - /** - * Fetches the page content with a HEAD request. - * Will affect cookies, but will not change the base URL. - * @param string/SimpleUrl $url Target to fetch as string. - * @param hash/SimpleFormEncoding $parameters Additional parameters for - * HEAD request. - * @return boolean True if successful. - * @access public - */ + /** + * Fetches the page content with a HEAD request. + * Will affect cookies, but will not change the base URL. + * @param string/SimpleUrl $url Target to fetch as string. + * @param hash/SimpleHeadEncoding $parameters Additional parameters for + * HEAD request. + * @return boolean True if successful. + * @access public + */ function head($url, $parameters = false) { if (! is_object($url)) { $url = new SimpleUrl($url); } - if (is_array($parameters)) { - $parameters = new SimpleFormEncoding($parameters); - } if ($this->getUrl()) { $url = $url->makeAbsolute($this->getUrl()); } - $response = &$this->_user_agent->fetchResponse( - 'HEAD', - $url, - $parameters); + $response = &$this->_user_agent->fetchResponse($url, new SimpleHeadEncoding($parameters)); return ! $response->isError(); } - /** - * Fetches the page content with a simple GET request. - * @param string/SimpleUrl $url Target to fetch. - * @param hash/SimpleFormEncoding $parameters Additional parameters for - * GET request. - * @return string Content of page or false. - * @access public - */ + /** + * Fetches the page content with a simple GET request. + * @param string/SimpleUrl $url Target to fetch. + * @param hash/SimpleFormEncoding $parameters Additional parameters for + * GET request. + * @return string Content of page or false. + * @access public + */ function get($url, $parameters = false) { if (! is_object($url)) { $url = new SimpleUrl($url); } - if (is_array($parameters)) { - $parameters = new SimpleFormEncoding($parameters); - } if ($this->getUrl()) { $url = $url->makeAbsolute($this->getUrl()); } - return $this->_load('GET', $url, $parameters); + return $this->_load($url, new SimpleGetEncoding($parameters)); } - /** - * Fetches the page content with a POST request. - * @param string/SimpleUrl $url Target to fetch as string. - * @param hash/SimpleFormEncoding $parameters POST parameters. - * @return string Content of page. - * @access public - */ + /** + * Fetches the page content with a POST request. + * @param string/SimpleUrl $url Target to fetch as string. + * @param hash/SimpleFormEncoding $parameters POST parameters. + * @return string Content of page. + * @access public + */ function post($url, $parameters = false) { if (! is_object($url)) { $url = new SimpleUrl($url); } - if (is_array($parameters)) { - $parameters = new SimpleFormEncoding($parameters); - } if ($this->getUrl()) { $url = $url->makeAbsolute($this->getUrl()); } - return $this->_load('POST', $url, $parameters); + return $this->_load($url, new SimplePostEncoding($parameters)); } - /** - * Equivalent to hitting the retry button on the - * browser. Will attempt to repeat the page fetch. If - * there is no history to repeat it will give false. - * @return string/boolean Content if fetch succeeded - * else false. - * @access public - */ + /** + * Equivalent to hitting the retry button on the + * browser. Will attempt to repeat the page fetch. If + * there is no history to repeat it will give false. + * @return string/boolean Content if fetch succeeded + * else false. + * @access public + */ function retry() { $frames = $this->_page->getFrameFocus(); if (count($frames) > 0) { $this->_loadFrame( $frames, - $this->_page->getMethod(), $this->_page->getUrl(), $this->_page->getRequestData()); return $this->_page->getRaw(); } - if ($method = $this->_history->getMethod()) { - $this->_page = &$this->_fetch( - $method, - $this->_history->getUrl(), - $this->_history->getParameters()); + if ($url = $this->_history->getUrl()) { + $this->_page = &$this->_fetch($url, $this->_history->getParameters()); return $this->_page->getRaw(); } return false; } - /** - * Equivalent to hitting the back button on the - * browser. The browser history is unchanged on - * failure. - * @return boolean True if history entry and - * fetch succeeded - * @access public - */ + /** + * Equivalent to hitting the back button on the + * browser. The browser history is unchanged on + * failure. The page content is refetched as there + * is no concept of content caching in SimpleTest. + * @return boolean True if history entry and + * fetch succeeded + * @access public + */ function back() { if (! $this->_history->back()) { return false; @@ -545,14 +517,15 @@ return $content; } - /** - * Equivalent to hitting the forward button on the - * browser. The browser history is unchanged on - * failure. - * @return boolean True if history entry and - * fetch succeeded - * @access public - */ + /** + * Equivalent to hitting the forward button on the + * browser. The browser history is unchanged on + * failure. The page content is refetched as there + * is no concept of content caching in SimpleTest. + * @return boolean True if history entry and + * fetch succeeded + * @access public + */ function forward() { if (! $this->_history->forward()) { return false; @@ -564,16 +537,16 @@ return $content; } - /** - * Retries a request after setting the authentication - * for the current realm. - * @param string $username Username for realm. - * @param string $password Password for realm. - * @return boolean True if successful fetch. Note - * that authentication may still have - * failed. - * @access public - */ + /** + * Retries a request after setting the authentication + * for the current realm. + * @param string $username Username for realm. + * @param string $password Password for realm. + * @return boolean True if successful fetch. Note + * that authentication may still have + * failed. + * @access public + */ function authenticate($username, $password) { if (! $this->_page->getRealm()) { return false; @@ -590,383 +563,401 @@ return $this->retry(); } - /** - * Accessor for a breakdown of the frameset. - * @return array Hash tree of frames by name - * or index if no name. - * @access public - */ + /** + * Accessor for a breakdown of the frameset. + * @return array Hash tree of frames by name + * or index if no name. + * @access public + */ function getFrames() { return $this->_page->getFrames(); } - /** - * Accessor for current frame focus. Will be - * false if no frame has focus. - * @return integer/string/boolean Label if any, otherwise - * the position in the frameset - * or false if none. - * @access public - */ + /** + * Accessor for current frame focus. Will be + * false if no frame has focus. + * @return integer/string/boolean Label if any, otherwise + * the position in the frameset + * or false if none. + * @access public + */ function getFrameFocus() { return $this->_page->getFrameFocus(); } - /** - * Sets the focus by index. The integer index starts from 1. - * @param integer $choice Chosen frame. - * @return boolean True if frame exists. - * @access public - */ + /** + * Sets the focus by index. The integer index starts from 1. + * @param integer $choice Chosen frame. + * @return boolean True if frame exists. + * @access public + */ function setFrameFocusByIndex($choice) { return $this->_page->setFrameFocusByIndex($choice); } - /** - * Sets the focus by name. - * @param string $name Chosen frame. - * @return boolean True if frame exists. - * @access public - */ + /** + * Sets the focus by name. + * @param string $name Chosen frame. + * @return boolean True if frame exists. + * @access public + */ function setFrameFocus($name) { return $this->_page->setFrameFocus($name); } - /** - * Clears the frame focus. All frames will be searched - * for content. - * @access public - */ + /** + * Clears the frame focus. All frames will be searched + * for content. + * @access public + */ function clearFrameFocus() { return $this->_page->clearFrameFocus(); } - /** - * 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->_page->getTransportError(); } - /** - * 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() { return $this->_page->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() { return $this->_page->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() { return $this->_page->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() { return $this->_page->getRealm(); } - /** - * Accessor for current URL of page or frame if - * focused. - * @return string Location of current page or frame as - * a string. - */ + /** + * Accessor for current URL of page or frame if + * focused. + * @return string Location of current page or frame as + * a string. + */ function getUrl() { $url = $this->_page->getUrl(); return $url ? $url->asString() : false; } - /** - * Accessor for raw bytes sent down the wire. - * @return string Original text sent. - * @access public - */ + /** + * Accessor for raw bytes sent down the wire. + * @return string Original text sent. + * @access public + */ function getRequest() { return $this->_page->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() { return $this->_page->getHeaders(); } - /** - * Accessor for raw page information. - * @return string Original text content of web page. - * @access public - */ + /** + * Accessor for raw page information. + * @return string Original text content of web page. + * @access public + */ function getContent() { return $this->_page->getRaw(); } - /** - * Accessor for plain text version of the page. - * @return string Normalised text representation. - * @access public - */ + /** + * Accessor for plain text version of the page. + * @return string Normalised text representation. + * @access public + */ function getContentAsText() { return $this->_page->getText(); } - /** - * 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->_page->getTitle(); } - /** - * Accessor for a list of all fixed links in current page. - * @return array List of urls with scheme of - * http or https and hostname. - * @access public - */ + /** + * Accessor for a list of all fixed links in current page. + * @return array List of urls with scheme of + * http or https and hostname. + * @access public + */ function getAbsoluteUrls() { return $this->_page->getAbsoluteUrls(); } - /** - * 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() { return $this->_page->getRelativeUrls(); } - /** - * Sets all form fields with that name. - * @param string $name Name of field in forms. - * @param string $value New value of field. - * @return boolean True if field exists, otherwise false. - * @access public - */ + /** + * Sets all form fields with that name. + * @param string $name Name of field in forms. + * @param string $value New value of field. + * @return boolean True if field exists, otherwise false. + * @access public + */ function setField($name, $value) { return $this->_page->setField($name, $value); } + + /** + * Sets all form fields with that name. Will use label if + * one is available (not yet implemented). + * @param string $name Name of field in forms. + * @param string $value New value of field. + * @return boolean True if field exists, otherwise false. + * @access public + */ + function setFieldByName($name, $value) { + return $this->_page->setFieldByName($name, $value); + } - /** - * Sets all form fields with that id attribute. - * @param string/integer $id Id of field in forms. - * @param string $value New value of field. - * @return boolean True if field exists, otherwise false. - * @access public - */ + /** + * Sets all form fields with that id attribute. + * @param string/integer $id Id of field in forms. + * @param string $value New value of field. + * @return boolean True if field exists, otherwise false. + * @access public + */ function setFieldById($id, $value) { return $this->_page->setFieldById($id, $value); } - /** - * Accessor for a form element value within the 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) { - return $this->_page->getField($name); + /** + * Accessor for a form element value within the page. + * Finds the first match. + * @param string $label Field label. + * @return string/boolean A value if the field is + * present, false if unchecked + * and null if missing. + * @access public + */ + function getField($label) { + return $this->_page->getField($label); + } + + /** + * Accessor for a form element value within the 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 getFieldByName($name) { + return $this->_page->getFieldByName($name); } - /** - * Accessor for a form element value within the page. - * @param string/integer $id Id of field in forms. - * @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 the page. + * @param string/integer $id Id of field in forms. + * @return string/boolean A string if the field is + * present, false if unchecked + * and null if missing. + * @access public + */ function getFieldById($id) { return $this->_page->getFieldById($id); } - /** - * Clicks the submit button by label. The owning - * form will be submitted by this. - * @param string $label Button label. An unlabeled - * button can be triggered by 'Submit'. - * @param hash $additional Additional form data. - * @return string/boolean Page on success. - * @access public - */ + /** + * Clicks the submit button by label. The owning + * form will be submitted by this. + * @param string $label Button label. An unlabeled + * button can be triggered by 'Submit'. + * @param hash $additional Additional form data. + * @return string/boolean Page on success. + * @access public + */ function clickSubmit($label = 'Submit', $additional = false) { if (! ($form = &$this->_page->getFormBySubmitLabel($label))) { return false; } $success = $this->_load( - $form->getMethod(), $form->getAction(), - $form->submitButtonByLabel($label, $additional)); + $form->submitButton(new SimpleByLabel($label), $additional)); return ($success ? $this->getContent() : $success); } - /** - * Clicks the submit button by name attribute. The owning - * form will be submitted by this. - * @param string $name Button name. - * @param hash $additional Additional form data. - * @return string/boolean Page on success. - * @access public - */ + /** + * Clicks the submit button by name attribute. The owning + * form will be submitted by this. + * @param string $name Button name. + * @param hash $additional Additional form data. + * @return string/boolean Page on success. + * @access public + */ function clickSubmitByName($name, $additional = false) { if (! ($form = &$this->_page->getFormBySubmitName($name))) { return false; } $success = $this->_load( - $form->getMethod(), $form->getAction(), - $form->submitButtonByName($name, $additional)); + $form->submitButton(new SimpleByName($name), $additional)); return ($success ? $this->getContent() : $success); } - /** - * Clicks the submit button by ID attribute of the button - * itself. The owning form will be submitted by this. - * @param string $id Button ID. - * @param hash $additional Additional form data. - * @return string/boolean Page on success. - * @access public - */ + /** + * Clicks the submit button by ID attribute of the button + * itself. The owning form will be submitted by this. + * @param string $id Button ID. + * @param hash $additional Additional form data. + * @return string/boolean Page on success. + * @access public + */ function clickSubmitById($id, $additional = false) { if (! ($form = &$this->_page->getFormBySubmitId($id))) { return false; } $success = $this->_load( - $form->getMethod(), $form->getAction(), - $form->submitButtonById($id, $additional)); + $form->submitButton(new SimpleById($id), $additional)); return ($success ? $this->getContent() : $success); } - /** - * Clicks the submit image by some kind of label. Usually - * the alt tag or the nearest equivalent. The owning - * form will be submitted by this. Clicking outside of - * the boundary of the coordinates will result in - * a failure. - * @param string $label ID attribute of button. - * @param integer $x X-coordinate of imaginary click. - * @param integer $y Y-coordinate of imaginary click. - * @param hash $additional Additional form data. - * @return string/boolean Page on success. - * @access public - */ + /** + * Clicks the submit image by some kind of label. Usually + * the alt tag or the nearest equivalent. The owning + * form will be submitted by this. Clicking outside of + * the boundary of the coordinates will result in + * a failure. + * @param string $label ID attribute of button. + * @param integer $x X-coordinate of imaginary click. + * @param integer $y Y-coordinate of imaginary click. + * @param hash $additional Additional form data. + * @return string/boolean Page on success. + * @access public + */ function clickImage($label, $x = 1, $y = 1, $additional = false) { if (! ($form = &$this->_page->getFormByImageLabel($label))) { return false; } $success = $this->_load( - $form->getMethod(), $form->getAction(), - $form->submitImageByLabel($label, $x, $y, $additional)); + $form->submitImage(new SimpleByLabel($label), $x, $y, $additional)); return ($success ? $this->getContent() : $success); } - /** - * Clicks the submit image by the name. Usually - * the alt tag or the nearest equivalent. The owning - * form will be submitted by this. Clicking outside of - * the boundary of the coordinates will result in - * a failure. - * @param string $name Name attribute of button. - * @param integer $x X-coordinate of imaginary click. - * @param integer $y Y-coordinate of imaginary click. - * @param hash $additional Additional form data. - * @return string/boolean Page on success. - * @access public - */ + /** + * Clicks the submit image by the name. Usually + * the alt tag or the nearest equivalent. The owning + * form will be submitted by this. Clicking outside of + * the boundary of the coordinates will result in + * a failure. + * @param string $name Name attribute of button. + * @param integer $x X-coordinate of imaginary click. + * @param integer $y Y-coordinate of imaginary click. + * @param hash $additional Additional form data. + * @return string/boolean Page on success. + * @access public + */ function clickImageByName($name, $x = 1, $y = 1, $additional = false) { if (! ($form = &$this->_page->getFormByImageName($name))) { return false; } $success = $this->_load( - $form->getMethod(), $form->getAction(), - $form->submitImageByName($name, $x, $y, $additional)); + $form->submitImage(new SimpleByName($name), $x, $y, $additional)); return ($success ? $this->getContent() : $success); } - /** - * Clicks the submit image by ID attribute. The owning - * form will be submitted by this. Clicking outside of - * the boundary of the coordinates will result in - * a failure. - * @param integer/string $id ID attribute of button. - * @param integer $x X-coordinate of imaginary click. - * @param integer $y Y-coordinate of imaginary click. - * @param hash $additional Additional form data. - * @return string/boolean Page on success. - * @access public - */ + /** + * Clicks the submit image by ID attribute. The owning + * form will be submitted by this. Clicking outside of + * the boundary of the coordinates will result in + * a failure. + * @param integer/string $id ID attribute of button. + * @param integer $x X-coordinate of imaginary click. + * @param integer $y Y-coordinate of imaginary click. + * @param hash $additional Additional form data. + * @return string/boolean Page on success. + * @access public + */ function clickImageById($id, $x = 1, $y = 1, $additional = false) { if (! ($form = &$this->_page->getFormByImageId($id))) { return false; } $success = $this->_load( - $form->getMethod(), $form->getAction(), - $form->submitImageById($id, $x, $y, $additional)); + $form->submitImage(new SimpleById($id), $x, $y, $additional)); return ($success ? $this->getContent() : $success); } - /** - * Submits a form by the ID. - * @param string $id The form ID. No submit button value - * will be sent. - * @return string/boolean Page on success. - * @access public - */ + /** + * Submits a form by the ID. + * @param string $id The form ID. No submit button value + * will be sent. + * @return string/boolean Page on success. + * @access public + */ function submitFormById($id) { if (! ($form = &$this->_page->getFormById($id))) { return false; } $success = $this->_load( - $form->getMethod(), $form->getAction(), $form->submit()); return ($success ? $this->getContent() : $success); } - /** - * Follows a link by label. Will click the first link - * found with this link text by default, or a later - * one if an index is given. The match ignores case and - * white space issues. - * @param string $label Text between the anchor tags. - * @param integer $index Link position counting from zero. - * @return string/boolean Page on success. - * @access public - */ + /** + * Follows a link by label. Will click the first link + * found with this link text by default, or a later + * one if an index is given. The match ignores case and + * white space issues. + * @param string $label Text between the anchor tags. + * @param integer $index Link position counting from zero. + * @return string/boolean Page on success. + * @access public + */ function clickLink($label, $index = 0) { $urls = $this->_page->getUrlsByLabel($label); if (count($urls) == 0) { @@ -975,42 +966,60 @@ if (count($urls) < $index + 1) { return false; } - $this->_load('GET', $urls[$index]); + $this->_load($urls[$index], new SimpleGetEncoding()); return $this->getContent(); } - /** - * Tests to see if a link is present by label. - * @param string $label Text of value attribute. - * @return boolean True if link present. - * @access public - */ + /** + * Tests to see if a link is present by label. + * @param string $label Text of value attribute. + * @return boolean True if link present. + * @access public + */ function isLink($label) { return (count($this->_page->getUrlsByLabel($label)) > 0); } - /** - * Follows a link by id attribute. - * @param string $id ID attribute value. - * @return string/boolean Page on success. - * @access public - */ + /** + * Follows a link by id attribute. + * @param string $id ID attribute value. + * @return string/boolean Page on success. + * @access public + */ function clickLinkById($id) { if (! ($url = $this->_page->getUrlById($id))) { return false; } - $this->_load('GET', $url); + $this->_load($url, new SimpleGetEncoding()); return $this->getContent(); } - /** - * Tests to see if a link is present by ID attribute. - * @param string $id Text of id attribute. - * @return boolean True if link present. - * @access public - */ + /** + * Tests to see if a link is present by ID attribute. + * @param string $id Text of id attribute. + * @return boolean True if link present. + * @access public + */ function isLinkById($id) { return (boolean)$this->_page->getUrlById($id); } + + /** + * Clicks a visible text item. Will first try buttons, + * then links and then images. + * @param string $label Visible text or alt text. + * @return string/boolean Raw page or false. + * @access public + */ + function click($label) { + $raw = $this->clickSubmit($label); + if (! $raw) { + $raw = $this->clickLink($label); + } + if (! $raw) { + $raw = $this->clickImage($label); + } + return $raw; + } } ?> \ No newline at end of file diff --git a/vendors/simpletest/collector.php b/vendors/simpletest/collector.php new file mode 100644 index 000000000..b1a772059 --- /dev/null +++ b/vendors/simpletest/collector.php @@ -0,0 +1,123 @@ + + * @package SimpleTest + * @subpackage UnitTester + * @version $Id: collector.php,v 1.6 2005/03/26 01:54:05 tswicegood Exp $ + */ + +/** + * The basic collector for {@link GroupTest} + * + * @see collect(), GroupTest::collect() + * @package SimpleTest + * @subpackage UnitTester + */ +class SimpleCollector { + + /** + * Strips off any kind of slash at the end so as to normalise the path + * + * @param string $path Path to normalise. + */ + function _removeTrailingSlash($path) { + return preg_replace('|[\\/]$|', '', $path); + + /** + * @internal + * Try benchmarking the following. It's more code, but by not using the + * regex, it may be faster? Also, shouldn't be looking for + * DIRECTORY_SEPERATOR instead of a manual "/"? + */ + if (substr($path, -1) == DIRECTORY_SEPERATOR) { + return substr($path, 0, -1); + } else { + return $path; + } + } + + /** + * Scans the directory and adds what it can. + * @param object $test Group test with {@link GroupTest::addTestFile()} method. + * @param string $path Directory to scan. + * @see _attemptToAdd() + */ + function collect(&$test, $path) { + $path = $this->_removeTrailingSlash($path); + if ($handle = opendir($path)) { + while (($entry = readdir($handle)) !== false) { + $this->_handle($test, $path . DIRECTORY_SEPARATOR . $entry); + } + closedir($handle); + } + } + + /** + * This method determines what should be done with a given file and adds + * it via {@link GroupTest::addTestFile()} if necessary. + * + * This method should be overriden to provide custom matching criteria, + * such as pattern matching, recursive matching, etc. For an example, see + * {@link SimplePatternCollector::_handle()}. + * + * @param object $test Group test with {@link GroupTest::addTestFile()} method. + * @param string $filename A filename as generated by {@link collect()} + * @see collect() + * @access protected + */ + function _handle(&$test, $file) { + if (!is_dir($file)) { + $test->addTestFile($file); + } + } +} + +/** + * An extension to {@link SimpleCollector} that only adds files matching a + * given pattern. + * + * @package SimpleTest + * @subpackage UnitTester + * @see SimpleCollector + */ +class SimplePatternCollector extends SimpleCollector { + var $_pattern; + + /** + * Scans the directory and adds what it can that matches a given pattern. + * + * No verification is done on the pattern, so it is incumbent about the + * developer to insure it is a proper pattern. + * + * Defaults to files ending in "php" + * + * @param object $test See {@link SimpleCollector::collect()} + * @param string $path See {@link Simplecollector::collect()} + * @param string $pattern Perl compatible regex to test name against + * See {@link http://us4.php.net/manual/en/reference.pcre.pattern.syntax.php PHP's PCRE} + * for full documentation of valid pattern.s + */ + function collect(&$test, $path, $pattern = '/php$/i') { + $this->_pattern = $pattern; + + parent::collect($test, $path); + } + + /** + * Attempts to add files that match a given pattern. + * + * @see SimpleCollector::_handle() + * @param object $test Group test with {@link GroupTest::addTestFile()} method. + * @param string $path Directory to scan. + * @access protected + */ + function _handle(&$test, $filename) { + if (preg_match($this->_pattern, $filename)) { + parent::_handle($test, $filename); + } + } +} +?> \ No newline at end of file diff --git a/vendors/simpletest/docs/en/index.html b/vendors/simpletest/docs/en/index.html index 0dabbcdae..047972727 100644 --- a/vendors/simpletest/docs/en/index.html +++ b/vendors/simpletest/docs/en/index.html @@ -195,11 +195,11 @@ $test->run(new HtmlReporter());
1/1 test cases complete. 2 passes and 0 fails.
- And if you get this... + And if you get this...
Fatal error: Failed opening required '../classes/log.php' (include_path='') in /home/marcus/projects/lastcraft/tutorial_tests/Log/tests/log_test.php on line 7
- it means you're missing the classes/Log.php file that could look like... + it means you're missing the classes/Log.php file that could look like...
 <?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());	
+?>	
 

diff --git a/vendors/simpletest/docs/fr/index.html b/vendors/simpletest/docs/fr/index.html index 8844259f4..f4b2ad930 100644 --- a/vendors/simpletest/docs/fr/index.html +++ b/vendors/simpletest/docs/fr/index.html @@ -149,11 +149,11 @@ $test->run(new HtmlReporter());
1/1 test cases complete. 2 passes and 0 fails.
- Et si vous obtenez ça... + Et si vous obtenez ça...
Fatal error: Failed opening required '../classes/log.php' (include_path='') in /home/marcus/projects/lastcraft/tutorial_tests/Log/tests/log_test.php on line 7
- c'est qu'il vous manque le fichier classes/Log.php qui pourrait ressembler à : + c'est qu'il vous manque le fichier classes/Log.php qui pourrait ressembler à :
 <?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: 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/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: 0
 
diff --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('addExitPattern('-->', 'comment'); } - /** - * Pattern matches to start and end a tag. - * @param SimpleLexer $lexer Lexer to add patterns to. - * @param string $tag Name of tag to scan for. - * @access private - * @static - */ + /** + * Pattern matches to start and end a tag. + * @param SimpleLexer $lexer Lexer to add patterns to. + * @param string $tag Name of tag to scan for. + * @access private + * @static + */ function _addTag(&$lexer, $tag) { $lexer->addSpecialPattern("", 'text', 'acceptEndToken'); $lexer->addEntryPattern("<$tag", 'text', 'tag'); } - /** - * Pattern matches to parse the inside of a tag - * including the attributes and their quoting. - * @param SimpleLexer $lexer Lexer to add patterns to. - * @access private - * @static - */ + /** + * Pattern matches to parse the inside of a tag + * including the attributes and their quoting. + * @param SimpleLexer $lexer Lexer to add patterns to. + * @access private + * @static + */ function _addInTagTokens(&$lexer) { $lexer->mapHandler('tag', 'acceptStartToken'); $lexer->addSpecialPattern('\s+', 'tag', 'ignore'); @@ -549,13 +559,13 @@ $lexer->addExitPattern('>', 'tag'); } - /** - * Matches attributes that are either single quoted, - * double quoted or unquoted. - * @param SimpleLexer $lexer Lexer to add patterns to. - * @access private - * @static - */ + /** + * Matches attributes that are either single quoted, + * double quoted or unquoted. + * @param SimpleLexer $lexer Lexer to add patterns to. + * @access private + * @static + */ function _addAttributeTokens(&$lexer) { $lexer->mapHandler('dq_attribute', 'acceptAttributeToken'); $lexer->addEntryPattern('=\s*"', 'tag', 'dq_attribute'); @@ -569,17 +579,17 @@ $lexer->addSpecialPattern('=\s*[^>\s]*', 'tag', 'uq_attribute'); } - /** - * Accepts a token from the tag mode. If the - * starting element completes then the element - * is dispatched and the current attributes - * set back to empty. The element or attribute - * name is converted to lower case. - * @param string $token Incoming characters. - * @param integer $event Lexer event type. - * @return boolean False if parse error. - * @access public - */ + /** + * Accepts a token from the tag mode. If the + * starting element completes then the element + * is dispatched and the current attributes + * set back to empty. The element or attribute + * name is converted to lower case. + * @param string $token Incoming characters. + * @param integer $event Lexer event type. + * @return boolean False if parse error. + * @access public + */ function acceptStartToken($token, $event) { if ($event == LEXER_ENTER) { $this->_tag = strtolower(substr($token, 1)); @@ -600,14 +610,14 @@ return true; } - /** - * Accepts a token from the end tag mode. - * The element name is converted to lower case. - * @param string $token Incoming characters. - * @param integer $event Lexer event type. - * @return boolean False if parse error. - * @access public - */ + /** + * Accepts a token from the end tag mode. + * The element name is converted to lower case. + * @param string $token Incoming characters. + * @param integer $event Lexer event type. + * @return boolean False if parse error. + * @access public + */ function acceptEndToken($token, $event) { if (! preg_match('/<\/(.*)>/', $token, $matches)) { return false; @@ -615,13 +625,13 @@ return $this->_listener->endElement(strtolower($matches[1])); } - /** - * Part of the tag data. - * @param string $token Incoming characters. - * @param integer $event Lexer event type. - * @return boolean False if parse error. - * @access public - */ + /** + * Part of the tag data. + * @param string $token Incoming characters. + * @param integer $event Lexer event type. + * @return boolean False if parse error. + * @access public + */ function acceptAttributeToken($token, $event) { if ($event == LEXER_UNMATCHED) { $this->_attributes[$this->_current_attribute] .= @@ -634,46 +644,46 @@ return true; } - /** - * A character entity. - * @param string $token Incoming characters. - * @param integer $event Lexer event type. - * @return boolean False if parse error. - * @access public - */ + /** + * A character entity. + * @param string $token Incoming characters. + * @param integer $event Lexer event type. + * @return boolean False if parse error. + * @access public + */ function acceptEntityToken($token, $event) { } - /** - * Character data between tags regarded as - * important. - * @param string $token Incoming characters. - * @param integer $event Lexer event type. - * @return boolean False if parse error. - * @access public - */ + /** + * Character data between tags regarded as + * important. + * @param string $token Incoming characters. + * @param integer $event Lexer event type. + * @return boolean False if parse error. + * @access public + */ function acceptTextToken($token, $event) { return $this->_listener->addContent($token); } - /** - * Incoming data to be ignored. - * @param string $token Incoming characters. - * @param integer $event Lexer event type. - * @return boolean False if parse error. - * @access public - */ + /** + * Incoming data to be ignored. + * @param string $token Incoming characters. + * @param integer $event Lexer event type. + * @return boolean False if parse error. + * @access public + */ function ignore($token, $event) { return true; } - /** - * Decodes any HTML entities. - * @param string $html Incoming HTML. - * @return string Outgoing plain text. - * @access public - * @static - */ + /** + * Decodes any HTML entities. + * @param string $html Incoming HTML. + * @return string Outgoing plain text. + * @access public + * @static + */ function decodeHtml($html) { static $translations; if (! isset($translations)) { @@ -682,17 +692,18 @@ return strtr($html, $translations); } - /** - * Turns HTML into text browser visible text. Images - * are converted to their alt text and tags are supressed. - * Entities are converted to their visible representation. - * @param string $html HTML to convert. - * @return string Plain text. - * @access public - * @static - */ + /** + * Turns HTML into text browser visible text. Images + * are converted to their alt text and tags are supressed. + * Entities are converted to their visible representation. + * @param string $html HTML to convert. + * @return string Plain text. + * @access public + * @static + */ function normalise($html) { - $text = preg_replace('||', ' \1 ', $html); + $text = preg_replace('||', '', $html); + $text = preg_replace('||', ' \1 ', $text); $text = preg_replace('||', ' \1 ', $text); $text = preg_replace('||', ' \1 ', $text); $text = preg_replace('|<.*?>|', '', $text); @@ -702,48 +713,48 @@ } } - /** - * SAX event handler. - * @package SimpleTest - * @subpackage WebTester - * @abstract - */ + /** + * SAX event handler. + * @package SimpleTest + * @subpackage WebTester + * @abstract + */ class SimpleSaxListener { - /** - * Sets the document to write to. - * @access public - */ + /** + * Sets the document to write to. + * @access public + */ function SimpleSaxListener() { } - /** - * Start of element event. - * @param string $name Element name. - * @param hash $attributes Name value pairs. - * Attributes without content - * are marked as true. - * @return boolean False on parse error. - * @access public - */ + /** + * Start of element event. + * @param string $name Element name. + * @param hash $attributes Name value pairs. + * Attributes without content + * are marked as true. + * @return boolean False on parse error. + * @access public + */ function startElement($name, $attributes) { } - /** - * 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) { } - /** - * Unparsed, but relevant data. - * @param string $text May include unparsed tags. - * @return boolean False on parse error. - * @access public - */ + /** + * Unparsed, but relevant data. + * @param string $text May include unparsed tags. + * @return boolean False on parse error. + * @access public + */ function addContent($text) { } } diff --git a/vendors/simpletest/remote.php b/vendors/simpletest/remote.php index dc1117ff3..b0d91c0e2 100644 --- a/vendors/simpletest/remote.php +++ b/vendors/simpletest/remote.php @@ -1,58 +1,58 @@ _url = $url; $this->_dry_url = $dry_url ? $dry_url : $url; $this->_size = false; } - /** - * Accessor for the test name for subclasses. - * @return string Name of the test. - * @access public - */ + /** + * Accessor for the test name for subclasses. + * @return string Name of the test. + * @access public + */ function getLabel() { return $this->_url; } - /** - * Runs the top level test for this class. Currently - * reads the data as a single chunk. I'll fix this - * once I have added iteration to the browser. - * @param SimpleReporter $reporter Target of test results. - * @returns boolean True if no failures. - * @access public - */ + /** + * Runs the top level test for this class. Currently + * reads the data as a single chunk. I'll fix this + * once I have added iteration to the browser. + * @param SimpleReporter $reporter Target of test results. + * @returns boolean True if no failures. + * @access public + */ function run(&$reporter) { $browser = &$this->_createBrowser(); $xml = $browser->get($this->_url); @@ -68,31 +68,31 @@ return true; } - /** - * Creates a new web browser object for fetching - * the XML report. - * @return SimpleBrowser New browser. - * @access protected - */ + /** + * Creates a new web browser object for fetching + * the XML report. + * @return SimpleBrowser New browser. + * @access protected + */ function &_createBrowser() { return new SimpleBrowser(); } - /** - * Creates the XML parser. - * @param SimpleReporter $reporter Target of test results. - * @return SimpleTestXmlListener XML reader. - * @access protected - */ + /** + * Creates the XML parser. + * @param SimpleReporter $reporter Target of test results. + * @return SimpleTestXmlListener XML reader. + * @access protected + */ function &_createParser(&$reporter) { return new SimpleTestXmlParser($reporter); } - /** - * Accessor for the number of subtests. - * @return integer Number of test cases. - * @access public - */ + /** + * Accessor for the number of subtests. + * @return integer Number of test cases. + * @access public + */ function getSize() { if ($this->_size === false) { $browser = &$this->_createBrowser(); diff --git a/vendors/simpletest/reporter.php b/vendors/simpletest/reporter.php index 2f534febf..2b93e75b1 100644 --- a/vendors/simpletest/reporter.php +++ b/vendors/simpletest/reporter.php @@ -1,43 +1,43 @@ SimpleReporter(); $this->_character_set = $character_set; } - /** - * Paints the top of the web page setting the - * title to the name of the starting test. - * @param string $test_name Name class of test. - * @access public - */ + /** + * Paints the top of the web page setting the + * title to the name of the starting test. + * @param string $test_name Name class of test. + * @access public + */ function paintHeader($test_name) { $this->sendNoCacheHeaders(); print "\n\n$test_name\n"; @@ -51,13 +51,13 @@ flush(); } - /** - * Send the headers necessary to ensure the page is - * reloaded on every request. Otherwise you could be - * scratching your head over out of date test data. - * @access public - * @static - */ + /** + * Send the headers necessary to ensure the page is + * reloaded on every request. Otherwise you could be + * scratching your head over out of date test data. + * @access public + * @static + */ function sendNoCacheHeaders() { if (! headers_sent()) { header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); @@ -68,21 +68,21 @@ } } - /** - * Paints the CSS. Add additional styles here. - * @return string CSS code as text. - * @access protected - */ + /** + * Paints the CSS. Add additional styles here. + * @return string CSS code as text. + * @access protected + */ function _getCss() { return ".fail { color: red; } pre { background-color: lightgray; }"; } - /** - * Paints the end of the test with a summary of - * the passes and failures. - * @param string $test_name Name class of test. - * @access public - */ + /** + * Paints the end of the test with a summary of + * the passes and failures. + * @param string $test_name Name class of test. + * @access public + */ function paintFooter($test_name) { $colour = ($this->getFailCount() + $this->getExceptionCount() > 0 ? "red" : "green"); print "
\n\n"; } - /** - * Paints the test failure with a breadcrumbs - * trail of the nesting test suites below the - * top level test. - * @param string $message Failure message displayed in - * the context of the other tests. - * @access public - */ + /** + * Paints the test failure with a breadcrumbs + * trail of the nesting test suites below the + * top level test. + * @param string $message Failure message displayed in + * the context of the other tests. + * @access public + */ function paintFail($message) { parent::paintFail($message); print "Fail: "; @@ -114,12 +114,12 @@ print " -> " . $this->_htmlEntities($message) . "
\n"; } - /** - * Paints a PHP error or exception. - * @param string $message Message is ignored. - * @access public - * @abstract - */ + /** + * Paints a PHP error or exception. + * @param string $message Message is ignored. + * @access public + * @abstract + */ function paintException($message) { parent::paintException($message); print "Exception: "; @@ -129,51 +129,51 @@ print " -> " . $this->_htmlEntities($message) . "
\n"; } - /** - * Paints formatted text such as dumped variables. - * @param string $message Text to show. - * @access public - */ + /** + * Paints formatted text such as dumped variables. + * @param string $message Text to show. + * @access public + */ function paintFormattedMessage($message) { print '
' . $this->_htmlEntities($message) . '
'; } - /** - * Character set adjusted entity conversion. - * @param string $message Plain text or Unicode message. - * @return string Browser readable message. - * @access protected - */ + /** + * Character set adjusted entity conversion. + * @param string $message Plain text or Unicode message. + * @return string Browser readable message. + * @access protected + */ function _htmlEntities($message) { return htmlentities($message, ENT_COMPAT, $this->_character_set); } } - /** - * Sample minimal test displayer. Generates only - * failure messages and a pass count. For command - * line use. I've tried to make it look like JUnit, - * but I wanted to output the errors as they arrived - * which meant dropping the dots. - * @package SimpleTest - * @subpackage UnitTester - */ + /** + * Sample minimal test displayer. Generates only + * failure messages and a pass count. For command + * line use. I've tried to make it look like JUnit, + * but I wanted to output the errors as they arrived + * which meant dropping the dots. + * @package SimpleTest + * @subpackage UnitTester + */ class TextReporter extends SimpleReporter { - /** - * Does nothing yet. The first output will - * be sent on the first test start. - * @access public - */ + /** + * Does nothing yet. The first output will + * be sent on the first test start. + * @access public + */ function TextReporter() { $this->SimpleReporter(); } - /** - * Paints the title only. - * @param string $test_name Name class of test. - * @access public - */ + /** + * Paints the title only. + * @param string $test_name Name class of test. + * @access public + */ function paintHeader($test_name) { if (! SimpleReporter::inCli()) { header('Content-type: text/plain'); @@ -182,12 +182,12 @@ flush(); } - /** - * Paints the end of the test with a summary of - * the passes and failures. - * @param string $test_name Name class of test. - * @access public - */ + /** + * Paints the end of the test with a summary of + * the passes and failures. + * @param string $test_name Name class of test. + * @access public + */ function paintFooter($test_name) { if ($this->getFailCount() + $this->getExceptionCount() == 0) { print "OK\n"; @@ -202,12 +202,12 @@ } - /** - * Paints the test failure as a stack trace. - * @param string $message Failure message displayed in - * the context of the other tests. - * @access public - */ + /** + * Paints the test failure as a stack trace. + * @param string $message Failure message displayed in + * the context of the other tests. + * @access public + */ function paintFail($message) { parent::paintFail($message); print $this->getFailCount() . ") $message\n"; @@ -217,22 +217,22 @@ print "\n"; } - /** - * Paints a PHP error or exception. - * @param string $message Message is ignored. - * @access public - * @abstract - */ + /** + * Paints a PHP error or exception. + * @param string $message Message is ignored. + * @access public + * @abstract + */ function paintException($message) { parent::paintException($message); print "Exception " . $this->getExceptionCount() . "!\n$message\n"; } - /** - * Paints formatted text such as dumped variables. - * @param string $message Text to show. - * @access public - */ + /** + * Paints formatted text such as dumped variables. + * @param string $message Text to show. + * @access public + */ function paintFormattedMessage($message) { print "$message\n"; flush(); diff --git a/vendors/simpletest/runner.php b/vendors/simpletest/runner.php index 0d349c8b5..5c673f64b 100644 --- a/vendors/simpletest/runner.php +++ b/vendors/simpletest/runner.php @@ -1,15 +1,15 @@ _test_case = &$test_case; } - /** - * Accessor for test case being run. - * @return SimpleTestCase Test case. - * @access public - */ + /** + * Accessor for test case being run. + * @return SimpleTestCase Test case. + * @access public + */ function &getTestCase() { return $this->_test_case; } - /** - * Invokes a test method and buffered with setUp() - * and tearDown() calls. - * @param string $method Test method to call. - * @access public - */ + /** + * Invokes a test method and buffered with setUp() + * and tearDown() calls. + * @param string $method Test method to call. + * @access public + */ function invoke($method) { $this->_test_case->setUp(); $this->_test_case->$method(); @@ -60,66 +60,66 @@ } } - /** - * Do nothing decorator. Just passes the invocation - * straight through. - * @package SimpleTest - * @subpackage UnitTester - */ + /** + * Do nothing decorator. Just passes the invocation + * straight through. + * @package SimpleTest + * @subpackage UnitTester + */ class SimpleInvokerDecorator { var $_invoker; - /** - * Stores the invoker to wrap. - * @param SimpleInvoker $invoker Test method runner. - */ + /** + * Stores the invoker to wrap. + * @param SimpleInvoker $invoker Test method runner. + */ function SimpleInvokerDecorator(&$invoker) { $this->_invoker = &$invoker; } - /** - * Accessor for test case being run. - * @return SimpleTestCase Test case. - * @access public - */ + /** + * Accessor for test case being run. + * @return SimpleTestCase Test case. + * @access public + */ function &getTestCase() { return $this->_invoker->getTestCase(); } - /** - * Invokes a test method and buffered with setUp() - * and tearDown() calls. - * @param string $method Test method to call. - * @access public - */ + /** + * Invokes a test method and buffered with setUp() + * and tearDown() calls. + * @param string $method Test method to call. + * @access public + */ function invoke($method) { $this->_invoker->invoke($method); } } - /** - * Extension that traps errors into an error queue. - * @package SimpleTest - * @subpackage UnitTester - */ + /** + * Extension that traps errors into an error queue. + * @package SimpleTest + * @subpackage UnitTester + */ class SimpleErrorTrappingInvoker extends SimpleInvokerDecorator { - /** - /** - * Stores the invoker to wrap. - * @param SimpleInvoker $invoker Test method runner. - */ + /** + /** + * Stores the invoker to wrap. + * @param SimpleInvoker $invoker Test method runner. + */ function SimpleErrorTrappingInvoker(&$invoker) { $this->SimpleInvokerDecorator($invoker); } - /** - * Invokes a test method and dispatches any - * untrapped errors. Called back from - * the visiting runner. - * @param string $method Test method to call. - * @access public - */ + /** + * Invokes a test method and dispatches any + * untrapped errors. Called back from + * the visiting runner. + * @param string $method Test method to call. + * @access public + */ function invoke($method) { set_error_handler('simpleTestErrorHandler'); parent::invoke($method); @@ -132,42 +132,42 @@ } } - /** - * The standard runner. Will run every method starting - * with test Basically the - * Mediator pattern. - * @package SimpleTest - * @subpackage UnitTester - */ + /** + * The standard runner. Will run every method starting + * with test Basically the + * Mediator pattern. + * @package SimpleTest + * @subpackage UnitTester + */ class SimpleRunner { var $_test_case; var $_scorer; - /** - * Takes in the test case and reporter to mediate between. - * @param SimpleTestCase $test_case Test case to run. - * @param SimpleScorer $scorer Reporter to receive events. - */ + /** + * Takes in the test case and reporter to mediate between. + * @param SimpleTestCase $test_case Test case to run. + * @param SimpleScorer $scorer Reporter to receive events. + */ function SimpleRunner(&$test_case, &$scorer) { $this->_test_case = &$test_case; $this->_scorer = &$scorer; } - /** - * Accessor for test case being run. - * @return SimpleTestCase Test case. - * @access public - */ + /** + * Accessor for test case being run. + * @return SimpleTestCase Test case. + * @access public + */ function &getTestCase() { return $this->_test_case; } - /** - * Runs the test methods in the test case. - * @param SimpleTest $test_case Test case to run test on. - * @param string $method Name of test method. - * @access public - */ + /** + * Runs the test methods in the test case. + * @param SimpleTest $test_case Test case to run test on. + * @param string $method Name of test method. + * @access public + */ function run() { $methods = get_class_methods(get_class($this->_test_case)); $invoker = &$this->_test_case->createInvoker(); @@ -186,113 +186,113 @@ } } - /** - * Tests to see if the method is the constructor and - * so should be ignored. - * @param string $method Method name to try. - * @return boolean True if constructor. - * @access protected - */ + /** + * Tests to see if the method is the constructor and + * so should be ignored. + * @param string $method Method name to try. + * @return boolean True if constructor. + * @access protected + */ function _isConstructor($method) { return SimpleTestCompatibility::isA( $this->_test_case, strtolower($method)); } - /** - * Tests to see if the method is a test that should - * be run. Currently any method that starts with 'test' - * is a candidate. - * @param string $method Method name to try. - * @return boolean True if test method. - * @access protected - */ + /** + * Tests to see if the method is a test that should + * be run. Currently any method that starts with 'test' + * is a candidate. + * @param string $method Method name to try. + * @return boolean True if test method. + * @access protected + */ function _isTest($method) { return strtolower(substr($method, 0, 4)) == 'test'; } - /** - * Paints the start of a test method. - * @param string $test_name Name of test or other label. - * @access public - */ + /** + * Paints the start of a test method. + * @param string $test_name Name of test or other label. + * @access public + */ function paintMethodStart($test_name) { $this->_scorer->paintMethodStart($test_name); } - /** - * Paints the end of a test method. - * @param string $test_name Name of test or other label. - * @access public - */ + /** + * Paints the end of a test method. + * @param string $test_name Name of test or other label. + * @access public + */ function paintMethodEnd($test_name) { $this->_scorer->paintMethodEnd($test_name); } - /** - * Chains to the wrapped reporter. - * @param string $message Message is ignored. - * @access public - */ + /** + * Chains to the wrapped reporter. + * @param string $message Message is ignored. + * @access public + */ function paintPass($message) { $this->_scorer->paintPass($message); } - /** - * Chains to the wrapped reporter. - * @param string $message Message is ignored. - * @access public - */ + /** + * Chains to the wrapped reporter. + * @param string $message Message is ignored. + * @access public + */ function paintFail($message) { $this->_scorer->paintFail($message); } - /** - * Chains to the wrapped reporter. - * @param string $message Text of error formatted by - * the test case. - * @access public - */ + /** + * Chains to the wrapped reporter. + * @param string $message Text of error formatted by + * the test case. + * @access public + */ function paintError($message) { $this->_scorer->paintError($message); } - /** - * Chains to the wrapped reporter. - * @param Exception $exception Object thrown. - * @access public - */ + /** + * Chains to the wrapped reporter. + * @param Exception $exception Object thrown. + * @access public + */ function paintException($exception) { $this->_scorer->paintException($exception); } - /** - * Chains to the wrapped reporter. - * @param string $message Text to display. - * @access public - */ + /** + * Chains to the wrapped reporter. + * @param string $message Text to display. + * @access public + */ function paintMessage($message) { $this->_scorer->paintMessage($message); } - /** - * Chains to the wrapped reporter. - * @param string $message Text to display. - * @access public - */ + /** + * Chains to the wrapped reporter. + * @param string $message Text to display. + * @access public + */ function paintFormattedMessage($message) { $this->_scorer->paintFormattedMessage($message); } - /** - * Chains to the wrapped reporter. - * @param string $type Event type as text. - * @param mixed $payload Message or object. - * @return boolean Should return false if this - * type of signal should fail the - * test suite. - * @access public - */ + /** + * Chains to the wrapped reporter. + * @param string $type Event type as text. + * @param mixed $payload Message or object. + * @return boolean Should return false if this + * type of signal should fail the + * test suite. + * @access public + */ function paintSignal($type, &$payload) { $this->_scorer->paintSignal($type, $payload); } diff --git a/vendors/simpletest/scorer.php b/vendors/simpletest/scorer.php index fc79c4b59..29baf3260 100644 --- a/vendors/simpletest/scorer.php +++ b/vendors/simpletest/scorer.php @@ -1,29 +1,29 @@ _passes = 0; $this->_fails = 0; @@ -31,32 +31,32 @@ $this->_is_dry_run = false; } - /** - * Signals that the next evaluation will be a dry - * run. That is, the structure events will be - * recorded, but no tests will be run. - */ + /** + * Signals that the next evaluation will be a dry + * run. That is, the structure events will be + * recorded, but no tests will be run. + */ function makeDry($is_dry = true) { $this->_is_dry_run = $is_dry; } - /** - * The reporter has a veto on what should be run. - * @param string $test_case_name name of test case. - * @param string $method Name of test method. - * @access public - */ + /** + * The reporter has a veto on what should be run. + * @param string $test_case_name name of test case. + * @param string $method Name of test method. + * @access public + */ function shouldInvoke($test_case_name, $method) { return ! $this->_is_dry_run; } - /** - * Accessor for current status. Will be false - * if there have been any failures or exceptions. - * Used for command line tools. - * @return boolean True if no failures. - * @access public - */ + /** + * Accessor for current status. Will be false + * if there have been any failures or exceptions. + * Used for command line tools. + * @return boolean True if no failures. + * @access public + */ function getStatus() { if ($this->_exceptions + $this->_fails > 0) { return false; @@ -64,165 +64,165 @@ return true; } - /** - * Paints the start of a test method. - * @param string $test_name Name of test or other label. - * @access public - */ + /** + * Paints the start of a test method. + * @param string $test_name Name of test or other label. + * @access public + */ function paintMethodStart($test_name) { } - /** - * Paints the end of a test method. - * @param string $test_name Name of test or other label. - * @access public - */ + /** + * Paints the end of a test method. + * @param string $test_name Name of test or other label. + * @access public + */ function paintMethodEnd($test_name) { } - /** - * Paints the start of a test case. - * @param string $test_name Name of test or other label. - * @access public - */ + /** + * Paints the start of a test case. + * @param string $test_name Name of test or other label. + * @access public + */ function paintCaseStart($test_name) { } - /** - * Paints the end of a test case. - * @param string $test_name Name of test or other label. - * @access public - */ + /** + * Paints the end of a test case. + * @param string $test_name Name of test or other label. + * @access public + */ function paintCaseEnd($test_name) { } - /** - * Paints the start of a group test. - * @param string $test_name Name of test or other label. - * @param integer $size Number of test cases starting. - * @access public - */ + /** + * Paints the start of a group test. + * @param string $test_name Name of test or other label. + * @param integer $size Number of test cases starting. + * @access public + */ function paintGroupStart($test_name, $size) { } - /** - * Paints the end of a group test. - * @param string $test_name Name of test or other label. - * @access public - */ + /** + * Paints the end of a group test. + * @param string $test_name Name of test or other label. + * @access public + */ function paintGroupEnd($test_name) { } - /** - * Increments the pass count. - * @param string $message Message is ignored. - * @access public - */ + /** + * Increments the pass count. + * @param string $message Message is ignored. + * @access public + */ function paintPass($message) { $this->_passes++; } - /** - * Increments the fail count. - * @param string $message Message is ignored. - * @access public - */ + /** + * Increments the fail count. + * @param string $message Message is ignored. + * @access public + */ function paintFail($message) { $this->_fails++; } - /** - * Deals with PHP 4 throwing an error. - * @param string $message Text of error formatted by - * the test case. - * @access public - */ + /** + * Deals with PHP 4 throwing an error. + * @param string $message Text of error formatted by + * the test case. + * @access public + */ function paintError($message) { $this->paintException($message); } - /** - * Deals with PHP 5 throwing an exception - * This isn't really implemented yet. - * @param Exception $exception Object thrown. - * @access public - */ + /** + * Deals with PHP 5 throwing an exception + * This isn't really implemented yet. + * @param Exception $exception Object thrown. + * @access public + */ function paintException($exception) { $this->_exceptions++; } - /** - * Accessor for the number of passes so far. - * @return integer Number of passes. - * @access public - */ + /** + * Accessor for the number of passes so far. + * @return integer Number of passes. + * @access public + */ function getPassCount() { return $this->_passes; } - /** - * Accessor for the number of fails so far. - * @return integer Number of fails. - * @access public - */ + /** + * Accessor for the number of fails so far. + * @return integer Number of fails. + * @access public + */ function getFailCount() { return $this->_fails; } - /** - * Accessor for the number of untrapped errors - * so far. - * @return integer Number of exceptions. - * @access public - */ + /** + * Accessor for the number of untrapped errors + * so far. + * @return integer Number of exceptions. + * @access public + */ function getExceptionCount() { return $this->_exceptions; } - /** - * Paints a simple supplementary message. - * @param string $message Text to display. - * @access public - */ + /** + * Paints a simple supplementary message. + * @param string $message Text to display. + * @access public + */ function paintMessage($message) { } - /** - * Paints a formatted ASCII message such as a - * variable dump. - * @param string $message Text to display. - * @access public - */ + /** + * Paints a formatted ASCII message such as a + * variable dump. + * @param string $message Text to display. + * @access public + */ function paintFormattedMessage($message) { } - /** - * By default just ignores user generated events. - * @param string $type Event type as text. - * @param mixed $payload Message or object. - * @access public - */ - function paintSignal($type, &$payload) { + /** + * By default just ignores user generated events. + * @param string $type Event type as text. + * @param mixed $payload Message or object. + * @access public + */ + function paintSignal($type, $payload) { } } - /** - * Recipient of generated test messages that can display - * page footers and headers. Also keeps track of the - * test nesting. This is the main base class on which - * to build the finished test (page based) displays. - * @package SimpleTest - * @subpackage UnitTester - */ + /** + * Recipient of generated test messages that can display + * page footers and headers. Also keeps track of the + * test nesting. This is the main base class on which + * to build the finished test (page based) displays. + * @package SimpleTest + * @subpackage UnitTester + */ class SimpleReporter extends SimpleScorer { var $_test_stack; var $_size; var $_progress; - /** - * Starts the display with no results in. - * @access public - */ + /** + * Starts the display with no results in. + * @access public + */ function SimpleReporter() { $this->SimpleScorer(); $this->_test_stack = array(); @@ -230,15 +230,15 @@ $this->_progress = 0; } - /** - * Paints the start of a group test. Will also paint - * the page header and footer if this is the - * first test. Will stash the size if the first - * start. - * @param string $test_name Name of test that is starting. - * @param integer $size Number of test cases starting. - * @access public - */ + /** + * Paints the start of a group test. Will also paint + * the page header and footer if this is the + * first test. Will stash the size if the first + * start. + * @param string $test_name Name of test that is starting. + * @param integer $size Number of test cases starting. + * @access public + */ function paintGroupStart($test_name, $size) { if (! isset($this->_size)) { $this->_size = $size; @@ -249,13 +249,13 @@ $this->_test_stack[] = $test_name; } - /** - * Paints the end of a group test. Will paint the page - * footer if the stack of tests has unwound. - * @param string $test_name Name of test that is ending. - * @param integer $progress Number of test cases ending. - * @access public - */ + /** + * Paints the end of a group test. Will paint the page + * footer if the stack of tests has unwound. + * @param string $test_name Name of test that is ending. + * @param integer $progress Number of test cases ending. + * @access public + */ function paintGroupEnd($test_name) { array_pop($this->_test_stack); if (count($this->_test_stack) == 0) { @@ -263,14 +263,14 @@ } } - /** - * Paints the start of a test case. Will also paint - * the page header and footer if this is the - * first test. Will stash the size if the first - * start. - * @param string $test_name Name of test that is starting. - * @access public - */ + /** + * Paints the start of a test case. Will also paint + * the page header and footer if this is the + * first test. Will stash the size if the first + * start. + * @param string $test_name Name of test that is starting. + * @access public + */ function paintCaseStart($test_name) { if (! isset($this->_size)) { $this->_size = 1; @@ -281,12 +281,12 @@ $this->_test_stack[] = $test_name; } - /** - * Paints the end of a test case. Will paint the page - * footer if the stack of tests has unwound. - * @param string $test_name Name of test that is ending. - * @access public - */ + /** + * Paints the end of a test case. Will paint the page + * footer if the stack of tests has unwound. + * @param string $test_name Name of test that is ending. + * @access public + */ function paintCaseEnd($test_name) { $this->_progress++; array_pop($this->_test_stack); @@ -295,86 +295,84 @@ } } - /** - * Paints the start of a test method. - * @param string $test_name Name of test that is starting. - * @access public - */ + /** + * Paints the start of a test method. + * @param string $test_name Name of test that is starting. + * @access public + */ function paintMethodStart($test_name) { $this->_test_stack[] = $test_name; } - /** - * Paints the end of a test method. Will paint the page - * footer if the stack of tests has unwound. - * @param string $test_name Name of test that is ending. - * @access public - */ + /** + * Paints the end of a test method. Will paint the page + * footer if the stack of tests has unwound. + * @param string $test_name Name of test that is ending. + * @access public + */ function paintMethodEnd($test_name) { array_pop($this->_test_stack); } - /** - * Paints the test document header. - * @param string $test_name First test top level - * to start. - * @access public - * @abstract - */ + /** + * Paints the test document header. + * @param string $test_name First test top level + * to start. + * @access public + * @abstract + */ function paintHeader($test_name) { } - /** - * Paints the test document footer. - * @param string $test_name The top level test. - * @access public - * @abstract - */ + /** + * Paints the test document footer. + * @param string $test_name The top level test. + * @access public + * @abstract + */ function paintFooter($test_name) { } - /** - * Accessor for internal test stack. For - * subclasses that need to see the whole test - * history for display purposes. - * @return array List of methods in nesting order. - * @access public - */ + /** + * Accessor for internal test stack. For + * subclasses that need to see the whole test + * history for display purposes. + * @return array List of methods in nesting order. + * @access public + */ function getTestList() { return $this->_test_stack; } - /** - * Accessor for total test size in number - * of test cases. Null until the first - * test is started. - * @return integer Total number of cases at start. - * @access public - */ + /** + * Accessor for total test size in number + * of test cases. Null until the first + * test is started. + * @return integer Total number of cases at start. + * @access public + */ function getTestCaseCount() { return $this->_size; } - /** - * Accessor for the number of test cases - * completed so far. - * @return integer Number of ended cases. - * @access public - */ + /** + * Accessor for the number of test cases + * completed so far. + * @return integer Number of ended cases. + * @access public + */ function getTestCaseProgress() { return $this->_progress; } - /** - * Static check for running in the comand line. - * @return boolean True if CLI. - * @access public - * @static - */ + /** + * Static check for running in the comand line. + * @return boolean True if CLI. + * @access public + * @static + */ function inCli() { - $method = getenv('REQUEST_METHOD'); - return empty($method); - // return php_sapi_name() == 'cli'; + return php_sapi_name() == 'cli'; } } ?> \ No newline at end of file diff --git a/vendors/simpletest/selector.php b/vendors/simpletest/selector.php new file mode 100644 index 000000000..7efaafa90 --- /dev/null +++ b/vendors/simpletest/selector.php @@ -0,0 +1,100 @@ +_name = $name; + } + + /** + * 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 SimpleByLabel { + var $_label; + + /** + * Stashes the name for later comparison. + * @param string $label Visible text to match. + */ + function SimpleByLabel($label) { + $this->_label = $label; + } + + /** + * Comparison. Compares visible text of widget or + * related label. + * @param SimpleWidget $widget Control to compare. + * @access public + */ + function isMatch($widget) { + if (! method_exists($widget, 'isLabel')) { + return false; + } + return $widget->isLabel($this->_label); + } + } + + /** + * Used to extract form elements for testing against. + * Searches dy id attribute. + * @package SimpleTest + * @subpackage WebTester + */ + class SimpleById { + var $_id; + + /** + * Stashes the name for later comparison. + * @param string $id ID atribute to match. + */ + function SimpleById($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); + } + } +?> \ No newline at end of file diff --git a/vendors/simpletest/shell_tester.php b/vendors/simpletest/shell_tester.php index 1c11886b2..e217423de 100644 --- a/vendors/simpletest/shell_tester.php +++ b/vendors/simpletest/shell_tester.php @@ -1,85 +1,85 @@ _output = false; } - /** - * Actually runs the command. Does not trap the - * error stream output as this need PHP 4.3+. - * @param string $command The actual command line - * to run. - * @return integer Exit code. - * @access public - */ + /** + * Actually runs the command. Does not trap the + * error stream output as this need PHP 4.3+. + * @param string $command The actual command line + * to run. + * @return integer Exit code. + * @access public + */ function execute($command) { $this->_output = false; exec($command, $this->_output, $ret); return $ret; } - /** - * Accessor for the last output. - * @return string Output as text. - * @access public - */ + /** + * Accessor for the last output. + * @return string Output as text. + * @access public + */ function getOutput() { return implode("\n", $this->_output); } - /** - * Accessor for the last output. - * @return array Output as array of lines. - * @access public - */ - function getOutputAsList() { - return $this->_output; - } + /** + * Accessor for the last output. + * @return array Output as array of lines. + * @access public + */ + function getOutputAsList() { + return $this->_output; + } } - /** - * Test case for testing of command line scripts and - * utilities. Usually scripts taht are external to the - * PHP code, but support it in some way. - * @package SimpleTest - * @subpackage UnitTester - */ + /** + * Test case for testing of command line scripts and + * utilities. Usually scripts taht are external to the + * PHP code, but support it in some way. + * @package SimpleTest + * @subpackage UnitTester + */ class ShellTestCase extends SimpleTestCase { var $_current_shell; var $_last_status; var $_last_command; - /** - * Creates an empty test case. Should be subclassed - * with test methods for a functional test case. - * @param string $label Name of test case. Will use - * the class name if none specified. - * @access public - */ + /** + * Creates an empty test case. Should be subclassed + * with test methods for a functional test case. + * @param string $label Name of test case. Will use + * the class name if none specified. + * @access public + */ function ShellTestCase($label = false) { $this->SimpleTestCase($label); $this->_current_shell = &$this->_createShell(); @@ -87,12 +87,12 @@ $this->_last_command = ''; } - /** - * Executes a command and buffers the results. - * @param string $command Command to run. - * @return boolean True if zero exit code. - * @access public - */ + /** + * Executes a command and buffers the results. + * @param string $command Command to run. + * @return boolean True if zero exit code. + * @access public + */ function execute($command) { $shell = &$this->_getShell(); $this->_last_status = $shell->execute($command); @@ -100,42 +100,76 @@ return ($this->_last_status === 0); } - /** - * Dumps the output of the last command. - * @access public - */ + /** + * Dumps the output of the last command. + * @access public + */ function dumpOutput() { $this->dump($this->getOutput()); } - /** - * Accessor for the last output. - * @return string Output as text. - * @access public - */ - function getOutput() { + /** + * Accessor for the last output. + * @return string Output as text. + * @access public + */ + function getOutput() { $shell = &$this->_getShell(); return $shell->getOutput(); - } + } - /** - * Accessor for the last output. - * @return array Output as array of lines. - * @access public - */ - function getOutputAsList() { + /** + * Accessor for the last output. + * @return array Output as array of lines. + * @access public + */ + function getOutputAsList() { $shell = &$this->_getShell(); return $shell->getOutputAsList(); - } + } + + /** + * Will trigger a pass if the two parameters have + * the same value only. Otherwise a fail. This + * is for testing hand extracted text, etc. + * @param mixed $first Value to compare. + * @param mixed $second Value to compare. + * @param string $message Message to display. + * @return boolean True on pass + * @access public + */ + function assertEqual($first, $second, $message = "%s") { + return $this->assert( + new EqualExpectation($first), + $second, + $message); + } + + /** + * Will trigger a pass if the two parameters have + * a different value. Otherwise a fail. This + * is for testing hand extracted text, etc. + * @param mixed $first Value to compare. + * @param mixed $second Value to compare. + * @param string $message Message to display. + * @return boolean True on pass + * @access public + */ + function assertNotEqual($first, $second, $message = "%s") { + return $this->assert( + new NotEqualExpectation($first), + $second, + $message); + } - /** - * Tests the last status code from the shell. - * @param integer $status Expected status of last - * command. - * @param string $message Message to display. - * @return boolean True if pass. - * @access public - */ + /** + * Tests the last status code from the shell. + * @param integer $status Expected status of last + * command. + * @param string $message Message to display. + * @return boolean True if pass. + * @access public + */ function assertExitCode($status, $message = "%s") { $message = sprintf($message, "Expected status code of [$status] from [" . $this->_last_command . "], but got [" . @@ -143,129 +177,130 @@ return $this->assertTrue($status === $this->_last_status, $message); } - /** - * Attempt to exactly match the combined STDERR and - * STDOUT output. - * @param string $expected Expected output. - * @param string $message Message to display. - * @return boolean True if pass. - * @access public - */ + /** + * Attempt to exactly match the combined STDERR and + * STDOUT output. + * @param string $expected Expected output. + * @param string $message Message to display. + * @return boolean True if pass. + * @access public + */ function assertOutput($expected, $message = "%s") { $shell = &$this->_getShell(); - return $this->assertExpectation( + return $this->assert( new EqualExpectation($expected), $shell->getOutput(), $message); } - /** - * Scans the output for a Perl regex. If found - * anywhere it passes, else it fails. - * @param string $pattern Regex to search for. - * @param string $message Message to display. - * @return boolean True if pass. - * @access public - */ + /** + * Scans the output for a Perl regex. If found + * anywhere it passes, else it fails. + * @param string $pattern Regex to search for. + * @param string $message Message to display. + * @return boolean True if pass. + * @access public + */ function assertOutputPattern($pattern, $message = "%s") { $shell = &$this->_getShell(); - return $this->assertExpectation( - new WantedPatternExpectation($pattern), + return $this->assert( + new PatternExpectation($pattern), $shell->getOutput(), $message); } - /** - * If a Perl regex is found anywhere in the current - * output then a failure is generated, else a pass. - * @param string $pattern Regex to search for. - * @param $message Message to display. - * @return boolean True if pass. - * @access public - */ + /** + * If a Perl regex is found anywhere in the current + * output then a failure is generated, else a pass. + * @param string $pattern Regex to search for. + * @param $message Message to display. + * @return boolean True if pass. + * @access public + */ function assertNoOutputPattern($pattern, $message = "%s") { $shell = &$this->_getShell(); - return $this->assertExpectation( - new UnwantedPatternExpectation($pattern), + return $this->assert( + new NoPatternExpectation($pattern), $shell->getOutput(), $message); } - /** - * File existence check. - * @param string $path Full filename and path. - * @param string $message Message to display. - * @return boolean True if pass. - * @access public - */ + /** + * File existence check. + * @param string $path Full filename and path. + * @param string $message Message to display. + * @return boolean True if pass. + * @access public + */ function assertFileExists($path, $message = "%s") { $message = sprintf($message, "File [$path] should exist"); return $this->assertTrue(file_exists($path), $message); } - /** - * File non-existence check. - * @param string $path Full filename and path. - * @param string $message Message to display. - * @return boolean True if pass. - * @access public - */ + /** + * File non-existence check. + * @param string $path Full filename and path. + * @param string $message Message to display. + * @return boolean True if pass. + * @access public + */ function assertFileNotExists($path, $message = "%s") { $message = sprintf($message, "File [$path] should not exist"); return $this->assertFalse(file_exists($path), $message); } - /** - * Scans a file for a Perl regex. If found - * anywhere it passes, else it fails. - * @param string $pattern Regex to search for. - * @param string $path Full filename and path. - * @param string $message Message to display. - * @return boolean True if pass. - * @access public - */ + /** + * Scans a file for a Perl regex. If found + * anywhere it passes, else it fails. + * @param string $pattern Regex to search for. + * @param string $path Full filename and path. + * @param string $message Message to display. + * @return boolean True if pass. + * @access public + */ function assertFilePattern($pattern, $path, $message = "%s") { $shell = &$this->_getShell(); - return $this->assertExpectation( - new WantedPatternExpectation($pattern), + return $this->assert( + new PatternExpectation($pattern), implode('', file($path)), $message); } - /** - * If a Perl regex is found anywhere in the named - * file then a failure is generated, else a pass. - * @param string $pattern Regex to search for. - * @param string $path Full filename and path. - * @param string $message Message to display. - * @return boolean True if pass. - * @access public - */ + /** + * If a Perl regex is found anywhere in the named + * file then a failure is generated, else a pass. + * @param string $pattern Regex to search for. + * @param string $path Full filename and path. + * @param string $message Message to display. + * @return boolean True if pass. + * @access public + */ function assertNoFilePattern($pattern, $path, $message = "%s") { $shell = &$this->_getShell(); - return $this->assertExpectation( - new UnwantedPatternExpectation($pattern), + return $this->assert( + new NoPatternExpectation($pattern), implode('', file($path)), $message); } - /** - * Accessor for current shell. Used for testing the - * the tester itself. - * @return Shell Current shell. - * @access protected - */ + /** + * Accessor for current shell. Used for testing the + * the tester itself. + * @return Shell Current shell. + * @access protected + */ function &_getShell() { return $this->_current_shell; } - /** - * Factory for the shell to run the command on. - * @return Shell New shell object. - * @access protected - */ + /** + * Factory for the shell to run the command on. + * @return Shell New shell object. + * @access protected + */ function &_createShell() { - return new SimpleShell(); + $shell = &new SimpleShell(); + return $shell; } } ?> \ No newline at end of file diff --git a/vendors/simpletest/simple_test.php b/vendors/simpletest/simple_test.php index 0154d6691..46a255997 100644 --- a/vendors/simpletest/simple_test.php +++ b/vendors/simpletest/simple_test.php @@ -1,15 +1,15 @@ _label = $label ? $label : get_class($this); - $this->_runner = false; + if ($label) { + $this->_label = $label; + } } - /** - * Accessor for the test name for subclasses. - * @return string Name of the test. - * @access public - */ + /** + * Accessor for the test name for subclasses. + * @return string Name of the test. + * @access public + */ function getLabel() { - return $this->_label; + return $this->_label ? $this->_label : get_class($this); } - /** - * Used to invoke the single tests. - * @return SimpleInvoker Individual test runner. - * @access public - */ + /** + * Used to invoke the single tests. + * @return SimpleInvoker Individual test runner. + * @access public + */ function &createInvoker() { - return new SimpleErrorTrappingInvoker(new SimpleInvoker($this)); + $invoker = &new SimpleErrorTrappingInvoker(new SimpleInvoker($this)); + return $invoker; } - /** - * Can modify the incoming reporter so as to run - * the tests differently. This version simply - * passes it straight through. - * @param SimpleReporter $reporter Incoming observer. - * @return SimpleReporter - * @access protected - */ + /** + * Can modify the incoming reporter so as to run + * the tests differently. This version simply + * passes it straight through. + * @param SimpleReporter $reporter Incoming observer. + * @return SimpleReporter + * @access protected + */ function &_createRunner(&$reporter) { - return new SimpleRunner($this, $reporter); + $runner = &new SimpleRunner($this, $reporter); + return $runner; } - /** - * Uses reflection to run every method within itself - * starting with the string "test" unless a method - * is specified. - * @param SimpleReporter $reporter Current test reporter. - * @access public - */ + /** + * Uses reflection to run every method within itself + * starting with the string "test" unless a method + * is specified. + * @param SimpleReporter $reporter Current test reporter. + * @access public + */ function run(&$reporter) { $reporter->paintCaseStart($this->getLabel()); $this->_runner = &$this->_createRunner($reporter); @@ -89,126 +92,133 @@ return $reporter->getStatus(); } - /** - * Sets up unit test wide variables at the start - * of each test method. To be overridden in - * actual user test cases. - * @access public - */ + /** + * Sets up unit test wide variables at the start + * of each test method. To be overridden in + * actual user test cases. + * @access public + */ function setUp() { } - /** - * Clears the data set in the setUp() method call. - * To be overridden by the user in actual user test cases. - * @access public - */ + /** + * Clears the data set in the setUp() method call. + * To be overridden by the user in actual user test cases. + * @access public + */ function tearDown() { } - /** - * Sends a pass event with a message. - * @param string $message Message to send. - * @access public - */ + /** + * Sends a pass event with a message. + * @param string $message Message to send. + * @access public + */ function pass($message = "Pass") { $this->_runner->paintPass($message . $this->getAssertionLine(' at line [%d]')); + return true; } - /** - * Sends a fail event with a message. - * @param string $message Message to send. - * @access public - */ + /** + * Sends a fail event with a message. + * @param string $message Message to send. + * @access public + */ function fail($message = "Fail") { $this->_runner->paintFail($message . $this->getAssertionLine(' at line [%d]')); + return false; } - /** - * Formats a PHP error and dispatches it to the - * runner. - * @param integer $severity PHP error code. - * @param string $message Text of error. - * @param string $file File error occoured in. - * @param integer $line Line number of error. - * @param hash $globals PHP super global arrays. - * @access public - */ + /** + * Formats a PHP error and dispatches it to the + * runner. + * @param integer $severity PHP error code. + * @param string $message Text of error. + * @param string $file File error occoured in. + * @param integer $line Line number of error. + * @param hash $globals PHP super global arrays. + * @access public + */ function error($severity, $message, $file, $line, $globals) { $severity = SimpleErrorQueue::getSeverityAsString($severity); $this->_runner->paintError( "Unexpected PHP error [$message] severity [$severity] in [$file] line [$line]"); } - /** - * Sends a user defined event to the test runner. - * This is for small scale extension where - * both the test case and either the runner or - * display are subclassed. - * @param string $type Type of event. - * @param mixed $payload Object or message to deliver. - * @access public - */ + /** + * Sends a user defined event to the test runner. + * This is for small scale extension where + * both the test case and either the runner or + * display are subclassed. + * @param string $type Type of event. + * @param mixed $payload Object or message to deliver. + * @access public + */ function signal($type, &$payload) { $this->_runner->paintSignal($type, $payload); } - /** - * Cancels any outstanding errors. - * @access public - */ + /** + * Cancels any outstanding errors. + * @access public + */ function swallowErrors() { $queue = &SimpleErrorQueue::instance(); $queue->clear(); } - /** - * Runs an expectation directly, for extending the - * tests with new expectation classes. - * @param SimpleExpectation $expectation Expectation subclass. - * @param mixed $test_value Value to compare. - * @param string $message Message to display. - * @return boolean True on pass - * @access public - */ - function assertExpectation(&$expectation, $test_value, $message = '%s') { + /** + * Runs an expectation directly, for extending the + * tests with new expectation classes. + * @param SimpleExpectation $expectation Expectation subclass. + * @param mixed $compare Value to compare. + * @param string $message Message to display. + * @return boolean True on pass + * @access public + */ + function assert(&$expectation, $compare, $message = '%s') { return $this->assertTrue( - $expectation->test($test_value), - sprintf($message, $expectation->overlayMessage($test_value))); + $expectation->test($compare), + sprintf($message, $expectation->overlayMessage($compare))); + } + + /** + * @deprecated + */ + function assertExpectation(&$expectation, $compare, $message = '%s') { + return $this->assert($expectation, $compare, $message); } - /** - * Called from within the test methods to register - * passes and failures. - * @param boolean $result Pass on true. - * @param string $message Message to display describing - * the test state. - * @return boolean True on pass - * @access public - */ + /** + * Called from within the test methods to register + * passes and failures. + * @param boolean $result Pass on true. + * @param string $message Message to display describing + * the test state. + * @return boolean True on pass + * @access public + */ function assertTrue($result, $message = false) { if (! $message) { $message = 'True assertion got ' . ($result ? 'True' : 'False'); } if ($result) { - $this->pass($message); - return true; + return $this->pass($message); } else { - $this->fail($message); - return false; + return $this->fail($message); } } - /** - * Will be true on false and vice versa. False - * is the PHP definition of false, so that null, - * empty strings, zero and an empty array all count - * as false. - * @param boolean $result Pass on false. - * @param string $message Message to display. - * @return boolean True on pass - * @access public - */ + /** + * Will be true on false and vice versa. False + * is the PHP definition of false, so that null, + * empty strings, zero and an empty array all count + * as false. + * @param boolean $result Pass on false. + * @param string $message Message to display. + * @return boolean True on pass + * @access public + */ function assertFalse($result, $message = false) { if (! $message) { $message = 'False assertion got ' . ($result ? 'True' : 'False'); @@ -216,16 +226,16 @@ return $this->assertTrue(! $result, $message); } - /** - * 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 assert* - * method embedded in format string. - * @access public - */ + /** + * 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 assert* + * method embedded in format string. + * @access public + */ function getAssertionLine($format = '%d', $stack = false) { if ($stack === false) { $stack = SimpleTestCompatibility::getStackTrace(); @@ -233,15 +243,15 @@ return SimpleDumper::getFormattedAssertionLine($stack, $format); } - /** - * Sends a formatted dump of a variable to the - * test suite for those emergency debugging - * situations. - * @param mixed $variable Variable to display. - * @param string $message Message to display. - * @return mixed The original variable. - * @access public - */ + /** + * Sends a formatted dump of a variable to the + * test suite for those emergency debugging + * situations. + * @param mixed $variable Variable to display. + * @param string $message Message to display. + * @return mixed The original variable. + * @access public + */ function dump($variable, $message = false) { $formatted = SimpleDumper::dump($variable); if ($message) { @@ -251,94 +261,98 @@ return $variable; } - /** - * Dispatches a text message straight to the - * test suite. Useful for status bar displays. - * @param string $message Message to show. - * @access public - */ + /** + * Dispatches a text message straight to the + * test suite. Useful for status bar displays. + * @param string $message Message to show. + * @access public + */ function sendMessage($message) { $this->_runner->PaintMessage($message); } - /** - * Accessor for the number of subtests. - * @return integer Number of test cases. - * @access public - * @static - */ + /** + * Accessor for the number of subtests. + * @return integer Number of test cases. + * @access public + * @static + */ function getSize() { return 1; } } - /** - * This is a composite test class for combining - * test cases and other RunnableTest classes into - * a group test. - * @package SimpleTest - * @subpackage UnitTester - */ + /** + * This is a composite test class for combining + * test cases and other RunnableTest classes into + * a group test. + * @package SimpleTest + * @subpackage UnitTester + */ class GroupTest { var $_label; var $_test_cases; var $_old_track_errors; var $_xdebug_is_enabled; - /** - * Sets the name of the test suite. - * @param string $label Name sent at the start and end - * of the test. - * @access public - */ - function GroupTest($label) { - $this->_label = $label; + /** + * Sets the name of the test suite. + * @param string $label Name sent at the start and end + * of the test. + * @access public + */ + function GroupTest($label = false) { + $this->_label = $label ? $label : get_class($this); $this->_test_cases = array(); $this->_old_track_errors = ini_get('track_errors'); $this->_xdebug_is_enabled = function_exists('xdebug_is_enabled') ? xdebug_is_enabled() : false; } - /** - * Accessor for the test name for subclasses. - * @return string Name of the test. - * @access public - */ + /** + * Accessor for the test name for subclasses. + * @return string Name of the test. + * @access public + */ function getLabel() { return $this->_label; } - /** - * Adds a test into the suite. Can be either a group - * test or some other unit test. - * @param SimpleTestCase $test_case Suite or individual test - * case implementing the - * runnable test interface. - * @access public - */ + /** + * Adds a test into the suite. Can be either a group + * test or some other unit test. + * @param SimpleTestCase $test_case Suite or individual test + * case implementing the + * runnable test interface. + * @access public + */ function addTestCase(&$test_case) { $this->_test_cases[] = &$test_case; } - /** - * Adds a test into the suite by class name. The class will - * be instantiated as needed. - * @param SimpleTestCase $test_case Suite or individual test - * case implementing the - * runnable test interface. - * @access public - */ + /** + * Adds a test into the suite by class name. The class will + * be instantiated as needed. + * @param SimpleTestCase $test_case Suite or individual test + * case implementing the + * runnable test interface. + * @access public + */ function addTestClass($class) { - $this->_test_cases[] = $class; + if ($this->_getBaseTestCase($class) == 'grouptest') { + $this->_test_cases[] = &new $class(); + } else { + $this->_test_cases[] = $class; + } } - /** - * Builds a group test from a library of test cases. - * The new group is composed into this one. - * @param string $test_file File name of library with - * test case classes. - * @access public - */ + /** + * Builds a group test from a library of test cases. + * The new group is composed into this one. + * @param string $test_file File name of library with + * test case classes. + * @access public + */ function addTestFile($test_file) { $existing_classes = get_declared_classes(); if ($error = $this->_requireWithError($test_file)) { @@ -353,34 +367,34 @@ $this->addTestCase($this->_createGroupFromClasses($test_file, $classes)); } - /** - * Requires a source file recording any syntax errors. - * @param string $file File name to require in. - * @return string/boolean An error message on failure or false - * if no errors. - * @access private - */ + /** + * Requires a source file recording any syntax errors. + * @param string $file File name to require in. + * @return string/boolean An error message on failure or false + * if no errors. + * @access private + */ function _requireWithError($file) { $this->_enableErrorReporting(); include($file); $error = isset($php_errormsg) ? $php_errormsg : false; $this->_disableErrorReporting(); - $self_inflicted = array( + $self_inflicted_errors = array( 'Assigning the return value of new by reference is deprecated', 'var: Deprecated. Please use the public/private/protected modifiers'); - if (in_array($error, $self_inflicted)) { + if (in_array($error, $self_inflicted_errors)) { return false; } return $error; } - /** - * Sets up detection of parse errors. Note that XDebug - * interferes with this and has to be disabled. This is - * to make sure the correct error code is returned - * from unattended scripts. - * @access private - */ + /** + * Sets up detection of parse errors. Note that XDebug + * interferes with this and has to be disabled. This is + * to make sure the correct error code is returned + * from unattended scripts. + * @access private + */ function _enableErrorReporting() { if ($this->_xdebug_is_enabled) { xdebug_disable(); @@ -388,12 +402,12 @@ ini_set('track_errors', true); } - /** - * Resets detection of parse errors to their old values. - * This is to make sure the correct error code is returned - * from unattended scripts. - * @access private - */ + /** + * Resets detection of parse errors to their old values. + * This is to make sure the correct error code is returned + * from unattended scripts. + * @access private + */ function _disableErrorReporting() { ini_set('track_errors', $this->_old_track_errors); if ($this->_xdebug_is_enabled) { @@ -401,37 +415,36 @@ } } - /** - * Calculates the incoming test cases from a before - * and after list of loaded classes. - * @param array $existing_classes Classes before require(). - * @param array $new_classes Classes after require(). - * @return array New classes which are test - * cases that shouldn't be ignored. - * @access private - */ + /** + * Calculates the incoming test cases from a before + * and after list of loaded classes. + * @param array $existing_classes Classes before require(). + * @param array $new_classes Classes after require(). + * @return array New classes which are test + * cases that shouldn't be ignored. + * @access private + */ function _selectRunnableTests($existing_classes, $new_classes) { $classes = array(); foreach ($new_classes as $class) { if (in_array($class, $existing_classes)) { continue; } - if (! $this->_isTestCase($class)) { - continue; + if ($this->_getBaseTestCase($class)) { + $classes[] = $class; } - $classes[] = $class; } return $classes; } - /** - * Builds a group test from a class list. - * @param string $title Title of new group. - * @param array $classes Test classes. - * @return GroupTest Group loaded with the new - * test cases. - * @access private - */ + /** + * Builds a group test from a class list. + * @param string $title Title of new group. + * @param array $classes Test classes. + * @return GroupTest Group loaded with the new + * test cases. + * @access private + */ function _createGroupFromClasses($title, $classes) { $group = new GroupTest($title); foreach ($classes as $class) { @@ -443,28 +456,39 @@ return $group; } - /** - * Test to see if a class is derived from the - * TestCase class. - * @param string $class Class name. - * @access private - */ - function _isTestCase($class) { + /** + * Test to see if a class is derived from the + * SimpleTestCase class. + * @param string $class Class name. + * @access private + */ + function _getBaseTestCase($class) { while ($class = get_parent_class($class)) { $class = strtolower($class); if ($class == "simpletestcase" || $class == "grouptest") { - return true; + return $class; } } return false; } + + /** + * Delegates to a visiting collector to add test + * files. + * @param string $path Path to scan from. + * @param SimpleCollector $collector Directory scanner. + * @access public + */ + function collect($path, &$collector) { + $collector->collect($this, $path); + } - /** - * Invokes run() on all of the held test cases, instantiating - * them if necessary. - * @param SimpleReporter $reporter Current test reporter. - * @access public - */ + /** + * Invokes run() on all of the held test cases, instantiating + * them if necessary. + * @param SimpleReporter $reporter Current test reporter. + * @access public + */ function run(&$reporter) { $reporter->paintGroupStart($this->getLabel(), $this->getSize()); for ($i = 0, $count = count($this->_test_cases); $i < $count; $i++) { @@ -480,11 +504,11 @@ return $reporter->getStatus(); } - /** - * Number of contained test cases. - * @return integer Total count of cases in the group. - * @access public - */ + /** + * Number of contained test cases. + * @return integer Total count of cases in the group. + * @access public + */ function getSize() { $count = 0; foreach ($this->_test_cases as $case) { @@ -498,41 +522,41 @@ } } - /** - * This is a failing group test for when a test suite hasn't - * loaded properly. - * @package SimpleTest - * @subpackage UnitTester - */ + /** + * This is a failing group test for when a test suite hasn't + * loaded properly. + * @package SimpleTest + * @subpackage UnitTester + */ class BadGroupTest { var $_label; var $_error; - /** - * Sets the name of the test suite and error message. - * @param string $label Name sent at the start and end - * of the test. - * @access public - */ + /** + * Sets the name of the test suite and error message. + * @param string $label Name sent at the start and end + * of the test. + * @access public + */ function BadGroupTest($label, $error) { $this->_label = $label; $this->_error = $error; } - /** - * Accessor for the test name for subclasses. - * @return string Name of the test. - * @access public - */ + /** + * Accessor for the test name for subclasses. + * @return string Name of the test. + * @access public + */ function getLabel() { return $this->_label; } - /** - * Sends a single error to the reporter. - * @param SimpleReporter $reporter Current test reporter. - * @access public - */ + /** + * Sends a single error to the reporter. + * @param SimpleReporter $reporter Current test reporter. + * @access public + */ function run(&$reporter) { $reporter->paintGroupStart($this->getLabel(), $this->getSize()); $reporter->paintFail('Bad GroupTest [' . $this->getLabel() . @@ -541,11 +565,11 @@ return $reporter->getStatus(); } - /** - * Number of contained test cases. Always zero. - * @return integer Total count of cases in the group. - * @access public - */ + /** + * Number of contained test cases. Always zero. + * @return integer Total count of cases in the group. + * @access public + */ function getSize() { return 0; } diff --git a/vendors/simpletest/socket.php b/vendors/simpletest/socket.php index f56bcf5ad..9355f3f42 100644 --- a/vendors/simpletest/socket.php +++ b/vendors/simpletest/socket.php @@ -1,88 +1,88 @@ _clearError(); } - /** - * Test for an outstanding error. - * @return boolean True if there is an error. - * @access public - */ + /** + * Test for an outstanding error. + * @return boolean True if there is an error. + * @access public + */ function isError() { return ($this->_error != ''); } - /** - * Accessor for an outstanding error. - * @return string Empty string if no error otherwise - * the error message. - * @access public - */ + /** + * Accessor for an outstanding error. + * @return string Empty string if no error otherwise + * the error message. + * @access public + */ function getError() { return $this->_error; } - /** - * Sets the internal error. - * @param string Error message to stash. - * @access protected - */ + /** + * Sets the internal error. + * @param string Error message to stash. + * @access protected + */ function _setError($error) { $this->_error = $error; } - /** - * Resets the error state to no error. - * @access protected - */ + /** + * Resets the error state to no error. + * @access protected + */ function _clearError() { $this->_setError(''); } } - /** - * Wrapper for TCP/IP socket. - * @package SimpleTest - * @subpackage WebTester - */ + /** + * Wrapper for TCP/IP socket. + * @package SimpleTest + * @subpackage WebTester + */ class SimpleSocket extends SimpleStickyError { var $_handle; var $_is_open; var $_sent; - /** - * Opens a socket for reading and writing. - * @param string $host Hostname to send request to. - * @param integer $port Port on remote machine to open. - * @param integer $timeout Connection timeout in seconds. - * @access public - */ + /** + * Opens a socket for reading and writing. + * @param string $host Hostname to send request to. + * @param integer $port Port on remote machine to open. + * @param integer $timeout Connection timeout in seconds. + * @access public + */ function SimpleSocket($host, $port, $timeout) { $this->SimpleStickyError(); $this->_is_open = false; @@ -95,12 +95,12 @@ SimpleTestCompatibility::setTimeout($this->_handle, $timeout); } - /** - * Writes some data to the socket and saves alocal copy. - * @param string $message String to send to socket. - * @return boolean True if successful. - * @access public - */ + /** + * Writes some data to the socket and saves alocal copy. + * @param string $message String to send to socket. + * @return boolean True if successful. + * @access public + */ function write($message) { if ($this->isError() || ! $this->isOpen()) { return false; @@ -118,15 +118,15 @@ return true; } - /** - * Reads data from the socket. The error suppresion - * is a workaround for PHP4 always throwing a warning - * with a secure socket. - * @param integer $block_size Size of chunk to read. - * @return integer Incoming bytes. False - * on error. - * @access public - */ + /** + * Reads data from the socket. The error suppresion + * is a workaround for PHP4 always throwing a warning + * with a secure socket. + * @param integer $block_size Size of chunk to read. + * @return string/boolean Incoming bytes. False + * on error. + * @access public + */ function read($block_size = 255) { if ($this->isError() || ! $this->isOpen()) { return false; @@ -139,76 +139,76 @@ return $raw; } - /** - * Accessor for socket open state. - * @return boolean True if open. - * @access public - */ + /** + * Accessor for socket open state. + * @return boolean True if open. + * @access public + */ function isOpen() { return $this->_is_open; } - /** - * Closes the socket preventing further reads. - * Cannot be reopened once closed. - * @return boolean True if successful. - * @access public - */ + /** + * Closes the socket preventing further reads. + * Cannot be reopened once closed. + * @return boolean True if successful. + * @access public + */ function close() { $this->_is_open = false; return fclose($this->_handle); } - /** - * Accessor for content so far. - * @return string Bytes sent only. - * @access public - */ + /** + * Accessor for content so far. + * @return string Bytes sent only. + * @access public + */ function getSent() { return $this->_sent; } - /** - * Actually opens the low level socket. - * @param string $host Host to connect to. - * @param integer $port Port on host. - * @param integer $error_number Recipient of error code. - * @param string $error Recipoent of error message. - * @param integer $timeout Maximum time to wait for connection. - * @access protected - */ + /** + * Actually opens the low level socket. + * @param string $host Host to connect to. + * @param integer $port Port on host. + * @param integer $error_number Recipient of error code. + * @param string $error Recipoent of error message. + * @param integer $timeout Maximum time to wait for connection. + * @access protected + */ function _openSocket($host, $port, &$error_number, &$error, $timeout) { return @fsockopen($host, $port, $error_number, $error, $timeout); } } - /** - * Wrapper for TCP/IP socket over TLS. - * @package SimpleTest - * @subpackage WebTester - */ + /** + * Wrapper for TCP/IP socket over TLS. + * @package SimpleTest + * @subpackage WebTester + */ class SimpleSecureSocket extends SimpleSocket { - /** - * Opens a secure socket for reading and writing. - * @param string $host Hostname to send request to. - * @param integer $port Port on remote machine to open. - * @param integer $timeout Connection timeout in seconds. - * @access public - */ + /** + * Opens a secure socket for reading and writing. + * @param string $host Hostname to send request to. + * @param integer $port Port on remote machine to open. + * @param integer $timeout Connection timeout in seconds. + * @access public + */ function SimpleSecureSocket($host, $port, $timeout) { $this->SimpleSocket($host, $port, $timeout); } - /** - * Actually opens the low level socket. - * @param string $host Host to connect to. - * @param integer $port Port on host. - * @param integer $error_number Recipient of error code. - * @param string $error Recipient of error message. - * @param integer $timeout Maximum time to wait for connection. - * @access protected - */ + /** + * Actually opens the low level socket. + * @param string $host Host to connect to. + * @param integer $port Port on host. + * @param integer $error_number Recipient of error code. + * @param string $error Recipient of error message. + * @param integer $timeout Maximum time to wait for connection. + * @access protected + */ function _openSocket($host, $port, &$error_number, &$error, $timeout) { return parent::_openSocket("tls://$host", $port, $error_number, $error, $timeout); } diff --git a/vendors/simpletest/tag.php b/vendors/simpletest/tag.php index e3c2e57d8..e040b0f98 100644 --- a/vendors/simpletest/tag.php +++ b/vendors/simpletest/tag.php @@ -1,92 +1,93 @@ _name = $name; + $this->_name = strtolower(trim($name)); $this->_attributes = $attributes; $this->_content = ''; } - /** - * Check to see if the tag can have both start and - * end tags with content in between. - * @return boolean True if content allowed. - * @access public - */ + /** + * Check to see if the tag can have both start and + * end tags with content in between. + * @return boolean True if content allowed. + * @access public + */ function expectEndTag() { return true; } - /** - * Appends string content to the current content. - * @param string $content Additional text. - * @access public - */ + /** + * Appends string content to the current content. + * @param string $content Additional text. + * @access public + */ function addContent($content) { $this->_content .= (string)$content; } - /** - * Adds an enclosed tag to the content. - * @param SimpleTag $tag New tag. - * @access public - */ + /** + * Adds an enclosed tag to the content. + * @param SimpleTag $tag New tag. + * @access public + */ function addTag(&$tag) { } - /** - * Accessor for tag name. - * @return string Name of tag. - * @access public - */ + /** + * Accessor for tag name. + * @return string Name of tag. + * @access public + */ function getTagName() { return $this->_name; } - /** - * List oflegal child elements. - * @return array List of element names. - * @access public - */ + /** + * List of legal child elements. + * @return array List of element names. + * @access public + */ function getChildElements() { return array(); } - /** - * Accessor for an attribute. - * @param string $label Attribute name. - * @return string Attribute value. - * @access public - */ + /** + * Accessor for an attribute. + * @param string $label Attribute name. + * @return string Attribute value. + * @access public + */ function getAttribute($label) { $label = strtolower($label); if (! isset($this->_attributes[$label])) { @@ -98,85 +99,85 @@ return (string)$this->_attributes[$label]; } - /** - * Sets an attribute. - * @param string $label Attribute name. - * @return string $value New attribute value. - * @access protected - */ + /** + * Sets an attribute. + * @param string $label Attribute name. + * @return string $value New attribute value. + * @access protected + */ function _setAttribute($label, $value) { $this->_attributes[strtolower($label)] = $value; } - /** - * Accessor for the whole content so far. - * @return string Content as big raw string. - * @access public - */ + /** + * Accessor for the whole content so far. + * @return string Content as big raw string. + * @access public + */ function getContent() { return $this->_content; } - /** - * Accessor for content reduced to visible text. Acts - * like a text mode browser, normalising space and - * reducing images to their alt text. - * @return string Content as plain text. - * @access public - */ + /** + * Accessor for content reduced to visible text. Acts + * like a text mode browser, normalising space and + * reducing images to their alt text. + * @return string Content as plain text. + * @access public + */ function getText() { return SimpleSaxParser::normalise($this->_content); } - /** - * Test to see if id attribute matches. - * @param string $id ID to test against. - * @return boolean True on match. - * @access public - */ + /** + * Test to see if id attribute matches. + * @param string $id ID to test against. + * @return boolean True on match. + * @access public + */ function isId($id) { return ($this->getAttribute('id') == $id); } } - /** - * Page title. - * @package SimpleTest - * @subpackage WebTester - */ + /** + * Page title. + * @package SimpleTest + * @subpackage WebTester + */ class SimpleTitleTag extends SimpleTag { - /** - * Starts with a named tag with attributes only. - * @param hash $attributes Attribute names and - * string values. - */ + /** + * Starts with a named tag with attributes only. + * @param hash $attributes Attribute names and + * string values. + */ function SimpleTitleTag($attributes) { $this->SimpleTag('title', $attributes); } } - /** - * Link. - * @package SimpleTest - * @subpackage WebTester - */ + /** + * Link. + * @package SimpleTest + * @subpackage WebTester + */ class SimpleAnchorTag extends SimpleTag { - /** - * Starts with a named tag with attributes only. - * @param hash $attributes Attribute names and - * string values. - */ + /** + * Starts with a named tag with attributes only. + * @param hash $attributes Attribute names and + * string values. + */ function SimpleAnchorTag($attributes) { $this->SimpleTag('a', $attributes); } - /** - * Accessor for URL as string. - * @return string Coerced as string. - * @access public - */ + /** + * Accessor for URL as string. + * @return string Coerced as string. + * @access public + */ function getHref() { $url = $this->getAttribute('href'); if (is_bool($url)) { @@ -186,42 +187,44 @@ } } - /** - * Form element. - * @package SimpleTest - * @subpackage WebTester - */ + /** + * Form element. + * @package SimpleTest + * @subpackage WebTester + */ class SimpleWidget extends SimpleTag { var $_value; + var $_label; var $_is_set; - /** - * Starts with a named tag with attributes only. - * @param string $name Tag name. - * @param hash $attributes Attribute names and - * string values. - */ + /** + * Starts with a named tag with attributes only. + * @param string $name Tag name. + * @param hash $attributes Attribute names and + * string values. + */ function SimpleWidget($name, $attributes) { $this->SimpleTag($name, $attributes); $this->_value = false; + $this->_label = false; $this->_is_set = false; } - /** - * Accessor for name submitted as the key in - * GET/POST variables hash. - * @return string Parsed value. - * @access public - */ + /** + * Accessor for name submitted as the key in + * GET/POST variables hash. + * @return string Parsed value. + * @access public + */ function getName() { return $this->getAttribute('name'); } - /** - * Accessor for default value parsed with the tag. - * @return string Parsed value. - * @access public - */ + /** + * Accessor for default value parsed with the tag. + * @return string Parsed value. + * @access public + */ function getDefault() { $default = $this->getAttribute('value'); if ($default === true) { @@ -233,13 +236,13 @@ return $default; } - /** - * Accessor for currently set value or default if - * none. - * @return string Value set by form or default - * if none. - * @access public - */ + /** + * Accessor for currently set value or default if + * none. + * @return string Value set by form or default + * if none. + * @access public + */ function getValue() { if (! $this->_is_set) { return $this->getDefault(); @@ -247,40 +250,69 @@ return $this->_value; } - /** - * Sets the current form element value. - * @param string $value New value. - * @return boolean True if allowed. - * @access public - */ + /** + * Sets the current form element value. + * @param string $value New value. + * @return boolean True if allowed. + * @access public + */ function setValue($value) { $this->_value = $value; $this->_is_set = true; return true; } - /** - * Resets the form element value back to the - * default. - * @access public - */ + /** + * Resets the form element value back to the + * default. + * @access public + */ function resetValue() { $this->_is_set = false; } + + /** + * Allows setting of a label externally, say by a + * label tag. + * @param string $label Label to attach. + * @access public + */ + function setLabel($label) { + $this->_label = trim($label); + } + + /** + * Reads external or internal label. + * @param string $label Label to test. + * @return boolean True is match. + * @access public + */ + function isLabel($label) { + return $this->_label == trim($label); + } + + /** + * Dispatches the value into the form encoded packet. + * @param SimpleEncoding $encoding Form packet. + * @access public + */ + function write(&$encoding) { + $encoding->add($this->getName(), $this->getValue()); + } } - /** - * Text, password and hidden field. - * @package SimpleTest - * @subpackage WebTester - */ + /** + * Text, password and hidden field. + * @package SimpleTest + * @subpackage WebTester + */ class SimpleTextTag extends SimpleWidget { - /** - * Starts with a named tag with attributes only. - * @param hash $attributes Attribute names and - * string values. - */ + /** + * Starts with a named tag with attributes only. + * @param hash $attributes Attribute names and + * string values. + */ function SimpleTextTag($attributes) { $this->SimpleWidget('input', $attributes); if ($this->getAttribute('value') === false) { @@ -288,22 +320,22 @@ } } - /** - * Tag contains no content. - * @return boolean False. - * @access public - */ + /** + * Tag contains no content. + * @return boolean False. + * @access public + */ function expectEndTag() { return false; } - /** - * Sets the current form element value. Cannot - * change the value of a hidden field. - * @param string $value New value. - * @return boolean True if allowed. - * @access public - */ + /** + * Sets the current form element value. Cannot + * change the value of a hidden field. + * @param string $value New value. + * @return boolean True if allowed. + * @access public + */ function setValue($value) { if ($this->getAttribute('type') == 'hidden') { return false; @@ -312,18 +344,18 @@ } } - /** - * Submit button as input tag. - * @package SimpleTest - * @subpackage WebTester - */ + /** + * Submit button as input tag. + * @package SimpleTest + * @subpackage WebTester + */ class SimpleSubmitTag extends SimpleWidget { - /** - * Starts with a named tag with attributes only. - * @param hash $attributes Attribute names and - * string values. - */ + /** + * Starts with a named tag with attributes only. + * @param hash $attributes Attribute names and + * string values. + */ function SimpleSubmitTag($attributes) { $this->SimpleWidget('input', $attributes); if ($this->getAttribute('name') === false) { @@ -334,84 +366,94 @@ } } - /** - * Tag contains no end element. - * @return boolean False. - * @access public - */ + /** + * Tag contains no end element. + * @return boolean False. + * @access public + */ function expectEndTag() { return false; } - /** - * Disables the setting of the button value. - * @param string $value Ignored. - * @return boolean True if allowed. - * @access public - */ + /** + * Disables the setting of the button value. + * @param string $value Ignored. + * @return boolean True if allowed. + * @access public + */ function setValue($value) { return false; } - /** - * Value of browser visible text. - * @return string Visible label. - * @access public - */ + /** + * Value of browser visible text. + * @return string Visible label. + * @access public + */ function getLabel() { return $this->getValue(); } - /** - * Gets the values submitted as a form. - * @return array Hash of name and values. - * @access public - */ + /** + * Test for a label match when searching. + * @param string $label Label to test. + * @return boolean True on match. + * @access public + */ + function isLabel($label) { + return trim($label) == trim($this->getLabel()); + } + + /** + * Gets the values submitted as a form. + * @return array Hash of name and values. + * @access public + */ function getSubmitValues() { return array($this->getName() => $this->getValue()); } } - /** - * Image button as input tag. - * @package SimpleTest - * @subpackage WebTester - */ + /** + * Image button as input tag. + * @package SimpleTest + * @subpackage WebTester + */ class SimpleImageSubmitTag extends SimpleWidget { - /** - * Starts with a named tag with attributes only. - * @param hash $attributes Attribute names and - * string values. - */ + /** + * Starts with a named tag with attributes only. + * @param hash $attributes Attribute names and + * string values. + */ function SimpleImageSubmitTag($attributes) { $this->SimpleWidget('input', $attributes); } - /** - * Tag contains no end element. - * @return boolean False. - * @access public - */ + /** + * Tag contains no end element. + * @return boolean False. + * @access public + */ function expectEndTag() { return false; } - /** - * Disables the setting of the button value. - * @param string $value Ignored. - * @return boolean True if allowed. - * @access public - */ + /** + * Disables the setting of the button value. + * @param string $value Ignored. + * @return boolean True if allowed. + * @access public + */ function setValue($value) { return false; } - /** - * Value of browser visible text. - * @return string Visible label. - * @access public - */ + /** + * Value of browser visible text. + * @return string Visible label. + * @access public + */ function getLabel() { if ($this->getAttribute('title')) { return $this->getAttribute('title'); @@ -419,11 +461,21 @@ return $this->getAttribute('alt'); } - /** - * Gets the values submitted as a form. - * @return array Hash of name and values. - * @access public - */ + /** + * Test for a label match when searching. + * @param string $label Label to test. + * @return boolean True on match. + * @access public + */ + function isLabel($label) { + return trim($label) == trim($this->getLabel()); + } + + /** + * Gets the values submitted as a form. + * @return array Hash of name and values. + * @access public + */ function getSubmitValues($x, $y) { return array( $this->getName() . '.x' => $x, @@ -431,58 +483,68 @@ } } - /** - * Submit button as button tag. - * @package SimpleTest - * @subpackage WebTester - */ + /** + * Submit button as button tag. + * @package SimpleTest + * @subpackage WebTester + */ class SimpleButtonTag extends SimpleWidget { - /** - * Starts with a named tag with attributes only. - * Defaults are very browser dependent. - * @param hash $attributes Attribute names and - * string values. - */ + /** + * Starts with a named tag with attributes only. + * Defaults are very browser dependent. + * @param hash $attributes Attribute names and + * string values. + */ function SimpleButtonTag($attributes) { $this->SimpleWidget('button', $attributes); } - /** - * Check to see if the tag can have both start and - * end tags with content in between. - * @return boolean True if content allowed. - * @access public - */ + /** + * Check to see if the tag can have both start and + * end tags with content in between. + * @return boolean True if content allowed. + * @access public + */ function expectEndTag() { return true; } - /** - * Disables the setting of the button value. - * @param string $value Ignored. - * @return boolean True if allowed. - * @access public - */ + /** + * Disables the setting of the button value. + * @param string $value Ignored. + * @return boolean True if allowed. + * @access public + */ function setValue($value) { return false; } - /** - * Value of browser visible text. - * @return string Visible label. - * @access public - */ + /** + * Value of browser visible text. + * @return string Visible label. + * @access public + */ function getLabel() { return $this->getContent(); } - /** - * Gets the values submitted as a form. Gone - * for the Mozilla defaults values. - * @return array Hash of name and values. - * @access public - */ + /** + * Test for a label match when searching. + * @param string $label Label to test. + * @return boolean True on match. + * @access public + */ + function isLabel($label) { + return trim($label) == trim($this->getLabel()); + } + + /** + * Gets the values submitted as a form. Gone + * for the Mozilla defaults values. + * @return array Hash of name and values. + * @access public + */ function getSubmitValues() { if ($this->getAttribute('name') === false) { return array(); @@ -494,27 +556,27 @@ } } - /** - * Content tag for text area. - * @package SimpleTest - * @subpackage WebTester - */ + /** + * Content tag for text area. + * @package SimpleTest + * @subpackage WebTester + */ class SimpleTextAreaTag extends SimpleWidget { - /** - * Starts with a named tag with attributes only. - * @param hash $attributes Attribute names and - * string values. - */ + /** + * Starts with a named tag with attributes only. + * @param hash $attributes Attribute names and + * string values. + */ function SimpleTextAreaTag($attributes) { $this->SimpleWidget('textarea', $attributes); } - /** - * Accessor for starting value. - * @return string Parsed value. - * @access public - */ + /** + * Accessor for starting value. + * @return string Parsed value. + * @access public + */ function getDefault() { if ($this->_wrapIsEnabled()) { return wordwrap( @@ -525,12 +587,12 @@ return $this->getContent(); } - /** - * Applies word wrapping if needed. - * @param string $value New value. - * @return boolean True if allowed. - * @access public - */ + /** + * Applies word wrapping if needed. + * @param string $value New value. + * @return boolean True if allowed. + * @access public + */ function setValue($value) { if ($this->_wrapIsEnabled()) { $value = wordwrap( @@ -541,11 +603,11 @@ return parent::setValue($value); } - /** - * Test to see if text should be wrapped. - * @return boolean True if wrapping on. - * @access private - */ + /** + * Test to see if text should be wrapped. + * @return boolean True if wrapping on. + * @access private + */ function _wrapIsEnabled() { if ($this->getAttribute('cols')) { $wrap = $this->getAttribute('wrap'); @@ -557,18 +619,59 @@ } } - /** - * Checkbox widget. - * @package SimpleTest - * @subpackage WebTester - */ + /** + * File upload widget. + * @package SimpleTest + * @subpackage WebTester + */ + class SimpleUploadTag extends SimpleWidget { + + /** + * Starts with attributes only. + * @param hash $attributes Attribute names and + * string values. + */ + function SimpleUploadTag($attributes) { + $this->SimpleWidget('input', $attributes); + } + + /** + * Tag contains no content. + * @return boolean False. + * @access public + */ + function expectEndTag() { + return false; + } + + /** + * Dispatches the value into the form encoded packet. + * @param SimpleEncoding $encoding Form packet. + * @access public + */ + function write(&$encoding) { + if (! file_exists($this->getValue())) { + return; + } + $encoding->attach( + $this->getName(), + implode('', file($this->getValue())), + basename($this->getValue())); + } + } + + /** + * Checkbox widget. + * @package SimpleTest + * @subpackage WebTester + */ class SimpleCheckboxTag extends SimpleWidget { - /** - * Starts with attributes only. - * @param hash $attributes Attribute names and - * string values. - */ + /** + * Starts with attributes only. + * @param hash $attributes Attribute names and + * string values. + */ function SimpleCheckboxTag($attributes) { $this->SimpleWidget('input', $attributes); if ($this->getAttribute('value') === false) { @@ -576,23 +679,23 @@ } } - /** - * Tag contains no content. - * @return boolean False. - * @access public - */ + /** + * Tag contains no content. + * @return boolean False. + * @access public + */ function expectEndTag() { return false; } - /** - * The only allowed value in the one in the - * "value" attribute. The default for this - * attribute is "on". - * @param string $value New value. - * @return boolean True if allowed. - * @access public - */ + /** + * The only allowed value in the one in the + * "value" attribute. The default for this + * attribute is "on". + * @param string $value New value. + * @return boolean True if allowed. + * @access public + */ function setValue($value) { if ($value === false) { return parent::setValue($value); @@ -603,12 +706,12 @@ return parent::setValue($value); } - /** - * Accessor for starting value. The default - * value is "on". - * @return string Parsed value. - * @access public - */ + /** + * Accessor for starting value. The default + * value is "on". + * @return string Parsed value. + * @access public + */ function getDefault() { if ($this->getAttribute('checked')) { return $this->getAttribute('value'); @@ -617,51 +720,51 @@ } } - /** - * Drop down widget. - * @package SimpleTest - * @subpackage WebTester - */ + /** + * Drop down widget. + * @package SimpleTest + * @subpackage WebTester + */ class SimpleSelectionTag extends SimpleWidget { var $_options; var $_choice; - /** - * Starts with attributes only. - * @param hash $attributes Attribute names and - * string values. - */ + /** + * Starts with attributes only. + * @param hash $attributes Attribute names and + * string values. + */ function SimpleSelectionTag($attributes) { $this->SimpleWidget('select', $attributes); $this->_options = array(); $this->_choice = false; } - /** - * Adds an option tag to a selection field. - * @param SimpleOptionTag $tag New option. - * @access public - */ + /** + * Adds an option tag to a selection field. + * @param SimpleOptionTag $tag New option. + * @access public + */ function addTag(&$tag) { if ($tag->getTagName() == 'option') { $this->_options[] = &$tag; } } - /** - * Text within the selection element is ignored. - * @param string $content Ignored. - * @access public - */ + /** + * Text within the selection element is ignored. + * @param string $content Ignored. + * @access public + */ function addContent($content) { } - /** - * Scans options for defaults. If none, then - * the first option is selected. - * @return string Selected field. - * @access public - */ + /** + * Scans options for defaults. If none, then + * the first option is selected. + * @return string Selected field. + * @access public + */ function getDefault() { for ($i = 0, $count = count($this->_options); $i < $count; $i++) { if ($this->_options[$i]->getAttribute('selected')) { @@ -674,12 +777,12 @@ return ''; } - /** - * Can only set allowed values. - * @param string $value New choice. - * @return boolean True if allowed. - * @access public - */ + /** + * Can only set allowed values. + * @param string $value New choice. + * @return boolean True if allowed. + * @access public + */ function setValue($value) { for ($i = 0, $count = count($this->_options); $i < $count; $i++) { if (trim($this->_options[$i]->getContent()) == trim($value)) { @@ -690,12 +793,12 @@ return false; } - /** - * Accessor for current selection value. - * @return string Value attribute or - * content of opton. - * @access public - */ + /** + * Accessor for current selection value. + * @return string Value attribute or + * content of opton. + * @access public + */ function getValue() { if ($this->_choice === false) { return $this->getDefault(); @@ -704,51 +807,51 @@ } } - /** - * Drop down widget. - * @package SimpleTest - * @subpackage WebTester - */ + /** + * Drop down widget. + * @package SimpleTest + * @subpackage WebTester + */ class MultipleSelectionTag extends SimpleWidget { var $_options; var $_values; - /** - * Starts with attributes only. - * @param hash $attributes Attribute names and - * string values. - */ + /** + * Starts with attributes only. + * @param hash $attributes Attribute names and + * string values. + */ function MultipleSelectionTag($attributes) { $this->SimpleWidget('select', $attributes); $this->_options = array(); $this->_values = false; } - /** - * Adds an option tag to a selection field. - * @param SimpleOptionTag $tag New option. - * @access public - */ + /** + * Adds an option tag to a selection field. + * @param SimpleOptionTag $tag New option. + * @access public + */ function addTag(&$tag) { if ($tag->getTagName() == 'option') { $this->_options[] = &$tag; } } - /** - * Text within the selection element is ignored. - * @param string $content Ignored. - * @access public - */ + /** + * Text within the selection element is ignored. + * @param string $content Ignored. + * @access public + */ function addContent($content) { } - /** - * Scans options for defaults to populate the - * value array(). - * @return array Selected fields. - * @access public - */ + /** + * Scans options for defaults to populate the + * value array(). + * @return array Selected fields. + * @access public + */ function getDefault() { $default = array(); for ($i = 0, $count = count($this->_options); $i < $count; $i++) { @@ -759,12 +862,12 @@ return $default; } - /** - * Can only set allowed values. - * @param array $values New choices. - * @return boolean True if allowed. - * @access public - */ + /** + * Can only set allowed values. + * @param array $values New choices. + * @return boolean True if allowed. + * @access public + */ function setValue($values) { foreach ($values as $value) { $is_option = false; @@ -782,11 +885,11 @@ return true; } - /** - * Accessor for current selection value. - * @return array List of currently set options. - * @access public - */ + /** + * Accessor for current selection value. + * @return array List of currently set options. + * @access public + */ function getValue() { if ($this->_values === false) { return $this->getDefault(); @@ -795,36 +898,36 @@ } } - /** - * Option for selection field. - * @package SimpleTest - * @subpackage WebTester - */ + /** + * Option for selection field. + * @package SimpleTest + * @subpackage WebTester + */ class SimpleOptionTag extends SimpleWidget { - /** - * Stashes the attributes. - */ + /** + * Stashes the attributes. + */ function SimpleOptionTag($attributes) { $this->SimpleWidget('option', $attributes); } - /** - * Does nothing. - * @param string $value Ignored. - * @return boolean Not allowed. - * @access public - */ + /** + * Does nothing. + * @param string $value Ignored. + * @return boolean Not allowed. + * @access public + */ function setValue($value) { return false; } - /** - * Accessor for starting value. Will be set to - * the option label if no value exists. - * @return string Parsed value. - * @access public - */ + /** + * Accessor for starting value. Will be set to + * the option label if no value exists. + * @return string Parsed value. + * @access public + */ function getDefault() { if ($this->getAttribute('value') === false) { return $this->getContent(); @@ -833,17 +936,17 @@ } } - /** - * Radio button. - * @package SimpleTest - * @subpackage WebTester - */ + /** + * Radio button. + * @package SimpleTest + * @subpackage WebTester + */ class SimpleRadioButtonTag extends SimpleWidget { - /** - * Stashes the attributes. - * @param array $attributes Hash of attributes. - */ + /** + * Stashes the attributes. + * @param array $attributes Hash of attributes. + */ function SimpleRadioButtonTag($attributes) { $this->SimpleWidget('input', $attributes); if ($this->getAttribute('value') === false) { @@ -851,22 +954,22 @@ } } - /** - * Tag contains no content. - * @return boolean False. - * @access public - */ + /** + * Tag contains no content. + * @return boolean False. + * @access public + */ function expectEndTag() { return false; } - /** - * The only allowed value in the one in the - * "value" attribute. - * @param string $value New value. - * @return boolean True if allowed. - * @access public - */ + /** + * The only allowed value in the one in the + * "value" attribute. + * @param string $value New value. + * @return boolean True if allowed. + * @access public + */ function setValue($value) { if ($value === false) { return parent::setValue($value); @@ -877,11 +980,11 @@ return parent::setValue($value); } - /** - * Accessor for starting value. - * @return string Parsed value. - * @access public - */ + /** + * Accessor for starting value. + * @return string Parsed value. + * @access public + */ function getDefault() { if ($this->getAttribute('checked')) { return $this->getAttribute('value'); @@ -889,40 +992,62 @@ return false; } } + + /** + * A group of multiple widgets with some shared behaviour. + * @package SimpleTest + * @subpackage WebTester + */ + class SimpleTagGroup { + var $_widgets = array(); - /** - * A group of tags with the same name within a form. - * @package SimpleTest - * @subpackage WebTester - */ - class SimpleCheckboxGroup { - var $_widgets; + /** + * Adds a tag to the group. + * @param SimpleWidget $widget + * @access public + */ + function addWidget(&$widget) { + $this->_widgets[] = &$widget; + } - /** - * Starts empty. - * @access public - */ - function SimpleCheckboxGroup() { - $this->_widgets = array(); + /** + * Accessor to widget set. + * @return array All widgets. + * @access protected + */ + function &_getWidgets() { + return $this->_widgets; } - /** - * Accessor for an attribute. - * @param string $label Attribute name. - * @return boolean Always false. - * @access public - */ + /** + * Accessor for an attribute. + * @param string $label Attribute name. + * @return boolean Always false. + * @access public + */ function getAttribute($label) { return false; } - /** - * Scans the checkboxes for one with the appropriate - * ID field. - * @param string $id ID value to try. - * @return boolean True if matched. - * @access public - */ + /** + * Fetches the name for the widget from the first + * member. + * @return string Name of widget. + * @access public + */ + function getName() { + if (count($this->_widgets) > 0) { + return $this->_widgets[0]->getName(); + } + } + + /** + * Scans the widgets for one with the appropriate + * ID field. + * @param string $id ID value to try. + * @return boolean True if matched. + * @access public + */ function isId($id) { for ($i = 0, $count = count($this->_widgets); $i < $count; $i++) { if ($this->_widgets[$i]->isId($id)) { @@ -931,94 +1056,110 @@ } return false; } - - /** - * Adds a tag to the group. - * @param SimpleWidget $widget - * @access public - */ - function addWidget(&$widget) { - $this->_widgets[] = &$widget; - } - /** - * Fetches the name for the widget from the first - * member. - * @return string Name of widget. - * @access public - */ - function getName() { - if (count($this->_widgets) > 0) { - return $this->_widgets[0]->getName(); + /** + * Scans the widgets for one with the appropriate + * attached label. + * @param string $label Attached label to try. + * @return boolean True if matched. + * @access public + */ + function isLabel($label) { + for ($i = 0, $count = count($this->_widgets); $i < $count; $i++) { + if ($this->_widgets[$i]->isLabel($label)) { + return true; + } } + return false; } - /** - * Accessor for current selected widget or false - * if none. - * @return string/array Widget values or false if none. - * @access public - */ + /** + * Dispatches the value into the form encoded packet. + * @param SimpleEncoding $encoding Form packet. + * @access public + */ + function write(&$encoding) { + $encoding->add($this->getName(), $this->getValue()); + } + } + + /** + * A group of tags with the same name within a form. + * @package SimpleTest + * @subpackage WebTester + */ + class SimpleCheckboxGroup extends SimpleTagGroup { + + /** + * Accessor for current selected widget or false + * if none. + * @return string/array Widget values or false if none. + * @access public + */ function getValue() { $values = array(); - for ($i = 0, $count = count($this->_widgets); $i < $count; $i++) { - if ($this->_widgets[$i]->getValue()) { - $values[] = $this->_widgets[$i]->getValue(); + $widgets = &$this->_getWidgets(); + for ($i = 0, $count = count($widgets); $i < $count; $i++) { + if ($widgets[$i]->getValue()) { + $values[] = $widgets[$i]->getValue(); } } return $this->_coerceValues($values); } - /** - * Accessor for starting value that is active. - * @return string/array Widget values or false if none. - * @access public - */ + /** + * Accessor for starting value that is active. + * @return string/array Widget values or false if none. + * @access public + */ function getDefault() { $values = array(); - for ($i = 0, $count = count($this->_widgets); $i < $count; $i++) { - if ($this->_widgets[$i]->getDefault()) { - $values[] = $this->_widgets[$i]->getDefault(); + $widgets = &$this->_getWidgets(); + for ($i = 0, $count = count($widgets); $i < $count; $i++) { + if ($widgets[$i]->getDefault()) { + $values[] = $widgets[$i]->getDefault(); } } return $this->_coerceValues($values); } - /** - * Accessor for current set values. - * @param string/array/boolean $values Either a single string, a - * hash or false for nothing set. - * @return boolean True if all values can be set. - * @access public - */ + /** + * Accessor for current set values. + * @param string/array/boolean $values Either a single string, a + * hash or false for nothing set. + * @return boolean True if all values can be set. + * @access public + */ function setValue($values) { $values = $this->_makeArray($values); if (! $this->_valuesArePossible($values)) { return false; } - for ($i = 0, $count = count($this->_widgets); $i < $count; $i++) { - $possible = $this->_widgets[$i]->getAttribute('value'); - if (in_array($this->_widgets[$i]->getAttribute('value'), $values)) { - $this->_widgets[$i]->setValue($possible); + $widgets = &$this->_getWidgets(); + for ($i = 0, $count = count($widgets); $i < $count; $i++) { + $possible = $widgets[$i]->getAttribute('value'); + if (in_array($widgets[$i]->getAttribute('value'), $values)) { + $widgets[$i]->setValue($possible); } else { - $this->_widgets[$i]->setValue(false); + $widgets[$i]->setValue(false); } } return true; } - /** - * Tests to see if a possible value set is legal. - * @param string/array/boolean $values Either a single string, a - * hash or false for nothing set. - * @return boolean False if trying to set a - * missing value. - * @access private - */ + /** + * Tests to see if a possible value set is legal. + * @param string/array/boolean $values Either a single string, a + * hash or false for nothing set. + * @return boolean False if trying to set a + * missing value. + * @access private + */ function _valuesArePossible($values) { $matches = array(); - for ($i = 0, $count = count($this->_widgets); $i < $count; $i++) { - $possible = $this->_widgets[$i]->getAttribute('value'); + $widgets = &$this->_getWidgets(); + for ($i = 0, $count = count($widgets); $i < $count; $i++) { + $possible = $widgets[$i]->getAttribute('value'); if (in_array($possible, $values)) { $matches[] = $possible; } @@ -1026,14 +1167,14 @@ return ($values == $matches); } - /** - * Converts the output to an appropriate format. This means - * that no values is false, a single value is just that - * value and only two or more are contained in an array. - * @param array $values List of values of widgets. - * @return string/array/boolean Expected format for a tag. - * @access private - */ + /** + * Converts the output to an appropriate format. This means + * that no values is false, a single value is just that + * value and only two or more are contained in an array. + * @param array $values List of values of widgets. + * @return string/array/boolean Expected format for a tag. + * @access private + */ function _coerceValues($values) { if (count($values) == 0) { return false; @@ -1044,15 +1185,15 @@ } } - /** - * Converts false or string into array. The opposite of - * the coercian method. - * @param string/array/boolean $value A single item is converted - * to a one item list. False - * gives an empty list. - * @return array List of values, possibly empty. - * @access private - */ + /** + * Converts false or string into array. The opposite of + * the coercian method. + * @param string/array/boolean $value A single item is converted + * to a one item list. False + * gives an empty list. + * @return array List of values, possibly empty. + * @access private + */ function _makeArray($value) { if ($value === false) { return array(); @@ -1064,176 +1205,150 @@ } } - /** - * A group of tags with the same name within a form. - * Used for radio buttons. - * @package SimpleTest - * @subpackage WebTester - */ - class SimpleRadioGroup { - var $_widgets; + /** + * A group of tags with the same name within a form. + * Used for radio buttons. + * @package SimpleTest + * @subpackage WebTester + */ + class SimpleRadioGroup extends SimpleTagGroup { - /** - * Starts empty. - * @access public - */ - function SimpleRadioGroup() { - $this->_widgets = array(); - } - - /** - * Accessor for an attribute. - * @param string $label Attribute name. - * @return boolean Always false. - * @access public - */ - function getAttribute($label) { - return false; - } - - /** - * Scans the checkboxes for one with the appropriate - * ID field. - * @param string $id ID value to try. - * @return boolean True if matched. - * @access public - */ - function isId($id) { - for ($i = 0, $count = count($this->_widgets); $i < $count; $i++) { - if ($this->_widgets[$i]->isId($id)) { - return true; - } - } - return false; - } - - /** - * Adds a tag to the group. - * @param SimpleWidget $widget - * @access public - */ - function addWidget(&$widget) { - $this->_widgets[] = &$widget; - } - - /** - * Fetches the name for the widget from the first - * member. - * @return string Name of widget. - * @access public - */ - function getName() { - if (count($this->_widgets) > 0) { - return $this->_widgets[0]->getName(); - } - } - - /** - * Each tag is tried in turn until one is - * successfully set. The others will be - * unchecked if successful. - * @param string $value New value. - * @return boolean True if any allowed. - * @access public - */ + /** + * Each tag is tried in turn until one is + * successfully set. The others will be + * unchecked if successful. + * @param string $value New value. + * @return boolean True if any allowed. + * @access public + */ function setValue($value) { if (! $this->_valueIsPossible($value)) { return false; } $index = false; - for ($i = 0, $count = count($this->_widgets); $i < $count; $i++) { - if (! $this->_widgets[$i]->setValue($value)) { - $this->_widgets[$i]->setValue(false); + $widgets = &$this->_getWidgets(); + for ($i = 0, $count = count($widgets); $i < $count; $i++) { + if (! $widgets[$i]->setValue($value)) { + $widgets[$i]->setValue(false); } } return true; } - /** - * Tests to see if a value is allowed. - * @param string Attempted value. - * @return boolean True if a valid value. - * @access private - */ + /** + * Tests to see if a value is allowed. + * @param string Attempted value. + * @return boolean True if a valid value. + * @access private + */ function _valueIsPossible($value) { - for ($i = 0, $count = count($this->_widgets); $i < $count; $i++) { - if ($this->_widgets[$i]->getAttribute('value') == $value) { + $widgets = &$this->_getWidgets(); + for ($i = 0, $count = count($widgets); $i < $count; $i++) { + if ($widgets[$i]->getAttribute('value') == $value) { return true; } } return false; } - /** - * Accessor for current selected widget or false - * if none. - * @return string/boolean Value attribute or - * content of opton. - * @access public - */ + /** + * Accessor for current selected widget or false + * if none. + * @return string/boolean Value attribute or + * content of opton. + * @access public + */ function getValue() { - for ($i = 0, $count = count($this->_widgets); $i < $count; $i++) { - if ($this->_widgets[$i]->getValue()) { - return $this->_widgets[$i]->getValue(); + $widgets = &$this->_getWidgets(); + for ($i = 0, $count = count($widgets); $i < $count; $i++) { + if ($widgets[$i]->getValue()) { + return $widgets[$i]->getValue(); } } return false; } - /** - * Accessor for starting value that is active. - * @return string/boolean Value of first checked - * widget or false if none. - * @access public - */ + /** + * Accessor for starting value that is active. + * @return string/boolean Value of first checked + * widget or false if none. + * @access public + */ function getDefault() { - for ($i = 0, $count = count($this->_widgets); $i < $count; $i++) { - if ($this->_widgets[$i]->getDefault()) { - return $this->_widgets[$i]->getDefault(); + $widgets = &$this->_getWidgets(); + for ($i = 0, $count = count($widgets); $i < $count; $i++) { + if ($widgets[$i]->getDefault()) { + return $widgets[$i]->getDefault(); } } return false; } } - /** - * Tag to aid parsing the form. - * @package SimpleTest - * @subpackage WebTester - */ + /** + * Tag to keep track of labels. + * @package SimpleTest + * @subpackage WebTester + */ + class SimpleLabelTag extends SimpleTag { + + /** + * Starts with a named tag with attributes only. + * @param hash $attributes Attribute names and + * string values. + */ + function SimpleLabelTag($attributes) { + $this->SimpleTag('label', $attributes); + } + + /** + * Access for the ID to attach the label to. + * @return string For attribute. + * @access public + */ + function getFor() { + return $this->getAttribute('for'); + } + } + + /** + * Tag to aid parsing the form. + * @package SimpleTest + * @subpackage WebTester + */ class SimpleFormTag extends SimpleTag { - /** - * Starts with a named tag with attributes only. - * @param hash $attributes Attribute names and - * string values. - */ + /** + * Starts with a named tag with attributes only. + * @param hash $attributes Attribute names and + * string values. + */ function SimpleFormTag($attributes) { $this->SimpleTag('form', $attributes); } } - /** - * Tag to aid parsing the frames in a page. - * @package SimpleTest - * @subpackage WebTester - */ + /** + * Tag to aid parsing the frames in a page. + * @package SimpleTest + * @subpackage WebTester + */ class SimpleFrameTag extends SimpleTag { - /** - * Starts with a named tag with attributes only. - * @param hash $attributes Attribute names and - * string values. - */ + /** + * Starts with a named tag with attributes only. + * @param hash $attributes Attribute names and + * string values. + */ function SimpleFrameTag($attributes) { $this->SimpleTag('frame', $attributes); } - /** - * Tag contains no content. - * @return boolean False. - * @access public - */ + /** + * Tag contains no content. + * @return boolean False. + * @access public + */ function expectEndTag() { return false; } diff --git a/vendors/simpletest/test/acceptance_test.php b/vendors/simpletest/test/acceptance_test.php index 354fbb20c..a9c10bb5e 100644 --- a/vendors/simpletest/test/acceptance_test.php +++ b/vendors/simpletest/test/acceptance_test.php @@ -10,10 +10,9 @@ function testGet() { $browser = &new SimpleBrowser(); $browser->addHeader('User-Agent: SimpleTest ' . SimpleTestOptions::getVersion()); - $this->assertTrue($browser->get('http://www.lastcraft.com/test/network_confirm.php')); - $this->assertWantedPattern('/target for the SimpleTest/', $browser->getContent()); - $this->assertWantedPattern('/Request method.*?
GET<\/dd>/', $browser->getContent()); + $this->assertPattern('/target for the SimpleTest/', $browser->getContent()); + $this->assertPattern('/Request method.*?
GET<\/dd>/', $browser->getContent()); $this->assertEqual($browser->getTitle(), 'Simple test target file'); $this->assertEqual($browser->getResponseCode(), 200); $this->assertEqual($browser->getMimeType(), 'text/html'); @@ -23,8 +22,8 @@ $browser = &new SimpleBrowser(); $browser->addHeader('User-Agent: SimpleTest ' . SimpleTestOptions::getVersion()); $this->assertTrue($browser->post('http://www.lastcraft.com/test/network_confirm.php')); - $this->assertWantedPattern('/target for the SimpleTest/', $browser->getContent()); - $this->assertWantedPattern('/Request method.*?
POST<\/dd>/', $browser->getContent()); + $this->assertPattern('/target for the SimpleTest/', $browser->getContent()); + $this->assertPattern('/Request method.*?
POST<\/dd>/', $browser->getContent()); } function testAbsoluteLinkFollowing() { @@ -32,7 +31,7 @@ $browser->addHeader('User-Agent: SimpleTest ' . SimpleTestOptions::getVersion()); $browser->get('http://www.lastcraft.com/test/link_confirm.php'); $this->assertTrue($browser->clickLink('Absolute')); - $this->assertWantedPattern('/target for the SimpleTest/', $browser->getContent()); + $this->assertPattern('/target for the SimpleTest/', $browser->getContent()); } function testRelativeLinkFollowing() { @@ -40,7 +39,15 @@ $browser->addHeader('User-Agent: SimpleTest ' . SimpleTestOptions::getVersion()); $browser->get('http://www.lastcraft.com/test/link_confirm.php'); $this->assertTrue($browser->clickLink('Relative')); - $this->assertWantedPattern('/target for the SimpleTest/', $browser->getContent()); + $this->assertPattern('/target for the SimpleTest/', $browser->getContent()); + } + + function testUnifiedClickLinkClicking() { + $browser = &new SimpleBrowser(); + $browser->addHeader('User-Agent: SimpleTest ' . SimpleTestOptions::getVersion()); + $browser->get('http://www.lastcraft.com/test/link_confirm.php'); + $this->assertTrue($browser->click('Relative')); + $this->assertPattern('/target for the SimpleTest/', $browser->getContent()); } function testIdLinkFollowing() { @@ -48,7 +55,7 @@ $browser->addHeader('User-Agent: SimpleTest ' . SimpleTestOptions::getVersion()); $browser->get('http://www.lastcraft.com/test/link_confirm.php'); $this->assertTrue($browser->clickLinkById(1)); - $this->assertWantedPattern('/target for the SimpleTest/', $browser->getContent()); + $this->assertPattern('/target for the SimpleTest/', $browser->getContent()); } function testCookieReading() { @@ -65,22 +72,29 @@ $browser->addHeader('User-Agent: SimpleTest ' . SimpleTestOptions::getVersion()); $browser->get('http://www.lastcraft.com/test/form.html'); $this->assertTrue($browser->clickSubmit('Go!')); - $this->assertWantedPattern('/Request method.*?
POST<\/dd>/', $browser->getContent()); - $this->assertWantedPattern('/go=\[Go!\]/', $browser->getContent()); + $this->assertPattern('/Request method.*?
POST<\/dd>/', $browser->getContent()); + $this->assertPattern('/go=\[Go!\]/', $browser->getContent()); + } + + function testUnifiedClickCanSubmit() { + $browser = &new SimpleBrowser(); + $browser->addHeader('User-Agent: SimpleTest ' . SimpleTestOptions::getVersion()); + $browser->get('http://www.lastcraft.com/test/form.html'); + $this->assertTrue($browser->click('Go!')); + $this->assertPattern('/go=\[Go!\]/', $browser->getContent()); } } class TestOfLiveFetching extends WebTestCase { - function setUp() { $this->addHeader('User-Agent: SimpleTest ' . SimpleTestOptions::getVersion()); } function testGet() { $this->assertTrue($this->get('http://www.lastcraft.com/test/network_confirm.php')); - $this->assertTrue($this->getUrl() == 'http://www.lastcraft.com/test/network_confirm.php'); - $this->assertWantedPattern('/target for the SimpleTest/'); - $this->assertWantedPattern('/Request method.*?
GET<\/dd>/'); + $this->assertEqual($this->getUrl(), 'http://www.lastcraft.com/test/network_confirm.php'); + $this->assertWantedText('target for the SimpleTest'); + $this->assertPattern('/Request method.*?
GET<\/dd>/'); $this->assertTitle('Simple test target file'); $this->assertResponse(200); $this->assertMime('text/html'); @@ -98,18 +112,18 @@ function testPost() { $this->assertTrue($this->post('http://www.lastcraft.com/test/network_confirm.php')); $this->assertWantedText('target for the SimpleTest'); - $this->assertWantedPattern('/Request method.*?
POST<\/dd>/'); + $this->assertPattern('/Request method.*?
POST<\/dd>/'); } function testGetWithData() { $this->get('http://www.lastcraft.com/test/network_confirm.php', array("a" => "aaa")); - $this->assertWantedPattern('/Request method.*?
GET<\/dd>/'); + $this->assertPattern('/Request method.*?
GET<\/dd>/'); $this->assertWantedText('a=[aaa]'); } function testPostWithData() { $this->post('http://www.lastcraft.com/test/network_confirm.php', array("a" => "aaa")); - $this->assertWantedPattern('/Request method.*?
POST<\/dd>/'); + $this->assertPattern('/Request method.*?
POST<\/dd>/'); $this->assertWantedText('a=[aaa]'); } @@ -153,14 +167,13 @@ } class TestOfLivePageLinkingWithMinimalLinks extends WebTestCase { - function setUp() { $this->addHeader('User-Agent: SimpleTest ' . SimpleTestOptions::getVersion()); } function testClickToExplicitelyNamedSelfReturns() { $this->get('http://www.lastcraft.com/test/front_controller_style/a_page.php'); - $this->assertTrue($this->getUrl() == 'http://www.lastcraft.com/test/front_controller_style/a_page.php'); + $this->assertEqual($this->getUrl(), 'http://www.lastcraft.com/test/front_controller_style/a_page.php'); $this->assertTitle('Simple test page with links'); $this->clickLink('Self'); $this->assertTitle('Simple test page with links'); @@ -206,7 +219,6 @@ } class TestOfLiveFrontControllerEmulation extends WebTestCase { - function setUp() { $this->addHeader('User-Agent: SimpleTest ' . SimpleTestOptions::getVersion()); } @@ -239,16 +251,16 @@ $this->get('http://www.lastcraft.com/test/front_controller_style/'); $this->clickLink('Empty query'); $this->assertResponse(200); - $this->assertWantedPattern('/Simple test front controller/'); - $this->assertWantedPattern('/raw get data.*?\[\].*?get data/si'); + $this->assertPattern('/Simple test front controller/'); + $this->assertPattern('/raw get data.*?\[\].*?get data/si'); } function testJumpToUnnamedPageWithEmptyLink() { $this->get('http://www.lastcraft.com/test/front_controller_style/'); $this->clickLink('Empty link'); $this->assertResponse(200); - $this->assertWantedPattern('/Simple test front controller/'); - $this->assertWantedPattern('/raw get data.*?\[\].*?get data/si'); + $this->assertPattern('/Simple test front controller/'); + $this->assertPattern('/raw get data.*?\[\].*?get data/si'); } function testJumpBackADirectoryLevel() { @@ -294,7 +306,6 @@ } class TestOfLiveHeaders extends WebTestCase { - function setUp() { $this->addHeader('User-Agent: SimpleTest ' . SimpleTestOptions::getVersion()); } @@ -309,7 +320,6 @@ } class TestOfLiveRedirects extends WebTestCase { - function setUp() { $this->addHeader('User-Agent: SimpleTest ' . SimpleTestOptions::getVersion()); } @@ -356,21 +366,23 @@ } class TestOfLiveCookies extends WebTestCase { - function setUp() { $this->addHeader('User-Agent: SimpleTest ' . SimpleTestOptions::getVersion()); } function testCookieSetting() { - $this->setCookie('a', 'Test cookie a', 'www.lastcraft.com'); - $this->setCookie('b', 'Test cookie b', 'www.lastcraft.com', 'test'); + $this->setCookie('a', 'Test cookie a'); + $this->setCookie('b', 'Test cookie b', 'www.lastcraft.com'); + $this->setCookie('c', 'Test cookie c', 'www.lastcraft.com', 'test'); $this->get('http://www.lastcraft.com/test/network_confirm.php'); - $this->assertWantedPattern('/Test cookie a/'); - $this->assertWantedPattern('/Test cookie b/'); + $this->assertPattern('/Test cookie a/'); + $this->assertPattern('/Test cookie b/'); + $this->assertPattern('/Test cookie c/'); $this->assertCookie('a'); $this->assertCookie('b', 'Test cookie b'); $this->assertTrue($this->getCookie('a') == 'Test cookie a'); $this->assertTrue($this->getCookie('b') == 'Test cookie b'); + $this->assertTrue($this->getCookie('c') == 'Test cookie c'); } function testCookieReading() { @@ -387,43 +399,42 @@ $this->assertCookie('day_cookie', 'C'); } - function testTimedCookieExpiry() { + function testTimedCookieExpiryWith100SecondMargin() { $this->get('http://www.lastcraft.com/test/set_cookies.php'); $this->ageCookies(3600); - $this->restart(time() + 60); // Includes a 60 sec. clock drift margin. + $this->restart(time() + 100); $this->assertNoCookie('session_cookie'); $this->assertNoCookie('hour_cookie'); $this->assertCookie('day_cookie', 'C'); } - function testOfClockOverDrift() { + function testNoClockOverDriftBy100Seconds() { $this->get('http://www.lastcraft.com/test/set_cookies.php'); - $this->restart(time() + 160); // Allows sixty second drift. + $this->restart(time() + 200); $this->assertNoCookie( 'short_cookie', - '%s->Please check your computer clock setting if you are not using NTP'); + '%s -> Please check your computer clock setting if you are not using NTP'); } - function testOfClockUnderDrift() { + function testNoClockUnderDriftBy100Seconds() { $this->get('http://www.lastcraft.com/test/set_cookies.php'); - $this->restart(time() + 40); // Allows sixty second drift. + $this->restart(time() + 0); $this->assertCookie( 'short_cookie', 'B', - '%s->Please check your computer clock setting if you are not using NTP'); + '%s -> Please check your computer clock setting if you are not using NTP'); } function testCookiePath() { $this->get('http://www.lastcraft.com/test/set_cookies.php'); - $this->assertNoCookie("path_cookie", "D"); + $this->assertNoCookie('path_cookie', 'D'); $this->get('./path/show_cookies.php'); - $this->assertWantedPattern('/path_cookie/'); - $this->assertCookie("path_cookie", "D"); + $this->assertPattern('/path_cookie/'); + $this->assertCookie('path_cookie', 'D'); } } class TestOfLiveForms extends WebTestCase { - function setUp() { $this->addHeader('User-Agent: SimpleTest ' . SimpleTestOptions::getVersion()); } @@ -431,21 +442,21 @@ function testSimpleSubmit() { $this->get('http://www.lastcraft.com/test/form.html'); $this->assertTrue($this->clickSubmit('Go!')); - $this->assertWantedPattern('/Request method.*?
POST<\/dd>/'); + $this->assertPattern('/Request method.*?
POST<\/dd>/'); $this->assertWantedText('go=[Go!]'); } function testDefaultFormValues() { $this->get('http://www.lastcraft.com/test/form.html'); - $this->assertField('a', ''); - $this->assertField('b', 'Default text'); - $this->assertField('c', ''); - $this->assertField('d', 'd1'); - $this->assertField('e', false); - $this->assertField('f', 'on'); - $this->assertField('g', 'g3'); - $this->assertField('h', 2); - $this->assertField('go', 'Go!'); + $this->assertFieldByName('a', ''); + $this->assertFieldByName('b', 'Default text'); + $this->assertFieldByName('c', ''); + $this->assertFieldByName('d', 'd1'); + $this->assertFieldByName('e', false); + $this->assertFieldByName('f', 'on'); + $this->assertFieldByName('g', 'g3'); + $this->assertFieldByName('h', 2); + $this->assertFieldByName('go', 'Go!'); $this->assertTrue($this->clickSubmit('Go!')); $this->assertWantedText('go=[Go!]'); $this->assertWantedText('a=[]'); @@ -457,16 +468,16 @@ $this->assertWantedText('g=[g3]'); } - function testFormSubmissionByLabel() { + function testFormSubmissionByButtonLabel() { $this->get('http://www.lastcraft.com/test/form.html'); - $this->setField('a', 'aaa'); - $this->setField('b', 'bbb'); - $this->setField('c', 'ccc'); - $this->setField('d', 'D2'); - $this->setField('e', 'on'); - $this->setField('f', false); - $this->setField('g', 'g2'); - $this->setField('h', 1); + $this->setFieldByName('a', 'aaa'); + $this->setFieldByName('b', 'bbb'); + $this->setFieldByName('c', 'ccc'); + $this->setFieldByName('d', 'D2'); + $this->setFieldByName('e', 'on'); + $this->setFieldByName('f', false); + $this->setFieldByName('g', 'g2'); + $this->setFieldByName('h', 1); $this->assertTrue($this->clickSubmit('Go!')); $this->assertWantedText('a=[aaa]'); $this->assertWantedText('b=[bbb]'); @@ -486,11 +497,12 @@ function testFormSubmissionByName() { $this->get('http://www.lastcraft.com/test/form.html'); + $this->setFieldByName('a', 'A'); $this->assertTrue($this->clickSubmitByName('go')); - $this->assertWantedText('go=[Go!]'); + $this->assertWantedText('a=[A]'); } - function testFormSubmissionByNameAndadditionalParameters() { + function testFormSubmissionByNameAndAdditionalParameters() { $this->get('http://www.lastcraft.com/test/form.html'); $this->assertTrue($this->clickSubmitByName('go', array('add' => 'A'))); $this->assertWantedText('go=[Go!]'); @@ -510,21 +522,77 @@ $this->assertFieldById(3, ''); $this->assertFieldById(4, 'd1'); $this->assertFieldById(5, false); + $this->assertFieldById(6, 'on'); + $this->assertFieldById(8, 'g3'); + $this->assertFieldById(11, 2); $this->setFieldById(1, 'aaa'); $this->setFieldById(2, 'bbb'); $this->setFieldById(3, 'ccc'); $this->setFieldById(4, 'D2'); $this->setFieldById(5, 'on'); + $this->setFieldById(6, false); + $this->setFieldById(8, 'g2'); + $this->setFieldById(11, 'H1'); $this->assertTrue($this->clickSubmitById(99)); $this->assertWantedText('a=[aaa]'); $this->assertWantedText('b=[bbb]'); $this->assertWantedText('c=[ccc]'); $this->assertWantedText('d=[d2]'); $this->assertWantedText('e=[on]'); + $this->assertNoUnwantedText('f=['); + $this->assertWantedText('g=[g2]'); + $this->assertWantedText('h=[1]'); $this->assertWantedText('go=[Go!]'); } - function testImageSubmissionByLabel() { + function testFormSubmissionWithLabels() { + $this->get('http://www.lastcraft.com/test/form.html'); + $this->assertField('Text A', ''); + $this->assertField('Text B', 'Default text'); + $this->assertField('Text area C', ''); + $this->assertField('Selection D', 'd1'); + $this->assertField('Checkbox E', false); + $this->assertField('Checkbox F', 'on'); + $this->assertField('3', 'g3'); + $this->assertField('Selection H', 2); + $this->setField('Text A', 'aaa'); + $this->setField('Text B', 'bbb'); + $this->setField('Text area C', 'ccc'); + $this->setField('Selection D', 'D2'); + $this->setField('Checkbox E', 'on'); + $this->setField('Checkbox F', false); + $this->setField('2', 'g2'); + $this->setField('Selection H', 'H1'); + $this->assertTrue($this->clickSubmit('Go!')); + $this->assertWantedText('a=[aaa]'); + $this->assertWantedText('b=[bbb]'); + $this->assertWantedText('c=[ccc]'); + $this->assertWantedText('d=[d2]'); + $this->assertWantedText('e=[on]'); + $this->assertNoUnwantedText('f=['); + $this->assertWantedText('g=[g2]'); + $this->assertWantedText('h=[1]'); + $this->assertWantedText('go=[Go!]'); + } + + function testFormSubmissionWithMixedPostAndGet() { + $this->get('http://www.lastcraft.com/test/form_with_mixed_post_and_get.html'); + $this->setFieldByName('a', 'A'); + $this->assertTrue($this->clickSubmit('Go!')); + $this->assertWantedText('a=[A]'); + $this->assertWantedText('x=[X]'); + $this->assertWantedText('y=[Y]'); + } + + function testFormSubmissionWithoutAction() { + $this->get('http://www.lastcraft.com/test/form_without_action.php?test=test'); + $this->assertWantedText('_GET : [test]'); + $this->assertTrue($this->clickSubmit('Submit Post With Empty Action')); + $this->assertWantedText('_GET : [test]'); + $this->assertWantedText('_POST : [test]'); + } + + function testImageSubmissionByLabel() { $this->get('http://www.lastcraft.com/test/form.html'); $this->assertTrue($this->clickImage('Image go!', 10, 12)); $this->assertWantedText('go_x=[10]'); @@ -554,39 +622,74 @@ function testButtonSubmissionByLabel() { $this->get('http://www.lastcraft.com/test/form.html'); $this->assertTrue($this->clickSubmit('Button go!', 10, 12)); - $this->assertWantedPattern('/go=\[ButtonGo\]/s'); + $this->assertPattern('/go=\[ButtonGo\]/s'); } function testSelfSubmit() { $this->get('http://www.lastcraft.com/test/self_form.php'); - $this->assertNoUnwantedPattern('/

submitted<\/p>/i'); - $this->assertNoUnwantedPattern('/

wrong form<\/p>/i'); - $this->assertTitle('Test of form self submission'); + $this->assertNoUnwantedText('[Submitted]'); + $this->assertNoUnwantedText('[Wrong form]'); $this->assertTrue($this->clickSubmit()); - $this->assertWantedPattern('/

submitted<\/p>/i'); - $this->assertNoUnwantedPattern('/

wrong form<\/p>/i'); + $this->assertWantedText('[Submitted]'); + $this->assertNoUnwantedText('[Wrong form]'); $this->assertTitle('Test of form self submission'); } + function testSelfSubmitWithParameters() { + $this->get('http://www.lastcraft.com/test/self_form.php'); + $this->setFieldByName('visible', 'Resent'); + $this->assertTrue($this->clickSubmit()); + $this->assertWantedText('[Resent]'); + } + function testSettingOfBlankOption() { $this->get('http://www.lastcraft.com/test/form.html'); - $this->assertTrue($this->setField('d', '')); + $this->assertTrue($this->setFieldByName('d', '')); $this->clickSubmit('Go!'); $this->assertWantedText('d=[]'); } + + function testSendingMultipartFormDataEncodedForm() { + $this->get('http://www.lastcraft.com/test/form_data_encoded_form.html'); + $this->assertField('Text A', ''); + $this->assertField('Text B', 'Default text'); + $this->assertField('Text area C', ''); + $this->assertField('Selection D', 'd1'); + $this->assertField('Checkbox E', false); + $this->assertField('Checkbox F', 'on'); + $this->assertField('3', 'g3'); + $this->assertField('Selection H', 2); + $this->setField('Text A', 'aaa'); + $this->setField('Text B', 'bbb'); + $this->setField('Text area C', 'ccc'); + $this->setField('Selection D', 'D2'); + $this->setField('Checkbox E', 'on'); + $this->setField('Checkbox F', false); + $this->setField('2', 'g2'); + $this->setField('Selection H', 'H1'); + $this->assertTrue($this->clickSubmit('Go!')); + $this->assertWantedText('a=[aaa]'); + $this->assertWantedText('b=[bbb]'); + $this->assertWantedText('c=[ccc]'); + $this->assertWantedText('d=[d2]'); + $this->assertWantedText('e=[on]'); + $this->assertNoUnwantedText('f=['); + $this->assertWantedText('g=[g2]'); + $this->assertWantedText('h=[1]'); + $this->assertWantedText('go=[Go!]'); + } } class TestOfLiveMultiValueWidgets extends WebTestCase { - function setUp() { $this->addHeader('User-Agent: SimpleTest ' . SimpleTestOptions::getVersion()); } function testDefaultFormValueSubmission() { $this->get('http://www.lastcraft.com/test/multiple_widget_form.html'); - $this->assertField('a', array('a2', 'a3')); - $this->assertField('b', array('b2', 'b3')); - $this->assertField('c[]', array('c2', 'c3')); + $this->assertFieldByName('a', array('a2', 'a3')); + $this->assertFieldByName('b', array('b2', 'b3')); + $this->assertFieldByName('c[]', array('c2', 'c3')); $this->assertTrue($this->clickSubmit('Go!')); $this->assertWantedText('a=[a2, a3]'); $this->assertWantedText('b=[b2, b3]'); @@ -595,23 +698,35 @@ function testSubmittingMultipleValues() { $this->get('http://www.lastcraft.com/test/multiple_widget_form.html'); - $this->setField('a', array('a1', 'a4')); - $this->assertField('a', array('a1', 'a4')); - $this->assertField('a', array('a4', 'a1')); - $this->setField('b', array('b1', 'b4')); - $this->assertField('b', array('b1', 'b4')); - $this->setField('c[]', array('c1', 'c4')); + $this->setFieldByName('a', array('a1', 'a4')); + $this->assertFieldByName('a', array('a1', 'a4')); + $this->assertFieldByName('a', array('a4', 'a1')); + $this->setFieldByName('b', array('b1', 'b4')); + $this->assertFieldByName('b', array('b1', 'b4')); + $this->setFieldByName('c[]', array('c1', 'c4')); $this->assertField('c[]', array('c1', 'c4')); $this->assertTrue($this->clickSubmit('Go!')); $this->assertWantedText('a=[a1, a4]'); $this->assertWantedText('b=[b1, b4]'); $this->assertWantedText('c=[c1, c4]'); } - + + function testSubmittingMultipleValuesByLabel() { + $this->get('http://www.lastcraft.com/test/multiple_widget_form.html'); + $this->setField('Multiple selection A', array('a1', 'a4')); + $this->assertField('Multiple selection A', array('a1', 'a4')); + $this->assertField('Multiple selection A', array('a4', 'a1')); + $this->setField('multiple selection C', array('c1', 'c4')); + $this->assertField('multiple selection C', array('c1', 'c4')); + $this->assertTrue($this->clickSubmit('Go!')); + $this->assertWantedText('a=[a1, a4]'); + $this->assertWantedText('c=[c1, c4]'); + } + function testSavantStyleHiddenFieldDefaults() { $this->get('http://www.lastcraft.com/test/savant_style_form.html'); - $this->assertField('a', array('a0')); - $this->assertField('b', array('b0')); + $this->assertFieldByName('a', array('a0')); + $this->assertFieldByName('b', array('b0')); $this->assertTrue($this->clickSubmit('Go!')); $this->assertWantedText('a=[a0]'); $this->assertWantedText('b=[b0]'); @@ -619,8 +734,8 @@ function testSavantStyleHiddenDefaultsAreOverridden() { $this->get('http://www.lastcraft.com/test/savant_style_form.html'); - $this->assertTrue($this->setField('a', array('a1'))); - $this->assertTrue($this->setField('b', 'b1')); + $this->assertTrue($this->setFieldByName('a', array('a1'))); + $this->assertTrue($this->setFieldByName('b', 'b1')); $this->assertTrue($this->clickSubmit('Go!')); $this->assertWantedText('a=[a1]'); $this->assertWantedText('b=[b1]'); @@ -638,19 +753,55 @@ } } - class TestOfLiveHistoryNavigation extends WebTestCase { + class TestOfFileUploads extends WebTestCase { + function setUp() { + $this->addHeader('User-Agent: SimpleTest ' . SimpleTestOptions::getVersion()); + } + + function testSingleFileUpload() { + $this->get('http://www.lastcraft.com/test/upload_form.html'); + $this->assertTrue($this->setField('Content:', + dirname(__FILE__) . '/support/upload_sample.txt')); + $this->assertField('Content:', dirname(__FILE__) . '/support/upload_sample.txt'); + $this->click('Go!'); + $this->assertWantedText('Sample for testing file upload'); + } + function testMultipleFileUpload() { + $this->get('http://www.lastcraft.com/test/upload_form.html'); + $this->assertTrue($this->setField('Content:', + dirname(__FILE__) . '/support/upload_sample.txt')); + $this->assertTrue($this->setField('Supplemental:', + dirname(__FILE__) . '/support/supplementary_upload_sample.txt')); + $this->assertField('Supplemental:', + dirname(__FILE__) . '/support/supplementary_upload_sample.txt'); + $this->click('Go!'); + $this->assertWantedText('Sample for testing file upload'); + $this->assertWantedText('Some more text content'); + } + + function testBinaryFileUpload() { + $this->get('http://www.lastcraft.com/test/upload_form.html'); + $this->assertTrue($this->setField('Content:', + dirname(__FILE__) . '/support/latin1_sample')); + $this->click('Go!'); + $this->assertWantedText( + implode('', file(dirname(__FILE__) . '/support/latin1_sample'))); + } + } + + class TestOfLiveHistoryNavigation extends WebTestCase { function setUp() { $this->addHeader('User-Agent: SimpleTest ' . SimpleTestOptions::getVersion()); } function testRetry() { $this->get('http://www.lastcraft.com/test/cookie_based_counter.php'); - $this->assertWantedPattern('/count: 1/i'); + $this->assertPattern('/count: 1/i'); $this->retry(); - $this->assertWantedPattern('/count: 2/i'); + $this->assertPattern('/count: 2/i'); $this->retry(); - $this->assertWantedPattern('/count: 3/i'); + $this->assertPattern('/count: 3/i'); } function testOfBackButton() { @@ -667,10 +818,10 @@ function testGetRetryResubmitsData() { $this->assertTrue($this->get( 'http://www.lastcraft.com/test/network_confirm.php?a=aaa')); - $this->assertWantedPattern('/Request method.*?

GET<\/dd>/'); + $this->assertPattern('/Request method.*?
GET<\/dd>/'); $this->assertWantedText('a=[aaa]'); $this->retry(); - $this->assertWantedPattern('/Request method.*?
GET<\/dd>/'); + $this->assertPattern('/Request method.*?
GET<\/dd>/'); $this->assertWantedText('a=[aaa]'); } @@ -678,10 +829,10 @@ $this->assertTrue($this->get( 'http://www.lastcraft.com/test/network_confirm.php', array('a' => 'aaa'))); - $this->assertWantedPattern('/Request method.*?
GET<\/dd>/'); + $this->assertPattern('/Request method.*?
GET<\/dd>/'); $this->assertWantedText('a=[aaa]'); $this->retry(); - $this->assertWantedPattern('/Request method.*?
GET<\/dd>/'); + $this->assertPattern('/Request method.*?
GET<\/dd>/'); $this->assertWantedText('a=[aaa]'); } @@ -689,26 +840,25 @@ $this->assertTrue($this->post( 'http://www.lastcraft.com/test/network_confirm.php', array('a' => 'aaa'))); - $this->assertWantedPattern('/Request method.*?
POST<\/dd>/'); + $this->assertPattern('/Request method.*?
POST<\/dd>/'); $this->assertWantedText('a=[aaa]'); $this->retry(); - $this->assertWantedPattern('/Request method.*?
POST<\/dd>/'); + $this->assertPattern('/Request method.*?
POST<\/dd>/'); $this->assertWantedText('a=[aaa]'); } function testGetRetryResubmitsRepeatedData() { $this->assertTrue($this->get( 'http://www.lastcraft.com/test/network_confirm.php?a=1&a=2')); - $this->assertWantedPattern('/Request method.*?
GET<\/dd>/'); + $this->assertPattern('/Request method.*?
GET<\/dd>/'); $this->assertWantedText('a=[1, 2]'); $this->retry(); - $this->assertWantedPattern('/Request method.*?
GET<\/dd>/'); + $this->assertPattern('/Request method.*?
GET<\/dd>/'); $this->assertWantedText('a=[1, 2]'); } } class TestOfLiveAuthentication extends WebTestCase { - function setUp() { $this->addHeader('User-Agent: SimpleTest ' . SimpleTestOptions::getVersion()); } @@ -724,11 +874,32 @@ $this->assertResponse(200); } + function testTrailingSlashImpliedWithinRealm() { + $this->get('http://www.lastcraft.com/test/protected/'); + $this->authenticate('test', 'secret'); + $this->assertResponse(200); + $this->get('http://www.lastcraft.com/test/protected'); + $this->assertResponse(200); + } + + function testTrailingSlashImpliedSettingRealm() { + $this->get('http://www.lastcraft.com/test/protected'); + $this->authenticate('test', 'secret'); + $this->assertResponse(200); + $this->get('http://www.lastcraft.com/test/protected/'); + $this->assertResponse(200); + } + function testEncodedAuthenticationFetchesPage() { $this->get('http://test:secret@www.lastcraft.com/test/protected/'); $this->assertResponse(200); } - + + function testEncodedAuthenticationFetchesPageAfterTrailingSlashRedirect() { + $this->get('http://test:secret@www.lastcraft.com/test/protected'); + $this->assertResponse(200); + } + function testRealmExtendsToWholeDirectory() { $this->get('http://www.lastcraft.com/test/protected/1.html'); $this->authenticate('test', 'secret'); @@ -744,6 +915,12 @@ $this->assertTitle('Simple test target file'); } + function testRedirectKeepsEncodedAuthentication() { + $this->get('http://test:secret@www.lastcraft.com/test/protected/local_redirect.php'); + $this->assertResponse(200); + $this->assertTitle('Simple test target file'); + } + function testSessionRestartLosesAuthentication() { $this->get('http://www.lastcraft.com/test/protected/'); $this->authenticate('test', 'secret'); @@ -755,7 +932,6 @@ } class TestOfLoadingFrames extends WebTestCase { - function setUp() { $this->addHeader('User-Agent: SimpleTest ' . SimpleTestOptions::getVersion()); } @@ -881,7 +1057,7 @@ function testJumpToNamedPageReplacesJustThatFrame() { $this->get('http://www.lastcraft.com/test/messy_frameset.html'); - $this->assertWantedPattern('/Simple test front controller/'); + $this->assertPattern('/Simple test front controller/'); $this->clickLink('Index'); $this->assertResponse(200); $this->assertWantedText('[action=index]'); @@ -910,30 +1086,30 @@ $this->get('http://www.lastcraft.com/test/messy_frameset.html'); $this->clickLink('Empty query'); $this->assertResponse(200); - $this->assertWantedPattern('/Simple test front controller/'); - $this->assertWantedPattern('/raw get data.*?\[\].*?get data/si'); - $this->assertWantedPattern('/Count: 1/'); + $this->assertPattern('/Simple test front controller/'); + $this->assertPattern('/raw get data.*?\[\].*?get data/si'); + $this->assertPattern('/Count: 1/'); } function testJumpToUnnamedPageWithEmptyLinkReplacesJustThatFrame() { $this->get('http://www.lastcraft.com/test/messy_frameset.html'); $this->clickLink('Empty link'); $this->assertResponse(200); - $this->assertWantedPattern('/Simple test front controller/'); - $this->assertWantedPattern('/raw get data.*?\[\].*?get data/si'); - $this->assertWantedPattern('/Count: 1/'); + $this->assertPattern('/Simple test front controller/'); + $this->assertPattern('/raw get data.*?\[\].*?get data/si'); + $this->assertPattern('/Count: 1/'); } function testJumpBackADirectoryLevelReplacesJustThatFrame() { $this->get('http://www.lastcraft.com/test/messy_frameset.html'); $this->clickLink('Down one'); - $this->assertWantedPattern('/index of \/test/i'); - $this->assertWantedPattern('/Count: 1/'); + $this->assertPattern('/index of \/test/i'); + $this->assertPattern('/Count: 1/'); } function testSubmitToNamedPageReplacesJustThatFrame() { $this->get('http://www.lastcraft.com/test/messy_frameset.html'); - $this->assertWantedPattern('/Simple test front controller/'); + $this->assertPattern('/Simple test front controller/'); $this->clickSubmit('Index'); $this->assertResponse(200); $this->assertWantedText('[action=Index]'); @@ -967,8 +1143,8 @@ function testSubmitBackADirectoryLevelReplacesJustThatFrame() { $this->get('http://www.lastcraft.com/test/messy_frameset.html'); $this->clickSubmit('Down one'); - $this->assertWantedPattern('/index of \/test/i'); - $this->assertWantedPattern('/Count: 1/'); + $this->assertPattern('/index of \/test/i'); + $this->assertPattern('/Count: 1/'); } function testTopLinkExitsFrameset() { @@ -988,6 +1164,9 @@ } class TestOfFrameAuthentication extends WebTestCase { + function setUp() { + $this->addHeader('User-Agent: SimpleTest ' . SimpleTestOptions::getVersion()); + } function testUnauthenticatedFrameSendsChallenge() { $this->get('http://www.lastcraft.com/test/protected/'); @@ -1029,28 +1208,31 @@ } class TestOfNestedFrames extends WebTestCase { + function setUp() { + $this->addHeader('User-Agent: SimpleTest ' . SimpleTestOptions::getVersion()); + } function testCanNavigateToSpecificContent() { $this->get('http://www.lastcraft.com/test/nested_frameset.html'); $this->assertTitle('Nested frameset for testing of SimpleTest'); - $this->assertWantedPattern('/This is frame A/'); - $this->assertWantedPattern('/This is frame B/'); - $this->assertWantedPattern('/Simple test front controller/'); + $this->assertPattern('/This is frame A/'); + $this->assertPattern('/This is frame B/'); + $this->assertPattern('/Simple test front controller/'); $this->assertLink('2'); $this->assertLink('Set one to 2'); - $this->assertWantedPattern('/Count: 1/'); - $this->assertWantedPattern('/r=rrr/'); + $this->assertPattern('/Count: 1/'); + $this->assertPattern('/r=rrr/'); $this->setFrameFocus('pair'); - $this->assertWantedPattern('/This is frame A/'); - $this->assertWantedPattern('/This is frame B/'); - $this->assertNoUnwantedPattern('/Simple test front controller/'); + $this->assertPattern('/This is frame A/'); + $this->assertPattern('/This is frame B/'); + $this->assertNoPattern('/Simple test front controller/'); $this->assertNoLink('2'); $this->setFrameFocus('aaa'); - $this->assertWantedPattern('/This is frame A/'); - $this->assertNoUnwantedPattern('/This is frame B/'); + $this->assertPattern('/This is frame A/'); + $this->assertNoPattern('/This is frame B/'); $this->clearFrameFocus(); $this->assertResponse(200); @@ -1058,28 +1240,28 @@ $this->assertResponse(200); $this->setFrameFocus('Front controller'); $this->assertResponse(200); - $this->assertWantedPattern('/Simple test front controller/'); + $this->assertPattern('/Simple test front controller/'); $this->assertNoLink('2'); } function testReloadingFramesetPage() { $this->get('http://www.lastcraft.com/test/nested_frameset.html'); - $this->assertWantedPattern('/Count: 1/'); + $this->assertPattern('/Count: 1/'); $this->retry(); - $this->assertWantedPattern('/Count: 2/'); + $this->assertPattern('/Count: 2/'); $this->retry(); - $this->assertWantedPattern('/Count: 3/'); + $this->assertPattern('/Count: 3/'); } function testRetryingNestedPageOnlyRetriesThatSet() { $this->get('http://www.lastcraft.com/test/nested_frameset.html'); - $this->assertWantedPattern('/Count: 1/'); + $this->assertPattern('/Count: 1/'); $this->setFrameFocus('messy'); $this->retry(); - $this->assertWantedPattern('/Count: 2/'); + $this->assertPattern('/Count: 2/'); $this->setFrameFocus('Counter'); $this->retry(); - $this->assertWantedPattern('/Count: 3/'); + $this->assertPattern('/Count: 3/'); $this->clearFrameFocus(); $this->setFrameFocus('messy'); @@ -1087,7 +1269,7 @@ $this->retry(); $this->clearFrameFocus(); - $this->assertWantedPattern('/Count: 3/'); + $this->assertPattern('/Count: 3/'); } function testAuthenticatingNestedPage() { @@ -1100,7 +1282,7 @@ $this->authenticate('test', 'secret'); $this->assertResponse(200); - $this->assertWantedPattern('/A target for the SimpleTest test suite/'); + $this->assertPattern('/A target for the SimpleTest test suite/'); } } ?> \ No newline at end of file diff --git a/vendors/simpletest/test/all_tests.php b/vendors/simpletest/test/all_tests.php index 92615f06b..720f58f5e 100644 --- a/vendors/simpletest/test/all_tests.php +++ b/vendors/simpletest/test/all_tests.php @@ -1,28 +1,11 @@ GroupTest('All tests for SimpleTest ' . SimpleTestOptions::getVersion()); - $this->addTestCase(new UnitTests()); - $this->addTestFile('shell_test.php'); - $this->addTestFile('live_test.php'); - $this->addTestFile('acceptance_test.php'); - $this->addTestFile('real_sites_test.php'); - } + if (! defined('TEST')) { + define('TEST', __FILE__); } - + require_once(dirname(__FILE__) . '/test_groups.php'); + require_once(dirname(__FILE__) . '/../reporter.php'); + $test = &new AllTests(); if (SimpleReporter::inCli()) { exit ($test->run(new TextReporter()) ? 0 : 1); diff --git a/vendors/simpletest/test/authentication_test.php b/vendors/simpletest/test/authentication_test.php index dd1b14c27..f132ea9cb 100644 --- a/vendors/simpletest/test/authentication_test.php +++ b/vendors/simpletest/test/authentication_test.php @@ -38,6 +38,14 @@ new SimpleUrl('http://www.here.com/pathmore/hello.html'))); } + function testInsideWithMissingTrailingSlash() { + $realm = &new SimpleRealm( + 'Basic', + new SimpleUrl('http://www.here.com/path/')); + $this->assertTrue($realm->isWithin( + new SimpleUrl('http://www.here.com/path'))); + } + function testDifferentPageNameStillInside() { $realm = &new SimpleRealm( 'Basic', diff --git a/vendors/simpletest/test/browser_test.php b/vendors/simpletest/test/browser_test.php index 81f9fba48..ad0fd35ae 100644 --- a/vendors/simpletest/test/browser_test.php +++ b/vendors/simpletest/test/browser_test.php @@ -24,7 +24,6 @@ function testEmptyHistoryHasFalseContents() { $history = &new SimpleBrowserHistory(); - $this->assertIdentical($history->getMethod(), false); $this->assertIdentical($history->getUrl(), false); $this->assertIdentical($history->getParameters(), false); } @@ -38,130 +37,107 @@ function testCurrentTargetAccessors() { $history = &new SimpleBrowserHistory(); $history->recordEntry( - 'GET', new SimpleUrl('http://www.here.com/'), - new SimpleFormEncoding()); - $this->assertIdentical($history->getMethod(), 'GET'); + new SimpleGetEncoding()); $this->assertIdentical($history->getUrl(), new SimpleUrl('http://www.here.com/')); - $this->assertIdentical($history->getParameters(), new SimpleFormEncoding()); + $this->assertIdentical($history->getParameters(), new SimpleGetEncoding()); } function testSecondEntryAccessors() { $history = &new SimpleBrowserHistory(); $history->recordEntry( - 'GET', new SimpleUrl('http://www.first.com/'), - new SimpleFormEncoding()); + new SimpleGetEncoding()); $history->recordEntry( - 'POST', new SimpleUrl('http://www.second.com/'), - new SimpleFormEncoding(array('a' => 1))); - $this->assertIdentical($history->getMethod(), 'POST'); + new SimplePostEncoding(array('a' => 1))); $this->assertIdentical($history->getUrl(), new SimpleUrl('http://www.second.com/')); $this->assertIdentical( $history->getParameters(), - new SimpleFormEncoding(array('a' => 1))); + new SimplePostEncoding(array('a' => 1))); } function testGoingBackwards() { $history = &new SimpleBrowserHistory(); $history->recordEntry( - 'GET', new SimpleUrl('http://www.first.com/'), - new SimpleFormEncoding()); + new SimpleGetEncoding()); $history->recordEntry( - 'POST', new SimpleUrl('http://www.second.com/'), - new SimpleFormEncoding(array('a' => 1))); + new SimplePostEncoding(array('a' => 1))); $this->assertTrue($history->back()); - $this->assertIdentical($history->getMethod(), 'GET'); $this->assertIdentical($history->getUrl(), new SimpleUrl('http://www.first.com/')); - $this->assertIdentical($history->getParameters(), new SimpleFormEncoding()); + $this->assertIdentical($history->getParameters(), new SimpleGetEncoding()); } function testGoingBackwardsOffBeginning() { $history = &new SimpleBrowserHistory(); $history->recordEntry( - 'GET', new SimpleUrl('http://www.first.com/'), - new SimpleFormEncoding()); + new SimpleGetEncoding()); $this->assertFalse($history->back()); - $this->assertIdentical($history->getMethod(), 'GET'); $this->assertIdentical($history->getUrl(), new SimpleUrl('http://www.first.com/')); - $this->assertIdentical($history->getParameters(), new SimpleFormEncoding()); + $this->assertIdentical($history->getParameters(), new SimpleGetEncoding()); } function testGoingForwardsOffEnd() { $history = &new SimpleBrowserHistory(); $history->recordEntry( - 'GET', new SimpleUrl('http://www.first.com/'), - new SimpleFormEncoding()); + new SimpleGetEncoding()); $this->assertFalse($history->forward()); - $this->assertIdentical($history->getMethod(), 'GET'); $this->assertIdentical($history->getUrl(), new SimpleUrl('http://www.first.com/')); - $this->assertIdentical($history->getParameters(), new SimpleFormEncoding()); + $this->assertIdentical($history->getParameters(), new SimpleGetEncoding()); } function testGoingBackwardsAndForwards() { $history = &new SimpleBrowserHistory(); $history->recordEntry( - 'GET', new SimpleUrl('http://www.first.com/'), - new SimpleFormEncoding()); + new SimpleGetEncoding()); $history->recordEntry( - 'POST', new SimpleUrl('http://www.second.com/'), - new SimpleFormEncoding(array('a' => 1))); + new SimplePostEncoding(array('a' => 1))); $this->assertTrue($history->back()); $this->assertTrue($history->forward()); - $this->assertIdentical($history->getMethod(), 'POST'); $this->assertIdentical($history->getUrl(), new SimpleUrl('http://www.second.com/')); $this->assertIdentical( $history->getParameters(), - new SimpleFormEncoding(array('a' => 1))); + new SimplePostEncoding(array('a' => 1))); } function testNewEntryReplacesNextOne() { $history = &new SimpleBrowserHistory(); $history->recordEntry( - 'GET', new SimpleUrl('http://www.first.com/'), - new SimpleFormEncoding()); + new SimpleGetEncoding()); $history->recordEntry( - 'POST', new SimpleUrl('http://www.second.com/'), - new SimpleFormEncoding(array('a' => 1))); + new SimplePostEncoding(array('a' => 1))); $history->back(); $history->recordEntry( - 'GET', new SimpleUrl('http://www.third.com/'), - new SimpleFormEncoding()); - $this->assertIdentical($history->getMethod(), 'GET'); + new SimpleGetEncoding()); $this->assertIdentical($history->getUrl(), new SimpleUrl('http://www.third.com/')); - $this->assertIdentical($history->getParameters(), new SimpleFormEncoding()); + $this->assertIdentical($history->getParameters(), new SimpleGetEncoding()); } function testNewEntryDropsFutureEntries() { $history = &new SimpleBrowserHistory(); $history->recordEntry( - 'GET', new SimpleUrl('http://www.first.com/'), - new SimpleFormEncoding()); + new SimpleGetEncoding()); $history->recordEntry( - 'GET', new SimpleUrl('http://www.second.com/'), - new SimpleFormEncoding()); + new SimpleGetEncoding()); $history->recordEntry( - 'GET', new SimpleUrl('http://www.third.com/'), - new SimpleFormEncoding()); + new SimpleGetEncoding()); $history->back(); $history->back(); $history->recordEntry( - 'GET', new SimpleUrl('http://www.fourth.com/'), - new SimpleFormEncoding()); + new SimpleGetEncoding()); $this->assertIdentical($history->getUrl(), new SimpleUrl('http://www.fourth.com/')); $this->assertFalse($history->forward()); $history->back(); @@ -247,17 +223,17 @@ function testFormHandling() { $page = &new MockSimplePage($this); - $page->setReturnValue('getField', 'Value'); - $page->expectOnce('getField', array('key')); - $page->expectOnce('setField', array('key', 'Value')); + $page->setReturnValue('getFieldByName', 'Value'); + $page->expectOnce('getFieldByName', array('key')); + $page->expectOnce('setFieldByName', array('key', 'Value')); $page->setReturnValue('getFieldById', 'Id value'); $page->expectOnce('getFieldById', array(99)); $page->expectOnce('setFieldById', array(99, 'Id value')); $browser = &$this->loadPage($page); - $this->assertEqual($browser->getField('key'), 'Value'); + $this->assertEqual($browser->getFieldByName('key'), 'Value'); $this->assertEqual($browser->getFieldById(99), 'Id value'); - $browser->setField('key', 'Value'); + $browser->setFieldByName('key', 'Value'); $browser->setFieldById(99, 'Id value'); $page->tally(); @@ -280,11 +256,11 @@ $agent->expectArgumentsAt( 0, 'fetchResponse', - array('GET', new SimpleUrl('http://this.com/page.html'), false)); + array(new SimpleUrl('http://this.com/page.html'), new SimpleGetEncoding())); $agent->expectArgumentsAt( 1, 'fetchResponse', - array('GET', new SimpleUrl('http://this.com/new.html'), false)); + array(new SimpleUrl('http://this.com/new.html'), new SimpleGetEncoding())); $agent->expectCallCount('fetchResponse', 2); $page = &new MockSimplePage($this); @@ -306,13 +282,13 @@ $agent->expectArgumentsAt( 0, 'fetchResponse', - array('GET', new SimpleUrl('http://this.com/page.html'), false)); + array(new SimpleUrl('http://this.com/page.html'), new SimpleGetEncoding())); $target = new SimpleUrl('http://this.com/new.html'); $target->setTarget('missing'); $agent->expectArgumentsAt( 1, 'fetchResponse', - array('GET', $target, false)); + array($target, new SimpleGetEncoding())); $agent->expectCallCount('fetchResponse', 2); $parsed_url = new SimpleUrl('http://this.com/new.html'); @@ -351,7 +327,7 @@ $agent->expectArgumentsAt( 1, 'fetchResponse', - array('GET', new SimpleUrl('1.html'), false)); + array(new SimpleUrl('1.html'), new SimpleGetEncoding())); $agent->expectCallCount('fetchResponse', 2); $page = &new MockSimplePage($this); @@ -371,9 +347,8 @@ $agent = &new MockSimpleUserAgent($this); $agent->setReturnReference('fetchResponse', new MockSimpleHttpResponse($this)); $agent->expectArgumentsAt(1, 'fetchResponse', array( - 'GET', new SimpleUrl('http://this.com/link.html'), - false)); + new SimpleGetEncoding())); $agent->expectCallCount('fetchResponse', 2); $page = &new MockSimplePage($this); @@ -405,16 +380,15 @@ $agent = &new MockSimpleUserAgent($this); $agent->setReturnReference('fetchResponse', new MockSimpleHttpResponse($this)); $agent->expectArgumentsAt(1, 'fetchResponse', array( - 'POST', new SimpleUrl('http://this.com/handler.html'), - new SimpleFormEncoding(array('a' => 'A')))); + new SimplePostEncoding(array('a' => 'A')))); $agent->expectCallCount('fetchResponse', 2); $form = &new MockSimpleForm($this); $form->setReturnValue('getAction', new SimpleUrl('http://this.com/handler.html')); $form->setReturnValue('getMethod', 'post'); - $form->setReturnValue('submitButtonByLabel', new SimpleFormEncoding(array('a' => 'A'))); - $form->expectOnce('submitButtonByLabel', array('Go', false)); + $form->setReturnValue('submitButton', new SimplePostEncoding(array('a' => 'A'))); + $form->expectOnce('submitButton', array(new SimpleByLabel('Go'), false)); $page = &new MockSimplePage($this); $page->setReturnReference('getFormBySubmitLabel', $form); @@ -434,15 +408,14 @@ $agent = &new MockSimpleUserAgent($this); $agent->setReturnReference('fetchResponse', new MockSimpleHttpResponse($this)); $agent->expectArgumentsAt(1, 'fetchResponse', array( - 'GET', new SimpleUrl('http://this.com/page.html'), - new SimpleFormEncoding(array('a' => 'A')))); + new SimpleGetEncoding(array('a' => 'A')))); $agent->expectCallCount('fetchResponse', 2); $form = &new MockSimpleForm($this); $form->setReturnValue('getAction', new SimpleUrl('http://this.com/page.html')); $form->setReturnValue('getMethod', 'get'); - $form->setReturnValue('submitButtonByLabel', new SimpleFormEncoding(array('a' => 'A'))); + $form->setReturnValue('submitButton', new SimpleGetEncoding(array('a' => 'A'))); $page = &new MockSimplePage($this); $page->setReturnReference('getFormBySubmitLabel', $form); @@ -466,7 +439,7 @@ $form = &new MockSimpleForm($this); $form->setReturnValue('getAction', new SimpleUrl('http://this.com/handler.html')); $form->setReturnValue('getMethod', 'post'); - $form->setReturnValue('submitButtonByName', new SimpleFormEncoding(array('a' => 'A'))); + $form->setReturnValue('submitButton', new SimplePostEncoding(array('a' => 'A'))); $page = &new MockSimplePage($this); $page->setReturnReference('getFormBySubmitName', $form); @@ -487,8 +460,8 @@ $form = &new MockSimpleForm($this); $form->setReturnValue('getAction', new SimpleUrl('http://this.com/handler.html')); $form->setReturnValue('getMethod', 'post'); - $form->setReturnValue('submitButtonById', new SimpleFormEncoding(array('a' => 'A'))); - $form->expectOnce('submitButtonById', array(99, false)); + $form->setReturnValue('submitButton', new SimplePostEncoding(array('a' => 'A'))); + $form->expectOnce('submitButton', array(new SimpleById(99), false)); $page = &new MockSimplePage($this); $page->setReturnReference('getFormBySubmitId', $form); @@ -510,8 +483,8 @@ $form = &new MockSimpleForm($this); $form->setReturnValue('getAction', new SimpleUrl('http://this.com/handler.html')); $form->setReturnValue('getMethod', 'post'); - $form->setReturnValue('submitImageByLabel', new SimpleFormEncoding(array('a' => 'A'))); - $form->expectOnce('submitImageByLabel', array('Go!', 10, 11, false)); + $form->setReturnValue('submitImage', new SimplePostEncoding(array('a' => 'A'))); + $form->expectOnce('submitImage', array(new SimpleByLabel('Go!'), 10, 11, false)); $page = &new MockSimplePage($this); $page->setReturnReference('getFormByImageLabel', $form); @@ -533,8 +506,8 @@ $form = &new MockSimpleForm($this); $form->setReturnValue('getAction', new SimpleUrl('http://this.com/handler.html')); $form->setReturnValue('getMethod', 'post'); - $form->setReturnValue('submitImageByName', new SimpleFormEncoding(array('a' => 'A'))); - $form->expectOnce('submitImageByName', array('a', 10, 11, false)); + $form->setReturnValue('submitImage', new SimplePostEncoding(array('a' => 'A'))); + $form->expectOnce('submitImage', array(new SimpleByName('a'), 10, 11, false)); $page = &new MockSimplePage($this); $page->setReturnReference('getFormByImageName', $form); @@ -556,8 +529,8 @@ $form = &new MockSimpleForm($this); $form->setReturnValue('getAction', new SimpleUrl('http://this.com/handler.html')); $form->setReturnValue('getMethod', 'post'); - $form->setReturnValue('submitImageById', new SimpleFormEncoding(array('a' => 'A'))); - $form->expectOnce('submitImageById', array(99, 10, 11, false)); + $form->setReturnValue('submitImage', new SimplePostEncoding(array('a' => 'A'))); + $form->expectOnce('submitImage', array(new SimpleById(99), 10, 11, false)); $page = &new MockSimplePage($this); $page->setReturnReference('getFormByImageId', $form); @@ -576,15 +549,14 @@ $agent = &new MockSimpleUserAgent($this); $agent->setReturnReference('fetchResponse', new MockSimpleHttpResponse($this)); $agent->expectArgumentsAt(1, 'fetchResponse', array( - 'POST', new SimpleUrl('http://this.com/handler.html'), - new SimpleFormEncoding(array('a' => 'A')))); + new SimplePostEncoding(array('a' => 'A')))); $agent->expectCallCount('fetchResponse', 2); $form = &new MockSimpleForm($this); $form->setReturnValue('getAction', new SimpleUrl('http://this.com/handler.html')); $form->setReturnValue('getMethod', 'post'); - $form->setReturnValue('submit', new SimpleFormEncoding(array('a' => 'A'))); + $form->setReturnValue('submit', new SimplePostEncoding(array('a' => 'A'))); $page = &new MockSimplePage($this); $page->setReturnReference('getFormById', $form); @@ -616,7 +588,7 @@ $response = &new MockSimpleHttpResponse($this); $response->setReturnValue('getUrl', $url); $response->setReturnValue('getContent', $raw); - $agent->setReturnReference('fetchResponse', $response, array('*', $url, '*')); + $agent->setReturnReference('fetchResponse', $response, array($url, '*')); } return $agent; } diff --git a/vendors/simpletest/test/collector_test.php b/vendors/simpletest/test/collector_test.php new file mode 100644 index 000000000..7a03dcf7d --- /dev/null +++ b/vendors/simpletest/test/collector_test.php @@ -0,0 +1,59 @@ +EqualExpectation(str_replace('\\', '/', $value), $message); + } + + function test($compare) { + return parent::test(str_replace('\\', '/', $compare)); + } +} + +class TestOfCollector extends UnitTestCase { + + function testCollectionIsAddedToGroup() { + $group = &new MockGroupTest($this); + $group->expectMinimumCallCount('addTestFile', 2); + $group->expectArguments( + 'addTestFile', + array(new PatternExpectation('/collectable\\.(1|2)$/'))); + + $collector = &new SimpleCollector(); + $collector->collect($group, dirname(__FILE__) . '/support/collector/'); + + $group->tally(); + } +} + +class TestOfPatternCollector extends UnitTestCase { + + function testAddingEverythingToGroup() { + $group = &new MockGroupTest($this); + $group->expectCallCount('addTestFile', 2); + $group->expectArguments( + 'addTestFile', + array(new PatternExpectation('/collectable\\.(1|2)$/'))); + + $collector = &new SimplePatternCollector(); + $collector->collect($group, dirname(__FILE__) . '/support/collector/', '/.*/'); + + $group->tally(); + } + + function testOnlyMatchedFilesAreAddedToGroup() { + $group = &new MockGroupTest($this); + $group->expectOnce('addTestFile', array(new PathEqualExpectation( + dirname(__FILE__) . '/support/collector/collectable.1'))); + + $collector = &new SimplePatternCollector(); + $collector->collect($group, dirname(__FILE__) . '/support/collector/', '/1$/'); + + $group->tally(); + } +} +?> \ No newline at end of file diff --git a/vendors/simpletest/test/dumper_test.php b/vendors/simpletest/test/dumper_test.php index 179ccdc62..a61ded230 100644 --- a/vendors/simpletest/test/dumper_test.php +++ b/vendors/simpletest/test/dumper_test.php @@ -40,46 +40,46 @@ function testDescribeNull() { $dumper = new SimpleDumper(); - $this->assertWantedPattern('/null/i', $dumper->describeValue(null)); + $this->assertPattern('/null/i', $dumper->describeValue(null)); } function testDescribeBoolean() { $dumper = new SimpleDumper(); - $this->assertWantedPattern('/boolean/i', $dumper->describeValue(true)); - $this->assertWantedPattern('/true/i', $dumper->describeValue(true)); - $this->assertWantedPattern('/false/i', $dumper->describeValue(false)); + $this->assertPattern('/boolean/i', $dumper->describeValue(true)); + $this->assertPattern('/true/i', $dumper->describeValue(true)); + $this->assertPattern('/false/i', $dumper->describeValue(false)); } function testDescribeString() { $dumper = new SimpleDumper(); - $this->assertWantedPattern('/string/i', $dumper->describeValue('Hello')); - $this->assertWantedPattern('/Hello/', $dumper->describeValue('Hello')); + $this->assertPattern('/string/i', $dumper->describeValue('Hello')); + $this->assertPattern('/Hello/', $dumper->describeValue('Hello')); } function testDescribeInteger() { $dumper = new SimpleDumper(); - $this->assertWantedPattern('/integer/i', $dumper->describeValue(35)); - $this->assertWantedPattern('/35/', $dumper->describeValue(35)); + $this->assertPattern('/integer/i', $dumper->describeValue(35)); + $this->assertPattern('/35/', $dumper->describeValue(35)); } function testDescribeFloat() { $dumper = new SimpleDumper(); - $this->assertWantedPattern('/float/i', $dumper->describeValue(0.99)); - $this->assertWantedPattern('/0\.99/', $dumper->describeValue(0.99)); + $this->assertPattern('/float/i', $dumper->describeValue(0.99)); + $this->assertPattern('/0\.99/', $dumper->describeValue(0.99)); } function testDescribeArray() { $dumper = new SimpleDumper(); - $this->assertWantedPattern('/array/i', $dumper->describeValue(array(1, 4))); - $this->assertWantedPattern('/2/i', $dumper->describeValue(array(1, 4))); + $this->assertPattern('/array/i', $dumper->describeValue(array(1, 4))); + $this->assertPattern('/2/i', $dumper->describeValue(array(1, 4))); } function testDescribeObject() { $dumper = new SimpleDumper(); - $this->assertWantedPattern( + $this->assertPattern( '/object/i', $dumper->describeValue(new DumperDummy())); - $this->assertWantedPattern( + $this->assertPattern( '/DumperDummy/i', $dumper->describeValue(new DumperDummy())); } diff --git a/vendors/simpletest/test/encoding_test.php b/vendors/simpletest/test/encoding_test.php index b65cd73f7..614e24ae2 100644 --- a/vendors/simpletest/test/encoding_test.php +++ b/vendors/simpletest/test/encoding_test.php @@ -2,133 +2,186 @@ // $Id$ require_once(dirname(__FILE__) . '/../url.php'); + require_once(dirname(__FILE__) . '/../socket.php'); - class FormEncodingTestCase extends UnitTestCase { + Mock::generate('SimpleSocket'); + + class TestOfEncodedParts extends UnitTestCase { - function testEmpty() { - $encoding = &new SimpleFormEncoding(); + function testFormEncodedAsKeyEqualsValue() { + $pair = new SimpleEncodedPair('a', 'A'); + $this->assertEqual($pair->asRequest(), 'a=A'); + } + + function testMimeEncodedAsHeadersAndContent() { + $pair = new SimpleEncodedPair('a', 'A'); + $this->assertEqual( + $pair->asMime(), + "Content-Disposition: form-data; name=\"a\"\r\n\r\nA"); + } + + function testAttachmentEncodedAsHeadersWithDispositionAndContent() { + $part = new SimpleAttachment('a', 'A', 'aaa.txt'); + $this->assertEqual( + $part->asMime(), + "Content-Disposition: form-data; name=\"a\"; filename=\"aaa.txt\"\r\n" . + "Content-Type: text/plain\r\n\r\nA"); + } + } + + class TestOfEncoding extends UnitTestCase { + var $_content_so_far; + + function write($content) { + $this->_content_so_far .= $content; + } + + function clear() { + $this->_content_so_far = ''; + } + + function assertWritten($encoding, $content, $message = '%s') { + $this->clear(); + $encoding->writeTo($this); + $this->assertIdentical($this->_content_so_far, $content, $message); + } + + function testGetEmpty() { + $encoding = &new SimpleGetEncoding(); $this->assertIdentical($encoding->getValue('a'), false); - $this->assertIdentical($encoding->getKeys(), array()); - $this->assertIdentical($encoding->asString(), ''); + $this->assertIdentical($encoding->asUrlRequest(), ''); + } + + function testPostEmpty() { + $encoding = &new SimplePostEncoding(); + $this->assertIdentical($encoding->getValue('a'), false); + $this->assertWritten($encoding, ''); } function testPrefilled() { - $encoding = &new SimpleFormEncoding(array('a' => 'aaa')); + $encoding = &new SimplePostEncoding(array('a' => 'aaa')); $this->assertIdentical($encoding->getValue('a'), 'aaa'); - $this->assertIdentical($encoding->getKeys(), array('a')); - $this->assertIdentical($encoding->asString(), 'a=aaa'); + $this->assertWritten($encoding, 'a=aaa'); } function testPrefilledWithObject() { - $encoding = &new SimpleFormEncoding(new SimpleFormEncoding(array('a' => 'aaa'))); + $encoding = &new SimplePostEncoding(new SimpleEncoding(array('a' => 'aaa'))); $this->assertIdentical($encoding->getValue('a'), 'aaa'); - $this->assertIdentical($encoding->getKeys(), array('a')); - $this->assertIdentical($encoding->asString(), 'a=aaa'); + $this->assertWritten($encoding, 'a=aaa'); } function testMultiplePrefilled() { - $encoding = &new SimpleFormEncoding(array('a' => array('a1', 'a2'))); + $encoding = &new SimplePostEncoding(array('a' => array('a1', 'a2'))); $this->assertIdentical($encoding->getValue('a'), array('a1', 'a2')); - $this->assertIdentical($encoding->asString(), 'a=a1&a=a2'); + $this->assertWritten($encoding, 'a=a1&a=a2'); } function testSingleParameter() { - $encoding = &new SimpleFormEncoding(); + $encoding = &new SimplePostEncoding(); $encoding->add('a', 'Hello'); $this->assertEqual($encoding->getValue('a'), 'Hello'); - $this->assertIdentical($encoding->asString(), 'a=Hello'); + $this->assertWritten($encoding, 'a=Hello'); } function testFalseParameter() { - $encoding = &new SimpleFormEncoding(); + $encoding = &new SimplePostEncoding(); $encoding->add('a', false); $this->assertEqual($encoding->getValue('a'), false); - $this->assertIdentical($encoding->asString(), ''); + $this->assertWritten($encoding, ''); } function testUrlEncoding() { - $encoding = &new SimpleFormEncoding(); + $encoding = &new SimplePostEncoding(); $encoding->add('a', 'Hello there!'); - $this->assertIdentical($encoding->asString(), 'a=Hello+there%21'); + $this->assertWritten($encoding, 'a=Hello+there%21'); } function testMultipleParameter() { - $encoding = &new SimpleFormEncoding(); + $encoding = &new SimplePostEncoding(); $encoding->add('a', 'Hello'); $encoding->add('b', 'Goodbye'); - $this->assertIdentical($encoding->asString(), 'a=Hello&b=Goodbye'); + $this->assertWritten($encoding, 'a=Hello&b=Goodbye'); } function testEmptyParameters() { - $encoding = &new SimpleFormEncoding(); + $encoding = &new SimplePostEncoding(); $encoding->add('a', ''); $encoding->add('b', ''); - $this->assertIdentical($encoding->asString(), 'a=&b='); + $this->assertWritten($encoding, 'a=&b='); } function testRepeatedParameter() { - $encoding = &new SimpleFormEncoding(); + $encoding = &new SimplePostEncoding(); $encoding->add('a', 'Hello'); $encoding->add('a', 'Goodbye'); $this->assertIdentical($encoding->getValue('a'), array('Hello', 'Goodbye')); - $this->assertIdentical($encoding->asString(), 'a=Hello&a=Goodbye'); - } - - function testDefaultCoordinatesAreUnset() { - $encoding = &new SimpleFormEncoding(); - $this->assertIdentical($encoding->getX(), false); - $this->assertIdentical($encoding->getY(), false); - } - - function testSettingCoordinates() { - $encoding = &new SimpleFormEncoding(); - $encoding->setCoordinates('32', '45'); - $this->assertIdentical($encoding->getX(), 32); - $this->assertIdentical($encoding->getY(), 45); - $this->assertIdentical($encoding->asString(), '?32,45'); - } - - function testClearingCordinates() { - $encoding = &new SimpleFormEncoding(); - $encoding->setCoordinates('32', '45'); - $encoding->setCoordinates(); - $this->assertIdentical($encoding->getX(), false); - $this->assertIdentical($encoding->getY(), false); + $this->assertWritten($encoding, 'a=Hello&a=Goodbye'); } function testAddingLists() { - $encoding = &new SimpleFormEncoding(); + $encoding = &new SimplePostEncoding(); $encoding->add('a', array('Hello', 'Goodbye')); $this->assertIdentical($encoding->getValue('a'), array('Hello', 'Goodbye')); - $this->assertIdentical($encoding->asString(), 'a=Hello&a=Goodbye'); + $this->assertWritten($encoding, 'a=Hello&a=Goodbye'); } function testMergeInHash() { - $encoding = &new SimpleFormEncoding(array('a' => 'A1', 'b' => 'B')); + $encoding = &new SimpleGetEncoding(array('a' => 'A1', 'b' => 'B')); $encoding->merge(array('a' => 'A2')); $this->assertIdentical($encoding->getValue('a'), array('A1', 'A2')); $this->assertIdentical($encoding->getValue('b'), 'B'); } function testMergeInObject() { - $encoding = &new SimpleFormEncoding(array('a' => 'A1', 'b' => 'B')); - $encoding->merge(new SimpleFormEncoding(array('a' => 'A2'))); + $encoding = &new SimpleGetEncoding(array('a' => 'A1', 'b' => 'B')); + $encoding->merge(new SimpleEncoding(array('a' => 'A2'))); $this->assertIdentical($encoding->getValue('a'), array('A1', 'A2')); $this->assertIdentical($encoding->getValue('b'), 'B'); } - function testMergeInObjectWithCordinates() { - $incoming = new SimpleFormEncoding(array('a' => 'A2')); - $incoming->setCoordinates(25, 24); - - $encoding = &new SimpleFormEncoding(array('a' => 'A1')); - $encoding->setCoordinates(1, 2); - $encoding->merge($incoming); - - $this->assertIdentical($encoding->getValue('a'), array('A1', 'A2')); - $this->assertIdentical($encoding->getX(), 25); - $this->assertIdentical($encoding->getY(), 24); - $this->assertIdentical($encoding->asString(), 'a=A1&a=A2?25,24'); + function testPrefilledMultipart() { + $encoding = &new SimpleMultipartEncoding(array('a' => 'aaa'), 'boundary'); + $this->assertIdentical($encoding->getValue('a'), 'aaa'); + $this->assertwritten($encoding, + "--boundary\r\n" . + "Content-Disposition: form-data; name=\"a\"\r\n" . + "\r\n" . + "aaa\r\n" . + "--boundary--\r\n"); + } + + function testAttachment() { + $encoding = &new SimpleMultipartEncoding(array(), 'boundary'); + $encoding->attach('a', 'aaa', 'aaa.txt'); + $this->assertIdentical($encoding->getValue('a'), 'aaa.txt'); + $this->assertwritten($encoding, + "--boundary\r\n" . + "Content-Disposition: form-data; name=\"a\"; filename=\"aaa.txt\"\r\n" . + "Content-Type: text/plain\r\n" . + "\r\n" . + "aaa\r\n" . + "--boundary--\r\n"); + } + } + + class TestOfFormHeaders extends UnitTestCase { + + function testEmptyEncodingWritesZeroContentLength() { + $socket = &new MockSimpleSocket($this); + $socket->expectArgumentsAt(0, 'write', array("Content-Length: 0\r\n")); + $socket->expectArgumentsAt(1, 'write', array("Content-Type: application/x-www-form-urlencoded\r\n")); + $encoding = &new SimplePostEncoding(); + $encoding->writeHeadersTo($socket); + $socket->tally(); + } + + function testEmptyMultipartEncodingWritesEndBoundaryContentLength() { + $socket = &new MockSimpleSocket($this); + $socket->expectArgumentsAt(0, 'write', array("Content-Length: 14\r\n")); + $socket->expectArgumentsAt(1, 'write', array("Content-Type: multipart/form-data, boundary=boundary\r\n")); + $encoding = &new SimpleMultipartEncoding(array(), 'boundary'); + $encoding->writeHeadersTo($socket); + $socket->tally(); } } ?> \ No newline at end of file diff --git a/vendors/simpletest/test/expectation_test.php b/vendors/simpletest/test/expectation_test.php index 52d7cfc1d..73a032678 100644 --- a/vendors/simpletest/test/expectation_test.php +++ b/vendors/simpletest/test/expectation_test.php @@ -8,10 +8,10 @@ $is_true = &new EqualExpectation(true); $this->assertTrue($is_true->test(true)); $this->assertFalse($is_true->test(false)); - $this->assertWantedPattern( + $this->assertPattern( '/equal expectation.*?boolean: true/i', $is_true->testMessage(true)); - $this->assertWantedPattern( + $this->assertPattern( '/fails.*?boolean.*?boolean/i', $is_true->testMessage(false)); } @@ -20,9 +20,9 @@ $hello = &new EqualExpectation("Hello"); $this->assertTrue($hello->test("Hello")); $this->assertFalse($hello->test("Goodbye")); - $this->assertWantedPattern('/Equal expectation.*?Hello/', $hello->testMessage("Hello")); - $this->assertWantedPattern('/fails/', $hello->testMessage("Goodbye")); - $this->assertWantedPattern('/fails.*?goodbye/i', $hello->testMessage("Goodbye")); + $this->assertPattern('/Equal expectation.*?Hello/', $hello->testMessage("Hello")); + $this->assertPattern('/fails/', $hello->testMessage("Goodbye")); + $this->assertPattern('/fails.*?goodbye/i', $hello->testMessage("Goodbye")); } function testStringPosition() { @@ -35,13 +35,13 @@ "z" => 0); $str = &new EqualExpectation("abc"); foreach ($comparisons as $compare => $position) { - $this->assertWantedPattern( + $this->assertPattern( "/at character $position/", $str->testMessage($compare)); } $str = &new EqualExpectation("abcd"); foreach ($comparisons as $compare => $position) { - $this->assertWantedPattern( + $this->assertPattern( "/at character $position/", $str->testMessage($compare)); } @@ -51,10 +51,10 @@ $fifteen = &new EqualExpectation(15); $this->assertTrue($fifteen->test(15)); $this->assertFalse($fifteen->test(14)); - $this->assertWantedPattern( + $this->assertPattern( '/equal expectation.*?15/i', $fifteen->testMessage(15)); - $this->assertWantedPattern( + $this->assertPattern( '/fails.*?15.*?14/i', $fifteen->testMessage(14)); } @@ -63,10 +63,10 @@ $pi = &new EqualExpectation(3.14); $this->assertTrue($pi->test(3.14)); $this->assertFalse($pi->test(3.15)); - $this->assertWantedPattern( + $this->assertPattern( '/float.*?3\.14/i', $pi->testMessage(3.14)); - $this->assertWantedPattern( + $this->assertPattern( '/fails.*?3\.14.*?3\.15/i', $pi->testMessage(3.15)); } @@ -78,14 +78,14 @@ $this->assertEqual( $colours->testMessage(array("r", "g", "b")), "Equal expectation [Array: 3 items]"); - $this->assertWantedPattern('/fails/', $colours->testMessage(array("r", "g", "z"))); - $this->assertWantedPattern( + $this->assertPattern('/fails/', $colours->testMessage(array("r", "g", "z"))); + $this->assertPattern( '/\[2\] at character 0/', $colours->testMessage(array("r", "g", "z"))); - $this->assertWantedPattern( + $this->assertPattern( '/key.*? does not match/', $colours->testMessage(array("r", "g"))); - $this->assertWantedPattern( + $this->assertPattern( '/key.*? does not match/', $colours->testMessage(array("r", "g", "b", "z"))); } @@ -94,10 +94,10 @@ $is_blue = &new EqualExpectation(array("r" => 0, "g" => 0, "b" => 255)); $this->assertTrue($is_blue->test(array("r" => 0, "g" => 0, "b" => 255))); $this->assertFalse($is_blue->test(array("r" => 0, "g" => 255, "b" => 0))); - $this->assertWantedPattern( + $this->assertPattern( '/array.*?3 items/i', $is_blue->testMessage(array("r" => 0, "g" => 0, "b" => 255))); - $this->assertWantedPattern( + $this->assertPattern( '/fails.*?\[b\]/', $is_blue->testMessage(array("r" => 0, "g" => 0, "b" => 254))); } @@ -108,7 +108,7 @@ "b" => array( "c" => 2, "d" => "Three"))); - $this->assertWantedPattern( + $this->assertPattern( '/member.*?\[b\].*?\[d\].*?at character 5/', $tree->testMessage(array( "a" => 1, @@ -123,16 +123,37 @@ } } + class TestOfWithin extends UnitTestCase { + + function testWithinFloatingPointMargin() { + $within = new WithinMarginExpectation(1.0, 0.2); + $this->assertFalse($within->test(0.7)); + $this->assertTrue($within->test(0.8)); + $this->assertTrue($within->test(0.9)); + $this->assertTrue($within->test(1.1)); + $this->assertTrue($within->test(1.2)); + $this->assertFalse($within->test(1.3)); + } + + function testOutsideFloatingPointMargin() { + $within = new OutsideMarginExpectation(1.0, 0.2); + $this->assertTrue($within->test(0.7)); + $this->assertFalse($within->test(0.8)); + $this->assertFalse($within->test(1.2)); + $this->assertTrue($within->test(1.3)); + } + } + class TestOfInequality extends UnitTestCase { function testStringMismatch() { $not_hello = &new NotEqualExpectation("Hello"); $this->assertTrue($not_hello->test("Goodbye")); $this->assertFalse($not_hello->test("Hello")); - $this->assertWantedPattern( + $this->assertPattern( '/at character 0/', $not_hello->testMessage("Goodbye")); - $this->assertWantedPattern( + $this->assertPattern( '/matches/', $not_hello->testMessage("Hello")); } @@ -153,13 +174,13 @@ $this->assertTrue($string->test("37")); $this->assertFalse($string->test(37)); $this->assertFalse($string->test("38")); - $this->assertWantedPattern( + $this->assertPattern( '/identical.*?string.*?37/i', $string->testMessage("37")); - $this->assertWantedPattern( + $this->assertPattern( '/fails.*?37/', $string->testMessage(37)); - $this->assertWantedPattern( + $this->assertPattern( '/at character 1/', $string->testMessage("38")); } @@ -181,10 +202,10 @@ $this->assertTrue($string->test("38")); $this->assertTrue($string->test(37)); $this->assertFalse($string->test("37")); - $this->assertWantedPattern( + $this->assertPattern( '/at character 1/', $string->testMessage("38")); - $this->assertWantedPattern( + $this->assertPattern( '/passes.*?type/', $string->testMessage(37)); } @@ -193,13 +214,13 @@ class TestOfPatterns extends UnitTestCase { function testWanted() { - $pattern = &new WantedPatternExpectation('/hello/i'); + $pattern = &new PatternExpectation('/hello/i'); $this->assertTrue($pattern->test("Hello world")); $this->assertFalse($pattern->test("Goodbye world")); } function testUnwanted() { - $pattern = &new UnwantedPatternExpectation('/hello/i'); + $pattern = &new NoPatternExpectation('/hello/i'); $this->assertFalse($pattern->test("Hello world")); $this->assertTrue($pattern->test("Goodbye world")); } diff --git a/vendors/simpletest/test/form_test.php b/vendors/simpletest/test/form_test.php index 526cf7228..a9829ed1b 100644 --- a/vendors/simpletest/test/form_test.php +++ b/vendors/simpletest/test/form_test.php @@ -14,7 +14,7 @@ $form->getAction(), new SimpleUrl('http://host/a/here.php')); $this->assertIdentical($form->getId(), '33'); - $this->assertNull($form->getValue('a')); + $this->assertNull($form->getValue(new SimpleByName('a'))); } function testEmptyAction() { @@ -57,11 +57,11 @@ new SimpleUrl('htp://host')); $form->addWidget(new SimpleTextTag( array('name' => 'me', 'type' => 'text', 'value' => 'Myself'))); - $this->assertIdentical($form->getValue('me'), 'Myself'); - $this->assertTrue($form->setField('me', 'Not me')); - $this->assertFalse($form->setField('not_present', 'Not me')); - $this->assertIdentical($form->getValue('me'), 'Not me'); - $this->assertNull($form->getValue('not_present')); + $this->assertIdentical($form->getValue(new SimpleByName('me')), 'Myself'); + $this->assertTrue($form->setField(new SimpleByName('me'), 'Not me')); + $this->assertFalse($form->setField(new SimpleByName('not_present'), 'Not me')); + $this->assertIdentical($form->getValue(new SimpleByName('me')), 'Not me'); + $this->assertNull($form->getValue(new SimpleByName('not_present'))); } function testTextWidgetById() { @@ -70,16 +70,28 @@ new SimpleUrl('htp://host')); $form->addWidget(new SimpleTextTag( array('name' => 'me', 'type' => 'text', 'value' => 'Myself', 'id' => 50))); - $this->assertIdentical($form->getValueById(50), 'Myself'); - $this->assertTrue($form->setFieldById(50, 'Not me')); - $this->assertIdentical($form->getValueById(50), 'Not me'); + $this->assertIdentical($form->getValue(new SimpleById(50)), 'Myself'); + $this->assertTrue($form->setField(new SimpleById(50), 'Not me')); + $this->assertIdentical($form->getValue(new SimpleById(50)), 'Not me'); + } + + function testTextWidgetByLabel() { + $form = &new SimpleForm( + new SimpleFormTag(array()), + new SimpleUrl('htp://host')); + $widget = &new SimpleTextTag(array('name' => 'me', 'type' => 'text', 'value' => 'a')); + $form->addWidget($widget); + $widget->setLabel('thing'); + $this->assertIdentical($form->getValue(new SimpleByLabel('thing')), 'a'); + $this->assertTrue($form->setField(new SimpleByLabel('thing'), 'b')); + $this->assertIdentical($form->getValue(new SimpleByLabel('thing')), 'b'); } function testSubmitEmpty() { $form = &new SimpleForm( new SimpleFormTag(array()), new SimpleUrl('htp://host')); - $this->assertIdentical($form->submit(), new SimpleFormEncoding()); + $this->assertIdentical($form->submit(), new SimpleGetEncoding()); } function testSubmitButton() { @@ -88,18 +100,18 @@ new SimpleUrl('http://host')); $form->addWidget(new SimpleSubmitTag( array('type' => 'submit', 'name' => 'go', 'value' => 'Go!', 'id' => '9'))); - $this->assertTrue($form->hasSubmitName('go')); - $this->assertEqual($form->getValue('go'), 'Go!'); - $this->assertEqual($form->getValueById(9), 'Go!'); + $this->assertTrue($form->hasSubmit(new SimpleByName('go'))); + $this->assertEqual($form->getValue(new SimpleByName('go')), 'Go!'); + $this->assertEqual($form->getValue(new SimpleById(9)), 'Go!'); $this->assertEqual( - $form->submitButtonByName('go'), - new SimpleFormEncoding(array('go' => 'Go!'))); + $form->submitButton(new SimpleByName('go')), + new SimpleGetEncoding(array('go' => 'Go!'))); $this->assertEqual( - $form->submitButtonByLabel('Go!'), - new SimpleFormEncoding(array('go' => 'Go!'))); + $form->submitButton(new SimpleByLabel('Go!')), + new SimpleGetEncoding(array('go' => 'Go!'))); $this->assertEqual( - $form->submitButtonById(9), - new SimpleFormEncoding(array('go' => 'Go!'))); + $form->submitButton(new SimpleById(9)), + new SimpleGetEncoding(array('go' => 'Go!'))); } function testSubmitWithAdditionalParameters() { @@ -107,16 +119,10 @@ new SimpleFormTag(array()), new SimpleUrl('http://host')); $form->addWidget(new SimpleSubmitTag( - array('type' => 'submit', 'name' => 'go', 'value' => 'Go!', 'id' => '9'))); + array('type' => 'submit', 'name' => 'go', 'value' => 'Go!'))); $this->assertEqual( - $form->submitButtonByName('go', array('a' => 'A')), - new SimpleFormEncoding(array('go' => 'Go!', 'a' => 'A'))); - $this->assertEqual( - $form->submitButtonByLabel('Go!', array('a' => 'A')), - new SimpleFormEncoding(array('go' => 'Go!', 'a' => 'A'))); - $this->assertEqual( - $form->submitButtonById(9, array('a' => 'A')), - new SimpleFormEncoding(array('go' => 'Go!', 'a' => 'A'))); + $form->submitButton(new SimpleByLabel('Go!'), array('a' => 'A')), + new SimpleGetEncoding(array('go' => 'Go!', 'a' => 'A'))); } function testSubmitButtonWithLabelOfSubmit() { @@ -124,19 +130,13 @@ new SimpleFormTag(array()), new SimpleUrl('http://host')); $form->addWidget(new SimpleSubmitTag( - array('type' => 'submit', 'name' => 'test', 'value' => 'Submit', 'id' => '9'))); - $this->assertTrue($form->hasSubmitName('test')); - $this->assertEqual($form->getValue('test'), 'Submit'); - $this->assertEqual($form->getValueById(9), 'Submit'); + array('type' => 'submit', 'name' => 'test', 'value' => 'Submit'))); $this->assertEqual( - $form->submitButtonByName('test'), - new SimpleFormEncoding(array('test' => 'Submit'))); + $form->submitButton(new SimpleByName('test')), + new SimpleGetEncoding(array('test' => 'Submit'))); $this->assertEqual( - $form->submitButtonByLabel('Submit'), - new SimpleFormEncoding(array('test' => 'Submit'))); - $this->assertEqual( - $form->submitButtonById(9), - new SimpleFormEncoding(array('test' => 'Submit'))); + $form->submitButton(new SimpleByLabel('Submit')), + new SimpleGetEncoding(array('test' => 'Submit'))); } function testSubmitButtonWithWhitespacePaddedLabelOfSubmit() { @@ -144,12 +144,10 @@ new SimpleFormTag(array()), new SimpleUrl('http://host')); $form->addWidget(new SimpleSubmitTag( - array('type' => 'submit', 'name' => 'test', 'value' => ' Submit ', 'id' => '9'))); - $this->assertEqual($form->getValue('test'), ' Submit '); - $this->assertEqual($form->getValueById(9), ' Submit '); + array('type' => 'submit', 'name' => 'test', 'value' => ' Submit '))); $this->assertEqual( - $form->submitButtonByLabel('Submit'), - new SimpleFormEncoding(array('test' => ' Submit '))); + $form->submitButton(new SimpleByLabel('Submit')), + new SimpleGetEncoding(array('test' => ' Submit '))); } function testImageSubmitButton() { @@ -162,18 +160,18 @@ 'name' => 'go', 'alt' => 'Go!', 'id' => '9'))); - $this->assertTrue($form->hasImageLabel('Go!')); + $this->assertTrue($form->hasImage(new SimpleByLabel('Go!'))); $this->assertEqual( - $form->submitImageByLabel('Go!', 100, 101), - new SimpleFormEncoding(array('go.x' => 100, 'go.y' => 101))); - $this->assertTrue($form->hasImageName('go')); + $form->submitImage(new SimpleByLabel('Go!'), 100, 101), + new SimpleGetEncoding(array('go.x' => 100, 'go.y' => 101))); + $this->assertTrue($form->hasImage(new SimpleByName('go'))); $this->assertEqual( - $form->submitImageByName('go', 100, 101), - new SimpleFormEncoding(array('go.x' => 100, 'go.y' => 101))); - $this->assertTrue($form->hasImageId(9)); + $form->submitImage(new SimpleByName('go'), 100, 101), + new SimpleGetEncoding(array('go.x' => 100, 'go.y' => 101))); + $this->assertTrue($form->hasImage(new SimpleById(9))); $this->assertEqual( - $form->submitImageById(9, 100, 101), - new SimpleFormEncoding(array('go.x' => 100, 'go.y' => 101))); + $form->submitImage(new SimpleById(9), 100, 101), + new SimpleGetEncoding(array('go.x' => 100, 'go.y' => 101))); } function testImageSubmitButtonWithAdditionalData() { @@ -184,19 +182,10 @@ 'type' => 'image', 'src' => 'source.jpg', 'name' => 'go', - 'alt' => 'Go!', - 'id' => '9'))); + 'alt' => 'Go!'))); $this->assertEqual( - $form->submitImageByLabel('Go!', 100, 101, array('a' => 'A')), - new SimpleFormEncoding(array('go.x' => 100, 'go.y' => 101, 'a' => 'A'))); - $this->assertTrue($form->hasImageName('go')); - $this->assertEqual( - $form->submitImageByName('go', 100, 101, array('a' => 'A')), - new SimpleFormEncoding(array('go.x' => 100, 'go.y' => 101, 'a' => 'A'))); - $this->assertTrue($form->hasImageId(9)); - $this->assertEqual( - $form->submitImageById(9, 100, 101, array('a' => 'A')), - new SimpleFormEncoding(array('go.x' => 100, 'go.y' => 101, 'a' => 'A'))); + $form->submitImage(new SimpleByLabel('Go!'), 100, 101, array('a' => 'A')), + new SimpleGetEncoding(array('go.x' => 100, 'go.y' => 101, 'a' => 'A'))); } function testButtonTag() { @@ -207,17 +196,17 @@ array('type' => 'submit', 'name' => 'go', 'value' => 'Go', 'id' => '9')); $widget->addContent('Go!'); $form->addWidget($widget); - $this->assertTrue($form->hasSubmitName('go')); - $this->assertTrue($form->hasSubmitLabel('Go!')); + $this->assertTrue($form->hasSubmit(new SimpleByName('go'))); + $this->assertTrue($form->hasSubmit(new SimpleByLabel('Go!'))); $this->assertEqual( - $form->submitButtonByName('go'), - new SimpleFormEncoding(array('go' => 'Go'))); + $form->submitButton(new SimpleByName('go')), + new SimpleGetEncoding(array('go' => 'Go'))); $this->assertEqual( - $form->submitButtonByLabel('Go!'), - new SimpleFormEncoding(array('go' => 'Go'))); + $form->submitButton(new SimpleByLabel('Go!')), + new SimpleGetEncoding(array('go' => 'Go'))); $this->assertEqual( - $form->submitButtonById(9), - new SimpleFormEncoding(array('go' => 'Go'))); + $form->submitButton(new SimpleById(9)), + new SimpleGetEncoding(array('go' => 'Go'))); } function testSingleSelectFieldSubmitted() { @@ -230,7 +219,20 @@ $form->addWidget($select); $this->assertIdentical( $form->submit(), - new SimpleFormEncoding(array('a' => 'aaa'))); + new SimpleGetEncoding(array('a' => 'aaa'))); + } + + function testSingleSelectFieldSubmittedWithPost() { + $form = &new SimpleForm( + new SimpleFormTag(array('method' => 'post')), + new SimpleUrl('htp://host')); + $select = &new SimpleSelectionTag(array('name' => 'a')); + $select->addTag(new SimpleOptionTag( + array('value' => 'aaa', 'selected' => ''))); + $form->addWidget($select); + $this->assertIdentical( + $form->submit(), + new SimplePostEncoding(array('a' => 'aaa'))); } function testUnchecked() { @@ -239,11 +241,11 @@ new SimpleUrl('htp://host')); $form->addWidget(new SimpleCheckboxTag( array('name' => 'me', 'type' => 'checkbox'))); - $this->assertIdentical($form->getValue('me'), false); - $this->assertTrue($form->setField('me', 'on')); - $this->assertEqual($form->getValue('me'), 'on'); - $this->assertFalse($form->setField('me', 'other')); - $this->assertEqual($form->getValue('me'), 'on'); + $this->assertIdentical($form->getValue(new SimpleByName('me')), false); + $this->assertTrue($form->setField(new SimpleByName('me'), 'on')); + $this->assertEqual($form->getValue(new SimpleByName('me')), 'on'); + $this->assertFalse($form->setField(new SimpleByName('me'), 'other')); + $this->assertEqual($form->getValue(new SimpleByName('me')), 'on'); } function testChecked() { @@ -252,11 +254,11 @@ new SimpleUrl('htp://host')); $form->addWidget(new SimpleCheckboxTag( array('name' => 'me', 'value' => 'a', 'type' => 'checkbox', 'checked' => ''))); - $this->assertIdentical($form->getValue('me'), 'a'); - $this->assertFalse($form->setField('me', 'on')); - $this->assertEqual($form->getValue('me'), 'a'); - $this->assertTrue($form->setField('me', false)); - $this->assertEqual($form->getValue('me'), false); + $this->assertIdentical($form->getValue(new SimpleByName('me')), 'a'); + $this->assertTrue($form->setField(new SimpleByName('me'), 'a')); + $this->assertEqual($form->getValue(new SimpleByName('me')), 'a'); + $this->assertTrue($form->setField(new SimpleByName('me'), false)); + $this->assertEqual($form->getValue(new SimpleByName('me')), false); } function testSingleUncheckedRadioButton() { @@ -265,9 +267,9 @@ new SimpleUrl('htp://host')); $form->addWidget(new SimpleRadioButtonTag( array('name' => 'me', 'value' => 'a', 'type' => 'radio'))); - $this->assertIdentical($form->getValue('me'), false); - $this->assertTrue($form->setField('me', 'a')); - $this->assertIdentical($form->getValue('me'), 'a'); + $this->assertIdentical($form->getValue(new SimpleByName('me')), false); + $this->assertTrue($form->setField(new SimpleByName('me'), 'a')); + $this->assertEqual($form->getValue(new SimpleByName('me')), 'a'); } function testSingleCheckedRadioButton() { @@ -276,8 +278,8 @@ new SimpleUrl('htp://host')); $form->addWidget(new SimpleRadioButtonTag( array('name' => 'me', 'value' => 'a', 'type' => 'radio', 'checked' => ''))); - $this->assertIdentical($form->getValue('me'), 'a'); - $this->assertFalse($form->setField('me', 'other')); + $this->assertIdentical($form->getValue(new SimpleByName('me')), 'a'); + $this->assertFalse($form->setField(new SimpleByName('me'), 'other')); } function testUncheckedRadioButtons() { @@ -288,13 +290,13 @@ array('name' => 'me', 'value' => 'a', 'type' => 'radio'))); $form->addWidget(new SimpleRadioButtonTag( array('name' => 'me', 'value' => 'b', 'type' => 'radio'))); - $this->assertIdentical($form->getValue('me'), false); - $this->assertTrue($form->setField('me', 'a')); - $this->assertIdentical($form->getValue('me'), 'a'); - $this->assertTrue($form->setField('me', 'b')); - $this->assertIdentical($form->getValue('me'), 'b'); - $this->assertFalse($form->setField('me', 'c')); - $this->assertIdentical($form->getValue('me'), 'b'); + $this->assertIdentical($form->getValue(new SimpleByName('me')), false); + $this->assertTrue($form->setField(new SimpleByName('me'), 'a')); + $this->assertIdentical($form->getValue(new SimpleByName('me')), 'a'); + $this->assertTrue($form->setField(new SimpleByName('me'), 'b')); + $this->assertIdentical($form->getValue(new SimpleByName('me')), 'b'); + $this->assertFalse($form->setField(new SimpleByName('me'), 'c')); + $this->assertIdentical($form->getValue(new SimpleByName('me')), 'b'); } function testCheckedRadioButtons() { @@ -305,9 +307,9 @@ array('name' => 'me', 'value' => 'a', 'type' => 'radio'))); $form->addWidget(new SimpleRadioButtonTag( array('name' => 'me', 'value' => 'b', 'type' => 'radio', 'checked' => ''))); - $this->assertIdentical($form->getValue('me'), 'b'); - $this->assertTrue($form->setField('me', 'a')); - $this->assertIdentical($form->getValue('me'), 'a'); + $this->assertIdentical($form->getValue(new SimpleByName('me')), 'b'); + $this->assertTrue($form->setField(new SimpleByName('me'), 'a')); + $this->assertIdentical($form->getValue(new SimpleByName('me')), 'a'); } function testMultipleFieldsWithSameKey() { @@ -318,9 +320,9 @@ array('name' => 'a', 'type' => 'checkbox', 'value' => 'me'))); $form->addWidget(new SimpleCheckboxTag( array('name' => 'a', 'type' => 'checkbox', 'value' => 'you'))); - $this->assertIdentical($form->getValue('a'), false); - $this->assertTrue($form->setField('a', 'me')); - $this->assertIdentical($form->getValue('a'), 'me'); + $this->assertIdentical($form->getValue(new SimpleByName('a')), false); + $this->assertTrue($form->setField(new SimpleByName('a'), 'me')); + $this->assertIdentical($form->getValue(new SimpleByName('a')), 'me'); } } ?> \ No newline at end of file diff --git a/vendors/simpletest/test/frames_test.php b/vendors/simpletest/test/frames_test.php index 8a2f083c1..2d9bb80ba 100644 --- a/vendors/simpletest/test/frames_test.php +++ b/vendors/simpletest/test/frames_test.php @@ -99,17 +99,17 @@ $this->assertEqual($frameset->getText(), 'Stuff1 Stuff2'); } - function testFieldIsFirstInFramelist() { + function testFieldFoundIsFirstInFramelist() { $frame1 = &new MockSimplePage($this); - $frame1->setReturnValue('getField', null); - $frame1->expectOnce('getField', array('a')); + $frame1->setReturnValue('getFieldByName', null); + $frame1->expectOnce('getFieldByName', array('a')); $frame2 = &new MockSimplePage($this); - $frame2->setReturnValue('getField', 'A'); - $frame2->expectOnce('getField', array('a')); + $frame2->setReturnValue('getFieldByName', 'A'); + $frame2->expectOnce('getFieldByName', array('a')); $frame3 = &new MockSimplePage($this); - $frame3->expectNever('getField'); + $frame3->expectNever('getFieldByName'); $page = &new MockSimplePage($this); $frameset = &new SimpleFrameset($page); @@ -117,7 +117,7 @@ $frameset->addFrame($frame2); $frameset->addFrame($frame3); - $this->assertIdentical($frameset->getField('a'), 'A'); + $this->assertIdentical($frameset->getFieldByName('a'), 'A'); $frame1->tally(); $frame2->tally(); } @@ -512,18 +512,18 @@ function testSettingAllFrameFieldsWhenNoFrameFocus() { $frame1 = &new MockSimplePage($this); - $frame1->expectOnce('setField', array('a', 'A')); + $frame1->expectOnce('setFieldByName', array('a', 'A')); $frame1->expectOnce('setFieldById', array(22, 'A')); $frame2 = &new MockSimplePage($this); - $frame2->expectOnce('setField', array('a', 'A')); + $frame2->expectOnce('setFieldByName', array('a', 'A')); $frame2->expectOnce('setFieldById', array(22, 'A')); $frameset = &new SimpleFrameset(new MockSimplePage($this)); $frameset->addFrame($frame1, 'A'); $frameset->addFrame($frame2, 'B'); - $frameset->setField('a', 'A'); + $frameset->setFieldByName('a', 'A'); $frameset->setFieldById(22, 'A'); $frame1->tally(); $frame2->tally(); diff --git a/vendors/simpletest/test/http_test.php b/vendors/simpletest/test/http_test.php index c214a2169..f72556098 100644 --- a/vendors/simpletest/test/http_test.php +++ b/vendors/simpletest/test/http_test.php @@ -275,8 +275,7 @@ $route = &new MockSimpleRoute($this); $route->setReturnReference('createConnection', $socket); - $request = &new SimpleHttpRequest($route, 'GET'); - + $request = &new SimpleHttpRequest($route, new SimpleGetEncoding()); $reponse = &$request->fetch(15); $this->assertTrue($reponse->isError()); } @@ -289,8 +288,7 @@ $route->setReturnReference('createConnection', $socket); $route->expectArguments('createConnection', array('GET', 15)); - $request = &new SimpleHttpRequest($route, 'GET'); - + $request = &new SimpleHttpRequest($route, new SimpleGetEncoding()); $this->assertIsA($request->fetch(15), 'SimpleHttpResponse'); $socket->tally(); $route->tally(); @@ -305,7 +303,7 @@ $route = &new MockSimpleRoute($this); $route->setReturnReference('createConnection', $socket); - $request = &new SimpleHttpRequest($route, 'GET'); + $request = &new SimpleHttpRequest($route, new SimpleGetEncoding()); $request->addHeaderLine('My: stuff'); $request->fetch(15); @@ -321,10 +319,10 @@ $route = &new MockSimpleRoute($this); $route->setReturnReference('createConnection', $socket); - $request = &new SimpleHttpRequest($route, 'GET'); + $request = &new SimpleHttpRequest($route, new SimpleGetEncoding()); $request->setCookie(new SimpleCookie('a', 'A')); - $this->assertIsA($request->fetch(15), 'SimpleHttpResponse'); + $socket->tally(); } @@ -335,24 +333,24 @@ $route = &new MockSimpleRoute($this); $route->setReturnReference('createConnection', $socket); - $request = &new SimpleHttpRequest($route, 'GET'); + $request = &new SimpleHttpRequest($route, new SimpleGetEncoding()); $request->setCookie(new SimpleCookie('a', 'A')); $request->setCookie(new SimpleCookie('b', 'B')); - $request->fetch(15); + $socket->tally(); } } class TestOfHttpPostRequest extends UnitTestCase { - function testReadingBadConnection() { + function testReadingBadConnectionCausesErrorBecauseOfDeadSocket() { $socket = &new MockSimpleSocket($this); $route = &new MockSimpleRoute($this); $route->setReturnReference('createConnection', $socket); - $request = &new SimpleHttpRequest($route, 'POST', ''); + $request = &new SimpleHttpRequest($route, new SimplePostEncoding()); $reponse = &$request->fetch(15); $this->assertTrue($reponse->isError()); @@ -369,9 +367,9 @@ $route->setReturnReference('createConnection', $socket); $route->expectArguments('createConnection', array('POST', 15)); - $request = &new SimpleHttpRequest($route, 'POST', new SimpleFormEncoding()); - + $request = &new SimpleHttpRequest($route, new SimplePostEncoding()); $this->assertIsA($request->fetch(15), 'SimpleHttpResponse'); + $socket->tally(); $route->tally(); } @@ -389,10 +387,9 @@ $request = &new SimpleHttpRequest( $route, - 'POST', - new SimpleFormEncoding(array('a' => 'A'))); - + new SimplePostEncoding(array('a' => 'A'))); $this->assertIsA($request->fetch(15), 'SimpleHttpResponse'); + $socket->tally(); $route->tally(); } @@ -459,9 +456,9 @@ $socket = &new MockSimpleSocket($this); $socket->setReturnValue('getSent', ''); - $response = &new SimpleHttpResponse($socket, 'GET', new SimpleUrl('here')); + $response = &new SimpleHttpResponse($socket, new SimpleUrl('here'), new SimpleGetEncoding()); $this->assertTrue($response->isError()); - $this->assertWantedPattern('/Nothing fetched/', $response->getError()); + $this->assertPattern('/Nothing fetched/', $response->getError()); $this->assertIdentical($response->getContent(), false); $this->assertIdentical($response->getSent(), ''); } @@ -473,7 +470,7 @@ $socket->setReturnValue("read", ""); $socket->setReturnValue('getSent', 'HTTP/1.1 ...'); - $response = &new SimpleHttpResponse($socket, 'GET', new SimpleUrl('here')); + $response = &new SimpleHttpResponse($socket, new SimpleUrl('here'), new SimpleGetEncoding()); $this->assertTrue($response->isError()); $this->assertEqual($response->getContent(), ''); $this->assertEqual($response->getSent(), 'HTTP/1.1 ...'); @@ -486,7 +483,7 @@ $socket->setReturnValueAt(2, "read", "Content-Type: text/plain\r\n"); $socket->setReturnValue("read", ""); - $response = &new SimpleHttpResponse($socket, 'GET', new SimpleUrl('here')); + $response = &new SimpleHttpResponse($socket, new SimpleUrl('here'), new SimpleGetEncoding()); $this->assertTrue($response->isError()); $this->assertEqual($response->getContent(), ""); } @@ -500,7 +497,7 @@ $socket->setReturnValueAt(4, "read", "with two lines in it\n"); $socket->setReturnValue("read", ""); - $response = &new SimpleHttpResponse($socket, 'GET', new SimpleUrl('here')); + $response = &new SimpleHttpResponse($socket, new SimpleUrl('here'), new SimpleGetEncoding()); $this->assertFalse($response->isError()); $this->assertEqual( $response->getContent(), @@ -524,7 +521,7 @@ $socket->setReturnValueAt(6, "read", "\r\n"); $socket->setReturnValue("read", ""); - $response = &new SimpleHttpResponse($socket, 'GET', new SimpleUrl('here')); + $response = &new SimpleHttpResponse($socket, new SimpleUrl('here'), new SimpleGetEncoding()); $this->assertFalse($response->isError()); $headers = $response->getHeaders(); $cookies = $headers->getNewCookies(); @@ -543,7 +540,7 @@ $socket->setReturnValueAt(4, "read", "\r\n"); $socket->setReturnValue("read", ""); - $response = &new SimpleHttpResponse($socket, 'GET', new SimpleUrl('here')); + $response = &new SimpleHttpResponse($socket, new SimpleUrl('here'), new SimpleGetEncoding()); $headers = $response->getHeaders(); $this->assertTrue($headers->isRedirect()); $this->assertEqual($headers->getLocation(), "http://www.somewhere-else.com/"); @@ -558,7 +555,7 @@ $socket->setReturnValueAt(4, "read", "\r\n"); $socket->setReturnValue("read", ""); - $response = &new SimpleHttpResponse($socket, 'GET', new SimpleUrl('here')); + $response = &new SimpleHttpResponse($socket, new SimpleUrl('here'), new SimpleGetEncoding()); $headers = $response->getHeaders(); $this->assertTrue($headers->isRedirect()); $this->assertEqual($headers->getLocation(), "http://www.somewhere-else.com:80/"); diff --git a/vendors/simpletest/test/live_test.php b/vendors/simpletest/test/live_test.php index 2cbed8cc1..9693e46fd 100644 --- a/vendors/simpletest/test/live_test.php +++ b/vendors/simpletest/test/live_test.php @@ -14,8 +14,8 @@ function testBadSocket() { $socket = &new SimpleSocket('bad_url', 111, 5); $this->assertTrue($socket->isError()); - $this->assertWantedPattern( - '/Cannot open \\[bad_url:111\\] with \\[.*?\\] within \\[5\\] seconds/', + $this->assertPattern( + '/Cannot open \\[bad_url:111\\] with \\[/', $socket->getError()); $this->assertFalse($socket->isOpen()); $this->assertFalse($socket->write('A message')); diff --git a/vendors/simpletest/test/page_test.php b/vendors/simpletest/test/page_test.php index 2495ad888..1c2b77b2d 100644 --- a/vendors/simpletest/test/page_test.php +++ b/vendors/simpletest/test/page_test.php @@ -456,19 +456,47 @@ } } - class TestOfForms extends UnitTestCase { + class TestOfFormsCreatedFromEventStream extends UnitTestCase { - function testButtons() { + function testFormCanBeSubmitted() { + $page = &new SimplePage(new MockSimpleHttpResponse($this)); + $page->acceptFormStart( + new SimpleFormTag(array('method' => 'GET', 'action' => 'here.php'))); + $page->AcceptTag( + new SimpleSubmitTag(array('type' => 'submit', 'name' => 's'))); + $page->acceptFormEnd(); + $form = &$page->getFormBySubmitLabel('Submit'); + $this->assertEqual( + $form->submitButton(new SimpleByLabel('Submit')), + new SimpleGetEncoding(array('s' => 'Submit'))); + } + + function testInputFieldCanBeReadBack() { $page = &new SimplePage(new MockSimpleHttpResponse($this)); $page->acceptFormStart( new SimpleFormTag(array("method" => "GET", "action" => "here.php"))); + $page->AcceptTag( + new SimpleTextTag(array("type" => "text", "name" => "a", "value" => "A"))); $page->AcceptTag( new SimpleSubmitTag(array("type" => "submit", "name" => "s"))); $page->acceptFormEnd(); - $form = &$page->getFormBySubmitLabel("Submit"); - $this->assertEqual( - $form->submitButtonByLabel("Submit"), - new SimpleFormEncoding(array("s" => "Submit"))); + $this->assertEqual($page->getFieldByName('a'), 'A'); + } + + function testInputFieldCanBeReadBackByLabel() { + $label = &new SimpleLabelTag(array()); + $page = &new SimplePage(new MockSimpleHttpResponse($this)); + $page->acceptFormStart( + new SimpleFormTag(array("method" => "GET", "action" => "here.php"))); + $page->acceptLabelStart($label); + $label->addContent('l'); + $page->AcceptTag( + new SimpleTextTag(array("type" => "text", "name" => "a", "value" => "A"))); + $page->acceptLabelEnd(); + $page->AcceptTag( + new SimpleSubmitTag(array("type" => "submit", "name" => "s"))); + $page->acceptFormEnd(); + $this->assertEqual($page->getField('l'), 'A'); } } @@ -476,7 +504,8 @@ function &parse($response) { $builder = &new SimplePageBuilder(); - return $builder->parse($response); + $page = &$builder->parse($response); + return $page; } function testEmptyPage() { @@ -522,7 +551,6 @@ function testTitle() { $response = &new MockSimpleHttpResponse($this); $response->setReturnValue('getContent', 'Me'); - $page = &$this->parse($response); $this->assertEqual($page->getTitle(), 'Me'); } @@ -532,7 +560,6 @@ $response->setReturnValue( 'getContent', ' <b>Me&Me '); - $page = &$this->parse($response); $this->assertEqual($page->getTitle(), "Me&Me"); } @@ -543,9 +570,8 @@ '
' . '' . '
'); - $page = &$this->parse($response); - $this->assertEqual($page->getField('here'), "Hello"); + $this->assertEqual($page->getFieldByName('here'), "Hello"); } function testUnclosedForm() { @@ -554,9 +580,8 @@ '
' . '' . ''); - $page = &$this->parse($response); - $this->assertEqual($page->getField('here'), "Hello"); + $this->assertEqual($page->getFieldByName('here'), "Hello"); } function testEmptyFrameset() { @@ -564,7 +589,6 @@ $response->setReturnValue( 'getContent', ''); - $page = &$this->parse($response); $this->assertTrue($page->hasFrames()); $this->assertIdentical($page->getFrameset(), array()); @@ -604,7 +628,6 @@ $response->setReturnValue( 'getContent', ''); - $page = &$this->parse($response); $this->assertTrue($page->hasFrames()); $this->assertIdentical($page->getFrameset(), array()); @@ -630,7 +653,8 @@ function testNamedFrames() { $response = &new MockSimpleHttpResponse($this); - $response->setReturnValue('getContent', '' . + $response->setReturnValue('getContent', + '' . '' . '' . '' . @@ -652,7 +676,6 @@ $response->setReturnValue( 'getContent', '
'); - $page = &$this->parse($response); $this->assertNull($page->getFormBySubmitLabel('submit')); $this->assertIsA($page->getFormBySubmitName('submit'), 'SimpleForm'); @@ -664,7 +687,6 @@ $response->setReturnValue( 'getContent', '
'); - $page = &$this->parse($response); $this->assertIsA($page->getFormBySubmitName('submit'), 'SimpleForm'); $this->assertIsA($page->getFormBySubmitLabel('Submit'), 'SimpleForm'); @@ -672,10 +694,10 @@ function testFindFormByImage() { $response = &new MockSimpleHttpResponse($this); - $response->setReturnValue('getContent', '
' . + $response->setReturnValue('getContent', + '' . '' . '
'); - $page = &$this->parse($response); $this->assertIsA($page->getFormByImageLabel('Label'), 'SimpleForm'); $this->assertIsA($page->getFormByImageName('me'), 'SimpleForm'); @@ -684,10 +706,10 @@ function testFindFormByButtonTag() { $response = &new MockSimpleHttpResponse($this); - $response->setReturnValue('getContent', '
' . + $response->setReturnValue('getContent', + '' . '' . '
'); - $page = &$this->parse($response); $this->assertNull($page->getFormBySubmitLabel('b')); $this->assertNull($page->getFormBySubmitLabel('B')); @@ -700,7 +722,6 @@ $response->setReturnValue( 'getContent', '
'); - $page = &$this->parse($response); $this->assertNull($page->getFormById(54)); $this->assertIsA($page->getFormById(55), 'SimpleForm'); @@ -708,85 +729,155 @@ function testReadingTextField() { $response = &new MockSimpleHttpResponse($this); - $response->setReturnValue('getContent', '
' . + $response->setReturnValue('getContent', + '' . '' . '' . '
'); - $page = &$this->parse($response); - $this->assertNull($page->getField('missing')); - $this->assertIdentical($page->getField('a'), ''); - $this->assertIdentical($page->getField('b'), 'bbb'); + $this->assertNull($page->getFieldByName('missing')); + $this->assertIdentical($page->getFieldByName('a'), ''); + $this->assertIdentical($page->getFieldByName('b'), 'bbb'); } function testReadingTextFieldIsCaseInsensitive() { $response = &new MockSimpleHttpResponse($this); - $response->setReturnValue('getContent', '
' . + $response->setReturnValue('getContent', + '' . '' . '' . '
'); - $page = &$this->parse($response); - $this->assertNull($page->getField('missing')); - $this->assertIdentical($page->getField('a'), ''); - $this->assertIdentical($page->getField('b'), 'bbb'); + $this->assertNull($page->getFieldByName('missing')); + $this->assertIdentical($page->getFieldByName('a'), ''); + $this->assertIdentical($page->getFieldByName('b'), 'bbb'); } function testSettingTextField() { $response = &new MockSimpleHttpResponse($this); - $response->setReturnValue('getContent', '
' . + $response->setReturnValue('getContent', + '' . '' . '' . '' . '
'); - $page = &$this->parse($response); - $this->assertTrue($page->setField('a', 'aaa')); - $this->assertEqual($page->getField('a'), 'aaa'); + $this->assertTrue($page->setFieldByName('a', 'aaa')); + $this->assertEqual($page->getFieldByName('a'), 'aaa'); $this->assertTrue($page->setFieldById(3, 'bbb')); $this->assertEqual($page->getFieldById(3), 'bbb'); - $this->assertFalse($page->setField('z', 'zzz')); - $this->assertNull($page->getField('z')); + $this->assertFalse($page->setFieldByName('z', 'zzz')); + $this->assertNull($page->getFieldByName('z')); + } + + function testSettingTextFieldByEnclosingLabel() { + $response = &new MockSimpleHttpResponse($this); + $response->setReturnValue('getContent', + '
' . + '' . + '
'); + $page = &$this->parse($response); + $this->assertEqual($page->getFieldByName('a'), 'A'); + $this->assertEqual($page->getField('Stuff'), 'A'); + $this->assertTrue($page->setField('Stuff', 'aaa')); + $this->assertEqual($page->getField('Stuff'), 'aaa'); + } + + function testGettingTextFieldByEnclosingLabelWithConflictingOtherFields() { + $response = &new MockSimpleHttpResponse($this); + $response->setReturnValue('getContent', + '
' . + '' . + '' . + '
'); + $page = &$this->parse($response); + $this->assertEqual($page->getFieldByName('a'), 'A'); + $this->assertEqual($page->getFieldByName('b'), 'B'); + $this->assertEqual($page->getField('Stuff'), 'A'); + } + + function testSettingTextFieldByExternalLabel() { + $response = &new MockSimpleHttpResponse($this); + $response->setReturnValue('getContent', + '
' . + '' . + '' . + '
'); + $page = &$this->parse($response); + $this->assertEqual($page->getField('Stuff'), 'A'); + $this->assertTrue($page->setField('Stuff', 'aaa')); + $this->assertEqual($page->getField('Stuff'), 'aaa'); } function testReadingTextArea() { $response = &new MockSimpleHttpResponse($this); - $response->setReturnValue('getContent', '
' . + $response->setReturnValue('getContent', + '' . '' . '' . '
'); - $page = &$this->parse($response); - $this->assertEqual($page->getField('a'), 'aaa'); + $this->assertEqual($page->getFieldByName('a'), 'aaa'); } function testSettingTextArea() { $response = &new MockSimpleHttpResponse($this); - $response->setReturnValue('getContent', '
' . + $response->setReturnValue('getContent', + '' . '' . '' . '
'); - $page = &$this->parse($response); - $this->assertTrue($page->setField('a', 'AAA')); - $this->assertEqual($page->getField('a'), 'AAA'); + $this->assertTrue($page->setFieldByName('a', 'AAA')); + $this->assertEqual($page->getFieldByName('a'), 'AAA'); } function testSettingSelectionField() { $response = &new MockSimpleHttpResponse($this); - $response->setReturnValue('getContent', '
' . + $response->setReturnValue('getContent', + '' . '' . '' . '
'); - $page = &$this->parse($response); - $this->assertEqual($page->getField('a'), 'bbb'); - $this->assertFalse($page->setField('a', 'ccc')); - $this->assertTrue($page->setField('a', 'aaa')); - $this->assertEqual($page->getField('a'), 'aaa'); + $this->assertEqual($page->getFieldByName('a'), 'bbb'); + $this->assertFalse($page->setFieldByName('a', 'ccc')); + $this->assertTrue($page->setFieldByName('a', 'aaa')); + $this->assertEqual($page->getFieldByName('a'), 'aaa'); + } + + function testSettingSelectionFieldByEnclosingLabel() { + $response = &new MockSimpleHttpResponse($this); + $response->setReturnValue('getContent', + '
' . + '' . + '
'); + $page = &$this->parse($response); + $this->assertEqual($page->getField('Stuff'), 'A'); + $this->assertTrue($page->setField('Stuff', 'B')); + $this->assertEqual($page->getField('Stuff'), 'B'); + } + + function testSettingRadioButonByEnclosingLabel() { + $response = &new MockSimpleHttpResponse($this); + $response->setReturnValue('getContent', + '
' . + '' . + '' . + '
'); + $page = &$this->parse($response); + $this->assertEqual($page->getField('A'), 'a'); + $this->assertTrue($page->setField('B', 'b')); + $this->assertEqual($page->getField('B'), 'b'); } } ?> \ No newline at end of file diff --git a/vendors/simpletest/test/parser_test.php b/vendors/simpletest/test/parser_test.php index 63a76b9c8..b99471c00 100644 --- a/vendors/simpletest/test/parser_test.php +++ b/vendors/simpletest/test/parser_test.php @@ -561,6 +561,14 @@ $this->assertTrue($this->_parser->acceptStartToken(">", LEXER_EXIT)); } + function testSimpleLabelStart() { + $this->_parser->parse(""); + $this->_listener->expectOnce("startElement", array("label", array())); + $this->_listener->setReturnValue("startElement", true); + $this->assertTrue($this->_parser->acceptStartToken("assertTrue($this->_parser->acceptStartToken(">", LEXER_EXIT)); + } + function testLinkStart() { $this->_parser->parse(""); $this->_listener->expectOnce("startElement", array("a", array("href" => "here.html"))); diff --git a/vendors/simpletest/test/real_sites_test.php b/vendors/simpletest/test/real_sites_test.php index 07e4ccd0b..ef0c1e3ee 100644 --- a/vendors/simpletest/test/real_sites_test.php +++ b/vendors/simpletest/test/real_sites_test.php @@ -1,6 +1,5 @@ assertTitle('SourceForge.net: Search'); $this->assertTrue($this->clickLink('SimpleTest')); $this->clickLink('statistics'); - $this->assertWantedPattern('/Statistics for the past 7 days/'); - $this->assertTrue($this->setField('report', 'Monthly')); - $this->clickSubmit('Change Stats View'); - $this->assertWantedPattern('/Statistics for the past \d+ months/'); + $this->assertWantedText('SimpleTest: Statistics'); + $this->assertTrue($this->setField('mode', 'All Time')); + $this->clickSubmit('Change View'); + $this->assertWantedText('Mar 2003'); } } ?> \ No newline at end of file diff --git a/vendors/simpletest/test/shell_test.php b/vendors/simpletest/test/shell_test.php index 94bb8ca70..823d32ebf 100644 --- a/vendors/simpletest/test/shell_test.php +++ b/vendors/simpletest/test/shell_test.php @@ -8,7 +8,7 @@ function testEcho() { $shell = &new SimpleShell(); $this->assertIdentical($shell->execute('echo Hello'), 0); - $this->assertWantedPattern('/Hello/', $shell->getOutput()); + $this->assertPattern('/Hello/', $shell->getOutput()); } function testBadCommand() { diff --git a/vendors/simpletest/test/shell_tester_test.php b/vendors/simpletest/test/shell_tester_test.php index ea52eba0e..091ce8abe 100644 --- a/vendors/simpletest/test/shell_tester_test.php +++ b/vendors/simpletest/test/shell_tester_test.php @@ -10,6 +10,11 @@ return $this->_mock_shell; } + function testGenericEquality() { + $this->assertEqual('a', 'a'); + $this->assertNotEqual('a', 'A'); + } + function testExitCode() { $this->_mock_shell = &new MockSimpleShell($this); $this->_mock_shell->setReturnValue('execute', 0); diff --git a/vendors/simpletest/test/simple_mock_test.php b/vendors/simpletest/test/simple_mock_test.php index 43a0bafae..502b30cf7 100644 --- a/vendors/simpletest/test/simple_mock_test.php +++ b/vendors/simpletest/test/simple_mock_test.php @@ -3,12 +3,12 @@ require_once(dirname(__FILE__) . '/../expectation.php'); - class TestOfWildcardExpectation extends UnitTestCase { + class TestOfAnythingExpectation extends UnitTestCase { function testSimpleInteger() { - $expectation = new WildcardExpectation(); + $expectation = new AnythingExpectation(); $this->assertTrue($expectation->test(33)); - $this->assertWantedPattern( + $this->assertPattern( '/matches.*33/i', $expectation->testMessage(33)); } @@ -45,8 +45,8 @@ $this->assertFalse($expectation->test(array())); } - function testWildcardExpectations() { - $expectation = new ParametersExpectation(array(new WildcardExpectation())); + function testAnythingExpectations() { + $expectation = new ParametersExpectation(array(new AnythingExpectation())); $this->assertFalse($expectation->test(array())); $this->assertIdentical($expectation->test(array(null)), true); $this->assertIdentical($expectation->test(array(13)), true); @@ -54,7 +54,7 @@ function testOtherExpectations() { $expectation = new ParametersExpectation( - array(new WantedPatternExpectation('/hello/i'))); + array(new PatternExpectation('/hello/i'))); $this->assertFalse($expectation->test(array('Goodbye'))); $this->assertTrue($expectation->test(array('hello'))); $this->assertTrue($expectation->test(array('Hello'))); @@ -68,7 +68,7 @@ function testLongList() { $expectation = new ParametersExpectation( - array("0", 0, new WildcardExpectation(), false)); + array("0", 0, new AnythingExpectation(), false)); $this->assertTrue($expectation->test(array("0", 0, 37, false))); $this->assertFalse($expectation->test(array("0", 0, 37, true))); $this->assertFalse($expectation->test(array("0", 0, 37))); @@ -106,7 +106,7 @@ function testWildcard() { $map = new CallMap(); - $map->addValue(array(new WildcardExpectation(), 1, 3), "Fred"); + $map->addValue(array(new AnythingExpectation(), 1, 3), "Fred"); $this->assertTrue($map->isMatch(array(2, 1, 3))); $this->assertEqual($map->findFirstMatch(array(2, 1, 3)), "Fred"); } @@ -125,7 +125,7 @@ $map->addValue(array(1, 3), "1, 3"); $map->addValue(array(1), "1"); $map->addValue(array(1, 4), "1, 4"); - $map->addValue(array(new WildcardExpectation()), "Any"); + $map->addValue(array(new AnythingExpectation()), "Any"); $map->addValue(array(2), "2"); $map->addValue("", "Default"); $map->addValue(array(), "None"); @@ -150,6 +150,10 @@ function anotherMethod() { return true; } + + function __get($key) { + return $key; + } } Stub::generate("Dummy"); @@ -385,7 +389,7 @@ $mock->setReturnValue( "aMethod", "aaa", - array(new wantedPatternExpectation('/hello/i'))); + array(new PatternExpectation('/hello/i'))); $this->assertIdentical($mock->aMethod('Hello'), "aaa"); $this->assertNull($mock->aMethod('Goodbye')); } @@ -410,6 +414,23 @@ } } + class TestOfSpecialMethods extends UnitTestCase { + + function testReturnFromSpecialMethod() { + $mock = &new MockDummy($this); + $mock->setReturnValue('__get', '1st Return', array('first')); + $mock->setReturnValue('__get', '2nd Return', array('second')); + + $this->assertEqual($mock->__get('first'), '1st Return'); + $this->assertEqual($mock->__get('second'), '2nd Return'); + + if (phpversion() >= 5) { + $this->assertEqual($mock->first, $mock->__get('first')); + $this->assertEqual($mock->second, $mock->__get('second')); + } + } + } + Mock::generate("SimpleTestCase"); class TestOfMockTally extends UnitTestCase { diff --git a/vendors/simpletest/test/support/collector/collectable.1 b/vendors/simpletest/test/support/collector/collectable.1 new file mode 100644 index 000000000..e69de29bb diff --git a/vendors/simpletest/test/support/collector/collectable.2 b/vendors/simpletest/test/support/collector/collectable.2 new file mode 100644 index 000000000..e69de29bb diff --git a/vendors/simpletest/test/support/latin1_sample b/vendors/simpletest/test/support/latin1_sample new file mode 100644 index 000000000..190352577 --- /dev/null +++ b/vendors/simpletest/test/support/latin1_sample @@ -0,0 +1 @@ +£¹²³¼½¾@¶øþðßæ«»¢µ \ No newline at end of file diff --git a/vendors/simpletest/test/support/supplementary_upload_sample.txt b/vendors/simpletest/test/support/supplementary_upload_sample.txt new file mode 100644 index 000000000..d8aa9e810 --- /dev/null +++ b/vendors/simpletest/test/support/supplementary_upload_sample.txt @@ -0,0 +1 @@ +Some more text content \ No newline at end of file diff --git a/vendors/simpletest/test/support/upload_sample.txt b/vendors/simpletest/test/support/upload_sample.txt new file mode 100644 index 000000000..ec98d7c5e --- /dev/null +++ b/vendors/simpletest/test/support/upload_sample.txt @@ -0,0 +1 @@ +Sample for testing file upload \ No newline at end of file diff --git a/vendors/simpletest/test/tag_test.php b/vendors/simpletest/test/tag_test.php index 01c05e56b..f6f2717c7 100644 --- a/vendors/simpletest/test/tag_test.php +++ b/vendors/simpletest/test/tag_test.php @@ -2,6 +2,9 @@ // $Id$ require_once(dirname(__FILE__) . '/../tag.php'); + require_once(dirname(__FILE__) . '/../encoding.php'); + + Mock::generate('SimpleMultipartEncoding'); class TestOfTag extends UnitTestCase { @@ -58,11 +61,17 @@ class TestOfWidget extends UnitTestCase { function testTextEmptyDefault() { - $tag = &new SimpleTextTag(array('' => 'text')); + $tag = &new SimpleTextTag(array('type' => 'text')); $this->assertIdentical($tag->getDefault(), ''); $this->assertIdentical($tag->getValue(), ''); } + function testSettingOfExternalLabel() { + $tag = &new SimpleTextTag(array('type' => 'text')); + $tag->setLabel('it'); + $this->assertTrue($tag->isLabel('it')); + } + function testTextDefault() { $tag = &new SimpleTextTag(array('value' => 'aaa')); $this->assertEqual($tag->getDefault(), 'aaa'); @@ -393,6 +402,19 @@ $this->assertTrue($group->isId('i1')); $this->assertTrue($group->isId('i2')); } + + function testIsLabelMatchesAnyWidgetInSet() { + $group = &new SimpleRadioGroup(); + $button1 = &new SimpleRadioButtonTag(array('value' => 'A')); + $button1->setLabel('one'); + $group->addWidget($button1); + $button2 = &new SimpleRadioButtonTag(array('value' => 'B')); + $button2->setLabel('two'); + $group->addWidget($button2); + $this->assertFalse($group->isLabel('three')); + $this->assertTrue($group->isLabel('one')); + $this->assertTrue($group->isLabel('two')); + } } class TestOfTagGroup extends UnitTestCase { @@ -459,4 +481,39 @@ $this->assertTrue($group->isId(2)); } } + + class TestOfUploadWidget extends UnitTestCase { + + function testValueIsFilePath() { + $upload = &new SimpleUploadTag(array('name' => 'a')); + $upload->setValue(dirname(__FILE__) . '/support/upload_sample.txt'); + $this->assertEqual($upload->getValue(), dirname(__FILE__) . '/support/upload_sample.txt'); + } + + function testSubmitsFileContents() { + $encoding = &new MockSimpleMultipartEncoding($this); + $encoding->expectOnce('attach', array( + 'a', + 'Sample for testing file upload', + 'upload_sample.txt')); + $upload = &new SimpleUploadTag(array('name' => 'a')); + $upload->setValue(dirname(__FILE__) . '/support/upload_sample.txt'); + $upload->write($encoding); + $encoding->tally(); + } + } + + class TestOfLabelTag extends UnitTestCase { + + function testLabelShouldHaveAnEndTag() { + $label = &new SimpleLabelTag(array()); + $this->assertTrue($label->expectEndTag()); + } + + function testContentIsTextOnly() { + $label = &new SimpleLabelTag(array()); + $label->addContent('Here are words'); + $this->assertEqual($label->getText(), 'Here are words'); + } + } ?> \ No newline at end of file diff --git a/vendors/simpletest/test/test_groups.php b/vendors/simpletest/test/test_groups.php new file mode 100644 index 000000000..17e5b2221 --- /dev/null +++ b/vendors/simpletest/test/test_groups.php @@ -0,0 +1,55 @@ +GroupTest('Unit tests'); + $test_path = dirname(__FILE__); + $this->addTestFile($test_path . '/errors_test.php'); + $this->addTestFile($test_path . '/options_test.php'); + $this->addTestFile($test_path . '/dumper_test.php'); + $this->addTestFile($test_path . '/expectation_test.php'); + $this->addTestFile($test_path . '/unit_tester_test.php'); + $this->addTestFile($test_path . '/collector_test.php'); + $this->addTestFile($test_path . '/simple_mock_test.php'); + $this->addTestFile($test_path . '/adapter_test.php'); + $this->addTestFile($test_path . '/socket_test.php'); + $this->addTestFile($test_path . '/encoding_test.php'); + $this->addTestFile($test_path . '/url_test.php'); + $this->addTestFile($test_path . '/http_test.php'); + $this->addTestFile($test_path . '/authentication_test.php'); + $this->addTestFile($test_path . '/user_agent_test.php'); + $this->addTestFile($test_path . '/parser_test.php'); + $this->addTestFile($test_path . '/tag_test.php'); + $this->addTestFile($test_path . '/form_test.php'); + $this->addTestFile($test_path . '/page_test.php'); + $this->addTestFile($test_path . '/frames_test.php'); + $this->addTestFile($test_path . '/browser_test.php'); + $this->addTestFile($test_path . '/web_tester_test.php'); + $this->addTestFile($test_path . '/shell_tester_test.php'); + $this->addTestFile($test_path . '/xml_test.php'); + } + } + + // Uncomment and modify the following line if you are accessing + // the net via a proxy server. + // + // SimpleTestOptions::useProxy('http://my-proxy', 'optional username', 'optional password'); + + class AllTests extends GroupTest { + function AllTests() { + $this->GroupTest('All tests for SimpleTest ' . SimpleTestOptions::getVersion()); + $this->addTestCase(new UnitTests()); + $this->addTestFile(dirname(__FILE__) . '/shell_test.php'); + $this->addTestFile(dirname(__FILE__) . '/live_test.php'); + $this->addTestFile(dirname(__FILE__) . '/acceptance_test.php'); + $this->addTestFile(dirname(__FILE__) . '/real_sites_test.php'); + } + } +?> \ No newline at end of file diff --git a/vendors/simpletest/test/unit_tester_test.php b/vendors/simpletest/test/unit_tester_test.php index 80d869fd2..2d9755e04 100644 --- a/vendors/simpletest/test/unit_tester_test.php +++ b/vendors/simpletest/test/unit_tester_test.php @@ -1,6 +1,9 @@ assertIsA($this, 'UnitTestCase'); $this->assertNotA($this, 'WebTestCase'); } + + function testReferenceAssertionOnObjects() { + $a = &new ReferenceForTesting(); + $b = &$a; + $this->assertReference($a, $b); + } + + function testReferenceAssertionOnScalars() { + $a = 25; + $b = &$a; + $this->assertReference($a, $b); + } + + function testCloneOnObjects() { + $a = &new ReferenceForTesting(); + $b = &new ReferenceForTesting(); + $this->assertCopy($a, $b); + } + + function testCloneOnScalars() { + $a = 25; + $b = 25; + $this->assertCopy($a, $b); + } } class JBehaveStyleRunner extends SimpleRunner { @@ -38,7 +65,8 @@ class TestOfJBehaveStyleRunner extends UnitTestCase { function &_createRunner(&$reporter) { - return new JBehaveStyleRunner($this, $reporter); + $runner = &new JBehaveStyleRunner($this, $reporter); + return $runner; } function testFail() { diff --git a/vendors/simpletest/test/unit_tests.php b/vendors/simpletest/test/unit_tests.php index ccc733f21..c0fe08fc7 100644 --- a/vendors/simpletest/test/unit_tests.php +++ b/vendors/simpletest/test/unit_tests.php @@ -3,41 +3,8 @@ if (! defined('TEST')) { define('TEST', __FILE__); } - require_once('../unit_tester.php'); - require_once('../web_tester.php'); - require_once('../shell_tester.php'); - require_once('../reporter.php'); - require_once('../mock_objects.php'); - require_once('../extensions/pear_test_case.php'); - require_once('../extensions/phpunit_test_case.php'); - - class UnitTests extends GroupTest { - function UnitTests() { - $this->GroupTest('Unit tests'); - $this->addTestFile('errors_test.php'); - $this->addTestFile('options_test.php'); - $this->addTestFile('dumper_test.php'); - $this->addTestFile('expectation_test.php'); - $this->addTestFile('unit_tester_test.php'); - $this->addTestFile('simple_mock_test.php'); - $this->addTestFile('adapter_test.php'); - $this->addTestFile('socket_test.php'); - $this->addTestFile('encoding_test.php'); - $this->addTestFile('url_test.php'); - $this->addTestFile('http_test.php'); - $this->addTestFile('authentication_test.php'); - $this->addTestFile('user_agent_test.php'); - $this->addTestFile('parser_test.php'); - $this->addTestFile('tag_test.php'); - $this->addTestFile('form_test.php'); - $this->addTestFile('page_test.php'); - $this->addTestFile('frames_test.php'); - $this->addTestFile('browser_test.php'); - $this->addTestFile('web_tester_test.php'); - $this->addTestFile('shell_tester_test.php'); - $this->addTestFile('xml_test.php'); - } - } + require_once(dirname(__FILE__) . '/test_groups.php'); + require_once(dirname(__FILE__) . '/../reporter.php'); if (TEST == __FILE__) { $test = &new UnitTests(); diff --git a/vendors/simpletest/test/url_test.php b/vendors/simpletest/test/url_test.php index cae496eb2..533731976 100644 --- a/vendors/simpletest/test/url_test.php +++ b/vendors/simpletest/test/url_test.php @@ -31,39 +31,49 @@ function testParseBareParameter() { $url = new SimpleUrl('?a'); $this->assertEqual($url->getPath(), ''); - $this->assertEqual($url->getEncodedRequest(), '?a='); + $this->assertEqual($url->getEncodedRequest(), '?a'); + $url->addRequestParameter('x', 'X'); + $this->assertEqual($url->getEncodedRequest(), '?a=&x=X'); } function testParseEmptyParameter() { $url = new SimpleUrl('?a='); $this->assertEqual($url->getPath(), ''); $this->assertEqual($url->getEncodedRequest(), '?a='); + $url->addRequestParameter('x', 'X'); + $this->assertEqual($url->getEncodedRequest(), '?a=&x=X'); } function testParseParameterPair() { $url = new SimpleUrl('?a=A'); $this->assertEqual($url->getPath(), ''); $this->assertEqual($url->getEncodedRequest(), '?a=A'); + $url->addRequestParameter('x', 'X'); + $this->assertEqual($url->getEncodedRequest(), '?a=A&x=X'); } function testParseMultipleParameters() { $url = new SimpleUrl('?a=A&b=B'); $this->assertEqual($url->getEncodedRequest(), '?a=A&b=B'); + $url->addRequestParameter('x', 'X'); + $this->assertEqual($url->getEncodedRequest(), '?a=A&b=B&x=X'); } function testParsingParameterMixture() { $url = new SimpleUrl('?a=A&b=&c'); - $this->assertEqual($url->getEncodedRequest(), '?a=A&b=&c='); + $this->assertEqual($url->getEncodedRequest(), '?a=A&b=&c'); + $url->addRequestParameter('x', 'X'); + $this->assertEqual($url->getEncodedRequest(), '?a=A&b=&c=&x=X'); } - function testAddParameters() { + function testAddParametersFromScratch() { $url = new SimpleUrl(''); $url->addRequestParameter('a', 'A'); $this->assertEqual($url->getEncodedRequest(), '?a=A'); $url->addRequestParameter('b', 'B'); $this->assertEqual($url->getEncodedRequest(), '?a=A&b=B'); $url->addRequestParameter('a', 'aaa'); - $this->assertEqual($url->getEncodedRequest(), '?a=A&a=aaa&b=B'); + $this->assertEqual($url->getEncodedRequest(), '?a=A&b=B&a=aaa'); } function testClearingParameters() { @@ -93,14 +103,13 @@ $url->setCoordinates('32', '45'); $this->assertIdentical($url->getX(), 32); $this->assertIdentical($url->getY(), 45); - $this->assertEqual($url->getEncodedRequest(), '?32,45'); + $this->assertEqual($url->getEncodedRequest(), ''); } function testParseCordinates() { $url = new SimpleUrl('?32,45'); $this->assertIdentical($url->getX(), 32); $this->assertIdentical($url->getY(), 45); - $this->assertEqual($url->getEncodedRequest(), '?32,45'); } function testClearingCordinates() { @@ -114,14 +123,14 @@ $url = new SimpleUrl('?a=A&b=&c?32,45'); $this->assertIdentical($url->getX(), 32); $this->assertIdentical($url->getY(), 45); - $this->assertEqual($url->getEncodedRequest(), '?a=A&b=&c=?32,45'); + $this->assertEqual($url->getEncodedRequest(), '?a=A&b=&c'); } function testParsingParameterWithBadCordinates() { $url = new SimpleUrl('?a=A&b=&c?32'); $this->assertIdentical($url->getX(), false); $this->assertIdentical($url->getY(), false); - $this->assertEqual($url->getEncodedRequest(), '?a=A&b=&c?32='); + $this->assertEqual($url->getEncodedRequest(), '?a=A&b=&c?32'); } function testPageSplitting() { @@ -169,7 +178,7 @@ array("a" => "1")); $this->assertUrl( "username:password@somewhere.com:243?1,2", - array(false, "username", "password", "somewhere.com", 243, "/", "com", "?1,2", false), + array(false, "username", "password", "somewhere.com", 243, "/", "com", "", false), array(), array(1, 2)); $this->assertUrl( @@ -180,7 +189,7 @@ array(false, "username", false, "www.somewhere.com", 243, "/", "com", "", "anchor")); $this->assertUrl( "/this/that/here.php?a=1&b=2?3,4", - array(false, false, false, false, false, "/this/that/here.php", false, "?a=1&b=2?3,4", false), + array(false, false, false, false, false, "/this/that/here.php", false, "?a=1&b=2", false), array("a" => "1", "b" => "2"), array(3, 4)); $this->assertUrl( @@ -220,6 +229,7 @@ $this->assertPreserved('http://host?a=1&a=2'); $this->assertPreserved('http://host#stuff'); $this->assertPreserved('http://me:secret@www.here.com/a/b/c/here.html?a=A?7,6'); + $this->assertPreserved('http://www.here.com/?a=A__b=B'); } function assertUrl($raw, $parts, $params = false, $coords = false) { @@ -242,6 +252,11 @@ } } + function testUrlWithTwoSlashesInPath() { + $url = new SimpleUrl('/article/categoryedit/insert//'); + $this->assertEqual($url->getPath(), '/article/categoryedit/insert//'); + } + function assertPreserved($string) { $url = new SimpleUrl($string); $this->assertEqual($url->asString(), $string); @@ -285,7 +300,7 @@ $this->assertEqual($absolute->getScheme(), 'http'); $this->assertEqual($absolute->getHost(), 'host.com'); $this->assertEqual($absolute->getPath(), '/I/am/here/'); - $this->assertEqual($absolute->getEncodedRequest(), '?a='); + $this->assertEqual($absolute->getEncodedRequest(), '?a'); $this->assertEqual($absolute->getFragment(), 'b'); } @@ -311,6 +326,14 @@ $this->assertEqual($absolute->getPath(), '/here.html'); } + function testCarryAuthenticationFromRootPage() { + $url = new SimpleUrl('here.html'); + $absolute = $url->makeAbsolute('http://test:secret@host.com/'); + $this->assertEqual($absolute->getPath(), '/here.html'); + $this->assertEqual($absolute->getUsername(), 'test'); + $this->assertEqual($absolute->getPassword(), 'secret'); + } + function testMakingCoordinateUrlAbsolute() { $url = new SimpleUrl('?1,2'); $this->assertEqual($url->getPath(), ''); @@ -347,6 +370,14 @@ $this->assertEqual($absolute->getFragment(), 'f'); } + function testMakingAbsoluteCarriesAuthenticationWhenAlreadyAbsolute() { + $url = new SimpleUrl('https://www.lastcraft.com'); + $absolute = $url->makeAbsolute('http://test:secret@host.com/here/'); + $this->assertEqual($absolute->getHost(), 'www.lastcraft.com'); + $this->assertEqual($absolute->getUsername(), 'test'); + $this->assertEqual($absolute->getPassword(), 'secret'); + } + function testMakingHostOnlyAbsoluteDoesNotCarryAnyOtherInformation() { $url = new SimpleUrl('http://www.lastcraft.com'); $absolute = $url->makeAbsolute('https://host.com:81/here/'); diff --git a/vendors/simpletest/test/user_agent_test.php b/vendors/simpletest/test/user_agent_test.php index 24b436bc1..2018dbd9e 100644 --- a/vendors/simpletest/test/user_agent_test.php +++ b/vendors/simpletest/test/user_agent_test.php @@ -148,18 +148,17 @@ $request = &new MockSimpleHttpRequest($this); $request->setReturnReference('fetch', $response); + $url = new SimpleUrl('http://test:secret@this.com/page.html'); + $url->addRequestParameters(array('a' => 'A', 'b' => 'B')); + $agent = &new MockRequestUserAgent($this); $agent->setReturnReference('_createHttpRequest', $request); - $agent->expectOnce('_createHttpRequest', array( - 'GET', - new SimpleUrl('http://test:secret@this.com/page.html?a=A&b=B'), - new SimpleFormEncoding())); + $agent->expectOnce('_createHttpRequest', array($url, new SimpleGetEncoding())); $agent->SimpleUserAgent(); $agent->fetchResponse( - 'GET', new SimpleUrl('http://test:secret@this.com/page.html'), - new SimpleFormEncoding(array('a' => 'A', 'b' => 'B'))); + new SimpleGetEncoding(array('a' => 'A', 'b' => 'B'))); $agent->tally(); } @@ -176,21 +175,17 @@ $request = &new MockSimpleHttpRequest($this); $request->setReturnReference('fetch', $response); - $url = new SimpleUrl('http://this.com/page.html'); + $url = new SimpleUrl('http://test:secret@this.com/page.html'); $url->addRequestParameters(array('a' => 'A', 'b' => 'B')); $agent = &new MockRequestUserAgent($this); $agent->setReturnReference('_createHttpRequest', $request); - $agent->expectOnce('_createHttpRequest', array( - 'HEAD', - new SimpleUrl('http://test:secret@this.com/page.html?a=A&b=B'), - new SimpleFormEncoding())); + $agent->expectOnce('_createHttpRequest', array($url, new SimpleHeadEncoding())); $agent->SimpleUserAgent(); $agent->fetchResponse( - 'HEAD', new SimpleUrl('http://test:secret@this.com/page.html'), - new SimpleFormEncoding(array('a' => 'A', 'b' => 'B'))); + new SimpleHeadEncoding(array('a' => 'A', 'b' => 'B'))); $agent->tally(); } @@ -207,18 +202,18 @@ $request = &new MockSimpleHttpRequest($this); $request->setReturnReference('fetch', $response); + $encoding = new SimplePostEncoding(array('a' => 'A', 'b' => 'B')); + $agent = &new MockRequestUserAgent($this); $agent->setReturnReference('_createHttpRequest', $request); $agent->expectOnce('_createHttpRequest', array( - 'POST', new SimpleUrl('http://test:secret@this.com/page.html'), - new SimpleFormEncoding(array('a' => 'A', 'b' => 'B')))); + $encoding)); $agent->SimpleUserAgent(); $agent->fetchResponse( - 'POST', new SimpleUrl('http://test:secret@this.com/page.html'), - new SimpleFormEncoding(array('a' => 'A', 'b' => 'B'))); + $encoding); $agent->tally(); } } @@ -243,7 +238,7 @@ $agent->SimpleUserAgent(); $agent->addHeader('User-Agent: SimpleTest'); - $response = &$agent->fetchResponse('GET', new SimpleUrl('http://this.host/')); + $response = &$agent->fetchResponse(new SimpleUrl('http://this.host/'), new SimpleGetEncoding()); $request->tally(); } } @@ -290,9 +285,8 @@ $agent = &$this->_createPartialFetcher($request); $agent->setCookie('a', 'A'); $response = $agent->fetchResponse( - 'GET', new SimpleUrl('http://this.com/this/path/page.html'), - array()); + new SimpleGetEncoding()); $this->assertEqual($response->getContent(), "stuff"); $request->tally(); } @@ -303,9 +297,8 @@ $agent->setCookie("a", "A"); $agent->fetchResponse( - "GET", new SimpleUrl('http://this.com/this/path/page.html'), - array()); + new SimpleGetEncoding()); $this->assertEqual($agent->getCookieValue("this.com", "this/path/", "a"), "AAAA"); } @@ -316,9 +309,8 @@ $agent->setCookie("a", "A", "this/path/", "Wed, 25-Dec-02 04:24:21 GMT"); $agent->fetchResponse( - 'GET', new SimpleUrl('http://this.com/this/path/page.html'), - array()); + new SimpleGetEncoding()); $this->assertIdentical( $agent->getCookieValue("this.com", "this/path/", "a"), "b"); @@ -334,9 +326,8 @@ $agent = &$this->_createPartialFetcher($request); $agent->fetchResponse( - 'GET', new SimpleUrl('http://this.com/this/path/page.html'), - array()); + new SimpleGetEncoding()); $agent->restart("Wed, 25-Dec-02 04:24:20 GMT"); $this->assertIdentical( $agent->getCookieValue("this.com", "this/path/", "a"), @@ -355,9 +346,8 @@ $this->assertNull($agent->getBaseCookieValue("a", false)); $agent->fetchResponse( - 'GET', new SimpleUrl('http://this.com/this/path/page.html'), - array()); + new SimpleGetEncoding()); $agent->setCookie("b", "BBB", "this.com", "this/path/"); $this->assertEqual( $agent->getBaseCookieValue("a", new SimpleUrl('http://this.com/this/path/page.html')), @@ -395,7 +385,7 @@ $agent->SimpleUserAgent(); $agent->setMaximumRedirects(0); - $response = &$agent->fetchResponse('GET', new SimpleUrl('here.html')); + $response = &$agent->fetchResponse(new SimpleUrl('here.html'), new SimpleGetEncoding()); $this->assertEqual($response->getContent(), 'stuff'); $agent->tally(); @@ -415,7 +405,7 @@ $agent->SimpleUserAgent(); $agent->setMaximumRedirects(1); - $response = &$agent->fetchResponse('GET', new SimpleUrl('one.html')); + $response = &$agent->fetchResponse(new SimpleUrl('one.html'), new SimpleGetEncoding()); $this->assertEqual($response->getContent(), 'second'); $agent->tally(); @@ -439,7 +429,7 @@ $agent->SimpleUserAgent(); $agent->setMaximumRedirects(2); - $response = &$agent->fetchResponse('GET', new SimpleUrl('one.html')); + $response = &$agent->fetchResponse(new SimpleUrl('one.html'), new SimpleGetEncoding()); $this->assertEqual($response->getContent(), 'third'); $agent->tally(); @@ -463,7 +453,7 @@ $agent->SimpleUserAgent(); $agent->setMaximumRedirects(2); - $response = &$agent->fetchResponse('GET', new SimpleUrl('one.html')); + $response = &$agent->fetchResponse(new SimpleUrl('one.html'), new SimpleGetEncoding()); $this->assertEqual($response->getContent(), 'second'); $agent->tally(); @@ -475,17 +465,17 @@ 0, '_createHttpRequest', $this->createRedirect('first', 'two.html')); - $agent->expectArgumentsAt(0, '_createHttpRequest', array('POST', '*', '*')); + $agent->expectArgumentsAt(0, '_createHttpRequest', array('*', new IsAExpectation('SimplePostEncoding'))); $agent->setReturnReferenceAt( 1, '_createHttpRequest', $this->createRedirect('second', 'three.html')); - $agent->expectArgumentsAt(1, '_createHttpRequest', array('GET', '*', '*')); + $agent->expectArgumentsAt(1, '_createHttpRequest', array('*', new IsAExpectation('SimpleGetEncoding'))); $agent->expectCallCount('_createHttpRequest', 2); $agent->SimpleUserAgent(); $agent->setMaximumRedirects(1); - $response = &$agent->fetchResponse('POST', new SimpleUrl('one.html')); + $response = &$agent->fetchResponse(new SimpleUrl('one.html'), new SimplePostEncoding()); $agent->tally(); } @@ -512,8 +502,8 @@ $agent->SimpleUserAgent(); $response = &$agent->fetchResponse( - 'GET', - new SimpleUrl('http://this.host/this/path/page.html')); + new SimpleUrl('http://this.host/this/path/page.html'), + new SimpleGetEncoding()); $this->assertTrue($response->isError()); } } @@ -538,8 +528,8 @@ $agent->SimpleUserAgent(); $response = &$agent->fetchResponse( - 'GET', - new SimpleUrl('http://test:secret@this.host')); + new SimpleUrl('http://test:secret@this.host'), + new SimpleGetEncoding()); $request->tally(); } } diff --git a/vendors/simpletest/test/visual_test.php b/vendors/simpletest/test/visual_test.php index 4261525c6..03d04d69f 100644 --- a/vendors/simpletest/test/visual_test.php +++ b/vendors/simpletest/test/visual_test.php @@ -44,8 +44,8 @@ function testExpectation() { $expectation = &new EqualExpectation(25, 'My expectation message: %s'); - $this->assertExpectation($expectation, 25, 'My assert message : %s'); - $this->assertExpectation($expectation, 24, 'My assert message : %s'); // Fail. + $this->assert($expectation, 25, 'My assert message : %s'); + $this->assert($expectation, 24, 'My assert message : %s'); // Fail. } function testNull() { @@ -92,6 +92,16 @@ $this->assertEqual(array("a" => "A", "b" => "B"), array("b" => "B", "a" => "A"), "%s -> Pass"); $this->assertEqual(array("a" => "A", "b" => "B"), array("b" => "B", "a" => "Z"), "%s -> Pass"); } + + function testWithin() { + $this->assertWithinMargin(5, 5.4, 0.5, "%s -> Pass"); + $this->assertWithinMargin(5, 5.6, 0.5, "%s -> Fail"); // Fail. + } + + function testOutside() { + $this->assertOutsideMargin(5, 5.4, 0.5, "%s -> Fail"); // Fail. + $this->assertOutsideMargin(5, 5.6, 0.5, "%s -> Pass"); + } function testStringIdentity() { $a = "fred"; @@ -143,10 +153,10 @@ } function testPatterns() { - $this->assertWantedPattern('/hello/i', "Hello there", "%s -> Pass"); - $this->assertNoUnwantedPattern('/hello/', "Hello there", "%s -> Pass"); - $this->assertWantedPattern('/hello/', "Hello there", "%s -> Fail"); // Fail. - $this->assertNoUnwantedPattern('/hello/i', "Hello there", "%s -> Fail"); // Fail. + $this->assertPattern('/hello/i', "Hello there", "%s -> Pass"); + $this->assertNoPattern('/hello/', "Hello there", "%s -> Pass"); + $this->assertPattern('/hello/', "Hello there", "%s -> Fail"); // Fail. + $this->assertNoPattern('/hello/i', "Hello there", "%s -> Fail"); // Fail. } function testLongStrings() { @@ -366,7 +376,7 @@ } } - $test = &new GroupTest("Visual test with 49 passes, 49 fails and 4 exceptions"); + $test = &new GroupTest("Visual test with 51 passes, 51 fails and 4 exceptions"); $test->addTestCase(new TestOfUnitTestCaseOutput()); $test->addTestCase(new TestOfMockObjectsOutput()); $test->addTestCase(new TestOfPastBugs()); diff --git a/vendors/simpletest/test/web_tester_test.php b/vendors/simpletest/test/web_tester_test.php index 65244b0a0..6ddb2561b 100644 --- a/vendors/simpletest/test/web_tester_test.php +++ b/vendors/simpletest/test/web_tester_test.php @@ -65,6 +65,14 @@ $this->assertIdentical($expectation->test(' a : AB '), false); } + function testHeaderValueWithColons() { + $expectation = new HttpHeaderExpectation('a', 'A:B:C'); + $this->assertIdentical($expectation->test('a: A'), false); + $this->assertIdentical($expectation->test('a: A:B'), false); + $this->assertIdentical($expectation->test('a: A:B:C'), true); + $this->assertIdentical($expectation->test('a: A:B:C:D'), false); + } + function testMultilineSearch() { $expectation = new HttpHeaderExpectation('a', 'A'); $this->assertIdentical($expectation->test("aa: A\r\nb: B\r\nc: C"), false); @@ -130,4 +138,12 @@ $this->assertIdentical($expectation->test('the wanted text is here'), false); } } + + class TestOfGenericAssertionsInWebTester extends WebTestCase { + + function testEquality() { + $this->assertEqual('a', 'a'); + $this->assertNotEqual('a', 'A'); + } + } ?> \ No newline at end of file diff --git a/vendors/simpletest/unit_tester.php b/vendors/simpletest/unit_tester.php index 948f77340..17409dfb4 100644 --- a/vendors/simpletest/unit_tester.php +++ b/vendors/simpletest/unit_tester.php @@ -1,35 +1,35 @@ SimpleTestCase($label); } - /** - * Will be true if the value is null. - * @param null $value Supposedly null value. - * @param string $message Message to display. - * @return boolean True on pass - * @access public - */ + /** + * Will be true if the value is null. + * @param null $value Supposedly null value. + * @param string $message Message to display. + * @return boolean True on pass + * @access public + */ function assertNull($value, $message = "%s") { $dumper = &new SimpleDumper(); $message = sprintf( @@ -52,13 +52,13 @@ return $this->assertTrue(! isset($value), $message); } - /** - * Will be true if the value is set. - * @param mixed $value Supposedly set value. - * @param string $message Message to display. - * @return boolean True on pass. - * @access public - */ + /** + * Will be true if the value is set. + * @param mixed $value Supposedly set value. + * @param string $message Message to display. + * @return boolean True on pass. + * @access public + */ function assertNotNull($value, $message = "%s") { $dumper = &new SimpleDumper(); $message = sprintf( @@ -67,113 +67,147 @@ return $this->assertTrue(isset($value), $message); } - /** - * Type and class test. Will pass if class - * matches the type name or is a subclass or - * if not an object, but the type is correct. - * @param mixed $object Object to test. - * @param string $type Type name as string. - * @param string $message Message to display. - * @return boolean True on pass. - * @access public - */ + /** + * Type and class test. Will pass if class + * matches the type name or is a subclass or + * if not an object, but the type is correct. + * @param mixed $object Object to test. + * @param string $type Type name as string. + * @param string $message Message to display. + * @return boolean True on pass. + * @access public + */ function assertIsA($object, $type, $message = "%s") { - return $this->assertExpectation( + return $this->assert( new IsAExpectation($type), $object, $message); } - /** - * Type and class mismatch test. Will pass if class - * name or underling type does not match the one - * specified. - * @param mixed $object Object to test. - * @param string $type Type name as string. - * @param string $message Message to display. - * @return boolean True on pass. - * @access public - */ + /** + * Type and class mismatch test. Will pass if class + * name or underling type does not match the one + * specified. + * @param mixed $object Object to test. + * @param string $type Type name as string. + * @param string $message Message to display. + * @return boolean True on pass. + * @access public + */ function assertNotA($object, $type, $message = "%s") { - return $this->assertExpectation( + return $this->assert( new NotAExpectation($type), $object, $message); } - /** - * Will trigger a pass if the two parameters have - * the same value only. Otherwise a fail. - * @param mixed $first Value to compare. - * @param mixed $second Value to compare. - * @param string $message Message to display. - * @return boolean True on pass - * @access public - */ + /** + * Will trigger a pass if the two parameters have + * the same value only. Otherwise a fail. + * @param mixed $first Value to compare. + * @param mixed $second Value to compare. + * @param string $message Message to display. + * @return boolean True on pass + * @access public + */ function assertEqual($first, $second, $message = "%s") { - return $this->assertExpectation( + return $this->assert( new EqualExpectation($first), $second, $message); } - /** - * Will trigger a pass if the two parameters have - * a different value. Otherwise a fail. - * @param mixed $first Value to compare. - * @param mixed $second Value to compare. - * @param string $message Message to display. - * @return boolean True on pass - * @access public - */ + /** + * Will trigger a pass if the two parameters have + * a different value. Otherwise a fail. + * @param mixed $first Value to compare. + * @param mixed $second Value to compare. + * @param string $message Message to display. + * @return boolean True on pass + * @access public + */ function assertNotEqual($first, $second, $message = "%s") { - return $this->assertExpectation( + return $this->assert( new NotEqualExpectation($first), $second, $message); } - /** - * Will trigger a pass if the two parameters have - * the same value and same type. Otherwise a fail. - * @param mixed $first Value to compare. - * @param mixed $second Value to compare. - * @param string $message Message to display. - * @return boolean True on pass - * @access public - */ + /** + * Will trigger a pass if the if the first parameter + * is near enough to the second by the margin. + * @param mixed $first Value to compare. + * @param mixed $second Value to compare. + * @param mixed $margin Fuzziness of match. + * @param string $message Message to display. + * @return boolean True on pass + * @access public + */ + function assertWithinMargin($first, $second, $margin, $message = "%s") { + return $this->assert( + new WithinMarginExpectation($first, $margin), + $second, + $message); + } + + /** + * Will trigger a pass if the two parameters differ + * by more than the margin. + * @param mixed $first Value to compare. + * @param mixed $second Value to compare. + * @param mixed $margin Fuzziness of match. + * @param string $message Message to display. + * @return boolean True on pass + * @access public + */ + function assertOutsideMargin($first, $second, $margin, $message = "%s") { + return $this->assert( + new OutsideMarginExpectation($first, $margin), + $second, + $message); + } + + /** + * Will trigger a pass if the two parameters have + * the same value and same type. Otherwise a fail. + * @param mixed $first Value to compare. + * @param mixed $second Value to compare. + * @param string $message Message to display. + * @return boolean True on pass + * @access public + */ function assertIdentical($first, $second, $message = "%s") { - return $this->assertExpectation( + return $this->assert( new IdenticalExpectation($first), $second, $message); } - /** - * Will trigger a pass if the two parameters have - * the different value or different type. - * @param mixed $first Value to compare. - * @param mixed $second Value to compare. - * @param string $message Message to display. - * @return boolean True on pass - * @access public - */ + /** + * Will trigger a pass if the two parameters have + * the different value or different type. + * @param mixed $first Value to compare. + * @param mixed $second Value to compare. + * @param string $message Message to display. + * @return boolean True on pass + * @access public + */ function assertNotIdentical($first, $second, $message = "%s") { - return $this->assertExpectation( + return $this->assert( new NotIdenticalExpectation($first), $second, $message); } - /** - * Will trigger a pass if both parameters refer - * to the same object. Fail otherwise. - * @param mixed $first Object reference to check. - * @param mixed $second Hopefully the same object. - * @param string $message Message to display. - * @return boolean True on pass - * @access public - */ + /** + * Will trigger a pass if both parameters refer + * to the same object. Fail otherwise. + * @param mixed $first Object reference to check. + * @param mixed $second Hopefully the same object. + * @param string $message Message to display. + * @return boolean True on pass + * @access public + */ function assertReference(&$first, &$second, $message = "%s") { $dumper = &new SimpleDumper(); $message = sprintf( @@ -186,15 +220,15 @@ $message); } - /** - * Will trigger a pass if both parameters refer - * to different objects. Fail otherwise. - * @param mixed $first Object reference to check. - * @param mixed $second Hopefully not the same object. - * @param string $message Message to display. - * @return boolean True on pass - * @access public - */ + /** + * Will trigger a pass if both parameters refer + * to different objects. Fail otherwise. + * @param mixed $first Object reference to check. + * @param mixed $second Hopefully not the same object. + * @param string $message Message to display. + * @return boolean True on pass + * @access public + */ function assertCopy(&$first, &$second, $message = "%s") { $dumper = &new SimpleDumper(); $message = sprintf( @@ -207,47 +241,61 @@ $message); } - /** - * Will trigger a pass if the Perl regex pattern - * is found in the subject. Fail otherwise. - * @param string $pattern Perl regex to look for including - * the regex delimiters. - * @param string $subject String to search in. - * @param string $message Message to display. - * @return boolean True on pass - * @access public - */ + /** + * Will trigger a pass if the Perl regex pattern + * is found in the subject. Fail otherwise. + * @param string $pattern Perl regex to look for including + * the regex delimiters. + * @param string $subject String to search in. + * @param string $message Message to display. + * @return boolean True on pass + * @access public + */ + function assertPattern($pattern, $subject, $message = "%s") { + return $this->assert( + new PatternExpectation($pattern), + $subject, + $message); + } + + /** + * @deprecated + */ function assertWantedPattern($pattern, $subject, $message = "%s") { - return $this->assertExpectation( - new WantedPatternExpectation($pattern), + return $this->assertPattern($pattern, $subject, $message); + } + + /** + * Will trigger a pass if the perl regex pattern + * is not present in subject. Fail if found. + * @param string $pattern Perl regex to look for including + * the regex delimiters. + * @param string $subject String to search in. + * @param string $message Message to display. + * @return boolean True on pass + * @access public + */ + function assertNoPattern($pattern, $subject, $message = "%s") { + return $this->assert( + new NoPatternExpectation($pattern), $subject, $message); } - /** - * Will trigger a pass if the perl regex pattern - * is not present in subject. Fail if found. - * @param string $pattern Perl regex to look for including - * the regex delimiters. - * @param string $subject String to search in. - * @param string $message Message to display. - * @return boolean True on pass - * @access public - */ + /** + * @deprecated + */ function assertNoUnwantedPattern($pattern, $subject, $message = "%s") { - return $this->assertExpectation( - new UnwantedPatternExpectation($pattern), - $subject, - $message); + return $this->assertNoPattern($pattern, $subject, $message); } - /** - * Confirms that no errors have occoured so - * far in the test method. - * @param string $message Message to display. - * @return boolean True on pass - * @access public - */ + /** + * Confirms that no errors have occoured so + * far in the test method. + * @param string $message Message to display. + * @return boolean True on pass + * @access public + */ function assertNoErrors($message = "%s") { $queue = &SimpleErrorQueue::instance(); return $this->assertTrue( @@ -255,15 +303,15 @@ sprintf($message, "Should be no errors")); } - /** - * Confirms that an error has occoured and - * optionally that the error text matches exactly. - * @param string $expected Expected error text or - * false for no check. - * @param string $message Message to display. - * @return boolean True on pass - * @access public - */ + /** + * Confirms that an error has occoured and + * optionally that the error text matches exactly. + * @param string $expected Expected error text or + * false for no check. + * @param string $message Message to display. + * @return boolean True on pass + * @access public + */ function assertError($expected = false, $message = "%s") { $queue = &SimpleErrorQueue::instance(); if ($queue->isEmpty()) { @@ -272,32 +320,37 @@ } list($severity, $content, $file, $line, $globals) = $queue->extract(); $severity = SimpleErrorQueue::getSeverityAsString($severity); - return $this->assertTrue( - ! $expected || ($expected == $content), - "Expected [$expected] in PHP error [$content] severity [$severity] in [$file] line [$line]"); + if (! $expected) { + return $this->pass( + "Captured a PHP error of [$content] severity [$severity] in [$file] line [$line] -> %s"); + } + $expected = $this->_coerceToExpectation($expected); + return $this->assert( + $expected, + $content, + "Expected PHP error [$content] severity [$severity] in [$file] line [$line] -> %s"); } - /** - * Confirms that an error has occoured and - * that the error text matches a Perl regular - * expression. - * @param string $pattern Perl regular expresion to - * match against. - * @param string $message Message to display. - * @return boolean True on pass - * @access public - */ - function assertErrorPattern($pattern, $message = "%s") { - $queue = &SimpleErrorQueue::instance(); - if ($queue->isEmpty()) { - $this->fail(sprintf($message, "Expected error not found")); - return; + /** + * Creates an equality 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; } - list($severity, $content, $file, $line, $globals) = $queue->extract(); - $severity = SimpleErrorQueue::getSeverityAsString($severity); - return $this->assertTrue( - (boolean)preg_match($pattern, $content), - "Expected pattern match [$pattern] in PHP error [$content] severity [$severity] in [$file] line [$line]"); + return new EqualExpectation($expected); + } + + /** + * @deprecated + */ + function assertErrorPattern($pattern, $message = "%s") { + return $this->assertError(new PatternExpectation($pattern), $message); } } ?> diff --git a/vendors/simpletest/url.php b/vendors/simpletest/url.php index 9ba0f3fbc..3ebccea84 100644 --- a/vendors/simpletest/url.php +++ b/vendors/simpletest/url.php @@ -1,26 +1,27 @@ _chompCoordinates($url); + $this->setCoordinates($x, $y); $this->_scheme = $this->_chompScheme($url); list($this->_username, $this->_password) = $this->_chompLogin($url); $this->_host = $this->_chompHost($url); @@ -49,18 +54,17 @@ } $this->_path = $this->_chompPath($url); $this->_request = $this->_parseRequest($this->_chompRequest($url)); - $this->_request->setCoordinates($x, $y); $this->_fragment = (strncmp($url, "#", 1) == 0 ? substr($url, 1) : false); $this->_target = false; } - /** - * Extracts the X, Y coordinate pair from an image map. - * @param string $url URL so far. The coordinates will be - * removed. - * @return array X, Y as a pair of integers. - * @access private - */ + /** + * Extracts the X, Y coordinate pair from an image map. + * @param string $url URL so far. The coordinates will be + * removed. + * @return array X, Y as a pair of integers. + * @access private + */ function _chompCoordinates(&$url) { if (preg_match('/(.*)\?(\d+),(\d+)$/', $url, $matches)) { $url = $matches[1]; @@ -69,13 +73,13 @@ return array(false, false); } - /** - * Extracts the scheme part of an incoming URL. - * @param string $url URL so far. The scheme will be - * removed. - * @return string Scheme part or false. - * @access private - */ + /** + * Extracts the scheme part of an incoming URL. + * @param string $url URL so far. The scheme will be + * removed. + * @return string Scheme part or false. + * @access private + */ function _chompScheme(&$url) { if (preg_match('/(.*?):(\/\/)(.*)/', $url, $matches)) { $url = $matches[2] . $matches[3]; @@ -84,19 +88,19 @@ return false; } - /** - * Extracts the username and password from the - * incoming URL. The // prefix will be reattached - * to the URL after the doublet is extracted. - * @param string $url URL so far. The username and - * password are removed. - * @return array Two item list of username and - * password. Will urldecode() them. - * @access private - */ + /** + * Extracts the username and password from the + * incoming URL. The // prefix will be reattached + * to the URL after the doublet is extracted. + * @param string $url URL so far. The username and + * password are removed. + * @return array Two item list of username and + * password. Will urldecode() them. + * @access private + */ function _chompLogin(&$url) { $prefix = ''; - if (preg_match('/(\/\/)(.*)/', $url, $matches)) { + if (preg_match('/^(\/\/)(.*)/', $url, $matches)) { $prefix = $matches[1]; $url = $matches[2]; } @@ -111,19 +115,19 @@ return array(false, false); } - /** - * Extracts the host part of an incoming URL. - * Includes the port number part. Will extract - * the host if it starts with // or it has - * a top level domain or it has at least two - * dots. - * @param string $url URL so far. The host will be - * removed. - * @return string Host part guess or false. - * @access private - */ + /** + * Extracts the host part of an incoming URL. + * Includes the port number part. Will extract + * the host if it starts with // or it has + * a top level domain or it has at least two + * dots. + * @param string $url URL so far. The host will be + * removed. + * @return string Host part guess or false. + * @access private + */ function _chompHost(&$url) { - if (preg_match('/(\/\/)(.*?)(\/.*|\?.*|#.*|$)/', $url, $matches)) { + if (preg_match('/^(\/\/)(.*?)(\/.*|\?.*|#.*|$)/', $url, $matches)) { $url = $matches[3]; return $matches[2]; } @@ -140,14 +144,14 @@ return false; } - /** - * Extracts the path information from the incoming - * URL. Strips this path from the URL. - * @param string $url URL so far. The host will be - * removed. - * @return string Path part or '/'. - * @access private - */ + /** + * Extracts the path information from the incoming + * URL. Strips this path from the URL. + * @param string $url URL so far. The host will be + * removed. + * @return string Path part or '/'. + * @access private + */ function _chompPath(&$url) { if (preg_match('/(.*?)(\?|#|$)(.*)/', $url, $matches)) { $url = $matches[2] . $matches[3]; @@ -156,13 +160,13 @@ return ''; } - /** - * Strips off the request data. - * @param string $url URL so far. The request will be - * removed. - * @return string Raw request part. - * @access private - */ + /** + * Strips off the request data. + * @param string $url URL so far. The request will be + * removed. + * @return string Raw request part. + * @access private + */ function _chompRequest(&$url) { if (preg_match('/\?(.*?)(#|$)(.*)/', $url, $matches)) { $url = $matches[2] . $matches[3]; @@ -171,14 +175,15 @@ return ''; } - /** - * Breaks the request down into an object. - * @param string $raw Raw request. - * @return SimpleFormEncoding Parsed data. - * @access private - */ + /** + * Breaks the request down into an object. + * @param string $raw Raw request. + * @return SimpleFormEncoding Parsed data. + * @access private + */ function _parseRequest($raw) { - $request = new SimpleFormEncoding(); + $this->_raw = $raw; + $request = new SimpleGetEncoding(); foreach (split("&", $raw) as $pair) { if (preg_match('/(.*?)=(.*)/', $pair, $matches)) { $request->add($matches[1], urldecode($matches[2])); @@ -189,68 +194,68 @@ return $request; } - /** - * Accessor for protocol part. - * @param string $default Value to use if not present. - * @return string Scheme name, e.g "http". - * @access public - */ + /** + * Accessor for protocol part. + * @param string $default Value to use if not present. + * @return string Scheme name, e.g "http". + * @access public + */ function getScheme($default = false) { return $this->_scheme ? $this->_scheme : $default; } - /** - * Accessor for user name. - * @return string Username preceding host. - * @access public - */ + /** + * Accessor for user name. + * @return string Username preceding host. + * @access public + */ function getUsername() { return $this->_username; } - /** - * Accessor for password. - * @return string Password preceding host. - * @access public - */ + /** + * Accessor for password. + * @return string Password preceding host. + * @access public + */ function getPassword() { return $this->_password; } - /** - * Accessor for hostname and port. - * @param string $default Value to use if not present. - * @return string Hostname only. - * @access public - */ + /** + * Accessor for hostname and port. + * @param string $default Value to use if not present. + * @return string Hostname only. + * @access public + */ function getHost($default = false) { return $this->_host ? $this->_host : $default; } - /** - * Accessor for top level domain. - * @return string Last part of host. - * @access public - */ + /** + * Accessor for top level domain. + * @return string Last part of host. + * @access public + */ function getTld() { $path_parts = pathinfo($this->getHost()); return (isset($path_parts['extension']) ? $path_parts['extension'] : false); } - /** - * Accessor for port number. - * @return integer TCP/IP port number. - * @access public - */ + /** + * Accessor for port number. + * @return integer TCP/IP port number. + * @access public + */ function getPort() { return $this->_port; } - /** - * Accessor for path. - * @return string Full path including leading slash if implied. - * @access public - */ + /** + * Accessor for path. + * @return string Full path including leading slash if implied. + * @access public + */ function getPath() { if (! $this->_path && $this->_host) { return '/'; @@ -258,12 +263,12 @@ return $this->_path; } - /** - * Accessor for page if any. This may be a - * directory name if ambiguious. - * @return Page name. - * @access public - */ + /** + * Accessor for page if any. This may be a + * directory name if ambiguious. + * @return Page name. + * @access public + */ function getPage() { if (! preg_match('/([^\/]*?)$/', $this->getPath(), $matches)) { return false; @@ -271,11 +276,11 @@ return $matches[1]; } - /** - * Gets the path to the page. - * @return string Path less the page. - * @access public - */ + /** + * Gets the path to the page. + * @return string Path less the page. + * @access public + */ function getBasePath() { if (! preg_match('/(.*\/)[^\/]*?$/', $this->getPath(), $matches)) { return false; @@ -283,111 +288,126 @@ return $matches[1]; } - /** - * Accessor for fragment at end of URL after the "#". - * @return string Part after "#". - * @access public - */ + /** + * Accessor for fragment at end of URL after the "#". + * @return string Part after "#". + * @access public + */ function getFragment() { return $this->_fragment; } - /** - * Accessor for horizontal image coordinate. - * @return integer X value. - * @access public - */ + /** + * 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->_request->getX(); + return $this->_x; } - /** - * Accessor for vertical image coordinate. - * @return integer Y value. - * @access public - */ + /** + * Accessor for vertical image coordinate. + * @return integer Y value. + * @access public + */ function getY() { - return $this->_request->getY(); + return $this->_y; } - /** - * Accessor for current request parameters - * in URL string form - * @return string Form is string "?a=1&b=2", etc. - * @access public - */ + /** + * Accessor for current request parameters + * in URL string form. Will return teh original request + * if at all possible even if it doesn't make much + * sense. + * @return string Form is string "?a=1&b=2", etc. + * @access public + */ function getEncodedRequest() { - $encoded = $this->_request->asString(); + if ($this->_raw) { + $encoded = $this->_raw; + } else { + $encoded = $this->_request->asUrlRequest(); + } if ($encoded) { return '?' . preg_replace('/^\?/', '', $encoded); } return ''; } - /** - * Adds an additional parameter to the request. - * @param string $key Name of parameter. - * @param string $value Value as string. - * @access public - */ + /** + * Adds an additional parameter to the request. + * @param string $key Name of parameter. + * @param string $value Value as string. + * @access public + */ function addRequestParameter($key, $value) { + $this->_raw = false; $this->_request->add($key, $value); } - /** - * Adds additional parameters to the request. - * @param hash/SimpleFormEncoding $parameters Additional - * parameters. - * @access public - */ + /** + * Adds additional parameters to the request. + * @param hash/SimpleFormEncoding $parameters Additional + * parameters. + * @access public + */ function addRequestParameters($parameters) { + $this->_raw = false; $this->_request->merge($parameters); } - /** - * Clears down all parameters. - * @access public - */ + /** + * Clears down all parameters. + * @access public + */ function clearRequest() { - $this->_request = &new SimpleFormEncoding(); + $this->_raw = false; + $this->_request = &new SimpleGetEncoding(); } - /** - * Sets image coordinates. Set to flase to clear - * them. - * @param integer $x Horizontal position. - * @param integer $y Vertical position. - * @access public - */ - function setCoordinates($x = false, $y = false) { - $this->_request->setCoordinates($x, $y); - } - - /** - * Gets the frame target if present. Although - * not strictly part of the URL specification it - * acts as similarily to the browser. - * @return boolean/string Frame name or false if none. - * @access public - */ + /** + * Gets the frame target if present. Although + * not strictly part of the URL specification it + * acts as similarily to the browser. + * @return boolean/string Frame name or false if none. + * @access public + */ function getTarget() { return $this->_target; } - /** - * Attaches a frame target. - * @param string $frame Name of frame. - * @access public - */ + /** + * Attaches a frame target. + * @param string $frame Name of frame. + * @access public + */ function setTarget($frame) { + $this->_raw = false; $this->_target = $frame; } - /** - * Renders the URL back into a string. - * @return string URL in canonical form. - * @access public - */ + /** + * Renders the URL back into a string. + * @return string URL in canonical form. + * @access public + */ function asString() { $scheme = $identity = $host = $path = $encoded = $fragment = ''; if ($this->_username && $this->_password) { @@ -402,51 +422,48 @@ } $encoded = $this->getEncodedRequest(); $fragment = $this->getFragment() ? '#'. $this->getFragment() : ''; - return "$scheme://$identity$host$path$encoded$fragment"; + $coords = $this->getX() === false ? '' : '?' . $this->getX() . ',' . $this->getY(); + return "$scheme://$identity$host$path$encoded$fragment$coords"; } - /** - * Replaces unknown sections to turn a relative - * URL into an absolute one. The base URL can - * be either a string or a SimpleUrl object. - * @param string/SimpleUrl $base Base URL. - * @access public - */ + /** + * Replaces unknown sections to turn a relative + * URL into an absolute one. The base URL can + * be either a string or a SimpleUrl object. + * @param string/SimpleUrl $base Base URL. + * @access public + */ function makeAbsolute($base) { if (! is_object($base)) { $base = new SimpleUrl($base); } $scheme = $this->getScheme() ? $this->getScheme() : $base->getScheme(); - $host = $this->getHost() ? $this->getHost() : $base->getHost(); - $port = $this->_extractAbsolutePort($base); + if ($this->getHost()) { + $host = $this->getHost(); + $port = $this->getPort() ? ':' . $this->getPort() : ''; + $identity = $this->getIdentity() ? $this->getIdentity() . '@' : ''; + if (! $identity) { + $identity = $base->getIdentity() ? $base->getIdentity() . '@' : ''; + } + } else { + $host = $base->getHost(); + $port = $base->getPort() ? ':' . $base->getPort() : ''; + $identity = $base->getIdentity() ? $base->getIdentity() . '@' : ''; + } $path = $this->normalisePath($this->_extractAbsolutePath($base)); - $identity = $this->_getIdentity() ? $this->_getIdentity() . '@' : ''; $encoded = $this->getEncodedRequest(); $fragment = $this->getFragment() ? '#'. $this->getFragment() : ''; - return new SimpleUrl("$scheme://$identity$host$port$path$encoded$fragment"); + $coords = $this->getX() === false ? '' : '?' . $this->getX() . ',' . $this->getY(); + return new SimpleUrl("$scheme://$identity$host$port$path$encoded$fragment$coords"); } - /** - * Extracts the port from the base URL if it's needed, but - * not present, in the current URL. - * @param string/SimpleUrl $base Base URL. - * @param string Absolute port number. - * @access private - */ - function _extractAbsolutePort($base) { - if ($this->getHost()) { - return ($this->getPort() ? ':' . $this->getPort() : ''); - } - return ($base->getPort() ? ':' . $base->getPort() : ''); - } - - /** - * Replaces unknown sections of the path with base parts - * to return a complete absolute one. - * @param string/SimpleUrl $base Base URL. - * @param string Absolute path. - * @access private - */ + /** + * Replaces unknown sections of the path with base parts + * to return a complete absolute one. + * @param string/SimpleUrl $base Base URL. + * @param string Absolute path. + * @access private + */ function _extractAbsolutePath($base) { if ($this->getHost()) { return $this->_path; @@ -460,47 +477,47 @@ return $base->getPath(); } - /** - * Simple test to see if a path part is relative. - * @param string $path Path to test. - * @return boolean True if starts with a "/". - * @access private - */ + /** + * Simple test to see if a path part is relative. + * @param string $path Path to test. + * @return boolean True if starts with a "/". + * @access private + */ function _isRelativePath($path) { return (substr($path, 0, 1) != '/'); } - /** - * Extracts the username and password for use in rendering - * a URL. - * @return string/boolean Form of username:password@ or false. - * @access private - */ - function _getIdentity() { + /** + * Extracts the username and password for use in rendering + * a URL. + * @return string/boolean Form of username:password@ or false. + * @access public + */ + function getIdentity() { if ($this->_username && $this->_password) { return $this->_username . ':' . $this->_password; } return false; } - /** - * Replaces . and .. sections of the path. - * @param string $path Unoptimised path. - * @return string Path with dots removed if possible. - * @access public - */ + /** + * Replaces . and .. sections of the path. + * @param string $path Unoptimised path. + * @return string Path with dots removed if possible. + * @access public + */ function normalisePath($path) { $path = preg_replace('|/[^/]+/\.\./|', '/', $path); return preg_replace('|/\./|', '/', $path); } - /** - * A pipe seperated list of all TLDs that result in two part - * domain names. - * @return string Pipe separated list. - * @access public - * @static - */ + /** + * A pipe seperated list of all TLDs that result in two part + * domain names. + * @return string Pipe separated list. + * @access public + * @static + */ function getAllTopLevelDomains() { return 'com|edu|net|org|gov|mil|int|biz|info|name|pro|aero|coop|museum'; } diff --git a/vendors/simpletest/user_agent.php b/vendors/simpletest/user_agent.php index a18b84159..564959d42 100644 --- a/vendors/simpletest/user_agent.php +++ b/vendors/simpletest/user_agent.php @@ -1,45 +1,50 @@ _cookies = array(); } - /** - * Removes expired and temporary cookies as if - * the browser was closed and re-opened. - * @param string/integer $now Time to test expiry against. - * @access public - */ + /** + * Removes expired and temporary cookies as if + * the browser was closed and re-opened. + * @param string/integer $now Time to test expiry against. + * @access public + */ function restartSession($date = false) { $surviving_cookies = array(); for ($i = 0; $i < count($this->_cookies); $i++) { @@ -57,26 +62,26 @@ $this->_cookies = $surviving_cookies; } - /** - * Ages all cookies in the cookie jar. - * @param integer $interval The old session is moved - * into the past by this number - * of seconds. Cookies now over - * age will be removed. - * @access public - */ + /** + * Ages all cookies in the cookie jar. + * @param integer $interval The old session is moved + * into the past by this number + * of seconds. Cookies now over + * age will be removed. + * @access public + */ function agePrematurely($interval) { for ($i = 0; $i < count($this->_cookies); $i++) { $this->_cookies[$i]->agePrematurely($interval); } } - /** - * Adds a cookie to the jar. This will overwrite - * cookies with matching host, paths and keys. - * @param SimpleCookie $cookie New cookie. - * @access public - */ + /** + * Adds a cookie to the jar. This will overwrite + * cookies with matching host, paths and keys. + * @param SimpleCookie $cookie New cookie. + * @access public + */ function setCookie($cookie) { for ($i = 0; $i < count($this->_cookies); $i++) { $is_match = $this->_isMatch( @@ -92,18 +97,18 @@ $this->_cookies[] = $cookie; } - /** - * Fetches a hash of all valid cookies filtered - * by host, path and keyed by name - * Any cookies with missing categories will not - * be filtered out by that category. Expired - * cookies must be cleared by restarting the session. - * @param string $host Host name requirement. - * @param string $path Path encompassing cookies. - * @return hash Valid cookie objects keyed - * on the cookie name. - * @access public - */ + /** + * Fetches a hash of all valid cookies filtered + * by host, path and keyed by name + * Any cookies with missing categories will not + * be filtered out by that category. Expired + * cookies must be cleared by restarting the session. + * @param string $host Host name requirement. + * @param string $path Path encompassing cookies. + * @return hash Valid cookie objects keyed + * on the cookie name. + * @access public + */ function getValidCookies($host = false, $path = "/") { $valid_cookies = array(); foreach ($this->_cookies as $cookie) { @@ -114,17 +119,17 @@ return $valid_cookies; } - /** - * Tests cookie for matching against search - * criteria. - * @param SimpleTest $cookie Cookie to test. - * @param string $host Host must match. - * @param string $path Cookie path must be shorter than - * this path. - * @param string $name Name must match. - * @return boolean True if matched. - * @access private - */ + /** + * Tests cookie for matching against search + * criteria. + * @param SimpleTest $cookie Cookie to test. + * @param string $host Host must match. + * @param string $path Cookie path must be shorter than + * this path. + * @param string $name Name must match. + * @return boolean True if matched. + * @access private + */ function _isMatch($cookie, $host, $path, $name) { if ($cookie->getName() != $name) { return false; @@ -138,12 +143,12 @@ return true; } - /** - * Adds the current cookies to a request. - * @param SimpleHttpRequest $request Request to modify. - * @param SimpleUrl $url Cookie selector. - * @access private - */ + /** + * Adds the current cookies to a request. + * @param SimpleHttpRequest $request Request to modify. + * @param SimpleUrl $url Cookie selector. + * @access private + */ function addHeaders(&$request, $url) { $cookies = $this->getValidCookies($url->getHost(), $url->getPath()); foreach ($cookies as $cookie) { @@ -152,12 +157,12 @@ } } - /** - * Fetches web pages whilst keeping track of - * cookies and authentication. - * @package SimpleTest - * @subpackage WebTester - */ + /** + * Fetches web pages whilst keeping track of + * cookies and authentication. + * @package SimpleTest + * @subpackage WebTester + */ class SimpleUserAgent { var $_cookie_jar; var $_authenticator; @@ -168,10 +173,10 @@ var $_connection_timeout; var $_additional_headers; - /** - * Starts with no cookies, realms or proxies. - * @access public - */ + /** + * Starts with no cookies, realms or proxies. + * @access public + */ function SimpleUserAgent() { $this->_cookie_jar = &new SimpleCookieJar(); $this->_authenticator = &new SimpleAuthenticator(); @@ -183,49 +188,49 @@ $this->_additional_headers = array(); } - /** - * Removes expired and temporary cookies as if - * the browser was closed and re-opened. Authorisation - * has to be obtained again as well. - * @param string/integer $date Time when session restarted. - * If omitted then all persistent - * cookies are kept. - * @access public - */ + /** + * Removes expired and temporary cookies as if + * the browser was closed and re-opened. Authorisation + * has to be obtained again as well. + * @param string/integer $date Time when session restarted. + * If omitted then all persistent + * cookies are kept. + * @access public + */ function restart($date = false) { $this->_cookie_jar->restartSession($date); $this->_authenticator->restartSession(); } - /** - * Adds a header to every fetch. - * @param string $header Header line to add to every - * request until cleared. - * @access public - */ + /** + * Adds a header to every fetch. + * @param string $header Header line to add to every + * request until cleared. + * @access public + */ function addHeader($header) { $this->_additional_headers[] = $header; } - /** - * Ages the cookies by the specified time. - * @param integer $interval Amount in seconds. - * @access public - */ + /** + * Ages the cookies by the specified time. + * @param integer $interval Amount in seconds. + * @access public + */ function ageCookies($interval) { $this->_cookie_jar->agePrematurely($interval); } - /** - * Sets an additional cookie. If a cookie has - * the same name and path it is replaced. - * @param string $name Cookie key. - * @param string $value Value of cookie. - * @param string $host Host upon which the cookie is valid. - * @param string $path Cookie path if not host wide. - * @param string $expiry Expiry date. - * @access public - */ + /** + * Sets an additional cookie. If a cookie has + * the same name and path it is replaced. + * @param string $name Cookie key. + * @param string $value Value of cookie. + * @param string $host Host upon which the cookie is valid. + * @param string $path Cookie path if not host wide. + * @param string $expiry Expiry date. + * @access public + */ function setCookie($name, $value, $host = false, $path = '/', $expiry = false) { $cookie = new SimpleCookie($name, $value, $path, $expiry); if ($host) { @@ -234,16 +239,16 @@ $this->_cookie_jar->setCookie($cookie); } - /** - * Reads the most specific cookie value from the - * browser cookies. - * @param string $host Host to search. - * @param string $path Applicable path. - * @param string $name Name of cookie to read. - * @return string False if not present, else the - * value as a string. - * @access public - */ + /** + * Reads the most specific cookie value from the + * browser cookies. + * @param string $host Host to search. + * @param string $path Applicable path. + * @param string $name Name of cookie to read. + * @return string False if not present, else the + * value as a string. + * @access public + */ function getCookieValue($host, $path, $name) { $longest_path = ''; foreach ($this->_cookie_jar->getValidCookies($host, $path) as $cookie) { @@ -257,14 +262,14 @@ return (isset($value) ? $value : false); } - /** - * Reads the current cookies within the base URL. - * @param string $name Key of cookie to find. - * @param SimpleUrl $base Base URL to search from. - * @return string Null if there is no base URL, false - * if the cookie is not set. - * @access public - */ + /** + * Reads the current cookies within the base URL. + * @param string $name Key of cookie to find. + * @param SimpleUrl $base Base URL to search from. + * @return string Null if there is no base URL, false + * if the cookie is not set. + * @access public + */ function getBaseCookieValue($name, $base) { if (! $base) { return null; @@ -272,34 +277,34 @@ return $this->getCookieValue($base->getHost(), $base->getPath(), $name); } - /** - * Sets the socket timeout for opening a connection. - * @param integer $timeout Maximum time in seconds. - * @access public - */ + /** + * Sets the socket timeout for opening a connection. + * @param integer $timeout Maximum time in seconds. + * @access public + */ function setConnectionTimeout($timeout) { $this->_connection_timeout = $timeout; } - /** - * Sets the maximum number of redirects before - * a page will be loaded anyway. - * @param integer $max Most hops allowed. - * @access public - */ + /** + * Sets the maximum number of redirects before + * a page will be loaded anyway. + * @param integer $max Most hops allowed. + * @access public + */ function setMaximumRedirects($max) { $this->_max_redirects = $max; } - /** - * Sets proxy to use on all requests for when - * testing from behind a firewall. Set URL - * to false to disable. - * @param string $proxy Proxy URL. - * @param string $username Proxy username for authentication. - * @param string $password Proxy password for authentication. - * @access public - */ + /** + * Sets proxy to use on all requests for when + * testing from behind a firewall. Set URL + * to false to disable. + * @param string $proxy Proxy URL. + * @param string $username Proxy username for authentication. + * @param string $password Proxy password for authentication. + * @access public + */ function useProxy($proxy, $username, $password) { if (! $proxy) { $this->_proxy = false; @@ -313,43 +318,42 @@ $this->_proxy_password = $password; } - /** - * Test to see if the redirect limit is passed. - * @param integer $redirects Count so far. - * @return boolean True if over. - * @access private - */ + /** + * Test to see if the redirect limit is passed. + * @param integer $redirects Count so far. + * @return boolean True if over. + * @access private + */ function _isTooManyRedirects($redirects) { return ($redirects > $this->_max_redirects); } - /** - * Sets the identity for the current realm. - * @param string $host Host to which realm applies. - * @param string $realm Full name of realm. - * @param string $username Username for realm. - * @param string $password Password for realm. - * @access public - */ + /** + * Sets the identity for the current realm. + * @param string $host Host to which realm applies. + * @param string $realm Full name of realm. + * @param string $username Username for realm. + * @param string $password Password for realm. + * @access public + */ function setIdentity($host, $realm, $username, $password) { $this->_authenticator->setIdentityForRealm($host, $realm, $username, $password); } - /** - * Fetches a URL as a response object. Will keep trying if redirected. - * It will also collect authentication realm information. - * @param string $method GET, POST, etc. - * @param string/SimpleUrl $url Target to fetch. - * @param SimpleFormEncoding $parameters Additional parameters for request. - * @return SimpleHttpResponse Hopefully the target page. - * @access public - */ - function &fetchResponse($method, $url, $parameters = false) { - if ($method != 'POST') { - $url->addRequestParameters($parameters); - $parameters = false; + /** + * Fetches a URL as a response object. Will keep trying if redirected. + * It will also collect authentication realm information. + * @param string/SimpleUrl $url Target to fetch. + * @param SimpleEncoding $encoding Additional parameters for request. + * @return SimpleHttpResponse Hopefully the target page. + * @access public + */ + function &fetchResponse($url, $encoding) { + if ($encoding->getMethod() != 'POST') { + $url->addRequestParameters($encoding); + $encoding->clear(); } - $response = &$this->_fetchWhileRedirected($method, $url, $parameters); + $response = &$this->_fetchWhileRedirected($url, $encoding); if ($headers = $response->getHeaders()) { if ($headers->isChallenge()) { $this->_authenticator->addRealm( @@ -361,19 +365,18 @@ return $response; } - /** - * Fetches the page until no longer redirected or - * until the redirect limit runs out. - * @param string $method GET, POST, etc. - * @param SimpleUrl $url Target to fetch. - * @param SimpelFormEncoding $parameters Additional parameters for request. - * @return SimpleHttpResponse Hopefully the target page. - * @access private - */ - function &_fetchWhileRedirected($method, $url, $parameters) { + /** + * Fetches the page until no longer redirected or + * until the redirect limit runs out. + * @param SimpleUrl $url Target to fetch. + * @param SimpelFormEncoding $encoding Additional parameters for request. + * @return SimpleHttpResponse Hopefully the target page. + * @access private + */ + function &_fetchWhileRedirected($url, $encoding) { $redirects = 0; do { - $response = &$this->_fetch($method, $url, $parameters); + $response = &$this->_fetch($url, $encoding); if ($response->isError()) { return $response; } @@ -384,100 +387,87 @@ if (! $headers->isRedirect()) { break; } - $method = 'GET'; - $parameters = false; + $encoding = new SimpleGetEncoding(); } while (! $this->_isTooManyRedirects(++$redirects)); return $response; } - /** - * Actually make the web request. - * @param string $method GET, POST, etc. - * @param SimpleUrl $url Target to fetch. - * @param SimpleFormEncoding $parameters Additional parameters for request. - * @return SimpleHttpResponse Headers and hopefully content. - * @access protected - */ - function &_fetch($method, $url, $parameters) { - if (! $parameters) { - $parameters = new SimpleFormEncoding(); - } - $request = &$this->_createRequest($method, $url, $parameters); - return $request->fetch($this->_connection_timeout); + /** + * Actually make the web request. + * @param SimpleUrl $url Target to fetch. + * @param SimpleFormEncoding $encoding Additional parameters for request. + * @return SimpleHttpResponse Headers and hopefully content. + * @access protected + */ + function &_fetch($url, $encoding) { + $request = &$this->_createRequest($url, $encoding); + $response = &$request->fetch($this->_connection_timeout); + return $response; } - /** - * Creates a full page request. - * @param string $method Fetching method. - * @param SimpleUrl $url Target to fetch as url object. - * @param SimpleFormEncoding $parameters POST/GET parameters. - * @return SimpleHttpRequest New request. - * @access private - */ - function &_createRequest($method, $url, $parameters) { - $request = &$this->_createHttpRequest($method, $url, $parameters); + /** + * Creates a full page request. + * @param SimpleUrl $url Target to fetch as url object. + * @param SimpleFormEncoding $encoding POST/GET parameters. + * @return SimpleHttpRequest New request. + * @access private + */ + function &_createRequest($url, $encoding) { + $request = &$this->_createHttpRequest($url, $encoding); $this->_addAdditionalHeaders($request); $this->_cookie_jar->addHeaders($request, $url); $this->_authenticator->addHeaders($request, $url); return $request; } - /** - * Builds the appropriate HTTP request object. - * @param string $method Fetching method. - * @param SimpleUrl $url Target to fetch as url object. - * @param SimpleFormEncoding $parameters POST/GET parameters. - * @return SimpleHttpRequest New request object. - * @access protected - */ - function &_createHttpRequest($method, $url, $parameters) { - if ($method == 'POST') { - $request = &new SimpleHttpRequest( - $this->_createRoute($url), - 'POST', - $parameters); - return $request; - } - if ($parameters) { - $url->addRequestParameters($parameters); - } - return new SimpleHttpRequest($this->_createRoute($url), $method); + /** + * Builds the appropriate HTTP request object. + * @param SimpleUrl $url Target to fetch as url object. + * @param SimpleFormEncoding $parameters POST/GET parameters. + * @return SimpleHttpRequest New request object. + * @access protected + */ + function &_createHttpRequest($url, $encoding) { + $request = &new SimpleHttpRequest($this->_createRoute($url), $encoding); + return $request; } - /** - * Sets up either a direct route or via a proxy. - * @param SimpleUrl $url Target to fetch as url object. - * @return SimpleRoute Route to take to fetch URL. - * @access protected - */ + /** + * Sets up either a direct route or via a proxy. + * @param SimpleUrl $url Target to fetch as url object. + * @return SimpleRoute Route to take to fetch URL. + * @access protected + */ function &_createRoute($url) { if ($this->_proxy) { - return new SimpleProxyRoute( + $route = &new SimpleProxyRoute( $url, $this->_proxy, $this->_proxy_username, $this->_proxy_password); + } else { + $route = &new SimpleRoute($url); } - return new SimpleRoute($url); + return $route; } - /** - * Adds additional manual headers. - * @param SimpleHttpRequest $request Outgoing request. - * @access private - */ + /** + * Adds additional manual headers. + * @param SimpleHttpRequest $request Outgoing request. + * @access private + */ function _addAdditionalHeaders(&$request) { foreach ($this->_additional_headers as $header) { $request->addHeaderLine($header); } } - /** - * Extracts new cookies into the cookie jar. - * @param SimpleUrl $url Target to fetch as url object. - * @param array $cookies New cookies. - * @access private - */ + /** + * Extracts new cookies into the cookie jar. + * @param SimpleUrl $url Target to fetch as url object. + * @param array $cookies New cookies. + * @access private + */ function _addCookiesToJar($url, $cookies) { foreach ($cookies as $cookie) { if ($url->getHost()) { diff --git a/vendors/simpletest/web_tester.php b/vendors/simpletest/web_tester.php index dee967998..68311ee38 100644 --- a/vendors/simpletest/web_tester.php +++ b/vendors/simpletest/web_tester.php @@ -1,33 +1,33 @@ SimpleExpectation(); if (is_array($value)) { @@ -36,14 +36,14 @@ $this->_value = $value; } - /** - * Tests the expectation. True if it matches - * a string value or an array value in any order. - * @param mixed $compare Comparison value. False for - * an unset field. - * @return boolean True if correct. - * @access public - */ + /** + * Tests the expectation. True if it matches + * a string value or an array value in any order. + * @param mixed $compare Comparison value. False for + * an unset field. + * @return boolean True if correct. + * @access public + */ function test($compare) { if ($this->_value === false) { return ($compare === false); @@ -57,22 +57,22 @@ return false; } - /** - * Tests for valid field comparisons with a single option. - * @param mixed $value Value to type check. - * @return boolean True if integer, string or float. - * @access private - */ + /** + * Tests for valid field comparisons with a single option. + * @param mixed $value Value to type check. + * @return boolean True if integer, string or float. + * @access private + */ function _isSingle($value) { return is_string($value) || is_integer($value) || is_float($value); } - /** - * String comparison for simple field with a single option. - * @param mixed $compare String to test against. - * @returns boolean True if matching. - * @access private - */ + /** + * String comparison for simple field with a single option. + * @param mixed $compare String to test against. + * @returns boolean True if matching. + * @access private + */ function _testSingle($compare) { if (is_array($compare) && count($compare) == 1) { $compare = $compare[0]; @@ -83,12 +83,12 @@ return ($this->_value == $compare); } - /** - * List comparison for multivalue field. - * @param mixed $compare List in any order to test against. - * @returns boolean True if matching. - * @access private - */ + /** + * List comparison for multivalue field. + * @param mixed $compare List in any order to test against. + * @returns boolean True if matching. + * @access private + */ function _testMultiple($compare) { if (is_string($compare)) { $compare = array($compare); @@ -100,13 +100,13 @@ return ($this->_value === $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 (is_array($compare)) { @@ -123,64 +123,64 @@ } } - /** - * Test for a specific HTTP header within a header block. - * @package SimpleTest - * @subpackage WebTester - */ + /** + * Test for a specific HTTP header within a header block. + * @package SimpleTest + * @subpackage WebTester + */ class HttpHeaderExpectation extends SimpleExpectation { var $_expected_header; var $_expected_value; - /** - * Sets the field and value to compare against. - * @param string $header Case insenstive trimmed header name. - * @param string $value Optional value to compare. If not - * given then any value will match. - */ + /** + * Sets the field and value to compare against. + * @param string $header Case insenstive trimmed header name. + * @param string $value Optional value to compare. If not + * given then any value will match. + */ function HttpHeaderExpectation($header, $value = false) { $this->_expected_header = $this->_normaliseHeader($header); $this->_expected_value = $value; } - /** - * Accessor for subclases. - * @return mixed Expectation set in constructor. - * @access protected - */ + /** + * Accessor for subclases. + * @return mixed Expectation set in constructor. + * @access protected + */ function _getExpectation() { return $this->_expected_value; } - /** - * Removes whitespace at ends and case variations. - * @param string $header Name of header. - * @param string Trimmed and lowecased header - * name. - * @access private - */ + /** + * Removes whitespace at ends and case variations. + * @param string $header Name of header. + * @param string Trimmed and lowecased header + * name. + * @access private + */ function _normaliseHeader($header) { return strtolower(trim($header)); } - /** - * Tests the expectation. True if it matches - * a string value or an array value in any order. - * @param mixed $compare Raw header block to search. - * @return boolean True if header present. - * @access public - */ + /** + * Tests the expectation. True if it matches + * a string value or an array value in any order. + * @param mixed $compare Raw header block to search. + * @return boolean True if header present. + * @access public + */ function test($compare) { return is_string($this->_findHeader($compare)); } - /** - * Searches the incoming result. Will extract the matching - * line as text. - * @param mixed $compare Raw header block to search. - * @return string Matching header line. - * @access protected - */ + /** + * Searches the incoming result. Will extract the matching + * line as text. + * @param mixed $compare Raw header block to search. + * @return string Matching header line. + * @access protected + */ function _findHeader($compare) { $lines = split("\r\n", $compare); foreach ($lines as $line) { @@ -191,14 +191,14 @@ return false; } - /** - * Compares a single header line against the expectation. - * @param string $line A single line to compare. - * @return boolean True if matched. - * @access private - */ + /** + * Compares a single header line against the expectation. + * @param string $line A single line to compare. + * @return boolean True if matched. + * @access private + */ function _testHeaderLine($line) { - if (count($parsed = split(':', $line)) < 2) { + if (count($parsed = split(':', $line, 2)) < 2) { return false; } list($header, $value) = $parsed; @@ -208,13 +208,13 @@ return $this->_testHeaderValue($value, $this->_expected_value); } - /** - * Tests the value part of the header. - * @param string $value Value to test. - * @param mixed $expected Value to test against. - * @return boolean True if matched. - * @access protected - */ + /** + * Tests the value part of the header. + * @param string $value Value to test. + * @param mixed $expected Value to test against. + * @return boolean True if matched. + * @access protected + */ function _testHeaderValue($value, $expected) { if ($expected === false) { return true; @@ -222,13 +222,13 @@ return (trim($value) == trim($expected)); } - /** - * Returns a human readable test message. - * @param mixed $compare Raw header block to search. - * @return string Description of success - * or failure. - * @access public - */ + /** + * Returns a human readable test message. + * @param mixed $compare Raw header block to search. + * @return string Description of success + * or failure. + * @access public + */ function testMessage($compare) { $expectation = $this->_expected_header; if ($this->_expected_value) { @@ -242,41 +242,41 @@ } } - /** - * Test for a specific HTTP header within a header block that - * should not be found. - * @package SimpleTest - * @subpackage WebTester - */ + /** + * Test for a specific HTTP header within a header block that + * should not be found. + * @package SimpleTest + * @subpackage WebTester + */ class HttpUnwantedHeaderExpectation extends HttpHeaderExpectation { var $_expected_header; var $_expected_value; - /** - * Sets the field and value to compare against. - * @param string $unwanted Case insenstive trimmed header name. - */ + /** + * Sets the field and value to compare against. + * @param string $unwanted Case insenstive trimmed header name. + */ function HttpUnwantedHeaderExpectation($unwanted) { $this->HttpHeaderExpectation($unwanted); } - /** - * Tests that the unwanted header is not found. - * @param mixed $compare Raw header block to search. - * @return boolean True if header present. - * @access public - */ + /** + * Tests that the unwanted header is not found. + * @param mixed $compare Raw header block to search. + * @return boolean True if header present. + * @access public + */ function test($compare) { return ($this->_findHeader($compare) === false); } - /** - * Returns a human readable test message. - * @param mixed $compare Raw header block to search. - * @return string Description of success - * or failure. - * @access public - */ + /** + * Returns a human readable test message. + * @param mixed $compare Raw header block to search. + * @return string Description of success + * or failure. + * @access public + */ function testMessage($compare) { $expectation = $this->_getExpectation(); if (is_string($line = $this->_findHeader($compare))) { @@ -287,81 +287,81 @@ } } - /** - * Test for a specific HTTP header within a header block. - * @package SimpleTest - * @subpackage WebTester - */ + /** + * Test for a specific HTTP header within a header block. + * @package SimpleTest + * @subpackage WebTester + */ class HttpHeaderPatternExpectation extends HttpHeaderExpectation { - /** - * Sets the field and value to compare against. - * @param string $header Case insenstive header name. - * @param string $pattern Pattern to compare value against. - * @access public - */ + /** + * Sets the field and value to compare against. + * @param string $header Case insenstive header name. + * @param string $pattern Pattern to compare value against. + * @access public + */ function HttpHeaderPatternExpectation($header, $pattern) { $this->HttpHeaderExpectation($header, $pattern); } - /** - * Tests the value part of the header. - * @param string $value Value to test. - * @param mixed $pattern Pattern to test against. - * @return boolean True if matched. - * @access protected - */ + /** + * Tests the value part of the header. + * @param string $value Value to test. + * @param mixed $pattern Pattern to test against. + * @return boolean True if matched. + * @access protected + */ function _testHeaderValue($value, $expected) { return (boolean)preg_match($expected, trim($value)); } } - /** - * Test for a text substring. - * @package SimpleTest - * @subpackage UnitTester - */ + /** + * Test for a text substring. + * @package SimpleTest + * @subpackage UnitTester + */ class WantedTextExpectation extends SimpleExpectation { var $_substring; - /** - * Sets the value to compare against. - * @param string $substring Text to search for. - * @param string $message Customised message on failure. - * @access public - */ + /** + * Sets the value to compare against. + * @param string $substring Text to search for. + * @param string $message Customised message on failure. + * @access public + */ function WantedTextExpectation($substring, $message = '%s') { $this->SimpleExpectation($message); $this->_substring = $substring; } - /** - * Accessor for the substring. - * @return string Text to match. - * @access protected - */ + /** + * Accessor for the substring. + * @return string Text to match. + * @access protected + */ function _getSubstring() { return $this->_substring; } - /** - * Tests the expectation. True if the text contains the - * substring. - * @param string $compare Comparison value. - * @return boolean True if correct. - * @access public - */ + /** + * Tests the expectation. True if the text contains the + * substring. + * @param string $compare Comparison value. + * @return boolean True if correct. + * @access public + */ function test($compare) { return (strpos($compare, $this->_substring) !== false); } - /** - * 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->_describeTextMatch($this->_getSubstring(), $compare); @@ -373,13 +373,13 @@ } } - /** - * Describes a pattern match including the string - * found and it's position. - * @param string $substring Text to search for. - * @param string $subject Subject to search. - * @access protected - */ + /** + * Describes a pattern match including the string + * found and it's position. + * @param string $substring Text to search for. + * @param string $subject Subject to search. + * @access protected + */ function _describeTextMatch($substring, $subject) { $position = strpos($subject, $substring); $dumper = &$this->_getDumper(); @@ -389,42 +389,42 @@ } } - /** - * Fail if a substring is detected within the - * comparison text. - * @package SimpleTest - * @subpackage UnitTester - */ + /** + * Fail if a substring is detected within the + * comparison text. + * @package SimpleTest + * @subpackage UnitTester + */ class UnwantedTextExpectation extends WantedTextExpectation { - /** - * Sets the reject pattern - * @param string $substring Text to search for. - * @param string $message Customised message on failure. - * @access public - */ + /** + * Sets the reject pattern + * @param string $substring Text to search for. + * @param string $message Customised message on failure. + * @access public + */ function UnwantedTextExpectation($substring, $message = '%s') { $this->WantedTextExpectation($substring, $message); } - /** - * Tests the expectation. False if the substring appears - * in the text. - * @param string $compare Comparison value. - * @return boolean True if correct. - * @access public - */ + /** + * Tests the expectation. False if the substring appears + * in the text. + * @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(); @@ -437,28 +437,28 @@ } } - /** - * Extension that builds a web browser at the start of each - * test. - * @package SimpleTest - * @subpackage WebTester - */ + /** + * Extension that builds a web browser at the start of each + * test. + * @package SimpleTest + * @subpackage WebTester + */ class WebTestCaseInvoker extends SimpleInvokerDecorator { - /** - * Takes in the test case and reporter to mediate between. - * @param SimpleTestCase $test_case Test case to run. - * @param SimpleScorer $scorer Reporter to receive events. - */ + /** + * Takes in the test case and reporter to mediate between. + * @param SimpleTestCase $test_case Test case to run. + * @param SimpleScorer $scorer Reporter to receive events. + */ function WebTestCaseInvoker(&$invoker) { $this->SimpleInvokerDecorator($invoker); } - /** - * Builds the browser and runs the test. - * @param string $method Test method to call. - * @access public - */ + /** + * Builds the browser and runs the test. + * @param string $method Test method to call. + * @access public + */ function invoke($method) { $test = &$this->getTestCase(); $test->setBrowser($test->createBrowser()); @@ -467,132 +467,142 @@ } } - /** - * Test case for testing of web pages. Allows - * fetching of pages, parsing of HTML and - * submitting forms. - * @package SimpleTest - * @subpackage WebTester - */ + /** + * Test case for testing of web pages. Allows + * fetching of pages, parsing of HTML and + * submitting forms. + * @package SimpleTest + * @subpackage WebTester + */ class WebTestCase extends SimpleTestCase { var $_browser; - /** - * Creates an empty test case. Should be subclassed - * with test methods for a functional test case. - * @param string $label Name of test case. Will use - * the class name if none specified. - * @access public - */ + /** + * Creates an empty test case. Should be subclassed + * with test methods for a functional test case. + * @param string $label Name of test case. Will use + * the class name if none specified. + * @access public + */ function WebTestCase($label = false) { $this->SimpleTestCase($label); } - /** - * Sets the invoker to one that restarts the browser on - * each request. - * @return SimpleInvoker Invoker for each method. - * @access public - */ + /** + * Sets the invoker to one that restarts the browser on + * each request. + * @return SimpleInvoker Invoker for each method. + * @access public + */ function &createInvoker() { - return new WebTestCaseInvoker(parent::createInvoker()); + $invoker = &new WebTestCaseInvoker(parent::createInvoker()); + return $invoker; } - /** - * Gets a current browser reference for setting - * special expectations or for detailed - * examination of page fetches. - * @return SimpleBrowser Current test browser object. - * @access public - */ + /** + * Gets a current browser reference for setting + * special expectations or for detailed + * examination of page fetches. + * @return SimpleBrowser Current test browser object. + * @access public + */ function &getBrowser() { return $this->_browser; } - /** - * Gets a current browser reference for setting - * special expectations or for detailed - * examination of page fetches. - * @param SimpleBrowser $browser New test browser object. - * @access public - */ + /** + * Gets a current browser reference for setting + * special expectations or for detailed + * examination of page fetches. + * @param SimpleBrowser $browser New test browser object. + * @access public + */ function setBrowser(&$browser) { return $this->_browser = &$browser; } - /** - * Clears the current browser reference to help the - * PHP garbage collector. - * @access public - */ + /** + * Clears the current browser reference to help the + * PHP garbage collector. + * @access public + */ function unsetBrowser() { unset($this->_browser); } - /** - * Creates a new default web browser object. - * Will be cleared at the end of the test method. - * @return TestBrowser New browser. - * @access public - */ + /** + * Creates a new default web browser object. + * Will be cleared at the end of the test method. + * @return TestBrowser New browser. + * @access public + */ function &createBrowser() { - return new SimpleBrowser(); + $browser = &new SimpleBrowser(); + return $browser; } - /** - * Gets the last response error. - * @return string Last low level HTTP error. - * @access public - */ + /** + * Gets the last response error. + * @return string Last low level HTTP error. + * @access public + */ function getTransportError() { return $this->_browser->getTransportError(); } - /** - * Accessor for the currently selected URL. - * @return string Current location or false if - * no page yet fetched. - * @access public - */ + /** + * Accessor for the currently selected URL. + * @return string Current location or false if + * no page yet fetched. + * @access public + */ function getUrl() { return $this->_browser->getUrl(); } - /** - * Dumps the current request for debugging. - * @access public - */ + /** + * Dumps the current request for debugging. + * @access public + */ function showRequest() { $this->dump($this->_browser->getRequest()); } - /** - * Dumps the current HTTP headers for debugging. - * @access public - */ + /** + * Dumps the current HTTP headers for debugging. + * @access public + */ function showHeaders() { $this->dump($this->_browser->getHeaders()); } - /** - * Dumps the current HTML source for debugging. - * @access public - */ + /** + * Dumps the current HTML source for debugging. + * @access public + */ function showSource() { $this->dump($this->_browser->getContent()); } + + /** + * Dumps the visible text only for debugging. + * @access public + */ + function showText() { + $this->dump(wordwrap($this->_browser->getContentAsText(), 80)); + } - /** - * Simulates the closing and reopening of the browser. - * Temporary cookies will be discarded and timed - * cookies will be expired if later than the - * specified time. - * @param string/integer $date Time when session restarted. - * If ommitted then all persistent - * cookies are kept. Time is either - * Cookie format string or timestamp. - * @access public - */ + /** + * Simulates the closing and reopening of the browser. + * Temporary cookies will be discarded and timed + * cookies will be expired if later than the + * specified time. + * @param string/integer $date Time when session restarted. + * If ommitted then all persistent + * cookies are kept. Time is either + * Cookie format string or timestamp. + * @access public + */ function restart($date = false) { if ($date === false) { $date = time(); @@ -600,41 +610,41 @@ $this->_browser->restart($date); } - /** - * Moves cookie expiry times back into the past. - * Useful for testing timeouts and expiries. - * @param integer $interval Amount to age in seconds. - * @access public - */ + /** + * Moves cookie expiry times back into the past. + * Useful for testing timeouts and expiries. + * @param integer $interval Amount to age in seconds. + * @access public + */ function ageCookies($interval) { $this->_browser->ageCookies($interval); } - /** - * Disables frames support. Frames will not be fetched - * and the frameset page will be used instead. - * @access public - */ + /** + * Disables frames support. Frames will not be fetched + * and the frameset page will be used instead. + * @access public + */ function ignoreFrames() { $this->_browser->ignoreFrames(); } - /** - * Adds a header to every fetch. - * @param string $header Header line to add to every - * request until cleared. - * @access public - */ + /** + * Adds a header to every fetch. + * @param string $header Header line to add to every + * request until cleared. + * @access public + */ function addHeader($header) { $this->_browser->addHeader($header); } - /** - * Sets the maximum number of redirects before - * the web page is loaded regardless. - * @param integer $max Maximum hops. - * @access public - */ + /** + * Sets the maximum number of redirects before + * the web page is loaded regardless. + * @param integer $max Maximum hops. + * @access public + */ function setMaximumRedirects($max) { if (! $this->_browser) { trigger_error( @@ -643,431 +653,507 @@ $this->_browser->setMaximumRedirects($max); } - /** - * Sets the socket timeout for opening a connection and - * receiving at least one byte of information. - * @param integer $timeout Maximum time in seconds. - * @access public - */ + /** + * Sets the socket timeout for opening a connection and + * receiving at least one byte of information. + * @param integer $timeout Maximum time in seconds. + * @access public + */ function setConnectionTimeout($timeout) { $this->_browser->setConnectionTimeout($timeout); } - /** - * Sets proxy to use on all requests for when - * testing from behind a firewall. Set URL - * to false to disable. - * @param string $proxy Proxy URL. - * @param string $username Proxy username for authentication. - * @param string $password Proxy password for authentication. - * @access public - */ + /** + * Sets proxy to use on all requests for when + * testing from behind a firewall. Set URL + * to false to disable. + * @param string $proxy Proxy URL. + * @param string $username Proxy username for authentication. + * @param string $password Proxy password for authentication. + * @access public + */ function useProxy($proxy, $username = false, $password = false) { $this->_browser->useProxy($proxy, $username, $password); } - /** - * Fetches a page into the page buffer. If - * there is no base for the URL then the - * current base URL is used. After the fetch - * the base URL reflects the new location. - * @param string $url URL to fetch. - * @param hash $parameters Optional additional GET data. - * @return boolean True on success. - * @access public - */ + /** + * Fetches a page into the page buffer. If + * there is no base for the URL then the + * current base URL is used. After the fetch + * the base URL reflects the new location. + * @param string $url URL to fetch. + * @param hash $parameters Optional additional GET data. + * @return boolean/string Raw page on success. + * @access public + */ function get($url, $parameters = false) { - $content = $this->_browser->get($url, $parameters); - if ($content === false) { - return false; - } - return true; + return $this->_browser->get($url, $parameters); } - /** - * Fetches a page by POST into the page buffer. - * If there is no base for the URL then the - * current base URL is used. After the fetch - * the base URL reflects the new location. - * @param string $url URL to fetch. - * @param hash $parameters Optional additional GET data. - * @return boolean True on success. - * @access public - */ + /** + * Fetches a page by POST into the page buffer. + * If there is no base for the URL then the + * current base URL is used. After the fetch + * the base URL reflects the new location. + * @param string $url URL to fetch. + * @param hash $parameters Optional additional GET data. + * @return boolean/string Raw page on success. + * @access public + */ function post($url, $parameters = false) { - $content = $this->_browser->post($url, $parameters); - if ($content === false) { - return false; - } - return true; + return $this->_browser->post($url, $parameters); } - /** - * Does a HTTP HEAD fetch, fetching only the page - * headers. The current base URL is unchanged by this. - * @param string $url URL to fetch. - * @param hash $parameters Optional additional GET data. - * @return boolean True on success. - * @access public - */ + /** + * Does a HTTP HEAD fetch, fetching only the page + * headers. The current base URL is unchanged by this. + * @param string $url URL to fetch. + * @param hash $parameters Optional additional GET data. + * @return boolean True on success. + * @access public + */ function head($url, $parameters = false) { return $this->_browser->head($url, $parameters); } - /** - * Equivalent to hitting the retry button on the - * browser. Will attempt to repeat the page fetch. - * @return boolean True if fetch succeeded. - * @access public - */ + /** + * Equivalent to hitting the retry button on the + * browser. Will attempt to repeat the page fetch. + * @return boolean True if fetch succeeded. + * @access public + */ function retry() { return $this->_browser->retry(); } - /** - * Equivalent to hitting the back button on the - * browser. - * @return boolean True if history entry and - * fetch succeeded. - * @access public - */ + /** + * Equivalent to hitting the back button on the + * browser. + * @return boolean True if history entry and + * fetch succeeded. + * @access public + */ function back() { return $this->_browser->back(); } - /** - * Equivalent to hitting the forward button on the - * browser. - * @return boolean True if history entry and - * fetch succeeded. - * @access public - */ + /** + * Equivalent to hitting the forward button on the + * browser. + * @return boolean True if history entry and + * fetch succeeded. + * @access public + */ function forward() { return $this->_browser->forward(); } - /** - * Retries a request after setting the authentication - * for the current realm. - * @param string $username Username for realm. - * @param string $password Password for realm. - * @return boolean True if successful fetch. Note - * that authentication may still have - * failed. - * @access public - */ + /** + * Retries a request after setting the authentication + * for the current realm. + * @param string $username Username for realm. + * @param string $password Password for realm. + * @return boolean True if successful fetch. Note + * that authentication may still have + * failed. + * @access public + */ function authenticate($username, $password) { return $this->_browser->authenticate($username, $password); } - /** - * Gets the cookie value for the current browser context. - * @param string $name Name of cookie. - * @return string Value of cookie or false if unset. - * @access public - */ + /** + * Gets the cookie value for the current browser context. + * @param string $name Name of cookie. + * @return string Value of cookie or false if unset. + * @access public + */ function getCookie($name) { return $this->_browser->getCurrentCookieValue($name); } - /** - * Sets a cookie in the current browser. - * @param string $name Name of cookie. - * @param string $value Cookie value. - * @param string $host Host upon which the cookie is valid. - * @param string $path Cookie path if not host wide. - * @param string $expiry Expiry date. - * @access public - */ + /** + * Sets a cookie in the current browser. + * @param string $name Name of cookie. + * @param string $value Cookie value. + * @param string $host Host upon which the cookie is valid. + * @param string $path Cookie path if not host wide. + * @param string $expiry Expiry date. + * @access public + */ function setCookie($name, $value, $host = false, $path = "/", $expiry = false) { $this->_browser->setCookie($name, $value, $host, $path, $expiry); } - /** - * Accessor for current frame focus. Will be - * false if no frame has focus. - * @return integer/string/boolean Label if any, otherwise - * the position in the frameset - * or false if none. - * @access public - */ + /** + * Accessor for current frame focus. Will be + * false if no frame has focus. + * @return integer/string/boolean Label if any, otherwise + * the position in the frameset + * or false if none. + * @access public + */ function getFrameFocus() { return $this->_browser->getFrameFocus(); } - /** - * Sets the focus by index. The integer index starts from 1. - * @param integer $choice Chosen frame. - * @return boolean True if frame exists. - * @access public - */ + /** + * Sets the focus by index. The integer index starts from 1. + * @param integer $choice Chosen frame. + * @return boolean True if frame exists. + * @access public + */ function setFrameFocusByIndex($choice) { return $this->_browser->setFrameFocusByIndex($choice); } - /** - * Sets the focus by name. - * @param string $name Chosen frame. - * @return boolean True if frame exists. - * @access public - */ + /** + * Sets the focus by name. + * @param string $name Chosen frame. + * @return boolean True if frame exists. + * @access public + */ function setFrameFocus($name) { return $this->_browser->setFrameFocus($name); } - /** - * Clears the frame focus. All frames will be searched - * for content. - * @access public - */ + /** + * Clears the frame focus. All frames will be searched + * for content. + * @access public + */ function clearFrameFocus() { return $this->_browser->clearFrameFocus(); } - /** - * Clicks the submit button by label. The owning - * form will be submitted by this. - * @param string $label Button label. An unlabeled - * button can be triggered by 'Submit'. - * @param hash $additional Additional form values. - * @return boolean/string Page on success. - * @access public - */ + /** + * Clicks a visible text item. Will first try buttons, + * then links and then images. + * @param string $label Visible text or alt text. + * @return string/boolean Raw page or false. + * @access public + */ + function click($label) { + return $this->_browser->click($label); + } + + /** + * Clicks the submit button by label. The owning + * form will be submitted by this. + * @param string $label Button label. An unlabeled + * button can be triggered by 'Submit'. + * @param hash $additional Additional form values. + * @return boolean/string Page on success, else false. + * @access public + */ function clickSubmit($label = 'Submit', $additional = false) { return $this->_browser->clickSubmit($label, $additional); } - /** - * Clicks the submit button by name attribute. The owning - * form will be submitted by this. - * @param string $name Name attribute of button. - * @param hash $additional Additional form values. - * @return boolean/string Page on success. - * @access public - */ + /** + * Clicks the submit button by name attribute. The owning + * form will be submitted by this. + * @param string $name Name attribute of button. + * @param hash $additional Additional form values. + * @return boolean/string Page on success. + * @access public + */ function clickSubmitByName($name, $additional = false) { return $this->_browser->clickSubmitByName($name, $additional); } - /** - * Clicks the submit button by ID attribute. The owning - * form will be submitted by this. - * @param string $id ID attribute of button. - * @param hash $additional Additional form values. - * @return boolean/string Page on success. - * @access public - */ + /** + * Clicks the submit button by ID attribute. The owning + * form will be submitted by this. + * @param string $id ID attribute of button. + * @param hash $additional Additional form values. + * @return boolean/string Page on success. + * @access public + */ function clickSubmitById($id, $additional = false) { return $this->_browser->clickSubmitById($id, $additional); } - /** - * Clicks the submit image by some kind of label. Usually - * the alt tag or the nearest equivalent. The owning - * form will be submitted by this. Clicking outside of - * the boundary of the coordinates will result in - * a failure. - * @param string $label Alt attribute of button. - * @param integer $x X-coordinate of imaginary click. - * @param integer $y Y-coordinate of imaginary click. - * @param hash $additional Additional form values. - * @return boolean/string Page on success. - * @access public - */ + /** + * Clicks the submit image by some kind of label. Usually + * the alt tag or the nearest equivalent. The owning + * form will be submitted by this. Clicking outside of + * the boundary of the coordinates will result in + * a failure. + * @param string $label Alt attribute of button. + * @param integer $x X-coordinate of imaginary click. + * @param integer $y Y-coordinate of imaginary click. + * @param hash $additional Additional form values. + * @return boolean/string Page on success. + * @access public + */ function clickImage($label, $x = 1, $y = 1, $additional = false) { return $this->_browser->clickImage($label, $x, $y, $additional); } - /** - * Clicks the submit image by the name. Usually - * the alt tag or the nearest equivalent. The owning - * form will be submitted by this. Clicking outside of - * the boundary of the coordinates will result in - * a failure. - * @param string $name Name attribute of button. - * @param integer $x X-coordinate of imaginary click. - * @param integer $y Y-coordinate of imaginary click. - * @param hash $additional Additional form values. - * @return boolean/string Page on success. - * @access public - */ + /** + * Clicks the submit image by the name. Usually + * the alt tag or the nearest equivalent. The owning + * form will be submitted by this. Clicking outside of + * the boundary of the coordinates will result in + * a failure. + * @param string $name Name attribute of button. + * @param integer $x X-coordinate of imaginary click. + * @param integer $y Y-coordinate of imaginary click. + * @param hash $additional Additional form values. + * @return boolean/string Page on success. + * @access public + */ function clickImageByName($name, $x = 1, $y = 1, $additional = false) { return $this->_browser->clickImageByName($name, $x, $y, $additional); } - /** - * Clicks the submit image by ID attribute. The owning - * form will be submitted by this. Clicking outside of - * the boundary of the coordinates will result in - * a failure. - * @param integer/string $id ID attribute of button. - * @param integer $x X-coordinate of imaginary click. - * @param integer $y Y-coordinate of imaginary click. - * @param hash $additional Additional form values. - * @return boolean/string Page on success. - * @access public - */ + /** + * Clicks the submit image by ID attribute. The owning + * form will be submitted by this. Clicking outside of + * the boundary of the coordinates will result in + * a failure. + * @param integer/string $id ID attribute of button. + * @param integer $x X-coordinate of imaginary click. + * @param integer $y Y-coordinate of imaginary click. + * @param hash $additional Additional form values. + * @return boolean/string Page on success. + * @access public + */ function clickImageById($id, $x = 1, $y = 1, $additional = false) { return $this->_browser->clickImageById($id, $x, $y, $additional); } - /** - * Submits a form by the ID. - * @param string $id Form ID. No button information - * is submitted this way. - * @return boolean/string Page on success. - * @access public - */ + /** + * Submits a form by the ID. + * @param string $id Form ID. No button information + * is submitted this way. + * @return boolean/string Page on success. + * @access public + */ function submitFormById($id) { return $this->_browser->submitFormById($id); } - /** - * Follows a link by name. Will click the first link - * found with this link text by default, or a later - * one if an index is given. Match is case insensitive - * with normalised space. - * @param string $label Text between the anchor tags. - * @param integer $index Link position counting from zero. - * @return boolean/string Page on success. - * @access public - */ + /** + * Follows a link by name. Will click the first link + * found with this link text by default, or a later + * one if an index is given. Match is case insensitive + * with normalised space. + * @param string $label Text between the anchor tags. + * @param integer $index Link position counting from zero. + * @return boolean/string Page on success. + * @access public + */ function clickLink($label, $index = 0) { return $this->_browser->clickLink($label, $index); } - /** - * Follows a link by id attribute. - * @param string $id ID attribute value. - * @return boolean/string Page on success. - * @access public - */ + /** + * Follows a link by id attribute. + * @param string $id ID attribute value. + * @return boolean/string Page on success. + * @access public + */ function clickLinkById($id) { return $this->_browser->clickLinkById($id); } - /** - * Tests for the presence of a link label. Match is - * case insensitive with normalised space. - * @param string $label Text between the anchor tags. - * @param string $message Message to display. Default - * can be embedded with %s. - * @return boolean True if link present. - * @access public - */ + /** + * Will trigger a pass if the two parameters have + * the same value only. Otherwise a fail. This + * is for testing hand extracted text, etc. + * @param mixed $first Value to compare. + * @param mixed $second Value to compare. + * @param string $message Message to display. + * @return boolean True on pass + * @access public + */ + function assertEqual($first, $second, $message = "%s") { + return $this->assert( + new EqualExpectation($first), + $second, + $message); + } + + /** + * Will trigger a pass if the two parameters have + * a different value. Otherwise a fail. This + * is for testing hand extracted text, etc. + * @param mixed $first Value to compare. + * @param mixed $second Value to compare. + * @param string $message Message to display. + * @return boolean True on pass + * @access public + */ + function assertNotEqual($first, $second, $message = "%s") { + return $this->assert( + new NotEqualExpectation($first), + $second, + $message); + } + + /** + * Tests for the presence of a link label. Match is + * case insensitive with normalised space. + * @param string $label Text between the anchor tags. + * @param string $message Message to display. Default + * can be embedded with %s. + * @return boolean True if link present. + * @access public + */ function assertLink($label, $message = "%s") { return $this->assertTrue( $this->_browser->isLink($label), sprintf($message, "Link [$label] should exist")); } - /** - * Tests for the non-presence of a link label. Match is - * case insensitive with normalised space. - * @param string/integer $label Text between the anchor tags - * or ID attribute. - * @param string $message Message to display. Default - * can be embedded with %s. - * @return boolean True if link missing. - * @access public - */ + /** + * Tests for the non-presence of a link label. Match is + * case insensitive with normalised space. + * @param string/integer $label Text between the anchor tags + * or ID attribute. + * @param string $message Message to display. Default + * can be embedded with %s. + * @return boolean True if link missing. + * @access public + */ function assertNoLink($label, $message = "%s") { return $this->assertFalse( $this->_browser->isLink($label), sprintf($message, "Link [$label] should not exist")); } - /** - * Tests for the presence of a link id attribute. - * @param string $id Id attribute value. - * @param string $message Message to display. Default - * can be embedded with %s. - * @return boolean True if link present. - * @access public - */ + /** + * Tests for the presence of a link id attribute. + * @param string $id Id attribute value. + * @param string $message Message to display. Default + * can be embedded with %s. + * @return boolean True if link present. + * @access public + */ function assertLinkById($id, $message = "%s") { return $this->assertTrue( $this->_browser->isLinkById($id), sprintf($message, "Link ID [$id] should exist")); } - /** - * Tests for the non-presence of a link label. Match is - * case insensitive with normalised space. - * @param string $id Id attribute value. - * @param string $message Message to display. Default - * can be embedded with %s. - * @return boolean True if link missing. - * @access public - */ + /** + * Tests for the non-presence of a link label. Match is + * case insensitive with normalised space. + * @param string $id Id attribute value. + * @param string $message Message to display. Default + * can be embedded with %s. + * @return boolean True if link missing. + * @access public + */ function assertNoLinkById($id, $message = "%s") { return $this->assertFalse( $this->_browser->isLinkById($id), sprintf($message, "Link ID [$id] should not exist")); } - /** - * Sets all form fields with that name. - * @param string $name Name of field in forms. - * @param string $value New value of field. - * @return boolean True if field exists, otherwise false. - * @access public - */ - function setField($name, $value) { - return $this->_browser->setField($name, $value); + /** + * Sets all form fields with that label, or name if there + * is no label attached. + * @param string $name Name of field in forms. + * @param string $value New value of field. + * @return boolean True if field exists, otherwise false. + * @access public + */ + function setField($label, $value) { + return $this->_browser->setField($label, $value); + } + + /** + * Sets all form fields with that name. + * @param string $name Name of field in forms. + * @param string $value New value of field. + * @return boolean True if field exists, otherwise false. + * @access public + */ + function setFieldByName($name, $value) { + return $this->_browser->setFieldByName($name, $value); } - /** - * Sets all form fields with that name. - * @param string/integer $id Id of field in forms. - * @param string $value New value of field. - * @return boolean True if field exists, otherwise false. - * @access public - */ + /** + * Sets all form fields with that name. + * @param string/integer $id Id of field in forms. + * @param string $value New value of field. + * @return boolean True if field exists, otherwise false. + * @access public + */ function setFieldById($id, $value) { return $this->_browser->setFieldById($id, $value); } - /** - * Confirms that the form element is currently set - * to the expected value. A missing form will always - * fail. If no value is given then only the existence - * of the field is checked. - * @param string $name Name of field in forms. - * @param mixed $expected Expected string/array value or - * false for unset fields. - * @param string $message Message to display. Default - * can be embedded with %s. - * @return boolean True if pass. - * @access public - */ - function assertField($name, $expected = true, $message = "%s") { - $value = $this->_browser->getField($name); + /** + * Confirms that the form element is currently set + * to the expected value. A missing form will always + * fail. If no value is given then only the existence + * of the field is checked. + * @param string $name Name of field in forms. + * @param mixed $expected Expected string/array value or + * false for unset fields. + * @param string $message Message to display. Default + * can be embedded with %s. + * @return boolean True if pass. + * @access public + */ + function assertField($label, $expected = true, $message = "%s") { + $value = $this->_browser->getField($label); if ($expected === true) { return $this->assertTrue( isset($value), - sprintf($message, "Field [$name] should exist")); + sprintf($message, "Field [$label] should exist")); } else { - return $this->assertExpectation( + return $this->assert( new FieldExpectation($expected), $value, - sprintf($message, "Field [$name] should match with [%s]")); + sprintf($message, "Field [$label] should match with [%s]")); + } + } + + /** + * Confirms that the form element is currently set + * to the expected value. A missing form element will always + * fail. If no value is given then only the existence + * of the field is checked. + * @param string $name Name of field in forms. + * @param mixed $expected Expected string/array value or + * false for unset fields. + * @param string $message Message to display. Default + * can be embedded with %s. + * @return boolean True if pass. + * @access public + */ + function assertFieldByName($name, $expected = true, $message = "%s") { + $value = $this->_browser->getFieldByName($name); + if ($expected === true) { + return $this->assertTrue( + isset($value), + sprintf($message, "Field name [$name] should exist")); + } else { + return $this->assert( + new FieldExpectation($expected), + $value, + sprintf($message, "Field name [$name] should match with [%s]")); } } - /** - * Confirms that the form element is currently set - * to the expected value. A missing form will always - * fail. If no ID is given then only the existence - * of the field is checked. - * @param string/integer $id Name of field in forms. - * @param mixed $expected Expected string/array value or - * false for unset fields. - * @param string $message Message to display. Default - * can be embedded with %s. - * @return boolean True if pass. - * @access public - */ + /** + * Confirms that the form element is currently set + * to the expected value. A missing form will always + * fail. If no ID is given then only the existence + * of the field is checked. + * @param string/integer $id Name of field in forms. + * @param mixed $expected Expected string/array value or + * false for unset fields. + * @param string $message Message to display. Default + * can be embedded with %s. + * @return boolean True if pass. + * @access public + */ function assertFieldById($id, $expected = true, $message = "%s") { $value = $this->_browser->getFieldById($id); if ($expected === true) { @@ -1075,22 +1161,22 @@ isset($value), sprintf($message, "Field of ID [$id] should exist")); } else { - return $this->assertExpectation( + return $this->assert( new FieldExpectation($expected), $value, sprintf($message, "Field of ID [$id] should match with [%s]")); } } - /** - * Checks the response code against a list - * of possible values. - * @param array $responses Possible responses for a pass. - * @param string $message Message to display. Default - * can be embedded with %s. - * @return boolean True if pass. - * @access public - */ + /** + * Checks the response code against a list + * of possible values. + * @param array $responses Possible responses for a pass. + * @param string $message Message to display. Default + * can be embedded with %s. + * @return boolean True if pass. + * @access public + */ function assertResponse($responses, $message = '%s') { $responses = (is_array($responses) ? $responses : array($responses)); $code = $this->_browser->getResponseCode(); @@ -1099,14 +1185,14 @@ return $this->assertTrue(in_array($code, $responses), $message); } - /** - * Checks the mime type against a list - * of possible values. - * @param array $types Possible mime types for a pass. - * @param string $message Message to display. - * @return boolean True if pass. - * @access public - */ + /** + * Checks the mime type against a list + * of possible values. + * @param array $types Possible mime types for a pass. + * @param string $message Message to display. + * @return boolean True if pass. + * @access public + */ function assertMime($types, $message = '%s') { $types = (is_array($types) ? $types : array($types)); $type = $this->_browser->getMimeType(); @@ -1115,14 +1201,14 @@ return $this->assertTrue(in_array($type, $types), $message); } - /** - * Attempt to match the authentication type within - * the security realm we are currently matching. - * @param string $authentication Usually basic. - * @param string $message Message to display. - * @return boolean True if pass. - * @access public - */ + /** + * Attempt to match the authentication type within + * the security realm we are currently matching. + * @param string $authentication Usually basic. + * @param string $message Message to display. + * @return boolean True if pass. + * @access public + */ function assertAuthentication($authentication = false, $message = '%s') { if (! $authentication) { $message = sprintf($message, "Expected any authentication type, got [" . @@ -1139,26 +1225,26 @@ } } - /** - * Checks that no authentication is necessary to view - * the desired page. - * @param string $message Message to display. - * @return boolean True if pass. - * @access public - */ + /** + * Checks that no authentication is necessary to view + * the desired page. + * @param string $message Message to display. + * @return boolean True if pass. + * @access public + */ function assertNoAuthentication($message = '%s') { $message = sprintf($message, "Expected no authentication type, got [" . $this->_browser->getAuthentication() . "]"); return $this->assertFalse($this->_browser->getAuthentication(), $message); } - /** - * Attempts to match the current security realm. - * @param string $realm Name of security realm. - * @param string $message Message to display. - * @return boolean True if pass. - * @access public - */ + /** + * Attempts to match the current security realm. + * @param string $realm Name of security realm. + * @param string $message Message to display. + * @return boolean True if pass. + * @access public + */ function assertRealm($realm, $message = '%s') { $message = sprintf($message, "Expected realm [$realm] got [" . $this->_browser->getRealm() . "]"); @@ -1167,60 +1253,60 @@ $message); } - /** - * Checks each header line for the required value. If no - * value is given then only an existence check is made. - * @param string $header Case insensitive header name. - * @param string $value Case sensitive trimmed string to - * match against. - * @return boolean True if pass. - * @access public - */ + /** + * Checks each header line for the required value. If no + * value is given then only an existence check is made. + * @param string $header Case insensitive header name. + * @param string $value Case sensitive trimmed string to + * match against. + * @return boolean True if pass. + * @access public + */ function assertHeader($header, $value = false, $message = '%s') { - return $this->assertExpectation( + return $this->assert( new HttpHeaderExpectation($header, $value), $this->_browser->getHeaders(), $message); } - /** - * Checks each header line for the required pattern. - * @param string $header Case insensitive header name. - * @param string $pattern Pattern to match value against. - * @return boolean True if pass. - * @access public - */ + /** + * Checks each header line for the required pattern. + * @param string $header Case insensitive header name. + * @param string $pattern Pattern to match value against. + * @return boolean True if pass. + * @access public + */ function assertHeaderPattern($header, $pattern, $message = '%s') { - return $this->assertExpectation( + return $this->assert( new HttpHeaderPatternExpectation($header, $pattern), $this->_browser->getHeaders(), $message); } - /** - * Confirms that the header type has not been received. - * Only the landing page is checked. If you want to check - * redirect pages, then you should limit redirects so - * as to capture the page you want. - * @param string $header Case insensitive header name. - * @return boolean True if pass. - * @access public - */ + /** + * Confirms that the header type has not been received. + * Only the landing page is checked. If you want to check + * redirect pages, then you should limit redirects so + * as to capture the page you want. + * @param string $header Case insensitive header name. + * @return boolean True if pass. + * @access public + */ function assertNoUnwantedHeader($header, $message = '%s') { - return $this->assertExpectation( + return $this->assert( new HttpUnwantedHeaderExpectation($header), $this->_browser->getHeaders(), $message); } - /** - * Tests the text between the title tags. - * @param string $title Expected title or empty - * if expecting no title. - * @param string $message Message to display. - * @return boolean True if pass. - * @access public - */ + /** + * Tests the text between the title tags. + * @param string $title Expected title or empty + * if expecting no title. + * @param string $message Message to display. + * @return boolean True if pass. + * @access public + */ function assertTitle($title = false, $message = '%s') { return $this->assertTrue( $title === $this->_browser->getTitle(), @@ -1228,78 +1314,92 @@ $this->_browser->getTitle() . "]")); } - /** - * Will trigger a pass if the text is found in the plain - * text form of the page. - * @param string $text Text to look for. - * @param string $message Message to display. - * @return boolean True if pass. - * @access public - */ + /** + * Will trigger a pass if the text is found in the plain + * text form of the page. + * @param string $text Text to look for. + * @param string $message Message to display. + * @return boolean True if pass. + * @access public + */ function assertWantedText($text, $message = '%s') { - return $this->assertExpectation( + return $this->assert( new WantedTextExpectation($text), $this->_browser->getContentAsText(), $message); } - /** - * Will trigger a pass if the text is not found in the plain - * text form of the page. - * @param string $text Text to look for. - * @param string $message Message to display. - * @return boolean True if pass. - * @access public - */ + /** + * Will trigger a pass if the text is not found in the plain + * text form of the page. + * @param string $text Text to look for. + * @param string $message Message to display. + * @return boolean True if pass. + * @access public + */ function assertNoUnwantedText($text, $message = '%s') { - return $this->assertExpectation( + return $this->assert( new UnwantedTextExpectation($text), $this->_browser->getContentAsText(), $message); } - /** - * Will trigger a pass if the Perl regex pattern - * is found in the raw content. - * @param string $pattern Perl regex to look for including - * the regex delimiters. - * @param string $message Message to display. - * @return boolean True if pass. - * @access public - */ + /** + * Will trigger a pass if the Perl regex pattern + * is found in the raw content. + * @param string $pattern Perl regex to look for including + * the regex delimiters. + * @param string $message Message to display. + * @return boolean True if pass. + * @access public + */ + function assertPattern($pattern, $message = '%s') { + return $this->assert( + new PatternExpectation($pattern), + $this->_browser->getContent(), + $message); + } + + /** + * @deprecated + */ function assertWantedPattern($pattern, $message = '%s') { - return $this->assertExpectation( - new WantedPatternExpectation($pattern), + return $this->assertPattern($pattern, $message); + } + + /** + * Will trigger a pass if the perl regex pattern + * is not present in raw content. + * @param string $pattern Perl regex to look for including + * the regex delimiters. + * @param string $message Message to display. + * @return boolean True if pass. + * @access public + */ + function assertNoPattern($pattern, $message = '%s') { + return $this->assert( + new NoPatternExpectation($pattern), $this->_browser->getContent(), $message); } - /** - * Will trigger a pass if the perl regex pattern - * is not present in raw content. - * @param string $pattern Perl regex to look for including - * the regex delimiters. - * @param string $message Message to display. - * @return boolean True if pass. - * @access public - */ + /** + * @deprecated + */ function assertNoUnwantedPattern($pattern, $message = '%s') { - return $this->assertExpectation( - new UnwantedPatternExpectation($pattern), - $this->_browser->getContent(), - $message); + return $this->assertNoPattern($pattern, $message); } - /** - * Checks that a cookie is set for the current page - * and optionally checks the value. - * @param string $name Name of cookie to test. - * @param string $expected Expected value as a string or - * false if any value will do. - * @param string $message Message to display. - * @return boolean True if pass. - * @access public - */ + /** + * Checks that a cookie is set for the current page + * and optionally checks the value. + * @param string $name Name of cookie to test. + * @param string $expected Expected value as a string or + * false if any value will do. + * @param string $message Message to display. + * @return boolean True if pass. + * @access public + */ function assertCookie($name, $expected = false, $message = '%s') { $value = $this->getCookie($name); if ($expected) { @@ -1313,14 +1413,14 @@ } } - /** - * Checks that no cookie is present or that it has - * been successfully cleared. - * @param string $name Name of cookie to test. - * @param string $message Message to display. - * @return boolean True if pass. - * @access public - */ + /** + * Checks that no cookie is present or that it has + * been successfully cleared. + * @param string $name Name of cookie to test. + * @param string $message Message to display. + * @return boolean True if pass. + * @access public + */ function assertNoCookie($name, $message = '%s') { return $this->assertTrue( $this->getCookie($name) === false, diff --git a/vendors/simpletest/xml.php b/vendors/simpletest/xml.php index d160b8893..c4ab5cd5d 100644 --- a/vendors/simpletest/xml.php +++ b/vendors/simpletest/xml.php @@ -1,57 +1,57 @@ SimpleReporter(); $this->_namespace = ($namespace ? $namespace . ':' : ''); $this->_indent = $indent; } - /** - * Calculates the pretty printing indent level - * from the current level of nesting. - * @param integer $offset Extra indenting level. - * @return string Leading space. - * @access protected - */ + /** + * Calculates the pretty printing indent level + * from the current level of nesting. + * @param integer $offset Extra indenting level. + * @return string Leading space. + * @access protected + */ function _getIndent($offset = 0) { return str_repeat( $this->_indent, count($this->getTestList()) + $offset); } - /** - * Converts character string to parsed XML - * entities string. - * @param string text Unparsed character data. - * @return string Parsed character data. - * @access public - */ + /** + * Converts character string to parsed XML + * entities string. + * @param string text Unparsed character data. + * @return string Parsed character data. + * @access public + */ function toParsedXml($text) { return str_replace( array('&', '<', '>', '"', '\''), @@ -59,12 +59,12 @@ $text); } - /** - * Paints the start of a group test. - * @param string $test_name Name of test that is starting. - * @param integer $size Number of test cases starting. - * @access public - */ + /** + * Paints the start of a group test. + * @param string $test_name Name of test that is starting. + * @param integer $size Number of test cases starting. + * @access public + */ function paintGroupStart($test_name, $size) { parent::paintGroupStart($test_name, $size); print $this->_getIndent(); @@ -75,22 +75,22 @@ "_namespace . "name>\n"; } - /** - * Paints the end of a group test. - * @param string $test_name Name of test that is ending. - * @access public - */ + /** + * Paints the end of a group test. + * @param string $test_name Name of test that is ending. + * @access public + */ function paintGroupEnd($test_name) { print $this->_getIndent(); print "_namespace . "group>\n"; parent::paintGroupEnd($test_name); } - /** - * Paints the start of a test case. - * @param string $test_name Name of test that is starting. - * @access public - */ + /** + * Paints the start of a test case. + * @param string $test_name Name of test that is starting. + * @access public + */ function paintCaseStart($test_name) { parent::paintCaseStart($test_name); print $this->_getIndent(); @@ -101,22 +101,22 @@ "_namespace . "name>\n"; } - /** - * Paints the end of a test case. - * @param string $test_name Name of test that is ending. - * @access public - */ + /** + * Paints the end of a test case. + * @param string $test_name Name of test that is ending. + * @access public + */ function paintCaseEnd($test_name) { print $this->_getIndent(); print "_namespace . "case>\n"; parent::paintCaseEnd($test_name); } - /** - * Paints the start of a test method. - * @param string $test_name Name of test that is starting. - * @access public - */ + /** + * Paints the start of a test method. + * @param string $test_name Name of test that is starting. + * @access public + */ function paintMethodStart($test_name) { parent::paintMethodStart($test_name); print $this->_getIndent(); @@ -127,23 +127,23 @@ "_namespace . "name>\n"; } - /** - * Paints the end of a test method. - * @param string $test_name Name of test that is ending. - * @param integer $progress Number of test cases ending. - * @access public - */ + /** + * Paints the end of a test method. + * @param string $test_name Name of test that is ending. + * @param integer $progress Number of test cases ending. + * @access public + */ function paintMethodEnd($test_name) { print $this->_getIndent(); print "_namespace . "test>\n"; parent::paintMethodEnd($test_name); } - /** - * Increments the pass count. - * @param string $message Message is ignored. - * @access public - */ + /** + * Increments the pass count. + * @param string $message Message is ignored. + * @access public + */ function paintPass($message) { parent::paintPass($message); print $this->_getIndent(1); @@ -152,11 +152,11 @@ print "_namespace . "pass>\n"; } - /** - * Increments the fail count. - * @param string $message Message is ignored. - * @access public - */ + /** + * Increments the fail count. + * @param string $message Message is ignored. + * @access public + */ function paintFail($message) { parent::paintFail($message); print $this->_getIndent(1); @@ -165,12 +165,12 @@ print "_namespace . "fail>\n"; } - /** - * Paints a PHP error or exception. - * @param string $message Message is ignored. - * @access public - * @abstract - */ + /** + * Paints a PHP error or exception. + * @param string $message Message is ignored. + * @access public + * @abstract + */ function paintException($message) { parent::paintException($message); print $this->_getIndent(1); @@ -179,11 +179,11 @@ print "_namespace . "exception>\n"; } - /** - * Paints a simple supplementary message. - * @param string $message Text to display. - * @access public - */ + /** + * Paints a simple supplementary message. + * @param string $message Text to display. + * @access public + */ function paintMessage($message) { parent::paintMessage($message); print $this->_getIndent(1); @@ -192,12 +192,12 @@ print "_namespace . "message>\n"; } - /** - * Paints a formatted ASCII message such as a - * variable dump. - * @param string $message Text to display. - * @access public - */ + /** + * Paints a formatted ASCII message such as a + * variable dump. + * @param string $message Text to display. + * @access public + */ function paintFormattedMessage($message) { parent::paintFormattedMessage($message); print $this->_getIndent(1); @@ -206,12 +206,12 @@ print "_namespace . "formatted>\n"; } - /** - * Serialises the event object. - * @param string $type Event type as text. - * @param mixed $payload Message or object. - * @access public - */ + /** + * Serialises the event object. + * @param string $type Event type as text. + * @param mixed $payload Message or object. + * @access public + */ function paintSignal($type, &$payload) { parent::paintSignal($type, $payload); print $this->_getIndent(1); @@ -220,13 +220,13 @@ print "_namespace . "signal>\n"; } - /** - * Paints the test document header. - * @param string $test_name First test top level - * to start. - * @access public - * @abstract - */ + /** + * Paints the test document header. + * @param string $test_name First test top level + * to start. + * @access public + * @abstract + */ function paintHeader($test_name) { if (! SimpleReporter::inCli()) { header('Content-type: text/xml'); @@ -240,191 +240,191 @@ print "<" . $this->_namespace . "run>\n"; } - /** - * Paints the test document footer. - * @param string $test_name The top level test. - * @access public - * @abstract - */ + /** + * Paints the test document footer. + * @param string $test_name The top level test. + * @access public + * @abstract + */ function paintFooter($test_name) { print "_namespace . "run>\n"; } } - /** - * Accumulator for incoming tag. Holds the - * incoming test structure information for - * later dispatch to the reporter. - * @package SimpleTest - * @subpackage UnitTester - */ + /** + * Accumulator for incoming tag. Holds the + * incoming test structure information for + * later dispatch to the reporter. + * @package SimpleTest + * @subpackage UnitTester + */ class NestingXmlTag { var $_name; var $_attributes; - /** - * Sets the basic test information except - * the name. - * @param hash $attributes Name value pairs. - * @access public - */ + /** + * Sets the basic test information except + * the name. + * @param hash $attributes Name value pairs. + * @access public + */ function NestingXmlTag($attributes) { $this->_name = false; $this->_attributes = $attributes; } - /** - * Sets the test case/method name. - * @param string $name Name of test. - * @access public - */ + /** + * Sets the test case/method name. + * @param string $name Name of test. + * @access public + */ function setName($name) { $this->_name = $name; } - /** - * Accessor for name. - * @return string Name of test. - * @access public - */ + /** + * Accessor for name. + * @return string Name of test. + * @access public + */ function getName() { return $this->_name; } - /** - * Accessor for attributes. - * @return hash All attributes. - * @access protected - */ + /** + * Accessor for attributes. + * @return hash All attributes. + * @access protected + */ function _getAttributes() { return $this->_attributes; } } - /** - * Accumulator for incoming method tag. Holds the - * incoming test structure information for - * later dispatch to the reporter. - * @package SimpleTest - * @subpackage UnitTester - */ + /** + * Accumulator for incoming method tag. Holds the + * incoming test structure information for + * later dispatch to the reporter. + * @package SimpleTest + * @subpackage UnitTester + */ class NestingMethodTag extends NestingXmlTag { - /** - * Sets the basic test information except - * the name. - * @param hash $attributes Name value pairs. - * @access public - */ + /** + * Sets the basic test information except + * the name. + * @param hash $attributes Name value pairs. + * @access public + */ function NestingMethodTag($attributes) { $this->NestingXmlTag($attributes); } - /** - * Signals the appropriate start event on the - * listener. - * @param SimpleReporter $listener Target for events. - * @access public - */ + /** + * Signals the appropriate start event on the + * listener. + * @param SimpleReporter $listener Target for events. + * @access public + */ function paintStart(&$listener) { $listener->paintMethodStart($this->getName()); } - /** - * Signals the appropriate end event on the - * listener. - * @param SimpleReporter $listener Target for events. - * @access public - */ + /** + * Signals the appropriate end event on the + * listener. + * @param SimpleReporter $listener Target for events. + * @access public + */ function paintEnd(&$listener) { $listener->paintMethodEnd($this->getName()); } } - /** - * Accumulator for incoming case tag. Holds the - * incoming test structure information for - * later dispatch to the reporter. - * @package SimpleTest - * @subpackage UnitTester - */ + /** + * Accumulator for incoming case tag. Holds the + * incoming test structure information for + * later dispatch to the reporter. + * @package SimpleTest + * @subpackage UnitTester + */ class NestingCaseTag extends NestingXmlTag { - /** - * Sets the basic test information except - * the name. - * @param hash $attributes Name value pairs. - * @access public - */ + /** + * Sets the basic test information except + * the name. + * @param hash $attributes Name value pairs. + * @access public + */ function NestingCaseTag($attributes) { $this->NestingXmlTag($attributes); } - /** - * Signals the appropriate start event on the - * listener. - * @param SimpleReporter $listener Target for events. - * @access public - */ + /** + * Signals the appropriate start event on the + * listener. + * @param SimpleReporter $listener Target for events. + * @access public + */ function paintStart(&$listener) { $listener->paintCaseStart($this->getName()); } - /** - * Signals the appropriate end event on the - * listener. - * @param SimpleReporter $listener Target for events. - * @access public - */ + /** + * Signals the appropriate end event on the + * listener. + * @param SimpleReporter $listener Target for events. + * @access public + */ function paintEnd(&$listener) { $listener->paintCaseEnd($this->getName()); } } - /** - * Accumulator for incoming group tag. Holds the - * incoming test structure information for - * later dispatch to the reporter. - * @package SimpleTest - * @subpackage UnitTester - */ + /** + * Accumulator for incoming group tag. Holds the + * incoming test structure information for + * later dispatch to the reporter. + * @package SimpleTest + * @subpackage UnitTester + */ class NestingGroupTag extends NestingXmlTag { - /** - * Sets the basic test information except - * the name. - * @param hash $attributes Name value pairs. - * @access public - */ + /** + * Sets the basic test information except + * the name. + * @param hash $attributes Name value pairs. + * @access public + */ function NestingGroupTag($attributes) { $this->NestingXmlTag($attributes); } - /** - * Signals the appropriate start event on the - * listener. - * @param SimpleReporter $listener Target for events. - * @access public - */ + /** + * Signals the appropriate start event on the + * listener. + * @param SimpleReporter $listener Target for events. + * @access public + */ function paintStart(&$listener) { $listener->paintGroupStart($this->getName(), $this->getSize()); } - /** - * Signals the appropriate end event on the - * listener. - * @param SimpleReporter $listener Target for events. - * @access public - */ + /** + * Signals the appropriate end event on the + * listener. + * @param SimpleReporter $listener Target for events. + * @access public + */ function paintEnd(&$listener) { $listener->paintGroupEnd($this->getName()); } - /** - * The size in the attributes. - * @return integer Value of size attribute or zero. - * @access public - */ + /** + * The size in the attributes. + * @return integer Value of size attribute or zero. + * @access public + */ function getSize() { $attributes = $this->_getAttributes(); if (isset($attributes['SIZE'])) { @@ -434,12 +434,12 @@ } } - /** - * Parser for importing the output of the XmlReporter. - * Dispatches that output to another reporter. - * @package SimpleTest - * @subpackage UnitTester - */ + /** + * Parser for importing the output of the XmlReporter. + * Dispatches that output to another reporter. + * @package SimpleTest + * @subpackage UnitTester + */ class SimpleTestXmlParser { var $_listener; var $_expat; @@ -448,12 +448,12 @@ var $_content; var $_attributes; - /** - * Loads a listener with the SimpleReporter - * interface. - * @param SimpleReporter $listener Listener of tag events. - * @access public - */ + /** + * Loads a listener with the SimpleReporter + * interface. + * @param SimpleReporter $listener Listener of tag events. + * @access public + */ function SimpleTestXmlParser(&$listener) { $this->_listener = &$listener; $this->_expat = &$this->_createParser(); @@ -463,13 +463,13 @@ $this->_attributes = array(); } - /** - * Parses a block of XML sending the results to - * the listener. - * @param string $chunk Block of text to read. - * @return boolean True if valid XML. - * @access public - */ + /** + * Parses a block of XML sending the results to + * the listener. + * @param string $chunk Block of text to read. + * @return boolean True if valid XML. + * @access public + */ function parse($chunk) { if (! xml_parse($this->_expat, $chunk)) { trigger_error('XML parse error with ' . @@ -479,11 +479,11 @@ return true; } - /** - * Sets up expat as the XML parser. - * @return resource Expat handle. - * @access protected - */ + /** + * Sets up expat as the XML parser. + * @return resource Expat handle. + * @access protected + */ function &_createParser() { $expat = xml_parser_create(); xml_set_object($expat, $this); @@ -493,57 +493,56 @@ return $expat; } - /** - * Opens a new test nesting level. - * @return NestedXmlTag The group, case or method tag - * to start. - * @access private - */ + /** + * Opens a new test nesting level. + * @return NestedXmlTag The group, case or method tag + * to start. + * @access private + */ function _pushNestingTag($nested) { array_unshift($this->_tag_stack, $nested); } - /** - * Accessor for current test structure tag. - * @return NestedXmlTag The group, case or method tag - * being parsed. - * @access private - */ + /** + * Accessor for current test structure tag. + * @return NestedXmlTag The group, case or method tag + * being parsed. + * @access private + */ function &_getCurrentNestingTag() { return $this->_tag_stack[0]; } - /** - * Ends a nesting tag. - * @return NestedXmlTag The group, case or method tag - * just finished. - * @access private - */ + /** + * Ends a nesting tag. + * @return NestedXmlTag The group, case or method tag + * just finished. + * @access private + */ function _popNestingTag() { return array_shift($this->_tag_stack); } - /** - * Test if tag is a leaf node with only text content. - * @param string $tag XML tag name. - * @return @boolean True if leaf, false if nesting. - * @private - */ + /** + * Test if tag is a leaf node with only text content. + * @param string $tag XML tag name. + * @return @boolean True if leaf, false if nesting. + * @private + */ function _isLeaf($tag) { - return in_array( - $tag, - array('NAME', 'PASS', 'FAIL', 'EXCEPTION', 'MESSAGE', 'FORMATTED', 'SIGNAL')); + return in_array($tag, array( + 'NAME', 'PASS', 'FAIL', 'EXCEPTION', 'MESSAGE', 'FORMATTED', 'SIGNAL')); } - /** - * Handler for start of event element. - * @param resource $expat Parser handle. - * @param string $tag Element name. - * @param hash $attributes Name value pairs. - * Attributes without content - * are marked as true. - * @access protected - */ + /** + * Handler for start of event element. + * @param resource $expat Parser handle. + * @param string $tag Element name. + * @param hash $attributes Name value pairs. + * Attributes without content + * are marked as true. + * @access protected + */ function _startElement($expat, $tag, $attributes) { $this->_attributes = $attributes; if ($tag == 'GROUP') { @@ -558,12 +557,12 @@ } } - /** - * End of element event. - * @param resource $expat Parser handle. - * @param string $tag Element name. - * @access protected - */ + /** + * End of element event. + * @param resource $expat Parser handle. + * @param string $tag Element name. + * @access protected + */ function _endElement($expat, $tag) { $this->_in_content_tag = false; if (in_array($tag, array('GROUP', 'CASE', 'TEST'))) { @@ -590,12 +589,12 @@ } } - /** - * Content between start and end elements. - * @param resource $expat Parser handle. - * @param string $text Usually output messages. - * @access protected - */ + /** + * Content between start and end elements. + * @param resource $expat Parser handle. + * @param string $text Usually output messages. + * @access protected + */ function _addContent($expat, $text) { if ($this->_in_content_tag) { $this->_content .= $text; @@ -603,12 +602,12 @@ return true; } - /** - * XML and Doctype handler. Discards all such content. - * @param resource $expat Parser handle. - * @param string $default Text of default content. - * @access protected - */ + /** + * XML and Doctype handler. Discards all such content. + * @param resource $expat Parser handle. + * @param string $default Text of default content. + * @access protected + */ function _default($expat, $default) { } }