mirror of
https://github.com/Mibew/java.git
synced 2025-02-14 20:35:49 +03:00
158 lines
4.0 KiB
PHP
158 lines
4.0 KiB
PHP
|
<?php
|
||
|
|
||
|
require_once dirname(__FILE__) . '/../../../../webim/libs/classes/event_dispatcher.php';
|
||
|
require_once dirname(__FILE__) . '/../../../../webim/libs/classes/plugin.php';
|
||
|
require_once dirname(__FILE__) . '/phpunit_autotest_plugin_manager/plugin.mibew.inc.php';
|
||
|
|
||
|
/**
|
||
|
* Test class for EventDispatcher.
|
||
|
* Generated by PHPUnit on 2012-07-17 at 16:09:00.
|
||
|
*/
|
||
|
class EventDispatcherTest extends PHPUnit_Framework_TestCase {
|
||
|
|
||
|
protected static $plugin = null;
|
||
|
|
||
|
public static function setUpBeforeClass() {
|
||
|
self::$plugin = new Phpunit_autotest_plugin_managerPlugin();
|
||
|
}
|
||
|
|
||
|
public static function tearDownAfterClass() {
|
||
|
self::$plugin = null;
|
||
|
}
|
||
|
|
||
|
public function testGetInstance() {
|
||
|
$dispatcher = EventDispatcher::getInstance();
|
||
|
$another_dispatcher = EventDispatcher::getInstance();
|
||
|
$this->assertSame($dispatcher, $another_dispatcher);
|
||
|
unset($another_dispatcher);
|
||
|
return $dispatcher;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @depends testGetInstance
|
||
|
*/
|
||
|
public function testRegisterEvent($dispatcher) {
|
||
|
// Try to register new event
|
||
|
$this->assertTrue($dispatcher->registerEvent('some_test_event'));
|
||
|
$this->assertTrue($dispatcher->registerEvent('some_another_test_event'));
|
||
|
|
||
|
// Try to register already registered event
|
||
|
// Following code wait for trigger user error, which converts by PHPUnit to an
|
||
|
// Exception
|
||
|
try{
|
||
|
$dispatcher->registerEvent('some_test_event');
|
||
|
$this->fail("Error expected!");
|
||
|
} catch(Exception $e) {}
|
||
|
return $dispatcher;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @depends testRegisterEvent
|
||
|
*/
|
||
|
public function testAttachListener($dispatcher) {
|
||
|
// Try to attach listener to unregistered event
|
||
|
// Following code wait for trigger user error, which converts by PHPUnit to an
|
||
|
// Exception
|
||
|
try{
|
||
|
$dispatcher->attachListener(
|
||
|
'unreginstered_event',
|
||
|
self::$plugin,
|
||
|
'testEventListener'
|
||
|
);
|
||
|
$this->fail("Error expected!");
|
||
|
} catch(Exception $e) {}
|
||
|
|
||
|
// Try to Attach wrong method as listener to event
|
||
|
// Following code wait for trigger user error, which converts by PHPUnit to an
|
||
|
// Exception
|
||
|
try{
|
||
|
$dispatcher->attachListener(
|
||
|
'some_test_event',
|
||
|
self::$plugin,
|
||
|
'wrongEventListener'
|
||
|
);
|
||
|
$this->fail("Error expected!");
|
||
|
} catch(Exception $e) {}
|
||
|
|
||
|
// Try to attach listener to registered event
|
||
|
$this->assertTrue(
|
||
|
$dispatcher->attachListener(
|
||
|
'some_test_event',
|
||
|
self::$plugin,
|
||
|
'testEventListener'
|
||
|
)
|
||
|
);
|
||
|
|
||
|
// Try to attach listener to registered event
|
||
|
$this->assertTrue(
|
||
|
$dispatcher->attachListener(
|
||
|
'some_another_test_event',
|
||
|
self::$plugin,
|
||
|
'testEventListener'
|
||
|
)
|
||
|
);
|
||
|
|
||
|
return $dispatcher;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @depends testAttachListener
|
||
|
*/
|
||
|
public function testDetachListener($dispatcher) {
|
||
|
// Try to detach listener for unregistered event.
|
||
|
// Following code wait for trigger user error, which converts by PHPUnit to an
|
||
|
// Exception
|
||
|
try{
|
||
|
$dispatcher->detachListener(
|
||
|
'unreginstered_event',
|
||
|
self::$plugin,
|
||
|
'testEventListener'
|
||
|
);
|
||
|
$this->fail("Error expected!");
|
||
|
} catch(Exception $e) {}
|
||
|
|
||
|
// Try to detach listner that was not attached to registerd event
|
||
|
$this->assertFalse(
|
||
|
$dispatcher->detachListener(
|
||
|
'some_test_event',
|
||
|
self::$plugin,
|
||
|
'wrongEventListener'
|
||
|
)
|
||
|
);
|
||
|
|
||
|
// Try to detach listener that was attached to registered
|
||
|
$this->assertTrue(
|
||
|
$dispatcher->detachListener(
|
||
|
'some_test_event',
|
||
|
self::$plugin,
|
||
|
'testEventListener'
|
||
|
)
|
||
|
);
|
||
|
return $dispatcher;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @depends testDetachListener
|
||
|
*/
|
||
|
public function testTriggerEvent($dispatcher) {
|
||
|
// Try to trigger unregistered event
|
||
|
// Following code wait for trigger user error, which converts by PHPUnit to an
|
||
|
// Exception
|
||
|
try{
|
||
|
$dispatcher->triggerEvent('unregistered_event', array());
|
||
|
$this->fail("Error expected!");
|
||
|
} catch(Exception $e) {}
|
||
|
|
||
|
// Try to thrigger registered event
|
||
|
// Wait for exception thrown by
|
||
|
// Phpunit_autotest_plugin_managerPlugin::testEventListener()
|
||
|
try{
|
||
|
$dispatcher->triggerEvent('some_another_test_event', array());
|
||
|
$this->fail("Exception excpected!");
|
||
|
} catch(Exception $e) {}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
?>
|