plugins = new Plugins(); $this->plugins->addPluginPath('test'.DS.'plugins'); $this->plugins->loadHeadersFromPluginPaths(); } public function testGetPluginsClass() { $this->assertInstanceOf('FuzeWorks\Plugins', $this->plugins); } /** * @depends testGetPluginsClass */ public function testLoadPlugin() { $this->assertInstanceOf('\Application\Plugin\TestLoadPlugin', $this->plugins->get('testLoadPlugin')); } /** * @depends testLoadPlugin */ public function testReloadPlugin() { $this->assertSame($this->plugins->get('testReloadPlugin'), $this->plugins->get('testReloadPlugin')); } /** * @depends testLoadPlugin */ public function testLoadHeader() { // Load the header object require_once('test' . DS . 'plugins' . DS . 'testLoadHeader'.DS.'loadHeader'.DS.'header.php'); $header = new Plugins\TestLoadHeaderHeader(); // Register the header object $this->plugins->addPlugin($header); // Assert the plugin $this->assertInstanceOf('Application\Plugin\Plug', $this->plugins->get('Plug')); } /** * @depends testLoadPlugin * @expectedException FuzeWorks\Exception\PluginException */ public function testMissingHeader() { $this->plugins->get('testMissingHeader'); } /** * @depends testLoadPlugin */ public function testGetPluginMethod() { $this->assertEquals('test_string', $this->plugins->get('testGetPluginMethod')); } /** * @depends testLoadPlugin */ public function testGetPluginWithClassFile() { $this->assertInstanceOf('OtherPlug', $this->plugins->get('TestGetPluginWithClassFile')); } /** * @depends testLoadPlugin * @expectedException FuzeWorks\Exception\PluginException */ public function testMissingPlugin() { $this->plugins->get('testMissingPlugin'); } /** * @depends testMissingPlugin * @expectedException FuzeWorks\Exception\PluginException */ public function testLoadHeaderNotIPluginHeader() { // Attempt to load all headers $this->plugins->loadHeadersFromPluginPaths(); $this->plugins->get('TestLoadHeaderNotIPluginHeader'); } /** * @depends testLoadPlugin * @expectedException FuzeWorks\Exception\PluginException */ public function testInvalidClass() { $this->plugins->get('testInvalidClass'); } /** * @expectedException FuzeWorks\Exception\PluginException */ public function testGetMissingName() { $this->plugins->get(''); } /** * @depends testLoadPlugin * @expectedException FuzeWorks\Exception\PluginException */ public function testDisabledPlugin() { Factory::getInstance()->config->plugins->disabled_plugins = array('TestDisabledPlugin'); $this->plugins->loadHeadersFromPluginPaths(); $this->plugins->get('testDisabledPlugin'); } /** * @depends testLoadPlugin * @expectedException FuzeWorks\Exception\PluginException */ public function testRunInvalidDirectory() { $this->plugins->addPluginPath('exists_not'); $this->plugins->loadHeadersFromPluginPaths(); $this->plugins->get('testRunInvalidDirectory'); } public function testAddPluginPath() { // Add the pluginPath $this->plugins->addPluginPath('test'.DS.'plugins'.DS.'testAddPluginPath'); // And try to load it again $this->plugins->loadHeadersFromPluginPaths(); $this->assertInstanceOf('Application\Plugin\ActualPlugin', $this->plugins->get('ActualPlugin')); } /** * @depends testAddPluginPath */ public function testRemovePluginPath() { // Test if the path does NOT exist $this->assertFalse(in_array('test'.DS.'plugins'.DS.'testRemovePluginPath', $this->plugins->getPluginPaths())); // Add it $this->plugins->addPluginPath('test'.DS.'plugins'.DS.'testRemovePluginPath'); // Assert if it's there $this->assertTrue(in_array('test'.DS.'plugins'.DS.'testRemovePluginPath', $this->plugins->getPluginPaths())); // Remove it $this->plugins->removePluginPath('test'.DS.'plugins'.DS.'testRemovePluginPath'); // And test if it's gone again $this->assertFalse(in_array('test'.DS.'plugins'.DS.'testRemovePluginPath', $this->plugins->getPluginPaths())); } public function testSetDirectories() { // Add the directory $appDir = Core::$appDirs[0]; $directory = 'test' . DS . 'helpers'; $expected = [$appDir, 'test'.DS.'plugins', $directory]; $this->plugins->setDirectories([$directory]); $this->assertEquals($expected, $this->plugins->getPluginPaths()); } public function tearDown() { $factory = Factory::getInstance(); $factory->config->plugins->revert(); } }