summaryrefslogtreecommitdiff
path: root/plugins/Irc/extlib/phergie/Tests
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/Irc/extlib/phergie/Tests')
-rw-r--r--plugins/Irc/extlib/phergie/Tests/Phergie/Plugin/HandlerTest.php461
-rwxr-xr-xplugins/Irc/extlib/phergie/Tests/Phergie/Plugin/Mock.php49
-rw-r--r--plugins/Irc/extlib/phergie/Tests/Phergie/Plugin/PingTest.php175
-rw-r--r--plugins/Irc/extlib/phergie/Tests/Phergie/Plugin/PongTest.php74
-rw-r--r--plugins/Irc/extlib/phergie/Tests/Phergie/Plugin/TerryChayTest.php99
-rw-r--r--plugins/Irc/extlib/phergie/Tests/Phergie/Plugin/TestCase.php207
-rwxr-xr-xplugins/Irc/extlib/phergie/Tests/Phergie/Plugin/TestNonInstantiablePluginFromFile.php43
-rw-r--r--plugins/Irc/extlib/phergie/Tests/TestHelper.php26
-rw-r--r--plugins/Irc/extlib/phergie/Tests/phpunit.xml26
9 files changed, 1160 insertions, 0 deletions
diff --git a/plugins/Irc/extlib/phergie/Tests/Phergie/Plugin/HandlerTest.php b/plugins/Irc/extlib/phergie/Tests/Phergie/Plugin/HandlerTest.php
new file mode 100644
index 000000000..b359c1155
--- /dev/null
+++ b/plugins/Irc/extlib/phergie/Tests/Phergie/Plugin/HandlerTest.php
@@ -0,0 +1,461 @@
+<?php
+/**
+ * Phergie
+ *
+ * PHP version 5
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.
+ * It is also available through the world-wide-web at this URL:
+ * http://phergie.org/license
+ *
+ * @category Phergie
+ * @package Phergie_Tests
+ * @author Phergie Development Team <team@phergie.org>
+ * @copyright 2008-2010 Phergie Development Team (http://phergie.org)
+ * @license http://phergie.org/license New BSD License
+ * @link http://pear.phergie.org/package/Phergie_Tests
+ */
+
+/**
+ * Unit test suite for Pherge_Plugin_Handler.
+ *
+ * @category Phergie
+ * @package Phergie_Tests
+ * @author Phergie Development Team <team@phergie.org>
+ * @license http://phergie.org/license New BSD License
+ * @link http://pear.phergie.org/package/Phergie_Tests
+ */
+class Phergie_Plugin_HandlerTest extends PHPUnit_Framework_TestCase
+{
+ /**
+ * Plugin handler instance being tested
+ *
+ * @var Phergie_Plugin_Handler
+ */
+ protected $handler;
+
+ /**
+ * Sets up a new handler instance before each test.
+ *
+ * @return void
+ */
+ public function setUp()
+ {
+ $this->handler = new Phergie_Plugin_Handler(
+ new Phergie_Config(),
+ new Phergie_Event_Handler()
+ );
+ }
+
+ /**
+ * Destroys the handler instance after each test
+ *
+ * @return void
+ */
+ public function tearDown()
+ {
+ unset($this->handler);
+ }
+
+ /**
+ * Ensures that we can iterate over the handler
+ *
+ * @return void
+ */
+ public function testImplementsIterator()
+ {
+ $reflection = new ReflectionObject($this->handler);
+ $this->assertTrue(
+ $reflection->implementsInterface('IteratorAggregate')
+ );
+
+ $this->assertType(
+ 'Iterator', $this->handler->getIterator(),
+ 'getIterator() must actually return an Iterator'
+ );
+ }
+
+ /**
+ * Ensures a newly instantiated handler does not have plugins associated
+ * with it
+ *
+ * @depends testImplementsIterator
+ * @return void
+ */
+ public function testEmptyHandlerHasNoPlugins()
+ {
+ $count = 0;
+ foreach ($this->handler as $plugin) {
+ $count++;
+ }
+
+ $this->assertEquals(0, $count);
+ }
+
+ /**
+ * Ensures a newly instantiated handler does not default to autoload
+ *
+ * @return void
+ */
+ public function testDefaultsToNotAutoload()
+ {
+ $this->assertFalse($this->handler->getAutoload());
+ }
+
+ /**
+ * addPath provides a fluent interface
+ *
+ * @return void
+ */
+ public function testAddPathProvidesFluentInterface()
+ {
+ $handler = $this->handler->addPath(dirname(__FILE__));
+ $this->assertSame($this->handler, $handler);
+ }
+
+ /**
+ * addPath throws an exception when it cannot read the directory
+ *
+ * @return void
+ */
+ public function testAddPathThrowsExceptionOnUnreadableDirectory()
+ {
+ try {
+ $this->handler->addPath('/an/unreadable/directory/path');
+ } catch(Phergie_Plugin_Exception $e) {
+ $this->assertEquals(
+ Phergie_Plugin_Exception::ERR_DIRECTORY_NOT_READABLE,
+ $e->getCode()
+ );
+ return;
+ }
+
+ $this->fail('An expected exception has not been raised.');
+ }
+
+ /**
+ * adds a path into the plugin handler and then ensures that files
+ * in that location can be found
+ *
+ * @return void
+ */
+ public function testAddPath()
+ {
+ $plugin_name = 'Mock';
+ try {
+ $this->handler->addPlugin($plugin_name);
+ } catch(Phergie_Plugin_Exception $e) {
+ $this->assertEquals(
+ Phergie_Plugin_Exception::ERR_CLASS_NOT_FOUND,
+ $e->getCode()
+ );
+
+ $this->handler->addPath(dirname(__FILE__), 'Phergie_Plugin_');
+
+ try {
+ $this->handler->addPlugin($plugin_name);
+ } catch(Phergie_Plugin_Exception $e) {
+ $this->fail(
+ 'After adding the directory, the plugin was still '
+ . 'not found.'
+ );
+ }
+
+ return;
+ }
+
+ $this->fail(
+ 'Before adding the directory, an expected exception '
+ . 'was not raised'
+ );
+ }
+
+ /**
+ * addPlugin returns the plugin instance that was added
+ *
+ * @return void
+ */
+ public function testAddPluginByInstanceReturnsPluginInstance() {
+ $plugin = $this->getMock('Phergie_Plugin_Abstract');
+ $plugin
+ ->expects($this->any())
+ ->method('getName')
+ ->will($this->returnValue('TestPlugin'));
+
+ $returned_plugin = $this->handler->addPlugin($plugin);
+ $this->assertSame(
+ $returned_plugin,
+ $plugin,
+ 'addPlugin returns the same instance that is passed to it'
+ );
+ }
+
+ /**
+ * Can add a plugin to the handler by shortname
+ *
+ * @return void
+ */
+ public function testAddPluginToHandlerByShortname()
+ {
+ $plugin_name = 'Mock';
+ $this->handler->addPath(dirname(__FILE__), 'Phergie_Plugin_');
+
+ $returned_plugin = $this->handler->addPlugin($plugin_name);
+ $this->assertTrue($this->handler->hasPlugin($plugin_name));
+ $this->assertType(
+ 'Phergie_Plugin_Mock',
+ $this->handler->getPlugin($plugin_name)
+ );
+ $this->assertSame(
+ $this->handler->getPlugin($plugin_name),
+ $returned_plugin,
+ 'Handler contains plugin when added by shortname.'
+ );
+ }
+
+
+ /**
+ * Can add a plugin to the handler by instance
+ *
+ * @return void
+ */
+ public function testAddPluginToHandlerByInstance()
+ {
+ $plugin = $this->getMock('Phergie_Plugin_Abstract');
+ $plugin
+ ->expects($this->any())
+ ->method('getName')
+ ->will($this->returnValue('TestPlugin'));
+
+ $returned_plugin = $this->handler->addPlugin($plugin);
+
+ $this->assertTrue($this->handler->hasPlugin('TestPlugin'));
+ $this->assertSame(
+ $plugin, $returned_plugin,
+ 'addPlugin returns the same plugin'
+ );
+ $this->assertSame(
+ $plugin, $this->handler->getPlugin('TestPlugin'),
+ 'getPlugin returns the same plugin'
+ );
+ }
+
+ /**
+ * addPlugin throws an exception when it can't find the plugin
+ *
+ * @return void
+ */
+ public function testAddPluginThrowsExceptionIfCannotFindPlugin()
+ {
+ try {
+ $this->handler->addPlugin('TestPlugin');
+ } catch(Phergie_Plugin_Exception $e) {
+ $this->assertEquals(
+ Phergie_Plugin_Exception::ERR_CLASS_NOT_FOUND,
+ $e->getCode()
+ );
+ return;
+ }
+
+ $this->fail('An expected exception has not been raised.');
+ }
+
+ /**
+ * addPlugin throws an exception when trying to instantiate a
+ * class that doesn't extend from Phergie_Plugin_Abstract
+ *
+ * @return void
+ */
+ public function testAddPluginThrowsExceptionIfRequestingNonPlugin()
+ {
+ try {
+ $this->handler->addPlugin('Handler');
+ } catch(Phergie_Plugin_Exception $e) {
+ $this->assertEquals(
+ Phergie_Plugin_Exception::ERR_INCORRECT_BASE_CLASS,
+ $e->getCode()
+ );
+ return;
+ }
+
+ $this->fail('An expected exception has not been raised.');
+ }
+
+ /**
+ * addPlugin throws an exception when trying to instantiate a
+ * class that can't be instantiated.
+ *
+ * @return void
+ */
+ public function testAddPluginThrowsExceptionIfPluginNotInstantiable()
+ {
+ $this->handler->addPath(dirname(__FILE__), 'Phergie_Plugin_');
+ try {
+ $this->handler->addPlugin('TestNonInstantiablePluginFromFile');
+ } catch(Phergie_Plugin_Exception $e) {
+ $this->assertEquals(
+ Phergie_Plugin_Exception::ERR_CLASS_NOT_INSTANTIABLE,
+ $e->getCode()
+ );
+ return;
+ }
+
+ $this->fail('An expected exception has not been raised.');
+ }
+
+ /**
+ * addPlugin with shortname and arguments passes args to constructor
+ *
+ * @return null
+ */
+ public function testAddPluginShortnamePassesArgsToConstructor()
+ {
+ $plugin_name = 'Mock';
+ $this->handler->addPath(dirname(__FILE__), 'Phergie_Plugin_');
+
+ $arguments = array('a', 'b', 'c');
+
+ $plugin = $this->handler->addPlugin($plugin_name, $arguments);
+ $this->assertAttributeSame(
+ $arguments,
+ 'args',
+ $plugin,
+ 'Arguments passed in to addPlugin match the arguments '
+ . 'the Mock plugin constructor received'
+ );
+ }
+
+ /**
+ * addPlugin passes Phergie_Config to instantiated plugin
+ *
+ * @return null
+ */
+ public function testAddPluginPassesPhergieConfigToInstantiatedPlugin()
+ {
+ $my_config = new Phergie_Config();
+ $my_config['my_option'] = 'my_value';
+
+ // create a new handler with this config
+ unset($this->handler);
+ $this->handler = new Phergie_Plugin_Handler(
+ $my_config,
+ new Phergie_Event_Handler()
+ );
+
+ $plugin_name = 'Mock';
+ $this->handler->addPath(dirname(__FILE__), 'Phergie_Plugin_');
+
+ $plugin = $this->handler->addPlugin($plugin_name);
+
+ $this->assertSame(
+ $my_config,
+ $plugin->getConfig(),
+ 'addPlugin passes Phergie_Config to instantiated plugin'
+ );
+ }
+
+ /**
+ * addPlugin passes Phergie_Event_Handler to instantiated plugin
+ *
+ * @return null
+ */
+ public function testAddPluginPassesPhergieEventHandlerToInstantiatedPlugin()
+ {
+ $plugin = $this->getMock('Phergie_Plugin_Abstract');
+ $plugin
+ ->expects($this->any())
+ ->method('getName')
+ ->will($this->returnValue('TestPlugin'));
+
+ $my_event_handler = new Phergie_Event_Handler();
+ $my_event_handler->addEvent($plugin, 'ping');
+
+ // create a new plugin handler with this event handler
+ unset($this->handler);
+ $this->handler = new Phergie_Plugin_Handler(
+ new Phergie_Config(),
+ $my_event_handler
+ );
+
+ $plugin_name = 'Mock';
+ $this->handler->addPath(dirname(__FILE__), 'Phergie_Plugin_');
+
+ $plugin = $this->handler->addPlugin($plugin_name);
+
+ $this->assertSame(
+ $my_event_handler,
+ $plugin->getEventHandler(),
+ 'addPlugin passes Phergie_Event_Handler to instantiated plugin'
+ );
+ }
+
+ /**
+ * @todo addPlugin calls onLoad() to instantiated plugin
+ */
+
+ /**
+ * implements __isset
+ *
+ * @return void
+ */
+ public function testPluginHandlerImplementsIsset()
+ {
+ $plugin_name = 'TestPlugin';
+
+ $this->assertFalse(isset($this->handler->{$plugin_name}));
+
+ $plugin = $this->getMock('Phergie_Plugin_Abstract');
+ $plugin
+ ->expects($this->any())
+ ->method('getName')
+ ->will($this->returnValue($plugin_name));
+
+ $this->handler->addPlugin($plugin);
+
+ $this->assertTrue(isset($this->handler->{$plugin_name}));
+
+ }
+
+ /**
+ * addPlugin() returns the same plugin when requested twice
+ *
+ * @return void
+ */
+ public function testAddPluginReturnsSamePluginWhenAskedTwice()
+ {
+ $plugin_name = 'Mock';
+ $this->handler->addPath(dirname(__FILE__), 'Phergie_Plugin_');
+
+ $plugin1 = $this->handler->addPlugin($plugin_name);
+ $plugin2 = $this->handler->addPlugin($plugin_name);
+ $this->assertSame($plugin1, $plugin2);
+ }
+
+
+ /**
+ * Tests an exception is thrown when trying to get a plugin
+ * that is not already loaded and autoload is off
+ *
+ * @depends testDefaultsToNotAutoload
+ * @return void
+ */
+ public function testExceptionThrownWhenLoadingPluginWithoutAutoload()
+ {
+ $this->handler->addPath(dirname(__FILE__), 'Phergie_Plugin_');
+
+ try {
+ $this->handler->getPlugin('Mock');
+ } catch (Phergie_Plugin_Exception $expected) {
+ $this->assertEquals(
+ Phergie_Plugin_Exception::ERR_PLUGIN_NOT_LOADED,
+ $expected->getCode()
+ );
+ return;
+ }
+
+ $this->fail('An expected exception has not been raised.');
+ }
+}
diff --git a/plugins/Irc/extlib/phergie/Tests/Phergie/Plugin/Mock.php b/plugins/Irc/extlib/phergie/Tests/Phergie/Plugin/Mock.php
new file mode 100755
index 000000000..714e3d9a4
--- /dev/null
+++ b/plugins/Irc/extlib/phergie/Tests/Phergie/Plugin/Mock.php
@@ -0,0 +1,49 @@
+<?php
+/**
+ * Phergie
+ *
+ * PHP version 5
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.
+ * It is also available through the world-wide-web at this URL:
+ * http://phergie.org/license
+ *
+ * @category Phergie
+ * @package Phergie_Tests
+ * @author Phergie Development Team <team@phergie.org>
+ * @copyright 2008-2010 Phergie Development Team (http://phergie.org)
+ * @license http://phergie.org/license New BSD License
+ * @link http://pear.phergie.org/package/Phergie_Tests
+ */
+
+/**
+ * Creates a plugin on the filesystem that can be used by
+ * Phergie_Plugin_Handler's addPath utility to be located and loaded.
+ *
+ * @category Phergie
+ * @package Phergie_Tests
+ * @author Phergie Development Team <team@phergie.org>
+ * @license http://phergie.org/license New BSD License
+ * @link http://pear.phergie.org/package/Phergie_Tests
+ */
+class Phergie_Plugin_Mock extends Phergie_Plugin_Abstract
+{
+ /**
+ * holds the arguments that were passed in to the constructor
+ * @var array
+ */
+ protected $args;
+
+ /**
+ * processes a variable number of arguments into the args property
+ *
+ * @return null
+ */
+ public function __construct()
+ {
+ $this->args = func_get_args();
+ }
+}
diff --git a/plugins/Irc/extlib/phergie/Tests/Phergie/Plugin/PingTest.php b/plugins/Irc/extlib/phergie/Tests/Phergie/Plugin/PingTest.php
new file mode 100644
index 000000000..b9c2dde3d
--- /dev/null
+++ b/plugins/Irc/extlib/phergie/Tests/Phergie/Plugin/PingTest.php
@@ -0,0 +1,175 @@
+<?php
+/**
+ * Phergie
+ *
+ * PHP version 5
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.
+ * It is also available through the world-wide-web at this URL:
+ * http://phergie.org/license
+ *
+ * @category Phergie
+ * @package Phergie
+ * @author Phergie Development Team <team@phergie.org>
+ * @copyright 2008-2010 Phergie Development Team (http://phergie.org)
+ * @license http://phergie.org/license New BSD License
+ * @link http://pear.phergie.org/package/Phergie
+ */
+
+require_once(dirname(__FILE__) . '/TestCase.php');
+
+/**
+ * Unit test suite for Pherge_Plugin_Ping.
+ *
+ * @category Phergie
+ * @package Phergie_Tests
+ * @author Phergie Development Team <team@phergie.org>
+ * @license http://phergie.org/license New BSD License
+ * @link http://pear.phergie.org/package/Phergie
+ */
+class Phergie_Plugin_PingTest extends Phergie_Plugin_TestCase
+{
+ protected $config = array('ping.ping' => 10,
+ 'ping.event' => 300);
+
+ /**
+ * Sets up the fixture, for example, opens a network connection.
+ * This method is called before a test is executed.
+ */
+ protected function setUp()
+ {
+ $this->setPlugin(new Phergie_Plugin_Ping);
+ }
+
+ /**
+ * Test the lastEvent setter and getter
+ */
+ public function testSetGetLastEvent()
+ {
+ $expected = rand(100000,200000);
+ $this->plugin->setLastEvent($expected);
+ $this->assertEquals($expected,
+ $this->plugin->getLastEvent(),
+ 'Assert that the last event was set and gotten ' .
+ 'correctly');
+ }
+
+ /**
+ * Test the lastPing setter and getter
+ */
+ public function testSetGetLastPing()
+ {
+
+ $expected = rand(100000,200000);
+ $this->plugin->setLastPing($expected);
+ $this->assertEquals($expected,
+ $this->plugin->getLastPing(),
+ 'Assert that the last ping was set and gotten ' .
+ 'correctly');
+ }
+
+ /**
+ * Tests the onConnect hook
+ */
+ public function testOnConnect()
+ {
+ $time = time() - 1;
+ // We need to make sure time() is going to be creater next time it is called
+
+ $this->plugin->onConnect();
+ $this->assertNull($this->plugin->getLastPing(),
+ 'onConnect should set last ping to null');
+ $this->assertGreaterThan($time,
+ $this->plugin->getLastEvent(),
+ 'onConnect should update lastEvent with the ' .
+ 'current timestamp');
+ $this->assertLessThan($time + 2,
+ $this->plugin->getLastEvent(),
+ 'onConnect should update lastEvent with the ' .
+ 'current timestamp');
+ }
+
+ /**
+ * Test that the preEvent method updates the lastEvent with the current time
+ */
+ public function testPreEvent()
+ {
+ $time = time() -1;
+ $this->plugin->preEvent();
+ $this->assertGreaterThan($time,
+ $this->plugin->getLastEvent(),
+ 'Last event time was set properly on preEvent');
+ $this->assertLessThan($time +2,
+ $this->plugin->getLastEvent(),
+ 'Last Event time was set properly on preEvent');
+ }
+
+ /**
+ * @todo Implement testOnPingResponse().
+ */
+ public function testOnPingResponse()
+ {
+ $this->plugin->setLastPing(time());
+ $this->plugin->onPingResponse();
+ $this->assertNull($this->plugin->getLastPing(),
+ 'Last ping time should be null after onPingResponse');
+
+ }
+
+ /**
+ * Test that the plugin issues a quit when the ping threashold
+ * has been exceeded
+ */
+ public function testOnTickExceededPingThresholdQuits()
+ {
+ $this->plugin->setLastPing(1);
+ $this->plugin->onTick();
+ $this->assertHasEvent(Phergie_Event_Command::TYPE_QUIT);
+ }
+
+ /**
+ * Test that the plugin issues a quit when the ping threashold
+ * has been exceeded
+ */
+ public function testOnTickPingWithinThresholdDoesNotQuits()
+ {
+ $this->plugin->setLastPing(time());
+ $this->plugin->onTick();
+ $this->assertDoesNotHaveEvent(Phergie_Event_Command::TYPE_QUIT);
+ }
+
+ /**
+ * Test that a ping is emitted when the event threashold is exceeded
+ */
+ public function testPingEmittedAfterThresholdExceeded()
+ {
+ $this->plugin->setLastEvent(time() - $this->config['ping.event'] - 1);
+ $this->plugin->onTick();
+ $this->assertHasEvent(Phergie_Event_Command::TYPE_PING);
+ $events = $this->getResponseEvents(Phergie_Event_Command::TYPE_PING);
+ foreach ($events as $event) {
+ $this->assertEventEmitter($event,
+ $this->plugin,
+ 'Assert that the event was emitted by the tested plugin');
+ }
+ }
+
+ /**
+ * Test that no ping is emitted when the event thresthold is not exceeded
+ */
+ public function testNoPingEmittedWhenThresholdNotExceeded()
+ {
+ $this->plugin->setLastEvent(time() - $this->config['ping.event'] +1);
+ $this->plugin->onTick();
+ $this->assertDoesNotHaveEvent(Phergie_Event_Command::TYPE_PING);
+ }
+
+ public function tearDown()
+ {
+ $this->handler->clearEvents();
+ }
+
+} \ No newline at end of file
diff --git a/plugins/Irc/extlib/phergie/Tests/Phergie/Plugin/PongTest.php b/plugins/Irc/extlib/phergie/Tests/Phergie/Plugin/PongTest.php
new file mode 100644
index 000000000..a8bc8fd05
--- /dev/null
+++ b/plugins/Irc/extlib/phergie/Tests/Phergie/Plugin/PongTest.php
@@ -0,0 +1,74 @@
+<?php
+/**
+ * Phergie
+ *
+ * PHP version 5
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.
+ * It is also available through the world-wide-web at this URL:
+ * http://phergie.org/license
+ *
+ * @category Phergie
+ * @package Phergie
+ * @author Phergie Development Team <team@phergie.org>
+ * @copyright 2008-2010 Phergie Development Team (http://phergie.org)
+ * @license http://phergie.org/license New BSD License
+ * @link http://pear.phergie.org/package/Phergie
+ */
+
+require_once(dirname(__FILE__) . '/TestCase.php');
+
+/**
+ * Unit test suite for Pherge_Plugin_Pong.
+ *
+ * @category Phergie
+ * @package Phergie_Tests
+ * @author Phergie Development Team <team@phergie.org>
+ * @license http://phergie.org/license New BSD License
+ * @link http://pear.phergie.org/package/Phergie
+ */
+class Phergie_Plugin_PongTest extends Phergie_Plugin_TestCase
+{
+ /**
+ * Sets up the fixture, for example, opens a network connection.
+ * This method is called before a test is executed.
+ */
+ protected function setUp()
+ {
+ $this->setPlugin(new Phergie_Plugin_Pong);
+ }
+
+ /**
+ * Test that when a ping is received, a Phergie_Event_Command::TYPE_PONG
+ * is set to the handler
+ *
+ * @event Phergie_Event_Command::TYPE_PING
+ */
+ public function testOnPing()
+ {
+ $this->plugin->onPing();
+ $this->assertHasEvent(Phergie_Event_Command::TYPE_PONG);
+ }
+
+ /**
+ * Test that when a ping is received, a Phergie_Event_Command::TYPE_PONG
+ * is set to the handler
+ *
+ * @event Phergie_Event_Command::TYPE_PING
+ */
+ public function testOnPingResponseArguement()
+ {
+ $this->plugin->onPing();
+ $this->assertHasEvent(Phergie_Event_Command::TYPE_PONG);
+ $events = $this->getResponseEvents(Phergie_Event_Command::TYPE_PONG);
+ $this->assertTrue(count($events) === 1, 'Assert that only one pong is emitted');
+ $this->assertEventEmitter(current($events),
+ $this->plugin,
+ 'Assert that the tested plugin emitted the event');
+
+ }
+
+}
diff --git a/plugins/Irc/extlib/phergie/Tests/Phergie/Plugin/TerryChayTest.php b/plugins/Irc/extlib/phergie/Tests/Phergie/Plugin/TerryChayTest.php
new file mode 100644
index 000000000..e76020b6b
--- /dev/null
+++ b/plugins/Irc/extlib/phergie/Tests/Phergie/Plugin/TerryChayTest.php
@@ -0,0 +1,99 @@
+<?php
+/**
+ * Phergie
+ *
+ * PHP version 5
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.
+ * It is also available through the world-wide-web at this URL:
+ * http://phergie.org/license
+ *
+ * @category Phergie
+ * @package Phergie
+ * @author Phergie Development Team <team@phergie.org>
+ * @copyright 2008-2010 Phergie Development Team (http://phergie.org)
+ * @license http://phergie.org/license New BSD License
+ * @link http://pear.phergie.org/package/Phergie
+ */
+
+require_once(dirname(__FILE__) . '/TestCase.php');
+
+/**
+ * Unit test suite for Pherge_Plugin_TerryChay.
+ *
+ * @category Phergie
+ * @package Phergie_Tests
+ * @author Phergie Development Team <team@phergie.org>
+ * @license http://phergie.org/license New BSD License
+ * @link http://pear.phergie.org/package/Phergie
+ */
+class Phergie_Plugin_TerryChayTest extends Phergie_Plugin_TestCase
+{
+ /**
+ * Sets up the fixture, for example, opens a network connection.
+ * This method is called before a test is executed.
+ */
+ protected function setUp()
+ {
+ $this->setPlugin(new Phergie_Plugin_TerryChay());
+ $config = new Phergie_Config();
+ $handler = new Phergie_Plugin_Handler($config, $this->handler);
+ $this->plugin->setPluginHandler($handler);
+ $handler->addPlugin($this->plugin);
+ $handler->addPlugin(new Phergie_Plugin_Http($config));
+ $this->plugin->setConfig($config);
+ $this->connection->setNick('phergie');
+ $this->plugin->onLoad();
+ }
+
+ /**
+ * @event Phergie_Event_Request::privmsg
+ * @eventArg #zftalk
+ * @eventArg tychay
+ */
+ public function testWithTyChay()
+ {
+ $this->plugin->onPrivMsg();
+ $this->assertHasEvent(Phergie_Event_Command::TYPE_PRIVMSG);
+ }
+
+ /**
+ * @event Phergie_Event_Request::privmsg
+ * @eventArg #zftalk
+ * @eventArg terrychay
+ */
+ public function testWithTerryChay()
+ {
+ $this->plugin->onPrivMsg();
+ $this->assertDoesNotHaveEvent(Phergie_Event_Command::TYPE_PRIVMSG,
+ 'string "terrychay" should not invoke a response');
+ }
+
+ /**
+ * @event Phergie_Event_Request::privmsg
+ * @eventArg #zftalk
+ * @eventArg terry chay
+ */
+ public function testWithTerry_Chay()
+ {
+ $this->plugin->onPrivMsg();
+ $this->assertHasEvent(Phergie_Event_Command::TYPE_PRIVMSG,
+ 'string "terry chay" should invoke a response');
+ }
+
+ /**
+ * @event Phergie_Event_Request::privmsg
+ * @eventArg #zftalk
+ * @eventArg Elazar is not Mr. Chay
+ */
+ public function testWithNoTyChay()
+ {
+ $this->plugin->onPrivMsg();
+ $this->assertDoesNotHaveEvent(Phergie_Event_Command::TYPE_PRIVMSG,
+ 'Failed asserting that elazar is not ' .
+ 'tychay');
+ }
+} \ No newline at end of file
diff --git a/plugins/Irc/extlib/phergie/Tests/Phergie/Plugin/TestCase.php b/plugins/Irc/extlib/phergie/Tests/Phergie/Plugin/TestCase.php
new file mode 100644
index 000000000..36b81d6fa
--- /dev/null
+++ b/plugins/Irc/extlib/phergie/Tests/Phergie/Plugin/TestCase.php
@@ -0,0 +1,207 @@
+<?php
+/**
+ * Phergie
+ *
+ * PHP version 5
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.
+ * It is also available through the world-wide-web at this URL:
+ * http://phergie.org/license
+ *
+ * @category Phergie
+ * @package Phergie_Tests
+ * @author Phergie Development Team <team@phergie.org>
+ * @copyright 2008-2010 Phergie Development Team (http://phergie.org)
+ * @license http://phergie.org/license New BSD License
+ * @link http://pear.phergie.org/package/Phergie_Tests
+ */
+
+/**
+ * Unit test suite for Pherge_Plugin classes
+ *
+ * @category Phergie
+ * @package Phergie_Tests
+ * @author Phergie Development Team <team@phergie.org>
+ * @license http://phergie.org/license New BSD License
+ * @link http://pear.phergie.org/package/Phergie_Tests
+ */
+abstract class Phergie_Plugin_TestCase extends PHPUnit_Framework_TestCase
+{
+ /**
+ * @var Phergie_Event_Handler
+ */
+ protected $handler;
+
+ /**
+ * @var Phergie_Connection
+ */
+ protected $connection;
+
+ /**
+ * @var array
+ */
+ protected $eventArgs;
+
+ /**
+ * @var Phergie_Plugin_Abstract
+ */
+ protected $plugin;
+
+ /**
+ * @var array
+ */
+ protected $config = array();
+
+ /**
+ * Constructs a test case with the given name.
+ *
+ * @param string $name
+ * @param array $data
+ * @param string $dataName
+ */
+ public function __construct($name = NULL, array $data = array(), $dataName = '')
+ {
+ parent::__construct($name, $data, $dataName);
+ $this->connection = new Phergie_Connection();
+ $this->handler = new Phergie_Event_Handler();
+ }
+
+ /**
+ * Assert that a given event type exists in the event handler
+ * @param string $event
+ * @param string $message
+ */
+ public function assertHasEvent($event, $message = null)
+ {
+ self::assertTrue($this->handler->hasEventOfType($event), $message);
+ }
+
+ /**
+ * Assert that a given event type DOES NOT exist in the event handler
+ * @param string $event
+ * @param string $message
+ */
+ public function assertDoesNotHaveEvent($event, $message = null)
+ {
+ self::assertFalse($this->handler->hasEventOfType($event), $message);
+ }
+
+ /**
+ * Assert that the emitter of the given command event was the given
+ * plugin
+ *
+ * @param Phergie_Event_Command $event
+ * @param Phergie_Plugin_Abstract $plugin
+ * @param string $message
+ */
+ public function assertEventEmitter(Phergie_Event_Command $event,
+ Phergie_Plugin_Abstract $plugin,
+ $message = null)
+ {
+ $this->assertSame($plugin, $event->getPlugin(), $message);
+ }
+
+ /**
+ * Gets the events added to the handler by the plugin
+ * @param string $type
+ * @return array | null
+ */
+ public function getResponseEvents($type = null)
+ {
+ if (is_string($type) && strlen($type) > 0) {
+ return $this->handler->getEventsOfType($type);
+ }
+ return $this->handler->getEvents();
+ }
+
+ /**
+ * Sets the event for the test
+ * @param array $event
+ * @param array $eventArgs
+ */
+ public function setEvent(array $event, array $eventArgs = null)
+ {
+ $eventClass = 'Phergie_Event_Request';
+ if (is_array($event)) {
+ $eventClass = $event[0];
+ $eventType = $event[1];
+ } else {
+ throw new InvalidArgumentException("Invalid value for \$event");
+ }
+ $event = new $eventClass();
+ $event->setType($eventType);
+ $event->setArguments($eventArgs);
+ $this->plugin->setEvent($event);
+ $this->eventArgs = $eventArgs;
+ }
+
+ /**
+ * Sets the plugin to be tested
+ * If a plugin requries config for testing, an array placed in
+ * $this->config will be parsed into a Phergie_Config object and
+ * attached to the plugin
+ */
+ protected function setPlugin(Phergie_Plugin_Abstract $plugin)
+ {
+ $this->plugin = $plugin;
+ $this->plugin->setEventHandler($this->handler);
+ $this->plugin->setConnection($this->connection);
+ $this->connection->setNick('test');
+ if (!empty($this->config)) {
+ $config = new Phergie_Config();
+ foreach ($this->config as $configKey => $configValue) {
+ $config[$configKey] = $configValue;
+ }
+ $plugin->setConfig($config);
+ }
+ }
+
+ /**
+ * Overrides the runTest method to add additional annotations
+ * @return PHPUnit_Framework_TestResult
+ */
+ protected function runTest()
+ {
+ if (null === $this->plugin) {
+ throw new RuntimeException(
+ 'Tests cannot be run before plugin is set'
+ );
+ }
+
+ // Clean the event handler... important!
+ $this->handler->clearEvents();
+
+ $info = $this->getAnnotations();
+ $event = null;
+ $eventArgs = array();
+ if (isset($info['method']['event']) && isset($info['method']['event'][0])) {
+ if (!is_string($info['method']['event'][0])) {
+ throw new InvalidArgumentException(
+ 'Only one event may be specified'
+ );
+ }
+ $event = $info['method']['event'][0];
+
+ if (stristr($event, '::')) {
+ $event = explode('::', $event);
+ }
+ }
+ if (isset($info['method']['eventArg'])) {
+ $eventArgs = $info['method']['eventArg'];
+ }
+ if (null !== $event) {
+ $this->setEvent($event, $eventArgs);
+ }
+
+ $testResult = parent::runTest();
+
+ // Clean the event handler again... just incase this time.
+ $this->handler->clearEvents();
+
+ return $testResult;
+ }
+
+}
diff --git a/plugins/Irc/extlib/phergie/Tests/Phergie/Plugin/TestNonInstantiablePluginFromFile.php b/plugins/Irc/extlib/phergie/Tests/Phergie/Plugin/TestNonInstantiablePluginFromFile.php
new file mode 100755
index 000000000..f9bddd151
--- /dev/null
+++ b/plugins/Irc/extlib/phergie/Tests/Phergie/Plugin/TestNonInstantiablePluginFromFile.php
@@ -0,0 +1,43 @@
+<?php
+/**
+ * Phergie
+ *
+ * PHP version 5
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.
+ * It is also available through the world-wide-web at this URL:
+ * http://phergie.org/license
+ *
+ * @category Phergie
+ * @package Phergie_Tests
+ * @author Phergie Development Team <team@phergie.org>
+ * @copyright 2008-2010 Phergie Development Team (http://phergie.org)
+ * @license http://phergie.org/license New BSD License
+ * @link http://pear.phergie.org/package/Phergie_Tests
+ */
+
+/**
+ * Creates a plugin on the filesystem that can be used by
+ * Phergie_Plugin_Handler's addPath utility to be located and loaded.
+ *
+ * @category Phergie
+ * @package Phergie_Tests
+ * @author Phergie Development Team <team@phergie.org>
+ * @license http://phergie.org/license New BSD License
+ * @link http://pear.phergie.org/package/Phergie_Tests
+ */
+class Phergie_Plugin_TestNonInstantiablePluginFromFile
+extends Phergie_Plugin_Abstract
+{
+ /**
+ * Private constructor to ensure that this class is not instantiable.
+ *
+ * @return void
+ */
+ private function __construct()
+ {
+ }
+}
diff --git a/plugins/Irc/extlib/phergie/Tests/TestHelper.php b/plugins/Irc/extlib/phergie/Tests/TestHelper.php
new file mode 100644
index 000000000..6593539bc
--- /dev/null
+++ b/plugins/Irc/extlib/phergie/Tests/TestHelper.php
@@ -0,0 +1,26 @@
+<?php
+/**
+ * Phergie
+ *
+ * PHP version 5
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.
+ * It is also available through the world-wide-web at this URL:
+ * http://phergie.org/license
+ *
+ * @category Phergie
+ * @package Phergie_Tests
+ * @author Phergie Development Team <team@phergie.org>
+ * @copyright 2008-2010 Phergie Development Team (http://phergie.org)
+ * @license http://phergie.org/license New BSD License
+ * @link http://pear.phergie.org/package/Phergie_Tests
+ */
+
+error_reporting(E_ALL | E_STRICT);
+
+// Phergie components require Phergie_Autoload to function correctly.
+require_once dirname(__FILE__) . '/../Phergie/Autoload.php';
+Phergie_Autoload::registerAutoloader();
diff --git a/plugins/Irc/extlib/phergie/Tests/phpunit.xml b/plugins/Irc/extlib/phergie/Tests/phpunit.xml
new file mode 100644
index 000000000..b96589e4a
--- /dev/null
+++ b/plugins/Irc/extlib/phergie/Tests/phpunit.xml
@@ -0,0 +1,26 @@
+<!--
+/**
+ * Phergie
+ *
+ * PHP version 5
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.
+ * It is also available through the world-wide-web at this URL:
+ * http://phergie.org/license
+ *
+ * @category Phergie
+ * @package Phergie_Tests
+ * @author Phergie Development Team <team@phergie.org>
+ * @copyright 2008-2010 Phergie Development Team (http://phergie.org)
+ * @license http://phergie.org/license New BSD License
+ * @link http://pear.phergie.org/package/Phergie_Tests
+ */
+-->
+<phpunit colors="true" bootstrap="./TestHelper.php">
+ <testsuite name="Phergie Test Suite">
+ <directory>./</directory>
+ </testsuite>
+</phpunit>