From c5e790171b9a71111487bb1d9627198336d0cf74 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sat, 15 Sep 2007 13:03:44 -0400 Subject: [PATCH] Added the installer unit test * Installer.php: (BSInstaller::__construct): Fixed a bad call to the registry * UnitTest/AllTests.php: Add the installer test * UnitTest/InstallerTest.php: New file --- Installer.php | 6 +-- UnitTest/AllTests.php | 3 ++ UnitTest/InstallerTest.php | 88 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+), 3 deletions(-) create mode 100644 UnitTest/InstallerTest.php diff --git a/Installer.php b/Installer.php index 4ea44c3..9cff8f2 100644 --- a/Installer.php +++ b/Installer.php @@ -65,14 +65,14 @@ abstract class BSInstaller $methods = get_class_methods($this); foreach ($methods AS $name) { - if (preg_match('#step([0-9]+)#', $name)) + if (preg_match('/step([0-9]+)/', $name)) { $this->steps[] = $name; } } natsort($this->steps); - - $this->_runStep(BSApp::GetType('Input')->inputClean('step', TYPE_UINT)); + + $this->_runStep(BSApp::Registry()->getType('Input')->inputClean('step', TYPE_UINT)); } // ################################################################### diff --git a/UnitTest/AllTests.php b/UnitTest/AllTests.php index 3e4bf63..1b2ffa5 100644 --- a/UnitTest/AllTests.php +++ b/UnitTest/AllTests.php @@ -31,6 +31,9 @@ class AllTests require_once 'InputTest.php'; $suite->addTestSuite('InputTest'); + require_once 'InstallerTest.php'; + $suite->addTestSuite('InstallerTest'); + require_once 'AppTest.php'; $suite->addTestSuite('AppTest'); diff --git a/UnitTest/InstallerTest.php b/UnitTest/InstallerTest.php new file mode 100644 index 0000000..c74d635 --- /dev/null +++ b/UnitTest/InstallerTest.php @@ -0,0 +1,88 @@ +input = $this->input = BSApp::LoadModule('Input'); + } + + private function _loadClass() + { + ob_start(); + $this->fixture = new TestInstallerFixture('InstallerTest.php'); + $data = ob_get_contents(); + ob_clean(); + ob_end_clean(); + return $data; + } + + public function stepCheck($step) + { + $this->assertEquals($this->input->in['step'], $step); + } + + public function testWelcome() + { + $this->input->in['step'] = 0; + $data = $this->_loadClass(); + $this->assertTrue(strpos($data, 'This is a welcome page.') !== false); + } + + public function testStep1() + { + $this->input->in['step'] = 1; + $data = $this->_loadClass(); + $this->assertTrue(strpos($data, '') !== false); + } + + public function testLastStep() + { + $this->input->in['step'] = 2; + $data = $this->_loadClass(); + $this->assertTrue(strpos($data, '') !== false); + } +} + +class TestInstallerFixture extends BSInstaller +{ + public $rig; + + protected function _pageTitle() + { + return 'Test Installer'; + } + + protected function _finalLink() + { + return 'FINAL LINK'; + } + + protected function _welcomePage() + { + return 'This is a welcome page.'; + } + + public function step1() + { + global $rig; + $rig->stepCheck(1); + } + + public function step2() + { + global $rig; + $rig->stepCheck(2); + } +} + +?> \ No newline at end of file -- 2.43.5