function testInstallPlugin() { $GLOBALS['sys_pluginsroot'] = dirname(__FILE__) . '/test/custom/'; $GLOBALS['sys_custompluginsroot'] = dirname(__FILE__) . '/test/custom/'; $GLOBALS['sys_pluginsroot'] = dirname(__FILE__) . '/test/custom/'; mkdir(dirname(__FILE__) . '/test'); mkdir(dirname(__FILE__) . '/test/custom'); //The plugins $plugin = new MockPlugin($this); //The plugin factory $plugin_factory = new MockPluginFactory($this); $plugin_factory->expectOnce('createPlugin', array('New_Plugin')); $plugin_factory->setReturnReference('createPlugin', $plugin); stub($plugin_factory)->getAllPossiblePluginsDir()->returns(array(dirname(__FILE__) . '/test')); $forgeupgrade_config = mock('ForgeUpgradeConfig'); expect($forgeupgrade_config)->addPath($GLOBALS['sys_pluginsroot'] . 'New_Plugin')->once(); expect($forgeupgrade_config)->recordOnlyPath($GLOBALS['sys_pluginsroot'] . 'New_Plugin')->once(); //The plugins manager $pm = new PluginManager($plugin_factory, mock('EventManager'), mock('SiteCache'), $forgeupgrade_config); $this->assertReference($pm->installPlugin('New_Plugin'), $plugin); // plugin manager must call postInstall 1 time on plugin after its creation $plugin->expectCallCount('postInstall', 1); // Plugin dir was created in "/etc" $this->assertTrue(is_dir(dirname(__FILE__) . '/test/custom/New_Plugin')); $this->_remove_directory(dirname(__FILE__) . '/test'); }
function testInstallPlugin() { $GLOBALS['sys_pluginsroot'] = dirname(__FILE__) . '/test/custom/'; $GLOBALS['sys_custompluginsroot'] = dirname(__FILE__) . '/test/custom/'; $GLOBALS['sys_pluginsroot'] = dirname(__FILE__) . '/test/custom/'; $GLOBALS['forgeupgrade_file'] = dirname(__FILE__) . '/test/forgeupgrade.ini'; mkdir(dirname(__FILE__) . '/test'); mkdir(dirname(__FILE__) . '/test/custom'); touch($GLOBALS['forgeupgrade_file']); //The plugins $plugin = new MockPlugin($this); //The plugin factory $plugin_factory = new MockPluginFactory($this); $plugin_factory->expectOnce('createPlugin', array('New_Plugin')); $plugin_factory->setReturnReference('createPlugin', $plugin); //The plugins manager $pm = new PluginManagerTestVersion($this); $pm->setReturnReference('_getPluginFactory', $plugin_factory); $fuc = new ForgeUpgradeConfigTestPluginManager($this); $fuc->expectOnce('run'); $fuc->setReturnValue('run', true); $pm->setReturnValue('_getForgeUpgradeConfig', $fuc); $this->assertReference($pm->installPlugin('New_Plugin'), $plugin); // plugin manager must call postInstall 1 time on plugin after its creation $plugin->expectCallCount('postInstall', 1); // Plugin dir was created in "/etc" $this->assertTrue(is_dir(dirname(__FILE__) . '/test/custom/New_Plugin')); // Forgeupgrade config updated // do not use parse_ini_file to be independent of implementation $wantedLine = dirname(__FILE__) . '/test/custom/New_Plugin'; $lineFound = false; $conf = file($GLOBALS['forgeupgrade_file'], FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); foreach ($conf as $line) { if (preg_match('%path\\[\\]\\s*=\\s*"' . $wantedLine . '"%', $line)) { $lineFound = true; } } $this->assertTrue($lineFound, "Forgeupgrade configuration file must contains {$wantedLine}"); $this->_remove_directory(dirname(__FILE__) . '/test'); }