From bb39c97f2896a1f9487e490b0664aa45c8c97dd9 Mon Sep 17 00:00:00 2001 From: dogmatic69 Date: Sat, 29 Sep 2012 16:50:27 +0100 Subject: [PATCH] skipping assertions if the event class does not implement the method to no skew the test results --- .../Test/Lib/InfinitasEventTestCase.php | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/Core/Events/Test/Lib/InfinitasEventTestCase.php b/Core/Events/Test/Lib/InfinitasEventTestCase.php index b188646db..bc89caa2c 100644 --- a/Core/Events/Test/Lib/InfinitasEventTestCase.php +++ b/Core/Events/Test/Lib/InfinitasEventTestCase.php @@ -78,6 +78,24 @@ protected function _manualCall($event, $object = null) { return $expected; } +/** + * @brief test if the event class has the required event + * + * @param string $event the event to check for + * + * @return boolean + */ + protected function _hasTrigger($event) { + $method = 'on' . ucfirst($event); + $parentMethods = get_class_methods(get_parent_class($this->EventClass)); + $methods = get_class_methods($this->EventClass); + if(!in_array($method, array_diff($methods, $parentMethods))) { + return false; + } + + return true; + } + /** * @brief test the instance is loaded correctly */ @@ -89,6 +107,10 @@ public function testInstance() { * @brief test getting the plugins details */ public function testPluginRollCall() { + if(!$this->_hasTrigger('pluginRollCall')) { + return false; + } + $expected = $this->_manualCall('pluginRollCall'); $result = $this->Event->trigger($this->ObjectObject, $this->plugin . '.pluginRollCall'); @@ -99,6 +121,10 @@ public function testPluginRollCall() { * @brief test getting additional db configs */ public function testRequireDatabaseConfigs() { + if(!$this->_hasTrigger('requireDatabaseConfigs')) { + return false; + } + $expected = $this->_manualCall('requireDatabaseConfigs', $this->ObjectEvent); $result = $this->Event->trigger($this->ModelObject, $this->plugin . '.requireDatabaseConfigs'); @@ -109,6 +135,10 @@ public function testRequireDatabaseConfigs() { * @brief test getting the admin menu */ public function testAdminMenu() { + if(!$this->_hasTrigger('adminMenu')) { + return false; + } + $expected = $this->_manualCall('adminMenu', $this->ObjectEvent); $result = $this->Event->trigger($this->ViewObject, $this->plugin . '.adminMenu'); @@ -119,9 +149,27 @@ public function testAdminMenu() { *@brief test required helpers load correctly */ public function testRequireHelpers() { + if(!$this->_hasTrigger('requireHelpersToLoad')) { + return false; + } + $expected = $this->_manualCall('requireHelpersToLoad', $this->ViewtEvent); $result = $this->Event->trigger($this->ViewObject, $this->plugin . '.requireHelpersToLoad'); $this->assertEquals($expected, $result); } + +/** + *@brief test required helpers load correctly + */ + public function testRequireCss() { + if(!$this->_hasTrigger('requireCssToLoad')) { + return false; + } + + $expected = $this->_manualCall('requireCssToLoad', $this->ViewtEvent); + + $result = $this->Event->trigger($this->ViewObject, $this->plugin . '.requireCssToLoad'); + $this->assertEquals($expected, $result); + } } \ No newline at end of file