More SQL command (drop table, drop database)

delete, select & insert upgraded 
More utility function (node to array, arrayToNode)
XMLDB special move command
PHP Unit Test
This commit is contained in:
Chouchen
2010-10-11 14:03:38 +00:00
parent 0b54511565
commit 69b9eb42e2
126 changed files with 42747 additions and 178 deletions

View File

@@ -0,0 +1,198 @@
<?php
/**
* adapter for SimpleTest to use PEAR PHPUnit test cases
* @package SimpleTest
* @subpackage Extensions
* @version $Id: pear_test_case.php 1388 2006-11-10 20:59:59Z lastcraft $
*/
/**#@+
* include SimpleTest files
*/
require_once(dirname(__FILE__) . '/../dumper.php');
require_once(dirname(__FILE__) . '/../compatibility.php');
require_once(dirname(__FILE__) . '/../test_case.php');
require_once(dirname(__FILE__) . '/../expectation.php');
/**#@-*/
/**
* Adapter for PEAR PHPUnit test case to allow
* legacy PEAR test cases to be used with SimpleTest.
* @package SimpleTest
* @subpackage Extensions
*/
class PHPUnit_TestCase extends SimpleTestCase {
var $_loosely_typed;
/**
* Constructor. Sets the test name.
* @param $label Test name to display.
* @public
*/
function PHPUnit_TestCase($label = false) {
$this->SimpleTestCase($label);
$this->_loosely_typed = false;
}
/**
* Will test straight equality if set to loose
* typing, or identity if not.
* @param $first First value.
* @param $second Comparison value.
* @param $message Message to display.
* @public
*/
function assertEquals($first, $second, $message = "%s", $delta = 0) {
if ($this->_loosely_typed) {
$expectation = &new EqualExpectation($first);
} else {
$expectation = &new IdenticalExpectation($first);
}
$this->assert($expectation, $second, $message);
}
/**
* Passes if the value tested is not null.
* @param $value Value to test against.
* @param $message Message to display.
* @public
*/
function assertNotNull($value, $message = "%s") {
parent::assert(new TrueExpectation(), isset($value), $message);
}
/**
* Passes if the value tested is null.
* @param $value Value to test against.
* @param $message Message to display.
* @public
*/
function assertNull($value, $message = "%s") {
parent::assert(new TrueExpectation(), !isset($value), $message);
}
/**
* In PHP5 the identity test tests for the same
* object. This is a reference test in PHP4.
* @param $first First object handle.
* @param $second Hopefully the same handle.
* @param $message Message to display.
* @public
*/
function assertSame(&$first, &$second, $message = "%s") {
$dumper = &new SimpleDumper();
$message = sprintf(
$message,
"[" . $dumper->describeValue($first) .
"] and [" . $dumper->describeValue($second) .
"] should reference the same object");
return $this->assert(
new TrueExpectation(),
SimpleTestCompatibility::isReference($first, $second),
$message);
}
/**
* In PHP5 the identity test tests for the same
* object. This is a reference test in PHP4.
* @param $first First object handle.
* @param $second Hopefully a different handle.
* @param $message Message to display.
* @public
*/
function assertNotSame(&$first, &$second, $message = "%s") {
$dumper = &new SimpleDumper();
$message = sprintf(
$message,
"[" . $dumper->describeValue($first) .
"] and [" . $dumper->describeValue($second) .
"] should not be the same object");
return $this->assert(
new falseExpectation(),
SimpleTestCompatibility::isReference($first, $second),
$message);
}
/**
* Sends pass if the test condition resolves true,
* a fail otherwise.
* @param $condition Condition to test true.
* @param $message Message to display.
* @public
*/
function assertTrue($condition, $message = "%s") {
parent::assert(new TrueExpectation(), $condition, $message);
}
/**
* Sends pass if the test condition resolves false,
* a fail otherwise.
* @param $condition Condition to test false.
* @param $message Message to display.
* @public
*/
function assertFalse($condition, $message = "%s") {
parent::assert(new FalseExpectation(), $condition, $message);
}
/**
* Tests a regex match. Needs refactoring.
* @param $pattern Regex to match.
* @param $subject String to search in.
* @param $message Message to display.
* @public
*/
function assertRegExp($pattern, $subject, $message = "%s") {
$this->assert(new PatternExpectation($pattern), $subject, $message);
}
/**
* Tests the type of a value.
* @param $value Value to take type of.
* @param $type Hoped for type.
* @param $message Message to display.
* @public
*/
function assertType($value, $type, $message = "%s") {
parent::assert(new TrueExpectation(), gettype($value) == strtolower($type), $message);
}
/**
* Sets equality operation to act as a simple equal
* comparison only, allowing a broader range of
* matches.
* @param $loosely_typed True for broader comparison.
* @public
*/
function setLooselyTyped($loosely_typed) {
$this->_loosely_typed = $loosely_typed;
}
/**
* For progress indication during
* a test amongst other things.
* @return Usually one.
* @public
*/
function countTestCases() {
return $this->getSize();
}
/**
* Accessor for name, normally just the class
* name.
* @public
*/
function getName() {
return $this->getLabel();
}
/**
* Does nothing. For compatibility only.
* @param $name Dummy
* @public
*/
function setName($name) {
}
}
?>

View File

@@ -0,0 +1,96 @@
<?php
/**
* adapter for SimpleTest to use PHPUnit test cases
* @package SimpleTest
* @subpackage Extensions
* @version $Id: phpunit_test_case.php 1530 2007-06-04 23:35:45Z lastcraft $
*/
/**#@+
* include SimpleTest files
*/
require_once(dirname(__FILE__) . '/../unit_tester.php');
require_once(dirname(__FILE__) . '/../expectation.php');
/**#@-*/
/**
* Adapter for sourceforge PHPUnit test case to allow
* legacy test cases to be used with SimpleTest.
* @package SimpleTest
* @subpackage Extensions
*/
class TestCase extends SimpleTestCase {
/**
* Constructor. Sets the test name.
* @param $label Test name to display.
* @public
*/
function TestCase($label = false) {
$this->SimpleTestCase($label);
}
/**
* Sends pass if the test condition resolves true,
* a fail otherwise.
* @param $condition Condition to test true.
* @param $message Message to display.
* @public
*/
function assert($condition, $message = false) {
parent::assert(new TrueExpectation(), $condition, $message);
}
/**
* Will test straight equality if set to loose
* typing, or identity if not.
* @param $first First value.
* @param $second Comparison value.
* @param $message Message to display.
* @public
*/
function assertEquals($first, $second, $message = false) {
parent::assert(new EqualExpectation($first), $second, $message);
}
/**
* Simple string equality.
* @param $first First value.
* @param $second Comparison value.
* @param $message Message to display.
* @public
*/
function assertEqualsMultilineStrings($first, $second, $message = false) {
parent::assert(new EqualExpectation($first), $second, $message);
}
/**
* Tests a regex match.
* @param $pattern Regex to match.
* @param $subject String to search in.
* @param $message Message to display.
* @public
*/
function assertRegexp($pattern, $subject, $message = false) {
parent::assert(new PatternExpectation($pattern), $subject, $message);
}
/**
* Sends an error which we interpret as a fail
* with a different message for compatibility.
* @param $message Message to display.
* @public
*/
function error($message) {
parent::fail("Error triggered [$message]");
}
/**
* Accessor for name.
* @public
*/
function name() {
return $this->getLabel();
}
}
?>

View File

@@ -0,0 +1,42 @@
<?php
class TestDoxReporter extends SimpleReporter
{
var $_test_case_pattern = '/^TestOf(.*)$/';
function TestDoxReporter($test_case_pattern = '/^TestOf(.*)$/') {
parent::SimpleScorer();
$this->_test_case_pattern = empty($test_case_pattern) ? '/^(.*)$/' : $test_case_pattern;
}
function paintCaseStart($test_name) {
preg_match($this->_test_case_pattern, $test_name, $matches);
if (!empty($matches[1])) {
echo $matches[1] . "\n";
} else {
echo $test_name . "\n";
}
}
function paintCaseEnd() {
echo "\n";
}
function paintMethodStart($test_name) {
if (!preg_match('/^test(.*)$/i', $test_name, $matches)) {
return;
}
$test_name = $matches[1];
$test_name = preg_replace('/([A-Z])([A-Z])/', '$1 $2', $test_name);
echo '- ' . strtolower(preg_replace('/([a-zA-Z])([A-Z0-9])/', '$1 $2', $test_name));
}
function paintMethodEnd() {
echo "\n";
}
function paintFail() {
echo " [FAILED]";
}
}

View File

@@ -0,0 +1,108 @@
<?php
// $Id: test.php 1641 2008-01-22 20:13:52Z pp11 $
require_once dirname(__FILE__) . '/../../autorun.php';
require_once dirname(__FILE__) . '/../testdox.php';
// uncomment to see test dox in action
//SimpleTest::prefer(new TestDoxReporter());
class TestOfTestDoxReporter extends UnitTestCase
{
function testIsAnInstanceOfSimpleScorerAndReporter() {
$dox = new TestDoxReporter();
$this->assertIsA($dox, 'SimpleScorer');
$this->assertIsA($dox, 'SimpleReporter');
}
function testOutputsNameOfTestCase() {
$dox = new TestDoxReporter();
ob_start();
$dox->paintCaseStart('TestOfTestDoxReporter');
$buffer = ob_get_clean();
$this->assertWantedPattern('/^TestDoxReporter/', $buffer);
}
function testOutputOfTestCaseNameFilteredByConstructParameter() {
$dox = new TestDoxReporter('/^(.*)Test$/');
ob_start();
$dox->paintCaseStart('SomeGreatWidgetTest');
$buffer = ob_get_clean();
$this->assertWantedPattern('/^SomeGreatWidget/', $buffer);
}
function testIfTest_case_patternIsEmptyAssumeEverythingMatches() {
$dox = new TestDoxReporter('');
ob_start();
$dox->paintCaseStart('TestOfTestDoxReporter');
$buffer = ob_get_clean();
$this->assertWantedPattern('/^TestOfTestDoxReporter/', $buffer);
}
function testEmptyLineInsertedWhenCaseEnds() {
$dox = new TestDoxReporter();
ob_start();
$dox->paintCaseEnd('TestOfTestDoxReporter');
$buffer = ob_get_clean();
$this->assertEqual("\n", $buffer);
}
function testPaintsTestMethodInTestDoxFormat() {
$dox = new TestDoxReporter();
ob_start();
$dox->paintMethodStart('testSomeGreatTestCase');
$buffer = ob_get_clean();
$this->assertEqual("- some great test case", $buffer);
unset($buffer);
$random = rand(100, 200);
ob_start();
$dox->paintMethodStart("testRandomNumberIs{$random}");
$buffer = ob_get_clean();
$this->assertEqual("- random number is {$random}", $buffer);
}
function testDoesNotOutputAnythingOnNoneTestMethods() {
$dox = new TestDoxReporter();
ob_start();
$dox->paintMethodStart('nonMatchingMethod');
$buffer = ob_get_clean();
$this->assertEqual('', $buffer);
}
function testPaintMethodAddLineBreak() {
$dox = new TestDoxReporter();
ob_start();
$dox->paintMethodEnd('someMethod');
$buffer = ob_get_clean();
$this->assertEqual("\n", $buffer);
$this->assertNoErrors();
}
function testProperlySpacesSingleLettersInMethodName() {
$dox = new TestDoxReporter();
ob_start();
$dox->paintMethodStart('testAVerySimpleAgainAVerySimpleMethod');
$buffer = ob_get_clean();
$this->assertEqual('- a very simple again a very simple method', $buffer);
}
function testOnFailureThisPrintsFailureNotice() {
$dox = new TestDoxReporter();
ob_start();
$dox->paintFail();
$buffer = ob_get_clean();
$this->assertEqual(' [FAILED]', $buffer);
}
function testWhenMatchingMethodNamesTestPrefixIsCaseInsensitive() {
$dox = new TestDoxReporter();
ob_start();
$dox->paintMethodStart('TESTSupportsAllUppercaseTestPrefixEvenThoughIDoNotKnowWhyYouWouldDoThat');
$buffer = ob_get_clean();
$this->assertEqual(
'- supports all uppercase test prefix even though i do not know why you would do that',
$buffer
);
}
}