Skip to content

Commit

Permalink
skipping assertions if the event class does not implement the method …
Browse files Browse the repository at this point in the history
…to no skew the test results
  • Loading branch information
dogmatic69 committed Sep 29, 2012
1 parent 63cf471 commit bb39c97
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions Core/Events/Test/Lib/InfinitasEventTestCase.php
Expand Up @@ -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
*/
Expand All @@ -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');
Expand All @@ -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');
Expand All @@ -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');
Expand All @@ -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);
}
}

0 comments on commit bb39c97

Please sign in to comment.