Пример #1
0
 function render($blockContent = NULL)
 {
     if ($this->hidden) {
         return NULL;
     }
     // create an invocation, execute it, and return the HTML.
     $wfi = new WFModuleInvocation($this->invocationPath, $this->page()->module()->invocation());
     $wfi->setTargetRootModule($this->targetRootModule);
     return $wfi->execute();
 }
 /**
  * A Helper function that will execute an invocation path and store the resulting module locally for execution of asserts.
  *
  * NOTE: Use the $moduleVars to "stuff" a DB connection so your controller runs in the same DB tx as the test.
  *
  * @param string Invocation Path
  * @param array An array of data to "stuff" into the WFModule instance.
  */
 public function executeInvocationPath($invocationPath = NULL, $moduleVars = array())
 {
     // set up
     $invocationPath = $invocationPath ? $invocationPath : $this->invocationPath;
     $moduleData = array_merge($this->moduleData, $moduleVars);
     if ($this->formId && count($this->formData)) {
         // render the "requestPage" so we can pull out
         // setup invocation
         $formInvocation = new WFModuleInvocation($invocationPath, $this->invocationParentInvocation, $this->invocationSkinDelegate);
         $formModule = $formInvocation->module();
         // inject data
         $formModule->setValuesForKeys($moduleData);
         $formInvocation->execute();
         // stuff appropriate data into our page under test
         $requestPage = $formModule->requestPage();
         $form = $requestPage->outlet($this->formId);
         $formSubmitButtonId = $this->formSubmitButton ? $this->formSubmitButton : $form->defaultSubmitID();
         if (!$formSubmitButtonId) {
             throw new Exception("No form submit id was specified, and the form doesn't have a defaultSubmitID configured.");
         }
         $formSubmitButton = $requestPage->outlet($formSubmitButtonId);
         $submitAction = $formSubmitButton->submitAction();
         $rpc = $submitAction->rpc();
         $this->formData = array_merge($this->formData, $form->phocoaFormParameters());
         $_REQUEST = array_merge($_REQUEST, $this->formData);
     }
     // set up invocation to test
     $this->invocation = new WFModuleInvocation($invocationPath, $this->invocationParentInvocation, $this->invocationSkinDelegate);
     $this->module = $this->invocation->module();
     // inject data
     $this->module->setValuesForKeys($moduleData);
     // form -- automatic from $_REQUEST
     // request -- automatic from $_REQUEST
     // execute
     try {
         $this->pageOutput = $this->invocation->execute();
     } catch (Exception $e) {
         if ($this->expectException and $e instanceof $this->expectException) {
             $this->assertEquals($this->expectExceptionUrl, $e->getRedirectURL(), "Unexpected url for exception of type {$this->expectException}.");
         } else {
             throw $e;
         }
     }
     return $this;
 }
/**
 *  Smarty plugin to allow inclusion of WFModule invocations from the skin.
 *
 *  Smarty Params:
 *  invocationPath - The invocationPath for the module. See {@link WFModuleInvocation}. Required.
 *  targetRootModule - If you want to customize the value of {@link WFModuleInvocation::$targetRootModule}, specify it in the param.
 *                     BOOLEAN, but remember that in smarty targetRootModule="false" passing the STRING false, so do targetRootModule=false
 *  respondsToForms - Controls whether or not the instance of the module will "respond" to form submissions. Default: FALSE. This is useful when using WFSkinModuleView to embed functions like login or search into skins.
 *
 *  IMPORTANT!!!! WFSkinModuleView is intended for use only from skin template files. Results if used from a WFModule/Page are UNPREDICTABLE -- basically some functions will mistake the "root" module for the root of the skin rather than the root of the current WFModuleInvocation hierarchy when programmiatcally invoking WFModuleInvocations.
 *
 *  @param array The params from smarty tag
 *  @param object WFSmarty object of the current tpl
 *  @return string The HTML snippet from the WFModule.
 *  @throws Exception if the module cannot be found or no invocationPath is specified.
 */
function smarty_function_WFSkinModuleView($params, $smarty)
{
    if (empty($params['invocationPath'])) {
        throw new Exception("InvocationPath is required.");
    }
    $respondsToForms = isset($params['respondsToForms']) ? $params['respondsToForms'] : false;
    $rc = WFRequestController::sharedRequestController();
    // if there is no root invocation, then something bad has happened (probably an exception has been thrown during the main WFModuleInvocation setup), so just bail on any sub-modules.
    $rootInv = $rc->rootModuleInvocation();
    if (!$rootInv) {
        return NULL;
    }
    $modInvocation = new WFModuleInvocation($params['invocationPath'], $rootInv);
    $modInvocation->setRespondsToForms($respondsToForms);
    if (isset($params['targetRootModule'])) {
        $modInvocation->setTargetRootModule($params['targetRootModule']);
    }
    return $modInvocation->execute();
}
Пример #4
0
 /**
  *  Easily convert an invocation path into the resulting HTML.
  *
  *  Perfect for buliding emails, AJAX popups, etc.
  *
  *  NOTE: this mechanism doesn't allow you to communitcate with the module before execution.
  *
  *  If you want to pass data to a WFModuleInvocation before executing, you'll need to instantiate WFModuleInvocation
  *  yourself and call execute() manually.
  *
  *  @param string The {@lin invocationPathk WFModule::__construct()} for the module.
  *  @param object WFModuleInvocation The parent WFModuleInvocation that is creating this invocation, or NULL if this is the root invocation. Default is NULL (no parent).
  *  @param string The name of the skin delegate to use. Default is NULL (no skin).
  *  @return string The resulting output of module execution.
  *  @throws object WFException Any exception generated during execution.
  */
 public static function quickModule($invocationPath, $parentInvocation = NULL, $skinDelegate = NULL)
 {
     try {
         while (true) {
             try {
                 $modInv = new WFModuleInvocation($invocationPath, $parentInvocation, $skinDelegate);
                 $result = $modInv->execute();
                 break;
             } catch (WFRequestController_InternalRedirectException $e) {
                 $invocationPath = $e->getRedirectURL();
                 $invocationPath = ltrim(substr($invocationPath, strlen(WWW_ROOT)), '/');
             }
         }
     } catch (Exception $e) {
         WFLog::log("Uncaught Exception with quickModule('{$invocationPath}'): (" . get_class($e) . ") " . $e->getMessage(), WFLog::WARN_LOG);
         throw $e;
     }
     return $result;
 }
Пример #5
0
 private function executeAndAssert($invocationPath, $expectedResult)
 {
     if (!is_array($expectedResult)) {
         $expectedResult = array($expectedResult);
     }
     $result = NULL;
     try {
         $result = WFModuleInvocation::quickModule($invocationPath);
     } catch (Exception $e) {
         $this->fail('Invocation Path: "' . $invocationPath . '" threw an exception: ' . get_class($e) . ': ' . $e->getMessage());
     }
     foreach ($expectedResult as $r) {
         $this->assertContains($r, $result);
     }
 }