function test_checkFiles()
 {
     $aFiles[] = array('path' => OX_PLUGIN_ADMINPATH . '/templates/', 'name' => 'testPlugin.html');
     $aFiles[] = array('path' => OX_PLUGIN_ADMINPATH . '/images/', 'name' => 'testPlugin2.jpg');
     $aFiles[] = array('path' => OX_PLUGIN_ADMINPATH . '/', 'name' => 'testPlugin-index.php');
     $aFiles[] = array('path' => OX_PLUGIN_PLUGINPATH, 'name' => 'testPluginPackage.readme.txt');
     $aFiles[] = array('path' => OX_PLUGIN_GROUPPATH . '/', 'name' => 'processPreferences.php');
     $aFiles[] = array('path' => OX_PLUGIN_GROUPPATH . '/etc/', 'name' => 'tables_testplugin.xml');
     $aFiles[] = array('path' => OX_PLUGIN_GROUPPATH . '/etc/DataObjects/', 'name' => 'Testplugin_table.php');
     $name = 'testPlugin';
     $oManager = new OX_Plugin_ComponentGroupManager();
     $this->assertFalse($oManager->_checkFiles($name, $aFiles));
     $oManager->aErrors = array();
     $oManager->pathPackages = $this->testpathPackages;
     $oManager->pathPluginsAdmin = $this->testpathPluginsAdmin;
     $this->assertTrue($oManager->_checkFiles($name, $aFiles));
     if ($oManager->countErrors()) {
         foreach ($oManager->aErrors as $msg) {
             $this->assertTrue(false, $msg);
         }
     }
 }
 function test_removeFiles()
 {
     $name = 'testPlugin';
     $varPath = '/var/tmp';
     if (!file_exists(MAX_PATH . $varPath)) {
         mkdir(MAX_PATH . $varPath);
     }
     // set up some package folders and files
     $aConf = $GLOBALS['_MAX']['CONF']['pluginPaths'];
     $aPathPlugins = explode('/', $aConf['plugins']);
     $varPathPlugins = $varPath;
     foreach ($aPathPlugins as $sub) {
         if (trim($sub)) {
             $varPathPlugins .= '/' . $sub;
             if (!file_exists(MAX_PATH . $varPathPlugins)) {
                 mkdir(MAX_PATH . $varPathPlugins);
             }
         }
     }
     $varPathPlugins .= '/';
     $aPathPackages = explode('/', $aConf['packages']);
     $varPathPackages = $varPath;
     foreach ($aPathPackages as $sub) {
         if (trim($sub)) {
             $varPathPackages .= '/' . $sub;
             if (!file_exists(MAX_PATH . $varPathPackages)) {
                 mkdir(MAX_PATH . $varPathPackages);
             }
         }
     }
     $varPathPackages .= '/';
     if (!file_exists(MAX_PATH . $varPathPackages . $name)) {
         mkdir(MAX_PATH . $varPathPackages . $name);
         mkdir(MAX_PATH . $varPathPackages . $name . '/etc');
     }
     $file = 'testPluginPackage.xml';
     copy(MAX_PATH . $this->testpathPackages . $file, MAX_PATH . $varPathPackages . $file);
     $this->assertTrue(file_exists(MAX_PATH . $varPathPackages . $file), 'not found ' . $file);
     $file = $name . '/testPlugin.xml';
     copy(MAX_PATH . $this->testpathPackages . $file, MAX_PATH . $varPathPackages . $file);
     $this->assertTrue(file_exists(MAX_PATH . $varPathPackages . $file), 'not found ' . $file);
     $file = $name . '/processPreferences.php';
     copy(MAX_PATH . $this->testpathPackages . $file, MAX_PATH . $varPathPackages . $file);
     $this->assertTrue(file_exists(MAX_PATH . $varPathPackages . $file), 'not found ' . $file);
     $file = 'testPluginPackage.readme.txt';
     copy(MAX_PATH . $this->testpathPackages . $file, MAX_PATH . $varPathPackages . $file);
     $this->assertTrue(file_exists(MAX_PATH . $varPathPackages . $file), 'not found ' . $file);
     $file = $name . '/etc/tables_testplugin.xml';
     copy(MAX_PATH . $this->testpathPackages . $file, MAX_PATH . $varPathPackages . $file);
     $this->assertTrue(file_exists(MAX_PATH . $varPathPackages . $file), 'not found ' . $file);
     // set up some admin folders and files
     $aPathAdmin = explode('/', $aConf['admin']);
     $varPathAdmin = $varPath;
     foreach ($aPathAdmin as $sub) {
         if (trim($sub)) {
             $varPathAdmin .= '/' . $sub;
             if (!file_exists(MAX_PATH . $varPathAdmin)) {
                 mkdir(MAX_PATH . $varPathAdmin);
             }
         }
     }
     $varPathAdmin .= '/';
     if (!file_exists(MAX_PATH . $varPathAdmin . $name)) {
         mkdir(MAX_PATH . $varPathAdmin . $name);
         mkdir(MAX_PATH . $varPathAdmin . $name . '/templates');
     }
     $file = $name . '/testPlugin-index.php';
     copy(MAX_PATH . $this->testpathPluginsAdmin . $file, MAX_PATH . $varPathAdmin . $file);
     $this->assertTrue(file_exists(MAX_PATH . $varPathAdmin . $file), 'not found ' . $file);
     $file = $name . '/templates/testPlugin.html';
     copy(MAX_PATH . $this->testpathPluginsAdmin . $file, MAX_PATH . $varPathAdmin . $file);
     $this->assertTrue(file_exists(MAX_PATH . $varPathAdmin . $file), 'not found ' . $file);
     // finally finished setting up the test data!
     $oPluginManager = new OX_Plugin_ComponentGroupManager();
     $oPluginManager->pathPackages = $varPathPackages;
     $oPluginManager->pathPluginsAdmin = $varPathAdmin;
     // check the package file
     $oPluginManager->aErrors = array();
     $aPkgFiles[] = array('path' => OX_PLUGIN_PLUGINPATH . '/', 'name' => 'testPluginPackage.xml');
     $this->assertTrue($oPluginManager->_checkFiles('', $aPkgFiles));
     if ($oPluginManager->countErrors()) {
         foreach ($oPluginManager->aErrors as $msg) {
             $this->assertTrue(false, $msg);
         }
     }
     // assuming its all ok, remove the package file (send in no name)
     // usually used for package readme files
     $oPluginManager->aErrors = array();
     //$this->assertTrue($oPluginManager->_removeFiles('', array('files'=>$aPkgFiles)));
     $this->assertTrue($oPluginManager->_removeFiles('', $aPkgFiles));
     if ($oPluginManager->countErrors()) {
         foreach ($oPluginManager->aErrors as $msg) {
             $this->assertTrue(false, $msg);
         }
     }
     // check again, this time it should be gone
     $oPluginManager->aErrors = array();
     $this->assertFalse($oPluginManager->_checkFiles('', $aPkgFiles));
     $this->assertEqual($oPluginManager->countErrors(), 1);
     // check plugin files
     $oPluginManager->aErrors = array();
     $aFiles = array();
     $aFiles[] = array('path' => OX_PLUGIN_ADMINPATH . '/templates/', 'name' => 'testPlugin.html');
     $aFiles[] = array('path' => OX_PLUGIN_ADMINPATH . '/', 'name' => 'testPlugin-index.php');
     $aFiles[] = array('path' => OX_PLUGIN_GROUPPATH . '/etc/', 'name' => 'tables_testplugin.xml');
     $aFiles[] = array('path' => OX_PLUGIN_GROUPPATH . '/', 'name' => 'testPlugin.xml');
     $aFiles[] = array('path' => OX_PLUGIN_GROUPPATH . '/', 'name' => 'processPreferences.php');
     $aFiles[] = array('path' => OX_PLUGIN_GROUPPATH . '/etc/', 'name' => 'tables_testplugin.xml');
     $aFiles[] = array('path' => OX_PLUGIN_PLUGINPATH . '/', 'name' => 'testPluginPackage.readme.txt');
     $this->assertTrue($oPluginManager->_checkFiles($name, $aFiles));
     if ($oPluginManager->countErrors()) {
         foreach ($oPluginManager->aErrors as $msg) {
             $this->assertTrue(false, $msg);
         }
     }
     // remove the plugin files
     $oPluginManager->aErrors = array();
     //$this->assertTrue($oPluginManager->_removeFiles($name, array('files'=>$aFiles)));
     $this->assertTrue($oPluginManager->_removeFiles($name, $aFiles));
     if ($oPluginManager->countErrors()) {
         foreach ($oPluginManager->aErrors as $msg) {
             $this->assertTrue(false, $msg);
         }
     }
     // check again, this time they should be gone
     $oPluginManager->aErrors = array();
     $this->assertFalse($oPluginManager->_checkFiles($name, $aFiles));
     $this->assertEqual($oPluginManager->countErrors(), 1);
     // _removeFiles will also remove the specific plugin folders if it is empty
     $this->assertFalse(file_exists(MAX_PATH . $varPathPackages . $name . '/etc'));
     $this->assertFalse(file_exists(MAX_PATH . $varPathPackages . $name));
     $this->assertFalse(file_exists(MAX_PATH . $varPathAdmin . $name . '/templates'));
     $this->assertFalse(file_exists(MAX_PATH . $varPathAdmin . $name));
     // not the top level ones though
     $this->assertTrue(file_exists(MAX_PATH . $varPathPackages));
     $this->assertTrue(file_exists(MAX_PATH . $varPathAdmin));
     @rmdir(MAX_PATH . $varPathPackages);
     @rmdir(MAX_PATH . $varPathAdmin);
     @rmdir(MAX_PATH . $varPath . 'www/admin');
     @rmdir(MAX_PATH . $varPath . 'www');
     @rmdir(MAX_PATH . $varPath . 'plugins');
     @rmdir(MAX_PATH . $varPath);
 }