From 086e9255f6f8b104d29b4b433aa5d8304da44d5b Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sun, 13 Jan 2008 14:11:46 -0800 Subject: [PATCH] Adding fixes in the unit tests for all the refactoring we did --- Date.php | 2 +- UnitTest/ApiTest.php | 3 +- UnitTest/AppTest.php | 145 ++------------------------------ UnitTest/DatabaseMySQLTest.php | 5 +- UnitTest/DatabaseMySQLiTest.php | 6 +- UnitTest/DateTest.php | 5 +- UnitTest/FunctionsTest.php | 42 ++++----- UnitTest/InputTest.php | 3 +- UnitTest/InstallerTest.php | 3 +- UnitTest/TemplateTest.php | 8 +- 10 files changed, 48 insertions(+), 174 deletions(-) diff --git a/Date.php b/Date.php index 7145399..5761b03 100644 --- a/Date.php +++ b/Date.php @@ -87,7 +87,7 @@ class BSDate * * @return array List of timezones */ - public static function fetch_time_zone_list() + public static function fetch_timezone_list() { $opt = array(); diff --git a/UnitTest/ApiTest.php b/UnitTest/ApiTest.php index cdb2517..2caa68b 100644 --- a/UnitTest/ApiTest.php +++ b/UnitTest/ApiTest.php @@ -2,6 +2,7 @@ require_once 'PHPUnit/Framework.php'; require_once ISSO . '/Api.php'; +require_once ISSO . '/DbMySql.php'; /** * ApiTest @@ -18,7 +19,7 @@ class ApiTest extends PHPUnit_Framework_TestCase public function setUp() { - $this->db = BSApp::LoadModule('DbMySql'); + BSApp::$db = $this->db = new BSDbMySql(); $this->db->connect(TEST_DB_MYSQL_HOST, TEST_DB_MYSQL_USER, TEST_DB_MYSQL_PASSWORD, TEST_DB_MYSQL_DATABASE); $this->fixture = new TestApiFixture(); diff --git a/UnitTest/AppTest.php b/UnitTest/AppTest.php index 6130ccf..6b79269 100644 --- a/UnitTest/AppTest.php +++ b/UnitTest/AppTest.php @@ -18,153 +18,18 @@ class AppTest extends PHPUnit_Framework_TestCase require_once ISSO . '/App.php'; } - public function testLoadModule() - { - $this->assertTrue(BSApp::LoadModule('Input') instanceof BSInput); - } - - public function testLoadBadModule() - { - try - { - BSApp::LoadModule('nonExistentModule'); - $this->fail('exception expected'); - } - catch (Exception $e) - {} - } - - public function testSetGetAppPath() - { - BSApp::SetAppPath(getcwd()); - $this->assertEquals(getcwd() . DIRECTORY_SEPARATOR, BSApp::GetAppPath()); - } - - public function testSetGetAppVersion() - { - BSApp::SetAppVersion('1.0-test'); - $this->assertEquals('1.0-test', BSApp::GetAppVersion()); - } - - public function testSetGetApplication() - { - BSApp::SetApplication('ISSO Tests'); - $this->assertEquals('ISSO Tests', BSApp::GetApplication()); - } - - public function testSetGetWebPath() - { - $path = DIRECTORY_SEPARATOR . 'Server' . DIRECTORY_SEPARATOR . 'htdocs' . DIRECTORY_SEPARATOR . 'ISSO'; - BSApp::SetWebPath($path); - $this->assertEquals($path . DIRECTORY_SEPARATOR, BSApp::GetWebPath()); - } - public function testSetGetDebug() { - BSApp::SetDebug(true); - $this->assertSame(true, BSApp::GetDebug()); + BSApp::set_debug(true); + $this->assertSame(true, BSApp::get_debug()); } public function testDebugList() { - $this->assertEquals('', BSApp::GetDebugList()); - - BSApp::Debug('dbg'); - $this->assertEquals('', BSApp::GetDebugList()); - } - - public function testRegisterValue() - { - BSApp::Registry()->someKey = 'someValue'; - - $registry = BSApp::Registry(); - $this->assertEquals($registry->someKey, 'someValue'); - } - - public function testGetAll() - { - BSApp::Registry()->test = 1; - $this->assertType('array', BSApp::Registry()->allObjects()); - $this->assertSame(sizeof(BSApp::Registry()->allObjects()), 3); - } - - public function testOverWriteRegister() - { - BSApp::Registry()->valueToOverWrite = 1; - BSApp::Registry()->valueToOverWrite = 2; - $this->assertEquals(2, BSApp::Registry()->valueToOverWrite); - } - - public function testGet() - { - BSApp::Registry()->testGet = 123; - $this->assertEquals(123, BSApp::Registry()->testGet); - } - - public function testUnregister() - { - BSApp::Registry()->testUnregister = 1; - unset(BSApp::Registry()->testUnregister); - $this->assertObjectNotHasAttribute('testUnregister', BSApp::Registry()); - } - - public function testGetNoExist() - { - try - { - BSApp::Registry()->doesNotExist; - $this->fail('exception expected'); - } - catch (Exception $e) - {} - } - - public function testUnregisterNoExist() - { - try - { - unset(BSApp::Registry()->keyThatWontExist); - $this->fail('exception expected'); - } - catch (Exception $e) - {} - } - - public function testGetType() - { - $input = BSApp::LoadModule('Input'); - BSApp::Registry()->input = $input; - $this->assertSame($input, BSApp::Registry()->getType('Input')); - - $this->assertEquals(null, BSApp::Registry()->getType('Date')); - } - - public function testRequiredModules() - { - try - { - BSApp::RequiredModules(array('Input')); - } - catch (Exception $e) - { - $this->fail('unexpcted exception'); - } - - try - { - BSApp::RequiredModules(array('Input', 'Db')); - $this->fail('exception expected'); - } - catch (Exception $e) - {} + $this->assertEquals('', BSApp::get_debug_list()); - try - { - BSApp::RequiredModules(array('Date')); - $this->fail('exception expected'); - } - catch (Exception $e) - {} + BSApp::debug('dbg'); + $this->assertEquals('', BSApp::get_debug_list()); } } diff --git a/UnitTest/DatabaseMySQLTest.php b/UnitTest/DatabaseMySQLTest.php index 1f68604..a7746eb 100644 --- a/UnitTest/DatabaseMySQLTest.php +++ b/UnitTest/DatabaseMySQLTest.php @@ -10,7 +10,7 @@ class DatabaseMySQLTest extends DatabaseTestAbstract require_once 'tests.config.php'; require_once ISSO . '/App.php'; - $this->fixture = BSApp::LoadModule('DbMySql'); + $this->fixture = new BSDbMySql(); $this->fixture->connect(TEST_DB_MYSQL_HOST, TEST_DB_MYSQL_USER, TEST_DB_MYSQL_PASSWORD, TEST_DB_MYSQL_DATABASE); $this->fixture->query(" CREATE TABLE test @@ -32,7 +32,8 @@ class DatabaseMySQLTest extends DatabaseTestAbstract { try { - BSApp::LoadModule('DbMySql')->connect('localhost', '--invalid user--', '--invalid password--', '--nodatabase--'); + $test = new BSDbMySql(); + $test->connect('localhost', '--invalid user--', '--invalid password--', '--nodatabase--'); $this->fail('exception expected'); } catch (BSDbException $e) diff --git a/UnitTest/DatabaseMySQLiTest.php b/UnitTest/DatabaseMySQLiTest.php index 84c6c53..88907fd 100644 --- a/UnitTest/DatabaseMySQLiTest.php +++ b/UnitTest/DatabaseMySQLiTest.php @@ -9,8 +9,9 @@ class DatabaseMySQLiTest extends DatabaseTestAbstract { require_once 'tests.config.php'; require_once ISSO . '/App.php'; + require_once ISSO . '/DbMySqlI.php'; - $this->fixture = BSApp::LoadModule('DbMySqlI'); + $this->fixture = new BSDbMySqlI(); $this->fixture->connect(TEST_DB_MYSQL_HOST, TEST_DB_MYSQL_USER, TEST_DB_MYSQL_PASSWORD, TEST_DB_MYSQL_DATABASE); $this->fixture->query(" CREATE TABLE test @@ -32,7 +33,8 @@ class DatabaseMySQLiTest extends DatabaseTestAbstract { try { - BSApp::LoadModule('DbMySqlI')->connect('localhost', '--invalid user--', '--invalid password--', '--nodatabase--'); + $test = new BSDbMySqlI(); + $test->connect('localhost', '--invalid user--', '--invalid password--', '--nodatabase--'); $this->fail('exception expected'); } catch (BSDbException $e) diff --git a/UnitTest/DateTest.php b/UnitTest/DateTest.php index 8aa42df..e0c7609 100644 --- a/UnitTest/DateTest.php +++ b/UnitTest/DateTest.php @@ -19,7 +19,8 @@ class DateTest extends PHPUnit_Framework_TestCase public function setUp() { require_once ISSO . '/App.php'; - $this->fixture = BSApp::LoadModule('Date'); + require_once ISSO . '/Date.php'; + $this->fixture = new BSDate(); } public function testGmtTimes() @@ -43,7 +44,7 @@ class DateTest extends PHPUnit_Framework_TestCase public function testTimezoneList() { - $this->assertEquals(sizeof(BSDate::FetchTimeZoneList()), 30); + $this->assertEquals(sizeof(BSDate::fetch_timezone_list()), 30); } } diff --git a/UnitTest/FunctionsTest.php b/UnitTest/FunctionsTest.php index 269b29e..0356a53 100644 --- a/UnitTest/FunctionsTest.php +++ b/UnitTest/FunctionsTest.php @@ -21,19 +21,19 @@ class FunctionsTest extends PHPUnit_Framework_TestCase { $this->assertEquals('', BSFunctions::$cssClass); - BSFunctions::SwapCssClasses('1', '2'); + BSFunctions::swap_css_classes('1', '2'); $this->assertEquals('2', BSFunctions::$cssClass); - BSFunctions::SwapCssClasses('1', '2'); + BSFunctions::swap_css_classes('1', '2'); $this->assertEquals('1', BSFunctions::$cssClass); - BSFunctions::SwapCssClasses('1', '2'); + BSFunctions::swap_css_classes('1', '2'); $this->assertEquals('2', BSFunctions::$cssClass); } public function testFetchSourcePath() { - $this->assertEquals('a' . DIRECTORY_SEPARATOR, BSFunctions::FetchSourcePath('a')); + $this->assertEquals('a' . DIRECTORY_SEPARATOR, BSFunctions::fetch_source_path('a')); } public function testDownloadFile() @@ -43,14 +43,14 @@ class FunctionsTest extends PHPUnit_Framework_TestCase public function testIsValidEmail() { - $this->assertTrue(BSFunctions::IsValidEmail('test@example.com')); - $this->assertTrue(BSFunctions::IsValidEmail('test@example.co.uk')); - $this->assertTrue(BSFunctions::IsValidEmail('test.foo_hi@example.edu.k12.paloalto.ca.us')); + $this->assertTrue(BSFunctions::is_valid_email('test@example.com')); + $this->assertTrue(BSFunctions::is_valid_email('test@example.co.uk')); + $this->assertTrue(BSFunctions::is_valid_email('test.foo_hi@example.edu.k12.paloalto.ca.us')); - $this->assertFalse(BSFunctions::IsValidEmail('')); - $this->assertFalse(BSFunctions::IsValidEmail('te#st@example.com')); - $this->assertFalse(BSFunctions::IsValidEmail('@example.com')); - $this->assertFalse(BSFunctions::IsValidEmail('test@.com')); + $this->assertFalse(BSFunctions::is_valid_email('')); + $this->assertFalse(BSFunctions::is_valid_email('te#st@example.com')); + $this->assertFalse(BSFunctions::is_valid_email('@example.com')); + $this->assertFalse(BSFunctions::is_valid_email('test@.com')); } public function testIsBrowser() @@ -63,7 +63,7 @@ class FunctionsTest extends PHPUnit_Framework_TestCase $values = array(); for ($i = 0; $i < 100; $i++) { - $random = BSFunctions::Random(5); + $random = BSFunctions::random(5); $this->assertEquals(5, strlen($random)); $this->assertFalse(in_array($random, $values)); $values[] = $random; @@ -78,10 +78,10 @@ class FunctionsTest extends PHPUnit_Framework_TestCase $this->assertEquals('b', next($array)); $this->assertEquals('c', next($array)); - BSFunctions::ArraySetCurrent($array, 0); + BSFunctions::array_set_current($array, 0); $this->assertEquals('a', current($array)); - BSFunctions::ArraySetCurrent($array, 3); + BSFunctions::array_set_current($array, 3); $this->assertEquals('d', current($array)); } @@ -92,9 +92,9 @@ class FunctionsTest extends PHPUnit_Framework_TestCase public function testFetchExtension() { - $this->assertEquals('txt', BSFunctions::FetchExtension('test.txt')); - $this->assertEquals('', BSFunctions::FetchExtension('test')); - $this->assertEquals('xml', BSFunctions::FetchExtension('test.file.xml')); + $this->assertEquals('txt', BSFunctions::fetch_extension('test.txt')); + $this->assertEquals('', BSFunctions::fetch_extension('test')); + $this->assertEquals('xml', BSFunctions::fetch_extension('test.file.xml')); } public function testFetchMaxPhpFileSize() @@ -110,19 +110,19 @@ class FunctionsTest extends PHPUnit_Framework_TestCase public function testConvertLineBreaks() { $string = "test\r\nstring\r\n"; - $this->assertFalse(strpos("\r", BSFunctions::ConvertLineBreaks($string))); + $this->assertFalse(strpos("\r", BSFunctions::convert_line_breaks($string))); } public function testArrayStripEmpty() { $array = array(1, 4, 6); - $this->assertEquals(3, sizeof(BSFunctions::ArrayStripEmpty($array))); + $this->assertEquals(3, sizeof(BSFunctions::array_strip_empty($array))); $array = array(1, 0, 5, ''); - $this->assertEquals(2, sizeof(BSFunctions::ArrayStripEmpty($array))); + $this->assertEquals(2, sizeof(BSFunctions::array_strip_empty($array))); $array = array('', 'test' => array('', 6)); - $array = BSFunctions::ArrayStripEmpty($array); + $array = BSFunctions::array_strip_empty($array); $this->assertEquals(1, sizeof($array)); $this->assertEquals(1, sizeof($array['test'])); } diff --git a/UnitTest/InputTest.php b/UnitTest/InputTest.php index 01adc63..a94d74f 100644 --- a/UnitTest/InputTest.php +++ b/UnitTest/InputTest.php @@ -46,7 +46,8 @@ class InputTest extends PHPUnit_Framework_TestCase }*/ require_once ISSO . '/App.php'; - $this->fixture = BSApp::LoadModule('Input'); + require_once ISSO . '/Input.php'; + $this->fixture = new BSInput(); } public function testSanitizeInputData() diff --git a/UnitTest/InstallerTest.php b/UnitTest/InstallerTest.php index 92e06e8..b6168a2 100644 --- a/UnitTest/InstallerTest.php +++ b/UnitTest/InstallerTest.php @@ -2,6 +2,7 @@ require_once 'PHPUnit/Framework.php'; require_once ISSO . '/Installer.php'; +require_once ISSO . '/Input.php'; class InstallerTest extends PHPUnit_Framework_TestCase { @@ -13,7 +14,7 @@ class InstallerTest extends PHPUnit_Framework_TestCase global $rig; $rig = $this; - BSApp::Registry()->input = $this->input = BSApp::LoadModule('Input'); + BSApp::$input = new BSInput(); } private function _loadClass() diff --git a/UnitTest/TemplateTest.php b/UnitTest/TemplateTest.php index 483eac2..261fa24 100644 --- a/UnitTest/TemplateTest.php +++ b/UnitTest/TemplateTest.php @@ -10,17 +10,19 @@ class TemplateTest extends PHPUnit_Framework_TestCase public function setUp() { require_once ISSO . '/App.php'; + require_once ISSO . '/Template.php'; - $this->fixture = BSApp::LoadModule('Template'); + $this->fixture = new BSTemplate(); $this->fixture->setTemplateDirectory(TEST_TEMPLATE_PATH); $this->fixture->setExtension('test.tpl'); if ($this->db == null) { - $this->db = BSApp::LoadModule('DbMySql'); + require_once ISSO . '/DbMySql.php'; + $this->db = new BSDbMySql(); $this->db->connect(TEST_DB_MYSQL_HOST, TEST_DB_MYSQL_USER, TEST_DB_MYSQL_PASSWORD, TEST_DB_MYSQL_DATABASE); $this->db->query("CREATE TABLE template (filename VARCHAR (250) NOT NULL, template TEXT NOT NULL, timestamp INT NOT NULL);"); - BSApp::Registry()->db = $this->db; + BSApp::$db = $this->db; } } -- 2.43.5