/** * A method for returning an array of the available geotargeting modes. * * @return array An array of strings representing the available geotargeting modes. */ function AvailableGeotargetingModes() { Language_Loader::load('default'); $plugins =& MAX_Plugin::getPlugins('geotargeting'); $modes['none'] = $GLOBALS['strNone']; $pluginModes = MAX_Plugin::callOnPlugins($plugins, 'getModuleInfo'); foreach ($pluginModes as $key => $pluginMode) { $modes[$key] = $pluginMode; } return $modes; }
/** * A method to test the callOnPlugins() method. * * @TODO Deal with class name case changes. */ function testCallOnPlugins() { // 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 with a non-array parameter for the plugins $aPlugins = 'bar'; $result = MAX_Plugin::callOnPlugins($aPlugins, 'foo'); $this->assertEqual(count($oTestErrorHandler->aErrors), 1); $this->assertEqual($oTestErrorHandler->aErrors[0]->message, 'Bad argument: Not an array of plugins.'); $this->assertFalse($result); $oTestErrorHandler->reset(); // Test with an array of non-plugins $aPlugins = array('bar'); $result = MAX_Plugin::callOnPlugins($aPlugins, 'foo'); $this->assertEqual(count($oTestErrorHandler->aErrors), 1); $this->assertEqual($oTestErrorHandler->aErrors[0]->message, 'Bad argument: Not an array of plugins.'); $this->assertFalse($result); $oTestErrorHandler->reset(); // Prepare an array of plugins $aPlugins = MAX_Plugin::getPlugins('reports', 'standard', true, 0); // Test with a bad method $result = MAX_Plugin::callOnPlugins($aPlugins, 'foo'); $this->assertEqual(count($oTestErrorHandler->aErrors), 1); $this->assertEqual($oTestErrorHandler->aErrors[0]->message, "Method 'foo()' not defined in class 'Plugins_Reports_Standard_AdvertisingAnalysisReport'."); $this->assertFalse($result); $oTestErrorHandler->reset(); // Unset the error handler PEAR::popErrorHandling(); // Test with a real method, no parameters $result = MAX_Plugin::callOnPlugins($aPlugins, 'getDefaults'); foreach ($aPlugins as $key => $oPlugin) { if (is_a($oPlugin, 'Plugins_Reports_Standard_LiveCampaignDeliveryReport')) { $this->assertTrue(is_array($result[$key])); $this->assertEqual(count($result[$key]), 2); } else { $this->assertTrue(is_array($result[$key])); $this->assertEqual(count($result[$key]), 3); } } // Test with a real method, with parameters $result = MAX_Plugin::callOnPlugins($aPlugins, 'useReportWriter', array('foo')); foreach ($aPlugins as $key => $oPlugin) { $this->assertNull($result[$key]); } }