From 6746f4265b229dcabb6d33875a6f3e4c808cc9e9 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sat, 28 Jul 2007 18:16:35 +0000 Subject: [PATCH] Our test suite is now done with PHPUnit, although it's rather broken --- docs/UnitTest/AllTests.php | 54 ++++++++++++++----- docs/UnitTest/DateTest.php | 13 +++-- docs/UnitTest/FunctionsTest.php | 46 ++++++++-------- docs/UnitTest/InputTest.php | 84 ++++++++++++++++-------------- docs/UnitTest/RegisterTest.php | 54 +++++++++++-------- docs/UnitTest/XmlTest.php | 13 +++-- docs/UnitTest/tests.config.php.new | 31 +++++++++++ 7 files changed, 190 insertions(+), 105 deletions(-) create mode 100644 docs/UnitTest/tests.config.php.new diff --git a/docs/UnitTest/AllTests.php b/docs/UnitTest/AllTests.php index 22e5764..9444f56 100644 --- a/docs/UnitTest/AllTests.php +++ b/docs/UnitTest/AllTests.php @@ -1,21 +1,49 @@ addTestFile('RegisterTest.php'); -$test->addTestFile('FunctionsTest.php'); -$test->addTestFile('DateTest.php'); -$test->addTestFile('InputTest.php'); -$test->addTestFile('XmlTest.php'); -$test->addTestFile('MarkdownTest.php'); +class AllTests +{ + public static function main() + { + PHPUnit_TextUI_TestRunner::run(self::suite()); + } + + public static function suite() + { + $suite = new PHPUnit_Framework_TestSuite('ISSO'); + + require_once 'DateTest.php'; + $suite->addTestSuite('DateTest'); + + require_once 'FunctionsTest.php'; + $suite->addTestSuite('FunctionsTest'); + + require_once 'InputTest.php'; + $suite->addTestSuite('InputTest'); + + require_once 'RegisterTest.php'; + $suite->addTestSuite('RegisterTest'); + + require_once 'XmlTest.php'; + $suite->addTestSuite('XmlTest'); + + return $suite; + } +} -// run -$test->run(new CustomHtmlReporter()); +if (PHPUnit_MAIN_METHOD == 'AllTests') +{ + AllTests::main(); +} ?> \ No newline at end of file diff --git a/docs/UnitTest/DateTest.php b/docs/UnitTest/DateTest.php index 4694c99..05aa9eb 100644 --- a/docs/UnitTest/DateTest.php +++ b/docs/UnitTest/DateTest.php @@ -1,5 +1,7 @@ fixture = BSRegister::LoadModule('Date'); } @@ -24,24 +27,24 @@ class DateTest extends UnitTestCase { $this->fixture->setUserTimeZone(0); - $this->assertEqual(gmdate(self::DATE_FORMAT, TIMENOW), $this->fixture->format(self::DATE_FORMAT, TIMENOW)); + $this->assertEquals(gmdate(self::DATE_FORMAT, TIMENOW), $this->fixture->format(self::DATE_FORMAT, TIMENOW)); } public function testGmtMinus8() { $this->fixture->setUserTimeZone(-8); - $this->assertEqual('2007-04-01 00:00:00', $this->fixture->format(self::DATE_FORMAT, 1175414400)); + $this->assertEquals('2007-04-01 00:00:00', $this->fixture->format(self::DATE_FORMAT, 1175414400)); } public function testGmtNoAdjust() { $this->fixture->setUserTimeZone(4); - $this->assertEqual(gmdate(self::DATE_FORMAT, TIMENOW), $this->fixture->format(self::DATE_FORMAT, TIMENOW, false)); + $this->assertEquals(gmdate(self::DATE_FORMAT, TIMENOW), $this->fixture->format(self::DATE_FORMAT, TIMENOW, false)); } public function testTimezoneList() { - $this->assertEqual(sizeof(BSDate::FetchTimeZoneList()), 30); + $this->assertEquals(sizeof(BSDate::FetchTimeZoneList()), 30); } } diff --git a/docs/UnitTest/FunctionsTest.php b/docs/UnitTest/FunctionsTest.php index 9d29d9d..b7c6425 100644 --- a/docs/UnitTest/FunctionsTest.php +++ b/docs/UnitTest/FunctionsTest.php @@ -1,7 +1,6 @@ assertEqual('', BSFunctions::$cssClass); + $this->assertEquals('', BSFunctions::$cssClass); BSFunctions::SwapCssClasses('1', '2'); - $this->assertEqual('2', BSFunctions::$cssClass); + $this->assertEquals('2', BSFunctions::$cssClass); BSFunctions::SwapCssClasses('1', '2'); - $this->assertEqual('1', BSFunctions::$cssClass); + $this->assertEquals('1', BSFunctions::$cssClass); BSFunctions::SwapCssClasses('1', '2'); - $this->assertEqual('2', BSFunctions::$cssClass); + $this->assertEquals('2', BSFunctions::$cssClass); } public function testFetchSourcePath() { - $this->assertEqual('a' . DIRECTORY_SEPARATOR, BSFunctions::FetchSourcePath('a')); + $this->assertEquals('a' . DIRECTORY_SEPARATOR, BSFunctions::FetchSourcePath('a')); } public function testDownloadFile() @@ -61,7 +65,7 @@ class FunctionsTest extends UnitTestCase for ($i = 0; $i < 100; $i++) { $random = BSFunctions::Random(5); - $this->assertEqual(5, strlen($random)); + $this->assertEquals(5, strlen($random)); $this->assertFalse(in_array($random, $values)); $values[] = $random; } @@ -71,15 +75,15 @@ class FunctionsTest extends UnitTestCase { $array = array('a', 'b', 'c', 'd'); - $this->assertEqual('a', current($array)); - $this->assertEqual('b', next($array)); - $this->assertEqual('c', next($array)); + $this->assertEquals('a', current($array)); + $this->assertEquals('b', next($array)); + $this->assertEquals('c', next($array)); BSFunctions::ArraySetCurrent($array, 0); - $this->assertEqual('a', current($array)); + $this->assertEquals('a', current($array)); BSFunctions::ArraySetCurrent($array, 3); - $this->assertEqual('d', current($array)); + $this->assertEquals('d', current($array)); } public function testFetchMicrotimeDiff() @@ -89,9 +93,9 @@ class FunctionsTest extends UnitTestCase public function testFetchExtension() { - $this->assertEqual('txt', BSFunctions::FetchExtension('test.txt')); - $this->assertEqual('', BSFunctions::FetchExtension('test')); - $this->assertEqual('xml', BSFunctions::FetchExtension('test.file.xml')); + $this->assertEquals('txt', BSFunctions::FetchExtension('test.txt')); + $this->assertEquals('', BSFunctions::FetchExtension('test')); + $this->assertEquals('xml', BSFunctions::FetchExtension('test.file.xml')); } public function testFetchMaxPhpFileSize() @@ -113,15 +117,15 @@ class FunctionsTest extends UnitTestCase public function testArrayStripEmpty() { $array = array(1, 4, 6); - $this->assertEqual(3, sizeof(BSFunctions::ArrayStripEmpty($array))); + $this->assertEquals(3, sizeof(BSFunctions::ArrayStripEmpty($array))); $array = array(1, 0, 5, ''); - $this->assertEqual(2, sizeof(BSFunctions::ArrayStripEmpty($array))); + $this->assertEquals(2, sizeof(BSFunctions::ArrayStripEmpty($array))); $array = array('', 'test' => array('', 6)); $array = BSFunctions::ArrayStripEmpty($array); - $this->assertEqual(1, sizeof($array)); - $this->assertEqual(1, sizeof($array['test'])); + $this->assertEquals(1, sizeof($array)); + $this->assertEquals(1, sizeof($array['test'])); } } diff --git a/docs/UnitTest/InputTest.php b/docs/UnitTest/InputTest.php index 1951171..a35d38e 100644 --- a/docs/UnitTest/InputTest.php +++ b/docs/UnitTest/InputTest.php @@ -1,5 +1,7 @@ fixture = BSRegister::LoadModule('Input'); } public function testSanitizeInputData() { - $this->assertEqual(10, sizeof($this->fixture->in)); - $this->assertEqual(2, sizeof($this->fixture->in['nest'])); - $this->assertEqual('"a var"', $this->fixture->in['somecookie']); - $this->assertEqual('test\'ing', $this->fixture->in['nest']['"hi"']); + $this->assertEquals(10, sizeof($this->fixture->in)); + $this->assertEquals(2, sizeof($this->fixture->in['nest'])); + $this->assertEquals('"a var"', $this->fixture->in['somecookie']); + $this->assertEquals('test\'ing', $this->fixture->in['nest']['"hi"']); } public function testEntityEncode() { - $this->assertEqual('<a href="http://www.something.com/test.php?do=run&moo=foo">', $this->fixture->entityEncode('')); + $this->assertEquals('<a href="http://www.something.com/test.php?do=run&moo=foo">', $this->fixture->entityEncode('')); } public function testUnsanitize() { - $this->assertEqual('', $this->fixture->unsanitize('')); - $this->assertEqual('', $this->fixture->unsanitize('<script type="text/javascript"> alert("XSS is fun!"); </script>')); - $this->assertEqual('', $this->fixture->unsanitize($this->fixture->sanitize(''))); + $this->assertEquals('', $this->fixture->unsanitize('')); + $this->assertEquals('', $this->fixture->unsanitize('<script type="text/javascript"> alert("XSS is fun!"); </script>')); + $this->assertEquals('', $this->fixture->unsanitize($this->fixture->sanitize(''))); } public function testClean() { - $this->assertEqual(0, $this->fixture->clean('abc', TYPE_INT)); - $this->assertEqual(-1, $this->fixture->clean('-1', TYPE_INT)); - $this->assertEqual(4, $this->fixture->clean('4def', TYPE_INT)); + $this->assertEquals(0, $this->fixture->clean('abc', TYPE_INT)); + $this->assertEquals(-1, $this->fixture->clean('-1', TYPE_INT)); + $this->assertEquals(4, $this->fixture->clean('4def', TYPE_INT)); - $this->assertEqual(0, $this->fixture->clean('abc', TYPE_UINT)); - $this->assertEqual(0, $this->fixture->clean(-100, TYPE_UINT)); - $this->assertEqual(40, $this->fixture->clean('40.965', TYPE_UINT)); + $this->assertEquals(0, $this->fixture->clean('abc', TYPE_UINT)); + $this->assertEquals(0, $this->fixture->clean(-100, TYPE_UINT)); + $this->assertEquals(40, $this->fixture->clean('40.965', TYPE_UINT)); - $this->assertEqual(0, $this->fixture->clean('0.0', TYPE_FLOAT)); - $this->assertNotEqual(0, $this->fixture->clean('0.032', TYPE_FLOAT)); + $this->assertEquals(0, $this->fixture->clean('0.0', TYPE_FLOAT)); + $this->assertNotEquals(0, $this->fixture->clean('0.032', TYPE_FLOAT)); - $this->assertEqual(true, $this->fixture->clean('aafsdfa', TYPE_BOOL)); - $this->assertEqual(false, $this->fixture->clean('', TYPE_BOOL)); - $this->assertEqual(false, $this->fixture->clean('0', TYPE_BOOL)); - $this->assertEqual(true, $this->fixture->clean('0.0', TYPE_BOOL)); + $this->assertEquals(true, $this->fixture->clean('aafsdfa', TYPE_BOOL)); + $this->assertEquals(false, $this->fixture->clean('', TYPE_BOOL)); + $this->assertEquals(false, $this->fixture->clean('0', TYPE_BOOL)); + $this->assertEquals(true, $this->fixture->clean('0.0', TYPE_BOOL)); - $this->assertEqual('', $this->fixture->clean('', TYPE_STR)); + $this->assertEquals('', $this->fixture->clean('', TYPE_STR)); - $this->assertEqual('', $this->fixture->clean('', TYPE_STRUN)); - $this->assertEqual('', $this->fixture->clean($this->fixture->sanitize(''), TYPE_STRUN)); + $this->assertEquals('', $this->fixture->clean('', TYPE_STRUN)); + $this->assertEquals('', $this->fixture->clean($this->fixture->sanitize(''), TYPE_STRUN)); - $this->assertEqual('', $this->fixture->clean('', TYPE_NONE)); + $this->assertEquals('', $this->fixture->clean('', TYPE_NONE)); - $this->assertEqual('åß∂ƒ©˙∆˚¬…æΩ≈ç√∫≤≥÷œ∑®†¥øπ“‘’”', $this->fixture->clean('åß∂ƒ©˙∆˚¬…æΩ≈ç√∫≤≥÷œ∑®†¥øπ“‘’”', TYPE_BIN)); + $this->assertEquals('åß∂ƒ©˙∆˚¬…æΩ≈ç√∫≤≥÷œ∑®†¥øπ“‘’”', $this->fixture->clean('åß∂ƒ©˙∆˚¬…æΩ≈ç√∫≤≥÷œ∑®†¥øπ“‘’”', TYPE_BIN)); $this->fixture->clean('asdfa', TYPE_THIS_DOES_NOT_EXIST); - $this->assertError(); + // TODO - use exceptions + // $this->assertError(); } public function testCleanArray() @@ -109,19 +113,19 @@ class InputTest extends UnitTestCase $newarray = $this->fixture->clean($array, TYPE_UINT); - $this->assertEqual(4, sizeof($newarray)); - $this->assertEqual(1, $newarray['a']); - $this->assertEqual(2, $newarray['b']); - $this->assertEqual(0, $newarray['c']); - $this->assertEqual(0, $newarray['d']); + $this->assertEquals(4, sizeof($newarray)); + $this->assertEquals(1, $newarray['a']); + $this->assertEquals(2, $newarray['b']); + $this->assertEquals(0, $newarray['c']); + $this->assertEquals(0, $newarray['d']); } public function testInputClean() { - $this->assertEqual(-1.0, $this->fixture->inputClean('abc', TYPE_FLOAT)); - $this->assertEqual(-1.0, $this->fixture->in['abc']); + $this->assertEquals(-1.0, $this->fixture->inputClean('abc', TYPE_FLOAT)); + $this->assertEquals(-1.0, $this->fixture->in['abc']); - $this->assertEqual('', $this->fixture->inputClean(':does:not:exist', TYPE_STR)); + $this->assertEquals('', $this->fixture->inputClean(':does:not:exist', TYPE_STR)); } public function testInputCleanArray() @@ -132,19 +136,19 @@ class InputTest extends UnitTestCase 'ab"c"' => TYPE_INT )); - $this->assertEqual(-1.0, $this->fixture->in['abc']); - $this->assertEqual(2, $this->fixture->in['ab"c"']); + $this->assertEquals(-1.0, $this->fixture->in['abc']); + $this->assertEquals(2, $this->fixture->in['ab"c"']); } public function testEscape() { - $this->assertEqual("this isn\'t a test", $this->fixture->escape("this isn't a test", true)); + $this->assertEquals("this isn\'t a test", $this->fixture->escape("this isn't a test", true)); } public function testInputEscape() { - $this->assertEqual("isn\'t it cool", $this->fixture->inputEscape('another"value"')); - $this->assertEqual('', $this->fixture->inputEscape(':will:never:exist')); + $this->assertEquals("isn\'t it cool", $this->fixture->inputEscape('another"value"')); + $this->assertEquals('', $this->fixture->inputEscape(':will:never:exist')); } public function testPostCheck() diff --git a/docs/UnitTest/RegisterTest.php b/docs/UnitTest/RegisterTest.php index b6f5938..594ee30 100644 --- a/docs/UnitTest/RegisterTest.php +++ b/docs/UnitTest/RegisterTest.php @@ -1,7 +1,7 @@ assertTrue(BSRegister::LoadModule('Input') instanceof BSInput); @@ -22,46 +27,47 @@ class RegisterTest extends UnitTestCase public function testLoadBadModule() { BSRegister::LoadModule('nonExistentModule'); - $this->assertError(); + // TODO - use exceptions + // $this->assertError(); } public function testSetGetAppPath() { BSRegister::SetAppPath(getcwd()); - $this->assertEqual(getcwd() . DIRECTORY_SEPARATOR, BSRegister::GetAppPath()); + $this->assertEquals(getcwd() . DIRECTORY_SEPARATOR, BSRegister::GetAppPath()); } public function testSetGetAppVersion() { BSRegister::SetAppVersion('1.0-test'); - $this->assertEqual('1.0-test', BSRegister::GetAppVersion()); + $this->assertEquals('1.0-test', BSRegister::GetAppVersion()); } public function testSetGetApplication() { BSRegister::SetApplication('ISSO Tests'); - $this->assertEqual('ISSO Tests', BSRegister::GetApplication()); + $this->assertEquals('ISSO Tests', BSRegister::GetApplication()); } public function testSetGetWebPath() { $path = DIRECTORY_SEPARATOR . 'Server' . DIRECTORY_SEPARATOR . 'htdocs' . DIRECTORY_SEPARATOR . 'ISSO'; BSRegister::SetWebPath($path); - $this->assertEqual($path . DIRECTORY_SEPARATOR, BSRegister::GetWebPath()); + $this->assertEquals($path . DIRECTORY_SEPARATOR, BSRegister::GetWebPath()); } public function testSetGetDebug() { BSRegister::SetDebug(true); - $this->assertIdentical(true, BSRegister::GetDebug()); + $this->assertSame(true, BSRegister::GetDebug()); } public function testDebugList() { - $this->assertEqual('', BSRegister::GetDebugList()); + $this->assertEquals('', BSRegister::GetDebugList()); BSRegister::Debug('dbg'); - $this->assertEqual('', BSRegister::GetDebugList()); + $this->assertEquals('', BSRegister::GetDebugList()); } public function testRegisterValue() @@ -69,28 +75,29 @@ class RegisterTest extends UnitTestCase BSRegister::Register('someKey', 'someValue'); $registry = BSRegister::GetAll(); - $this->assertEqual($registry['someKey'], 'someValue'); + $this->assertEquals($registry['someKey'], 'someValue'); } public function testGetAll() { BSRegister::Register('test', 1); - $this->assertIsA(BSRegister::GetAll(), 'array'); - $this->assertEqual(sizeof(BSRegister::GetAll()), 2); + $this->assertType('array', BSRegister::GetAll()); + $this->assertEquals(sizeof(BSRegister::GetAll()), 2); } public function testOverWriteRegister() { BSRegister::Register('valueToOverWrite', 1); BSRegister::Register('valueToOverWrite', 2); - $this->assertError(); - $this->assertEqual(1, BSRegister::Get('valueToOverWrite')); + // TODO - use exceptions + // $this->assertError(); + $this->assertEquals(1, BSRegister::Get('valueToOverWrite')); } public function testGet() { BSRegister::Register('testGet', 123); - $this->assertEqual(123, BSRegister::Get('testGet')); + $this->assertEquals(123, BSRegister::Get('testGet')); } public function testUnregister() @@ -98,10 +105,12 @@ class RegisterTest extends UnitTestCase BSRegister::Register('testUnregister', 1); BSRegister::Unregister('testUnregister'); BSRegister::Register('testUnregister', 2); - $this->assertNoErrors(); - $this->assertEqual(2, BSRegister::Get('testUnregister')); + // TODO - use exceptions + // $this->assertNoErrors(); + $this->assertEquals(2, BSRegister::Get('testUnregister')); } + /* TODO - use exceptions public function testGetNoExist() { BSRegister::Get('doesNotExist'); @@ -113,16 +122,18 @@ class RegisterTest extends UnitTestCase BSRegister::Unregister('keyThatWontExist'); $this->assertError(); } + */ public function testGetType() { $input = BSRegister::LoadModule('Input'); BSRegister::Register('input', $input); - $this->assertReference($input, BSRegister::GetType('Input')); + $this->assertSame($input, BSRegister::GetType('Input')); - $this->assertEqual(null, BSRegister::GetType('Date')); + $this->assertEquals(null, BSRegister::GetType('Date')); } + /* TODO - use exceptions public function testRequiredModules() { BSRegister::RequiredModules(array('Input')); @@ -134,6 +145,7 @@ class RegisterTest extends UnitTestCase BSRegister::RequiredModules(array('Date')); $this->assertError(); } + */ } ?> \ No newline at end of file diff --git a/docs/UnitTest/XmlTest.php b/docs/UnitTest/XmlTest.php index ab348c4..2a642a5 100644 --- a/docs/UnitTest/XmlTest.php +++ b/docs/UnitTest/XmlTest.php @@ -1,5 +1,7 @@ array('value' => 'elm2 Value') ) ); - $this->assertEqual($results, BSXml::Parse($xml)); + $this->assertEquals($results, BSXml::Parse($xml)); } public function testInvalidXml() @@ -44,7 +46,8 @@ class XmlTest extends UnitTestCase BSXml::Parse($xml); - $this->assertError(); + // TODO - use exceptions + // $this->assertError(); } public function testUnifyNode() @@ -58,14 +61,14 @@ class XmlTest extends UnitTestCase $array = BSXml::Parse($xml); BSXml::UnifyNode($array['root']['elm2']); - $this->assertEqual($array['root']['elm2'][0]['value'], 'elm2 Value'); + $this->assertEquals($array['root']['elm2'][0]['value'], 'elm2 Value'); } public function testUtf8Xml() { $xml = 'test: π'; $array = BSXml::Parse($xml, true); - $this->assertEqual($array['root']['utf8']['value'], 'test: π'); + $this->assertEquals($array['root']['utf8']['value'], 'test: π'); } } diff --git a/docs/UnitTest/tests.config.php.new b/docs/UnitTest/tests.config.php.new new file mode 100644 index 0000000..9bdf099 --- /dev/null +++ b/docs/UnitTest/tests.config.php.new @@ -0,0 +1,31 @@ + \ No newline at end of file -- 2.43.5