Skip to content

Commit

Permalink
better checks for when the class has the method to test and not just …
Browse files Browse the repository at this point in the history
…a base method
  • Loading branch information
dogmatic69 committed Sep 29, 2012
1 parent bb39c97 commit 17dd6bb
Showing 1 changed file with 52 additions and 7 deletions.
59 changes: 52 additions & 7 deletions Core/Events/Test/Lib/InfinitasEventTestCase.php
Expand Up @@ -83,17 +83,20 @@ protected function _manualCall($event, $object = null) {
*
* @param string $event the event to check for
*
* @return boolean
* @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;
$eventClass = new ReflectionClass(get_class($this->EventClass));
$parentMethods = $eventClass->getParentClass()->getMethods(ReflectionMethod::IS_PUBLIC);

foreach($parentMethods as $parentMethod) {
$declaringClass = $eventClass->getMethod($parentMethod->getName())->getDeclaringClass()->getName();
if($declaringClass === $eventClass->getName() && $parentMethod->getName() == 'on' . ucfirst($event)) {
return true;
}
}

return true;
return false;
}

/**
Expand Down Expand Up @@ -159,6 +162,20 @@ public function testRequireHelpers() {
$this->assertEquals($expected, $result);
}

/**
*@brief test required helpers load correctly
*/
public function testRequireComponents() {
if(!$this->_hasTrigger('requireComponentsToLoad')) {
return false;
}

$expected = $this->_manualCall('requireComponentsToLoad', $this->ViewtEvent);

$result = $this->Event->trigger($this->ViewObject, $this->plugin . '.requireComponentsToLoad');
$this->assertEquals($expected, $result);
}

/**
*@brief test required helpers load correctly
*/
Expand All @@ -172,4 +189,32 @@ public function testRequireCss() {
$result = $this->Event->trigger($this->ViewObject, $this->plugin . '.requireCssToLoad');
$this->assertEquals($expected, $result);
}

/**
*@brief test required helpers load correctly
*/
public function testRequireJs() {
if(!$this->_hasTrigger('requireJavascriptToLoad')) {
return false;
}

$expected = $this->_manualCall('requireJavascriptToLoad', $this->ViewtEvent);

$result = $this->Event->trigger($this->ViewObject, $this->plugin . '.requireJavascriptToLoad');
$this->assertEquals($expected, $result);
}

/**
*@brief test required helpers load correctly
*/
public function testUserProfile() {
if(!$this->_hasTrigger('userProfile')) {
return false;
}

$expected = $this->_manualCall('userProfile', $this->ViewtEvent);

$result = $this->Event->trigger($this->ViewObject, $this->plugin . '.userProfile');
$this->assertEquals($expected, $result);
}
}

0 comments on commit 17dd6bb

Please sign in to comment.