Implemented Unit Tests for the patch

This commit is contained in:
Abel Hoogeveen 2018-01-16 22:18:54 +01:00
parent a2de80ae53
commit c42cfffd40
3 changed files with 29 additions and 3 deletions

View File

@ -140,7 +140,7 @@ class Events
}
foreach (self::$listeners[$eventName][$priority] as $i => $_callback) {
if ($_callback == $callback) {
if ($_callback[0] == $callback) {
unset(self::$listeners[$eventName][$priority][$i]);
return;

View File

@ -202,6 +202,24 @@ class eventsTest extends CoreTestAbstract
$this->assertNull(Events::removeListener(function($x) {echo "Called"; }, 'mockEvent', EventPriority::NORMAL));
}
/**
* @depends testAddAndRemoveListener
*/
public function testListenerVariablePass()
{
$event = $this->getMockBuilder(MockEvent::class)->getMock();
$passVariable = 'value';
$eventName = get_class($event);
Events::addListener(function($event, $passVariable) {
$this->assertEquals('value', $passVariable);
}, $eventName, EventPriority::NORMAL, $passVariable);
Events::fireEvent($event);
}
public function testDisable()
{
// First add the listener, expect it to be never called

View File

@ -118,7 +118,7 @@ class loggerTest extends CoreTestAbstract
Logger::exceptionHandler($exception);
// Check the output
$this->assertEquals('<h1>500</h1><h3>Internal Server Error</h3>', $this->output->get_output());
$this->assertEquals('<h1>500</h1><h3>Internal Server Error</h3><p></p>', $this->output->get_output());
// Check the logs
$log = Logger::$Logs[0];
@ -213,13 +213,21 @@ class loggerTest extends CoreTestAbstract
Logger::http_error($code);
// Check the output
$this->assertEquals('<h1>'.$code.'</h1><h3>'.$description.'</h3>', $this->output->get_output());
$this->assertEquals('<h1>'.$code.'</h1><h3>'.$description.'</h3><p></p>', $this->output->get_output());
}
// Test when not viewing
Logger::http_error(404, false);
}
/**
* @depends testHttpError
*/
public function testHttpErrorWithoutLayout()
{
$this->assertFalse(Logger::http_error(500, '', false));
}
public function testEnableDisable()
{
// First enable