diff --git a/admin/tool/unittest/ex_reporter.php b/admin/tool/unittest/ex_reporter.php
index 5d440f37d6d..b7b296cc77a 100644
--- a/admin/tool/unittest/ex_reporter.php
+++ b/admin/tool/unittest/ex_reporter.php
@@ -55,8 +55,8 @@ class ExHtmlReporter extends HtmlReporter {
*
* @param bool $showpasses Whether this reporter should output anything for passes.
*/
- function ExHtmlReporter($showpasses) {
- $this->HtmlReporter();
+ function __construct($showpasses) {
+ parent::__construct('UTF-8');
$this->showpasses = $showpasses;
$this->strrunonlyfolder = $this->get_string('runonlyfolder');
@@ -254,7 +254,7 @@ class ExHtmlReporter extends HtmlReporter {
echo '
',
$this->get_string('runat', userdate($this->timestart)), ' ',
$this->get_string('timetakes', format_time(time() - $this->timestart)), ' ',
- $this->get_string('version', SimpleTestOptions::getVersion()),
+ $this->get_string('version', SimpleTest::getVersion()),
'
';
}
diff --git a/admin/tool/unittest/ex_simple_test.php b/admin/tool/unittest/ex_simple_test.php
index 1428a01da4b..dd6ee8a4391 100644
--- a/admin/tool/unittest/ex_simple_test.php
+++ b/admin/tool/unittest/ex_simple_test.php
@@ -46,7 +46,7 @@ class AutoGroupTest extends TestSuite {
$this->showsearch = $showsearch;
}
- function run(&$reporter) {
+ function run($reporter) {
global $UNITTEST;
$UNITTEST->running = true;
@@ -85,7 +85,7 @@ class AutoGroupTest extends TestSuite {
$s_count++;
// OK, found: this shows as a 'Notice' for any 'simpletest/test*.php' file.
- $this->addTestCase(new FindFileNotice($file_path, 'Found unit test file, '. $s_count));
+ $this->add(new FindFileNotice($file_path, 'Found unit test file, '. $s_count));
// addTestFile: Unfortunately this doesn't return fail/success (bool).
$this->addTestFile($file_path, true);
@@ -105,9 +105,9 @@ class AutoGroupTest extends TestSuite {
$path = $dir;
$count = $this->_recurseFolders($path);
if ($count <= 0) {
- $this->addTestCase(new BadAutoGroupTest($path, 'Search complete. No unit test files found'));
+ $this->add(new BadAutoGroupTest($path, 'Search complete. No unit test files found'));
} else {
- $this->addTestCase(new AutoGroupTestNotice($path, 'Search complete. Total unit test files found: '. $count));
+ $this->add(new AutoGroupTestNotice($path, 'Search complete. Total unit test files found: '. $count));
}
if ($this->showsearch) {
echo '';
@@ -116,6 +116,7 @@ class AutoGroupTest extends TestSuite {
}
function addTestFile($file, $internalcall = false) {
+
if ($this->showsearch) {
if ($internalcall) {
echo '' . basename($file) . '';
@@ -126,10 +127,10 @@ class AutoGroupTest extends TestSuite {
// get blank screens because evil people turn down error_reporting elsewhere.
error_reporting(E_ALL);
}
- if(!is_file($file) ){
- parent::addTestCase(new BadTest($file, 'Not a file or does not exist'));
+ if (!is_file($file) ){
+ parent::add(new BadTest($file, 'Not a file or does not exist'));
}
- parent::addTestFile($file);
+ parent::addFile($file);
}
}
diff --git a/admin/tool/unittest/simpletestcoveragelib.php b/admin/tool/unittest/simpletestcoveragelib.php
index 88943c7fc55..addcd83786f 100644
--- a/admin/tool/unittest/simpletestcoveragelib.php
+++ b/admin/tool/unittest/simpletestcoveragelib.php
@@ -123,7 +123,7 @@ class autogroup_test_coverage extends AutoGroupTest {
* automatically generating the coverage report. Only supports one instrumentation
* to be executed and reported.
*/
- public function run(&$simpletestreporter) {
+ public function run($simpletestreporter) {
global $CFG;
if (moodle_coverage_recorder::can_run_codecoverage() && $this->performcoverage) {
@@ -148,7 +148,7 @@ class autogroup_test_coverage extends AutoGroupTest {
* allowing further process of coverage data once tests are over. Supports multiple
* instrumentations (code coverage gathering sessions) to be executed.
*/
- public function run_with_external_coverage(&$simpletestreporter, &$covrecorder) {
+ public function run_with_external_coverage($simpletestreporter, $covrecorder) {
if (moodle_coverage_recorder::can_run_codecoverage() && $this->performcoverage) {
$covrecorder->setIncludePaths($this->includecoverage);
diff --git a/admin/tool/unittest/simpletestlib.php b/admin/tool/unittest/simpletestlib.php
index e2c573f16b1..e60faf73ac5 100644
--- a/admin/tool/unittest/simpletestlib.php
+++ b/admin/tool/unittest/simpletestlib.php
@@ -82,8 +82,8 @@ function recurseFolders($path, $callback, $fileregexp = '/.*/', $exclude = false
class IgnoreWhitespaceExpectation extends SimpleExpectation {
var $expect;
- function IgnoreWhitespaceExpectation($content, $message = '%s') {
- $this->SimpleExpectation($message);
+ function __construct($content, $message = '%s') {
+ parent::__construct($message);
$this->expect=$this->normalise($content);
}
@@ -111,8 +111,8 @@ class IgnoreWhitespaceExpectation extends SimpleExpectation {
class ArraysHaveSameValuesExpectation extends SimpleExpectation {
var $expect;
- function ArraysHaveSameValuesExpectation($expected, $message = '%s') {
- $this->SimpleExpectation($message);
+ function __construct($expected, $message = '%s') {
+ parent::__construct($message);
if (!is_array($expected)) {
trigger_error('Attempt to create an ArraysHaveSameValuesExpectation ' .
'with an expected value that is not an array.');
@@ -149,8 +149,8 @@ class ArraysHaveSameValuesExpectation extends SimpleExpectation {
class CheckSpecifiedFieldsExpectation extends SimpleExpectation {
var $expect;
- function CheckSpecifiedFieldsExpectation($expected, $message = '%s') {
- $this->SimpleExpectation($message);
+ function __construct($expected, $message = '%s') {
+ parent::__construct($message);
if (!is_object($expected)) {
trigger_error('Attempt to create a CheckSpecifiedFieldsExpectation ' .
'with an expected value that is not an object.');
@@ -651,7 +651,7 @@ class UnitTestCaseUsingDatabase extends UnitTestCase {
}
// Only do this after the above text.
- parent::UnitTestCase($label);
+ parent::__construct($label);
// Create the test DB instance.
$this->realdb = $DB;
@@ -974,7 +974,7 @@ class FakeDBUnitTestCase extends UnitTestCase {
return;
}
- parent::UnitTestCase($label);
+ parent::__construct($label);
// MDL-16483 Get PKs and save data to text file
$this->pkfile = $CFG->dataroot.'/testtablespks.csv';
diff --git a/lib/simpletest/testcompletionlib.php b/lib/simpletest/testcompletionlib.php
index 1496494b936..f218c0f7e40 100644
--- a/lib/simpletest/testcompletionlib.php
+++ b/lib/simpletest/testcompletionlib.php
@@ -208,7 +208,7 @@ class completionlib_test extends UnitTestCaseUsingDatabase {
new TimeModifiedExpectation(array('completionstate'=>COMPLETION_COMPLETE_PASS))));
$c->update_state($cm,COMPLETION_COMPLETE_PASS);
- $c->tally();
+ //$c->tally();
}
function test_internal_get_state() {
@@ -242,8 +242,8 @@ class completionlib_test extends UnitTestCaseUsingDatabase {
// * the grade_item/grade_grade calls are static and can't be mocked
// * the plugin_supports call is static and can't be mocked
- $DB->tally();
- $c->tally();
+ //$DB->tally();
+ //$c->tally();
}
function test_set_module_viewed() {
@@ -281,7 +281,7 @@ class completionlib_test extends UnitTestCaseUsingDatabase {
$c->expectOnce('update_state',array($cm,COMPLETION_COMPLETE,1337));
$c->set_module_viewed($cm,1337);
- $c->tally();
+ //$c->tally();
}
function test_count_user_data() {
@@ -298,7 +298,7 @@ WHERE
$c=new completion_info($course);
$this->assertEqual(666,$c->count_user_data($cm));
- $DB->tally();
+ //$DB->tally();
}
function test_delete_all_state() {
@@ -325,7 +325,7 @@ WHERE
$this->assertEqual(array(13=>array(43=>'foo'),14=>array(42=>'foo')),
$SESSION->completioncache);
- $DB->tally();
+ //$DB->tally();
}
function test_reset_all_state() {
@@ -355,8 +355,8 @@ WHERE
$c->reset_all_state($cm);
- $DB->tally();
- $c->tally();
+ //$DB->tally();
+ //$c->tally();
}
function test_get_data() {
@@ -447,7 +447,7 @@ WHERE
'id'=>'0','coursemoduleid'=>14,'userid'=>314159,'completionstate'=>0,
'viewed'=>0,'timemodified'=>0),'updated'=>$now)),$SESSION->completioncache);
- $DB->tally();
+ //$DB->tally();
}
function test_internal_set_data() {
@@ -487,7 +487,7 @@ WHERE
$DB->expectAt(1,'update_record', array('course_modules_completion', $d3));
$c->internal_set_data($cm, $data);
- $DB->tally();
+ //$DB->tally();
}
function test_get_activities() {
@@ -514,7 +514,7 @@ WHERE
$result=$c->get_activities($modinfo);
$this->assertEqual(array(13=>(object)array('id'=>13,'modname'=>'frog','name'=>'kermit')),$result);
- $DB->tally();
+ //$DB->tally();
}
// get_tracked_users() cannot easily be tested because it uses
@@ -606,8 +606,8 @@ WHERE
}
$this->assertTrue($resultok);
- $DB->tally();
- $c->tally();
+ //$DB->tally();
+ //$c->tally();
}
function test_inform_grade_changed() {
@@ -652,7 +652,7 @@ WHERE
$c->expectAt(1,'update_state',array($cm,COMPLETION_INCOMPLETE,31337));
$c->inform_grade_changed($cm,$item,$grade,false);
- $c->tally();
+ //$c->tally();
}
function test_internal_get_grade_state() {
diff --git a/lib/simpletestlib/HELP_MY_TESTS_DONT_WORK_ANYMORE b/lib/simpletestlib/HELP_MY_TESTS_DONT_WORK_ANYMORE
old mode 100644
new mode 100755
index 2d6612badb4..a65e83e8762
--- a/lib/simpletestlib/HELP_MY_TESTS_DONT_WORK_ANYMORE
+++ b/lib/simpletestlib/HELP_MY_TESTS_DONT_WORK_ANYMORE
@@ -5,13 +5,64 @@ written with earlier versions will fail with the newest ones. The most
dramatic changes are in the alpha releases. Here is a list of possible
problems and their fixes...
+assertText() no longer finds a string inside a |', '', $text);
- $text = preg_replace('|
]*alt\s*=\s*"([^"]*)"[^>]*>|', ' \1 ', $text);
- $text = preg_replace('|
]*alt\s*=\s*\'([^\']*)\'[^>]*>|', ' \1 ', $text);
- $text = preg_replace('|
]*alt\s*=\s*([a-zA-Z_]+)[^>]*>|', ' \1 ', $text);
- $text = preg_replace('|<[^>]*>|', '', $text);
- $text = SimpleHtmlSaxParser::decodeHtml($text);
- $text = preg_replace('|\s+|', ' ', $text);
- return trim(trim($text), "\xA0"); // TODO: The \xAO is a . Add a test for this.
- }
}
/**
- * SAX event handler.
+ * SAX event handler. Maintains a list of
+ * open tags and dispatches them as they close.
* @package SimpleTest
* @subpackage WebTester
- * @abstract
*/
-class SimpleSaxListener {
-
+class SimplePhpPageBuilder {
+ private $tags;
+ private $page;
+ private $private_content_tag;
+ private $open_forms = array();
+ private $complete_forms = array();
+ private $frameset = false;
+ private $loading_frames = array();
+ private $frameset_nesting_level = 0;
+ private $left_over_labels = array();
+
/**
- * Sets the document to write to.
+ * Frees up any references so as to allow the PHP garbage
+ * collection from unset() to work.
* @access public
*/
- function SimpleSaxListener() {
+ function free() {
+ unset($this->tags);
+ unset($this->page);
+ unset($this->private_content_tags);
+ $this->open_forms = array();
+ $this->complete_forms = array();
+ $this->frameset = false;
+ $this->loading_frames = array();
+ $this->frameset_nesting_level = 0;
+ $this->left_over_labels = array();
}
-
+
/**
- * Start of element event.
- * @param string $name Element name.
- * @param hash $attributes Name value pairs.
- * Attributes without content
- * are marked as true.
- * @return boolean False on parse error.
+ * This builder is always available.
+ * @return boolean Always true.
+ */
+ function can() {
+ return true;
+ }
+
+ /**
+ * Reads the raw content and send events
+ * into the page to be built.
+ * @param $response SimpleHttpResponse Fetched response.
+ * @return SimplePage Newly parsed page.
+ * @access public
+ */
+ function parse($response) {
+ $this->tags = array();
+ $this->page = $this->createPage($response);
+ $parser = $this->createParser($this);
+ $parser->parse($response->getContent());
+ $this->acceptPageEnd();
+ $page = $this->page;
+ $this->free();
+ return $page;
+ }
+
+ /**
+ * Creates an empty page.
+ * @return SimplePage New unparsed page.
+ * @access protected
+ */
+ protected function createPage($response) {
+ return new SimplePage($response);
+ }
+
+ /**
+ * Creates the parser used with the builder.
+ * @param SimplePhpPageBuilder $listener Target of parser.
+ * @return SimpleSaxParser Parser to generate
+ * events for the builder.
+ * @access protected
+ */
+ protected function createParser(&$listener) {
+ return new SimpleHtmlSaxParser($listener);
+ }
+
+ /**
+ * Start of element event. Opens a new tag.
+ * @param string $name Element name.
+ * @param hash $attributes Attributes without content
+ * are marked as true.
+ * @return boolean False on parse error.
* @access public
*/
function startElement($name, $attributes) {
+ $factory = new SimpleTagBuilder();
+ $tag = $factory->createTag($name, $attributes);
+ if (! $tag) {
+ return true;
+ }
+ if ($tag->getTagName() == 'label') {
+ $this->acceptLabelStart($tag);
+ $this->openTag($tag);
+ return true;
+ }
+ if ($tag->getTagName() == 'form') {
+ $this->acceptFormStart($tag);
+ return true;
+ }
+ if ($tag->getTagName() == 'frameset') {
+ $this->acceptFramesetStart($tag);
+ return true;
+ }
+ if ($tag->getTagName() == 'frame') {
+ $this->acceptFrame($tag);
+ return true;
+ }
+ if ($tag->isPrivateContent() && ! isset($this->private_content_tag)) {
+ $this->private_content_tag = &$tag;
+ }
+ if ($tag->expectEndTag()) {
+ $this->openTag($tag);
+ return true;
+ }
+ $this->acceptTag($tag);
+ return true;
}
-
+
/**
* End of element event.
* @param string $name Element name.
@@ -750,15 +811,244 @@ class SimpleSaxListener {
* @access public
*/
function endElement($name) {
+ if ($name == 'label') {
+ $this->acceptLabelEnd();
+ return true;
+ }
+ if ($name == 'form') {
+ $this->acceptFormEnd();
+ return true;
+ }
+ if ($name == 'frameset') {
+ $this->acceptFramesetEnd();
+ return true;
+ }
+ if ($this->hasNamedTagOnOpenTagStack($name)) {
+ $tag = array_pop($this->tags[$name]);
+ if ($tag->isPrivateContent() && $this->private_content_tag->getTagName() == $name) {
+ unset($this->private_content_tag);
+ }
+ $this->addContentTagToOpenTags($tag);
+ $this->acceptTag($tag);
+ return true;
+ }
+ return true;
}
-
+
/**
- * Unparsed, but relevant data.
+ * Test to see if there are any open tags awaiting
+ * closure that match the tag name.
+ * @param string $name Element name.
+ * @return boolean True if any are still open.
+ * @access private
+ */
+ protected function hasNamedTagOnOpenTagStack($name) {
+ return isset($this->tags[$name]) && (count($this->tags[$name]) > 0);
+ }
+
+ /**
+ * Unparsed, but relevant data. The data is added
+ * to every open tag.
* @param string $text May include unparsed tags.
* @return boolean False on parse error.
* @access public
*/
function addContent($text) {
+ if (isset($this->private_content_tag)) {
+ $this->private_content_tag->addContent($text);
+ } else {
+ $this->addContentToAllOpenTags($text);
+ }
+ return true;
+ }
+
+ /**
+ * Any content fills all currently open tags unless it
+ * is part of an option tag.
+ * @param string $text May include unparsed tags.
+ * @access private
+ */
+ protected function addContentToAllOpenTags($text) {
+ foreach (array_keys($this->tags) as $name) {
+ for ($i = 0, $count = count($this->tags[$name]); $i < $count; $i++) {
+ $this->tags[$name][$i]->addContent($text);
+ }
+ }
+ }
+
+ /**
+ * Parsed data in tag form. The parsed tag is added
+ * to every open tag. Used for adding options to select
+ * fields only.
+ * @param SimpleTag $tag Option tags only.
+ * @access private
+ */
+ protected function addContentTagToOpenTags(&$tag) {
+ if ($tag->getTagName() != 'option') {
+ return;
+ }
+ foreach (array_keys($this->tags) as $name) {
+ for ($i = 0, $count = count($this->tags[$name]); $i < $count; $i++) {
+ $this->tags[$name][$i]->addTag($tag);
+ }
+ }
+ }
+
+ /**
+ * Opens a tag for receiving content. Multiple tags
+ * will be receiving input at the same time.
+ * @param SimpleTag $tag New content tag.
+ * @access private
+ */
+ protected function openTag($tag) {
+ $name = $tag->getTagName();
+ if (! in_array($name, array_keys($this->tags))) {
+ $this->tags[$name] = array();
+ }
+ $this->tags[$name][] = $tag;
+ }
+
+ /**
+ * Adds a tag to the page.
+ * @param SimpleTag $tag Tag to accept.
+ * @access public
+ */
+ protected function acceptTag($tag) {
+ if ($tag->getTagName() == "a") {
+ $this->page->addLink($tag);
+ } elseif ($tag->getTagName() == "base") {
+ $this->page->setBase($tag->getAttribute('href'));
+ } elseif ($tag->getTagName() == "title") {
+ $this->page->setTitle($tag);
+ } elseif ($this->isFormElement($tag->getTagName())) {
+ for ($i = 0; $i < count($this->open_forms); $i++) {
+ $this->open_forms[$i]->addWidget($tag);
+ }
+ $this->last_widget = $tag;
+ }
+ }
+
+ /**
+ * Opens a label for a described widget.
+ * @param SimpleFormTag $tag Tag to accept.
+ * @access public
+ */
+ protected function acceptLabelStart($tag) {
+ $this->label = $tag;
+ unset($this->last_widget);
+ }
+
+ /**
+ * Closes the most recently opened label.
+ * @access public
+ */
+ protected function acceptLabelEnd() {
+ if (isset($this->label)) {
+ if (isset($this->last_widget)) {
+ $this->last_widget->setLabel($this->label->getText());
+ unset($this->last_widget);
+ } else {
+ $this->left_over_labels[] = SimpleTestCompatibility::copy($this->label);
+ }
+ unset($this->label);
+ }
+ }
+
+ /**
+ * Tests to see if a tag is a possible form
+ * element.
+ * @param string $name HTML element name.
+ * @return boolean True if form element.
+ * @access private
+ */
+ protected function isFormElement($name) {
+ return in_array($name, array('input', 'button', 'textarea', 'select'));
+ }
+
+ /**
+ * Opens a form. New widgets go here.
+ * @param SimpleFormTag $tag Tag to accept.
+ * @access public
+ */
+ protected function acceptFormStart($tag) {
+ $this->open_forms[] = new SimpleForm($tag, $this->page);
+ }
+
+ /**
+ * Closes the most recently opened form.
+ * @access public
+ */
+ protected function acceptFormEnd() {
+ if (count($this->open_forms)) {
+ $this->complete_forms[] = array_pop($this->open_forms);
+ }
+ }
+
+ /**
+ * Opens a frameset. A frameset may contain nested
+ * frameset tags.
+ * @param SimpleFramesetTag $tag Tag to accept.
+ * @access public
+ */
+ protected function acceptFramesetStart($tag) {
+ if (! $this->isLoadingFrames()) {
+ $this->frameset = $tag;
+ }
+ $this->frameset_nesting_level++;
+ }
+
+ /**
+ * Closes the most recently opened frameset.
+ * @access public
+ */
+ protected function acceptFramesetEnd() {
+ if ($this->isLoadingFrames()) {
+ $this->frameset_nesting_level--;
+ }
+ }
+
+ /**
+ * Takes a single frame tag and stashes it in
+ * the current frame set.
+ * @param SimpleFrameTag $tag Tag to accept.
+ * @access public
+ */
+ protected function acceptFrame($tag) {
+ if ($this->isLoadingFrames()) {
+ if ($tag->getAttribute('src')) {
+ $this->loading_frames[] = $tag;
+ }
+ }
+ }
+
+ /**
+ * Test to see if in the middle of reading
+ * a frameset.
+ * @return boolean True if inframeset.
+ * @access private
+ */
+ protected function isLoadingFrames() {
+ return $this->frameset and $this->frameset_nesting_level > 0;
+ }
+
+ /**
+ * Marker for end of complete page. Any work in
+ * progress can now be closed.
+ * @access public
+ */
+ protected function acceptPageEnd() {
+ while (count($this->open_forms)) {
+ $this->complete_forms[] = array_pop($this->open_forms);
+ }
+ foreach ($this->left_over_labels as $label) {
+ for ($i = 0, $count = count($this->complete_forms); $i < $count; $i++) {
+ $this->complete_forms[$i]->attachLabelBySelector(
+ new SimpleById($label->getFor()),
+ $label->getText());
+ }
+ }
+ $this->page->setForms($this->complete_forms);
+ $this->page->setFrames($this->loading_frames);
}
}
?>
\ No newline at end of file
diff --git a/lib/simpletestlib/readme_moodle.txt b/lib/simpletestlib/readme_moodle.txt
index 67365e45be0..740af27a137 100644
--- a/lib/simpletestlib/readme_moodle.txt
+++ b/lib/simpletestlib/readme_moodle.txt
@@ -1,17 +1,12 @@
-Description of Simpletest 1.0.1 library import into Moodle
+Description of Simpletest 1.1.0 library import into Moodle
Obtained from http://www.simpletest.org/en/download.html
Changes:
+ * removed extensions and test directories (documentation is kept because it is not available online)
+ * neutralised autorun.php - only execution via our UIs is allowed
* test_case.php - added our global $CFG before include() MDL-10064
- * errors.php - added extra PHP5 error types - otherwise you sometimes get PHP notices when running the tests.
- * fixed exception support (MDL-17534) - try/catch in invoker.php and errors.php
- * Bug fix in simpletest.php and test_case.php. Marked with //moodlefix begins,
- //moodlefix ends comments. This has been reported back to the simpletest mailing
- list. Hopefully will be included in a future release.
* modified run() in test_case.php - skipping tests that need fake db if prefix not set
- * search replace deprecated "=& new"
- * MDL-20876 - replaced deprecated split() with explode()
* test_case.php - added TIME_ALLOWED_PER_UNIT_TEST constant which
resets php time limit for each test function - MDL-24909. Marked with
comments (replace existing per-class hack in test_case.php).
diff --git a/lib/simpletestlib/recorder.php b/lib/simpletestlib/recorder.php
new file mode 100644
index 00000000000..b3d0d01c625
--- /dev/null
+++ b/lib/simpletestlib/recorder.php
@@ -0,0 +1,101 @@
+time, $this->breadcrumb, $this->message) =
+ array(time(), $breadcrumb, $message);
+ }
+}
+
+/**
+ * A single pass captured for later.
+ * @package SimpleTest
+ * @subpackage Extensions
+ */
+class SimpleResultOfPass extends SimpleResult { }
+
+/**
+ * A single failure captured for later.
+ * @package SimpleTest
+ * @subpackage Extensions
+ */
+class SimpleResultOfFail extends SimpleResult { }
+
+/**
+ * A single exception captured for later.
+ * @package SimpleTest
+ * @subpackage Extensions
+ */
+class SimpleResultOfException extends SimpleResult { }
+
+/**
+ * Array-based test recorder. Returns an array
+ * with timestamp, status, test name and message for each pass and failure.
+ * @package SimpleTest
+ * @subpackage Extensions
+ */
+class Recorder extends SimpleReporterDecorator {
+ public $results = array();
+
+ /**
+ * Stashes the pass as a SimpleResultOfPass
+ * for later retrieval.
+ * @param string $message Pass message to be displayed
+ * eventually.
+ */
+ function paintPass($message) {
+ parent::paintPass($message);
+ $this->results[] = new SimpleResultOfPass(parent::getTestList(), $message);
+ }
+
+ /**
+ * Stashes the fail as a SimpleResultOfFail
+ * for later retrieval.
+ * @param string $message Failure message to be displayed
+ * eventually.
+ */
+ function paintFail($message) {
+ parent::paintFail($message);
+ $this->results[] = new SimpleResultOfFail(parent::getTestList(), $message);
+ }
+
+ /**
+ * Stashes the exception as a SimpleResultOfException
+ * for later retrieval.
+ * @param string $message Exception message to be displayed
+ * eventually.
+ */
+ function paintException($message) {
+ parent::paintException($message);
+ $this->results[] = new SimpleResultOfException(parent::getTestList(), $message);
+ }
+}
+?>
\ No newline at end of file
diff --git a/lib/simpletestlib/reflection_php4.php b/lib/simpletestlib/reflection_php4.php
index c30eea888db..39801ea1bdb 100644
--- a/lib/simpletestlib/reflection_php4.php
+++ b/lib/simpletestlib/reflection_php4.php
@@ -3,7 +3,7 @@
* base include file for SimpleTest
* @package SimpleTest
* @subpackage UnitTester
- * @version $Id$
+ * @version $Id: reflection_php4.php 2011 2011-04-29 08:22:48Z pp11 $
*/
/**
@@ -112,7 +112,7 @@ class SimpleReflection {
function isInterface() {
return false;
}
-
+
/**
* Scans for final methods, but as it's PHP 4 there
* aren't any.
diff --git a/lib/simpletestlib/reflection_php5.php b/lib/simpletestlib/reflection_php5.php
index 0f2e50b3038..43d8a7b287f 100644
--- a/lib/simpletestlib/reflection_php5.php
+++ b/lib/simpletestlib/reflection_php5.php
@@ -3,7 +3,7 @@
* base include file for SimpleTest
* @package SimpleTest
* @subpackage UnitTester
- * @version $Id$
+ * @version $Id: reflection_php5.php 2011 2011-04-29 08:22:48Z pp11 $
*/
/**
@@ -12,15 +12,15 @@
* @subpackage UnitTester
*/
class SimpleReflection {
- var $_interface;
+ private $interface;
/**
* Stashes the class/interface.
* @param string $interface Class or interface
* to inspect.
*/
- function SimpleReflection($interface) {
- $this->_interface = $interface;
+ function __construct($interface) {
+ $this->interface = $interface;
}
/**
@@ -31,10 +31,10 @@ class SimpleReflection {
* @access public
*/
function classExists() {
- if (! class_exists($this->_interface)) {
+ if (! class_exists($this->interface)) {
return false;
}
- $reflection = new ReflectionClass($this->_interface);
+ $reflection = new ReflectionClass($this->interface);
return ! $reflection->isInterface();
}
@@ -45,7 +45,7 @@ class SimpleReflection {
* @access public
*/
function classExistsSansAutoload() {
- return class_exists($this->_interface, false);
+ return class_exists($this->interface, false);
}
/**
@@ -55,7 +55,7 @@ class SimpleReflection {
* @access public
*/
function classOrInterfaceExists() {
- return $this->_classOrInterfaceExistsWithAutoload($this->_interface, true);
+ return $this->classOrInterfaceExistsWithAutoload($this->interface, true);
}
/**
@@ -65,7 +65,7 @@ class SimpleReflection {
* @access public
*/
function classOrInterfaceExistsSansAutoload() {
- return $this->_classOrInterfaceExistsWithAutoload($this->_interface, false);
+ return $this->classOrInterfaceExistsWithAutoload($this->interface, false);
}
/**
@@ -76,13 +76,13 @@ class SimpleReflection {
* @return boolean True if interface defined.
* @access private
*/
- function _classOrInterfaceExistsWithAutoload($interface, $autoload) {
+ protected function classOrInterfaceExistsWithAutoload($interface, $autoload) {
if (function_exists('interface_exists')) {
- if (interface_exists($this->_interface, $autoload)) {
+ if (interface_exists($this->interface, $autoload)) {
return true;
}
}
- return class_exists($this->_interface, $autoload);
+ return class_exists($this->interface, $autoload);
}
/**
@@ -92,7 +92,7 @@ class SimpleReflection {
* @access public
*/
function getMethods() {
- return array_unique(get_class_methods($this->_interface));
+ return array_unique(get_class_methods($this->interface));
}
/**
@@ -103,11 +103,11 @@ class SimpleReflection {
* @access public
*/
function getInterfaces() {
- $reflection = new ReflectionClass($this->_interface);
+ $reflection = new ReflectionClass($this->interface);
if ($reflection->isInterface()) {
- return array($this->_interface);
+ return array($this->interface);
}
- return $this->_onlyParents($reflection->getInterfaces());
+ return $this->onlyParents($reflection->getInterfaces());
}
/**
@@ -131,7 +131,7 @@ class SimpleReflection {
* @returns boolean True if enforced.
* @access private
*/
- function _isInterfaceMethod($method) {
+ protected function isInterfaceMethod($method) {
return in_array($method, $this->getInterfaceMethods());
}
@@ -141,7 +141,7 @@ class SimpleReflection {
* @access public
*/
function getParent() {
- $reflection = new ReflectionClass($this->_interface);
+ $reflection = new ReflectionClass($this->interface);
$parent = $reflection->getParentClass();
if ($parent) {
return $parent->getName();
@@ -155,7 +155,7 @@ class SimpleReflection {
* @access public
*/
function isAbstract() {
- $reflection = new ReflectionClass($this->_interface);
+ $reflection = new ReflectionClass($this->interface);
return $reflection->isAbstract();
}
@@ -165,7 +165,7 @@ class SimpleReflection {
* @access public
*/
function isInterface() {
- $reflection = new ReflectionClass($this->_interface);
+ $reflection = new ReflectionClass($this->interface);
return $reflection->isInterface();
}
@@ -176,7 +176,7 @@ class SimpleReflection {
* @access public
*/
function hasFinal() {
- $reflection = new ReflectionClass($this->_interface);
+ $reflection = new ReflectionClass($this->interface);
foreach ($reflection->getMethods() as $method) {
if ($method->isFinal()) {
return true;
@@ -193,7 +193,7 @@ class SimpleReflection {
* @returns array List of parent interface names.
* @access private
*/
- function _onlyParents($interfaces) {
+ protected function onlyParents($interfaces) {
$parents = array();
$blacklist = array();
foreach ($interfaces as $interface) {
@@ -218,8 +218,8 @@ class SimpleReflection {
* @return bool true if method is abstract, else false
* @access private
*/
- function _isAbstractMethod($name) {
- $interface = new ReflectionClass($this->_interface);
+ protected function isAbstractMethod($name) {
+ $interface = new ReflectionClass($this->interface);
if (! $interface->hasMethod($name)) {
return false;
}
@@ -232,8 +232,8 @@ class SimpleReflection {
* @return bool true if method is the constructor
* @access private
*/
- function _isConstructor($name) {
- return ($name == '__construct') || ($name == $this->_interface);
+ protected function isConstructor($name) {
+ return ($name == '__construct') || ($name == $this->interface);
}
/**
@@ -242,8 +242,8 @@ class SimpleReflection {
* @return bool true if method is abstract in parent, else false
* @access private
*/
- function _isAbstractMethodInParents($name) {
- $interface = new ReflectionClass($this->_interface);
+ protected function isAbstractMethodInParents($name) {
+ $interface = new ReflectionClass($this->interface);
$parent = $interface->getParentClass();
while($parent) {
if (! $parent->hasMethod($name)) {
@@ -263,8 +263,8 @@ class SimpleReflection {
* @return bool true if method is static, else false
* @access private
*/
- function _isStaticMethod($name) {
- $interface = new ReflectionClass($this->_interface);
+ protected function isStaticMethod($name) {
+ $interface = new ReflectionClass($this->interface);
if (! $interface->hasMethod($name)) {
return false;
}
@@ -294,13 +294,19 @@ class SimpleReflection {
if ($name == '__toString') {
return "function $name()";
}
- if ($this->_isInterfaceMethod($name) ||
- $this->_isAbstractMethod($name) ||
- $this->_isAbstractMethodInParents($name) ||
- $this->_isStaticMethod($name)) {
- return $this->_getFullSignature($name);
+
+ // This wonky try-catch is a work around for a faulty method_exists()
+ // in early versions of PHP 5 which would return false for static
+ // methods. The Reflection classes work fine, but hasMethod()
+ // doesn't exist prior to PHP 5.1.0, so we need to use a more crude
+ // detection method.
+ try {
+ $interface = new ReflectionClass($this->interface);
+ $interface->getMethod($name);
+ } catch (ReflectionException $e) {
+ return "function $name()";
}
- return "function $name()";
+ return $this->getFullSignature($name);
}
/**
@@ -311,13 +317,13 @@ class SimpleReflection {
* bracket.
* @access private
*/
- function _getFullSignature($name) {
- $interface = new ReflectionClass($this->_interface);
+ protected function getFullSignature($name) {
+ $interface = new ReflectionClass($this->interface);
$method = $interface->getMethod($name);
$reference = $method->returnsReference() ? '&' : '';
$static = $method->isStatic() ? 'static ' : '';
return "{$static}function $reference$name(" .
- implode(', ', $this->_getParameterSignatures($method)) .
+ implode(', ', $this->getParameterSignatures($method)) .
")";
}
@@ -329,7 +335,7 @@ class SimpleReflection {
* a snippet of code.
* @access private
*/
- function _getParameterSignatures($method) {
+ protected function getParameterSignatures($method) {
$signatures = array();
foreach ($method->getParameters() as $parameter) {
$signature = '';
@@ -342,8 +348,8 @@ class SimpleReflection {
if ($parameter->isPassedByReference()) {
$signature .= '&';
}
- $signature .= '$' . $this->_suppressSpurious($parameter->getName());
- if ($this->_isOptional($parameter)) {
+ $signature .= '$' . $this->suppressSpurious($parameter->getName());
+ if ($this->isOptional($parameter)) {
$signature .= ' = null';
}
$signatures[] = $signature;
@@ -359,7 +365,7 @@ class SimpleReflection {
* @return string Cleaner name.
* @access private
*/
- function _suppressSpurious($name) {
+ protected function suppressSpurious($name) {
return str_replace(array('[', ']', ' '), '', $name);
}
@@ -370,11 +376,11 @@ class SimpleReflection {
* @return boolean True if optional.
* @access private
*/
- function _isOptional($parameter) {
+ protected function isOptional($parameter) {
if (method_exists($parameter, 'isOptional')) {
return $parameter->isOptional();
}
return false;
}
}
-?>
+?>
\ No newline at end of file
diff --git a/lib/simpletestlib/remote.php b/lib/simpletestlib/remote.php
index 764e840a5c1..4bb37b7c51b 100644
--- a/lib/simpletestlib/remote.php
+++ b/lib/simpletestlib/remote.php
@@ -3,7 +3,7 @@
* base include file for SimpleTest
* @package SimpleTest
* @subpackage UnitTester
- * @version $Id$
+ * @version $Id: remote.php 2011 2011-04-29 08:22:48Z pp11 $
*/
/**#@+
@@ -20,29 +20,29 @@ require_once(dirname(__FILE__) . '/test_case.php');
* @subpackage UnitTester
*/
class RemoteTestCase {
- var $_url;
- var $_dry_url;
- var $_size;
-
+ private $url;
+ private $dry_url;
+ private $size;
+
/**
* Sets the location of the remote test.
* @param string $url Test location.
* @param string $dry_url Location for dry run.
* @access public
*/
- function RemoteTestCase($url, $dry_url = false) {
- $this->_url = $url;
- $this->_dry_url = $dry_url ? $dry_url : $url;
- $this->_size = false;
+ function __construct($url, $dry_url = false) {
+ $this->url = $url;
+ $this->dry_url = $dry_url ? $dry_url : $url;
+ $this->size = false;
}
-
+
/**
* Accessor for the test name for subclasses.
* @return string Name of the test.
* @access public
*/
function getLabel() {
- return $this->_url;
+ return $this->url;
}
/**
@@ -53,65 +53,63 @@ class RemoteTestCase {
* @returns boolean True if no failures.
* @access public
*/
- function run(&$reporter) {
- $browser = &$this->_createBrowser();
- $xml = $browser->get($this->_url);
+ function run($reporter) {
+ $browser = $this->createBrowser();
+ $xml = $browser->get($this->url);
if (! $xml) {
- trigger_error('Cannot read remote test URL [' . $this->_url . ']');
+ trigger_error('Cannot read remote test URL [' . $this->url . ']');
return false;
}
- $parser = &$this->_createParser($reporter);
+ $parser = $this->createParser($reporter);
if (! $parser->parse($xml)) {
- trigger_error('Cannot parse incoming XML from [' . $this->_url . ']');
+ trigger_error('Cannot parse incoming XML from [' . $this->url . ']');
return false;
}
return true;
}
-
+
/**
* Creates a new web browser object for fetching
* the XML report.
* @return SimpleBrowser New browser.
* @access protected
*/
- function &_createBrowser() {
- $browser = new SimpleBrowser();
- return $browser;
+ protected function createBrowser() {
+ return new SimpleBrowser();
}
-
+
/**
* Creates the XML parser.
* @param SimpleReporter $reporter Target of test results.
* @return SimpleTestXmlListener XML reader.
* @access protected
*/
- function &_createParser(&$reporter) {
- $parser = new SimpleTestXmlParser($reporter);
- return $parser;
+ protected function createParser($reporter) {
+ return new SimpleTestXmlParser($reporter);
}
-
+
/**
* Accessor for the number of subtests.
* @return integer Number of test cases.
* @access public
*/
function getSize() {
- if ($this->_size === false) {
- $browser = &$this->_createBrowser();
- $xml = $browser->get($this->_dry_url);
+ if ($this->size === false) {
+ $browser = $this->createBrowser();
+ $xml = $browser->get($this->dry_url);
if (! $xml) {
- trigger_error('Cannot read remote test URL [' . $this->_dry_url . ']');
+ trigger_error('Cannot read remote test URL [' . $this->dry_url . ']');
return false;
}
$reporter = new SimpleReporter();
- $parser = &$this->_createParser($reporter);
+ $parser = $this->createParser($reporter);
if (! $parser->parse($xml)) {
- trigger_error('Cannot parse incoming XML from [' . $this->_dry_url . ']');
+ trigger_error('Cannot parse incoming XML from [' . $this->dry_url . ']');
return false;
}
- $this->_size = $reporter->getTestCaseCount();
+ $this->size = $reporter->getTestCaseCount();
}
- return $this->_size;
+ return $this->size;
}
}
?>
\ No newline at end of file
diff --git a/lib/simpletestlib/reporter.php b/lib/simpletestlib/reporter.php
old mode 100644
new mode 100755
index 20a6c9e514f..bd4f3fa41dd
--- a/lib/simpletestlib/reporter.php
+++ b/lib/simpletestlib/reporter.php
@@ -3,13 +3,14 @@
* base include file for SimpleTest
* @package SimpleTest
* @subpackage UnitTester
- * @version $Id$
+ * @version $Id: reporter.php 2005 2010-11-02 14:09:34Z lastcraft $
*/
/**#@+
* include other SimpleTest class files
*/
require_once(dirname(__FILE__) . '/scorer.php');
+//require_once(dirname(__FILE__) . '/arguments.php');
/**#@-*/
/**
@@ -19,7 +20,7 @@ require_once(dirname(__FILE__) . '/scorer.php');
* @subpackage UnitTester
*/
class HtmlReporter extends SimpleReporter {
- var $_character_set;
+ private $character_set;
/**
* Does nothing yet. The first output will
@@ -27,9 +28,9 @@ class HtmlReporter extends SimpleReporter {
* by a web browser.
* @access public
*/
- function HtmlReporter($character_set = 'ISO-8859-1') {
- $this->SimpleReporter();
- $this->_character_set = $character_set;
+ function __construct($character_set = 'ISO-8859-1') {
+ parent::__construct();
+ $this->character_set = $character_set;
}
/**
@@ -43,9 +44,9 @@ class HtmlReporter extends SimpleReporter {
print "";
print "\n\n$test_name\n";
print "\n";
+ $this->character_set . "\">\n";
print "\n";
print "\n\n";
print "$test_name
\n";
@@ -57,9 +58,8 @@ class HtmlReporter extends SimpleReporter {
* reloaded on every request. Otherwise you could be
* scratching your head over out of date test data.
* @access public
- * @static
*/
- function sendNoCacheHeaders() {
+ static function sendNoCacheHeaders() {
if (! headers_sent()) {
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
@@ -74,7 +74,7 @@ class HtmlReporter extends SimpleReporter {
* @return string CSS code as text.
* @access protected
*/
- function _getCss() {
+ protected function getCss() {
return ".fail { background-color: inherit; color: red; }" .
".pass { background-color: inherit; color: green; }" .
" pre { background-color: lightgray; color: inherit; }";
@@ -106,7 +106,6 @@ class HtmlReporter extends SimpleReporter {
* top level test.
* @param string $message Failure message displayed in
* the context of the other tests.
- * @access public
*/
function paintFail($message) {
parent::paintFail($message);
@@ -114,7 +113,7 @@ class HtmlReporter extends SimpleReporter {
$breadcrumb = $this->getTestList();
array_shift($breadcrumb);
print implode(" -> ", $breadcrumb);
- print " -> " . $this->_htmlEntities($message) . "
\n";
+ print " -> " . $this->htmlEntities($message) . "
\n";
}
/**
@@ -128,7 +127,7 @@ class HtmlReporter extends SimpleReporter {
$breadcrumb = $this->getTestList();
array_shift($breadcrumb);
print implode(" -> ", $breadcrumb);
- print " -> " . $this->_htmlEntities($message) . "
\n";
+ print " -> " . $this->htmlEntities($message) . "
\n";
}
/**
@@ -146,9 +145,9 @@ class HtmlReporter extends SimpleReporter {
'] with message ['. $exception->getMessage() .
'] in ['. $exception->getFile() .
' line ' . $exception->getLine() . ']';
- print " -> " . $this->_htmlEntities($message) . "
\n";
+ print " -> " . $this->htmlEntities($message) . "
\n";
}
-
+
/**
* Prints the message for skipping tests.
* @param string $message Text of skip condition.
@@ -160,16 +159,16 @@ class HtmlReporter extends SimpleReporter {
$breadcrumb = $this->getTestList();
array_shift($breadcrumb);
print implode(" -> ", $breadcrumb);
- print " -> " . $this->_htmlEntities($message) . "
\n";
+ print " -> " . $this->htmlEntities($message) . "
\n";
}
/**
- * Paints formatted text such as dumped variables.
+ * Paints formatted text such as dumped privateiables.
* @param string $message Text to show.
* @access public
*/
function paintFormattedMessage($message) {
- print '' . $this->_htmlEntities($message) . '
';
+ print '' . $this->htmlEntities($message) . '
';
}
/**
@@ -178,8 +177,8 @@ class HtmlReporter extends SimpleReporter {
* @return string Browser readable message.
* @access protected
*/
- function _htmlEntities($message) {
- return htmlentities($message, ENT_COMPAT, $this->_character_set);
+ protected function htmlEntities($message) {
+ return htmlentities($message, ENT_COMPAT, $this->character_set);
}
}
@@ -197,10 +196,9 @@ class TextReporter extends SimpleReporter {
/**
* Does nothing yet. The first output will
* be sent on the first test start.
- * @access public
*/
- function TextReporter() {
- $this->SimpleReporter();
+ function __construct() {
+ parent::__construct();
}
/**
@@ -283,7 +281,7 @@ class TextReporter extends SimpleReporter {
print "\tin " . implode("\n\tin ", array_reverse($breadcrumb));
print "\n";
}
-
+
/**
* Prints the message for skipping tests.
* @param string $message Text of skip condition.
@@ -295,7 +293,7 @@ class TextReporter extends SimpleReporter {
}
/**
- * Paints formatted text such as dumped variables.
+ * Paints formatted text such as dumped privateiables.
* @param string $message Text to show.
* @access public
*/
@@ -312,10 +310,10 @@ class TextReporter extends SimpleReporter {
* @subpackage UnitTester
*/
class SelectiveReporter extends SimpleReporterDecorator {
- var $_just_this_case = false;
- var $_just_this_test = false;
- var $_on;
-
+ private $just_this_case = false;
+ private $just_this_test = false;
+ private $on;
+
/**
* Selects the test case or group to be run,
* and optionally a specific test.
@@ -323,17 +321,17 @@ class SelectiveReporter extends SimpleReporterDecorator {
* @param string $just_this_case Only this case or group will run.
* @param string $just_this_test Only this test method will run.
*/
- function SelectiveReporter(&$reporter, $just_this_case = false, $just_this_test = false) {
+ function __construct($reporter, $just_this_case = false, $just_this_test = false) {
if (isset($just_this_case) && $just_this_case) {
- $this->_just_this_case = strtolower($just_this_case);
- $this->_off();
+ $this->just_this_case = strtolower($just_this_case);
+ $this->off();
} else {
- $this->_on();
+ $this->on();
}
if (isset($just_this_test) && $just_this_test) {
- $this->_just_this_test = strtolower($just_this_test);
+ $this->just_this_test = strtolower($just_this_test);
}
- $this->SimpleReporterDecorator($reporter);
+ parent::__construct($reporter);
}
/**
@@ -342,8 +340,8 @@ class SelectiveReporter extends SimpleReporterDecorator {
* @return boolean True if matched.
* @access protected
*/
- function _matchesTestCase($test_case) {
- return $this->_just_this_case == strtolower($test_case);
+ protected function matchesTestCase($test_case) {
+ return $this->just_this_case == strtolower($test_case);
}
/**
@@ -354,40 +352,40 @@ class SelectiveReporter extends SimpleReporterDecorator {
* @return boolean True if matched.
* @access protected
*/
- function _shouldRunTest($test_case, $method) {
- if ($this->_isOn() || $this->_matchesTestCase($test_case)) {
- if ($this->_just_this_test) {
- return $this->_just_this_test == strtolower($method);
+ protected function shouldRunTest($test_case, $method) {
+ if ($this->isOn() || $this->matchesTestCase($test_case)) {
+ if ($this->just_this_test) {
+ return $this->just_this_test == strtolower($method);
} else {
return true;
}
}
return false;
}
-
+
/**
* Switch on testing for the group or subgroup.
* @access private
*/
- function _on() {
- $this->_on = true;
+ protected function on() {
+ $this->on = true;
}
-
+
/**
* Switch off testing for the group or subgroup.
* @access private
*/
- function _off() {
- $this->_on = false;
+ protected function off() {
+ $this->on = false;
}
-
+
/**
* Is this group actually being tested?
* @return boolean True if the current test group is active.
* @access private
*/
- function _isOn() {
- return $this->_on;
+ protected function isOn() {
+ return $this->on;
}
/**
@@ -398,8 +396,8 @@ class SelectiveReporter extends SimpleReporterDecorator {
* @access public
*/
function shouldInvoke($test_case, $method) {
- if ($this->_shouldRunTest($test_case, $method)) {
- return $this->_reporter->shouldInvoke($test_case, $method);
+ if ($this->shouldRunTest($test_case, $method)) {
+ return $this->reporter->shouldInvoke($test_case, $method);
}
return false;
}
@@ -411,10 +409,10 @@ class SelectiveReporter extends SimpleReporterDecorator {
* @access public
*/
function paintGroupStart($test_case, $size) {
- if ($this->_just_this_case && $this->_matchesTestCase($test_case)) {
- $this->_on();
+ if ($this->just_this_case && $this->matchesTestCase($test_case)) {
+ $this->on();
}
- $this->_reporter->paintGroupStart($test_case, $size);
+ $this->reporter->paintGroupStart($test_case, $size);
}
/**
@@ -423,9 +421,9 @@ class SelectiveReporter extends SimpleReporterDecorator {
* @access public
*/
function paintGroupEnd($test_case) {
- $this->_reporter->paintGroupEnd($test_case);
- if ($this->_just_this_case && $this->_matchesTestCase($test_case)) {
- $this->_off();
+ $this->reporter->paintGroupEnd($test_case);
+ if ($this->just_this_case && $this->matchesTestCase($test_case)) {
+ $this->off();
}
}
}
@@ -436,7 +434,7 @@ class SelectiveReporter extends SimpleReporterDecorator {
* @subpackage UnitTester
*/
class NoSkipsReporter extends SimpleReporterDecorator {
-
+
/**
* Does nothing.
* @param string $message Text of skip condition.
diff --git a/lib/simpletestlib/scorer.php b/lib/simpletestlib/scorer.php
index b0dc65d2d80..27776f4b631 100644
--- a/lib/simpletestlib/scorer.php
+++ b/lib/simpletestlib/scorer.php
@@ -3,7 +3,7 @@
* base include file for SimpleTest
* @package SimpleTest
* @subpackage UnitTester
- * @version $Id$
+ * @version $Id: scorer.php 2011 2011-04-29 08:22:48Z pp11 $
*/
/**#@+*/
@@ -19,20 +19,20 @@ require_once(dirname(__FILE__) . '/invoker.php');
* @abstract
*/
class SimpleScorer {
- var $_passes;
- var $_fails;
- var $_exceptions;
- var $_is_dry_run;
+ private $passes;
+ private $fails;
+ private $exceptions;
+ private $is_dry_run;
/**
* Starts the test run with no results.
* @access public
*/
- function SimpleScorer() {
- $this->_passes = 0;
- $this->_fails = 0;
- $this->_exceptions = 0;
- $this->_is_dry_run = false;
+ function __construct() {
+ $this->passes = 0;
+ $this->fails = 0;
+ $this->exceptions = 0;
+ $this->is_dry_run = false;
}
/**
@@ -43,7 +43,7 @@ class SimpleScorer {
* @access public
*/
function makeDry($is_dry = true) {
- $this->_is_dry_run = $is_dry;
+ $this->is_dry_run = $is_dry;
}
/**
@@ -53,7 +53,7 @@ class SimpleScorer {
* @access public
*/
function shouldInvoke($test_case_name, $method) {
- return ! $this->_is_dry_run;
+ return ! $this->is_dry_run;
}
/**
@@ -63,7 +63,7 @@ class SimpleScorer {
* @return SimpleInvoker Wrapped test runner.
* @access public
*/
- function &createInvoker(&$invoker) {
+ function createInvoker($invoker) {
return $invoker;
}
@@ -75,7 +75,7 @@ class SimpleScorer {
* @access public
*/
function getStatus() {
- if ($this->_exceptions + $this->_fails > 0) {
+ if ($this->exceptions + $this->fails > 0) {
return false;
}
return true;
@@ -136,7 +136,7 @@ class SimpleScorer {
* @access public
*/
function paintPass($message) {
- $this->_passes++;
+ $this->passes++;
}
/**
@@ -145,7 +145,7 @@ class SimpleScorer {
* @access public
*/
function paintFail($message) {
- $this->_fails++;
+ $this->fails++;
}
/**
@@ -155,7 +155,7 @@ class SimpleScorer {
* @access public
*/
function paintError($message) {
- $this->_exceptions++;
+ $this->exceptions++;
}
/**
@@ -164,9 +164,9 @@ class SimpleScorer {
* @access public
*/
function paintException($exception) {
- $this->_exceptions++;
+ $this->exceptions++;
}
-
+
/**
* Prints the message for skipping tests.
* @param string $message Text of skip condition.
@@ -181,7 +181,7 @@ class SimpleScorer {
* @access public
*/
function getPassCount() {
- return $this->_passes;
+ return $this->passes;
}
/**
@@ -190,7 +190,7 @@ class SimpleScorer {
* @access public
*/
function getFailCount() {
- return $this->_fails;
+ return $this->fails;
}
/**
@@ -200,7 +200,7 @@ class SimpleScorer {
* @access public
*/
function getExceptionCount() {
- return $this->_exceptions;
+ return $this->exceptions;
}
/**
@@ -213,7 +213,7 @@ class SimpleScorer {
/**
* Paints a formatted ASCII message such as a
- * variable dump.
+ * privateiable dump.
* @param string $message Text to display.
* @access public
*/
@@ -239,24 +239,23 @@ class SimpleScorer {
* @subpackage UnitTester
*/
class SimpleReporter extends SimpleScorer {
- var $_test_stack;
- var $_size;
- var $_progress;
+ private $test_stack;
+ private $size;
+ private $progress;
/**
* Starts the display with no results in.
* @access public
*/
- function SimpleReporter() {
- $this->SimpleScorer();
- $this->_test_stack = array();
- $this->_size = null;
- $this->_progress = 0;
+ function __construct() {
+ parent::__construct();
+ $this->test_stack = array();
+ $this->size = null;
+ $this->progress = 0;
}
-
+
/**
- * Gets the formatter for variables and other small
- * generic data items.
+ * Gets the formatter for small generic data items.
* @return SimpleDumper Formatter.
* @access public
*/
@@ -274,13 +273,13 @@ class SimpleReporter extends SimpleScorer {
* @access public
*/
function paintGroupStart($test_name, $size) {
- if (! isset($this->_size)) {
- $this->_size = $size;
+ if (! isset($this->size)) {
+ $this->size = $size;
}
- if (count($this->_test_stack) == 0) {
+ if (count($this->test_stack) == 0) {
$this->paintHeader($test_name);
}
- $this->_test_stack[] = $test_name;
+ $this->test_stack[] = $test_name;
}
/**
@@ -291,8 +290,8 @@ class SimpleReporter extends SimpleScorer {
* @access public
*/
function paintGroupEnd($test_name) {
- array_pop($this->_test_stack);
- if (count($this->_test_stack) == 0) {
+ array_pop($this->test_stack);
+ if (count($this->test_stack) == 0) {
$this->paintFooter($test_name);
}
}
@@ -306,13 +305,13 @@ class SimpleReporter extends SimpleScorer {
* @access public
*/
function paintCaseStart($test_name) {
- if (! isset($this->_size)) {
- $this->_size = 1;
+ if (! isset($this->size)) {
+ $this->size = 1;
}
- if (count($this->_test_stack) == 0) {
+ if (count($this->test_stack) == 0) {
$this->paintHeader($test_name);
}
- $this->_test_stack[] = $test_name;
+ $this->test_stack[] = $test_name;
}
/**
@@ -322,9 +321,9 @@ class SimpleReporter extends SimpleScorer {
* @access public
*/
function paintCaseEnd($test_name) {
- $this->_progress++;
- array_pop($this->_test_stack);
- if (count($this->_test_stack) == 0) {
+ $this->progress++;
+ array_pop($this->test_stack);
+ if (count($this->test_stack) == 0) {
$this->paintFooter($test_name);
}
}
@@ -335,7 +334,7 @@ class SimpleReporter extends SimpleScorer {
* @access public
*/
function paintMethodStart($test_name) {
- $this->_test_stack[] = $test_name;
+ $this->test_stack[] = $test_name;
}
/**
@@ -345,7 +344,7 @@ class SimpleReporter extends SimpleScorer {
* @access public
*/
function paintMethodEnd($test_name) {
- array_pop($this->_test_stack);
+ array_pop($this->test_stack);
}
/**
@@ -375,7 +374,7 @@ class SimpleReporter extends SimpleScorer {
* @access public
*/
function getTestList() {
- return $this->_test_stack;
+ return $this->test_stack;
}
/**
@@ -386,7 +385,7 @@ class SimpleReporter extends SimpleScorer {
* @access public
*/
function getTestCaseCount() {
- return $this->_size;
+ return $this->size;
}
/**
@@ -396,16 +395,15 @@ class SimpleReporter extends SimpleScorer {
* @access public
*/
function getTestCaseProgress() {
- return $this->_progress;
+ return $this->progress;
}
/**
* Static check for running in the comand line.
* @return boolean True if CLI.
* @access public
- * @static
*/
- function inCli() {
+ static function inCli() {
return php_sapi_name() == 'cli';
}
}
@@ -416,14 +414,14 @@ class SimpleReporter extends SimpleScorer {
* @subpackage UnitTester
*/
class SimpleReporterDecorator {
- var $_reporter;
+ protected $reporter;
/**
* Mediates between the reporter and the test case.
* @param SimpleScorer $reporter Reporter to receive events.
*/
- function SimpleReporterDecorator(&$reporter) {
- $this->_reporter = &$reporter;
+ function __construct($reporter) {
+ $this->reporter = $reporter;
}
/**
@@ -434,7 +432,7 @@ class SimpleReporterDecorator {
* @access public
*/
function makeDry($is_dry = true) {
- $this->_reporter->makeDry($is_dry);
+ $this->reporter->makeDry($is_dry);
}
/**
@@ -445,39 +443,53 @@ class SimpleReporterDecorator {
* @access public
*/
function getStatus() {
- return $this->_reporter->getStatus();
+ return $this->reporter->getStatus();
+ }
+
+ /**
+ * The nesting of the test cases so far. Not
+ * all reporters have this facility.
+ * @return array Test list if accessible.
+ * @access public
+ */
+ function getTestList() {
+ if (method_exists($this->reporter, 'getTestList')) {
+ return $this->reporter->getTestList();
+ } else {
+ return array();
+ }
}
/**
* The reporter has a veto on what should be run.
- * @param string $test_case_name name of test case.
+ * @param string $test_case_name Name of test case.
* @param string $method Name of test method.
* @return boolean True if test should be run.
* @access public
*/
function shouldInvoke($test_case_name, $method) {
- return $this->_reporter->shouldInvoke($test_case_name, $method);
+ return $this->reporter->shouldInvoke($test_case_name, $method);
}
/**
- * Can wrap the invoker in preperation for running
+ * Can wrap the invoker in preparation for running
* a test.
* @param SimpleInvoker $invoker Individual test runner.
* @return SimpleInvoker Wrapped test runner.
* @access public
*/
- function &createInvoker(&$invoker) {
- return $this->_reporter->createInvoker($invoker);
+ function createInvoker($invoker) {
+ return $this->reporter->createInvoker($invoker);
}
-
+
/**
- * Gets the formatter for variables and other small
+ * Gets the formatter for privateiables and other small
* generic data items.
* @return SimpleDumper Formatter.
* @access public
*/
function getDumper() {
- return $this->_reporter->getDumper();
+ return $this->reporter->getDumper();
}
/**
@@ -487,7 +499,7 @@ class SimpleReporterDecorator {
* @access public
*/
function paintGroupStart($test_name, $size) {
- $this->_reporter->paintGroupStart($test_name, $size);
+ $this->reporter->paintGroupStart($test_name, $size);
}
/**
@@ -496,7 +508,7 @@ class SimpleReporterDecorator {
* @access public
*/
function paintGroupEnd($test_name) {
- $this->_reporter->paintGroupEnd($test_name);
+ $this->reporter->paintGroupEnd($test_name);
}
/**
@@ -505,7 +517,7 @@ class SimpleReporterDecorator {
* @access public
*/
function paintCaseStart($test_name) {
- $this->_reporter->paintCaseStart($test_name);
+ $this->reporter->paintCaseStart($test_name);
}
/**
@@ -514,7 +526,7 @@ class SimpleReporterDecorator {
* @access public
*/
function paintCaseEnd($test_name) {
- $this->_reporter->paintCaseEnd($test_name);
+ $this->reporter->paintCaseEnd($test_name);
}
/**
@@ -523,7 +535,7 @@ class SimpleReporterDecorator {
* @access public
*/
function paintMethodStart($test_name) {
- $this->_reporter->paintMethodStart($test_name);
+ $this->reporter->paintMethodStart($test_name);
}
/**
@@ -532,7 +544,7 @@ class SimpleReporterDecorator {
* @access public
*/
function paintMethodEnd($test_name) {
- $this->_reporter->paintMethodEnd($test_name);
+ $this->reporter->paintMethodEnd($test_name);
}
/**
@@ -541,7 +553,7 @@ class SimpleReporterDecorator {
* @access public
*/
function paintPass($message) {
- $this->_reporter->paintPass($message);
+ $this->reporter->paintPass($message);
}
/**
@@ -550,7 +562,7 @@ class SimpleReporterDecorator {
* @access public
*/
function paintFail($message) {
- $this->_reporter->paintFail($message);
+ $this->reporter->paintFail($message);
}
/**
@@ -560,7 +572,7 @@ class SimpleReporterDecorator {
* @access public
*/
function paintError($message) {
- $this->_reporter->paintError($message);
+ $this->reporter->paintError($message);
}
/**
@@ -569,16 +581,16 @@ class SimpleReporterDecorator {
* @access public
*/
function paintException($exception) {
- $this->_reporter->paintException($exception);
+ $this->reporter->paintException($exception);
}
-
+
/**
* Prints the message for skipping tests.
* @param string $message Text of skip condition.
* @access public
*/
function paintSkip($message) {
- $this->_reporter->paintSkip($message);
+ $this->reporter->paintSkip($message);
}
/**
@@ -587,7 +599,7 @@ class SimpleReporterDecorator {
* @access public
*/
function paintMessage($message) {
- $this->_reporter->paintMessage($message);
+ $this->reporter->paintMessage($message);
}
/**
@@ -596,7 +608,7 @@ class SimpleReporterDecorator {
* @access public
*/
function paintFormattedMessage($message) {
- $this->_reporter->paintFormattedMessage($message);
+ $this->reporter->paintFormattedMessage($message);
}
/**
@@ -608,8 +620,8 @@ class SimpleReporterDecorator {
* test suite.
* @access public
*/
- function paintSignal($type, &$payload) {
- $this->_reporter->paintSignal($type, $payload);
+ function paintSignal($type, $payload) {
+ $this->reporter->paintSignal($type, $payload);
}
}
@@ -620,15 +632,15 @@ class SimpleReporterDecorator {
* @subpackage UnitTester
*/
class MultipleReporter {
- var $_reporters = array();
+ private $reporters = array();
/**
* Adds a reporter to the subscriber list.
* @param SimpleScorer $reporter Reporter to receive events.
* @access public
*/
- function attachReporter(&$reporter) {
- $this->_reporters[] = &$reporter;
+ function attachReporter($reporter) {
+ $this->reporters[] = $reporter;
}
/**
@@ -639,8 +651,8 @@ class MultipleReporter {
* @access public
*/
function makeDry($is_dry = true) {
- for ($i = 0; $i < count($this->_reporters); $i++) {
- $this->_reporters[$i]->makeDry($is_dry);
+ for ($i = 0; $i < count($this->reporters); $i++) {
+ $this->reporters[$i]->makeDry($is_dry);
}
}
@@ -653,8 +665,8 @@ class MultipleReporter {
* @access public
*/
function getStatus() {
- for ($i = 0; $i < count($this->_reporters); $i++) {
- if (! $this->_reporters[$i]->getStatus()) {
+ for ($i = 0; $i < count($this->reporters); $i++) {
+ if (! $this->reporters[$i]->getStatus()) {
return false;
}
}
@@ -669,8 +681,8 @@ class MultipleReporter {
* @access public
*/
function shouldInvoke($test_case_name, $method) {
- for ($i = 0; $i < count($this->_reporters); $i++) {
- if (! $this->_reporters[$i]->shouldInvoke($test_case_name, $method)) {
+ for ($i = 0; $i < count($this->reporters); $i++) {
+ if (! $this->reporters[$i]->shouldInvoke($test_case_name, $method)) {
return false;
}
}
@@ -683,15 +695,15 @@ class MultipleReporter {
* @return SimpleInvoker Wrapped test runner.
* @access public
*/
- function &createInvoker(&$invoker) {
- for ($i = 0; $i < count($this->_reporters); $i++) {
- $invoker = &$this->_reporters[$i]->createInvoker($invoker);
+ function createInvoker($invoker) {
+ for ($i = 0; $i < count($this->reporters); $i++) {
+ $invoker = $this->reporters[$i]->createInvoker($invoker);
}
return $invoker;
}
-
+
/**
- * Gets the formatter for variables and other small
+ * Gets the formatter for privateiables and other small
* generic data items.
* @return SimpleDumper Formatter.
* @access public
@@ -707,8 +719,8 @@ class MultipleReporter {
* @access public
*/
function paintGroupStart($test_name, $size) {
- for ($i = 0; $i < count($this->_reporters); $i++) {
- $this->_reporters[$i]->paintGroupStart($test_name, $size);
+ for ($i = 0; $i < count($this->reporters); $i++) {
+ $this->reporters[$i]->paintGroupStart($test_name, $size);
}
}
@@ -718,8 +730,8 @@ class MultipleReporter {
* @access public
*/
function paintGroupEnd($test_name) {
- for ($i = 0; $i < count($this->_reporters); $i++) {
- $this->_reporters[$i]->paintGroupEnd($test_name);
+ for ($i = 0; $i < count($this->reporters); $i++) {
+ $this->reporters[$i]->paintGroupEnd($test_name);
}
}
@@ -729,8 +741,8 @@ class MultipleReporter {
* @access public
*/
function paintCaseStart($test_name) {
- for ($i = 0; $i < count($this->_reporters); $i++) {
- $this->_reporters[$i]->paintCaseStart($test_name);
+ for ($i = 0; $i < count($this->reporters); $i++) {
+ $this->reporters[$i]->paintCaseStart($test_name);
}
}
@@ -740,8 +752,8 @@ class MultipleReporter {
* @access public
*/
function paintCaseEnd($test_name) {
- for ($i = 0; $i < count($this->_reporters); $i++) {
- $this->_reporters[$i]->paintCaseEnd($test_name);
+ for ($i = 0; $i < count($this->reporters); $i++) {
+ $this->reporters[$i]->paintCaseEnd($test_name);
}
}
@@ -751,8 +763,8 @@ class MultipleReporter {
* @access public
*/
function paintMethodStart($test_name) {
- for ($i = 0; $i < count($this->_reporters); $i++) {
- $this->_reporters[$i]->paintMethodStart($test_name);
+ for ($i = 0; $i < count($this->reporters); $i++) {
+ $this->reporters[$i]->paintMethodStart($test_name);
}
}
@@ -762,8 +774,8 @@ class MultipleReporter {
* @access public
*/
function paintMethodEnd($test_name) {
- for ($i = 0; $i < count($this->_reporters); $i++) {
- $this->_reporters[$i]->paintMethodEnd($test_name);
+ for ($i = 0; $i < count($this->reporters); $i++) {
+ $this->reporters[$i]->paintMethodEnd($test_name);
}
}
@@ -773,8 +785,8 @@ class MultipleReporter {
* @access public
*/
function paintPass($message) {
- for ($i = 0; $i < count($this->_reporters); $i++) {
- $this->_reporters[$i]->paintPass($message);
+ for ($i = 0; $i < count($this->reporters); $i++) {
+ $this->reporters[$i]->paintPass($message);
}
}
@@ -784,8 +796,8 @@ class MultipleReporter {
* @access public
*/
function paintFail($message) {
- for ($i = 0; $i < count($this->_reporters); $i++) {
- $this->_reporters[$i]->paintFail($message);
+ for ($i = 0; $i < count($this->reporters); $i++) {
+ $this->reporters[$i]->paintFail($message);
}
}
@@ -796,19 +808,19 @@ class MultipleReporter {
* @access public
*/
function paintError($message) {
- for ($i = 0; $i < count($this->_reporters); $i++) {
- $this->_reporters[$i]->paintError($message);
+ for ($i = 0; $i < count($this->reporters); $i++) {
+ $this->reporters[$i]->paintError($message);
}
}
-
+
/**
* Chains to the wrapped reporter.
* @param Exception $exception Exception to display.
* @access public
*/
function paintException($exception) {
- for ($i = 0; $i < count($this->_reporters); $i++) {
- $this->_reporters[$i]->paintException($exception);
+ for ($i = 0; $i < count($this->reporters); $i++) {
+ $this->reporters[$i]->paintException($exception);
}
}
@@ -818,8 +830,8 @@ class MultipleReporter {
* @access public
*/
function paintSkip($message) {
- for ($i = 0; $i < count($this->_reporters); $i++) {
- $this->_reporters[$i]->paintSkip($message);
+ for ($i = 0; $i < count($this->reporters); $i++) {
+ $this->reporters[$i]->paintSkip($message);
}
}
@@ -829,8 +841,8 @@ class MultipleReporter {
* @access public
*/
function paintMessage($message) {
- for ($i = 0; $i < count($this->_reporters); $i++) {
- $this->_reporters[$i]->paintMessage($message);
+ for ($i = 0; $i < count($this->reporters); $i++) {
+ $this->reporters[$i]->paintMessage($message);
}
}
@@ -840,8 +852,8 @@ class MultipleReporter {
* @access public
*/
function paintFormattedMessage($message) {
- for ($i = 0; $i < count($this->_reporters); $i++) {
- $this->_reporters[$i]->paintFormattedMessage($message);
+ for ($i = 0; $i < count($this->reporters); $i++) {
+ $this->reporters[$i]->paintFormattedMessage($message);
}
}
@@ -854,9 +866,9 @@ class MultipleReporter {
* test suite.
* @access public
*/
- function paintSignal($type, &$payload) {
- for ($i = 0; $i < count($this->_reporters); $i++) {
- $this->_reporters[$i]->paintSignal($type, $payload);
+ function paintSignal($type, $payload) {
+ for ($i = 0; $i < count($this->reporters); $i++) {
+ $this->reporters[$i]->paintSignal($type, $payload);
}
}
}
diff --git a/lib/simpletestlib/selector.php b/lib/simpletestlib/selector.php
old mode 100644
new mode 100755
index 7c5962e1a13..ba2fed312a8
--- a/lib/simpletestlib/selector.php
+++ b/lib/simpletestlib/selector.php
@@ -3,7 +3,7 @@
* Base include file for SimpleTest.
* @package SimpleTest
* @subpackage WebTester
- * @version $Id$
+ * @version $Id: selector.php 1786 2008-04-26 17:32:20Z pp11 $
*/
/**#@+
@@ -20,18 +20,22 @@ require_once(dirname(__FILE__) . '/encoding.php');
* @subpackage WebTester
*/
class SimpleByName {
- var $_name;
+ private $name;
/**
* Stashes the name for later comparison.
* @param string $name Name attribute to match.
*/
- function SimpleByName($name) {
- $this->_name = $name;
+ function __construct($name) {
+ $this->name = $name;
}
+ /**
+ * Accessor for name.
+ * @returns string $name Name to match.
+ */
function getName() {
- return $this->_name;
+ return $this->name;
}
/**
@@ -40,7 +44,7 @@ class SimpleByName {
* @access public
*/
function isMatch($widget) {
- return ($widget->getName() == $this->_name);
+ return ($widget->getName() == $this->name);
}
}
@@ -51,14 +55,14 @@ class SimpleByName {
* @subpackage WebTester
*/
class SimpleByLabel {
- var $_label;
+ private $label;
/**
* Stashes the name for later comparison.
* @param string $label Visible text to match.
*/
- function SimpleByLabel($label) {
- $this->_label = $label;
+ function __construct($label) {
+ $this->label = $label;
}
/**
@@ -71,7 +75,7 @@ class SimpleByLabel {
if (! method_exists($widget, 'isLabel')) {
return false;
}
- return $widget->isLabel($this->_label);
+ return $widget->isLabel($this->label);
}
}
@@ -82,14 +86,14 @@ class SimpleByLabel {
* @subpackage WebTester
*/
class SimpleById {
- var $_id;
+ private $id;
/**
* Stashes the name for later comparison.
* @param string $id ID atribute to match.
*/
- function SimpleById($id) {
- $this->_id = $id;
+ function __construct($id) {
+ $this->id = $id;
}
/**
@@ -98,7 +102,7 @@ class SimpleById {
* @access public
*/
function isMatch($widget) {
- return $widget->isId($this->_id);
+ return $widget->isId($this->id);
}
}
@@ -109,14 +113,14 @@ class SimpleById {
* @subpackage WebTester
*/
class SimpleByLabelOrName {
- var $_label;
+ private $label;
/**
* Stashes the name/label for later comparison.
* @param string $label Visible text to match.
*/
- function SimpleByLabelOrName($label) {
- $this->_label = $label;
+ function __construct($label) {
+ $this->label = $label;
}
/**
@@ -127,11 +131,11 @@ class SimpleByLabelOrName {
*/
function isMatch($widget) {
if (method_exists($widget, 'isLabel')) {
- if ($widget->isLabel($this->_label)) {
+ if ($widget->isLabel($this->label)) {
return true;
}
}
- return ($widget->getName() == $this->_label);
+ return ($widget->getName() == $this->label);
}
}
?>
\ No newline at end of file
diff --git a/lib/simpletestlib/shell_tester.php b/lib/simpletestlib/shell_tester.php
index 14186796d83..9a3bd389eeb 100644
--- a/lib/simpletestlib/shell_tester.php
+++ b/lib/simpletestlib/shell_tester.php
@@ -3,7 +3,7 @@
* base include file for SimpleTest
* @package SimpleTest
* @subpackage UnitTester
- * @version $Id$
+ * @version $Id: shell_tester.php 2011 2011-04-29 08:22:48Z pp11 $
*/
/**#@+
@@ -18,14 +18,14 @@ require_once(dirname(__FILE__) . '/test_case.php');
* @subpackage UnitTester
*/
class SimpleShell {
- var $_output;
+ private $output;
/**
* Executes the shell comand and stashes the output.
* @access public
*/
- function SimpleShell() {
- $this->_output = false;
+ function __construct() {
+ $this->output = false;
}
/**
@@ -37,8 +37,8 @@ class SimpleShell {
* @access public
*/
function execute($command) {
- $this->_output = false;
- exec($command, $this->_output, $ret);
+ $this->output = false;
+ exec($command, $this->output, $ret);
return $ret;
}
@@ -48,7 +48,7 @@ class SimpleShell {
* @access public
*/
function getOutput() {
- return implode("\n", $this->_output);
+ return implode("\n", $this->output);
}
/**
@@ -57,7 +57,7 @@ class SimpleShell {
* @access public
*/
function getOutputAsList() {
- return $this->_output;
+ return $this->output;
}
}
@@ -69,9 +69,9 @@ class SimpleShell {
* @subpackage UnitTester
*/
class ShellTestCase extends SimpleTestCase {
- var $_current_shell;
- var $_last_status;
- var $_last_command;
+ private $current_shell;
+ private $last_status;
+ private $last_command;
/**
* Creates an empty test case. Should be subclassed
@@ -80,11 +80,11 @@ class ShellTestCase extends SimpleTestCase {
* the class name if none specified.
* @access public
*/
- function ShellTestCase($label = false) {
- $this->SimpleTestCase($label);
- $this->_current_shell = &$this->_createShell();
- $this->_last_status = false;
- $this->_last_command = '';
+ function __construct($label = false) {
+ parent::__construct($label);
+ $this->current_shell = $this->createShell();
+ $this->last_status = false;
+ $this->last_command = '';
}
/**
@@ -94,10 +94,10 @@ class ShellTestCase extends SimpleTestCase {
* @access public
*/
function execute($command) {
- $shell = &$this->_getShell();
- $this->_last_status = $shell->execute($command);
- $this->_last_command = $command;
- return ($this->_last_status === 0);
+ $shell = $this->getShell();
+ $this->last_status = $shell->execute($command);
+ $this->last_command = $command;
+ return ($this->last_status === 0);
}
/**
@@ -114,7 +114,7 @@ class ShellTestCase extends SimpleTestCase {
* @access public
*/
function getOutput() {
- $shell = &$this->_getShell();
+ $shell = $this->getShell();
return $shell->getOutput();
}
@@ -124,7 +124,7 @@ class ShellTestCase extends SimpleTestCase {
* @access public
*/
function getOutputAsList() {
- $shell = &$this->_getShell();
+ $shell = $this->getShell();
return $shell->getOutputAsList();
}
@@ -154,7 +154,7 @@ class ShellTestCase extends SimpleTestCase {
function assertFalse($result, $message = '%s') {
return $this->assert(new FalseExpectation(), $result, $message);
}
-
+
/**
* Will trigger a pass if the two parameters have
* the same value only. Otherwise a fail. This
@@ -171,7 +171,7 @@ class ShellTestCase extends SimpleTestCase {
$second,
$message);
}
-
+
/**
* Will trigger a pass if the two parameters have
* a different value. Otherwise a fail. This
@@ -199,9 +199,9 @@ class ShellTestCase extends SimpleTestCase {
*/
function assertExitCode($status, $message = "%s") {
$message = sprintf($message, "Expected status code of [$status] from [" .
- $this->_last_command . "], but got [" .
- $this->_last_status . "]");
- return $this->assertTrue($status === $this->_last_status, $message);
+ $this->last_command . "], but got [" .
+ $this->last_status . "]");
+ return $this->assertTrue($status === $this->last_status, $message);
}
/**
@@ -213,7 +213,7 @@ class ShellTestCase extends SimpleTestCase {
* @access public
*/
function assertOutput($expected, $message = "%s") {
- $shell = &$this->_getShell();
+ $shell = $this->getShell();
return $this->assert(
new EqualExpectation($expected),
$shell->getOutput(),
@@ -229,7 +229,7 @@ class ShellTestCase extends SimpleTestCase {
* @access public
*/
function assertOutputPattern($pattern, $message = "%s") {
- $shell = &$this->_getShell();
+ $shell = $this->getShell();
return $this->assert(
new PatternExpectation($pattern),
$shell->getOutput(),
@@ -245,7 +245,7 @@ class ShellTestCase extends SimpleTestCase {
* @access public
*/
function assertNoOutputPattern($pattern, $message = "%s") {
- $shell = &$this->_getShell();
+ $shell = $this->getShell();
return $this->assert(
new NoPatternExpectation($pattern),
$shell->getOutput(),
@@ -286,7 +286,6 @@ class ShellTestCase extends SimpleTestCase {
* @access public
*/
function assertFilePattern($pattern, $path, $message = "%s") {
- $shell = &$this->_getShell();
return $this->assert(
new PatternExpectation($pattern),
implode('', file($path)),
@@ -303,7 +302,6 @@ class ShellTestCase extends SimpleTestCase {
* @access public
*/
function assertNoFilePattern($pattern, $path, $message = "%s") {
- $shell = &$this->_getShell();
return $this->assert(
new NoPatternExpectation($pattern),
implode('', file($path)),
@@ -316,8 +314,8 @@ class ShellTestCase extends SimpleTestCase {
* @return Shell Current shell.
* @access protected
*/
- function &_getShell() {
- return $this->_current_shell;
+ protected function getShell() {
+ return $this->current_shell;
}
/**
@@ -325,9 +323,8 @@ class ShellTestCase extends SimpleTestCase {
* @return Shell New shell object.
* @access protected
*/
- function &_createShell() {
- $shell = new SimpleShell();
- return $shell;
+ protected function createShell() {
+ return new SimpleShell();
}
}
-?>
+?>
\ No newline at end of file
diff --git a/lib/simpletestlib/simpletest.php b/lib/simpletestlib/simpletest.php
index 0079a1ffaf9..425c869a825 100644
--- a/lib/simpletestlib/simpletest.php
+++ b/lib/simpletestlib/simpletest.php
@@ -3,17 +3,13 @@
* Global state for SimpleTest and kicker script in future versions.
* @package SimpleTest
* @subpackage UnitTester
- * @version $Id$
+ * @version $Id: simpletest.php 2011 2011-04-29 08:22:48Z pp11 $
*/
/**#@+
* include SimpleTest files
*/
-if (version_compare(phpversion(), '5') >= 0) {
- require_once(dirname(__FILE__) . '/reflection_php5.php');
-} else {
- require_once(dirname(__FILE__) . '/reflection_php4.php');
-}
+require_once(dirname(__FILE__) . '/reflection_php5.php');
require_once(dirname(__FILE__) . '/default_reporter.php');
require_once(dirname(__FILE__) . '/compatibility.php');
/**#@-*/
@@ -29,10 +25,8 @@ class SimpleTest {
/**
* Reads the SimpleTest version from the release file.
* @return string Version string.
- * @static
- * @access public
*/
- function getVersion() {
+ static function getVersion() {
$content = file(dirname(__FILE__) . '/VERSION');
return trim($content[0]);
}
@@ -40,14 +34,10 @@ class SimpleTest {
/**
* Sets the name of a test case to ignore, usually
* because the class is an abstract case that should
- * not be run. Once PHP4 is dropped this will disappear
- * as a public method and "abstract" will rule.
* @param string $class Add a class to ignore.
- * @static
- * @access public
*/
- function ignore($class) {
- $registry = &SimpleTest::_getRegistry();
+ static function ignore($class) {
+ $registry = &SimpleTest::getRegistry();
$registry['IgnoreList'][strtolower($class)] = true;
}
@@ -63,11 +53,9 @@ class SimpleTest {
* the ignore() calls. It's just nice to have the ignore()
* calls at the top of the file before the actual declarations.
* @param array $classes Class names of interest.
- * @static
- * @access public
*/
- function ignoreParentsIfIgnored($classes) {
- $registry = &SimpleTest::_getRegistry();
+ static function ignoreParentsIfIgnored($classes) {
+ $registry = &SimpleTest::getRegistry();
foreach ($classes as $class) {
if (SimpleTest::isIgnored($class)) {
$reflection = new SimpleReflection($class);
@@ -83,13 +71,11 @@ class SimpleTest {
* which can be retrieved with SimpleTest :: preferred() method.
* Instances of the same class are overwritten.
* @param object $object Preferred object
- * @static
- * @access public
* @see preferred()
*/
- function prefer(&$object) {
- $registry = &SimpleTest::_getRegistry();
- $registry['Preferred'][] = &$object;
+ static function prefer($object) {
+ $registry = &SimpleTest::getRegistry();
+ $registry['Preferred'][] = $object;
}
/**
@@ -97,16 +83,14 @@ class SimpleTest {
* can be applied in order to retrieve the object of the specific
* class
* @param array|string $classes Allowed classes or interfaces.
- * @static
- * @access public
* @return array|object|null
* @see prefer()
*/
- function &preferred($classes) {
+ static function preferred($classes) {
if (! is_array($classes)) {
$classes = array($classes);
}
- $registry = &SimpleTest::_getRegistry();
+ $registry = &SimpleTest::getRegistry();
for ($i = count($registry['Preferred']) - 1; $i >= 0; $i--) {
foreach ($classes as $class) {
if (SimpleTestCompatibility::isA($registry['Preferred'][$i], $class)) {
@@ -125,30 +109,12 @@ class SimpleTest {
* use it.
* @param string $class Class name to test.
* @return boolean True if should not be run.
- * @access public
- * @static
*/
- function isIgnored($class) {
- $registry = &SimpleTest::_getRegistry();
+ static function isIgnored($class) {
+ $registry = &SimpleTest::getRegistry();
return isset($registry['IgnoreList'][strtolower($class)]);
}
- /**
- * @deprecated
- */
- function setMockBaseClass($mock_base) {
- $registry = &SimpleTest::_getRegistry();
- $registry['MockBaseClass'] = $mock_base;
- }
-
- /**
- * @deprecated
- */
- function getMockBaseClass() {
- $registry = &SimpleTest::_getRegistry();
- return $registry['MockBaseClass'];
- }
-
/**
* Sets proxy to use on all requests for when
* testing from behind a firewall. Set host
@@ -157,10 +123,9 @@ class SimpleTest {
* @param string $proxy Proxy host as URL.
* @param string $username Proxy username for authentication.
* @param string $password Proxy password for authentication.
- * @access public
*/
- function useProxy($proxy, $username = false, $password = false) {
- $registry = &SimpleTest::_getRegistry();
+ static function useProxy($proxy, $username = false, $password = false) {
+ $registry = &SimpleTest::getRegistry();
$registry['DefaultProxy'] = $proxy;
$registry['DefaultProxyUsername'] = $username;
$registry['DefaultProxyPassword'] = $password;
@@ -169,43 +134,60 @@ class SimpleTest {
/**
* Accessor for default proxy host.
* @return string Proxy URL.
- * @access public
*/
- function getDefaultProxy() {
- $registry = &SimpleTest::_getRegistry();
+ static function getDefaultProxy() {
+ $registry = &SimpleTest::getRegistry();
return $registry['DefaultProxy'];
}
/**
* Accessor for default proxy username.
* @return string Proxy username for authentication.
- * @access public
*/
- function getDefaultProxyUsername() {
- $registry = &SimpleTest::_getRegistry();
+ static function getDefaultProxyUsername() {
+ $registry = &SimpleTest::getRegistry();
return $registry['DefaultProxyUsername'];
}
/**
* Accessor for default proxy password.
* @return string Proxy password for authentication.
- * @access public
*/
- function getDefaultProxyPassword() {
- $registry = &SimpleTest::_getRegistry();
+ static function getDefaultProxyPassword() {
+ $registry = &SimpleTest::getRegistry();
return $registry['DefaultProxyPassword'];
}
+ /**
+ * Accessor for default HTML parsers.
+ * @return array List of parsers to try in
+ * order until one responds true
+ * to can().
+ */
+ static function getParsers() {
+ $registry = &SimpleTest::getRegistry();
+ return $registry['Parsers'];
+ }
+
+ /**
+ * Set the list of HTML parsers to attempt to use by default.
+ * @param array $parsers List of parsers to try in
+ * order until one responds true
+ * to can().
+ */
+ static function setParsers($parsers) {
+ $registry = &SimpleTest::getRegistry();
+ $registry['Parsers'] = $parsers;
+ }
+
/**
* Accessor for global registry of options.
* @return hash All stored values.
- * @access private
- * @static
*/
- function &_getRegistry() {
+ protected static function &getRegistry() {
static $registry = false;
if (! $registry) {
- $registry = SimpleTest::_getDefaults();
+ $registry = SimpleTest::getDefaults();
}
return $registry;
}
@@ -214,10 +196,8 @@ class SimpleTest {
* Accessor for the context of the current
* test run.
* @return SimpleTestContext Current test run.
- * @access public
- * @static
*/
- function &getContext() {
+ static function getContext() {
static $context = false;
if (! $context) {
$context = new SimpleTestContext();
@@ -228,12 +208,10 @@ class SimpleTest {
/**
* Constant default values.
* @return hash All registry defaults.
- * @access private
- * @static
*/
- function _getDefaults() {
+ protected static function getDefaults() {
return array(
- 'StubBaseClass' => 'SimpleStub',
+ 'Parsers' => false,
'MockBaseClass' => 'SimpleMock',
'IgnoreList' => array(),
'DefaultProxy' => false,
@@ -241,6 +219,22 @@ class SimpleTest {
'DefaultProxyPassword' => false,
'Preferred' => array(new HtmlReporter(), new TextReporter(), new XmlReporter()));
}
+
+ /**
+ * @deprecated
+ */
+ static function setMockBaseClass($mock_base) {
+ $registry = &SimpleTest::getRegistry();
+ $registry['MockBaseClass'] = $mock_base;
+ }
+
+ /**
+ * @deprecated
+ */
+ static function getMockBaseClass() {
+ $registry = &SimpleTest::getRegistry();
+ return $registry['MockBaseClass'];
+ }
}
/**
@@ -252,16 +246,16 @@ class SimpleTest {
* @package SimpleTest
*/
class SimpleTestContext {
- var $_test;
- var $_reporter;
- var $_resources;
+ private $test;
+ private $reporter;
+ private $resources;
/**
* Clears down the current context.
* @access public
*/
function clear() {
- $this->_resources = array();
+ $this->resources = array();
}
/**
@@ -269,33 +263,18 @@ class SimpleTestContext {
* global instance can be used by the mock objects
* to send message to the test cases.
* @param SimpleTestCase $test Test case to register.
- * @access public
*/
- function setTest(&$test) {
+ function setTest($test) {
$this->clear();
- $this->_test = &$test;
+ $this->test = $test;
}
-//moodlefix begins
- /**
- * Unsets the current test case instance. Avoids
- * problems when test classes rely on their destructors
- * being called at a predictable time.
- * @access public
- */
- function unsetTest() {
- $this->clear();
- $this->_test = NULL;
- }
-
-//moodlefix ends
/**
* Accessor for currently running test case.
* @return SimpleTestCase Current test.
- * @access public
*/
- function &getTest() {
- return $this->_test;
+ function getTest() {
+ return $this->test;
}
/**
@@ -303,33 +282,29 @@ class SimpleTestContext {
* global instance can be used by the mock objects
* to send messages.
* @param SimpleReporter $reporter Reporter to register.
- * @access public
*/
- function setReporter(&$reporter) {
+ function setReporter($reporter) {
$this->clear();
- $this->_reporter = &$reporter;
+ $this->reporter = $reporter;
}
/**
* Accessor for current reporter.
* @return SimpleReporter Current reporter.
- * @access public
*/
- function &getReporter() {
- return $this->_reporter;
+ function getReporter() {
+ return $this->reporter;
}
/**
* Accessor for the Singleton resource.
* @return object Global resource.
- * @access public
- * @static
*/
- function &get($resource) {
- if (! isset($this->_resources[$resource])) {
- $this->_resources[$resource] = new $resource();
+ function get($resource) {
+ if (! isset($this->resources[$resource])) {
+ $this->resources[$resource] = new $resource();
}
- return $this->_resources[$resource];
+ return $this->resources[$resource];
}
}
@@ -340,15 +315,15 @@ class SimpleTestContext {
* @subpackage UnitTester
*/
class SimpleStackTrace {
- var $_prefixes;
+ private $prefixes;
/**
* Stashes the list of target prefixes.
* @param array $prefixes List of method prefixes
* to search for.
*/
- function SimpleStackTrace($prefixes) {
- $this->_prefixes = $prefixes;
+ function __construct($prefixes) {
+ $this->prefixes = $prefixes;
}
/**
@@ -357,15 +332,14 @@ class SimpleStackTrace {
* @param array $stack List of stack frames.
* @return string Snippet of test report with line
* number and file.
- * @access public
*/
function traceMethod($stack = false) {
- $stack = $stack ? $stack : $this->_captureTrace();
+ $stack = $stack ? $stack : $this->captureTrace();
foreach ($stack as $frame) {
- if ($this->_frameLiesWithinSimpleTestFolder($frame)) {
+ if ($this->frameLiesWithinSimpleTestFolder($frame)) {
continue;
}
- if ($this->_frameMatchesPrefix($frame)) {
+ if ($this->frameMatchesPrefix($frame)) {
return ' at [' . $frame['file'] . ' line ' . $frame['line'] . ']';
}
}
@@ -376,9 +350,8 @@ class SimpleStackTrace {
* Test to see if error is generated by SimpleTest itself.
* @param array $frame PHP stack frame.
* @return boolean True if a SimpleTest file.
- * @access private
*/
- function _frameLiesWithinSimpleTestFolder($frame) {
+ protected function frameLiesWithinSimpleTestFolder($frame) {
if (isset($frame['file'])) {
$path = substr(SIMPLE_TEST, 0, -1);
if (strpos($frame['file'], $path) === 0) {
@@ -394,10 +367,9 @@ class SimpleStackTrace {
* Tries to determine if the method call is an assert, etc.
* @param array $frame PHP stack frame.
* @return boolean True if matches a target.
- * @access private
*/
- function _frameMatchesPrefix($frame) {
- foreach ($this->_prefixes as $prefix) {
+ protected function frameMatchesPrefix($frame) {
+ foreach ($this->prefixes as $prefix) {
if (strncmp($frame['function'], $prefix, strlen($prefix)) == 0) {
return true;
}
@@ -408,84 +380,12 @@ class SimpleStackTrace {
/**
* Grabs a current stack trace.
* @return array Fulle trace.
- * @access private
*/
- function _captureTrace() {
+ protected function captureTrace() {
if (function_exists('debug_backtrace')) {
return array_reverse(debug_backtrace());
}
return array();
}
}
-
-/**
- * @package SimpleTest
- * @subpackage UnitTester
- * @deprecated
- */
-class SimpleTestOptions extends SimpleTest {
-
- /**
- * @deprecated
- */
- function getVersion() {
- return Simpletest::getVersion();
- }
-
- /**
- * @deprecated
- */
- function ignore($class) {
- return Simpletest::ignore($class);
- }
-
- /**
- * @deprecated
- */
- function isIgnored($class) {
- return Simpletest::isIgnored($class);
- }
-
- /**
- * @deprecated
- */
- function setMockBaseClass($mock_base) {
- return Simpletest::setMockBaseClass($mock_base);
- }
-
- /**
- * @deprecated
- */
- function getMockBaseClass() {
- return Simpletest::getMockBaseClass();
- }
-
- /**
- * @deprecated
- */
- function useProxy($proxy, $username = false, $password = false) {
- return Simpletest::useProxy($proxy, $username, $password);
- }
-
- /**
- * @deprecated
- */
- function getDefaultProxy() {
- return Simpletest::getDefaultProxy();
- }
-
- /**
- * @deprecated
- */
- function getDefaultProxyUsername() {
- return Simpletest::getDefaultProxyUsername();
- }
-
- /**
- * @deprecated
- */
- function getDefaultProxyPassword() {
- return Simpletest::getDefaultProxyPassword();
- }
-}
-?>
+?>
\ No newline at end of file
diff --git a/lib/simpletestlib/socket.php b/lib/simpletestlib/socket.php
old mode 100644
new mode 100755
index 735a1986b34..06e8ca62d00
--- a/lib/simpletestlib/socket.php
+++ b/lib/simpletestlib/socket.php
@@ -3,7 +3,7 @@
* base include file for SimpleTest
* @package SimpleTest
* @subpackage MockObjects
- * @version $Id$
+ * @version $Id: socket.php 1953 2009-09-20 01:26:25Z jsweat $
*/
/**#@+
@@ -19,14 +19,14 @@ require_once(dirname(__FILE__) . '/compatibility.php');
* @subpackage WebTester
*/
class SimpleStickyError {
- var $_error = 'Constructor not chained';
+ private $error = 'Constructor not chained';
/**
* Sets the error to empty.
* @access public
*/
- function SimpleStickyError() {
- $this->_clearError();
+ function __construct() {
+ $this->clearError();
}
/**
@@ -35,7 +35,7 @@ class SimpleStickyError {
* @access public
*/
function isError() {
- return ($this->_error != '');
+ return ($this->error != '');
}
/**
@@ -45,7 +45,7 @@ class SimpleStickyError {
* @access public
*/
function getError() {
- return $this->_error;
+ return $this->error;
}
/**
@@ -53,16 +53,112 @@ class SimpleStickyError {
* @param string Error message to stash.
* @access protected
*/
- function _setError($error) {
- $this->_error = $error;
+ function setError($error) {
+ $this->error = $error;
}
/**
* Resets the error state to no error.
* @access protected
*/
- function _clearError() {
- $this->_setError('');
+ function clearError() {
+ $this->setError('');
+ }
+}
+
+/**
+ * @package SimpleTest
+ * @subpackage WebTester
+ */
+class SimpleFileSocket extends SimpleStickyError {
+ private $handle;
+ private $is_open = false;
+ private $sent = '';
+ private $block_size;
+
+ /**
+ * Opens a socket for reading and writing.
+ * @param SimpleUrl $file Target URI to fetch.
+ * @param integer $block_size Size of chunk to read.
+ * @access public
+ */
+ function __construct($file, $block_size = 1024) {
+ parent::__construct();
+ if (! ($this->handle = $this->openFile($file, $error))) {
+ $file_string = $file->asString();
+ $this->setError("Cannot open [$file_string] with [$error]");
+ return;
+ }
+ $this->is_open = true;
+ $this->block_size = $block_size;
+ }
+
+ /**
+ * Writes some data to the socket and saves alocal copy.
+ * @param string $message String to send to socket.
+ * @return boolean True if successful.
+ * @access public
+ */
+ function write($message) {
+ return true;
+ }
+
+ /**
+ * Reads data from the socket. The error suppresion
+ * is a workaround for PHP4 always throwing a warning
+ * with a secure socket.
+ * @return integer/boolean Incoming bytes. False
+ * on error.
+ * @access public
+ */
+ function read() {
+ $raw = @fread($this->handle, $this->block_size);
+ if ($raw === false) {
+ $this->setError('Cannot read from socket');
+ $this->close();
+ }
+ return $raw;
+ }
+
+ /**
+ * Accessor for socket open state.
+ * @return boolean True if open.
+ * @access public
+ */
+ function isOpen() {
+ return $this->is_open;
+ }
+
+ /**
+ * Closes the socket preventing further reads.
+ * Cannot be reopened once closed.
+ * @return boolean True if successful.
+ * @access public
+ */
+ function close() {
+ if (!$this->is_open) return false;
+ $this->is_open = false;
+ return fclose($this->handle);
+ }
+
+ /**
+ * Accessor for content so far.
+ * @return string Bytes sent only.
+ * @access public
+ */
+ function getSent() {
+ return $this->sent;
+ }
+
+ /**
+ * Actually opens the low level socket.
+ * @param SimpleUrl $file SimpleUrl file target.
+ * @param string $error Recipient of error message.
+ * @param integer $timeout Maximum time to wait for connection.
+ * @access protected
+ */
+ protected function openFile($file, &$error) {
+ return @fopen($file->asString(), 'r');
}
}
@@ -72,10 +168,10 @@ class SimpleStickyError {
* @subpackage WebTester
*/
class SimpleSocket extends SimpleStickyError {
- var $_handle;
- var $_is_open = false;
- var $_sent = '';
- var $lock_size;
+ private $handle;
+ private $is_open = false;
+ private $sent = '';
+ private $lock_size;
/**
* Opens a socket for reading and writing.
@@ -85,15 +181,15 @@ class SimpleSocket extends SimpleStickyError {
* @param integer $block_size Size of chunk to read.
* @access public
*/
- function SimpleSocket($host, $port, $timeout, $block_size = 255) {
- $this->SimpleStickyError();
- if (! ($this->_handle = $this->_openSocket($host, $port, $error_number, $error, $timeout))) {
- $this->_setError("Cannot open [$host:$port] with [$error] within [$timeout] seconds");
+ function __construct($host, $port, $timeout, $block_size = 255) {
+ parent::__construct();
+ if (! ($this->handle = $this->openSocket($host, $port, $error_number, $error, $timeout))) {
+ $this->setError("Cannot open [$host:$port] with [$error] within [$timeout] seconds");
return;
}
- $this->_is_open = true;
- $this->_block_size = $block_size;
- SimpleTestCompatibility::setTimeout($this->_handle, $timeout);
+ $this->is_open = true;
+ $this->block_size = $block_size;
+ SimpleTestCompatibility::setTimeout($this->handle, $timeout);
}
/**
@@ -106,16 +202,16 @@ class SimpleSocket extends SimpleStickyError {
if ($this->isError() || ! $this->isOpen()) {
return false;
}
- $count = fwrite($this->_handle, $message);
+ $count = fwrite($this->handle, $message);
if (! $count) {
if ($count === false) {
- $this->_setError('Cannot write to socket');
+ $this->setError('Cannot write to socket');
$this->close();
}
return false;
}
- fflush($this->_handle);
- $this->_sent .= $message;
+ fflush($this->handle);
+ $this->sent .= $message;
return true;
}
@@ -131,9 +227,9 @@ class SimpleSocket extends SimpleStickyError {
if ($this->isError() || ! $this->isOpen()) {
return false;
}
- $raw = @fread($this->_handle, $this->_block_size);
+ $raw = @fread($this->handle, $this->block_size);
if ($raw === false) {
- $this->_setError('Cannot read from socket');
+ $this->setError('Cannot read from socket');
$this->close();
}
return $raw;
@@ -145,7 +241,7 @@ class SimpleSocket extends SimpleStickyError {
* @access public
*/
function isOpen() {
- return $this->_is_open;
+ return $this->is_open;
}
/**
@@ -155,8 +251,8 @@ class SimpleSocket extends SimpleStickyError {
* @access public
*/
function close() {
- $this->_is_open = false;
- return fclose($this->_handle);
+ $this->is_open = false;
+ return fclose($this->handle);
}
/**
@@ -165,7 +261,7 @@ class SimpleSocket extends SimpleStickyError {
* @access public
*/
function getSent() {
- return $this->_sent;
+ return $this->sent;
}
/**
@@ -177,7 +273,7 @@ class SimpleSocket extends SimpleStickyError {
* @param integer $timeout Maximum time to wait for connection.
* @access protected
*/
- function _openSocket($host, $port, &$error_number, &$error, $timeout) {
+ protected function openSocket($host, $port, &$error_number, &$error, $timeout) {
return @fsockopen($host, $port, $error_number, $error, $timeout);
}
}
@@ -196,8 +292,8 @@ class SimpleSecureSocket extends SimpleSocket {
* @param integer $timeout Connection timeout in seconds.
* @access public
*/
- function SimpleSecureSocket($host, $port, $timeout) {
- $this->SimpleSocket($host, $port, $timeout);
+ function __construct($host, $port, $timeout) {
+ parent::__construct($host, $port, $timeout);
}
/**
@@ -209,8 +305,8 @@ class SimpleSecureSocket extends SimpleSocket {
* @param integer $timeout Maximum time to wait for connection.
* @access protected
*/
- function _openSocket($host, $port, &$error_number, &$error, $timeout) {
- return parent::_openSocket("tls://$host", $port, $error_number, $error, $timeout);
+ function openSocket($host, $port, &$error_number, &$error, $timeout) {
+ return parent::openSocket("tls://$host", $port, $error_number, $error, $timeout);
}
}
?>
\ No newline at end of file
diff --git a/lib/simpletestlib/tag.php b/lib/simpletestlib/tag.php
index b0d037ab00f..afe649ec5dd 100644
--- a/lib/simpletestlib/tag.php
+++ b/lib/simpletestlib/tag.php
@@ -3,26 +3,121 @@
* Base include file for SimpleTest.
* @package SimpleTest
* @subpackage WebTester
- * @version $Id$
+ * @version $Id: tag.php 2011 2011-04-29 08:22:48Z pp11 $
*/
-
+
/**#@+
* include SimpleTest files
*/
-require_once(dirname(__FILE__) . '/parser.php');
+require_once(dirname(__FILE__) . '/page.php');
require_once(dirname(__FILE__) . '/encoding.php');
/**#@-*/
+/**
+ * Creates tags and widgets given HTML tag
+ * attributes.
+ * @package SimpleTest
+ * @subpackage WebTester
+ */
+class SimpleTagBuilder {
+
+ /**
+ * Factory for the tag objects. Creates the
+ * appropriate tag object for the incoming tag name
+ * and attributes.
+ * @param string $name HTML tag name.
+ * @param hash $attributes Element attributes.
+ * @return SimpleTag Tag object.
+ * @access public
+ */
+ function createTag($name, $attributes) {
+ static $map = array(
+ 'a' => 'SimpleAnchorTag',
+ 'title' => 'SimpleTitleTag',
+ 'base' => 'SimpleBaseTag',
+ 'button' => 'SimpleButtonTag',
+ 'textarea' => 'SimpleTextAreaTag',
+ 'option' => 'SimpleOptionTag',
+ 'label' => 'SimpleLabelTag',
+ 'form' => 'SimpleFormTag',
+ 'frame' => 'SimpleFrameTag');
+ $attributes = $this->keysToLowerCase($attributes);
+ if (array_key_exists($name, $map)) {
+ $tag_class = $map[$name];
+ return new $tag_class($attributes);
+ } elseif ($name == 'select') {
+ return $this->createSelectionTag($attributes);
+ } elseif ($name == 'input') {
+ return $this->createInputTag($attributes);
+ }
+ return new SimpleTag($name, $attributes);
+ }
+
+ /**
+ * Factory for selection fields.
+ * @param hash $attributes Element attributes.
+ * @return SimpleTag Tag object.
+ * @access protected
+ */
+ protected function createSelectionTag($attributes) {
+ if (isset($attributes['multiple'])) {
+ return new MultipleSelectionTag($attributes);
+ }
+ return new SimpleSelectionTag($attributes);
+ }
+
+ /**
+ * Factory for input tags.
+ * @param hash $attributes Element attributes.
+ * @return SimpleTag Tag object.
+ * @access protected
+ */
+ protected function createInputTag($attributes) {
+ if (! isset($attributes['type'])) {
+ return new SimpleTextTag($attributes);
+ }
+ $type = strtolower(trim($attributes['type']));
+ $map = array(
+ 'submit' => 'SimpleSubmitTag',
+ 'image' => 'SimpleImageSubmitTag',
+ 'checkbox' => 'SimpleCheckboxTag',
+ 'radio' => 'SimpleRadioButtonTag',
+ 'text' => 'SimpleTextTag',
+ 'hidden' => 'SimpleTextTag',
+ 'password' => 'SimpleTextTag',
+ 'file' => 'SimpleUploadTag');
+ if (array_key_exists($type, $map)) {
+ $tag_class = $map[$type];
+ return new $tag_class($attributes);
+ }
+ return false;
+ }
+
+ /**
+ * Make the keys lower case for case insensitive look-ups.
+ * @param hash $map Hash to convert.
+ * @return hash Unchanged values, but keys lower case.
+ * @access private
+ */
+ protected function keysToLowerCase($map) {
+ $lower = array();
+ foreach ($map as $key => $value) {
+ $lower[strtolower($key)] = $value;
+ }
+ return $lower;
+ }
+}
+
/**
* HTML or XML tag.
* @package SimpleTest
* @subpackage WebTester
*/
class SimpleTag {
- var $_name;
- var $_attributes;
- var $_content;
-
+ private $name;
+ private $attributes;
+ private $content;
+
/**
* Starts with a named tag with attributes only.
* @param string $name Tag name.
@@ -31,12 +126,12 @@ class SimpleTag {
* the keys must have been
* converted to lower case.
*/
- function SimpleTag($name, $attributes) {
- $this->_name = strtolower(trim($name));
- $this->_attributes = $attributes;
- $this->_content = '';
+ function __construct($name, $attributes) {
+ $this->name = strtolower(trim($name));
+ $this->attributes = $attributes;
+ $this->content = '';
}
-
+
/**
* Check to see if the tag can have both start and
* end tags with content in between.
@@ -46,7 +141,7 @@ class SimpleTag {
function expectEndTag() {
return true;
}
-
+
/**
* The current tag should not swallow all content for
* itself as it's searchable page content. Private
@@ -66,26 +161,37 @@ class SimpleTag {
* @access public
*/
function addContent($content) {
- $this->_content .= (string)$content;
+ $this->content .= (string)$content;
+ return $this;
}
-
+
/**
* Adds an enclosed tag to the content.
* @param SimpleTag $tag New tag.
* @access public
*/
- function addTag(&$tag) {
+ function addTag($tag) {
}
-
+
+ /**
+ * Adds multiple enclosed tags to the content.
+ * @param array List of SimpleTag objects to be added.
+ */
+ function addTags($tags) {
+ foreach ($tags as $tag) {
+ $this->addTag($tag);
+ }
+ }
+
/**
* Accessor for tag name.
* @return string Name of tag.
* @access public
*/
function getTagName() {
- return $this->_name;
+ return $this->name;
}
-
+
/**
* List of legal child elements.
* @return array List of element names.
@@ -94,7 +200,7 @@ class SimpleTag {
function getChildElements() {
return array();
}
-
+
/**
* Accessor for an attribute.
* @param string $label Attribute name.
@@ -103,31 +209,31 @@ class SimpleTag {
*/
function getAttribute($label) {
$label = strtolower($label);
- if (! isset($this->_attributes[$label])) {
+ if (! isset($this->attributes[$label])) {
return false;
}
- return (string)$this->_attributes[$label];
+ return (string)$this->attributes[$label];
}
-
+
/**
* Sets an attribute.
* @param string $label Attribute name.
* @return string $value New attribute value.
* @access protected
*/
- function _setAttribute($label, $value) {
- $this->_attributes[strtolower($label)] = $value;
+ protected function setAttribute($label, $value) {
+ $this->attributes[strtolower($label)] = $value;
}
-
+
/**
* Accessor for the whole content so far.
* @return string Content as big raw string.
* @access public
*/
function getContent() {
- return $this->_content;
+ return $this->content;
}
-
+
/**
* Accessor for content reduced to visible text. Acts
* like a text mode browser, normalising space and
@@ -136,9 +242,9 @@ class SimpleTag {
* @access public
*/
function getText() {
- return SimpleHtmlSaxParser::normalise($this->_content);
+ return SimplePage::normalise($this->content);
}
-
+
/**
* Test to see if id attribute matches.
* @param string $id ID to test against.
@@ -156,14 +262,14 @@ class SimpleTag {
* @subpackage WebTester
*/
class SimpleBaseTag extends SimpleTag {
-
+
/**
* Starts with a named tag with attributes only.
* @param hash $attributes Attribute names and
* string values.
*/
- function SimpleBaseTag($attributes) {
- $this->SimpleTag('base', $attributes);
+ function __construct($attributes) {
+ parent::__construct('base', $attributes);
}
/**
@@ -182,14 +288,14 @@ class SimpleBaseTag extends SimpleTag {
* @subpackage WebTester
*/
class SimpleTitleTag extends SimpleTag {
-
+
/**
* Starts with a named tag with attributes only.
* @param hash $attributes Attribute names and
* string values.
*/
- function SimpleTitleTag($attributes) {
- $this->SimpleTag('title', $attributes);
+ function __construct($attributes) {
+ parent::__construct('title', $attributes);
}
}
@@ -199,16 +305,16 @@ class SimpleTitleTag extends SimpleTag {
* @subpackage WebTester
*/
class SimpleAnchorTag extends SimpleTag {
-
+
/**
* Starts with a named tag with attributes only.
* @param hash $attributes Attribute names and
* string values.
*/
- function SimpleAnchorTag($attributes) {
- $this->SimpleTag('a', $attributes);
+ function __construct($attributes) {
+ parent::__construct('a', $attributes);
}
-
+
/**
* Accessor for URL as string.
* @return string Coerced as string.
@@ -229,33 +335,33 @@ class SimpleAnchorTag extends SimpleTag {
* @subpackage WebTester
*/
class SimpleWidget extends SimpleTag {
- var $_value;
- var $_label;
- var $_is_set;
-
+ private $value;
+ private $label;
+ private $is_set;
+
/**
* Starts with a named tag with attributes only.
* @param string $name Tag name.
* @param hash $attributes Attribute names and
* string values.
*/
- function SimpleWidget($name, $attributes) {
- $this->SimpleTag($name, $attributes);
- $this->_value = false;
- $this->_label = false;
- $this->_is_set = false;
+ function __construct($name, $attributes) {
+ parent::__construct($name, $attributes);
+ $this->value = false;
+ $this->label = false;
+ $this->is_set = false;
}
-
+
/**
* Accessor for name submitted as the key in
- * GET/POST variables hash.
+ * GET/POST privateiables hash.
* @return string Parsed value.
* @access public
*/
function getName() {
return $this->getAttribute('name');
}
-
+
/**
* Accessor for default value parsed with the tag.
* @return string Parsed value.
@@ -264,7 +370,7 @@ class SimpleWidget extends SimpleTag {
function getDefault() {
return $this->getAttribute('value');
}
-
+
/**
* Accessor for currently set value or default if
* none.
@@ -273,12 +379,12 @@ class SimpleWidget extends SimpleTag {
* @access public
*/
function getValue() {
- if (! $this->_is_set) {
+ if (! $this->is_set) {
return $this->getDefault();
}
- return $this->_value;
+ return $this->value;
}
-
+
/**
* Sets the current form element value.
* @param string $value New value.
@@ -286,20 +392,20 @@ class SimpleWidget extends SimpleTag {
* @access public
*/
function setValue($value) {
- $this->_value = $value;
- $this->_is_set = true;
+ $this->value = $value;
+ $this->is_set = true;
return true;
}
-
+
/**
* Resets the form element value back to the
* default.
* @access public
*/
function resetValue() {
- $this->_is_set = false;
+ $this->is_set = false;
}
-
+
/**
* Allows setting of a label externally, say by a
* label tag.
@@ -307,9 +413,10 @@ class SimpleWidget extends SimpleTag {
* @access public
*/
function setLabel($label) {
- $this->_label = trim($label);
+ $this->label = trim($label);
+ return $this;
}
-
+
/**
* Reads external or internal label.
* @param string $label Label to test.
@@ -317,15 +424,15 @@ class SimpleWidget extends SimpleTag {
* @access public
*/
function isLabel($label) {
- return $this->_label == trim($label);
+ return $this->label == trim($label);
}
-
+
/**
* Dispatches the value into the form encoded packet.
* @param SimpleEncoding $encoding Form packet.
* @access public
*/
- function write(&$encoding) {
+ function write($encoding) {
if ($this->getName()) {
$encoding->add($this->getName(), $this->getValue());
}
@@ -338,19 +445,19 @@ class SimpleWidget extends SimpleTag {
* @subpackage WebTester
*/
class SimpleTextTag extends SimpleWidget {
-
+
/**
* Starts with a named tag with attributes only.
* @param hash $attributes Attribute names and
* string values.
*/
- function SimpleTextTag($attributes) {
- $this->SimpleWidget('input', $attributes);
+ function __construct($attributes) {
+ parent::__construct('input', $attributes);
if ($this->getAttribute('value') === false) {
- $this->_setAttribute('value', '');
+ $this->setAttribute('value', '');
}
}
-
+
/**
* Tag contains no content.
* @return boolean False.
@@ -359,7 +466,7 @@ class SimpleTextTag extends SimpleWidget {
function expectEndTag() {
return false;
}
-
+
/**
* Sets the current form element value. Cannot
* change the value of a hidden field.
@@ -381,19 +488,19 @@ class SimpleTextTag extends SimpleWidget {
* @subpackage WebTester
*/
class SimpleSubmitTag extends SimpleWidget {
-
+
/**
* Starts with a named tag with attributes only.
* @param hash $attributes Attribute names and
* string values.
*/
- function SimpleSubmitTag($attributes) {
- $this->SimpleWidget('input', $attributes);
+ function __construct($attributes) {
+ parent::__construct('input', $attributes);
if ($this->getAttribute('value') === false) {
- $this->_setAttribute('value', 'Submit');
+ $this->setAttribute('value', 'Submit');
}
}
-
+
/**
* Tag contains no end element.
* @return boolean False.
@@ -402,7 +509,7 @@ class SimpleSubmitTag extends SimpleWidget {
function expectEndTag() {
return false;
}
-
+
/**
* Disables the setting of the button value.
* @param string $value Ignored.
@@ -412,7 +519,7 @@ class SimpleSubmitTag extends SimpleWidget {
function setValue($value) {
return false;
}
-
+
/**
* Value of browser visible text.
* @return string Visible label.
@@ -421,7 +528,7 @@ class SimpleSubmitTag extends SimpleWidget {
function getLabel() {
return $this->getValue();
}
-
+
/**
* Test for a label match when searching.
* @param string $label Label to test.
@@ -432,23 +539,23 @@ class SimpleSubmitTag extends SimpleWidget {
return trim($label) == trim($this->getLabel());
}
}
-
+
/**
* Image button as input tag.
* @package SimpleTest
* @subpackage WebTester
*/
class SimpleImageSubmitTag extends SimpleWidget {
-
+
/**
* Starts with a named tag with attributes only.
* @param hash $attributes Attribute names and
* string values.
*/
- function SimpleImageSubmitTag($attributes) {
- $this->SimpleWidget('input', $attributes);
+ function __construct($attributes) {
+ parent::__construct('input', $attributes);
}
-
+
/**
* Tag contains no end element.
* @return boolean False.
@@ -457,7 +564,7 @@ class SimpleImageSubmitTag extends SimpleWidget {
function expectEndTag() {
return false;
}
-
+
/**
* Disables the setting of the button value.
* @param string $value Ignored.
@@ -467,7 +574,7 @@ class SimpleImageSubmitTag extends SimpleWidget {
function setValue($value) {
return false;
}
-
+
/**
* Value of browser visible text.
* @return string Visible label.
@@ -479,7 +586,7 @@ class SimpleImageSubmitTag extends SimpleWidget {
}
return $this->getAttribute('alt');
}
-
+
/**
* Test for a label match when searching.
* @param string $label Label to test.
@@ -489,7 +596,7 @@ class SimpleImageSubmitTag extends SimpleWidget {
function isLabel($label) {
return trim($label) == trim($this->getLabel());
}
-
+
/**
* Dispatches the value into the form encoded packet.
* @param SimpleEncoding $encoding Form packet.
@@ -497,7 +604,7 @@ class SimpleImageSubmitTag extends SimpleWidget {
* @param integer $y Y coordinate of click.
* @access public
*/
- function write(&$encoding, $x, $y) {
+ function write($encoding, $x = 1, $y = 1) {
if ($this->getName()) {
$encoding->add($this->getName() . '.x', $x);
$encoding->add($this->getName() . '.y', $y);
@@ -507,24 +614,24 @@ class SimpleImageSubmitTag extends SimpleWidget {
}
}
}
-
+
/**
* Submit button as button tag.
* @package SimpleTest
* @subpackage WebTester
*/
class SimpleButtonTag extends SimpleWidget {
-
+
/**
* Starts with a named tag with attributes only.
* Defaults are very browser dependent.
* @param hash $attributes Attribute names and
* string values.
*/
- function SimpleButtonTag($attributes) {
- $this->SimpleWidget('button', $attributes);
+ function __construct($attributes) {
+ parent::__construct('button', $attributes);
}
-
+
/**
* Check to see if the tag can have both start and
* end tags with content in between.
@@ -534,7 +641,7 @@ class SimpleButtonTag extends SimpleWidget {
function expectEndTag() {
return true;
}
-
+
/**
* Disables the setting of the button value.
* @param string $value Ignored.
@@ -544,7 +651,7 @@ class SimpleButtonTag extends SimpleWidget {
function setValue($value) {
return false;
}
-
+
/**
* Value of browser visible text.
* @return string Visible label.
@@ -553,7 +660,7 @@ class SimpleButtonTag extends SimpleWidget {
function getLabel() {
return $this->getContent();
}
-
+
/**
* Test for a label match when searching.
* @param string $label Label to test.
@@ -571,25 +678,25 @@ class SimpleButtonTag extends SimpleWidget {
* @subpackage WebTester
*/
class SimpleTextAreaTag extends SimpleWidget {
-
+
/**
* Starts with a named tag with attributes only.
* @param hash $attributes Attribute names and
* string values.
*/
- function SimpleTextAreaTag($attributes) {
- $this->SimpleWidget('textarea', $attributes);
+ function __construct($attributes) {
+ parent::__construct('textarea', $attributes);
}
-
+
/**
* Accessor for starting value.
* @return string Parsed value.
* @access public
*/
function getDefault() {
- return $this->_wrap(SimpleHtmlSaxParser::decodeHtml($this->getContent()));
+ return $this->wrap(html_entity_decode($this->getContent(), ENT_QUOTES));
}
-
+
/**
* Applies word wrapping if needed.
* @param string $value New value.
@@ -597,15 +704,15 @@ class SimpleTextAreaTag extends SimpleWidget {
* @access public
*/
function setValue($value) {
- return parent::setValue($this->_wrap($value));
+ return parent::setValue($this->wrap($value));
}
-
+
/**
* Test to see if text should be wrapped.
* @return boolean True if wrapping on.
* @access private
*/
- function _wrapIsEnabled() {
+ function wrapIsEnabled() {
if ($this->getAttribute('cols')) {
$wrap = $this->getAttribute('wrap');
if (($wrap == 'physical') || ($wrap == 'hard')) {
@@ -614,7 +721,7 @@ class SimpleTextAreaTag extends SimpleWidget {
}
return false;
}
-
+
/**
* Performs the formatting that is peculiar to
* this tag. There is strange behaviour in this
@@ -625,13 +732,13 @@ class SimpleTextAreaTag extends SimpleWidget {
* returns and line feeds
* @access private
*/
- function _wrap($text) {
+ protected function wrap($text) {
$text = str_replace("\r\r\n", "\r\n", str_replace("\n", "\r\n", $text));
$text = str_replace("\r\n\n", "\r\n", str_replace("\r", "\r\n", $text));
if (strncmp($text, "\r\n", strlen("\r\n")) == 0) {
$text = substr($text, strlen("\r\n"));
}
- if ($this->_wrapIsEnabled()) {
+ if ($this->wrapIsEnabled()) {
return wordwrap(
$text,
(integer)$this->getAttribute('cols'),
@@ -639,7 +746,7 @@ class SimpleTextAreaTag extends SimpleWidget {
}
return $text;
}
-
+
/**
* The content of textarea is not part of the page.
* @return boolean True.
@@ -656,16 +763,16 @@ class SimpleTextAreaTag extends SimpleWidget {
* @subpackage WebTester
*/
class SimpleUploadTag extends SimpleWidget {
-
+
/**
* Starts with attributes only.
* @param hash $attributes Attribute names and
* string values.
*/
- function SimpleUploadTag($attributes) {
- $this->SimpleWidget('input', $attributes);
+ function __construct($attributes) {
+ parent::__construct('input', $attributes);
}
-
+
/**
* Tag contains no content.
* @return boolean False.
@@ -674,13 +781,13 @@ class SimpleUploadTag extends SimpleWidget {
function expectEndTag() {
return false;
}
-
+
/**
* Dispatches the value into the form encoded packet.
* @param SimpleEncoding $encoding Form packet.
* @access public
*/
- function write(&$encoding) {
+ function write($encoding) {
if (! file_exists($this->getValue())) {
return;
}
@@ -697,39 +804,40 @@ class SimpleUploadTag extends SimpleWidget {
* @subpackage WebTester
*/
class SimpleSelectionTag extends SimpleWidget {
- var $_options;
- var $_choice;
-
+ private $options;
+ private $choice;
+
/**
* Starts with attributes only.
* @param hash $attributes Attribute names and
* string values.
*/
- function SimpleSelectionTag($attributes) {
- $this->SimpleWidget('select', $attributes);
- $this->_options = array();
- $this->_choice = false;
+ function __construct($attributes) {
+ parent::__construct('select', $attributes);
+ $this->options = array();
+ $this->choice = false;
}
-
+
/**
* Adds an option tag to a selection field.
* @param SimpleOptionTag $tag New option.
* @access public
*/
- function addTag(&$tag) {
+ function addTag($tag) {
if ($tag->getTagName() == 'option') {
- $this->_options[] = &$tag;
+ $this->options[] = $tag;
}
}
-
+
/**
* Text within the selection element is ignored.
* @param string $content Ignored.
* @access public
*/
function addContent($content) {
+ return $this;
}
-
+
/**
* Scans options for defaults. If none, then
* the first option is selected.
@@ -737,17 +845,17 @@ class SimpleSelectionTag extends SimpleWidget {
* @access public
*/
function getDefault() {
- for ($i = 0, $count = count($this->_options); $i < $count; $i++) {
- if ($this->_options[$i]->getAttribute('selected') !== false) {
- return $this->_options[$i]->getDefault();
+ for ($i = 0, $count = count($this->options); $i < $count; $i++) {
+ if ($this->options[$i]->getAttribute('selected') !== false) {
+ return $this->options[$i]->getDefault();
}
}
if ($count > 0) {
- return $this->_options[0]->getDefault();
+ return $this->options[0]->getDefault();
}
return '';
}
-
+
/**
* Can only set allowed values.
* @param string $value New choice.
@@ -755,15 +863,15 @@ class SimpleSelectionTag extends SimpleWidget {
* @access public
*/
function setValue($value) {
- for ($i = 0, $count = count($this->_options); $i < $count; $i++) {
- if ($this->_options[$i]->isValue($value)) {
- $this->_choice = $i;
+ for ($i = 0, $count = count($this->options); $i < $count; $i++) {
+ if ($this->options[$i]->isValue($value)) {
+ $this->choice = $i;
return true;
}
}
return false;
}
-
+
/**
* Accessor for current selection value.
* @return string Value attribute or
@@ -771,10 +879,10 @@ class SimpleSelectionTag extends SimpleWidget {
* @access public
*/
function getValue() {
- if ($this->_choice === false) {
+ if ($this->choice === false) {
return $this->getDefault();
}
- return $this->_options[$this->_choice]->getValue();
+ return $this->options[$this->choice]->getValue();
}
}
@@ -784,39 +892,40 @@ class SimpleSelectionTag extends SimpleWidget {
* @subpackage WebTester
*/
class MultipleSelectionTag extends SimpleWidget {
- var $_options;
- var $_values;
-
+ private $options;
+ private $values;
+
/**
* Starts with attributes only.
* @param hash $attributes Attribute names and
* string values.
*/
- function MultipleSelectionTag($attributes) {
- $this->SimpleWidget('select', $attributes);
- $this->_options = array();
- $this->_values = false;
+ function __construct($attributes) {
+ parent::__construct('select', $attributes);
+ $this->options = array();
+ $this->values = false;
}
-
+
/**
* Adds an option tag to a selection field.
* @param SimpleOptionTag $tag New option.
* @access public
*/
- function addTag(&$tag) {
+ function addTag($tag) {
if ($tag->getTagName() == 'option') {
- $this->_options[] = &$tag;
+ $this->options[] = &$tag;
}
}
-
+
/**
* Text within the selection element is ignored.
* @param string $content Ignored.
* @access public
*/
function addContent($content) {
+ return $this;
}
-
+
/**
* Scans options for defaults to populate the
* value array().
@@ -825,14 +934,14 @@ class MultipleSelectionTag extends SimpleWidget {
*/
function getDefault() {
$default = array();
- for ($i = 0, $count = count($this->_options); $i < $count; $i++) {
- if ($this->_options[$i]->getAttribute('selected') !== false) {
- $default[] = $this->_options[$i]->getDefault();
+ for ($i = 0, $count = count($this->options); $i < $count; $i++) {
+ if ($this->options[$i]->getAttribute('selected') !== false) {
+ $default[] = $this->options[$i]->getDefault();
}
}
return $default;
}
-
+
/**
* Can only set allowed values. Any illegal value
* will result in a failure, but all correct values
@@ -845,9 +954,9 @@ class MultipleSelectionTag extends SimpleWidget {
$achieved = array();
foreach ($desired as $value) {
$success = false;
- for ($i = 0, $count = count($this->_options); $i < $count; $i++) {
- if ($this->_options[$i]->isValue($value)) {
- $achieved[] = $this->_options[$i]->getValue();
+ for ($i = 0, $count = count($this->options); $i < $count; $i++) {
+ if ($this->options[$i]->isValue($value)) {
+ $achieved[] = $this->options[$i]->getValue();
$success = true;
break;
}
@@ -856,20 +965,20 @@ class MultipleSelectionTag extends SimpleWidget {
return false;
}
}
- $this->_values = $achieved;
+ $this->values = $achieved;
return true;
}
-
+
/**
* Accessor for current selection value.
* @return array List of currently set options.
* @access public
*/
function getValue() {
- if ($this->_values === false) {
+ if ($this->values === false) {
return $this->getDefault();
}
- return $this->_values;
+ return $this->values;
}
}
@@ -879,14 +988,14 @@ class MultipleSelectionTag extends SimpleWidget {
* @subpackage WebTester
*/
class SimpleOptionTag extends SimpleWidget {
-
+
/**
* Stashes the attributes.
*/
- function SimpleOptionTag($attributes) {
- $this->SimpleWidget('option', $attributes);
+ function __construct($attributes) {
+ parent::__construct('option', $attributes);
}
-
+
/**
* Does nothing.
* @param string $value Ignored.
@@ -896,7 +1005,7 @@ class SimpleOptionTag extends SimpleWidget {
function setValue($value) {
return false;
}
-
+
/**
* Test to see if a value matches the option.
* @param string $compare Value to compare with.
@@ -908,9 +1017,9 @@ class SimpleOptionTag extends SimpleWidget {
if (trim($this->getValue()) == $compare) {
return true;
}
- return trim($this->getContent()) == $compare;
+ return trim(strip_tags($this->getContent())) == $compare;
}
-
+
/**
* Accessor for starting value. Will be set to
* the option label if no value exists.
@@ -919,11 +1028,11 @@ class SimpleOptionTag extends SimpleWidget {
*/
function getDefault() {
if ($this->getAttribute('value') === false) {
- return $this->getContent();
+ return strip_tags($this->getContent());
}
return $this->getAttribute('value');
}
-
+
/**
* The content of options is not part of the page.
* @return boolean True.
@@ -940,18 +1049,18 @@ class SimpleOptionTag extends SimpleWidget {
* @subpackage WebTester
*/
class SimpleRadioButtonTag extends SimpleWidget {
-
+
/**
* Stashes the attributes.
* @param array $attributes Hash of attributes.
*/
- function SimpleRadioButtonTag($attributes) {
- $this->SimpleWidget('input', $attributes);
+ function __construct($attributes) {
+ parent::__construct('input', $attributes);
if ($this->getAttribute('value') === false) {
- $this->_setAttribute('value', 'on');
+ $this->setAttribute('value', 'on');
}
}
-
+
/**
* Tag contains no content.
* @return boolean False.
@@ -960,7 +1069,7 @@ class SimpleRadioButtonTag extends SimpleWidget {
function expectEndTag() {
return false;
}
-
+
/**
* The only allowed value sn the one in the
* "value" attribute.
@@ -977,7 +1086,7 @@ class SimpleRadioButtonTag extends SimpleWidget {
}
return parent::setValue($value);
}
-
+
/**
* Accessor for starting value.
* @return string Parsed value.
@@ -997,19 +1106,19 @@ class SimpleRadioButtonTag extends SimpleWidget {
* @subpackage WebTester
*/
class SimpleCheckboxTag extends SimpleWidget {
-
+
/**
* Starts with attributes only.
* @param hash $attributes Attribute names and
* string values.
*/
- function SimpleCheckboxTag($attributes) {
- $this->SimpleWidget('input', $attributes);
+ function __construct($attributes) {
+ parent::__construct('input', $attributes);
if ($this->getAttribute('value') === false) {
- $this->_setAttribute('value', 'on');
+ $this->setAttribute('value', 'on');
}
}
-
+
/**
* Tag contains no content.
* @return boolean False.
@@ -1018,7 +1127,7 @@ class SimpleCheckboxTag extends SimpleWidget {
function expectEndTag() {
return false;
}
-
+
/**
* The only allowed value in the one in the
* "value" attribute. The default for this
@@ -1040,7 +1149,7 @@ class SimpleCheckboxTag extends SimpleWidget {
}
return parent::setValue($value);
}
-
+
/**
* Accessor for starting value. The default
* value is "on".
@@ -1061,24 +1170,24 @@ class SimpleCheckboxTag extends SimpleWidget {
* @subpackage WebTester
*/
class SimpleTagGroup {
- var $_widgets = array();
+ private $widgets = array();
/**
* Adds a tag to the group.
* @param SimpleWidget $widget
* @access public
*/
- function addWidget(&$widget) {
- $this->_widgets[] = &$widget;
+ function addWidget($widget) {
+ $this->widgets[] = $widget;
}
-
+
/**
* Accessor to widget set.
* @return array All widgets.
* @access protected
*/
- function &_getWidgets() {
- return $this->_widgets;
+ protected function &getWidgets() {
+ return $this->widgets;
}
/**
@@ -1090,7 +1199,7 @@ class SimpleTagGroup {
function getAttribute($label) {
return false;
}
-
+
/**
* Fetches the name for the widget from the first
* member.
@@ -1098,11 +1207,11 @@ class SimpleTagGroup {
* @access public
*/
function getName() {
- if (count($this->_widgets) > 0) {
- return $this->_widgets[0]->getName();
+ if (count($this->widgets) > 0) {
+ return $this->widgets[0]->getName();
}
}
-
+
/**
* Scans the widgets for one with the appropriate
* ID field.
@@ -1111,14 +1220,14 @@ class SimpleTagGroup {
* @access public
*/
function isId($id) {
- for ($i = 0, $count = count($this->_widgets); $i < $count; $i++) {
- if ($this->_widgets[$i]->isId($id)) {
+ for ($i = 0, $count = count($this->widgets); $i < $count; $i++) {
+ if ($this->widgets[$i]->isId($id)) {
return true;
}
}
return false;
}
-
+
/**
* Scans the widgets for one with the appropriate
* attached label.
@@ -1127,20 +1236,20 @@ class SimpleTagGroup {
* @access public
*/
function isLabel($label) {
- for ($i = 0, $count = count($this->_widgets); $i < $count; $i++) {
- if ($this->_widgets[$i]->isLabel($label)) {
+ for ($i = 0, $count = count($this->widgets); $i < $count; $i++) {
+ if ($this->widgets[$i]->isLabel($label)) {
return true;
}
}
return false;
}
-
+
/**
* Dispatches the value into the form encoded packet.
* @param SimpleEncoding $encoding Form packet.
* @access public
*/
- function write(&$encoding) {
+ function write($encoding) {
$encoding->add($this->getName(), $this->getValue());
}
}
@@ -1151,7 +1260,7 @@ class SimpleTagGroup {
* @subpackage WebTester
*/
class SimpleCheckboxGroup extends SimpleTagGroup {
-
+
/**
* Accessor for current selected widget or false
* if none.
@@ -1160,15 +1269,15 @@ class SimpleCheckboxGroup extends SimpleTagGroup {
*/
function getValue() {
$values = array();
- $widgets = &$this->_getWidgets();
+ $widgets = $this->getWidgets();
for ($i = 0, $count = count($widgets); $i < $count; $i++) {
if ($widgets[$i]->getValue() !== false) {
$values[] = $widgets[$i]->getValue();
}
}
- return $this->_coerceValues($values);
+ return $this->coerceValues($values);
}
-
+
/**
* Accessor for starting value that is active.
* @return string/array Widget values or false if none.
@@ -1176,15 +1285,15 @@ class SimpleCheckboxGroup extends SimpleTagGroup {
*/
function getDefault() {
$values = array();
- $widgets = &$this->_getWidgets();
+ $widgets = $this->getWidgets();
for ($i = 0, $count = count($widgets); $i < $count; $i++) {
if ($widgets[$i]->getDefault() !== false) {
$values[] = $widgets[$i]->getDefault();
}
}
- return $this->_coerceValues($values);
+ return $this->coerceValues($values);
}
-
+
/**
* Accessor for current set values.
* @param string/array/boolean $values Either a single string, a
@@ -1193,11 +1302,11 @@ class SimpleCheckboxGroup extends SimpleTagGroup {
* @access public
*/
function setValue($values) {
- $values = $this->_makeArray($values);
- if (! $this->_valuesArePossible($values)) {
+ $values = $this->makeArray($values);
+ if (! $this->valuesArePossible($values)) {
return false;
}
- $widgets = &$this->_getWidgets();
+ $widgets = $this->getWidgets();
for ($i = 0, $count = count($widgets); $i < $count; $i++) {
$possible = $widgets[$i]->getAttribute('value');
if (in_array($widgets[$i]->getAttribute('value'), $values)) {
@@ -1208,7 +1317,7 @@ class SimpleCheckboxGroup extends SimpleTagGroup {
}
return true;
}
-
+
/**
* Tests to see if a possible value set is legal.
* @param string/array/boolean $values Either a single string, a
@@ -1217,9 +1326,9 @@ class SimpleCheckboxGroup extends SimpleTagGroup {
* missing value.
* @access private
*/
- function _valuesArePossible($values) {
+ protected function valuesArePossible($values) {
$matches = array();
- $widgets = &$this->_getWidgets();
+ $widgets = &$this->getWidgets();
for ($i = 0, $count = count($widgets); $i < $count; $i++) {
$possible = $widgets[$i]->getAttribute('value');
if (in_array($possible, $values)) {
@@ -1228,7 +1337,7 @@ class SimpleCheckboxGroup extends SimpleTagGroup {
}
return ($values == $matches);
}
-
+
/**
* Converts the output to an appropriate format. This means
* that no values is false, a single value is just that
@@ -1237,7 +1346,7 @@ class SimpleCheckboxGroup extends SimpleTagGroup {
* @return string/array/boolean Expected format for a tag.
* @access private
*/
- function _coerceValues($values) {
+ protected function coerceValues($values) {
if (count($values) == 0) {
return false;
} elseif (count($values) == 1) {
@@ -1246,7 +1355,7 @@ class SimpleCheckboxGroup extends SimpleTagGroup {
return $values;
}
}
-
+
/**
* Converts false or string into array. The opposite of
* the coercian method.
@@ -1256,7 +1365,7 @@ class SimpleCheckboxGroup extends SimpleTagGroup {
* @return array List of values, possibly empty.
* @access private
*/
- function _makeArray($value) {
+ protected function makeArray($value) {
if ($value === false) {
return array();
}
@@ -1274,7 +1383,7 @@ class SimpleCheckboxGroup extends SimpleTagGroup {
* @subpackage WebTester
*/
class SimpleRadioGroup extends SimpleTagGroup {
-
+
/**
* Each tag is tried in turn until one is
* successfully set. The others will be
@@ -1284,11 +1393,11 @@ class SimpleRadioGroup extends SimpleTagGroup {
* @access public
*/
function setValue($value) {
- if (! $this->_valueIsPossible($value)) {
+ if (! $this->valueIsPossible($value)) {
return false;
}
$index = false;
- $widgets = &$this->_getWidgets();
+ $widgets = $this->getWidgets();
for ($i = 0, $count = count($widgets); $i < $count; $i++) {
if (! $widgets[$i]->setValue($value)) {
$widgets[$i]->setValue(false);
@@ -1296,15 +1405,15 @@ class SimpleRadioGroup extends SimpleTagGroup {
}
return true;
}
-
+
/**
* Tests to see if a value is allowed.
* @param string Attempted value.
* @return boolean True if a valid value.
* @access private
*/
- function _valueIsPossible($value) {
- $widgets = &$this->_getWidgets();
+ protected function valueIsPossible($value) {
+ $widgets = $this->getWidgets();
for ($i = 0, $count = count($widgets); $i < $count; $i++) {
if ($widgets[$i]->getAttribute('value') == $value) {
return true;
@@ -1312,7 +1421,7 @@ class SimpleRadioGroup extends SimpleTagGroup {
}
return false;
}
-
+
/**
* Accessor for current selected widget or false
* if none.
@@ -1321,7 +1430,7 @@ class SimpleRadioGroup extends SimpleTagGroup {
* @access public
*/
function getValue() {
- $widgets = &$this->_getWidgets();
+ $widgets = $this->getWidgets();
for ($i = 0, $count = count($widgets); $i < $count; $i++) {
if ($widgets[$i]->getValue() !== false) {
return $widgets[$i]->getValue();
@@ -1329,7 +1438,7 @@ class SimpleRadioGroup extends SimpleTagGroup {
}
return false;
}
-
+
/**
* Accessor for starting value that is active.
* @return string/boolean Value of first checked
@@ -1337,7 +1446,7 @@ class SimpleRadioGroup extends SimpleTagGroup {
* @access public
*/
function getDefault() {
- $widgets = &$this->_getWidgets();
+ $widgets = $this->getWidgets();
for ($i = 0, $count = count($widgets); $i < $count; $i++) {
if ($widgets[$i]->getDefault() !== false) {
return $widgets[$i]->getDefault();
@@ -1353,16 +1462,16 @@ class SimpleRadioGroup extends SimpleTagGroup {
* @subpackage WebTester
*/
class SimpleLabelTag extends SimpleTag {
-
+
/**
* Starts with a named tag with attributes only.
* @param hash $attributes Attribute names and
* string values.
*/
- function SimpleLabelTag($attributes) {
- $this->SimpleTag('label', $attributes);
+ function __construct($attributes) {
+ parent::__construct('label', $attributes);
}
-
+
/**
* Access for the ID to attach the label to.
* @return string For attribute.
@@ -1379,14 +1488,14 @@ class SimpleLabelTag extends SimpleTag {
* @subpackage WebTester
*/
class SimpleFormTag extends SimpleTag {
-
+
/**
* Starts with a named tag with attributes only.
* @param hash $attributes Attribute names and
* string values.
*/
- function SimpleFormTag($attributes) {
- $this->SimpleTag('form', $attributes);
+ function __construct($attributes) {
+ parent::__construct('form', $attributes);
}
}
@@ -1396,16 +1505,16 @@ class SimpleFormTag extends SimpleTag {
* @subpackage WebTester
*/
class SimpleFrameTag extends SimpleTag {
-
+
/**
* Starts with a named tag with attributes only.
* @param hash $attributes Attribute names and
* string values.
*/
- function SimpleFrameTag($attributes) {
- $this->SimpleTag('frame', $attributes);
+ function __construct($attributes) {
+ parent::__construct('frame', $attributes);
}
-
+
/**
* Tag contains no content.
* @return boolean False.
diff --git a/lib/simpletestlib/test_case.php b/lib/simpletestlib/test_case.php
index bc59e6573a1..18a283059a1 100644
--- a/lib/simpletestlib/test_case.php
+++ b/lib/simpletestlib/test_case.php
@@ -3,7 +3,7 @@
* Base include file for SimpleTest
* @package SimpleTest
* @subpackage UnitTester
- * @version $Id$
+ * @version $Id: test_case.php 2012 2011-04-29 08:57:00Z pp11 $
*/
/**#@+
@@ -17,19 +17,15 @@ require_once(dirname(__FILE__) . '/scorer.php');
require_once(dirname(__FILE__) . '/expectation.php');
require_once(dirname(__FILE__) . '/dumper.php');
require_once(dirname(__FILE__) . '/simpletest.php');
-if (version_compare(phpversion(), '5') >= 0) {
- require_once(dirname(__FILE__) . '/exceptions.php');
- require_once(dirname(__FILE__) . '/reflection_php5.php');
-} else {
- require_once(dirname(__FILE__) . '/reflection_php4.php');
-}
+require_once(dirname(__FILE__) . '/exceptions.php');
+require_once(dirname(__FILE__) . '/reflection_php5.php');
+/**#@-*/
if (! defined('SIMPLE_TEST')) {
/**
* @ignore
*/
define('SIMPLE_TEST', dirname(__FILE__) . DIRECTORY_SEPARATOR);
}
-/**#@-*/
/**
* Basic test case. This is the smallest unit of a test
@@ -40,10 +36,10 @@ if (! defined('SIMPLE_TEST')) {
* @subpackage UnitTester
*/
class SimpleTestCase {
- var $_label = false;
- var $_reporter;
- var $_observers;
- var $_should_skip = false;
+ private $label = false;
+ protected $reporter;
+ private $observers;
+ private $should_skip = false;
/**
* Sets up the test with no display.
@@ -51,9 +47,9 @@ class SimpleTestCase {
* the class name is used.
* @access public
*/
- function SimpleTestCase($label = false) {
+ function __construct($label = false) {
if ($label) {
- $this->_label = $label;
+ $this->label = $label;
}
}
@@ -63,7 +59,7 @@ class SimpleTestCase {
* @access public
*/
function getLabel() {
- return $this->_label ? $this->_label : get_class($this);
+ return $this->label ? $this->label : get_class($this);
}
/**
@@ -83,13 +79,21 @@ class SimpleTestCase {
* @access public
*/
function skipIf($should_skip, $message = '%s') {
- if ($should_skip && ! $this->_should_skip) {
- $this->_should_skip = true;
+ if ($should_skip && ! $this->should_skip) {
+ $this->should_skip = true;
$message = sprintf($message, 'Skipping [' . get_class($this) . ']');
- $this->_reporter->paintSkip($message . $this->getAssertionLine());
+ $this->reporter->paintSkip($message . $this->getAssertionLine());
}
}
+ /**
+ * Accessor for the private variable $_shoud_skip
+ * @access public
+ */
+ function shouldSkip() {
+ return $this->should_skip;
+ }
+
/**
* Will issue a message to the reporter and tell the test
* case to skip if the incoming flag is false.
@@ -106,12 +110,9 @@ class SimpleTestCase {
* @return SimpleInvoker Individual test runner.
* @access public
*/
- function &createInvoker() {
- $invoker = new SimpleErrorTrappingInvoker(new SimpleInvoker($this));
- if (version_compare(phpversion(), '5') >= 0) {
- $invoker = new SimpleExceptionTrappingInvoker($invoker);
- }
- return $invoker;
+ function createInvoker() {
+ return new SimpleErrorTrappingInvoker(
+ new SimpleExceptionTrappingInvoker(new SimpleInvoker($this)));
}
/**
@@ -122,28 +123,30 @@ class SimpleTestCase {
* @return boolean True if all tests passed.
* @access public
*/
- function run(&$reporter) {
- $context = &SimpleTest::getContext();
+ function run($reporter) {
+ $context = SimpleTest::getContext();
$context->setTest($this);
$context->setReporter($reporter);
- $this->_reporter = &$reporter;
+ $this->reporter = $reporter;
$started = false;
foreach ($this->getTests() as $method) {
if ($reporter->shouldInvoke($this->getLabel(), $method)) {
$this->skip();
- if ($this->_should_skip) {
+ if ($this->should_skip) {
break;
}
if (! $started) {
$reporter->paintCaseStart($this->getLabel());
$started = true;
}
-//moodlefix begins
+
+ //moodlefix begins
if (defined('TIME_ALLOWED_PER_UNIT_TEST')) {
set_time_limit(TIME_ALLOWED_PER_UNIT_TEST);
}
-//moodlefix ends
- $invoker = &$this->_reporter->createInvoker($this->createInvoker());
+ //moodlefix ends
+
+ $invoker = $this->reporter->createInvoker($this->createInvoker());
$invoker->before($method);
$invoker->invoke($method);
$invoker->after($method);
@@ -152,10 +155,8 @@ class SimpleTestCase {
if ($started) {
$reporter->paintCaseEnd($this->getLabel());
}
- unset($this->_reporter);
-//moodlefix begins
- $context->unsetTest();
-//moodlefix ends
+ unset($this->reporter);
+ $context->setTest(null);
return $reporter->getStatus();
}
@@ -170,7 +171,7 @@ class SimpleTestCase {
function getTests() {
$methods = array();
foreach (get_class_methods(get_class($this)) as $method) {
- if ($this->_isTest($method)) {
+ if ($this->isTest($method)) {
$methods[] = $method;
}
}
@@ -185,7 +186,7 @@ class SimpleTestCase {
* @return boolean True if test method.
* @access protected
*/
- function _isTest($method) {
+ protected function isTest($method) {
if (strtolower(substr($method, 0, 4)) == 'test') {
return ! SimpleTestCompatibility::isA($this, strtolower($method));
}
@@ -198,8 +199,8 @@ class SimpleTestCase {
* @access public
*/
function before($method) {
- $this->_reporter->paintMethodStart($method);
- $this->_observers = array();
+ $this->reporter->paintMethodStart($method);
+ $this->observers = array();
}
/**
@@ -225,10 +226,10 @@ class SimpleTestCase {
* @access public
*/
function after($method) {
- for ($i = 0; $i < count($this->_observers); $i++) {
- $this->_observers[$i]->atTestEnd($method, $this);
+ for ($i = 0; $i < count($this->observers); $i++) {
+ $this->observers[$i]->atTestEnd($method, $this);
}
- $this->_reporter->paintMethodEnd($method);
+ $this->reporter->paintMethodEnd($method);
}
/**
@@ -237,18 +238,18 @@ class SimpleTestCase {
* method.
* @access public
*/
- function tell(&$observer) {
- $this->_observers[] = &$observer;
+ function tell($observer) {
+ $this->observers[] = &$observer;
}
/**
* @deprecated
*/
function pass($message = "Pass") {
- if (! isset($this->_reporter)) {
+ if (! isset($this->reporter)) {
trigger_error('Can only make assertions within test methods');
}
- $this->_reporter->paintPass(
+ $this->reporter->paintPass(
$message . $this->getAssertionLine());
return true;
}
@@ -259,10 +260,10 @@ class SimpleTestCase {
* @access public
*/
function fail($message = "Fail") {
- if (! isset($this->_reporter)) {
+ if (! isset($this->reporter)) {
trigger_error('Can only make assertions within test methods');
}
- $this->_reporter->paintFail(
+ $this->reporter->paintFail(
$message . $this->getAssertionLine());
return false;
}
@@ -277,10 +278,10 @@ class SimpleTestCase {
* @access public
*/
function error($severity, $message, $file, $line) {
- if (! isset($this->_reporter)) {
+ if (! isset($this->reporter)) {
trigger_error('Can only make assertions within test methods');
}
- $this->_reporter->paintError(
+ $this->reporter->paintError(
"Unexpected PHP error [$message] severity [$severity] in [$file line $line]");
}
@@ -291,17 +292,19 @@ class SimpleTestCase {
* @access public
*/
function exception($exception) {
- $this->_reporter->paintException($exception);
+ $this->reporter->paintException($exception);
}
/**
- * @deprecated
+ * For user defined expansion of the available messages.
+ * @param string $type Tag for sorting the signals.
+ * @param mixed $payload Extra user specific information.
*/
- function signal($type, &$payload) {
- if (! isset($this->_reporter)) {
+ function signal($type, $payload) {
+ if (! isset($this->reporter)) {
trigger_error('Can only make assertions within test methods');
}
- $this->_reporter->paintSignal($type, $payload);
+ $this->reporter->paintSignal($type, $payload);
}
/**
@@ -313,25 +316,18 @@ class SimpleTestCase {
* @return boolean True on pass
* @access public
*/
- function assert(&$expectation, $compare, $message = '%s') {
+ function assert($expectation, $compare, $message = '%s') {
if ($expectation->test($compare)) {
return $this->pass(sprintf(
$message,
- $expectation->overlayMessage($compare, $this->_reporter->getDumper())));
+ $expectation->overlayMessage($compare, $this->reporter->getDumper())));
} else {
return $this->fail(sprintf(
$message,
- $expectation->overlayMessage($compare, $this->_reporter->getDumper())));
+ $expectation->overlayMessage($compare, $this->reporter->getDumper())));
}
}
- /**
- * @deprecated
- */
- function assertExpectation(&$expectation, $compare, $message = '%s') {
- return $this->assert($expectation, $compare, $message);
- }
-
/**
* Uses a stack trace to find the line of an assertion.
* @return string Line number of first assert*
@@ -353,27 +349,19 @@ class SimpleTestCase {
* @access public
*/
function dump($variable, $message = false) {
- $dumper = $this->_reporter->getDumper();
+ $dumper = $this->reporter->getDumper();
$formatted = $dumper->dump($variable);
if ($message) {
$formatted = $message . "\n" . $formatted;
}
- $this->_reporter->paintFormattedMessage($formatted);
+ $this->reporter->paintFormattedMessage($formatted);
return $variable;
}
- /**
- * @deprecated
- */
- function sendMessage($message) {
- $this->_reporter->PaintMessage($message);
- }
-
/**
* Accessor for the number of subtests including myelf.
* @return integer Number of test cases.
* @access public
- * @static
*/
function getSize() {
return 1;
@@ -382,6 +370,8 @@ class SimpleTestCase {
/**
* Helps to extract test cases automatically from a file.
+ * @package SimpleTest
+ * @subpackage UnitTester
*/
class SimpleFileLoader {
@@ -393,20 +383,21 @@ class SimpleFileLoader {
* @return TestSuite The new test suite.
* @access public
*/
- function &load($test_file) {
+ function load($test_file) {
$existing_classes = get_declared_classes();
$existing_globals = get_defined_vars();
- global $CFG;
+
+ global $CFG; // moodle hack
+
include_once($test_file);
$new_globals = get_defined_vars();
- $this->_makeFileVariablesGlobal($existing_globals, $new_globals);
+ $this->makeFileVariablesGlobal($existing_globals, $new_globals);
$new_classes = array_diff(get_declared_classes(), $existing_classes);
if (empty($new_classes)) {
- $new_classes = $this->_scrapeClassesFromFile($test_file);
+ $new_classes = $this->scrapeClassesFromFile($test_file);
}
$classes = $this->selectRunnableTests($new_classes);
- $suite = &$this->createSuiteFromClasses($test_file, $classes);
- return $suite;
+ return $this->createSuiteFromClasses($test_file, $classes);
}
/**
@@ -415,10 +406,10 @@ class SimpleFileLoader {
* @param hash $new Variables after the file was loaded.
* @access private
*/
- function _makeFileVariablesGlobal($existing, $new) {
+ protected function makeFileVariablesGlobal($existing, $new) {
$globals = array_diff(array_keys($new), array_keys($existing));
foreach ($globals as $global) {
- $_GLOBALS[$global] = $new[$global];
+ $GLOBALS[$global] = $new[$global];
}
}
@@ -432,7 +423,7 @@ class SimpleFileLoader {
* @param string $test_file File name with classes.
* @access private
*/
- function _scrapeClassesFromFile($test_file) {
+ protected function scrapeClassesFromFile($test_file) {
preg_match_all('~^\s*class\s+(\w+)(\s+(extends|implements)\s+\w+)*\s*\{~mi',
file_get_contents($test_file),
$matches );
@@ -470,7 +461,7 @@ class SimpleFileLoader {
* test cases.
* @access public
*/
- function &createSuiteFromClasses($title, $classes) {
+ function createSuiteFromClasses($title, $classes) {
if (count($classes) == 0) {
$suite = new BadTestSuite($title, "No runnable test cases in [$title]");
return $suite;
@@ -479,7 +470,7 @@ class SimpleFileLoader {
$suite = new TestSuite($title);
foreach ($classes as $class) {
if (! SimpleTest::isIgnored($class)) {
- $suite->addTestClass($class);
+ $suite->add($class);
}
}
return $suite;
@@ -494,8 +485,8 @@ class SimpleFileLoader {
* @subpackage UnitTester
*/
class TestSuite {
- var $_label;
- var $_test_cases;
+ private $label;
+ private $test_cases;
/**
* Sets the name of the test suite.
@@ -504,8 +495,8 @@ class TestSuite {
* @access public
*/
function TestSuite($label = false) {
- $this->_label = $label;
- $this->_test_cases = array();
+ $this->label = $label;
+ $this->test_cases = array();
}
/**
@@ -515,29 +506,11 @@ class TestSuite {
* @access public
*/
function getLabel() {
- if (! $this->_label) {
+ if (! $this->label) {
return ($this->getSize() == 1) ?
- get_class($this->_test_cases[0]) : get_class($this);
+ get_class($this->test_cases[0]) : get_class($this);
} else {
- return $this->_label;
- }
- }
-
- /**
- * @deprecated
- */
- function addTestCase(&$test_case) {
- $this->_test_cases[] = &$test_case;
- }
-
- /**
- * @deprecated
- */
- function addTestClass($class) {
- if (TestSuite::getBaseTestCase($class) == 'testsuite') {
- $this->_test_cases[] = new $class();
- } else {
- $this->_test_cases[] = $class;
+ return $this->label;
}
}
@@ -549,23 +522,16 @@ class TestSuite {
* runnable test interface.
* @access public
*/
- function add(&$test_case) {
+ function add($test_case) {
if (! is_string($test_case)) {
- $this->_test_cases[] = &$test_case;
- } elseif (TestSuite::getBaseTestCase($class) == 'testsuite') {
- $this->_test_cases[] = new $class();
+ $this->test_cases[] = $test_case;
+ } elseif (TestSuite::getBaseTestCase($test_case) == 'testsuite') {
+ $this->test_cases[] = new $test_case();
} else {
- $this->_test_cases[] = $class;
+ $this->test_cases[] = $test_case;
}
}
- /**
- * @deprecated
- */
- function addTestFile($test_file) {
- $this->addFile($test_file);
- }
-
/**
* Builds a test suite from a library of test cases.
* The new suite is composed into this one.
@@ -585,7 +551,7 @@ class TestSuite {
* @param SimpleCollector $collector Directory scanner.
* @access public
*/
- function collect($path, &$collector) {
+ function collect($path, $collector) {
$collector->collect($this, $path);
}
@@ -595,11 +561,12 @@ class TestSuite {
* @param SimpleReporter $reporter Current test reporter.
* @access public
*/
- function run(&$reporter) {
+ function run($reporter) {
$reporter->paintGroupStart($this->getLabel(), $this->getSize());
- for ($i = 0, $count = count($this->_test_cases); $i < $count; $i++) {
- if (is_string($this->_test_cases[$i])) {
- $class = $this->_test_cases[$i];
+ for ($i = 0, $count = count($this->test_cases); $i < $count; $i++) {
+ if (is_string($this->test_cases[$i])) {
+ $class = $this->test_cases[$i];
+
// moodle hack start - need to do this before the constructor call, because of FakeDBUnitTestCase.
global $CFG;
if (is_subclass_of($class, 'FakeDBUnitTestCase')) {
@@ -613,11 +580,12 @@ class TestSuite {
continue;
}
// moodle hack end
+
$test = new $class();
$test->run($reporter);
unset($test);
} else {
- $this->_test_cases[$i]->run($reporter);
+ $this->test_cases[$i]->run($reporter);
}
}
$reporter->paintGroupEnd($this->getLabel());
@@ -631,7 +599,7 @@ class TestSuite {
*/
function getSize() {
$count = 0;
- foreach ($this->_test_cases as $case) {
+ foreach ($this->test_cases as $case) {
if (is_string($case)) {
if (! SimpleTest::isIgnored($case)) {
$count++;
@@ -648,9 +616,8 @@ class TestSuite {
* SimpleTestCase class.
* @param string $class Class name.
* @access public
- * @static
*/
- function getBaseTestCase($class) {
+ static function getBaseTestCase($class) {
while ($class = get_parent_class($class)) {
$class = strtolower($class);
if ($class == 'simpletestcase' || $class == 'testsuite') {
@@ -661,18 +628,6 @@ class TestSuite {
}
}
-/**
- * @package SimpleTest
- * @subpackage UnitTester
- * @deprecated
- */
-class GroupTest extends TestSuite {
- // moodle fix: adding old style constructor to make it compatible with PHP 5.3
- function GroupTest($label = false) {
- parent::TestSuite($label);
- }
-}
-
/**
* This is a failing group test for when a test suite hasn't
* loaded properly.
@@ -680,8 +635,8 @@ class GroupTest extends TestSuite {
* @subpackage UnitTester
*/
class BadTestSuite {
- var $_label;
- var $_error;
+ private $label;
+ private $error;
/**
* Sets the name of the test suite and error message.
@@ -690,8 +645,8 @@ class BadTestSuite {
* @access public
*/
function BadTestSuite($label, $error) {
- $this->_label = $label;
- $this->_error = $error;
+ $this->label = $label;
+ $this->error = $error;
}
/**
@@ -700,7 +655,7 @@ class BadTestSuite {
* @access public
*/
function getLabel() {
- return $this->_label;
+ return $this->label;
}
/**
@@ -708,10 +663,10 @@ class BadTestSuite {
* @param SimpleReporter $reporter Current test reporter.
* @access public
*/
- function run(&$reporter) {
+ function run($reporter) {
$reporter->paintGroupStart($this->getLabel(), $this->getSize());
$reporter->paintFail('Bad TestSuite [' . $this->getLabel() .
- '] with error [' . $this->_error . ']');
+ '] with error [' . $this->error . ']');
$reporter->paintGroupEnd($this->getLabel());
return $reporter->getStatus();
}
@@ -725,11 +680,4 @@ class BadTestSuite {
return 0;
}
}
-
-/**
- * @package SimpleTest
- * @subpackage UnitTester
- * @deprecated
- */
-class BadGroupTest extends BadTestSuite { }
?>
diff --git a/lib/simpletestlib/tidy_parser.php b/lib/simpletestlib/tidy_parser.php
new file mode 100755
index 00000000000..3d8b4b2ac7d
--- /dev/null
+++ b/lib/simpletestlib/tidy_parser.php
@@ -0,0 +1,382 @@
+free();
+ }
+
+ /**
+ * Frees up any references so as to allow the PHP garbage
+ * collection from unset() to work.
+ */
+ private function free() {
+ unset($this->page);
+ $this->forms = array();
+ $this->labels = array();
+ }
+
+ /**
+ * This builder is only available if the 'tidy' extension is loaded.
+ * @return boolean True if available.
+ */
+ function can() {
+ return extension_loaded('tidy');
+ }
+
+ /**
+ * Reads the raw content the page using HTML Tidy.
+ * @param $response SimpleHttpResponse Fetched response.
+ * @return SimplePage Newly parsed page.
+ */
+ function parse($response) {
+ $this->page = new SimplePage($response);
+ $tidied = tidy_parse_string($input = $this->insertGuards($response->getContent()),
+ array('output-xml' => false, 'wrap' => '0', 'indent' => 'no'),
+ 'latin1');
+ $this->walkTree($tidied->html());
+ $this->attachLabels($this->widgets_by_id, $this->labels);
+ $this->page->setForms($this->forms);
+ $page = $this->page;
+ $this->free();
+ return $page;
+ }
+
+ /**
+ * Stops HTMLTidy stripping content that we wish to preserve.
+ * @param string The raw html.
+ * @return string The html with guard tags inserted.
+ */
+ private function insertGuards($html) {
+ return $this->insertEmptyTagGuards($this->insertTextareaSimpleWhitespaceGuards($html));
+ }
+
+ /**
+ * Removes the extra content added during the parse stage
+ * in order to preserve content we don't want stripped
+ * out by HTMLTidy.
+ * @param string The raw html.
+ * @return string The html with guard tags removed.
+ */
+ private function stripGuards($html) {
+ return $this->stripTextareaWhitespaceGuards($this->stripEmptyTagGuards($html));
+ }
+
+ /**
+ * HTML tidy strips out empty tags such as