Пример #1
0
 /**
  * A method to include a plugin, and call a method statically on the plugin class.
  *
  * @static
  * @param string $module The plugin module name (i.e. /plugins/module directory).
  * @param string $package The plugin package name (i.e. /plugins/module/package
  *                        directory).
  * @param string $name Optional name of the PHP file which contains the plugin,
  *                     otherwise the plugin with the same name as the package
  *                     is assumed.
  * @param string $staticMethod The name of the method of the plugin to call statically.
  * @param array $aParams An optional array of parameters to pass to the method called.
  * @return mixed The result of the static method call, or false on failure to include
  *               the plugin.
  */
 function &callStaticMethod($module, $package, $name = null, $staticMethod, $aParams = null)
 {
     if ($name === null) {
         $name = $package;
     }
     if (!MAX_Plugin::_isEnabledPlugin($module, $package, $name)) {
         return false;
     }
     if (!MAX_Plugin::_includePluginFile($module, $package, $name)) {
         return false;
     }
     $className = MAX_Plugin::_getPluginClassName($module, $package, $name);
     // PHP4/5 compatibility for get_class_methods.
     $aClassMethods = array_map(strtolower, get_class_methods($className));
     if (!$aClassMethods) {
         $aClassMethods = array();
     }
     if (!in_array(strtolower($staticMethod), $aClassMethods)) {
         MAX::raiseError("Method '{$staticMethod}()' not defined in class '{$className}'.", MAX_ERROR_INVALIDARGS);
         return false;
     }
     if (is_null($aParams)) {
         return call_user_func(array($className, $staticMethod));
     } else {
         return call_user_func_array(array($className, $staticMethod), $aParams);
     }
 }
 /**
  * A method to test the _includePluginFile() method.
  */
 function test_includePluginFile()
 {
     // Set the error handling class' handleErrors() method as
     // the error handler for PHP for this test.
     $oTestErrorHandler = new TestErrorHandler();
     PEAR::pushErrorHandling(PEAR_ERROR_CALLBACK, array(&$oTestErrorHandler, 'handleErrors'));
     // Test basic case where plugin file does not exist
     $result = MAX_Plugin::_includePluginFile('foo', 'bar');
     $this->assertEqual(count($oTestErrorHandler->aErrors), 1);
     $this->assertEqual($oTestErrorHandler->aErrors[0]->message, 'Unable to include the file ' . MAX_PATH . '/plugins/foo/bar/bar' . MAX_PLUGINS_EXTENSION . '.');
     $this->assertFalse($result);
     $oTestErrorHandler->reset();
     // Test plugin name case where plugin file does not exist
     $result = MAX_Plugin::_includePluginFile('foo', 'bar', 'baz');
     $this->assertEqual(count($oTestErrorHandler->aErrors), 1);
     $this->assertEqual($oTestErrorHandler->aErrors[0]->message, 'Unable to include the file ' . MAX_PATH . '/plugins/foo/bar/baz' . MAX_PLUGINS_EXTENSION . '.');
     $this->assertFalse($result);
     $oTestErrorHandler->reset();
     /**
      * @TODO Write a test for testing where the plugin file exists, but the plugin
      * file name is "wrong". This will probably require that the MAX_Plugin class
      * be changed from a static class to a normal class, so that the
      * _getPluginClassName() method can be mocked to return an invalid class name.
      */
     // Test correct inclusion of a plugin
     $result = MAX_Plugin::_includePluginFile('reports', 'standard', 'advertisingAnalysisReport');
     $this->assertEqual(count($oTestErrorHandler->aErrors), 0);
     $this->assertTrue($result);
     $oTestErrorHandler->reset();
     // Unset the error handler
     PEAR::popErrorHandling();
 }