X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=plugins%2FIrc%2Fextlib%2Fphergie%2FTests%2FPhergie%2FPlugin%2FHandlerTest.php;h=98c70dfceeae881439fcd5137e6a699faa845b6e;hb=HEAD;hp=dcf52a65a1bb9d44d042df752fb8f17dee30dbfb;hpb=bee50840728ca8af99e988bcce71876849ba61d3;p=quix0rs-gnu-social.git diff --git a/plugins/Irc/extlib/phergie/Tests/Phergie/Plugin/HandlerTest.php b/plugins/Irc/extlib/phergie/Tests/Phergie/Plugin/HandlerTest.php index dcf52a65a1..98c70dfcee 100644 --- a/plugins/Irc/extlib/phergie/Tests/Phergie/Plugin/HandlerTest.php +++ b/plugins/Irc/extlib/phergie/Tests/Phergie/Plugin/HandlerTest.php @@ -108,6 +108,77 @@ class Phergie_Plugin_HandlerTest extends PHPUnit_Framework_TestCase ); } + /** + * Tests that a default iterator is returned if none is explicitly set. + * + * @return void + */ + public function testGetIteratorReturnsDefault() + { + $this->assertType( + 'Phergie_Plugin_Iterator', + $this->handler->getIterator() + ); + } + + /** + * Tests the ability to change the handler's iterator class when a valid + * class is specified. + * + * @return void + */ + public function testSetIteratorClassWithValidClass() + { + eval(' + class DummyIterator extends FilterIterator { + public function accept() { + return true; + } + } + '); + + $this->handler->setIteratorClass('DummyIterator'); + + $this->assertType( + 'DummyIterator', + $this->handler->getIterator() + ); + } + + /** + * Tests that a failure occurs when a nonexistent iterator class is + * specified. + * + * @return void + */ + public function testSetIteratorClassWithNonexistentClass() + { + try { + $this->handler->setIteratorClass('FooIterator'); + $this->fail('Expected exception was not thrown'); + } catch (Phergie_Plugin_Exception $e) { + return; + } + $this->fail('Unexpected exception was thrown'); + } + + /** + * Tests that a failure occurs when a class that is not a subclass of + * FilterIterator is specified. + * + * @return void + */ + public function testSetIteratorClassWithNonFilterIteratorClass() + { + try { + $this->handler->setIteratorClass('ArrayIterator'); + $this->fail('Expected exception was not thrown'); + } catch (Phergie_Plugin_Exception $e) { + return; + } + $this->fail('Unexpected exception was thrown'); + } + /** * Tests countability of the plugin handler. * @@ -422,7 +493,7 @@ class Phergie_Plugin_HandlerTest extends PHPUnit_Framework_TestCase */ public function testAddPluginThrowsExceptionWhenPluginClassNotFound() { - $path = sys_get_temp_dir() . '/Phergie/Plugin'; + $path = common_get_temp_dir() . '/Phergie/Plugin'; $this->removeDirectory(dirname($path)); mkdir($path, 0777, true); touch($path . '/TestPlugin.php'); @@ -714,23 +785,53 @@ class Phergie_Plugin_HandlerTest extends PHPUnit_Framework_TestCase } /** - * Tests the plugin receiving and using a predefined iterator instance. + * Tests that multiple plugin iterators can be used concurrently. * - * @depends testGetPlugins * @return void */ - public function testSetIterator() + public function testUseMultiplePluginIteratorsConcurrently() { - $plugin = $this->getMockPlugin('TestPlugin'); - $this->handler->addPlugin($plugin); - $plugins = $this->handler->getPlugins(); - $iterator = new ArrayIterator($plugins); - $this->handler->setIterator($iterator); - $this->assertSame($this->handler->getIterator(), $iterator); - $iterated = array(); - foreach ($this->handler as $plugin) { - $iterated[strtolower($plugin->getName())] = $plugin; - } - $this->assertEquals($iterated, $plugins); + $plugin1 = $this->getMockPlugin('TestPlugin1'); + $this->handler->addPlugin($plugin1); + + $plugin2 = $this->getMockPlugin('TestPlugin2'); + $this->handler->addPlugin($plugin2); + + $iterator1 = $this->handler->getIterator(); + $iterator1->next(); + $this->assertSame($plugin2, $iterator1->current()); + + $iterator2 = $this->handler->getIterator(); + $this->assertSame($plugin1, $iterator2->current()); + } + + /** + * Tests adding plugin paths via configuration. + * + * @return void + */ + public function testAddPluginPathsViaConfiguration() + { + $dir = dirname(__FILE__); + $prefix = 'Phergie_Plugin_'; + $paths = array($dir => $prefix); + $this->config + ->expects($this->any()) + ->method('offsetExists') + ->will($this->returnValue(true)); + $this->config + ->expects($this->any()) + ->method('offsetGet') + ->will($this->returnValue($paths)); + + // Reinitialize the handler so the configuration change takes effect + // within the constructor + $this->handler = new Phergie_Plugin_Handler( + $this->config, + $this->events + ); + + $this->handler->setAutoload(true); + $this->handler->getPlugin('Mock'); } }