[limb-svn] r5999 - in 3.x/trunk/limb/tests_runner/lib/simpletest: . extensions extensions/dom_tester extensions/selenium ui ui/recorder
svn at limb-project.com
svn at limb-project.com
Mon Jun 18 17:13:08 MSD 2007
Author: pachanga
Date: 2007-06-18 17:13:08 +0400 (Mon, 18 Jun 2007)
New Revision: 5999
URL: http://fisheye.limb-project.com/changelog/limb/?cs=5999
Added:
3.x/trunk/limb/tests_runner/lib/simpletest/autorun.php
3.x/trunk/limb/tests_runner/lib/simpletest/default_reporter.php
3.x/trunk/limb/tests_runner/lib/simpletest/extensions/dom_tester.php
3.x/trunk/limb/tests_runner/lib/simpletest/extensions/dom_tester/
3.x/trunk/limb/tests_runner/lib/simpletest/extensions/dom_tester/css_selector.php
3.x/trunk/limb/tests_runner/lib/simpletest/extensions/dom_tester/dom_tester.html
3.x/trunk/limb/tests_runner/lib/simpletest/extensions/dom_tester/dom_tester_child_adjacent.html
3.x/trunk/limb/tests_runner/lib/simpletest/extensions/dom_tester/dom_tester_doc_test.php
3.x/trunk/limb/tests_runner/lib/simpletest/extensions/dom_tester/dom_tester_test.php
3.x/trunk/limb/tests_runner/lib/simpletest/extensions/selenese_tester.php
3.x/trunk/limb/tests_runner/lib/simpletest/extensions/selenium.php
3.x/trunk/limb/tests_runner/lib/simpletest/extensions/selenium/
3.x/trunk/limb/tests_runner/lib/simpletest/extensions/selenium/remote-control.php
3.x/trunk/limb/tests_runner/lib/simpletest/extensions/selenium/remote-control_test.php
3.x/trunk/limb/tests_runner/lib/simpletest/extensions/testdox.php
3.x/trunk/limb/tests_runner/lib/simpletest/ui/recorder.php
3.x/trunk/limb/tests_runner/lib/simpletest/ui/recorder/
3.x/trunk/limb/tests_runner/lib/simpletest/ui/recorder/sample_test.php
3.x/trunk/limb/tests_runner/lib/simpletest/ui/recorder/test.php
Modified:
3.x/trunk/limb/tests_runner/lib/simpletest/TODO
3.x/trunk/limb/tests_runner/lib/simpletest/authentication.php
3.x/trunk/limb/tests_runner/lib/simpletest/browser.php
3.x/trunk/limb/tests_runner/lib/simpletest/collector.php
3.x/trunk/limb/tests_runner/lib/simpletest/compatibility.php
3.x/trunk/limb/tests_runner/lib/simpletest/cookies.php
3.x/trunk/limb/tests_runner/lib/simpletest/detached.php
3.x/trunk/limb/tests_runner/lib/simpletest/dumper.php
3.x/trunk/limb/tests_runner/lib/simpletest/eclipse.php
3.x/trunk/limb/tests_runner/lib/simpletest/encoding.php
3.x/trunk/limb/tests_runner/lib/simpletest/errors.php
3.x/trunk/limb/tests_runner/lib/simpletest/exceptions.php
3.x/trunk/limb/tests_runner/lib/simpletest/expectation.php
3.x/trunk/limb/tests_runner/lib/simpletest/extensions/pear_test_case.php
3.x/trunk/limb/tests_runner/lib/simpletest/extensions/phpunit_test_case.php
3.x/trunk/limb/tests_runner/lib/simpletest/form.php
3.x/trunk/limb/tests_runner/lib/simpletest/frames.php
3.x/trunk/limb/tests_runner/lib/simpletest/http.php
3.x/trunk/limb/tests_runner/lib/simpletest/invoker.php
3.x/trunk/limb/tests_runner/lib/simpletest/mock_objects.php
3.x/trunk/limb/tests_runner/lib/simpletest/page.php
3.x/trunk/limb/tests_runner/lib/simpletest/parser.php
3.x/trunk/limb/tests_runner/lib/simpletest/reflection_php4.php
3.x/trunk/limb/tests_runner/lib/simpletest/reflection_php5.php
3.x/trunk/limb/tests_runner/lib/simpletest/remote.php
3.x/trunk/limb/tests_runner/lib/simpletest/reporter.php
3.x/trunk/limb/tests_runner/lib/simpletest/scorer.php
3.x/trunk/limb/tests_runner/lib/simpletest/selector.php
3.x/trunk/limb/tests_runner/lib/simpletest/shell_tester.php
3.x/trunk/limb/tests_runner/lib/simpletest/simpletest.php
3.x/trunk/limb/tests_runner/lib/simpletest/socket.php
3.x/trunk/limb/tests_runner/lib/simpletest/tag.php
3.x/trunk/limb/tests_runner/lib/simpletest/test_case.php
3.x/trunk/limb/tests_runner/lib/simpletest/ui/array_reporter.php
3.x/trunk/limb/tests_runner/lib/simpletest/ui/colortext_reporter.php
3.x/trunk/limb/tests_runner/lib/simpletest/ui/webunit_reporter.php
3.x/trunk/limb/tests_runner/lib/simpletest/unit_tester.php
3.x/trunk/limb/tests_runner/lib/simpletest/url.php
3.x/trunk/limb/tests_runner/lib/simpletest/user_agent.php
3.x/trunk/limb/tests_runner/lib/simpletest/web_tester.php
3.x/trunk/limb/tests_runner/lib/simpletest/xml.php
Log:
-- adding new version of SimpleTest from CVS(as of 18/06/2006 13:20 GMT)
Modified: 3.x/trunk/limb/tests_runner/lib/simpletest/TODO
===================================================================
--- 3.x/trunk/limb/tests_runner/lib/simpletest/TODO 2007-06-18 12:28:49 UTC (rev 5998)
+++ 3.x/trunk/limb/tests_runner/lib/simpletest/TODO 2007-06-18 13:13:08 UTC (rev 5999)
@@ -1,11 +1,11 @@
TODO
This is immediate stuff only for this iteration (1.0.1beta2) of 15 hours.
-$Id: TODO,v 1.508 2007/01/16 23:35:21 lastcraft Exp $
+$Id: TODO,v 1.509 2007/03/08 00:57:43 lastcraft Exp $
Unit tester
-----------
-Fix errors_test.php in PHP 5.2+ (2).
+Fix errors_test.php in PHP 5.2+ (1/2).
Reporter
--------
@@ -13,7 +13,7 @@
Mock objects
------------
-Mocks should inherit mocked class (9/4).
+Mocks should inherit mocked class (12/4).
Parser
------
Modified: 3.x/trunk/limb/tests_runner/lib/simpletest/authentication.php
===================================================================
--- 3.x/trunk/limb/tests_runner/lib/simpletest/authentication.php 2007-06-18 12:28:49 UTC (rev 5998)
+++ 3.x/trunk/limb/tests_runner/lib/simpletest/authentication.php 2007-06-18 13:13:08 UTC (rev 5999)
@@ -1,7 +1,7 @@
<?php
/**
* Base include file for SimpleTest
- * @package tests_runner
+ * @package SimpleTest
* @subpackage WebTester
* @version $Id$
*/
@@ -12,7 +12,7 @@
/**
* Represents a single security realm's identity.
- * @package tests_runner
+ * @package SimpleTest
* @subpackage WebTester
*/
class SimpleRealm {
@@ -125,7 +125,7 @@
/**
* Manages security realms.
- * @package tests_runner
+ * @package SimpleTest
* @subpackage WebTester
*/
class SimpleAuthenticator {
Added: 3.x/trunk/limb/tests_runner/lib/simpletest/autorun.php
===================================================================
--- 3.x/trunk/limb/tests_runner/lib/simpletest/autorun.php (rev 0)
+++ 3.x/trunk/limb/tests_runner/lib/simpletest/autorun.php 2007-06-18 13:13:08 UTC (rev 5999)
@@ -0,0 +1,64 @@
+<?php
+ /**
+ * Autorunner which runs all tests cases found in a file
+ * that includes this module.
+ * @package SimpleTest
+ * @version $Id: autorun.php,v 1.8 2007/05/08 22:08:06 lastcraft Exp $
+ */
+ require_once dirname(__FILE__) . '/unit_tester.php';
+ require_once dirname(__FILE__) . '/mock_objects.php';
+ require_once dirname(__FILE__) . '/collector.php';
+ require_once dirname(__FILE__) . '/default_reporter.php';
+
+ $GLOBALS['SIMPLETEST_AUTORUNNER_INITIAL_CLASSES'] = get_declared_classes();
+ register_shutdown_function('simpletest_autorun');
+
+ function simpletest_autorun() {
+ if (tests_have_run()) {
+ return;
+ }
+ $candidates = array_intersect(
+ capture_new_classes(),
+ classes_defined_in_initial_file());
+ $loader = new SimpleFileLoader();
+ $suite = $loader->createSuiteFromClasses(
+ basename(initial_file()),
+ $loader->selectRunnableTests($candidates));
+ $result = $suite->run(SimpleTest::preferred(
+ array('SimpleReporter', 'SimpleReporterDecorator')));
+ if (SimpleReporter::inCli()) {
+ exit($result ? 0 : 1);
+ }
+ }
+
+ function tests_have_run() {
+ if ($context = SimpleTest::getContext()) {
+ if ($context->getTest()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ function initial_file() {
+ static $file = false;
+ if (! $file) {
+ $file = reset(get_included_files());
+ }
+ return $file;
+ }
+
+ function classes_defined_in_initial_file() {
+ if (! preg_match_all('~class\s+(\w+)~', file_get_contents(initial_file()), $matches)) {
+ return array();
+ }
+ return array_map('strtolower', $matches[1]);
+ }
+
+ function capture_new_classes() {
+ global $SIMPLETEST_AUTORUNNER_INITIAL_CLASSES;
+ return array_map('strtolower', array_diff(get_declared_classes(),
+ $SIMPLETEST_AUTORUNNER_INITIAL_CLASSES ?
+ $SIMPLETEST_AUTORUNNER_INITIAL_CLASSES : array()));
+ }
+?>
\ No newline at end of file
Modified: 3.x/trunk/limb/tests_runner/lib/simpletest/browser.php
===================================================================
--- 3.x/trunk/limb/tests_runner/lib/simpletest/browser.php 2007-06-18 12:28:49 UTC (rev 5998)
+++ 3.x/trunk/limb/tests_runner/lib/simpletest/browser.php 2007-06-18 13:13:08 UTC (rev 5999)
@@ -1,7 +1,7 @@
<?php
/**
* Base include file for SimpleTest
- * @package tests_runner
+ * @package SimpleTest
* @subpackage WebTester
* @version $Id$
*/
@@ -24,7 +24,7 @@
/**
* Browser history list.
- * @package tests_runner
+ * @package SimpleTest
* @subpackage WebTester
*/
class SimpleBrowserHistory {
@@ -154,7 +154,7 @@
* Simulated web browser. This is an aggregate of
* the user agent, the HTML parsing, request history
* and the last header set.
- * @package tests_runner
+ * @package SimpleTest
* @subpackage WebTester
*/
class SimpleBrowser {
Modified: 3.x/trunk/limb/tests_runner/lib/simpletest/collector.php
===================================================================
--- 3.x/trunk/limb/tests_runner/lib/simpletest/collector.php 2007-06-18 12:28:49 UTC (rev 5998)
+++ 3.x/trunk/limb/tests_runner/lib/simpletest/collector.php 2007-06-18 13:13:08 UTC (rev 5999)
@@ -4,7 +4,7 @@
* {@link SimplePatternCollector}.
*
* @author Travis Swicegood <development at domain51.com>
- * @package tests_runner
+ * @package SimpleTest
* @subpackage UnitTester
* @version $Id$
*/
@@ -13,7 +13,7 @@
* The basic collector for {@link GroupTest}
*
* @see collect(), GroupTest::collect()
- * @package tests_runner
+ * @package SimpleTest
* @subpackage UnitTester
*/
class SimpleCollector {
@@ -43,6 +43,9 @@
$path = $this->_removeTrailingSlash($path);
if ($handle = opendir($path)) {
while (($entry = readdir($handle)) !== false) {
+ if ($this->_isHidden($entry)) {
+ continue;
+ }
$this->_handle($test, $path . DIRECTORY_SEPARATOR . $entry);
}
closedir($handle);
@@ -63,17 +66,29 @@
* @access protected
*/
function _handle(&$test, $file) {
- if (! is_dir($file)) {
- $test->addTestFile($file);
+ if (is_dir($file)) {
+ return;
}
+ $test->addTestFile($file);
}
+
+ /**
+ * Tests for hidden files so as to skip them. Currently
+ * only tests for Unix hidden files.
+ * @param string $filename Plain filename.
+ * @return boolean True if hidden file.
+ * @access private
+ */
+ function _isHidden($filename) {
+ return strncmp($filename, '.', 1) == 0;
+ }
}
/**
* An extension to {@link SimpleCollector} that only adds files matching a
* given pattern.
*
- * @package tests_runner
+ * @package SimpleTest
* @subpackage UnitTester
* @see SimpleCollector
*/
Modified: 3.x/trunk/limb/tests_runner/lib/simpletest/compatibility.php
===================================================================
--- 3.x/trunk/limb/tests_runner/lib/simpletest/compatibility.php 2007-06-18 12:28:49 UTC (rev 5998)
+++ 3.x/trunk/limb/tests_runner/lib/simpletest/compatibility.php 2007-06-18 13:13:08 UTC (rev 5999)
@@ -1,14 +1,14 @@
<?php
/**
* base include file for SimpleTest
- * @package tests_runner
+ * @package SimpleTest
* @version $Id$
*/
/**
* Static methods for compatibility between different
* PHP versions.
- * @package tests_runner
+ * @package SimpleTest
*/
class SimpleTestCompatibility {
Modified: 3.x/trunk/limb/tests_runner/lib/simpletest/cookies.php
===================================================================
--- 3.x/trunk/limb/tests_runner/lib/simpletest/cookies.php 2007-06-18 12:28:49 UTC (rev 5998)
+++ 3.x/trunk/limb/tests_runner/lib/simpletest/cookies.php 2007-06-18 13:13:08 UTC (rev 5999)
@@ -1,7 +1,7 @@
<?php
/**
* Base include file for SimpleTest
- * @package tests_runner
+ * @package SimpleTest
* @subpackage WebTester
* @version $Id$
*/
@@ -17,7 +17,7 @@
* arbitary stuff. I have used...
* http://wp.netscape.com/newsref/std/cookie_spec.html
* http://www.cookiecentral.com/faq/
- * @package tests_runner
+ * @package SimpleTest
* @subpackage WebTester
*/
class SimpleCookie {
@@ -222,7 +222,7 @@
/**
* Repository for cookies. This stuff is a
* tiny bit browser dependent.
- * @package tests_runner
+ * @package SimpleTest
* @subpackage WebTester
*/
class SimpleCookieJar {
Added: 3.x/trunk/limb/tests_runner/lib/simpletest/default_reporter.php
===================================================================
--- 3.x/trunk/limb/tests_runner/lib/simpletest/default_reporter.php (rev 0)
+++ 3.x/trunk/limb/tests_runner/lib/simpletest/default_reporter.php 2007-06-18 13:13:08 UTC (rev 5999)
@@ -0,0 +1,89 @@
+<?php
+ /**
+ * Optional include file for SimpleTest
+ * @package SimpleTest
+ * @subpackage UnitTester
+ * @version $Id: default_reporter.php,v 1.3 2007/05/28 18:27:37 lastcraft Exp $
+ */
+
+ /**#@+
+ * include other SimpleTest class files
+ */
+ require_once(dirname(__FILE__) . '/scorer.php');
+ require_once(dirname(__FILE__) . '/reporter.php');
+ require_once(dirname(__FILE__) . '/xml.php');
+ /**#@-*/
+
+ /**
+ * Parser for command line arguments. Extracts
+ * the a specific test to run and engages XML
+ * reporting when necessary.
+ * @package SimpleTest
+ * @subpackage UnitTester
+ */
+ class SimpleCommandLineParser {
+ var $_to_property = array(
+ 'case' => '_case', 'c' => '_case',
+ 'test' => '_test', 't' => '_test',
+ 'xml' => '_xml', 'x' => '_xml');
+ var $_case = '';
+ var $_test = '';
+ var $_xml = false;
+
+ function SimpleCommandLineParser($arguments) {
+ if (! is_array($arguments)) {
+ return;
+ }
+ foreach ($arguments as $i => $argument) {
+ if (preg_match('/^--?(test|case|t|c)=(.+)$/', $argument, $matches)) {
+ $property = $this->_to_property[$matches[1]];
+ $this->$property = $matches[2];
+ } elseif (preg_match('/^--?(test|case|t|c)$/', $argument, $matches)) {
+ $property = $this->_to_property[$matches[1]];
+ if (isset($arguments[$i + 1])) {
+ $this->$property = $arguments[$i + 1];
+ }
+ } elseif (preg_match('/^--?(xml|x)$/', $argument)) {
+ $this->_xml = true;
+ }
+ }
+ }
+
+ function getTest() {
+ return $this->_test;
+ }
+
+ function getTestCase() {
+ return $this->_case;
+ }
+
+ function isXml() {
+ return $this->_xml;
+ }
+ }
+
+ /**
+ * The default reporter used by SimpleTest's autorun
+ * feature.
+ * @package SimpleTest
+ * @subpackage UnitTester
+ */
+ class DefaultReporter extends SimpleReporterDecorator {
+
+ /**
+ * Assembles the appopriate reporter for the environment.
+ */
+ function DefaultReporter() {
+ if (SimpleReporter::inCli()) {
+ global $argv;
+ $parser = new SimpleCommandLineParser($argv);
+ $reporter_class = $parser->isXml() ? 'XmlReporter' : 'TextReporter';
+ $reporter = &new SelectiveReporter(
+ new $reporter_class(), $parser->getTestCase(), $parser->getTest());
+ } else {
+ $reporter = &new SelectiveReporter(new HtmlReporter(), @$_GET['c'], @$_GET['t']);
+ }
+ $this->SimpleReporterDecorator($reporter);
+ }
+ }
+?>
\ No newline at end of file
Modified: 3.x/trunk/limb/tests_runner/lib/simpletest/detached.php
===================================================================
--- 3.x/trunk/limb/tests_runner/lib/simpletest/detached.php 2007-06-18 12:28:49 UTC (rev 5998)
+++ 3.x/trunk/limb/tests_runner/lib/simpletest/detached.php 2007-06-18 13:13:08 UTC (rev 5999)
@@ -1,7 +1,7 @@
<?php
/**
* base include file for SimpleTest
- * @package tests_runner
+ * @package SimpleTest
* @subpackage UnitTester
* @version $Id$
*/
@@ -15,7 +15,7 @@
/**
* Runs an XML formated test in a separate process.
- * @package tests_runner
+ * @package SimpleTest
* @subpackage UnitTester
*/
class DetachedTestCase {
Modified: 3.x/trunk/limb/tests_runner/lib/simpletest/dumper.php
===================================================================
--- 3.x/trunk/limb/tests_runner/lib/simpletest/dumper.php 2007-06-18 12:28:49 UTC (rev 5998)
+++ 3.x/trunk/limb/tests_runner/lib/simpletest/dumper.php 2007-06-18 13:13:08 UTC (rev 5999)
@@ -1,7 +1,7 @@
<?php
/**
* base include file for SimpleTest
- * @package tests_runner
+ * @package SimpleTest
* @subpackage UnitTester
* @version $Id$
*/
@@ -14,7 +14,7 @@
/**
* Displays variables as text and does diffs.
- * @package tests_runner
+ * @package SimpleTest
* @subpackage UnitTester
*/
class SimpleDumper {
Modified: 3.x/trunk/limb/tests_runner/lib/simpletest/eclipse.php
===================================================================
--- 3.x/trunk/limb/tests_runner/lib/simpletest/eclipse.php 2007-06-18 12:28:49 UTC (rev 5998)
+++ 3.x/trunk/limb/tests_runner/lib/simpletest/eclipse.php 2007-06-18 13:13:08 UTC (rev 5999)
@@ -1,7 +1,7 @@
<?php
/**
* base include file for eclipse plugin
- * @package tests_runner
+ * @package SimpleTest
* @subpackage Eclipse
* @version $Id$
*/
@@ -17,7 +17,7 @@
/**
* base reported class for eclipse plugin
- * @package tests_runner
+ * @package SimpleTest
* @subpackage Eclipse
*/
class EclipseReporter extends SimpleScorer {
@@ -154,7 +154,7 @@
/**
* base invoker class for eclipse plugin
- * @package tests_runner
+ * @package SimpleTest
* @subpackage Eclipse
*/
class EclipseInvoker extends SimpleInvokerDecorator{
Modified: 3.x/trunk/limb/tests_runner/lib/simpletest/encoding.php
===================================================================
--- 3.x/trunk/limb/tests_runner/lib/simpletest/encoding.php 2007-06-18 12:28:49 UTC (rev 5998)
+++ 3.x/trunk/limb/tests_runner/lib/simpletest/encoding.php 2007-06-18 13:13:08 UTC (rev 5999)
@@ -1,7 +1,7 @@
<?php
/**
* base include file for SimpleTest
- * @package tests_runner
+ * @package SimpleTest
* @subpackage WebTester
* @version $Id$
*/
@@ -14,7 +14,7 @@
/**
* Single post parameter.
- * @package tests_runner
+ * @package SimpleTest
* @subpackage WebTester
*/
class SimpleEncodedPair {
@@ -83,7 +83,7 @@
/**
* Single post parameter.
- * @package tests_runner
+ * @package SimpleTest
* @subpackage WebTester
*/
class SimpleAttachment {
@@ -185,7 +185,7 @@
/**
* Bundle of GET/POST parameters. Can include
* repeated parameters.
- * @package tests_runner
+ * @package SimpleTest
* @subpackage WebTester
*/
class SimpleEncoding {
@@ -323,7 +323,7 @@
/**
* Bundle of GET parameters. Can include
* repeated parameters.
- * @package tests_runner
+ * @package SimpleTest
* @subpackage WebTester
*/
class SimpleGetEncoding extends SimpleEncoding {
@@ -378,7 +378,7 @@
/**
* Bundle of URL parameters for a HEAD request.
- * @package tests_runner
+ * @package SimpleTest
* @subpackage WebTester
*/
class SimpleHeadEncoding extends SimpleGetEncoding {
@@ -407,7 +407,7 @@
/**
* Bundle of POST parameters. Can include
* repeated parameters.
- * @package tests_runner
+ * @package SimpleTest
* @subpackage WebTester
*/
class SimplePostEncoding extends SimpleEncoding {
@@ -465,7 +465,7 @@
/**
* Bundle of POST parameters in the multipart
* format. Can include file uploads.
- * @package tests_runner
+ * @package SimpleTest
* @subpackage WebTester
*/
class SimpleMultipartEncoding extends SimplePostEncoding {
Modified: 3.x/trunk/limb/tests_runner/lib/simpletest/errors.php
===================================================================
--- 3.x/trunk/limb/tests_runner/lib/simpletest/errors.php 2007-06-18 12:28:49 UTC (rev 5998)
+++ 3.x/trunk/limb/tests_runner/lib/simpletest/errors.php 2007-06-18 13:13:08 UTC (rev 5999)
@@ -1,7 +1,7 @@
<?php
/**
* base include file for SimpleTest
- * @package tests_runner
+ * @package SimpleTest
* @subpackage UnitTester
* @version $Id$
*/
@@ -23,7 +23,7 @@
/**
* Extension that traps errors into an error queue.
- * @package tests_runner
+ * @package SimpleTest
* @subpackage UnitTester
*/
class SimpleErrorTrappingInvoker extends SimpleInvokerDecorator {
@@ -56,12 +56,26 @@
}
restore_error_handler();
}
+
+ function after($method) {
+ $context = &SimpleTest::getContext();
+ $queue = &$context->get('SimpleErrorQueue');
+ $queue->setTestCase($this->getTestCase());
+ while (list($expected, $message) = $queue->extractExpectation()) {
+ $testCase = &$this->getTestCase();
+
+ $testCase->fail(
+ sprintf('Expected PHP error [%s] not caught', $expected->_value)
+ );
+ }
+ parent::after($method);
+ }
}
/**
* Singleton error queue used to record trapped
* errors.
- * @package tests_runner
+ * @package SimpleTest
* @subpackage UnitTester
*/
class SimpleErrorQueue {
@@ -141,6 +155,13 @@
return false;
}
+ function extractExpectation() {
+ if (count($this->_expectation_queue)) {
+ return array_shift($this->_expectation_queue);
+ }
+ return false;
+ }
+
/**
* Discards the contents of the error queue.
* @access public
@@ -186,9 +207,7 @@
* @access public
*/
function expectError($expected, $message) {
- array_push(
- $this->_expectation_queue,
- array($expected, $message));
+ array_push($this->_expectation_queue, array($expected, $message));
}
/**
@@ -213,6 +232,9 @@
E_USER_ERROR => 'E_USER_ERROR',
E_USER_WARNING => 'E_USER_WARNING',
E_USER_NOTICE => 'E_USER_NOTICE');
+ if(version_compare(phpversion(), '5.2.0', '>=')) {
+ $map[E_RECOVERABLE_ERROR] = 'E_RECOVERABLE_ERROR';
+ }
return $map[$severity];
}
}
@@ -229,7 +251,7 @@
* @static
* @access public
*/
-function SimpleTestErrorHandler($severity, $message, $filename, $line, $super_globals) {
+function SimpleTestErrorHandler($severity, $message, $filename = null, $line = null, $super_globals = null, $mask = null) {
$severity = $severity & error_reporting();
if ($severity) {
restore_error_handler();
@@ -241,10 +263,7 @@
$queue = &$context->get('SimpleErrorQueue');
$queue->add($severity, $message, $filename, $line);
set_error_handler('SimpleTestErrorHandler');
- } else {
- if (version_compare(phpversion(), '5.2') >= 0) {
- return false;
- }
}
+ return true;
}
?>
\ No newline at end of file
Modified: 3.x/trunk/limb/tests_runner/lib/simpletest/exceptions.php
===================================================================
--- 3.x/trunk/limb/tests_runner/lib/simpletest/exceptions.php 2007-06-18 12:28:49 UTC (rev 5998)
+++ 3.x/trunk/limb/tests_runner/lib/simpletest/exceptions.php 2007-06-18 13:13:08 UTC (rev 5999)
@@ -1,7 +1,7 @@
<?php
/**
* base include file for SimpleTest
- * @package tests_runner
+ * @package SimpleTest
* @subpackage UnitTester
* @version $Id$
*/
@@ -16,7 +16,7 @@
/**
* Extension that traps exceptions and turns them into
* an error message. PHP5 only.
- * @package tests_runner
+ * @package SimpleTest
* @subpackage UnitTester
*/
class SimpleExceptionTrappingInvoker extends SimpleInvokerDecorator {
@@ -58,7 +58,7 @@
* exception. This could be improved to accept
* a pattern expectation to test the error
* message, but that will have to come later.
- * @package tests_runner
+ * @package SimpleTest
* @subpackage UnitTester
*/
class ExceptionExpectation extends SimpleExpectation {
@@ -125,7 +125,7 @@
* Stores expected exceptions for when they
* get thrown. Saves the irritating try...catch
* block.
- * @package tests_runner
+ * @package SimpleTest
* @subpackage UnitTester
*/
class SimpleExceptionTrap {
Modified: 3.x/trunk/limb/tests_runner/lib/simpletest/expectation.php
===================================================================
--- 3.x/trunk/limb/tests_runner/lib/simpletest/expectation.php 2007-06-18 12:28:49 UTC (rev 5998)
+++ 3.x/trunk/limb/tests_runner/lib/simpletest/expectation.php 2007-06-18 13:13:08 UTC (rev 5999)
@@ -1,7 +1,7 @@
<?php
/**
* base include file for SimpleTest
- * @package tests_runner
+ * @package SimpleTest
* @subpackage UnitTester
* @version $Id$
*/
@@ -16,12 +16,12 @@
/**
* Assertion that can display failure information.
* Also includes various helper methods.
- * @package tests_runner
+ * @package SimpleTest
* @subpackage UnitTester
* @abstract
*/
class SimpleExpectation {
- var $_dumper;
+ var $_dumper = false;
var $_message;
/**
@@ -74,6 +74,10 @@
* @access protected
*/
function &_getDumper() {
+ if (! $this->_dumper) {
+ $dumper = &new SimpleDumper();
+ return $dumper;
+ }
return $this->_dumper;
}
@@ -95,7 +99,7 @@
/**
* A wildcard expectation always matches.
- * @package tests_runner
+ * @package SimpleTest
* @subpackage MockObjects
*/
class AnythingExpectation extends SimpleExpectation {
@@ -124,8 +128,37 @@
}
/**
+ * An expectation that never matches.
+ * @package SimpleTest
+ * @subpackage MockObjects
+ */
+ class FailedExpectation extends SimpleExpectation {
+
+ /**
+ * Tests the expectation. Always false.
+ * @param mixed $compare Ignored.
+ * @return boolean True.
+ * @access public
+ */
+ function test($compare) {
+ return false;
+ }
+
+ /**
+ * Returns a human readable test message.
+ * @param mixed $compare Comparison value.
+ * @return string Description of failure.
+ * @access public
+ */
+ function testMessage($compare) {
+ $dumper = &$this->_getDumper();
+ return 'Failed expectation never matches [' . $dumper->describeValue($compare) . ']';
+ }
+ }
+
+ /**
* An expectation that passes on boolean true.
- * @package tests_runner
+ * @package SimpleTest
* @subpackage MockObjects
*/
class TrueExpectation extends SimpleExpectation {
@@ -155,7 +188,7 @@
/**
* An expectation that passes on boolean false.
- * @package tests_runner
+ * @package SimpleTest
* @subpackage MockObjects
*/
class FalseExpectation extends SimpleExpectation {
@@ -185,7 +218,7 @@
/**
* Test for equality.
- * @package tests_runner
+ * @package SimpleTest
* @subpackage UnitTester
*/
class EqualExpectation extends SimpleExpectation {
@@ -239,35 +272,9 @@
}
}
- class ReferenceExpectation extends SimpleExpectation {
- var $_value;
-
- function ReferenceExpectation(&$value, $message = '%s') {
- $this->SimpleExpectation($message);
- $this->_value =& $value;
- }
-
- function test(&$compare) {
- return SimpleTestCompatibility::isReference($this->_value, $compare);
- }
-
- function testMessage($compare) {
- if ($this->test($compare)) {
- return "Reference expectation [" . $this->_dumper->describeValue($this->_value) . "]";
- } else {
- return "Reference expectation fails " .
- $this->_dumper->describeDifference($this->_value, $compare);
- }
- }
-
- function _getValue() {
- return $this->_value;
- }
- }
-
/**
* Test for inequality.
- * @package tests_runner
+ * @package SimpleTest
* @subpackage UnitTester
*/
class NotEqualExpectation extends EqualExpectation {
@@ -315,7 +322,7 @@
/**
* Test for being within a range.
- * @package tests_runner
+ * @package SimpleTest
* @subpackage UnitTester
*/
class WithinMarginExpectation extends SimpleExpectation {
@@ -390,7 +397,7 @@
/**
* Test for being outside of a range.
- * @package tests_runner
+ * @package SimpleTest
* @subpackage UnitTester
*/
class OutsideMarginExpectation extends WithinMarginExpectation {
@@ -435,8 +442,59 @@
}
/**
+ * Test for reference.
+ * @package SimpleTest
+ * @subpackage UnitTester
+ */
+ class ReferenceExpectation extends SimpleExpectation {
+ var $_value;
+
+ /**
+ * Sets the reference value to compare against.
+ * @param mixed $value Test reference to match.
+ * @param string $message Customised message on failure.
+ * @access public
+ */
+ function ReferenceExpectation(&$value, $message = '%s') {
+ $this->SimpleExpectation($message);
+ $this->_value =& $value;
+ }
+
+ /**
+ * Tests the expectation. True if it exactly
+ * references the held value.
+ * @param mixed $compare Comparison reference.
+ * @return boolean True if correct.
+ * @access public
+ */
+ function test(&$compare) {
+ return SimpleTestCompatibility::isReference($this->_value, $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 "Reference expectation [" . $this->_dumper->describeValue($this->_value) . "]";
+ } else {
+ return "Reference expectation fails " .
+ $this->_dumper->describeDifference($this->_value, $compare);
+ }
+ }
+
+ function _getValue() {
+ return $this->_value;
+ }
+ }
+
+ /**
* Test for identity.
- * @package tests_runner
+ * @package SimpleTest
* @subpackage UnitTester
*/
class IdenticalExpectation extends EqualExpectation {
@@ -484,7 +542,7 @@
/**
* Test for non-identity.
- * @package tests_runner
+ * @package SimpleTest
* @subpackage UnitTester
*/
class NotIdenticalExpectation extends IdenticalExpectation {
@@ -530,7 +588,7 @@
/**
* Test for a pattern using Perl regex rules.
- * @package tests_runner
+ * @package SimpleTest
* @subpackage UnitTester
*/
class PatternExpectation extends SimpleExpectation {
@@ -604,7 +662,7 @@
}
/**
- * @package tests_runner
+ * @package SimpleTest
* @subpackage UnitTester
* @deprecated
*/
@@ -614,7 +672,7 @@
/**
* Fail if a pattern is detected within the
* comparison.
- * @package tests_runner
+ * @package SimpleTest
* @subpackage UnitTester
*/
class NoPatternExpectation extends PatternExpectation {
@@ -660,7 +718,7 @@
}
/**
- * @package tests_runner
+ * @package SimpleTest
* @subpackage UnitTester
* @deprecated
*/
@@ -669,7 +727,7 @@
/**
* Tests either type or class name if it's an object.
- * @package tests_runner
+ * @package SimpleTest
* @subpackage UnitTester
*/
class IsAExpectation extends SimpleExpectation {
@@ -746,7 +804,7 @@
/**
* Tests either type or class name if it's an object.
* Will succeed if the type does not match.
- * @package tests_runner
+ * @package SimpleTest
* @subpackage UnitTester
*/
class NotAExpectation extends IsAExpectation {
@@ -789,7 +847,7 @@
/**
* Tests for existance of a method in an object
- * @package tests_runner
+ * @package SimpleTest
* @subpackage UnitTester
*/
class MethodExistsExpectation extends SimpleExpectation {
Added: 3.x/trunk/limb/tests_runner/lib/simpletest/extensions/dom_tester/css_selector.php
===================================================================
--- 3.x/trunk/limb/tests_runner/lib/simpletest/extensions/dom_tester/css_selector.php (rev 0)
+++ 3.x/trunk/limb/tests_runner/lib/simpletest/extensions/dom_tester/css_selector.php 2007-06-18 13:13:08 UTC (rev 5999)
@@ -0,0 +1,311 @@
+<?php
+
+/**
+ * @package SimpleTest
+ * @subpackage DomTestCase
+ * @author Perrick Penet <perrick at noparking.net>
+ * @version $Id: css_selector.php,v 1.3 2007/06/08 20:37:35 pp11 Exp $
+ */
+
+/**
+ * CssSelector
+ *
+ * Allow to navigate a DOM with CSS selector.
+ *
+ * based on getElementsBySelector version 0.4 - Simon Willison, 2003-03-25
+ * http://simon.incutio.com/archive/2003/03/25/getElementsBySelector
+ *
+ * derived from sfDomCssSelector Id 3053 (Symfony version 1.0.2) - Fabien Potencier, 2006-12-16
+ * http://www.symfony-project.com/api/symfony/util/sfDomCssSelector.html
+ *
+ * @param DomDocument $dom
+ *
+ */
+
+class CssSelector {
+ protected $dom = null;
+
+ public function __construct($dom)
+ {
+ $this->dom = $dom;
+ }
+
+ public function getTexts($selector)
+ {
+ $texts = array();
+ foreach ($this->getElements($selector) as $element)
+ {
+ $texts[] = $element->nodeValue;
+ }
+
+ return $texts;
+ }
+
+ public function getElements($selector)
+ {
+ $all_nodes = array();
+ foreach ($this->tokenize_selectors($selector) as $selector)
+ {
+ $nodes = array($this->dom);
+ foreach ($this->tokenize($selector) as $token)
+ {
+ $combinator = $token['combinator'];
+ $token = trim($token['name']);
+ $pos = strpos($token, '#');
+ if (false !== $pos && preg_match('/^[A-Za-z0-9]*$/', substr($token, 0, $pos)))
+ {
+ // Token is an ID selector
+ $tagName = substr($token, 0, $pos);
+ $id = substr($token, $pos + 1);
+ $xpath = new DomXPath($this->dom);
+ $element = $xpath->query(sprintf("//*[@id = '%s']", $id))->item(0);
+ if (!$element || ($tagName && strtolower($element->nodeName) != $tagName))
+ {
+ // tag with that ID not found
+ return array();
+ }
+
+ // Set nodes to contain just this element
+ $nodes = array($element);
+
+ continue; // Skip to next token
+ }
+
+ $pos = strpos($token, '.');
+ if (false !== $pos && preg_match('/^[A-Za-z0-9]*$/', substr($token, 0, $pos)))
+ {
+ // Token contains a class selector
+ $tagName = substr($token, 0, $pos);
+ if (!$tagName)
+ {
+ $tagName = '*';
+ }
+ $className = substr($token, $pos + 1);
+
+ // Get elements matching tag, filter them for class selector
+ $founds = $this->getElementsByTagName($nodes, $tagName, $combinator);
+ $nodes = array();
+ foreach ($founds as $found)
+ {
+ if (preg_match('/\b'.$className.'\b/', $found->getAttribute('class')))
+ {
+ $nodes[] = $found;
+ }
+ }
+
+ continue; // Skip to next token
+ }
+
+ // Code to deal with attribute selectors
+ if (preg_match('/^(\w*)(\[.+\])$/', $token, $matches))
+ {
+ $tagName = $matches[1] ? $matches[1] : '*';
+ preg_match_all('/
+ \[
+ (\w+) # attribute
+ ([=~\|\^\$\*]?) # modifier (optional)
+ =? # equal (optional)
+ (
+ "([^"]*)" # quoted value (optional)
+ |
+ ([^\]]*) # non quoted value (optional)
+ )
+ \]
+ /x', $matches[2], $matches, PREG_SET_ORDER);
+
+ // Grab all of the tagName elements within current node
+ $founds = $this->getElementsByTagName($nodes, $tagName, $combinator);
+ $nodes = array();
+ foreach ($founds as $found)
+ {
+ $ok = false;
+ foreach ($matches as $match)
+ {
+ $attrName = $match[1];
+ $attrOperator = $match[2];
+ $attrValue = $match[4];
+
+ switch ($attrOperator)
+ {
+ case '=': // Equality
+ $ok = $found->getAttribute($attrName) == $attrValue;
+ break;
+ case '~': // Match one of space seperated words
+ $ok = preg_match('/\b'.preg_quote($attrValue, '/').'\b/', $found->getAttribute($attrName));
+ break;
+ case '|': // Match start with value followed by optional hyphen
+ $ok = preg_match('/^'.preg_quote($attrValue, '/').'-?/', $found->getAttribute($attrName));
+ break;
+ case '^': // Match starts with value
+ $ok = 0 === strpos($found->getAttribute($attrName), $attrValue);
+ break;
+ case '$': // Match ends with value
+ $ok = $attrValue == substr($found->getAttribute($attrName), -strlen($attrValue));
+ break;
+ case '*': // Match ends with value
+ $ok = false !== strpos($found->getAttribute($attrName), $attrValue);
+ break;
+ default :
+ // Just test for existence of attribute
+ $ok = $found->hasAttribute($attrName);
+ }
+
+ if (false == $ok)
+ {
+ break;
+ }
+ }
+
+ if ($ok)
+ {
+ $nodes[] = $found;
+ }
+ }
+
+ continue; // Skip to next token
+ }
+
+ if (preg_match('/^(\w*)(:first-child)$/', $token, $matches)) {
+ $token = $matches[1] ? $matches[1] : '*';
+ $combinator = $matches[2] ? $matches[2] : '';
+ }
+
+ // If we get here, token is JUST an element (not a class or ID selector)
+ $nodes = $this->getElementsByTagName($nodes, $token, $combinator);
+ }
+
+ foreach ($nodes as $node)
+ {
+ if (!$node->getAttribute('sf_matched'))
+ {
+ $node->setAttribute('sf_matched', true);
+ $all_nodes[] = $node;
+ }
+ }
+ }
+
+ foreach ($all_nodes as $node)
+ {
+ $node->removeAttribute('sf_matched');
+ }
+
+ return $all_nodes;
+ }
+
+ protected function getElementsByTagName($nodes, $tagName, $combinator = ' ')
+ {
+ $founds = array();
+ foreach ($nodes as $node)
+ {
+ switch ($combinator)
+ {
+ case ' ':
+ foreach ($node->getElementsByTagName($tagName) as $element)
+ {
+ $founds[] = $element;
+ }
+ break;
+ case '>':
+ foreach ($node->childNodes as $element)
+ {
+ if ($tagName == $element->nodeName)
+ {
+ $founds[] = $element;
+ }
+ }
+ break;
+ case '+':
+ $element = $node->nextSibling;
+ if ($element->nodeName == "#text") {
+ $element = $element->nextSibling;
+ }
+ if ($element && $tagName == $element->nodeName) {
+ $founds[] = $element;
+ }
+ break;
+ case ':first-child':
+ foreach ($node->getElementsByTagName($tagName) as $element) {
+ if (count($founds) == 0) {
+ $founds[] = $element;
+ }
+ }
+ break;
+ }
+ }
+
+ return $founds;
+ }
+
+ protected function tokenize_selectors($selector)
+ {
+ // split tokens by , except in an attribute selector
+ $tokens = array();
+ $quoted = false;
+ $token = '';
+ for ($i = 0, $max = strlen($selector); $i < $max; $i++)
+ {
+ if (',' == $selector[$i] && !$quoted)
+ {
+ $tokens[] = trim($token);
+ $token = '';
+ }
+ else if ('"' == $selector[$i])
+ {
+ $token .= $selector[$i];
+ $quoted = $quoted ? false : true;
+ }
+ else
+ {
+ $token .= $selector[$i];
+ }
+ }
+ if ($token)
+ {
+ $tokens[] = trim($token);
+ }
+
+ return $tokens;
+ }
+
+ protected function tokenize($selector)
+ {
+ // split tokens by space except if space is in an attribute selector
+ $tokens = array();
+ $combinators = array(' ', '>', '+');
+ $quoted = false;
+ $token = array('combinator' => ' ', 'name' => '');
+ for ($i = 0, $max = strlen($selector); $i < $max; $i++)
+ {
+ if (in_array($selector[$i], $combinators) && !$quoted)
+ {
+ // remove all whitespaces around the combinator
+ $combinator = $selector[$i];
+ while (in_array($selector[$i + 1], $combinators))
+ {
+ if (' ' != $selector[++$i])
+ {
+ $combinator = $selector[$i];
+ }
+ }
+
+ $tokens[] = $token;
+ $token = array('combinator' => $combinator, 'name' => '');
+ }
+ else if ('"' == $selector[$i])
+ {
+ $token['name'] .= $selector[$i];
+ $quoted = $quoted ? false : true;
+ }
+ else
+ {
+ $token['name'] .= $selector[$i];
+ }
+ }
+ if ($token['name'])
+ {
+ $tokens[] = $token;
+ }
+
+ return $tokens;
+ }
+}
Added: 3.x/trunk/limb/tests_runner/lib/simpletest/extensions/dom_tester/dom_tester.html
===================================================================
--- 3.x/trunk/limb/tests_runner/lib/simpletest/extensions/dom_tester/dom_tester.html (rev 0)
+++ 3.x/trunk/limb/tests_runner/lib/simpletest/extensions/dom_tester/dom_tester.html 2007-06-18 13:13:08 UTC (rev 5999)
@@ -0,0 +1,48 @@
+<html>
+ <head>
+ </head>
+ <body>
+ <h1>Test page</h1>
+
+ <h2>Title 1</h2>
+ <p class="header">header</p>
+ <p class="foo bar foobar">multi-classes</p>
+ <p class="myfoo">myfoo</p>
+ <p class="myfoo" id="mybar">myfoo bis</p>
+
+ <p onclick="javascript:alert('with a . and a # inside an attribute');">works great</p>
+
+ <ul id="list">
+ <li>First</li>
+ <li>Second with a <a href="http://www.google.com/" class="foo1 bar1 bar1-foo1 foobar1">link</a></li>
+ </ul>
+
+ <ul id="anotherlist">
+ <li>First</li>
+ <li>Third with a <a class="bar1-foo1">another link</a></li>
+ </ul>
+
+ <h2>Title 2</h2>
+ <ul id="mylist">
+ <li>element 1</li>
+ <li>element 2</li>
+ <ul>
+ <li>element 3</li>
+ <li>element 4</li>
+ </ul>
+ </ul>
+
+ <div id="combinators">
+ <ul>
+ <li>test 1</li>
+ <li>test 2</li>
+ <ul>
+ <li>test 3</li>
+ <li>test 4</li>
+ </ul>
+ </ul>
+ </div>
+
+ <div id="footer">footer</div>
+ </body>
+</html>
\ No newline at end of file
Added: 3.x/trunk/limb/tests_runner/lib/simpletest/extensions/dom_tester/dom_tester_child_adjacent.html
===================================================================
--- 3.x/trunk/limb/tests_runner/lib/simpletest/extensions/dom_tester/dom_tester_child_adjacent.html (rev 0)
+++ 3.x/trunk/limb/tests_runner/lib/simpletest/extensions/dom_tester/dom_tester_child_adjacent.html 2007-06-18 13:13:08 UTC (rev 5999)
@@ -0,0 +1,23 @@
+<html>
+<head>
+ <title>Foo!</title>
+ <style>
+p {
+ text-decoration: underline;
+}
+
+p + p {
+ color: red;
+}
+
+body > p + p > a {
+ background-color: black;
+}
+ </style>
+</head>
+<body>
+<p>First paragraph</p>
+<p>Second paragraph</p>
+<p>Third <a href='http://localhost/'>paragraph</a></p>
+</body>
+</html>
Added: 3.x/trunk/limb/tests_runner/lib/simpletest/extensions/dom_tester/dom_tester_doc_test.php
===================================================================
--- 3.x/trunk/limb/tests_runner/lib/simpletest/extensions/dom_tester/dom_tester_doc_test.php (rev 0)
+++ 3.x/trunk/limb/tests_runner/lib/simpletest/extensions/dom_tester/dom_tester_doc_test.php 2007-06-18 13:13:08 UTC (rev 5999)
@@ -0,0 +1,25 @@
+<?php
+
+// $Id: dom_tester_doc_test.php,v 1.1 2007/05/31 21:29:21 pp11 Exp $
+
+require_once(dirname(__FILE__) . '/../../autorun.php');
+require_once(dirname(__FILE__) . '/../dom_tester.php');
+
+SimpleTest :: prefer(new TextReporter());
+
+class TestOfLiveCssSelectors extends DomTestCase {
+ function setUp() {
+ $this->addHeader('User-Agent: SimpleTest ' . SimpleTest::getVersion());
+ }
+
+ function testGet() {
+ $url = 'http://localhost/~perrick/simpletest/docs/simpletest.org/';
+ $this->assertTrue($this->get($url));
+ $this->assertEqual($this->getUrl(), $url);
+ $this->assertElementsBySelector('h2', array('Screenshots', 'Documentation', 'Contributing'));
+ $this->assertElementsBySelector('a[href="http://simpletest.org/api/"]', array('the complete API', 'documented API'));
+ $this->assertElementsBySelector('div#content > p > strong', array('SimpleTest PHP unit tester'));
+ }
+}
+
+?>
\ No newline at end of file
Added: 3.x/trunk/limb/tests_runner/lib/simpletest/extensions/dom_tester/dom_tester_test.php
===================================================================
--- 3.x/trunk/limb/tests_runner/lib/simpletest/extensions/dom_tester/dom_tester_test.php (rev 0)
+++ 3.x/trunk/limb/tests_runner/lib/simpletest/extensions/dom_tester/dom_tester_test.php 2007-06-18 13:13:08 UTC (rev 5999)
@@ -0,0 +1,175 @@
+<?php
+
+// $Id: dom_tester_test.php,v 1.3 2007/06/08 20:37:35 pp11 Exp $
+
+require_once(dirname(__FILE__) . '/../../autorun.php');
+require_once(dirname(__FILE__) . '/../dom_tester.php');
+
+class TestOfLiveCssSelectors extends DomTestCase {
+ function setUp() {
+ $this->addHeader('User-Agent: SimpleTest ' . SimpleTest::getVersion());
+ }
+
+ function testGet() {
+// $url = 'http://simpletest.org/live/extensions/dom_tester/dom_tester.html';
+ $url = 'http://localhost/~perrick/simpletest/extensions/dom_tester/dom_tester.html';
+ $this->assertTrue($this->get($url));
+ $this->assertEqual($this->getUrl(), $url);
+ $this->assertElementsBySelector('h1', array('Test page'));
+ $this->assertElementsBySelector('ul#list li a[href]', array('link'));
+ $this->assertElementsBySelector('body h1', array('Test page'));
+ $this->assertElementsBySelector('#mybar', array('myfoo bis'));
+ }
+}
+
+class TestOfCssSelectors extends UnitTestCase {
+ function TestOfCssSelectors() {
+ $html = file_get_contents(dirname(__FILE__) . '/dom_tester.html');
+ $this->dom = new DomDocument('1.0', 'utf-8');
+ $this->dom->validateOnParse = true;
+ $this->dom->loadHTML($html);
+ }
+
+ function testBasicSelector() {
+ $expectation = new CssSelectorExpectation($this->dom, 'h1');
+ $this->assertTrue($expectation->test(array('Test page')));
+
+ $expectation = new CssSelectorExpectation($this->dom, 'h2');
+ $this->assertTrue($expectation->test(array('Title 1', 'Title 2')));
+
+ $expectation = new CssSelectorExpectation($this->dom, '#footer');
+ $this->assertTrue($expectation->test(array('footer')));
+
+ $expectation = new CssSelectorExpectation($this->dom, 'div#footer');
+ $this->assertTrue($expectation->test(array('footer')));
+
+ $expectation = new CssSelectorExpectation($this->dom, '.header');
+ $this->assertTrue($expectation->test(array('header')));
+
+ $expectation = new CssSelectorExpectation($this->dom, 'p.header');
+ $this->assertTrue($expectation->test(array('header')));
+
+ $expectation = new CssSelectorExpectation($this->dom, 'div.header');
+ $this->assertTrue($expectation->test(array()));
+
+ $expectation = new CssSelectorExpectation($this->dom, 'ul#mylist ul li');
+ $this->assertTrue($expectation->test(array('element 3', 'element 4')));
+
+ $expectation = new CssSelectorExpectation($this->dom, '#nonexistant');
+ $this->assertTrue($expectation->test(array()));
+ }
+
+ function testAttributeSelectors() {
+ $expectation = new CssSelectorExpectation($this->dom, 'ul#list li a[href]');
+ $this->assertTrue($expectation->test(array('link')));
+
+ $expectation = new CssSelectorExpectation($this->dom, 'ul#list li a[class~="foo1"]');
+ $this->assertTrue($expectation->test(array('link')));
+
+ $expectation = new CssSelectorExpectation($this->dom, 'ul#list li a[class~="bar1"]');
+ $this->assertTrue($expectation->test(array('link')));
+
+ $expectation = new CssSelectorExpectation($this->dom, 'ul#list li a[class~="foobar1"]');
+ $this->assertTrue($expectation->test(array('link')));
+
+ $expectation = new CssSelectorExpectation($this->dom, 'ul#list li a[class^="foo1"]');
+ $this->assertTrue($expectation->test(array('link')));
+
+ $expectation = new CssSelectorExpectation($this->dom, 'ul#list li a[class$="foobar1"]');
+ $this->assertTrue($expectation->test(array('link')));
+
+ $expectation = new CssSelectorExpectation($this->dom, 'ul#list li a[class*="oba"]');
+ $this->assertTrue($expectation->test(array('link')));
+
+ $expectation = new CssSelectorExpectation($this->dom, 'ul#list li a[href="http://www.google.com/"]');
+ $this->assertTrue($expectation->test(array('link')));
+
+ $expectation = new CssSelectorExpectation($this->dom, 'ul#anotherlist li a[class|="bar1"]');
+ $this->assertTrue($expectation->test(array('another link')));
+
+ $expectation = new CssSelectorExpectation($this->dom, 'ul#list li a[class*="oba"][class*="ba"]');
+ $this->assertTrue($expectation->test(array('link')));
+
+ $expectation = new CssSelectorExpectation($this->dom, 'p[class="myfoo"][id="mybar"]');
+ $this->assertTrue($expectation->test(array('myfoo bis')));
+
+ $expectation = new CssSelectorExpectation($this->dom, 'p[onclick*="a . and a #"]');
+ $this->assertTrue($expectation->test(array('works great')));
+ }
+
+ function testCombinators() {
+ $expectation = new CssSelectorExpectation($this->dom, 'body h1');
+ $this->assertTrue($expectation->test(array('Test page')));
+
+ $expectation = new CssSelectorExpectation($this->dom, 'div#combinators > ul > li');
+ $this->assertTrue($expectation->test(array('test 1', 'test 2')));
+
+ $expectation = new CssSelectorExpectation($this->dom, 'div#combinators>ul>li');
+ $this->assertTrue($expectation->test(array('test 1', 'test 2')));
+
+ $expectation = new CssSelectorExpectation($this->dom, 'div#combinators li + li');
+ $this->assertTrue($expectation->test(array('test 2', 'test 4')));
+
+ $expectation = new CssSelectorExpectation($this->dom, 'div#combinators li+li');
+ $this->assertTrue($expectation->test(array('test 2', 'test 4')));
+
+ $expectation = new CssSelectorExpectation($this->dom, 'h1, h2');
+ $this->assertTrue($expectation->test(array('Test page', 'Title 1', 'Title 2')));
+
+ $expectation = new CssSelectorExpectation($this->dom, 'h1,h2');
+ $this->assertTrue($expectation->test(array('Test page', 'Title 1', 'Title 2')));
+
+ $expectation = new CssSelectorExpectation($this->dom, 'h1 , h2');
+ $this->assertTrue($expectation->test(array('Test page', 'Title 1', 'Title 2')));
+
+ $expectation = new CssSelectorExpectation($this->dom, 'h1, h1,h1');
+ $this->assertTrue($expectation->test(array('Test page')));
+
+ $expectation = new CssSelectorExpectation($this->dom, 'h1,h2,h1');
+ $this->assertTrue($expectation->test(array('Test page', 'Title 1', 'Title 2')));
+
+ $expectation = new CssSelectorExpectation($this->dom, 'p[onclick*="a . and a #"], div#combinators > ul > li + li');
+ $this->assertTrue($expectation->test(array('works great', 'test 2')));
+ }
+}
+
+class TestsOfChildAndAdjacentSelectors extends DomTestCase {
+ function TestsOfChildAndAdjacentSelectors() {
+ $html = file_get_contents(dirname(__FILE__) . '/dom_tester_child_adjacent.html');
+ $this->dom = new DomDocument('1.0', 'utf-8');
+ $this->dom->validateOnParse = true;
+ $this->dom->loadHTML($html);
+ }
+
+ function testFirstChild() {
+ $expectation = new CssSelectorExpectation($this->dom, 'p:first-child');
+ $this->assertTrue($expectation->test(array('First paragraph')));
+
+ $expectation = new CssSelectorExpectation($this->dom, 'body > p:first-child');
+ $this->assertTrue($expectation->test(array('First paragraph')));
+
+ $expectation = new CssSelectorExpectation($this->dom, 'body > p > a:first-child');
+ $this->assertTrue($expectation->test(array('paragraph')));
+ }
+
+ function testChildren() {
+ $expectation = new CssSelectorExpectation($this->dom, 'body > p');
+ $this->assertTrue($expectation->test(array('First paragraph', 'Second paragraph', 'Third paragraph')));
+
+ $expectation = new CssSelectorExpectation($this->dom, 'body > p > a');
+ $this->assertTrue($expectation->test(array('paragraph')));
+ }
+
+ function testAdjacents() {
+ $expectation = new CssSelectorExpectation($this->dom, 'p + p');
+ $this->assertTrue($expectation->test(array('Second paragraph', 'Third paragraph')));
+
+ $expectation = new CssSelectorExpectation($this->dom, 'body > p + p');
+ $this->assertTrue($expectation->test(array('Second paragraph', 'Third paragraph')));
+
+ $expectation = new CssSelectorExpectation($this->dom, 'body > p + p > a');
+ $this->assertTrue($expectation->test(array('paragraph')));
+ }
+}
+
+?>
Added: 3.x/trunk/limb/tests_runner/lib/simpletest/extensions/dom_tester.php
===================================================================
--- 3.x/trunk/limb/tests_runner/lib/simpletest/extensions/dom_tester.php (rev 0)
+++ 3.x/trunk/limb/tests_runner/lib/simpletest/extensions/dom_tester.php 2007-06-18 13:13:08 UTC (rev 5999)
@@ -0,0 +1,112 @@
+<?php
+
+/**
+ * @package SimpleTest
+ * @subpackage DomTestCase
+ * @author Perrick Penet <perrick at noparking.net>
+ * @version $Id: dom_tester.php,v 1.1 2007/05/09 11:15:52 pp11 Exp $
+ */
+
+/**#@+
+ * include SimpleTest files
+ */
+require_once dirname(__FILE__).'/../web_tester.php';
+require_once dirname(__FILE__).'/dom_tester/css_selector.php';
+/**#@-*/
+
+/**
+ * CssSelectorExpectation
+ *
+ * Create a CSS Selector expectactation
+ *
+ * @param DomDocument $_dom
+ * @param string $_selector
+ * @param array $_value
+ *
+ */
+
+class CssSelectorExpectation extends SimpleExpectation {
+ var $_dom;
+ var $_selector;
+ var $_value;
+
+ /**
+ * Sets the dom tree and the css selector to compare against
+ * @param mixed $dom Dom tree to search into.
+ * @param mixed $selector Css selector to match element.
+ * @param string $message Customised message on failure.
+ * @access public
+ */
+ function CssSelectorExpectation($dom, $selector, $message = '%s') {
+ $this->SimpleExpectation($message);
+ $this->_dom = $dom;
+ $this->_selector = $selector;
+
+ $css_selector = new CssSelector($this->_dom);
+ $this->_value = $css_selector->getTexts($this->_selector);
+ }
+
+ /**
+ * 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
+ */
+ function testMessage($compare) {
+ $dumper = &$this->_getDumper();
+ if (is_array($compare)) {
+ sort($compare);
+ }
+ if ($this->test($compare)) {
+ return "CSS selector expectation [" . $dumper->describeValue($this->_value) . "]".
+ " using [" . $dumper->describeValue($this->_selector) . "]";
+ } else {
+ return "CSS selector expectation [" . $dumper->describeValue($this->_value) . "]".
+ " using [" . $dumper->describeValue($this->_selector) . "]".
+ " fails with [" .
+ $dumper->describeValue($compare) . "] " .
+ $dumper->describeDifference($this->_value, $compare);
+ }
+ }
+}
+
+/**
+ * DomTestCase
+ *
+ * Extend Web test case with DOM related assertions,
+ * CSS selectors in particular
+ *
+ * @category Testing
+ * @package DomTestCase
+ *
+ * @param DomDocument $dom
+ *
+ */
+class DomTestCase extends WebTestCase {
+ var $dom;
+
+ function assertElementsBySelector($selector, $elements, $message = '%s') {
+ $this->dom = new DomDocument('1.0', 'utf-8');
+ $this->dom->validateOnParse = true;
+ $this->dom->loadHTML($this->_browser->getContent());
+
+ return $this->assert(
+ new CssSelectorExpectation($this->dom, $selector),
+ $elements,
+ $message);
+ }
+}
+
+?>
Modified: 3.x/trunk/limb/tests_runner/lib/simpletest/extensions/pear_test_case.php
===================================================================
--- 3.x/trunk/limb/tests_runner/lib/simpletest/extensions/pear_test_case.php 2007-06-18 12:28:49 UTC (rev 5998)
+++ 3.x/trunk/limb/tests_runner/lib/simpletest/extensions/pear_test_case.php 2007-06-18 13:13:08 UTC (rev 5999)
@@ -1,7 +1,7 @@
<?php
/**
* adapter for SimpleTest to use PEAR PHPUnit test cases
- * @package tests_runner
+ * @package SimpleTest
* @subpackage Extensions
* @version $Id$
*/
@@ -18,7 +18,7 @@
/**
* Adapter for PEAR PHPUnit test case to allow
* legacy PEAR test cases to be used with SimpleTest.
- * @package tests_runner
+ * @package SimpleTest
* @subpackage Extensions
*/
class PHPUnit_TestCase extends SimpleTestCase {
@@ -58,7 +58,7 @@
* @public
*/
function assertNotNull($value, $message = "%s") {
- parent::assertTrue(isset($value), $message);
+ parent::assert(new TrueExpectation(), isset($value), $message);
}
/**
@@ -68,7 +68,7 @@
* @public
*/
function assertNull($value, $message = "%s") {
- parent::assertTrue(!isset($value), $message);
+ parent::assert(new TrueExpectation(), !isset($value), $message);
}
/**
@@ -86,7 +86,8 @@
"[" . $dumper->describeValue($first) .
"] and [" . $dumper->describeValue($second) .
"] should reference the same object");
- return $this->assertTrue(
+ return $this->assert(
+ new TrueExpectation(),
SimpleTestCompatibility::isReference($first, $second),
$message);
}
@@ -106,7 +107,8 @@
"[" . $dumper->describeValue($first) .
"] and [" . $dumper->describeValue($second) .
"] should not be the same object");
- return $this->assertFalse(
+ return $this->assert(
+ new falseExpectation(),
SimpleTestCompatibility::isReference($first, $second),
$message);
}
@@ -119,7 +121,7 @@
* @public
*/
function assertTrue($condition, $message = "%s") {
- parent::assertTrue($condition, $message);
+ parent::assert(new TrueExpectation(), $condition, $message);
}
/**
@@ -130,7 +132,7 @@
* @public
*/
function assertFalse($condition, $message = "%s") {
- parent::assertTrue(!$condition, $message);
+ parent::assert(new FalseExpectation(), $condition, $message);
}
/**
@@ -152,7 +154,7 @@
* @public
*/
function assertType($value, $type, $message = "%s") {
- parent::assertTrue(gettype($value) == strtolower($type), $message);
+ parent::assert(new TrueExpectation(), gettype($value) == strtolower($type), $message);
}
/**
Modified: 3.x/trunk/limb/tests_runner/lib/simpletest/extensions/phpunit_test_case.php
===================================================================
--- 3.x/trunk/limb/tests_runner/lib/simpletest/extensions/phpunit_test_case.php 2007-06-18 12:28:49 UTC (rev 5998)
+++ 3.x/trunk/limb/tests_runner/lib/simpletest/extensions/phpunit_test_case.php 2007-06-18 13:13:08 UTC (rev 5999)
@@ -1,7 +1,7 @@
<?php
/**
* adapter for SimpleTest to use PHPUnit test cases
- * @package tests_runner
+ * @package SimpleTest
* @subpackage Extensions
* @version $Id$
*/
@@ -16,7 +16,7 @@
/**
* Adapter for sourceforge PHPUnit test case to allow
* legacy test cases to be used with SimpleTest.
- * @package tests_runner
+ * @package SimpleTest
* @subpackage Extensions
*/
class TestCase extends SimpleTestCase {
@@ -26,7 +26,7 @@
* @param $label Test name to display.
* @public
*/
- function TestCase($label) {
+ function TestCase($label = false) {
$this->SimpleTestCase($label);
}
@@ -38,7 +38,7 @@
* @public
*/
function assert($condition, $message = false) {
- parent::assertTrue($condition, $message);
+ parent::assert(new TrueExpectation(), $condition, $message);
}
/**
Added: 3.x/trunk/limb/tests_runner/lib/simpletest/extensions/selenese_tester.php
===================================================================
--- 3.x/trunk/limb/tests_runner/lib/simpletest/extensions/selenese_tester.php (rev 0)
+++ 3.x/trunk/limb/tests_runner/lib/simpletest/extensions/selenese_tester.php 2007-06-18 13:13:08 UTC (rev 5999)
@@ -0,0 +1,393 @@
+<?php
+/**
+ * @package SeleneseTestCase
+ * @subpackage UnitTester
+ * @version $Id: selenese_tester.php,v 1.2 2007/06/06 16:58:53 pp11 Exp $
+ */
+
+/**#@+
+ * include SimpleTest files
+ */
+require_once dirname(__FILE__).'/../unit_tester.php';
+require_once dirname(__FILE__).'/selenium/remote-control.php';
+/**#@-*/
+
+/**
+ * SeleneseTestCase
+ *
+ * Integrate selenese html test suite support (can be generated by selenium-IDE)
+ *
+ * @category Testing
+ * @package selenese_tester
+ * @author Guidet Alexandre <alwex at free.fr>
+ *
+ * @param simpleSelenium $selenium
+ * @param string $html
+ * @param string $testFile
+ * @param array $parsed_table
+ * @param string $logMessages
+ * @param array $_commandMap
+ *
+ */
+class SeleneseTestCase extends UnitTestCase {
+ var $selenium;
+ var $html;
+ var $testFile;
+ var $parsed_table;
+ var $logMessages;
+ var $_commandMap = array("verify",
+ "verifyErrorOnNext",
+ "verifyNotErrorOnNext",
+ "verifyFailureOnNext",
+ "verifyNotFailureOnNext",
+ "verifySelected",
+ "verifyNotSelected",
+ "verifyAlert",
+ "verifyNotAlert",
+ "verifyAllButtons",
+ "verifyNotAllButtons",
+ "verifyAllFields",
+ "verifyNotAllFields",
+ "verifyAllLinks",
+ "verifyNotAllLinks",
+ "verifyAllWindowIds",
+ "verifyNotAllWindowIds",
+ "verifyAllWindowNames",
+ "verifyNotAllWindowNames",
+ "verifyAllWindowTitles",
+ "verifyNotAllWindowTitles",
+ "verifyAttribute",
+ "verifyNotAttribute",
+ "verifyAttributeFromAllWindows",
+ "verifyNotAttributeFromAllWindows",
+ "verifyBodyText",
+ "verifyNotBodyText",
+ "verifyConfirmation",
+ "verifyNotConfirmation",
+ "verifyCookie",
+ "verifyNotCookie",
+ "verifyCursorPosition",
+ "verifyNotCursorPosition",
+ "verifyElementHeight",
+ "verifyNotElementHeight",
+ "verifyElementIndex",
+ "verifyNotElementIndex",
+ "verifyElementPositionLeft",
+ "verifyNotElementPositionLeft",
+ "verifyElementPositionTop",
+ "verifyNotElementPositionTop",
+ "verifyElementWidth",
+ "verifyNotElementWidth",
+ "verifyEval",
+ "verifyNotEval",
+ "verifyExpression",
+ "verifyNotExpression",
+ "verifyHtmlSource",
+ "verifyNotHtmlSource",
+ "verifyLocation",
+ "verifyNotLocation",
+ "verifyLogMessages",
+ "verifyNotLogMessages",
+ "verifyMouseSpeed",
+ "verifyNotMouseSpeed",
+ "verifyPrompt",
+ "verifyNotPrompt",
+ "verifySelectedId",
+ "verifyNotSelectedId",
+ "verifySelectedIds",
+ "verifyNotSelectedIds",
+ "verifySelectedIndex",
+ "verifyNotSelectedIndex",
+ "verifySelectedIndexes",
+ "verifyNotSelectedIndexes",
+ "verifySelectedLabel",
+ "verifyNotSelectedLabel",
+ "verifySelectedLabels",
+ "verifyNotSelectedLabels",
+ "verifySelectedValue",
+ "verifyNotSelectedValue",
+ "verifySelectedValues",
+ "verifyNotSelectedValues",
+ "verifySelectOptions",
+ "verifyNotSelectOptions",
+ "verifyTable",
+ "verifyNotTable",
+ "verifyText",
+ "verifyNotText",
+ "verifyTitle",
+ "verifyNotTitle",
+ "verifyValue",
+ "verifyNotValue",
+ "verifyWhetherThisFrameMatchFrameExpression",
+ "verifyNotWhetherThisFrameMatchFrameExpression",
+ "verifyWhetherThisWindowMatchWindowExpression",
+ "verifyNotWhetherThisWindowMatchWindowExpression",
+ "verifyAlertPresent",
+ "verifyAlertNotPresent",
+ "verifyChecked",
+ "verifyNotChecked",
+ "verifyConfirmationPresent",
+ "verifyConfirmationNotPresent",
+ "verifyEditable",
+ "verifyNotEditable",
+ "verifyElementPresent",
+ "verifyElementNotPresent",
+ "verifyOrdered",
+ "verifyNotOrdered",
+ "verifyPromptPresent",
+ "verifyPromptNotPresent",
+ "verifySomethingSelected",
+ "verifyNotSomethingSelected",
+ "verifyTextPresent",
+ "verifyTextNotPresent",
+ "verifyVisible",
+ "verifyNotVisible",
+ "assert",
+ "assertErrorOnNext",
+ "assertNotErrorOnNext",
+ "assertFailureOnNext",
+ "assertNotFailureOnNext",
+ "assertSelected",
+ "assertNotSelected",
+ "assertAlert",
+ "assertNotAlert",
+ "assertAllButtons",
+ "assertNotAllButtons",
+ "assertAllFields",
+ "assertNotAllFields",
+ "assertAllLinks",
+ "assertNotAllLinks",
+ "assertAllWindowIds",
+ "assertNotAllWindowIds",
+ "assertAllWindowNames",
+ "assertNotAllWindowNames",
+ "assertAllWindowTitles",
+ "assertNotAllWindowTitles",
+ "assertAttribute",
+ "assertNotAttribute",
+ "assertAttributeFromAllWindows",
+ "assertNotAttributeFromAllWindows",
+ "assertBodyText",
+ "assertNotBodyText",
+ "assertConfirmation",
+ "assertNotConfirmation",
+ "assertCookie",
+ "assertNotCookie",
+ "assertCursorPosition",
+ "assertNotCursorPosition",
+ "assertElementHeight",
+ "assertNotElementHeight",
+ "assertElementIndex",
+ "assertNotElementIndex",
+ "assertElementPositionLeft",
+ "assertNotElementPositionLeft",
+ "assertElementPositionTop",
+ "assertNotElementPositionTop",
+ "assertElementWidth",
+ "assertNotElementWidth",
+ "assertEval",
+ "assertNotEval",
+ "assertExpression",
+ "assertNotExpression",
+ "assertHtmlSource",
+ "assertNotHtmlSource",
+ "assertLocation",
+ "assertNotLocation",
+ "assertLogMessages",
+ "assertNotLogMessages",
+ "assertMouseSpeed",
+ "assertNotMouseSpeed",
+ "assertPrompt",
+ "assertNotPrompt",
+ "assertSelectedId",
+ "assertNotSelectedId",
+ "assertSelectedIds",
+ "assertNotSelectedIds",
+ "assertSelectedIndex",
+ "assertNotSelectedIndex",
+ "assertSelectedIndexes",
+ "assertNotSelectedIndexes",
+ "assertSelectedLabel",
+ "assertNotSelectedLabel",
+ "assertSelectedLabels",
+ "assertNotSelectedLabels",
+ "assertSelectedValue",
+ "assertNotSelectedValue",
+ "assertSelectedValues",
+ "assertNotSelectedValues",
+ "assertSelectOptions",
+ "assertNotSelectOptions",
+ "assertTable",
+ "assertNotTable",
+ "assertText",
+ "assertNotText",
+ "assertTitle",
+ "assertNotTitle",
+ "assertValue",
+ "assertNotValue",
+ "assertWhetherThisFrameMatchFrameExpression",
+ "assertNotWhetherThisFrameMatchFrameExpression",
+ "assertWhetherThisWindowMatchWindowExpression",
+ "assertNotWhetherThisWindowMatchWindowExpression",
+ "assertAlertPresent",
+ "assertAlertNotPresent",
+ "assertChecked",
+ "assertNotChecked",
+ "assertConfirmationPresent",
+ "assertConfirmationNotPresent",
+ "assertEditable",
+ "assertNotEditable",
+ "assertElementPresent",
+ "assertElementNotPresent",
+ "assertOrdered",
+ "assertNotOrdered",
+ "assertPromptPresent",
+ "assertPromptNotPresent",
+ "assertSomethingSelected",
+ "assertNotSomethingSelected",
+ "assertTextPresent",
+ "assertTextNotPresent",
+ "assertVisible",
+ "assertNotVisible");
+
+ /**
+ * constructor
+ *
+ * Construct the object with the specified browser and url
+ *
+ * @param string $browser
+ * @param string $url
+ */
+ function __construct($browser, $url) {
+ $this->selenium = new SimpleSeleniumRemoteControl($browser, $url);
+ $this->parsed_table = array();
+ }
+
+ /**
+ * tidy
+ *
+ * Reformat the selenium-IDE html test suites
+ */
+ function tidy() {
+ $tmp = $this->html;
+ preg_match('/<meta.*>/', $tmp, $matche);
+ $matche[0] = str_replace("/>", ">", $matche[0]);
+ $matche[0] = str_replace(">", "/>", $matche[0]);
+ $tmp = preg_replace('/<meta.*>/', $matche[0], $tmp);
+ $this->html = $tmp;
+ }
+
+ /**
+ * parse
+ *
+ * Extract the called selenium fonction from the html suite
+ */
+ function parse() {
+ $parsedTab = array();
+ $key1 = 0;
+
+ $contenthtml = new DOMDocument;
+ @$contenthtml->loadHtml($this->html);
+ $content = simplexml_import_dom($contenthtml);
+ foreach ($content->body->table->tbody->tr as $tr){
+ $key2 = 0;
+ foreach ($tr->td as $td){
+ $parsedTab[$key1][$key2] = $td;
+ $key2++;
+ }
+ $key1++;
+ }
+
+ $this->parsed_table = $parsedTab;
+ }
+
+ /**
+ * assertFunction
+ *
+ * Integrate selenium fonctions in simpletest
+ *
+ * @param string $function
+ * @param string $param1
+ * @param string $param2
+ *
+ */
+ function assertFunction($function, $param1, $param2) {
+ $_verifyMap = array('verify', 'verifyTextPresent', 'verifyTextNotPresent', 'verifyValue');
+
+ $reponse = $this->selenium->__call($function, array($param1, $param2));
+
+ $message = $reponse;
+ $message .= " using command '".$function ."' with target '".$param1."'";
+ if (!empty($param2)) {
+ $message .= " and value '".$param2."'";
+ }
+ $message .= " in file '".$this->testFile."'";
+
+ if (!in_array($function, $_verifyMap)) {
+ $reponse = substr($reponse, 0, 2) == 'OK' ? true : false;
+ }
+
+ $this->assertTrue($reponse, $message);
+ }
+
+ /**
+ * launch
+ *
+ * Launch the html test suite from a PHP variable on the url declared wihle
+ * constructing the object. The filename is used to localize the error.
+ *
+ * @param string $testFile
+ * @param string $filename
+ *
+ */
+ function launch($html="") {
+ $this->html = $html;
+ $this->tidy();
+ $this->parse();
+
+ $this->selenium->start();
+ foreach ($this->parsed_table as $test) {
+ if (in_array($test[0], $this->_commandMap)) {
+ $this->assertFunction($test[0], $test[1], $test[2]);
+ } else {
+ $this->selenium->__call($test[0], array($test[1], $test[2]));
+ }
+ }
+ $this->selenium->stop();
+ }
+
+ /**
+ * launchPhpFile
+ *
+ * Parse the PHP file then launch the computed test suite
+ *
+ * @param string $file
+ *
+ */
+ function launchPhpFile($file) {
+ ob_start();
+ require($file);
+ $data = ob_get_contents();
+ ob_end_clean();
+
+ $this->testFile = $file;
+ $this->html = $data;
+ $this->launch($this->html);
+ }
+
+ /**
+ * launchFile
+ *
+ * Launch the html test suite file on the url declared wihle constructing the object
+ *
+ * @param string $testFile
+ *
+ */
+ function launchFile($testFile) {
+ $this->testFile = $testFile;
+ $this->html = file_get_contents($testFile);
+ $this->launch($this->html);
+ }
+}
+
+?>
Added: 3.x/trunk/limb/tests_runner/lib/simpletest/extensions/selenium/remote-control.php
===================================================================
--- 3.x/trunk/limb/tests_runner/lib/simpletest/extensions/selenium/remote-control.php (rev 0)
+++ 3.x/trunk/limb/tests_runner/lib/simpletest/extensions/selenium/remote-control.php 2007-06-18 13:13:08 UTC (rev 5999)
@@ -0,0 +1,126 @@
+<?php
+
+/**
+ *
+ * Based on the Domain51_Testing_Selenium class available at
+ * http://domain51.googlecode.com/svn/Domain51/trunk/
+ *
+ * @author Travis Swicegood <development [at] domain51 [dot] com>
+ *
+ */
+class SimpleSeleniumRemoteControl
+{
+ private $_browser = '';
+ private $_browserUrl = '';
+ private $_host = 'localhost';
+ private $_port = 4444;
+ private $_timeout = 30000;
+ private $_sessionId = null;
+
+ private $_commandMap = array(
+ 'bool' => array(
+ 'verify',
+ 'verifyTextPresent',
+ 'verifyTextNotPresent',
+ 'verifyValue'
+ ),
+ 'string' => array(
+ 'getNewBrowserSession',
+ ),
+ );
+
+ public function __construct($browser, $browserUrl, $host = 'localhost', $port = 4444, $timeout = 30000) {
+ $this->_browser = $browser;
+ $this->_browserUrl = $browserUrl;
+ $this->_host = $host;
+ $this->_port = $port;
+ $this->_timeout = $timeout;
+ }
+
+ public function sessionIdParser($response) {
+ return substr($response, 3);
+ }
+
+ public function start() {
+ $response = $this->cmd('getNewBrowserSession', array($this->_browser, $this->_browserUrl));
+ $this->_sessionId = $this->sessionIdParser($response);
+ }
+
+ public function stop() {
+ $this->cmd('testComplete');
+ $this->_sessionId = null;
+ }
+
+ public function __call($method, $arguments) {
+ $response = $this->cmd($method, $arguments);
+
+ foreach ($this->_commandMap as $type => $commands) {
+ if (!in_array($method, $commands)) {
+ continue;
+ $type = null;
+ }
+ break;
+ }
+
+ switch ($type) {
+ case 'bool' :
+ return substr($response, 0, 2) == 'OK' ? true : false;
+ break;
+
+ case 'string' :
+ default:
+ return $response;
+ }
+ }
+
+ private function _server() {
+ return "http://{$this->_host}:{$this->_port}/selenium-server/driver/";
+ }
+
+ public function buildUrlCmd($method, $arguments = array()) {
+ $params = array(
+ 'cmd=' . urlencode($method),
+ );
+ $i = 1;
+ foreach ($arguments as $param) {
+ $params[] = $i++ . '=' . urlencode(trim($param));
+ }
+ if (isset($this->_sessionId)) {
+ $params[] = 'sessionId=' . $this->_sessionId;
+ }
+
+ return $this->_server()."?".implode('&', $params);
+ }
+
+ public function cmd($method, $arguments = array()) {
+ $url = $this->buildUrlCmd($method, $arguments);
+ $response = $this->_sendRequest($url);
+ return $response;
+ }
+
+ public function isUp() {
+ return (bool)@fsockopen($this->_host, $this->_port, $errno, $errstr, 30);
+ }
+
+ private function _initCurl($url) {
+ if (!function_exists('curl_init')) {
+ throw new Exception('this code currently requires the curl extension');
+ }
+ if (!$ch = curl_init($url)) {
+ throw new Exception('Unable to setup curl');
+ }
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+ curl_setopt($ch, CURLOPT_TIMEOUT, floor($this->_timeout));
+ return $ch;
+ }
+
+ private function _sendRequest($url) {
+ $ch = $this->_initCurl($url);
+ $result = curl_exec($ch);
+ if (($errno = curl_errno($ch)) != 0) {
+ throw new Exception('Curl returned non-null errno ' . $errno . ':' . curl_error($ch));
+ }
+ curl_close($ch);
+ return $result;
+ }
+}
Added: 3.x/trunk/limb/tests_runner/lib/simpletest/extensions/selenium/remote-control_test.php
===================================================================
--- 3.x/trunk/limb/tests_runner/lib/simpletest/extensions/selenium/remote-control_test.php (rev 0)
+++ 3.x/trunk/limb/tests_runner/lib/simpletest/extensions/selenium/remote-control_test.php 2007-06-18 13:13:08 UTC (rev 5999)
@@ -0,0 +1,36 @@
+<?php
+
+// $Id: remote-control_test.php,v 1.2 2007/06/06 16:58:53 pp11 Exp $
+
+require_once(dirname(__FILE__) . '/../../autorun.php');
+require_once(dirname(__FILE__) . '/remote-control.php');
+
+class TestOfSimpleSeleniumRemoteControl extends UnitTestCase {
+ function testSesssionIdShouldBePreserved() {
+ $remote_control = new SimpleSeleniumRemoteControl("tester", "http://simpletest.org/");
+ $this->assertEqual($remote_control->sessionIdParser('OK,123456789123456789'), '123456789123456789');
+ }
+
+ function testIsUpReturnsFalseWhenDirectedToLocalhostDown() {
+ $remote_control = new SimpleSeleniumRemoteControl("tester", "http://simpletest.org/", "localhost-down");;
+ $this->assertFalse($remote_control->isUp());
+ }
+
+ function testIsUpReturnsTrueWhenDirectedToLocalhostOnPort80() {
+ $remote_control = new SimpleSeleniumRemoteControl("tester", "http://simpletest.org/", "localhost", "80");
+ $this->assertTrue($remote_control->isUp());
+ }
+
+ function testIsUpReturnsTrue() {
+ $remote_control = new SimpleSeleniumRemoteControl("*custom opera -nosession", "http://simpletest.org/");
+ $this->assertTrue($remote_control->isUp());
+ }
+
+ function testOfCommandCreation() {
+ $remote_control = new SimpleSeleniumRemoteControl("tester", "http://simpletest.org/");
+ $this->assertEqual($remote_control->buildUrlCmd("test"), 'http://localhost:4444/selenium-server/driver/?cmd=test');
+ $this->assertEqual($remote_control->buildUrlCmd("test", array("next")), 'http://localhost:4444/selenium-server/driver/?cmd=test&1=next');
+ $this->assertEqual($remote_control->buildUrlCmd("test", array("t")), 'http://localhost:4444/selenium-server/driver/?cmd=test&1=%C3%A9t%C3%A9');
+ $this->assertEqual($remote_control->buildUrlCmd("test", array("next", "then")), 'http://localhost:4444/selenium-server/driver/?cmd=test&1=next&2=then');
+ }
+}
\ No newline at end of file
Added: 3.x/trunk/limb/tests_runner/lib/simpletest/extensions/selenium.php
===================================================================
--- 3.x/trunk/limb/tests_runner/lib/simpletest/extensions/selenium.php (rev 0)
+++ 3.x/trunk/limb/tests_runner/lib/simpletest/extensions/selenium.php 2007-06-18 13:13:08 UTC (rev 5999)
@@ -0,0 +1,117 @@
+<?php
+
+require_once dirname(__FILE__) . '/../unit_tester.php';
+require_once dirname(__FILE__) . '/selenium/remote-control.php';
+
+class SeleniumTestCase extends UnitTestCase
+{
+ /**#@+
+ * Selenium instantiation variables
+ */
+ protected $browser = '';
+ protected $browserUrl = '';
+ protected $host = 'localhost';
+ protected $port = '4444';
+ protected $timeout = 30000;
+ /**#@-*/
+
+ protected $selenium = null;
+ protected $newInstanceEachTest = true;
+
+ public function __construct($name = 'Selenium Test Case') {
+ parent::UnitTestCase($name);
+
+ if (empty($this->browser)) {
+ trigger_error('browser property must be set in ' . get_class($this));
+ exit;
+ }
+
+ if (empty($this->browserUrl)) {
+ trigger_error('browserUrl property must be set in ' . get_class($this));
+ exit;
+ }
+ }
+
+ public function setUp() {
+ parent::setUp();
+
+ if (is_null($this->selenium)) {
+ $this->selenium = new SimpleSeleniumRemoteControl(
+ $this->browser,
+ $this->browserUrl,
+ $this->host,
+ $this->port,
+ $this->timeout
+ );
+ $this->selenium->start();
+ }
+ }
+
+ public function tearDown() {
+ parent::tearDown();
+
+ if ($this->newInstanceEachTest) {
+ $this->selenium->stop();
+ $this->selenium = null;
+ }
+ }
+
+ public function __call($method, $arguments) {
+ return call_user_func_array(
+ array($this->selenium, $method),
+ $arguments
+ );
+ }
+
+ public function verifyText($text) {
+ return $this->assertTrue(
+ $this->selenium->verifyText($text),
+ sprintf(
+ 'verifyText failed when on [%s]',
+ $text
+ )
+ );
+ }
+
+ public function verifyTextPresent($text) {
+ return $this->assertTrue(
+ $this->selenium->verifyTextPresent($text),
+ sprintf(
+ 'verifyTextPresent failed when on [%s]',
+ $text
+ )
+ );
+ }
+
+ public function verifyTextNotPresent($text) {
+ return $this->assertTrue(
+ $this->selenium->verifyTextNotPresent($text),
+ sprintf(
+ 'verifyTextNotPresent failed on [%s]',
+ $text
+ )
+ );
+ }
+
+ public function verifyValue($selector, $value) {
+ return $this->assertTrue(
+ $this->selenium->verifyValue($selector, $value),
+ sprintf(
+ 'verifyValue failed on [%s] == [%s]',
+ $selector,
+ $value
+ )
+ );
+ }
+
+ public function verifyTitle($pattern) {
+ return $this->assertTrue(
+ $this->selenium->verifyTitle($pattern),
+ sprintf(
+ 'verifyTitle failed on [%s]',
+ $pattern
+ )
+ );
+ }
+}
+
Added: 3.x/trunk/limb/tests_runner/lib/simpletest/extensions/testdox.php
===================================================================
--- 3.x/trunk/limb/tests_runner/lib/simpletest/extensions/testdox.php (rev 0)
+++ 3.x/trunk/limb/tests_runner/lib/simpletest/extensions/testdox.php 2007-06-18 13:13:08 UTC (rev 5999)
@@ -0,0 +1,42 @@
+<?php
+
+class TestDoxReporter extends SimpleReporter
+{
+ var $_test_case_pattern = '/^TestOf(.*)$/';
+
+ function TestDoxReporter($test_case_pattern = '/^TestOf(.*)$/') {
+ parent::SimpleScorer();
+ $this->_test_case_pattern = empty($test_case_pattern) ? '/^(.*)$/' : $test_case_pattern;
+ }
+
+ function paintCaseStart($test_name) {
+ preg_match($this->_test_case_pattern, $test_name, $matches);
+ if (!empty($matches[1])) {
+ echo $matches[1] . "\n";
+ } else {
+ echo $test_name . "\n";
+ }
+ }
+
+ function paintCaseEnd() {
+ echo "\n";
+ }
+
+ function paintMethodStart($test_name) {
+ if (!preg_match('/^test(.*)$/i', $test_name, $matches)) {
+ return;
+ }
+ $test_name = $matches[1];
+
+ $test_name = preg_replace('/([A-Z])([A-Z])/', '$1 $2', $test_name);
+ echo '- ' . strtolower(preg_replace('/([a-zA-Z])([A-Z0-9])/', '$1 $2', $test_name));
+ }
+
+ function paintMethodEnd() {
+ echo "\n";
+ }
+
+ function paintFail() {
+ echo " [FAILED]";
+ }
+}
Modified: 3.x/trunk/limb/tests_runner/lib/simpletest/form.php
===================================================================
--- 3.x/trunk/limb/tests_runner/lib/simpletest/form.php 2007-06-18 12:28:49 UTC (rev 5998)
+++ 3.x/trunk/limb/tests_runner/lib/simpletest/form.php 2007-06-18 13:13:08 UTC (rev 5999)
@@ -1,7 +1,7 @@
<?php
/**
* Base include file for SimpleTest.
- * @package tests_runner
+ * @package SimpleTest
* @subpackage WebTester
* @version $Id$
*/
@@ -16,7 +16,7 @@
/**
* Form tag class to hold widget values.
- * @package tests_runner
+ * @package SimpleTest
* @subpackage WebTester
*/
class SimpleForm {
Modified: 3.x/trunk/limb/tests_runner/lib/simpletest/frames.php
===================================================================
--- 3.x/trunk/limb/tests_runner/lib/simpletest/frames.php 2007-06-18 12:28:49 UTC (rev 5998)
+++ 3.x/trunk/limb/tests_runner/lib/simpletest/frames.php 2007-06-18 13:13:08 UTC (rev 5999)
@@ -1,7 +1,7 @@
<?php
/**
* Base include file for SimpleTest
- * @package tests_runner
+ * @package SimpleTest
* @subpackage WebTester
* @version $Id$
*/
@@ -18,7 +18,7 @@
* adds subframes. The original page will be
* mostly ignored. Implements the SimplePage
* interface so as to be interchangeable.
- * @package tests_runner
+ * @package SimpleTest
* @subpackage WebTester
*/
class SimpleFrameset {
Modified: 3.x/trunk/limb/tests_runner/lib/simpletest/http.php
===================================================================
--- 3.x/trunk/limb/tests_runner/lib/simpletest/http.php 2007-06-18 12:28:49 UTC (rev 5998)
+++ 3.x/trunk/limb/tests_runner/lib/simpletest/http.php 2007-06-18 13:13:08 UTC (rev 5999)
@@ -1,7 +1,7 @@
<?php
/**
* base include file for SimpleTest
- * @package tests_runner
+ * @package SimpleTest
* @subpackage WebTester
* @version $Id$
*/
@@ -17,7 +17,7 @@
/**
* Creates HTTP headers for the end point of
* a HTTP request.
- * @package tests_runner
+ * @package SimpleTest
* @subpackage WebTester
*/
class SimpleRoute {
@@ -109,7 +109,7 @@
/**
* Creates HTTP headers for the end point of
* a HTTP request via a proxy server.
- * @package tests_runner
+ * @package SimpleTest
* @subpackage WebTester
*/
class SimpleProxyRoute extends SimpleRoute {
@@ -190,7 +190,7 @@
/**
* HTTP request for a web page. Factory for
* HttpResponse object.
- * @package tests_runner
+ * @package SimpleTest
* @subpackage WebTester
*/
class SimpleHttpRequest {
@@ -289,7 +289,7 @@
/**
* Collection of header lines in the response.
- * @package tests_runner
+ * @package SimpleTest
* @subpackage WebTester
*/
class SimpleHttpHeaders {
@@ -475,7 +475,7 @@
/**
* Basic HTTP response.
- * @package tests_runner
+ * @package SimpleTest
* @subpackage WebTester
*/
class SimpleHttpResponse extends SimpleStickyError {
Modified: 3.x/trunk/limb/tests_runner/lib/simpletest/invoker.php
===================================================================
--- 3.x/trunk/limb/tests_runner/lib/simpletest/invoker.php 2007-06-18 12:28:49 UTC (rev 5998)
+++ 3.x/trunk/limb/tests_runner/lib/simpletest/invoker.php 2007-06-18 13:13:08 UTC (rev 5999)
@@ -1,7 +1,7 @@
<?php
/**
* Base include file for SimpleTest
- * @package tests_runner
+ * @package SimpleTest
* @subpackage UnitTester
* @version $Id$
*/
@@ -24,7 +24,7 @@
* This is called by the class runner to run a
* single test method. Will also run the setUp()
* and tearDown() methods.
- * @package tests_runner
+ * @package SimpleTest
* @subpackage UnitTester
*/
class SimpleInvoker {
@@ -83,7 +83,7 @@
/**
* Do nothing decorator. Just passes the invocation
* straight through.
- * @package tests_runner
+ * @package SimpleTest
* @subpackage UnitTester
*/
class SimpleInvokerDecorator {
Modified: 3.x/trunk/limb/tests_runner/lib/simpletest/mock_objects.php
===================================================================
--- 3.x/trunk/limb/tests_runner/lib/simpletest/mock_objects.php 2007-06-18 12:28:49 UTC (rev 5998)
+++ 3.x/trunk/limb/tests_runner/lib/simpletest/mock_objects.php 2007-06-18 13:13:08 UTC (rev 5999)
@@ -1,7 +1,7 @@
<?php
/**
* base include file for SimpleTest
- * @package tests_runner
+ * @package SimpleTest
* @subpackage MockObjects
* @version $Id$
*/
@@ -28,7 +28,7 @@
/**
* Parameter comparison assertion.
- * @package tests_runner
+ * @package SimpleTest
* @subpackage MockObjects
*/
class ParametersExpectation extends SimpleExpectation {
@@ -161,7 +161,7 @@
/**
* Confirms that the number of calls on a method is as expected.
- * @package tests_runner
+ * @package SimpleTest
* @subpackage MockObjects
*/
class CallCountExpectation extends SimpleExpectation {
@@ -206,7 +206,7 @@
/**
* Confirms that the number of calls on a method is as expected.
- * @package tests_runner
+ * @package SimpleTest
* @subpackage MockObjects
*/
class MinimumCallCountExpectation extends SimpleExpectation {
@@ -251,7 +251,7 @@
/**
* Confirms that the number of calls on a method is as expected.
- * @package tests_runner
+ * @package SimpleTest
* @subpackage MockObjects
*/
class MaximumCallCountExpectation extends SimpleExpectation {
@@ -297,7 +297,7 @@
/**
* Retrieves values and references by searching the
* parameter lists until a match is found.
- * @package tests_runner
+ * @package SimpleTest
* @subpackage MockObjects
*/
class CallMap {
@@ -389,7 +389,7 @@
* calls upon them. The mock will assert the
* expectations against it's attached test case in
* addition to the server stub behaviour.
- * @package tests_runner
+ * @package SimpleTest
* @subpackage MockObjects
*/
class SimpleMock {
@@ -406,23 +406,19 @@
/**
* 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.
*/
function SimpleMock() {
$this->_returns = array();
$this->_return_sequence = array();
$this->_call_counts = array();
- $test = &$this->_getCurrentTestCase();
- $test->tell($this);
$this->_expected_counts = array();
$this->_max_counts = array();
$this->_expected_args = array();
$this->_expected_args_at = array();
+ $test = &$this->_getCurrentTestCase();
+ $test->tell($this);
}
-
+
/**
* Disables a name check when setting expectations.
* This hack is needed for the partial mocks.
@@ -744,7 +740,7 @@
function expectOnce($method, $args = false, $message = '%s') {
$this->expectCallCount($method, 1, $message);
if ($args !== false) {
- $this->expectArguments($method, $args, $message);
+ $this->expect($method, $args, $message);
}
}
@@ -760,7 +756,7 @@
function expectAtLeastOnce($method, $args = false, $message = '%s') {
$this->expectMinimumCallCount($method, 1, $message);
if ($args !== false) {
- $this->expectArguments($method, $args, $message);
+ $this->expect($method, $args, $message);
}
}
@@ -775,8 +771,8 @@
* test method has finished. Totals up the call
* counts and triggers a test assertion if a test
* is present for expected call counts.
- * @param string $test_method Current method name.
- * @param SimpleTestCase $test Test to send message to.
+ * @param string $test_method Current method name.
+ * @param SimpleTestCase $test Test to send message to.
* @access public
*/
function atTestEnd($test_method, &$test) {
@@ -866,7 +862,7 @@
/**
* Static methods only service class for code generation of
* mock objects.
- * @package tests_runner
+ * @package SimpleTest
* @subpackage MockObjects
*/
class Mock {
@@ -896,14 +892,6 @@
*/
function generate($class, $mock_class = false, $methods = false) {
$generator = new MockGenerator($class, $mock_class);
- return $generator->generate($methods);
- }
-
- /**
- * Temporary method while refactoring.
- */
- function generateSubclass($class, $mock_class = false, $methods = array()) {
- $generator = new MockGenerator($class, $mock_class);
return $generator->generateSubclass($methods);
}
@@ -936,8 +924,8 @@
}
/**
- * @package tests_runner
- * @subpackage MockObjects
+ * @package SimpleTest
+ * @subpackage MockObjects
* @deprecated
*/
class Stub extends Mock {
@@ -945,7 +933,7 @@
/**
* Service class for code generation of mock objects.
- * @package tests_runner
+ * @package SimpleTest
* @subpackage MockObjects
*/
class MockGenerator {
@@ -954,6 +942,12 @@
var $_mock_base;
var $_reflection;
+ /**
+ * Builds initial reflection object.
+ * @param string $class Class to be mocked.
+ * @param string $mock_class New class with identical interface,
+ * but no behaviour.
+ */
function MockGenerator($class, $mock_class) {
$this->_class = $class;
$this->_mock_class = $mock_class;
@@ -982,16 +976,16 @@
if ($mock_reflection->classExistsSansAutoload()) {
return false;
}
- return eval(
- $this->_createClassCode($methods ? $methods : array()) .
- " return true;");
+ $code = $this->_createClassCode($methods ? $methods : array());
+ return eval("$code return \$code;");
}
/**
- * Subclasses a class and overrides every method with a mock one.
- * that can have return values and expectations set.
+ * Subclasses a class and overrides every method with a mock one
+ * that can have return values and expectations set. Chains
+ * to an aggregated SimpleMock.
* @param array $methods Additional methods to add beyond
- * those in th cloned class. Use this
+ * 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.
@@ -1005,14 +999,12 @@
if ($mock_reflection->classExistsSansAutoload()) {
return false;
}
- if ($this->_reflection->isInterface()) {
- return eval(
- $this->_createClassCode($methods ? $methods : array()) .
- " return true;");
+ if ($this->_reflection->isInterface() || $this->_reflection->hasFinal()) {
+ $code = $this->_createClassCode($methods ? $methods : array());
+ return eval("$code return \$code;");
} else {
- return eval(
- $this->_createSubclassCode($methods ? $methods : array()) .
- " return true;");
+ $code = $this->_createSubclassCode($methods ? $methods : array());
+ return eval("$code return \$code;");
}
}
@@ -1034,7 +1026,8 @@
trigger_error('Partial mock class [' . $this->_mock_class . '] already exists');
return false;
}
- return eval($this->_extendClassCode($methods));
+ $code = $this->_extendClassCode($methods);
+ return eval("$code return \$code;");
}
/**
@@ -1189,7 +1182,9 @@
* @access private
*/
function _addMethodList($methods) {
- return " var \$_mocked_methods = array('" . implode("', '", $methods) . "');\n";
+ return " var \$_mocked_methods = array('" .
+ implode("', '", array_map('strtolower', $methods)) .
+ "');\n";
}
/**
@@ -1199,7 +1194,7 @@
* @access private
*/
function _bailOutIfNotMocked($alias) {
- $code = " if (! in_array($alias, \$this->_mocked_methods)) {\n";
+ $code = " if (! in_array(strtolower($alias), \$this->_mocked_methods)) {\n";
$code .= " trigger_error(\"Method [$alias] is not mocked\");\n";
$code .= " \$null = null;\n";
$code .= " return \$null;\n";
@@ -1281,7 +1276,6 @@
$code .= " \$this->_mock->expectAtLeastOnce(\$method, \$args, \$msg);\n";
$code .= " }\n";
$code .= " function tally() {\n";
- $code .= " \$this->_mock->tally();\n";
$code .= " }\n";
return $code;
}
Modified: 3.x/trunk/limb/tests_runner/lib/simpletest/page.php
===================================================================
--- 3.x/trunk/limb/tests_runner/lib/simpletest/page.php 2007-06-18 12:28:49 UTC (rev 5998)
+++ 3.x/trunk/limb/tests_runner/lib/simpletest/page.php 2007-06-18 13:13:08 UTC (rev 5999)
@@ -1,7 +1,7 @@
<?php
/**
* Base include file for SimpleTest
- * @package tests_runner
+ * @package SimpleTest
* @subpackage WebTester
* @version $Id$
*/
@@ -19,7 +19,7 @@
/**
* Creates tags and widgets given HTML tag
* attributes.
- * @package tests_runner
+ * @package SimpleTest
* @subpackage WebTester
*/
class SimpleTagBuilder {
@@ -113,7 +113,7 @@
/**
* SAX event handler. Maintains a list of
* open tags and dispatches them as they close.
- * @package tests_runner
+ * @package SimpleTest
* @subpackage WebTester
*/
class SimplePageBuilder extends SimpleSaxListener {
@@ -327,7 +327,7 @@
/**
* A wrapper for a web page.
- * @package tests_runner
+ * @package SimpleTest
* @subpackage WebTester
*/
class SimplePage {
Modified: 3.x/trunk/limb/tests_runner/lib/simpletest/parser.php
===================================================================
--- 3.x/trunk/limb/tests_runner/lib/simpletest/parser.php 2007-06-18 12:28:49 UTC (rev 5998)
+++ 3.x/trunk/limb/tests_runner/lib/simpletest/parser.php 2007-06-18 13:13:08 UTC (rev 5999)
@@ -1,7 +1,7 @@
<?php
/**
* base include file for SimpleTest
- * @package tests_runner
+ * @package SimpleTest
* @subpackage MockObjects
* @version $Id$
*/
@@ -30,7 +30,7 @@
* Compounded regular expression. Any of
* the contained patterns could match and
* when one does, it's label is returned.
- * @package tests_runner
+ * @package SimpleTest
* @subpackage WebTester
*/
class ParallelRegex {
@@ -126,7 +126,7 @@
/**
* States for a stack machine.
- * @package tests_runner
+ * @package SimpleTest
* @subpackage WebTester
*/
class SimpleStateStack {
@@ -182,7 +182,7 @@
* content is only scanned by the PHP regex
* parser once. Lexer modes must not start
* with leading underscores.
- * @package tests_runner
+ * @package SimpleTest
* @subpackage WebTester
*/
class SimpleLexer {
@@ -452,7 +452,7 @@
/**
* Breas HTML into SAX events.
- * @package tests_runner
+ * @package SimpleTest
* @subpackage WebTester
*/
class SimpleHtmlLexer extends SimpleLexer {
@@ -545,7 +545,7 @@
/**
* Converts HTML tokens into selected SAX events.
- * @package tests_runner
+ * @package SimpleTest
* @subpackage WebTester
*/
class SimpleHtmlSaxParser {
@@ -729,7 +729,7 @@
/**
* SAX event handler.
- * @package tests_runner
+ * @package SimpleTest
* @subpackage WebTester
* @abstract
*/
Modified: 3.x/trunk/limb/tests_runner/lib/simpletest/reflection_php4.php
===================================================================
--- 3.x/trunk/limb/tests_runner/lib/simpletest/reflection_php4.php 2007-06-18 12:28:49 UTC (rev 5998)
+++ 3.x/trunk/limb/tests_runner/lib/simpletest/reflection_php4.php 2007-06-18 13:13:08 UTC (rev 5999)
@@ -1,14 +1,14 @@
<?php
/**
* base include file for SimpleTest
- * @package tests_runner
+ * @package SimpleTest
* @subpackage UnitTester
* @version $Id$
*/
/**
* Version specific reflection API.
- * @package tests_runner
+ * @package SimpleTest
* @subpackage UnitTester
* @ignore duplicate with reflection_php5.php
*/
@@ -112,6 +112,16 @@
function isInterface() {
return false;
}
+
+ /**
+ * Scans for final methods, but as it's PHP 4 there
+ * aren't any.
+ * @returns boolean True if the class has a final method.
+ * @access public
+ */
+ function hasFinal() {
+ return false;
+ }
/**
* Gets the source code matching the declaration
Modified: 3.x/trunk/limb/tests_runner/lib/simpletest/reflection_php5.php
===================================================================
--- 3.x/trunk/limb/tests_runner/lib/simpletest/reflection_php5.php 2007-06-18 12:28:49 UTC (rev 5998)
+++ 3.x/trunk/limb/tests_runner/lib/simpletest/reflection_php5.php 2007-06-18 13:13:08 UTC (rev 5999)
@@ -1,302 +1,371 @@
<?php
- /**
- * base include file for SimpleTest
- * @package tests_runner
- * @subpackage UnitTester
- * @version $Id$
- */
+/**
+ * base include file for SimpleTest
+ * @package SimpleTest
+ * @subpackage UnitTester
+ * @version $Id$
+ */
- /**
- * Version specific reflection API.
- * @package tests_runner
- * @subpackage UnitTester
- */
- class SimpleReflection {
- var $_interface;
+/**
+ * Version specific reflection API.
+ * @package SimpleTest
+ * @subpackage UnitTester
+ */
+class SimpleReflection {
+ var $_interface;
- /**
- * Stashes the class/interface.
- * @param string $interface Class or interface
- * to inspect.
- */
- function SimpleReflection($interface) {
- $this->_interface = $interface;
- }
+ /**
+ * Stashes the class/interface.
+ * @param string $interface Class or interface
+ * to inspect.
+ */
+ function SimpleReflection($interface) {
+ $this->_interface = $interface;
+ }
- /**
- * Checks that a class has been declared. Versions
- * before PHP5.0.2 need a check that it's not really
- * an interface.
- * @return boolean True if defined.
- * @access public
- */
- function classExists() {
- if (! class_exists($this->_interface)) {
- return false;
- }
- $reflection = new ReflectionClass($this->_interface);
- return ! $reflection->isInterface();
- }
+ /**
+ * Checks that a class has been declared. Versions
+ * before PHP5.0.2 need a check that it's not really
+ * an interface.
+ * @return boolean True if defined.
+ * @access public
+ */
+ function classExists() {
+ if (! class_exists($this->_interface)) {
+ return false;
+ }
+ $reflection = new ReflectionClass($this->_interface);
+ return ! $reflection->isInterface();
+ }
- /**
- * Needed to kill the autoload feature in PHP5
- * for classes created dynamically.
- * @return boolean True if defined.
- * @access public
- */
- function classExistsSansAutoload() {
- return class_exists($this->_interface, false);
- }
+ /**
+ * Needed to kill the autoload feature in PHP5
+ * for classes created dynamically.
+ * @return boolean True if defined.
+ * @access public
+ */
+ function classExistsSansAutoload() {
+ return class_exists($this->_interface, false);
+ }
- /**
- * Checks that a class or interface has been
- * declared.
- * @return boolean True if defined.
- * @access public
- */
- function classOrInterfaceExists() {
- return $this->_classOrInterfaceExistsWithAutoload($this->_interface, true);
- }
+ /**
+ * Checks that a class or interface has been
+ * declared.
+ * @return boolean True if defined.
+ * @access public
+ */
+ function classOrInterfaceExists() {
+ return $this->_classOrInterfaceExistsWithAutoload($this->_interface, true);
+ }
- /**
- * Needed to kill the autoload feature in PHP5
- * for classes created dynamically.
- * @return boolean True if defined.
- * @access public
- */
- function classOrInterfaceExistsSansAutoload() {
- return $this->_classOrInterfaceExistsWithAutoload($this->_interface, false);
- }
+ /**
+ * Needed to kill the autoload feature in PHP5
+ * for classes created dynamically.
+ * @return boolean True if defined.
+ * @access public
+ */
+ function classOrInterfaceExistsSansAutoload() {
+ return $this->_classOrInterfaceExistsWithAutoload($this->_interface, false);
+ }
- /**
- * Needed to select the autoload feature in PHP5
- * for classes created dynamically.
- * @param string $interface Class or interface name.
- * @param boolean $autoload True totriggerautoload.
- * @return boolean True if interface defined.
- * @access private
- */
- function _classOrInterfaceExistsWithAutoload($interface, $autoload) {
- if (function_exists('interface_exists')) {
- if (interface_exists($this->_interface, $autoload)) {
- return true;
- }
- }
- return class_exists($this->_interface, $autoload);
- }
+ /**
+ * Needed to select the autoload feature in PHP5
+ * for classes created dynamically.
+ * @param string $interface Class or interface name.
+ * @param boolean $autoload True totriggerautoload.
+ * @return boolean True if interface defined.
+ * @access private
+ */
+ function _classOrInterfaceExistsWithAutoload($interface, $autoload) {
+ if (function_exists('interface_exists')) {
+ if (interface_exists($this->_interface, $autoload)) {
+ return true;
+ }
+ }
+ return class_exists($this->_interface, $autoload);
+ }
- /**
- * Gets the list of methods on a class or
- * interface. Needs to recursively look at all of
- * the interfaces included.
- * @returns array List of method names.
- * @access public
- */
- function getMethods() {
- return array_unique(get_class_methods($this->_interface));
- }
+ /**
+ * Gets the list of methods on a class or
+ * interface.
+ * @returns array List of method names.
+ * @access public
+ */
+ function getMethods() {
+ return array_unique(get_class_methods($this->_interface));
+ }
- /**
- * Gets the list of interfaces from a class. If the
- * class name is actually an interface then just that
- * interface is returned.
- * @returns array List of interfaces.
- * @access public
- */
- function getInterfaces() {
- $reflection = new ReflectionClass($this->_interface);
- if ($reflection->isInterface()) {
- return array($this->_interface);
- }
- return $this->_onlyParents($reflection->getInterfaces());
- }
+ /**
+ * Gets the list of interfaces from a class. If the
+ * class name is actually an interface then just that
+ * interface is returned.
+ * @returns array List of interfaces.
+ * @access public
+ */
+ function getInterfaces() {
+ $reflection = new ReflectionClass($this->_interface);
+ if ($reflection->isInterface()) {
+ return array($this->_interface);
+ }
+ return $this->_onlyParents($reflection->getInterfaces());
+ }
- /**
- * Gets the list of methods for the implemented
- * interfaces only.
- * @returns array List of enforced method signatures.
- * @access public
- */
- function getInterfaceMethods() {
- $methods = array();
- foreach ($this->getInterfaces() as $interface) {
- $methods = array_merge($methods, get_class_methods($interface));
- }
- return array_unique($methods);
- }
-
- /**
- * Checks to see if the method signature has to be tightly
- * specified.
- * @param string $method Method name.
- * @returns boolean True if enforced.
- * @access private
- */
- function _isInterfaceMethod($method) {
- return in_array($method, $this->getInterfaceMethods());
- }
+ /**
+ * Gets the list of methods for the implemented
+ * interfaces only.
+ * @returns array List of enforced method signatures.
+ * @access public
+ */
+ function getInterfaceMethods() {
+ $methods = array();
+ foreach ($this->getInterfaces() as $interface) {
+ $methods = array_merge($methods, get_class_methods($interface));
+ }
+ return array_unique($methods);
+ }
- /**
- * Finds the parent class name.
- * @returns string Parent class name.
- * @access public
- */
- function getParent() {
- $reflection = new ReflectionClass($this->_interface);
- $parent = $reflection->getParentClass();
- if ($parent) {
- return $parent->getName();
- }
- return false;
- }
+ /**
+ * Checks to see if the method signature has to be tightly
+ * specified.
+ * @param string $method Method name.
+ * @returns boolean True if enforced.
+ * @access private
+ */
+ function _isInterfaceMethod($method) {
+ return in_array($method, $this->getInterfaceMethods());
+ }
- /**
- * Determines if the class is abstract.
- * @returns boolean True if abstract.
- * @access public
- */
- function isAbstract() {
- $reflection = new ReflectionClass($this->_interface);
- return $reflection->isAbstract();
- }
+ /**
+ * Finds the parent class name.
+ * @returns string Parent class name.
+ * @access public
+ */
+ function getParent() {
+ $reflection = new ReflectionClass($this->_interface);
+ $parent = $reflection->getParentClass();
+ if ($parent) {
+ return $parent->getName();
+ }
+ return false;
+ }
- /**
- * Determines if the class is an interface.
- * @returns boolean True if interface.
- * @access public
- */
- function isInterface() {
- $reflection = new ReflectionClass($this->_interface);
- return $reflection->isInterface();
- }
+ /**
+ * Trivially determines if the class is abstract.
+ * @returns boolean True if abstract.
+ * @access public
+ */
+ function isAbstract() {
+ $reflection = new ReflectionClass($this->_interface);
+ return $reflection->isAbstract();
+ }
- /**
- * Whittles a list of interfaces down to only the top
- * level parents.
- * @param array $interfaces Reflection API interfaces
- * to reduce.
- * @returns array List of parent interface names.
- * @access private
- */
- function _onlyParents($interfaces) {
- $parents = array();
- $blacklist = array();
- foreach ($interfaces as $interface) {
- foreach($interfaces as $possible_parent) {
- if ($interface->getName() == $possible_parent->getName()) {
- continue;
- }
- if ($interface->isSubClassOf($possible_parent)) {
- $blacklist[$possible_parent->getName()] = true;
- }
- }
- if (!isset($blacklist[$interface->getName()])) {
- $parents[] = $interface->getName();
- }
- }
- return $parents;
+ /**
+ * Trivially determines if the class is an interface.
+ * @returns boolean True if interface.
+ * @access public
+ */
+ function isInterface() {
+ $reflection = new ReflectionClass($this->_interface);
+ return $reflection->isInterface();
+ }
+
+ /**
+ * Scans for final methods, as they screw up inherited
+ * mocks by not allowing you to override them.
+ * @returns boolean True if the class has a final method.
+ * @access public
+ */
+ function hasFinal() {
+ $reflection = new ReflectionClass($this->_interface);
+ foreach ($reflection->getMethods() as $method) {
+ if ($method->isFinal()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Whittles a list of interfaces down to only the
+ * necessary top level parents.
+ * @param array $interfaces Reflection API interfaces
+ * to reduce.
+ * @returns array List of parent interface names.
+ * @access private
+ */
+ function _onlyParents($interfaces) {
+ $parents = array();
+ $blacklist = array();
+ foreach ($interfaces as $interface) {
+ foreach($interfaces as $possible_parent) {
+ if ($interface->getName() == $possible_parent->getName()) {
+ continue;
+ }
+ if ($interface->isSubClassOf($possible_parent)) {
+ $blacklist[$possible_parent->getName()] = true;
+ }
+ }
+ if (!isset($blacklist[$interface->getName()])) {
+ $parents[] = $interface->getName();
+ }
+ }
+ return $parents;
+ }
+
+ /**
+ * Checks whether a method is abstract or not.
+ *
+ * @param string $name Method name.
+ * @return bool true if method is abstract, else false
+ * @access private
+ */
+ function _isAbstractMethod($name) {
+ $interface = new ReflectionClass($this->_interface);
+ if (! $interface->hasMethod($name)) {
+ return false;
}
+ return $interface->getMethod($name)->isAbstract();
+ }
- /**
- * Gets the source code matching the declaration
- * of a method.
- * @param string $name Method name.
- * @return string Method signature up to last
- * bracket.
- * @access public
- */
- function getSignature($name) {
- if ($name == '__set') {
- return 'function __set($key, $value)';
- }
- if ($name == '__call') {
- return 'function __call($method, $arguments)';
- }
- if (version_compare(phpversion(), '5.1.0', '>=')) {
- if (in_array($name, array('__get', '__isset', $name == '__unset'))) {
- return "function {$name}(\$key)";
- }
- }
- if (! is_callable(array($this->_interface, $name))) {
- return "function $name()";
- }
- if ($this->_isInterfaceMethod($name)) {
- return $this->_getFullSignature($name);
- }
- return "function $name()";
+ /**
+ * Checks whether a method is abstract in parent or not.
+ *
+ * @param string $name Method name.
+ * @return bool true if method is abstract in parent, else false
+ * @access private
+ */
+ function _isAbstractMethodInParent($name) {
+ $interface = new ReflectionClass($this->_interface);
+ if (! $parent = $interface->getParentClass()) {
+ return false;
}
-
- /**
- * For a signature specified in an interface, full
- * details must be replicated to be a valid implementation.
- * @param string $name Method name.
- * @return string Method signature up to last
- * bracket.
- * @access private
- */
- function _getFullSignature($name) {
- $interface = new ReflectionClass($this->_interface);
- $method = $interface->getMethod($name);
- $reference = $method->returnsReference() ? '&' : '';
- return "function $reference$name(" .
- implode(', ', $this->_getParameterSignatures($method)) .
- ")";
+ if (! $parent->hasMethod($name)) {
+ return false;
}
+ return $parent->getMethod($name)->isAbstract();
+ }
- /**
- * Gets the source code for each parameter.
- * @param ReflectionMethod $method Method object from
- * reflection API
- * @return array List of strings, each
- * a snippet of code.
- * @access private
- */
- function _getParameterSignatures($method) {
- $signatures = array();
- foreach ($method->getParameters() as $parameter) {
- $signature = '';
- $type = $parameter->getClass();
- if (is_null($type) && version_compare(phpversion(), '5.1.0', '>=') && $parameter->isArray()) {
- $signature .= 'array ';
- } elseif (!is_null($type)) {
- $signature .= $type->getName() . ' ';
- }
- if ($parameter->isPassedByReference()) {
- $signature .= '&';
- }
- $signature .= '$' . $this->_suppressSpurious($parameter->getName());
-